From 5fa7ddfaedb8df84eb521fa148d1046bbb849afa Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 2 Jan 2013 19:04:48 +0100 Subject: [PATCH] MYST3: Enable texture filtering. Also use GL_ARB_texture_non_power_of_two when it's available. When GL_ARB_texture_non_power_of_two is not available the clamping is incorrect due to the padded sides, resulting in white lines on some edges of the cube. --- engines/myst3/gfx.cpp | 35 +++++++++++++++++++++++++++-------- engines/myst3/gfx.h | 2 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/engines/myst3/gfx.cpp b/engines/myst3/gfx.cpp index 9c5b4f77f1e..3cc9e2dc693 100644 --- a/engines/myst3/gfx.cpp +++ b/engines/myst3/gfx.cpp @@ -47,7 +47,7 @@ namespace Myst3 { class OpenGLTexture : public Texture { public: - OpenGLTexture(const Graphics::Surface *surface); + OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport); virtual ~OpenGLTexture(); void update(const Graphics::Surface *surface); @@ -72,13 +72,19 @@ static uint32 upperPowerOfTwo(uint32 v) return v; } -OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface) { +OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface, bool nonPoTSupport) { width = surface->w; height = surface->h; format = surface->format; - internalHeight = upperPowerOfTwo(height); - internalWidth = upperPowerOfTwo(width); + // Pad the textures if non power of two support is unavailable + if (nonPoTSupport) { + internalHeight = height; + internalWidth = width; + } else { + internalHeight = upperPowerOfTwo(height); + internalWidth = upperPowerOfTwo(width); + } if (format.bytesPerPixel == 4) { internalFormat = GL_RGBA; @@ -92,8 +98,13 @@ OpenGLTexture::OpenGLTexture(const Graphics::Surface *surface) { glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, internalWidth, internalHeight, 0, internalFormat, sourceFormat, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + // TODO: If non power of two textures are unavailable this clamping + // has no effect on the padded sides (resulting in white lines on the edges) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); update(surface); } @@ -109,7 +120,8 @@ void OpenGLTexture::update(const Graphics::Surface *surface) { Renderer::Renderer(OSystem *system) : _system(system), - _font(0) { + _font(0), + _nonPowerOfTwoTexSupport(false) { } Renderer::~Renderer() { @@ -118,7 +130,7 @@ Renderer::~Renderer() { } Texture *Renderer::createTexture(const Graphics::Surface *surface) { - return new OpenGLTexture(surface); + return new OpenGLTexture(surface, _nonPowerOfTwoTexSupport); } void Renderer::freeTexture(Texture *texture) { @@ -127,6 +139,13 @@ void Renderer::freeTexture(Texture *texture) { } void Renderer::init() { + // Check the available OpenGL extensions + const char* extensions = (const char*)glGetString(GL_EXTENSIONS); + if (strstr(extensions, "GL_ARB_texture_non_power_of_two")) + _nonPowerOfTwoTexSupport = true; + else + warning("GL_ARB_texture_non_power_of_two is not available."); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/engines/myst3/gfx.h b/engines/myst3/gfx.h index ae93fe86ad1..d9a69011abb 100644 --- a/engines/myst3/gfx.h +++ b/engines/myst3/gfx.h @@ -89,6 +89,8 @@ protected: double _cubeProjectionMatrix[16]; double _cubeModelViewMatrix[16]; + bool _nonPowerOfTwoTexSupport; + Common::Rect getFontCharacterRect(uint8 character); };