Refactor texture caps
parent
965ee69a98
commit
cd2293f6c6
|
@ -18,7 +18,9 @@ bool EXT_texture_compression_s3tc = false;
|
||||||
bool EXT_texture_filter_anisotropic = false;
|
bool EXT_texture_filter_anisotropic = false;
|
||||||
bool MESA_pack_invert = false;
|
bool MESA_pack_invert = false;
|
||||||
GLint maxPointSize = 0;
|
GLint maxPointSize = 0;
|
||||||
|
GLint maxTextureSize = 0;
|
||||||
GLfloat maxLineWidth = 0.0f;
|
GLfloat maxLineWidth = 0.0f;
|
||||||
|
GLint maxTextureAnisotropy = 0;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -59,6 +61,13 @@ bool init(util::array_view<std::string> ignore) noexcept
|
||||||
maxPointSize = pointSizeRange[1];
|
maxPointSize = pointSizeRange[1];
|
||||||
maxLineWidth = lineWidthRange[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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,9 @@ extern bool ARB_vertex_array_object;
|
||||||
extern bool EXT_framebuffer_object;
|
extern bool EXT_framebuffer_object;
|
||||||
#endif
|
#endif
|
||||||
extern GLint maxPointSize;
|
extern GLint maxPointSize;
|
||||||
|
extern GLint maxTextureSize;
|
||||||
extern GLfloat maxLineWidth;
|
extern GLfloat maxLineWidth;
|
||||||
|
extern GLint maxTextureAnisotropy;
|
||||||
|
|
||||||
bool init(util::array_view<std::string> = {}) noexcept;
|
bool init(util::array_view<std::string> = {}) noexcept;
|
||||||
bool checkVersion(int) noexcept;
|
bool checkVersion(int) noexcept;
|
||||||
|
|
|
@ -30,12 +30,8 @@ using namespace celestia;
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static bool texCapsInitialized = false;
|
|
||||||
|
|
||||||
struct TextureCaps
|
struct TextureCaps
|
||||||
{
|
{
|
||||||
bool maxLevelSupported;
|
|
||||||
GLint maxTextureSize;
|
|
||||||
GLint preferredAnisotropy;
|
GLint preferredAnisotropy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,23 +88,19 @@ static bool testMaxLevel()
|
||||||
|
|
||||||
static const TextureCaps& GetTextureCaps()
|
static const TextureCaps& GetTextureCaps()
|
||||||
{
|
{
|
||||||
|
static bool texCapsInitialized = false;
|
||||||
|
|
||||||
if (!texCapsInitialized)
|
if (!texCapsInitialized)
|
||||||
{
|
{
|
||||||
texCapsInitialized = true;
|
texCapsInitialized = true;
|
||||||
|
|
||||||
texCaps.maxLevelSupported = testMaxLevel();
|
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texCaps.maxTextureSize);
|
|
||||||
|
|
||||||
texCaps.preferredAnisotropy = 1;
|
texCaps.preferredAnisotropy = 1;
|
||||||
#ifndef GL_ES
|
#ifndef GL_ES
|
||||||
if (gl::EXT_texture_filter_anisotropic)
|
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
|
// Cap the preferred level texture anisotropy to 8; eventually, we should allow
|
||||||
// the user to control this.
|
// the user to control this.
|
||||||
texCaps.preferredAnisotropy = min(8, maxAnisotropy);
|
texCaps.preferredAnisotropy = min(8, gl::maxTextureAnisotropy);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1006,8 +998,8 @@ static Texture* CreateTextureFromImage(Image& img,
|
||||||
bool splittingAllowed = true;
|
bool splittingAllowed = true;
|
||||||
Texture* tex = nullptr;
|
Texture* tex = nullptr;
|
||||||
|
|
||||||
int maxDim = GetTextureCaps().maxTextureSize;
|
const int maxDim = gl::maxTextureSize;
|
||||||
if ((img.getWidth() > maxDim || img.getHeight() > maxDim) &&
|
if ((img.getWidth() > maxDim || img.getHeight() > maxDim)
|
||||||
splittingAllowed)
|
splittingAllowed)
|
||||||
{
|
{
|
||||||
// The texture is too large; we need to split it.
|
// The texture is too large; we need to split it.
|
||||||
|
|
Loading…
Reference in New Issue