From e3e9f5b6fb9173ea38ab4b37b137dd17ffe761ad Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 12 Feb 2026 17:44:30 -0800 Subject: Use the texture register --- src/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index d0696d0..1fd39e0 100644 --- a/src/main.c +++ b/src/main.c @@ -247,9 +247,8 @@ static void RenderModel(swgfx* gfx, const sgImage* textures, const Model* model) const ModelObject* object = &objects[i]; // TODO: This indexing into the textures array assumes that we have loaded a // single model. Generalize later. - assert((size_t)object->material < MaxTextures); - const sgImage* texture = &textures[object->material]; - sgTexture(gfx, texture, sgBilinear); + assert((size_t)object->material < SWGFX_MAX_TEXTURES); + sgTextureActivate(gfx, (sgTextureId)object->material); switch (model->type) { case ModelTypeIndexed: RenderIndexedModel(gfx, &model->indexed, object); break; case ModelTypeFlat: /* TODO: Render flat models. */ break; @@ -361,13 +360,14 @@ static bool Resize(State* state) { static bool LoadTexture(State* state, const char* path) { assert(state); - if (state->numTextures >= MaxTextures) { + if ((state->numTextures >= MaxTextures) || (state->numTextures >= SWGFX_MAX_TEXTURES)) { fprintf(stderr, "Cannot load texture. Maximum number of textures loaded\n"); return false; } // TODO: This indexing into the textures array assumes that we have loaded a // single model. Generalize later. - sgImage* texture = &state->textures[state->numTextures++]; + const size_t id = state->numTextures++; + sgImage* texture = &state->textures[id]; int channels = 0; constexpr int desired_channels = 4; texture->pixels = (sgPixel*)stbi_load(path, &texture->width, &texture->height, &channels, desired_channels); @@ -378,6 +378,7 @@ static bool LoadTexture(State* state, const char* path) { assert(channels == desired_channels); // Gamma-correct for lighting. sgGamma(state->gfx, texture->pixels, texture->width, texture->height); + sgTextureRegister(state->gfx, (sgTextureId)id, texture, sgBilinear); return true; } -- cgit v1.2.3