Can select to use Cg shaders.
This commit is contained in:
parent
e01a0e297a
commit
8eef955a48
11
Makefile
11
Makefile
|
@ -2,6 +2,7 @@ include config.mk
|
||||||
|
|
||||||
TARGET = ssnes
|
TARGET = ssnes
|
||||||
|
|
||||||
|
DEFINES =
|
||||||
OBJ = ssnes.o
|
OBJ = ssnes.o
|
||||||
LIBS = -lsamplerate libsnes.a
|
LIBS = -lsamplerate libsnes.a
|
||||||
|
|
||||||
|
@ -27,8 +28,14 @@ endif
|
||||||
|
|
||||||
ifeq ($(BUILD_OPENGL), 1)
|
ifeq ($(BUILD_OPENGL), 1)
|
||||||
OBJ += gl.o
|
OBJ += gl.o
|
||||||
LIBS += -lglfw -lCg -lCgGL
|
LIBS += -lglfw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(BUILD_CG), 1)
|
||||||
|
LIBS += -lCg -lCgGL
|
||||||
|
DEFINES += -DHAVE_CG
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(BUILD_FILTER), 1)
|
ifeq ($(BUILD_FILTER), 1)
|
||||||
OBJ += hqflt/hq.o
|
OBJ += hqflt/hq.o
|
||||||
OBJ += hqflt/grayscale.o
|
OBJ += hqflt/grayscale.o
|
||||||
|
@ -37,7 +44,7 @@ ifeq ($(BUILD_FILTER), 1)
|
||||||
OBJ += hqflt/snes_ntsc/snes_ntsc.o
|
OBJ += hqflt/snes_ntsc/snes_ntsc.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS = -Wall -O3 -march=native -std=gnu99 -I.
|
CFLAGS = -Wall -O3 -march=native -std=gnu99 -Wno-unused-variable -I. $(DEFINES)
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
|
6
config.h
6
config.h
|
@ -22,6 +22,7 @@
|
||||||
#ifndef __CONFIG_H
|
#ifndef __CONFIG_H
|
||||||
#define __CONFIG_H
|
#define __CONFIG_H
|
||||||
|
|
||||||
|
#include <GL/glfw.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "libsnes.hpp"
|
#include "libsnes.hpp"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
|
@ -63,6 +64,9 @@ static const bool vsync = true;
|
||||||
// Smooths picture
|
// Smooths picture
|
||||||
static const bool video_smooth = false;
|
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
|
// On resize and fullscreen, rendering area will stay 4:3
|
||||||
static const bool force_aspect = true;
|
static const bool force_aspect = true;
|
||||||
|
|
||||||
|
@ -87,7 +91,7 @@ static const bool force_aspect = true;
|
||||||
static const bool audio_enable = true;
|
static const bool audio_enable = true;
|
||||||
|
|
||||||
// Output samplerate
|
// Output samplerate
|
||||||
static const unsigned out_rate = 44100;
|
static const unsigned out_rate = 48000;
|
||||||
|
|
||||||
// Input samplerate from libSNES.
|
// Input samplerate from libSNES.
|
||||||
// Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled.
|
// Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
BUILD_OPENGL = 1
|
BUILD_OPENGL = 1
|
||||||
|
BUILD_CG = 1
|
||||||
BUILD_FILTER = 0
|
BUILD_FILTER = 0
|
||||||
|
|
||||||
BUILD_RSOUND = 0
|
BUILD_RSOUND = 0
|
||||||
|
|
22
gl.c
22
gl.c
|
@ -18,20 +18,22 @@
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
|
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
|
#include "config.h"
|
||||||
#include <GL/glfw.h>
|
#include <GL/glfw.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "libsnes.hpp"
|
#include "libsnes.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CG
|
||||||
#include <Cg/cg.h>
|
#include <Cg/cg.h>
|
||||||
#include <Cg/cgGL.h>
|
#include <Cg/cgGL.h>
|
||||||
|
|
||||||
// Lots of globals, yes I know. :(
|
|
||||||
static CGcontext cgCtx;
|
static CGcontext cgCtx;
|
||||||
static CGprogram cgPrg;
|
static CGprogram cgPrg;
|
||||||
static CGprofile cgVProf;
|
static CGprofile cgVProf;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Lots of globals, yes I know. :(
|
||||||
static GLuint texture;
|
static GLuint texture;
|
||||||
static uint8_t *gl_buffer;
|
static uint8_t *gl_buffer;
|
||||||
static bool keep_aspect = true;
|
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)
|
static void gl_free(void *data)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_CG
|
||||||
|
cgDestroyContext(cgCtx);
|
||||||
|
#endif
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDeleteTextures(1, &texture);
|
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);
|
glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), vertexes);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), tex_coords);
|
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), tex_coords);
|
||||||
|
|
||||||
|
#ifdef HAVE_CG
|
||||||
cgCtx = cgCreateContext();
|
cgCtx = cgCreateContext();
|
||||||
if (cgCtx == NULL)
|
if (cgCtx == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to create Cg context\n");
|
fprintf(stderr, "Failed to create Cg context\n");
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
cgVProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
||||||
if (cgVProf == CG_PROFILE_UNKNOWN)
|
if (cgVProf == CG_PROFILE_UNKNOWN)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid profile type\n");
|
fprintf(stderr, "Invalid profile type\n");
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
cgGLSetOptimalOptions(cgVProf);
|
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)
|
if (cgPrg == NULL)
|
||||||
{
|
{
|
||||||
CGerror err = cgGetError();
|
CGerror err = cgGetError();
|
||||||
fprintf(stderr, "CG error: %s\n", cgGetErrorString(err));
|
fprintf(stderr, "CG error: %s\n", cgGetErrorString(err));
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
cgGLLoadProgram(cgPrg);
|
cgGLLoadProgram(cgPrg);
|
||||||
cgGLEnableProfile(cgVProf);
|
cgGLEnableProfile(cgVProf);
|
||||||
cgGLBindProgram(cgPrg);
|
cgGLBindProgram(cgPrg);
|
||||||
|
#endif
|
||||||
|
|
||||||
*input = &input_glfw;
|
*input = &input_glfw;
|
||||||
return gl;
|
return gl;
|
||||||
|
error:
|
||||||
|
free(gl);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const video_driver_t video_gl = {
|
const video_driver_t video_gl = {
|
||||||
|
|
Loading…
Reference in New Issue