Skip to content

renderer: implement ivec_t and the ability to send integer vectors to GLSL #1040

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/engine/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ void Com_Free_Aligned( void *ptr );

using vec_t = float;
using vec2_t = vec_t[2];

using vec3_t = vec_t[3];
using vec4_t = vec_t[4];

Expand All @@ -236,6 +235,11 @@ void Com_Free_Aligned( void *ptr );
using matrix_t = vec_t[4 * 4];
using quat_t = vec_t[4];

using ivec_t = int;
using ivec2_t = ivec_t[2];
using ivec3_t = ivec_t[3];
using ivec4_t = ivec_t[4];

// A transform_t represents a product of basic
// transformations, which are a rotation about an arbitrary
// axis, a uniform scale or a translation. Any a product can
Expand Down
121 changes: 121 additions & 0 deletions src/engine/renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,127 @@ class GLUniform1i : protected GLUniform
}
};

class GLUniform2i : protected GLUniform
{
protected:
GLUniform2i( GLShader *shader, const char *name ) :
GLUniform( shader, name )
{
}

inline void SetValue( const ivec2_t v )
{
shaderProgram_t *p = _shader->GetProgram();

ASSERT_EQ(p, glState.currentProgram);

#if defined( LOG_GLSL_UNIFORMS )
if ( r_logFile->integer )
{
GLimp_LogComment( va( "GLSL_SetUniform2i( %s, shader: %s, value: [ %d, %d ] ) ---\n",
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ] ) );
}
#endif
#if defined( USE_UNIFORM_FIREWALL )
ivec2_t *firewall = ( ivec2_t * ) &p->uniformFirewall[ _firewallIndex ];

if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
{
return;
}

( *firewall )[ 0 ] = v[ 0 ];
( *firewall )[ 1 ] = v[ 1 ];
#endif
glUniform2i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ] );
}

size_t GetSize() override
{
return sizeof( ivec2_t );
}
};

class GLUniform3i : protected GLUniform
{
protected:
GLUniform3i( GLShader *shader, const char *name ) :
GLUniform( shader, name )
{
}

inline void SetValue( const ivec3_t v )
{
shaderProgram_t *p = _shader->GetProgram();

ASSERT_EQ(p, glState.currentProgram);

#if defined( LOG_GLSL_UNIFORMS )
if ( r_logFile->integer )
{
GLimp_LogComment( va( "GLSL_SetUniform3i( %s, shader: %s, value: [ %d, %d, %d ] ) ---\n",
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ] ) );
}
#endif
#if defined( USE_UNIFORM_FIREWALL )
ivec3_t *firewall = ( ivec3_t * ) &p->uniformFirewall[ _firewallIndex ];

if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
{
return;
}

VectorCopy( v, *firewall );
#endif
glUniform3i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ], v[ 2 ] );
}
public:
size_t GetSize() override
{
return sizeof( ivec3_t );
}
};

class GLUniform4i : protected GLUniform
{
protected:
GLUniform4i( GLShader *shader, const char *name ) :
GLUniform( shader, name )
{
}

inline void SetValue( const ivec4_t v )
{
shaderProgram_t *p = _shader->GetProgram();

ASSERT_EQ(p, glState.currentProgram);

#if defined( LOG_GLSL_UNIFORMS )
if ( r_logFile->integer )
{
GLimp_LogComment( va( "GLSL_SetUniform4i( %s, shader: %s, value: [ %d, %d, %d, %d ] ) ---\n",
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] ) );
}
#endif
#if defined( USE_UNIFORM_FIREWALL )
ivec4_t *firewall = ( ivec4_t * ) &p->uniformFirewall[ _firewallIndex ];

if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
{
return;
}

Vector4Copy( v, *firewall );
#endif
glUniform4i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] );
}
public:
size_t GetSize() override
{
return sizeof( ivec4_t );
}
};

class GLUniform1f : protected GLUniform
{
protected:
Expand Down