2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-01-08 00:08:18 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
2010-05-28 16:22:06 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2010-05-28 16:22:06 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2010-05-28 16:22:06 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2010-05-28 16:22:06 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../driver.h"
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
#include <stdint.h>
|
2012-04-07 09:55:37 +00:00
|
|
|
#include "../libretro.h"
|
2010-05-28 00:45:18 +00:00
|
|
|
#include <stdio.h>
|
2010-12-26 03:15:12 +00:00
|
|
|
#include <string.h>
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../general.h"
|
2011-03-06 18:56:35 +00:00
|
|
|
#include <math.h>
|
2011-01-07 16:59:53 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-12-30 11:54:16 +00:00
|
|
|
#include "config.h"
|
2011-01-07 16:59:53 +00:00
|
|
|
#endif
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2011-03-14 21:09:35 +00:00
|
|
|
#include "gl_common.h"
|
2012-05-26 13:21:51 +00:00
|
|
|
#include "gl_font.h"
|
2011-03-26 17:34:58 +00:00
|
|
|
#include "gfx_common.h"
|
2012-05-26 02:47:24 +00:00
|
|
|
#include "gfx_context.h"
|
2012-03-16 22:26:57 +00:00
|
|
|
#include "../compat/strl.h"
|
2011-01-06 22:15:49 +00:00
|
|
|
|
2012-05-25 21:18:38 +00:00
|
|
|
#ifdef HAVE_SDL
|
2011-02-04 12:46:51 +00:00
|
|
|
#define NO_SDL_GLEXT
|
2012-05-26 08:20:06 +00:00
|
|
|
#include "context/sdl_ctx.h"
|
2012-04-21 21:25:32 +00:00
|
|
|
#include "../input/rarch_sdl_input.h"
|
2012-05-25 21:18:38 +00:00
|
|
|
#endif
|
2011-02-04 12:46:51 +00:00
|
|
|
|
2010-11-12 22:09:43 +00:00
|
|
|
#ifdef HAVE_CG
|
2011-01-05 16:22:12 +00:00
|
|
|
#include "shader_cg.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
|
|
|
#include "shader_glsl.h"
|
2010-11-12 22:09:43 +00:00
|
|
|
#endif
|
2010-11-12 21:32:38 +00:00
|
|
|
|
2011-01-11 21:13:55 +00:00
|
|
|
|
2011-01-22 23:27:20 +00:00
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
#include "fonts.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-05 00:21:35 +00:00
|
|
|
// Used for the last pass when rendering to the back buffer.
|
|
|
|
static const GLfloat vertexes_flipped[] = {
|
2011-03-12 18:28:56 +00:00
|
|
|
0, 0,
|
|
|
|
0, 1,
|
|
|
|
1, 1,
|
|
|
|
1, 0
|
2010-11-08 23:01:17 +00:00
|
|
|
};
|
|
|
|
|
2011-06-05 00:21:35 +00:00
|
|
|
// Used when rendering to an FBO.
|
|
|
|
// Texture coords have to be aligned with vertex coordinates.
|
|
|
|
static const GLfloat vertexes[] = {
|
2011-06-01 10:19:48 +00:00
|
|
|
0, 1,
|
|
|
|
0, 0,
|
|
|
|
1, 0,
|
|
|
|
1, 1
|
|
|
|
};
|
|
|
|
|
2010-11-12 21:32:38 +00:00
|
|
|
static const GLfloat tex_coords[] = {
|
|
|
|
0, 1,
|
2010-11-08 23:13:57 +00:00
|
|
|
0, 0,
|
2010-11-12 21:32:38 +00:00
|
|
|
1, 0,
|
|
|
|
1, 1
|
2010-11-08 23:13:57 +00:00
|
|
|
};
|
|
|
|
|
2011-11-12 14:51:37 +00:00
|
|
|
static const GLfloat white_color[] = {
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
};
|
|
|
|
|
2012-05-25 21:18:38 +00:00
|
|
|
#ifdef HAVE_SDL
|
2011-12-24 23:59:46 +00:00
|
|
|
#define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) }
|
2012-05-25 21:18:38 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-05-26 13:45:00 +00:00
|
|
|
#if defined(_WIN32) && !defined(RARCH_CONSOLE)
|
2011-03-06 21:18:25 +00:00
|
|
|
static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL;
|
|
|
|
static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL;
|
|
|
|
static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL;
|
|
|
|
static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL;
|
|
|
|
static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL;
|
|
|
|
|
|
|
|
static bool load_fbo_proc(void)
|
|
|
|
{
|
|
|
|
LOAD_SYM(glGenFramebuffers);
|
|
|
|
LOAD_SYM(glBindFramebuffer);
|
|
|
|
LOAD_SYM(glFramebufferTexture2D);
|
|
|
|
LOAD_SYM(glCheckFramebufferStatus);
|
|
|
|
LOAD_SYM(glDeleteFramebuffers);
|
|
|
|
|
|
|
|
return pglGenFramebuffers && pglBindFramebuffer && pglFramebufferTexture2D &&
|
|
|
|
pglCheckFramebufferStatus && pglDeleteFramebuffers;
|
|
|
|
}
|
2012-05-25 14:00:17 +00:00
|
|
|
#elif defined(HAVE_OPENGLES)
|
|
|
|
#define pglGenFramebuffers glGenFramebuffersOES
|
|
|
|
#define pglBindFramebuffer glBindFramebufferOES
|
|
|
|
#define pglFramebufferTexture2D glFramebufferTexture2DOES
|
|
|
|
#define pglCheckFramebufferStatus glCheckFramebufferStatusOES
|
|
|
|
#define pglDeleteFramebuffers glDeleteFramebuffersOES
|
2012-05-25 14:20:28 +00:00
|
|
|
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
|
|
|
|
#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
|
|
|
|
#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES
|
2012-05-26 13:45:00 +00:00
|
|
|
#define glOrtho glOrthof
|
2012-05-25 14:00:17 +00:00
|
|
|
static bool load_fbo_proc(void) { return true; }
|
2011-03-06 21:18:25 +00:00
|
|
|
#else
|
|
|
|
#define pglGenFramebuffers glGenFramebuffers
|
|
|
|
#define pglBindFramebuffer glBindFramebuffer
|
|
|
|
#define pglFramebufferTexture2D glFramebufferTexture2D
|
|
|
|
#define pglCheckFramebufferStatus glCheckFramebufferStatus
|
|
|
|
#define pglDeleteFramebuffers glDeleteFramebuffers
|
|
|
|
static bool load_fbo_proc(void) { return true; }
|
|
|
|
#endif
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-03-06 21:18:25 +00:00
|
|
|
|
2011-05-22 16:48:43 +00:00
|
|
|
#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32)
|
2011-05-18 20:40:42 +00:00
|
|
|
PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture = NULL;
|
|
|
|
PFNGLACTIVETEXTUREPROC pglActiveTexture = NULL;
|
|
|
|
static inline bool load_gl_proc(void)
|
|
|
|
{
|
|
|
|
LOAD_SYM(glClientActiveTexture);
|
|
|
|
LOAD_SYM(glActiveTexture);
|
|
|
|
return pglClientActiveTexture && pglActiveTexture;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline bool load_gl_proc(void) { return true; }
|
|
|
|
#endif
|
|
|
|
|
2011-01-22 23:27:20 +00:00
|
|
|
////////////////// Shaders
|
2011-02-28 15:59:31 +00:00
|
|
|
static bool gl_shader_init(void)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2011-02-28 15:59:31 +00:00
|
|
|
switch (g_settings.video.shader_type)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SHADER_AUTO:
|
2011-02-28 15:59:31 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
if (*g_settings.video.cg_shader_path && *g_settings.video.bsnes_shader_path)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n");
|
2011-02-28 15:59:31 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CG
|
2012-01-31 23:14:04 +00:00
|
|
|
if (*g_settings.video.cg_shader_path)
|
2011-02-28 15:59:31 +00:00
|
|
|
return gl_cg_init(g_settings.video.cg_shader_path);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
2012-01-31 23:14:04 +00:00
|
|
|
if (*g_settings.video.bsnes_shader_path)
|
2011-02-28 15:59:31 +00:00
|
|
|
return gl_glsl_init(g_settings.video.bsnes_shader_path);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2011-01-05 18:29:29 +00:00
|
|
|
|
2011-01-05 16:22:12 +00:00
|
|
|
#ifdef HAVE_CG
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SHADER_CG:
|
2011-02-28 15:59:31 +00:00
|
|
|
{
|
|
|
|
return gl_cg_init(g_settings.video.cg_shader_path);
|
|
|
|
break;
|
|
|
|
}
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SHADER_BSNES:
|
2011-02-28 15:59:31 +00:00
|
|
|
{
|
|
|
|
return gl_glsl_init(g_settings.video.bsnes_shader_path);
|
|
|
|
break;
|
|
|
|
}
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-28 15:59:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-05 16:22:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:40:19 +00:00
|
|
|
static void gl_shader_use(unsigned index)
|
2011-01-22 23:27:20 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
2011-03-06 18:56:35 +00:00
|
|
|
gl_cg_use(index);
|
2011-01-22 23:27:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
2011-03-06 18:56:35 +00:00
|
|
|
gl_glsl_use(index);
|
2011-01-22 23:27:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
static void gl_shader_deinit(void)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
|
|
|
gl_cg_deinit();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
|
|
|
gl_glsl_deinit();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
static void gl_shader_set_proj_matrix(void)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
|
|
|
gl_cg_set_proj_matrix();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
|
|
|
gl_glsl_set_proj_matrix();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:40:19 +00:00
|
|
|
static void gl_shader_set_params(unsigned width, unsigned height,
|
2011-01-05 16:22:12 +00:00
|
|
|
unsigned tex_width, unsigned tex_height,
|
2011-05-11 11:24:59 +00:00
|
|
|
unsigned out_width, unsigned out_height,
|
2011-05-23 15:41:52 +00:00
|
|
|
unsigned frame_count,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *info,
|
2011-07-03 13:39:35 +00:00
|
|
|
const struct gl_tex_info *prev_info,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
2011-05-23 15:41:52 +00:00
|
|
|
gl_cg_set_params(width, height,
|
|
|
|
tex_width, tex_height,
|
|
|
|
out_width, out_height,
|
2011-07-03 13:39:35 +00:00
|
|
|
frame_count, info, prev_info, fbo_info, fbo_info_cnt);
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
2011-05-23 15:41:52 +00:00
|
|
|
gl_glsl_set_params(width, height,
|
|
|
|
tex_width, tex_height,
|
|
|
|
out_width, out_height,
|
2011-07-03 13:39:35 +00:00
|
|
|
frame_count, info, prev_info, fbo_info, fbo_info_cnt);
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
static unsigned gl_shader_num(void)
|
2011-03-12 14:30:57 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_CG
|
|
|
|
unsigned cg_num = gl_cg_num();
|
2012-01-31 23:14:04 +00:00
|
|
|
if (cg_num)
|
|
|
|
return cg_num;
|
2011-03-12 14:30:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
|
|
|
unsigned glsl_num = gl_glsl_num();
|
2012-01-31 23:14:04 +00:00
|
|
|
if (glsl_num)
|
|
|
|
return glsl_num;
|
2011-03-12 14:30:57 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
return 0;
|
2011-03-12 14:30:57 +00:00
|
|
|
}
|
2011-03-14 20:28:30 +00:00
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
static bool gl_shader_filter_type(unsigned index, bool *smooth)
|
2011-03-14 21:09:35 +00:00
|
|
|
{
|
|
|
|
bool valid = false;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2011-03-14 21:09:35 +00:00
|
|
|
#ifdef HAVE_CG
|
|
|
|
if (!valid)
|
|
|
|
valid = gl_cg_filter_type(index, smooth);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
|
|
|
if (!valid)
|
|
|
|
valid = gl_glsl_filter_type(index, smooth);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2011-03-14 21:51:03 +00:00
|
|
|
static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
|
2011-03-14 20:28:30 +00:00
|
|
|
{
|
2011-03-14 21:51:03 +00:00
|
|
|
scale->valid = false;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2011-03-14 20:28:30 +00:00
|
|
|
#ifdef HAVE_CG
|
2011-03-14 21:51:03 +00:00
|
|
|
if (!scale->valid)
|
|
|
|
gl_cg_shader_scale(index, scale);
|
2011-03-14 20:28:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XML
|
2011-03-14 21:51:03 +00:00
|
|
|
if (!scale->valid)
|
|
|
|
gl_glsl_shader_scale(index, scale);
|
2011-03-14 20:28:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-01-22 23:27:20 +00:00
|
|
|
///////////////////
|
|
|
|
|
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height,
|
|
|
|
unsigned vp_width, unsigned vp_height);
|
|
|
|
|
|
|
|
static void gl_create_fbo_textures(gl_t *gl)
|
|
|
|
{
|
|
|
|
glGenTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
|
|
|
|
GLuint base_filt = g_settings.video.second_pass_smooth ? GL_LINEAR : GL_NEAREST;
|
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
|
|
|
|
|
|
|
GLuint filter_type = base_filt;
|
|
|
|
bool smooth;
|
|
|
|
if (gl_shader_filter_type(i + 2, &smooth))
|
|
|
|
filter_type = smooth ? GL_LINEAR : GL_NEAREST;
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type);
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-05-26 14:29:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, RARCH_GL_TEXTURE_TYPE,
|
|
|
|
RARCH_GL_FORMAT32, NULL);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool gl_create_fbo_targets(gl_t *gl)
|
|
|
|
{
|
|
|
|
pglGenFramebuffers(gl->fbo_pass, gl->fbo);
|
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
|
|
|
{
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]);
|
|
|
|
pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0);
|
|
|
|
|
|
|
|
GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n");
|
2012-01-31 23:14:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_deinit_fbo(gl_t *gl)
|
|
|
|
{
|
|
|
|
if (gl->fbo_inited)
|
|
|
|
{
|
|
|
|
glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
|
|
|
|
memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture));
|
|
|
|
memset(gl->fbo, 0, sizeof(gl->fbo));
|
|
|
|
gl->fbo_inited = false;
|
|
|
|
gl->render_to_tex = false;
|
|
|
|
gl->fbo_pass = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
|
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
// No need to use FBOs.
|
2011-03-30 21:09:29 +00:00
|
|
|
if (!g_settings.video.render_to_texture && gl_shader_num() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct gl_fbo_scale scale, scale_last;
|
|
|
|
gl_shader_scale(1, &scale);
|
|
|
|
gl_shader_scale(gl_shader_num(), &scale_last);
|
|
|
|
|
|
|
|
// No need to use FBOs.
|
|
|
|
if (gl_shader_num() == 1 && !scale.valid && !g_settings.video.render_to_texture)
|
2011-03-06 18:56:35 +00:00
|
|
|
return;
|
|
|
|
|
2011-03-06 21:18:25 +00:00
|
|
|
if (!load_fbo_proc())
|
2011-03-06 23:03:10 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to locate FBO functions. Won't be able to use render-to-texture.\n");
|
2011-03-06 21:18:25 +00:00
|
|
|
return;
|
2011-03-06 23:03:10 +00:00
|
|
|
}
|
2011-03-06 21:18:25 +00:00
|
|
|
|
2011-03-12 15:33:01 +00:00
|
|
|
gl->fbo_pass = gl_shader_num() - 1;
|
2011-03-30 21:09:29 +00:00
|
|
|
if (scale_last.valid)
|
2011-03-14 22:20:51 +00:00
|
|
|
gl->fbo_pass++;
|
2011-03-23 10:05:18 +00:00
|
|
|
|
2011-03-30 21:09:29 +00:00
|
|
|
if (gl->fbo_pass <= 0)
|
|
|
|
gl->fbo_pass = 1;
|
|
|
|
|
2011-03-23 10:05:18 +00:00
|
|
|
if (!scale.valid)
|
2011-03-15 17:14:01 +00:00
|
|
|
{
|
|
|
|
scale.scale_x = g_settings.video.fbo_scale_x;
|
|
|
|
scale.scale_y = g_settings.video.fbo_scale_y;
|
2012-04-21 21:25:32 +00:00
|
|
|
scale.type_x = scale.type_y = RARCH_SCALE_INPUT;
|
2012-01-31 23:14:04 +00:00
|
|
|
scale.valid = true;
|
2011-03-15 17:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gl->fbo_scale[0] = scale;
|
2011-03-27 18:29:47 +00:00
|
|
|
|
2011-03-15 17:14:01 +00:00
|
|
|
for (int i = 1; i < gl->fbo_pass; i++)
|
2011-03-14 22:20:51 +00:00
|
|
|
{
|
|
|
|
gl_shader_scale(i + 1, &gl->fbo_scale[i]);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
if (!gl->fbo_scale[i].valid)
|
2011-03-14 22:20:51 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_scale[i].scale_x = gl->fbo_scale[i].scale_y = 1.0f;
|
2012-04-21 21:25:32 +00:00
|
|
|
gl->fbo_scale[i].type_x = gl->fbo_scale[i].type_y = RARCH_SCALE_INPUT;
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_scale[i].valid = true;
|
2011-03-14 22:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_compute_fbo_geometry(gl, width, height, gl->win_width, gl->win_height);
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2011-03-12 15:33:01 +00:00
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].width = next_pow2(gl->fbo_rect[i].img_width);
|
|
|
|
gl->fbo_rect[i].height = next_pow2(gl->fbo_rect[i].img_height);
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Creating FBO %d @ %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height);
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
2011-03-14 20:28:30 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_create_fbo_textures(gl);
|
|
|
|
if (!gl_create_fbo_targets(gl))
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
return;
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
2011-03-12 15:33:01 +00:00
|
|
|
|
|
|
|
gl->fbo_inited = true;
|
2011-03-06 15:52:49 +00:00
|
|
|
}
|
2012-01-30 19:22:36 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2011-03-06 21:18:25 +00:00
|
|
|
////////////
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2012-04-02 15:26:23 +00:00
|
|
|
static void set_projection(gl_t *gl, bool allow_rotate)
|
2011-03-20 01:10:02 +00:00
|
|
|
{
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2012-04-02 15:26:23 +00:00
|
|
|
|
|
|
|
if (allow_rotate)
|
|
|
|
glRotatef(gl->rotation, 0, 0, 1);
|
|
|
|
|
2012-04-01 17:20:37 +00:00
|
|
|
glOrtho(0, 1, 0, 1, -1, 1);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2012-04-02 15:26:23 +00:00
|
|
|
|
|
|
|
gl_shader_set_proj_matrix();
|
2012-04-01 17:20:37 +00:00
|
|
|
}
|
2011-03-20 01:10:02 +00:00
|
|
|
|
2012-04-02 15:26:23 +00:00
|
|
|
static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate)
|
2012-04-01 17:20:37 +00:00
|
|
|
{
|
2011-03-20 01:10:02 +00:00
|
|
|
if (gl->keep_aspect && !force_full)
|
|
|
|
{
|
|
|
|
float desired_aspect = g_settings.video.aspect_ratio;
|
|
|
|
float device_aspect = (float)width / height;
|
|
|
|
|
|
|
|
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
|
|
|
// assume they are actually equal.
|
|
|
|
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
|
|
|
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
|
|
|
glViewport(width * (0.5 - delta), 0, 2.0 * width * delta, height);
|
|
|
|
width = 2.0 * width * delta;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
|
|
|
glViewport(0, height * (0.5 - delta), width, 2.0 * height * delta);
|
|
|
|
height = 2.0 * height * delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
2012-04-02 15:26:23 +00:00
|
|
|
set_projection(gl, allow_rotate);
|
2011-03-20 01:10:02 +00:00
|
|
|
|
|
|
|
gl->vp_width = width;
|
|
|
|
gl->vp_height = height;
|
|
|
|
|
2011-03-27 18:29:47 +00:00
|
|
|
// Set last backbuffer viewport.
|
|
|
|
if (!force_full)
|
|
|
|
{
|
|
|
|
gl->vp_out_width = width;
|
|
|
|
gl->vp_out_height = height;
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
//RARCH_LOG("Setting viewport @ %ux%u\n", width, height);
|
2011-03-20 01:10:02 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 17:20:37 +00:00
|
|
|
static void gl_set_rotation(void *data, unsigned rotation)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
gl->rotation = 90 * rotation;
|
2012-04-02 15:26:23 +00:00
|
|
|
set_projection(gl, true);
|
2012-04-01 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 00:01:44 +00:00
|
|
|
static inline void set_lut_texture_coords(const GLfloat *coords)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_XML) || defined(HAVE_CG)
|
|
|
|
// For texture images.
|
|
|
|
pglClientActiveTexture(GL_TEXTURE1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2011-11-12 14:51:37 +00:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, coords);
|
2011-06-05 00:01:44 +00:00
|
|
|
pglClientActiveTexture(GL_TEXTURE0);
|
|
|
|
#else
|
|
|
|
(void)coords;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-05 00:21:35 +00:00
|
|
|
static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt)
|
|
|
|
{
|
|
|
|
coords[1] = yamt;
|
|
|
|
coords[4] = xamt;
|
|
|
|
coords[6] = xamt;
|
|
|
|
coords[7] = yamt;
|
|
|
|
}
|
|
|
|
|
2011-06-11 10:54:14 +00:00
|
|
|
static void check_window(gl_t *gl)
|
|
|
|
{
|
2011-09-13 12:06:49 +00:00
|
|
|
bool quit, resize;
|
2011-06-11 10:54:14 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_check_window(&quit,
|
2011-09-13 12:06:49 +00:00
|
|
|
&resize, &gl->win_width, &gl->win_height,
|
|
|
|
gl->frame_count);
|
|
|
|
|
|
|
|
if (quit)
|
|
|
|
gl->quitting = true;
|
|
|
|
else if (resize)
|
|
|
|
gl->should_resize = true;
|
2011-06-11 10:54:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height,
|
|
|
|
unsigned vp_width, unsigned vp_height)
|
2010-11-08 22:38:32 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
unsigned last_width = width;
|
|
|
|
unsigned last_height = height;
|
|
|
|
unsigned last_max_width = gl->tex_w;
|
|
|
|
unsigned last_max_height = gl->tex_h;
|
|
|
|
// Calculate viewports for FBOs.
|
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
|
|
|
{
|
|
|
|
switch (gl->fbo_scale[i].type_x)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_INPUT:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x;
|
|
|
|
gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x;
|
|
|
|
break;
|
2011-06-11 10:54:14 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x;
|
|
|
|
break;
|
2011-05-11 11:24:59 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_VIEWPORT:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * vp_width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (gl->fbo_scale[i].type_y)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_INPUT:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y;
|
|
|
|
gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y;
|
|
|
|
break;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y;
|
|
|
|
break;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SCALE_VIEWPORT:
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * vp_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_width = gl->fbo_rect[i].img_width;
|
|
|
|
last_height = gl->fbo_rect[i].img_height;
|
|
|
|
last_max_width = gl->fbo_rect[i].max_img_width;
|
|
|
|
last_max_height = gl->fbo_rect[i].max_img_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_start_frame_fbo(gl_t *gl)
|
|
|
|
{
|
2011-07-03 13:39:35 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2012-01-31 23:14:04 +00:00
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]);
|
|
|
|
gl->render_to_tex = true;
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false);
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
// Need to preserve the "flipped" state when in FBO as well to have
|
|
|
|
// consistent texture coordinates.
|
|
|
|
// We will "flip" it in place on last pass.
|
|
|
|
if (gl->render_to_tex)
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, vertexes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_check_fbo_dimensions(gl_t *gl)
|
|
|
|
{
|
|
|
|
// Check if we have to recreate our FBO textures.
|
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
// Check proactively since we might suddently get sizes of tex_w width or tex_h height.
|
|
|
|
if (gl->fbo_rect[i].max_img_width > gl->fbo_rect[i].width ||
|
|
|
|
gl->fbo_rect[i].max_img_height > gl->fbo_rect[i].height)
|
2011-03-14 22:48:19 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
unsigned img_width = gl->fbo_rect[i].max_img_width;
|
|
|
|
unsigned img_height = gl->fbo_rect[i].max_img_height;
|
|
|
|
unsigned max = img_width > img_height ? img_width : img_height;
|
|
|
|
unsigned pow2_size = next_pow2(max);
|
|
|
|
gl->fbo_rect[i].width = gl->fbo_rect[i].height = pow2_size;
|
|
|
|
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-05-26 14:29:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, RARCH_GL_TEXTURE_TYPE,
|
|
|
|
RARCH_GL_FORMAT32, NULL);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0);
|
|
|
|
|
|
|
|
GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Failed to reinit FBO texture.\n");
|
2011-03-14 22:48:19 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Recreating FBO texture #%d: %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-03-14 22:48:19 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info)
|
|
|
|
{
|
|
|
|
GLfloat fbo_tex_coords[8] = {0.0f};
|
|
|
|
|
|
|
|
// Render the rest of our passes.
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords);
|
|
|
|
|
|
|
|
// It's kinda handy ... :)
|
|
|
|
const struct gl_fbo_rect *prev_rect;
|
|
|
|
const struct gl_fbo_rect *rect;
|
|
|
|
struct gl_tex_info *fbo_info;
|
|
|
|
|
|
|
|
struct gl_tex_info fbo_tex_info[MAX_SHADERS];
|
|
|
|
unsigned fbo_tex_info_cnt = 0;
|
|
|
|
|
|
|
|
// Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO.
|
|
|
|
for (int i = 1; i < gl->fbo_pass; i++)
|
2011-01-06 19:01:32 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
prev_rect = &gl->fbo_rect[i - 1];
|
|
|
|
rect = &gl->fbo_rect[i];
|
|
|
|
fbo_info = &fbo_tex_info[i - 1];
|
2011-09-11 13:33:28 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width;
|
|
|
|
GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height;
|
|
|
|
|
|
|
|
set_texture_coords(fbo_tex_coords, xamt, yamt);
|
|
|
|
|
|
|
|
fbo_info->tex = gl->fbo_texture[i - 1];
|
|
|
|
fbo_info->input_size[0] = prev_rect->img_width;
|
|
|
|
fbo_info->input_size[1] = prev_rect->img_height;
|
|
|
|
fbo_info->tex_size[0] = prev_rect->width;
|
|
|
|
fbo_info->tex_size[1] = prev_rect->height;
|
|
|
|
memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords));
|
|
|
|
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]);
|
|
|
|
gl_shader_use(i + 1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
// Render to FBO with certain size.
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, rect->img_width, rect->img_height, true, false);
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
|
|
|
|
prev_rect->width, prev_rect->height,
|
|
|
|
gl->vp_width, gl->vp_height, gl->frame_count,
|
|
|
|
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
|
|
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
|
|
|
fbo_tex_info_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render our last FBO texture directly to screen.
|
|
|
|
prev_rect = &gl->fbo_rect[gl->fbo_pass - 1];
|
|
|
|
GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width;
|
|
|
|
GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height;
|
|
|
|
|
|
|
|
set_texture_coords(fbo_tex_coords, xamt, yamt);
|
|
|
|
|
|
|
|
// Render our FBO texture to back buffer.
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
gl_shader_use(gl->fbo_pass + 1);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
gl->render_to_tex = false;
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
|
|
|
|
prev_rect->width, prev_rect->height,
|
|
|
|
gl->vp_width, gl->vp_height, gl->frame_count,
|
|
|
|
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
|
|
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped);
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
static void gl_update_resize(gl_t *gl)
|
|
|
|
{
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
if (!gl->render_to_tex)
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2012-01-31 23:14:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_check_fbo_dimensions(gl);
|
|
|
|
|
|
|
|
// Go back to what we're supposed to do, render to FBO #0 :D
|
|
|
|
gl_start_frame_fbo(gl);
|
2011-01-06 19:01:32 +00:00
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
#else
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2012-01-31 23:14:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-01-06 19:01:32 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsigned pitch)
|
|
|
|
{
|
|
|
|
// Res change. Need to clear out texture.
|
|
|
|
if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index]) && gl->empty_buf)
|
2010-12-26 03:15:12 +00:00
|
|
|
{
|
2011-07-03 13:39:35 +00:00
|
|
|
gl->last_width[gl->tex_index] = width;
|
|
|
|
gl->last_height[gl->tex_index] = height;
|
2011-01-22 23:27:20 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch));
|
2011-01-13 20:25:52 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w);
|
2011-03-07 18:12:14 +00:00
|
|
|
|
2011-03-27 18:33:14 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, gl->tex_w, gl->tex_h, gl->texture_type,
|
2011-05-31 21:03:01 +00:00
|
|
|
gl->texture_fmt, gl->empty_buf);
|
2010-12-26 03:15:12 +00:00
|
|
|
|
2011-06-05 00:21:35 +00:00
|
|
|
GLfloat xamt = (GLfloat)width / gl->tex_w;
|
|
|
|
GLfloat yamt = (GLfloat)height / gl->tex_h;
|
2011-03-16 11:28:02 +00:00
|
|
|
|
2011-06-05 00:21:35 +00:00
|
|
|
set_texture_coords(gl->tex_coords, xamt, yamt);
|
2010-12-26 03:15:12 +00:00
|
|
|
}
|
2011-11-12 11:28:07 +00:00
|
|
|
// We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly.
|
2012-01-31 23:14:04 +00:00
|
|
|
else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] ||
|
|
|
|
height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK])
|
2011-07-03 13:39:35 +00:00
|
|
|
{
|
|
|
|
GLfloat xamt = (GLfloat)width / gl->tex_w;
|
|
|
|
GLfloat yamt = (GLfloat)height / gl->tex_h;
|
|
|
|
set_texture_coords(gl->tex_coords, xamt, yamt);
|
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-06-01 10:19:48 +00:00
|
|
|
|
2012-05-26 13:45:00 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
|
|
|
static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch)
|
|
|
|
{
|
2012-05-26 13:59:22 +00:00
|
|
|
size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size;
|
|
|
|
size_t buffer_stride = gl->tex_w * gl->base_size;
|
2012-05-26 13:45:00 +00:00
|
|
|
const uint8_t *frame_copy = frame;
|
2012-05-26 13:59:22 +00:00
|
|
|
size_t frame_copy_size = width * gl->base_size;
|
|
|
|
|
2012-05-26 13:45:00 +00:00
|
|
|
for (unsigned h = 0; h < height; h++)
|
|
|
|
{
|
|
|
|
glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE,
|
2012-05-26 13:59:22 +00:00
|
|
|
buffer_addr,
|
|
|
|
frame_copy_size,
|
|
|
|
frame_copy);
|
2012-05-26 13:45:00 +00:00
|
|
|
|
|
|
|
frame_copy += pitch;
|
|
|
|
buffer_addr += buffer_stride;
|
|
|
|
}
|
|
|
|
}
|
2012-05-26 14:01:59 +00:00
|
|
|
|
|
|
|
static void gl_init_textures(gl_t *gl)
|
|
|
|
{
|
|
|
|
glGenTextures(TEXTURES, gl->texture);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
|
|
|
|
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_MAG_FILTER, gl->tex_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
|
|
|
|
|
|
|
glTextureReferenceSCE(GL_TEXTURE_2D, 1,
|
|
|
|
gl->tex_w, gl->tex_h, 0,
|
|
|
|
gl->texture_fmt,
|
|
|
|
gl->tex_w * gl->base_size,
|
|
|
|
gl->tex_w * gl->tex_h * i * gl->base_size);
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
2012-05-26 13:45:00 +00:00
|
|
|
#else
|
2012-05-25 19:40:19 +00:00
|
|
|
static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2011-03-07 18:12:14 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
|
2010-12-26 03:15:12 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
2011-03-07 18:12:14 +00:00
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, frame);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-02-26 22:56:45 +00:00
|
|
|
|
2012-05-26 13:46:37 +00:00
|
|
|
static void gl_init_textures(gl_t *gl)
|
|
|
|
{
|
|
|
|
glGenTextures(TEXTURES, gl->texture);
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
|
|
|
|
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_MAG_FILTER, gl->tex_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-05-26 14:29:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT, gl->tex_w, gl->tex_h, 0, gl->texture_type,
|
2012-05-26 13:46:37 +00:00
|
|
|
gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL);
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
2012-05-26 14:01:59 +00:00
|
|
|
#endif
|
2012-05-26 13:46:37 +00:00
|
|
|
|
2012-05-25 19:40:19 +00:00
|
|
|
static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
|
|
|
memmove(gl->prev_info + 1, gl->prev_info, sizeof(*tex_info) * (TEXTURES - 1));
|
|
|
|
memcpy(&gl->prev_info[0], tex_info, sizeof(*tex_info));
|
|
|
|
gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK;
|
|
|
|
}
|
2011-12-24 12:46:12 +00:00
|
|
|
|
2012-05-26 13:21:51 +00:00
|
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
static inline void gl_render_msg_pre(gl_t *gl)
|
|
|
|
{
|
|
|
|
gl_shader_use(0);
|
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, false);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gl_render_msg_post(gl_t *gl)
|
|
|
|
{
|
|
|
|
// Go back to old rendering path.
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped);
|
|
|
|
glColorPointer(4, GL_FLOAT, 0, white_color);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
set_projection(gl, true);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define gl_render_msg_pre(...)
|
|
|
|
#define gl_render_msg_post(...)
|
|
|
|
#endif
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_shader_use(1);
|
|
|
|
gl->frame_count++;
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2010-12-14 13:28:09 +00:00
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
// Render to texture in first pass.
|
2011-03-06 18:56:35 +00:00
|
|
|
if (gl->fbo_inited)
|
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
// Recompute FBO geometry.
|
2012-05-25 19:40:19 +00:00
|
|
|
// When width/height changes or window sizes change, we have to recalcuate geometry of our FBO.
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height);
|
|
|
|
gl_start_frame_fbo(gl);
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
if (gl->should_resize)
|
|
|
|
{
|
|
|
|
gl->should_resize = false;
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_set_resize(gl->win_width, gl->win_height);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
// On resize, we might have to recreate our FBOs due to "Viewport" scale, and set a new viewport.
|
|
|
|
gl_update_resize(gl);
|
|
|
|
}
|
2011-03-12 15:33:01 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_update_input_size(gl, width, height, pitch);
|
2011-03-14 22:48:19 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_copy_frame(gl, frame, width, height, pitch);
|
2011-03-14 22:48:19 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
struct gl_tex_info tex_info = {0};
|
|
|
|
tex_info.tex = gl->texture[gl->tex_index];
|
|
|
|
tex_info.input_size[0] = width;
|
|
|
|
tex_info.input_size[1] = height;
|
|
|
|
tex_info.tex_size[0] = gl->tex_w;
|
|
|
|
tex_info.tex_size[1] = gl->tex_h;
|
2011-03-12 15:33:01 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords));
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
gl_shader_set_params(width, height,
|
|
|
|
gl->tex_w, gl->tex_h,
|
|
|
|
gl->vp_width, gl->vp_height,
|
|
|
|
gl->frame_count,
|
|
|
|
&tex_info, gl->prev_info, NULL, 0);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
2011-06-05 00:01:44 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->fbo_inited)
|
|
|
|
gl_frame_fbo(gl, &tex_info);
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_next_texture_index(gl, &tex_info);
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2011-01-22 23:48:47 +00:00
|
|
|
if (msg)
|
2012-05-26 13:21:51 +00:00
|
|
|
{
|
|
|
|
gl_render_msg_pre(gl);
|
2011-01-22 23:48:47 +00:00
|
|
|
gl_render_msg(gl, msg);
|
2012-05-26 13:21:51 +00:00
|
|
|
gl_render_msg_post(gl);
|
|
|
|
}
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_update_window_title(false);
|
|
|
|
gfx_ctx_swap_buffers();
|
2010-05-28 00:45:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_free(void *data)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2011-01-22 23:27:20 +00:00
|
|
|
gl_deinit_font(gl);
|
2011-01-05 16:22:12 +00:00
|
|
|
gl_shader_deinit();
|
2010-11-08 22:38:32 +00:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2011-11-12 14:51:37 +00:00
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
2011-11-12 11:28:07 +00:00
|
|
|
glDeleteTextures(TEXTURES, gl->texture);
|
2011-03-23 22:48:13 +00:00
|
|
|
|
2012-05-26 13:45:00 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0);
|
|
|
|
glDeleteBuffers(1, &gl->pbo);
|
|
|
|
#endif
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_deinit_fbo(gl);
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_destroy();
|
2011-03-13 19:52:06 +00:00
|
|
|
|
2011-05-31 21:03:01 +00:00
|
|
|
if (gl->empty_buf)
|
|
|
|
free(gl->empty_buf);
|
|
|
|
|
2011-03-13 19:52:06 +00:00
|
|
|
free(gl);
|
2010-05-28 00:45:18 +00:00
|
|
|
}
|
|
|
|
|
2010-08-16 16:40:17 +00:00
|
|
|
static void gl_set_nonblock_state(void *data, bool state)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2010-08-16 16:40:17 +00:00
|
|
|
if (gl->vsync)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("GL VSync => %s\n", state ? "off" : "on");
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_set_swap_interval(state ? 0 : 1, true);
|
2010-08-16 16:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 18:31:36 +00:00
|
|
|
static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
2010-05-28 00:45:18 +00:00
|
|
|
{
|
2011-08-07 13:00:34 +00:00
|
|
|
#ifdef _WIN32
|
2011-08-07 19:15:50 +00:00
|
|
|
gfx_set_dwm();
|
2011-08-07 13:00:34 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
if (!gfx_ctx_init())
|
2011-01-06 17:34:11 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-05-25 20:28:20 +00:00
|
|
|
unsigned full_x = 0, full_y = 0;
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_get_video_size(&full_x, &full_y);
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y);
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false);
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2011-09-13 16:50:40 +00:00
|
|
|
unsigned win_width = video->width;
|
|
|
|
unsigned win_height = video->height;
|
|
|
|
if (video->fullscreen && (win_width == 0) && (win_height == 0))
|
|
|
|
{
|
|
|
|
win_width = full_x;
|
|
|
|
win_height = full_y;
|
|
|
|
}
|
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
if (!gfx_ctx_set_video_mode(win_width, win_height,
|
2011-09-13 16:50:40 +00:00
|
|
|
g_settings.video.force_16bit ? 15 : 0, video->fullscreen))
|
2011-01-06 17:34:11 +00:00
|
|
|
return NULL;
|
2011-01-11 21:33:28 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_update_window_title(true);
|
2011-08-06 01:28:07 +00:00
|
|
|
|
2011-03-12 18:09:25 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2011-06-11 20:02:05 +00:00
|
|
|
#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32)
|
2011-05-18 20:40:42 +00:00
|
|
|
// Win32 GL lib doesn't have some functions needed for XML shaders.
|
|
|
|
// Need to load dynamically :(
|
|
|
|
if (!load_gl_proc())
|
|
|
|
{
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_destroy();
|
2011-05-18 20:40:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-11 21:33:28 +00:00
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t));
|
2011-01-11 20:16:57 +00:00
|
|
|
if (!gl)
|
2011-05-18 20:40:42 +00:00
|
|
|
{
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_destroy();
|
2011-01-11 20:16:57 +00:00
|
|
|
return NULL;
|
2011-05-18 20:40:42 +00:00
|
|
|
}
|
2011-01-11 20:16:57 +00:00
|
|
|
|
2011-05-31 21:03:01 +00:00
|
|
|
gl->vsync = video->vsync;
|
2011-08-16 08:26:36 +00:00
|
|
|
gl->fullscreen = video->fullscreen;
|
2011-09-13 12:06:49 +00:00
|
|
|
|
2011-02-28 15:59:31 +00:00
|
|
|
gl->full_x = full_x;
|
|
|
|
gl->full_y = full_y;
|
2011-09-13 16:50:40 +00:00
|
|
|
gl->win_width = win_width;
|
|
|
|
gl->win_height = win_height;
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height);
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2012-05-26 22:51:02 +00:00
|
|
|
#ifdef HAVE_CG_MENU
|
|
|
|
RARCH_LOG("Initializing menu shader...\n");
|
|
|
|
gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE);
|
|
|
|
#endif
|
|
|
|
|
2011-01-11 18:23:21 +00:00
|
|
|
if (!gl_shader_init())
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Shader init failed.\n");
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_destroy();
|
2011-01-11 20:16:57 +00:00
|
|
|
free(gl);
|
2011-01-11 18:23:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("GL: Loaded %u program(s).\n", gl_shader_num());
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
2011-03-12 14:30:57 +00:00
|
|
|
// Set up render to texture.
|
2012-04-21 21:25:32 +00:00
|
|
|
gl_init_fbo(gl, RARCH_SCALE_BASE * video->input_scale,
|
|
|
|
RARCH_SCALE_BASE * video->input_scale);
|
2012-01-30 19:22:36 +00:00
|
|
|
#endif
|
2011-06-11 20:02:05 +00:00
|
|
|
|
2011-03-30 12:57:45 +00:00
|
|
|
gl->keep_aspect = video->force_aspect;
|
|
|
|
|
2011-03-16 11:47:31 +00:00
|
|
|
// Apparently need to set viewport for passes when we aren't using FBOs.
|
2011-05-26 20:25:30 +00:00
|
|
|
gl_shader_use(0);
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2011-03-16 11:47:31 +00:00
|
|
|
gl_shader_use(1);
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2011-01-06 19:01:32 +00:00
|
|
|
|
2011-03-14 20:28:30 +00:00
|
|
|
bool force_smooth;
|
|
|
|
if (gl_shader_filter_type(1, &force_smooth))
|
|
|
|
gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST;
|
2010-05-29 12:45:40 +00:00
|
|
|
else
|
2011-03-14 20:28:30 +00:00
|
|
|
gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST;
|
2010-05-28 00:54:20 +00:00
|
|
|
|
2012-05-26 14:29:02 +00:00
|
|
|
gl->texture_type = RARCH_GL_TEXTURE_TYPE;
|
|
|
|
gl->texture_fmt = video->rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16;
|
2011-03-07 18:12:14 +00:00
|
|
|
gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2010-11-08 22:38:32 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2011-03-12 18:28:56 +00:00
|
|
|
glDisable(GL_DITHER);
|
2011-03-12 18:09:25 +00:00
|
|
|
glClearColor(0, 0, 0, 1);
|
2010-05-28 00:45:18 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2010-11-08 22:38:32 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2011-11-12 14:51:37 +00:00
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped);
|
2010-12-26 03:15:12 +00:00
|
|
|
|
|
|
|
memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords));
|
2011-11-12 14:51:37 +00:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords);
|
|
|
|
glColorPointer(4, GL_FLOAT, 0, white_color);
|
2010-12-26 03:15:12 +00:00
|
|
|
|
2011-06-05 00:01:44 +00:00
|
|
|
set_lut_texture_coords(tex_coords);
|
2011-05-18 18:38:04 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
gl->tex_w = RARCH_SCALE_BASE * video->input_scale;
|
|
|
|
gl->tex_h = RARCH_SCALE_BASE * video->input_scale;
|
2011-03-07 18:12:14 +00:00
|
|
|
|
2012-05-26 22:51:02 +00:00
|
|
|
#ifdef HAVE_OPENGL_PBO
|
2012-05-26 13:45:00 +00:00
|
|
|
glGenBuffers(1, &gl->pbo);
|
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo);
|
|
|
|
glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW);
|
|
|
|
#endif
|
|
|
|
|
2011-05-31 21:03:01 +00:00
|
|
|
// Empty buffer that we use to clear out the texture with on res change.
|
2011-08-29 15:05:11 +00:00
|
|
|
gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size);
|
2012-05-26 13:46:37 +00:00
|
|
|
gl_init_textures(gl);
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2011-11-12 11:28:07 +00:00
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
2011-07-03 13:39:35 +00:00
|
|
|
{
|
|
|
|
gl->last_width[i] = gl->tex_w;
|
|
|
|
gl->last_height[i] = gl->tex_h;
|
|
|
|
}
|
|
|
|
|
2011-11-12 11:28:07 +00:00
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
gl->prev_info[i].tex = gl->texture[(gl->tex_index - (i + 1)) & TEXTURES_MASK];
|
|
|
|
gl->prev_info[i].input_size[0] = gl->tex_w;
|
|
|
|
gl->prev_info[i].tex_size[0] = gl->tex_w;
|
|
|
|
gl->prev_info[i].input_size[1] = gl->tex_h;
|
|
|
|
gl->prev_info[i].tex_size[1] = gl->tex_h;
|
|
|
|
memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords));
|
|
|
|
}
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_input_driver(input, input_data);
|
2011-01-23 01:48:06 +00:00
|
|
|
gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size);
|
2011-06-11 20:02:05 +00:00
|
|
|
|
2011-01-11 21:33:28 +00:00
|
|
|
if (!gl_check_error())
|
|
|
|
{
|
2012-05-26 02:47:24 +00:00
|
|
|
gfx_ctx_destroy();
|
2011-01-11 21:33:28 +00:00
|
|
|
free(gl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-16 16:40:17 +00:00
|
|
|
return gl;
|
2010-05-28 00:45:18 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 19:01:32 +00:00
|
|
|
static bool gl_alive(void *data)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-10-18 17:51:38 +00:00
|
|
|
check_window(gl);
|
2011-01-06 19:01:32 +00:00
|
|
|
return !gl->quitting;
|
|
|
|
}
|
|
|
|
|
2011-02-05 20:45:44 +00:00
|
|
|
static bool gl_focus(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2012-05-26 02:47:24 +00:00
|
|
|
return gfx_ctx_window_has_focus();
|
2011-02-05 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 16:59:06 +00:00
|
|
|
#ifdef HAVE_XML
|
2011-03-29 16:28:31 +00:00
|
|
|
static bool gl_xml_shader(void *data, const char *path)
|
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-06-07 13:58:30 +00:00
|
|
|
|
2011-03-29 16:59:06 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_deinit_fbo(gl);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
|
|
|
|
2011-06-11 20:02:05 +00:00
|
|
|
gl_shader_deinit();
|
|
|
|
|
2011-03-29 16:59:06 +00:00
|
|
|
if (!gl_glsl_init(path))
|
|
|
|
return false;
|
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
// Set up render to texture again.
|
2011-03-29 16:59:06 +00:00
|
|
|
gl_init_fbo(gl, gl->tex_w, gl->tex_h);
|
2012-01-30 19:22:36 +00:00
|
|
|
#endif
|
2011-03-29 16:59:06 +00:00
|
|
|
|
|
|
|
// Apparently need to set viewport for passes when we aren't using FBOs.
|
2011-05-26 20:25:30 +00:00
|
|
|
gl_shader_use(0);
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2011-03-29 16:59:06 +00:00
|
|
|
gl_shader_use(1);
|
2012-04-02 15:26:23 +00:00
|
|
|
set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2011-03-29 16:59:06 +00:00
|
|
|
|
2011-03-29 16:28:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
2011-03-29 16:28:31 +00:00
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
const video_driver_t video_gl = {
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_init,
|
|
|
|
gl_frame,
|
|
|
|
gl_set_nonblock_state,
|
|
|
|
gl_alive,
|
|
|
|
gl_focus,
|
2011-03-29 16:59:06 +00:00
|
|
|
#ifdef HAVE_XML
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_xml_shader,
|
|
|
|
#else
|
|
|
|
NULL,
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_free,
|
2012-04-01 17:20:37 +00:00
|
|
|
"gl",
|
|
|
|
|
|
|
|
gl_set_rotation,
|
2010-05-28 00:45:18 +00:00
|
|
|
};
|
2010-12-14 13:28:09 +00:00
|
|
|
|