Configurable FBO support.

This commit is contained in:
Themaister 2011-03-23 23:48:13 +01:00
parent e484e22e2f
commit 6c85e6e702
7 changed files with 47 additions and 1 deletions

View File

@ -77,6 +77,10 @@ else
endif
endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
endif
ifeq ($(HAVE_XVIDEO), 1)
OBJ += gfx/xvideo.o input/x11_input.o
LIBS += -lXv -lX11

View File

@ -14,6 +14,7 @@ HAVE_XAUDIO = 1
HAVE_RSOUND = 1
HAVE_FILTER = 1
HAVE_NETPLAY = 1
HAVE_FBO = 1
libsnes ?= -lsnes
LIBS = -lm
@ -76,6 +77,10 @@ else
LIBS += $(libsnes)
endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
endif
ifneq ($(V),1)
Q := @
endif

View File

@ -80,6 +80,12 @@ static const bool _xml_supp = true;
static const bool _xml_supp = false;
#endif
#ifdef HAVE_FBO
static const bool _fbo_supp = true;
#else
static const bool _fbo_supp = false;
#endif
#ifdef HAVE_DYNAMIC
static const bool _dynamic_supp = true;
#else

View File

@ -73,6 +73,7 @@ static const GLfloat fbo_tex_coords[] = {
1, 0
};
#ifdef HAVE_FBO
#ifdef _WIN32
static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL;
static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL;
@ -100,6 +101,7 @@ static bool load_fbo_proc(void)
#define pglDeleteFramebuffers glDeleteFramebuffers
static bool load_fbo_proc(void) { return true; }
#endif
#endif
#define MAX_SHADERS 16
@ -109,6 +111,7 @@ typedef struct gl
GLuint texture;
GLuint tex_filter;
#ifdef HAVE_FBO
// Render-to-texture, multipass shaders
GLuint fbo[MAX_SHADERS];
GLuint fbo_texture[MAX_SHADERS];
@ -117,6 +120,7 @@ typedef struct gl
bool render_to_tex;
int fbo_pass;
bool fbo_inited;
#endif
bool should_resize;
bool quitting;
@ -132,7 +136,9 @@ typedef struct gl
unsigned last_height;
unsigned tex_w, tex_h;
GLfloat tex_coords[8];
#ifdef HAVE_FBO
GLfloat fbo_tex_coords[8];
#endif
GLenum texture_type; // XBGR1555 or RGBA
GLenum texture_fmt;
@ -270,6 +276,7 @@ static bool gl_shader_filter_type(unsigned index, bool *smooth)
return valid;
}
#ifdef HAVE_FBO
static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
{
scale->valid = false;
@ -283,6 +290,7 @@ static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
gl_glsl_shader_scale(index, scale);
#endif
}
#endif
///////////////////
//////////////// Message rendering
@ -310,6 +318,7 @@ static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_s
static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
{
#ifdef HAVE_FBO
if (!g_settings.video.render_to_texture && gl_shader_num() <= 1)
return;
@ -404,6 +413,11 @@ error:
glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
SSNES_WARN("Failed to set up FBO. Two-pass shading will not work.\n");
#else
(void)gl;
(void)width;
(void)height;
#endif
}
static inline void gl_deinit_font(gl_t *gl)
@ -537,6 +551,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
gl_shader_use(1);
#ifdef HAVE_FBO
// Render to texture in first pass.
if (gl->fbo_inited)
{
@ -552,13 +567,16 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
gl->render_to_tex = true;
set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true);
}
#endif
if (gl->should_resize)
{
gl->should_resize = false;
SDL_SetVideoMode(gl->win_width, gl->win_height, 0, SDL_OPENGL | SDL_RESIZABLE | (g_settings.video.fullscreen ? SDL_FULLSCREEN : 0));
#ifdef HAVE_FBO
if (!gl->render_to_tex)
#endif
set_viewport(gl, gl->win_width, gl->win_height, false);
}
@ -597,6 +615,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
glDrawArrays(GL_QUADS, 0, 4);
#ifdef HAVE_FBO
if (gl->fbo_inited)
{
// Render the rest of our passes.
@ -655,6 +674,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
glDrawArrays(GL_QUADS, 0, 4);
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), gl->tex_coords);
}
#endif
if (msg)
gl_render_msg(gl, msg);
@ -676,11 +696,14 @@ static void gl_free(void *data)
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDeleteTextures(1, &gl->texture);
#ifdef HAVE_FBO
if (gl->fbo_inited)
{
glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
}
#endif
SDL_QuitSubSystem(SDL_INIT_VIDEO);
free(gl);

View File

@ -27,6 +27,12 @@ else
check_lib AL -lopenal alcOpenDevice
fi
if [ "$OS" = "Darwin" ]; then
check_lib FBO "-framework OpenGL" glFramebufferTexture2D
else
check_lib FBO -lGL glFramebufferTexture2D
fi
check_pkgconf RSOUND rsound 1.1
check_lib ROAR -lroar roar_vs_new
check_pkgconf JACK jack 0.120.1
@ -56,7 +62,7 @@ check_pkgconf FREETYPE freetype2
check_lib XVIDEO -lXv XvShmCreateImage
# Creates config.mk and config.h.
VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY"
VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO"
create_config_make config.mk $VARS
create_config_header config.h $VARS

View File

@ -16,6 +16,7 @@ add_command_line_enable SRC "Enable libsamplerate support" no
add_command_line_enable CONFIGFILE "Disable support for config file" yes
add_command_line_enable CG "Enable Cg shader support" auto
add_command_line_enable XML "Enable bSNES-style XML shader support" auto
add_command_line_enable FBO "Enable render-to-texture (FBO) support" auto
add_command_line_enable ALSA "Enable ALSA support" auto
add_command_line_enable OSS "Enable OSS support" auto
add_command_line_enable RSOUND "Enable RSound support" auto

View File

@ -263,6 +263,7 @@ static void print_features(void)
_PSUPP(filter, "Filter", "CPU based video filters");
_PSUPP(cg, "Cg", "Cg pixel shaders");
_PSUPP(xml, "XML", "bSNES XML pixel shaders");
_PSUPP(fbo, "FBO", "OpenGL render-to-texture (multi-pass shaders)");
_PSUPP(dynamic, "Dynamic", "Dynamic run-time loading of libsnes library");
_PSUPP(ffmpeg, "FFmpeg", "On-the-fly recording of gameplay with libavcodec");
_PSUPP(src, "SRC", "libsamplerate audio resampling");