mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
glsurface.h/.cpp: change how the palette is handled and fix tinting/fading
git-svn-id: https://svn.eduke32.com/eduke32@6932 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
a0faeaf8f6
commit
9e90b0633b
4 changed files with 24 additions and 32 deletions
|
@ -9,7 +9,6 @@
|
|||
#define GLSURFACE_H_
|
||||
|
||||
#include "compat.h"
|
||||
#include "palette.h"
|
||||
|
||||
// Initialize the glsurface with the Software renderer's buffer resolution.
|
||||
// If the Software renderer's resolution and the actual resolution don't match,
|
||||
|
@ -21,9 +20,9 @@ bool glsurface_initialize(vec2_t inputBufferResolution);
|
|||
// Destroy an existing surface.
|
||||
void glsurface_destroy();
|
||||
|
||||
// Sets the palette at paletteID to contain the byte buffer pointed to by pPalette.
|
||||
// Sets the palette to contain the RGBA byte buffer pointed to by pPalette.
|
||||
// If the surface is not initialized, the function returns immediately.
|
||||
void glsurface_setPalette(int32_t paletteID, void* pPalette);
|
||||
void glsurface_setPalette(void* pPalette);
|
||||
|
||||
// Returns a pointer to the start of the surface's pixel buffer
|
||||
// Returns NULL if the surface is not initialized.
|
||||
|
@ -32,10 +31,9 @@ void* glsurface_getBuffer();
|
|||
// Returns the resolution of the surface's buffer
|
||||
vec2_t glsurface_getBufferResolution();
|
||||
|
||||
// Blit the surface's pixel buffer to the screen.
|
||||
// paletteID is the id of a palette previously set with glsurface_setPalette().
|
||||
// Blit the surface's pixel buffer to the screen using the palette set with glsurface_setPalette().
|
||||
// Renders as soon as the data has been uploaded.
|
||||
// If the surface is not initialized, the function returns immediately.
|
||||
void glsurface_blitBuffer(int32_t paletteID);
|
||||
void glsurface_blitBuffer();
|
||||
|
||||
#endif /* GLSURFACE_H_ */
|
||||
|
|
|
@ -15,7 +15,7 @@ static void* buffer;
|
|||
static GLuint bufferTexID;
|
||||
static vec2_t bufferRes;
|
||||
|
||||
static GLuint paletteTexIDs[MAXBASEPALS];
|
||||
static GLuint paletteTexID;
|
||||
|
||||
static GLuint quadVertsID = 0;
|
||||
|
||||
|
@ -97,6 +97,8 @@ bool glsurface_initialize(vec2_t inputBufferResolution)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, bufferRes.x, bufferRes.y, 0, GL_RED, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glsurface_setPalette(curpalettefaded);
|
||||
|
||||
const char* const VERTEX_SHADER_CODE =
|
||||
"#version 110\n\
|
||||
\n\
|
||||
|
@ -127,7 +129,7 @@ bool glsurface_initialize(vec2_t inputBufferResolution)
|
|||
{\n\
|
||||
vec4 color = texture2D(s_texture, v_texCoord.xy);\n\
|
||||
color.r = c_paletteOffset + c_paletteScale*color.r;\n\
|
||||
color = texture2D(s_palette, color.rg);\n\
|
||||
color.rgb = texture2D(s_palette, color.rg).rgb;\n\
|
||||
\n\
|
||||
// DEBUG \n\
|
||||
//color = texture2D(s_palette, v_texCoord.xy);\n\
|
||||
|
@ -156,11 +158,6 @@ bool glsurface_initialize(vec2_t inputBufferResolution)
|
|||
glUniform1i(texSamplerLoc, 0);
|
||||
glUniform1i(paletteSamplerLoc, 1);
|
||||
|
||||
for (int basepalnum = 0; basepalnum < MAXBASEPALS; ++basepalnum)
|
||||
{
|
||||
glsurface_setPalette(basepalnum, basepaltable[basepalnum]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -176,14 +173,14 @@ void glsurface_destroy()
|
|||
|
||||
glDeleteTextures(1, &bufferTexID);
|
||||
bufferTexID = 0;
|
||||
glDeleteTextures(MAXBASEPALS, paletteTexIDs);
|
||||
memset(paletteTexIDs, 0, sizeof(paletteTexIDs));
|
||||
glDeleteTextures(1, &paletteTexID);
|
||||
paletteTexID = 0;
|
||||
|
||||
glDeleteProgram(shaderProgramID);
|
||||
shaderProgramID = 0;
|
||||
}
|
||||
|
||||
void glsurface_setPalette(int32_t paletteID, void* pPalette)
|
||||
void glsurface_setPalette(void* pPalette)
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
|
@ -191,15 +188,15 @@ void glsurface_setPalette(int32_t paletteID, void* pPalette)
|
|||
return;
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
if (paletteTexIDs[paletteID])
|
||||
if (paletteTexID)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, paletteTexIDs[paletteID]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*) buffer);
|
||||
// assume the texture is already bound to GL_TEXTURE1
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*) pPalette);
|
||||
}
|
||||
else
|
||||
{
|
||||
glGenTextures(1, paletteTexIDs+paletteID);
|
||||
glBindTexture(GL_TEXTURE_2D, paletteTexIDs[paletteID]);
|
||||
glGenTextures(1, &paletteTexID);
|
||||
glBindTexture(GL_TEXTURE_2D, paletteTexID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
@ -207,7 +204,7 @@ void glsurface_setPalette(int32_t paletteID, void* pPalette)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 256, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, pPalette);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pPalette);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,14 +218,11 @@ vec2_t glsurface_getBufferResolution()
|
|||
return bufferRes;
|
||||
}
|
||||
|
||||
void glsurface_blitBuffer(int32_t paletteID)
|
||||
void glsurface_blitBuffer()
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, paletteTexIDs[paletteID]);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bufferRes.x, bufferRes.y, GL_RED, GL_UNSIGNED_BYTE, (void*) buffer);
|
||||
|
||||
|
|
|
@ -660,11 +660,7 @@ void paletteSetColorTable(int32_t id, uint8_t const * const table)
|
|||
Bmemcpy(basepaltable[id], table, 768);
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() == REND_CLASSIC)
|
||||
{
|
||||
glsurface_setPalette(id, basepaltable[id]);
|
||||
}
|
||||
else if (videoGetRenderMode() >= REND_POLYMOST)
|
||||
if (videoGetRenderMode() >= REND_POLYMOST)
|
||||
{
|
||||
uploadbasepalette(id);
|
||||
}
|
||||
|
@ -746,6 +742,7 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
|
|||
|
||||
if (palsumdidchange || newpalettesum != g_lastpalettesum)
|
||||
{
|
||||
glsurface_setPalette(curpalettefaded);
|
||||
// if ((flags&1) == 0)
|
||||
videoUpdatePalette(0, 256);
|
||||
}
|
||||
|
@ -828,7 +825,10 @@ void videoFadePalette(uint8_t r, uint8_t g, uint8_t b, uint8_t offset)
|
|||
uint32_t newpalettesum = XXH32((uint8_t *) curpalettefaded, sizeof(curpalettefaded), sizeof(curpalettefaded));
|
||||
|
||||
if (newpalettesum != lastpalettesum || newpalettesum != g_lastpalettesum)
|
||||
{
|
||||
glsurface_setPalette(curpalettefaded);
|
||||
videoUpdatePalette(0, 256);
|
||||
}
|
||||
|
||||
g_lastpalettesum = lastpalettesum = newpalettesum;
|
||||
}
|
||||
|
|
|
@ -1820,7 +1820,7 @@ void videoShowFrame(int32_t w)
|
|||
}
|
||||
else
|
||||
{
|
||||
glsurface_blitBuffer(curbasepal);
|
||||
glsurface_blitBuffer();
|
||||
}
|
||||
|
||||
static uint32_t lastSwapTime = 0;
|
||||
|
|
Loading…
Reference in a new issue