mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-01-22 08:21:48 +00:00
caching the current active texture slot in GL3
it reduces the total number of API calls by a good amount
This commit is contained in:
parent
2aaf17b061
commit
249bcb2d07
1 changed files with 16 additions and 9 deletions
|
@ -249,6 +249,7 @@ struct OpenGL3
|
||||||
ArrayBuffer indexBuffer;
|
ArrayBuffer indexBuffer;
|
||||||
|
|
||||||
GLuint boundTextures[2];
|
GLuint boundTextures[2];
|
||||||
|
int activeTextureSlot;
|
||||||
cullType_t cullType;
|
cullType_t cullType;
|
||||||
unsigned int srcBlendBits;
|
unsigned int srcBlendBits;
|
||||||
unsigned int dstBlendBits;
|
unsigned int dstBlendBits;
|
||||||
|
@ -1126,6 +1127,17 @@ static void FBO_ResolveColor()
|
||||||
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ApplyActiveTexture(int slot)
|
||||||
|
{
|
||||||
|
if(slot == gl.activeTextureSlot)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0 + slot);
|
||||||
|
gl.activeTextureSlot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
static void ApplyPipeline(PipelineId pipelineId)
|
static void ApplyPipeline(PipelineId pipelineId)
|
||||||
{
|
{
|
||||||
if(pipelineId == gl.pipelineId)
|
if(pipelineId == gl.pipelineId)
|
||||||
|
@ -1165,7 +1177,7 @@ static void ApplyPipeline(PipelineId pipelineId)
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform1i(pipeline->textureLocations[0], 0);
|
glUniform1i(pipeline->textureLocations[0], 0);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
ApplyActiveTexture(1);
|
||||||
if(pipelineId == PID_SOFT_SPRITE && gl.fbMSEnabled)
|
if(pipelineId == PID_SOFT_SPRITE && gl.fbMSEnabled)
|
||||||
{
|
{
|
||||||
// we don't have a "BindTextureMS" function for caching/tracking MS texture binds
|
// we don't have a "BindTextureMS" function for caching/tracking MS texture binds
|
||||||
|
@ -1173,7 +1185,7 @@ static void ApplyPipeline(PipelineId pipelineId)
|
||||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, gl.fbMS.depthStencil);
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, gl.fbMS.depthStencil);
|
||||||
}
|
}
|
||||||
glUniform1i(pipeline->textureLocations[1], 1);
|
glUniform1i(pipeline->textureLocations[1], 1);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
ApplyActiveTexture(0);
|
||||||
|
|
||||||
memset(pipeline->uniformsDirty, 0xFF, sizeof(pipeline->uniformsDirty));
|
memset(pipeline->uniformsDirty, 0xFF, sizeof(pipeline->uniformsDirty));
|
||||||
}
|
}
|
||||||
|
@ -1213,6 +1225,7 @@ static void BindTexture(int slot, GLuint texture)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplyActiveTexture(slot);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
gl.boundTextures[slot] = texture;
|
gl.boundTextures[slot] = texture;
|
||||||
}
|
}
|
||||||
|
@ -1740,6 +1753,7 @@ static void SetDefaultState()
|
||||||
|
|
||||||
gl.boundTextures[0] = GLuint(-1);
|
gl.boundTextures[0] = GLuint(-1);
|
||||||
gl.boundTextures[1] = GLuint(-1);
|
gl.boundTextures[1] = GLuint(-1);
|
||||||
|
gl.activeTextureSlot = 0;
|
||||||
gl.cullType = CT_TWO_SIDED;
|
gl.cullType = CT_TWO_SIDED;
|
||||||
gl.srcBlendBits = GLS_SRCBLEND_SRC_ALPHA;
|
gl.srcBlendBits = GLS_SRCBLEND_SRC_ALPHA;
|
||||||
gl.dstBlendBits = GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
|
gl.dstBlendBits = GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
|
||||||
|
@ -2209,7 +2223,6 @@ static void DrawGeneric()
|
||||||
UploadVertexArray(VB_COLOR, tess.svars[i].colors);
|
UploadVertexArray(VB_COLOR, tess.svars[i].colors);
|
||||||
|
|
||||||
BindBundle(0, &stage->bundle);
|
BindBundle(0, &stage->bundle);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
|
|
||||||
if(stage->mtStages == 0)
|
if(stage->mtStages == 0)
|
||||||
{
|
{
|
||||||
|
@ -2226,8 +2239,6 @@ static void DrawGeneric()
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
if(pipeline->uniformsDirty[GU_ALPHA_TEX])
|
if(pipeline->uniformsDirty[GU_ALPHA_TEX])
|
||||||
{
|
{
|
||||||
glUniform2ui(pipeline->uniformLocations[GU_ALPHA_TEX], gl.alphaTest, gl.texEnv);
|
glUniform2ui(pipeline->uniformLocations[GU_ALPHA_TEX], gl.alphaTest, gl.texEnv);
|
||||||
|
@ -2246,9 +2257,7 @@ static void DrawGeneric()
|
||||||
UploadVertexArray(VB_COLOR, tess.svarsFog.colors);
|
UploadVertexArray(VB_COLOR, tess.svarsFog.colors);
|
||||||
|
|
||||||
BindImage(0, tr.fogImage);
|
BindImage(0, tr.fogImage);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
BindImage(1, tr.whiteImage);
|
BindImage(1, tr.whiteImage);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
ApplyTexEnv(TE_DISABLED);
|
ApplyTexEnv(TE_DISABLED);
|
||||||
if(pipeline->uniformsDirty[GU_ALPHA_TEX])
|
if(pipeline->uniformsDirty[GU_ALPHA_TEX])
|
||||||
|
@ -2385,9 +2394,7 @@ static void DrawDepthFade()
|
||||||
BindBundle(0, &stage->bundle);
|
BindBundle(0, &stage->bundle);
|
||||||
if(!gl.fbMSEnabled)
|
if(!gl.fbMSEnabled)
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
BindTexture(1, gl.fbSS[gl.fbReadIndex].depthStencil);
|
BindTexture(1, gl.fbSS[gl.fbReadIndex].depthStencil);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawElements(tess.numIndexes);
|
DrawElements(tess.numIndexes);
|
||||||
|
|
Loading…
Reference in a new issue