2012-04-21 23:13:50 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* copyright (c) 2011-2017 - Daniel De Matteis
|
2011-01-11 22:13:55 +01:00
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-01-11 22:13:55 +01: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 23:13:50 +02:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-01-11 22:13:55 +01: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 23:31:57 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-01-11 22:13:55 +01:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GL_COMMON_H
|
|
|
|
#define __GL_COMMON_H
|
|
|
|
|
2015-07-12 04:20:48 +02:00
|
|
|
#include <string.h>
|
2011-05-18 22:11:34 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2015-04-09 04:57:17 +02:00
|
|
|
#include "../../config.h"
|
2011-05-18 22:11:34 +02:00
|
|
|
#endif
|
2011-01-11 22:13:55 +01:00
|
|
|
|
2015-07-12 04:20:48 +02:00
|
|
|
#include <retro_inline.h>
|
|
|
|
#include <gfx/math/matrix_4x4.h>
|
|
|
|
#include <gfx/scaler/scaler.h>
|
|
|
|
#include <formats/image.h>
|
|
|
|
|
2015-11-23 12:03:38 +01:00
|
|
|
#include "../../verbosity.h"
|
2015-12-05 12:07:22 +01:00
|
|
|
#include "../font_driver.h"
|
2016-03-05 07:27:48 +01:00
|
|
|
#include "../video_coord_array.h"
|
2017-05-09 01:25:59 +02:00
|
|
|
#include "../video_driver.h"
|
2016-10-24 04:02:03 +02:00
|
|
|
#include "../drivers/gl_symlinks.h"
|
2015-01-12 07:02:55 +01:00
|
|
|
|
2017-04-11 18:54:26 +01:00
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
|
2012-05-26 15:21:51 +02:00
|
|
|
typedef struct gl
|
|
|
|
{
|
2015-12-13 14:55:19 +01:00
|
|
|
int version_major;
|
|
|
|
int version_minor;
|
|
|
|
|
2012-05-26 15:21:51 +02:00
|
|
|
bool vsync;
|
2015-06-22 21:09:18 +02:00
|
|
|
GLuint texture[GFX_MAX_TEXTURES];
|
2014-09-12 02:51:23 +02:00
|
|
|
unsigned tex_index; /* For use with PREV. */
|
2013-07-06 22:10:09 +02:00
|
|
|
unsigned textures;
|
2016-05-10 02:39:09 +02:00
|
|
|
struct video_tex_info tex_info;
|
|
|
|
struct video_tex_info prev_info[GFX_MAX_TEXTURES];
|
2014-05-11 13:13:38 +02:00
|
|
|
GLuint tex_mag_filter;
|
|
|
|
GLuint tex_min_filter;
|
|
|
|
bool tex_mipmap;
|
2012-05-26 15:21:51 +02:00
|
|
|
|
|
|
|
void *empty_buf;
|
2012-10-02 00:58:43 +02:00
|
|
|
|
2012-09-15 15:17:34 +02:00
|
|
|
void *conv_buffer;
|
2012-10-02 00:58:43 +02:00
|
|
|
struct scaler_ctx scaler;
|
2012-05-26 15:21:51 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_FBO
|
2014-09-12 02:51:23 +02:00
|
|
|
/* Render-to-texture, multipass shaders. */
|
2015-06-22 21:09:18 +02:00
|
|
|
GLuint fbo[GFX_MAX_SHADERS];
|
|
|
|
GLuint fbo_texture[GFX_MAX_SHADERS];
|
2016-05-10 02:34:36 +02:00
|
|
|
struct video_fbo_rect fbo_rect[GFX_MAX_SHADERS];
|
2015-06-22 21:09:18 +02:00
|
|
|
struct gfx_fbo_scale fbo_scale[GFX_MAX_SHADERS];
|
2012-05-26 15:21:51 +02:00
|
|
|
int fbo_pass;
|
|
|
|
bool fbo_inited;
|
2013-03-27 16:15:15 +01:00
|
|
|
|
2015-08-30 18:37:41 +02:00
|
|
|
bool fbo_feedback_enable;
|
|
|
|
unsigned fbo_feedback_pass;
|
|
|
|
GLuint fbo_feedback;
|
|
|
|
GLuint fbo_feedback_texture;
|
|
|
|
|
2015-06-22 21:09:18 +02:00
|
|
|
GLuint hw_render_fbo[GFX_MAX_TEXTURES];
|
|
|
|
GLuint hw_render_depth[GFX_MAX_TEXTURES];
|
2013-03-27 16:15:15 +01:00
|
|
|
bool hw_render_fbo_init;
|
2013-03-29 02:50:42 +01:00
|
|
|
bool hw_render_depth_init;
|
2014-06-05 17:41:10 +02:00
|
|
|
bool has_srgb_fbo_gles3;
|
2012-05-26 15:21:51 +02:00
|
|
|
#endif
|
2016-08-01 17:33:50 +02:00
|
|
|
bool has_fp_fbo;
|
2016-08-01 17:28:43 +02:00
|
|
|
bool has_srgb_fbo;
|
2013-05-18 21:53:26 +02:00
|
|
|
bool hw_render_use;
|
2012-05-26 15:21:51 +02:00
|
|
|
|
|
|
|
bool should_resize;
|
|
|
|
bool quitting;
|
|
|
|
bool fullscreen;
|
|
|
|
bool keep_aspect;
|
|
|
|
unsigned rotation;
|
|
|
|
|
2015-02-14 05:52:05 +01:00
|
|
|
struct video_viewport vp;
|
2012-10-28 00:38:31 +02:00
|
|
|
unsigned vp_out_width;
|
|
|
|
unsigned vp_out_height;
|
2015-06-22 21:09:18 +02:00
|
|
|
unsigned last_width[GFX_MAX_TEXTURES];
|
|
|
|
unsigned last_height[GFX_MAX_TEXTURES];
|
2012-05-26 15:21:51 +02:00
|
|
|
unsigned tex_w, tex_h;
|
2014-10-26 02:32:10 +01:00
|
|
|
math_matrix_4x4 mvp, mvp_no_rot;
|
2012-05-26 15:21:51 +02:00
|
|
|
|
2016-05-10 02:32:49 +02:00
|
|
|
struct video_coords coords;
|
2015-07-12 03:57:06 +02:00
|
|
|
const float *vertex_ptr;
|
|
|
|
const float *white_color_ptr;
|
2012-08-14 23:32:55 +02:00
|
|
|
|
2012-05-26 15:45:00 +02:00
|
|
|
GLuint pbo;
|
2013-01-03 01:18:19 +01:00
|
|
|
|
2012-10-20 01:12:02 +02:00
|
|
|
GLenum internal_fmt;
|
2014-09-12 02:51:23 +02:00
|
|
|
GLenum texture_type; /* RGB565 or ARGB */
|
2012-05-26 15:21:51 +02:00
|
|
|
GLenum texture_fmt;
|
2013-08-16 00:30:54 +02:00
|
|
|
GLenum wrap_mode;
|
2014-09-12 02:51:23 +02:00
|
|
|
unsigned base_size; /* 2 or 4 */
|
2013-10-29 23:21:15 +01:00
|
|
|
#ifdef HAVE_OPENGLES
|
|
|
|
bool support_unpack_row_length;
|
2014-01-01 21:42:31 +01:00
|
|
|
#else
|
|
|
|
bool have_es2_compat;
|
2013-10-29 23:21:15 +01:00
|
|
|
#endif
|
2015-11-27 21:21:04 -03:00
|
|
|
bool have_full_npot_support;
|
2012-05-26 15:21:51 +02:00
|
|
|
|
2012-10-19 23:08:53 -04:00
|
|
|
bool egl_images;
|
2013-07-06 22:10:09 +02:00
|
|
|
video_info_t video_info;
|
2012-11-21 16:24:28 +01:00
|
|
|
|
2012-12-23 18:36:58 +01:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-10-15 16:06:59 +02:00
|
|
|
unsigned overlays;
|
2012-12-20 11:16:22 +01:00
|
|
|
bool overlay_enable;
|
2013-01-11 16:23:04 +01:00
|
|
|
bool overlay_full_screen;
|
2014-06-13 17:46:53 +02:00
|
|
|
GLuint *overlay_tex;
|
2015-07-12 03:57:06 +02:00
|
|
|
float *overlay_vertex_coord;
|
|
|
|
float *overlay_tex_coord;
|
|
|
|
float *overlay_color_coord;
|
2012-12-23 18:36:58 +01:00
|
|
|
#endif
|
2012-12-19 13:26:11 +01:00
|
|
|
|
2014-04-19 17:22:25 +02:00
|
|
|
#ifdef HAVE_GL_ASYNC_READBACK
|
2014-09-12 02:51:23 +02:00
|
|
|
/* PBOs used for asynchronous viewport readbacks. */
|
2012-11-21 16:24:28 +01:00
|
|
|
GLuint pbo_readback[4];
|
2014-04-27 10:40:24 +02:00
|
|
|
bool pbo_readback_valid[4];
|
2012-11-21 16:24:28 +01:00
|
|
|
bool pbo_readback_enable;
|
|
|
|
unsigned pbo_readback_index;
|
2012-11-21 22:12:56 +01:00
|
|
|
struct scaler_ctx pbo_readback_scaler;
|
2012-11-21 16:24:28 +01:00
|
|
|
#endif
|
2014-02-06 21:35:57 +01:00
|
|
|
void *readback_buffer_screenshot;
|
2012-12-07 02:00:46 -05:00
|
|
|
|
2013-11-08 04:36:16 +01:00
|
|
|
#if defined(HAVE_MENU)
|
2014-06-10 02:15:29 +02:00
|
|
|
GLuint menu_texture;
|
|
|
|
bool menu_texture_enable;
|
|
|
|
bool menu_texture_full_screen;
|
2015-07-12 03:57:06 +02:00
|
|
|
float menu_texture_alpha;
|
2013-02-27 20:20:29 -05:00
|
|
|
#endif
|
|
|
|
|
2016-09-05 21:43:02 +02:00
|
|
|
#ifdef HAVE_GL_SYNC
|
|
|
|
#define MAX_FENCES 4
|
2013-05-04 22:48:24 +02:00
|
|
|
bool have_sync;
|
2013-05-26 13:43:24 +02:00
|
|
|
GLsync fences[MAX_FENCES];
|
|
|
|
unsigned fence_count;
|
2016-09-05 21:43:02 +02:00
|
|
|
#endif
|
2013-06-22 15:06:56 +02:00
|
|
|
|
|
|
|
GLuint vao;
|
2012-05-26 15:21:51 +02:00
|
|
|
} gl_t;
|
|
|
|
|
2015-01-19 21:24:08 +01:00
|
|
|
bool gl_load_luts(const struct video_shader *generic_shader,
|
2014-10-02 13:32:42 +02:00
|
|
|
GLuint *lut_textures);
|
2012-12-19 13:26:11 +01:00
|
|
|
|
2017-05-11 02:56:11 +02:00
|
|
|
#ifdef NO_GL_FF_VERTEX
|
|
|
|
#define gl_ff_vertex(coords) ((void)0)
|
|
|
|
#else
|
|
|
|
static INLINE void gl_ff_vertex(const struct video_coords *coords)
|
|
|
|
{
|
|
|
|
/* Fall back to fixed function-style if needed and possible. */
|
|
|
|
glClientActiveTexture(GL_TEXTURE1);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, coords->lut_tex_coord);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glClientActiveTexture(GL_TEXTURE0);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, coords->vertex);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glColorPointer(4, GL_FLOAT, 0, coords->color);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, coords->tex_coord);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_GL_FF_MATRIX
|
|
|
|
#define gl_ff_matrix(mat) ((void)0)
|
|
|
|
#else
|
|
|
|
static INLINE void gl_ff_matrix(const math_matrix_4x4 *mat)
|
|
|
|
{
|
|
|
|
math_matrix_4x4 ident;
|
|
|
|
|
|
|
|
/* Fall back to fixed function-style if needed and possible. */
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixf(mat->data);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
matrix_4x4_identity(ident);
|
|
|
|
glLoadMatrixf(ident.data);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-12 21:58:35 +01:00
|
|
|
static INLINE unsigned gl_wrap_type_to_enum(enum gfx_wrap_type type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
#ifndef HAVE_OPENGLES
|
|
|
|
case RARCH_WRAP_BORDER:
|
|
|
|
return GL_CLAMP_TO_BORDER;
|
|
|
|
#else
|
|
|
|
case RARCH_WRAP_BORDER:
|
|
|
|
#endif
|
|
|
|
case RARCH_WRAP_EDGE:
|
|
|
|
return GL_CLAMP_TO_EDGE;
|
|
|
|
case RARCH_WRAP_REPEAT:
|
|
|
|
return GL_REPEAT;
|
|
|
|
case RARCH_WRAP_MIRRORED_REPEAT:
|
|
|
|
return GL_MIRRORED_REPEAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-11 02:56:11 +02:00
|
|
|
|
2016-05-16 05:55:42 +02:00
|
|
|
bool gl_query_core_context_in_use(void);
|
2016-12-14 16:59:16 +01:00
|
|
|
void gl_load_texture_image(GLenum target,
|
2016-12-14 07:29:37 -08:00
|
|
|
GLint level,
|
|
|
|
GLint internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLint border,
|
|
|
|
GLenum format,
|
|
|
|
GLenum type,
|
|
|
|
const GLvoid * data);
|
2015-03-30 02:59:39 +02:00
|
|
|
|
2017-04-11 18:54:26 +01:00
|
|
|
RETRO_END_DECLS
|
|
|
|
|
2014-10-02 13:32:42 +02:00
|
|
|
#endif
|