Optimized OpenGL samplers binding
Former-commit-id: 6afb2ed4d9851e09ff1006cf7c81df0cac0bed7d
This commit is contained in:
parent
9428097b53
commit
4026e310bc
|
|
@ -78,6 +78,7 @@ class NAZARA_API NzOpenGL
|
|||
|
||||
static void BindBuffer(nzBufferType type, GLuint id);
|
||||
static void BindProgram(GLuint id);
|
||||
static void BindSampler(GLuint unit, GLuint id);
|
||||
static void BindScissorBox(const NzRecti& scissorBox);
|
||||
static void BindTexture(nzImageType type, GLuint id);
|
||||
static void BindTexture(unsigned int textureUnit, nzImageType type, GLuint id);
|
||||
|
|
@ -86,6 +87,7 @@ class NAZARA_API NzOpenGL
|
|||
|
||||
static void DeleteBuffer(nzBufferType type, GLuint id);
|
||||
static void DeleteProgram(GLuint id);
|
||||
static void DeleteSampler(GLuint id);
|
||||
static void DeleteTexture(GLuint id);
|
||||
|
||||
static GLuint GetCurrentBuffer(nzBufferType type);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ namespace
|
|||
{
|
||||
GLuint buffersBinding[nzBufferType_Max+1] = {0};
|
||||
GLuint currentProgram = 0;
|
||||
GLuint samplers[32] = {0}; // 32 est pour l'instant la plus haute limite (GL_TEXTURE31)
|
||||
GLuint texturesBinding[32] = {0}; // 32 est pour l'instant la plus haute limite (GL_TEXTURE31)
|
||||
NzRecti currentScissorBox = NzRecti(0,0,0,0);
|
||||
NzRecti currentViewport = NzRecti(0,0,0,0);
|
||||
|
|
@ -326,6 +327,29 @@ void NzOpenGL::BindProgram(GLuint id)
|
|||
}
|
||||
}
|
||||
|
||||
void NzOpenGL::BindSampler(GLuint unit, GLuint id)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!glBindSampler)
|
||||
{
|
||||
NazaraError("Sampler are not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s_contextStates)
|
||||
{
|
||||
NazaraError("No context activated");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_contextStates->samplers[unit] != id)
|
||||
{
|
||||
glBindSampler(unit, id);
|
||||
s_contextStates->samplers[unit] = id;
|
||||
}
|
||||
}
|
||||
|
||||
void NzOpenGL::BindScissorBox(const NzRecti& scissorBox)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
|
|
@ -487,6 +511,31 @@ void NzOpenGL::DeleteProgram(GLuint id)
|
|||
s_contextStates->currentProgram = 0;
|
||||
}
|
||||
|
||||
void NzOpenGL::DeleteSampler(GLuint id)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!glDeleteSamplers)
|
||||
{
|
||||
NazaraError("Sampler are not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s_contextStates)
|
||||
{
|
||||
NazaraError("No context activated");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glDeleteSamplers(1, &id);
|
||||
|
||||
for (GLuint& binding : s_contextStates->samplers)
|
||||
{
|
||||
if (binding == id)
|
||||
binding = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void NzOpenGL::DeleteTexture(GLuint id)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ void NzTextureSampler::Bind(unsigned int unit) const
|
|||
if (!m_samplerId)
|
||||
UpdateSamplerId();
|
||||
|
||||
glBindSampler(unit, m_samplerId);
|
||||
NzOpenGL::BindSampler(unit, m_samplerId);
|
||||
}
|
||||
|
||||
unsigned int NzTextureSampler::GetOpenGLID() const
|
||||
|
|
@ -379,7 +379,7 @@ void NzTextureSampler::Uninitialize()
|
|||
{
|
||||
NzContext::EnsureContext();
|
||||
for (const std::pair<nzUInt32, GLuint>& pair : s_samplers)
|
||||
glDeleteSamplers(1, &pair.second);
|
||||
NzOpenGL::DeleteSampler(pair.second);
|
||||
|
||||
s_samplers.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue