diff options
Diffstat (limited to 'backends/sdl/sdl_gl.cpp')
-rw-r--r-- | backends/sdl/sdl_gl.cpp | 174 |
1 files changed, 27 insertions, 147 deletions
diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index 504810c711..6675f11d01 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -32,9 +32,9 @@ int glGetColorTable(int, int, int, void *) { return 0; } #include "fb2opengl.h" -class OSystem_SDL_Normal : public OSystem_SDL_Common { +class OSystem_SDL_OpenGL : public OSystem_SDL_Common { public: - OSystem_SDL_Normal() : _tmpscreen(0), _overlay_visible(false) { _glScreenStart = 0; _glBilinearFilter = true; } + OSystem_SDL_OpenGL() { _glScreenStart = 0; _glBilinearFilter = true; } // Set colors of the palette void set_palette(const byte *colors, uint start, uint num); @@ -60,27 +60,16 @@ protected: SDL_Surface *tmpSurface; // Used for black rectangles blitting SDL_Rect tmpBlackRect; // Black rectangle at end of the GL screen - typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height); - - SDL_Surface *_tmpscreen; // temporary screen (for scalers/overlay) - bool _overlay_visible; - - virtual void draw_mouse(); - virtual void undraw_mouse(); - virtual void load_gfx_mode(); virtual void unload_gfx_mode(); void hotswap_gfx_mode(); - - int TMP_SCREEN_WIDTH; }; OSystem_SDL_Common *OSystem_SDL_Common::create() { - return new OSystem_SDL_Normal(); + return new OSystem_SDL_OpenGL(); } -void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) { +void OSystem_SDL_OpenGL::set_palette(const byte *colors, uint start, uint num) { const byte *b = colors; uint i; SDL_Color *base = _currentPalette + start; @@ -98,116 +87,7 @@ void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) { _paletteDirtyEnd = start + num; } -void OSystem_SDL_Normal::draw_mouse() { - if (!_overlay_visible) { - OSystem_SDL_Common::draw_mouse(); - } - - if (_mouseDrawn || !_mouseVisible) - return; - - int x = _mouseCurState.x - _mouseHotspotX; - int y = _mouseCurState.y - _mouseHotspotY; - int w = _mouseCurState.w; - int h = _mouseCurState.h; - byte color; - byte *src = _mouseData; // Image representing the mouse - uint16 *bak = (uint16*)_mouseBackup; // Surface used to backup the area obscured by the mouse - uint16 *dst; // Surface we are drawing into - - // clip the mouse rect, and addjust the src pointer accordingly - if (x < 0) { - w += x; - src -= x; - x = 0; - } - if (y < 0) { - h += y; - src -= y * _mouseCurState.w; - y = 0; - } - - // Quick check to see if anything has to be drawn at all - if (w <= 0 || h <= 0) - return; - - if (w > _screenWidth - x) - w = _screenWidth - x; - if (h > _screenHeight - y) - h = _screenHeight - y; - - // Store the bounding box so that undraw mouse can restore the area the - // mouse currently covers to its original content. - _mouseOldState.x = x; - _mouseOldState.y = y; - _mouseOldState.w = w; - _mouseOldState.h = h; - - // Draw the mouse cursor; backup the covered area in "bak" - - if (SDL_LockSurface(_tmpscreen) == -1) - error("SDL_LockSurface failed: %s.\n", SDL_GetError()); - - // Mark as dirty - add_dirty_rect(x, y, w, h); - - dst = (uint16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1); - while (h > 0) { - int width = w; - while (width > 0) { - *bak++ = *dst; - color = *src++; - if (color != 0xFF) // 0xFF = transparent, don't draw - *dst = RBGToColor(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b); - dst++; - width--; - } - src += _mouseCurState.w - w; - bak += MAX_MOUSE_W - w; - dst += TMP_SCREEN_WIDTH - w; - h--; - } - - SDL_UnlockSurface(_tmpscreen); - - // Finally, set the flag to indicate the mouse has been drawn - _mouseDrawn = true; -} - -void OSystem_SDL_Normal::undraw_mouse() { - if (!_overlay_visible) { - OSystem_SDL_Common::undraw_mouse(); - } - - if (!_mouseDrawn) - return; - _mouseDrawn = false; - - if (SDL_LockSurface(_tmpscreen) == -1) - error("SDL_LockSurface failed: %s.\n", SDL_GetError()); - - uint16 *dst, *bak = (uint16 *)_mouseBackup; - const int old_mouse_x = _mouseOldState.x; - const int old_mouse_y = _mouseOldState.y; - const int old_mouse_w = _mouseOldState.w; - const int old_mouse_h = _mouseOldState.h; - int x, y; - - // No need to do clipping here, since draw_mouse() did that already - - dst = (uint16 *)_tmpscreen->pixels + (old_mouse_y+1) * TMP_SCREEN_WIDTH + (old_mouse_x+1); - for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) { - for (x = 0; x < old_mouse_w; ++x) { - dst[x] = bak[x]; - } - } - - add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h); - - SDL_UnlockSurface(_tmpscreen); -} - -void OSystem_SDL_Normal::load_gfx_mode() { +void OSystem_SDL_OpenGL::load_gfx_mode() { 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 @@ -221,7 +101,7 @@ void OSystem_SDL_Normal::load_gfx_mode() { _scaleFactor = 2; _tmpscreen = NULL; - TMP_SCREEN_WIDTH = (_screenWidth + 3); + _tmpScreenWidth = (_screenWidth + 3); // // Create the surface that contains the 8 bit game data @@ -251,9 +131,9 @@ void OSystem_SDL_Normal::load_gfx_mode() { // // Need some extra bytes around when using 2xSaI - uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(_screenHeight+3),sizeof(uint16)); + uint16 *tmp_screen = (uint16*)calloc(_tmpScreenWidth*(_screenHeight+3),sizeof(uint16)); _tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen, - TMP_SCREEN_WIDTH, _screenHeight + 3, 16, TMP_SCREEN_WIDTH*2, + _tmpScreenWidth, _screenHeight + 3, 16, _tmpScreenWidth*2, Rmask, Gmask, Bmask, @@ -284,7 +164,7 @@ void OSystem_SDL_Normal::load_gfx_mode() { } -void OSystem_SDL_Normal::unload_gfx_mode() { +void OSystem_SDL_OpenGL::unload_gfx_mode() { if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; @@ -297,7 +177,7 @@ void OSystem_SDL_Normal::unload_gfx_mode() { } } -void OSystem_SDL_Normal::update_screen() { +void OSystem_SDL_OpenGL::update_screen() { // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { @@ -343,7 +223,7 @@ void OSystem_SDL_Normal::update_screen() { SDL_Rect *last_rect = _dirty_rect_list + _num_dirty_rects; // Convert appropriate parts of the 8bpp image into 16bpp - if (!_overlay_visible) { + if (!_overlayVisible) { SDL_Rect dst; for(r = _dirty_rect_list; r != last_rect; ++r) { dst = *r; @@ -370,7 +250,7 @@ void OSystem_SDL_Normal::update_screen() { _forceFull = false; } -void OSystem_SDL_Normal::hotswap_gfx_mode() { +void OSystem_SDL_OpenGL::hotswap_gfx_mode() { /* We allocate a screen sized bitmap which contains a "backup" * of the screen data during the change. Then we draw that to * the new screen right after it's setup. @@ -393,7 +273,7 @@ void OSystem_SDL_Normal::hotswap_gfx_mode() { update_screen(); } -uint32 OSystem_SDL_Normal::property(int param, Property *value) { +uint32 OSystem_SDL_OpenGL::property(int param, Property *value) { if (param == PROP_TOGGLE_FULLSCREEN) { _full_screen ^= true; @@ -460,27 +340,27 @@ uint32 OSystem_SDL_Normal::property(int param, Property *value) { } -void OSystem_SDL_Normal::show_overlay() +void OSystem_SDL_OpenGL::show_overlay() { // hide the mouse undraw_mouse(); - _overlay_visible = true; + _overlayVisible = true; clear_overlay(); } -void OSystem_SDL_Normal::hide_overlay() +void OSystem_SDL_OpenGL::hide_overlay() { // hide the mouse undraw_mouse(); - _overlay_visible = false; + _overlayVisible = false; _forceFull = true; } -void OSystem_SDL_Normal::clear_overlay() +void OSystem_SDL_OpenGL::clear_overlay() { - if (!_overlay_visible) + if (!_overlayVisible) return; // hide the mouse @@ -499,9 +379,9 @@ void OSystem_SDL_Normal::clear_overlay() _forceFull = true; } -void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch) +void OSystem_SDL_OpenGL::grab_overlay(int16 *buf, int pitch) { - if (!_overlay_visible) + if (!_overlayVisible) return; if (_tmpscreen == NULL) @@ -513,20 +393,20 @@ void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch) if (SDL_LockSurface(_tmpscreen) == -1) error("SDL_LockSurface failed: %s.\n", SDL_GetError()); - int16 *src = (int16 *)_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1; + int16 *src = (int16 *)_tmpscreen->pixels + _tmpScreenWidth + 1; int h = _screenHeight; do { memcpy(buf, src, _screenWidth*2); - src += TMP_SCREEN_WIDTH; + src += _tmpScreenWidth; buf += pitch; } while (--h); SDL_UnlockSurface(_tmpscreen); } -void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h) +void OSystem_SDL_OpenGL::copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h) { - if (!_overlay_visible) + if (!_overlayVisible) return; if (_tmpscreen == NULL) @@ -550,10 +430,10 @@ void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, i if (SDL_LockSurface(_tmpscreen) == -1) error("SDL_LockSurface failed: %s.\n", SDL_GetError()); - int16 *dst = (int16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1); + int16 *dst = (int16 *)_tmpscreen->pixels + (y+1) * _tmpScreenWidth + (x+1); do { memcpy(dst, buf, w*2); - dst += TMP_SCREEN_WIDTH; + dst += _tmpScreenWidth; buf += pitch; } while (--h); |