Refactor texture caps

pull/1191/head
Hleb Valoshka 2021-11-27 22:39:30 +02:00
parent 965ee69a98
commit cd2293f6c6
3 changed files with 16 additions and 13 deletions

View File

@ -18,7 +18,9 @@ bool EXT_texture_compression_s3tc = false;
bool EXT_texture_filter_anisotropic = false;
bool MESA_pack_invert = false;
GLint maxPointSize = 0;
GLint maxTextureSize = 0;
GLfloat maxLineWidth = 0.0f;
GLint maxTextureAnisotropy = 0;
namespace
{
@ -59,6 +61,13 @@ bool init(util::array_view<std::string> ignore) noexcept
maxPointSize = pointSizeRange[1];
maxLineWidth = lineWidthRange[1];
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
#ifndef GL_ES
if (gl::EXT_texture_filter_anisotropic)
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxTextureAnisotropy);
#endif
return true;
}

View File

@ -49,7 +49,9 @@ extern bool ARB_vertex_array_object;
extern bool EXT_framebuffer_object;
#endif
extern GLint maxPointSize;
extern GLint maxTextureSize;
extern GLfloat maxLineWidth;
extern GLint maxTextureAnisotropy;
bool init(util::array_view<std::string> = {}) noexcept;
bool checkVersion(int) noexcept;

View File

@ -30,12 +30,8 @@ using namespace celestia;
using namespace Eigen;
using namespace std;
static bool texCapsInitialized = false;
struct TextureCaps
{
bool maxLevelSupported;
GLint maxTextureSize;
GLint preferredAnisotropy;
};
@ -92,23 +88,19 @@ static bool testMaxLevel()
static const TextureCaps& GetTextureCaps()
{
static bool texCapsInitialized = false;
if (!texCapsInitialized)
{
texCapsInitialized = true;
texCaps.maxLevelSupported = testMaxLevel();
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texCaps.maxTextureSize);
texCaps.preferredAnisotropy = 1;
#ifndef GL_ES
if (gl::EXT_texture_filter_anisotropic)
{
GLint maxAnisotropy = 1;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
// Cap the preferred level texture anisotropy to 8; eventually, we should allow
// the user to control this.
texCaps.preferredAnisotropy = min(8, maxAnisotropy);
texCaps.preferredAnisotropy = min(8, gl::maxTextureAnisotropy);
}
#endif
}
@ -1006,8 +998,8 @@ static Texture* CreateTextureFromImage(Image& img,
bool splittingAllowed = true;
Texture* tex = nullptr;
int maxDim = GetTextureCaps().maxTextureSize;
if ((img.getWidth() > maxDim || img.getHeight() > maxDim) &&
const int maxDim = gl::maxTextureSize;
if ((img.getWidth() > maxDim || img.getHeight() > maxDim)
splittingAllowed)
{
// The texture is too large; we need to split it.