Skip to content

Commit affbe51

Browse files
committed
renderer: implement ivec_t
1 parent b18a6ea commit affbe51

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

src/engine/qcommon/q_shared.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ void Com_Free_Aligned( void *ptr );
227227

228228
using vec_t = float;
229229
using vec2_t = vec_t[2];
230-
231230
using vec3_t = vec_t[3];
232231
using vec4_t = vec_t[4];
233232

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

238+
using ivec_t = int;
239+
using ivec2_t = ivec_t[2];
240+
using ivec3_t = ivec_t[3];
241+
using ivec4_t = ivec_t[4];
242+
239243
// A transform_t represents a product of basic
240244
// transformations, which are a rotation about an arbitrary
241245
// axis, a uniform scale or a translation. Any a product can

src/engine/renderer/gl_shader.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,127 @@ class GLUniform1i : protected GLUniform
418418
}
419419
};
420420

421+
class GLUniform2i : protected GLUniform
422+
{
423+
protected:
424+
GLUniform2i( GLShader *shader, const char *name ) :
425+
GLUniform( shader, name )
426+
{
427+
}
428+
429+
inline void SetValue( const ivec2_t v )
430+
{
431+
shaderProgram_t *p = _shader->GetProgram();
432+
433+
ASSERT_EQ(p, glState.currentProgram);
434+
435+
#if defined( LOG_GLSL_UNIFORMS )
436+
if ( r_logFile->integer )
437+
{
438+
GLimp_LogComment( va( "GLSL_SetUniform2i( %s, shader: %s, value: [ %d, %d ] ) ---\n",
439+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ] ) );
440+
}
441+
#endif
442+
#if defined( USE_UNIFORM_FIREWALL )
443+
ivec2_t *firewall = ( ivec2_t * ) &p->uniformFirewall[ _firewallIndex ];
444+
445+
if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
446+
{
447+
return;
448+
}
449+
450+
( *firewall )[ 0 ] = v[ 0 ];
451+
( *firewall )[ 1 ] = v[ 1 ];
452+
#endif
453+
glUniform2i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ] );
454+
}
455+
456+
size_t GetSize() override
457+
{
458+
return sizeof( ivec2_t );
459+
}
460+
};
461+
462+
class GLUniform3i : protected GLUniform
463+
{
464+
protected:
465+
GLUniform3i( GLShader *shader, const char *name ) :
466+
GLUniform( shader, name )
467+
{
468+
}
469+
470+
inline void SetValue( const ivec3_t v )
471+
{
472+
shaderProgram_t *p = _shader->GetProgram();
473+
474+
ASSERT_EQ(p, glState.currentProgram);
475+
476+
#if defined( LOG_GLSL_UNIFORMS )
477+
if ( r_logFile->integer )
478+
{
479+
GLimp_LogComment( va( "GLSL_SetUniform3i( %s, shader: %s, value: [ %d, %d, %d ] ) ---\n",
480+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ] ) );
481+
}
482+
#endif
483+
#if defined( USE_UNIFORM_FIREWALL )
484+
ivec3_t *firewall = ( ivec3_t * ) &p->uniformFirewall[ _firewallIndex ];
485+
486+
if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
487+
{
488+
return;
489+
}
490+
491+
VectorCopy( v, *firewall );
492+
#endif
493+
glUniform3i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ], v[ 2 ] );
494+
}
495+
public:
496+
size_t GetSize() override
497+
{
498+
return sizeof( ivec3_t );
499+
}
500+
};
501+
502+
class GLUniform4i : protected GLUniform
503+
{
504+
protected:
505+
GLUniform4i( GLShader *shader, const char *name ) :
506+
GLUniform( shader, name )
507+
{
508+
}
509+
510+
inline void SetValue( const ivec4_t v )
511+
{
512+
shaderProgram_t *p = _shader->GetProgram();
513+
514+
ASSERT_EQ(p, glState.currentProgram);
515+
516+
#if defined( LOG_GLSL_UNIFORMS )
517+
if ( r_logFile->integer )
518+
{
519+
GLimp_LogComment( va( "GLSL_SetUniform4i( %s, shader: %s, value: [ %d, %d, %d, %d ] ) ---\n",
520+
this->GetName(), _shader->GetName().c_str(), v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] ) );
521+
}
522+
#endif
523+
#if defined( USE_UNIFORM_FIREWALL )
524+
ivec4_t *firewall = ( ivec4_t * ) &p->uniformFirewall[ _firewallIndex ];
525+
526+
if ( !memcmp( *firewall, v, sizeof( *firewall ) ) )
527+
{
528+
return;
529+
}
530+
531+
Vector4Copy( v, *firewall );
532+
#endif
533+
glUniform4i( p->uniformLocations[ _locationIndex ], v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ] );
534+
}
535+
public:
536+
size_t GetSize() override
537+
{
538+
return sizeof( ivec4_t );
539+
}
540+
};
541+
421542
class GLUniform1f : protected GLUniform
422543
{
423544
protected:

0 commit comments

Comments
 (0)