diff --git a/Makefile b/Makefile index 35185ddf6c..4fc8717b0c 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ include config.mk TARGET = ssnes +DEFINES = OBJ = ssnes.o LIBS = -lsamplerate libsnes.a @@ -27,8 +28,14 @@ endif ifeq ($(BUILD_OPENGL), 1) OBJ += gl.o - LIBS += -lglfw -lCg -lCgGL + LIBS += -lglfw endif + +ifeq ($(BUILD_CG), 1) + LIBS += -lCg -lCgGL + DEFINES += -DHAVE_CG +endif + ifeq ($(BUILD_FILTER), 1) OBJ += hqflt/hq.o OBJ += hqflt/grayscale.o @@ -37,7 +44,7 @@ ifeq ($(BUILD_FILTER), 1) OBJ += hqflt/snes_ntsc/snes_ntsc.o endif -CFLAGS = -Wall -O3 -march=native -std=gnu99 -I. +CFLAGS = -Wall -O3 -march=native -std=gnu99 -Wno-unused-variable -I. $(DEFINES) all: $(TARGET) diff --git a/config.h b/config.h index ac891d0636..edeb0f3ab8 100644 --- a/config.h +++ b/config.h @@ -22,6 +22,7 @@ #ifndef __CONFIG_H #define __CONFIG_H +#include #include #include "libsnes.hpp" #include "driver.h" @@ -63,6 +64,9 @@ static const bool vsync = true; // Smooths picture static const bool video_smooth = false; +// Path to custom Cg shader. If using custom shaders, it is recommended to disable video_smooth and VIDEO_FILTER. +static const char *cg_shader_path = "hqflt/crt.cg"; + // On resize and fullscreen, rendering area will stay 4:3 static const bool force_aspect = true; @@ -87,7 +91,7 @@ static const bool force_aspect = true; static const bool audio_enable = true; // Output samplerate -static const unsigned out_rate = 44100; +static const unsigned out_rate = 48000; // Input samplerate from libSNES. // Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled. diff --git a/config.mk b/config.mk index 4a8dae50e4..6907ff9c5b 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,6 @@ BUILD_OPENGL = 1 +BUILD_CG = 1 BUILD_FILTER = 0 BUILD_RSOUND = 0 diff --git a/gl.c b/gl.c index 0e6e381c33..1a430a85df 100644 --- a/gl.c +++ b/gl.c @@ -18,20 +18,22 @@ #define GL_GLEXT_PROTOTYPES #include "driver.h" +#include "config.h" #include #include #include "libsnes.hpp" #include #include +#ifdef HAVE_CG #include #include - -// Lots of globals, yes I know. :( static CGcontext cgCtx; static CGprogram cgPrg; static CGprofile cgVProf; +#endif +// Lots of globals, yes I know. :( static GLuint texture; static uint8_t *gl_buffer; static bool keep_aspect = true; @@ -244,6 +246,9 @@ static bool gl_frame(void *data, const uint16_t* frame, int width, int height, i static void gl_free(void *data) { +#ifdef HAVE_CG + cgDestroyContext(cgCtx); +#endif glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDeleteTextures(1, &texture); @@ -319,32 +324,37 @@ static void* gl_init(video_info_t *video, const input_driver_t **input) glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), vertexes); glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), tex_coords); +#ifdef HAVE_CG cgCtx = cgCreateContext(); if (cgCtx == NULL) { fprintf(stderr, "Failed to create Cg context\n"); - return NULL; + goto error; } cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT); if (cgVProf == CG_PROFILE_UNKNOWN) { fprintf(stderr, "Invalid profile type\n"); - return NULL; + goto error; } cgGLSetOptimalOptions(cgVProf); - cgPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, "hqflt/crt.cg", cgVProf, "main", 0); + cgPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, cg_shader_path, cgVProf, "main", 0); if (cgPrg == NULL) { CGerror err = cgGetError(); fprintf(stderr, "CG error: %s\n", cgGetErrorString(err)); - return NULL; + goto error; } cgGLLoadProgram(cgPrg); cgGLEnableProfile(cgVProf); cgGLBindProgram(cgPrg); +#endif *input = &input_glfw; return gl; +error: + free(gl); + return NULL; } const video_driver_t video_gl = {