OpenGL: Fix TextureSampler mipmap issue
This commit is contained in:
@@ -43,8 +43,8 @@ namespace Nz
|
||||
OpenGLTextureSampler& glSampler = *static_cast<OpenGLTextureSampler*>(texBinding.sampler);
|
||||
|
||||
auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, resourceIndex);
|
||||
textureDescriptor.sampler = glSampler.GetSampler().GetObjectId();
|
||||
textureDescriptor.texture = glTexture.GetTexture().GetObjectId();
|
||||
textureDescriptor.sampler = glSampler.GetSampler(glTexture.GetLevelCount() > 1).GetObjectId();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,21 +9,30 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
OpenGLTextureSampler::OpenGLTextureSampler(OpenGLDevice& device, TextureSamplerInfo samplerInfo)
|
||||
OpenGLTextureSampler::OpenGLTextureSampler(OpenGLDevice& device, const TextureSamplerInfo& samplerInfo)
|
||||
{
|
||||
if (!m_sampler.Create(device))
|
||||
BuildSampler(device, m_samplerWithMipmaps, samplerInfo, true);
|
||||
BuildSampler(device, m_samplerWithoutMipmaps, samplerInfo, false);
|
||||
}
|
||||
|
||||
void OpenGLTextureSampler::BuildSampler(OpenGLDevice& device, GL::Sampler& sampler, const TextureSamplerInfo& samplerInfo, bool withMipmaps)
|
||||
{
|
||||
if (!sampler.Create(device))
|
||||
throw std::runtime_error("failed to create sampler object");
|
||||
|
||||
// In OpenGL, min and mipmap sampler are part of the same enum
|
||||
// In OpenGL, min and mipmap sampler are part of the same enum (and mipmaps filter should only be used with mipmaps)
|
||||
if (withMipmaps)
|
||||
sampler.SetParameteri(GL_TEXTURE_MIN_FILTER, ToOpenGL(samplerInfo.minFilter, samplerInfo.mipmapMode));
|
||||
else
|
||||
sampler.SetParameteri(GL_TEXTURE_MIN_FILTER, ToOpenGL(samplerInfo.minFilter));
|
||||
|
||||
m_sampler.SetParameteri(GL_TEXTURE_MIN_FILTER, ToOpenGL(samplerInfo.minFilter, samplerInfo.mipmapMode));
|
||||
m_sampler.SetParameteri(GL_TEXTURE_MAG_FILTER, ToOpenGL(samplerInfo.magFilter));
|
||||
sampler.SetParameteri(GL_TEXTURE_MAG_FILTER, ToOpenGL(samplerInfo.magFilter));
|
||||
|
||||
m_sampler.SetParameteri(GL_TEXTURE_WRAP_S, ToOpenGL(samplerInfo.wrapModeU));
|
||||
m_sampler.SetParameteri(GL_TEXTURE_WRAP_T, ToOpenGL(samplerInfo.wrapModeV));
|
||||
m_sampler.SetParameteri(GL_TEXTURE_WRAP_R, ToOpenGL(samplerInfo.wrapModeW));
|
||||
sampler.SetParameteri(GL_TEXTURE_WRAP_S, ToOpenGL(samplerInfo.wrapModeU));
|
||||
sampler.SetParameteri(GL_TEXTURE_WRAP_T, ToOpenGL(samplerInfo.wrapModeV));
|
||||
sampler.SetParameteri(GL_TEXTURE_WRAP_R, ToOpenGL(samplerInfo.wrapModeW));
|
||||
|
||||
if (samplerInfo.anisotropyLevel > 1.f)
|
||||
m_sampler.SetParameterf(GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerInfo.anisotropyLevel);
|
||||
sampler.SetParameterf(GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerInfo.anisotropyLevel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user