Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge generic2D shader into generic #1483

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/engine/renderer/gl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ ShaderKind shaderKind = ShaderKind::Unknown;

// *INDENT-OFF*

GLShader_generic2D *gl_generic2DShader = nullptr;
GLShader_generic *gl_genericShader = nullptr;
GLShader_genericMaterial *gl_genericShaderMaterial = nullptr;
GLShader_cull *gl_cullShader = nullptr;
Expand Down Expand Up @@ -2172,31 +2171,6 @@ void GLShader::WriteUniformsToBuffer( uint32_t* buffer ) {
}
}

GLShader_generic2D::GLShader_generic2D( GLShaderManager *manager ) :
GLShader( "generic2D", "generic", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_ColorMap( this ),
u_DepthMap( this ),
u_TextureMatrix( this ),
u_AlphaThreshold( this ),
u_ModelMatrix( this ),
u_ModelViewProjectionMatrix( this ),
u_ColorModulate( this ),
u_Color( this ),
u_DepthScale( this ),
GLDeformStage( this )
{
}

void GLShader_generic2D::BuildShaderCompileMacros( std::string& compileMacros )
{
compileMacros += "GENERIC_2D ";
}

void GLShader_generic2D::SetShaderProgramUniforms( shaderProgram_t *shaderProgram )
{
glUniform1i( glGetUniformLocation( shaderProgram->program, "u_ColorMap" ), 0 );
}

GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
GLShader( "generic", ATTR_POSITION | ATTR_TEXCOORD | ATTR_QTANGENT, manager ),
u_ColorMap( this ),
Expand All @@ -2219,7 +2193,8 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
GLCompileMacro_USE_DEPTH_FADE( this )
GLCompileMacro_USE_DEPTH_FADE( this ),
GLCompileMacro_GENERIC_2D( this )
{
}

Expand Down
47 changes: 23 additions & 24 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@ class GLCompileMacro
USE_SHADOWING,
LIGHT_DIRECTIONAL,
USE_DEPTH_FADE,
GENERIC_2D,
USE_PHYSICAL_MAPPING,
};

Expand Down Expand Up @@ -2110,6 +2111,26 @@ class GLCompileMacro_USE_DEPTH_FADE :
}
};

class GLCompileMacro_GENERIC_2D :
GLCompileMacro {
public:
GLCompileMacro_GENERIC_2D( GLShader* shader ) :
GLCompileMacro( shader ) {
}

const char* GetName() const override {
return "GENERIC_2D";
}

EGLCompileMacro GetType() const override {
return EGLCompileMacro::GENERIC_2D;
}

void SetGeneric2D( bool enable ) {
SetMacro( enable );
}
};

class GLCompileMacro_USE_PHYSICAL_MAPPING :
GLCompileMacro
{
Expand Down Expand Up @@ -3918,28 +3939,6 @@ class u_Lights :
}
};

// FIXME: this is the same as 'generic' and has no reason for existing.
// It was added along with RmlUi transforms to add "gl_FragDepth = 0;" to the GLSL,
// but that turns out not to be needed.
class GLShader_generic2D :
public GLShader,
public u_ColorMap,
public u_DepthMap,
public u_TextureMatrix,
public u_AlphaThreshold,
public u_ModelMatrix,
public u_ModelViewProjectionMatrix,
public u_ColorModulate,
public u_Color,
public u_DepthScale,
public GLDeformStage
{
public:
GLShader_generic2D( GLShaderManager *manager );
void BuildShaderCompileMacros( std::string& compileMacros ) override;
void SetShaderProgramUniforms( shaderProgram_t *shaderProgram ) override;
};

class GLShader_generic :
public GLShader,
public u_ColorMap,
Expand All @@ -3962,7 +3961,8 @@ class GLShader_generic :
public GLCompileMacro_USE_VERTEX_ANIMATION,
public GLCompileMacro_USE_TCGEN_ENVIRONMENT,
public GLCompileMacro_USE_TCGEN_LIGHTMAP,
public GLCompileMacro_USE_DEPTH_FADE
public GLCompileMacro_USE_DEPTH_FADE,
public GLCompileMacro_GENERIC_2D
{
public:
GLShader_generic( GLShaderManager *manager );
Expand Down Expand Up @@ -4714,7 +4714,6 @@ std::string GetShaderPath();

extern ShaderKind shaderKind;

extern GLShader_generic2D *gl_generic2DShader;
extern GLShader_generic *gl_genericShader;
extern GLShader_genericMaterial *gl_genericShaderMaterial;
extern GLShader_cull *gl_cullShader;
Expand Down
50 changes: 7 additions & 43 deletions src/engine/renderer/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ static void GLSL_InitGPUShadersOrError()
gl_shaderManager.GenerateBuiltinHeaders();

// single texture rendering
gl_shaderManager.load( gl_generic2DShader );
gl_shaderManager.load( gl_genericShader );

// standard light mapping
Expand Down Expand Up @@ -469,7 +468,6 @@ void GLSL_ShutdownGPUShaders()

gl_shaderManager.freeAll();

gl_generic2DShader = nullptr;
gl_genericShader = nullptr;
gl_genericShaderMaterial = nullptr;
gl_cullShader = nullptr;
Expand Down Expand Up @@ -816,46 +814,6 @@ void Render_NOP( shaderStage_t * )
{
}

static void Render_generic2D( shaderStage_t *pStage )
{
GLimp_LogComment( "--- Render_generic2D ---\n" );

// Disable depth testing and writing
GL_State( ( pStage->stateBits & ~GLS_DEPTHMASK_TRUE ) | GLS_DEPTHTEST_DISABLE );

gl_generic2DShader->BindProgram( pStage->deformIndex );

// set uniforms
// u_AlphaThreshold
gl_generic2DShader->SetUniform_AlphaTest( pStage->stateBits );

// u_ColorModulate
colorGen_t rgbGen = SetRgbGen( pStage );
alphaGen_t alphaGen = SetAlphaGen( pStage );

gl_generic2DShader->SetUniform_ColorModulate( rgbGen, alphaGen );

// u_Color
gl_generic2DShader->SetUniform_Color( tess.svars.color );

gl_generic2DShader->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
gl_generic2DShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] );

// u_DeformGen
gl_generic2DShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime );

// bind u_ColorMap
gl_generic2DShader->SetUniform_ColorMapBindless( BindAnimatedImage( 0, &pStage->bundle[TB_COLORMAP] ) );
gl_generic2DShader->SetUniform_TextureMatrix( tess.svars.texMatrices[ TB_COLORMAP ] );

gl_generic2DShader->SetRequiredVertexPointers();

Tess_DrawElements();
GL_CheckErrors();

GL_CheckErrors();
}

void Render_generic3D( shaderStage_t *pStage )
{
GLimp_LogComment( "--- Render_generic3D ---\n" );
Expand Down Expand Up @@ -970,7 +928,13 @@ void Render_generic( shaderStage_t *pStage )
{
if ( backEnd.projection2D )
{
Render_generic2D( pStage );
glState.glStateBitsMask = ~uint32_t( GLS_DEPTHMASK_TRUE ) | GLS_DEPTHTEST_DISABLE;
gl_genericShader->SetGeneric2D( true );

Render_generic3D( pStage );

glState.glStateBitsMask = 0;
gl_genericShader->SetGeneric2D( false );
return;
}

Expand Down
Loading