Skip to content

Commit

Permalink
gl2shim: simple matrix invalidation, do not calculate MVP every drawcall
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Oct 6, 2023
1 parent b1cd99d commit 889938b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ref/gl/gl2_shim/gl2_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static struct
float mvp[16], mv[16], pr[16], dummy[16];
GLenum mode;
float *current;
uint64_t update;
} gl2wrap_matrix;


Expand Down Expand Up @@ -738,7 +739,7 @@ static void APIENTRY GL2_LoadIdentity( void )
m[6] = m[7] = m[8] = m[9] = 0.0f;
m[11] = m[12] = m[13] = m[14] = 0.0f;
m[0] = m[5] = m[10] = m[15] = 1.0f;

gl2wrap_matrix.update = 0xFFFFFFFFFFFFFFFF;
}


Expand Down Expand Up @@ -768,6 +769,7 @@ static void APIENTRY GL2_Ortho(double l, double r, double b, double t, double n,
m[9] *= m10;
m[10] *= m10;
m[11] *= m10;
gl2wrap_matrix.update = 0xFFFFFFFFFFFFFFFF;
}

static void GL2_Mul4x4(const GLfloat *in0, const GLfloat *in1, GLfloat *out)
Expand All @@ -792,13 +794,18 @@ static void GL2_Mul4x4(const GLfloat *in0, const GLfloat *in1, GLfloat *out)

static void GL2_UpdateMVP( gl2wrap_prog_t *prog )
{
GL2_Mul4x4(gl2wrap_matrix.mv, gl2wrap_matrix.pr, gl2wrap_matrix.mvp );
pglUniformMatrix4fvARB(prog->uMVP, 1, false, (void*)gl2wrap_matrix.mvp);
if( gl2wrap_matrix.update & ( 1U << prog->flags ) )
{
gl2wrap_matrix.update &= ~( 1U << prog->flags );
GL2_Mul4x4( gl2wrap_matrix.mv, gl2wrap_matrix.pr, gl2wrap_matrix.mvp );
pglUniformMatrix4fvARB( prog->uMVP, 1, false, (void*)gl2wrap_matrix.mvp );
}
}

static void APIENTRY GL2_LoadMatrixf( const GLfloat *m )
{
memcpy( gl2wrap_matrix.current, m, 16*sizeof(float) );
memcpy( gl2wrap_matrix.current, m, 16 * sizeof(float) );
gl2wrap_matrix.update = 0xFFFFFFFFFFFFFFFF;
}

static void ( APIENTRY*_pglDepthRangef)(GLfloat far, GLfloat near);
Expand Down

0 comments on commit 889938b

Please sign in to comment.