Some minor cleanups to the OpenGL class. I still need to figure out

how to integrate phosphor mode with Blargg filtering.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2475 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2012-05-15 21:43:19 +00:00
parent 4fdfbde53a
commit f1e25447f7
4 changed files with 29 additions and 104 deletions

View File

@ -44,13 +44,10 @@ FBSurfaceGL::FBSurfaceGL(FrameBufferGL& buffer, uInt32 width, uInt32 height)
// Based on experimentation, the following are the fastest 16-bit
// formats for OpenGL (on all platforms)
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE,
myTexWidth, myTexHeight, 16,
#ifdef HAVE_GL_BGRA
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
#else
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
#endif
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, myTexWidth, myTexHeight, 16,
myFB.myPixelFormat.Rmask, myFB.myPixelFormat.Gmask,
myFB.myPixelFormat.Bmask, 0x00000000);
myPitch = myTexture->pitch >> 1;
// Associate the SDL surface with a GL texture object
@ -261,11 +258,7 @@ void FBSurfaceGL::update()
myGL.ActiveTexture(GL_TEXTURE0);
myGL.BindTexture(GL_TEXTURE_2D, myTexID);
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
#ifdef HAVE_GL_BGRA
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
#else
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
#endif
myTexture->pixels);
myGL.EnableClientState(GL_VERTEX_ARRAY);
@ -321,13 +314,8 @@ void FBSurfaceGL::reload()
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create the texture in the most optimal format
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
myTexWidth, myTexHeight, 0,
#ifdef HAVE_GL_BGRA
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myTexWidth, myTexHeight, 0,
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
#else
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
#endif
myTexture->pixels);
// Cache vertex and texture coordinates using vertex buffer object

View File

@ -47,13 +47,10 @@ FBSurfaceTIA::FBSurfaceTIA(FrameBufferGL& buffer)
// Based on experimentation, the following are the fastest 16-bit
// formats for OpenGL (on all platforms)
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE,
myTexWidth, myTexHeight, 16,
#ifdef HAVE_GL_BGRA
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
#else
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
#endif
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, myTexWidth, myTexHeight, 16,
myFB.myPixelFormat.Rmask, myFB.myPixelFormat.Gmask,
myFB.myPixelFormat.Bmask, 0x00000000);
myPitch = myTexture->pitch >> 1;
}
@ -134,31 +131,22 @@ void FBSurfaceTIA::update()
case FrameBufferGL::kBlarggNTSC:
{
#ifdef HAVE_GL_BGRA
myFB.myNTSCFilter.blit_1555
#else
myFB.myNTSCFilter.blit_5551
#endif
(currentFrame, width, height, buffer, myTexture->pitch);
break;
}
}
// Texturemap complete texture to surface so we have free scaling
// and antialiasing
myGL.EnableClientState(GL_VERTEX_ARRAY);
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
// Update TIA image (texture 0), then blend scanlines (texture 1)
myGL.ActiveTexture(GL_TEXTURE0);
myGL.BindTexture(GL_TEXTURE_2D, myTexID[0]);
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
#ifdef HAVE_GL_BGRA
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
#else
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
#endif
myTexture->pixels);
myGL.EnableClientState(GL_VERTEX_ARRAY);
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
if(myFB.myVBOAvailable)
{
myGL.BindBuffer(GL_ARRAY_BUFFER, myVBOID);
@ -238,13 +226,8 @@ void FBSurfaceTIA::reload()
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create the texture in the most optimal format
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
myTexWidth, myTexHeight, 0,
#ifdef HAVE_GL_BGRA
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myTexWidth, myTexHeight, 0,
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
#else
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
#endif
myTexture->pixels);
// Scanline texture (@ index 1)
@ -254,17 +237,10 @@ void FBSurfaceTIA::reload()
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#ifdef HAVE_GL_BGRA
static uInt16 const scanline[4] = { 0x0000, 0x0000, 0x8000, 0x0000 };
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0,
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
scanline);
#else
static uInt16 const scanline[4] = { 0x0000, 0x0000, 0x0001, 0x0000 };
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0,
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
scanline);
#endif
// Cache vertex and texture coordinates using vertex buffer object
if(myFB.myVBOAvailable)

View File

