mirror of https://github.com/snes9xgit/snes9x.git
Use libepoxy to cut out the OpenGL loading cruft.
This commit is contained in:
parent
b34ecf8973
commit
f7bf180b39
|
@ -211,6 +211,10 @@ if test yes = "$with_opengl" ; then
|
|||
],[
|
||||
OPENGL=0
|
||||
])
|
||||
|
||||
PKG_CHECK_MODULES([EPOXY], [epoxy]);
|
||||
CFLAGS="$CFLAGS $EPOXY_CFLAGS"
|
||||
LIBS="$LIBS $EPOXY_LIBS"
|
||||
fi
|
||||
|
||||
GTKJOY=0
|
||||
|
|
|
@ -197,20 +197,6 @@
|
|||
|
||||
#include "../gtk_display_driver_opengl.h"
|
||||
|
||||
extern getProcAddressProc xglGetProcAddress;
|
||||
|
||||
static void ReduceToPath(char* filename)
|
||||
{
|
||||
for (int i = strlen(filename); i >= 0; i--)
|
||||
{
|
||||
if (filename[i] == '\\' || filename[i] == '/')
|
||||
{
|
||||
filename[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char* ReadShaderFileContents(const char *filename)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
|
@ -233,6 +219,18 @@ static char* ReadShaderFileContents(const char* filename)
|
|||
return contents;
|
||||
}
|
||||
|
||||
static void ReduceToPath(char* filename)
|
||||
{
|
||||
for (int i = strlen(filename); i >= 0; i--)
|
||||
{
|
||||
if (filename[i] == '\\' || filename[i] == '/')
|
||||
{
|
||||
filename[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#ifndef max
|
||||
|
@ -307,31 +305,12 @@ void CGLCG::ClearPasses()
|
|||
|
||||
bool CGLCG::LoadFBOFunctions()
|
||||
{
|
||||
if (fboFunctionsLoaded)
|
||||
return true;
|
||||
|
||||
const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
|
||||
|
||||
if (extensions && strstr(extensions, "framebuffer_object"))
|
||||
{
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glGenFramebuffers");
|
||||
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glDeleteFramebuffers");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glBindFramebuffer");
|
||||
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glFramebufferTexture2D");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glCheckFramebufferStatus");
|
||||
glClientActiveTexture = (PFNGLACTIVETEXTUREPROC)xglGetProcAddress(
|
||||
(const GLubyte*)"glClientActiveTexture");
|
||||
|
||||
if (glGenFramebuffers && glDeleteFramebuffers && glBindFramebuffer && glFramebufferTexture2D && glClientActiveTexture)
|
||||
{
|
||||
fboFunctionsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
return fboFunctionsLoaded;
|
||||
}
|
||||
|
|
|
@ -192,10 +192,10 @@
|
|||
#ifndef CGGLCG_H
|
||||
#define CGGLCG_H
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
#include "CCGShader.h"
|
||||
#include "GL/glext.h"
|
||||
#include "cgFunctions.h"
|
||||
#include <GL/gl.h>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
|
@ -304,13 +304,6 @@ private:
|
|||
unsigned int frameCnt;
|
||||
static const GLfloat lut_coords[8];
|
||||
|
||||
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
|
||||
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
|
||||
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
|
||||
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
|
||||
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
|
||||
PFNGLACTIVETEXTUREPROC glClientActiveTexture;
|
||||
|
||||
public:
|
||||
CGLCG(CGcontext cgContext);
|
||||
~CGLCG(void);
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
#include "cgFunctions.h"
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
void* hCgDll = NULL;
|
||||
void* hCgGLDll = NULL;
|
||||
|
|
|
@ -199,7 +199,7 @@
|
|||
#define CGD3D9DLL_API
|
||||
#define CGGL_API
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
#define CG_API
|
||||
typedef struct _CGprogram* CGprogram;
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -15,102 +13,13 @@
|
|||
|
||||
#include "Cg/CGLCG.h"
|
||||
|
||||
static const char *glGenBuffersNames[] = { "glGenBuffers",
|
||||
"glGenBuffersARB",
|
||||
"glGenBuffersEXT",
|
||||
NULL };
|
||||
static const char *glDeleteBuffersNames[] = { "glDeleteBuffers",
|
||||
"glDeleteBuffersARB",
|
||||
"glDeleteBuffersEXT",
|
||||
NULL };
|
||||
static const char *glBindBufferNames[] = { "glBindBuffer",
|
||||
"glBindBufferARB",
|
||||
"glBindBufferEXT",
|
||||
NULL };
|
||||
static const char *glBufferDataNames[] = { "glBufferData",
|
||||
"glBufferDataARB",
|
||||
"glBufferDataEXT",
|
||||
NULL };
|
||||
static const char *glBufferSubDataNames[] = { "glBufferSubData",
|
||||
"glBufferSubDataARB",
|
||||
"glBufferSubDataEXT",
|
||||
NULL };
|
||||
static const char *glMapBufferNames[] = { "glMapBuffer",
|
||||
"glMapBufferARB",
|
||||
"glMapBufferEXT",
|
||||
NULL };
|
||||
static const char *glUnmapBufferNames[] = { "glUnmapBuffer",
|
||||
"glUnmapBufferARB",
|
||||
"glUnmapBufferEXT",
|
||||
NULL };
|
||||
|
||||
getProcAddressProc xglGetProcAddress = NULL;
|
||||
|
||||
gl_proc
|
||||
get_null_address_proc (const GLubyte *name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gl_proc
|
||||
S9xOpenGLDisplayDriver::get_aliased_extension (const char **name)
|
||||
{
|
||||
gl_proc ext_proc = NULL;
|
||||
|
||||
for (int i = 0; name[i]; i++)
|
||||
{
|
||||
ext_proc = glGetProcAddress ((GLubyte *) name[i]);
|
||||
|
||||
if (ext_proc)
|
||||
break;
|
||||
}
|
||||
|
||||
return ext_proc;
|
||||
}
|
||||
|
||||
S9xOpenGLDisplayDriver::S9xOpenGLDisplayDriver (Snes9xWindow *window,
|
||||
Snes9xConfig *config)
|
||||
{
|
||||
void *dl_handle = NULL;
|
||||
|
||||
this->window = window;
|
||||
this->config = config;
|
||||
this->drawing_area = GTK_WIDGET (window->drawing_area);
|
||||
|
||||
dl_handle = dlopen (NULL, RTLD_LAZY);
|
||||
|
||||
if (dl_handle)
|
||||
{
|
||||
dlerror ();
|
||||
|
||||
#ifdef __GNUC__
|
||||
__extension__
|
||||
#endif
|
||||
getProcAddressProc functor = reinterpret_cast<getProcAddressProc> (dlsym (dl_handle, "glXGetProcAddress"));
|
||||
glGetProcAddress = functor;
|
||||
xglGetProcAddress = glGetProcAddress;
|
||||
|
||||
if (dlerror () != NULL)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
__extension__
|
||||
#endif
|
||||
getProcAddressProc functor = reinterpret_cast<getProcAddressProc> (dlsym (dl_handle, "glXGetProcAddressARB"));
|
||||
glGetProcAddress = functor;
|
||||
xglGetProcAddress = glGetProcAddress;
|
||||
|
||||
if (dlerror () != NULL)
|
||||
glGetProcAddress = get_null_address_proc;
|
||||
}
|
||||
|
||||
/* ok to close the handle, since didn't really open anything */
|
||||
dlclose (dl_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
glGetProcAddress = get_null_address_proc;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -438,46 +347,9 @@ S9xOpenGLDisplayDriver::load_pixel_buffer_functions (void)
|
|||
return 0;
|
||||
|
||||
if (strstr (extensions, "pixel_buffer_object"))
|
||||
{
|
||||
glGenBuffers =
|
||||
(glGenBuffersProc)
|
||||
get_aliased_extension (glGenBuffersNames);
|
||||
|
||||
glDeleteBuffers =
|
||||
(glDeleteBuffersProc)
|
||||
get_aliased_extension (glDeleteBuffersNames);
|
||||
|
||||
glBindBuffer =
|
||||
(glBindBufferProc)
|
||||
get_aliased_extension (glBindBufferNames);
|
||||
|
||||
glBufferData =
|
||||
(glBufferDataProc)
|
||||
get_aliased_extension (glBufferDataNames);
|
||||
|
||||
glBufferSubData =
|
||||
(glBufferSubDataProc)
|
||||
get_aliased_extension (glBufferSubDataNames);
|
||||
|
||||
glMapBuffer =
|
||||
(glMapBufferProc)
|
||||
get_aliased_extension (glMapBufferNames);
|
||||
|
||||
glUnmapBuffer =
|
||||
(glUnmapBufferProc)
|
||||
get_aliased_extension (glUnmapBufferNames);
|
||||
|
||||
if (glGenBuffers &&
|
||||
glBindBuffer &&
|
||||
glBufferData &&
|
||||
glBufferSubData &&
|
||||
glMapBuffer &&
|
||||
glUnmapBuffer &&
|
||||
glDeleteBuffers)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -491,36 +363,9 @@ S9xOpenGLDisplayDriver::load_shader_functions (void)
|
|||
return 0;
|
||||
|
||||
if (strstr (extensions, "fragment_program"))
|
||||
{
|
||||
glCreateProgram = (glCreateProgramProc) glGetProcAddress ((GLubyte *) "glCreateProgram");
|
||||
glCreateShader = (glCreateShaderProc) glGetProcAddress ((GLubyte *) "glCreateShader");
|
||||
glCompileShader = (glCompileShaderProc) glGetProcAddress ((GLubyte *) "glCompileShader");
|
||||
glDeleteShader = (glDeleteShaderProc) glGetProcAddress ((GLubyte *) "glDeleteShader");
|
||||
glDeleteProgram = (glDeleteProgramProc) glGetProcAddress ((GLubyte *) "glDeleteProgram");
|
||||
glAttachShader = (glAttachShaderProc) glGetProcAddress ((GLubyte *) "glAttachShader");
|
||||
glDetachShader = (glDetachShaderProc) glGetProcAddress ((GLubyte *) "glDetachShader");
|
||||
glLinkProgram = (glLinkProgramProc) glGetProcAddress ((GLubyte *) "glLinkProgram");
|
||||
glUseProgram = (glUseProgramProc) glGetProcAddress ((GLubyte *) "glUseProgram");
|
||||
glShaderSource = (glShaderSourceProc) glGetProcAddress ((GLubyte *) "glShaderSource");
|
||||
glGetUniformLocation = (glGetUniformLocationProc) glGetProcAddress ((GLubyte *) "glGetUniformLocation");
|
||||
glUniform2fv = (glUniform2fvProc) glGetProcAddress ((GLubyte *) "glUniform2fv");
|
||||
|
||||
if (glCreateProgram &&
|
||||
glCreateShader &&
|
||||
glCompileShader &&
|
||||
glDeleteShader &&
|
||||
glDeleteProgram &&
|
||||
glAttachShader &&
|
||||
glDetachShader &&
|
||||
glLinkProgram &&
|
||||
glUseProgram &&
|
||||
glShaderSource &&
|
||||
glGetUniformLocation &&
|
||||
glUniform2fv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -899,52 +744,16 @@ S9xOpenGLDisplayDriver::init (void)
|
|||
void
|
||||
S9xOpenGLDisplayDriver::swap_control (int enable)
|
||||
{
|
||||
static glSwapIntervalProc glSwapInterval = NULL;
|
||||
static glXSwapIntervalEXTProc glXSwapIntervalEXT = NULL;
|
||||
static int queried = FALSE;
|
||||
const char *ext_str;
|
||||
|
||||
enable = enable ? 1 : 0;
|
||||
const char *extensions = (const char *) glGetString (GL_EXTENSIONS);
|
||||
|
||||
if (!queried)
|
||||
if (strstr (extensions, "EXT_swap_control"))
|
||||
{
|
||||
ext_str = glXQueryExtensionsString (display, DefaultScreen (display));
|
||||
|
||||
/* We try to set this with both extensions since some cards pretend
|
||||
* to support both, but ignore one. */
|
||||
|
||||
if (strstr (ext_str, "GLX_MESA_swap_control"))
|
||||
{
|
||||
glSwapInterval = (glSwapIntervalProc)
|
||||
glGetProcAddress ((GLubyte *) "glXSwapIntervalMESA");
|
||||
}
|
||||
|
||||
if (strstr (ext_str, "GLX_SGI_swap_control"))
|
||||
{
|
||||
glSwapInterval = (glSwapIntervalProc)
|
||||
glGetProcAddress ((GLubyte *) "glXSwapIntervalSGI");
|
||||
}
|
||||
|
||||
if (strstr (ext_str, "GLX_EXT_swap_control"))
|
||||
{
|
||||
glXSwapIntervalEXT = (glXSwapIntervalEXTProc)
|
||||
glGetProcAddress ((GLubyte *) "glXSwapIntervalEXT");
|
||||
}
|
||||
|
||||
queried = TRUE;
|
||||
}
|
||||
|
||||
if (glXSwapIntervalEXT)
|
||||
{
|
||||
if (glSwapInterval)
|
||||
glSwapInterval (0);
|
||||
|
||||
glXSwapIntervalEXT (display, xwindow, enable);
|
||||
}
|
||||
|
||||
else if (glSwapInterval)
|
||||
else if (strstr (extensions, "SGI_swap_control"))
|
||||
{
|
||||
glSwapInterval (enable);
|
||||
glXSwapIntervalSGI (enable);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "gtk_s9x.h"
|
||||
#include "gtk_display_driver.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
||||
#include "Cg/CGLCG.h"
|
||||
|
||||
|
@ -13,12 +13,6 @@
|
|||
#define PBO_FMT_24 1
|
||||
#define PBO_FMT_32 2
|
||||
|
||||
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||
#define GL_WRITE_ONLY 0x88B9
|
||||
#define GL_STREAM_DRAW 0x88E0
|
||||
#define GL_TEXTURE_RECTANGLE 0x84F5
|
||||
#define GL_FRAGMENT_SHADER 0x8B30
|
||||
#define GL_VERTEX_SHADER 0x8B31
|
||||
#define BUFFER_OFFSET(i) ((char *) NULL + (i))
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
|
@ -31,49 +25,6 @@
|
|||
#define PBO_GET_FORMAT(x) (((x) == PBO_FMT_32) ? GL_BGRA : GL_RGB)
|
||||
#define PBO_GET_PACKING(x) (((x) == PBO_FMT_16) ? GL_UNSIGNED_SHORT_5_6_5 : (((x) == PBO_FMT_24) ? GL_UNSIGNED_BYTE : PBO_BGRA_NATIVE_ORDER))
|
||||
|
||||
/* The following are procedure pointer types.
|
||||
* These aren't necessarily guaranteed to be in GL 1.1 */
|
||||
typedef void (*gl_proc) (void);
|
||||
typedef gl_proc (*getProcAddressProc) (const GLubyte *name);
|
||||
|
||||
typedef GLint (*glSwapIntervalProc) (GLint interval);
|
||||
typedef void (*glXSwapIntervalEXTProc) (Display *dpy,
|
||||
GLXDrawable drawable,
|
||||
int interval);
|
||||
/* Procedures for pixel buffer objects */
|
||||
typedef void (*glGenBuffersProc) (GLsizei n, GLuint *buffers);
|
||||
typedef void (*glDeleteBuffersProc) (GLsizei n, const GLuint *buffers);
|
||||
typedef void (*glBindBufferProc) (GLenum target, GLuint buffer);
|
||||
typedef void (*glBufferDataProc) (GLenum target,
|
||||
GLsizeiptr size,
|
||||
const GLvoid *data,
|
||||
GLenum usage);
|
||||
typedef void (*glBufferSubDataProc) (GLenum target,
|
||||
GLintptr offset,
|
||||
GLsizeiptr size,
|
||||
const GLvoid *data);
|
||||
typedef GLvoid *(*glMapBufferProc) (GLenum target, GLenum access);
|
||||
typedef GLboolean (*glUnmapBufferProc) (GLenum target);
|
||||
/* Procedures for GLSL */
|
||||
typedef GLuint (*glCreateProgramProc) (void);
|
||||
typedef GLuint (*glCreateShaderProc) (GLenum type);
|
||||
typedef void (*glCompileShaderProc) (GLuint shader);
|
||||
typedef void (*glDeleteShaderProc) (GLuint shader);
|
||||
typedef void (*glDeleteProgramProc) (GLuint program);
|
||||
typedef void (*glAttachShaderProc) (GLuint program, GLuint shader);
|
||||
typedef void (*glDetachShaderProc) (GLuint program, GLuint shader);
|
||||
typedef void (*glLinkProgramProc) (GLuint program);
|
||||
typedef void (*glUseProgramProc) (GLuint program);
|
||||
typedef void (*glShaderSourceProc) (GLuint shader,
|
||||
GLsizei count,
|
||||
const GLchar* *string,
|
||||
const GLint *length);
|
||||
typedef GLint (*glGetUniformLocationProc) (GLuint program,
|
||||
const GLchar *name);
|
||||
typedef void (*glUniform2fvProc) (GLint location,
|
||||
GLsizei count,
|
||||
const GLfloat *value);
|
||||
|
||||
class S9xOpenGLDisplayDriver : public S9xDisplayDriver
|
||||
{
|
||||
public:
|
||||
|
@ -96,33 +47,11 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver
|
|||
int load_pixel_buffer_functions (void);
|
||||
int load_shader_functions (void);
|
||||
int load_shaders (const char *);
|
||||
gl_proc get_aliased_extension (const char **name);
|
||||
void update_texture_size (int width, int height);
|
||||
int init_glx (void);
|
||||
void create_window (int width, int height);
|
||||
void resize_window (int width, int height);
|
||||
|
||||
getProcAddressProc glGetProcAddress;
|
||||
glGenBuffersProc glGenBuffers;
|
||||
glBindBufferProc glBindBuffer;
|
||||
glBufferDataProc glBufferData;
|
||||
glBufferSubDataProc glBufferSubData;
|
||||
glMapBufferProc glMapBuffer;
|
||||
glUnmapBufferProc glUnmapBuffer;
|
||||
glDeleteBuffersProc glDeleteBuffers;
|
||||
glCreateProgramProc glCreateProgram;
|
||||
glCreateShaderProc glCreateShader;
|
||||
glCompileShaderProc glCompileShader;
|
||||
glDeleteShaderProc glDeleteShader;
|
||||
glDeleteProgramProc glDeleteProgram;
|
||||
glAttachShaderProc glAttachShader;
|
||||
glDetachShaderProc glDetachShader;
|
||||
glLinkProgramProc glLinkProgram;
|
||||
glUseProgramProc glUseProgram;
|
||||
glShaderSourceProc glShaderSource;
|
||||
glGetUniformLocationProc glGetUniformLocation;
|
||||
glUniform2fvProc glUniform2fv;
|
||||
|
||||
GLint texture_width;
|
||||
GLint texture_height;
|
||||
GLfloat vertices[8];
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "gtk_s9x.h"
|
||||
#include "gtk_builder_window.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue