From c509186c0acf605673a95bbdaf9a55bc11a77a49 Mon Sep 17 00:00:00 2001 From: stephena Date: Sun, 14 Dec 2008 21:44:06 +0000 Subject: [PATCH] Fixed crash with setting the UI palette in OpenGL mode. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1562 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/FrameBufferGL.cxx | 54 ++++++++++++----------------- stella/src/common/FrameBufferGL.hxx | 19 +++++----- stella/src/emucore/OSystem.cxx | 5 ++- stella/src/gui/Dialog.cxx | 4 +-- 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/stella/src/common/FrameBufferGL.cxx b/stella/src/common/FrameBufferGL.cxx index cf840d5b7..de36ec403 100644 --- a/stella/src/common/FrameBufferGL.cxx +++ b/stella/src/common/FrameBufferGL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferGL.cxx,v 1.114 2008-12-12 18:32:53 stephena Exp $ +// $Id: FrameBufferGL.cxx,v 1.115 2008-12-14 21:44:06 stephena Exp $ //============================================================================ #ifdef DISPLAY_OPENGL @@ -72,13 +72,21 @@ static void (APIENTRY* p_glTexParameteri)( GLenum, GLenum, GLint ); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameBufferGL::FrameBufferGL(OSystem* osystem) : FrameBuffer(osystem), - myBaseSurface(NULL), + myTiaSurface(NULL), myFilterParamName("GL_NEAREST"), myWidthScaleFactor(1.0), myHeightScaleFactor(1.0), myHaveTexRectEXT(false), myDirtyFlag(true) { + // We need a pixel format for palette value calculations + // It's done this way (vs directly accessing a FBSurfaceGL object) + // since the structure may be needed before any FBSurface's have + // be created + SDL_Surface* s = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 16, + 0x00007c00, 0x000003e0, 0x0000001f, 0x00000000); + myPixelFormat = *(s->format); + SDL_FreeSurface(s); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -340,7 +348,6 @@ cerr << "setVidMode: w = " << mode.screen_w << ", h = " << mode.screen_h << endl p_glPushMatrix(); p_glLoadIdentity(); - // Allocate GL textures cerr << "dimensions: " << endl << " basew = " << baseWidth << endl << " baseh = " << baseHeight << endl @@ -352,17 +359,18 @@ cerr << "dimensions: " << endl << " imageh = " << mode.image_h << endl << endl; - if(1)//!inUIMode) + // The framebuffer only takes responsibility for TIA surfaces + // Other surfaces (such as the ones used for dialogs) are allocated + // in the Dialog class + if(!inUIMode) { - delete myBaseSurface; - myBaseSurface = new FBSurfaceGL(*this, baseWidth, baseHeight, + delete myTiaSurface; + myTiaSurface = new FBSurfaceGL(*this, baseWidth, baseHeight, mode.image_w, mode.image_h); - } -// myOSystem->setUIPalette(); - // Old textures currently in use by various UI items need to be - // refreshed as well (only seems to be required for OSX) + // Any previously allocated textures currently in use by various UI items + // need to be refreshed as well (only seems to be required for OSX) reloadSurfaces(); // Make sure any old parts of the screen are erased @@ -383,8 +391,8 @@ void FrameBufferGL::drawMediaSource() uInt8* previousFrame = mediasrc.previousFrameBuffer(); uInt32 width = mediasrc.width(); uInt32 height = mediasrc.height(); - uInt32 pitch = myBaseSurface->pitch(); - uInt16* buffer = (uInt16*) myBaseSurface->pixels(); + uInt32 pitch = myTiaSurface->pitch(); + uInt16* buffer = (uInt16*) myTiaSurface->pixels(); // TODO - is this fast enough? if(!myUsePhosphor) @@ -443,8 +451,8 @@ void FrameBufferGL::drawMediaSource() // And blit the surface if(myDirtyFlag) { - myBaseSurface->addDirtyRect(0, 0, 0, 0); - myBaseSurface->update(); + myTiaSurface->addDirtyRect(0, 0, 0, 0); + myTiaSurface->update(); } } @@ -471,12 +479,6 @@ void FrameBufferGL::enablePhosphor(bool enable, int blend) myRedrawEntireFrame = true; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Uint32 FrameBufferGL::mapRGB(Uint8 r, Uint8 g, Uint8 b) const -{ - return myBaseSurface->mapRGB(r, g, b); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBufferGL::toggleFilter() { @@ -704,18 +706,6 @@ void FBSurfaceGL::setPos(uInt32 x, uInt32 y) { myXOrig = x; myYOrig = y; -#if 0 - // Only non-base surfaces can be arbitrarily 'moved' - if(!myIsBaseSurface) - { - // Make sure pitch is valid - recalc(); - - myXOrig = x; - myYOrig = y; - myXOffset = myYOffset = myBaseOffset = 0; - } -#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/common/FrameBufferGL.hxx b/stella/src/common/FrameBufferGL.hxx index c926dcc8c..41119780e 100644 --- a/stella/src/common/FrameBufferGL.hxx +++ b/stella/src/common/FrameBufferGL.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferGL.hxx,v 1.61 2008-12-12 15:51:06 stephena Exp $ +// $Id: FrameBufferGL.hxx,v 1.62 2008-12-14 21:44:06 stephena Exp $ //============================================================================ #ifndef FRAMEBUFFER_GL_HXX @@ -35,7 +35,7 @@ class FBSurfaceGL; This class implements an SDL OpenGL framebuffer. @author Stephen Anthony - @version $Id: FrameBufferGL.hxx,v 1.61 2008-12-12 15:51:06 stephena Exp $ + @version $Id: FrameBufferGL.hxx,v 1.62 2008-12-14 21:44:06 stephena Exp $ */ class FrameBufferGL : public FrameBuffer { @@ -76,7 +76,8 @@ class FrameBufferGL : public FrameBuffer @param g The green component of the color. @param b The blue component of the color. */ - Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) const; + Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) const + { return SDL_MapRGB(&myPixelFormat, r, g, b); } /** This method is called to query the type of the FrameBuffer. @@ -151,8 +152,12 @@ class FrameBufferGL : public FrameBuffer bool loadFuncs(); private: - // The lower-most base surface (could be TIA or dialog-based) - FBSurfaceGL* myBaseSurface; + // The lower-most base surface (will always be a TIA surface, + // since Dialog surfaces are allocated by the Dialog class directly). + FBSurfaceGL* myTiaSurface; + + // Used for mapRGB (when palettes are created) + SDL_PixelFormat myPixelFormat; /* // Holds all items specifically needed by GL commands @@ -201,7 +206,7 @@ class FrameBufferGL : public FrameBuffer A surface suitable for OpenGL rendering mode. @author Stephen Anthony - @version $Id: FrameBufferGL.hxx,v 1.61 2008-12-12 15:51:06 stephena Exp $ + @version $Id: FrameBufferGL.hxx,v 1.62 2008-12-14 21:44:06 stephena Exp $ */ class FBSurfaceGL : public FBSurface { @@ -232,8 +237,6 @@ class FBSurfaceGL : public FBSurface private: inline void* pixels() const { return myTexture->pixels; } inline uInt32 pitch() const { return myPitch; } - inline uInt32 mapRGB(Uint8 r, Uint8 g, Uint8 b) const - { return SDL_MapRGB(myTexture->format, r, g, b); } void recalc(); static uInt32 power_of_two(uInt32 input) diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index 51d5113d8..d41f3db62 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: OSystem.cxx,v 1.132 2008-12-12 18:32:53 stephena Exp $ +// $Id: OSystem.cxx,v 1.133 2008-12-14 21:44:06 stephena Exp $ //============================================================================ #include @@ -347,6 +347,9 @@ bool OSystem::createFrameBuffer(bool showmessage) // Let the system know that we've possibly resized the display if(changeBuffer) myEventHandler->handleResizeEvent(); + // Update the UI palette + setUIPalette(); + if(showmessage) { switch(myFrameBuffer->type()) diff --git a/stella/src/gui/Dialog.cxx b/stella/src/gui/Dialog.cxx index db833c09d..d788a35eb 100644 --- a/stella/src/gui/Dialog.cxx +++ b/stella/src/gui/Dialog.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Dialog.cxx,v 1.66 2008-12-12 18:32:53 stephena Exp $ +// $Id: Dialog.cxx,v 1.67 2008-12-14 21:44:06 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -101,8 +101,6 @@ cerr << "!!!! surface is too small !!!!" << endl; } */ -instance().setUIPalette(); - center(); loadConfig();