2002-06-17 13:16:51 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 The ScummVM project
|
2002-06-17 13:16:51 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
#include "sdl-common.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
#include "common/scaler.h"
|
2002-10-22 00:58:48 +00:00
|
|
|
#include "common/util.h"
|
2002-06-17 13:16:51 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2002-07-25 23:30:43 +00:00
|
|
|
int glColorTable(int, int, int, int, int, void *) { return 0; }
|
|
|
|
int glGetColorTable(int, int, int, void *) { return 0; }
|
2002-06-17 13:16:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fb2opengl.h"
|
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
class OSystem_SDL_OpenGL : public OSystem_SDL_Common {
|
2002-06-17 13:16:51 +00:00
|
|
|
public:
|
2003-04-18 01:19:30 +00:00
|
|
|
OSystem_SDL_OpenGL();
|
2002-10-22 00:58:48 +00:00
|
|
|
|
2002-06-17 13:16:51 +00:00
|
|
|
// Update the dirty areas of the screen
|
|
|
|
void update_screen();
|
|
|
|
|
|
|
|
// Set a parameter
|
|
|
|
uint32 property(int param, Property *value);
|
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
// Get the next event.
|
|
|
|
// Returns true if an event was retrieved.
|
2003-06-22 14:31:17 +00:00
|
|
|
//bool poll_event(Event *event);
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
protected:
|
|
|
|
FB2GL fb2gl;
|
2003-04-15 01:32:16 +00:00
|
|
|
int _glFlags;
|
2002-10-29 14:57:32 +00:00
|
|
|
int _glScreenStart;
|
2002-10-30 02:31:49 +00:00
|
|
|
bool _glBilinearFilter;
|
2003-04-18 01:19:30 +00:00
|
|
|
bool _usingOpenGL;
|
2002-10-25 14:56:58 +00:00
|
|
|
SDL_Surface *tmpSurface; // Used for black rectangles blitting
|
2003-06-30 02:38:56 +00:00
|
|
|
SDL_Rect tmpBlackRect; // Bottom black border
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_Rect _glWindow; // Only uses w and h (for window resizing)
|
2003-04-15 01:32:16 +00:00
|
|
|
int _glBottomOfTexture;
|
2003-06-30 02:38:56 +00:00
|
|
|
int _glBorderHeight; // Used if using black borders
|
2003-04-18 01:19:30 +00:00
|
|
|
|
|
|
|
SDL_Surface *_hwscreen; // hardware screen (=> _usingOpenGL == false)
|
|
|
|
|
|
|
|
ScalerProc *_scaler_proc;
|
2003-04-15 01:32:16 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
virtual void load_gfx_mode();
|
|
|
|
virtual void unload_gfx_mode();
|
2003-08-22 07:40:40 +00:00
|
|
|
virtual bool save_screenshot(const char *filename);
|
2003-04-15 01:32:16 +00:00
|
|
|
void hotswap_gfx_mode();
|
2002-06-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
2003-05-14 19:47:57 +00:00
|
|
|
OSystem_SDL_Common *OSystem_SDL_Common::create_intern() {
|
2002-12-13 17:21:23 +00:00
|
|
|
return new OSystem_SDL_OpenGL();
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
OSystem_SDL_OpenGL::OSystem_SDL_OpenGL()
|
|
|
|
: _hwscreen(0), _scaler_proc(0)
|
|
|
|
{
|
|
|
|
_glScreenStart = 0;
|
2003-06-30 02:38:56 +00:00
|
|
|
_glBilinearFilter = false;
|
2003-06-17 06:13:57 +00:00
|
|
|
_usingOpenGL = false; // false => Switch to filters used in the sdl.cpp version
|
2003-04-18 01:19:30 +00:00
|
|
|
_glBottomOfTexture = 256; // height is always 256
|
2003-06-30 02:38:56 +00:00
|
|
|
_glBorderHeight = 0; // Forces _glScreenStart to always be 0
|
2003-04-18 01:19:30 +00:00
|
|
|
// 640x480 resolution
|
|
|
|
_glWindow.w = 640;
|
|
|
|
_glWindow.h = 480;
|
|
|
|
}
|
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
void OSystem_SDL_OpenGL::load_gfx_mode() {
|
2002-10-25 14:56:58 +00:00
|
|
|
uint32 Rmask, Gmask, Bmask, Amask;
|
|
|
|
// I have to force 16 bit color depth with 565 ordering
|
|
|
|
// SDL_SetVideoMode sometimes doesn't accept your color depth definition
|
|
|
|
Rmask = 0xF800; // 5
|
|
|
|
Gmask = 0x07E0; // 6
|
|
|
|
Bmask = 0x001F; // 5
|
|
|
|
Amask = 0;
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_forceFull = true;
|
2003-07-20 18:53:27 +00:00
|
|
|
_mode_flags |= DF_UPDATE_EXPAND_1_PIXEL;
|
2002-10-22 00:58:48 +00:00
|
|
|
|
2002-12-13 16:15:58 +00:00
|
|
|
_tmpscreen = NULL;
|
2002-12-13 17:21:23 +00:00
|
|
|
_tmpScreenWidth = (_screenWidth + 3);
|
2003-04-18 01:19:30 +00:00
|
|
|
|
|
|
|
switch(_mode) {
|
2003-06-22 14:18:33 +00:00
|
|
|
case GFX_BILINEAR:
|
|
|
|
_usingOpenGL = true;
|
|
|
|
_mode = GFX_NORMAL;
|
|
|
|
break;
|
2003-09-14 12:52:38 +00:00
|
|
|
|
|
|
|
case GFX_NORMAL:
|
|
|
|
_scaleFactor = 1;
|
|
|
|
_scaler_proc = Normal1x;
|
|
|
|
break;
|
|
|
|
case GFX_DOUBLESIZE:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = Normal2x;
|
|
|
|
break;
|
|
|
|
case GFX_TRIPLESIZE:
|
|
|
|
_scaleFactor = 3;
|
|
|
|
_scaler_proc = Normal3x;
|
|
|
|
break;
|
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
case GFX_2XSAI:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = _2xSaI;
|
|
|
|
break;
|
|
|
|
case GFX_SUPER2XSAI:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = Super2xSaI;
|
|
|
|
break;
|
|
|
|
case GFX_SUPEREAGLE:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = SuperEagle;
|
|
|
|
break;
|
|
|
|
case GFX_ADVMAME2X:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = AdvMame2x;
|
|
|
|
break;
|
2003-05-13 15:58:27 +00:00
|
|
|
case GFX_ADVMAME3X:
|
|
|
|
_scaleFactor = 3;
|
|
|
|
_scaler_proc = AdvMame3x;
|
|
|
|
break;
|
2003-09-27 21:20:00 +00:00
|
|
|
case GFX_HQ2X:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = HQ2x;
|
|
|
|
break;
|
|
|
|
case GFX_HQ3X:
|
|
|
|
_scaleFactor = 3;
|
|
|
|
_scaler_proc = HQ3x;
|
|
|
|
break;
|
2003-04-18 01:19:30 +00:00
|
|
|
case GFX_TV2X:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = TV2x;
|
|
|
|
break;
|
|
|
|
case GFX_DOTMATRIX:
|
|
|
|
_scaleFactor = 2;
|
|
|
|
_scaler_proc = DotMatrix;
|
|
|
|
break;
|
2003-06-17 06:13:57 +00:00
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
default:
|
2003-06-17 06:13:57 +00:00
|
|
|
error("unknown gfx mode %d", _mode);
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
2003-09-14 12:52:38 +00:00
|
|
|
|
2003-06-30 02:38:56 +00:00
|
|
|
if (_mode != GFX_NORMAL) {
|
2003-09-14 12:52:38 +00:00
|
|
|
_usingOpenGL = false;
|
2003-06-30 02:38:56 +00:00
|
|
|
}
|
2003-09-14 12:52:38 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
//
|
|
|
|
// Create the surface that contains the 8 bit game data
|
|
|
|
//
|
2002-09-28 16:19:28 +00:00
|
|
|
_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0);
|
|
|
|
if (_screen == NULL)
|
2002-10-22 00:58:48 +00:00
|
|
|
error("_screen failed");
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
//
|
|
|
|
// Create the surface that contains the scaled graphics in 16 bit mode
|
|
|
|
//
|
2003-04-18 01:19:30 +00:00
|
|
|
if (_usingOpenGL) {
|
|
|
|
|
2003-06-20 10:59:22 +00:00
|
|
|
_glFlags = FB2GL_NO_320 | FB2GL_RGBA | FB2GL_16BIT;
|
2003-04-18 01:19:30 +00:00
|
|
|
if (_full_screen) {
|
2003-06-20 10:59:22 +00:00
|
|
|
_glFlags |= FB2GL_FS;
|
2003-04-18 01:19:30 +00:00
|
|
|
_glScreenStart = 0;
|
|
|
|
}
|
2003-06-30 02:38:56 +00:00
|
|
|
|
|
|
|
// Note: Our GL screen is vertically stretched (yfix = 15).
|
|
|
|
// That makes visible only 320x240 of the GL screen.
|
|
|
|
// 320x240 visible in GL screen => yfix = 15
|
|
|
|
// 320x200 visible in GL screen => yfix = 72
|
|
|
|
int yfix = 15;
|
|
|
|
_glBorderHeight = 0;
|
|
|
|
if (_screenHeight == 200) {
|
|
|
|
// If we are not using borders, we want 320x200 visible
|
|
|
|
yfix = _glScreenStart? 15: 72;
|
|
|
|
// 20 (top) + 200 (height) + 20 (bottom) = 240
|
|
|
|
_glBorderHeight = 20;
|
|
|
|
}
|
2003-04-18 01:19:30 +00:00
|
|
|
// _glWindow defines the resolution
|
2003-06-30 02:38:56 +00:00
|
|
|
fb2gl.init(_glWindow.w, _glWindow.h, 0, yfix, _glFlags);
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2003-06-22 11:55:40 +00:00
|
|
|
} else { // SDL backend
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2003-06-22 12:30:58 +00:00
|
|
|
_hwscreen = SDL_SetVideoMode(_screenWidth * _scaleFactor, (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor, 16,
|
|
|
|
_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
|
2003-04-18 01:19:30 +00:00
|
|
|
);
|
|
|
|
if (_hwscreen == NULL)
|
|
|
|
error("_hwscreen failed");
|
|
|
|
|
|
|
|
// Distinguish 555 and 565 mode
|
|
|
|
if (_hwscreen->format->Rmask == 0x7C00)
|
2003-09-21 12:10:32 +00:00
|
|
|
InitScalers(555);
|
2003-04-18 01:19:30 +00:00
|
|
|
else
|
2003-09-21 12:10:32 +00:00
|
|
|
InitScalers(565);
|
2002-10-29 14:57:32 +00:00
|
|
|
}
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
//
|
|
|
|
// Create the surface used for the graphics in 16 bit before scaling, and also the overlay
|
|
|
|
//
|
|
|
|
|
|
|
|
// Need some extra bytes around when using 2xSaI
|
2003-03-06 18:30:44 +00:00
|
|
|
uint16 *tmp_screen = (uint16 *)calloc(_tmpScreenWidth * (_screenHeight + 3),sizeof(uint16));
|
2003-04-18 01:19:30 +00:00
|
|
|
|
|
|
|
if (_usingOpenGL) {
|
|
|
|
_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
|
|
|
|
_tmpScreenWidth,
|
|
|
|
_screenHeight + 3,
|
|
|
|
16,
|
|
|
|
_tmpScreenWidth * 2,
|
2002-10-25 14:56:58 +00:00
|
|
|
Rmask,
|
|
|
|
Gmask,
|
|
|
|
Bmask,
|
|
|
|
Amask);
|
2003-07-05 13:41:14 +00:00
|
|
|
|
|
|
|
tmpBlackRect.x = 0;
|
|
|
|
tmpBlackRect.y = 0;
|
|
|
|
tmpBlackRect.w = _screenWidth;
|
|
|
|
tmpBlackRect.h = 256-_screenHeight-_glScreenStart;
|
|
|
|
|
|
|
|
if (!_adjustAspectRatio) {
|
|
|
|
// Don't use the whole screen (black borders)
|
|
|
|
fb2gl.init(0, 0, 0, 15, _glFlags);
|
|
|
|
_glScreenStart = _glBorderHeight;
|
|
|
|
|
|
|
|
// Top black border
|
|
|
|
SDL_Rect blackrect = {
|
|
|
|
0,
|
|
|
|
0, // _glScreenStart,
|
|
|
|
_screenWidth,
|
|
|
|
_newShakePos + _glScreenStart
|
|
|
|
};
|
|
|
|
|
|
|
|
SDL_FillRect(tmpSurface, &blackrect, 0);
|
|
|
|
fb2gl.blit16(tmpSurface, 1, &blackrect, 0, 0);
|
|
|
|
|
|
|
|
// Bottom black border
|
|
|
|
int _glBottomOfGameScreen = _screenHeight +
|
|
|
|
_glScreenStart + _currentShakePos;
|
|
|
|
|
|
|
|
tmpBlackRect.h = _glBottomOfTexture -
|
|
|
|
_glBottomOfGameScreen;
|
|
|
|
|
|
|
|
SDL_FillRect(tmpSurface, &tmpBlackRect, 0);
|
|
|
|
fb2gl.blit16(tmpSurface, 1, &tmpBlackRect, 0,
|
|
|
|
_glBottomOfGameScreen);
|
|
|
|
} else {
|
|
|
|
// Use the whole screen
|
|
|
|
fb2gl.init(0, 0, 0, 72, _glFlags);
|
|
|
|
_glScreenStart = 0;
|
|
|
|
}
|
|
|
|
|
2003-06-22 11:55:40 +00:00
|
|
|
} else { // SDL backend
|
2003-04-18 01:19:30 +00:00
|
|
|
_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
|
|
|
|
_tmpScreenWidth,
|
|
|
|
_screenHeight + 3,
|
|
|
|
16,
|
|
|
|
_tmpScreenWidth * 2,
|
|
|
|
_hwscreen->format->Rmask,
|
|
|
|
_hwscreen->format->Gmask,
|
|
|
|
_hwscreen->format->Bmask,
|
|
|
|
_hwscreen->format->Amask);
|
|
|
|
}
|
2002-10-22 00:58:48 +00:00
|
|
|
|
2002-10-25 14:56:58 +00:00
|
|
|
tmpSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth,
|
2002-10-25 03:13:56 +00:00
|
|
|
// 320x256 texture (black end)
|
2002-10-29 14:57:32 +00:00
|
|
|
256-_screenHeight-_glScreenStart,
|
2002-10-25 03:13:56 +00:00
|
|
|
16,
|
2002-10-25 14:56:58 +00:00
|
|
|
Rmask,
|
|
|
|
Gmask,
|
|
|
|
Bmask,
|
|
|
|
Amask);
|
2003-07-05 13:41:14 +00:00
|
|
|
|
2002-12-13 16:15:58 +00:00
|
|
|
if (_tmpscreen == NULL)
|
|
|
|
error("_tmpscreen failed");
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
// keyboard cursor control, some other better place for it?
|
|
|
|
km.x_max = _screenWidth * _scaleFactor - 1;
|
|
|
|
km.y_max = _screenHeight * _scaleFactor - 1;
|
|
|
|
km.delay_time = 25;
|
|
|
|
km.last_time = 0;
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
void OSystem_SDL_OpenGL::unload_gfx_mode() {
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_screen) {
|
|
|
|
SDL_FreeSurface(_screen);
|
|
|
|
_screen = NULL;
|
2002-08-24 10:41:32 +00:00
|
|
|
}
|
2003-04-18 01:19:30 +00:00
|
|
|
if (_hwscreen) {
|
|
|
|
SDL_FreeSurface(_hwscreen);
|
|
|
|
_hwscreen = NULL;
|
|
|
|
}
|
2002-12-13 16:15:58 +00:00
|
|
|
if (_tmpscreen) {
|
2003-03-06 18:30:44 +00:00
|
|
|
free((uint16 *)_tmpscreen->pixels);
|
2002-12-13 16:15:58 +00:00
|
|
|
SDL_FreeSurface(_tmpscreen);
|
|
|
|
_tmpscreen = NULL;
|
2002-10-22 00:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2003-04-15 01:32:16 +00:00
|
|
|
void OSystem_SDL_OpenGL::hotswap_gfx_mode() {
|
|
|
|
if (!_screen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Keep around the old _screen & _tmpscreen so we can restore the screen data
|
|
|
|
// after the mode switch.
|
|
|
|
SDL_Surface *old_screen = _screen;
|
|
|
|
SDL_Surface *old_tmpscreen = _tmpscreen;
|
|
|
|
|
|
|
|
// Release the HW screen surface
|
2003-04-18 01:19:30 +00:00
|
|
|
if (fb2gl.getScreen()) { // _usingOpenGL was true
|
2003-06-20 10:59:22 +00:00
|
|
|
SDL_FreeSurface(fb2gl.getScreen());
|
|
|
|
fb2gl.setScreen(NULL);
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
|
|
|
if (_hwscreen) {
|
2003-06-20 10:59:22 +00:00
|
|
|
SDL_FreeSurface(_hwscreen);
|
|
|
|
_hwscreen = NULL;
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
2003-04-15 01:32:16 +00:00
|
|
|
|
|
|
|
// Setup the new GFX mode
|
|
|
|
load_gfx_mode();
|
|
|
|
|
|
|
|
// reset palette
|
|
|
|
SDL_SetColors(_screen, _currentPalette, 0, 256);
|
|
|
|
|
|
|
|
// Restore old screen content
|
|
|
|
SDL_BlitSurface(old_screen, NULL, _screen, NULL);
|
|
|
|
SDL_BlitSurface(old_tmpscreen, NULL, _tmpscreen, NULL);
|
|
|
|
|
|
|
|
// Free the old surfaces
|
|
|
|
SDL_FreeSurface(old_screen);
|
|
|
|
free(old_tmpscreen->pixels);
|
|
|
|
SDL_FreeSurface(old_tmpscreen);
|
|
|
|
|
2003-09-06 20:21:54 +00:00
|
|
|
// Blit everything to the screen
|
2003-04-15 01:32:16 +00:00
|
|
|
update_screen();
|
2003-09-06 20:21:54 +00:00
|
|
|
|
|
|
|
// Make sure that an EVENT_SCREEN_CHANGED gets sent later
|
|
|
|
_modeChanged = true;
|
2003-04-15 01:32:16 +00:00
|
|
|
}
|
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
void OSystem_SDL_OpenGL::update_screen() {
|
2003-06-17 17:34:52 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends
|
2003-06-17 17:34:52 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
// If the shake position changed, fill the dirty area with blackness
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_currentShakePos != _newShakePos) {
|
2003-04-18 01:19:30 +00:00
|
|
|
if (_usingOpenGL) {
|
2003-06-30 02:38:56 +00:00
|
|
|
// Top black border
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_Rect blackrect = {
|
|
|
|
0,
|
2003-06-30 02:38:56 +00:00
|
|
|
0, // _glScreenStart,
|
2003-04-18 01:19:30 +00:00
|
|
|
_screenWidth,
|
|
|
|
_newShakePos + _glScreenStart
|
|
|
|
};
|
2002-10-25 14:56:58 +00:00
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_FillRect(tmpSurface, &blackrect, 0);
|
|
|
|
fb2gl.blit16(tmpSurface, 1, &blackrect, 0, 0);
|
2003-06-22 11:55:40 +00:00
|
|
|
} else { // SDL backend
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_Rect blackrect = {0, 0, _screenWidth * _scaleFactor, _newShakePos * _scaleFactor};
|
2003-07-21 00:01:05 +00:00
|
|
|
|
|
|
|
if (_adjustAspectRatio)
|
|
|
|
blackrect.h = real2Aspect(blackrect.h - 1) + 1;
|
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_FillRect(_hwscreen, &blackrect, 0);
|
|
|
|
}
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_currentShakePos = _newShakePos;
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
_forceFull = true;
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
// Make sure the mouse is drawn, if it should be drawn.
|
|
|
|
draw_mouse();
|
|
|
|
|
|
|
|
// Check whether the palette was changed in the meantime and update the
|
|
|
|
// screen surface accordingly.
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_paletteDirtyEnd != 0) {
|
2002-10-22 00:58:48 +00:00
|
|
|
SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart,
|
|
|
|
_paletteDirtyStart,
|
|
|
|
_paletteDirtyEnd - _paletteDirtyStart);
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
_paletteDirtyEnd = 0;
|
2002-10-22 00:58:48 +00:00
|
|
|
|
|
|
|
_forceFull = true;
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
// Force a full redraw if requested
|
|
|
|
if (_forceFull) {
|
|
|
|
_num_dirty_rects = 1;
|
|
|
|
|
|
|
|
_dirty_rect_list[0].x = 0;
|
|
|
|
_dirty_rect_list[0].y = 0;
|
|
|
|
_dirty_rect_list[0].w = _screenWidth;
|
|
|
|
_dirty_rect_list[0].h = _screenHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only draw anything if necessary
|
|
|
|
if (_num_dirty_rects > 0) {
|
|
|
|
|
|
|
|
SDL_Rect *r;
|
2003-06-19 16:16:35 +00:00
|
|
|
SDL_Rect dst;
|
2003-04-18 01:19:30 +00:00
|
|
|
uint32 srcPitch, dstPitch;
|
2002-10-22 00:58:48 +00:00
|
|
|
SDL_Rect *last_rect = _dirty_rect_list + _num_dirty_rects;
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2003-06-19 16:16:35 +00:00
|
|
|
|
|
|
|
if (_usingOpenGL) {
|
|
|
|
|
|
|
|
if (!_overlayVisible) {
|
|
|
|
for (r = _dirty_rect_list; r != last_rect; ++r) {
|
|
|
|
dst = *r;
|
|
|
|
dst.x++; // Shift rect by one since 2xSai needs to acces the data around
|
|
|
|
dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
|
2003-06-17 17:34:52 +00:00
|
|
|
if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
|
|
|
|
error("SDL_BlitSurface failed: %s", SDL_GetError());
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
2003-06-17 17:34:52 +00:00
|
|
|
}
|
2003-06-19 16:16:35 +00:00
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
// Almost the same thing as SDL_UpdateRects
|
|
|
|
fb2gl.blit16(
|
|
|
|
_tmpscreen,
|
|
|
|
_num_dirty_rects,
|
|
|
|
_dirty_rect_list,
|
|
|
|
0,
|
|
|
|
_currentShakePos + _glScreenStart
|
|
|
|
);
|
|
|
|
|
|
|
|
int _glBottomOfGameScreen = _screenHeight +
|
|
|
|
_glScreenStart + _currentShakePos;
|
|
|
|
|
|
|
|
// Bottom black border height
|
|
|
|
tmpBlackRect.h = _glBottomOfTexture - _glBottomOfGameScreen;
|
2003-06-30 02:38:56 +00:00
|
|
|
if (_adjustAspectRatio && tmpBlackRect.h > 0) {
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_FillRect(tmpSurface, &tmpBlackRect, 0);
|
|
|
|
fb2gl.blit16(tmpSurface, 1, &tmpBlackRect, 0,
|
|
|
|
_glBottomOfGameScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
fb2gl.display();
|
2003-06-19 16:16:35 +00:00
|
|
|
} else { // SDL backend
|
|
|
|
|
2003-06-22 12:30:58 +00:00
|
|
|
if (_scaler_proc == Normal1x && !_adjustAspectRatio) {
|
2003-06-19 16:16:35 +00:00
|
|
|
SDL_Surface *target = _overlayVisible ? _tmpscreen : _screen;
|
|
|
|
for (r = _dirty_rect_list; r != last_rect; ++r) {
|
|
|
|
dst = *r;
|
|
|
|
|
|
|
|
if (_overlayVisible) {
|
|
|
|
// FIXME: I don't understand why this is necessary...
|
|
|
|
dst.x--;
|
|
|
|
dst.y--;
|
|
|
|
}
|
2003-07-03 19:12:24 +00:00
|
|
|
dst.y += _currentShakePos;
|
2003-06-19 16:16:35 +00:00
|
|
|
if (SDL_BlitSurface(target, r, _hwscreen, &dst) != 0)
|
|
|
|
error("SDL_BlitSurface failed: %s", SDL_GetError());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_overlayVisible) {
|
|
|
|
for (r = _dirty_rect_list; r != last_rect; ++r) {
|
|
|
|
dst = *r;
|
|
|
|
dst.x++; // Shift rect by one since 2xSai needs to acces the data around
|
|
|
|
dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
|
|
|
|
if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
|
|
|
|
error("SDL_BlitSurface failed: %s", SDL_GetError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_LockSurface(_tmpscreen);
|
|
|
|
SDL_LockSurface(_hwscreen);
|
|
|
|
|
|
|
|
srcPitch = _tmpscreen->pitch;
|
|
|
|
dstPitch = _hwscreen->pitch;
|
|
|
|
|
|
|
|
for (r = _dirty_rect_list; r != last_rect; ++r) {
|
|
|
|
register int dst_y = r->y + _currentShakePos;
|
|
|
|
register int dst_h = 0;
|
2003-06-22 12:30:58 +00:00
|
|
|
register int orig_dst_y = 0;
|
|
|
|
|
2003-06-19 16:16:35 +00:00
|
|
|
if (dst_y < _screenHeight) {
|
|
|
|
dst_h = r->h;
|
|
|
|
if (dst_h > _screenHeight - dst_y)
|
|
|
|
dst_h = _screenHeight - dst_y;
|
|
|
|
|
|
|
|
dst_y *= _scaleFactor;
|
|
|
|
|
2003-06-22 12:30:58 +00:00
|
|
|
if (_adjustAspectRatio) {
|
|
|
|
orig_dst_y = dst_y;
|
|
|
|
dst_y = real2Aspect(dst_y);
|
|
|
|
}
|
|
|
|
|
2003-06-19 16:16:35 +00:00
|
|
|
_scaler_proc((byte *)_tmpscreen->pixels + (r->x * 2 + 2) + (r->y + 1) * srcPitch, srcPitch,
|
|
|
|
(byte *)_hwscreen->pixels + r->x * 2 * _scaleFactor + dst_y * dstPitch, dstPitch, r->w, dst_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
r->x *= _scaleFactor;
|
|
|
|
r->y = dst_y;
|
|
|
|
r->w *= _scaleFactor;
|
|
|
|
r->h = dst_h * _scaleFactor;
|
2003-06-22 12:30:58 +00:00
|
|
|
|
|
|
|
if (_adjustAspectRatio && orig_dst_y / _scaleFactor < _screenHeight)
|
|
|
|
r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y);
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 16:16:35 +00:00
|
|
|
SDL_UnlockSurface(_tmpscreen);
|
|
|
|
SDL_UnlockSurface(_hwscreen);
|
2003-04-18 01:19:30 +00:00
|
|
|
}
|
2003-06-19 16:16:35 +00:00
|
|
|
|
|
|
|
// Readjust the dirty rect list in case we are doing a full update.
|
|
|
|
// This is necessary if shaking is active.
|
|
|
|
if (_forceFull) {
|
|
|
|
_dirty_rect_list[0].y = 0;
|
2003-06-22 12:30:58 +00:00
|
|
|
_dirty_rect_list[0].h = (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor;
|
2003-06-19 16:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, blit all our changes to the screen
|
|
|
|
SDL_UpdateRects(_hwscreen, _num_dirty_rects, _dirty_rect_list);
|
2003-04-18 01:19:30 +00:00
|
|
|
} // END OF "SDL backend"
|
|
|
|
} // if (num_dirty_rects > 0) ...
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2002-10-22 00:58:48 +00:00
|
|
|
_num_dirty_rects = 0;
|
|
|
|
_forceFull = false;
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2003-06-22 14:31:17 +00:00
|
|
|
/*
|
2003-04-18 01:19:30 +00:00
|
|
|
bool OSystem_SDL_OpenGL::poll_event(Event *event) {
|
|
|
|
SDL_Event ev;
|
|
|
|
ev.type = 0;
|
|
|
|
|
2003-06-22 14:31:17 +00:00
|
|
|
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_PeepEvents(&ev, 1, SDL_GETEVENT, SDL_VIDEORESIZEMASK);
|
|
|
|
|
2003-06-22 14:18:33 +00:00
|
|
|
if (_usingOpenGL && ev.type == SDL_VIDEORESIZE) {
|
2003-04-18 01:19:30 +00:00
|
|
|
int w = ev.resize.w;
|
|
|
|
int h = ev.resize.h;
|
|
|
|
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
|
|
|
|
_glWindow.w = w;
|
|
|
|
_glWindow.h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OSystem_SDL_Common::poll_event(event);
|
|
|
|
}
|
2003-06-22 14:31:17 +00:00
|
|
|
*/
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2002-12-13 17:21:23 +00:00
|
|
|
uint32 OSystem_SDL_OpenGL::property(int param, Property *value) {
|
2002-06-17 13:16:51 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends
|
2003-07-02 15:08:46 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
if (param == PROP_TOGGLE_FULLSCREEN) {
|
2003-04-18 01:19:30 +00:00
|
|
|
if (!_usingOpenGL)
|
|
|
|
assert(_hwscreen != 0);
|
2002-06-17 13:16:51 +00:00
|
|
|
_full_screen ^= true;
|
2003-04-15 01:32:16 +00:00
|
|
|
#ifdef MACOSX
|
|
|
|
// On OS X, SDL_WM_ToggleFullScreen is currently not implemented. Worse,
|
|
|
|
// it still always returns -1. So we simply don't call it at all and
|
|
|
|
// use hotswap_gfx_mode() directly to switch to fullscreen mode.
|
|
|
|
hotswap_gfx_mode();
|
|
|
|
#else
|
2003-04-18 01:19:30 +00:00
|
|
|
SDL_Surface *_tmpScreen;
|
|
|
|
if (_usingOpenGL) {
|
|
|
|
_tmpScreen = fb2gl.getScreen();
|
|
|
|
}
|
|
|
|
else { // SDL backend
|
|
|
|
_tmpScreen = _hwscreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SDL_WM_ToggleFullScreen(_tmpScreen)) {
|
2003-04-15 01:32:16 +00:00
|
|
|
// if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode
|
|
|
|
hotswap_gfx_mode();
|
|
|
|
}
|
|
|
|
#endif
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-06-17 13:16:51 +00:00
|
|
|
return 1;
|
2003-06-22 11:55:40 +00:00
|
|
|
} else if (param == PROP_TOGGLE_ASPECT_RATIO) {
|
|
|
|
|
2003-06-22 12:30:58 +00:00
|
|
|
if (_usingOpenGL) {
|
2003-07-10 10:24:06 +00:00
|
|
|
_adjustAspectRatio ^= true;
|
2003-07-05 13:41:14 +00:00
|
|
|
if (!_adjustAspectRatio) {
|
2003-06-22 12:30:58 +00:00
|
|
|
// Don't use the whole screen (black borders)
|
|
|
|
fb2gl.init(0, 0, 0, 15, _glFlags);
|
2003-06-30 02:38:56 +00:00
|
|
|
_glScreenStart = _glBorderHeight;
|
2003-07-05 13:41:14 +00:00
|
|
|
|
2003-06-30 02:38:56 +00:00
|
|
|
// Top black border
|
|
|
|
SDL_Rect blackrect = {
|
|
|
|
0,
|
|
|
|
0, // _glScreenStart,
|
|
|
|
_screenWidth,
|
|
|
|
_newShakePos + _glScreenStart
|
|
|
|
};
|
|
|
|
|
|
|
|
SDL_FillRect(tmpSurface, &blackrect, 0);
|
|
|
|
fb2gl.blit16(tmpSurface, 1, &blackrect, 0, 0);
|
|
|
|
|
|
|
|
// Bottom black border
|
|
|
|
int _glBottomOfGameScreen = _screenHeight +
|
|
|
|
_glScreenStart + _currentShakePos;
|
|
|
|
|
|
|
|
tmpBlackRect.h = _glBottomOfTexture -
|
|
|
|
_glBottomOfGameScreen;
|
|
|
|
|
2003-06-22 12:30:58 +00:00
|
|
|
SDL_FillRect(tmpSurface, &tmpBlackRect, 0);
|
2003-06-30 02:38:56 +00:00
|
|
|
fb2gl.blit16(tmpSurface, 1, &tmpBlackRect, 0,
|
|
|
|
_glBottomOfGameScreen);
|
2003-06-22 12:30:58 +00:00
|
|
|
} else {
|
|
|
|
// Use the whole screen
|
2003-06-30 02:38:56 +00:00
|
|
|
fb2gl.init(0, 0, 0, 72, _glFlags);
|
2003-06-22 12:30:58 +00:00
|
|
|
_glScreenStart = 0;
|
|
|
|
}
|
|
|
|
|
2003-06-30 02:38:56 +00:00
|
|
|
SDL_Rect redraw = {0, 0, _screenWidth, _screenHeight};
|
|
|
|
fb2gl.blit16(_tmpscreen, 1, &redraw, 0, _glScreenStart);
|
2003-06-22 12:30:58 +00:00
|
|
|
fb2gl.display();
|
2003-06-22 11:55:40 +00:00
|
|
|
} else {
|
2003-06-22 12:30:58 +00:00
|
|
|
if (_screenHeight == 200) {
|
|
|
|
assert(_hwscreen != 0);
|
2003-07-10 10:24:06 +00:00
|
|
|
_adjustAspectRatio ^= true;
|
2003-06-22 12:30:58 +00:00
|
|
|
hotswap_gfx_mode();
|
|
|
|
}
|
2003-06-22 11:55:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (param == PROP_SET_GFX_MODE) {
|
2003-06-17 06:13:57 +00:00
|
|
|
if (value->gfx_mode > 10) { // OpenGL modes
|
2003-04-18 01:19:30 +00:00
|
|
|
if (!_usingOpenGL) {
|
|
|
|
_usingOpenGL = true;
|
|
|
|
_mode = GFX_NORMAL;
|
2003-06-30 02:38:56 +00:00
|
|
|
_scaleFactor = 1;
|
|
|
|
_scaler_proc = Normal1x;
|
2003-04-18 01:19:30 +00:00
|
|
|
hotswap_gfx_mode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-30 02:31:49 +00:00
|
|
|
switch(value->gfx_mode) {
|
2003-06-17 06:13:57 +00:00
|
|
|
case GFX_BILINEAR: // Bilinear Filtering (on/off)
|
2003-03-06 18:30:44 +00:00
|
|
|
_glBilinearFilter ^= true;
|
2003-06-19 16:33:46 +00:00
|
|
|
fb2gl.setBilinearMode(_glBilinearFilter);
|
2003-03-06 18:30:44 +00:00
|
|
|
break;
|
2003-04-18 01:19:30 +00:00
|
|
|
default: // SDL backend
|
2003-09-21 17:05:07 +00:00
|
|
|
if (value->gfx_mode >= 11)
|
|
|
|
return 0;
|
2003-04-18 01:19:30 +00:00
|
|
|
|
|
|
|
_mode = value->gfx_mode;
|
|
|
|
|
2003-06-30 02:38:56 +00:00
|
|
|
if (_usingOpenGL) {
|
|
|
|
_glBilinearFilter = false;
|
2003-04-18 01:19:30 +00:00
|
|
|
_usingOpenGL = false;
|
2003-06-30 02:38:56 +00:00
|
|
|
}
|
2003-04-18 01:19:30 +00:00
|
|
|
|
|
|
|
hotswap_gfx_mode();
|
2002-10-30 02:31:49 +00:00
|
|
|
};
|
2003-04-18 01:19:30 +00:00
|
|
|
|
2003-06-30 02:38:56 +00:00
|
|
|
/* if (_usingOpenGL) {
|
|
|
|
SDL_Rect redraw = {0, 0, _screenWidth, _screenHeight};
|
|
|
|
fb2gl.blit16(_tmpscreen, 1, &redraw, 0, _glScreenStart);
|
2003-04-18 01:19:30 +00:00
|
|
|
fb2gl.display();
|
2003-06-30 02:38:56 +00:00
|
|
|
}*/
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-10-29 14:57:32 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2002-08-24 10:41:32 +00:00
|
|
|
return OSystem_SDL_Common::property(param, value);
|
2002-06-17 13:16:51 +00:00
|
|
|
}
|
2003-08-22 07:40:40 +00:00
|
|
|
|
|
|
|
bool OSystem_SDL_OpenGL::save_screenshot(const char *filename) {
|
|
|
|
// FIXME: I don't know how to do this yet.
|
|
|
|
if (_usingOpenGL)
|
|
|
|
return false;
|
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends
|
2003-08-22 07:40:40 +00:00
|
|
|
|
|
|
|
assert(_hwscreen != NULL);
|
|
|
|
SDL_SaveBMP(_hwscreen, filename);
|
|
|
|
return true;
|
|
|
|
}
|