diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 39fd7a9fb..2aeb497bb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1067,6 +1067,33 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) return id; } + +// get hwr lighttable id for colormap, create it if it doesn't already exist +UINT32 HWR_GetLightTableID(extracolormap_t *colormap) +{ + boolean default_colormap = false; + if (!colormap) + { + colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id + // alternatively could just store the id in a global variable if there are issues + default_colormap = true; + } + + // create hw lighttable if there isn't one + if (!colormap->gl_lighttable_id) + { + UINT8 *colormap_pointer; + + if (default_colormap) + colormap_pointer = colormaps; // don't actually use the data from the "default colormap" + else + colormap_pointer = colormap->colormap; + colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer); + } + + return colormap->gl_lighttable_id; +} + // Note: all hardware lighttable ids assigned before this // call become invalid and must not be used. void HWR_ClearLightTables(void) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 3423bd09c..082a6a78c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -71,6 +71,7 @@ void HWR_SetPalette(RGBA_t *palette); void HWR_SetMapPalette(void); UINT32 HWR_CreateLightTable(UINT8 *lighttable); +UINT32 HWR_GetLightTableID(extracolormap_t *colormap); void HWR_ClearLightTables(void); GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e6e4688cc..820da8673 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -451,7 +451,6 @@ boolean HWR_PalRenderFlashpal(void) void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { RGBA_t poly_color, tint_color, fade_color; - boolean default_colormap = false; poly_color.rgba = 0xFFFFFFFF; tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; @@ -505,31 +504,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; if (HWR_ShouldUsePaletteRendering()) - { - boolean default_colormap = false; - if (!colormap) - { - colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id - // alternatively could just store the id in a global variable if there are issues - default_colormap = true; - } - // create hw lighttable if there isn't one - if (!colormap->gl_lighttable_id) - { - UINT8 *colormap_pointer; - - if (default_colormap) - colormap_pointer = colormaps; // don't actually use the data from the "default colormap" - else - colormap_pointer = colormap->colormap; - colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer); - } - Surface->LightTableId = colormap->gl_lighttable_id; - } + Surface->LightTableId = HWR_GetLightTableID(colormap); else - { Surface->LightTableId = 0; - } } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 83f5c3b31..899b122c5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -671,9 +671,9 @@ typedef enum gluniform_fade_end, // palette rendering - gluniform_screen_palette_tex, - gluniform_palette_lookup_tex, - gluniform_lighttable_tex, + gluniform_palette_tex, // 1d texture containing a palette + gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table + gluniform_lighttable_tex, // 2d texture containing a light table // misc. gluniform_leveltime, @@ -922,12 +922,12 @@ static float shader_leveltime = 0; #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler1D screen_palette_tex;\n" \ + "uniform sampler1D palette_tex;\n" \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ "float palette_coord = (tex_pal_idx + 0.5) / 256.0;\n" \ - "vec4 final_color = texture1D(screen_palette_tex, palette_coord);\n" \ + "vec4 final_color = texture1D(palette_tex, palette_coord);\n" \ "gl_FragColor = final_color;\n" \ "}\0" @@ -1209,7 +1209,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); // palette rendering - shader->uniforms[gluniform_screen_palette_tex] = GETUNI("screen_palette_tex"); + shader->uniforms[gluniform_palette_tex] = GETUNI("palette_tex"); shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex"); shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); @@ -1225,7 +1225,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) pglUseProgram(shader->program); // texture unit numbers for the samplers used for palette rendering - UNIFORM_1(shader->uniforms[gluniform_screen_palette_tex], 2, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i);