Reworked texture samplers internal

Former-commit-id: d26f8f12ccc1730519c6fa7d4bec725a0396d9f1
This commit is contained in:
Lynix 2013-03-16 01:07:00 +01:00
parent b82cbc074b
commit 200f46b442
2 changed files with 81 additions and 68 deletions

View File

@ -39,8 +39,10 @@ class NAZARA_API NzTextureSampler
static void SetDefaultWrapMode(nzSamplerWrap wrapMode); static void SetDefaultWrapMode(nzSamplerWrap wrapMode);
private: private:
void Apply(const NzTexture* texture); void Apply(const NzTexture* texture) const;
void Bind(unsigned int unit); void Bind(unsigned int unit) const;
unsigned int GetOpenGLID() const;
void UpdateSamplerId() const;
bool UseMipmaps(bool mipmaps); bool UseMipmaps(bool mipmaps);
static bool Initialize(); static bool Initialize();

View File

@ -212,7 +212,7 @@ void NzTextureSampler::SetDefaultWrapMode(nzSamplerWrap wrapMode)
} }
} }
void NzTextureSampler::Apply(const NzTexture* texture) void NzTextureSampler::Apply(const NzTexture* texture) const
{ {
// On considère que la texture est déjà active lors de l'appel à cette fonction // On considère que la texture est déjà active lors de l'appel à cette fonction
GLenum target = NzOpenGL::TextureTarget[texture->GetType()]; GLenum target = NzOpenGL::TextureTarget[texture->GetType()];
@ -275,12 +275,26 @@ void NzTextureSampler::Apply(const NzTexture* texture)
} }
} }
void NzTextureSampler::Bind(unsigned int unit) void NzTextureSampler::Bind(unsigned int unit) const
{ {
static_assert(nzSamplerFilter_Max < 0x4, "Maximum sampler filter mode takes more than 2 bits"); static_assert(nzSamplerFilter_Max < 0x4, "Maximum sampler filter mode takes more than 2 bits");
static_assert(nzSamplerWrap_Max < 0x4, "Maximum sampler wrap mode takes more than 2 bits"); static_assert(nzSamplerWrap_Max < 0x4, "Maximum sampler wrap mode takes more than 2 bits");
if (!m_samplerId) if (!m_samplerId)
UpdateSamplerId();
glBindSampler(unit, m_samplerId);
}
unsigned int NzTextureSampler::GetOpenGLID() const
{
if (!m_samplerId)
UpdateSamplerId();
return m_samplerId;
}
void NzTextureSampler::UpdateSamplerId() const
{ {
nzUInt32 key = (m_mipmaps << 0) | // 1 bit nzUInt32 key = (m_mipmaps << 0) | // 1 bit
(m_filterMode << 1) | // 2 bits (m_filterMode << 1) | // 2 bits
@ -346,9 +360,6 @@ void NzTextureSampler::Bind(unsigned int unit)
m_samplerId = it->second; m_samplerId = it->second;
} }
glBindSampler(unit, m_samplerId);
}
bool NzTextureSampler::UseMipmaps(bool mipmaps) bool NzTextureSampler::UseMipmaps(bool mipmaps)
{ {
if (m_mipmaps != mipmaps) if (m_mipmaps != mipmaps)