@ -42,7 +42,6 @@ FrameBufferGL::FrameBufferGL(OSystem* osystem)
: FrameBuffer(osystem),
myFilterType(kNone),
myTiaSurface(NULL),
myFilterParamName("GL_NEAREST"),
myDirtyFlag(true)
{
// We need a pixel format for palette value calculations
@ -50,11 +49,8 @@ FrameBufferGL::FrameBufferGL(OSystem* osystem)
// since the structure may be needed before any FBSurface's have
// been created
SDL_Surface* s = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 16,
#ifdef HAVE_GL_BGRA
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
#else
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
#endif
myPixelFormat = *(s->format);
SDL_FreeSurface(s);
}
@ -168,10 +164,10 @@ bool FrameBufferGL::initSubsystem(VideoMode& mode)
return false;
// Now check to see what color components were actually created
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, (int*)&myRGB[0] );
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, (int*)&myRGB[1] );
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, (int*)&myRGB[2] );
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, (int*)&myRGB[3] );
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &myRGB[0] );
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &myRGB[1] );
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &myRGB[2] );
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &myRGB[3] );
return true;
}
@ -186,15 +182,9 @@ string FrameBufferGL::about() const
<< " Version: " << p_gl.GetString(GL_VERSION) << endl
<< " Color: " << myDepth << " bit, " << myRGB[0] << "-"
<< myRGB[1] << "-" << myRGB[2] << "-" << myRGB[3] << ", "
#ifdef HAVE_GL_BGRA
<< "GL_BGRA" << endl
#else
<< "GL_RGBA" << endl
#endif
<< " Filter: " << myFilterParamName << endl
<< " Extensions: ";
if(myVBOAvailable) out << "VBO ";
out << endl;
<< " Extensions: VBO " << (myVBOAvailable ? "enabled" : "disabled")
<< endl;
return out.str();
}
@ -286,13 +276,7 @@ bool FrameBufferGL::setVidMode(VideoMode& mode)
// Load OpenGL function pointers
if(loadFuncs(kGL_BASIC))
{
// Grab OpenGL version number
string version((const char *)p_gl.GetString(GL_VERSION));
myGLVersion = atof(version.substr(0, 3).c_str());
myVBOAvailable = myOSystem->settings().getBool("gl_vbo") && loadFuncs(kGL_VBO);
}
else
return false;
@ -311,7 +295,7 @@ bool FrameBufferGL::setVidMode(VideoMode& mode)
p_gl.Ortho(0.0, mode.screen_w, mode.screen_h, 0.0, -1.0, 1.0);
p_gl.MatrixMode(GL_MODELVIEW);
p_gl.LoadIdentity();
p_gl.Translatef(0.375, 0.375, 0.0);
p_gl.Translatef(0.375, 0.375, 0.0); // fix scanline mis-draw issues
//cerr << "dimensions: " << (fullScreen() ? "(full)" : "") << endl << mode << endl;
@ -426,8 +410,8 @@ void FrameBufferGL::enableScanlineInterpolation(bool enable)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferGL::setTIAPalette(const uInt32* palette)
{
myTiaSurface->setTIAPalette(palette);
FrameBuffer::setTIAPalette(palette);
myTiaSurface->setTIAPalette(palette);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -454,9 +438,6 @@ void FrameBufferGL::scanline(uInt32 row, uInt8* data) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBufferGL::myLibraryLoaded = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float FrameBufferGL::myGLVersion = 0.0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FrameBufferGL::myVBOAvailable = false;

View File

@ -34,12 +34,6 @@ class TIA;
#include "bspf.hxx"
#include "FrameBuffer.hxx"
// Make sure we have access to the most common pixel format
// (it isn't available in certain versions of OpenGL ES
#if defined(GL_BGRA) && defined(GL_UNSIGNED_SHORT_1_5_5_5_REV)
#define HAVE_GL_BGRA
#endif
/**
This class implements an SDL OpenGL framebuffer.
@ -71,14 +65,6 @@ class FrameBufferGL : public FrameBuffer
*/
static bool loadLibrary(const string& library);
/**
Return version of the OpenGL library found by the OSystem
(0 indicates that the libary was not loaded successfully).
This will not return a valid version number until setVidMode()
has been called at least once.
*/
static float glVersion() { return myGLVersion; }
//////////////////////////////////////////////////////////////////////
// The following are derived from public methods in FrameBuffer.hxx
//////////////////////////////////////////////////////////////////////
@ -234,10 +220,7 @@ class FrameBufferGL : public FrameBuffer
uInt32 myDepth;
// The size of color components for OpenGL
uInt32 myRGB[4];
// The name of the texture filtering to use
string myFilterParamName;
Int32 myRGB[4];
// Indicates that the texture has been modified, and should be redrawn
bool myDirtyFlag;
@ -245,9 +228,6 @@ class FrameBufferGL : public FrameBuffer
// Indicates if the OpenGL library has been properly loaded
static bool myLibraryLoaded;
// Indicates the OpenGL version found (0 indicates none)
static float myGLVersion;
// Indicates whether Vertex Buffer Objects (VBO) are available
static bool myVBOAvailable;