More SDL1 cleanup.
This commit is contained in:
parent
4cbfed2a72
commit
0a61bab99e
|
@ -23,8 +23,6 @@ source_list = Split(
|
|||
""")
|
||||
|
||||
Import('env')
|
||||
if 'GL' in env['LIBS']:
|
||||
source_list.append('sdl-opengl.cpp')
|
||||
|
||||
if env['GTK'] or env['GTK3']:
|
||||
source_list.append('gui.cpp')
|
||||
|
|
|
@ -1,279 +0,0 @@
|
|||
#define GL_GLEXT_LEGACY
|
||||
|
||||
#include "sdl.h"
|
||||
#include "sdl-opengl.h"
|
||||
#include "../common/vidblit.h"
|
||||
#include "../../utils/memory.h"
|
||||
|
||||
#ifdef APPLEOPENGL
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <OpenGL/glext.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
#endif
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifndef APIENTRY
|
||||
#define APIENTRY
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
static SDL_Window *s_window = NULL;
|
||||
#endif
|
||||
static GLuint textures[2]={0,0}; // Normal image, scanline overlay.
|
||||
|
||||
static int left,right,top,bottom; // right and bottom are not inclusive.
|
||||
static int scanlines;
|
||||
static void *HiBuffer;
|
||||
|
||||
typedef void APIENTRY (*glColorTableEXT_Func)(GLenum target,
|
||||
GLenum internalformat, GLsizei width, GLenum format, GLenum type,
|
||||
const GLvoid *table);
|
||||
glColorTableEXT_Func p_glColorTableEXT;
|
||||
|
||||
void
|
||||
SetOpenGLPalette(uint8 *data)
|
||||
{
|
||||
if(!HiBuffer) {
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
p_glColorTableEXT(GL_TEXTURE_2D, GL_RGB, 256,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
} else {
|
||||
SetPaletteBlitToHigh((uint8*)data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BlitOpenGL(uint8 *buf)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
|
||||
if(HiBuffer) {
|
||||
Blit8ToHigh(buf, (uint8*)HiBuffer, 256, 240, 256*4, 1, 1);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, HiBuffer);
|
||||
}
|
||||
else {
|
||||
//glPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0,
|
||||
GL_COLOR_INDEX,GL_UNSIGNED_BYTE,buf);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(1.0f*left/256, 1.0f*bottom/256); // Bottom left of picture.
|
||||
glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
||||
|
||||
glTexCoord2f(1.0f*right/256, 1.0f*bottom/256);// Bottom right of picture.
|
||||
glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
||||
|
||||
glTexCoord2f(1.0f*right/256, 1.0f*top/256); // Top right of our picture.
|
||||
glVertex2f( 1.0f, 1.0f); // Top right of target.
|
||||
|
||||
glTexCoord2f(1.0f*left/256, 1.0f*top/256); // Top left of our picture.
|
||||
glVertex2f(-1.0f, 1.0f); // Top left of target.
|
||||
glEnd();
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
if(scanlines) {
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||
glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(1.0f*left/256,
|
||||
1.0f*bottom/256); // Bottom left of our picture.
|
||||
glVertex2f(-1.0f, -1.0f); // Bottom left of target.
|
||||
|
||||
glTexCoord2f(1.0f*right/256,
|
||||
1.0f*bottom/256); // Bottom right of our picture.
|
||||
glVertex2f( 1.0f, -1.0f); // Bottom right of target.
|
||||
|
||||
glTexCoord2f(1.0f*right/256,
|
||||
1.0f*top/256); // Top right of our picture.
|
||||
glVertex2f( 1.0f, 1.0f); // Top right of target.
|
||||
|
||||
glTexCoord2f(1.0f*left/256,
|
||||
1.0f*top/256); // Top left of our picture.
|
||||
glVertex2f(-1.0f, 1.0f); // Top left of target.
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GL_SwapWindow(s_window);
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
KillOpenGL(void)
|
||||
{
|
||||
if(textures[0]) {
|
||||
glDeleteTextures(2, &textures[0]);
|
||||
}
|
||||
textures[0]=0;
|
||||
if(HiBuffer) {
|
||||
free(HiBuffer);
|
||||
HiBuffer=0;
|
||||
}
|
||||
}
|
||||
/* Rectangle, left, right(not inclusive), top, bottom(not inclusive). */
|
||||
|
||||
int
|
||||
InitOpenGL(int l,
|
||||
int r,
|
||||
int t,
|
||||
int b,
|
||||
double xscale,
|
||||
double yscale,
|
||||
int efx,
|
||||
int ipolate,
|
||||
int stretchx,
|
||||
int stretchy,
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_Window *window,
|
||||
#endif
|
||||
SDL_Surface *screen)
|
||||
{
|
||||
const char *extensions;
|
||||
|
||||
#define LFG(x) if(!(##x = (x##_Func) SDL_GL_GetProcAddress(#x))) return(0);
|
||||
|
||||
#define LFGN(x) p_##x = (x##_Func) SDL_GL_GetProcAddress(#x)
|
||||
|
||||
// LFG(glBindTexture);
|
||||
LFGN(glColorTableEXT);
|
||||
// LFG(glTexImage2D);
|
||||
// LFG(glBegin);
|
||||
// LFG(glVertex2f);
|
||||
// LFG(glTexCoord2f);
|
||||
// LFG(glEnd);
|
||||
// LFG(glEnable);
|
||||
// LFG(glBlendFunc);
|
||||
// LFG(glGetString);
|
||||
// LFG(glViewport);
|
||||
// LFG(glGenTextures);
|
||||
// LFG(glDeleteTextures);
|
||||
// LFG(glTexParameteri);
|
||||
// LFG(glClearColor);
|
||||
// LFG(glLoadIdentity);
|
||||
// LFG(glClear);
|
||||
// LFG(glMatrixMode);
|
||||
// LFG(glDisable);
|
||||
|
||||
left=l;
|
||||
right=r;
|
||||
top=t;
|
||||
bottom=b;
|
||||
|
||||
HiBuffer=0;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
s_window = window;
|
||||
#endif
|
||||
extensions=(const char*)glGetString(GL_EXTENSIONS);
|
||||
|
||||
if((efx&2) || !extensions || !p_glColorTableEXT || !strstr(extensions,"GL_EXT_paletted_texture"))
|
||||
{
|
||||
if(!(efx&2)) // Don't want to print out a warning message in this case...
|
||||
FCEU_printf("Paletted texture extension not found. Using slower texture format...\n");
|
||||
HiBuffer=FCEU_malloc(4*256*256);
|
||||
memset(HiBuffer,0x00,4*256*256);
|
||||
#ifndef LSB_FIRST
|
||||
InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0,0);
|
||||
#else
|
||||
InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// FIXME
|
||||
#else
|
||||
if(screen->flags & SDL_FULLSCREEN)
|
||||
{
|
||||
xscale=(double)screen->w / (double)(r-l);
|
||||
yscale=(double)screen->h / (double)(b-t);
|
||||
if(xscale<yscale) yscale = xscale;
|
||||
if(yscale<xscale) xscale = yscale;
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
int rw=(int)((r-l)*xscale);
|
||||
int rh=(int)((b-t)*yscale);
|
||||
int sx=(screen->w-rw)/2; // Start x
|
||||
int sy=(screen->h-rh)/2; // Start y
|
||||
|
||||
if(stretchx) { sx=0; rw=screen->w; }
|
||||
if(stretchy) { sy=0; rh=screen->h; }
|
||||
glViewport(sx, sy, rw, rh);
|
||||
}
|
||||
glGenTextures(2, &textures[0]);
|
||||
scanlines=0;
|
||||
|
||||
if(efx&1)
|
||||
{
|
||||
uint8 *buf;
|
||||
int x,y;
|
||||
|
||||
scanlines=1;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||
|
||||
buf=(uint8*)FCEU_dmalloc(256*(256*2)*4);
|
||||
|
||||
for(y=0;y<(256*2);y++)
|
||||
for(x=0;x<256;x++)
|
||||
{
|
||||
buf[y*256*4+x*4]=0;
|
||||
buf[y*256*4+x*4+1]=0;
|
||||
buf[y*256*4+x*4+2]=0;
|
||||
buf[y*256*4+x*4+3]=(y&1)?0x00:0xFF; //?0xa0:0xFF; // <-- Pretty
|
||||
//buf[y*256+x]=(y&1)?0x00:0xFF;
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, (scanlines==2)?256*4:512, 0,
|
||||
GL_RGBA,GL_UNSIGNED_BYTE,buf);
|
||||
FCEU_dfree(buf);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Background color to black.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// In a double buffered setup with page flipping, be sure to clear both buffers.
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GL_SwapWindow(s_window);
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_GL_SwapWindow(s_window);
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
void SetOpenGLPalette(uint8 *data);
|
||||
void BlitOpenGL(uint8 *buf);
|
||||
void KillOpenGL(void);
|
||||
|
||||
int InitOpenGL(int l, int r, int t, int b,
|
||||
double xscale, double yscale,
|
||||
int efx, int ipolate,
|
||||
int stretchx, int stretchy,
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_Window *window,
|
||||
#endif
|
||||
SDL_Surface *screen);
|
||||
|
|
@ -75,25 +75,21 @@ InitSound()
|
|||
{
|
||||
int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq;
|
||||
SDL_AudioSpec spec;
|
||||
const char *driverName;
|
||||
|
||||
g_config->getOption("SDL.Sound", &sound);
|
||||
if(!sound) {
|
||||
if (!sound)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&spec, 0, sizeof(spec));
|
||||
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
puts(SDL_GetError());
|
||||
KillSound();
|
||||
return 0;
|
||||
}
|
||||
char driverName[8];
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
// TODO - SDL 2
|
||||
#else
|
||||
SDL_AudioDriverName(driverName, 8);
|
||||
fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName);
|
||||
#endif
|
||||
|
||||
// load configuration variables
|
||||
g_config->getOption("SDL.Sound.Rate", &soundrate);
|
||||
|
@ -117,21 +113,33 @@ InitSound()
|
|||
|
||||
// For safety, set a bare minimum:
|
||||
if (s_BufferSize < spec.samples * 2)
|
||||
s_BufferSize = spec.samples * 2;
|
||||
{
|
||||
s_BufferSize = spec.samples * 2;
|
||||
}
|
||||
|
||||
s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize);
|
||||
|
||||
if (!s_Buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
s_BufferRead = s_BufferWrite = s_BufferIn = 0;
|
||||
|
||||
if(SDL_OpenAudio(&spec, 0) < 0)
|
||||
if (SDL_OpenAudio(&spec, 0) < 0)
|
||||
{
|
||||
puts(SDL_GetError());
|
||||
KillSound();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
driverName = SDL_GetCurrentAudioDriver();
|
||||
|
||||
if ( driverName )
|
||||
{
|
||||
fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName);
|
||||
}
|
||||
|
||||
FCEUI_SetSoundVolume(soundvolume);
|
||||
FCEUI_SetSoundQuality(soundq);
|
||||
FCEUI_Sound(soundrate);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
/// \brief Handles the graphical game display for the SDL implementation.
|
||||
|
||||
#include "sdl.h"
|
||||
#include "sdl-opengl.h"
|
||||
#include "glxwin.h"
|
||||
#include "../common/vidblit.h"
|
||||
#include "../../fceu.h"
|
||||
|
@ -318,23 +317,10 @@ FCEUD_GetPalette(uint8 index,
|
|||
*/
|
||||
static void RedoPalette()
|
||||
{
|
||||
//#ifdef OPENGL
|
||||
// if(s_useOpenGL)
|
||||
// SetOpenGLPalette((uint8*)s_psdl);
|
||||
// else
|
||||
//#endif
|
||||
if (s_curbpp > 8)
|
||||
{
|
||||
if(s_curbpp > 8) {
|
||||
SetPaletteBlitToHigh((uint8*)s_psdl);
|
||||
} else
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
//TODO - SDL2
|
||||
#else
|
||||
SDL_SetPalette(s_screen, SDL_PHYSPAL, s_psdl, 0, 256);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
SetPaletteBlitToHigh((uint8*)s_psdl);
|
||||
}
|
||||
}
|
||||
// XXX soules - console lock/unlock unimplemented?
|
||||
|
||||
|
@ -350,14 +336,9 @@ void UnlockConsole(){}
|
|||
void
|
||||
BlitScreen(uint8 *XBuf)
|
||||
{
|
||||
//SDL_Surface *TmpScreen;
|
||||
uint8 *dest;
|
||||
int w, h, pitch;
|
||||
|
||||
//if(!s_screen) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
// refresh the palette if required
|
||||
if (s_paletterefresh)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue