Skip to content

Commit

Permalink
[GL] Always rely on cached internal texture format.
Browse files Browse the repository at this point in the history
- Removed GetTexParameterInternalFormat() and GetInternalformativ() from GLProfile namespace as they are not supported on GLES 3.0 and WebGL 2.0.
- Always cache internal format in GLTexture to avoid having to query the internal format later; Which is only supported on desktop GL anyway.
- Temporarily disable removal of supported texture formats information for GLES and WebGL backends.
  • Loading branch information
LukasBanana committed Aug 31, 2024
1 parent 03ca533 commit 00fdfc2
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 109 deletions.
12 changes: 0 additions & 12 deletions sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ GLint GetMaxViewports()
return value;
}

void GetTexParameterInternalFormat(GLenum target, GLint* params)
{
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, params);
}

void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params)
{
#ifdef GL_ARB_internalformat_query
glGetInternalformativ(target, internalformat, pname, bufsize, params);
#endif
}

void DepthRange(GLclamp_t nearVal, GLclamp_t farVal)
{
glDepthRange(nearVal, farVal);
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void GLGetSupportedTextureFormats(std::vector<Format>& textureFormats)
{
textureFormats = GetDefaultSupportedGLTextureFormats();

#if defined GL_ARB_internalformat_query && defined GL_ARB_internalformat_query2
#if GL_ARB_internalformat_query && GL_ARB_internalformat_query2

if (HasExtension(GLExt::ARB_internalformat_query) && HasExtension(GLExt::ARB_internalformat_query2))
{
Expand All @@ -160,7 +160,7 @@ static void GLGetSupportedTextureFormats(std::vector<Format>& textureFormats)

#endif

#ifdef GL_EXT_texture_compression_s3tc
#if GL_EXT_texture_compression_s3tc

const std::uint32_t numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS);

Expand Down
14 changes: 0 additions & 14 deletions sources/Renderer/OpenGL/GLESProfile/GLESProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ GLint GetMaxViewports()
return 1;
}

void GetTexParameterInternalFormat(GLenum target, GLint* params)
{
#ifdef GL_ES_VERSION_3_1
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, params);
#else
LLGL_TRAP_NOT_IMPLEMENTED(); //TODO
#endif
}

void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params)
{
LLGL_TRAP_NOT_IMPLEMENTED(); //TODO
}

