Fix up globals. Hurr, durr.

This commit is contained in:
Themaister 2010-11-13 02:48:32 +01:00
parent 7fa5ec216a
commit 43660dad6d

68
gl.c
View File

@ -28,19 +28,8 @@
#ifdef HAVE_CG #ifdef HAVE_CG
#include <Cg/cg.h> #include <Cg/cg.h>
#include <Cg/cgGL.h> #include <Cg/cgGL.h>
static CGcontext cgCtx;
static CGprogram cgPrg;
static CGprofile cgVProf;
static CGparameter cg_video_size, cg_texture_size;
#endif #endif
// Lots of globals, yes I know. :(
static GLuint texture;
static bool keep_aspect = true;
static GLuint tex_filter;
// Static coordinates for general 256 x 224 video output.
static const GLfloat vertexes[] = { static const GLfloat vertexes[] = {
0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0,
@ -55,11 +44,20 @@ static const GLfloat tex_coords[] = {
1, 1 1, 1
}; };
static bool keep_aspect = true;
typedef struct gl typedef struct gl
{ {
bool vsync; bool vsync;
unsigned real_x; unsigned real_x;
unsigned real_y; unsigned real_y;
#ifdef HAVE_CG
CGcontext cgCtx;
CGprogram cgPrg;
CGprofile cgVProf;
CGparameter cg_video_size, cg_texture_size;
#endif
GLuint texture;
GLuint tex_filter;
} gl_t; } gl_t;
@ -228,14 +226,13 @@ static inline void show_fps(void)
static bool gl_frame(void *data, const uint16_t* frame, int width, int height, int pitch) static bool gl_frame(void *data, const uint16_t* frame, int width, int height, int pitch)
{ {
//gl_t *gl = data; gl_t *gl = data;
(void)data;
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
#if HAVE_CG #if HAVE_CG
cgGLSetParameter2f(cg_video_size, width, height); cgGLSetParameter2f(gl->cg_video_size, width, height);
cgGLSetParameter2f(cg_texture_size, width, height); cgGLSetParameter2f(gl->cg_texture_size, width, height);
#endif #endif
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch >> 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch >> 1);
@ -252,12 +249,13 @@ static bool gl_frame(void *data, const uint16_t* frame, int width, int height, i
static void gl_free(void *data) static void gl_free(void *data)
{ {
gl_t *gl = data;
#ifdef HAVE_CG #ifdef HAVE_CG
cgDestroyContext(cgCtx); cgDestroyContext(gl->cgCtx);
#endif #endif
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDeleteTextures(1, &texture); glDeleteTextures(1, &gl->texture);
glfwTerminate(); glfwTerminate();
} }
@ -281,9 +279,9 @@ static void* gl_init(video_info_t *video, const input_driver_t **input)
keep_aspect = video->force_aspect; keep_aspect = video->force_aspect;
if ( video->smooth ) if ( video->smooth )
tex_filter = GL_LINEAR; gl->tex_filter = GL_LINEAR;
else else
tex_filter = GL_NEAREST; gl->tex_filter = GL_NEAREST;
glfwInit(); glfwInit();
@ -315,14 +313,14 @@ static void* gl_init(video_info_t *video, const input_driver_t **input)
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glGenTextures(1, &texture); glGenTextures(1, &gl->texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, gl->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, tex_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, tex_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -330,32 +328,32 @@ static void* gl_init(video_info_t *video, const input_driver_t **input)
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), tex_coords); glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), tex_coords);
#ifdef HAVE_CG #ifdef HAVE_CG
cgCtx = cgCreateContext(); gl->cgCtx = cgCreateContext();
if (cgCtx == NULL) if (gl->cgCtx == NULL)
{ {
fprintf(stderr, "Failed to create Cg context\n"); fprintf(stderr, "Failed to create Cg context\n");
goto error; goto error;
} }
cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); gl->cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
if (cgVProf == CG_PROFILE_UNKNOWN) if (gl->cgVProf == CG_PROFILE_UNKNOWN)
{ {
fprintf(stderr, "Invalid profile type\n"); fprintf(stderr, "Invalid profile type\n");
goto error; goto error;
} }
cgGLSetOptimalOptions(cgVProf); cgGLSetOptimalOptions(gl->cgVProf);
cgPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, cg_shader_path, cgVProf, "main", 0); gl->cgPrg = cgCreateProgramFromFile(gl->cgCtx, CG_SOURCE, cg_shader_path, gl->cgVProf, "main", 0);
if (cgPrg == NULL) if (gl->cgPrg == NULL)
{ {
CGerror err = cgGetError(); CGerror err = cgGetError();
fprintf(stderr, "CG error: %s\n", cgGetErrorString(err)); fprintf(stderr, "CG error: %s\n", cgGetErrorString(err));
goto error; goto error;
} }
cgGLLoadProgram(cgPrg); cgGLLoadProgram(gl->cgPrg);
cgGLEnableProfile(cgVProf); cgGLEnableProfile(gl->cgVProf);
cgGLBindProgram(cgPrg); cgGLBindProgram(gl->cgPrg);
cg_video_size = cgGetNamedParameter(cgPrg, "IN.video_size"); gl->cg_video_size = cgGetNamedParameter(gl->cgPrg, "IN.video_size");
cg_texture_size = cgGetNamedParameter(cgPrg, "IN.texture_size"); gl->cg_texture_size = cgGetNamedParameter(gl->cgPrg, "IN.texture_size");
#endif #endif