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
|
2016-01-10 03:41:52 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-01-07 17:06:50 +00:00
|
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
2016-09-17 23:57:17 +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
|
|
|
|
|
2015-11-09 01:08:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-01 16:10:59 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-09 01:08:40 +00:00
|
|
|
#include <compat/strl.h>
|
2014-10-23 02:34:35 +00:00
|
|
|
#include <gfx/scaler/scaler.h>
|
2015-11-09 04:23:11 +00:00
|
|
|
#include <gfx/math/matrix_4x4.h>
|
2015-02-22 03:56:18 +00:00
|
|
|
#include <formats/image.h>
|
2015-03-15 03:37:54 +00:00
|
|
|
#include <retro_inline.h>
|
2015-11-23 23:05:37 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-12-26 06:59:15 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-05-10 17:03:53 +00:00
|
|
|
#include <libretro.h>
|
2015-11-23 23:05:37 +00:00
|
|
|
|
2016-10-24 02:06:05 +00:00
|
|
|
#include <gfx/gl_capabilities.h>
|
2016-11-08 14:35:24 +00:00
|
|
|
#include <gfx/video_frame.h>
|
2016-10-24 02:06:05 +00:00
|
|
|
|
2016-08-02 14:22:57 +00:00
|
|
|
#include "gl_renderchains/render_chain_gl.h"
|
2016-08-02 00:27:05 +00:00
|
|
|
|
2016-09-05 16:31:32 +00:00
|
|
|
#include "../../configuration.h"
|
2015-12-05 15:12:29 +00:00
|
|
|
#include "../../record/record_driver.h"
|
2016-05-10 06:53:14 +00:00
|
|
|
#include "../../performance_counters.h"
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2015-01-12 05:45:12 +00:00
|
|
|
#include "../../retroarch.h"
|
2016-09-01 16:10:59 +00:00
|
|
|
#include "../../runloop.h"
|
2015-12-20 19:52:23 +00:00
|
|
|
#include "../../verbosity.h"
|
|
|
|
#include "../common/gl_common.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_THREADS
|
|
|
|
#include "../video_thread_wrapper.h"
|
|
|
|
#endif
|
2011-01-07 16:59:53 +00:00
|
|
|
|
2015-04-03 18:36:19 +00:00
|
|
|
#include "../font_driver.h"
|
2015-01-12 20:53:04 +00:00
|
|
|
#include "../video_context_driver.h"
|
2011-01-06 22:15:49 +00:00
|
|
|
|
2012-10-16 17:43:05 +00:00
|
|
|
#ifdef HAVE_GLSL
|
2015-01-12 21:23:48 +00:00
|
|
|
#include "../drivers_shader/shader_glsl.h"
|
2010-11-12 22:09:43 +00:00
|
|
|
#endif
|
2010-11-12 21:32:38 +00:00
|
|
|
|
2014-11-04 17:59:25 +00:00
|
|
|
#ifdef GL_DEBUG
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/string_list.h>
|
2016-08-08 16:37:46 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_OPENGLES2) || defined(HAVE_OPENGLES3) || defined(HAVE_OPENGLES_3_1) || defined(HAVE_OPENGLES_3_2)
|
|
|
|
#define HAVE_GL_DEBUG_ES
|
|
|
|
#endif
|
2014-11-04 17:59:25 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-05 12:22:50 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "../../menu/menu_driver.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-19 00:49:08 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
2015-11-19 07:56:08 +00:00
|
|
|
#include "../common/win32_common.h"
|
2015-01-19 00:49:08 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-12 20:41:27 +00:00
|
|
|
#include "../video_shader_driver.h"
|
2012-11-14 22:11:48 +00:00
|
|
|
|
2015-06-02 15:31:43 +00:00
|
|
|
#ifndef GL_SYNC_GPU_COMMANDS_COMPLETE
|
|
|
|
#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_SYNC_FLUSH_COMMANDS_BIT
|
|
|
|
#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001
|
|
|
|
#endif
|
|
|
|
|
2016-09-05 05:59:26 +00:00
|
|
|
#ifdef IOS
|
|
|
|
/* There is no default frame buffer on iOS. */
|
|
|
|
void cocoagl_bind_game_view_fbo(void);
|
|
|
|
#define gl_bind_backbuffer() cocoagl_bind_game_view_fbo()
|
|
|
|
#else
|
|
|
|
#define gl_bind_backbuffer() glBindFramebuffer(RARCH_GL_FRAMEBUFFER, 0)
|
|
|
|
#endif
|
|
|
|
|
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.
|
2016-09-17 23:57:17 +00:00
|
|
|
* Texture coords have to be aligned
|
2014-10-01 21:50:58 +00:00
|
|
|
* 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,
|
|
|
|
};
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
static bool gl_shared_context_use = false;
|
2016-05-16 03:47:34 +00:00
|
|
|
|
2016-08-02 01:12:48 +00:00
|
|
|
void context_bind_hw_render(bool enable)
|
2016-05-16 03:55:42 +00:00
|
|
|
{
|
|
|
|
if (gl_shared_context_use)
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_bind_hw_render(&enable);
|
2015-12-08 08:44:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 09:55:21 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2016-08-01 13:40:02 +00:00
|
|
|
static void gl_free_overlay(gl_t *gl)
|
|
|
|
{
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
gl->overlays = 0;
|
|
|
|
}
|
|
|
|
|
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,
|
2016-08-01 13:40:02 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
|
|
|
GLfloat *vertex = NULL;
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (image > gl->overlays)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Invalid overlay id: %u\n", image);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertex = (GLfloat*)&gl->overlay_vertex_coord[image * 8];
|
|
|
|
|
|
|
|
/* Flipped, so we preserve top-down semantics. */
|
|
|
|
y = 1.0f - y;
|
|
|
|
h = -h;
|
|
|
|
|
|
|
|
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-20 10:16:22 +00:00
|
|
|
static void gl_overlay_tex_geom(void *data,
|
2013-10-15 14:06:59 +00:00
|
|
|
unsigned image,
|
2016-08-01 13:40:02 +00:00
|
|
|
GLfloat x, GLfloat y,
|
|
|
|
GLfloat w, GLfloat h)
|
|
|
|
{
|
|
|
|
GLfloat *tex = NULL;
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tex = (GLfloat*)&gl->overlay_tex_coord[image * 8];
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_render_overlay(gl_t *gl)
|
|
|
|
{
|
|
|
|
video_shader_ctx_mvp_t mvp;
|
|
|
|
video_shader_ctx_coords_t coords;
|
|
|
|
video_shader_ctx_info_t shader_info;
|
|
|
|
unsigned i, width, height;
|
|
|
|
|
|
|
|
if (!gl || !gl->overlay_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
if (gl->overlay_full_screen)
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
|
|
|
/* Ensure that we reset the attrib array. */
|
|
|
|
shader_info.data = gl;
|
|
|
|
shader_info.idx = VIDEO_SHADER_STOCK_BLEND;
|
|
|
|
shader_info.set_active = true;
|
|
|
|
|
2016-11-20 15:31:45 +00:00
|
|
|
video_shader_driver_use(shader_info);
|
2016-08-01 13:40:02 +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;
|
|
|
|
|
|
|
|
coords.handle_data = NULL;
|
|
|
|
coords.data = &gl->coords;
|
|
|
|
|
2016-11-20 15:48:54 +00:00
|
|
|
video_shader_driver_set_coords(coords);
|
2016-08-01 13:40:02 +00:00
|
|
|
|
|
|
|
mvp.data = gl;
|
|
|
|
mvp.matrix = &gl->mvp_no_rot;
|
|
|
|
|
2016-11-20 15:45:06 +00:00
|
|
|
video_shader_driver_set_mvp(mvp);
|
2016-08-01 13:40:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < gl->overlays; i++)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->overlay_tex[i]);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 4 * i, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
gl->coords.vertices = 4;
|
|
|
|
if (gl->overlay_full_screen)
|
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
|
|
|
}
|
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
|
|
|
|
2016-08-01 16:08:18 +00:00
|
|
|
static void gl_set_projection(gl_t *gl,
|
|
|
|
struct video_ortho *ortho, bool allow_rotate)
|
|
|
|
{
|
|
|
|
math_matrix_4x4 rot;
|
|
|
|
|
|
|
|
/* Calculate projection. */
|
|
|
|
matrix_4x4_ortho(&gl->mvp_no_rot, ortho->left, ortho->right,
|
|
|
|
ortho->bottom, ortho->top, ortho->znear, ortho->zfar);
|
|
|
|
|
|
|
|
if (!allow_rotate)
|
|
|
|
{
|
|
|
|
gl->mvp = gl->mvp_no_rot;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
matrix_4x4_rotate_z(&rot, M_PI * gl->rotation / 180.0f);
|
|
|
|
matrix_4x4_multiply(&gl->mvp, &rot, &gl->mvp_no_rot);
|
|
|
|
}
|
|
|
|
|
2016-08-02 00:38:46 +00:00
|
|
|
void gl_set_viewport(void *data, unsigned viewport_width,
|
2016-08-01 16:08:18 +00:00
|
|
|
unsigned viewport_height, bool force_full, bool allow_rotate)
|
|
|
|
{
|
|
|
|
gfx_ctx_aspect_t aspect_data;
|
|
|
|
unsigned width, height;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
float device_aspect = (float)viewport_width / viewport_height;
|
|
|
|
struct video_ortho ortho = {0, 1, 0, 1, -1, 1};
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
|
|
|
aspect_data.aspect = &device_aspect;
|
|
|
|
aspect_data.width = viewport_width;
|
|
|
|
aspect_data.height = viewport_height;
|
|
|
|
|
|
|
|
video_context_driver_translate_aspect(&aspect_data);
|
|
|
|
|
|
|
|
if (settings->video.scale_integer && !force_full)
|
|
|
|
{
|
|
|
|
video_viewport_get_scaled_integer(&gl->vp,
|
|
|
|
viewport_width, viewport_height,
|
|
|
|
video_driver_get_aspect_ratio(), gl->keep_aspect);
|
|
|
|
viewport_width = gl->vp.width;
|
|
|
|
viewport_height = gl->vp.height;
|
|
|
|
}
|
|
|
|
else if (gl->keep_aspect && !force_full)
|
|
|
|
{
|
|
|
|
float desired_aspect = video_driver_get_aspect_ratio();
|
|
|
|
|
|
|
|
#if defined(HAVE_MENU)
|
|
|
|
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
|
|
|
{
|
|
|
|
const struct video_viewport *custom = video_viewport_get_custom();
|
|
|
|
|
|
|
|
/* GL has bottom-left origin viewport. */
|
|
|
|
x = custom->x;
|
|
|
|
y = height - custom->y - custom->height;
|
|
|
|
viewport_width = custom->width;
|
|
|
|
viewport_height = custom->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
float delta;
|
|
|
|
|
|
|
|
if (fabsf(device_aspect - desired_aspect) < 0.0001f)
|
|
|
|
{
|
2016-09-17 23:57:17 +00:00
|
|
|
/* If the aspect ratios of screen and desired aspect
|
|
|
|
* ratio are sufficiently equal (floating point stuff),
|
2016-08-01 16:08:18 +00:00
|
|
|
* assume they are actually equal.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if (device_aspect > desired_aspect)
|
|
|
|
{
|
|
|
|
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
x = (int)roundf(viewport_width * (0.5f - delta));
|
|
|
|
viewport_width = (unsigned)roundf(2.0f * viewport_width * delta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
|
|
|
y = (int)roundf(viewport_height * (0.5f - delta));
|
|
|
|
viewport_height = (unsigned)roundf(2.0f * viewport_height * delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->vp.x = x;
|
|
|
|
gl->vp.y = y;
|
|
|
|
gl->vp.width = viewport_width;
|
|
|
|
gl->vp.height = viewport_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl->vp.x = gl->vp.y = 0;
|
|
|
|
gl->vp.width = viewport_width;
|
|
|
|
gl->vp.height = viewport_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(RARCH_MOBILE)
|
|
|
|
/* In portrait mode, we want viewport to gravitate to top of screen. */
|
|
|
|
if (device_aspect < 1.0f)
|
|
|
|
gl->vp.y *= 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
|
|
|
|
gl_set_projection(gl, &ortho, allow_rotate);
|
|
|
|
|
|
|
|
/* Set last backbuffer viewport. */
|
|
|
|
if (!force_full)
|
|
|
|
{
|
|
|
|
gl->vp_out_width = viewport_width;
|
|
|
|
gl->vp_out_height = viewport_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
RARCH_LOG("Setting viewport @ %ux%u\n", viewport_width, viewport_height);
|
|
|
|
#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
|
|
|
{
|
2016-02-14 17:41:45 +00:00
|
|
|
video_shader_ctx_init_t init_data;
|
2014-10-02 09:11:34 +00:00
|
|
|
enum rarch_shader_type type;
|
2015-06-13 00:49:29 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-09-17 23:57:17 +00:00
|
|
|
const char *shader_path = (settings->video.shader_enable
|
2016-04-28 17:52:25 +00:00
|
|
|
&& *settings->path.shader) ? settings->path.shader : NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-19 20:09:39 +00:00
|
|
|
type = video_shader_parse_type(shader_path,
|
2016-09-17 23:57:17 +00:00
|
|
|
gl_query_core_context_in_use()
|
2016-08-01 19:58:18 +00:00
|
|
|
? RARCH_SHADER_GLSL : DEFAULT_SHADER_TYPE);
|
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:
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
2016-04-16 03:36:09 +00:00
|
|
|
shader_path = NULL;
|
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:
|
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:
|
2016-04-16 03:36:09 +00:00
|
|
|
RARCH_ERR("[GL]: Not loading any shader, or couldn't find valid shader backend. Continuing without shaders.\n");
|
|
|
|
return true;
|
2013-06-30 20:58:22 +00:00
|
|
|
}
|
2016-04-16 03:14:39 +00:00
|
|
|
|
2016-08-01 19:58:18 +00:00
|
|
|
init_data.gl.core_context_enabled = gl_query_core_context_in_use();
|
2016-04-16 03:36:09 +00:00
|
|
|
init_data.shader_type = type;
|
|
|
|
init_data.shader = NULL;
|
|
|
|
init_data.data = gl;
|
|
|
|
init_data.path = shader_path;
|
2016-02-14 17:41:45 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (video_shader_driver_init(&init_data))
|
2016-04-16 03:36:09 +00:00
|
|
|
return true;
|
2016-02-14 17:41:45 +00:00
|
|
|
|
2016-04-16 03:36:09 +00:00
|
|
|
RARCH_ERR("[GL]: Failed to initialize shader, falling back to stock.\n");
|
2016-02-14 17:41:45 +00:00
|
|
|
|
2016-04-16 03:36:09 +00:00
|
|
|
init_data.shader = NULL;
|
|
|
|
init_data.path = NULL;
|
2013-06-05 08:42:39 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
return video_shader_driver_init(&init_data);
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 15:05:48 +00:00
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2016-05-16 03:50:39 +00:00
|
|
|
static void gl_disable_client_arrays(void)
|
2013-04-06 09:26:06 +00:00
|
|
|
{
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
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
|
|
|
|
2016-08-02 00:54:38 +00:00
|
|
|
GLenum min_filter_to_mag(GLenum type)
|
2014-08-24 23:39:48 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GL_LINEAR_MIPMAP_LINEAR:
|
|
|
|
return GL_LINEAR;
|
|
|
|
case GL_NEAREST_MIPMAP_NEAREST:
|
|
|
|
return GL_NEAREST;
|
|
|
|
default:
|
2015-07-20 23:45:32 +00:00
|
|
|
break;
|
2014-08-24 23:39:48 +00:00
|
|
|
}
|
2015-07-20 23:45:32 +00:00
|
|
|
|
|
|
|
return type;
|
2014-08-24 23:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 22:48:13 +00:00
|
|
|
#ifdef HAVE_FBO
|
2016-08-01 16:08:18 +00:00
|
|
|
static uintptr_t gl_get_current_framebuffer(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
return gl->hw_render_fbo[(gl->tex_index + 1) % gl->textures];
|
|
|
|
}
|
2012-01-31 23:14:04 +00:00
|
|
|
#endif
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2016-08-01 16:08:18 +00:00
|
|
|
static void gl_set_rotation(void *data, unsigned rotation)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
struct video_ortho ortho = {0, 1, 0, 1, -1, 1};
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->rotation = 90 * rotation;
|
|
|
|
gl_set_projection(gl, &ortho, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_video_mode(void *data, unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
|
|
|
gfx_ctx_mode_t mode;
|
|
|
|
|
|
|
|
mode.width = width;
|
|
|
|
mode.height = height;
|
|
|
|
mode.fullscreen = fullscreen;
|
|
|
|
|
|
|
|
video_context_driver_set_video_mode(&mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-02-13 01:21:54 +00:00
|
|
|
GLfloat xamt, yamt;
|
2014-10-01 14:59:43 +00:00
|
|
|
bool set_coords = false;
|
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
if ((width != gl->last_width[gl->tex_index] ||
|
2014-10-01 14:59:43 +00:00
|
|
|
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. */
|
|
|
|
|
2016-03-24 02:32:00 +00:00
|
|
|
gl->last_width[gl->tex_index] = width;
|
2011-07-03 13:39:35 +00:00
|
|
|
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,
|
2015-02-11 14:46:55 +00:00
|
|
|
video_pixel_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
|
|
|
}
|
2016-09-17 23:57:17 +00:00
|
|
|
else if ((width !=
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->last_width[(gl->tex_index + gl->textures - 1) % gl->textures]) ||
|
2016-09-17 23:57:17 +00:00
|
|
|
(height !=
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->last_height[(gl->tex_index + gl->textures - 1) % gl->textures]))
|
2014-10-01 21:50:58 +00:00
|
|
|
{
|
2016-09-17 23:57:17 +00:00
|
|
|
/* We might have used different texture coordinates
|
2014-10-01 21:50:58 +00:00
|
|
|
* 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
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
if (!set_coords)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xamt = (GLfloat)width / gl->tex_w;
|
|
|
|
yamt = (GLfloat)height / gl->tex_h;
|
|
|
|
set_texture_coords(gl->tex_info.coord, xamt, yamt);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-06-01 10:19:48 +00:00
|
|
|
|
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;
|
2016-03-24 02:32:00 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
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;
|
2016-09-17 23:57:17 +00:00
|
|
|
memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords));
|
2012-11-18 13:21:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:42:54 +00:00
|
|
|
static void gl_init_textures_reference(gl_t *gl, unsigned i,
|
|
|
|
GLenum internal_fmt, GLenum texture_fmt, GLenum texture_type)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->wrap_mode);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->wrap_mode);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_min_filter);
|
|
|
|
|
|
|
|
#ifdef HAVE_PSGL
|
|
|
|
glTextureReferenceSCE(GL_TEXTURE_2D, 1,
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->tex_w, gl->tex_h, 0,
|
2015-12-03 21:42:54 +00:00
|
|
|
internal_fmt,
|
|
|
|
gl->tex_w * gl->base_size,
|
|
|
|
gl->tex_w * gl->tex_h * i * gl->base_size);
|
|
|
|
#else
|
|
|
|
if (gl->egl_images)
|
|
|
|
return;
|
|
|
|
|
2016-12-14 15:29:37 +00:00
|
|
|
loadTexture(GL_TEXTURE_2D,
|
|
|
|
0, internal_fmt, gl->tex_w, gl->tex_h, 0, texture_type,
|
|
|
|
texture_fmt, gl->empty_buf ? gl->empty_buf : NULL);
|
2015-12-03 21:42:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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;
|
2015-04-14 19:58:39 +00:00
|
|
|
GLenum internal_fmt, texture_type = 0, texture_fmt = 0;
|
2015-04-12 17:29:38 +00:00
|
|
|
|
|
|
|
(void)texture_type;
|
|
|
|
(void)texture_fmt;
|
2015-04-09 16:17:52 +00:00
|
|
|
|
2016-08-01 14:47:24 +00:00
|
|
|
#if defined(HAVE_EGL) && defined(HAVE_OPENGLES)
|
2015-04-16 20:39:28 +00:00
|
|
|
/* Use regular textures if we use HW render. */
|
2016-08-01 14:01:21 +00:00
|
|
|
gl->egl_images = !gl->hw_render_use && gl_check_capability(GL_CAPS_EGLIMAGE) &&
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_init_image_buffer((void*)video);
|
2013-04-06 16:40:50 +00:00
|
|
|
#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,
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->tex_w * gl->tex_h * gl->base_size * gl->textures,
|
2016-02-14 15:59:21 +00:00
|
|
|
NULL, GL_STREAM_DRAW);
|
2013-04-06 16:40:50 +00:00
|
|
|
#endif
|
2012-11-10 22:56:04 +00:00
|
|
|
|
2015-04-12 17:29:38 +00:00
|
|
|
internal_fmt = gl->internal_fmt;
|
2013-05-25 22:32:39 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2015-04-12 17:29:38 +00:00
|
|
|
texture_type = gl->texture_type;
|
|
|
|
texture_fmt = gl->texture_fmt;
|
2013-05-25 22:32:39 +00:00
|
|
|
#endif
|
2013-05-18 19:53:26 +00:00
|
|
|
|
2016-12-07 18:22:24 +00:00
|
|
|
#ifdef HAVE_OPENGLES
|
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))
|
|
|
|
{
|
2016-08-01 14:01:21 +00:00
|
|
|
if (gl_check_capability(GL_CAPS_ARGB8))
|
2013-05-18 19:53:26 +00:00
|
|
|
{
|
2016-12-10 08:39:07 +00:00
|
|
|
#if !defined(HAVE_PSGL)
|
2016-12-07 18:22:24 +00:00
|
|
|
if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED))
|
|
|
|
internal_fmt = GL_RGBA8_OES;
|
|
|
|
else
|
2016-12-10 08:39:07 +00:00
|
|
|
#endif
|
2016-12-07 18:22:24 +00:00
|
|
|
internal_fmt = GL_RGBA;
|
2013-05-18 19:53:26 +00:00
|
|
|
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++)
|
2015-12-03 21:42:54 +00:00
|
|
|
gl_init_textures_reference(gl, i, internal_fmt,
|
|
|
|
texture_fmt, texture_type);
|
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
|
|
|
|
2015-03-15 03:37:54 +00:00
|
|
|
static INLINE void gl_copy_frame(gl_t *gl, const void *frame,
|
2014-10-01 21:50:58 +00:00
|
|
|
unsigned width, unsigned height, unsigned pitch)
|
2012-09-10 09:12:57 +00:00
|
|
|
{
|
2015-09-20 08:02:47 +00:00
|
|
|
static struct retro_perf_counter copy_frame = {0};
|
|
|
|
|
2016-05-16 07:58:45 +00:00
|
|
|
performance_counter_init(©_frame, "copy_frame");
|
2016-05-16 07:53:54 +00:00
|
|
|
performance_counter_start(©_frame);
|
2015-04-12 17:29:38 +00:00
|
|
|
|
2016-08-03 14:47:01 +00:00
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
{
|
|
|
|
unsigned h;
|
2016-09-17 23:57:17 +00:00
|
|
|
size_t buffer_addr = gl->tex_w * gl->tex_h *
|
2016-08-03 14:47:01 +00:00
|
|
|
gl->tex_index * gl->base_size;
|
|
|
|
size_t buffer_stride = gl->tex_w * gl->base_size;
|
|
|
|
const uint8_t *frame_copy = frame;
|
|
|
|
size_t frame_copy_size = width * gl->base_size;
|
|
|
|
|
|
|
|
uint8_t *buffer = (uint8_t*)glMapBuffer(
|
|
|
|
GL_TEXTURE_REFERENCE_BUFFER_SCE, GL_READ_WRITE) + buffer_addr;
|
|
|
|
for (h = 0; h < height; h++, buffer += buffer_stride, frame_copy += pitch)
|
|
|
|
memcpy(buffer, frame_copy, frame_copy_size);
|
|
|
|
|
|
|
|
glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE);
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_OPENGLES)
|
2016-08-01 15:23:01 +00:00
|
|
|
#if defined(HAVE_EGL)
|
2012-10-20 03:08:53 +00:00
|
|
|
if (gl->egl_images)
|
2012-09-15 13:17:34 +00:00
|
|
|
{
|
2016-02-13 22:35:47 +00:00
|
|
|
gfx_ctx_image_t img_info;
|
|
|
|
bool new_egl = false;
|
2012-10-20 03:08:53 +00:00
|
|
|
EGLImageKHR img = 0;
|
2016-02-13 22:35:47 +00:00
|
|
|
|
|
|
|
img_info.frame = frame;
|
|
|
|
img_info.width = width;
|
|
|
|
img_info.height = height;
|
|
|
|
img_info.pitch = pitch;
|
|
|
|
img_info.index = gl->tex_index;
|
|
|
|
img_info.rgb32 = (gl->base_size == 4);
|
2016-02-14 01:00:14 +00:00
|
|
|
img_info.handle = &img;
|
2016-02-13 22:35:47 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
new_egl = video_context_driver_write_to_image_buffer(&img_info);
|
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
|
|
|
{
|
2016-05-08 12:10:28 +00:00
|
|
|
bool use_rgba = video_driver_supports_rgba();
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,
|
2016-02-14 15:59:21 +00:00
|
|
|
video_pixel_get_alignment(width * gl->base_size));
|
2013-01-03 00:18:19 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Fallback for GLES devices without GL_BGRA_EXT. */
|
2015-11-23 22:58:40 +00:00
|
|
|
if (gl->base_size == 4 && use_rgba)
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
2016-05-04 14:32:24 +00:00
|
|
|
video_frame_convert_argb8888_to_abgr8888(
|
2016-05-04 02:22:41 +00:00
|
|
|
&gl->scaler,
|
|
|
|
gl->conv_buffer,
|
2014-10-01 21:50:58 +00:00
|
|
|
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;
|
2015-02-13 01:21:54 +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
|
|
|
{
|
2016-09-17 23:57:17 +00:00
|
|
|
/* Slow path - conv_buffer is preallocated
|
2014-10-01 15:15:02 +00:00
|
|
|
* 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;
|
2015-02-13 01:21:54 +00:00
|
|
|
uint8_t *dst = (uint8_t*)gl->conv_buffer;
|
|
|
|
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
|
|
|
|
2015-02-13 01:21:54 +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,
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->texture_fmt, data_buf);
|
2012-09-11 10:32:50 +00:00
|
|
|
}
|
2012-10-19 23:12:02 +00:00
|
|
|
}
|
2015-06-26 15:46:13 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
const GLvoid *data_buf = frame;
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(pitch));
|
2014-10-01 15:15:02 +00:00
|
|
|
|
2015-06-26 15:46:13 +00:00
|
|
|
if (gl->base_size == 2 && !gl->have_es2_compat)
|
|
|
|
{
|
2016-05-04 14:32:24 +00:00
|
|
|
/* Convert to 32-bit textures on desktop GL.
|
|
|
|
*
|
|
|
|
* It is *much* faster (order of magnitude on my setup)
|
2016-09-17 23:57:17 +00:00
|
|
|
* to use a custom SIMD-optimized conversion routine
|
2016-05-04 14:32:24 +00:00
|
|
|
* than letting GL do it. */
|
|
|
|
video_frame_convert_rgb16_to_rgb32(
|
2016-05-04 02:22:41 +00:00
|
|
|
&gl->scaler,
|
|
|
|
gl->conv_buffer,
|
|
|
|
frame,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
pitch);
|
2015-06-26 15:46:13 +00:00
|
|
|
data_buf = gl->conv_buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-06-26 15:46:13 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
}
|
2012-10-19 23:12:02 +00:00
|
|
|
#endif
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_stop(©_frame);
|
2012-09-10 09:12:57 +00:00
|
|
|
}
|
2012-09-10 08:29:50 +00:00
|
|
|
|
2016-02-14 19:01:39 +00:00
|
|
|
static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx)
|
2012-10-01 02:04:50 +00:00
|
|
|
{
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned width, height;
|
2016-02-14 19:01:39 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
2015-05-19 22:45:42 +00:00
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
2015-04-26 03:21:43 +00:00
|
|
|
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.data = gl;
|
|
|
|
shader_info.idx = idx;
|
|
|
|
shader_info.set_active = true;
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2016-11-20 15:31:45 +00:00
|
|
|
video_shader_driver_use(shader_info);
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_set_viewport(gl, width, height, false, true);
|
2012-10-01 02:04:50 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 00:27:05 +00:00
|
|
|
void gl_load_texture_data(
|
2016-08-01 16:10:34 +00:00
|
|
|
uint32_t id_data,
|
|
|
|
enum gfx_wrap_type wrap_type,
|
|
|
|
enum texture_filter_type filter_type,
|
|
|
|
unsigned alignment,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
const void *frame, unsigned base_size)
|
|
|
|
{
|
|
|
|
GLint mag_filter, min_filter;
|
|
|
|
bool want_mipmap = false;
|
|
|
|
bool use_rgba = video_driver_supports_rgba();
|
|
|
|
bool rgb32 = (base_size == (sizeof(uint32_t)));
|
|
|
|
GLenum wrap = gl_wrap_type_to_enum(wrap_type);
|
|
|
|
GLuint id = (GLuint)id_data;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2016-08-01 16:10:34 +00:00
|
|
|
if (!gl_check_capability(GL_CAPS_MIPMAP))
|
|
|
|
{
|
|
|
|
/* Assume no mipmapping support. */
|
|
|
|
switch (filter_type)
|
|
|
|
{
|
|
|
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
|
|
|
filter_type = TEXTURE_FILTER_LINEAR;
|
|
|
|
break;
|
|
|
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
|
|
|
filter_type = TEXTURE_FILTER_NEAREST;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (filter_type)
|
|
|
|
{
|
|
|
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
|
|
|
min_filter = GL_LINEAR_MIPMAP_NEAREST;
|
|
|
|
mag_filter = GL_LINEAR;
|
|
|
|
want_mipmap = true;
|
|
|
|
break;
|
|
|
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
|
|
|
min_filter = GL_NEAREST_MIPMAP_NEAREST;
|
|
|
|
mag_filter = GL_NEAREST;
|
|
|
|
want_mipmap = true;
|
|
|
|
break;
|
|
|
|
case TEXTURE_FILTER_NEAREST:
|
|
|
|
min_filter = GL_NEAREST;
|
|
|
|
mag_filter = GL_NEAREST;
|
|
|
|
break;
|
|
|
|
case TEXTURE_FILTER_LINEAR:
|
|
|
|
default:
|
|
|
|
min_filter = GL_LINEAR;
|
|
|
|
mag_filter = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0,
|
|
|
|
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
width, height, 0,
|
|
|
|
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
|
|
|
|
(rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame);
|
|
|
|
|
|
|
|
if (want_mipmap && gl_check_capability(GL_CAPS_MIPMAP))
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_MENU)
|
|
|
|
static void gl_set_texture_frame(void *data,
|
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
enum texture_filter_type menu_filter;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
unsigned base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context_bind_hw_render(false);
|
|
|
|
|
|
|
|
menu_filter = settings->menu.linear_filter ? TEXTURE_FILTER_LINEAR : TEXTURE_FILTER_NEAREST;
|
|
|
|
|
|
|
|
if (!gl->menu_texture)
|
|
|
|
glGenTextures(1, &gl->menu_texture);
|
|
|
|
|
|
|
|
|
|
|
|
gl_load_texture_data(gl->menu_texture,
|
|
|
|
RARCH_WRAP_EDGE, menu_filter,
|
|
|
|
video_pixel_get_alignment(width * base_size),
|
|
|
|
width, height, frame,
|
|
|
|
base_size);
|
|
|
|
|
|
|
|
gl->menu_texture_alpha = alpha;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
|
|
|
|
|
|
|
context_bind_hw_render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_texture_enable(void *data, bool state, bool full_screen)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->menu_texture_enable = state;
|
|
|
|
gl->menu_texture_full_screen = full_screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_set_osd_msg(void *data, const char *msg,
|
|
|
|
const struct font_params *params, void *font)
|
|
|
|
{
|
|
|
|
font_driver_render_msg(font, msg, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
video_context_driver_show_mouse(&state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct video_shader *gl_get_current_shader(void *data)
|
|
|
|
{
|
|
|
|
video_shader_ctx_t shader_info;
|
|
|
|
|
|
|
|
video_shader_driver_direct_get_current_shader(&shader_info);
|
|
|
|
|
|
|
|
return shader_info.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_GL_ASYNC_READBACK)
|
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
|
|
|
{
|
2015-09-20 08:02:47 +00:00
|
|
|
static struct retro_perf_counter async_readback = {0};
|
|
|
|
|
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,
|
2015-02-11 14:46:55 +00:00
|
|
|
video_pixel_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. */
|
2016-05-16 07:58:45 +00:00
|
|
|
performance_counter_init(&async_readback, "async_readback");
|
2016-05-16 07:53:54 +00:00
|
|
|
performance_counter_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
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_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
|
|
|
|
|
2015-03-15 03:37:54 +00:00
|
|
|
static INLINE void gl_draw_texture(gl_t *gl)
|
2013-02-28 01:20:29 +00:00
|
|
|
{
|
2016-02-14 18:43:47 +00:00
|
|
|
video_shader_ctx_mvp_t mvp;
|
2016-02-14 17:59:42 +00:00
|
|
|
video_shader_ctx_coords_t coords;
|
2016-02-14 19:01:39 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned width, height;
|
2015-06-30 17:07:53 +00:00
|
|
|
GLfloat color[16];
|
|
|
|
|
|
|
|
color[ 0] = 1.0f;
|
|
|
|
color[ 1] = 1.0f;
|
|
|
|
color[ 2] = 1.0f;
|
|
|
|
color[ 3] = gl->menu_texture_alpha;
|
|
|
|
color[ 4] = 1.0f;
|
|
|
|
color[ 5] = 1.0f;
|
|
|
|
color[ 6] = 1.0f;
|
|
|
|
color[ 7] = gl->menu_texture_alpha;
|
|
|
|
color[ 8] = 1.0f;
|
|
|
|
color[ 9] = 1.0f;
|
|
|
|
color[10] = 1.0f;
|
|
|
|
color[11] = gl->menu_texture_alpha;
|
|
|
|
color[12] = 1.0f;
|
|
|
|
color[13] = 1.0f;
|
|
|
|
color[14] = 1.0f;
|
|
|
|
color[15] = gl->menu_texture_alpha;
|
2015-05-19 22:45:42 +00:00
|
|
|
|
2015-01-10 02:48:03 +00:00
|
|
|
if (!gl->menu_texture)
|
|
|
|
return;
|
2013-02-28 01:20:29 +00:00
|
|
|
|
2015-05-19 22:45:42 +00:00
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->coords.vertex = vertexes_flipped;
|
2013-04-07 12:05:39 +00:00
|
|
|
gl->coords.tex_coord = tex_coords;
|
2015-02-13 01:21:54 +00:00
|
|
|
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
|
|
|
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.data = gl;
|
2016-04-15 23:50:20 +00:00
|
|
|
shader_info.idx = VIDEO_SHADER_STOCK_BLEND;
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.set_active = true;
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2016-11-20 15:31:45 +00:00
|
|
|
video_shader_driver_use(shader_info);
|
2016-02-14 17:59:42 +00:00
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->coords.vertices = 4;
|
2016-02-14 17:59:42 +00:00
|
|
|
|
|
|
|
coords.handle_data = NULL;
|
|
|
|
coords.data = &gl->coords;
|
|
|
|
|
2016-11-20 15:48:54 +00:00
|
|
|
video_shader_driver_set_coords(coords);
|
2016-02-14 17:59:42 +00:00
|
|
|
|
2016-03-24 02:32:00 +00:00
|
|
|
mvp.data = gl;
|
|
|
|
mvp.matrix = &gl->mvp_no_rot;
|
2016-02-14 18:43:47 +00:00
|
|
|
|
2016-11-20 15:45:06 +00:00
|
|
|
video_shader_driver_set_mvp(mvp);
|
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
|
|
|
{
|
2015-05-19 22:45:42 +00:00
|
|
|
glViewport(0, 0, width, height);
|
2013-04-13 14:48:03 +00:00
|
|
|
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);
|
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
2014-10-01 18:37:52 +00:00
|
|
|
gl->coords.tex_coord = gl->tex_info.coord;
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->coords.color = gl->white_color_ptr;
|
2013-02-28 01:20:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-29 00:22:29 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
static bool gl_frame(void *data, const void *frame,
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned frame_width, unsigned frame_height,
|
2015-08-03 21:01:07 +00:00
|
|
|
uint64_t frame_count,
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned pitch, const char *msg)
|
2012-01-31 23:14:04 +00:00
|
|
|
{
|
2016-02-14 18:43:47 +00:00
|
|
|
video_shader_ctx_mvp_t mvp;
|
2016-02-14 17:59:42 +00:00
|
|
|
video_shader_ctx_coords_t coords;
|
2016-02-14 17:09:12 +00:00
|
|
|
video_shader_ctx_params_t params;
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned width, height;
|
2016-05-10 00:39:09 +00:00
|
|
|
struct video_tex_info feedback_info;
|
2016-02-14 19:01:39 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
2015-09-20 08:02:47 +00:00
|
|
|
static struct retro_perf_counter frame_run = {0};
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-10 02:48:03 +00:00
|
|
|
|
2016-05-16 07:58:45 +00:00
|
|
|
performance_counter_init(&frame_run, "frame_run");
|
2016-05-16 07:53:54 +00:00
|
|
|
performance_counter_start(&frame_run);
|
2012-10-20 03:08:53 +00:00
|
|
|
|
2016-02-13 20:15:18 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2015-05-19 22:45:42 +00:00
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2013-06-22 13:06:56 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_OPENGLES
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
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
|
|
|
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.data = gl;
|
|
|
|
shader_info.idx = 1;
|
|
|
|
shader_info.set_active = true;
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2016-11-20 15:31:45 +00:00
|
|
|
video_shader_driver_use(shader_info);
|
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. */
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_set_viewport(gl, width, height, false, true);
|
2013-04-10 18:42:54 +00:00
|
|
|
#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)
|
|
|
|
{
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_recompute_pass_sizes(gl, frame_width, frame_height,
|
2014-10-01 18:06:40 +00:00
|
|
|
gl->vp_out_width, gl->vp_out_height);
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_start_render(gl);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
if (gl->should_resize)
|
|
|
|
{
|
2016-02-14 01:15:43 +00:00
|
|
|
gfx_ctx_mode_t mode;
|
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
gl->should_resize = false;
|
2015-04-10 06:33:07 +00:00
|
|
|
|
2016-03-24 02:32:00 +00:00
|
|
|
mode.width = width;
|
|
|
|
mode.height = height;
|
2016-02-14 01:15:43 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_set_resize(&mode);
|
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);
|
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
/* Go back to what we're supposed to do,
|
2014-10-01 17:34:55 +00:00
|
|
|
* render to FBO #0. */
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_start_render(gl);
|
2014-10-01 17:34:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_set_viewport(gl, width, height, false, true);
|
2012-01-31 23:14:04 +00:00
|
|
|
}
|
2011-03-12 15:33:01 +00:00
|
|
|
|
2016-04-16 05:16:32 +00:00
|
|
|
if (frame)
|
|
|
|
gl->tex_index = ((gl->tex_index + 1) % gl->textures);
|
|
|
|
|
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. */
|
2016-09-17 23:57:17 +00:00
|
|
|
if (frame)
|
2014-10-01 16:23:02 +00:00
|
|
|
{
|
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
|
|
|
|
{
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_update_input_size(gl, frame_width, frame_height, pitch, true);
|
|
|
|
gl_copy_frame(gl, frame, frame_width, frame_height, pitch);
|
2013-03-27 15:15:15 +00:00
|
|
|
}
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
/* No point regenerating mipmaps
|
2014-10-01 16:23:02 +00:00
|
|
|
* if there are no new frames. */
|
2016-08-01 14:01:21 +00:00
|
|
|
if (gl->tex_mipmap && gl_check_capability(GL_CAPS_MIPMAP))
|
2014-10-01 16:23:02 +00:00
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
}
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
/* Have to reset rendering state which libretro core
|
2014-10-01 16:23:02 +00:00
|
|
|
* could easily have overridden. */
|
2013-09-07 13:04:40 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->hw_render_fbo_init)
|
|
|
|
{
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_update_input_size(gl, frame_width, frame_height, pitch, false);
|
2013-09-07 13:04:40 +00:00
|
|
|
if (!gl->fbo_inited)
|
|
|
|
{
|
|
|
|
gl_bind_backbuffer();
|
2015-05-19 22:45:42 +00:00
|
|
|
gl_set_viewport(gl, width, height, false, true);
|
2013-09-07 13:04:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2016-08-01 19:58:18 +00:00
|
|
|
if (!gl_query_core_context_in_use())
|
2013-06-23 09:55:21 +00:00
|
|
|
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];
|
2015-05-19 22:45:42 +00:00
|
|
|
gl->tex_info.input_size[0] = frame_width;
|
|
|
|
gl->tex_info.input_size[1] = frame_height;
|
2014-10-01 18:37:52 +00:00
|
|
|
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
|
|
|
|
2015-09-21 09:50:02 +00:00
|
|
|
feedback_info = gl->tex_info;
|
|
|
|
|
2015-10-11 14:54:01 +00:00
|
|
|
#ifdef HAVE_FBO
|
2015-08-30 16:37:41 +00:00
|
|
|
if (gl->fbo_feedback_enable)
|
|
|
|
{
|
2016-05-10 00:34:36 +00:00
|
|
|
const struct video_fbo_rect *rect = &gl->fbo_rect[gl->fbo_feedback_pass];
|
2016-03-24 02:32:00 +00:00
|
|
|
GLfloat xamt = (GLfloat)rect->img_width / rect->width;
|
|
|
|
GLfloat yamt = (GLfloat)rect->img_height / rect->height;
|
2015-08-30 16:37:41 +00:00
|
|
|
|
2016-03-24 02:32:00 +00:00
|
|
|
feedback_info.tex = gl->fbo_feedback_texture;
|
|
|
|
feedback_info.input_size[0] = rect->img_width;
|
|
|
|
feedback_info.input_size[1] = rect->img_height;
|
|
|
|
feedback_info.tex_size[0] = rect->width;
|
|
|
|
feedback_info.tex_size[1] = rect->height;
|
2015-08-30 16:37:41 +00:00
|
|
|
|
|
|
|
set_texture_coords(feedback_info.coord, xamt, yamt);
|
|
|
|
}
|
2015-10-11 14:54:01 +00:00
|
|
|
#endif
|
2015-08-30 16:37:41 +00:00
|
|
|
|
2012-01-31 23:14:04 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2014-08-27 21:40:19 +00:00
|
|
|
|
2016-02-14 17:09:12 +00:00
|
|
|
params.data = gl;
|
|
|
|
params.width = frame_width;
|
|
|
|
params.height = frame_height;
|
|
|
|
params.tex_width = gl->tex_w;
|
|
|
|
params.tex_height = gl->tex_h;
|
|
|
|
params.out_width = gl->vp.width;
|
|
|
|
params.out_height = gl->vp.height;
|
|
|
|
params.frame_counter = (unsigned int)frame_count;
|
|
|
|
params.info = &gl->tex_info;
|
|
|
|
params.prev_info = gl->prev_info;
|
|
|
|
params.feedback_info = &feedback_info;
|
|
|
|
params.fbo_info = NULL;
|
|
|
|
params.fbo_info_cnt = 0;
|
|
|
|
|
2016-11-20 15:40:08 +00:00
|
|
|
video_shader_driver_set_parameters(params);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2014-06-08 10:37:32 +00:00
|
|
|
gl->coords.vertices = 4;
|
2016-02-14 17:59:42 +00:00
|
|
|
coords.handle_data = NULL;
|
|
|
|
coords.data = &gl->coords;
|
|
|
|
|
2016-11-20 15:48:54 +00:00
|
|
|
video_shader_driver_set_coords(coords);
|
2016-02-14 17:59:42 +00:00
|
|
|
|
2016-02-14 18:43:47 +00:00
|
|
|
mvp.data = gl;
|
|
|
|
mvp.matrix = &gl->mvp;
|
|
|
|
|
2016-11-20 15:45:06 +00:00
|
|
|
video_shader_driver_set_mvp(mvp);
|
2016-02-14 18:43:47 +00:00
|
|
|
|
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)
|
2016-08-02 00:38:46 +00:00
|
|
|
gl_renderchain_render(gl, frame_count, &gl->tex_info, &feedback_info);
|
2011-03-23 22:48:13 +00:00
|
|
|
#endif
|
2011-03-06 15:52:49 +00:00
|
|
|
|
2016-08-01 22:42:03 +00:00
|
|
|
/* Set prev textures. */
|
|
|
|
gl_renderchain_bind_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)
|
2015-03-22 04:27:19 +00:00
|
|
|
if (gl->menu_texture_enable)
|
2015-07-01 21:46:39 +00:00
|
|
|
{
|
2015-12-06 17:28:37 +00:00
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_FRAME, NULL);
|
2015-07-01 21:46:39 +00:00
|
|
|
|
|
|
|
if (gl->menu_texture_enable)
|
|
|
|
gl_draw_texture(gl);
|
|
|
|
}
|
2013-02-28 01:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-20 16:51:16 +00:00
|
|
|
if (msg)
|
2015-12-05 09:49:28 +00:00
|
|
|
font_driver_render_msg(NULL, msg, NULL);
|
2011-01-22 23:27:20 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2016-02-29 00:43:40 +00:00
|
|
|
gl_render_overlay(gl);
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2012-12-19 12:26:11 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_update_window_title();
|
2012-05-27 20:39:29 +00:00
|
|
|
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_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)
|
|
|
|
{
|
2016-04-15 05:37:06 +00:00
|
|
|
shader_info.data = gl;
|
|
|
|
shader_info.idx = 0;
|
|
|
|
shader_info.set_active = true;
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2016-11-20 15:31:45 +00:00
|
|
|
video_shader_driver_use(shader_info);
|
2016-02-14 19:01:39 +00:00
|
|
|
|
2013-03-28 11:13:41 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2016-05-16 03:50:39 +00:00
|
|
|
gl_disable_client_arrays();
|
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
|
2015-09-26 10:57:52 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Disable BFI during fast forward, slow-motion,
|
|
|
|
* and pause to prevent flicker. */
|
2015-09-26 11:04:07 +00:00
|
|
|
if (
|
|
|
|
settings->video.black_frame_insertion
|
2016-05-08 21:12:04 +00:00
|
|
|
&& !input_driver_is_nonblock_state()
|
2016-02-29 00:33:14 +00:00
|
|
|
&& !runloop_ctl(RUNLOOP_CTL_IS_SLOWMOTION, NULL)
|
2016-02-29 00:29:49 +00:00
|
|
|
&& !runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
|
2014-08-28 16:57:02 +00:00
|
|
|
{
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_swap_buffers();
|
2014-08-28 16:57:02 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_swap_buffers();
|
2010-05-28 00:45:18 +00:00
|
|
|
|
2016-09-05 19:43:02 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->video.hard_sync && gl->have_sync)
|
2013-05-03 12:04:29 +00:00
|
|
|
{
|
2015-09-20 08:02:47 +00:00
|
|
|
static struct retro_perf_counter gl_fence = {0};
|
|
|
|
|
2016-05-16 07:58:45 +00:00
|
|
|
performance_counter_init(&gl_fence, "gl_fence");
|
2016-05-16 07:53:54 +00:00
|
|
|
performance_counter_start(&gl_fence);
|
2013-05-03 12:04:29 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->fences[gl->fence_count++] =
|
2014-10-01 21:50:58 +00:00
|
|
|
glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
2013-05-26 11:43:24 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
while (gl->fence_count > settings->video.hard_sync_frames)
|
2013-05-26 11:43:24 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_stop(&gl_fence);
|
2013-05-03 12:04:29 +00:00
|
|
|
}
|
2016-09-05 19:43:02 +00:00
|
|
|
#endif
|
2013-05-03 12:04:29 +00:00
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindVertexArray(0);
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2014-04-19 13:37:00 +00:00
|
|
|
|
2010-05-28 00:45:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-15 14:06:59 +00:00
|
|
|
|
2016-05-16 03:47:34 +00:00
|
|
|
static void gl_destroy_resources(gl_t *gl)
|
|
|
|
{
|
|
|
|
if (gl)
|
|
|
|
{
|
|
|
|
if (gl->empty_buf)
|
|
|
|
free(gl->empty_buf);
|
|
|
|
if (gl->conv_buffer)
|
|
|
|
free(gl->conv_buffer);
|
|
|
|
free(gl);
|
|
|
|
}
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
gl_shared_context_use = false;
|
2016-09-05 05:04:56 +00:00
|
|
|
gl_query_core_context_unset();
|
2016-05-16 03:47:34 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (!gl)
|
2012-05-27 20:39:29 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2016-09-05 19:43:02 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2013-05-26 11:43:24 +00:00
|
|
|
if (gl->have_sync)
|
|
|
|
{
|
2013-10-22 19:26:33 +00:00
|
|
|
unsigned i;
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2013-10-22 19:26:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-09-05 19:43:02 +00:00
|
|
|
#endif
|
2013-05-26 11:43:24 +00:00
|
|
|
|
2016-10-18 23:07:00 +00:00
|
|
|
font_driver_free_osd();
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_deinit();
|
2012-09-13 15:05:48 +00:00
|
|
|
|
|
|
|
#ifndef NO_GL_FF_VERTEX
|
2016-05-16 03:50:39 +00:00
|
|
|
gl_disable_client_arrays();
|
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
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_free(gl);
|
2013-03-30 14:39:00 +00:00
|
|
|
#endif
|
2012-01-31 23:14:04 +00:00
|
|
|
|
2013-06-22 13:06:56 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
2013-06-22 13:06:56 +00:00
|
|
|
{
|
2013-07-05 16:15:42 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
glDeleteVertexArrays(1, &gl->vao);
|
2013-06-22 13:06:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_free();
|
2015-05-02 20:37:27 +00:00
|
|
|
|
2016-05-16 03:47:34 +00:00
|
|
|
gl_destroy_resources(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)
|
|
|
|
{
|
2016-03-24 02:32:00 +00:00
|
|
|
unsigned interval = 0;
|
2015-04-09 16:17:52 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
settings_t *settings = config_get_ptr();
|
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
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2016-02-13 19:45:45 +00:00
|
|
|
|
2016-03-24 02:32:00 +00:00
|
|
|
if (!state)
|
|
|
|
interval = settings->video.swap_interval;
|
2016-02-13 19:45:45 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_swap_interval(&interval);
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2010-08-16 16:40:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 07:37:26 +00:00
|
|
|
static bool resolve_extensions(gl_t *gl, const char *context_ident)
|
2012-09-11 10:32:50 +00:00
|
|
|
{
|
2015-09-29 15:35:28 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-08-01 14:25:02 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2016-05-08 12:00:51 +00:00
|
|
|
struct retro_hw_render_callback *hwr =
|
|
|
|
video_driver_get_hw_context();
|
2016-08-01 14:25:02 +00:00
|
|
|
|
2016-09-05 05:04:56 +00:00
|
|
|
gl_query_core_context_set(hwr->context_type == RETRO_HW_CONTEXT_OPENGL_CORE);
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
2013-06-22 13:06:56 +00:00
|
|
|
{
|
2014-12-03 20:21:55 +00:00
|
|
|
RARCH_LOG("[GL]: Using Core GL context.\n");
|
2016-08-01 14:01:21 +00:00
|
|
|
if (!gl_check_capability(GL_CAPS_VAO))
|
2014-12-03 20:21:55 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Failed to initialize VAOs.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 04:14:32 +00:00
|
|
|
glGenVertexArrays(1, &gl->vao);
|
2013-06-22 13:06:56 +00:00
|
|
|
}
|
2014-01-01 20:42:31 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* GL_RGB565 internal format support.
|
2016-09-17 23:57:17 +00:00
|
|
|
* Even though ES2 support is claimed, the format
|
2014-10-01 21:50:58 +00:00
|
|
|
* is not supported on older ATI catalyst drivers.
|
|
|
|
*
|
2016-09-17 23:57:17 +00:00
|
|
|
* The speed gain from using GL_RGB565 is worth
|
2014-10-01 21:50:58 +00:00
|
|
|
* adding some workarounds for.
|
|
|
|
*/
|
2016-08-01 15:28:43 +00:00
|
|
|
gl->have_es2_compat = gl_check_capability(GL_CAPS_ES2_COMPAT);
|
2016-08-01 15:23:01 +00:00
|
|
|
gl->have_full_npot_support = gl_check_capability(GL_CAPS_FULL_NPOT_SUPPORT);
|
2013-06-22 13:06:56 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-05 19:43:02 +00:00
|
|
|
#ifdef HAVE_GL_SYNC
|
2016-08-01 14:01:21 +00:00
|
|
|
gl->have_sync = gl_check_capability(GL_CAPS_SYNC);
|
2015-03-20 21:08:36 +00:00
|
|
|
if (gl->have_sync && settings->video.hard_sync)
|
2013-05-03 12:04:29 +00:00
|
|
|
RARCH_LOG("[GL]: Using ARB_sync to reduce latency.\n");
|
2016-09-05 19:43:02 +00:00
|
|
|
#endif
|
2013-05-03 12:04:29 +00:00
|
|
|
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_unset_rgba();
|
2016-08-03 15:07:38 +00:00
|
|
|
#if defined(HAVE_OPENGLES) && !defined(HAVE_PSGL)
|
2016-08-01 15:23:01 +00:00
|
|
|
gl->have_full_npot_support = gl_check_capability(GL_CAPS_FULL_NPOT_SUPPORT);
|
2015-11-28 00:21:04 +00:00
|
|
|
|
2016-08-01 15:40:53 +00:00
|
|
|
if (!gl_check_capability(GL_CAPS_BGRA8888))
|
2012-09-29 18:06:48 +00:00
|
|
|
{
|
2016-05-08 12:10:28 +00:00
|
|
|
video_driver_set_rgba();
|
2013-01-03 00:18:19 +00:00
|
|
|
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-10-01 21:50:58 +00:00
|
|
|
/* GLES3 has unpack_subimage and sRGB in core. */
|
2016-08-01 14:36:57 +00:00
|
|
|
gl->support_unpack_row_length = gl_check_capability(GL_CAPS_UNPACK_ROW_LENGTH);
|
2016-08-01 15:40:53 +00:00
|
|
|
gl->has_srgb_fbo_gles3 = gl_check_capability(GL_CAPS_SRGB_FBO_ES3);
|
2014-10-01 21:50:58 +00:00
|
|
|
|
2016-08-01 15:40:53 +00:00
|
|
|
/* TODO/FIXME - No extensions for float FBO currently. */
|
2014-02-11 05:07:00 +00:00
|
|
|
#endif
|
2012-09-29 18:06:48 +00:00
|
|
|
|
2016-09-05 05:04:56 +00:00
|
|
|
gl->has_fp_fbo = gl_check_capability(GL_CAPS_FP_FBO);
|
|
|
|
if (settings->video.force_srgb_disable)
|
|
|
|
gl->has_srgb_fbo = false;
|
|
|
|
else
|
|
|
|
gl->has_srgb_fbo = gl_check_capability(GL_CAPS_SRGB_FBO);
|
2016-08-01 15:28:43 +00:00
|
|
|
|
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");
|
2016-08-01 15:40:53 +00:00
|
|
|
|
2016-08-01 19:58:18 +00:00
|
|
|
if (gl_query_core_context_in_use())
|
2013-08-14 12:00:21 +00:00
|
|
|
{
|
|
|
|
#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);
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2013-08-14 12:00:21 +00:00
|
|
|
if (ext)
|
|
|
|
{
|
2015-01-11 18:52:02 +00:00
|
|
|
size_t i;
|
2013-08-14 12:00:21 +00:00
|
|
|
struct string_list *list = string_split(ext, " ");
|
2015-01-11 18:52:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < list->size; i++)
|
2013-08-14 12:00:21 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-15 03:37:54 +00:00
|
|
|
static INLINE void gl_set_texture_fmts(gl_t *gl, bool rgb32)
|
2013-01-03 00:18:19 +00:00
|
|
|
{
|
2015-02-11 15:11:05 +00:00
|
|
|
gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT16;
|
|
|
|
gl->texture_type = RARCH_GL_TEXTURE_TYPE16;
|
|
|
|
gl->texture_fmt = RARCH_GL_FORMAT16;
|
|
|
|
gl->base_size = sizeof(uint16_t);
|
2013-01-03 00:18:19 +00:00
|
|
|
|
2015-02-11 15:11:05 +00:00
|
|
|
if (rgb32)
|
2013-01-03 00:18:19 +00:00
|
|
|
{
|
2016-05-08 12:00:51 +00:00
|
|
|
bool use_rgba = video_driver_supports_rgba();
|
2015-11-23 22:58:40 +00:00
|
|
|
|
2015-02-11 15:11:05 +00:00
|
|
|
gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT32;
|
|
|
|
gl->texture_type = RARCH_GL_TEXTURE_TYPE32;
|
|
|
|
gl->texture_fmt = RARCH_GL_FORMAT32;
|
|
|
|
gl->base_size = sizeof(uint32_t);
|
2014-01-01 20:42:31 +00:00
|
|
|
|
2015-11-23 22:58:40 +00:00
|
|
|
if (use_rgba)
|
2015-02-11 15:11:05 +00:00
|
|
|
{
|
|
|
|
gl->internal_fmt = GL_RGBA;
|
|
|
|
gl->texture_type = GL_RGBA;
|
|
|
|
}
|
|
|
|
}
|
2014-01-01 20:42:31 +00:00
|
|
|
#ifndef HAVE_OPENGLES
|
2015-02-11 15:11:05 +00:00
|
|
|
else if (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;
|
2016-02-14 15:59:21 +00:00
|
|
|
gl->texture_fmt = RARCH_GL_FORMAT16_565;
|
2014-01-01 20:42:31 +00:00
|
|
|
}
|
|
|
|
#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;
|
2015-11-18 02:08:19 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
bool *recording_enabled = recording_is_enabled();
|
2016-05-05 00:07:33 +00:00
|
|
|
#ifndef HAVE_OPENGLES3
|
|
|
|
struct scaler_ctx *scaler = NULL;
|
|
|
|
#endif
|
2015-11-18 02:08:19 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Only bother with this if we're doing GPU recording.
|
2016-09-17 23:57:17 +00:00
|
|
|
* Check recording_is_enabled() and not
|
|
|
|
* driver.recording_data, because recording is
|
2014-10-01 21:50:58 +00:00
|
|
|
* not initialized yet.
|
|
|
|
*/
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->pbo_readback_enable = settings->video.gpu_record
|
2015-11-18 02:08:19 +00:00
|
|
|
&& *recording_enabled;
|
|
|
|
|
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]);
|
2016-09-17 23:57:17 +00:00
|
|
|
glBufferData(GL_PIXEL_PACK_BUFFER, gl->vp.width *
|
2014-10-01 21:50:58 +00:00
|
|
|
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
|
2015-01-10 02:48:03 +00:00
|
|
|
scaler = &gl->pbo_readback_scaler;
|
2012-11-21 21:12:56 +00:00
|
|
|
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;
|
2014-12-03 17:36:25 +00:00
|
|
|
RARCH_ERR("Failed to initialize 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
|
|
|
{
|
2016-03-20 04:24:05 +00:00
|
|
|
enum gfx_ctx_api api;
|
2016-05-05 00:07:33 +00:00
|
|
|
const char *api_name = NULL;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2016-08-01 15:46:02 +00:00
|
|
|
struct retro_hw_render_callback *hwr = video_driver_get_hw_context();
|
|
|
|
unsigned major = hwr->version_major;
|
|
|
|
unsigned minor = hwr->version_minor;
|
2016-03-20 04:24:05 +00:00
|
|
|
|
2013-02-23 13:49:49 +00:00
|
|
|
#ifdef HAVE_OPENGLES
|
2016-05-05 00:07:33 +00:00
|
|
|
api = GFX_CTX_OPENGL_ES_API;
|
|
|
|
api_name = "OpenGL ES 2.0";
|
|
|
|
|
2016-03-04 19:49:55 +00:00
|
|
|
if (hwr->context_type == RETRO_HW_CONTEXT_OPENGLES3)
|
2013-12-13 13:19:25 +00:00
|
|
|
{
|
2016-05-05 00:07:33 +00:00
|
|
|
major = 3;
|
|
|
|
minor = 0;
|
2013-12-13 13:19:25 +00:00
|
|
|
api_name = "OpenGL ES 3.0";
|
|
|
|
}
|
2016-03-04 19:49:55 +00:00
|
|
|
else if (hwr->context_type == RETRO_HW_CONTEXT_OPENGLES_VERSION)
|
2014-05-03 13:21:14 +00:00
|
|
|
api_name = "OpenGL ES 3.1+";
|
2013-02-23 13:49:49 +00:00
|
|
|
#else
|
2016-05-05 00:07:33 +00:00
|
|
|
api = GFX_CTX_OPENGL_API;
|
|
|
|
api_name = "OpenGL";
|
2013-02-23 13:49:49 +00:00
|
|
|
#endif
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2014-10-24 05:26:51 +00:00
|
|
|
(void)api_name;
|
2013-02-23 13:49:49 +00:00
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
gl_shared_context_use = settings->video.shared_context
|
2016-03-04 19:49:55 +00:00
|
|
|
&& hwr->context_type != RETRO_HW_CONTEXT_NONE;
|
2014-04-19 14:59:26 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
return video_context_driver_init_first(gl, settings->video.context_driver,
|
2016-05-16 03:55:42 +00:00
|
|
|
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
|
2016-08-08 16:37:46 +00:00
|
|
|
#ifdef HAVE_GL_DEBUG_ES
|
2013-08-14 12:00:21 +00:00
|
|
|
#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
|
2016-08-08 16:37:46 +00:00
|
|
|
|
2013-08-14 12:00:21 +00:00
|
|
|
static void DEBUG_CALLBACK_TYPE gl_debug_cb(GLenum source, GLenum type,
|
|
|
|
GLuint id, GLenum severity, GLsizei length,
|
|
|
|
const GLchar *message, void *userParam)
|
|
|
|
{
|
2015-06-13 00:49:29 +00:00
|
|
|
const char *src = NULL;
|
2016-05-12 00:58:09 +00:00
|
|
|
const char *typestr = NULL;
|
2015-06-13 00:49:29 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-08-01 14:06:19 +00:00
|
|
|
if (gl_check_capability(GL_CAPS_DEBUG))
|
2013-08-14 12:00:21 +00:00
|
|
|
{
|
2016-08-08 16:37:46 +00:00
|
|
|
#ifdef HAVE_GL_DEBUG_ES
|
2014-04-21 12:37:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
RARCH_ERR("Neither GL_KHR_debug nor GL_ARB_debug_output are implemented. Cannot start GL debugging.\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 03:47:34 +00:00
|
|
|
|
2011-11-02 18:31:36 +00:00
|
|
|
static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
2010-05-28 00:45:18 +00:00
|
|
|
{
|
2016-02-14 01:12:18 +00:00
|
|
|
gfx_ctx_mode_t mode;
|
2016-02-13 22:26:33 +00:00
|
|
|
gfx_ctx_input_t inp;
|
2016-02-14 17:48:17 +00:00
|
|
|
unsigned interval, mip_level;
|
2016-03-29 13:28:13 +00:00
|
|
|
unsigned full_x, full_y;
|
2016-02-14 18:51:32 +00:00
|
|
|
video_shader_ctx_filter_t shader_filter;
|
2016-02-14 18:30:48 +00:00
|
|
|
video_shader_ctx_info_t shader_info;
|
2016-02-14 21:17:00 +00:00
|
|
|
video_shader_ctx_ident_t ident_info;
|
2016-05-09 02:54:25 +00:00
|
|
|
video_shader_ctx_wrap_t wrap_info = {0};
|
2016-03-04 19:49:55 +00:00
|
|
|
unsigned win_width = 0;
|
|
|
|
unsigned win_height = 0;
|
|
|
|
unsigned temp_width = 0;
|
|
|
|
unsigned temp_height = 0;
|
|
|
|
bool force_smooth = false;
|
|
|
|
const char *vendor = NULL;
|
|
|
|
const char *renderer = NULL;
|
|
|
|
const char *version = NULL;
|
|
|
|
struct retro_hw_render_callback *hwr = NULL;
|
2016-09-05 05:21:47 +00:00
|
|
|
char *error_string = NULL;
|
2016-03-04 19:49:55 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t));
|
|
|
|
const gfx_ctx_driver_t *ctx_driver = gl_get_context(gl);
|
2016-02-13 15:33:38 +00:00
|
|
|
if (!gl || !ctx_driver)
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2016-05-08 18:40:42 +00:00
|
|
|
video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver);
|
2015-11-23 20:20:21 +00:00
|
|
|
|
2015-04-09 16:07:58 +00:00
|
|
|
gl->video_info = *video;
|
2013-07-06 20:10:09 +00:00
|
|
|
|
2015-04-09 16:07:58 +00:00
|
|
|
RARCH_LOG("Found GL context: %s\n", ctx_driver->ident);
|
2012-09-24 23:26:22 +00:00
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_video_size(&mode);
|
2016-02-14 01:26:20 +00:00
|
|
|
|
2016-03-29 13:28:13 +00:00
|
|
|
full_x = mode.width;
|
|
|
|
full_y = mode.height;
|
2016-02-14 01:26:20 +00:00
|
|
|
mode.width = 0;
|
|
|
|
mode.height = 0;
|
|
|
|
|
2016-03-29 13:28:13 +00:00
|
|
|
RARCH_LOG("Detecting screen resolution %ux%u.\n", full_x, full_y);
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2016-02-13 19:45:45 +00:00
|
|
|
interval = video->vsync ? settings->video.swap_interval : 0;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_swap_interval(&interval);
|
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))
|
|
|
|
{
|
2016-03-29 13:28:13 +00:00
|
|
|
win_width = full_x;
|
|
|
|
win_height = full_y;
|
2011-09-13 16:50:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 01:12:18 +00:00
|
|
|
mode.width = win_width;
|
|
|
|
mode.height = win_height;
|
|
|
|
mode.fullscreen = video->fullscreen;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
if (!video_context_driver_set_video_mode(&mode))
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
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. */
|
2016-09-17 23:57:17 +00:00
|
|
|
glGetError();
|
2013-08-14 12:57:39 +00:00
|
|
|
|
2015-01-10 02:48:03 +00:00
|
|
|
vendor = (const char*)glGetString(GL_VENDOR);
|
|
|
|
renderer = (const char*)glGetString(GL_RENDERER);
|
|
|
|
version = (const char*)glGetString(GL_VERSION);
|
2013-07-12 23:46:57 +00:00
|
|
|
|
2015-01-10 02:48:03 +00:00
|
|
|
RARCH_LOG("[GL]: Vendor: %s, Renderer: %s.\n", vendor, renderer);
|
2013-08-16 08:18:58 +00:00
|
|
|
RARCH_LOG("[GL]: Version: %s.\n", version);
|
|
|
|
|
2015-12-26 06:59:15 +00:00
|
|
|
if (!string_is_empty(version))
|
2015-12-13 13:55:19 +00:00
|
|
|
sscanf(version, "%d.%d", &gl->version_major, &gl->version_minor);
|
|
|
|
|
2013-08-11 13:06:42 +00:00
|
|
|
#ifndef RARCH_CONSOLE
|
2015-04-09 16:07:58 +00:00
|
|
|
rglgen_resolve_symbols(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
|
|
|
|
2015-05-04 07:37:26 +00:00
|
|
|
if (!resolve_extensions(gl, ctx_driver->ident))
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
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;
|
2016-02-14 01:26:20 +00:00
|
|
|
|
|
|
|
mode.width = 0;
|
|
|
|
mode.height = 0;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_video_size(&mode);
|
2016-02-14 01:26:20 +00:00
|
|
|
|
|
|
|
temp_width = mode.width;
|
|
|
|
temp_height = mode.height;
|
|
|
|
mode.width = 0;
|
|
|
|
mode.height = 0;
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2014-10-01 21:50:58 +00:00
|
|
|
/* Get real known video size, which might have been altered by context. */
|
2015-05-20 00:18:05 +00:00
|
|
|
|
|
|
|
if (temp_width != 0 && temp_height != 0)
|
2015-11-23 11:54:15 +00:00
|
|
|
video_driver_set_size(&temp_width, &temp_height);
|
2015-05-20 00:18:05 +00:00
|
|
|
|
|
|
|
video_driver_get_size(&temp_width, &temp_height);
|
|
|
|
|
|
|
|
RARCH_LOG("GL: Using resolution %ux%u\n", temp_width, temp_height);
|
2011-02-28 15:59:31 +00:00
|
|
|
|
2016-05-08 12:00:51 +00:00
|
|
|
hwr = video_driver_get_hw_context();
|
2016-03-04 19:49:55 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->vertex_ptr = hwr->bottom_left_origin
|
2016-02-14 15:59:21 +00:00
|
|
|
? vertexes : vertexes_flipped;
|
2013-06-30 20:58:22 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->textures = 4;
|
2013-06-30 20:58:22 +00:00
|
|
|
#ifdef HAVE_FBO
|
2016-03-04 19:49:55 +00:00
|
|
|
gl->hw_render_use = hwr->context_type != RETRO_HW_CONTEXT_NONE;
|
2015-01-10 02:48:03 +00:00
|
|
|
|
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
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2014-04-19 13:37:00 +00:00
|
|
|
gl_begin_debug(gl);
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(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
|
2015-04-09 16:07:58 +00:00
|
|
|
gl_glsl_set_get_proc_address(ctx_driver->get_proc_address);
|
2016-08-01 19:58:18 +00:00
|
|
|
gl_glsl_set_context_type(gl_query_core_context_in_use(),
|
2016-03-04 19:49:55 +00:00
|
|
|
hwr->version_major, hwr->version_minor);
|
2012-09-24 23:26:22 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (!video_shader_driver_init_first())
|
2016-10-31 14:12:34 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL:]: Shader driver initialization failed.\n");
|
2015-12-08 08:27:25 +00:00
|
|
|
goto error;
|
2016-10-31 14:12:34 +00:00
|
|
|
}
|
2014-10-02 11:47:45 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_get_ident(&ident_info);
|
2016-02-14 21:17:00 +00:00
|
|
|
|
|
|
|
RARCH_LOG("[GL]: Default shader backend found: %s.\n", ident_info.ident);
|
2014-10-02 11:47:45 +00:00
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
if (!gl_shader_init(gl))
|
2011-01-11 18:23:21 +00:00
|
|
|
{
|
2014-12-03 17:36:25 +00:00
|
|
|
RARCH_ERR("[GL]: Shader initialization failed.\n");
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
2011-01-11 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
{
|
2016-02-22 11:25:41 +00:00
|
|
|
unsigned minimum;
|
2016-02-14 21:22:40 +00:00
|
|
|
video_shader_ctx_texture_t texture_info;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_get_prev_textures(&texture_info);
|
2016-02-14 21:22:40 +00:00
|
|
|
|
2016-02-22 11:25:41 +00:00
|
|
|
minimum = texture_info.id;
|
2016-03-01 23:07:31 +00:00
|
|
|
gl->textures = MAX(minimum + 1, gl->textures);
|
2013-07-06 20:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (!video_shader_driver_info(&shader_info))
|
2016-10-31 14:12:34 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Shader driver info check failed.\n");
|
2016-02-14 18:30:48 +00:00
|
|
|
goto error;
|
2016-10-31 14:12:34 +00:00
|
|
|
}
|
2016-02-14 18:30:48 +00:00
|
|
|
|
2014-10-02 11:47:45 +00:00
|
|
|
RARCH_LOG("[GL]: Using %u textures.\n", gl->textures);
|
2016-02-14 15:59:21 +00:00
|
|
|
RARCH_LOG("[GL]: Loaded %u program(s).\n",
|
2016-02-14 18:30:48 +00:00
|
|
|
shader_info.num);
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->tex_w = gl->tex_h = (RARCH_SCALE_BASE * video->input_scale);
|
|
|
|
gl->keep_aspect = video->force_aspect;
|
2011-03-30 12:57:45 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
/* Apparently need to set viewport for passes
|
2014-10-01 21:50:58 +00:00
|
|
|
* 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
|
|
|
|
2016-02-14 18:51:32 +00:00
|
|
|
mip_level = 1;
|
2016-05-08 19:11:27 +00:00
|
|
|
gl->tex_mipmap = video_shader_driver_mipmap_input(&mip_level);
|
2016-02-14 18:51:32 +00:00
|
|
|
shader_filter.index = 1;
|
|
|
|
shader_filter.smooth = &force_smooth;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (video_shader_driver_filter_type(&shader_filter))
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->tex_min_filter = gl->tex_mipmap ? (force_smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
2014-10-01 21:50:58 +00:00
|
|
|
: (force_smooth ? GL_LINEAR : GL_NEAREST);
|
2010-05-29 12:45:40 +00:00
|
|
|
else
|
2016-09-17 23:57:17 +00:00
|
|
|
gl->tex_min_filter = gl->tex_mipmap ?
|
|
|
|
(video->smooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
2014-10-01 21:50:58 +00:00
|
|
|
: (video->smooth ? GL_LINEAR : GL_NEAREST);
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2014-05-11 11:13:38 +00:00
|
|
|
gl->tex_mag_filter = min_filter_to_mag(gl->tex_min_filter);
|
2016-02-14 20:41:16 +00:00
|
|
|
|
|
|
|
wrap_info.idx = 1;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_wrap_type(&wrap_info);
|
2016-02-14 20:41:16 +00:00
|
|
|
|
|
|
|
gl->wrap_mode = gl_wrap_type_to_enum(wrap_info.type);
|
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
|
2016-08-01 19:58:18 +00:00
|
|
|
if (!gl_query_core_context_in_use())
|
2013-06-23 09:55:21 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2012-09-15 13:17:34 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-08 22:38:32 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-03-28 00:19:48 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
2011-03-12 18:28:56 +00:00
|
|
|
glDisable(GL_DITHER);
|
2010-05-28 00:45:18 +00:00
|
|
|
|
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
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
/* Empty buffer that we use to clear out
|
2014-10-01 21:50:58 +00:00
|
|
|
* the texture with on res change. */
|
2015-02-13 01:21:54 +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)
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->conv_buffer = calloc(sizeof(uint32_t), gl->tex_w * gl->tex_h);
|
2015-01-11 18:52:02 +00:00
|
|
|
|
2012-09-15 13:17:34 +00:00
|
|
|
if (!gl->conv_buffer)
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
2012-09-15 13:17:34 +00:00
|
|
|
#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
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_init(gl, gl->tex_w, gl->tex_h);
|
2013-03-27 15:15:15 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
if (gl->hw_render_use &&
|
2014-10-01 21:50:58 +00:00
|
|
|
!gl_init_hw_render(gl, gl->tex_w, gl->tex_h))
|
2016-10-31 14:12:34 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Hardware rendering context initialization failed.\n");
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
2016-10-31 14:12:34 +00:00
|
|
|
}
|
2013-03-27 15:15:15 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-13 22:26:33 +00:00
|
|
|
inp.input = input;
|
|
|
|
inp.input_data = input_data;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_input_driver(&inp);
|
2016-09-17 23:57:17 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->video.font_enable)
|
2016-10-18 23:07:00 +00:00
|
|
|
font_driver_init_osd(gl, false, FONT_DRIVER_RENDER_OPENGL_API);
|
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
|
|
|
|
2016-09-17 23:55:19 +00:00
|
|
|
if (!gl_check_error(&error_string))
|
2016-09-05 05:21:47 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("%s\n", error_string);
|
|
|
|
free(error_string);
|
2015-04-10 04:17:04 +00:00
|
|
|
goto error;
|
2016-09-05 05:21:47 +00:00
|
|
|
}
|
2011-01-11 21:33:28 +00:00
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2010-08-16 16:40:17 +00:00
|
|
|
return gl;
|
2015-04-10 04:17:04 +00:00
|
|
|
|
|
|
|
error:
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_destroy();
|
2016-05-16 03:47:34 +00:00
|
|
|
gl_destroy_resources(gl);
|
2015-04-10 04:17:04 +00:00
|
|
|
return NULL;
|
2010-05-28 00:45:18 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 19:01:32 +00:00
|
|
|
static bool gl_alive(void *data)
|
|
|
|
{
|
2016-02-13 18:53:14 +00:00
|
|
|
gfx_ctx_size_t size_data;
|
|
|
|
unsigned temp_width = 0;
|
|
|
|
unsigned temp_height = 0;
|
|
|
|
bool ret = false;
|
|
|
|
bool quit = false;
|
|
|
|
bool resize = false;
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2012-05-30 15:02:38 +00:00
|
|
|
|
2015-12-01 06:15:06 +00:00
|
|
|
/* Needed because some context drivers don't track their sizes */
|
|
|
|
video_driver_get_size(&temp_width, &temp_height);
|
|
|
|
|
2016-02-13 18:53:14 +00:00
|
|
|
size_data.quit = &quit;
|
|
|
|
size_data.resize = &resize;
|
|
|
|
size_data.width = &temp_width;
|
|
|
|
size_data.height = &temp_height;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
if (video_context_driver_check_window(&size_data))
|
2015-05-20 00:22:03 +00:00
|
|
|
{
|
|
|
|
if (quit)
|
|
|
|
gl->quitting = true;
|
|
|
|
else if (resize)
|
|
|
|
gl->should_resize = true;
|
2015-04-09 20:38:11 +00:00
|
|
|
|
2015-05-20 00:22:03 +00:00
|
|
|
ret = !gl->quitting;
|
|
|
|
}
|
2012-05-30 15:02:38 +00:00
|
|
|
|
2015-05-20 00:22:03 +00:00
|
|
|
if (temp_width != 0 && temp_height != 0)
|
2015-11-23 11:54:15 +00:00
|
|
|
video_driver_set_size(&temp_width, &temp_height);
|
2015-05-20 00:22:03 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-01-06 19:01:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 20:45:44 +00:00
|
|
|
static bool gl_focus(void *data)
|
|
|
|
{
|
2016-05-08 18:32:46 +00:00
|
|
|
return video_context_driver_focus();
|
2011-02-05 20:45:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool gl_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
2016-02-13 22:39:12 +00:00
|
|
|
bool enabled = enable;
|
2016-05-08 18:32:46 +00:00
|
|
|
return video_context_driver_suppress_screensaver(&enabled);
|
2015-01-18 21:32:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool gl_has_windowed(void *data)
|
|
|
|
{
|
2016-05-08 18:32:46 +00:00
|
|
|
return video_context_driver_has_windowed();
|
2014-10-08 15:23:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 23:56:13 +00:00
|
|
|
static void gl_update_tex_filter_frame(gl_t *gl)
|
|
|
|
{
|
2016-02-14 18:51:32 +00:00
|
|
|
video_shader_ctx_filter_t shader_filter;
|
2016-02-14 17:48:17 +00:00
|
|
|
unsigned i, mip_level;
|
2015-01-10 02:48:03 +00:00
|
|
|
GLenum wrap_mode;
|
|
|
|
GLuint new_filt;
|
2016-10-21 18:04:56 +00:00
|
|
|
video_shader_ctx_wrap_t wrap_info;
|
2016-05-09 02:54:25 +00:00
|
|
|
bool smooth = false;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2014-05-28 22:43:47 +00:00
|
|
|
|
|
|
|
if (!gl)
|
|
|
|
return;
|
|
|
|
|
2016-10-21 18:04:56 +00:00
|
|
|
wrap_info.idx = 0;
|
|
|
|
wrap_info.type = RARCH_WRAP_BORDER;
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2016-02-14 18:51:32 +00:00
|
|
|
shader_filter.index = 1;
|
|
|
|
shader_filter.smooth = &smooth;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (!video_shader_driver_filter_type(&shader_filter))
|
2015-03-20 21:08:36 +00:00
|
|
|
smooth = settings->video.smooth;
|
2013-04-13 23:56:13 +00:00
|
|
|
|
2016-02-14 17:48:17 +00:00
|
|
|
mip_level = 1;
|
2016-02-14 20:41:16 +00:00
|
|
|
wrap_info.idx = 1;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_wrap_type(&wrap_info);
|
2016-02-14 17:48:17 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
wrap_mode = gl_wrap_type_to_enum(wrap_info.type);
|
|
|
|
gl->tex_mipmap = video_shader_driver_mipmap_input(&mip_level);
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2013-07-06 20:10:09 +00:00
|
|
|
gl->video_info.smooth = smooth;
|
2016-09-17 23:57:17 +00:00
|
|
|
new_filt = gl->tex_mipmap ? (smooth ?
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST)
|
2014-10-01 21:50:58 +00:00
|
|
|
: (smooth ? GL_LINEAR : GL_NEAREST);
|
2015-02-13 01:21:54 +00:00
|
|
|
|
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;
|
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
gl->tex_min_filter = new_filt;
|
|
|
|
gl->tex_mag_filter = min_filter_to_mag(gl->tex_min_filter);
|
|
|
|
gl->wrap_mode = wrap_mode;
|
2014-05-11 11:13:38 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < gl->textures; i++)
|
2013-04-13 23:56:13 +00:00
|
|
|
{
|
2015-01-11 18:52:02 +00:00
|
|
|
if (!gl->texture[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gl->wrap_mode);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gl->wrap_mode);
|
|
|
|
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]);
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(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)
|
2016-04-16 05:16:32 +00:00
|
|
|
unsigned textures;
|
|
|
|
video_shader_ctx_texture_t texture_info;
|
2016-02-14 17:41:45 +00:00
|
|
|
video_shader_ctx_init_t init_data;
|
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;
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2011-06-07 13:58:30 +00:00
|
|
|
|
2013-01-08 02:46:18 +00:00
|
|
|
if (type == RARCH_SHADER_NONE)
|
|
|
|
return false;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_deinit();
|
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:
|
|
|
|
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:
|
|
|
|
break;
|
2012-09-21 19:20:30 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
default:
|
2016-04-16 05:16:32 +00:00
|
|
|
RARCH_ERR("[GL]: Cannot find shader core for path: %s.\n", path);
|
2016-04-16 05:19:21 +00:00
|
|
|
goto error;
|
2013-04-07 11:00:21 +00:00
|
|
|
}
|
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
|
|
|
|
|
2016-04-16 05:16:32 +00:00
|
|
|
init_data.shader_type = type;
|
|
|
|
init_data.shader = NULL;
|
|
|
|
init_data.data = gl;
|
|
|
|
init_data.path = path;
|
2016-02-14 17:41:45 +00:00
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
if (!video_shader_driver_init(&init_data))
|
2013-04-07 11:00:21 +00:00
|
|
|
{
|
2016-02-14 17:41:45 +00:00
|
|
|
init_data.path = NULL;
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_init(&init_data);
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
RARCH_WARN("[GL]: Failed to set multipass shader. Falling back to stock.\n");
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2016-04-16 05:19:21 +00:00
|
|
|
goto error;
|
2013-04-07 11:00:21 +00:00
|
|
|
}
|
2011-03-29 16:59:06 +00:00
|
|
|
|
2013-04-13 23:31:32 +00:00
|
|
|
gl_update_tex_filter_frame(gl);
|
|
|
|
|
2016-05-08 19:11:27 +00:00
|
|
|
video_shader_driver_get_prev_textures(&texture_info);
|
2016-02-14 21:22:40 +00:00
|
|
|
|
2016-04-16 05:16:32 +00:00
|
|
|
textures = texture_info.id + 1;
|
2016-02-14 21:22:40 +00:00
|
|
|
|
2016-04-16 05:16:32 +00:00
|
|
|
if (textures > gl->textures) /* Have to reinit a bit. */
|
|
|
|
{
|
2015-03-05 13:26:34 +00:00
|
|
|
#if defined(HAVE_FBO)
|
2016-04-16 05:16:32 +00:00
|
|
|
gl_deinit_hw_render(gl);
|
2013-07-06 20:10:09 +00:00
|
|
|
#endif
|
|
|
|
|
2016-04-16 05:16:32 +00:00
|
|
|
glDeleteTextures(gl->textures, gl->texture);
|
2013-07-06 20:10:09 +00:00
|
|
|
#if defined(HAVE_PSGL)
|
2016-04-16 05:16:32 +00:00
|
|
|
glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0);
|
|
|
|
glDeleteBuffers(1, &gl->pbo);
|
2013-07-06 20:10:09 +00:00
|
|
|
#endif
|
2016-04-16 05:16:32 +00:00
|
|
|
gl->textures = textures;
|
|
|
|
RARCH_LOG("[GL]: Using %u textures.\n", gl->textures);
|
|
|
|
gl->tex_index = 0;
|
|
|
|
gl_init_textures(gl, &gl->video_info);
|
|
|
|
gl_init_textures_data(gl);
|
2013-07-06 20:10:09 +00:00
|
|
|
|
2015-03-05 13:26:34 +00:00
|
|
|
#if defined(HAVE_FBO)
|
2016-04-16 05:16:32 +00:00
|
|
|
if (gl->hw_render_use)
|
|
|
|
gl_init_hw_render(gl, gl->tex_w, gl->tex_h);
|
2013-07-06 20:10:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-30 19:22:36 +00:00
|
|
|
#ifdef HAVE_FBO
|
2016-08-02 00:54:38 +00:00
|
|
|
gl_renderchain_init(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);
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2015-03-23 16:36:37 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
|
|
|
shader_dlg_params_reload();
|
|
|
|
#endif
|
2016-04-16 05:19:21 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
return true;
|
2016-04-16 05:19:21 +00:00
|
|
|
|
|
|
|
error:
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2014-09-09 04:07:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-29 16:28:31 +00:00
|
|
|
|
2015-02-14 04:52:05 +00:00
|
|
|
static void gl_viewport_info(void *data, struct video_viewport *vp)
|
2012-06-08 20:39:18 +00:00
|
|
|
{
|
2015-05-19 22:45:42 +00:00
|
|
|
unsigned width, height;
|
2014-05-28 22:43:47 +00:00
|
|
|
unsigned top_y, top_dist;
|
2015-04-26 03:21:43 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2015-05-19 22:45:42 +00:00
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
2015-02-14 04:52:05 +00:00
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
*vp = gl->vp;
|
2015-05-19 22:45:42 +00:00
|
|
|
vp->full_width = width;
|
|
|
|
vp->full_height = height;
|
2013-01-24 06:29:26 +00:00
|
|
|
|
2014-10-01 14:59:43 +00:00
|
|
|
/* Adjust as GL viewport is bottom-up. */
|
2015-02-13 01:21:54 +00:00
|
|
|
top_y = vp->y + vp->height;
|
2015-05-19 22:45:42 +00:00
|
|
|
top_dist = height - top_y;
|
2015-02-13 01:21:54 +00:00
|
|
|
vp->y = top_dist;
|
2012-06-08 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 02:48:03 +00:00
|
|
|
static bool gl_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
2016-05-04 23:32:35 +00:00
|
|
|
#ifndef NO_GL_READ_PIXELS
|
2015-09-20 08:02:47 +00:00
|
|
|
static struct retro_perf_counter read_viewport = {0};
|
|
|
|
unsigned num_pixels = 0;
|
|
|
|
gl_t *gl = (gl_t*)data;
|
2015-01-10 02:48:03 +00:00
|
|
|
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(false);
|
2015-01-10 02:48:03 +00:00
|
|
|
|
2016-05-16 07:58:45 +00:00
|
|
|
performance_counter_init(&read_viewport, "read_viewport");
|
2016-05-16 07:53:54 +00:00
|
|
|
performance_counter_start(&read_viewport);
|
2012-11-20 17:05:33 +00:00
|
|
|
|
2016-05-04 23:29:52 +00:00
|
|
|
num_pixels = gl->vp.width * gl->vp.height;
|
|
|
|
|
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)
|
|
|
|
{
|
2015-01-10 02:48:03 +00:00
|
|
|
const uint8_t *ptr = NULL;
|
|
|
|
|
2015-04-10 04:25:25 +00:00
|
|
|
/* Don't readback if we're in menu mode.
|
|
|
|
* We haven't buffered up enough frames yet, come back later. */
|
2016-09-17 23:57:17 +00:00
|
|
|
if (!gl->pbo_readback_valid[gl->pbo_readback_index])
|
2015-04-10 04:25:25 +00:00
|
|
|
goto error;
|
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;
|
2016-02-14 15:59:21 +00:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER,
|
|
|
|
gl->pbo_readback[gl->pbo_readback_index]);
|
2016-05-04 23:29:52 +00:00
|
|
|
|
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. */
|
2016-05-04 23:29:52 +00:00
|
|
|
ptr = (const uint8_t*)glMapBufferRange(GL_PIXEL_PACK_BUFFER,
|
2014-04-19 15:22:25 +00:00
|
|
|
0, num_pixels * sizeof(uint32_t), GL_MAP_READ_BIT);
|
2015-01-10 02:48:03 +00:00
|
|
|
|
2014-04-19 15:22:25 +00:00
|
|
|
if (ptr)
|
|
|
|
{
|
2016-05-04 16:44:39 +00:00
|
|
|
unsigned y;
|
2014-04-19 15:22:25 +00:00
|
|
|
for (y = 0; y < gl->vp.height; y++)
|
|
|
|
{
|
2016-05-04 16:44:39 +00:00
|
|
|
video_frame_convert_rgba_to_bgr(
|
|
|
|
(const void*)ptr,
|
|
|
|
buffer,
|
|
|
|
gl->vp.width);
|
2014-04-19 15:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2015-01-10 15:52:06 +00:00
|
|
|
ptr = (const uint8_t*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
2016-05-04 23:29:52 +00:00
|
|
|
if (ptr)
|
|
|
|
scaler_ctx_scale(&gl->pbo_readback_scaler, buffer, ptr);
|
|
|
|
#endif
|
|
|
|
|
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");
|
2015-04-10 04:25:25 +00:00
|
|
|
goto error;
|
2012-11-21 15:24:28 +00:00
|
|
|
}
|
2012-11-21 21:12:56 +00:00
|
|
|
|
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
|
|
|
}
|
2016-09-17 23:57:17 +00:00
|
|
|
else /* Use slow synchronous readbacks. Use this with plain screenshots
|
2016-02-14 15:59:21 +00:00
|
|
|
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
|
|
|
{
|
2016-09-17 23:57:17 +00:00
|
|
|
/* GLES2 only guarantees GL_RGBA/GL_UNSIGNED_BYTE
|
2014-10-01 21:50:58 +00:00
|
|
|
* readbacks so do just that.
|
2016-09-17 23:57:17 +00:00
|
|
|
* 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
|
2014-10-01 21:50:58 +00:00
|
|
|
* in the back buffer.
|
|
|
|
*
|
|
|
|
* Keep codepath similar for GLES and desktop GL.
|
|
|
|
*/
|
2014-02-06 20:35:57 +00:00
|
|
|
gl->readback_buffer_screenshot = malloc(num_pixels * sizeof(uint32_t));
|
2016-05-04 23:29:52 +00:00
|
|
|
|
2014-02-06 20:35:57 +00:00
|
|
|
if (!gl->readback_buffer_screenshot)
|
|
|
|
{
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_stop(&read_viewport);
|
2015-04-10 04:25:25 +00:00
|
|
|
goto error;
|
2014-02-06 20:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 22:42:14 +00:00
|
|
|
if (!runloop_ctl(RUNLOOP_CTL_IS_IDLE, NULL))
|
|
|
|
video_driver_cached_frame();
|
2014-02-06 20:35:57 +00:00
|
|
|
|
2016-05-04 16:44:39 +00:00
|
|
|
video_frame_convert_rgba_to_bgr(
|
|
|
|
(const void*)gl->readback_buffer_screenshot,
|
|
|
|
buffer,
|
|
|
|
num_pixels);
|
2014-02-06 20:35:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-16 07:48:14 +00:00
|
|
|
performance_counter_stop(&read_viewport);
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2012-06-08 20:39:18 +00:00
|
|
|
return true;
|
2015-04-10 04:25:25 +00:00
|
|
|
|
|
|
|
error:
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2016-05-04 23:32:35 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-10 04:25:25 +00:00
|
|
|
return false;
|
2014-09-09 04:07:11 +00:00
|
|
|
}
|
2012-06-08 20:39:18 +00:00
|
|
|
|
2015-03-16 12:39:25 +00:00
|
|
|
#if 0
|
|
|
|
#define READ_RAW_GL_FRAME_TEST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(READ_RAW_GL_FRAME_TEST)
|
|
|
|
static void* gl_read_frame_raw(void *data, unsigned *width_p,
|
|
|
|
unsigned *height_p, size_t *pitch_p)
|
|
|
|
{
|
2015-09-28 16:44:28 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
unsigned width = gl->last_width[gl->tex_index];
|
|
|
|
unsigned height = gl->last_height[gl->tex_index];
|
|
|
|
size_t pitch = gl->tex_w * gl->base_size;
|
2016-08-06 01:18:19 +00:00
|
|
|
void* buffer = NULL;
|
2015-03-16 15:28:30 +00:00
|
|
|
void* buffer_texture = NULL;
|
2015-03-16 14:29:52 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->hw_render_use)
|
2015-03-16 15:22:48 +00:00
|
|
|
{
|
2015-03-16 14:29:52 +00:00
|
|
|
buffer = malloc(pitch * height);
|
2015-03-16 15:22:48 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-03-16 14:29:52 +00:00
|
|
|
#endif
|
2016-08-06 01:18:19 +00:00
|
|
|
|
2015-03-16 14:29:52 +00:00
|
|
|
buffer_texture = malloc(pitch * gl->tex_h);
|
2015-03-16 12:39:25 +00:00
|
|
|
|
2015-03-16 15:22:48 +00:00
|
|
|
if (!buffer_texture)
|
|
|
|
{
|
|
|
|
if (buffer)
|
|
|
|
free(buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-16 12:39:25 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
2016-02-14 15:59:21 +00:00
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0,
|
|
|
|
gl->texture_type, gl->texture_fmt, buffer_texture);
|
2015-03-16 12:39:25 +00:00
|
|
|
|
2016-08-06 01:18:19 +00:00
|
|
|
*width_p = width;
|
2015-03-16 12:39:25 +00:00
|
|
|
*height_p = height;
|
2016-08-06 01:18:19 +00:00
|
|
|
*pitch_p = pitch;
|
2015-03-16 12:39:25 +00:00
|
|
|
|
2015-03-16 14:29:52 +00:00
|
|
|
#ifdef HAVE_FBO
|
|
|
|
if (gl->hw_render_use)
|
|
|
|
{
|
2015-09-28 16:44:28 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2015-03-16 14:29:52 +00:00
|
|
|
for(i = 0; i < height ; i++)
|
|
|
|
memcpy((uint8_t*)buffer + i * pitch,
|
|
|
|
(uint8_t*)buffer_texture + (height - 1 - i) * pitch, pitch);
|
2015-03-16 12:39:25 +00:00
|
|
|
|
2015-03-16 14:29:52 +00:00
|
|
|
free(buffer_texture);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return buffer_texture;
|
2015-03-16 12:39:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 05:57:29 +00:00
|
|
|
|
2016-05-09 01:44:46 +00:00
|
|
|
bool gl_load_luts(const struct video_shader *shader,
|
|
|
|
GLuint *textures_lut)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned num_luts = MIN(shader->luts, GFX_MAX_TEXTURES);
|
|
|
|
|
|
|
|
if (!shader->luts)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
glGenTextures(num_luts, textures_lut);
|
|
|
|
|
|
|
|
for (i = 0; i < num_luts; i++)
|
|
|
|
{
|
2016-08-01 22:31:04 +00:00
|
|
|
if (!gl_renderchain_add_lut(shader, i, textures_lut))
|
2016-05-09 01:44:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2016-09-17 23:57:17 +00:00
|
|
|
static bool gl_overlay_load(void *data,
|
2015-07-11 06:14:39 +00:00
|
|
|
const void *image_data, 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;
|
2016-09-17 23:57:17 +00:00
|
|
|
const struct texture_image *images =
|
2015-07-11 06:14:39 +00:00
|
|
|
(const struct texture_image*)image_data;
|
2015-01-10 02:48:03 +00:00
|
|
|
|
2014-05-28 22:43:47 +00:00
|
|
|
if (!gl)
|
|
|
|
return false;
|
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(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));
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2014-06-13 15:46:53 +00:00
|
|
|
if (!gl->overlay_tex)
|
2014-04-19 13:37:00 +00:00
|
|
|
{
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(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
|
|
|
|
2016-02-14 15:59:21 +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));
|
2015-02-13 01:21:54 +00:00
|
|
|
|
2016-09-17 23:57:17 +00:00
|
|
|
if ( !gl->overlay_vertex_coord
|
|
|
|
|| !gl->overlay_tex_coord
|
2016-02-14 15:59:21 +00:00
|
|
|
|| !gl->overlay_color_coord)
|
2014-06-13 15:46:53 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-13 01:21:54 +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
|
|
|
{
|
2016-09-17 23:57:17 +00:00
|
|
|
unsigned alignment = video_pixel_get_alignment(images[i].width
|
2015-02-11 14:46:55 +00:00
|
|
|
* sizeof(uint32_t));
|
2014-10-01 21:50:58 +00:00
|
|
|
|
2015-02-11 14:46:55 +00:00
|
|
|
gl_load_texture_data(gl->overlay_tex[i],
|
|
|
|
RARCH_WRAP_EDGE, TEXTURE_FILTER_LINEAR,
|
2015-02-11 14:53:37 +00:00
|
|
|
alignment,
|
2015-02-11 15:05:11 +00:00
|
|
|
images[i].width, images[i].height, images[i].pixels,
|
|
|
|
sizeof(uint32_t));
|
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);
|
2015-01-10 02:48:03 +00:00
|
|
|
|
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
|
|
|
|
2016-05-16 03:55:42 +00:00
|
|
|
context_bind_hw_render(true);
|
2012-12-19 12:26:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-28 22:43:47 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2015-02-13 01:21:54 +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->overlay_enable = state;
|
2015-04-10 06:49:01 +00:00
|
|
|
|
|
|
|
if (gl->fullscreen)
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_show_mouse(&state);
|
2012-12-20 10:16:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
static void gl_overlay_full_screen(void *data, bool enable)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
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;
|
2015-02-13 01:21:54 +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
|
|
|
|
2015-02-13 01:21:54 +00:00
|
|
|
color = (GLfloat*)&gl->overlay_color_coord[image * 16];
|
2014-10-01 14:59:43 +00:00
|
|
|
|
2015-02-13 01:21:54 +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
|
|
|
}
|
|
|
|
|
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-28 00:11:32 +00:00
|
|
|
|
|
|
|
static retro_proc_address_t gl_get_proc_address(void *data, const char *sym)
|
|
|
|
{
|
2016-05-09 02:54:25 +00:00
|
|
|
gfx_ctx_proc_address_t proc_address = {0};
|
2016-02-13 21:02:49 +00:00
|
|
|
|
|
|
|
proc_address.sym = sym;
|
|
|
|
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_proc_address(&proc_address);
|
2016-02-13 21:02:49 +00:00
|
|
|
|
|
|
|
return proc_address.addr;
|
2013-03-28 00:11:32 +00:00
|
|
|
}
|
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
|
|
|
{
|
2015-03-21 03:43:18 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2013-03-10 00:16:56 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
switch (aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_square_pixel();
|
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:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_core();
|
2013-04-20 08:56:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
2016-05-08 12:00:51 +00:00
|
|
|
video_driver_set_viewport_config();
|
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
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-14 15:59:21 +00:00
|
|
|
video_driver_set_aspect_ratio_value(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-23 10:23:08 +00:00
|
|
|
|
2016-08-01 13:31:17 +00:00
|
|
|
static void gl_apply_state_changes(void *data)
|
|
|
|
{
|
|
|
|
gl_t *gl = (gl_t*)data;
|
|
|
|
|
|
|
|
if (gl)
|
|
|
|
gl->should_resize = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-10 07:11:17 +00:00
|
|
|
static void gl_get_video_output_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
2015-02-24 19:09:10 +00:00
|
|
|
{
|
2016-02-13 18:36:02 +00:00
|
|
|
gfx_ctx_size_t size_data;
|
|
|
|
size_data.width = width;
|
|
|
|
size_data.height = height;
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_video_output_size(&size_data);
|
2015-02-24 19:09:10 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 20:36:23 +00:00
|
|
|
static void gl_get_video_output_prev(void *data)
|
|
|
|
{
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_video_output_prev();
|
2015-02-24 20:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_get_video_output_next(void *data)
|
|
|
|
{
|
2016-05-08 18:32:46 +00:00
|
|
|
video_context_driver_get_video_output_next();
|
2015-02-24 20:36:23 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 19:52:23 +00:00
|
|
|
static void video_texture_load_gl(
|
|
|
|
struct texture_image *ti,
|
|
|
|
enum texture_filter_type filter_type,
|
|
|
|
uintptr_t *id)
|
|
|
|
{
|
|
|
|
/* Generate the OpenGL texture object */
|
|
|
|
glGenTextures(1, (GLuint*)id);
|
2016-09-17 23:57:17 +00:00
|
|
|
gl_load_texture_data((GLuint)*id,
|
2015-12-20 19:52:23 +00:00
|
|
|
RARCH_WRAP_EDGE, filter_type,
|
|
|
|
4 /* TODO/FIXME - dehardcode */,
|
|
|
|
ti->width, ti->height, ti->pixels,
|
|
|
|
sizeof(uint32_t) /* TODO/FIXME - dehardcode */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-11 08:10:30 +00:00
|
|
|
#ifdef HAVE_THREADS
|
2015-12-20 19:52:23 +00:00
|
|
|
static int video_texture_load_wrap_gl_mipmap(void *data)
|
|
|
|
{
|
|
|
|
uintptr_t id = 0;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return 0;
|
2016-02-14 15:59:21 +00:00
|
|
|
video_texture_load_gl((struct texture_image*)data,
|
|
|
|
TEXTURE_FILTER_MIPMAP_LINEAR, &id);
|
2015-12-20 19:52:23 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int video_texture_load_wrap_gl(void *data)
|
|
|
|
{
|
|
|
|
uintptr_t id = 0;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return 0;
|
2016-02-14 15:59:21 +00:00
|
|
|
video_texture_load_gl((struct texture_image*)data,
|
|
|
|
TEXTURE_FILTER_LINEAR, &id);
|
2015-12-20 19:52:23 +00:00
|
|
|
return id;
|
|
|
|
}
|
2016-05-11 08:10:30 +00:00
|
|
|
#endif
|
2015-12-20 19:52:23 +00:00
|
|
|
|
2015-12-20 21:38:18 +00:00
|
|
|
static uintptr_t gl_load_texture(void *video_data, void *data,
|
2015-12-20 19:52:23 +00:00
|
|
|
bool threaded, enum texture_filter_type filter_type)
|
|
|
|
{
|
|
|
|
uintptr_t id = 0;
|
|
|
|
|
2016-03-13 14:30:30 +00:00
|
|
|
#ifdef HAVE_THREADS
|
2015-12-20 19:52:23 +00:00
|
|
|
if (threaded)
|
|
|
|
{
|
|
|
|
custom_command_method_t func = video_texture_load_wrap_gl;
|
|
|
|
|
|
|
|
switch (filter_type)
|
|
|
|
{
|
|
|
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
|
|
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
|
|
|
func = video_texture_load_wrap_gl_mipmap;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-10 01:14:23 +00:00
|
|
|
return video_thread_texture_load(data, func);
|
2015-12-20 19:52:23 +00:00
|
|
|
}
|
2016-03-13 14:30:30 +00:00
|
|
|
#endif
|
2015-12-20 19:52:23 +00:00
|
|
|
|
2015-12-20 20:08:03 +00:00
|
|
|
video_texture_load_gl((struct texture_image*)data, filter_type, &id);
|
2015-12-20 19:52:23 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
static void gl_unload_texture(void *data, uintptr_t id)
|
2015-12-20 19:52:23 +00:00
|
|
|
{
|
2016-02-16 19:24:00 +00:00
|
|
|
GLuint glid;
|
2015-12-20 19:52:23 +00:00
|
|
|
if (!id)
|
|
|
|
return;
|
|
|
|
|
2016-02-16 19:24:00 +00:00
|
|
|
glid = (GLuint)id;
|
|
|
|
glDeleteTextures(1, &glid);
|
2015-12-20 19:52:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 00:16:56 +00:00
|
|
|
static const video_poke_interface_t gl_poke_interface = {
|
2015-12-20 19:52:23 +00:00
|
|
|
gl_load_texture,
|
|
|
|
gl_unload_texture,
|
2015-02-24 20:57:51 +00:00
|
|
|
gl_set_video_mode,
|
2013-04-20 08:56:04 +00:00
|
|
|
NULL,
|
2015-02-24 19:09:10 +00:00
|
|
|
gl_get_video_output_size,
|
2015-02-24 20:36:23 +00:00
|
|
|
gl_get_video_output_prev,
|
|
|
|
gl_get_video_output_next,
|
2013-03-10 19:25:47 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-03-27 15:15:15 +00:00
|
|
|
gl_get_current_framebuffer,
|
2015-04-25 00:35:06 +00:00
|
|
|
#else
|
|
|
|
NULL,
|
2013-03-10 19:25:47 +00:00
|
|
|
#endif
|
2015-02-08 17:39:12 +00:00
|
|
|
gl_get_proc_address,
|
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-11 20:42:02 +00:00
|
|
|
gl_set_osd_msg,
|
2013-03-29 17:53:07 +00:00
|
|
|
gl_show_mouse,
|
2015-10-27 23:55:11 +00:00
|
|
|
#else
|
|
|
|
NULL,
|
2014-05-23 10:23:08 +00:00
|
|
|
NULL,
|
2015-10-27 23:55:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
#endif
|
2014-05-23 10:23:08 +00:00
|
|
|
|
2015-10-27 23:55:11 +00:00
|
|
|
NULL,
|
|
|
|
#ifdef HAVE_MENU
|
2014-05-23 10:23:08 +00:00
|
|
|
gl_get_current_shader,
|
2015-10-27 23:55:11 +00:00
|
|
|
#endif
|
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,
|
2015-01-18 21:32:14 +00:00
|
|
|
gl_suppress_screensaver,
|
2014-10-08 15:23:02 +00:00
|
|
|
gl_has_windowed,
|
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
|
|
|
|
2015-04-26 17:46:59 +00:00
|
|
|
gl_set_viewport,
|
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,
|
2015-03-16 12:39:25 +00:00
|
|
|
#if defined(READ_RAW_GL_FRAME_TEST)
|
|
|
|
gl_read_frame_raw,
|
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
#endif
|
2012-12-20 10:16:22 +00:00
|
|
|
|
2012-12-23 17:36:58 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2012-12-20 10:16:22 +00:00
|
|
|
gl_get_overlay_interface,
|
2012-12-23 17:36:58 +00:00
|
|
|
#endif
|
2013-03-10 00:16:56 +00:00
|
|
|
gl_get_poke_interface,
|
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
|
|
|
|