2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2013-03-11 06:13:11 +00:00
|
|
|
* Copyright (C) 2012-2013 - Michael Lelli
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2012-11-14 20:01:40 +00:00
|
|
|
#ifdef _MSC_VER
|
2012-11-15 08:40:31 +00:00
|
|
|
#pragma comment(lib, "opengl32")
|
2012-11-14 20:01:40 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../driver.h"
|
2012-11-01 05:21:18 +00:00
|
|
|
#include "../performance.h"
|
2012-10-01 22:58:43 +00:00
|
|
|
#include "scaler/scaler.h"
|
2012-12-19 12:26:11 +00:00
|
|
|
#include "image.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"
|
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
|
|
|
|
2010-11-12 22:09:43 +00:00
|
|
|
#ifdef HAVE_CG
|
2011-01-05 16:22:12 +00:00
|
|
|
#include "shader_cg.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-16 17:43:05 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2011-01-05 16:22:12 +00:00
|
|
|
#include "shader_glsl.h"
|
2010-11-12 22:09:43 +00:00
|
|
|
#endif
|
2010-11-12 21:32:38 +00:00
|
|
|
|
2012-11-14 22:11:48 +00:00
|
|
|
#include "shader_common.h"
|
|
|
|
|
2012-11-14 20:51:56 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
|
|
|
#define FPS_COUNTER
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 22:05:23 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include "../frontend/frontend_android.h"
|
|
|
|
#endif
|
|
|
|
|
2012-09-13 15:48:17 +00:00
|
|
|
// Used for the last pass when rendering to the back buffer.
|
|
|
|
const GLfloat vertexes_flipped[] = {
|
|
|
|
0, 1,
|
|
|
|
1, 1,
|
|
|
|
0, 0,
|
|
|
|
1, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
// Used when rendering to an FBO.
|
|
|
|
// Texture coords have to be aligned with vertex coordinates.
|
|
|
|
static const GLfloat vertexes[] = {
|
|
|
|
0, 0,
|
|
|
|
1, 0,
|
|
|
|
0, 1,
|
|
|
|
1, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GLfloat tex_coords[] = {
|
2010-11-08 23:13:57 +00:00
|
|
|
0, 0,
|
2010-11-12 21:32:38 +00:00
|
|
|
1, 0,
|
2012-09-10 08:29:50 +00:00
|
|
|
0, 1,
|
2010-11-12 21:32:38 +00:00
|
|
|
1, 1
|
2010-11-08 23:13:57 +00:00
|
|
|
};
|
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_render_overlay(void *data);
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_vertex_geom(void *data,
|
|
|
|
float x, float y, float w, float h);
|
|
|
|
static void gl_overlay_tex_geom(void *data,
|
|
|
|
float x, float y, float w, float h);
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2012-09-13 15:48:17 +00:00
|
|
|
static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt)
|
|
|
|
{
|
|
|
|
coords[2] = xamt;
|
|
|
|
coords[6] = xamt;
|
|
|
|
coords[5] = yamt;
|
|
|
|
coords[7] = yamt;
|
|
|
|
}
|
|
|
|
|
2012-05-27 10:26:43 +00:00
|
|
|
const GLfloat white_color[] = {
|
2011-11-12 14:51:37 +00:00
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
};
|
|
|
|
|
2012-05-27 18:50:06 +00:00
|
|
|
const GLfloat *vertex_ptr = vertexes_flipped;
|
|
|
|
const GLfloat *default_vertex_ptr = vertexes_flipped;
|
|
|
|
|
2012-10-02 21:36:18 +00:00
|
|
|
#undef LOAD_GL_SYM
|
2012-09-12 18:24:57 +00:00
|
|
|
#define LOAD_GL_SYM(SYM) if (!pgl##SYM) { \
|
2012-10-09 15:47:48 +00:00
|
|
|
gfx_ctx_proc_t sym = gl->ctx_driver->get_proc_address("gl" #SYM); \
|
2012-09-12 18:24:57 +00:00
|
|
|
memcpy(&(pgl##SYM), &sym, sizeof(sym)); \
|
|
|
|
}
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2012-10-21 10:20:53 +00:00
|
|
|
#if defined(HAVE_EGL) && defined(HAVE_OPENGLES2)
|
2012-10-20 08:58:02 +00:00
|
|
|
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC pglEGLImageTargetTexture2DOES;
|
2012-10-20 03:08:53 +00:00
|
|
|
|
|
|
|
static bool load_eglimage_proc(gl_t *gl)
|
|
|
|
{
|
|
|
|
LOAD_GL_SYM(EGLImageTargetTexture2DOES);
|
|
|
|
return pglEGLImageTargetTexture2DOES;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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)
|
2012-10-20 08:58:02 +00:00
|
|
|
static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers;
|
|
|
|
static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer;
|
|
|
|
static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D;
|
|
|
|
static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus;
|
|
|
|
static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers;
|
2013-03-29 01:50:42 +00:00
|
|
|
static PFNGLGENRENDERBUFFERSPROC pglGenRenderbuffers;
|
|
|
|
static PFNGLBINDRENDERBUFFERPROC pglBindRenderbuffer;
|
|
|
|
static PFNGLFRAMEBUFFERRENDERBUFFERPROC pglFramebufferRenderbuffer;
|
|
|
|
static PFNGLRENDERBUFFERSTORAGEPROC pglRenderbufferStorage;
|
|
|
|
static PFNGLDELETERENDERBUFFERSPROC pglDeleteRenderbuffers;
|
2011-03-06 21:18:25 +00:00
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
static bool load_fbo_proc(gl_t *gl)
|
2011-03-06 21:18:25 +00:00
|
|
|
{
|
2012-09-12 18:26:59 +00:00
|
|
|
LOAD_GL_SYM(GenFramebuffers);
|
|
|
|
LOAD_GL_SYM(BindFramebuffer);
|
|
|
|
LOAD_GL_SYM(FramebufferTexture2D);
|
|
|
|
LOAD_GL_SYM(CheckFramebufferStatus);
|
|
|
|
LOAD_GL_SYM(DeleteFramebuffers);
|
2013-03-29 01:50:42 +00:00
|
|
|
LOAD_GL_SYM(GenRenderbuffers);
|
|
|
|
LOAD_GL_SYM(BindRenderbuffer);
|
|
|
|
LOAD_GL_SYM(FramebufferRenderbuffer);
|
|
|
|
LOAD_GL_SYM(RenderbufferStorage);
|
|
|
|
LOAD_GL_SYM(DeleteRenderbuffers);
|
2011-03-06 21:18:25 +00:00
|
|
|
|
|
|
|
return pglGenFramebuffers && pglBindFramebuffer && pglFramebufferTexture2D &&
|
2013-03-29 01:50:42 +00:00
|
|
|
pglCheckFramebufferStatus && pglDeleteFramebuffers &&
|
|
|
|
pglGenRenderbuffers && pglBindRenderbuffer &&
|
|
|
|
pglFramebufferRenderbuffer && pglRenderbufferStorage &&
|
|
|
|
pglDeleteRenderbuffers;
|
2011-03-06 21:18:25 +00:00
|
|
|
}
|
2012-09-15 13:17:34 +00:00
|
|
|
#elif defined(HAVE_OPENGLES2)
|
|
|
|
#define pglGenFramebuffers glGenFramebuffers
|
|
|
|
#define pglBindFramebuffer glBindFramebuffer
|
|
|
|
#define pglFramebufferTexture2D glFramebufferTexture2D
|
|
|
|
#define pglCheckFramebufferStatus glCheckFramebufferStatus
|
|
|
|
#define pglDeleteFramebuffers glDeleteFramebuffers
|
2013-03-29 01:50:42 +00:00
|
|
|
#define pglGenRenderbuffers glGenRenderbuffers
|
|
|
|
#define pglBindRenderbuffer glBindRenderbuffer
|
|
|
|
#define pglFramebufferRenderbuffer glFramebufferRenderbuffer
|
|
|
|
#define pglRenderbufferStorage glRenderbufferStorage
|
|
|
|
#define pglDeleteRenderbuffers glDeleteRenderbuffers
|
2012-09-24 23:26:22 +00:00
|
|
|
#define load_fbo_proc(gl) (true)
|
2012-09-09 22:36:25 +00:00
|
|
|
#elif defined(HAVE_OPENGLES)
|
2012-05-25 14:00:17 +00:00
|
|
|
#define pglGenFramebuffers glGenFramebuffersOES
|
|
|
|
#define pglBindFramebuffer glBindFramebufferOES
|
|
|
|
#define pglFramebufferTexture2D glFramebufferTexture2DOES
|
|
|
|
#define pglCheckFramebufferStatus glCheckFramebufferStatusOES
|
|
|
|
#define pglDeleteFramebuffers glDeleteFramebuffersOES
|
2013-03-29 01:50:42 +00:00
|
|
|
#define pglGenRenderbuffers glGenRenderbuffersOES
|
|
|
|
#define pglBindRenderbuffer glBindRenderbufferOES
|
|
|
|
#define pglFramebufferRenderbuffer glFramebufferRenderbufferOES
|
|
|
|
#define pglRenderbufferStorage glRenderbufferStorageOES
|
|
|
|
#define pglDeleteRenderbuffers glDeleteRenderbuffersOES
|
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-09-24 23:26:22 +00:00
|
|
|
#define load_fbo_proc(gl) (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
|
2013-03-29 01:50:42 +00:00
|
|
|
#define pglGenRenderbuffers glGenRenderbuffers
|
|
|
|
#define pglBindRenderbuffer glBindRenderbuffer
|
|
|
|
#define pglFramebufferRenderbuffer glFramebufferRenderbuffer
|
|
|
|
#define pglRenderbufferStorage glRenderbufferStorage
|
|
|
|
#define pglDeleteRenderbuffers glDeleteRenderbuffers
|
2012-09-24 23:26:22 +00:00
|
|
|
#define load_fbo_proc(gl) (true)
|
2011-03-06 21:18:25 +00:00
|
|
|
#endif
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-03-06 21:18:25 +00:00
|
|
|
|
2012-08-16 08:09:44 +00:00
|
|
|
#ifdef _WIN32
|
2012-09-10 21:17:48 +00:00
|
|
|
PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture;
|
|
|
|
PFNGLACTIVETEXTUREPROC pglActiveTexture;
|
2012-11-21 15:24:28 +00:00
|
|
|
static PFNGLGENBUFFERSPROC pglGenBuffers;
|
|
|
|
static PFNGLGENBUFFERSPROC pglDeleteBuffers;
|
2012-09-10 21:17:48 +00:00
|
|
|
static PFNGLBINDBUFFERPROC pglBindBuffer;
|
2012-09-10 21:19:02 +00:00
|
|
|
static PFNGLBUFFERSUBDATAPROC pglBufferSubData;
|
|
|
|
static PFNGLBUFFERDATAPROC pglBufferData;
|
|
|
|
static PFNGLMAPBUFFERPROC pglMapBuffer;
|
|
|
|
static PFNGLUNMAPBUFFERPROC pglUnmapBuffer;
|
2012-09-24 23:26:22 +00:00
|
|
|
static inline bool load_gl_proc_win32(gl_t *gl)
|
2011-05-18 20:40:42 +00:00
|
|
|
{
|
2012-09-12 18:24:57 +00:00
|
|
|
LOAD_GL_SYM(ClientActiveTexture);
|
|
|
|
LOAD_GL_SYM(ActiveTexture);
|
2012-11-21 15:24:28 +00:00
|
|
|
LOAD_GL_SYM(GenBuffers);
|
|
|
|
LOAD_GL_SYM(DeleteBuffers);
|
2012-09-12 18:24:57 +00:00
|
|
|
LOAD_GL_SYM(BindBuffer);
|
|
|
|
LOAD_GL_SYM(BufferSubData);
|
|
|
|
LOAD_GL_SYM(BufferData);
|
|
|
|
LOAD_GL_SYM(MapBuffer);
|
|
|
|
LOAD_GL_SYM(UnmapBuffer);
|
2012-11-21 15:24:28 +00:00
|
|
|
|
|
|
|
return pglClientActiveTexture && pglActiveTexture &&
|
|
|
|
pglGenBuffers && pglDeleteBuffers &&
|
|
|
|
pglBindBuffer && pglBufferSubData && pglBufferData &&
|
|
|
|
pglMapBuffer && pglUnmapBuffer;
|
2011-05-18 20:40:42 +00:00
|
|
|
}
|
|
|
|
#else
|
2012-11-21 15:24:28 +00:00
|
|
|
#define pglGenBuffers glGenBuffers
|
|
|
|
#define pglDeleteBuffers glDeleteBuffers
|
2012-09-10 21:17:48 +00:00
|
|
|
#define pglBindBuffer glBindBuffer
|
|
|
|
#define pglBufferSubData glBufferSubData
|
|
|
|
#define pglBufferData glBufferData
|
|
|
|
#define pglMapBuffer glMapBuffer
|
|
|
|
#define pglUnmapBuffer glUnmapBuffer
|
2011-05-18 20:40:42 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-06 16:40:50 +00:00
|
|
|
#if defined(__APPLE__) || defined(HAVE_PSGL)
|
2013-03-29 00:23:30 +00:00
|
|
|
#define GL_RGBA32F GL_RGBA32F_ARB
|
|
|
|
#endif
|
|
|
|
|
2011-01-22 23:27:20 +00:00
|
|
|
////////////////// Shaders
|
2012-09-15 13:37:08 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static bool gl_shader_init(void *data)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-11-14 21:51:08 +00:00
|
|
|
const gl_shader_backend_t *backend = NULL;
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2013-04-07 11:08:09 +00:00
|
|
|
const char *shader_path = (g_settings.video.shader_enable && *g_settings.video.shader_path) ?
|
|
|
|
g_settings.video.shader_path : NULL;
|
|
|
|
enum rarch_shader_type type = gfx_shader_parse_type(shader_path, DEFAULT_SHADER_TYPE);
|
|
|
|
|
|
|
|
if (type == RARCH_SHADER_NONE)
|
2013-04-07 00:18:59 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: Not loading any shader.\n");
|
2013-04-06 23:38:11 +00:00
|
|
|
return true;
|
2013-04-07 00:18:59 +00:00
|
|
|
}
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2013-04-06 23:38:11 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2011-01-05 16:22:12 +00:00
|
|
|
#ifdef HAVE_CG
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_SHADER_CG:
|
2013-04-07 00:18:59 +00:00
|
|
|
RARCH_LOG("[GL]: Using Cg shader backend.\n");
|
2013-04-06 18:50:22 +00:00
|
|
|
backend = &gl_cg_backend;
|
2012-11-14 21:51:08 +00:00
|
|
|
break;
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-02 14:05:55 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2013-01-07 16:03:10 +00:00
|
|
|
case RARCH_SHADER_GLSL:
|
2013-04-07 00:18:59 +00:00
|
|
|
RARCH_LOG("[GL]: Using GLSL shader backend.\n");
|
2013-04-06 18:50:22 +00:00
|
|
|
backend = &gl_glsl_backend;
|
2012-11-14 21:51:08 +00:00
|
|
|
break;
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-28 15:59:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
if (!backend)
|
2013-04-07 00:18:59 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Didn't find valid shader backend. Continuing without shaders.\n");
|
2012-11-14 21:51:08 +00:00
|
|
|
return true;
|
2013-04-07 00:18:59 +00:00
|
|
|
}
|
2012-11-14 21:51:08 +00:00
|
|
|
|
|
|
|
gl->shader = backend;
|
|
|
|
return gl->shader->init(shader_path);
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_shader_deinit(void *data)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->deinit();
|
|
|
|
gl->shader = NULL;
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2012-09-11 21:32:00 +00:00
|
|
|
static void gl_set_coords(const struct gl_coords *coords)
|
|
|
|
{
|
2013-04-06 09:26:06 +00:00
|
|
|
pglClientActiveTexture(GL_TEXTURE1);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, coords->lut_tex_coord);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2013-04-06 09:26:06 +00:00
|
|
|
pglClientActiveTexture(GL_TEXTURE0);
|
2012-09-14 19:35:32 +00:00
|
|
|
glVertexPointer(2, GL_FLOAT, 0, coords->vertex);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2012-09-14 19:35:32 +00:00
|
|
|
glColorPointer(4, GL_FLOAT, 0, coords->color);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2012-09-14 19:35:32 +00:00
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, coords->tex_coord);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2013-04-06 09:26:06 +00:00
|
|
|
}
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2013-04-06 09:26:06 +00:00
|
|
|
static void gl_disable_client_arrays(void)
|
|
|
|
{
|
2012-09-14 19:35:32 +00:00
|
|
|
pglClientActiveTexture(GL_TEXTURE1);
|
2013-04-06 09:26:06 +00:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2012-09-14 19:35:32 +00:00
|
|
|
pglClientActiveTexture(GL_TEXTURE0);
|
2013-04-06 09:26:06 +00:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2012-09-11 21:32:00 +00:00
|
|
|
}
|
2012-09-13 15:05:48 +00:00
|
|
|
#endif
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifndef NO_GL_FF_MATRIX
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_set_mvp(const void *data)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
const math_matrix *mat = (const math_matrix*)data;
|
2012-09-11 21:32:00 +00:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(mat->data);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
}
|
2011-01-05 16:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-03 02:02:52 +00:00
|
|
|
void gl_shader_set_coords(void *data, const struct gl_coords *coords, const math_matrix *mat)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2013-01-03 02:02:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
bool ret_coords = false;
|
|
|
|
bool ret_mvp = false;
|
|
|
|
|
2012-11-15 21:29:02 +00:00
|
|
|
(void)ret_coords;
|
|
|
|
(void)ret_mvp;
|
|
|
|
|
2012-11-15 16:17:55 +00:00
|
|
|
if (gl->shader)
|
|
|
|
ret_coords = gl->shader->set_coords(coords);
|
|
|
|
if (gl->shader)
|
|
|
|
ret_mvp = gl->shader->set_mvp(mat);
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
// Fall back to FF-style if needed and possible.
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2012-09-11 21:32:00 +00:00
|
|
|
if (!ret_coords)
|
|
|
|
gl_set_coords(coords);
|
2012-09-13 15:05:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NO_GL_FF_MATRIX
|
2012-09-11 21:32:00 +00:00
|
|
|
if (!ret_mvp)
|
|
|
|
gl_set_mvp(mat);
|
2012-09-13 15:05:48 +00:00
|
|
|
#endif
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
#define gl_shader_num(gl) ((gl->shader) ? gl->shader->num_shaders() : 0)
|
|
|
|
#define gl_shader_filter_type(gl, index, smooth) ((gl->shader) ? gl->shader->filter_type(index, smooth) : false)
|
2011-03-14 21:09:35 +00:00
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-04-06 09:30:56 +00:00
|
|
|
static void gl_shader_scale(void *data, unsigned index, struct gfx_fbo_scale *scale)
|
2011-03-14 20:28:30 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
scale->valid = false;
|
2012-11-14 21:51:08 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->shader_scale(index, scale);
|
2011-03-14 20:28:30 +00:00
|
|
|
}
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_compute_fbo_geometry(void *data, unsigned width, unsigned height,
|
2012-08-10 04:50:41 +00:00
|
|
|
unsigned vp_width, unsigned vp_height)
|
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-08-10 04:50:41 +00:00
|
|
|
unsigned last_width = width;
|
|
|
|
unsigned last_height = height;
|
|
|
|
unsigned last_max_width = gl->tex_w;
|
|
|
|
unsigned last_max_height = gl->tex_h;
|
2012-10-23 06:28:02 +00:00
|
|
|
|
|
|
|
GLint max_size = 0;
|
2012-10-23 02:03:00 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
|
2012-10-23 06:28:02 +00:00
|
|
|
bool size_modified = false;
|
|
|
|
|
2012-08-10 04:50:41 +00:00
|
|
|
// Calculate viewports for FBOs.
|
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
|
|
|
{
|
|
|
|
switch (gl->fbo_scale[i].type_x)
|
|
|
|
{
|
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
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;
|
|
|
|
|
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
case RARCH_SCALE_INPUT:
|
|
|
|
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;
|
|
|
|
|
|
|
|
case RARCH_SCALE_ABSOLUTE:
|
|
|
|
gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RARCH_SCALE_VIEWPORT:
|
|
|
|
gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * vp_height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (gl->fbo_rect[i].img_width > (unsigned)max_size)
|
2012-10-23 02:03:00 +00:00
|
|
|
{
|
2012-10-23 06:28:02 +00:00
|
|
|
size_modified = true;
|
2012-10-23 02:03:00 +00:00
|
|
|
gl->fbo_rect[i].img_width = max_size;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (gl->fbo_rect[i].img_height > (unsigned)max_size)
|
2012-10-23 02:03:00 +00:00
|
|
|
{
|
2012-10-23 06:28:02 +00:00
|
|
|
size_modified = true;
|
2012-10-23 02:03:00 +00:00
|
|
|
gl->fbo_rect[i].img_height = max_size;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (gl->fbo_rect[i].max_img_width > (unsigned)max_size)
|
2012-10-23 02:03:00 +00:00
|
|
|
{
|
2012-10-23 06:28:02 +00:00
|
|
|
size_modified = true;
|
2012-10-23 02:03:00 +00:00
|
|
|
gl->fbo_rect[i].max_img_width = max_size;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
if (gl->fbo_rect[i].max_img_height > (unsigned)max_size)
|
2012-10-23 02:03:00 +00:00
|
|
|
{
|
2012-10-23 06:28:02 +00:00
|
|
|
size_modified = true;
|
2012-10-23 02:03:00 +00:00
|
|
|
gl->fbo_rect[i].max_img_height = max_size;
|
|
|
|
}
|
|
|
|
|
2012-10-23 06:28:02 +00:00
|
|
|
if (size_modified)
|
|
|
|
RARCH_WARN("FBO textures exceeded maximum size of GPU (%ux%u). Resizing to fit.\n", max_size, max_size);
|
|
|
|
|
2012-08-10 04:50:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_create_fbo_textures(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glGenTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
|
2013-04-06 03:46:09 +00:00
|
|
|
GLuint base_filt = gl->tex_filter;
|
2012-01-31 23:14:04 +00:00
|
|
|
for (int i = 0; i < gl->fbo_pass; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]);
|
2012-09-10 08:29:50 +00:00
|
|
|
|
2012-09-11 10:32:50 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->border_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->border_type);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
GLuint filter_type = base_filt;
|
2012-05-27 16:40:07 +00:00
|
|
|
bool smooth = false;
|
2012-11-14 21:51:08 +00:00
|
|
|
if (gl_shader_filter_type(gl, i + 2, &smooth))
|
2012-01-31 23:14:04 +00:00
|
|
|
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);
|
|
|
|
|
2013-03-25 15:42:41 +00:00
|
|
|
bool fp_fbo = gl->fbo_scale[i].valid && gl->fbo_scale[i].fp_fbo;
|
|
|
|
|
|
|
|
if (fp_fbo)
|
|
|
|
{
|
2013-03-26 14:10:56 +00:00
|
|
|
// GLES and GL are inconsistent in which arguments to pass.
|
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
bool has_fp_fbo = gl_query_extension("OES_texture_float_linear");
|
|
|
|
if (!has_fp_fbo)
|
|
|
|
RARCH_ERR("OES_texture_float_linear extension not found.\n");
|
|
|
|
|
|
|
|
RARCH_LOG("FBO pass #%d is floating-point.\n", i);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, GL_RGBA, GL_FLOAT, NULL);
|
|
|
|
#else
|
2013-03-25 15:42:41 +00:00
|
|
|
bool has_fp_fbo = gl_query_extension("ARB_texture_float");
|
|
|
|
if (!has_fp_fbo)
|
|
|
|
RARCH_ERR("ARB_texture_float extension was not found.\n");
|
|
|
|
|
|
|
|
RARCH_LOG("FBO pass #%d is floating-point.\n", i);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2013-04-07 02:17:44 +00:00
|
|
|
#endif
|
2013-03-25 15:42:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
|
|
|
RARCH_GL_FORMAT32, NULL);
|
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static bool gl_create_fbo_targets(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-12-10 12:18:10 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2012-01-31 23:14:04 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-03 02:02:52 +00:00
|
|
|
void gl_deinit_fbo(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-03 02:02:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
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->fbo_pass = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:35:19 +00:00
|
|
|
static void gl_update_tex_filter_frame(gl_t *gl)
|
|
|
|
{
|
|
|
|
bool smooth = false;
|
|
|
|
if (!gl_shader_filter_type(gl, 1, &smooth))
|
|
|
|
return;
|
|
|
|
|
|
|
|
GLuint new_filt = smooth ? GL_LINEAR : GL_NEAREST;
|
|
|
|
if (new_filt == gl->tex_filter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->tex_filter = new_filt;
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
if (gl->texture[i])
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
|
|
|
|
2013-01-03 02:02:52 +00:00
|
|
|
void gl_init_fbo(void *data, unsigned width, unsigned height)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2013-01-03 02:02:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2013-02-17 00:35:19 +00:00
|
|
|
gl_update_tex_filter_frame(gl);
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl_shader_num(gl) == 0)
|
2013-04-07 08:26:34 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-06 09:30:56 +00:00
|
|
|
struct gfx_fbo_scale scale, scale_last;
|
2012-11-14 21:51:08 +00:00
|
|
|
gl_shader_scale(gl, 1, &scale);
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_scale(gl, gl_shader_num(gl), &scale_last);
|
2011-03-30 21:09:29 +00:00
|
|
|
|
2013-02-10 22:33:00 +00:00
|
|
|
/* we always want FBO to be at least initialized on startup for consoles */
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl_shader_num(gl) == 1 && !scale.valid)
|
2011-03-06 18:56:35 +00:00
|
|
|
return;
|
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
if (!load_fbo_proc(gl))
|
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
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl->fbo_pass = gl_shader_num(gl) - 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
|
|
|
|
|
|
|
if (!scale.valid)
|
2011-03-15 17:14:01 +00:00
|
|
|
{
|
2013-04-06 03:46:09 +00:00
|
|
|
scale.scale_x = 1.0f;
|
|
|
|
scale.scale_y = 1.0f;
|
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
|
|
|
{
|
2012-11-14 21:51:08 +00:00
|
|
|
gl_shader_scale(gl, 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);
|
2012-11-18 14:04:42 +00:00
|
|
|
RARCH_ERR("Failed to create FBO targets. Will continue without FBO.\n");
|
2012-01-31 23:14:04 +00:00
|
|
|
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
|
|
|
}
|
2013-03-27 15:15:15 +00:00
|
|
|
|
2013-03-30 14:39:00 +00:00
|
|
|
#ifndef HAVE_RGL
|
2013-03-29 01:12:08 +00:00
|
|
|
bool gl_init_hw_render(gl_t *gl, unsigned width, unsigned height)
|
2013-03-27 15:15:15 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: Initializing HW render (%u x %u).\n", width, height);
|
|
|
|
|
2013-03-29 01:12:08 +00:00
|
|
|
if (!load_fbo_proc(gl))
|
|
|
|
return false;
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
pglGenFramebuffers(TEXTURES, gl->hw_render_fbo);
|
|
|
|
|
2013-03-29 01:50:42 +00:00
|
|
|
bool depth = g_extern.system.hw_render_callback.depth;
|
|
|
|
|
|
|
|
if (depth)
|
|
|
|
{
|
|
|
|
pglGenRenderbuffers(TEXTURES, gl->hw_render_depth);
|
|
|
|
gl->hw_render_depth_init = true;
|
|
|
|
}
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, gl->hw_render_fbo[i]);
|
|
|
|
pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->texture[i], 0);
|
2013-03-29 01:50:42 +00:00
|
|
|
|
|
|
|
if (depth)
|
|
|
|
{
|
|
|
|
pglBindRenderbuffer(GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
|
|
|
pglRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16,
|
|
|
|
width, height);
|
|
|
|
pglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
|
|
GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
|
|
|
}
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
2013-03-29 01:12:08 +00:00
|
|
|
{
|
2013-03-27 15:15:15 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to create HW render FBO.\n");
|
2013-03-29 01:12:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2013-03-29 01:50:42 +00:00
|
|
|
pglBindRenderbuffer(GL_RENDERBUFFER, 0);
|
2013-03-27 15:15:15 +00:00
|
|
|
gl->hw_render_fbo_init = true;
|
2013-03-29 01:12:08 +00:00
|
|
|
return true;
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
2012-01-30 19:22:36 +00:00
|
|
|
#endif
|
2013-03-30 14:39:00 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2013-01-03 02:02:52 +00:00
|
|
|
void gl_set_projection(void *data, struct gl_ortho *ortho, bool allow_rotate)
|
2011-03-20 01:10:02 +00:00
|
|
|
{
|
2013-01-03 02:02:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2012-09-24 20:51:26 +00:00
|
|
|
// Calculate projection.
|
2012-12-23 23:21:42 +00:00
|
|
|
matrix_ortho(&gl->mvp_no_rot, ortho->left, ortho->right,
|
2012-09-24 20:51:26 +00:00
|
|
|
ortho->bottom, ortho->top, ortho->znear, ortho->zfar);
|
|
|
|
|
|
|
|
if (allow_rotate)
|
|
|
|
{
|
|
|
|
math_matrix rot;
|
|
|
|
matrix_rotate_z(&rot, M_PI * gl->rotation / 180.0f);
|
2012-12-23 23:21:42 +00:00
|
|
|
matrix_multiply(&gl->mvp, &rot, &gl->mvp_no_rot);
|
2012-09-24 20:51:26 +00:00
|
|
|
}
|
2012-12-23 23:21:42 +00:00
|
|
|
else
|
|
|
|
gl->mvp = gl->mvp_no_rot;
|
2012-09-24 20:51:26 +00:00
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
2012-04-01 17:20:37 +00:00
|
|
|
}
|
2011-03-20 01:10:02 +00:00
|
|
|
|
2013-01-03 02:02:52 +00:00
|
|
|
void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_full, bool allow_rotate)
|
2012-04-01 17:20:37 +00:00
|
|
|
{
|
2013-01-03 02:02:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-06-08 20:39:18 +00:00
|
|
|
unsigned x = 0, y = 0;
|
|
|
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2013-01-24 23:17:07 +00:00
|
|
|
float device_aspect = 0.0f;
|
|
|
|
if (gl->ctx_driver->translate_aspect)
|
|
|
|
device_aspect = context_translate_aspect_func(width, height);
|
|
|
|
else
|
|
|
|
device_aspect = (float)width / height;
|
|
|
|
|
2013-01-29 18:28:33 +00:00
|
|
|
if (g_settings.video.scale_integer && !force_full)
|
|
|
|
{
|
2013-03-17 21:05:15 +00:00
|
|
|
gfx_scale_integer(&gl->vp, width, height, g_extern.system.aspect_ratio, gl->keep_aspect);
|
2013-01-29 18:28:33 +00:00
|
|
|
}
|
|
|
|
else if (gl->keep_aspect && !force_full)
|
2011-03-20 01:10:02 +00:00
|
|
|
{
|
2013-03-17 21:05:15 +00:00
|
|
|
float desired_aspect = g_extern.system.aspect_ratio;
|
2012-05-27 20:39:29 +00:00
|
|
|
float delta;
|
2011-03-20 01:10:02 +00:00
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2012-10-15 04:24:39 +00:00
|
|
|
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2012-05-27 20:39:29 +00:00
|
|
|
{
|
2012-10-15 04:24:39 +00:00
|
|
|
x = g_extern.console.screen.viewports.custom_vp.x;
|
|
|
|
y = g_extern.console.screen.viewports.custom_vp.y;
|
|
|
|
width = g_extern.console.screen.viewports.custom_vp.width;
|
|
|
|
height = g_extern.console.screen.viewports.custom_vp.height;
|
2012-05-27 20:39:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2012-05-27 21:14:46 +00:00
|
|
|
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
|
|
|
{
|
|
|
|
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
|
|
|
// assume they are actually equal.
|
|
|
|
}
|
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
|
|
|
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
2012-06-08 20:39:18 +00:00
|
|
|
x = (unsigned)(width * (0.5 - delta));
|
2012-05-27 21:14:46 +00:00
|
|
|
width = (unsigned)(2.0 * width * delta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-08 20:39:18 +00:00
|
|
|
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
|
|
|
y = (unsigned)(height * (0.5 - delta));
|
2012-05-27 21:14:46 +00:00
|
|
|
height = (unsigned)(2.0 * height * delta);
|
|
|
|
}
|
2011-03-20 01:10:02 +00:00
|
|
|
}
|
2013-01-29 18:28:33 +00:00
|
|
|
|
|
|
|
gl->vp.x = x;
|
|
|
|
gl->vp.y = y;
|
|
|
|
gl->vp.width = width;
|
|
|
|
gl->vp.height = height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl->vp.x = gl->vp.y = 0;
|
|
|
|
gl->vp.width = width;
|
|
|
|
gl->vp.height = height;
|
2011-03-20 01:10:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 00:10:46 +00:00
|
|
|
#if defined(ANDROID) || defined(IOS)
|
2013-01-24 23:20:55 +00:00
|
|
|
// In portrait mode, we want viewport to gravitate to top of screen.
|
|
|
|
if (device_aspect < 1.0f)
|
2013-01-29 18:28:33 +00:00
|
|
|
gl->vp.y *= 2;
|
2013-01-23 22:05:23 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-29 18:28:33 +00:00
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
2012-05-27 20:39:29 +00:00
|
|
|
gl_set_projection(gl, &ortho, allow_rotate);
|
2011-03-20 01:10:02 +00:00
|
|
|
|
2011-03-27 18:29:47 +00:00
|
|
|
// Set last backbuffer viewport.
|
|
|
|
if (!force_full)
|
|
|
|
{
|
2012-06-08 20:39:18 +00:00
|
|
|
gl->vp_out_width = width;
|
2011-03-27 18:29:47 +00:00
|
|
|
gl->vp_out_height = height;
|
|
|
|
}
|
|
|
|
|
2012-12-27 23:14:19 +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)
|
|
|
|
{
|
2013-04-07 13:51:00 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-05-27 21:33:31 +00:00
|
|
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2012-04-01 17:20:37 +00:00
|
|
|
gl->rotation = 90 * rotation;
|
2012-05-27 20:39:29 +00:00
|
|
|
gl_set_projection(gl, &ortho, true);
|
2012-04-01 17:20:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_start_frame_fbo(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
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]);
|
2012-05-27 10:26:43 +00:00
|
|
|
gl_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.
|
2012-11-18 20:31:25 +00:00
|
|
|
gl->coords.vertex = vertexes;
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_check_fbo_dimensions(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
// 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]);
|
2012-09-10 09:12:57 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-10-19 23:12:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT32, gl->fbo_rect[i].width, gl->fbo_rect[i].height,
|
|
|
|
0, RARCH_GL_TEXTURE_TYPE32,
|
2012-05-26 14:29:02 +00:00
|
|
|
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
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_frame_fbo(void *data, const struct gl_tex_info *tex_info)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-01-31 23:14:04 +00:00
|
|
|
GLfloat fbo_tex_coords[8] = {0.0f};
|
|
|
|
|
|
|
|
// Render the rest of our passes.
|
2012-08-14 21:32:55 +00:00
|
|
|
gl->coords.tex_coord = fbo_tex_coords;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
// 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]);
|
2013-04-13 07:01:25 +00:00
|
|
|
|
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(i + 1);
|
2012-01-31 23:14:04 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
// Render to FBO with certain size.
|
2012-05-27 10:26:43 +00:00
|
|
|
gl_set_viewport(gl, rect->img_width, rect->img_height, true, false);
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->set_params(prev_rect->img_width, prev_rect->img_height,
|
2012-01-31 23:14:04 +00:00
|
|
|
prev_rect->width, prev_rect->height,
|
2012-12-14 19:33:07 +00:00
|
|
|
gl->vp.width, gl->vp.height, g_extern.frame_count,
|
2012-01-31 23:14:04 +00:00
|
|
|
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
2012-09-13 18:47:49 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
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.
|
2013-02-08 20:50:55 +00:00
|
|
|
#ifdef IOS
|
|
|
|
// There is no default frame buffer on IOS.
|
|
|
|
extern void ios_bind_game_view_fbo();
|
|
|
|
ios_bind_game_view_fbo();
|
|
|
|
#else
|
2012-01-31 23:14:04 +00:00
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2013-02-08 20:50:55 +00:00
|
|
|
#endif
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(gl->fbo_pass + 1);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2012-05-27 10:26:43 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2013-04-13 07:01:25 +00:00
|
|
|
|
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->set_params(prev_rect->img_width, prev_rect->img_height,
|
2012-01-31 23:14:04 +00:00
|
|
|
prev_rect->width, prev_rect->height,
|
2012-12-14 19:33:07 +00:00
|
|
|
gl->vp.width, gl->vp.height, g_extern.frame_count,
|
2012-01-31 23:14:04 +00:00
|
|
|
tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
|
|
|
|
2012-08-14 21:32:55 +00:00
|
|
|
gl->coords.vertex = vertex_ptr;
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
2012-09-13 18:47:49 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2012-08-14 21:32:55 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_update_resize(void *data)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-11-18 20:34:22 +00:00
|
|
|
if (!gl->fbo_inited)
|
2012-05-27 10:26:43 +00:00
|
|
|
gl_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-05-27 10:26:43 +00:00
|
|
|
gl_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
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
static void gl_update_input_size(void *data, unsigned width, unsigned height, unsigned pitch, bool clear)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-01-31 23:14:04 +00:00
|
|
|
// 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;
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
if (clear)
|
|
|
|
{
|
2012-09-11 07:55:03 +00:00
|
|
|
#if defined(HAVE_PSGL)
|
2013-03-27 15:15:15 +00:00
|
|
|
glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE,
|
|
|
|
gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size,
|
|
|
|
gl->tex_w * gl->tex_h * gl->base_size,
|
|
|
|
gl->empty_buf);
|
2012-05-27 20:39:29 +00:00
|
|
|
#else
|
2013-03-27 15:15:15 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * sizeof(uint32_t)));
|
2012-09-11 10:32:50 +00:00
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, gl->tex_w, gl->tex_h, gl->texture_type,
|
|
|
|
gl->texture_fmt, gl->empty_buf);
|
2012-05-27 20:39:29 +00:00
|
|
|
#endif
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
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-10-01 22:58:43 +00:00
|
|
|
// It is *much* faster (order of mangnitude on my setup) to use a custom SIMD-optimized conversion routine than letting GL do it :(
|
2012-10-19 23:12:02 +00:00
|
|
|
#if !defined(HAVE_PSGL) && !defined(HAVE_OPENGLES2)
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_convert_frame_rgb16_32(void *data, void *output, const void *input, int width, int height, int in_pitch)
|
2012-10-01 22:58:43 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-10-01 22:58:43 +00:00
|
|
|
if (width != gl->scaler.in_width || height != gl->scaler.in_height)
|
|
|
|
{
|
|
|
|
gl->scaler.in_width = width;
|
|
|
|
gl->scaler.in_height = height;
|
|
|
|
gl->scaler.out_width = width;
|
|
|
|
gl->scaler.out_height = height;
|
2012-10-19 23:12:02 +00:00
|
|
|
gl->scaler.in_fmt = SCALER_FMT_RGB565;
|
2012-10-01 22:58:43 +00:00
|
|
|
gl->scaler.out_fmt = SCALER_FMT_ARGB8888;
|
|
|
|
gl->scaler.scaler_type = SCALER_TYPE_POINT;
|
|
|
|
scaler_ctx_gen_filter(&gl->scaler);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->scaler.in_stride = in_pitch;
|
|
|
|
gl->scaler.out_stride = width * sizeof(uint32_t);
|
|
|
|
scaler_ctx_scale(&gl->scaler, output, input);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_convert_frame_argb8888_abgr8888(void *data, void *output, const void *input,
|
2013-01-03 00:18:19 +00:00
|
|
|
int width, int height, int in_pitch)
|
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-01-03 00:18:19 +00:00
|
|
|
if (width != gl->scaler.in_width || height != gl->scaler.in_height)
|
|
|
|
{
|
|
|
|
gl->scaler.in_width = width;
|
|
|
|
gl->scaler.in_height = height;
|
|
|
|
gl->scaler.out_width = width;
|
|
|
|
gl->scaler.out_height = height;
|
|
|
|
gl->scaler.in_fmt = SCALER_FMT_ARGB8888;
|
|
|
|
gl->scaler.out_fmt = SCALER_FMT_ABGR8888;
|
|
|
|
gl->scaler.scaler_type = SCALER_TYPE_POINT;
|
|
|
|
scaler_ctx_gen_filter(&gl->scaler);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->scaler.in_stride = in_pitch;
|
|
|
|
gl->scaler.out_stride = width * sizeof(uint32_t);
|
|
|
|
scaler_ctx_scale(&gl->scaler, output, input);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_init_textures_data(void *data)
|
2012-11-18 13:21:47 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-11-18 13:21:47 +00:00
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
gl->last_width[i] = gl->tex_w;
|
|
|
|
gl->last_height[i] = gl->tex_h;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
2012-12-10 12:02:59 +00:00
|
|
|
gl->prev_info[i].tex = gl->texture[0];
|
2012-11-18 13:21:47 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_init_textures(void *data, const video_info_t *video)
|
2012-05-26 14:01:59 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-04-06 16:40:50 +00:00
|
|
|
#if defined(HAVE_EGL) && defined(HAVE_OPENGLES2)
|
|
|
|
gl->egl_images = load_eglimage_proc(gl) && context_init_egl_image_buffer_func(video);
|
|
|
|
#else
|
|
|
|
(void)video;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PSGL
|
2012-11-10 22:56:04 +00:00
|
|
|
if (!gl->pbo)
|
|
|
|
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);
|
2013-04-06 16:40:50 +00:00
|
|
|
#endif
|
2012-11-10 22:56:04 +00:00
|
|
|
|
2012-05-26 14:01:59 +00:00
|
|
|
glGenTextures(TEXTURES, gl->texture);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
|
2012-09-11 10:32:50 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->border_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->border_type);
|
2012-05-26 14:01:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
|
|
|
|
2013-04-06 16:40:50 +00:00
|
|
|
#ifdef HAVE_PSGL
|
2012-05-26 14:01:59 +00:00
|
|
|
glTextureReferenceSCE(GL_TEXTURE_2D, 1,
|
|
|
|
gl->tex_w, gl->tex_h, 0,
|
2012-11-18 17:23:20 +00:00
|
|
|
gl->internal_fmt,
|
2012-05-26 14:01:59 +00:00
|
|
|
gl->tex_w * gl->base_size,
|
|
|
|
gl->tex_w * gl->tex_h * i * gl->base_size);
|
2013-04-06 16:40:50 +00:00
|
|
|
#else
|
|
|
|
if (!gl->egl_images)
|
|
|
|
{
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, gl->internal_fmt, gl->tex_w, gl->tex_h, 0, gl->texture_type,
|
|
|
|
gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2012-05-26 14:01:59 +00:00
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
2013-04-06 16:40:50 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_copy_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch)
|
2012-09-10 09:12:57 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-04-06 16:40:50 +00:00
|
|
|
#if defined(HAVE_OPENGLES2)
|
|
|
|
#if defined(HAVE_EGL)
|
2012-10-20 03:08:53 +00:00
|
|
|
if (gl->egl_images)
|
2012-09-15 13:17:34 +00:00
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
EGLImageKHR img = 0;
|
2012-11-03 08:18:31 +00:00
|
|
|
bool new_egl = context_write_egl_image_func(frame, width, height, pitch, (gl->base_size == 4), gl->tex_index, &img);
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2012-10-20 08:58:02 +00:00
|
|
|
if (img == EGL_NO_IMAGE_KHR)
|
2012-10-20 03:08:53 +00:00
|
|
|
{
|
2012-10-20 08:58:02 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to create EGL image.\n");
|
|
|
|
return;
|
2012-10-20 03:08:53 +00:00
|
|
|
}
|
2012-10-20 08:58:02 +00:00
|
|
|
|
|
|
|
if (new_egl)
|
|
|
|
pglEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)img);
|
2012-09-11 10:32:50 +00:00
|
|
|
}
|
2012-10-20 03:08:53 +00:00
|
|
|
else
|
|
|
|
#endif
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
2013-01-03 00:18:19 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * gl->base_size));
|
|
|
|
|
|
|
|
// Fallback for GLES devices without GL_BGRA_EXT.
|
|
|
|
if (gl->base_size == 4 && driver.gfx_use_rgba)
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
2013-01-03 00:18:19 +00:00
|
|
|
gl_convert_frame_argb8888_abgr8888(gl, gl->conv_buffer, frame, width, height, pitch);
|
2012-09-11 10:32:50 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
2012-09-29 18:06:48 +00:00
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
2013-01-03 00:18:19 +00:00
|
|
|
gl->texture_fmt, gl->conv_buffer);
|
2012-09-29 18:06:48 +00:00
|
|
|
}
|
2013-01-03 00:18:19 +00:00
|
|
|
else
|
2012-09-29 18:06:48 +00:00
|
|
|
{
|
2013-01-03 00:18:19 +00:00
|
|
|
// No GL_UNPACK_ROW_LENGTH ;(
|
|
|
|
unsigned pitch_width = pitch / gl->base_size;
|
|
|
|
if (width == pitch_width) // Happy path :D
|
|
|
|
{
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, frame);
|
|
|
|
}
|
|
|
|
else // Slower path.
|
|
|
|
{
|
|
|
|
const unsigned line_bytes = width * gl->base_size;
|
2012-12-07 07:00:46 +00:00
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
uint8_t *dst = (uint8_t*)gl->conv_buffer; // This buffer is preallocated for this purpose.
|
|
|
|
const uint8_t *src = (const uint8_t*)frame;
|
2012-12-07 07:00:46 +00:00
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
for (unsigned h = 0; h < height; h++, src += pitch, dst += line_bytes)
|
|
|
|
memcpy(dst, src, line_bytes);
|
2012-12-08 11:35:10 +00:00
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, gl->conv_buffer);
|
|
|
|
}
|
2012-09-11 10:32:50 +00:00
|
|
|
}
|
2012-10-19 23:12:02 +00:00
|
|
|
}
|
2013-04-06 16:40:50 +00:00
|
|
|
#elif defined(HAVE_PSGL)
|
|
|
|
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;
|
|
|
|
const uint8_t *frame_copy = frame;
|
|
|
|
size_t frame_copy_size = width * gl->base_size;
|
|
|
|
|
|
|
|
uint8_t *buffer = (uint8_t*)glMapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, GL_READ_WRITE) + buffer_addr;
|
|
|
|
for (unsigned h = 0; h < height; h++, buffer += buffer_stride, frame_copy += pitch)
|
|
|
|
memcpy(buffer, frame_copy, frame_copy_size);
|
|
|
|
|
|
|
|
glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE);
|
2012-09-29 18:06:48 +00:00
|
|
|
#else
|
2012-10-19 23:12:02 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch));
|
|
|
|
if (gl->base_size == 2)
|
|
|
|
{
|
|
|
|
// Always use 32-bit textures on desktop GL.
|
|
|
|
gl_convert_frame_rgb16_32(gl, gl->conv_buffer, frame, width, height, pitch);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, gl->conv_buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-01 22:58:43 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, frame);
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
}
|
2012-10-19 23:12:02 +00:00
|
|
|
#endif
|
2012-09-10 09:12:57 +00:00
|
|
|
}
|
2012-09-10 08:29:50 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_set_prev_texture(void *data, const struct gl_tex_info *tex_info)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
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));
|
|
|
|
}
|
2011-12-24 12:46:12 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_set_shader_viewport(void *data, unsigned shader)
|
2012-10-01 02:04:50 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(shader);
|
2012-10-01 02:04:50 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:28:02 +00:00
|
|
|
#if !defined(HAVE_OPENGLES) && defined(HAVE_FFMPEG)
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_pbo_async_readback(void *data)
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-11-21 15:24:28 +00:00
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[gl->pbo_readback_index++]);
|
|
|
|
gl->pbo_readback_index &= 3;
|
|
|
|
|
|
|
|
// If set, we 3 rendered frames already buffered up.
|
|
|
|
gl->pbo_readback_valid |= gl->pbo_readback_index == 0;
|
|
|
|
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, get_alignment(gl->vp.width * sizeof(uint32_t)));
|
|
|
|
|
|
|
|
// Read asynchronously into PBO buffer.
|
|
|
|
RARCH_PERFORMANCE_INIT(async_readback);
|
|
|
|
RARCH_PERFORMANCE_START(async_readback);
|
|
|
|
glReadPixels(gl->vp.x, gl->vp.y,
|
|
|
|
gl->vp.width, gl->vp.height,
|
2012-11-21 21:12:56 +00:00
|
|
|
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
|
2012-11-21 15:24:28 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(async_readback);
|
|
|
|
|
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-04-07 12:05:39 +00:00
|
|
|
static inline void gl_draw_texture(void *data)
|
2013-02-28 01:20:29 +00:00
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2013-04-07 12:05:39 +00:00
|
|
|
const GLfloat color[] = {
|
|
|
|
1.0f, 1.0f, 1.0f, gl->rgui_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->rgui_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->rgui_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->rgui_texture_alpha,
|
|
|
|
};
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2013-04-07 12:05:39 +00:00
|
|
|
gl->coords.tex_coord = tex_coords;
|
|
|
|
gl->coords.color = color;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->rgui_texture);
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(0);
|
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2013-04-11 11:13:37 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-02-28 01:20:29 +00:00
|
|
|
glEnable(GL_BLEND);
|
2013-04-13 14:48:03 +00:00
|
|
|
|
|
|
|
if (gl->rgui_texture_full_screen)
|
|
|
|
{
|
|
|
|
glViewport(0, 0, gl->win_width, gl->win_height);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
2013-02-28 01:20:29 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
2013-03-02 16:46:36 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
2013-04-07 12:05:39 +00:00
|
|
|
gl->coords.color = white_color;
|
2013-02-28 01:20:29 +00:00
|
|
|
}
|
|
|
|
#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)
|
|
|
|
{
|
2012-10-20 03:08:53 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(frame_run);
|
|
|
|
RARCH_PERFORMANCE_START(frame_run);
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-01-12 02:13:03 +00:00
|
|
|
uint64_t lifecycle_mode_state = g_extern.lifecycle_mode_state;
|
2013-03-09 16:42:19 +00:00
|
|
|
(void)lifecycle_mode_state;
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2013-04-11 11:42:02 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
|
|
|
/* FIXME - check if it makes sense for all other platforms to do a glClear
|
|
|
|
* at start of gl_frame as well - if so, we can drop this ifdef and make
|
|
|
|
* it implicit */
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
#endif
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(1);
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2013-04-10 18:42:54 +00:00
|
|
|
#ifdef IOS // Apparently the viewport is lost each frame, thanks apple.
|
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
#endif
|
|
|
|
|
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-11-03 08:18:31 +00:00
|
|
|
context_set_resize_func(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-06-23 16:01:01 +00:00
|
|
|
if (frame) // Can be NULL for frame dupe / NULL render.
|
|
|
|
{
|
2012-12-10 12:18:10 +00:00
|
|
|
gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK;
|
2012-12-10 12:02:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
// Data is already on GPU :) Have to reset some state however incase core changed it.
|
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
|
|
|
gl_update_input_size(gl, width, height, pitch, false);
|
2012-10-01 21:59:11 +00:00
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
if (!gl->fbo_inited)
|
2013-03-27 15:22:56 +00:00
|
|
|
{
|
2013-03-27 15:15:15 +00:00
|
|
|
pglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
2013-03-27 15:22:56 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
}
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
gl_update_input_size(gl, width, height, pitch, true);
|
|
|
|
RARCH_PERFORMANCE_INIT(copy_frame);
|
|
|
|
RARCH_PERFORMANCE_START(copy_frame);
|
|
|
|
gl_copy_frame(gl, frame, width, height, pitch);
|
|
|
|
RARCH_PERFORMANCE_STOP(copy_frame);
|
|
|
|
}
|
2012-06-23 16:01:01 +00:00
|
|
|
}
|
2012-12-10 12:02:59 +00:00
|
|
|
else
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
// Have to reset rendering state which libretro core could easily have overridden.
|
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
#endif
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-03-29 13:11:53 +00:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
2013-03-28 11:13:41 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-10 12:18:10 +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;
|
|
|
|
|
|
|
|
memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords));
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2013-04-13 07:01:25 +00:00
|
|
|
|
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->set_params(width, height,
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->tex_w, gl->tex_h,
|
2012-10-27 22:38:31 +00:00
|
|
|
gl->vp.width, gl->vp.height,
|
2012-12-14 19:33:07 +00:00
|
|
|
g_extern.frame_count,
|
2012-01-31 23:14:04 +00:00
|
|
|
&tex_info, gl->prev_info, NULL, 0);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
2012-09-13 18:47:49 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 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-12-10 12:18:10 +00:00
|
|
|
gl_set_prev_texture(gl, &tex_info);
|
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-04-07 12:05:39 +00:00
|
|
|
if (gl->rgui_texture_enable)
|
|
|
|
gl_draw_texture(gl);
|
2013-02-28 01:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-14 20:51:56 +00:00
|
|
|
#ifdef FPS_COUNTER
|
2013-01-12 02:13:03 +00:00
|
|
|
if (lifecycle_mode_state & (1ULL << MODE_FPS_DRAW))
|
2012-11-14 20:51:56 +00:00
|
|
|
{
|
2012-11-15 16:30:31 +00:00
|
|
|
char fps_txt[128];
|
2013-03-11 19:05:05 +00:00
|
|
|
font_params_t params = {0};
|
|
|
|
|
2012-12-15 06:03:33 +00:00
|
|
|
gfx_get_fps(fps_txt, sizeof(fps_txt), true);
|
|
|
|
|
2012-12-14 23:07:31 +00:00
|
|
|
if (gl->font_ctx)
|
2013-03-11 19:05:05 +00:00
|
|
|
{
|
|
|
|
params.x = g_settings.video.msg_pos_x;
|
|
|
|
params.y = 0.56f;
|
|
|
|
params.scale = 1.04f;
|
|
|
|
params.color = WHITE;
|
|
|
|
gl->font_ctx->render_msg(gl, fps_txt, ¶ms);
|
|
|
|
}
|
2012-11-14 20:51:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2012-12-14 23:07:31 +00:00
|
|
|
if (msg && gl->font_ctx)
|
2013-03-11 19:05:05 +00:00
|
|
|
gl->font_ctx->render_msg(gl, msg, NULL);
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-03-29 12:26:07 +00:00
|
|
|
if (gl->overlay_enable)
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_render_overlay(gl);
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2012-12-03 02:21:10 +00:00
|
|
|
#if !defined(RARCH_CONSOLE)
|
2013-04-13 12:28:12 +00:00
|
|
|
context_update_window_title_func();
|
2012-05-30 15:02:38 +00:00
|
|
|
#endif
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2012-10-20 03:08:53 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(frame_run);
|
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
// Reset state which could easily mess up libretro core.
|
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(0);
|
2013-03-28 11:13:41 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2013-04-06 09:26:06 +00:00
|
|
|
gl_disable_client_arrays();
|
2013-03-28 11:13:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-11 13:00:58 +00:00
|
|
|
context_swap_buffers_func();
|
2013-04-13 12:28:12 +00:00
|
|
|
g_extern.frame_count++;
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2012-11-23 09:28:02 +00:00
|
|
|
#if !defined(HAVE_OPENGLES) && defined(HAVE_FFMPEG)
|
2012-11-21 21:52:58 +00:00
|
|
|
if (gl->pbo_readback_enable)
|
|
|
|
gl_pbo_async_readback(gl);
|
|
|
|
#endif
|
2013-03-28 11:13:41 +00:00
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_free(void *data)
|
|
|
|
{
|
2012-05-27 20:39:29 +00:00
|
|
|
#ifdef RARCH_CONSOLE
|
|
|
|
if (driver.video_data)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2012-12-14 23:07:31 +00:00
|
|
|
if (gl->font_ctx)
|
|
|
|
gl->font_ctx->deinit(gl);
|
2012-11-14 21:51:08 +00:00
|
|
|
gl_shader_deinit(gl);
|
2012-09-13 15:05:48 +00:00
|
|
|
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2012-09-10 08:29:50 +00:00
|
|
|
gl_disable_client_arrays();
|
2012-09-13 15:05:48 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-12 11:28:07 +00:00
|
|
|
glDeleteTextures(TEXTURES, gl->texture);
|
2012-12-23 17:36:58 +00:00
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-04-07 12:05:39 +00:00
|
|
|
if (gl->rgui_texture)
|
|
|
|
glDeleteTextures(1, &gl->rgui_texture);
|
2013-02-28 01:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2012-12-19 12:26:11 +00:00
|
|
|
if (gl->tex_overlay)
|
|
|
|
glDeleteTextures(1, &gl->tex_overlay);
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2011-03-23 22:48:13 +00:00
|
|
|
|
2012-09-11 07:55:03 +00:00
|
|
|
#if defined(HAVE_PSGL)
|
2012-05-26 13:45:00 +00:00
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0);
|
|
|
|
glDeleteBuffers(1, &gl->pbo);
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
scaler_ctx_gen_reset(&gl->scaler);
|
|
|
|
|
2012-11-23 09:28:02 +00:00
|
|
|
#if !defined(HAVE_OPENGLES) && defined(HAVE_FFMPEG)
|
2012-11-21 15:24:28 +00:00
|
|
|
if (gl->pbo_readback_enable)
|
2012-11-21 21:12:56 +00:00
|
|
|
{
|
2012-11-21 15:24:28 +00:00
|
|
|
pglDeleteBuffers(4, gl->pbo_readback);
|
2012-11-21 21:12:56 +00:00
|
|
|
scaler_ctx_gen_reset(&gl->pbo_readback_scaler);
|
|
|
|
}
|
2012-11-21 15:24:28 +00:00
|
|
|
#endif
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_deinit_fbo(gl);
|
2013-03-27 15:15:15 +00:00
|
|
|
|
2013-03-30 14:39:00 +00:00
|
|
|
#ifndef HAVE_RGL
|
2013-03-27 15:15:15 +00:00
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
pglDeleteFramebuffers(TEXTURES, gl->hw_render_fbo);
|
2013-04-04 18:21:51 +00:00
|
|
|
if (gl->hw_render_depth_init)
|
2013-03-29 01:50:42 +00:00
|
|
|
pglDeleteRenderbuffers(TEXTURES, gl->hw_render_depth);
|
2013-03-27 15:15:15 +00:00
|
|
|
gl->hw_render_fbo_init = false;
|
2013-03-30 14:39:00 +00:00
|
|
|
#endif
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2012-11-03 08:18:31 +00:00
|
|
|
context_destroy_func();
|
2011-03-13 19:52:06 +00:00
|
|
|
|
2012-09-15 13:17:34 +00:00
|
|
|
free(gl->empty_buf);
|
|
|
|
free(gl->conv_buffer);
|
2011-05-31 21:03:01 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2012-08-12 07:36:15 +00:00
|
|
|
RARCH_LOG("GL VSync => %s\n", state ? "off" : "on");
|
2012-12-26 08:32:15 +00:00
|
|
|
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
(void)gl;
|
2012-11-03 08:18:31 +00:00
|
|
|
context_swap_interval_func(state ? 0 : 1);
|
2010-08-16 16:40:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 11:33:23 +00:00
|
|
|
static bool resolve_extensions(gl_t *gl)
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Win32 GL lib doesn't have some elementary functions needed.
|
|
|
|
// Need to load dynamically :(
|
2012-09-24 23:26:22 +00:00
|
|
|
if (!load_gl_proc_win32(gl))
|
2012-09-11 10:32:50 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifdef NO_GL_CLAMP_TO_BORDER
|
2012-09-15 13:17:34 +00:00
|
|
|
// NOTE: This will be a serious problem for some shaders.
|
2012-09-11 10:32:50 +00:00
|
|
|
gl->border_type = GL_CLAMP_TO_EDGE;
|
|
|
|
#else
|
|
|
|
gl->border_type = GL_CLAMP_TO_BORDER;
|
|
|
|
#endif
|
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
driver.gfx_use_rgba = false;
|
2012-09-30 08:33:15 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
2013-01-03 00:18:19 +00:00
|
|
|
if (gl_query_extension("BGRA8888"))
|
|
|
|
RARCH_LOG("[GL]: BGRA8888 extension found for GLES.\n");
|
|
|
|
else
|
2012-09-29 18:06:48 +00:00
|
|
|
{
|
2013-01-03 00:18:19 +00:00
|
|
|
driver.gfx_use_rgba = true;
|
|
|
|
RARCH_WARN("[GL]: GLES implementation does not have BGRA8888 extension.\n"
|
|
|
|
"32-bit path will require conversion.\n");
|
2012-09-29 18:06:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-23 09:54:51 +00:00
|
|
|
#if 0
|
2012-09-29 18:06:48 +00:00
|
|
|
// Useful for debugging, but kinda obnoxious.
|
2012-09-15 13:17:34 +00:00
|
|
|
const char *ext = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
if (ext)
|
|
|
|
RARCH_LOG("[GL] Supported extensions: %s\n", ext);
|
2012-09-23 09:54:51 +00:00
|
|
|
#endif
|
2012-09-15 13:17:34 +00:00
|
|
|
|
2012-09-11 10:32:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_set_texture_fmts(void *data, bool rgb32)
|
2013-01-03 00:18:19 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
gl->internal_fmt = rgb32 ? RARCH_GL_INTERNAL_FORMAT32 : RARCH_GL_INTERNAL_FORMAT16;
|
|
|
|
gl->texture_type = rgb32 ? RARCH_GL_TEXTURE_TYPE32 : RARCH_GL_TEXTURE_TYPE16;
|
|
|
|
gl->texture_fmt = rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16;
|
|
|
|
gl->base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
|
|
|
|
|
|
|
if (driver.gfx_use_rgba && rgb32)
|
|
|
|
{
|
|
|
|
gl->internal_fmt = GL_RGBA;
|
|
|
|
gl->texture_type = GL_RGBA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static inline void gl_reinit_textures(void *data, const video_info_t *video)
|
2012-11-10 22:56:04 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-11-10 22:56:04 +00:00
|
|
|
unsigned old_base_size = gl->base_size;
|
2012-11-15 22:25:13 +00:00
|
|
|
unsigned old_width = gl->tex_w;
|
|
|
|
unsigned old_height = gl->tex_h;
|
2012-11-10 22:56:04 +00:00
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
gl_set_texture_fmts(gl, video->rgb32);
|
2012-11-15 22:25:13 +00:00
|
|
|
gl->tex_w = gl->tex_h = RARCH_SCALE_BASE * video->input_scale;
|
|
|
|
|
2012-11-18 13:21:47 +00:00
|
|
|
gl->empty_buf = realloc(gl->empty_buf, sizeof(uint32_t) * gl->tex_w * gl->tex_h);
|
|
|
|
if (gl->empty_buf)
|
|
|
|
memset(gl->empty_buf, 0, sizeof(uint32_t) * gl->tex_w * gl->tex_h);
|
|
|
|
|
2012-11-15 22:25:13 +00:00
|
|
|
if (old_base_size != gl->base_size || old_width != gl->tex_w || old_height != gl->tex_h)
|
2012-11-10 22:56:04 +00:00
|
|
|
{
|
2012-11-18 13:21:47 +00:00
|
|
|
RARCH_LOG("Reinitializing textures (%u x %u @ %u bpp)\n", gl->tex_w, gl->tex_h, gl->base_size * CHAR_BIT);
|
2012-11-18 14:39:29 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0);
|
|
|
|
glDeleteBuffers(1, &gl->pbo);
|
|
|
|
gl->pbo = 0;
|
|
|
|
#endif
|
|
|
|
|
2012-11-18 13:21:47 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2012-11-10 22:56:04 +00:00
|
|
|
glDeleteTextures(TEXTURES, gl->texture);
|
2012-11-18 14:39:29 +00:00
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-02-28 01:20:29 +00:00
|
|
|
glDeleteTextures(1, &gl->rgui_texture);
|
|
|
|
#endif
|
|
|
|
|
2012-11-10 22:56:04 +00:00
|
|
|
gl_init_textures(gl, video);
|
2012-11-18 13:21:47 +00:00
|
|
|
gl_init_textures_data(gl);
|
2012-11-15 22:25:13 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FBO
|
2012-11-18 14:22:32 +00:00
|
|
|
if (gl->tex_w > old_width || gl->tex_h > old_height)
|
|
|
|
{
|
|
|
|
RARCH_LOG("Reiniting FBO.\n");
|
|
|
|
gl_deinit_fbo(gl);
|
|
|
|
gl_init_fbo(gl, gl->tex_w, gl->tex_h);
|
|
|
|
}
|
2012-11-15 22:25:13 +00:00
|
|
|
#endif
|
2012-11-10 22:56:04 +00:00
|
|
|
}
|
2012-11-18 13:21:47 +00:00
|
|
|
else
|
|
|
|
RARCH_LOG("Reinitializing textures skipped.\n");
|
2012-11-18 14:06:33 +00:00
|
|
|
|
|
|
|
if (!gl_check_error())
|
2012-11-18 14:22:32 +00:00
|
|
|
RARCH_ERR("GL error reported while reinitializing textures. This should not happen ...\n");
|
2012-11-10 22:56:04 +00:00
|
|
|
}
|
2012-09-30 17:55:33 +00:00
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_init_pbo_readback(void *data)
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-11-23 09:28:02 +00:00
|
|
|
#if !defined(HAVE_OPENGLES) && defined(HAVE_FFMPEG)
|
2012-11-21 15:24:28 +00:00
|
|
|
// Only bother with this if we're doing FFmpeg GPU recording.
|
|
|
|
gl->pbo_readback_enable = g_settings.video.gpu_record && g_extern.recording;
|
|
|
|
if (!gl->pbo_readback_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RARCH_LOG("Async PBO readback enabled.\n");
|
|
|
|
|
|
|
|
pglGenBuffers(4, gl->pbo_readback);
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[i]);
|
|
|
|
pglBufferData(GL_PIXEL_PACK_BUFFER, gl->vp.width * gl->vp.height * sizeof(uint32_t),
|
2012-11-21 21:52:58 +00:00
|
|
|
NULL, GL_STREAM_READ);
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
2012-11-21 21:12:56 +00:00
|
|
|
|
|
|
|
struct scaler_ctx *scaler = &gl->pbo_readback_scaler;
|
|
|
|
scaler->in_width = gl->vp.width;
|
|
|
|
scaler->in_height = gl->vp.height;
|
|
|
|
scaler->out_width = gl->vp.width;
|
|
|
|
scaler->out_height = gl->vp.height;
|
|
|
|
scaler->in_stride = gl->vp.width * sizeof(uint32_t);
|
|
|
|
scaler->out_stride = gl->vp.width * 3;
|
|
|
|
scaler->in_fmt = SCALER_FMT_ARGB8888;
|
|
|
|
scaler->out_fmt = SCALER_FMT_BGR24;
|
2012-11-22 22:11:21 +00:00
|
|
|
scaler->scaler_type = SCALER_TYPE_POINT;
|
2012-11-21 21:12:56 +00:00
|
|
|
|
|
|
|
if (!scaler_ctx_gen_filter(scaler))
|
|
|
|
{
|
|
|
|
gl->pbo_readback_enable = false;
|
|
|
|
RARCH_ERR("Failed to init pixel conversion for PBO.\n");
|
|
|
|
pglDeleteBuffers(4, gl->pbo_readback);
|
|
|
|
}
|
|
|
|
|
2012-11-21 15:24:28 +00:00
|
|
|
#else
|
|
|
|
(void)gl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-23 13:49:49 +00:00
|
|
|
static const gfx_ctx_driver_t *gl_get_context(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENGLES
|
|
|
|
enum gfx_ctx_api api = GFX_CTX_OPENGL_ES_API;
|
|
|
|
const char *api_name = "OpenGL ES";
|
|
|
|
#else
|
|
|
|
enum gfx_ctx_api api = GFX_CTX_OPENGL_API;
|
|
|
|
const char *api_name = "OpenGL";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (*g_settings.video.gl_context)
|
|
|
|
{
|
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_find_driver(g_settings.video.gl_context);
|
|
|
|
if (ctx)
|
|
|
|
{
|
|
|
|
if (!ctx->bind_api(api))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to bind API %s to context %s.\n", api_name, g_settings.video.gl_context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctx->init())
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to init GL context: %s.\n", ctx->ident);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("Didn't find GL context: %s.\n", g_settings.video.gl_context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return gfx_ctx_init_first(api);
|
|
|
|
}
|
|
|
|
|
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-27 20:39:29 +00:00
|
|
|
#ifdef RARCH_CONSOLE
|
|
|
|
if (driver.video_data)
|
2012-11-10 22:56:04 +00:00
|
|
|
{
|
2012-11-14 20:51:56 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2012-11-10 22:56:04 +00:00
|
|
|
// Reinitialize textures as we might have changed pixel formats.
|
|
|
|
gl_reinit_textures(gl, video);
|
2012-05-27 20:39:29 +00:00
|
|
|
return driver.video_data;
|
2012-11-10 22:56:04 +00:00
|
|
|
}
|
2012-05-27 20:39:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-27 13:04:43 +00:00
|
|
|
gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t));
|
|
|
|
if (!gl)
|
|
|
|
return NULL;
|
|
|
|
|
2013-02-23 13:49:49 +00:00
|
|
|
gl->ctx_driver = gl_get_context();
|
2012-10-09 15:47:48 +00:00
|
|
|
if (!gl->ctx_driver)
|
2012-05-27 13:04:43 +00:00
|
|
|
{
|
|
|
|
free(gl);
|
2011-01-06 17:34:11 +00:00
|
|
|
return NULL;
|
2012-05-27 13:04:43 +00:00
|
|
|
}
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2012-10-09 15:47:48 +00:00
|
|
|
RARCH_LOG("Found GL context: %s\n", gl->ctx_driver->ident);
|
2012-09-24 23:26:22 +00:00
|
|
|
|
2012-11-03 08:18:31 +00:00
|
|
|
context_get_video_size_func(&gl->full_x, &gl->full_y);
|
2012-09-16 19:39:40 +00:00
|
|
|
RARCH_LOG("Detecting screen resolution %ux%u.\n", gl->full_x, gl->full_y);
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2012-11-03 08:18:31 +00:00
|
|
|
context_swap_interval_func(video->vsync ? 1 : 0);
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
unsigned win_width = video->width;
|
2011-09-13 16:50:40 +00:00
|
|
|
unsigned win_height = video->height;
|
|
|
|
if (video->fullscreen && (win_width == 0) && (win_height == 0))
|
|
|
|
{
|
2012-09-16 19:39:40 +00:00
|
|
|
win_width = gl->full_x;
|
|
|
|
win_height = gl->full_y;
|
2011-09-13 16:50:40 +00:00
|
|
|
}
|
|
|
|
|
2012-11-20 22:23:18 +00:00
|
|
|
if (!context_set_video_mode_func(win_width, win_height, video->fullscreen))
|
2012-05-27 13:04:43 +00:00
|
|
|
{
|
|
|
|
free(gl);
|
2011-01-06 17:34:11 +00:00
|
|
|
return NULL;
|
2012-05-27 13:04:43 +00:00
|
|
|
}
|
2011-01-11 21:33:28 +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
|
|
|
|
2012-12-27 11:33:23 +00:00
|
|
|
if (!resolve_extensions(gl))
|
2011-05-18 20:40:42 +00:00
|
|
|
{
|
2012-11-03 08:18:31 +00:00
|
|
|
context_destroy_func();
|
2012-05-27 13:04:43 +00:00
|
|
|
free(gl);
|
2011-05-18 20:40:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-11 21:33:28 +00:00
|
|
|
|
2012-09-16 19:39:40 +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
|
|
|
|
2012-09-16 19:39:40 +00:00
|
|
|
// Get real known video size, which might have been altered by context.
|
2012-11-03 08:18:31 +00:00
|
|
|
context_get_video_size_func(&gl->win_width, &gl->win_height);
|
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-09-16 19:39:40 +00:00
|
|
|
if (gl->full_x || gl->full_y) // We got bogus from gfx_ctx_get_video_size. Replace.
|
|
|
|
{
|
|
|
|
gl->full_x = gl->win_width;
|
|
|
|
gl->full_y = gl->win_height;
|
|
|
|
}
|
|
|
|
|
2012-10-16 17:43:05 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2012-10-09 15:47:48 +00:00
|
|
|
gl_glsl_set_get_proc_address(gl->ctx_driver->get_proc_address);
|
2012-09-24 23:26:22 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
if (!gl_shader_init(gl))
|
2011-01-11 18:23:21 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Shader init failed.\n");
|
2012-11-03 08:18:31 +00:00
|
|
|
context_destroy_func();
|
2011-01-11 20:16:57 +00:00
|
|
|
free(gl);
|
2011-01-11 18:23:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
RARCH_LOG("GL: Loaded %u program(s).\n", gl_shader_num(gl));
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2012-11-18 14:22:32 +00:00
|
|
|
gl->tex_w = RARCH_SCALE_BASE * video->input_scale;
|
|
|
|
gl->tex_h = RARCH_SCALE_BASE * video->input_scale;
|
|
|
|
|
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.
|
2012-09-30 17:55:33 +00:00
|
|
|
gl_set_shader_viewport(gl, 0);
|
|
|
|
gl_set_shader_viewport(gl, 1);
|
2011-01-06 19:01:32 +00:00
|
|
|
|
2012-05-27 15:46:47 +00:00
|
|
|
bool force_smooth = false;
|
2012-11-14 21:51:08 +00:00
|
|
|
if (gl_shader_filter_type(gl, 1, &force_smooth))
|
2011-03-14 20:28:30 +00:00
|
|
|
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
|
|
|
|
2013-01-03 00:18:19 +00:00
|
|
|
gl_set_texture_fmts(gl, video->rgb32);
|
2011-03-07 18:12:14 +00:00
|
|
|
|
2012-09-15 13:17:34 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2010-05-28 00:45:18 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2012-09-15 13:17:34 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-08 22:38:32 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-03-28 00:19:48 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
2011-03-12 18:28:56 +00:00
|
|
|
glDisable(GL_DITHER);
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2010-12-26 03:15:12 +00:00
|
|
|
memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords));
|
2012-09-11 21:32:00 +00:00
|
|
|
gl->coords.vertex = vertex_ptr;
|
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
|
|
|
gl->coords.color = white_color;
|
|
|
|
gl->coords.lut_tex_coord = tex_coords;
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
2011-05-18 18:38:04 +00:00
|
|
|
|
2011-05-31 21:03:01 +00:00
|
|
|
// Empty buffer that we use to clear out the texture with on res change.
|
2012-09-29 18:06:48 +00:00
|
|
|
gl->empty_buf = calloc(sizeof(uint32_t), gl->tex_w * gl->tex_h);
|
2012-09-15 13:17:34 +00:00
|
|
|
|
2012-10-01 22:58:43 +00:00
|
|
|
#if !defined(HAVE_PSGL)
|
2012-09-29 18:06:48 +00:00
|
|
|
gl->conv_buffer = calloc(sizeof(uint32_t), gl->tex_w * gl->tex_h);
|
2012-09-15 13:17:34 +00:00
|
|
|
if (!gl->conv_buffer)
|
|
|
|
{
|
2012-11-03 08:18:31 +00:00
|
|
|
context_destroy_func();
|
2012-09-15 13:17:34 +00:00
|
|
|
free(gl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-20 10:22:10 +00:00
|
|
|
gl_init_textures(gl, video);
|
2012-11-18 13:21:47 +00:00
|
|
|
gl_init_textures_data(gl);
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
// Set up render to texture.
|
|
|
|
gl_init_fbo(gl, gl->tex_w, gl->tex_h);
|
|
|
|
|
2013-03-30 14:40:53 +00:00
|
|
|
#ifndef HAVE_RGL
|
2013-03-29 14:26:47 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
enum retro_hw_context_type desired = RETRO_HW_CONTEXT_OPENGLES2;
|
|
|
|
#else
|
|
|
|
enum retro_hw_context_type desired = RETRO_HW_CONTEXT_OPENGL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_extern.system.hw_render_callback.context_type == desired
|
2013-03-29 01:12:08 +00:00
|
|
|
&& !gl_init_hw_render(gl, gl->tex_w, gl->tex_h))
|
|
|
|
{
|
|
|
|
context_destroy_func();
|
|
|
|
free(gl);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-30 14:39:00 +00:00
|
|
|
#endif
|
2013-03-27 15:15:15 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-16 01:21:43 +00:00
|
|
|
if (input && input_data)
|
|
|
|
context_input_driver_func(input, input_data);
|
2012-12-14 23:07:31 +00:00
|
|
|
|
2013-03-09 16:42:19 +00:00
|
|
|
#if !defined(HAVE_RMENU)
|
2012-12-14 23:17:43 +00:00
|
|
|
// Comes too early for console - moved to gl_start
|
2013-01-05 22:47:49 +00:00
|
|
|
if (g_settings.video.font_enable)
|
|
|
|
gl->font_ctx = gl_font_init_first(gl, g_settings.video.font_path, g_settings.video.font_size);
|
2012-12-14 23:17:43 +00:00
|
|
|
#endif
|
2012-09-10 21:17:48 +00:00
|
|
|
|
2012-11-21 15:24:28 +00:00
|
|
|
gl_init_pbo_readback(gl);
|
|
|
|
|
2011-01-11 21:33:28 +00:00
|
|
|
if (!gl_check_error())
|
|
|
|
{
|
2012-11-03 08:18:31 +00:00
|
|
|
context_destroy_func();
|
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;
|
2012-05-30 15:02:38 +00:00
|
|
|
bool quit, resize;
|
|
|
|
|
2012-11-03 08:18:31 +00:00
|
|
|
context_check_window_func(&quit,
|
2012-05-30 15:02:38 +00:00
|
|
|
&resize, &gl->win_width, &gl->win_height,
|
2012-12-14 19:33:07 +00:00
|
|
|
g_extern.frame_count);
|
2012-05-30 15:02:38 +00:00
|
|
|
|
|
|
|
if (quit)
|
|
|
|
gl->quitting = true;
|
|
|
|
else if (resize)
|
|
|
|
gl->should_resize = true;
|
|
|
|
|
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)
|
|
|
|
{
|
2012-12-26 08:32:15 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
(void)gl;
|
2012-11-03 08:18:31 +00:00
|
|
|
return context_has_focus_func();
|
2011-02-05 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 14:05:55 +00:00
|
|
|
#if defined(HAVE_GLSL) || defined(HAVE_CG)
|
2013-04-07 11:00:21 +00:00
|
|
|
static bool gl_set_shader(void *data, enum rarch_shader_type type, const char *path)
|
2011-03-29 16:28:31 +00:00
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2011-06-07 13:58:30 +00:00
|
|
|
|
2013-01-08 02:46:18 +00:00
|
|
|
if (type == RARCH_SHADER_NONE)
|
|
|
|
return false;
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
gl_shader_deinit(gl);
|
2011-06-11 20:02:05 +00:00
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
switch (type)
|
2012-09-21 19:20:30 +00:00
|
|
|
{
|
2013-01-02 14:05:55 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2013-04-07 11:00:21 +00:00
|
|
|
case RARCH_SHADER_GLSL:
|
|
|
|
gl->shader = &gl_glsl_backend;
|
|
|
|
break;
|
2012-09-21 19:20:30 +00:00
|
|
|
#endif
|
2013-04-07 11:00:21 +00:00
|
|
|
|
2012-09-21 19:20:30 +00:00
|
|
|
#ifdef HAVE_CG
|
2013-04-07 11:00:21 +00:00
|
|
|
case RARCH_SHADER_CG:
|
|
|
|
gl->shader = &gl_cg_backend;
|
|
|
|
break;
|
2012-09-21 19:20:30 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
default:
|
|
|
|
gl->shader = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-08 02:46:18 +00:00
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
if (!gl->shader)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Cannot find shader core for path: %s.\n", path);
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-08 02:46:18 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FBO
|
2013-04-07 11:00:21 +00:00
|
|
|
gl_deinit_fbo(gl);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2013-01-08 02:46:18 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
if (!gl->shader->init(path))
|
|
|
|
{
|
|
|
|
RARCH_WARN("[GL]: Failed to set multipass shader. Falling back to stock.\n");
|
|
|
|
bool ret = gl->shader->init(NULL);
|
2013-01-08 02:46:18 +00:00
|
|
|
if (!ret)
|
2013-04-07 11:00:21 +00:00
|
|
|
gl->shader = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-29 16:59:06 +00:00
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-04-07 11:00:21 +00:00
|
|
|
// Set up render to texture again.
|
|
|
|
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
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
// Apparently need to set viewport for passes when we aren't using FBOs.
|
|
|
|
gl_set_shader_viewport(gl, 0);
|
|
|
|
gl_set_shader_viewport(gl, 1);
|
|
|
|
return true;
|
2011-03-29 16:28:31 +00:00
|
|
|
}
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
2011-03-29 16:28:31 +00:00
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifndef NO_GL_READ_VIEWPORT
|
2012-10-27 22:38:31 +00:00
|
|
|
static void gl_viewport_info(void *data, struct rarch_viewport *vp)
|
2012-06-08 20:39:18 +00:00
|
|
|
{
|
2012-10-27 22:38:31 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
*vp = gl->vp;
|
2013-01-11 15:23:04 +00:00
|
|
|
vp->full_width = gl->win_width;
|
|
|
|
vp->full_height = gl->win_height;
|
2013-01-24 06:29:26 +00:00
|
|
|
|
|
|
|
// Adjust as GL viewport is bottom-up.
|
|
|
|
unsigned top_y = vp->y + vp->height;
|
|
|
|
unsigned top_dist = gl->win_height - top_y;
|
|
|
|
vp->y = top_dist;
|
2012-06-08 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool gl_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
2012-10-27 22:38:31 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-06-10 09:10:14 +00:00
|
|
|
|
2012-11-20 17:05:33 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(read_viewport);
|
|
|
|
RARCH_PERFORMANCE_START(read_viewport);
|
|
|
|
|
2012-10-22 23:03:57 +00:00
|
|
|
#ifdef HAVE_OPENGLES
|
2012-11-21 15:24:28 +00:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, get_alignment(gl->vp.width * 3));
|
2012-10-28 02:14:50 +00:00
|
|
|
glReadPixels(gl->vp.x, gl->vp.y,
|
|
|
|
gl->vp.width, gl->vp.height,
|
2012-10-22 23:03:57 +00:00
|
|
|
GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
|
2012-10-23 06:37:51 +00:00
|
|
|
uint8_t *pixels = (uint8_t*)buffer;
|
2012-10-27 22:38:31 +00:00
|
|
|
unsigned num_pixels = gl->vp.width * gl->vp.height;
|
2012-10-23 06:37:51 +00:00
|
|
|
// Convert RGB to BGR. Formats are byte ordered, so just swap 1st and 3rd byte.
|
|
|
|
for (unsigned i = 0; i <= num_pixels; pixels += 3, i++)
|
2012-10-22 23:03:57 +00:00
|
|
|
{
|
2012-10-23 06:37:51 +00:00
|
|
|
uint8_t tmp = pixels[2];
|
|
|
|
pixels[2] = pixels[0];
|
|
|
|
pixels[0] = tmp;
|
2012-10-22 23:03:57 +00:00
|
|
|
}
|
|
|
|
#else
|
2012-11-23 09:28:02 +00:00
|
|
|
#ifdef HAVE_FFMPEG
|
2012-11-21 15:24:28 +00:00
|
|
|
if (gl->pbo_readback_enable)
|
|
|
|
{
|
|
|
|
if (!gl->pbo_readback_valid) // We haven't buffered up enough frames yet, come back later.
|
|
|
|
return false;
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2012-11-21 15:24:28 +00:00
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[gl->pbo_readback_index]);
|
2012-11-21 21:12:56 +00:00
|
|
|
const void *ptr = pglMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
2012-11-21 15:24:28 +00:00
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to map pixel unpack buffer.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-21 21:12:56 +00:00
|
|
|
|
|
|
|
scaler_ctx_scale(&gl->pbo_readback_scaler, buffer, ptr);
|
2012-11-21 15:24:28 +00:00
|
|
|
pglUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
|
|
|
pglBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
|
|
|
}
|
|
|
|
else // Use slow synchronous readbacks. Use this with plain screenshots as we don't really care about performance in this case.
|
2012-11-23 09:28:02 +00:00
|
|
|
#endif
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, gl->vp.width);
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, get_alignment(gl->vp.width * 3));
|
|
|
|
|
|
|
|
glReadPixels(gl->vp.x, gl->vp.y,
|
|
|
|
gl->vp.width, gl->vp.height,
|
|
|
|
GL_BGR, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
}
|
2012-10-22 23:03:57 +00:00
|
|
|
#endif
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2012-11-20 17:05:33 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(read_viewport);
|
2012-06-08 20:39:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-08 22:24:43 +00:00
|
|
|
#endif
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2013-03-24 00:00:00 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-03-10 01:58:55 +00:00
|
|
|
static void gl_get_poke_interface(void *data, const video_poke_interface_t **iface);
|
2013-03-10 00:58:31 +00:00
|
|
|
|
2012-05-27 20:39:29 +00:00
|
|
|
static void gl_start(void)
|
|
|
|
{
|
|
|
|
video_info_t video_info = {0};
|
|
|
|
|
|
|
|
// Might have to supply correct values here.
|
|
|
|
video_info.vsync = g_settings.video.vsync;
|
|
|
|
video_info.force_aspect = false;
|
|
|
|
video_info.smooth = g_settings.video.smooth;
|
|
|
|
video_info.input_scale = 2;
|
|
|
|
video_info.fullscreen = true;
|
2012-11-18 20:50:27 +00:00
|
|
|
|
2012-10-15 04:24:39 +00:00
|
|
|
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2012-05-27 20:39:29 +00:00
|
|
|
{
|
2012-10-15 04:24:39 +00:00
|
|
|
video_info.width = g_extern.console.screen.viewports.custom_vp.width;
|
|
|
|
video_info.height = g_extern.console.screen.viewports.custom_vp.height;
|
2012-05-27 20:39:29 +00:00
|
|
|
}
|
2012-11-18 20:50:27 +00:00
|
|
|
|
2012-05-27 20:39:29 +00:00
|
|
|
driver.video_data = gl_init(&video_info, NULL, NULL);
|
|
|
|
|
2012-09-25 01:49:20 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2013-03-10 00:58:31 +00:00
|
|
|
gl_get_poke_interface(gl, &driver.video_poke);
|
2012-09-25 01:49:20 +00:00
|
|
|
|
2012-12-14 23:17:43 +00:00
|
|
|
// Comes too early for console - moved to gl_start
|
|
|
|
gl->font_ctx = gl_font_init_first(gl, g_settings.video.font_path, g_settings.video.font_size);
|
2012-05-27 20:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_stop(void)
|
|
|
|
{
|
|
|
|
void *data = driver.video_data;
|
|
|
|
driver.video_data = NULL;
|
|
|
|
gl_free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_restart(void)
|
|
|
|
{
|
2013-04-04 12:36:24 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2012-05-27 21:14:46 +00:00
|
|
|
if (!gl)
|
2012-05-27 20:39:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
gl_stop();
|
2012-09-09 22:36:25 +00:00
|
|
|
#ifdef HAVE_CG
|
2012-05-27 20:39:29 +00:00
|
|
|
gl_cg_invalidate_context();
|
2012-09-09 22:36:25 +00:00
|
|
|
#endif
|
2012-05-27 20:39:29 +00:00
|
|
|
gl_start();
|
|
|
|
}
|
2013-03-09 16:42:19 +00:00
|
|
|
#endif
|
2012-08-20 10:41:10 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2012-12-20 11:24:49 +00:00
|
|
|
static bool gl_overlay_load(void *data, const uint32_t *image, unsigned width, unsigned height)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
if (!gl->tex_overlay)
|
|
|
|
glGenTextures(1, &gl->tex_overlay);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->tex_overlay);
|
2013-03-09 17:37:50 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->border_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->border_type);
|
2012-12-19 12:26:11 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
2013-04-10 02:39:27 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2012-12-20 11:24:49 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * sizeof(uint32_t)));
|
2013-04-10 02:39:27 +00:00
|
|
|
#endif
|
2013-01-03 00:18:19 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
width, height, 0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
2012-12-20 11:24:49 +00:00
|
|
|
RARCH_GL_FORMAT32, image);
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_overlay_tex_geom(gl, 0, 0, 1, 1); // Default. Stretch to whole screen.
|
|
|
|
gl_overlay_vertex_geom(gl, 0, 0, 1, 1);
|
2013-01-29 20:51:15 +00:00
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_tex_geom(void *data,
|
2012-12-19 12:26:11 +00:00
|
|
|
GLfloat x, GLfloat y,
|
|
|
|
GLfloat w, GLfloat h)
|
|
|
|
{
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
gl->overlay_tex_coord[0] = x; gl->overlay_tex_coord[1] = y;
|
|
|
|
gl->overlay_tex_coord[2] = x + w; gl->overlay_tex_coord[3] = y;
|
|
|
|
gl->overlay_tex_coord[4] = x; gl->overlay_tex_coord[5] = y + h;
|
|
|
|
gl->overlay_tex_coord[6] = x + w; gl->overlay_tex_coord[7] = y + h;
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_vertex_geom(void *data,
|
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
// Flipped, so we preserve top-down semantics.
|
|
|
|
y = 1.0f - y;
|
|
|
|
h = -h;
|
|
|
|
|
|
|
|
gl->overlay_vertex_coord[0] = x; gl->overlay_vertex_coord[1] = y;
|
|
|
|
gl->overlay_vertex_coord[2] = x + w; gl->overlay_vertex_coord[3] = y;
|
|
|
|
gl->overlay_vertex_coord[4] = x; gl->overlay_vertex_coord[5] = y + h;
|
|
|
|
gl->overlay_vertex_coord[6] = x + w; gl->overlay_vertex_coord[7] = y + h;
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_enable(void *data, bool state)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
gl->overlay_enable = state;
|
2013-03-29 12:46:11 +00:00
|
|
|
if (gl->ctx_driver->show_mouse && gl->fullscreen)
|
|
|
|
gl->ctx_driver->show_mouse(state);
|
2012-12-20 10:16:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
static void gl_overlay_full_screen(void *data, bool enable)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
gl->overlay_full_screen = enable;
|
|
|
|
}
|
|
|
|
|
2013-01-29 20:51:15 +00:00
|
|
|
static void gl_overlay_set_alpha(void *data, float mod)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
gl->overlay_alpha_mod = mod;
|
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_render_overlay(void *data)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->tex_overlay);
|
|
|
|
|
2013-01-29 20:51:15 +00:00
|
|
|
const GLfloat white_color_mod[16] = {
|
|
|
|
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->overlay_alpha_mod,
|
|
|
|
};
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
if (gl->shader)
|
|
|
|
gl->shader->use(0);
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
gl->coords.vertex = gl->overlay_vertex_coord;
|
|
|
|
gl->coords.tex_coord = gl->overlay_tex_coord;
|
2013-01-29 20:51:15 +00:00
|
|
|
gl->coords.color = white_color_mod;
|
|
|
|
|
2013-04-13 07:01:25 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
if (gl->overlay_full_screen)
|
|
|
|
{
|
|
|
|
glViewport(0, 0, gl->win_width, gl->win_height);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
gl->coords.vertex = vertex_ptr;
|
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
2013-01-29 20:51:15 +00:00
|
|
|
gl->coords.color = white_color;
|
2012-12-19 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static const video_overlay_interface_t gl_overlay_interface = {
|
|
|
|
gl_overlay_enable,
|
|
|
|
gl_overlay_load,
|
|
|
|
gl_overlay_tex_geom,
|
|
|
|
gl_overlay_vertex_geom,
|
2013-01-11 15:23:04 +00:00
|
|
|
gl_overlay_full_screen,
|
2013-01-29 20:51:15 +00:00
|
|
|
gl_overlay_set_alpha,
|
2012-12-20 10:16:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gl_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &gl_overlay_interface;
|
|
|
|
}
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2013-03-10 00:16:56 +00:00
|
|
|
static void gl_set_filtering(void *data, unsigned index, bool smooth)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
GLuint filter = smooth ? GL_LINEAR : GL_NEAREST;
|
|
|
|
if (index == 1)
|
|
|
|
{
|
|
|
|
gl->tex_filter = filter;
|
|
|
|
// Apply to all PREV textures.
|
|
|
|
for (unsigned i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
|
|
|
}
|
|
|
|
}
|
2013-03-10 00:47:57 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-03-10 00:16:56 +00:00
|
|
|
else if (index >= 2 && gl->fbo_inited)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
|
|
|
}
|
2013-03-10 00:47:57 +00:00
|
|
|
#endif
|
2013-03-10 00:16:56 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
|
|
|
|
2013-03-11 23:00:42 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-03-27 15:15:15 +00:00
|
|
|
static uintptr_t gl_get_current_framebuffer(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
return gl->hw_render_fbo[(gl->tex_index + 1) & TEXTURES_MASK];
|
|
|
|
}
|
2013-03-28 00:11:32 +00:00
|
|
|
|
|
|
|
static retro_proc_address_t gl_get_proc_address(void *data, const char *sym)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
return gl->ctx_driver->get_proc_address(sym);
|
|
|
|
}
|
2013-03-11 23:00:42 +00:00
|
|
|
#endif
|
2013-03-10 19:12:50 +00:00
|
|
|
|
2013-03-10 00:16:56 +00:00
|
|
|
static void gl_set_aspect_ratio(void *data, unsigned aspectratio_index)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_AUTO)
|
|
|
|
gfx_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height);
|
|
|
|
else if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE)
|
|
|
|
gfx_set_core_viewport();
|
|
|
|
|
2013-03-17 21:05:15 +00:00
|
|
|
g_extern.system.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value;
|
2013-03-10 00:16:56 +00:00
|
|
|
g_settings.video.force_aspect = false;
|
|
|
|
gl->keep_aspect = true;
|
|
|
|
|
|
|
|
gl->should_resize = true;
|
|
|
|
}
|
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-04-07 12:05:39 +00:00
|
|
|
static void gl_set_texture_frame(void *data,
|
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (!gl->rgui_texture)
|
|
|
|
{
|
|
|
|
glGenTextures(1, &gl->rgui_texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->rgui_texture);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->border_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->border_type);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->rgui_texture);
|
|
|
|
|
|
|
|
gl->rgui_texture_alpha = alpha;
|
|
|
|
|
2013-04-07 16:03:25 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2013-04-07 12:05:39 +00:00
|
|
|
unsigned base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * base_size));
|
2013-04-07 16:03:25 +00:00
|
|
|
#endif
|
2013-04-07 12:05:39 +00:00
|
|
|
|
|
|
|
if (rgb32)
|
|
|
|
{
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
width, height,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
|
|
|
RARCH_GL_FORMAT32, frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, GL_RGBA, width, height, 0, GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_4_4_4_4, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
}
|
|
|
|
|
2013-04-13 14:48:03 +00:00
|
|
|
static void gl_set_texture_enable(void *data, bool state, bool full_screen)
|
2013-03-10 18:14:28 +00:00
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-04-07 12:05:39 +00:00
|
|
|
gl->rgui_texture_enable = state;
|
2013-04-13 14:48:03 +00:00
|
|
|
gl->rgui_texture_full_screen = full_screen;
|
2013-03-10 18:14:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-10 18:39:37 +00:00
|
|
|
static void gl_apply_state_changes(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
gl->should_resize = true;
|
|
|
|
}
|
|
|
|
|
2013-03-11 20:42:02 +00:00
|
|
|
static void gl_set_osd_msg(void *data, const char *msg, void *userdata)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
font_params_t *params = (font_params_t*)userdata;
|
|
|
|
|
|
|
|
if (gl->font_ctx)
|
|
|
|
gl->font_ctx->render_msg(gl, msg, params);
|
|
|
|
}
|
|
|
|
|
2013-03-29 17:53:07 +00:00
|
|
|
static void gl_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
if (gl->ctx_driver->show_mouse)
|
|
|
|
gl->ctx_driver->show_mouse(state);
|
|
|
|
}
|
|
|
|
|
2013-03-10 00:16:56 +00:00
|
|
|
static const video_poke_interface_t gl_poke_interface = {
|
|
|
|
gl_set_filtering,
|
2013-03-10 19:25:47 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-03-27 15:15:15 +00:00
|
|
|
gl_get_current_framebuffer,
|
2013-03-28 00:11:32 +00:00
|
|
|
gl_get_proc_address,
|
2013-03-10 19:25:47 +00:00
|
|
|
#endif
|
2013-03-10 00:16:56 +00:00
|
|
|
gl_set_aspect_ratio,
|
2013-03-10 18:39:37 +00:00
|
|
|
gl_apply_state_changes,
|
2013-04-07 16:03:25 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2013-04-07 12:05:39 +00:00
|
|
|
gl_set_texture_frame,
|
|
|
|
gl_set_texture_enable,
|
2013-03-10 18:14:28 +00:00
|
|
|
#endif
|
2013-03-11 20:42:02 +00:00
|
|
|
gl_set_osd_msg,
|
2013-03-29 17:53:07 +00:00
|
|
|
|
|
|
|
gl_show_mouse,
|
2013-03-10 00:16:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gl_get_poke_interface(void *data, const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &gl_poke_interface;
|
|
|
|
}
|
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
const video_driver_t video_gl = {
|
2012-05-27 20:50:03 +00:00
|
|
|
gl_init,
|
|
|
|
gl_frame,
|
|
|
|
gl_set_nonblock_state,
|
|
|
|
gl_alive,
|
|
|
|
gl_focus,
|
2012-05-27 21:16:22 +00:00
|
|
|
|
2013-01-02 14:05:55 +00:00
|
|
|
#if defined(HAVE_GLSL) || defined(HAVE_CG)
|
2012-09-21 19:20:30 +00:00
|
|
|
gl_set_shader,
|
2011-12-24 12:46:12 +00:00
|
|
|
#else
|
2012-05-27 20:50:03 +00:00
|
|
|
NULL,
|
2012-05-27 20:39:29 +00:00
|
|
|
#endif
|
2012-05-27 21:16:22 +00:00
|
|
|
|
2012-05-27 20:50:03 +00:00
|
|
|
gl_free,
|
|
|
|
"gl",
|
2012-05-27 21:16:22 +00:00
|
|
|
|
2013-03-24 00:00:00 +00:00
|
|
|
#if defined(HAVE_RGUI) || defined(HAVE_RMENU)
|
2012-05-27 20:50:03 +00:00
|
|
|
gl_start,
|
|
|
|
gl_stop,
|
|
|
|
gl_restart,
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
2012-05-27 21:16:22 +00:00
|
|
|
gl_set_rotation,
|
2012-06-08 22:24:43 +00:00
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifndef NO_GL_READ_VIEWPORT
|
2012-10-27 22:38:31 +00:00
|
|
|
gl_viewport_info,
|
2012-06-08 20:39:18 +00:00
|
|
|
gl_read_viewport,
|
2012-06-08 22:24:43 +00:00
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#endif
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_get_overlay_interface,
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2013-03-10 00:16:56 +00:00
|
|
|
gl_get_poke_interface,
|
2010-05-28 00:45:18 +00:00
|
|
|
};
|
2012-09-10 21:17:48 +00:00
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
|