OPENGL: Add antialiasing, hotkey: ctrl+alt+f. Fixed minor bugs.
svn-id: r51146
This commit is contained in:
parent
0c2d90f090
commit
ef880dd5da
5 changed files with 91 additions and 23 deletions
|
@ -80,7 +80,8 @@ GLTexture::GLTexture(byte bpp, GLenum format, GLenum type)
|
||||||
_textureHeight(0),
|
_textureHeight(0),
|
||||||
_realWidth(0),
|
_realWidth(0),
|
||||||
_realHeight(0),
|
_realHeight(0),
|
||||||
_refresh(false) {
|
_refresh(false),
|
||||||
|
_filter(GL_NEAREST) {
|
||||||
|
|
||||||
// Generates the texture ID for GL
|
// Generates the texture ID for GL
|
||||||
glGenTextures(1, &_textureName); CHECK_GL_ERROR();
|
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
|
// Allocate room for the texture now, but pixel data gets uploaded
|
||||||
// later (perhaps with multiple TexSubImage2D operations).
|
// later (perhaps with multiple TexSubImage2D operations).
|
||||||
glBindTexture(GL_TEXTURE_2D, _textureName); CHECK_GL_ERROR();
|
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_MAG_FILTER, _filter); CHECK_GL_ERROR();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 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_S, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR();
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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,
|
glTexImage2D(GL_TEXTURE_2D, 0, _glFormat,
|
||||||
|
@ -131,6 +132,8 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) {
|
||||||
|
|
||||||
if (_surface.w != _textureWidth || _surface.h != _textureHeight)
|
if (_surface.w != _textureWidth || _surface.h != _textureHeight)
|
||||||
_surface.create(_textureWidth, _textureHeight, _bytesPerPixel);
|
_surface.create(_textureWidth, _textureHeight, _bytesPerPixel);
|
||||||
|
else if (_refresh)
|
||||||
|
updateBuffer(_surface.pixels, _surface.pitch, 0, 0, _surface.w, _surface.h);
|
||||||
|
|
||||||
_refresh = false;
|
_refresh = false;
|
||||||
}
|
}
|
||||||
|
@ -141,12 +144,14 @@ void GLTexture::updateBuffer(const void *buf, int pitch, GLuint x, GLuint y, GLu
|
||||||
if (static_cast<int>(w) * _bytesPerPixel == pitch) {
|
if (static_cast<int>(w) * _bytesPerPixel == pitch) {
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
|
||||||
_glFormat, _glType, buf); CHECK_GL_ERROR();
|
_glFormat, _glType, buf); CHECK_GL_ERROR();
|
||||||
|
if (buf != _surface.pixels)
|
||||||
memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
|
memcpy(_surface.getBasePtr(x, y), buf, h * pitch);
|
||||||
} else {
|
} else {
|
||||||
const byte* src = static_cast<const byte*>(buf);
|
const byte* src = static_cast<const byte*>(buf);
|
||||||
do {
|
do {
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
|
||||||
w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
|
w, 1, _glFormat, _glType, src); CHECK_GL_ERROR();
|
||||||
|
if (buf != _surface.pixels)
|
||||||
memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
|
memcpy(_surface.getBasePtr(x, y), src, w * _bytesPerPixel);
|
||||||
++y;
|
++y;
|
||||||
src += pitch;
|
src += pitch;
|
||||||
|
|
|
@ -74,6 +74,8 @@ public:
|
||||||
GLuint getHeight() const { return _realHeight; }
|
GLuint getHeight() const { return _realHeight; }
|
||||||
GLuint getTextureName() const { return _textureName; }
|
GLuint getTextureName() const { return _textureName; }
|
||||||
|
|
||||||
|
void setFilter(GLint filter) { _filter = filter; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const byte _bytesPerPixel;
|
const byte _bytesPerPixel;
|
||||||
const GLenum _glFormat;
|
const GLenum _glFormat;
|
||||||
|
@ -86,4 +88,5 @@ protected:
|
||||||
GLuint _textureWidth;
|
GLuint _textureWidth;
|
||||||
GLuint _textureHeight;
|
GLuint _textureHeight;
|
||||||
bool _refresh;
|
bool _refresh;
|
||||||
|
GLint _filter;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
|
||||||
_videoMode.mode = OpenGL::GFX_NORMAL;
|
_videoMode.mode = OpenGL::GFX_NORMAL;
|
||||||
_videoMode.scaleFactor = 1;
|
_videoMode.scaleFactor = 1;
|
||||||
_videoMode.fullscreen = false;
|
_videoMode.fullscreen = false;
|
||||||
|
_videoMode.antialiasing = false;
|
||||||
|
|
||||||
_gamePalette = (byte *)calloc(sizeof(byte) * 4, 256);
|
_gamePalette = (byte *)calloc(sizeof(byte) * 4, 256);
|
||||||
_cursorPalette = (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) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenGLGraphicsManager::getGraphicsMode() const {
|
int OpenGLGraphicsManager::getGraphicsMode() const {
|
||||||
return OpenGL::GFX_NORMAL;
|
assert (_transactionMode == kTransactionNone);
|
||||||
|
return _videoMode.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
|
@ -131,7 +165,7 @@ void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::Pi
|
||||||
assert(_transactionMode == kTransactionActive);
|
assert(_transactionMode == kTransactionActive);
|
||||||
|
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
//avoid redundant format changes
|
// Avoid redundant format changes
|
||||||
Graphics::PixelFormat newFormat;
|
Graphics::PixelFormat newFormat;
|
||||||
if (!format)
|
if (!format)
|
||||||
newFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0);
|
newFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0);
|
||||||
|
@ -173,6 +207,8 @@ void OpenGLGraphicsManager::beginGFXTransaction() {
|
||||||
_transactionDetails.sizeChanged = false;
|
_transactionDetails.sizeChanged = false;
|
||||||
_transactionDetails.needHotswap = false;
|
_transactionDetails.needHotswap = false;
|
||||||
_transactionDetails.needUpdatescreen = false;
|
_transactionDetails.needUpdatescreen = false;
|
||||||
|
_transactionDetails.newContext = false;
|
||||||
|
_transactionDetails.filterChanged = false;
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
_transactionDetails.formatChanged = false;
|
_transactionDetails.formatChanged = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -237,14 +273,15 @@ OSystem::TransactionError OpenGLGraphicsManager::endGFXTransaction() {
|
||||||
errors |= endGFXTransaction();
|
errors |= endGFXTransaction();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//setGraphicsModeIntern();
|
clearOverlay();
|
||||||
//clearOverlay();
|
|
||||||
|
|
||||||
_videoMode.setup = true;
|
_videoMode.setup = true;
|
||||||
_screenChangeCount++;
|
_screenChangeCount++;
|
||||||
}
|
}
|
||||||
|
} else if (_transactionDetails.filterChanged) {
|
||||||
|
loadTextures();
|
||||||
|
internUpdateScreen();
|
||||||
} else if (_transactionDetails.needUpdatescreen) {
|
} else if (_transactionDetails.needUpdatescreen) {
|
||||||
//setGraphicsModeIntern();
|
|
||||||
internUpdateScreen();
|
internUpdateScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,34 +616,44 @@ void OpenGLGraphicsManager::initGL() {
|
||||||
glLoadIdentity(); CHECK_GL_ERROR();
|
glLoadIdentity(); CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLGraphicsManager::loadGFXMode() {
|
void OpenGLGraphicsManager::loadTextures() {
|
||||||
// Initialize OpenGL settings
|
|
||||||
initGL();
|
|
||||||
|
|
||||||
if (!_gameTexture) {
|
if (!_gameTexture) {
|
||||||
byte bpp;
|
byte bpp;
|
||||||
GLenum format;
|
GLenum format;
|
||||||
GLenum type;
|
GLenum type;
|
||||||
getGLPixelFormat(_screenFormat, bpp, format, type);
|
getGLPixelFormat(_screenFormat, bpp, format, type);
|
||||||
_gameTexture = new GLTexture(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);
|
_overlayFormat = Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0);
|
||||||
|
|
||||||
if (!_overlayTexture)
|
if (!_overlayTexture)
|
||||||
_overlayTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
|
_overlayTexture = new GLTexture(2, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4);
|
||||||
else if (_transactionDetails.newContext)
|
|
||||||
_overlayTexture->refresh();
|
|
||||||
|
|
||||||
if (!_cursorTexture)
|
if (!_cursorTexture)
|
||||||
_cursorTexture = new GLTexture(4, GL_RGBA, GL_UNSIGNED_BYTE);
|
_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();
|
_cursorTexture->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
_gameTexture->allocBuffer(_videoMode.screenWidth, _videoMode.screenHeight);
|
_gameTexture->allocBuffer(_videoMode.screenWidth, _videoMode.screenHeight);
|
||||||
_overlayTexture->allocBuffer(_videoMode.overlayWidth, _videoMode.overlayHeight);
|
_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();
|
internUpdateScreen();
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void initGL();
|
virtual void initGL();
|
||||||
|
virtual void loadTextures();
|
||||||
|
|
||||||
//
|
//
|
||||||
// GFX and video
|
// GFX and video
|
||||||
|
@ -117,6 +118,7 @@ protected:
|
||||||
bool needHotswap;
|
bool needHotswap;
|
||||||
bool needUpdatescreen;
|
bool needUpdatescreen;
|
||||||
bool newContext;
|
bool newContext;
|
||||||
|
bool filterChanged;
|
||||||
#ifdef USE_RGB_COLOR
|
#ifdef USE_RGB_COLOR
|
||||||
bool formatChanged;
|
bool formatChanged;
|
||||||
#endif
|
#endif
|
||||||
|
@ -133,6 +135,7 @@ protected:
|
||||||
|
|
||||||
int mode;
|
int mode;
|
||||||
int scaleFactor;
|
int scaleFactor;
|
||||||
|
bool antialiasing;
|
||||||
|
|
||||||
int screenWidth, screenHeight;
|
int screenWidth, screenHeight;
|
||||||
int overlayWidth, overlayHeight;
|
int overlayWidth, overlayHeight;
|
||||||
|
|
|
@ -165,7 +165,7 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_oldVideoMode.fullscreen != _videoMode.fullscreen)
|
if (_oldVideoMode.fullscreen || _videoMode.fullscreen)
|
||||||
_transactionDetails.newContext = true;
|
_transactionDetails.newContext = true;
|
||||||
|
|
||||||
_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
|
_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
|
||||||
|
@ -224,6 +224,15 @@ bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
|
||||||
return true;
|
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;
|
SDLKey sdlKey = (SDLKey)key;
|
||||||
|
|
||||||
// Increase/decrease the scale factor
|
// Increase/decrease the scale factor
|
||||||
|
@ -235,6 +244,7 @@ bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
|
||||||
beginGFXTransaction();
|
beginGFXTransaction();
|
||||||
setScale(factor);
|
setScale(factor);
|
||||||
endGFXTransaction();
|
endGFXTransaction();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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 ||
|
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);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue