diff options
author | Matthew Hoops | 2013-01-24 12:49:21 -0500 |
---|---|---|
committer | Matthew Hoops | 2013-01-24 12:49:21 -0500 |
commit | fa9dd0f6c0ca61fe6d0247128e1c9ba1dd9cf0e3 (patch) | |
tree | 1d317cf0ca6a4b08d88bf77c3beff503b64ec478 /backends/graphics | |
parent | 199425562e4a6e81d66adc41dfc2a5b78d2f0b47 (diff) | |
download | scummvm-rg350-fa9dd0f6c0ca61fe6d0247128e1c9ba1dd9cf0e3.tar.gz scummvm-rg350-fa9dd0f6c0ca61fe6d0247128e1c9ba1dd9cf0e3.tar.bz2 scummvm-rg350-fa9dd0f6c0ca61fe6d0247128e1c9ba1dd9cf0e3.zip |
OPENGL: Fix linear filtering when the texture size doesn't match the real size
Diffstat (limited to 'backends/graphics')
-rw-r--r-- | backends/graphics/opengl/gltexture.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/backends/graphics/opengl/gltexture.cpp b/backends/graphics/opengl/gltexture.cpp index ce69dc4aab..351c8f9b00 100644 --- a/backends/graphics/opengl/gltexture.cpp +++ b/backends/graphics/opengl/gltexture.cpp @@ -108,9 +108,18 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) { _realWidth = w; _realHeight = h; - if (w <= _textureWidth && h <= _textureHeight && !_refresh) - // Already allocated a sufficiently large buffer - return; + if (!_refresh) { + if (npot_supported && _filter == GL_LINEAR) { + // Check if we already allocated a correctly-sized buffer + // This is so we don't need to duplicate the last row/column + if (w == _textureWidth && h == _textureHeight) + return; + } else { + // Check if we already have a large enough buffer + if (w <= _textureWidth && h <= _textureHeight) + return; + } + } if (npot_supported) { _textureWidth = w; @@ -151,12 +160,37 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu } else { // Update the texture row by row const byte *src = (const byte *)buf; + GLuint curY = y; + GLuint height = h; do { - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, + glTexSubImage2D(GL_TEXTURE_2D, 0, x, curY, w, 1, _glFormat, _glType, src); CHECK_GL_ERROR(); - ++y; + curY++; src += pitch; - } while (--h); + } while (--height); + } + + // If we're in linear filter mode, repeat the last row/column if the real dimensions + // doesn't match the texture dimensions. + if (_filter == GL_LINEAR) { + if (_realWidth != _textureWidth && x + w == _realWidth) { + const byte *src = (const byte *)buf + (w - 1) * _bytesPerPixel; + GLuint curY = y; + GLuint height = h; + + do { + glTexSubImage2D(GL_TEXTURE_2D, 0, x + w, + curY, 1, 1, _glFormat, _glType, src); CHECK_GL_ERROR(); + + curY++; + src += pitch; + } while (--height); + } + + if (_realHeight != _textureHeight && y + h == _realHeight) { + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y + h, + w, 1, _glFormat, _glType, (const byte *)buf + pitch * (h - 1)); CHECK_GL_ERROR(); + } } } |