Minor cleanup of some Polymost shader program support functions

git-svn-id: https://svn.eduke32.com/eduke32@7419 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-03-19 17:09:06 +00:00
parent ff8e54432b
commit 4506b8490f

View file

@ -576,24 +576,21 @@ void polymost_resetVertexPointers()
void polymost_disableProgram() void polymost_disableProgram()
{ {
if (videoGetRenderMode() == REND_POLYMOST) if (videoGetRenderMode() != REND_POLYMOST)
{ return;
useShaderProgram(0); useShaderProgram(0);
}
} }
void polymost_resetProgram() void polymost_resetProgram()
{ {
if (videoGetRenderMode() == REND_POLYMOST) if (videoGetRenderMode() != REND_POLYMOST)
{ return;
if (r_enablepolymost2) if (r_enablepolymost2)
{
useShaderProgram(polymost2BasicShaderProgramID); useShaderProgram(polymost2BasicShaderProgramID);
}
else else
{
useShaderProgram(polymost1CurrentShaderProgramID); useShaderProgram(polymost1CurrentShaderProgramID);
}
// ensure that palswapTexture and paletteTexture[curbasepal] is bound // ensure that palswapTexture and paletteTexture[curbasepal] is bound
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
@ -601,7 +598,6 @@ void polymost_resetProgram()
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, paletteTextureIDs[curbasepal]); glBindTexture(GL_TEXTURE_2D, paletteTextureIDs[curbasepal]);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
}
} }
static void polymost_setCurrentShaderProgram(uint32_t programID) static void polymost_setCurrentShaderProgram(uint32_t programID)
@ -653,31 +649,28 @@ static void polymost_setCurrentShaderProgram(uint32_t programID)
void polymost_setTexturePosSize(vec4f_t const &texturePosSize) void polymost_setTexturePosSize(vec4f_t const &texturePosSize)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID)
{ return;
polymost1TexturePosSize = texturePosSize; polymost1TexturePosSize = texturePosSize;
glUniform4f(polymost1TexturePosSizeLoc, polymost1TexturePosSize.x, polymost1TexturePosSize.y, polymost1TexturePosSize.z, polymost1TexturePosSize.w); glUniform4f(polymost1TexturePosSizeLoc, polymost1TexturePosSize.x, polymost1TexturePosSize.y, polymost1TexturePosSize.z, polymost1TexturePosSize.w);
}
} }
static inline void polymost_setHalfTexelSize(vec2f_t const &halfTexelSize) static inline void polymost_setHalfTexelSize(vec2f_t const &halfTexelSize)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || (halfTexelSize.x == polymost1HalfTexelSize.x && halfTexelSize.y == polymost1HalfTexelSize.y))
{ return;
polymost1HalfTexelSize = halfTexelSize; polymost1HalfTexelSize = halfTexelSize;
glUniform2f(polymost1HalfTexelSizeLoc, polymost1HalfTexelSize.x, polymost1HalfTexelSize.y); glUniform2f(polymost1HalfTexelSizeLoc, polymost1HalfTexelSize.x, polymost1HalfTexelSize.y);
}
} }
static void polymost_setPalswap(uint32_t index) static void polymost_setPalswap(uint32_t index)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) static uint32_t lastPalswapIndex;
{
static uint32_t lastPalswapIndex = 0; if (currentShaderProgramID != polymost1CurrentShaderProgramID || index == lastPalswapIndex)
if (index == lastPalswapIndex)
{
return; return;
}
lastPalswapIndex = index; lastPalswapIndex = index;
polymost1PalswapPos.x = index*polymost1PalswapSize.x; polymost1PalswapPos.x = index*polymost1PalswapSize.x;
@ -685,134 +678,121 @@ static void polymost_setPalswap(uint32_t index)
polymost1PalswapPos.x = polymost1PalswapPos.x - polymost1PalswapPos.y + (0.5f/PALSWAP_TEXTURE_SIZE); polymost1PalswapPos.x = polymost1PalswapPos.x - polymost1PalswapPos.y + (0.5f/PALSWAP_TEXTURE_SIZE);
polymost1PalswapPos.y = polymost1PalswapPos.y * polymost1PalswapSize.y + (0.5f/PALSWAP_TEXTURE_SIZE); polymost1PalswapPos.y = polymost1PalswapPos.y * polymost1PalswapSize.y + (0.5f/PALSWAP_TEXTURE_SIZE);
glUniform2f(polymost1PalswapPosLoc, polymost1PalswapPos.x, polymost1PalswapPos.y); glUniform2f(polymost1PalswapPosLoc, polymost1PalswapPos.x, polymost1PalswapPos.y);
}
} }
static void polymost_setPalswapSize(uint32_t width, uint32_t height) static void polymost_setPalswapSize(uint32_t width, uint32_t height)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID)
{ return;
polymost1PalswapSize.x = width*(1.f/PALSWAP_TEXTURE_SIZE); polymost1PalswapSize.x = width*(1.f/PALSWAP_TEXTURE_SIZE);
polymost1PalswapSize.y = height*(1.f/PALSWAP_TEXTURE_SIZE); polymost1PalswapSize.y = height*(1.f/PALSWAP_TEXTURE_SIZE);
polymost1PalswapInnerSize.x = (width-1)*(1.f/PALSWAP_TEXTURE_SIZE); polymost1PalswapInnerSize.x = (width-1)*(1.f/PALSWAP_TEXTURE_SIZE);
polymost1PalswapInnerSize.y = (height-1)*(1.f/PALSWAP_TEXTURE_SIZE); polymost1PalswapInnerSize.y = (height-1)*(1.f/PALSWAP_TEXTURE_SIZE);
glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y); glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y);
}
} }
static void polymost_setShade(int32_t shade) static void polymost_setShade(int32_t shade)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID)
{ return;
if (!r_usetileshades || (globalflags & GLOBAL_NO_GL_TILESHADES)) if (!r_usetileshades || (globalflags & GLOBAL_NO_GL_TILESHADES))
shade = 0; shade = 0;
#if 0
else else
shade = /*getpalookup(r_usetileshades == 1, */shade/*)*/; shade = getpalookup(r_usetileshades == 1, shade);
#endif
static int32_t lastShade;
static int32_t lastNumShades;
static int32_t lastShade = 0;
static int32_t lastNumShades = 0;
if (shade != lastShade) if (shade != lastShade)
{ {
lastShade = shade; lastShade = shade;
polymost1Shade = shade; polymost1Shade = shade;
glUniform1f(polymost1ShadeLoc, polymost1Shade); glUniform1f(polymost1ShadeLoc, polymost1Shade);
} }
if (numshades != lastNumShades) if (numshades != lastNumShades)
{ {
lastNumShades = numshades; lastNumShades = numshades;
polymost1NumShades = numshades; polymost1NumShades = numshades;
glUniform1f(polymost1NumShadesLoc, polymost1NumShades); glUniform1f(polymost1NumShadesLoc, polymost1NumShades);
} }
}
} }
static void polymost_setVisibility(float visibility) static void polymost_setVisibility(float visibility)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID)
{ return;
polymost1VisFactor = visibility*fviewingrange*(1.f/(64.f*65536.f));
polymost1VisFactor = visibility * fviewingrange * (1.f / (64.f * 65536.f));
glUniform1f(polymost1VisFactorLoc, polymost1VisFactor); glUniform1f(polymost1VisFactorLoc, polymost1VisFactor);
}
} }
void polymost_setFogEnabled(char fogEnabled) void polymost_setFogEnabled(char fogEnabled)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || fogEnabled == polymost1FogEnabled)
{ return;
polymost1FogEnabled = fogEnabled; polymost1FogEnabled = fogEnabled;
glUniform1f(polymost1FogEnabledLoc, polymost1FogEnabled); glUniform1f(polymost1FogEnabledLoc, polymost1FogEnabled);
}
} }
void polymost_useColorOnly(char useColorOnly) void polymost_useColorOnly(char useColorOnly)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || useColorOnly == polymost1UseColorOnly)
{ return;
polymost1UseColorOnly = useColorOnly; polymost1UseColorOnly = useColorOnly;
glUniform1f(polymost1UseColorOnlyLoc, polymost1UseColorOnly); glUniform1f(polymost1UseColorOnlyLoc, polymost1UseColorOnly);
}
} }
void polymost_usePaletteIndexing(char usePaletteIndexing) void polymost_usePaletteIndexing(char usePaletteIndexing)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || usePaletteIndexing == polymost1UsePalette)
{ return;
polymost1UsePalette = usePaletteIndexing; polymost1UsePalette = usePaletteIndexing;
glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette); glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette);
}
} }
void polymost_useDetailMapping(char useDetailMapping) void polymost_useDetailMapping(char useDetailMapping)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || useDetailMapping == polymost1UseDetailMapping)
{
if (useDetailMapping == polymost1UseDetailMapping)
{
return; return;
}
if (useDetailMapping && if (useDetailMapping)
currentShaderProgramID != polymost1ExtendedShaderProgramID)
{
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID); polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
}
polymost1UseDetailMapping = useDetailMapping; polymost1UseDetailMapping = useDetailMapping;
glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping); glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping);
}
} }
void polymost_useGlowMapping(char useGlowMapping) void polymost_useGlowMapping(char useGlowMapping)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || useGlowMapping == polymost1UseGlowMapping)
{
if (useGlowMapping == polymost1UseGlowMapping)
{
return; return;
}
if (useGlowMapping && if (useGlowMapping)
currentShaderProgramID != polymost1ExtendedShaderProgramID)
{
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID); polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
}
polymost1UseGlowMapping = useGlowMapping; polymost1UseGlowMapping = useGlowMapping;
glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping); glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping);
}
} }
void polymost_npotEmulation(char npotEmulation, float factor, float xOffset) void polymost_npotEmulation(char npotEmulation, float factor, float xOffset)
{ {
if (currentShaderProgramID == polymost1CurrentShaderProgramID) if (currentShaderProgramID != polymost1CurrentShaderProgramID || npotEmulation == polymost1NPOTEmulation)
{ return;
polymost1NPOTEmulation = npotEmulation; polymost1NPOTEmulation = npotEmulation;
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation); glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
polymost1NPOTEmulationFactor = factor; polymost1NPOTEmulationFactor = factor;
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor); glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
polymost1NPOTEmulationXOffset = xOffset; polymost1NPOTEmulationXOffset = xOffset;
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset); glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
}
} }
void polymost_activeTexture(GLenum texture) void polymost_activeTexture(GLenum texture)
@ -3004,9 +2984,7 @@ static void polymost2_drawVBO(GLenum mode,
static void polymost_updatePalette() static void polymost_updatePalette()
{ {
if (videoGetRenderMode() != REND_POLYMOST) if (videoGetRenderMode() != REND_POLYMOST)
{
return; return;
}
polymost_setPalswap(globalpal); polymost_setPalswap(globalpal);
polymost_setShade(globalshade); polymost_setShade(globalshade);
@ -8393,7 +8371,6 @@ void polymost_fillpolygon(int32_t npoints)
polymost_usePaletteIndexing(false); polymost_usePaletteIndexing(false);
} }
if (videoGetRenderMode() == REND_POLYMOST)
polymost_updatePalette(); polymost_updatePalette();
float const f = getshadefactor(globalshade); float const f = getshadefactor(globalshade);
@ -8473,7 +8450,6 @@ int32_t polymost_drawtilescreen(int32_t tilex, int32_t tiley, int32_t wallnum, i
polymost_usePaletteIndexing(false); polymost_usePaletteIndexing(false);
} }
if (videoGetRenderMode() == REND_POLYMOST)
polymost_updatePalette(); polymost_updatePalette();
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);