aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorAlejandro Marzini2010-07-22 15:36:50 +0000
committerAlejandro Marzini2010-07-22 15:36:50 +0000
commitef880dd5daa205aefd425dae5dcf32e94d1f6723 (patch)
tree7480b67f3e88c63970b9b2dd2dba0c00f835a205 /backends/graphics
parent0c2d90f090ab439d3b53ca6aaab5027d527716ba (diff)
downloadscummvm-rg350-ef880dd5daa205aefd425dae5dcf32e94d1f6723.tar.gz
scummvm-rg350-ef880dd5daa205aefd425dae5dcf32e94d1f6723.tar.bz2
scummvm-rg350-ef880dd5daa205aefd425dae5dcf32e94d1f6723.zip
OPENGL: Add antialiasing, hotkey: ctrl+alt+f. Fixed minor bugs.
svn-id: r51146
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/opengl/gltexture.cpp15
-rw-r--r--backends/graphics/opengl/gltexture.h3
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp77
-rw-r--r--backends/graphics/opengl/opengl-graphics.h3
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp16
5 files changed, 91 insertions, 23 deletions
diff --git a/backends/graphics/opengl/gltexture.cpp b/backends/graphics/opengl/gltexture.cpp
index bd2d67edf5..c5dc2f2507 100644
--- a/backends/graphics/opengl/gltexture.cpp
+++ b/backends/graphics/opengl/gltexture.cpp
@@ -80,7 +80,8 @@ GLTexture::GLTexture(byte bpp, GLenum format, GLenum type)
_textureHeight(0),
_realWidth(0),
_realHeight(0),
- _refresh(false) {
+ _refresh(false),
+ _filter(GL_NEAREST) {
// Generates the texture ID for GL
glGenTextures(1, &_textureName); CHECK_GL_ERROR();
@@ -122,8 +123,8 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) {
// Allocate room for the texture now, but pixel data gets uploaded
// later (perhaps with multiple TexSubImage2D operations).
glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR();
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _filter); CHECK_GL_ERROR();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _filter); CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
glTexImage2D(GL_TEXTURE_2D, 0, _glFormat,
@@ -131,6 +132,8 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) {
if (_surface.w != _textureWidth || _surface.h != _textureHeight)
_surface.create(_textureWidth, _textureHeight, _bytesPerPixel);
+ else if (_refresh)
+ updateBuffer(_surface.pixels, _surface.pitch, 0, 0, _surface.w, _surface.h);
_refresh = false;
}
@@ -141,13 +144,15 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu
if (static_cast<int>(w) * _bytesPerPixel == pitch) {
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
_glFormat, _glType, buf); CHECK_GL_ERROR();
- memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
+ if (buf != _surface.pixels)
+ memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
} else {
const byte* src = static_cast<const byte*>(buf);
do {
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
- memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
+ if (buf != _surface.pixels)
+ memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
++y;
src += pitch;
} while (--h);
diff --git a/backends/graphics/opengl/gltexture.h b/backends/graphics/opengl/gltexture.h
index d689e02951..4a3ba5da8e 100644
--- a/backends/graphics/opengl/gltexture.h
+++ b/backends/graphics/opengl/gltexture.h
@@ -74,6 +74,8 @@ public:
GLuint getHeight() const { return _realHeight; }
GLuint getTextureName() const { return _textureName; }
+ void setFilter(GLint filter) { _filter = filter; }
+
protected:
const byte _bytesPerPixel;
const GLenum _glFormat;
@@ -86,4 +88,5 @@ protected:
GLuint _textureWidth;
GLuint _textureHeight;
bool _refresh;
+ GLint _filter;
};
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 1d378a4d11..8cc1e1ac29 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -48,6 +48,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
_videoMode.mode = OpenGL::GFX_NORMAL;
_videoMode.scaleFactor = 1;
_videoMode.fullscreen = false;
+ _videoMode.antialiasing = false;
_gamePalette = (byte *)calloc(sizeof(byte) * 4, 256);
_cursorPalette = (byte *)calloc(sizeof(byte) * 4, 256);
@@ -112,11 +113,44 @@ int OpenGLGraphicsManager::getDefaultGraphicsMode() const {
}
bool OpenGLGraphicsManager::setGraphicsMode(int mode) {
+ assert(_transactionMode == kTransactionActive);
+
+ if (_oldVideoMode.setup && _oldVideoMode.mode == mode)
+ return true;
+
+ int newScaleFactor = 1;
+
+ switch (mode) {
+ case OpenGL::GFX_NORMAL:
+ newScaleFactor = 1;
+ break;
+#ifdef USE_SCALERS
+ case OpenGL::GFX_DOUBLESIZE:
+ newScaleFactor = 2;
+ break;
+ case OpenGL::GFX_TRIPLESIZE:
+ newScaleFactor = 3;
+ break;
+#endif
+ default:
+ warning("unknown gfx mode %d", mode);
+ return false;
+ }
+
+ if (_oldVideoMode.setup && _oldVideoMode.scaleFactor != newScaleFactor)
+ _transactionDetails.needHotswap = true;
+
+ _transactionDetails.needUpdatescreen = true;
+
+ _videoMode.mode = mode;
+ _videoMode.scaleFactor = newScaleFactor;
+
return true;
}
int OpenGLGraphicsManager::getGraphicsMode() const {
- return OpenGL::GFX_NORMAL;
+ assert (_transactionMode == kTransactionNone);
+ return _videoMode.mode;
}
#ifdef USE_RGB_COLOR
@@ -131,7 +165,7 @@ void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::Pi
assert(_transactionMode == kTransactionActive);
#ifdef USE_RGB_COLOR
- //avoid redundant format changes
+ // Avoid redundant format changes
Graphics::PixelFormat newFormat;
if (!format)
newFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0);
@@ -173,6 +207,8 @@ void OpenGLGraphicsManager::beginGFXTransaction() {
_transactionDetails.sizeChanged = false;
_transactionDetails.needHotswap = false;
_transactionDetails.needUpdatescreen = false;
+ _transactionDetails.newContext = false;
+ _transactionDetails.filterChanged = false;
#ifdef USE_RGB_COLOR
_transactionDetails.formatChanged = false;
#endif
@@ -237,14 +273,15 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() {
errors |= endGFXTransaction();
}
} else {
- //setGraphicsModeIntern();
- //clearOverlay();
+ clearOverlay();
_videoMode.setup = true;
_screenChangeCount++;
}
+ } else if (_transactionDetails.filterChanged) {
+ loadTextures();
+ internUpdateScreen();
} else if (_transactionDetails.needUpdatescreen) {
- //setGraphicsModeIntern();
internUpdateScreen();
}
@@ -579,34 +616,44 @@ void OpenGLGraphicsManager::initGL() {
glLoadIdentity(); CHECK_GL_ERROR();
}
-bool OpenGLGraphicsManager::loadGFXMode() {
- // Initialize OpenGL settings
- initGL();
-
+void OpenGLGraphicsManager::loadTextures() {
if (!_gameTexture) {
byte bpp;
GLenum format;
GLenum type;
getGLPixelFormat(_screenFormat, bpp, format, type);
_gameTexture = new GLTexture(bpp, format, type);
- } else if (_transactionDetails.newContext)
- _gameTexture->refresh();
+ }
_overlayFormat = Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
if (!_overlayTexture)
_overlayTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
- else if (_transactionDetails.newContext)
- _overlayTexture->refresh();
if (!_cursorTexture)
_cursorTexture = new GLTexture(4, GL_RGBA, GL_UNSIGNED_BYTE);
- else if (_transactionDetails.newContext)
+
+ GLint filter = _videoMode.antialiasing ? GL_LINEAR : GL_NEAREST;
+ _gameTexture->setFilter(filter);
+ _overlayTexture->setFilter(filter);
+ _cursorTexture->setFilter(filter);
+
+ if (_transactionDetails.newContext || _transactionDetails.filterChanged) {
+ _gameTexture->refresh();
+ _overlayTexture->refresh();
_cursorTexture->refresh();
+ }
_gameTexture->allocBuffer(_videoMode.screenWidth, _videoMode.screenHeight);
_overlayTexture->allocBuffer(_videoMode.overlayWidth, _videoMode.overlayHeight);
- _cursorTexture->allocBuffer(16, 16);
+ _cursorTexture->allocBuffer(_cursorState.w, _cursorState.h);
+}
+
+bool OpenGLGraphicsManager::loadGFXMode() {
+ // Initialize OpenGL settings
+ initGL();
+
+ loadTextures();
internUpdateScreen();
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index 038f658bb9..e366216a8c 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -102,6 +102,7 @@ public:
protected:
virtual void initGL();
+ virtual void loadTextures();
//
// GFX and video
@@ -117,6 +118,7 @@ protected:
bool needHotswap;
bool needUpdatescreen;
bool newContext;
+ bool filterChanged;
#ifdef USE_RGB_COLOR
bool formatChanged;
#endif
@@ -133,6 +135,7 @@ protected:
int mode;
int scaleFactor;
+ bool antialiasing;
int screenWidth, screenHeight;
int overlayWidth, overlayHeight;
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index fe3662a520..4b77cf6f17 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -165,7 +165,7 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
}
}
- if (_oldVideoMode.fullscreen != _videoMode.fullscreen)
+ if (_oldVideoMode.fullscreen || _videoMode.fullscreen)
_transactionDetails.newContext = true;
_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
@@ -224,6 +224,15 @@ bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
return true;
}*/
+ // Ctrl-Alt-f toggles antialiasing
+ if (key == 'f') {
+ beginGFXTransaction();
+ _videoMode.antialiasing = !_videoMode.antialiasing;
+ _transactionDetails.filterChanged = true;
+ endGFXTransaction();
+ return true;
+ }
+
SDLKey sdlKey = (SDLKey)key;
// Increase/decrease the scale factor
@@ -235,7 +244,8 @@ bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
beginGFXTransaction();
setScale(factor);
endGFXTransaction();
- }
+ return true;
+ }
}
return false;
}
@@ -255,7 +265,7 @@ bool OpenGLSdlGraphicsManager::isScalerHotkey(const Common::Event &event) {
const bool isScaleKey = (event.kbd.keycode == Common::KEYCODE_EQUALS || event.kbd.keycode == Common::KEYCODE_PLUS || event.kbd.keycode == Common::KEYCODE_MINUS ||
event.kbd.keycode == Common::KEYCODE_KP_PLUS || event.kbd.keycode == Common::KEYCODE_KP_MINUS);
- return (isScaleKey || event.kbd.keycode == 'a');
+ return (isScaleKey || event.kbd.keycode == 'a' || event.kbd.keycode == 'f');
}
return false;
}