mirror of https://github.com/stella-emu/stella.git
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:
parent
4fdfbde53a
commit
f1e25447f7
|
@ -44,13 +44,10 @@ FBSurfaceGL::FBSurfaceGL(FrameBufferGL& buffer, uInt32 width, uInt32 height)
|
||||||
|
|
||||||
// Based on experimentation, the following are the fastest 16-bit
|
// Based on experimentation, the following are the fastest 16-bit
|
||||||
// formats for OpenGL (on all platforms)
|
// formats for OpenGL (on all platforms)
|
||||||
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, myTexWidth, myTexHeight, 16,
|
||||||
myTexWidth, myTexHeight, 16,
|
myFB.myPixelFormat.Rmask, myFB.myPixelFormat.Gmask,
|
||||||
#ifdef HAVE_GL_BGRA
|
myFB.myPixelFormat.Bmask, 0x00000000);
|
||||||
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
|
|
||||||
#else
|
|
||||||
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
|
|
||||||
#endif
|
|
||||||
myPitch = myTexture->pitch >> 1;
|
myPitch = myTexture->pitch >> 1;
|
||||||
|
|
||||||
// Associate the SDL surface with a GL texture object
|
// Associate the SDL surface with a GL texture object
|
||||||
|
@ -261,12 +258,8 @@ void FBSurfaceGL::update()
|
||||||
myGL.ActiveTexture(GL_TEXTURE0);
|
myGL.ActiveTexture(GL_TEXTURE0);
|
||||||
myGL.BindTexture(GL_TEXTURE_2D, myTexID);
|
myGL.BindTexture(GL_TEXTURE_2D, myTexID);
|
||||||
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
|
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
|
||||||
#ifdef HAVE_GL_BGRA
|
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||||
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
myTexture->pixels);
|
||||||
#else
|
|
||||||
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
|
|
||||||
#endif
|
|
||||||
myTexture->pixels);
|
|
||||||
|
|
||||||
myGL.EnableClientState(GL_VERTEX_ARRAY);
|
myGL.EnableClientState(GL_VERTEX_ARRAY);
|
||||||
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
|
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
@ -321,14 +314,9 @@ void FBSurfaceGL::reload()
|
||||||
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
// Create the texture in the most optimal format
|
// Create the texture in the most optimal format
|
||||||
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myTexWidth, myTexHeight, 0,
|
||||||
myTexWidth, myTexHeight, 0,
|
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||||
#ifdef HAVE_GL_BGRA
|
myTexture->pixels);
|
||||||
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
|
// Cache vertex and texture coordinates using vertex buffer object
|
||||||
if(myFB.myVBOAvailable)
|
if(myFB.myVBOAvailable)
|
||||||
|
|
|
@ -47,13 +47,10 @@ FBSurfaceTIA::FBSurfaceTIA(FrameBufferGL& buffer)
|
||||||
|
|
||||||
// Based on experimentation, the following are the fastest 16-bit
|
// Based on experimentation, the following are the fastest 16-bit
|
||||||
// formats for OpenGL (on all platforms)
|
// formats for OpenGL (on all platforms)
|
||||||
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
myTexture = SDL_CreateRGBSurface(SDL_SWSURFACE, myTexWidth, myTexHeight, 16,
|
||||||
myTexWidth, myTexHeight, 16,
|
myFB.myPixelFormat.Rmask, myFB.myPixelFormat.Gmask,
|
||||||
#ifdef HAVE_GL_BGRA
|
myFB.myPixelFormat.Bmask, 0x00000000);
|
||||||
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
|
|
||||||
#else
|
|
||||||
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
|
|
||||||
#endif
|
|
||||||
myPitch = myTexture->pitch >> 1;
|
myPitch = myTexture->pitch >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,31 +131,22 @@ void FBSurfaceTIA::update()
|
||||||
|
|
||||||
case FrameBufferGL::kBlarggNTSC:
|
case FrameBufferGL::kBlarggNTSC:
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GL_BGRA
|
|
||||||
myFB.myNTSCFilter.blit_1555
|
myFB.myNTSCFilter.blit_1555
|
||||||
#else
|
|
||||||
myFB.myNTSCFilter.blit_5551
|
|
||||||
#endif
|
|
||||||
(currentFrame, width, height, buffer, myTexture->pitch);
|
(currentFrame, width, height, buffer, myTexture->pitch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texturemap complete texture to surface so we have free scaling
|
myGL.EnableClientState(GL_VERTEX_ARRAY);
|
||||||
// and antialiasing
|
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
|
// Update TIA image (texture 0), then blend scanlines (texture 1)
|
||||||
myGL.ActiveTexture(GL_TEXTURE0);
|
myGL.ActiveTexture(GL_TEXTURE0);
|
||||||
myGL.BindTexture(GL_TEXTURE_2D, myTexID[0]);
|
myGL.BindTexture(GL_TEXTURE_2D, myTexID[0]);
|
||||||
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
|
myGL.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myTexWidth, myTexHeight,
|
||||||
#ifdef HAVE_GL_BGRA
|
|
||||||
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||||
#else
|
|
||||||
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
|
|
||||||
#endif
|
|
||||||
myTexture->pixels);
|
myTexture->pixels);
|
||||||
|
|
||||||
myGL.EnableClientState(GL_VERTEX_ARRAY);
|
|
||||||
myGL.EnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
|
|
||||||
if(myFB.myVBOAvailable)
|
if(myFB.myVBOAvailable)
|
||||||
{
|
{
|
||||||
myGL.BindBuffer(GL_ARRAY_BUFFER, myVBOID);
|
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);
|
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
// Create the texture in the most optimal format
|
// Create the texture in the most optimal format
|
||||||
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myTexWidth, myTexHeight, 0,
|
||||||
myTexWidth, myTexHeight, 0,
|
|
||||||
#ifdef HAVE_GL_BGRA
|
|
||||||
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||||
#else
|
|
||||||
GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1,
|
|
||||||
#endif
|
|
||||||
myTexture->pixels);
|
myTexture->pixels);
|
||||||
|
|
||||||
// Scanline texture (@ index 1)
|
// 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_S, GL_REPEAT);
|
||||||
myGL.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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 };
|
static uInt16 const scanline[4] = { 0x0000, 0x0000, 0x8000, 0x0000 };
|
||||||
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0,
|
myGL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0,
|
||||||
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV,
|
||||||
scanline);
|
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
|
// Cache vertex and texture coordinates using vertex buffer object
|
||||||
if(myFB.myVBOAvailable)
|
if(myFB.myVBOAvailable)
|
||||||
|
|
|
@ -42,7 +42,6 @@ FrameBufferGL::FrameBufferGL(OSystem* osystem)
|
||||||
: FrameBuffer(osystem),
|
: FrameBuffer(osystem),
|
||||||
myFilterType(kNone),
|
myFilterType(kNone),
|
||||||
myTiaSurface(NULL),
|
myTiaSurface(NULL),
|
||||||
myFilterParamName("GL_NEAREST"),
|
|
||||||
myDirtyFlag(true)
|
myDirtyFlag(true)
|
||||||
{
|
{
|
||||||
// We need a pixel format for palette value calculations
|
// 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
|
// since the structure may be needed before any FBSurface's have
|
||||||
// been created
|
// been created
|
||||||
SDL_Surface* s = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 16,
|
SDL_Surface* s = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 16,
|
||||||
#ifdef HAVE_GL_BGRA
|
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
|
||||||
0x00007c00, 0x000003e0, 0x0000001f, 0x00000000);
|
|
||||||
#else
|
|
||||||
0x0000f800, 0x000007c0, 0x0000003e, 0x00000000);
|
|
||||||
#endif
|
|
||||||
myPixelFormat = *(s->format);
|
myPixelFormat = *(s->format);
|
||||||
SDL_FreeSurface(s);
|
SDL_FreeSurface(s);
|
||||||
}
|
}
|
||||||
|
@ -168,10 +164,10 @@ bool FrameBufferGL::initSubsystem(VideoMode& mode)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Now check to see what color components were actually created
|
// 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_RED_SIZE, &myRGB[0] );
|
||||||
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, (int*)&myRGB[1] );
|
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &myRGB[1] );
|
||||||
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, (int*)&myRGB[2] );
|
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &myRGB[2] );
|
||||||
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, (int*)&myRGB[3] );
|
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &myRGB[3] );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -186,15 +182,9 @@ string FrameBufferGL::about() const
|
||||||
<< " Version: " << p_gl.GetString(GL_VERSION) << endl
|
<< " Version: " << p_gl.GetString(GL_VERSION) << endl
|
||||||
<< " Color: " << myDepth << " bit, " << myRGB[0] << "-"
|
<< " Color: " << myDepth << " bit, " << myRGB[0] << "-"
|
||||||
<< myRGB[1] << "-" << myRGB[2] << "-" << myRGB[3] << ", "
|
<< myRGB[1] << "-" << myRGB[2] << "-" << myRGB[3] << ", "
|
||||||
#ifdef HAVE_GL_BGRA
|
|
||||||
<< "GL_BGRA" << endl
|
<< "GL_BGRA" << endl
|
||||||
#else
|
<< " Extensions: VBO " << (myVBOAvailable ? "enabled" : "disabled")
|
||||||
<< "GL_RGBA" << endl
|
<< endl;
|
||||||
#endif
|
|
||||||
<< " Filter: " << myFilterParamName << endl
|
|
||||||
<< " Extensions: ";
|
|
||||||
if(myVBOAvailable) out << "VBO ";
|
|
||||||
out << endl;
|
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,13 +276,7 @@ bool FrameBufferGL::setVidMode(VideoMode& mode)
|
||||||
|
|
||||||
// Load OpenGL function pointers
|
// Load OpenGL function pointers
|
||||||
if(loadFuncs(kGL_BASIC))
|
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);
|
myVBOAvailable = myOSystem->settings().getBool("gl_vbo") && loadFuncs(kGL_VBO);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return false;
|
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.Ortho(0.0, mode.screen_w, mode.screen_h, 0.0, -1.0, 1.0);
|
||||||
p_gl.MatrixMode(GL_MODELVIEW);
|
p_gl.MatrixMode(GL_MODELVIEW);
|
||||||
p_gl.LoadIdentity();
|
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;
|
//cerr << "dimensions: " << (fullScreen() ? "(full)" : "") << endl << mode << endl;
|
||||||
|
|
||||||
|
@ -426,8 +410,8 @@ void FrameBufferGL::enableScanlineInterpolation(bool enable)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void FrameBufferGL::setTIAPalette(const uInt32* palette)
|
void FrameBufferGL::setTIAPalette(const uInt32* palette)
|
||||||
{
|
{
|
||||||
myTiaSurface->setTIAPalette(palette);
|
|
||||||
FrameBuffer::setTIAPalette(palette);
|
FrameBuffer::setTIAPalette(palette);
|
||||||
|
myTiaSurface->setTIAPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -454,9 +438,6 @@ void FrameBufferGL::scanline(uInt32 row, uInt8* data) const
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool FrameBufferGL::myLibraryLoaded = false;
|
bool FrameBufferGL::myLibraryLoaded = false;
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
float FrameBufferGL::myGLVersion = 0.0;
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool FrameBufferGL::myVBOAvailable = false;
|
bool FrameBufferGL::myVBOAvailable = false;
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,6 @@ class TIA;
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "FrameBuffer.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.
|
This class implements an SDL OpenGL framebuffer.
|
||||||
|
|
||||||
|
@ -71,14 +65,6 @@ class FrameBufferGL : public FrameBuffer
|
||||||
*/
|
*/
|
||||||
static bool loadLibrary(const string& library);
|
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
|
// The following are derived from public methods in FrameBuffer.hxx
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
@ -234,10 +220,7 @@ class FrameBufferGL : public FrameBuffer
|
||||||
uInt32 myDepth;
|
uInt32 myDepth;
|
||||||
|
|
||||||
// The size of color components for OpenGL
|
// The size of color components for OpenGL
|
||||||
uInt32 myRGB[4];
|
Int32 myRGB[4];
|
||||||
|
|
||||||
// The name of the texture filtering to use
|
|
||||||
string myFilterParamName;
|
|
||||||
|
|
||||||
// Indicates that the texture has been modified, and should be redrawn
|
// Indicates that the texture has been modified, and should be redrawn
|
||||||
bool myDirtyFlag;
|
bool myDirtyFlag;
|
||||||
|
@ -245,9 +228,6 @@ class FrameBufferGL : public FrameBuffer
|
||||||
// Indicates if the OpenGL library has been properly loaded
|
// Indicates if the OpenGL library has been properly loaded
|
||||||
static bool myLibraryLoaded;
|
static bool myLibraryLoaded;
|
||||||
|
|
||||||
// Indicates the OpenGL version found (0 indicates none)
|
|
||||||
static float myGLVersion;
|
|
||||||
|
|
||||||
// Indicates whether Vertex Buffer Objects (VBO) are available
|
// Indicates whether Vertex Buffer Objects (VBO) are available
|
||||||
static bool myVBOAvailable;
|
static bool myVBOAvailable;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue