Can select to use Cg shaders.

This commit is contained in:
Themaister 2010-11-12 23:09:43 +01:00
parent e01a0e297a
commit 8eef955a48
4 changed files with 31 additions and 9 deletions

View File

@ -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)

View File

@ -22,6 +22,7 @@
#ifndef __CONFIG_H
#define __CONFIG_H
#include <GL/glfw.h>
#include <stdbool.h>
#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.

View File

@ -1,5 +1,6 @@
BUILD_OPENGL = 1
BUILD_CG = 1
BUILD_FILTER = 0
BUILD_RSOUND = 0

22
gl.c
View File

@ -18,20 +18,22 @@
#define GL_GLEXT_PROTOTYPES
#include "driver.h"
#include "config.h"
#include <GL/glfw.h>
#include <stdint.h>
#include "libsnes.hpp"
#include <stdio.h>
#include <sys/time.h>
#ifdef HAVE_CG
#include <Cg/cg.h>
#include <Cg/cgGL.h>
// 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 = {