Skip to content

Commit

Permalink
GL: fixed mip level count query in GetTextureDescFromGLHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 2, 2024
1 parent c764b8a commit e7075e3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ static GLenum GetTextureInternalFormat(GLContextState& GLState, GLenum BindTarge
return GlFormat;
}

static TextureDesc GetTextureDescFromGLHandle(GLContextState& GLState, TextureDesc TexDesc, GLuint GLHandle, GLenum BindTarget)
static TextureDesc GetTextureDescFromGLHandle(const RenderDeviceInfo& DeviceInfo,
GLContextState& GLState,
TextureDesc TexDesc,
GLuint GLHandle,
GLenum BindTarget)
{
VERIFY(BindTarget != GL_TEXTURE_CUBE_MAP_ARRAY, "Cubemap arrays are not currently supported");

Expand Down Expand Up @@ -280,10 +284,13 @@ static TextureDesc GetTextureDescFromGLHandle(GLContextState& GLState, TextureDe
}
#endif

// GL_TEXTURE_IMMUTABLE_LEVELS is only supported in GL4.3+ and GLES3.1+
GLint MipLevels = 0;
glGetTexParameteriv(BindTarget, GL_TEXTURE_IMMUTABLE_LEVELS, &MipLevels);
DEV_CHECK_GL_ERROR("glGetTexLevelParameteriv(GL_TEXTURE_IMMUTABLE_LEVELS) failed");
// GL_TEXTURE_IMMUTABLE_LEVELS is supported in GL4.3+ and GLES3.0+.
if ((DeviceInfo.Type == RENDER_DEVICE_TYPE_GL && DeviceInfo.APIVersion >= Version{4, 3}) || DeviceInfo.Type == RENDER_DEVICE_TYPE_GLES)
{
glGetTexParameteriv(BindTarget, GL_TEXTURE_IMMUTABLE_LEVELS, &MipLevels);
DEV_CHECK_GL_ERROR("glGetTexLevelParameteriv(GL_TEXTURE_IMMUTABLE_LEVELS) failed");
}
if (MipLevels > 0)
{
if (TexDesc.MipLevels != 0 && TexDesc.MipLevels != static_cast<Uint32>(MipLevels))
Expand Down Expand Up @@ -321,7 +328,7 @@ TextureBaseGL::TextureBaseGL(IReferenceCounters* pRefCounters,
pRefCounters,
TexViewObjAllocator,
pDeviceGL,
GetTextureDescFromGLHandle(GLState, TexDesc, GLTextureHandle, BindTarget),
GetTextureDescFromGLHandle(pDeviceGL->GetDeviceInfo(), GLState, TexDesc, GLTextureHandle, BindTarget),
bIsDeviceInternal
},
// Create texture object wrapper, but use external texture handle
Expand Down

0 comments on commit e7075e3

Please sign in to comment.