mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- moved the main shader and its entire uniform maintenance into the backend.
This commit is contained in:
parent
50c2065425
commit
bd4e4834e3
17 changed files with 650 additions and 592 deletions
|
@ -772,6 +772,7 @@ set (PCH_SOURCES
|
|||
|
||||
glbackend/gl_hwtexture.cpp
|
||||
glbackend/gl_samplers.cpp
|
||||
glbackend/gl_shader.cpp
|
||||
glbackend/glbackend.cpp
|
||||
|
||||
mact/src/animlib.cpp
|
||||
|
|
|
@ -1489,23 +1489,8 @@ int32_t engineLoadBoardV5V6(const char *filename, char fromwhere, vec3_t *dapos,
|
|||
#endif
|
||||
|
||||
|
||||
static FORCE_INLINE void renderDisableFog(void)
|
||||
{
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() >= REND_POLYMOST)
|
||||
{
|
||||
polymost_setFogEnabled(false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static FORCE_INLINE void renderEnableFog(void)
|
||||
{
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() >= REND_POLYMOST && !nofog)
|
||||
polymost_setFogEnabled(true);
|
||||
#endif
|
||||
}
|
||||
void renderDisableFog(void);
|
||||
void renderEnableFog(void);
|
||||
|
||||
static vec2_t const zerovec = { 0, 0 };
|
||||
|
||||
|
|
|
@ -51,19 +51,6 @@ void polymost_completeMirror();
|
|||
int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall);
|
||||
int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr);
|
||||
|
||||
void polymost_resetVertexPointers(void);
|
||||
void polymost_disableProgram(void);
|
||||
void polymost_resetProgram(void);
|
||||
void polymost_setTexturePosSize(vec4f_t const &texturePosSize);
|
||||
void polymost_setHalfTexelSize(vec2f_t const &halfTexelSize);
|
||||
char polymost_getClamp();
|
||||
void polymost_setClamp(char clamp);
|
||||
void polymost_setVisibility(float visibility);
|
||||
void polymost_setFogEnabled(char fogEnabled);
|
||||
void polymost_useColorOnly(char useColorOnly);
|
||||
void polymost_usePaletteIndexing(char usePaletteIndexing);
|
||||
void polymost_useDetailMapping(char useDetailMapping);
|
||||
void polymost_useGlowMapping(char useGlowMapping);
|
||||
void useShaderProgram(uint32_t shaderID);
|
||||
|
||||
float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]);
|
||||
|
@ -71,8 +58,6 @@ float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]);
|
|||
void polymost_glinit(void);
|
||||
void polymost_glreset(void);
|
||||
|
||||
void polymost_init(void);
|
||||
|
||||
enum {
|
||||
INVALIDATE_ALL,
|
||||
INVALIDATE_ART,
|
||||
|
|
|
@ -60,7 +60,7 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t
|
|||
GLInterface.EnableDepthTest(false);
|
||||
GLInterface.EnableBlend(true); // When using line antialiasing, this is needed
|
||||
|
||||
polymost_useColorOnly(true);
|
||||
GLInterface.UseColorOnly(true);
|
||||
GLInterface.SetColorub(p.r, p.g, p.b, 255);
|
||||
|
||||
auto data = GLInterface.AllocVertices(2);
|
||||
|
@ -68,7 +68,7 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t
|
|||
data.second[1].Set((float) x2 * (1.f/4096.f), (float) y2 * (1.f/4096.f));
|
||||
GLInterface.Draw(DT_LINES, data.first, 2);
|
||||
|
||||
polymost_useColorOnly(false);
|
||||
GLInterface.UseColorOnly(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -417,7 +417,6 @@ void animvpx_setup_glstate(int32_t animvpx_flags)
|
|||
VSMatrix identity(0);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &identity);
|
||||
GLInterface.SetMatrix(Matrix_Projection, &identity);
|
||||
GLInterface.SetMatrix(Matrix_Texture0, &identity);
|
||||
|
||||
GLInterface.EnableAlphaTest(false);
|
||||
GLInterface.EnableDepthTest(false);
|
||||
|
@ -444,8 +443,7 @@ void animvpx_setup_glstate(int32_t animvpx_flags)
|
|||
|
||||
void animvpx_restore_glstate(void)
|
||||
{
|
||||
useShaderProgram(0);
|
||||
polymost_resetProgram();
|
||||
GLInterface.SetPolymostShader();
|
||||
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
|
|
|
@ -249,8 +249,8 @@ int32_t FindDistance3D(int32_t x, int32_t y, int32_t z)
|
|||
// Clear OSD background
|
||||
void COMMON_doclearbackground(int numcols, int height)
|
||||
{
|
||||
polymost_setFogEnabled(false);
|
||||
polymost_useColorOnly(true);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
GLInterface.UseColorOnly(true);
|
||||
|
||||
polymostSet2dView();
|
||||
|
||||
|
@ -277,8 +277,8 @@ void COMMON_doclearbackground(int numcols, int height)
|
|||
GLInterface.SetColor(0.f, 0.f, 0.f, 1.f);
|
||||
GLInterface.Draw(DT_TRIANGLE_STRIP, vert.first+4, 4);
|
||||
|
||||
polymost_useColorOnly(false);
|
||||
polymost_setFogEnabled(true);
|
||||
GLInterface.UseColorOnly(false);
|
||||
GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
|
||||
void COMMON_clearbackground(int numcols, int numrows)
|
||||
|
|
|
@ -8975,7 +8975,7 @@ killsprite:
|
|||
{
|
||||
GLInterface.EnableBlend(false);
|
||||
GLInterface.EnableAlphaTest(true);
|
||||
polymost_setClamp(1+2);
|
||||
GLInterface.SetClamp(1+2);
|
||||
|
||||
if (spritesortcnt < numSprites)
|
||||
{
|
||||
|
@ -9026,7 +9026,7 @@ killsprite:
|
|||
}
|
||||
}
|
||||
|
||||
polymost_setClamp(0);
|
||||
GLInterface.SetClamp(0);
|
||||
int32_t numMaskWalls = maskwallcnt;
|
||||
maskwallcnt = 0;
|
||||
for (i = 0; i < numMaskWalls; i++)
|
||||
|
@ -9071,7 +9071,7 @@ killsprite:
|
|||
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
polymost_setClamp(1+2);
|
||||
GLInterface.SetClamp(1+2);
|
||||
#endif
|
||||
|
||||
i = spritesortcnt;
|
||||
|
@ -9160,14 +9160,14 @@ killsprite:
|
|||
debugmask_add(maskwall[maskwallcnt], thewall[maskwall[maskwallcnt]]);
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
polymost_setClamp(0);
|
||||
GLInterface.SetClamp(0);
|
||||
#endif
|
||||
renderDrawMaskedWall(maskwallcnt);
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
polymost_setClamp(1+2);
|
||||
GLInterface.SetClamp(1+2);
|
||||
#endif
|
||||
while (spritesortcnt)
|
||||
{
|
||||
|
@ -9183,7 +9183,7 @@ killsprite:
|
|||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
{
|
||||
GLInterface.SetDepthMask(true);
|
||||
polymost_setClamp(0);
|
||||
GLInterface.SetClamp(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -12982,10 +12982,6 @@ int32_t videoSetRenderMode(int32_t renderer)
|
|||
if (videoGetRenderMode() >= REND_POLYMOST)
|
||||
glrendmode = rendmode;
|
||||
|
||||
if (renderer == REND_POLYMOST)
|
||||
{
|
||||
polymost_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -2058,10 +2058,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
float const xpanning = (float)sext->xpanning * (1.f/256.f);
|
||||
float const ypanning = (float)sext->ypanning * (1.f/256.f);
|
||||
|
||||
char prevClamp = polymost_getClamp();
|
||||
polymost_setClamp(0);
|
||||
polymost_usePaletteIndexing(false);
|
||||
polymost_setTexturePosSize({ 0.f, 0.f, 1.f, 1.f });
|
||||
int prevClamp = GLInterface.GetClamp();
|
||||
GLInterface.SetClamp(0);
|
||||
GLInterface.UsePaletteIndexing(false);
|
||||
|
||||
for (surfi=0; surfi<m->head.numsurfs; surfi++)
|
||||
{
|
||||
|
@ -2130,7 +2129,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
|
||||
if (!(tspr->extra&TSPR_EXTRA_MDHACK))
|
||||
{
|
||||
#ifdef USE_GLEXT
|
||||
//POGOTODO: if we add support for palette indexing on model skins, the texture for the palswap could be setup here
|
||||
texunits += 4;
|
||||
|
||||
|
@ -2140,7 +2138,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
{
|
||||
mdskinmap_t *sk;
|
||||
|
||||
polymost_useDetailMapping(true);
|
||||
GLInterface.UseDetailMapping(true);
|
||||
polymost_setupdetailtexture(3, tex);
|
||||
|
||||
for (sk = m->skinmap; sk; sk = sk->next)
|
||||
|
@ -2157,7 +2155,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
|
||||
if (i)
|
||||
{
|
||||
polymost_useGlowMapping(true);
|
||||
GLInterface.UseGlowMapping(true);
|
||||
polymost_setupglowtexture(4, tex);
|
||||
|
||||
texmat.loadIdentity();
|
||||
|
@ -2165,7 +2163,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
GLInterface.SetMatrix(Matrix_Texture4, &texmat);
|
||||
}
|
||||
|
||||
#endif
|
||||
indexhandle = m->vindexes;
|
||||
|
||||
//PLAG: delayed polygon-level sorted rendering
|
||||
|
@ -2217,10 +2214,8 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
md3draw_handle_triangles(s, indexhandle, texunits, NULL);
|
||||
}
|
||||
|
||||
#ifdef USE_GLEXT
|
||||
polymost_useDetailMapping(false);
|
||||
polymost_useGlowMapping(false);
|
||||
#endif
|
||||
GLInterface.UseDetailMapping(false);
|
||||
GLInterface.UseGlowMapping(false);
|
||||
}
|
||||
//------------
|
||||
|
||||
|
@ -2230,11 +2225,10 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
|
|||
|
||||
VSMatrix identity(0);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &identity);
|
||||
GLInterface.SetMatrix(Matrix_Texture0, &identity);
|
||||
|
||||
polymost_setClamp(prevClamp);
|
||||
polymost_usePaletteIndexing(true);
|
||||
polymost_resetVertexPointers();
|
||||
GLInterface.SetClamp(prevClamp);
|
||||
GLInterface.UsePaletteIndexing(true);
|
||||
GLInterface.SetPolymostShader();
|
||||
|
||||
globalnoeffect=0;
|
||||
return 1;
|
||||
|
|
|
@ -58,13 +58,13 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f)
|
|||
|
||||
GLInterface.EnableDepthTest(false);
|
||||
GLInterface.EnableAlphaTest(false);
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
|
||||
GLInterface.SetBlendFunc(STYLEALPHA_Src, STYLEALPHA_InvSrc);
|
||||
GLInterface.EnableBlend(true);
|
||||
GLInterface.SetColorub(r, g, b, f);
|
||||
|
||||
polymost_useColorOnly(true);
|
||||
GLInterface.UseColorOnly(true);
|
||||
|
||||
auto data = GLInterface.AllocVertices(3);
|
||||
auto vt = data.second;
|
||||
|
@ -72,7 +72,7 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f)
|
|||
vt[1].Set(2.5f, 1.f);
|
||||
vt[2].Set(.0f, -2.5f);
|
||||
GLInterface.Draw(DT_TRIANGLES, data.first, 3);
|
||||
polymost_useColorOnly(false);
|
||||
GLInterface.UseColorOnly(false);
|
||||
|
||||
GLInterface.SetMatrix(Matrix_Projection, &oldproj);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &oldmv);
|
||||
|
@ -93,12 +93,12 @@ void fullscreen_tint_gl_blood(void)
|
|||
|
||||
GLInterface.EnableDepthTest(false);
|
||||
GLInterface.EnableAlphaTest(false);
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
|
||||
GLInterface.SetBlendFunc(STYLEALPHA_One, STYLEALPHA_One);
|
||||
GLInterface.EnableBlend(true);
|
||||
|
||||
polymost_useColorOnly(true);
|
||||
GLInterface.UseColorOnly(true);
|
||||
GLInterface.SetColorub(max(tint_blood_r, 0), max(tint_blood_g, 0), max(tint_blood_b, 0), 255);
|
||||
auto data = GLInterface.AllocVertices(3);
|
||||
auto vt = data.second;
|
||||
|
@ -117,7 +117,7 @@ void fullscreen_tint_gl_blood(void)
|
|||
GLInterface.SetBlendOp(STYLEOP_Add);
|
||||
GLInterface.SetColorub(0,0,0,0);
|
||||
GLInterface.SetBlendFunc(STYLEALPHA_Src, STYLEALPHA_InvSrc);
|
||||
polymost_useColorOnly(false);
|
||||
GLInterface.UseColorOnly(false);
|
||||
|
||||
GLInterface.SetMatrix(Matrix_Projection, &oldproj);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &oldmv);
|
||||
|
|
|
@ -129,7 +129,6 @@ int32_t r_flatsky = 1;
|
|||
static float fogresult, fogresult2;
|
||||
coltypef fogcol, fogtable[MAXPALOOKUPS];
|
||||
|
||||
static uint32_t currentShaderProgramID = 0;
|
||||
static GLenum currentActiveTexture = 0;
|
||||
static uint32_t currentTextureID = 0;
|
||||
|
||||
|
@ -143,55 +142,6 @@ static FHardwareTexture *paletteTextureIDs[MAXBASEPALS];
|
|||
static FHardwareTexture *palswapTextureID = nullptr;
|
||||
//extern char const *polymost1Frag;
|
||||
//extern char const *polymost1Vert;
|
||||
static GLuint polymost1CurrentShaderProgramID = 0;
|
||||
static GLuint polymost1ExtendedShaderProgramID = 0;
|
||||
static GLint polymost1TexSamplerLoc = -1;
|
||||
static GLint polymost1PalSwapSamplerLoc = -1;
|
||||
static GLint polymost1PaletteSamplerLoc = -1;
|
||||
static GLint polymost1DetailSamplerLoc = -1;
|
||||
static GLint polymost1GlowSamplerLoc = -1;
|
||||
static GLint polymost1TexturePosSizeLoc = -1;
|
||||
static vec4f_t polymost1TexturePosSize = { 0.f, 0.f, 1.f, 1.f };
|
||||
static GLint polymost1HalfTexelSizeLoc = -1;
|
||||
static vec2f_t polymost1HalfTexelSize = { 0.f, 0.f };
|
||||
static GLint polymost1PalswapPosLoc = -1;
|
||||
static vec2f_t polymost1PalswapPos = { 0.f, 0.f };
|
||||
static GLint polymost1PalswapSizeLoc = -1;
|
||||
static vec2f_t polymost1PalswapSize = { 0.f, 0.f };
|
||||
static vec2f_t polymost1PalswapInnerSize = { 0.f, 0.f };
|
||||
static GLint polymost1ClampLoc = -1;
|
||||
static vec2f_t polymost1Clamp = { 0.f, 0.f };
|
||||
static GLint polymost1ShadeLoc = -1;
|
||||
static float polymost1Shade = 0.f;
|
||||
static GLint polymost1NumShadesLoc = -1;
|
||||
static float polymost1NumShades = 64.f;
|
||||
static GLint polymost1VisFactorLoc = -1;
|
||||
static float polymost1VisFactor = 128.f;
|
||||
static GLint polymost1FogEnabledLoc = -1;
|
||||
static float polymost1FogEnabled = 1.f;
|
||||
static GLint polymost1UseColorOnlyLoc = -1;
|
||||
static float polymost1UseColorOnly = 0.f;
|
||||
static GLint polymost1UsePaletteLoc = -1;
|
||||
static float polymost1UsePalette = 1.f;
|
||||
static GLint polymost1UseDetailMappingLoc = -1;
|
||||
static float polymost1UseDetailMapping = 0.f;
|
||||
static GLint polymost1UseGlowMappingLoc = -1;
|
||||
static float polymost1UseGlowMapping = 0.f;
|
||||
static GLint polymost1NPOTEmulationLoc = -1;
|
||||
static float polymost1NPOTEmulation = 0.f;
|
||||
static GLint polymost1NPOTEmulationFactorLoc = -1;
|
||||
static float polymost1NPOTEmulationFactor = 1.f;
|
||||
static GLint polymost1NPOTEmulationXOffsetLoc = -1;
|
||||
static float polymost1NPOTEmulationXOffset = 0.f;
|
||||
static GLint polymost1BrightnessLoc = -1;
|
||||
static float polymost1Brightness = 1.f;
|
||||
static GLint polymost1RotMatrixLoc = -1;
|
||||
static float polymost1RotMatrix[16] = { 1.f, 0.f, 0.f, 0.f,
|
||||
0.f, 1.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f };
|
||||
static GLint polymost1ShadeInterpolateLoc = -1;
|
||||
static float polymost1ShadeInterpolate = 1.f;
|
||||
|
||||
static inline float float_trans(uint32_t maskprops, uint8_t blend)
|
||||
{
|
||||
|
@ -356,44 +306,6 @@ static void calcmat(vec3f_t a0, const vec2f_t *offset, float f, float mat[16], i
|
|||
mat[14] = (mat[14] + a0.y*mat[2]) + (a0.z*mat[6] + a0.x*mat[10]);
|
||||
}
|
||||
|
||||
static GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int * pLength = nullptr)
|
||||
{
|
||||
GLuint shaderID = glCreateShader(shaderType);
|
||||
if (shaderID == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
glShaderSource(shaderID,
|
||||
1,
|
||||
&source,
|
||||
pLength);
|
||||
glCompileShader(shaderID);
|
||||
|
||||
GLint compileStatus;
|
||||
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compileStatus);
|
||||
if (!compileStatus)
|
||||
{
|
||||
GLint logLength;
|
||||
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
|
||||
OSD_Printf("Compile Status: %u\n", compileStatus);
|
||||
if (logLength > 0)
|
||||
{
|
||||
char *infoLog = (char*)Xmalloc(logLength);
|
||||
glGetShaderInfoLog(shaderID, logLength, &logLength, infoLog);
|
||||
OSD_Printf("Log:\n%s\n", infoLog);
|
||||
free(infoLog);
|
||||
}
|
||||
}
|
||||
|
||||
return shaderID;
|
||||
}
|
||||
|
||||
static GLuint polymost2_compileShader(GLenum shaderType, const char* const source, int length)
|
||||
{
|
||||
return polymost2_compileShader(shaderType, source, &length);
|
||||
}
|
||||
|
||||
void polymost_glreset()
|
||||
{
|
||||
for (bssize_t i=0; i<=MAXPALOOKUPS-1; i++)
|
||||
|
@ -450,286 +362,17 @@ void polymost_glreset()
|
|||
#endif
|
||||
}
|
||||
|
||||
// reset vertex pointers to polymost default
|
||||
void polymost_resetVertexPointers()
|
||||
{
|
||||
polymost_resetProgram();
|
||||
}
|
||||
|
||||
void polymost_disableProgram()
|
||||
{
|
||||
if (videoGetRenderMode() != REND_POLYMOST)
|
||||
return;
|
||||
|
||||
polymost_outputGLDebugMessage(3, "polymost_disableProgram()");
|
||||
|
||||
useShaderProgram(0);
|
||||
}
|
||||
|
||||
void polymost_resetProgram()
|
||||
{
|
||||
if (videoGetRenderMode() != REND_POLYMOST)
|
||||
return;
|
||||
|
||||
polymost_outputGLDebugMessage(3, "polymost_resetProgram()");
|
||||
|
||||
useShaderProgram(polymost1CurrentShaderProgramID);
|
||||
|
||||
// ensure that palswapTexture and paletteTexture[curbasepal] is bound
|
||||
GLInterface.BindTexture(1, palswapTextureID);
|
||||
GLInterface.BindTexture(2, paletteTextureIDs[curbasepal]);
|
||||
}
|
||||
|
||||
static void polymost_setCurrentShaderProgram(uint32_t programID)
|
||||
{
|
||||
polymost_outputGLDebugMessage(3, "polymost_setCurrentShaderProgram(programID:%u)", programID);
|
||||
|
||||
polymost1CurrentShaderProgramID = programID;
|
||||
useShaderProgram(programID);
|
||||
|
||||
//update the uniform locations
|
||||
polymost1TexSamplerLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "s_texture");
|
||||
polymost1PalSwapSamplerLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "s_palswap");
|
||||
polymost1PaletteSamplerLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "s_palette");
|
||||
polymost1DetailSamplerLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "s_detail");
|
||||
polymost1GlowSamplerLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "s_glow");
|
||||
polymost1TexturePosSizeLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_texturePosSize");
|
||||
polymost1HalfTexelSizeLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_halfTexelSize");
|
||||
polymost1PalswapPosLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_palswapPos");
|
||||
polymost1PalswapSizeLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_palswapSize");
|
||||
polymost1ClampLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_clamp");
|
||||
polymost1ShadeLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_shade");
|
||||
polymost1NumShadesLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_numShades");
|
||||
polymost1VisFactorLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_visFactor");
|
||||
polymost1FogEnabledLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_fogEnabled");
|
||||
polymost1UsePaletteLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_usePalette");
|
||||
polymost1UseColorOnlyLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useColorOnly");
|
||||
polymost1UseDetailMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useDetailMapping");
|
||||
polymost1UseGlowMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useGlowMapping");
|
||||
polymost1NPOTEmulationLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulation");
|
||||
polymost1NPOTEmulationFactorLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationFactor");
|
||||
polymost1NPOTEmulationXOffsetLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationXOffset");
|
||||
polymost1BrightnessLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_brightness");
|
||||
polymost1RotMatrixLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_rotMatrix");
|
||||
polymost1ShadeInterpolateLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_shadeInterpolate");
|
||||
|
||||
//set the uniforms to the current values
|
||||
glUniform4f(polymost1TexturePosSizeLoc, polymost1TexturePosSize.x, polymost1TexturePosSize.y, polymost1TexturePosSize.z, polymost1TexturePosSize.w);
|
||||
glUniform2f(polymost1HalfTexelSizeLoc, polymost1HalfTexelSize.x, polymost1HalfTexelSize.y);
|
||||
glUniform2f(polymost1PalswapPosLoc, polymost1PalswapPos.x, polymost1PalswapPos.y);
|
||||
glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y);
|
||||
glUniform2f(polymost1ClampLoc, polymost1Clamp.x, polymost1Clamp.y);
|
||||
glUniform1f(polymost1ShadeLoc, polymost1Shade);
|
||||
glUniform1f(polymost1NumShadesLoc, polymost1NumShades);
|
||||
glUniform1f(polymost1VisFactorLoc, polymost1VisFactor);
|
||||
glUniform1f(polymost1FogEnabledLoc, polymost1FogEnabled);
|
||||
glUniform1f(polymost1UseColorOnlyLoc, polymost1UseColorOnly);
|
||||
glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette);
|
||||
glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping);
|
||||
glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping);
|
||||
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
|
||||
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
|
||||
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
|
||||
glUniform1f(polymost1BrightnessLoc, polymost1Brightness);
|
||||
glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix);
|
||||
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
|
||||
}
|
||||
|
||||
void polymost_setTexturePosSize(vec4f_t const &texturePosSize)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1TexturePosSize = texturePosSize;
|
||||
glUniform4f(polymost1TexturePosSizeLoc, polymost1TexturePosSize.x, polymost1TexturePosSize.y, polymost1TexturePosSize.z, polymost1TexturePosSize.w);
|
||||
}
|
||||
|
||||
static inline void polymost_setHalfTexelSize(vec2f_t const &halfTexelSize)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1HalfTexelSize = halfTexelSize;
|
||||
glUniform2f(polymost1HalfTexelSizeLoc, polymost1HalfTexelSize.x, polymost1HalfTexelSize.y);
|
||||
}
|
||||
|
||||
static void polymost_setPalswap(uint32_t index)
|
||||
{
|
||||
static uint32_t lastPalswapIndex;
|
||||
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
lastPalswapIndex = index;
|
||||
polymost1PalswapPos.x = index*polymost1PalswapSize.x;
|
||||
polymost1PalswapPos.y = floorf(polymost1PalswapPos.x);
|
||||
polymost1PalswapPos = { polymost1PalswapPos.x - polymost1PalswapPos.y + (0.5f/PALSWAP_TEXTURE_SIZE),
|
||||
polymost1PalswapPos.y * polymost1PalswapSize.y + (0.5f/PALSWAP_TEXTURE_SIZE) };
|
||||
glUniform2f(polymost1PalswapPosLoc, polymost1PalswapPos.x, polymost1PalswapPos.y);
|
||||
}
|
||||
|
||||
static void polymost_setPalswapSize(uint32_t width, uint32_t height)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1PalswapSize = { width*(1.f/PALSWAP_TEXTURE_SIZE),
|
||||
height*(1.f/PALSWAP_TEXTURE_SIZE) };
|
||||
|
||||
polymost1PalswapInnerSize = { (width-1)*(1.f/PALSWAP_TEXTURE_SIZE),
|
||||
(height-1)*(1.f/PALSWAP_TEXTURE_SIZE) };
|
||||
|
||||
glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y);
|
||||
}
|
||||
|
||||
char polymost_getClamp()
|
||||
{
|
||||
return polymost1Clamp.x + polymost1Clamp.y*2.0;
|
||||
}
|
||||
|
||||
void polymost_setClamp(char clamp)
|
||||
{
|
||||
char clampx = clamp&1;
|
||||
char clampy = clamp>>1;
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID ||
|
||||
(clampx == polymost1Clamp.x && clampy == polymost1Clamp.y))
|
||||
return;
|
||||
|
||||
polymost1Clamp.x = clampx;
|
||||
polymost1Clamp.y = clampy;
|
||||
glUniform2f(polymost1ClampLoc, polymost1Clamp.x, polymost1Clamp.y);
|
||||
}
|
||||
|
||||
static void polymost_setShade(int32_t shade)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
if (globalflags & GLOBAL_NO_GL_TILESHADES)
|
||||
shade = 0;
|
||||
|
||||
static int32_t lastShade;
|
||||
static int32_t lastNumShades;
|
||||
|
||||
if (shade != lastShade)
|
||||
{
|
||||
lastShade = shade;
|
||||
polymost1Shade = shade;
|
||||
glUniform1f(polymost1ShadeLoc, polymost1Shade);
|
||||
}
|
||||
|
||||
if (numshades != lastNumShades)
|
||||
{
|
||||
lastNumShades = numshades;
|
||||
polymost1NumShades = numshades;
|
||||
glUniform1f(polymost1NumShadesLoc, polymost1NumShades);
|
||||
}
|
||||
}
|
||||
|
||||
static void polymost_setVisibility(float visibility)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
float visFactor = visibility * fviewingrange * (1.f / (64.f * 65536.f));
|
||||
if (visFactor == polymost1VisFactor)
|
||||
return;
|
||||
|
||||
polymost1VisFactor = visFactor;
|
||||
glUniform1f(polymost1VisFactorLoc, polymost1VisFactor);
|
||||
}
|
||||
|
||||
void polymost_setFogEnabled(char fogEnabled)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1FogEnabled = fogEnabled;
|
||||
glUniform1f(polymost1FogEnabledLoc, polymost1FogEnabled);
|
||||
}
|
||||
|
||||
void polymost_useColorOnly(char useColorOnly)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1UseColorOnly = useColorOnly;
|
||||
glUniform1f(polymost1UseColorOnlyLoc, polymost1UseColorOnly);
|
||||
}
|
||||
|
||||
void polymost_usePaletteIndexing(char usePaletteIndexing)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1UsePalette = usePaletteIndexing;
|
||||
glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette);
|
||||
}
|
||||
|
||||
void polymost_useDetailMapping(char useDetailMapping)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID || useDetailMapping == polymost1UseDetailMapping)
|
||||
return;
|
||||
|
||||
polymost1UseDetailMapping = useDetailMapping;
|
||||
glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping);
|
||||
}
|
||||
|
||||
void polymost_useGlowMapping(char useGlowMapping)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID || useGlowMapping == polymost1UseGlowMapping)
|
||||
return;
|
||||
|
||||
polymost1UseGlowMapping = useGlowMapping;
|
||||
glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping);
|
||||
}
|
||||
|
||||
void polymost_npotEmulation(char npotEmulation, float factor, float xOffset)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID || npotEmulation == polymost1NPOTEmulation)
|
||||
return;
|
||||
|
||||
polymost1NPOTEmulation = npotEmulation;
|
||||
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
|
||||
polymost1NPOTEmulationFactor = factor;
|
||||
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
|
||||
polymost1NPOTEmulationXOffset = xOffset;
|
||||
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
|
||||
}
|
||||
|
||||
void polymost_shadeInterpolate(int32_t shadeInterpolate)
|
||||
{
|
||||
if (currentShaderProgramID == polymost1CurrentShaderProgramID)
|
||||
{
|
||||
polymost1ShadeInterpolate = shadeInterpolate;
|
||||
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
|
||||
}
|
||||
}
|
||||
|
||||
void polymost_setBrightness(int brightness){
|
||||
if (currentShaderProgramID == polymost1CurrentShaderProgramID)
|
||||
{
|
||||
polymost1Brightness = 8.f / (brightness+8.f);
|
||||
glUniform1f(polymost1BrightnessLoc, polymost1Brightness);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void polymost_bindPth(pthtyp const* const pPth, int sampler)
|
||||
{
|
||||
Bassert(pPth);
|
||||
|
||||
vec4f_t texturePosSize = { 0.f, 0.f, 1.f, 1.f };
|
||||
vec2f_t halfTexelSize = { 0.f, 0.f };
|
||||
polymost_setTexturePosSize(texturePosSize);
|
||||
polymost_setHalfTexelSize(halfTexelSize);
|
||||
GLInterface.BindTexture(0, pPth->glpic, sampler);
|
||||
}
|
||||
|
||||
|
||||
void useShaderProgram(uint32_t shaderID)
|
||||
{
|
||||
glUseProgram(shaderID);
|
||||
currentShaderProgramID = shaderID;
|
||||
}
|
||||
|
||||
FileReader GetBaseResource(const char* fn);
|
||||
|
@ -742,56 +385,6 @@ void polymost_glinit()
|
|||
currentTextureID = 0;
|
||||
char allPacked = false;
|
||||
|
||||
auto fr1 = GetBaseResource("demolition/shaders/glsl/polymost.vp");
|
||||
TArray<uint8_t> polymost1Vert = fr1.Read();
|
||||
fr1 = GetBaseResource("demolition/shaders/glsl/polymost.fp");
|
||||
TArray<uint8_t> polymost1Frag = fr1.Read();
|
||||
// Zero-terminate both strings.
|
||||
polymost1Vert.Push(0);
|
||||
polymost1Frag.Push(0);
|
||||
|
||||
polymost1ExtendedShaderProgramID = glCreateProgram();
|
||||
GLuint polymost1BasicVertexShaderID = polymost2_compileShader(GL_VERTEX_SHADER, (char*)polymost1Vert.Data());
|
||||
GLuint polymost1ExtendedFragmentShaderID = polymost2_compileShader(GL_FRAGMENT_SHADER, (char*)polymost1Frag.Data());
|
||||
glAttachShader(polymost1ExtendedShaderProgramID, polymost1BasicVertexShaderID);
|
||||
glAttachShader(polymost1ExtendedShaderProgramID, polymost1ExtendedFragmentShaderID);
|
||||
glLinkProgram(polymost1ExtendedShaderProgramID);
|
||||
|
||||
char buffer[10000];
|
||||
glGetShaderInfoLog(polymost1BasicVertexShaderID, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
initprintf("Vertex shader:\n%s\n", buffer);
|
||||
}
|
||||
glGetShaderInfoLog(polymost1ExtendedFragmentShaderID, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
initprintf("Fragment shader:\n%s\n", buffer);
|
||||
}
|
||||
|
||||
glGetProgramInfoLog(polymost1ExtendedShaderProgramID, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
initprintf("Linking:\n%s\n", buffer);
|
||||
}
|
||||
GLint status = 0;
|
||||
glGetProgramiv(polymost1ExtendedShaderProgramID, GL_LINK_STATUS, &status);
|
||||
auto linked = (status == GL_TRUE);
|
||||
if (!linked)
|
||||
{
|
||||
// only print message if there's an error.
|
||||
wm_msgbox("Fatal error", "Unable to init shader\n");
|
||||
exit(1);
|
||||
}
|
||||
// set defaults
|
||||
polymost_setCurrentShaderProgram(polymost1ExtendedShaderProgramID);
|
||||
glUniform1i(polymost1TexSamplerLoc, 0);
|
||||
glUniform1i(polymost1PalSwapSamplerLoc, 1);
|
||||
glUniform1i(polymost1PaletteSamplerLoc, 2);
|
||||
glUniform1i(polymost1DetailSamplerLoc, 3);
|
||||
glUniform1i(polymost1GlowSamplerLoc, 4);
|
||||
polymost_setPalswapSize(256, numshades+1);
|
||||
useShaderProgram(0);
|
||||
|
||||
lastbasepal = -1;
|
||||
for (int basepalnum = 0; basepalnum < MAXBASEPALS; ++basepalnum)
|
||||
|
@ -804,15 +397,6 @@ void polymost_glinit()
|
|||
{
|
||||
uploadpalswap(palookupnum);
|
||||
}
|
||||
|
||||
polymost_resetVertexPointers();
|
||||
|
||||
}
|
||||
|
||||
void polymost_init()
|
||||
{
|
||||
lastbasepal = -1;
|
||||
polymost_resetVertexPointers();
|
||||
}
|
||||
|
||||
////////// VISIBILITY FOG ROUTINES //////////
|
||||
|
@ -1060,7 +644,7 @@ static void resizeglcheck(void)
|
|||
VSMatrix identity(0);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &identity);
|
||||
|
||||
if (!nofog) polymost_setFogEnabled(true);
|
||||
if (!nofog) GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1133,11 +717,6 @@ void uploadtexture(FHardwareTexture *tex, int32_t doalloc, vec2_t siz, int32_t t
|
|||
|
||||
void uploadbasepalette(int32_t basepalnum)
|
||||
{
|
||||
if (!polymost1ExtendedShaderProgramID)
|
||||
{
|
||||
//POGO: if we haven't initialized properly yet, we shouldn't be uploading base palettes
|
||||
return;
|
||||
}
|
||||
if (!basepaltable[basepalnum])
|
||||
{
|
||||
return;
|
||||
|
@ -1165,11 +744,6 @@ void uploadbasepalette(int32_t basepalnum)
|
|||
|
||||
void uploadpalswap(int32_t palookupnum)
|
||||
{
|
||||
if (!polymost1ExtendedShaderProgramID)
|
||||
{
|
||||
//POGO: if we haven't initialized properly yet, we shouldn't be uploading palette swap tables
|
||||
return;
|
||||
}
|
||||
if (!palookup[palookupnum])
|
||||
{
|
||||
return;
|
||||
|
@ -1826,8 +1400,8 @@ static void polymost_updatePalette()
|
|||
return;
|
||||
}
|
||||
|
||||
polymost_setPalswap(globalpal);
|
||||
polymost_setShade(globalshade);
|
||||
GLInterface.SetPalswap(globalpal);
|
||||
GLInterface.SetShade(globalshade, numshades);
|
||||
|
||||
//POGO: only bind the base pal once when it's swapped
|
||||
if (curbasepal != lastbasepal)
|
||||
|
@ -1840,7 +1414,7 @@ static void polymost_updatePalette()
|
|||
|
||||
static void polymost_updaterotmat(void)
|
||||
{
|
||||
if (currentShaderProgramID == polymost1CurrentShaderProgramID)
|
||||
if (1)
|
||||
{
|
||||
float matrix[16] = {
|
||||
1.f, 0.f, 0.f, 0.f,
|
||||
|
@ -1866,23 +1440,16 @@ static void polymost_updaterotmat(void)
|
|||
multiplyMatrix4f(matrix, udmatrix);
|
||||
multiplyMatrix4f(matrix, tiltmatrix);
|
||||
#endif
|
||||
Bmemcpy(polymost1RotMatrix, matrix, sizeof(matrix));
|
||||
glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix);
|
||||
GLInterface.SetMatrix(Matrix_View, matrix);
|
||||
}
|
||||
}
|
||||
|
||||
static void polymost_identityrotmat(void)
|
||||
{
|
||||
if (currentShaderProgramID == polymost1CurrentShaderProgramID)
|
||||
if (1)
|
||||
{
|
||||
float matrix[16] = {
|
||||
1.f, 0.f, 0.f, 0.f,
|
||||
0.f, 1.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f,
|
||||
};
|
||||
Bmemcpy(polymost1RotMatrix, matrix, sizeof(matrix));
|
||||
glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix);
|
||||
VSMatrix matrix(0);
|
||||
GLInterface.SetMatrix(Matrix_View, &matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2022,7 +1589,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
|
||||
//POGOTODO: I could move this into bindPth
|
||||
if (!(pth->flags & PTH_INDEXED))
|
||||
polymost_usePaletteIndexing(false);
|
||||
GLInterface.UsePaletteIndexing(false);
|
||||
|
||||
// The entire logic here is just one lousy hack.
|
||||
int mSampler = NoSampler;
|
||||
|
@ -2065,7 +1632,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
(detailpth = texcache_fetch(globalpicnum, DETAILPAL, 0, method & ~DAMETH_MASKPROPS)) &&
|
||||
detailpth->hicr && detailpth->hicr->palnum == DETAILPAL)
|
||||
{
|
||||
polymost_useDetailMapping(true);
|
||||
GLInterface.UseDetailMapping(true);
|
||||
polymost_setupdetailtexture(3, detailpth->glpic);
|
||||
|
||||
texmat.loadIdentity();
|
||||
|
@ -2089,7 +1656,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
(glowpth = texcache_fetch(globalpicnum, GLOWPAL, 0, (method & ~DAMETH_MASKPROPS) | DAMETH_MASK)) &&
|
||||
glowpth->hicr && (glowpth->hicr->palnum == GLOWPAL))
|
||||
{
|
||||
polymost_useGlowMapping(true);
|
||||
GLInterface.UseGlowMapping(true);
|
||||
polymost_setupglowtexture(4, glowpth->glpic);
|
||||
}
|
||||
}
|
||||
|
@ -2100,16 +1667,16 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
int32_t size2;
|
||||
for (size2 = 1; size2 < size; size2 += size2) {}
|
||||
if (size == size2)
|
||||
polymost_npotEmulation(false, 1.f, 0.f);
|
||||
GLInterface.SetNpotEmulation(false, 1.f, 0.f);
|
||||
else
|
||||
{
|
||||
float xOffset = 1.f / tilesiz[globalpicnum].x;
|
||||
polymost_npotEmulation(true, (1.f*size2) / size, xOffset);
|
||||
GLInterface.SetNpotEmulation(true, (1.f*size2) / size, xOffset);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
polymost_npotEmulation(false, 1.f, 0.f);
|
||||
GLInterface.SetNpotEmulation(false, 1.f, 0.f);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2333,12 +1900,10 @@ do
|
|||
GLInterface.Draw(DT_TRIANGLE_FAN, data.first, npoints);
|
||||
}
|
||||
|
||||
#ifdef USE_GLEXT
|
||||
GLInterface.UseDetailMapping(false);
|
||||
GLInterface.UseGlowMapping(false);
|
||||
GLInterface.SetNpotEmulation(false, 1.f, 0.f);
|
||||
|
||||
polymost_useDetailMapping(false);
|
||||
polymost_useGlowMapping(false);
|
||||
polymost_npotEmulation(false, 1.f, 0.f);
|
||||
#endif
|
||||
if (pth->hicr)
|
||||
{
|
||||
VSMatrix identity(0);
|
||||
|
@ -2356,7 +1921,7 @@ do
|
|||
if (!(pth->flags & PTH_INDEXED))
|
||||
{
|
||||
// restore palette usage if we were just rendering a non-indexed color texture
|
||||
polymost_usePaletteIndexing(true);
|
||||
GLInterface.UsePaletteIndexing(true);
|
||||
}
|
||||
if (fullbright_pass == 1)
|
||||
{
|
||||
|
@ -2365,7 +1930,7 @@ do
|
|||
globalshade = -128;
|
||||
fullbright_pass = 2;
|
||||
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
|
||||
GLInterface.SetDepthFunc(Depth_Equal);
|
||||
|
||||
|
@ -2374,7 +1939,7 @@ do
|
|||
GLInterface.SetDepthFunc(Depth_LessEqual);
|
||||
|
||||
if (!nofog)
|
||||
polymost_setFogEnabled(true);
|
||||
GLInterface.SetFogEnabled(true);
|
||||
|
||||
globalshade = shade;
|
||||
fullbright_pass = 0;
|
||||
|
@ -3771,7 +3336,7 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
|
|||
int const npot = (1<<(picsiz[globalpicnum]&15)) != tilesiz[globalpicnum].x;
|
||||
int const xpanning = (r_parallaxskypanning?global_cf_xpanning:0);
|
||||
|
||||
polymost_setClamp((npot || xpanning != 0) ? 0 : 2);
|
||||
GLInterface.SetClamp((npot || xpanning != 0) ? 0 : 2);
|
||||
|
||||
int picnumbak = globalpicnum;
|
||||
ti = globalpicnum;
|
||||
|
@ -3906,7 +3471,7 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
|
|||
|
||||
globalpicnum = picnumbak;
|
||||
|
||||
polymost_setClamp(0);
|
||||
GLInterface.SetClamp(0);
|
||||
|
||||
flatskyrender = 1;
|
||||
}
|
||||
|
@ -4016,7 +3581,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
globvis2 = (sector[sectnum].visibility != 0) ?
|
||||
mulscale4(globalcisibility2, (uint8_t)(sector[sectnum].visibility + 16)) :
|
||||
globalcisibility2;
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
tileUpdatePicnum(&globalpicnum, sectnum);
|
||||
|
||||
|
@ -4054,7 +3619,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
if (sec->visibility != 0)
|
||||
globvis2 = mulscale4(globvis2, (uint8_t)(sec->visibility + 16));
|
||||
float viscale = xdimscale*fxdimen*(.0000001f/256.f);
|
||||
polymost_setVisibility(globvis2*viscale);
|
||||
GLInterface.SetVisibility(globvis2*viscale, fviewingrange);
|
||||
|
||||
//Use clamping for tiled sky textures
|
||||
//(don't wrap around edges if the sky use multiple panels)
|
||||
|
@ -4073,7 +3638,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
skyclamphack = 0;
|
||||
flatskyrender = 1;
|
||||
globalshade += globvis2*xdimscale*fviewingrange*(1.f / (64.f * 65536.f * 256.f * 1024.f));
|
||||
polymost_setVisibility(0.f);
|
||||
GLInterface.SetVisibility(0.f, fviewingrange);
|
||||
polymost_domost(x0,fy0,x1,fy1);
|
||||
flatskyrender = 0;
|
||||
}
|
||||
|
@ -4353,7 +3918,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
skyclamphack = 0;
|
||||
skyzbufferhack = 0;
|
||||
if (!nofog)
|
||||
polymost_setFogEnabled(true);
|
||||
GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
|
||||
// Ceiling
|
||||
|
@ -4373,7 +3938,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
globvis2 = (sector[sectnum].visibility != 0) ?
|
||||
mulscale4(globalcisibility2, (uint8_t)(sector[sectnum].visibility + 16)) :
|
||||
globalcisibility2;
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
tileUpdatePicnum(&globalpicnum, sectnum);
|
||||
|
||||
|
@ -4411,7 +3976,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
if (sec->visibility != 0)
|
||||
globvis2 = mulscale4(globvis2, (uint8_t)(sec->visibility + 16));
|
||||
float viscale = xdimscale*fxdimen*(.0000001f/256.f);
|
||||
polymost_setVisibility(globvis2*viscale);
|
||||
GLInterface.SetVisibility(globvis2*viscale, fviewingrange);
|
||||
|
||||
//Use clamping for tiled sky textures
|
||||
//(don't wrap around edges if the sky use multiple panels)
|
||||
|
@ -4430,7 +3995,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
skyclamphack = 0;
|
||||
flatskyrender = 1;
|
||||
globalshade += globvis2*xdimscale*fviewingrange*(1.f / (64.f * 65536.f * 256.f * 1024.f));
|
||||
polymost_setVisibility(0.f);
|
||||
GLInterface.SetVisibility(0.f, fviewingrange);
|
||||
polymost_domost(x1,cy1,x0,cy0);
|
||||
flatskyrender = 0;
|
||||
}
|
||||
|
@ -4713,7 +4278,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
skyclamphack = 0;
|
||||
skyzbufferhack = 0;
|
||||
if (!nofog)
|
||||
polymost_setFogEnabled(true);
|
||||
GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
|
||||
#ifdef YAX_ENABLE
|
||||
|
@ -4721,13 +4286,6 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
{
|
||||
int32_t baselevp, checkcf, i, j;
|
||||
int16_t bn[2];
|
||||
# if 0
|
||||
int32_t obunchchk = (1 && yax_globalbunch>=0 &&
|
||||
haveymost[yax_globalbunch>>3]&pow2char[yax_globalbunch&7]);
|
||||
|
||||
// if (obunchchk)
|
||||
const int32_t x2 = yax_globalbunch*xdimen;
|
||||
# endif
|
||||
baselevp = (yax_globallev == YAX_MAXDRAWS);
|
||||
|
||||
yax_getbunches(sectnum, &bn[0], &bn[1]);
|
||||
|
@ -4806,7 +4364,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
if (sector[sectnum].visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sector[sectnum].visibility+16));
|
||||
globvis2 = globalvisibility2;
|
||||
if (sector[sectnum].visibility != 0) globvis2 = mulscale4(globvis2, (uint8_t)(sector[sectnum].visibility+16));
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
globalorientation = wal->cstat;
|
||||
tileUpdatePicnum(&globalpicnum, wallnum+16384);
|
||||
|
||||
|
@ -4851,7 +4409,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
if (sector[sectnum].visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sector[sectnum].visibility+16));
|
||||
globvis2 = globalvisibility2;
|
||||
if (sector[sectnum].visibility != 0) globvis2 = mulscale4(globvis2, (uint8_t)(sector[sectnum].visibility+16));
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
globalorientation = nwal->cstat;
|
||||
tileUpdatePicnum(&globalpicnum, wallnum+16384);
|
||||
|
||||
|
@ -4904,7 +4462,7 @@ static void polymost_drawalls(int32_t const bunch)
|
|||
globvis2 = (sector[sectnum].visibility != 0) ?
|
||||
mulscale4(globalvisibility2, (uint8_t)(sector[sectnum].visibility + 16)) :
|
||||
globalvisibility2;
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
globalorientation = wal->cstat;
|
||||
tileUpdatePicnum(&globalpicnum, wallnum+16384);
|
||||
|
||||
|
@ -5239,7 +4797,7 @@ void polymost_drawrooms()
|
|||
GLInterface.EnableDepthTest(true);
|
||||
GLInterface.SetDepthFunc(Depth_Always);
|
||||
|
||||
polymost_setBrightness(r_brightnesshack);
|
||||
GLInterface.SetBrightness(r_brightnesshack);
|
||||
|
||||
gvrcorrection = viewingrange*(1.f/65536.f);
|
||||
if (glprojectionhacks == 2)
|
||||
|
@ -5270,7 +4828,7 @@ void polymost_drawrooms()
|
|||
|
||||
gvisibility = ((float)globalvisibility)*FOGSCALE;
|
||||
|
||||
polymost_shadeInterpolate(r_shadeinterpolate);
|
||||
GLInterface.SetShadeInterpolate(r_shadeinterpolate);
|
||||
|
||||
//global cos/sin height angle
|
||||
if (r_yshearing)
|
||||
|
@ -5514,7 +5072,7 @@ static void polymost_drawmaskwallinternal(int32_t wallIndex)
|
|||
|
||||
globvis2 = globalvisibility2;
|
||||
globvis2 = (sector[sectnum].visibility != 0) ? mulscale4(globvis2, (uint8_t)(sector[sectnum].visibility + 16)) : globalvisibility2;
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
globalshade = (int32_t)wal->shade;
|
||||
globalpal = (int32_t)((uint8_t)wal->pal);
|
||||
|
@ -5894,7 +5452,7 @@ void polymost_drawsprite(int32_t snum)
|
|||
globvis2 = globalvisibility2;
|
||||
if (sector[tspr->sectnum].visibility != 0)
|
||||
globvis2 = mulscale4(globvis2, (uint8_t)(sector[tspr->sectnum].visibility + 16));
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
vec2_t off = { 0, 0 };
|
||||
|
||||
|
@ -6308,7 +5866,7 @@ void polymost_drawsprite(int32_t snum)
|
|||
globvis2 = globalhisibility2;
|
||||
if (sector[tspr->sectnum].visibility != 0)
|
||||
globvis2 = mulscale4(globvis2, (uint8_t)(sector[tspr->sectnum].visibility + 16));
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
if ((globalorientation & 64) != 0 && (globalposz > tspr->z) == (!(globalorientation & 8)))
|
||||
goto _drawsprite_return;
|
||||
|
@ -6691,12 +6249,12 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a,
|
|||
spriteext[tspr.owner].alpha = daalpha * (1.0f / 255.0f);
|
||||
tspr.blend = dablend;
|
||||
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
polymost_mddraw(&tspr);
|
||||
|
||||
if (!nofog) polymost_setFogEnabled(true);
|
||||
if (!nofog) GLInterface.SetFogEnabled(true);
|
||||
|
||||
gvrcorrection = ogvrcorrection;
|
||||
viewingrange = oldviewingrange;
|
||||
|
@ -6730,8 +6288,8 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
|
|||
|
||||
globvis = 0;
|
||||
globvis2 = 0;
|
||||
polymost_setClamp(1+2);
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetClamp(1+2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
int32_t const ogpicnum = globalpicnum;
|
||||
globalpicnum = picnum;
|
||||
|
@ -6931,14 +6489,14 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16
|
|||
xtex.v = yv2*(1.0/65536.0);
|
||||
ytex.v = yv*(1.0/65536.0);
|
||||
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
pow2xsplit = 0; polymost_drawpoly(fpxy,n,method);
|
||||
if (!nofog) polymost_setFogEnabled(true);
|
||||
if (!nofog) GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
|
||||
GLInterface.EnableAlphaTest(false);
|
||||
GLInterface.EnableBlend(false);
|
||||
polymost_setClamp(0);
|
||||
GLInterface.SetClamp(0);
|
||||
|
||||
GLInterface.SetMatrix(Matrix_Projection, &oldproj);
|
||||
GLInterface.SetMatrix(Matrix_ModelView, &oldmv);
|
||||
|
@ -7130,7 +6688,7 @@ void polymost_fillpolygon(int32_t npoints)
|
|||
polymost_outputGLDebugMessage(3, "polymost_fillpolygon(npoints:%d)", npoints);
|
||||
|
||||
globvis2 = 0;
|
||||
polymost_setVisibility(globvis2);
|
||||
GLInterface.SetVisibility(globvis2, fviewingrange);
|
||||
|
||||
globalx1 = mulscale16(globalx1,xyaspect);
|
||||
globaly2 = mulscale16(globaly2,xyaspect);
|
||||
|
@ -7157,7 +6715,7 @@ void polymost_fillpolygon(int32_t npoints)
|
|||
polymost_bindPth(pth, -1);
|
||||
|
||||
if (!(pth->flags & PTH_INDEXED))
|
||||
polymost_usePaletteIndexing(false);
|
||||
GLInterface.UsePaletteIndexing(false);
|
||||
}
|
||||
|
||||
polymost_updatePalette();
|
||||
|
@ -7182,7 +6740,7 @@ void polymost_fillpolygon(int32_t npoints)
|
|||
if (pth && !(pth->flags & PTH_INDEXED))
|
||||
{
|
||||
// restore palette usage if we were just rendering a non-indexed color texture
|
||||
polymost_usePaletteIndexing(true);
|
||||
GLInterface.UsePaletteIndexing(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7241,6 +6799,17 @@ static int32_t gen_font_glyph_tex(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// These are used by the automap drawers
|
||||
void renderDisableFog(void)
|
||||
{
|
||||
GLInterface.SetFogEnabled(false);
|
||||
}
|
||||
|
||||
void renderEnableFog(void)
|
||||
{
|
||||
if (!nofog) GLInterface.SetFogEnabled(true);
|
||||
}
|
||||
|
||||
int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize)
|
||||
{
|
||||
int const arbackcol = (unsigned)backcol < 256 ? backcol : 0;
|
||||
|
@ -7261,9 +6830,8 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
|
|||
return -1;
|
||||
|
||||
GLInterface.BindTexture(0, polymosttext);
|
||||
polymost_setTexturePosSize({0, 0, 1, 1});
|
||||
|
||||
polymost_usePaletteIndexing(false);
|
||||
GLInterface.UsePaletteIndexing(false);
|
||||
|
||||
polymostSet2dView(); // disables blending, texturing, and depth testing
|
||||
|
||||
|
@ -7271,7 +6839,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
|
|||
GLInterface.SetDepthMask(false);
|
||||
|
||||
// XXX: Don't fogify the OSD text in Mapster32 with r_usenewshading >= 2.
|
||||
polymost_setFogEnabled(false);
|
||||
GLInterface.SetFogEnabled(false);
|
||||
// We want to have readable text in wireframe mode, too:
|
||||
GLInterface.SetWireframe(false);
|
||||
lastglpolygonmode = 0;
|
||||
|
@ -7360,9 +6928,9 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba
|
|||
|
||||
GLInterface.SetDepthMask(true);
|
||||
|
||||
if (!nofog) polymost_setFogEnabled(true);
|
||||
if (!nofog) GLInterface.SetFogEnabled(true);
|
||||
|
||||
polymost_usePaletteIndexing(true);
|
||||
GLInterface.UsePaletteIndexing(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1132,15 +1132,14 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
|
|||
#endif
|
||||
const float phack[2] = { 0, 1.f/256.f };
|
||||
|
||||
char prevClamp = polymost_getClamp();
|
||||
polymost_setClamp(0);
|
||||
int prevClamp = GLInterface.GetClamp();
|
||||
GLInterface.SetClamp(0);
|
||||
if (!m->texid[globalpal])
|
||||
m->texid[globalpal] = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, globalpal);
|
||||
|
||||
GLInterface.BindTexture(0, m->texid[globalpal]);
|
||||
|
||||
polymost_usePaletteIndexing(false);
|
||||
polymost_setTexturePosSize({ 0.f, 0.f, 1.f, 1.f });
|
||||
GLInterface.UsePaletteIndexing(false);
|
||||
|
||||
auto data = GLInterface.AllocVertices(m->qcnt * 4);
|
||||
auto vt = data.second;
|
||||
|
@ -1183,7 +1182,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
|
|||
}
|
||||
|
||||
GLInterface.Draw(DT_QUADS, qstart, qdone * 4);
|
||||
polymost_setClamp(prevClamp);
|
||||
GLInterface.SetClamp(prevClamp);
|
||||
//------------
|
||||
GLInterface.SetCull(Cull_None);
|
||||
|
||||
|
|
26
source/glbackend/gl_renderstate.h
Normal file
26
source/glbackend/gl_renderstate.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
class PolymostShader;
|
||||
|
||||
struct PolymostRenderState
|
||||
{
|
||||
int PalSwapIndex;
|
||||
//float PalswapPos[2];
|
||||
//float PalswapSize[2];
|
||||
float Clamp[2];
|
||||
float Shade;
|
||||
float NumShades = 64.f;
|
||||
float VisFactor = 128.f;
|
||||
float FogEnabled = 1.f;
|
||||
float UseColorOnly;
|
||||
float UsePalette = 1.f;
|
||||
float UseDetailMapping;
|
||||
float UseGlowMapping;
|
||||
float NPOTEmulation;
|
||||
float NPOTEmulationFactor = 1.f;
|
||||
float NPOTEmulationXOffset;
|
||||
float Brightness = 1.f;
|
||||
float ShadeInterpolate = 1.f;
|
||||
|
||||
void Apply(PolymostShader *shader);
|
||||
};
|
179
source/glbackend/gl_shader.cpp
Normal file
179
source/glbackend/gl_shader.cpp
Normal file
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
** gl_shader.cpp
|
||||
**
|
||||
** GLSL shader handling
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2004-2019 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
|
||||
** covered by the terms of the GNU Lesser General Public License as published
|
||||
** by the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
** your option) any later version.
|
||||
** 5. Full disclosure of the entire project's source code, except for third
|
||||
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
#include <memory>
|
||||
#include "glbackend.h"
|
||||
#include "glad/glad.h"
|
||||
#include "gl_shader.h"
|
||||
#include "zstring.h"
|
||||
|
||||
#include "baselayer.h"
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FShader::Load(const char * name, const char * vert_prog, const char * frag_prog)
|
||||
{
|
||||
FString error;
|
||||
static char buffer[10000];
|
||||
|
||||
hVertProg = glCreateShader(GL_VERTEX_SHADER);
|
||||
hFragProg = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
glShaderSource(hVertProg, 1, &vert_prog, nullptr);
|
||||
glShaderSource(hFragProg, 1, &frag_prog, nullptr);
|
||||
|
||||
glCompileShader(hVertProg);
|
||||
glCompileShader(hFragProg);
|
||||
|
||||
hShader = glCreateProgram();
|
||||
|
||||
glAttachShader(hShader, hVertProg);
|
||||
glAttachShader(hShader, hFragProg);
|
||||
|
||||
//glBindAttribLocation(hShader, VATTR_VERTEX, "aPosition");
|
||||
//glBindAttribLocation(hShader, VATTR_TEXCOORD, "aTexCoord");
|
||||
//glBindAttribLocation(hShader, VATTR_COLOR, "aColor");
|
||||
//glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2");
|
||||
|
||||
glLinkProgram(hShader);
|
||||
|
||||
glGetShaderInfoLog(hVertProg, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
error << "Vertex shader:\n" << buffer << "\n";
|
||||
}
|
||||
glGetShaderInfoLog(hFragProg, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
error << "Fragment shader:\n" << buffer << "\n";
|
||||
}
|
||||
|
||||
glGetProgramInfoLog(hShader, 10000, NULL, buffer);
|
||||
if (*buffer)
|
||||
{
|
||||
error << "Linking:\n" << buffer << "\n";
|
||||
}
|
||||
int linked;
|
||||
glGetProgramiv(hShader, GL_LINK_STATUS, &linked);
|
||||
if (linked == 0)
|
||||
{
|
||||
// only print message if there's an error.
|
||||
initprintf("Init Shader '%s':\n%s\n", name, error.GetChars());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FShader::~FShader()
|
||||
{
|
||||
glDeleteProgram(hShader);
|
||||
glDeleteShader(hVertProg);
|
||||
glDeleteShader(hFragProg);
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FShader::Bind()
|
||||
{
|
||||
glUseProgram(hShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool PolymostShader::Load(const char * name, const char * vert_prog, const char * frag_prog)
|
||||
{
|
||||
if (!FShader::Load(name, vert_prog, frag_prog)) return false;
|
||||
|
||||
PalswapPos.Init(hShader, "u_palswapPos");
|
||||
PalswapSize.Init(hShader, "u_palswapSize");
|
||||
Clamp.Init(hShader, "u_clamp");
|
||||
Shade.Init(hShader, "u_shade");
|
||||
NumShades.Init(hShader, "u_numShades");
|
||||
VisFactor.Init(hShader, "u_visFactor");
|
||||
FogEnabled.Init(hShader, "u_fogEnabled");
|
||||
UseColorOnly.Init(hShader, "u_useColorOnly");
|
||||
UsePalette.Init(hShader, "u_usePalette");
|
||||
UseDetailMapping.Init(hShader, "u_useDetailMapping");
|
||||
UseGlowMapping.Init(hShader, "u_useGlowMapping");
|
||||
NPOTEmulation.Init(hShader, "u_npotEmulation");
|
||||
NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor");
|
||||
NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset");
|
||||
Brightness.Init(hShader, "u_brightness");
|
||||
RotMatrix.Init(hShader, "u_rotMatrix");
|
||||
ShadeInterpolate.Init(hShader, "u_shadeInterpolate");
|
||||
|
||||
glUseProgram(hShader);
|
||||
|
||||
int SamplerLoc;
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_texture");
|
||||
glUniform1i(SamplerLoc, 0);
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_palswap");
|
||||
glUniform1i(SamplerLoc, 1);
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_palette");
|
||||
glUniform1i(SamplerLoc, 2);
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_detail");
|
||||
glUniform1i(SamplerLoc, 3);
|
||||
SamplerLoc = glGetUniformLocation(hShader, "s_glow");
|
||||
glUniform1i(SamplerLoc, 4);
|
||||
|
||||
glUseProgram(0);
|
||||
return true;
|
||||
}
|
60
source/glbackend/gl_shader.h
Normal file
60
source/glbackend/gl_shader.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#pragma once;
|
||||
|
||||
#include "gl_uniform.h"
|
||||
|
||||
class FShader
|
||||
{
|
||||
friend class FShaderManager;
|
||||
friend class FRenderState;
|
||||
|
||||
unsigned int hVertProg = 0;
|
||||
unsigned int hFragProg = 0;
|
||||
|
||||
protected:
|
||||
unsigned int hShader = 0;
|
||||
|
||||
#if 0
|
||||
FName mName;
|
||||
int projectionmatrix_index;
|
||||
int viewmatrix_index;
|
||||
int modelmatrix_index;
|
||||
int texturematrix_index;
|
||||
bool currentTextureMatrixState = false;
|
||||
bool currentModelMatrixState = false;
|
||||
#endif
|
||||
|
||||
public:
|
||||
FShader() = default;
|
||||
virtual ~FShader();
|
||||
|
||||
virtual bool Load(const char * name, const char * vert_prog_lump, const char * fragprog); //, const char * fragprog2, const char *defines);
|
||||
bool Bind();
|
||||
unsigned int GetHandle() const { return hShader; }
|
||||
};
|
||||
|
||||
class PolymostShader : public FShader
|
||||
{
|
||||
public:
|
||||
FBufferedUniform2f PalswapPos;
|
||||
FBufferedUniform2f PalswapSize;
|
||||
FBufferedUniform2f Clamp;
|
||||
FBufferedUniform1f Shade;
|
||||
FBufferedUniform1f NumShades;
|
||||
FBufferedUniform1f VisFactor;
|
||||
FBufferedUniform1f FogEnabled;
|
||||
FBufferedUniform1f UseColorOnly;
|
||||
FBufferedUniform1f UsePalette;
|
||||
FBufferedUniform1f UseDetailMapping;
|
||||
FBufferedUniform1f UseGlowMapping;
|
||||
FBufferedUniform1f NPOTEmulation;
|
||||
FBufferedUniform1f NPOTEmulationFactor;
|
||||
FBufferedUniform1f NPOTEmulationXOffset;
|
||||
FBufferedUniform1f Brightness;
|
||||
FUniformMatrix4f RotMatrix;
|
||||
FBufferedUniform1f ShadeInterpolate;
|
||||
|
||||
public:
|
||||
|
||||
PolymostShader() = default;
|
||||
virtual bool Load(const char * name, const char * vert_prog_lump, const char * fragprog); //, const char * fragprog2, const char *defines);
|
||||
};
|
94
source/glbackend/gl_uniform.h
Normal file
94
source/glbackend/gl_uniform.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
#pragma once
|
||||
|
||||
class FBufferedUniform1f
|
||||
{
|
||||
float mBuffer;
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
void Init(GLuint hShader, const GLchar *name)
|
||||
{
|
||||
mIndex = glGetUniformLocation(hShader, name);
|
||||
mBuffer = 0;
|
||||
}
|
||||
|
||||
void Set(float newvalue)
|
||||
{
|
||||
if (newvalue != mBuffer)
|
||||
{
|
||||
mBuffer = newvalue;
|
||||
glUniform1f(mIndex, newvalue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FBufferedUniform2f
|
||||
{
|
||||
float mBuffer[2];
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
void Init(GLuint hShader, const GLchar *name)
|
||||
{
|
||||
mIndex = glGetUniformLocation(hShader, name);
|
||||
memset(mBuffer, 0, sizeof(mBuffer));
|
||||
}
|
||||
|
||||
void Set(const float *newvalue)
|
||||
{
|
||||
if (memcmp(newvalue, mBuffer, sizeof(mBuffer)))
|
||||
{
|
||||
memcpy(mBuffer, newvalue, sizeof(mBuffer));
|
||||
glUniform2fv(mIndex, 1, newvalue);
|
||||
}
|
||||
}
|
||||
|
||||
void Set(float f1, float f2)
|
||||
{
|
||||
if (mBuffer[0] != f1 || mBuffer[1] != f2)
|
||||
{
|
||||
mBuffer[0] = f1;
|
||||
mBuffer[1] = f2;
|
||||
glUniform2fv(mIndex, 1, mBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class FBufferedUniform4f
|
||||
{
|
||||
float mBuffer[4];
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
void Init(GLuint hShader, const GLchar *name)
|
||||
{
|
||||
mIndex = glGetUniformLocation(hShader, name);
|
||||
memset(mBuffer, 0, sizeof(mBuffer));
|
||||
}
|
||||
|
||||
void Set(const float *newvalue)
|
||||
{
|
||||
if (memcmp(newvalue, mBuffer, sizeof(mBuffer)))
|
||||
{
|
||||
memcpy(mBuffer, newvalue, sizeof(mBuffer));
|
||||
glUniform4fv(mIndex, 1, newvalue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FUniformMatrix4f
|
||||
{
|
||||
int mIndex;
|
||||
|
||||
public:
|
||||
void Init(GLuint hShader, const GLchar *name)
|
||||
{
|
||||
mIndex = glGetUniformLocation(hShader, name);
|
||||
}
|
||||
|
||||
void Set(const float *newvalue)
|
||||
{
|
||||
glUniformMatrix4fv(mIndex, 1, false, newvalue);
|
||||
}
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
#include "glbackend.h"
|
||||
#include "glad/glad.h"
|
||||
#include "gl_samplers.h"
|
||||
#include "gl_shader.h"
|
||||
|
||||
#include "baselayer.h"
|
||||
#include "resourcefile.h"
|
||||
|
@ -60,9 +61,29 @@ void GLInstance::Init()
|
|||
osdcmd_glinfo(NULL);
|
||||
glinfo.dumped = 1;
|
||||
}
|
||||
new(&renderState) PolymostRenderState; // reset to defaults.
|
||||
LoadPolymostShader();
|
||||
|
||||
}
|
||||
|
||||
void GLInstance::LoadPolymostShader()
|
||||
{
|
||||
auto fr1 = GetBaseResource("demolition/shaders/glsl/polymost.vp");
|
||||
TArray<uint8_t> polymost1Vert = fr1.Read();
|
||||
fr1 = GetBaseResource("demolition/shaders/glsl/polymost.fp");
|
||||
TArray<uint8_t> polymost1Frag = fr1.Read();
|
||||
// Zero-terminate both strings.
|
||||
polymost1Vert.Push(0);
|
||||
polymost1Frag.Push(0);
|
||||
polymostShader = new PolymostShader();
|
||||
if (!polymostShader->Load("PolymostShader", (const char*)polymost1Vert.Data(), (const char*)polymost1Frag.Data()))
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
SetPolymostShader();
|
||||
}
|
||||
|
||||
|
||||
void GLInstance::InitGLState(int fogmode, int multisample)
|
||||
{
|
||||
glShadeModel(GL_SMOOTH); // GL_FLAT
|
||||
|
@ -89,6 +110,10 @@ void GLInstance::Deinit()
|
|||
{
|
||||
if (mSamplers) delete mSamplers;
|
||||
mSamplers = nullptr;
|
||||
if (polymostShader) delete polymostShader;
|
||||
polymostShader = nullptr;
|
||||
|
||||
activeShader = nullptr;
|
||||
}
|
||||
|
||||
std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num)
|
||||
|
@ -108,6 +133,7 @@ static GLint primtypes[] =
|
|||
|
||||
void GLInstance::Draw(EDrawType type, size_t start, size_t count)
|
||||
{
|
||||
if (activeShader == polymostShader) renderState.Apply(polymostShader);
|
||||
glBegin(primtypes[type]);
|
||||
auto p = &Buffer[start];
|
||||
for (size_t i = 0; i < count; i++, p++)
|
||||
|
@ -188,22 +214,30 @@ void GLInstance::SetMatrix(int num, const VSMatrix *mat)
|
|||
matrices[num] = *mat;
|
||||
switch(num)
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case Matrix_View:
|
||||
polymostShader->RotMatrix.Set(mat->get());
|
||||
break;
|
||||
|
||||
case Matrix_Projection:
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(mat->get());
|
||||
break;
|
||||
|
||||
case Matrix_ModelView:
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(mat->get());
|
||||
break;
|
||||
|
||||
default:
|
||||
glActiveTexture(GL_TEXTURE0 + num - Matrix_Texture0);
|
||||
case Matrix_Texture3:
|
||||
case Matrix_Texture4:
|
||||
glActiveTexture(GL_TEXTURE3 + num - Matrix_Texture3);
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadMatrixf(mat->get());
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
break;
|
||||
}
|
||||
glLoadMatrixf(mat->get());
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
if (num > Matrix_Texture0) glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void GLInstance::EnableStencilWrite(int value)
|
||||
|
@ -326,3 +360,68 @@ void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer)
|
|||
{
|
||||
glReadPixels(0, 0, xdim, ydim, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
}
|
||||
|
||||
void GLInstance::SetPolymostShader()
|
||||
{
|
||||
if (activeShader != polymostShader)
|
||||
{
|
||||
polymostShader->Bind();
|
||||
activeShader = polymostShader;
|
||||
}
|
||||
//GLInterface.BindTexture(1, palswapTextureID);
|
||||
//GLInterface.BindTexture(2, paletteTextureIDs[curbasepal]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PolymostRenderState::Apply(PolymostShader* shader)
|
||||
{
|
||||
shader->Clamp.Set(Clamp);
|
||||
shader->Shade.Set(Shade);
|
||||
shader->NumShades.Set(NumShades);
|
||||
shader->VisFactor.Set(VisFactor);
|
||||
shader->FogEnabled.Set(FogEnabled);
|
||||
shader->UseColorOnly.Set(UseColorOnly);
|
||||
shader->UsePalette.Set(UsePalette);
|
||||
shader->UseDetailMapping.Set(UseDetailMapping);
|
||||
shader->UseGlowMapping.Set(UseGlowMapping);
|
||||
shader->NPOTEmulation.Set(NPOTEmulation);
|
||||
shader->NPOTEmulationFactor.Set(NPOTEmulationFactor);
|
||||
shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset);
|
||||
shader->ShadeInterpolate.Set(ShadeInterpolate);
|
||||
shader->Brightness.Set(Brightness);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void polymost_setPalswap(uint32_t index)
|
||||
{
|
||||
static uint32_t lastPalswapIndex;
|
||||
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
lastPalswapIndex = index;
|
||||
polymost1PalswapPos.x = index * polymost1PalswapSize.x;
|
||||
polymost1PalswapPos.y = floorf(polymost1PalswapPos.x);
|
||||
polymost1PalswapPos = { polymost1PalswapPos.x - polymost1PalswapPos.y + (0.5f / PALSWAP_TEXTURE_SIZE),
|
||||
polymost1PalswapPos.y * polymost1PalswapSize.y + (0.5f / PALSWAP_TEXTURE_SIZE) };
|
||||
glUniform2f(polymost1PalswapPosLoc, polymost1PalswapPos.x, polymost1PalswapPos.y);
|
||||
}
|
||||
|
||||
static void polymost_setPalswapSize(uint32_t width, uint32_t height)
|
||||
{
|
||||
if (currentShaderProgramID != polymost1CurrentShaderProgramID)
|
||||
return;
|
||||
|
||||
polymost1PalswapSize = { width * (1.f / PALSWAP_TEXTURE_SIZE),
|
||||
height * (1.f / PALSWAP_TEXTURE_SIZE) };
|
||||
|
||||
polymost1PalswapInnerSize = { (width - 1) * (1.f / PALSWAP_TEXTURE_SIZE),
|
||||
(height - 1) * (1.f / PALSWAP_TEXTURE_SIZE) };
|
||||
|
||||
glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -5,9 +5,12 @@
|
|||
#include <map>
|
||||
#include "gl_samplers.h"
|
||||
#include "gl_hwtexture.h"
|
||||
#include "gl_renderstate.h"
|
||||
#include "matrix.h"
|
||||
|
||||
class FSamplerManager;
|
||||
class FShader;
|
||||
class PolymostShader;
|
||||
|
||||
struct glinfo_t {
|
||||
const char* vendor;
|
||||
|
@ -59,16 +62,12 @@ enum EDrawType
|
|||
|
||||
enum EMatrixType
|
||||
{
|
||||
Matrix_View,
|
||||
Matrix_Projection,
|
||||
Matrix_ModelView,
|
||||
Matrix_Texture0,
|
||||
Matrix_Texture1,
|
||||
Matrix_Texture2,
|
||||
Matrix_Texture3,
|
||||
Matrix_Texture4,
|
||||
Matrix_Texture5,
|
||||
Matrix_Texture6,
|
||||
Matrix_Texture7,
|
||||
// These are the only ones being used.
|
||||
NUMMATRICES
|
||||
};
|
||||
|
||||
|
@ -128,6 +127,9 @@ class GLInstance
|
|||
int maxTextureSize;
|
||||
|
||||
VSMatrix matrices[NUMMATRICES];
|
||||
PolymostRenderState renderState;
|
||||
FShader* activeShader;
|
||||
PolymostShader* polymostShader;
|
||||
|
||||
|
||||
public:
|
||||
|
@ -136,6 +138,7 @@ public:
|
|||
|
||||
void Init();
|
||||
void InitGLState(int fogmode, int multisample);
|
||||
void LoadPolymostShader();
|
||||
|
||||
void Deinit();
|
||||
|
||||
|
@ -188,8 +191,79 @@ public:
|
|||
void SetViewport(int x, int y, int w, int h);
|
||||
void SetAlphaThreshold(float al);
|
||||
void SetWireframe(bool on);
|
||||
void SetPolymostShader();
|
||||
|
||||
void ReadPixels(int w, int h, uint8_t* buffer);
|
||||
|
||||
|
||||
void SetPalswap(uint32_t index)
|
||||
{
|
||||
renderState.PalSwapIndex = index;
|
||||
}
|
||||
|
||||
int GetClamp()
|
||||
{
|
||||
return int(renderState.Clamp[0] + 2*renderState.Clamp[1]);
|
||||
}
|
||||
|
||||
void SetClamp(int clamp)
|
||||
{
|
||||
renderState.Clamp[0] = clamp & 1;
|
||||
renderState.Clamp[1] = !!(clamp & 2);
|
||||
}
|
||||
|
||||
void SetShade(int32_t shade, int numshades)
|
||||
{
|
||||
renderState.Shade = shade;
|
||||
renderState.NumShades = numshades;
|
||||
}
|
||||
|
||||
void SetVisibility(float visibility, float fviewingrange)
|
||||
{
|
||||
renderState.VisFactor = visibility * fviewingrange * (1.f / (64.f * 65536.f));
|
||||
}
|
||||
|
||||
void SetFogEnabled(bool fogEnabled)
|
||||
{
|
||||
renderState.FogEnabled = fogEnabled;
|
||||
}
|
||||
|
||||
void UseColorOnly(bool useColorOnly)
|
||||
{
|
||||
renderState.UseColorOnly = useColorOnly;
|
||||
}
|
||||
|
||||
void UsePaletteIndexing(bool usePaletteIndexing)
|
||||
{
|
||||
renderState.UsePalette = usePaletteIndexing;
|
||||
}
|
||||
|
||||
void UseDetailMapping(bool useDetailMapping)
|
||||
{
|
||||
renderState.UseDetailMapping = useDetailMapping;
|
||||
}
|
||||
|
||||
void UseGlowMapping(bool useGlowMapping)
|
||||
{
|
||||
renderState.UseGlowMapping = useGlowMapping;
|
||||
}
|
||||
|
||||
void SetNpotEmulation(bool npotEmulation, float factor, float xOffset)
|
||||
{
|
||||
renderState.NPOTEmulation = npotEmulation;
|
||||
renderState.NPOTEmulationFactor = factor;
|
||||
renderState.NPOTEmulationXOffset = xOffset;
|
||||
}
|
||||
|
||||
void SetShadeInterpolate(int32_t shadeInterpolate)
|
||||
{
|
||||
renderState.ShadeInterpolate = shadeInterpolate;
|
||||
}
|
||||
|
||||
void SetBrightness(int brightness)
|
||||
{
|
||||
renderState.Brightness = 8.f / (brightness + 8.f);
|
||||
}
|
||||
};
|
||||
|
||||
extern GLInstance GLInterface;
|
||||
|
|
Loading…
Reference in a new issue