2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2012-2014 - 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"
|
2014-05-28 19:14:11 +00:00
|
|
|
#include "image/image.h"
|
2013-08-14 12:00:21 +00:00
|
|
|
#include "../file.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
|
|
|
|
2012-10-16 17:43:05 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2014-10-01 22:45:11 +00:00
|
|
|
#include "shader/shader_glsl.h"
|
2010-11-12 22:09:43 +00:00
|
|
|
#endif
|
2010-11-12 21:32:38 +00:00
|
|
|
|
2014-10-02 11:21:45 +00:00
|
|
|
#include "shader/shader_context.h"
|
2012-11-14 22:11:48 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Used for the last pass when rendering to the back buffer. */
|
2013-06-30 20:24:07 +00:00
|
|
|
static const GLfloat vertexes_flipped[] = {
|
2012-09-13 15:48:17 +00:00
|
|
|
0, 1,
|
|
|
|
1, 1,
|
|
|
|
0, 0,
|
|
|
|
1, 0
|
|
|
|
};
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Used when rendering to an FBO.
|
|
|
|
* Texture coords have to be aligned
|
|
|
|
* with vertex coordinates. */
|
2012-09-13 15:48:17 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-06-30 20:24:07 +00:00
|
|
|
static const GLfloat white_color[] = {
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
};
|
|
|
|
|
2014-10-01 23:11:01 +00:00
|
|
|
static inline unsigned get_alignment(unsigned pitch)
|
|
|
|
{
|
|
|
|
if (pitch & 1)
|
|
|
|
return 1;
|
|
|
|
if (pitch & 2)
|
|
|
|
return 2;
|
|
|
|
if (pitch & 4)
|
|
|
|
return 4;
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2013-06-23 09:55:21 +00:00
|
|
|
static inline bool gl_query_extension(gl_t *gl, const char *ext)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (gl->core_context)
|
|
|
|
{
|
|
|
|
#ifdef GL_NUM_EXTENSIONS
|
2013-10-22 13:08:17 +00:00
|
|
|
GLint i, exts;
|
|
|
|
exts = 0;
|
2013-06-23 09:55:21 +00:00
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &exts);
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < exts; i++)
|
2013-06-23 09:55:21 +00:00
|
|
|
{
|
2013-07-05 16:36:40 +00:00
|
|
|
const char *str = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
2013-06-23 09:55:21 +00:00
|
|
|
if (str && strstr(str, ext))
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *str = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
ret = str && strstr(str, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("Querying GL extension: %s => %s\n",
|
|
|
|
ext, ret ? "exists" : "doesn't exist");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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,
|
2013-10-15 14:06:59 +00:00
|
|
|
unsigned image,
|
2012-12-20 10:16:22 +00:00
|
|
|
float x, float y, float w, float h);
|
|
|
|
static void gl_overlay_tex_geom(void *data,
|
2013-10-15 14:06:59 +00:00
|
|
|
unsigned image,
|
2012-12-20 10:16:22 +00:00
|
|
|
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
|
|
|
|
2014-10-01 22:35:01 +00:00
|
|
|
#define set_texture_coords(coords, xamt, yamt) \
|
|
|
|
coords[2] = xamt; \
|
|
|
|
coords[6] = xamt; \
|
|
|
|
coords[5] = yamt; \
|
|
|
|
coords[7] = yamt
|
2012-09-13 15:48:17 +00:00
|
|
|
|
2012-10-21 10:20:53 +00:00
|
|
|
#if defined(HAVE_EGL) && defined(HAVE_OPENGLES2)
|
2013-07-05 16:15:42 +00:00
|
|
|
static bool check_eglimage_proc(void)
|
2012-10-20 03:08:53 +00:00
|
|
|
{
|
2013-07-05 16:15:42 +00:00
|
|
|
return glEGLImageTargetTexture2DOES != NULL;
|
2012-10-20 03:08:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-03 12:04:29 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2013-07-05 17:47:33 +00:00
|
|
|
static bool check_sync_proc(gl_t *gl)
|
2013-05-03 12:04:29 +00:00
|
|
|
{
|
2013-07-05 17:47:33 +00:00
|
|
|
if (!gl_query_extension(gl, "ARB_sync"))
|
|
|
|
return false;
|
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
return glFenceSync && glDeleteSync && glClientWaitSync;
|
2013-05-03 12:04:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2013-07-05 16:15:42 +00:00
|
|
|
static bool init_vao(gl_t *gl)
|
2013-06-22 13:06:56 +00:00
|
|
|
{
|
2013-08-15 23:28:51 +00:00
|
|
|
if (!gl->core_context && !gl_query_extension(gl, "ARB_vertex_array_object"))
|
2013-07-05 17:47:33 +00:00
|
|
|
return false;
|
|
|
|
|
2014-05-28 22:30:48 +00:00
|
|
|
if (!(glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays))
|
2013-06-22 13:06:56 +00:00
|
|
|
return false;
|
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
glGenVertexArrays(1, &gl->vao);
|
2013-06-22 13:06:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-07-05 16:15:42 +00:00
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
#define glGenFramebuffers glGenFramebuffersOES
|
|
|
|
#define glBindFramebuffer glBindFramebufferOES
|
|
|
|
#define glFramebufferTexture2D glFramebufferTexture2DOES
|
|
|
|
#define glCheckFramebufferStatus glCheckFramebufferStatusOES
|
|
|
|
#define glDeleteFramebuffers glDeleteFramebuffersOES
|
|
|
|
#define glGenRenderbuffers glGenRenderbuffersOES
|
|
|
|
#define glBindRenderbuffer glBindRenderbufferOES
|
|
|
|
#define glFramebufferRenderbuffer glFramebufferRenderbufferOES
|
|
|
|
#define glRenderbufferStorage glRenderbufferStorageOES
|
|
|
|
#define glDeleteRenderbuffers glDeleteRenderbuffersOES
|
2013-07-05 17:47:33 +00:00
|
|
|
#define check_fbo_proc(gl) (true)
|
2013-07-05 16:15:42 +00:00
|
|
|
#elif !defined(HAVE_OPENGLES2)
|
2013-07-05 17:47:33 +00:00
|
|
|
static bool check_fbo_proc(gl_t *gl)
|
2011-05-18 20:40:42 +00:00
|
|
|
{
|
2013-08-15 23:28:51 +00:00
|
|
|
if (!gl->core_context && !gl_query_extension(gl, "ARB_framebuffer_object"))
|
2013-07-05 17:47:33 +00:00
|
|
|
return false;
|
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
return glGenFramebuffers && glBindFramebuffer && glFramebufferTexture2D &&
|
|
|
|
glCheckFramebufferStatus && glDeleteFramebuffers &&
|
|
|
|
glGenRenderbuffers && glBindRenderbuffer &&
|
|
|
|
glFramebufferRenderbuffer && glRenderbufferStorage &&
|
|
|
|
glDeleteRenderbuffers;
|
2011-05-18 20:40:42 +00:00
|
|
|
}
|
|
|
|
#else
|
2013-07-05 17:47:33 +00:00
|
|
|
#define check_fbo_proc(gl) (true)
|
2011-05-18 20:40:42 +00:00
|
|
|
#endif
|
2013-07-05 16:15:42 +00:00
|
|
|
#endif
|
2013-03-29 00:23:30 +00:00
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Shaders */
|
2012-09-15 13:37:08 +00:00
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static bool gl_shader_init(gl_t *gl)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2014-10-02 09:11:34 +00:00
|
|
|
enum rarch_shader_type type;
|
2014-09-13 02:41:30 +00:00
|
|
|
bool ret = false;
|
2014-10-02 11:47:45 +00:00
|
|
|
const shader_backend_t *backend = NULL;
|
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;
|
2013-06-23 09:55:21 +00:00
|
|
|
|
2014-09-12 02:59:52 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
{
|
2014-09-13 23:49:24 +00:00
|
|
|
RARCH_ERR("Invalid GL instance passed.\n");
|
2014-09-12 02:59:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = gfx_shader_parse_type(shader_path,
|
|
|
|
gl->core_context ? RARCH_SHADER_GLSL : DEFAULT_SHADER_TYPE);
|
2013-04-07 11:08:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-08-11 13:25:04 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2013-06-30 20:58:22 +00:00
|
|
|
if (gl->core_context && RARCH_SHADER_CG)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Cg cannot be used with core GL context. Falling back to GLSL.\n");
|
|
|
|
backend = &gl_glsl_backend;
|
|
|
|
shader_path = NULL;
|
|
|
|
}
|
2013-08-11 13:25:04 +00:00
|
|
|
#endif
|
2013-06-30 20:58:22 +00:00
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
gl->shader = backend;
|
2014-05-27 19:55:54 +00:00
|
|
|
|
|
|
|
if (gl->shader && gl->shader->init)
|
2014-09-13 02:41:30 +00:00
|
|
|
{
|
2014-05-27 19:55:54 +00:00
|
|
|
ret = gl->shader->init(gl, shader_path);
|
|
|
|
|
2014-09-13 02:41:30 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Failed to init shader, falling back to stock.\n");
|
|
|
|
ret = gl->shader->init(gl, NULL);
|
|
|
|
}
|
2013-06-05 08:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
static void gl_shader_deinit(gl_t *gl)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
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
|
2013-06-23 09:55:21 +00:00
|
|
|
static void gl_disable_client_arrays(gl_t *gl)
|
2013-04-06 09:26:06 +00:00
|
|
|
{
|
2014-05-27 19:55:54 +00:00
|
|
|
if (!gl || gl->core_context)
|
2013-06-23 09:55:21 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
glClientActiveTexture(GL_TEXTURE1);
|
2013-04-06 09:26:06 +00:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2013-07-05 16:15:42 +00:00
|
|
|
glClientActiveTexture(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
|
|
|
|
2013-05-13 17:33:47 +00:00
|
|
|
#ifdef IOS
|
2014-10-01 21:50:58 +00:00
|
|
|
/* There is no default frame buffer on iOS. */
|
2013-07-05 02:10:05 +00:00
|
|
|
void apple_bind_game_view_fbo(void);
|
|
|
|
#define gl_bind_backbuffer() apple_bind_game_view_fbo()
|
2013-05-13 17:33:47 +00:00
|
|
|
#else
|
2014-05-22 18:23:02 +00:00
|
|
|
#define gl_bind_backbuffer() glBindFramebuffer(RARCH_GL_FRAMEBUFFER, 0)
|
2013-05-13 17:33:47 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-24 23:39:48 +00:00
|
|
|
static inline GLenum min_filter_to_mag(GLenum type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GL_LINEAR_MIPMAP_LINEAR:
|
|
|
|
return GL_LINEAR;
|
|
|
|
case GL_NEAREST_MIPMAP_NEAREST:
|
|
|
|
return GL_NEAREST;
|
|
|
|
default:
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_shader_scale(gl_t *gl, unsigned index, struct gfx_fbo_scale *scale)
|
2011-03-14 20:28:30 +00:00
|
|
|
{
|
2011-03-14 21:51:03 +00:00
|
|
|
scale->valid = false;
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->shader->shader_scale(index, scale);
|
2011-03-14 20:28:30 +00:00
|
|
|
}
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Compute FBO geometry.
|
|
|
|
* When width/height changes or window sizes change,
|
|
|
|
* we have to recalculate geometry of our FBO. */
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height,
|
2012-08-10 04:50:41 +00:00
|
|
|
unsigned vp_width, unsigned vp_height)
|
|
|
|
{
|
2013-11-16 12:56:50 +00:00
|
|
|
int i;
|
2014-10-01 18:06:40 +00:00
|
|
|
bool size_modified = false;
|
2012-10-23 06:28:02 +00:00
|
|
|
GLint max_size = 0;
|
2014-10-01 18:06:40 +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 02:03:00 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
|
2012-10-23 06:28:02 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Calculate viewports for FBOs. */
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->fbo_pass; i++)
|
2012-08-10 04:50:41 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-10-01 23:02:13 +00:00
|
|
|
static unsigned gl_wrap_type_to_enum(enum gfx_wrap_type type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
case RARCH_WRAP_BORDER:
|
|
|
|
return GL_CLAMP_TO_BORDER;
|
|
|
|
#else
|
|
|
|
case RARCH_WRAP_BORDER:
|
|
|
|
#endif
|
|
|
|
case RARCH_WRAP_EDGE:
|
|
|
|
return GL_CLAMP_TO_EDGE;
|
|
|
|
case RARCH_WRAP_REPEAT:
|
|
|
|
return GL_REPEAT;
|
|
|
|
case RARCH_WRAP_MIRRORED_REPEAT:
|
|
|
|
return GL_MIRRORED_REPEAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_create_fbo_textures(gl_t *gl)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
int i;
|
2014-10-01 17:34:55 +00:00
|
|
|
GLuint base_filt = g_settings.video.smooth ? GL_LINEAR : GL_NEAREST;
|
|
|
|
GLuint base_mip_filt = g_settings.video.smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST;
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2014-10-02 08:45:20 +00:00
|
|
|
glGenTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->fbo_pass; i++)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]);
|
2012-09-10 08:29:50 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
bool mipmapped = gl->shader->mipmap_input(i + 2);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
|
|
|
GLenum min_filter = mipmapped ? base_mip_filt : base_filt;
|
2012-05-27 16:40:07 +00:00
|
|
|
bool smooth = false;
|
2014-10-02 12:05:11 +00:00
|
|
|
if (gl->shader->filter_type(i + 2, &smooth))
|
|
|
|
min_filter = mipmapped ? (smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
|
|
|
: (smooth ? GL_LINEAR : GL_NEAREST);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
|
|
|
GLenum mag_filter = min_filter_to_mag(min_filter);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
enum gfx_wrap_type wrap = gl->shader->wrap_type(i + 2);
|
2013-08-15 22:30:54 +00:00
|
|
|
GLenum wrap_enum = gl_wrap_type_to_enum(wrap);
|
|
|
|
|
2014-05-11 11:13:38 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
2013-08-15 22:30:54 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_enum);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_enum);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-05-11 17:35:54 +00:00
|
|
|
bool fp_fbo = gl->fbo_scale[i].fp_fbo;
|
|
|
|
bool srgb_fbo = gl->fbo_scale[i].srgb_fbo;
|
2013-03-25 15:42:41 +00:00
|
|
|
|
2014-05-31 04:55:08 +00:00
|
|
|
if (fp_fbo)
|
2014-05-11 11:13:38 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
if (!gl->has_fp_fbo)
|
|
|
|
RARCH_ERR("[GL]: Floating-point FBO was requested, but is not supported. Falling back to UNORM. Result may band/clip/etc.!\n");
|
2014-05-11 11:13:38 +00:00
|
|
|
}
|
2014-05-31 04:55:08 +00:00
|
|
|
else if (srgb_fbo)
|
2014-05-11 11:13:38 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
if (!gl->has_srgb_fbo)
|
|
|
|
RARCH_ERR("[GL]: sRGB FBO was requested, but it is not supported. Falling back to UNORM. Result may have banding!\n");
|
2014-05-11 11:13:38 +00:00
|
|
|
}
|
2013-12-04 11:55:51 +00:00
|
|
|
|
2014-09-21 03:23:51 +00:00
|
|
|
if (g_settings.video.force_srgb_disable)
|
|
|
|
srgb_fbo = false;
|
|
|
|
|
2014-05-31 04:55:08 +00:00
|
|
|
#ifndef HAVE_OPENGLES2
|
|
|
|
if (fp_fbo && gl->has_fp_fbo)
|
2013-03-25 15:42:41 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
RARCH_LOG("[GL]: 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_FLOAT, NULL);
|
2013-03-25 15:42:41 +00:00
|
|
|
}
|
|
|
|
else
|
2014-05-31 04:55:08 +00:00
|
|
|
#endif
|
2013-03-25 15:42:41 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
if (srgb_fbo && gl->has_srgb_fbo)
|
2014-05-11 11:13:38 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
RARCH_LOG("[GL]: FBO pass #%d is sRGB.\n", i);
|
|
|
|
#ifdef HAVE_OPENGLES2
|
2014-10-01 21:50:58 +00:00
|
|
|
/* EXT defines are same as core GLES3 defines,
|
|
|
|
* but GLES3 variant requires different arguments. */
|
2014-05-31 04:55:08 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, GL_SRGB_ALPHA_EXT,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0,
|
2014-06-05 15:41:10 +00:00
|
|
|
gl->has_srgb_fbo_gles3 ? GL_RGBA : GL_SRGB_ALPHA_EXT,
|
|
|
|
GL_UNSIGNED_BYTE, NULL);
|
2014-05-31 04:55:08 +00:00
|
|
|
#else
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, GL_SRGB8_ALPHA8,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
#endif
|
2014-05-11 11:13:38 +00:00
|
|
|
}
|
|
|
|
else
|
2014-05-31 04:55:08 +00:00
|
|
|
#endif
|
2014-05-11 11:13:38 +00:00
|
|
|
{
|
2014-05-31 04:55:08 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
2014-05-11 11:13:38 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, GL_RGBA,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2014-05-31 04:55:08 +00:00
|
|
|
#else
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Avoid potential performance
|
|
|
|
* reductions on particular platforms. */
|
2014-05-11 11:13:38 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0,
|
|
|
|
RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, NULL);
|
2014-05-31 04:55:08 +00:00
|
|
|
#endif
|
2014-05-11 11:13:38 +00:00
|
|
|
}
|
2013-03-25 15:42:41 +00:00
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static bool gl_create_fbo_targets(gl_t *gl)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
int i;
|
2014-05-28 22:30:48 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2012-12-10 12:18:10 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2013-07-05 16:15:42 +00:00
|
|
|
glGenFramebuffers(gl->fbo_pass, gl->fbo);
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->fbo_pass; i++)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2014-05-22 18:23:02 +00:00
|
|
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[i]);
|
2014-10-01 21:50:58 +00:00
|
|
|
glFramebufferTexture2D(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-05-22 18:23:02 +00:00
|
|
|
GLenum status = glCheckFramebufferStatus(RARCH_GL_FRAMEBUFFER);
|
2014-05-22 18:32:51 +00:00
|
|
|
if (status != RARCH_GL_FRAMEBUFFER_COMPLETE)
|
2012-01-31 23:14:04 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2013-07-05 16:15:42 +00:00
|
|
|
glDeleteFramebuffers(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;
|
|
|
|
}
|
|
|
|
|
2014-10-02 10:55:19 +00:00
|
|
|
static void gl_deinit_fbo(gl_t *gl)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2014-10-01 21:53:18 +00:00
|
|
|
if (!gl->fbo_inited)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glDeleteTextures(gl->fbo_pass, gl->fbo_texture);
|
|
|
|
glDeleteFramebuffers(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;
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Set up render to texture. */
|
|
|
|
|
2014-10-02 10:14:12 +00:00
|
|
|
static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
int i;
|
2013-01-03 02:02:52 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
if (!gl || gl->shader->num_shaders() == 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);
|
2014-10-02 12:05:11 +00:00
|
|
|
gl_shader_scale(gl, gl->shader->num_shaders(), &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 */
|
2014-10-02 12:05:11 +00:00
|
|
|
if (gl->shader->num_shaders() == 1 && !scale.valid)
|
2011-03-06 18:56:35 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-05 17:47:33 +00:00
|
|
|
if (!check_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
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->fbo_pass = gl->shader->num_shaders() - 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
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (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;
|
2014-10-01 21:50:58 +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
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (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);
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: Creating FBO %d @ %ux%u\n", i,
|
2014-10-01 21:50:58 +00:00
|
|
|
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
|
|
|
|
2014-02-25 21:01:46 +00:00
|
|
|
#ifndef HAVE_GCMGL
|
2013-07-06 20:10:09 +00:00
|
|
|
static void gl_deinit_hw_render(gl_t *gl)
|
|
|
|
{
|
2014-05-28 22:30:48 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
glDeleteFramebuffers(gl->textures, gl->hw_render_fbo);
|
|
|
|
if (gl->hw_render_depth_init)
|
|
|
|
glDeleteRenderbuffers(gl->textures, gl->hw_render_depth);
|
|
|
|
gl->hw_render_fbo_init = false;
|
2014-04-19 13:37:00 +00:00
|
|
|
|
|
|
|
context_bind_hw_render(gl, false);
|
2013-07-06 20:10:09 +00:00
|
|
|
}
|
2013-05-18 19:53:26 +00:00
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
static bool gl_init_hw_render(gl_t *gl, unsigned width, unsigned height)
|
2013-03-27 15:15:15 +00:00
|
|
|
{
|
2014-10-01 18:06:40 +00:00
|
|
|
unsigned i;
|
|
|
|
bool depth = false, stencil = false;
|
|
|
|
GLint max_fbo_size = 0, max_renderbuffer_size = 0;
|
|
|
|
|
|
|
|
/* We can only share texture objects through contexts.
|
|
|
|
* FBOs are "abstract" objects and are not shared. */
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
RARCH_LOG("[GL]: Initializing HW render (%u x %u).\n", width, height);
|
2013-05-18 19:53:26 +00:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_fbo_size);
|
2014-05-22 19:00:17 +00:00
|
|
|
glGetIntegerv(RARCH_GL_MAX_RENDERBUFFER_SIZE, &max_renderbuffer_size);
|
2014-10-01 21:50:58 +00:00
|
|
|
RARCH_LOG("[GL]: Max texture size: %d px, renderbuffer size: %u px.\n",
|
|
|
|
max_fbo_size, max_renderbuffer_size);
|
2013-03-27 15:15:15 +00:00
|
|
|
|
2013-07-05 17:47:33 +00:00
|
|
|
if (!check_fbo_proc(gl))
|
2013-03-29 01:12:08 +00:00
|
|
|
return false;
|
|
|
|
|
2013-03-27 15:15:15 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2013-07-06 20:10:09 +00:00
|
|
|
glGenFramebuffers(gl->textures, gl->hw_render_fbo);
|
2013-03-27 15:15:15 +00:00
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
depth = g_extern.system.hw_render_callback.depth;
|
|
|
|
stencil = g_extern.system.hw_render_callback.stencil;
|
2013-06-22 13:06:56 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENGLES2
|
2013-06-23 09:55:21 +00:00
|
|
|
if (stencil && !gl_query_extension(gl, "OES_packed_depth_stencil"))
|
2013-06-22 13:06:56 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
2013-03-29 01:50:42 +00:00
|
|
|
|
|
|
|
if (depth)
|
|
|
|
{
|
2013-07-06 20:10:09 +00:00
|
|
|
glGenRenderbuffers(gl->textures, gl->hw_render_depth);
|
2013-03-29 01:50:42 +00:00
|
|
|
gl->hw_render_depth_init = true;
|
|
|
|
}
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->textures; i++)
|
2013-03-27 15:15:15 +00:00
|
|
|
{
|
2014-05-22 18:23:02 +00:00
|
|
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->hw_render_fbo[i]);
|
2014-10-01 21:50:58 +00:00
|
|
|
glFramebufferTexture2D(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->texture[i], 0);
|
2013-03-29 01:50:42 +00:00
|
|
|
|
|
|
|
if (depth)
|
|
|
|
{
|
2014-05-22 19:24:38 +00:00
|
|
|
glBindRenderbuffer(RARCH_GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
2014-10-01 21:50:58 +00:00
|
|
|
glRenderbufferStorage(RARCH_GL_RENDERBUFFER,
|
|
|
|
stencil ? RARCH_GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT16,
|
2014-05-22 19:26:57 +00:00
|
|
|
width, height);
|
|
|
|
glBindRenderbuffer(RARCH_GL_RENDERBUFFER, 0);
|
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
if (stencil)
|
|
|
|
{
|
2014-05-27 20:15:25 +00:00
|
|
|
#if defined(HAVE_OPENGLES2) || defined(HAVE_OPENGLES1) || defined(OSX_PPC)
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GLES2 is a bit weird, as always.
|
|
|
|
* There's no GL_DEPTH_STENCIL_ATTACHMENT like in desktop GL. */
|
|
|
|
glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_DEPTH_ATTACHMENT,
|
2014-05-22 18:44:33 +00:00
|
|
|
RARCH_GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
2014-10-01 21:50:58 +00:00
|
|
|
glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_STENCIL_ATTACHMENT,
|
2014-05-22 18:44:33 +00:00
|
|
|
RARCH_GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
2013-06-22 13:06:56 +00:00
|
|
|
#else
|
2014-10-01 21:50:58 +00:00
|
|
|
/* We use ARB FBO extensions, no need to check. */
|
|
|
|
glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER,
|
|
|
|
GL_DEPTH_STENCIL_ATTACHMENT,
|
2014-05-22 18:44:33 +00:00
|
|
|
RARCH_GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
glFramebufferRenderbuffer(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_DEPTH_ATTACHMENT,
|
2014-05-22 18:44:33 +00:00
|
|
|
RARCH_GL_RENDERBUFFER, gl->hw_render_depth[i]);
|
2013-06-22 13:06:56 +00:00
|
|
|
}
|
2013-03-29 01:50:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:23:02 +00:00
|
|
|
GLenum status = glCheckFramebufferStatus(RARCH_GL_FRAMEBUFFER);
|
2014-05-22 18:32:51 +00:00
|
|
|
if (status != RARCH_GL_FRAMEBUFFER_COMPLETE)
|
2013-03-29 01:12:08 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to create HW render FBO #%u, error: 0x%u.\n",
|
|
|
|
i, (unsigned)status);
|
2013-03-29 01:12:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 17:33:47 +00:00
|
|
|
gl_bind_backbuffer();
|
2013-03-27 15:15:15 +00:00
|
|
|
gl->hw_render_fbo_init = true;
|
2014-04-19 13:37:00 +00:00
|
|
|
|
|
|
|
context_bind_hw_render(gl, false);
|
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
|
|
|
|
2014-10-02 10:57:01 +00:00
|
|
|
static void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate)
|
2011-03-20 01:10:02 +00:00
|
|
|
{
|
2014-10-01 17:34:55 +00:00
|
|
|
math_matrix rot;
|
|
|
|
|
2014-10-01 21:50:58 +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);
|
|
|
|
|
2014-10-01 17:34:55 +00:00
|
|
|
if (!allow_rotate)
|
2012-09-24 20:51:26 +00:00
|
|
|
{
|
2012-12-23 23:21:42 +00:00
|
|
|
gl->mvp = gl->mvp_no_rot;
|
2014-10-01 17:34:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
matrix_rotate_z(&rot, M_PI * gl->rotation / 180.0f);
|
|
|
|
matrix_multiply(&gl->mvp, &rot, &gl->mvp_no_rot);
|
2012-04-01 17:20:37 +00:00
|
|
|
}
|
2011-03-20 01:10:02 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
void gl_set_viewport(gl_t *gl, unsigned width,
|
|
|
|
unsigned height, bool force_full, bool allow_rotate)
|
2012-04-01 17:20:37 +00:00
|
|
|
{
|
2014-10-02 08:21:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-10-01 14:59:43 +00:00
|
|
|
int x = 0, y = 0;
|
|
|
|
float device_aspect = (float)width / height;
|
2012-06-08 20:39:18 +00:00
|
|
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
if (ctx_driver->translate_aspect)
|
|
|
|
device_aspect = ctx_driver->translate_aspect(gl, width, height);
|
2013-01-24 23:17:07 +00:00
|
|
|
|
2013-01-29 18:28:33 +00:00
|
|
|
if (g_settings.video.scale_integer && !force_full)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
gfx_scale_integer(&gl->vp, width, height,
|
|
|
|
g_extern.system.aspect_ratio, gl->keep_aspect);
|
2013-04-18 06:57:38 +00:00
|
|
|
width = gl->vp.width;
|
|
|
|
height = gl->vp.height;
|
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-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
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
|
|
|
{
|
2013-04-20 08:56:04 +00:00
|
|
|
const struct rarch_viewport *custom =
|
2014-10-01 21:50:58 +00:00
|
|
|
(const struct rarch_viewport*)
|
2013-04-20 08:56:04 +00:00
|
|
|
&g_extern.console.screen.viewports.custom_vp;
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GL has bottom-left origin viewport. */
|
2013-04-20 08:56:04 +00:00
|
|
|
x = custom->x;
|
|
|
|
y = gl->win_height - custom->y - custom->height;
|
|
|
|
width = custom->width;
|
|
|
|
height = custom->height;
|
2012-05-27 20:39:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2013-09-12 20:23:56 +00:00
|
|
|
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
2012-05-27 21:14:46 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* If the aspect ratios of screen and desired aspect
|
|
|
|
* ratio are sufficiently equal (floating point stuff),
|
|
|
|
* assume they are actually equal.
|
|
|
|
*/
|
2012-05-27 21:14:46 +00:00
|
|
|
}
|
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
2013-09-12 20:23:56 +00:00
|
|
|
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
x = (int)roundf(width * (0.5f - delta));
|
|
|
|
width = (unsigned)roundf(2.0f * width * delta);
|
2012-05-27 21:14:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-12 20:23:56 +00:00
|
|
|
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
y = (int)roundf(height * (0.5f - delta));
|
|
|
|
height = (unsigned)roundf(2.0f * height * delta);
|
2012-05-27 21:14:46 +00:00
|
|
|
}
|
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-05-22 14:02:21 +00:00
|
|
|
#if defined(RARCH_MOBILE)
|
2014-10-01 21:50:58 +00:00
|
|
|
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
2013-01-24 23:20:55 +00:00
|
|
|
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
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Set last backbuffer viewport. */
|
2011-03-27 18:29:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
#if 0
|
|
|
|
RARCH_LOG("Setting viewport @ %ux%u\n", width, height);
|
|
|
|
#endif
|
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
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->rotation = 90 * rotation;
|
|
|
|
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
|
2014-05-11 11:13:38 +00:00
|
|
|
static inline void gl_start_frame_fbo(gl_t *gl)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2011-07-03 13:39:35 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2014-05-22 18:23:02 +00:00
|
|
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[0]);
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2014-10-01 17:34:55 +00:00
|
|
|
gl_set_viewport(gl, gl->fbo_rect[0].img_width,
|
|
|
|
gl->fbo_rect[0].img_height, true, false);
|
|
|
|
|
|
|
|
/* 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;
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2014-05-11 12:57:35 +00:00
|
|
|
#if defined(GL_FRAMEBUFFER_SRGB) && !defined(HAVE_OPENGLES)
|
2014-05-11 11:13:38 +00:00
|
|
|
if (gl->has_srgb_fbo)
|
|
|
|
glEnable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
#endif
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* On resize, we might have to recreate our FBOs
|
|
|
|
* due to "Viewport" scale, and set a new viewport. */
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_check_fbo_dimensions(gl_t *gl)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
int i;
|
2014-05-28 22:30:48 +00:00
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Check if we have to recreate our FBO textures. */
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->fbo_pass; i++)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-01-31 23:14:04 +00:00
|
|
|
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
|
|
|
{
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Check proactively since we might suddently
|
|
|
|
* get sizes of tex_w width or tex_h height. */
|
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);
|
2014-10-01 14:59:43 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->fbo_rect[i].width = gl->fbo_rect[i].height = pow2_size;
|
|
|
|
|
2014-05-22 18:23:02 +00:00
|
|
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[i]);
|
2012-01-31 23:14:04 +00:00
|
|
|
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,
|
2014-10-01 18:06:40 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
gl->fbo_rect[i].width,
|
|
|
|
gl->fbo_rect[i].height,
|
2012-10-19 23:12:02 +00:00
|
|
|
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
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
glFramebufferTexture2D(RARCH_GL_FRAMEBUFFER,
|
|
|
|
RARCH_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
|
|
|
gl->fbo_texture[i], 0);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-05-22 18:23:02 +00:00
|
|
|
GLenum status = glCheckFramebufferStatus(RARCH_GL_FRAMEBUFFER);
|
2014-05-22 18:32:51 +00:00
|
|
|
if (status != RARCH_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
|
|
|
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: Recreating FBO texture #%d: %ux%u\n",
|
2014-10-01 18:06:40 +00:00
|
|
|
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
|
|
|
|
2014-10-02 09:11:34 +00:00
|
|
|
static void gl_frame_fbo(gl_t *gl, shader_backend_t *shader,
|
2014-10-02 08:45:20 +00:00
|
|
|
const struct gl_tex_info *tex_info)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
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];
|
2013-11-16 12:56:50 +00:00
|
|
|
int i;
|
2014-10-01 14:59:43 +00:00
|
|
|
GLfloat xamt, yamt;
|
|
|
|
unsigned fbo_tex_info_cnt = 0;
|
2012-01-31 23:14:04 +00:00
|
|
|
GLfloat fbo_tex_coords[8] = {0.0f};
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* 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
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Calculate viewports, texture coordinates etc,
|
|
|
|
* and render all passes from FBOs, to another FBO. */
|
2013-10-22 13:08:17 +00:00
|
|
|
for (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];
|
2014-10-01 18:06:40 +00:00
|
|
|
rect = &gl->fbo_rect[i];
|
|
|
|
fbo_info = &fbo_tex_info[i - 1];
|
2011-09-11 13:33:28 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
xamt = (GLfloat)prev_rect->img_width / prev_rect->width;
|
|
|
|
yamt = (GLfloat)prev_rect->img_height / prev_rect->height;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
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));
|
2014-05-23 13:02:12 +00:00
|
|
|
fbo_tex_info_cnt++;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-05-22 18:23:02 +00:00
|
|
|
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[i]);
|
2013-04-13 07:01:25 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->use(gl, i + 1);
|
2012-01-31 23:14:04 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]);
|
|
|
|
|
2014-10-03 12:16:34 +00:00
|
|
|
if (shader->mipmap_input(i + 1))
|
2014-05-11 11:13:38 +00:00
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* 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);
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->set_params(gl, 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);
|
|
|
|
|
2014-06-08 10:37:32 +00:00
|
|
|
gl->coords.vertices = 4;
|
2014-10-02 13:17:21 +00:00
|
|
|
shader->set_coords(&gl->coords);
|
|
|
|
shader->set_mvp(gl, &gl->mvp);
|
2012-09-13 18:47:49 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 12:57:35 +00:00
|
|
|
#if defined(GL_FRAMEBUFFER_SRGB) && !defined(HAVE_OPENGLES)
|
2014-05-11 11:13:38 +00:00
|
|
|
if (gl->has_srgb_fbo)
|
|
|
|
glDisable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Render our last FBO texture directly to screen. */
|
2012-01-31 23:14:04 +00:00
|
|
|
prev_rect = &gl->fbo_rect[gl->fbo_pass - 1];
|
2014-10-01 14:59:43 +00:00
|
|
|
xamt = (GLfloat)prev_rect->img_width / prev_rect->width;
|
|
|
|
yamt = (GLfloat)prev_rect->img_height / prev_rect->height;
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
set_texture_coords(fbo_tex_coords, xamt, yamt);
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Push final FBO to list. */
|
2014-05-23 13:02:12 +00:00
|
|
|
fbo_info = &fbo_tex_info[gl->fbo_pass - 1];
|
|
|
|
fbo_info->tex = gl->fbo_texture[gl->fbo_pass - 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));
|
|
|
|
fbo_tex_info_cnt++;
|
|
|
|
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Render our FBO texture to back buffer. */
|
2013-05-13 17:33:47 +00:00
|
|
|
gl_bind_backbuffer();
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->use(gl, gl->fbo_pass + 1);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]);
|
|
|
|
|
2014-10-03 12:16:34 +00:00
|
|
|
if (shader->mipmap_input(gl->fbo_pass + 1))
|
2014-05-11 11:13:38 +00:00
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
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
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->set_params(gl, 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-06-30 20:24:07 +00:00
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
2012-08-14 21:32:55 +00:00
|
|
|
|
2014-06-08 10:37:32 +00:00
|
|
|
gl->coords.vertices = 4;
|
2014-10-02 13:17:21 +00:00
|
|
|
shader->set_coords(&gl->coords);
|
|
|
|
shader->set_mvp(gl, &gl->mvp);
|
2012-09-13 18:47:49 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2014-10-01 21:53:18 +00:00
|
|
|
static void gl_update_input_size(gl_t *gl, unsigned width,
|
|
|
|
unsigned height, unsigned pitch, bool clear)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
bool set_coords = false;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Resolution change. Need to clear out texture. */
|
|
|
|
|
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)
|
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,
|
|
|
|
get_alignment(width * sizeof(uint32_t)));
|
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
|
|
|
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
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
set_coords = true;
|
2010-12-26 03:15:12 +00:00
|
|
|
}
|
2014-10-01 14:59:43 +00:00
|
|
|
else if ((width !=
|
|
|
|
gl->last_width[(gl->tex_index + gl->textures - 1) % gl->textures]) ||
|
|
|
|
(height !=
|
|
|
|
gl->last_height[(gl->tex_index + gl->textures - 1) % gl->textures]))
|
2014-10-01 21:50:58 +00:00
|
|
|
{
|
|
|
|
/* We might have used different texture coordinates
|
|
|
|
* last frame. Edge case if resolution changes very rapidly. */
|
2014-10-01 14:59:43 +00:00
|
|
|
set_coords = true;
|
2014-10-01 21:50:58 +00:00
|
|
|
}
|
2014-10-01 14:59:43 +00:00
|
|
|
|
|
|
|
if (set_coords)
|
2011-07-03 13:39:35 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
GLfloat xamt = (GLfloat)width / gl->tex_w;
|
2011-07-03 13:39:35 +00:00
|
|
|
GLfloat yamt = (GLfloat)height / gl->tex_h;
|
2014-10-01 18:37:52 +00:00
|
|
|
set_texture_coords(gl->tex_info.coord, xamt, yamt);
|
2011-07-03 13:39:35 +00:00
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-06-01 10:19:48 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* It is *much* faster (order of magnitude 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)
|
2014-10-01 21:50:58 +00:00
|
|
|
static inline void gl_convert_frame_rgb16_32(gl_t *gl, void *output,
|
|
|
|
const void *input, int width, int height, int in_pitch)
|
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
|
2014-10-01 21:50:58 +00:00
|
|
|
static inline void gl_convert_frame_argb8888_abgr8888(gl_t *gl,
|
|
|
|
void *output, const void *input,
|
2013-01-03 00:18:19 +00:00
|
|
|
int width, int height, int in_pitch)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_init_textures_data(gl_t *gl)
|
2012-11-18 13:21:47 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < gl->textures; i++)
|
2012-11-18 13:21:47 +00:00
|
|
|
{
|
|
|
|
gl->last_width[i] = gl->tex_w;
|
|
|
|
gl->last_height[i] = gl->tex_h;
|
|
|
|
}
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->textures; i++)
|
2012-11-18 13:21:47 +00:00
|
|
|
{
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_init_textures(gl_t *gl, const video_info_t *video)
|
2012-05-26 14:01:59 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned i;
|
2013-04-06 16:40:50 +00:00
|
|
|
#if defined(HAVE_EGL) && defined(HAVE_OPENGLES2)
|
2013-05-18 13:51:36 +00:00
|
|
|
// Use regular textures if we use HW render.
|
2014-03-09 15:50:18 +00:00
|
|
|
gl->egl_images = !gl->hw_render_use && check_eglimage_proc() &&
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->ctx_driver->init_egl_image_buffer
|
2014-10-02 13:43:11 +00:00
|
|
|
&& gl->ctx_driver->init_egl_image_buffer(gl, video);
|
2013-04-06 16:40:50 +00:00
|
|
|
#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,
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->tex_w * gl->tex_h * gl->base_size * gl->textures, NULL, GL_STREAM_DRAW);
|
2013-04-06 16:40:50 +00:00
|
|
|
#endif
|
2012-11-10 22:56:04 +00:00
|
|
|
|
2013-05-18 19:53:26 +00:00
|
|
|
GLenum internal_fmt = gl->internal_fmt;
|
2013-05-25 22:32:39 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2013-05-18 19:53:26 +00:00
|
|
|
GLenum texture_type = gl->texture_type;
|
|
|
|
GLenum texture_fmt = gl->texture_fmt;
|
2013-05-25 22:32:39 +00:00
|
|
|
#endif
|
2013-05-18 19:53:26 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENGLES2
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GLES is picky about which format we use here.
|
|
|
|
* Without extensions, we can *only* render to 16-bit FBOs. */
|
|
|
|
|
2013-05-18 19:53:26 +00:00
|
|
|
if (gl->hw_render_use && gl->base_size == sizeof(uint32_t))
|
|
|
|
{
|
2014-10-01 21:53:18 +00:00
|
|
|
bool support_argb = gl_query_extension(gl, "OES_rgb8_rgba8")
|
|
|
|
|| gl_query_extension(gl, "ARM_argb8");
|
|
|
|
|
2013-05-18 19:53:26 +00:00
|
|
|
if (support_argb)
|
|
|
|
{
|
|
|
|
internal_fmt = GL_RGBA;
|
|
|
|
texture_type = GL_RGBA;
|
|
|
|
texture_fmt = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_WARN("[GL]: 32-bit FBO not supported. Falling back to 16-bit.\n");
|
|
|
|
internal_fmt = GL_RGB;
|
|
|
|
texture_type = GL_RGB;
|
|
|
|
texture_fmt = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
glGenTextures(gl->textures, gl->texture);
|
2012-05-26 14:01:59 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->textures; i++)
|
2012-05-26 14:01:59 +00:00
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
|
2013-08-15 22:30:54 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->wrap_mode);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->wrap_mode);
|
2014-05-11 11:13:38 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_min_filter);
|
2012-05-26 14:01:59 +00:00
|
|
|
|
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,
|
2013-05-18 19:53:26 +00:00
|
|
|
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,
|
2013-05-18 19:53:26 +00:00
|
|
|
0, internal_fmt, gl->tex_w, gl->tex_h, 0, texture_type,
|
|
|
|
texture_fmt, gl->empty_buf ? gl->empty_buf : NULL);
|
2013-04-06 16:40:50 +00:00
|
|
|
}
|
|
|
|
#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
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static inline void gl_copy_frame(gl_t *gl, const void *frame,
|
|
|
|
unsigned width, unsigned height, unsigned pitch)
|
2012-09-10 09:12:57 +00:00
|
|
|
{
|
2014-10-01 18:06:40 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(copy_frame);
|
|
|
|
RARCH_PERFORMANCE_START(copy_frame);
|
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;
|
2014-10-02 13:43:11 +00:00
|
|
|
bool new_egl = gl->ctx_driver->write_egl_image(gl,
|
2014-10-01 21:50:58 +00:00
|
|
|
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)
|
2013-07-05 16:15:42 +00:00
|
|
|
glEGLImageTargetTexture2DOES(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));
|
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Fallback for GLES devices without GL_BGRA_EXT. */
|
2013-01-03 00:18:19 +00:00
|
|
|
if (gl->base_size == 4 && driver.gfx_use_rgba)
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +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-10-29 22:21:15 +00:00
|
|
|
else if (gl->support_unpack_row_length)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2013-01-03 00:18:19 +00:00
|
|
|
else
|
2012-09-29 18:06:48 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
/* No GL_UNPACK_ROW_LENGTH. */
|
|
|
|
|
|
|
|
const GLvoid *data_buf = frame;
|
2013-01-03 00:18:19 +00:00
|
|
|
unsigned pitch_width = pitch / gl->base_size;
|
2014-10-01 14:59:43 +00:00
|
|
|
|
|
|
|
if (width != pitch_width)
|
2013-01-03 00:18:19 +00:00
|
|
|
{
|
2014-10-01 15:15:02 +00:00
|
|
|
/* Slow path - conv_buffer is preallocated
|
|
|
|
* just in case we hit this path. */
|
2014-10-01 14:59:43 +00:00
|
|
|
|
2013-11-29 02:06:04 +00:00
|
|
|
unsigned h;
|
2013-01-03 00:18:19 +00:00
|
|
|
const unsigned line_bytes = width * gl->base_size;
|
2014-10-01 14:59:43 +00:00
|
|
|
uint8_t *dst = (uint8_t*)gl->conv_buffer;
|
2013-01-03 00:18:19 +00:00
|
|
|
const uint8_t *src = (const uint8_t*)frame;
|
2012-12-07 07:00:46 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (h = 0; h < height; h++, src += pitch, dst += line_bytes)
|
2013-01-03 00:18:19 +00:00
|
|
|
memcpy(dst, src, line_bytes);
|
2012-12-08 11:35:10 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
data_buf = gl->conv_buffer;
|
2013-01-03 00:18:19 +00:00
|
|
|
}
|
2014-10-01 18:06:40 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, data_buf);
|
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)
|
2013-11-29 02:06:04 +00:00
|
|
|
unsigned h;
|
2013-04-06 16:40:50 +00:00
|
|
|
size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size;
|
|
|
|
size_t buffer_stride = gl->tex_w * gl->base_size;
|
|
|
|
const uint8_t *frame_copy = frame;
|
|
|
|
size_t frame_copy_size = width * gl->base_size;
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
uint8_t *buffer = (uint8_t*)glMapBuffer(
|
|
|
|
GL_TEXTURE_REFERENCE_BUFFER_SCE, GL_READ_WRITE) + buffer_addr;
|
2013-10-22 13:08:17 +00:00
|
|
|
for (h = 0; h < height; h++, buffer += buffer_stride, frame_copy += pitch)
|
2013-04-06 16:40:50 +00:00
|
|
|
memcpy(buffer, frame_copy, frame_copy_size);
|
|
|
|
|
|
|
|
glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE);
|
2012-09-29 18:06:48 +00:00
|
|
|
#else
|
2014-10-01 15:15:02 +00:00
|
|
|
const GLvoid *data_buf = frame;
|
2012-10-19 23:12:02 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch));
|
2014-01-01 20:42:31 +00:00
|
|
|
|
2014-10-01 15:15:02 +00:00
|
|
|
if (gl->base_size == 2 && !gl->have_es2_compat)
|
|
|
|
{
|
|
|
|
/* Convert to 32-bit textures on desktop GL. */
|
2014-10-01 21:50:58 +00:00
|
|
|
gl_convert_frame_rgb16_32(gl, gl->conv_buffer,
|
|
|
|
frame, width, height, pitch);
|
2014-10-01 15:15:02 +00:00
|
|
|
data_buf = gl->conv_buffer;
|
2012-10-19 23:12:02 +00:00
|
|
|
}
|
|
|
|
else
|
2012-10-01 22:58:43 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
|
2014-10-01 15:15:02 +00:00
|
|
|
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, width, height, gl->texture_type,
|
|
|
|
gl->texture_fmt, data_buf);
|
2014-01-03 13:42:00 +00:00
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2012-10-19 23:12:02 +00:00
|
|
|
#endif
|
2014-10-01 18:06:40 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(copy_frame);
|
2012-09-10 09:12:57 +00:00
|
|
|
}
|
2012-09-10 08:29:50 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static inline void gl_set_prev_texture(gl_t *gl,
|
|
|
|
const struct gl_tex_info *tex_info)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
memmove(gl->prev_info + 1, gl->prev_info,
|
|
|
|
sizeof(*tex_info) * (gl->textures - 1));
|
|
|
|
memcpy(&gl->prev_info[0], tex_info,
|
|
|
|
sizeof(*tex_info));
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-12-24 12:46:12 +00:00
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static inline void gl_set_shader_viewport(gl_t *gl, unsigned shader)
|
2012-10-01 02:04:50 +00:00
|
|
|
{
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->shader->use(gl, shader);
|
2012-10-01 02:04:50 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
}
|
|
|
|
|
2014-04-30 02:00:39 +00:00
|
|
|
#if defined(HAVE_GL_ASYNC_READBACK) && defined(HAVE_MENU)
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_pbo_async_readback(gl_t *gl)
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER,
|
|
|
|
gl->pbo_readback[gl->pbo_readback_index++]);
|
2012-11-21 15:24:28 +00:00
|
|
|
gl->pbo_readback_index &= 3;
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* 4 frames back, we can readback. */
|
2014-04-27 08:40:24 +00:00
|
|
|
gl->pbo_readback_valid[gl->pbo_readback_index] = true;
|
2012-11-21 15:24:28 +00:00
|
|
|
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
2014-10-01 21:50:58 +00:00
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT,
|
|
|
|
get_alignment(gl->vp.width * sizeof(uint32_t)));
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Read asynchronously into PBO buffer. */
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(async_readback);
|
|
|
|
RARCH_PERFORMANCE_START(async_readback);
|
2013-05-11 13:50:19 +00:00
|
|
|
glReadBuffer(GL_BACK);
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_OPENGLES3
|
|
|
|
glReadPixels(gl->vp.x, gl->vp.y,
|
|
|
|
gl->vp.width, gl->vp.height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
#else
|
2012-11-21 15:24:28 +00:00
|
|
|
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);
|
2014-04-19 15:22:25 +00:00
|
|
|
#endif
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(async_readback);
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
2014-06-17 15:08:46 +00:00
|
|
|
static inline void gl_draw_texture(gl_t *gl)
|
2013-02-28 01:20:29 +00:00
|
|
|
{
|
2014-06-10 00:15:29 +00:00
|
|
|
if (!gl->menu_texture)
|
2013-04-21 10:07:57 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-07 12:05:39 +00:00
|
|
|
const GLfloat color[] = {
|
2014-06-10 00:15:29 +00:00
|
|
|
1.0f, 1.0f, 1.0f, gl->menu_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->menu_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->menu_texture_alpha,
|
|
|
|
1.0f, 1.0f, 1.0f, gl->menu_texture_alpha,
|
2013-04-07 12:05:39 +00:00
|
|
|
};
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2013-06-30 21:01:23 +00:00
|
|
|
gl->coords.vertex = vertexes_flipped;
|
2013-04-07 12:05:39 +00:00
|
|
|
gl->coords.tex_coord = tex_coords;
|
|
|
|
gl->coords.color = color;
|
2014-06-10 00:15:29 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
2014-06-08 10:37:32 +00:00
|
|
|
gl->coords.vertices = 4;
|
2014-10-02 13:17:21 +00:00
|
|
|
gl->shader->set_coords(&gl->coords);
|
|
|
|
gl->shader->set_mvp(gl, &gl->mvp_no_rot);
|
2013-02-28 01:20:29 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
2013-04-13 14:48:03 +00:00
|
|
|
|
2014-06-10 00:15:29 +00:00
|
|
|
if (gl->menu_texture_full_screen)
|
2013-04-13 14:48:03 +00:00
|
|
|
{
|
|
|
|
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-06-30 21:01:23 +00:00
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
2013-06-30 20:24:07 +00:00
|
|
|
gl->coords.color = gl->white_color_ptr;
|
2013-02-28 01:20:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static bool gl_frame(void *data, const void *frame,
|
|
|
|
unsigned width, unsigned height, unsigned pitch, const char *msg)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(frame_run);
|
|
|
|
RARCH_PERFORMANCE_START(frame_run);
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-10-02 08:21:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-10-02 09:11:34 +00:00
|
|
|
shader_backend_t *shader = (shader_backend_t*)gl->shader;
|
2014-05-28 22:30:48 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return true;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2013-06-22 13:06:56 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
if (gl->core_context)
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindVertexArray(gl->vao);
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->use(gl, 1);
|
2011-05-26 10:53:24 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
#ifdef IOS
|
|
|
|
/* Apparently the viewport is lost each frame, thanks Apple. */
|
2013-04-10 18:42:54 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
#endif
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2014-10-01 18:06:40 +00:00
|
|
|
/* Render to texture in first pass. */
|
2011-03-06 18:56:35 +00:00
|
|
|
if (gl->fbo_inited)
|
|
|
|
{
|
2014-10-01 18:06:40 +00:00
|
|
|
gl_compute_fbo_geometry(gl, width, height,
|
|
|
|
gl->vp_out_width, gl->vp_out_height);
|
2012-01-31 23:14:04 +00:00
|
|
|
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;
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->set_resize(gl, gl->win_width, gl->win_height);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2014-10-01 17:34:55 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->fbo_inited)
|
|
|
|
{
|
|
|
|
gl_check_fbo_dimensions(gl);
|
|
|
|
|
|
|
|
/* Go back to what we're supposed to do,
|
|
|
|
* render to FBO #0. */
|
|
|
|
gl_start_frame_fbo(gl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-03-12 15:33:01 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->tex_index = frame ?
|
|
|
|
((gl->tex_index + 1) % gl->textures) : (gl->tex_index);
|
2014-10-01 16:23:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2012-12-10 12:02:59 +00:00
|
|
|
|
2014-10-01 16:23:02 +00:00
|
|
|
/* Can be NULL for frame dupe / NULL render. */
|
|
|
|
if (frame)
|
|
|
|
{
|
2013-03-27 15:15:15 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-09-07 13:04:40 +00:00
|
|
|
if (!gl->hw_render_fbo_init)
|
2013-03-27 15:15:15 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
gl_update_input_size(gl, width, height, pitch, true);
|
|
|
|
gl_copy_frame(gl, frame, width, height, pitch);
|
|
|
|
}
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2014-10-01 16:23:02 +00:00
|
|
|
/* No point regenerating mipmaps
|
|
|
|
* if there are no new frames. */
|
|
|
|
if (gl->tex_mipmap)
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
}
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2014-10-01 16:23:02 +00:00
|
|
|
/* Have to reset rendering state which libretro core
|
|
|
|
* could easily have overridden. */
|
2013-09-07 13:04:40 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
|
|
|
gl_update_input_size(gl, width, height, pitch, false);
|
|
|
|
if (!gl->fbo_inited)
|
|
|
|
{
|
|
|
|
gl_bind_backbuffer();
|
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
|
|
|
|
}
|
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2013-06-23 09:55:21 +00:00
|
|
|
if (!gl->core_context)
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2013-03-28 11:13:41 +00:00
|
|
|
#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);
|
2013-07-07 08:35:13 +00:00
|
|
|
glDisable(GL_BLEND);
|
2013-05-22 19:41:10 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2014-04-17 13:32:36 +00:00
|
|
|
glBlendEquation(GL_FUNC_ADD);
|
2013-03-28 11:13:41 +00:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->tex_info.tex = gl->texture[gl->tex_index];
|
|
|
|
gl->tex_info.input_size[0] = width;
|
|
|
|
gl->tex_info.input_size[1] = height;
|
|
|
|
gl->tex_info.tex_size[0] = gl->tex_w;
|
|
|
|
gl->tex_info.tex_size[1] = gl->tex_h;
|
2012-12-10 12:18:10 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2014-08-27 21:40:19 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->set_params(gl, 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,
|
2014-10-01 18:37:52 +00:00
|
|
|
&gl->tex_info, gl->prev_info, NULL, 0);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2014-06-08 10:37:32 +00:00
|
|
|
gl->coords.vertices = 4;
|
2014-10-02 13:17:21 +00:00
|
|
|
shader->set_coords(&gl->coords);
|
|
|
|
shader->set_mvp(gl, &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)
|
2014-10-02 08:45:20 +00:00
|
|
|
gl_frame_fbo(gl, shader, &gl->tex_info);
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2014-10-01 18:37:52 +00:00
|
|
|
gl_set_prev_texture(gl, &gl->tex_info);
|
2012-12-10 12:18:10 +00:00
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
2014-09-25 04:33:28 +00:00
|
|
|
if (g_extern.is_menu
|
2014-09-14 05:53:18 +00:00
|
|
|
&& driver.menu_ctx && driver.menu_ctx->frame)
|
2014-05-30 19:51:12 +00:00
|
|
|
driver.menu_ctx->frame();
|
2014-05-09 20:44:40 +00:00
|
|
|
|
2014-06-10 00:15:29 +00:00
|
|
|
if (gl->menu_texture_enable)
|
2014-05-11 20:33:34 +00:00
|
|
|
gl_draw_texture(gl);
|
2013-02-28 01:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-07 19:18:58 +00:00
|
|
|
if (msg && gl->font_driver && gl->font_handle)
|
|
|
|
gl->font_driver->render_msg(gl->font_handle, 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
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->update_window_title(gl);
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(frame_run);
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
#ifdef HAVE_FBO
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Reset state which could easily mess up libretro core. */
|
2013-03-28 11:13:41 +00:00
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
2014-10-02 12:05:11 +00:00
|
|
|
shader->use(gl, 0);
|
2013-03-28 11:13:41 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2013-06-23 09:55:21 +00:00
|
|
|
gl_disable_client_arrays(gl);
|
2013-03-28 11:13:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-06 20:35:57 +00:00
|
|
|
#ifndef NO_GL_READ_PIXELS
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Screenshots. */
|
2014-02-06 20:35:57 +00:00
|
|
|
if (gl->readback_buffer_screenshot)
|
|
|
|
{
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
#endif
|
|
|
|
glReadPixels(gl->vp.x, gl->vp.y,
|
|
|
|
gl->vp.width, gl->vp.height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, gl->readback_buffer_screenshot);
|
|
|
|
}
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2014-04-30 02:00:39 +00:00
|
|
|
#ifdef HAVE_MENU
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Don't readback if we're in menu mode. */
|
2014-06-10 00:15:29 +00:00
|
|
|
else if (gl->pbo_readback_enable && !gl->menu_texture_enable)
|
2013-05-11 13:50:19 +00:00
|
|
|
gl_pbo_async_readback(gl);
|
2014-02-06 20:35:57 +00:00
|
|
|
#endif
|
2014-04-30 02:00:39 +00:00
|
|
|
#endif
|
2013-05-11 13:50:19 +00:00
|
|
|
#endif
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Disable BFI during fast forward, slow-motion,
|
|
|
|
* and pause to prevent flicker. */
|
|
|
|
if (g_settings.video.black_frame_insertion &&
|
|
|
|
!driver.nonblock_state && !g_extern.is_slowmotion
|
|
|
|
&& !g_extern.is_paused)
|
2014-08-28 16:57:02 +00:00
|
|
|
{
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->swap_buffers(gl);
|
2014-08-28 16:57:02 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->swap_buffers(gl);
|
2013-04-13 12:28:12 +00:00
|
|
|
g_extern.frame_count++;
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2013-05-03 12:04:29 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2013-05-04 20:48:24 +00:00
|
|
|
if (g_settings.video.hard_sync && gl->have_sync)
|
2013-05-03 12:04:29 +00:00
|
|
|
{
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(gl_fence);
|
|
|
|
RARCH_PERFORMANCE_START(gl_fence);
|
2013-05-03 12:04:29 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->fences[gl->fence_count++] =
|
|
|
|
glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
2013-05-26 11:43:24 +00:00
|
|
|
|
|
|
|
while (gl->fence_count > g_settings.video.hard_sync_frames)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
glClientWaitSync(gl->fences[0],
|
|
|
|
GL_SYNC_FLUSH_COMMANDS_BIT, 1000000000);
|
2013-07-05 16:15:42 +00:00
|
|
|
glDeleteSync(gl->fences[0]);
|
2013-05-26 11:43:24 +00:00
|
|
|
|
|
|
|
gl->fence_count--;
|
2014-10-01 21:50:58 +00:00
|
|
|
memmove(gl->fences, gl->fences + 1,
|
|
|
|
gl->fence_count * sizeof(GLsync));
|
2013-05-26 11:43:24 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(gl_fence);
|
2013-05-03 12:04:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
if (gl->core_context)
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindVertexArray(0);
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-15 14:06:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
static void gl_free_overlay(gl_t *gl)
|
|
|
|
{
|
2014-05-28 22:30:48 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
glDeleteTextures(gl->overlays, gl->overlay_tex);
|
|
|
|
|
|
|
|
free(gl->overlay_tex);
|
|
|
|
free(gl->overlay_vertex_coord);
|
|
|
|
free(gl->overlay_tex_coord);
|
|
|
|
free(gl->overlay_color_coord);
|
|
|
|
gl->overlay_tex = NULL;
|
|
|
|
gl->overlay_vertex_coord = NULL;
|
|
|
|
gl->overlay_tex_coord = NULL;
|
|
|
|
gl->overlay_color_coord = NULL;
|
2013-10-15 14:06:59 +00:00
|
|
|
gl->overlays = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
static void gl_free(void *data)
|
|
|
|
{
|
2014-05-28 21:32:14 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-10-02 08:24:41 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-05-28 21:32:14 +00:00
|
|
|
|
|
|
|
if (!gl)
|
2012-05-27 20:39:29 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2013-05-26 11:43:24 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
|
|
|
if (gl->have_sync)
|
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < gl->fence_count; i++)
|
2013-05-26 11:43:24 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
glClientWaitSync(gl->fences[i],
|
|
|
|
GL_SYNC_FLUSH_COMMANDS_BIT, 1000000000);
|
2013-07-05 16:15:42 +00:00
|
|
|
glDeleteSync(gl->fences[i]);
|
2013-05-26 11:43:24 +00:00
|
|
|
}
|
|
|
|
gl->fence_count = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-07 19:18:58 +00:00
|
|
|
if (gl->font_driver && gl->font_handle)
|
|
|
|
gl->font_driver->free(gl->font_handle);
|
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
|
2013-06-23 09:55:21 +00:00
|
|
|
gl_disable_client_arrays(gl);
|
2012-09-13 15:05:48 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
glDeleteTextures(gl->textures, gl->texture);
|
2012-12-23 17:36:58 +00:00
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
2014-06-10 00:15:29 +00:00
|
|
|
if (gl->menu_texture)
|
|
|
|
glDeleteTextures(1, &gl->menu_texture);
|
2013-02-28 01:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-15 14:06:59 +00:00
|
|
|
gl_free_overlay(gl);
|
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);
|
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2012-11-21 15:24:28 +00:00
|
|
|
if (gl->pbo_readback_enable)
|
2012-11-21 21:12:56 +00:00
|
|
|
{
|
2013-07-05 16:15:42 +00:00
|
|
|
glDeleteBuffers(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);
|
2014-02-25 21:01:46 +00:00
|
|
|
#ifndef HAVE_GCMGL
|
2013-07-06 20:10:09 +00:00
|
|
|
gl_deinit_hw_render(gl);
|
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
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
if (gl->core_context)
|
|
|
|
{
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
glDeleteVertexArrays(1, &gl->vao);
|
2013-06-22 13:06:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
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-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-12-26 08:32:15 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-10-02 08:21:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-05-28 22:30:48 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: VSync => %s\n", state ? "off" : "on");
|
2014-10-01 14:59:43 +00:00
|
|
|
|
|
|
|
context_bind_hw_render(gl, false);
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->swap_interval(gl,
|
2014-10-01 21:50:58 +00:00
|
|
|
state ? 0 : g_settings.video.swap_interval);
|
2014-10-01 14:59:43 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
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
|
|
|
{
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->core_context =
|
|
|
|
(g_extern.system.hw_render_callback.context_type
|
|
|
|
== RETRO_HW_CONTEXT_OPENGL_CORE);
|
2013-07-12 22:53:26 +00:00
|
|
|
if (gl->core_context)
|
|
|
|
RARCH_LOG("[GL]: Using Core GL context.\n");
|
2013-06-22 13:06:56 +00:00
|
|
|
if (gl->core_context &&
|
2013-07-05 16:15:42 +00:00
|
|
|
!init_vao(gl))
|
2013-06-22 13:06:56 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Failed to init VAOs.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-01 20:42:31 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GL_RGB565 internal format support.
|
|
|
|
* Even though ES2 support is claimed, the format
|
|
|
|
* is not supported on older ATI catalyst drivers.
|
|
|
|
*
|
|
|
|
* The speed gain from using GL_RGB565 is worth
|
|
|
|
* adding some workarounds for.
|
|
|
|
*/
|
2014-01-05 21:29:57 +00:00
|
|
|
const char *vendor = (const char*)glGetString(GL_VENDOR);
|
2014-01-08 17:09:17 +00:00
|
|
|
const char *renderer = (const char*)glGetString(GL_RENDERER);
|
|
|
|
if (vendor && renderer && (strstr(vendor, "ATI") || strstr(renderer, "ATI")))
|
2014-01-05 21:29:57 +00:00
|
|
|
RARCH_LOG("[GL]: ATI card detected, skipping check for GL_RGB565 support.\n");
|
2014-01-08 17:09:17 +00:00
|
|
|
else
|
|
|
|
gl->have_es2_compat = gl_query_extension(gl, "ARB_ES2_compatibility");
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-03 12:04:29 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2013-07-05 17:47:33 +00:00
|
|
|
gl->have_sync = check_sync_proc(gl);
|
2013-05-04 20:48:24 +00:00
|
|
|
if (gl->have_sync && g_settings.video.hard_sync)
|
2013-05-03 12:04:29 +00:00
|
|
|
RARCH_LOG("[GL]: Using ARB_sync to reduce latency.\n");
|
|
|
|
#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
|
2014-10-01 21:50:58 +00:00
|
|
|
/* There are both APPLE and EXT variants. */
|
|
|
|
if (gl_query_extension(gl, "BGRA8888"))
|
2013-01-03 00:18:19 +00:00
|
|
|
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
|
|
|
}
|
2013-11-01 16:01:27 +00:00
|
|
|
|
2014-06-05 13:17:29 +00:00
|
|
|
bool gles3 = false;
|
|
|
|
const char *version = (const char*)glGetString(GL_VERSION);
|
|
|
|
unsigned gles_major = 0, gles_minor = 0;
|
2014-10-01 21:50:58 +00:00
|
|
|
/* This format is mandated by GLES. */
|
|
|
|
if (version && sscanf(version, "OpenGL ES %u.%u",
|
|
|
|
&gles_major, &gles_minor) == 2 && gles_major >= 3)
|
2014-06-05 13:17:29 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: GLES3 or newer detected. Auto-enabling some extensions.\n");
|
|
|
|
gles3 = true;
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GLES3 has unpack_subimage and sRGB in core. */
|
2014-06-05 13:17:29 +00:00
|
|
|
|
|
|
|
gl->support_unpack_row_length = gles3;
|
|
|
|
if (!gles3 && gl_query_extension(gl, "GL_EXT_unpack_subimage"))
|
2013-11-01 16:01:27 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: Extension GL_EXT_unpack_subimage, can copy textures faster using UNPACK_ROW_LENGTH.\n");
|
|
|
|
gl->support_unpack_row_length = true;
|
|
|
|
}
|
2014-10-01 21:50:58 +00:00
|
|
|
|
|
|
|
/* No extensions for float FBO currently. */
|
2014-06-05 13:17:29 +00:00
|
|
|
gl->has_srgb_fbo = gles3 || gl_query_extension(gl, "EXT_sRGB");
|
2014-06-05 15:41:10 +00:00
|
|
|
gl->has_srgb_fbo_gles3 = gles3;
|
2013-12-04 11:55:51 +00:00
|
|
|
#else
|
2014-02-11 05:07:00 +00:00
|
|
|
#ifdef HAVE_FBO
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Float FBO is core in 3.2. */
|
2014-05-27 20:27:16 +00:00
|
|
|
#ifdef HAVE_GCMGL
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->has_fp_fbo = false; /* FIXME - rewrite GL implementation */
|
2014-05-27 19:55:54 +00:00
|
|
|
#else
|
2013-12-04 11:55:51 +00:00
|
|
|
gl->has_fp_fbo = gl->core_context || gl_query_extension(gl, "ARB_texture_float");
|
2014-05-27 19:55:54 +00:00
|
|
|
#endif
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->has_srgb_fbo = gl->core_context ||
|
|
|
|
(gl_query_extension(gl, "EXT_texture_sRGB")
|
|
|
|
&& gl_query_extension(gl, "ARB_framebuffer_sRGB"));
|
2012-09-29 18:06:48 +00:00
|
|
|
#endif
|
2014-02-11 05:07:00 +00:00
|
|
|
#endif
|
2012-09-29 18:06:48 +00:00
|
|
|
|
2014-09-21 03:23:51 +00:00
|
|
|
if (g_settings.video.force_srgb_disable)
|
|
|
|
gl->has_srgb_fbo = false;
|
|
|
|
|
2013-08-14 12:00:21 +00:00
|
|
|
#ifdef GL_DEBUG
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Useful for debugging, but kinda obnoxious otherwise. */
|
2013-08-14 12:00:21 +00:00
|
|
|
RARCH_LOG("[GL]: Supported extensions:\n");
|
|
|
|
if (gl->core_context)
|
|
|
|
{
|
|
|
|
#ifdef GL_NUM_EXTENSIONS
|
|
|
|
GLint exts = 0;
|
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &exts);
|
|
|
|
for (GLint i = 0; i < exts; i++)
|
|
|
|
{
|
|
|
|
const char *ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
|
|
|
if (ext)
|
|
|
|
RARCH_LOG("\t%s\n", ext);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *ext = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
struct string_list *list = string_split(ext, " ");
|
|
|
|
for (size_t i = 0; i < list->size; i++)
|
|
|
|
RARCH_LOG("\t%s\n", list->elems[i].data);
|
|
|
|
string_list_free(list);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-17 15:08:46 +00:00
|
|
|
static inline void gl_set_texture_fmts(gl_t *gl, bool rgb32)
|
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;
|
|
|
|
}
|
2014-01-01 20:42:31 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_OPENGLES
|
2014-10-01 21:50:58 +00:00
|
|
|
if (!rgb32 && gl->have_es2_compat)
|
2014-01-01 20:42:31 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: Using GL_RGB565 for texture uploads.\n");
|
|
|
|
gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT16_565;
|
|
|
|
gl->texture_type = RARCH_GL_TEXTURE_TYPE16_565;
|
|
|
|
gl->texture_fmt = RARCH_GL_FORMAT16_565;
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-03 00:18:19 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2014-06-17 15:08:46 +00:00
|
|
|
static void gl_init_pbo_readback(gl_t *gl)
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
unsigned i;
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Only bother with this if we're doing GPU recording.
|
|
|
|
* Check g_extern.recording_enable and not
|
|
|
|
* driver.recording_data, because recording is
|
|
|
|
* not initialized yet.
|
|
|
|
*/
|
|
|
|
gl->pbo_readback_enable = g_settings.video.gpu_record
|
|
|
|
&& g_extern.recording_enable;
|
2012-11-21 15:24:28 +00:00
|
|
|
if (!gl->pbo_readback_enable)
|
|
|
|
return;
|
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
RARCH_LOG("[GL]: Async PBO readback enabled.\n");
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2013-07-05 16:15:42 +00:00
|
|
|
glGenBuffers(4, gl->pbo_readback);
|
2013-10-22 19:26:33 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
2012-11-21 15:24:28 +00:00
|
|
|
{
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[i]);
|
2014-10-01 21:50:58 +00:00
|
|
|
glBufferData(GL_PIXEL_PACK_BUFFER, gl->vp.width *
|
|
|
|
gl->vp.height * sizeof(uint32_t),
|
2014-04-19 15:27:49 +00:00
|
|
|
NULL, GL_STREAM_READ);
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
2012-11-21 21:12:56 +00:00
|
|
|
|
2014-04-19 15:27:49 +00:00
|
|
|
#ifndef HAVE_OPENGLES3
|
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");
|
2013-07-05 16:15:42 +00:00
|
|
|
glDeleteBuffers(4, gl->pbo_readback);
|
2012-11-21 21:12:56 +00:00
|
|
|
}
|
2014-04-19 15:27:49 +00:00
|
|
|
#endif
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
2013-05-11 13:50:19 +00:00
|
|
|
#endif
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2014-03-09 15:50:18 +00:00
|
|
|
static const gfx_ctx_driver_t *gl_get_context(gl_t *gl)
|
2013-02-23 13:49:49 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
const struct retro_hw_render_callback *cb =
|
|
|
|
(const struct retro_hw_render_callback*)
|
|
|
|
&g_extern.system.hw_render_callback;
|
2013-12-13 13:19:25 +00:00
|
|
|
unsigned major = cb->version_major;
|
|
|
|
unsigned minor = cb->version_minor;
|
2013-02-23 13:49:49 +00:00
|
|
|
#ifdef HAVE_OPENGLES
|
|
|
|
enum gfx_ctx_api api = GFX_CTX_OPENGL_ES_API;
|
2013-12-13 13:19:25 +00:00
|
|
|
const char *api_name = "OpenGL ES 2.0";
|
|
|
|
#ifdef HAVE_OPENGLES3
|
|
|
|
if (cb->context_type == RETRO_HW_CONTEXT_OPENGLES3)
|
|
|
|
{
|
|
|
|
major = 3;
|
|
|
|
minor = 0;
|
|
|
|
api_name = "OpenGL ES 3.0";
|
|
|
|
}
|
2014-05-03 13:21:14 +00:00
|
|
|
else if (cb->context_type == RETRO_HW_CONTEXT_OPENGLES_VERSION)
|
|
|
|
api_name = "OpenGL ES 3.1+";
|
2013-12-13 13:19:25 +00:00
|
|
|
#endif
|
2013-02-23 13:49:49 +00:00
|
|
|
#else
|
|
|
|
enum gfx_ctx_api api = GFX_CTX_OPENGL_API;
|
|
|
|
const char *api_name = "OpenGL";
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->shared_context_use = g_settings.video.shared_context
|
|
|
|
&& cb->context_type != RETRO_HW_CONTEXT_NONE;
|
2014-04-19 14:59:26 +00:00
|
|
|
|
2013-02-23 13:49:49 +00:00
|
|
|
if (*g_settings.video.gl_context)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
const gfx_ctx_driver_t *ctx = gfx_ctx_find_driver(
|
|
|
|
g_settings.video.gl_context);
|
|
|
|
|
2013-02-23 13:49:49 +00:00
|
|
|
if (ctx)
|
|
|
|
{
|
2014-03-09 15:50:18 +00:00
|
|
|
if (!ctx->bind_api(gl, api, major, minor))
|
2013-02-23 13:49:49 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to bind API %s to context %s.\n", api_name, g_settings.video.gl_context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Enables or disables offscreen HW context. */
|
2014-04-19 14:06:12 +00:00
|
|
|
if (ctx->bind_hw_render)
|
2014-04-19 14:59:26 +00:00
|
|
|
ctx->bind_hw_render(gl, gl->shared_context_use);
|
2014-04-19 14:06:12 +00:00
|
|
|
|
2014-03-09 15:50:18 +00:00
|
|
|
if (!ctx->init(gl))
|
2013-02-23 13:49:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2014-10-01 14:59:43 +00:00
|
|
|
|
|
|
|
return gfx_ctx_init_first(gl, api, major, minor, gl->shared_context_use);
|
2013-02-23 13:49:49 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 12:00:21 +00:00
|
|
|
#ifdef GL_DEBUG
|
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
#define DEBUG_CALLBACK_TYPE GL_APIENTRY
|
2014-10-01 21:50:58 +00:00
|
|
|
|
2014-04-21 12:37:43 +00:00
|
|
|
#define GL_DEBUG_SOURCE_API GL_DEBUG_SOURCE_API_KHR
|
|
|
|
#define GL_DEBUG_SOURCE_WINDOW_SYSTEM GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR
|
|
|
|
#define GL_DEBUG_SOURCE_SHADER_COMPILER GL_DEBUG_SOURCE_SHADER_COMPILER_KHR
|
|
|
|
#define GL_DEBUG_SOURCE_THIRD_PARTY GL_DEBUG_SOURCE_THIRD_PARTY_KHR
|
|
|
|
#define GL_DEBUG_SOURCE_APPLICATION GL_DEBUG_SOURCE_APPLICATION_KHR
|
|
|
|
#define GL_DEBUG_SOURCE_OTHER GL_DEBUG_SOURCE_OTHER_KHR
|
|
|
|
#define GL_DEBUG_TYPE_ERROR GL_DEBUG_TYPE_ERROR_KHR
|
|
|
|
#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR
|
|
|
|
#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR
|
|
|
|
#define GL_DEBUG_TYPE_PORTABILITY GL_DEBUG_TYPE_PORTABILITY_KHR
|
|
|
|
#define GL_DEBUG_TYPE_PERFORMANCE GL_DEBUG_TYPE_PERFORMANCE_KHR
|
|
|
|
#define GL_DEBUG_TYPE_MARKER GL_DEBUG_TYPE_MARKER_KHR
|
|
|
|
#define GL_DEBUG_TYPE_PUSH_GROUP GL_DEBUG_TYPE_PUSH_GROUP_KHR
|
|
|
|
#define GL_DEBUG_TYPE_POP_GROUP GL_DEBUG_TYPE_POP_GROUP_KHR
|
|
|
|
#define GL_DEBUG_TYPE_OTHER GL_DEBUG_TYPE_OTHER_KHR
|
|
|
|
#define GL_DEBUG_SEVERITY_HIGH GL_DEBUG_SEVERITY_HIGH_KHR
|
|
|
|
#define GL_DEBUG_SEVERITY_MEDIUM GL_DEBUG_SEVERITY_MEDIUM_KHR
|
|
|
|
#define GL_DEBUG_SEVERITY_LOW GL_DEBUG_SEVERITY_LOW_KHR
|
2013-08-14 12:00:21 +00:00
|
|
|
#else
|
|
|
|
#define DEBUG_CALLBACK_TYPE APIENTRY
|
|
|
|
#endif
|
|
|
|
static void DEBUG_CALLBACK_TYPE gl_debug_cb(GLenum source, GLenum type,
|
|
|
|
GLuint id, GLenum severity, GLsizei length,
|
|
|
|
const GLchar *message, void *userParam)
|
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
const char *src, *typestr;
|
|
|
|
gl_t *gl = (gl_t*)userParam; /* Useful for debugger. */
|
2013-08-14 12:00:21 +00:00
|
|
|
|
|
|
|
(void)gl;
|
2014-10-01 14:59:43 +00:00
|
|
|
(void)id;
|
|
|
|
(void)length;
|
2013-08-14 12:00:21 +00:00
|
|
|
|
|
|
|
switch (source)
|
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
case GL_DEBUG_SOURCE_API:
|
|
|
|
src = "API";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
|
|
|
src = "Window system";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
|
|
|
src = "Shader compiler";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
|
|
|
src = "3rd party";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SOURCE_APPLICATION:
|
|
|
|
src = "Application";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SOURCE_OTHER:
|
|
|
|
src = "Other";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
src = "Unknown";
|
|
|
|
break;
|
2013-08-14 12:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
case GL_DEBUG_TYPE_ERROR:
|
|
|
|
typestr = "Error";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
|
|
|
typestr = "Deprecated behavior";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
|
|
|
typestr = "Undefined behavior";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY:
|
|
|
|
typestr = "Portability";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE:
|
|
|
|
typestr = "Performance";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_MARKER:
|
|
|
|
typestr = "Marker";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_PUSH_GROUP:
|
|
|
|
typestr = "Push group";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_POP_GROUP:
|
|
|
|
typestr = "Pop group";
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_TYPE_OTHER:
|
|
|
|
typestr = "Other";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
typestr = "Unknown";
|
|
|
|
break;
|
2013-08-14 12:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (severity)
|
|
|
|
{
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH:
|
|
|
|
RARCH_ERR("[GL debug (High, %s, %s)]: %s\n", src, typestr, message);
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM:
|
|
|
|
RARCH_WARN("[GL debug (Medium, %s, %s)]: %s\n", src, typestr, message);
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SEVERITY_LOW:
|
|
|
|
RARCH_LOG("[GL debug (Low, %s, %s)]: %s\n", src, typestr, message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_begin_debug(gl_t *gl)
|
|
|
|
{
|
|
|
|
if (gl_query_extension(gl, "KHR_debug"))
|
|
|
|
{
|
2014-04-21 12:37:43 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
glDebugMessageCallbackKHR(gl_debug_cb, gl);
|
|
|
|
glDebugMessageControlKHR(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR);
|
|
|
|
#else
|
2013-08-14 12:00:21 +00:00
|
|
|
glDebugMessageCallback(gl_debug_cb, gl);
|
|
|
|
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
2014-04-21 12:37:43 +00:00
|
|
|
#endif
|
2013-08-14 12:00:21 +00:00
|
|
|
}
|
|
|
|
#ifndef HAVE_OPENGLES2
|
|
|
|
else if (gl_query_extension(gl, "ARB_debug_output"))
|
|
|
|
{
|
|
|
|
glDebugMessageCallbackARB(gl_debug_cb, gl);
|
|
|
|
glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
RARCH_ERR("Neither GL_KHR_debug nor GL_ARB_debug_output are implemented. Cannot start GL debugging.\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
unsigned win_width, win_height;
|
2014-10-02 08:21:36 +00:00
|
|
|
const gfx_ctx_driver_t *ctx_driver = NULL;
|
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 13:04:43 +00:00
|
|
|
gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t));
|
|
|
|
if (!gl)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver = gl_get_context(gl);
|
|
|
|
if (!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
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
gl->ctx_driver = ctx_driver;
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->video_info = *video;
|
|
|
|
|
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
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->get_video_size(gl, &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
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->swap_interval(gl,
|
|
|
|
video->vsync ? g_settings.video.swap_interval : 0);
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
win_width = video->width;
|
|
|
|
win_height = video->height;
|
|
|
|
|
2011-09-13 16:50:40 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-02 08:21:36 +00:00
|
|
|
if (!ctx_driver->set_video_mode(gl, 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
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Clear out potential error flags in case we use cached context. */
|
|
|
|
glGetError();
|
2013-08-14 12:57:39 +00:00
|
|
|
|
2013-07-12 23:46:57 +00:00
|
|
|
const char *vendor = (const char*)glGetString(GL_VENDOR);
|
|
|
|
const char *renderer = (const char*)glGetString(GL_RENDERER);
|
|
|
|
RARCH_LOG("[GL]: Vendor: %s, Renderer: %s.\n", vendor, renderer);
|
|
|
|
|
2013-08-16 08:18:58 +00:00
|
|
|
const char *version = (const char*)glGetString(GL_VERSION);
|
|
|
|
RARCH_LOG("[GL]: Version: %s.\n", version);
|
|
|
|
|
2013-08-11 13:06:42 +00:00
|
|
|
#ifndef RARCH_CONSOLE
|
2013-07-05 16:28:08 +00:00
|
|
|
rglgen_resolve_symbols(gl->ctx_driver->get_proc_address);
|
2013-08-11 13:06:42 +00:00
|
|
|
#endif
|
2013-07-12 22:53:26 +00:00
|
|
|
|
2011-03-12 18:09:25 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2014-04-17 13:32:36 +00:00
|
|
|
glBlendEquation(GL_FUNC_ADD);
|
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
|
|
|
{
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
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
|
|
|
|
2013-08-14 12:00:21 +00:00
|
|
|
#ifdef GL_DEBUG
|
|
|
|
gl_begin_debug(gl);
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Get real known video size, which might have been altered by context. */
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->get_video_size(gl, &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
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
if (gl->full_x || gl->full_y)
|
2012-09-16 19:39:40 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* We got bogus from gfx_ctx_get_video_size. Replace. */
|
2012-09-16 19:39:40 +00:00
|
|
|
gl->full_x = gl->win_width;
|
|
|
|
gl->full_y = gl->win_height;
|
|
|
|
}
|
|
|
|
|
2013-06-30 20:58:22 +00:00
|
|
|
struct retro_hw_render_callback *hw_render = &g_extern.system.hw_render_callback;
|
|
|
|
gl->vertex_ptr = hw_render->bottom_left_origin ? vertexes : vertexes_flipped;
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Better pipelining with GPU due to synchronous glSubTexImage.
|
|
|
|
* Multiple async PBOs would be an alternative,
|
|
|
|
* but still need multiple textures with PREV.
|
|
|
|
*/
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->textures = 4;
|
2013-06-30 20:58:22 +00:00
|
|
|
#ifdef HAVE_FBO
|
2014-05-03 13:21:14 +00:00
|
|
|
gl->hw_render_use = hw_render->context_type != RETRO_HW_CONTEXT_NONE;
|
2013-07-06 20:10:09 +00:00
|
|
|
if (gl->hw_render_use)
|
2014-04-19 13:37:00 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* All on GPU, no need to excessively
|
|
|
|
* create textures. */
|
|
|
|
gl->textures = 1;
|
2014-04-19 13:37:00 +00:00
|
|
|
#ifdef GL_DEBUG
|
2014-04-21 12:37:43 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2014-04-19 13:37:00 +00:00
|
|
|
gl_begin_debug(gl);
|
2014-04-21 12:37:43 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2014-04-19 13:37:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
2013-06-30 20:58:22 +00:00
|
|
|
#endif
|
|
|
|
gl->white_color_ptr = white_color;
|
|
|
|
|
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);
|
2014-10-01 21:50:58 +00:00
|
|
|
gl_glsl_set_context_type(gl->core_context,
|
|
|
|
hw_render->version_major, hw_render->version_minor);
|
2012-09-24 23:26:22 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-02 11:47:45 +00:00
|
|
|
gl->shader = (const shader_backend_t*)shader_ctx_init_first();
|
|
|
|
|
|
|
|
if (gl->shader)
|
|
|
|
{
|
|
|
|
RARCH_LOG("[GL]: Default shader backend found: %s.\n",
|
|
|
|
gl->shader->ident);
|
|
|
|
}
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
if (!gl_shader_init(gl))
|
2011-01-11 18:23:21 +00:00
|
|
|
{
|
2013-06-05 08:42:39 +00:00
|
|
|
RARCH_ERR("[GL]: Shader init failed.\n");
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
2011-01-11 20:16:57 +00:00
|
|
|
free(gl);
|
2011-01-11 18:23:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
if (gl->shader)
|
|
|
|
{
|
|
|
|
unsigned minimum = gl->shader->get_prev_textures();
|
|
|
|
gl->textures = max(minimum + 1, gl->textures);
|
|
|
|
}
|
|
|
|
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: Using %u textures.\n", gl->textures);
|
2014-10-02 12:05:11 +00:00
|
|
|
RARCH_LOG("[GL]: Loaded %u program(s).\n", gl->shader->num_shaders());
|
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;
|
|
|
|
|
2014-10-01 21:50:58 +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;
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->tex_mipmap = gl->shader->mipmap_input(1);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
if (gl->shader->filter_type(1, &force_smooth))
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->tex_min_filter = gl->tex_mipmap ? (force_smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
|
|
|
: (force_smooth ? GL_LINEAR : GL_NEAREST);
|
2010-05-29 12:45:40 +00:00
|
|
|
else
|
2014-10-01 21:50:58 +00:00
|
|
|
gl->tex_min_filter = gl->tex_mipmap ?
|
|
|
|
(video->smooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
|
|
|
: (video->smooth ? GL_LINEAR : GL_NEAREST);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
|
|
|
gl->tex_mag_filter = min_filter_to_mag(gl->tex_min_filter);
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->wrap_mode = gl_wrap_type_to_enum(gl->shader->wrap_type(1));
|
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
|
2013-06-23 09:55:21 +00:00
|
|
|
if (!gl->core_context)
|
|
|
|
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
|
|
|
|
2014-10-01 18:37:52 +00:00
|
|
|
memcpy(gl->tex_info.coord, tex_coords, sizeof(gl->tex_info.coord));
|
2013-06-30 20:24:07 +00:00
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
2013-06-30 20:24:07 +00:00
|
|
|
gl->coords.color = gl->white_color_ptr;
|
2012-09-11 21:32:00 +00:00
|
|
|
gl->coords.lut_tex_coord = tex_coords;
|
2014-06-07 19:18:58 +00:00
|
|
|
gl->coords.vertices = 4;
|
2011-05-18 18:38:04 +00:00
|
|
|
|
2014-10-01 21:50:58 +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)
|
|
|
|
{
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
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
|
|
|
|
gl_init_fbo(gl, gl->tex_w, gl->tex_h);
|
|
|
|
|
2014-02-25 21:01:46 +00:00
|
|
|
#ifndef HAVE_GCMGL
|
2014-10-01 21:50:58 +00:00
|
|
|
if (gl->hw_render_use &&
|
|
|
|
!gl_init_hw_render(gl, gl->tex_w, gl->tex_h))
|
2013-03-29 01:12:08 +00:00
|
|
|
{
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
2013-03-29 01:12:08 +00:00
|
|
|
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)
|
2014-10-02 08:21:36 +00:00
|
|
|
ctx_driver->input_driver(gl, input, input_data);
|
2012-12-14 23:07:31 +00:00
|
|
|
|
2014-01-08 18:42:17 +00:00
|
|
|
#ifndef RARCH_CONSOLE
|
2013-01-05 22:47:49 +00:00
|
|
|
if (g_settings.video.font_enable)
|
2014-01-08 18:42:17 +00:00
|
|
|
#endif
|
2013-11-01 16:01:27 +00:00
|
|
|
{
|
2014-06-07 19:18:58 +00:00
|
|
|
if (!gl_font_init_first(&gl->font_driver, &gl->font_handle,
|
2014-10-01 21:50:58 +00:00
|
|
|
gl, *g_settings.video.font_path
|
|
|
|
? g_settings.video.font_path : NULL, g_settings.video.font_size))
|
2014-06-07 19:18:58 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to init font renderer.\n");
|
2013-11-01 16:01:27 +00:00
|
|
|
}
|
2012-09-10 21:17:48 +00:00
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2012-11-21 15:24:28 +00:00
|
|
|
gl_init_pbo_readback(gl);
|
2013-05-11 13:50:19 +00:00
|
|
|
#endif
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2011-01-11 21:33:28 +00:00
|
|
|
if (!gl_check_error())
|
|
|
|
{
|
2014-10-02 08:24:41 +00:00
|
|
|
ctx_driver->destroy(gl);
|
2011-01-11 21:33:28 +00:00
|
|
|
free(gl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
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)
|
|
|
|
{
|
2013-11-02 16:54:34 +00:00
|
|
|
bool quit = false, resize = false;
|
2014-10-02 08:21:36 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-09-30 13:44:40 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return false;
|
2012-05-30 15:02:38 +00:00
|
|
|
|
2014-10-03 15:17:18 +00:00
|
|
|
gl->ctx_driver->check_window(gl, &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;
|
|
|
|
|
2014-05-29 00:21:22 +00:00
|
|
|
return !gl->quitting;
|
2011-01-06 19:01:32 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2014-10-02 08:21:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
|
|
|
|
|
|
|
if (gl && ctx_driver)
|
|
|
|
return ctx_driver->has_focus(gl);
|
|
|
|
return false;
|
2011-02-05 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 23:56:13 +00:00
|
|
|
static void gl_update_tex_filter_frame(gl_t *gl)
|
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned i;
|
2013-04-13 23:56:13 +00:00
|
|
|
bool smooth = false;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2014-10-02 12:05:11 +00:00
|
|
|
if (!gl->shader->filter_type(1, &smooth))
|
2013-04-13 23:56:13 +00:00
|
|
|
smooth = g_settings.video.smooth;
|
2014-10-02 12:05:11 +00:00
|
|
|
GLenum wrap_mode = gl_wrap_type_to_enum(gl->shader->wrap_type(1));
|
2013-04-13 23:56:13 +00:00
|
|
|
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->tex_mipmap = gl->shader->mipmap_input(1);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->video_info.smooth = smooth;
|
2014-10-01 21:50:58 +00:00
|
|
|
GLuint new_filt = gl->tex_mipmap ? (smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
|
|
|
: (smooth ? GL_LINEAR : GL_NEAREST);
|
2014-05-11 11:13:38 +00:00
|
|
|
if (new_filt == gl->tex_min_filter && wrap_mode == gl->wrap_mode)
|
2013-04-13 23:56:13 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-11 11:13:38 +00:00
|
|
|
gl->tex_min_filter = new_filt;
|
|
|
|
gl->tex_mag_filter = min_filter_to_mag(gl->tex_min_filter);
|
|
|
|
|
2013-08-15 22:30:54 +00:00
|
|
|
gl->wrap_mode = wrap_mode;
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->textures; i++)
|
2013-04-13 23:56:13 +00:00
|
|
|
{
|
|
|
|
if (gl->texture[i])
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
2013-08-15 22:30:54 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->wrap_mode);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->wrap_mode);
|
2014-05-11 11:13:38 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_min_filter);
|
2013-04-13 23:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2013-04-13 23:56:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 21:50:58 +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
|
|
|
{
|
2014-09-09 04:07:11 +00:00
|
|
|
#if defined(HAVE_GLSL) || defined(HAVE_CG)
|
2011-12-24 12:46:12 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
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:
|
|
|
|
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);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2013-04-07 11:00:21 +00:00
|
|
|
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
|
|
|
|
|
2014-03-07 04:32:17 +00:00
|
|
|
if (!gl->shader->init(gl, path))
|
2013-04-07 11:00:21 +00:00
|
|
|
{
|
|
|
|
RARCH_WARN("[GL]: Failed to set multipass shader. Falling back to stock.\n");
|
2014-03-07 04:32:17 +00:00
|
|
|
bool ret = gl->shader->init(gl, NULL);
|
2013-01-08 02:46:18 +00:00
|
|
|
if (!ret)
|
2013-04-07 11:00:21 +00:00
|
|
|
gl->shader = NULL;
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2013-04-07 11:00:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-29 16:59:06 +00:00
|
|
|
|
2013-04-13 23:31:32 +00:00
|
|
|
gl_update_tex_filter_frame(gl);
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
if (gl->shader)
|
|
|
|
{
|
|
|
|
unsigned textures = gl->shader->get_prev_textures() + 1;
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
if (textures > gl->textures) // Have to reinit a bit.
|
|
|
|
{
|
2014-02-25 21:01:46 +00:00
|
|
|
#if defined(HAVE_FBO) && !defined(HAVE_GCMGL)
|
2013-07-06 20:10:09 +00:00
|
|
|
gl_deinit_hw_render(gl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glDeleteTextures(gl->textures, gl->texture);
|
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0);
|
|
|
|
glDeleteBuffers(1, &gl->pbo);
|
|
|
|
#endif
|
|
|
|
gl->textures = textures;
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: Using %u textures.\n", gl->textures);
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->tex_index = 0;
|
|
|
|
gl_init_textures(gl, &gl->video_info);
|
|
|
|
gl_init_textures_data(gl);
|
|
|
|
|
2014-02-25 21:01:46 +00:00
|
|
|
#if defined(HAVE_FBO) && !defined(HAVE_GCMGL)
|
2013-07-06 20:10:09 +00:00
|
|
|
if (gl->hw_render_use)
|
|
|
|
gl_init_hw_render(gl, gl->tex_w, gl->tex_h);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-04-07 11:00:21 +00:00
|
|
|
gl_init_fbo(gl, gl->tex_w, gl->tex_h);
|
2012-01-30 19:22:36 +00:00
|
|
|
#endif
|
2011-03-29 16:59:06 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Apparently need to set viewport for passes when we aren't using FBOs. */
|
2013-04-07 11:00:21 +00:00
|
|
|
gl_set_shader_viewport(gl, 0);
|
|
|
|
gl_set_shader_viewport(gl, 1);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2013-04-07 11:00:21 +00:00
|
|
|
return true;
|
2014-09-09 04:07:11 +00:00
|
|
|
#else
|
|
|
|
return false;
|
2011-03-29 16:59:06 +00:00
|
|
|
#endif
|
2014-09-09 04:07:11 +00:00
|
|
|
}
|
2011-03-29 16:28:31 +00:00
|
|
|
|
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
|
|
|
{
|
2014-05-28 22:43:47 +00:00
|
|
|
unsigned top_y, top_dist;
|
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
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Adjust as GL viewport is bottom-up. */
|
2014-05-28 22:43:47 +00:00
|
|
|
top_y = vp->y + vp->height;
|
|
|
|
top_dist = gl->win_height - top_y;
|
2013-01-24 06:29:26 +00:00
|
|
|
vp->y = top_dist;
|
2012-06-08 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool gl_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
2014-09-09 04:07:11 +00:00
|
|
|
#ifndef NO_GL_READ_PIXELS
|
2012-10-27 22:38:31 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2014-01-06 15:20:20 +00:00
|
|
|
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_INIT(read_viewport);
|
|
|
|
RARCH_PERFORMANCE_START(read_viewport);
|
2012-11-20 17:05:33 +00:00
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2012-11-21 15:24:28 +00:00
|
|
|
if (gl->pbo_readback_enable)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Don't readback if we're in menu mode. */
|
|
|
|
if (!gl->pbo_readback_valid[gl->pbo_readback_index])
|
2014-04-19 15:22:25 +00:00
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* We haven't buffered up enough frames yet, come back later. */
|
2014-04-19 15:22:25 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2012-11-21 15:24:28 +00:00
|
|
|
return false;
|
2014-04-19 15:22:25 +00:00
|
|
|
}
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2014-04-27 08:40:24 +00:00
|
|
|
gl->pbo_readback_valid[gl->pbo_readback_index] = false;
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[gl->pbo_readback_index]);
|
2014-04-19 15:22:25 +00:00
|
|
|
#ifdef HAVE_OPENGLES3
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Slower path, but should work on all implementations at least. */
|
2014-04-19 15:22:25 +00:00
|
|
|
unsigned num_pixels = gl->vp.width * gl->vp.height;
|
|
|
|
const uint8_t *ptr = (const uint8_t*)glMapBufferRange(GL_PIXEL_PACK_BUFFER,
|
|
|
|
0, num_pixels * sizeof(uint32_t), GL_MAP_READ_BIT);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
unsigned x, y;
|
|
|
|
for (y = 0; y < gl->vp.height; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < gl->vp.width; x++, buffer += 3, ptr += 4)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
buffer[0] = ptr[2]; /* RGBA -> BGR. */
|
2014-04-19 15:22:25 +00:00
|
|
|
buffer[1] = ptr[1];
|
|
|
|
buffer[2] = ptr[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Failed to map pixel unpack buffer.\n");
|
|
|
|
context_bind_hw_render(gl, true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2013-07-05 16:15:42 +00:00
|
|
|
const void *ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
2012-11-21 15:24:28 +00:00
|
|
|
if (!ptr)
|
|
|
|
{
|
2014-04-19 15:22:25 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to map pixel unpack buffer.\n");
|
|
|
|
context_bind_hw_render(gl, true);
|
2012-11-21 15:24:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-21 21:12:56 +00:00
|
|
|
|
|
|
|
scaler_ctx_scale(&gl->pbo_readback_scaler, buffer, ptr);
|
2014-04-19 15:22:25 +00:00
|
|
|
#endif
|
2013-07-05 16:15:42 +00:00
|
|
|
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
2014-10-01 21:50:58 +00:00
|
|
|
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
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GLES2 only guarantees GL_RGBA/GL_UNSIGNED_BYTE
|
|
|
|
* readbacks so do just that.
|
|
|
|
* GLES2 also doesn't support reading back data
|
|
|
|
* from front buffer, so render a cached frame
|
|
|
|
* and have gl_frame() do the readback while it's
|
|
|
|
* in the back buffer.
|
|
|
|
*
|
|
|
|
* Keep codepath similar for GLES and desktop GL.
|
|
|
|
*/
|
2012-11-21 15:24:28 +00:00
|
|
|
|
2014-02-06 20:35:57 +00:00
|
|
|
unsigned num_pixels = gl->vp.width * gl->vp.height;
|
|
|
|
|
|
|
|
gl->readback_buffer_screenshot = malloc(num_pixels * sizeof(uint32_t));
|
|
|
|
if (!gl->readback_buffer_screenshot)
|
|
|
|
{
|
|
|
|
RARCH_PERFORMANCE_STOP(read_viewport);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2014-02-06 20:35:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-06 22:37:06 +00:00
|
|
|
rarch_render_cached_frame();
|
2014-02-06 20:35:57 +00:00
|
|
|
|
|
|
|
uint8_t *dst = buffer;
|
2014-02-06 21:49:14 +00:00
|
|
|
const uint8_t *src = (const uint8_t*)gl->readback_buffer_screenshot;
|
2014-02-06 20:35:57 +00:00
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < num_pixels; i++, dst += 3, src += 4)
|
|
|
|
{
|
2014-10-01 21:50:58 +00:00
|
|
|
dst[0] = src[2]; /* RGBA -> BGR. */
|
2014-02-06 20:35:57 +00:00
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
free(gl->readback_buffer_screenshot);
|
|
|
|
gl->readback_buffer_screenshot = NULL;
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2013-12-18 18:10:57 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(read_viewport);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2012-06-08 20:39:18 +00:00
|
|
|
return true;
|
2014-09-09 04:07:11 +00:00
|
|
|
#else
|
|
|
|
return false;
|
2012-06-08 22:24:43 +00:00
|
|
|
#endif
|
2014-09-09 04:07:11 +00:00
|
|
|
}
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-15 14:06:59 +00:00
|
|
|
static void gl_free_overlay(gl_t *gl);
|
2014-10-01 21:50:58 +00:00
|
|
|
static bool gl_overlay_load(void *data,
|
|
|
|
const struct texture_image *images, unsigned num_images)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2014-06-13 15:46:53 +00:00
|
|
|
unsigned i, j;
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2013-10-15 14:06:59 +00:00
|
|
|
gl_free_overlay(gl);
|
2014-06-13 15:46:53 +00:00
|
|
|
gl->overlay_tex = (GLuint*)calloc(num_images, sizeof(*gl->overlay_tex));
|
|
|
|
if (!gl->overlay_tex)
|
2014-04-19 13:37:00 +00:00
|
|
|
{
|
|
|
|
context_bind_hw_render(gl, true);
|
2013-10-15 14:06:59 +00:00
|
|
|
return false;
|
2014-04-19 13:37:00 +00:00
|
|
|
}
|
2013-10-15 14:06:59 +00:00
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
gl->overlay_vertex_coord = (GLfloat*)calloc(2 * 4 * num_images, sizeof(GLfloat));
|
|
|
|
gl->overlay_tex_coord = (GLfloat*)calloc(2 * 4 * num_images, sizeof(GLfloat));
|
|
|
|
gl->overlay_color_coord = (GLfloat*)calloc(4 * 4 * num_images, sizeof(GLfloat));
|
|
|
|
if (!gl->overlay_vertex_coord || !gl->overlay_tex_coord || !gl->overlay_color_coord)
|
|
|
|
return false;
|
|
|
|
|
2013-10-15 14:06:59 +00:00
|
|
|
gl->overlays = num_images;
|
2014-06-13 15:46:53 +00:00
|
|
|
glGenTextures(num_images, gl->overlay_tex);
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < num_images; i++)
|
2013-10-15 14:06:59 +00:00
|
|
|
{
|
2014-06-13 15:46:53 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->overlay_tex[i]);
|
2013-10-15 14:06:59 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,
|
|
|
|
get_alignment(images[i].width * sizeof(uint32_t)));
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ?
|
|
|
|
GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
images[i].width, images[i].height, 0,
|
|
|
|
driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
2013-12-31 18:03:58 +00:00
|
|
|
RARCH_GL_FORMAT32, images[i].pixels);
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Default. Stretch to whole screen. */
|
|
|
|
gl_overlay_tex_geom(gl, i, 0, 0, 1, 1);
|
2013-10-15 14:06:59 +00:00
|
|
|
gl_overlay_vertex_geom(gl, i, 0, 0, 1, 1);
|
2014-06-13 15:46:53 +00:00
|
|
|
for (j = 0; j < 16; j++)
|
|
|
|
gl->overlay_color_coord[16 * i + j] = 1.0f;
|
2013-10-15 14:06:59 +00:00
|
|
|
}
|
2013-01-29 20:51:15 +00:00
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
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,
|
2013-10-15 14:06:59 +00:00
|
|
|
unsigned image,
|
2012-12-19 12:26:11 +00:00
|
|
|
GLfloat x, GLfloat y,
|
|
|
|
GLfloat w, GLfloat h)
|
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
GLfloat *tex = NULL;
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
tex = (GLfloat*)&gl->overlay_tex_coord[image * 8];
|
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
return;
|
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
tex[0] = x; tex[1] = y;
|
|
|
|
tex[2] = x + w; tex[3] = y;
|
|
|
|
tex[4] = x; tex[5] = y + h;
|
|
|
|
tex[6] = x + w; tex[7] = y + h;
|
2012-12-19 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_vertex_geom(void *data,
|
2013-10-15 14:06:59 +00:00
|
|
|
unsigned image,
|
2012-12-20 10:16:22 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
GLfloat *vertex = NULL;
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
2014-06-13 15:46:53 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
vertex = (GLfloat*)&gl->overlay_vertex_coord[image * 8];
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Flipped, so we preserve top-down semantics. */
|
2012-12-19 12:26:11 +00:00
|
|
|
y = 1.0f - y;
|
|
|
|
h = -h;
|
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!vertex)
|
|
|
|
return;
|
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
vertex[0] = x; vertex[1] = y;
|
|
|
|
vertex[2] = x + w; vertex[3] = y;
|
|
|
|
vertex[4] = x; vertex[5] = y + h;
|
|
|
|
vertex[6] = x + w; vertex[7] = y + h;
|
2012-12-19 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 10:16:22 +00:00
|
|
|
static void gl_overlay_enable(void *data, bool state)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-10-02 08:27:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->overlay_enable = state;
|
2014-10-02 08:27:36 +00:00
|
|
|
if (ctx_driver->show_mouse && gl->fullscreen)
|
|
|
|
ctx_driver->show_mouse(gl, 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;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
|
|
|
if (gl)
|
|
|
|
gl->overlay_full_screen = enable;
|
2013-01-11 15:23:04 +00:00
|
|
|
}
|
|
|
|
|
2013-10-15 14:06:59 +00:00
|
|
|
static void gl_overlay_set_alpha(void *data, unsigned image, float mod)
|
2013-01-29 20:51:15 +00:00
|
|
|
{
|
2014-10-01 14:59:43 +00:00
|
|
|
GLfloat *color = NULL;
|
2013-01-29 20:51:15 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-06-13 15:46:53 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
color = (GLfloat*)&gl->overlay_color_coord[image * 16];
|
|
|
|
|
|
|
|
if (!color)
|
|
|
|
return;
|
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
color[ 0 + 3] = mod;
|
|
|
|
color[ 4 + 3] = mod;
|
|
|
|
color[ 8 + 3] = mod;
|
|
|
|
color[12 + 3] = mod;
|
2013-01-29 20:51:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 08:06:17 +00:00
|
|
|
static void gl_render_overlay(void *data)
|
2012-12-19 12:26:11 +00:00
|
|
|
{
|
2014-06-13 16:00:42 +00:00
|
|
|
unsigned i;
|
2013-01-05 08:06:17 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-06-13 15:46:53 +00:00
|
|
|
if (!gl)
|
2014-06-12 20:15:32 +00:00
|
|
|
return;
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
if (gl->overlay_full_screen)
|
|
|
|
glViewport(0, 0, gl->win_width, gl->win_height);
|
2013-10-15 14:06:59 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Ensure that we reset the attrib array. */
|
2014-10-02 12:05:11 +00:00
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
2014-06-13 15:46:53 +00:00
|
|
|
gl->coords.vertex = gl->overlay_vertex_coord;
|
|
|
|
gl->coords.tex_coord = gl->overlay_tex_coord;
|
|
|
|
gl->coords.color = gl->overlay_color_coord;
|
|
|
|
gl->coords.vertices = 4 * gl->overlays;
|
2014-10-02 13:17:21 +00:00
|
|
|
gl->shader->set_coords(&gl->coords);
|
|
|
|
gl->shader->set_mvp(gl, &gl->mvp_no_rot);
|
2014-06-13 15:46:53 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->overlays; i++)
|
2013-10-15 14:06:59 +00:00
|
|
|
{
|
2014-06-13 15:46:53 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->overlay_tex[i]);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 4 * i, 4);
|
2013-01-11 15:23:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 12:26:11 +00:00
|
|
|
glDisable(GL_BLEND);
|
2013-06-30 20:24:07 +00:00
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
2013-06-30 20:24:07 +00:00
|
|
|
gl->coords.color = gl->white_color_ptr;
|
2014-06-13 15:46:53 +00:00
|
|
|
gl->coords.vertices = 4;
|
2013-10-15 14:06:59 +00:00
|
|
|
if (gl->overlay_full_screen)
|
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
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
|
|
|
};
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static void gl_get_overlay_interface(void *data,
|
|
|
|
const video_overlay_interface_t **iface)
|
2012-12-20 10:16:22 +00:00
|
|
|
{
|
|
|
|
(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-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;
|
2013-07-06 20:10:09 +00:00
|
|
|
return gl->hw_render_fbo[(gl->tex_index + 1) % gl->textures];
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
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;
|
2014-10-02 08:27:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
|
|
|
|
|
|
|
return ctx_driver->get_proc_address(sym);
|
2013-03-28 00:11:32 +00:00
|
|
|
}
|
2013-03-11 23:00:42 +00:00
|
|
|
#endif
|
2013-03-10 19:12:50 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
2013-03-10 00:16:56 +00:00
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
switch (aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2014-10-01 14:59:43 +00:00
|
|
|
gfx_set_square_pixel_viewport(
|
|
|
|
g_extern.system.av_info.geometry.base_width,
|
|
|
|
g_extern.system.av_info.geometry.base_height);
|
2013-04-20 08:56:04 +00:00
|
|
|
break;
|
2013-03-10 00:16:56 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
case ASPECT_RATIO_CORE:
|
|
|
|
gfx_set_core_viewport();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
|
|
|
gfx_set_config_viewport();
|
|
|
|
break;
|
2013-03-10 00:16:56 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_extern.system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->keep_aspect = true;
|
|
|
|
gl->should_resize = true;
|
2013-03-10 00:16:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
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;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, false);
|
2013-04-07 12:05:39 +00:00
|
|
|
|
2014-06-10 00:15:29 +00:00
|
|
|
if (!gl->menu_texture)
|
2013-04-07 12:05:39 +00:00
|
|
|
{
|
2014-06-10 00:15:29 +00:00
|
|
|
glGenTextures(1, &gl->menu_texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
|
2013-08-15 22:30:54 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-04-07 12:05:39 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
else
|
2014-06-10 00:15:29 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
|
2013-04-07 12:05:39 +00:00
|
|
|
|
2014-06-10 00:15:29 +00:00
|
|
|
gl->menu_texture_alpha = alpha;
|
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));
|
|
|
|
|
|
|
|
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]);
|
2014-04-19 13:37:00 +00:00
|
|
|
context_bind_hw_render(gl, true);
|
2013-04-07 12:05:39 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->menu_texture_enable = state;
|
|
|
|
gl->menu_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;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
|
|
|
if (gl)
|
|
|
|
gl->should_resize = true;
|
2013-03-10 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static void gl_set_osd_msg(void *data, const char *msg,
|
|
|
|
const struct font_params *params)
|
2013-03-11 20:42:02 +00:00
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2014-06-07 19:18:58 +00:00
|
|
|
if (gl->font_driver && gl->font_handle)
|
|
|
|
{
|
|
|
|
context_bind_hw_render(gl, false);
|
|
|
|
gl->font_driver->render_msg(gl->font_handle, msg, params);
|
|
|
|
context_bind_hw_render(gl, true);
|
|
|
|
}
|
2013-03-11 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 17:53:07 +00:00
|
|
|
static void gl_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-10-02 08:27:36 +00:00
|
|
|
gfx_ctx_driver_t *ctx_driver = (gfx_ctx_driver_t*)gl->ctx_driver;
|
2014-05-28 22:43:47 +00:00
|
|
|
|
2014-10-02 08:27:36 +00:00
|
|
|
if (gl && ctx_driver->show_mouse)
|
|
|
|
ctx_driver->show_mouse(gl, state);
|
2013-03-29 17:53:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:23:08 +00:00
|
|
|
static struct gfx_shader *gl_get_current_shader(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-28 22:43:47 +00:00
|
|
|
return (gl && gl->shader) ? gl->shader->get_current_shader() : NULL;
|
2014-05-23 10:23:08 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 23:02:13 +00:00
|
|
|
|
2013-03-10 00:16:56 +00:00
|
|
|
static const video_poke_interface_t gl_poke_interface = {
|
2013-04-20 08:56:04 +00:00
|
|
|
NULL,
|
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-11-08 03:36:16 +00:00
|
|
|
#if defined(HAVE_MENU)
|
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,
|
2014-05-23 10:23:08 +00:00
|
|
|
NULL,
|
|
|
|
|
|
|
|
gl_get_current_shader,
|
2013-03-10 00:16:56 +00:00
|
|
|
};
|
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static void gl_get_poke_interface(void *data,
|
|
|
|
const video_poke_interface_t **iface)
|
2013-03-10 00:16:56 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &gl_poke_interface;
|
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
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
|
|
|
|
2012-09-21 19:20:30 +00:00
|
|
|
gl_set_shader,
|
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
|
|
|
|
|
|
|
gl_set_rotation,
|
2012-06-08 22:24:43 +00:00
|
|
|
|
2012-10-27 22:38:31 +00:00
|
|
|
gl_viewport_info,
|
2014-01-05 21:21:11 +00:00
|
|
|
|
2012-06-08 20:39:18 +00:00
|
|
|
gl_read_viewport,
|
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,
|
2014-10-01 23:02:13 +00:00
|
|
|
gl_wrap_type_to_enum,
|
2010-05-28 00:45:18 +00:00
|
|
|
};
|
2012-09-10 21:17:48 +00:00
|
|
|
|