void DepthRange(GLclamp_t nearVal, GLclamp_t farVal)
{
glDepthRangef(nearVal, farVal);
Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/GLESProfile/GLESProfileCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ static void GLGetSupportedTextureFormats(std::vector<Format>& textureFormats)
{
textureFormats = GetDefaultSupportedGLTextureFormats();

RemoveAllFromListIf(
/*RemoveAllFromListIf(
textureFormats,
[](Format format) -> bool
{
if (auto internalformat = GLTypes::MapOrZero(format))
{
GLint supported = 0;
GLProfile::GetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported);
glGetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported);
return (supported == GL_FALSE);
}
return true;
}
);
);*/

const auto numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS);

Expand Down
6 changes: 0 additions & 6 deletions sources/Renderer/OpenGL/GLProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ const char* GetShadingLanguageName();
// Returns the maximum number of viewports (GL_MAX_VIEWPORT for GL, 1 for GLES).
GLint GetMaxViewports();

// Returns the internal format of the first texture level for the specified bound texture target.
void GetTexParameterInternalFormat(GLenum target, GLint* params);

// Wrapper for glGetInternalformativ with special case for GLES.
void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params);

// Wrapper for glDepthRange/glDepthRangef.
void DepthRange(GLclamp_t nearVal, GLclamp_t farVal);

Expand Down
17 changes: 3 additions & 14 deletions sources/Renderer/OpenGL/Texture/GLTexSubImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ namespace LLGL
{


static void QueryGLInternalFormat(GLenum target, GLenum& internalFormat)
{
if (internalFormat == 0)
{
GLint format = 0;
GLProfile::GetTexParameterInternalFormat(target, &format);
LLGL_ASSERT(format != 0);
internalFormat = static_cast<GLenum>(format);
}
}

#ifdef LLGL_OPENGL

static void GLTexSubImage1DBase(
Expand All @@ -40,7 +29,7 @@ static void GLTexSubImage1DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(target, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTexSubImage1D(
Expand Down Expand Up @@ -79,7 +68,7 @@ static void GLTexSubImage2DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(target, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTexSubImage2D(
Expand Down Expand Up @@ -122,7 +111,7 @@ static void GLTexSubImage3DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(target, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTexSubImage3D(
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/Texture/GLTexSubImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool GLTexSubImage(
const TextureType type,
const TextureRegion& region,
const ImageView& imageView,
GLenum internalFormat = 0
GLenum internalFormat
);


Expand Down
62 changes: 35 additions & 27 deletions sources/Renderer/OpenGL/Texture/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,34 @@ static ImageFormat MapSwizzleImageFormat(const ImageFormat format)
}
}

// Binds the specified GL texture temporarily. Only used to gather texture information, not to bind texture for the graphics or compute pipeline.
static void BindGLTextureNonPersistent(const GLTexture& textureGL)
{
GLStateManager::Get().BindTexture(GLStateManager::GetTextureTarget(textureGL.GetType()), textureGL.GetID());
}

#if LLGL_OPENGL || GL_ES_VERSION_3_1

static GLenum GLGetTextureInternalFormat(const GLTexture& tex)
{
/* Bind texture and query attributes */
GLint format = 0;
BindGLTextureNonPersistent(tex);
glGetTexLevelParameteriv(tex.GetGLTexLevelTarget(), 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
return static_cast<GLenum>(format);
}

#endif

static GLenum GLGetRenderbufferInternalFormat(const GLTexture& tex)
{
/* Bind renderbuffer and query qttributes */
GLint format = 0;
GLStateManager::Get().BindRenderbuffer(tex.GetID());
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &format);
return static_cast<GLenum>(format);
}

void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const ImageView* initialImage)
{
/* Bind texture */
Expand All @@ -1030,8 +1058,12 @@ void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const
//GLStateManager::Get().BindBuffer(GLBufferTarget::PIXEL_UNPACK_BUFFER, 0);
GLTexImage(textureDesc, initialImage);

/* Store internal GL format */
//internalFormat_ = GetTextureInternalFormat();
/* Store internal GL format. Only desktop OpenGL can query the actual internal format. For GLES 3.0 and WebGL 2.0 we have to rely on the input format. */
#if LLGL_OPENGL || GL_ES_VERSION_3_1
internalFormat_ = GLGetTextureInternalFormat(*this);
#else
internalFormat_ = GLTypes::Map(textureDesc.format);
#endif

/* Initialize texture parameters for the first time (sampler states not supported for multisample textures) */
if (!IsMultiSampleTexture(textureDesc.type))
Expand Down Expand Up @@ -1063,31 +1095,7 @@ void GLTexture::AllocRenderbufferStorage(const TextureDescriptor& textureDesc)
);

/* Store internal GL format */
internalFormat_ = GetRenderbufferInternalFormat();
}

// Binds the specified GL texture temporarily. Only used to gather texture information, not to bind texture for the graphics or compute pipeline.
static void BindGLTextureNonPersistent(const GLTexture& textureGL)
{
GLStateManager::Get().BindTexture(GLStateManager::GetTextureTarget(textureGL.GetType()), textureGL.GetID());
}

GLenum GLTexture::GetTextureInternalFormat() const
{
/* Bind texture and query attributes */
GLint format = 0;
BindGLTextureNonPersistent(*this);
GLProfile::GetTexParameterInternalFormat(GetGLTexLevelTarget(), &format);
return static_cast<GLenum>(format);
}

GLenum GLTexture::GetRenderbufferInternalFormat() const
{
/* Bind renderbuffer and query qttributes */
GLint format = 0;
GLStateManager::Get().BindRenderbuffer(GetID());
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &format);
return static_cast<GLenum>(format);
internalFormat_ = GLGetRenderbufferInternalFormat(*this);
}

void GLTexture::GetTextureParams(GLint* extent, GLint* samples) const
Expand Down
3 changes: 0 additions & 3 deletions sources/Renderer/OpenGL/Texture/GLTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ class GLTexture final : public Texture
void AllocTextureStorage(const TextureDescriptor& textureDesc, const ImageView* initialImage);
void AllocRenderbufferStorage(const TextureDescriptor& textureDesc);

GLenum GetTextureInternalFormat() const;
GLenum GetRenderbufferInternalFormat() const;

void GetTextureParams(GLint* extent, GLint* samples) const;
void GetRenderbufferParams(GLint* extent, GLint* samples) const;

Expand Down
17 changes: 4 additions & 13 deletions sources/Renderer/OpenGL/Texture/GLTextureSubImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GLTextureSubImage.h"
#include "../GLTypes.h"
#include "../Ext/GLExtensions.h"
#include "../../../Core/Assertion.h"
#include <array>
#include <algorithm>

Expand All @@ -18,16 +19,6 @@ namespace LLGL

#if defined GL_ARB_direct_state_access && defined LLGL_GL_ENABLE_DSA_EXT

static void QueryGLInternalFormat(GLuint texID, GLenum& internalFormat)
{
if (internalFormat == 0)
{
GLint format = 0;
glGetTextureLevelParameteriv(texID, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
internalFormat = static_cast<GLenum>(format);
}
}

static void GLTextureSubImage1DBase(
GLuint texID,
std::uint32_t mipLevel,
Expand All @@ -36,7 +27,7 @@ static void GLTextureSubImage1DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(texID, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTextureSubImage1D(
Expand Down Expand Up @@ -73,7 +64,7 @@ static void GLTextureSubImage2DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(texID, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTextureSubImage2D(
Expand Down Expand Up @@ -116,7 +107,7 @@ static void GLTextureSubImage3DBase(
const ImageView& imageView,
GLenum internalFormat)
{
QueryGLInternalFormat(texID, internalFormat);
LLGL_ASSERT(internalFormat != 0);
if (IsCompressedFormat(imageView.format))
{
glCompressedTextureSubImage3D(
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/Texture/GLTextureSubImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void GLTextureSubImage(
const TextureType type,
const TextureRegion& region,
const ImageView& imageView,
GLenum internalFormat = 0
GLenum internalFormat
);


Expand Down
10 changes: 0 additions & 10 deletions sources/Renderer/OpenGL/WebGLProfile/WebGLProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ GLint GetMaxViewports()
return 1;
}

void GetTexParameterInternalFormat(GLenum target, GLint* params)
{
LLGL_TRAP_NOT_IMPLEMENTED(); //TODO
}

void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params)
{
LLGL_TRAP_NOT_IMPLEMENTED(); //TODO
}

void DepthRange(GLclamp_t nearVal, GLclamp_t farVal)
{
glDepthRangef(nearVal, farVal);
Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/WebGLProfile/WebGLProfileCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ static void GLGetSupportedTextureFormats(std::vector<Format>& textureFormats)
{
textureFormats = GetDefaultSupportedGLTextureFormats();

RemoveAllFromListIf(
/*RemoveAllFromListIf(
textureFormats,
[](Format format) -> bool
{
if (auto internalformat = GLTypes::MapOrZero(format))
{
GLint supported = 0;
GLProfile::GetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported);
glGetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported);
return (supported == GL_FALSE);
}
return true;
}
);
);*/

const auto numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS);

Expand Down

0 comments on commit 00fdfc2

Please sign in to comment.