Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vs49688 committed Sep 27, 2024
1 parent 467c700 commit 9f3dcd5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions drivers/glrend/devpixmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ br_error BR_CMETHOD(br_device_pixelmap_gl, rectangleStretchCopyTo)(br_device_pix
fmt = DeviceGLGetFormatDetails(src->type);
}

clut = self->screen->asFront.tex_white;
clut = self->asBack.clut->gl_tex ? self->asBack.clut->gl_tex : self->screen->asFront.tex_white;
if(fmt->indexed && src->map != NULL) {
if(src->map->stored != NULL) {
clut = BufferStoredGLGetCLUTTexture(stored, self->screen->asFront.tex_white);
clut = BufferStoredGLGetCLUTTexture(stored, self, clut);
} else {
clut = DeviceGLPixelmapToGLTexture(src->map);
clut_tmp = BR_TRUE;
Expand Down
2 changes: 1 addition & 1 deletion drivers/glrend/drv_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct br_buffer_stored *BufferStoredGLAllocate(br_renderer *renderer, br_token
br_token_value *tv);

GLenum BufferStoredGLGetTexture(br_buffer_stored *self);
GLuint BufferStoredGLGetCLUTTexture(br_buffer_stored *self, GLuint fallback);
GLuint BufferStoredGLGetCLUTTexture(br_buffer_stored *self, br_device_pixelmap *target, GLuint fallback);

/*
* gv1buckt.c
Expand Down
44 changes: 40 additions & 4 deletions drivers/glrend/sbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,57 @@ GLuint BufferStoredGLGetTexture(br_buffer_stored *self)
return self->gl_tex;
}

GLuint BufferStoredGLGetCLUTTexture(br_buffer_stored *self, GLuint fallback)
GLuint BufferStoredGLGetCLUTTexture(br_buffer_stored *self, br_device_pixelmap *target, GLuint fallback)
{
GLuint clut;

if(self == NULL)
return fallback;

/*
* If we have a CLUT, use it.
*/
if(self->source == NULL)
return fallback;
goto use_target;

if(self->source->map == NULL)
return fallback;
goto use_target;

if(self->source->map->stored == NULL)
goto use_target;

if((clut = BufferStoredGLGetTexture(self->source->map->stored)) != 0)
return clut;

use_target:
/*
* If there's no target pixelmap, see if our renderer's current state has one.
*/
if(target == NULL) {
const state_output *output;

if(!(self->renderer->state.current->valid & BR_STATE_OUTPUT))
return fallback;

target = self->renderer->state.current->output.colour;
}

/*
* Try to use the target's CLUT.
*/
if(target == NULL)
return fallback;

if(target->use_type != BRT_OFFSCREEN)
return fallback;

if(target->asBack.clut == NULL)
return fallback;

if(target->asBack.clut->gl_tex == 0)
return fallback;

return BufferStoredGLGetTexture(self->source->map->stored);
return target->asBack.clut->gl_tex;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/glrend/v1model.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void apply_stored_properties(HVIDEO hVideo, state_stack *state, uint32_t

if(model->is_indexed) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, BufferStoredGLGetCLUTTexture(stored, tex_default));
glBindTexture(GL_TEXTURE_2D, BufferStoredGLGetCLUTTexture(stored, NULL, tex_default));
glUniform1i(hVideo->brenderProgram.uniforms.main_texture, hVideo->brenderProgram.mainTextureBinding);

glActiveTexture(GL_TEXTURE1);
Expand Down
2 changes: 1 addition & 1 deletion examples/devpmtest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ int main(int argc, char **argv)
BRT_HIDPI_B, BR_TRUE,
/* Set these if you dare... */
BRT_RESIZABLE_B, BR_TRUE,
BRT_OPENGL_B, BR_FALSE,
BRT_OPENGL_B, BR_TRUE,
BR_NULL_TOKEN);
// clang-format on

Expand Down

0 comments on commit 9f3dcd5

Please sign in to comment.