aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2013-01-24 17:39:30 -0800
committerJohannes Schickel2013-01-24 17:39:30 -0800
commitfefa3bdd3f4dce5b1d65fb73a59d5713efd52fd6 (patch)
tree33a770696f9694a95b72235dc8a73a3923e2a4cd
parentf5e43484a0cf91c048e37049f838c835d2da052c (diff)
parentfa9dd0f6c0ca61fe6d0247128e1c9ba1dd9cf0e3 (diff)
downloadscummvm-rg350-fefa3bdd3f4dce5b1d65fb73a59d5713efd52fd6.tar.gz
scummvm-rg350-fefa3bdd3f4dce5b1d65fb73a59d5713efd52fd6.tar.bz2
scummvm-rg350-fefa3bdd3f4dce5b1d65fb73a59d5713efd52fd6.zip
Merge pull request #302 from clone2727/gl-linear-fix
OPENGL: Fix linear filtering when the texture size doesn't match the real size
-rw-r--r--backends/graphics/opengl/gltexture.cpp46
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();
+ }
}
}