我正在使用OpenGL 3.3和延迟着色。
当我在帧之间设置采样器的各向异性值时,下一帧会导致glClear下一帧的崩溃。
以下是我设置各向异性值的方法:
bool OpenGLRenderer::SetAnisotropicFiltering(const float newAnisoLevel)
{
if (newAnisoLevel < 0.0f || newAnisoLevel > GetMaxAnisotropicFiltering())
return false;
mCurrentAnisotropy = newAnisoLevel;
// the sampler used for geometry pass
GLCALL(glSamplerParameterf(mTextureSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, mCurrentAnisotropy));
// the sampler used in shading pass
GLCALL(glSamplerParameterf(mGBuffer.mTextureSampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, mCurrentAnisotropy));
return true;
}
几何体通道具有以下漫反射/普通纹理,并且设置如下:
GLCALL(glUseProgram(mGeometryProgram.mProgramHandle));
GLCALL(glGenSamplers(1, &mTextureSampler));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_S, GL_REPEAT));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_T, GL_REPEAT));
GLCALL(glUniform1i(glGetUniformLocation(mGeometryProgram.mProgramHandle, "unifDiffuseTexture"), OpenGLTexture::TEXTURE_UNIT_DIFFUSE));
GLCALL(glUniform1i(glGetUniformLocation(mGeometryProgram.mProgramHandle, "unifNormalTexture"), OpenGLTexture::TEXTURE_UNIT_NORMAL));
GLCALL(glBindSampler(OpenGLTexture::TEXTURE_UNIT_DIFFUSE, mTextureSampler));
GLCALL(glBindSampler(OpenGLTexture::TEXTURE_UNIT_NORMAL, mTextureSampler));
GLCALL(glUseProgram(0));
着色过程具有以下用于照明计算的纹理:
GLCALL(glUseProgram(shadingProgramID));
GLCALL(glGenSamplers(1, &mTextureSampler));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCALL(glSamplerParameteri(mTextureSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
GLCALL(glUniform1i(glGetUniformLocation(shadingProgramID, "unifPositionTexture"), GBuffer::GBUFFER_TEXTURE_POSITION));
GLCALL(glUniform1i(glGetUniformLocation(shadingProgramID, "unifNormalTexture"), GBuffer::GBUFFER_TEXTURE_NORMAL));
GLCALL(glUniform1i(glGetUniformLocation(shadingProgramID, "unifDiffuseTexture"), GBuffer::GBUFFER_TEXTURE_DIFFUSE));
GLCALL(glBindSampler(GBuffer::GBUFFER_TEXTURE_POSITION, mTextureSampler));
GLCALL(glBindSampler(GBuffer::GBUFFER_TEXTURE_NORMAL, mTextureSampler));
GLCALL(glBindSampler(GBuffer::GBUFFER_TEXTURE_DIFFUSE, mTextureSampler));
GLCALL(glUseProgram(0));
然后在下一帧上,当进行几何传递时,它立即在glClear函数上崩溃
void OpenGLRenderer::GeometryPass(const RenderQueue& renderQueue)
{
GLCALL(glUseProgram(mGeometryProgram.mProgramHandle));
GLCALL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mGBuffer.mFramebuffer));
GLCALL(glDepthMask(GL_TRUE));
GLCALL(glEnable(GL_DEPTH_TEST));
// clear GBuffer fbo
GLCALL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); // <----- crash!
// both containers are assumed to be sorted by MeshID ascending
auto meshIterator = mMeshes.begin();
for (const Renderable& renderable : renderQueue)
{
// lots of draw code.....
}
GLCALL(glDisable(GL_DEPTH_TEST));
GLCALL(glDepthMask(GL_FALSE));
GLCALL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
GLCALL(glUseProgram(0));
}
这可能是什么问题?
答案 0 :(得分:5)
您的范围验证错误。各向异性的最小可接受值 1.0f 。值 1.0f (默认值)表示 关闭 (各向同性)。
老实说,当你将各向异性设置在可接受的范围之上或之下时,我会考虑将值钳位到[1.0,MAX],而不是返回 false 而不执行任何其他操作。稍后您可以通过在函数返回后检查mCurrentAnisotropy
的值来确定您的请求是不可接受的。如果将各向异性级别存储为配置文件中的选项并且硬件更改,则此选项非常有用。虽然 16.0 几乎普遍是这些天的最大值,但是一些非常旧的硬件仅支持 8.0 。您仍然可以返回false
,报告警告或其他任何内容,但我个人总是将对各种各向异性水平的请求解释为支持意味着:“我希望最高的各向异性可能。”