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
|
2017-12-11 23:55:31 -08: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/>.
|
|
|
|
*/
|
|
|
|
|
2021-09-26 17:42:12 +02:00
|
|
|
#ifndef __GL2_COMMON_H
|
|
|
|
#define __GL2_COMMON_H
|
2011-01-11 22:13:55 +01:00
|
|
|
|
2017-12-04 06:03:11 +01:00
|
|
|
#include <boolean.h>
|
2015-07-12 04:20:48 +02:00
|
|
|
#include <string.h>
|
2018-10-10 18:24:41 +02:00
|
|
|
#include <libretro.h>
|
2017-12-04 06:03:11 +01:00
|
|
|
#include <retro_common_api.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 <gfx/math/matrix_4x4.h>
|
|
|
|
#include <gfx/scaler/scaler.h>
|
2019-01-20 01:49:21 +01:00
|
|
|
#include <glsym/glsym.h>
|
2015-07-12 04:20:48 +02:00
|
|
|
#include <formats/image.h>
|
|
|
|
|
2023-01-24 02:30:58 +01:00
|
|
|
#include "../video_driver.h"
|
2015-01-12 07:02:55 +01:00
|
|
|
|
2017-04-11 18:54:26 +01:00
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
|
2023-05-31 22:46:34 +02:00
|
|
|
#define GL2_BIND_TEXTURE(id, wrap_mode, mag_filter, min_filter) \
|
|
|
|
glBindTexture(GL_TEXTURE_2D, id); \
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode); \
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode); \
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); \
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter)
|
|
|
|
|
2017-12-04 06:03:11 +01:00
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
#define RARCH_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
|
|
|
|
#define RARCH_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES
|
|
|
|
#define RARCH_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
|
2022-01-24 16:22:07 +01:00
|
|
|
#elif (defined(__MACH__) && defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED < 101200))
|
2017-12-04 06:03:11 +01:00
|
|
|
#define RARCH_GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
|
|
|
|
#define RARCH_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
|
|
|
|
#define RARCH_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
|
|
|
|
#else
|
|
|
|
#define RARCH_GL_FRAMEBUFFER GL_FRAMEBUFFER
|
|
|
|
#define RARCH_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE
|
|
|
|
#define RARCH_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_OPENGLES2) || defined(HAVE_OPENGLES3) || defined(HAVE_OPENGLES_3_1) || defined(HAVE_OPENGLES_3_2)
|
|
|
|
#define RARCH_GL_RENDERBUFFER GL_RENDERBUFFER
|
|
|
|
#if defined(HAVE_OPENGLES2)
|
|
|
|
#define RARCH_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
|
|
|
|
#else
|
|
|
|
#define RARCH_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
|
|
|
|
#endif
|
|
|
|
#define RARCH_GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT
|
|
|
|
#define RARCH_GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT
|
2022-01-24 16:22:07 +01:00
|
|
|
#elif (defined(__MACH__) && defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED < 101200))
|
2017-12-04 06:03:11 +01:00
|
|
|
#define RARCH_GL_RENDERBUFFER GL_RENDERBUFFER_EXT
|
|
|
|
#define RARCH_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_EXT
|
|
|
|
#define RARCH_GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT
|
|
|
|
#define RARCH_GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT_EXT
|
|
|
|
#elif defined(HAVE_PSGL)
|
|
|
|
#define RARCH_GL_RENDERBUFFER GL_RENDERBUFFER_OES
|
|
|
|
#define RARCH_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_SCE
|
|
|
|
#define RARCH_GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES
|
|
|
|
#define RARCH_GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT_OES
|
|
|
|
#else
|
|
|
|
#define RARCH_GL_RENDERBUFFER GL_RENDERBUFFER
|
|
|
|
#define RARCH_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
|
|
|
|
#define RARCH_GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT
|
|
|
|
#define RARCH_GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT
|
|
|
|
#endif
|
|
|
|
|
2022-01-24 16:22:07 +01:00
|
|
|
#if (defined(__MACH__) && defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED < 101200))
|
2017-12-04 06:03:11 +01:00
|
|
|
#define RARCH_GL_MAX_RENDERBUFFER_SIZE GL_MAX_RENDERBUFFER_SIZE_EXT
|
|
|
|
#elif defined(HAVE_PSGL)
|
|
|
|
#define RARCH_GL_MAX_RENDERBUFFER_SIZE GL_MAX_RENDERBUFFER_SIZE_OES
|
|
|
|
#else
|
|
|
|
#define RARCH_GL_MAX_RENDERBUFFER_SIZE GL_MAX_RENDERBUFFER_SIZE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
#define glGenerateMipmap glGenerateMipmapOES
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__APPLE__) || defined(HAVE_PSGL)
|
2019-01-31 21:30:49 +01:00
|
|
|
#ifndef GL_RGBA32F
|
2017-12-04 06:03:11 +01:00
|
|
|
#define GL_RGBA32F GL_RGBA32F_ARB
|
|
|
|
#endif
|
2019-01-31 21:30:49 +01:00
|
|
|
#endif
|
2017-12-04 06:03:11 +01:00
|
|
|
|
|
|
|
#if defined(HAVE_PSGL)
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT32 GL_ARGB_SCE
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGB5 /* TODO: Verify if this is really 565 or just 555. */
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE32 GL_BGRA
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE16 GL_BGRA
|
|
|
|
#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV
|
|
|
|
#define RARCH_GL_FORMAT16 GL_RGB5
|
|
|
|
#elif defined(HAVE_OPENGLES)
|
|
|
|
/* Imgtec/SGX headers have this missing. */
|
|
|
|
#ifndef GL_BGRA_EXT
|
|
|
|
#define GL_BGRA_EXT 0x80E1
|
|
|
|
#endif
|
|
|
|
#ifndef GL_BGRA8_EXT
|
|
|
|
#define GL_BGRA8_EXT 0x93A1
|
|
|
|
#endif
|
|
|
|
#ifdef IOS
|
|
|
|
/* Stupid Apple */
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT32 GL_RGBA
|
|
|
|
#else
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT32 GL_BGRA_EXT
|
|
|
|
#endif
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGB
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE32 GL_BGRA_EXT
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE16 GL_RGB
|
|
|
|
#define RARCH_GL_FORMAT32 GL_UNSIGNED_BYTE
|
|
|
|
#define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_5_6_5
|
|
|
|
#else
|
|
|
|
/* On desktop, we always use 32-bit. */
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT32 GL_RGBA8
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGBA8
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE32 GL_BGRA
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE16 GL_BGRA
|
|
|
|
#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV
|
|
|
|
#define RARCH_GL_FORMAT16 GL_UNSIGNED_INT_8_8_8_8_REV
|
|
|
|
|
|
|
|
/* GL_RGB565 internal format isn't in desktop GL
|
|
|
|
* until 4.1 core (ARB_ES2_compatibility).
|
|
|
|
* Check for this. */
|
|
|
|
#ifndef GL_RGB565
|
|
|
|
#define GL_RGB565 0x8D62
|
|
|
|
#endif
|
|
|
|
#define RARCH_GL_INTERNAL_FORMAT16_565 GL_RGB565
|
|
|
|
#define RARCH_GL_TEXTURE_TYPE16_565 GL_RGB
|
|
|
|
#define RARCH_GL_FORMAT16_565 GL_UNSIGNED_SHORT_5_6_5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_OPENGLES2) /* TODO: Figure out exactly what. */
|
|
|
|
#define NO_GL_CLAMP_TO_BORDER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_OPENGLES)
|
|
|
|
#ifndef GL_UNPACK_ROW_LENGTH
|
|
|
|
#define GL_UNPACK_ROW_LENGTH 0x0CF2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_SRGB_ALPHA_EXT
|
|
|
|
#define GL_SRGB_ALPHA_EXT 0x8C42
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-09-26 17:42:12 +02:00
|
|
|
typedef struct gl2 gl2_t;
|
2018-05-13 05:53:06 +02:00
|
|
|
|
2023-01-23 18:22:13 +01:00
|
|
|
enum gl2_flags
|
|
|
|
{
|
2023-02-23 21:03:41 +01:00
|
|
|
GL2_FLAG_TEXTURE_MIPMAP = (1 << 0),
|
|
|
|
GL2_FLAG_SHOULD_RESIZE = (1 << 1),
|
|
|
|
GL2_FLAG_HAVE_MIPMAP = (1 << 2),
|
|
|
|
GL2_FLAG_QUITTING = (1 << 3),
|
|
|
|
GL2_FLAG_FULLSCREEN = (1 << 4),
|
|
|
|
GL2_FLAG_KEEP_ASPECT = (1 << 5),
|
|
|
|
GL2_FLAG_HAVE_FBO = (1 << 6),
|
|
|
|
GL2_FLAG_HW_RENDER_USE = (1 << 7),
|
|
|
|
GL2_FLAG_FBO_INITED = (1 << 8),
|
|
|
|
GL2_FLAG_FBO_FEEDBACK_ENABLE = (1 << 9),
|
|
|
|
GL2_FLAG_HW_RENDER_FBO_INIT = (1 << 10),
|
|
|
|
GL2_FLAG_SHARED_CONTEXT_USE = (1 << 11),
|
|
|
|
GL2_FLAG_CORE_CONTEXT_IN_USE = (1 << 12),
|
|
|
|
GL2_FLAG_HAVE_SYNC = (1 << 13),
|
|
|
|
GL2_FLAG_HAVE_UNPACK_ROW_LENGTH = (1 << 14),
|
|
|
|
GL2_FLAG_HAVE_ES2_COMPAT = (1 << 15),
|
|
|
|
GL2_FLAG_PBO_READBACK_ENABLE = (1 << 16),
|
|
|
|
GL2_FLAG_OVERLAY_ENABLE = (1 << 17),
|
|
|
|
GL2_FLAG_OVERLAY_FULLSCREEN = (1 << 18),
|
|
|
|
GL2_FLAG_MENU_TEXTURE_ENABLE = (1 << 19),
|
|
|
|
GL2_FLAG_MENU_TEXTURE_FULLSCREEN= (1 << 20),
|
2024-01-20 02:11:31 -05:00
|
|
|
GL2_FLAG_NONE = (1 << 21),
|
|
|
|
GL2_FLAG_FRAME_DUPE_LOCK = (1 << 22)
|
2023-01-23 18:22:13 +01:00
|
|
|
};
|
|
|
|
|
2021-09-26 17:42:12 +02:00
|
|
|
struct gl2
|
2012-05-26 15:21:51 +02:00
|
|
|
{
|
2020-08-17 15:09:19 +02:00
|
|
|
const shader_backend_t *shader;
|
|
|
|
void *shader_data;
|
|
|
|
void *renderchain_data;
|
|
|
|
void *ctx_data;
|
|
|
|
const gfx_ctx_driver_t *ctx_driver;
|
|
|
|
void *empty_buf;
|
|
|
|
void *conv_buffer;
|
|
|
|
void *readback_buffer_screenshot;
|
|
|
|
const float *vertex_ptr;
|
|
|
|
const float *white_color_ptr;
|
|
|
|
float *overlay_vertex_coord;
|
|
|
|
float *overlay_tex_coord;
|
|
|
|
float *overlay_color_coord;
|
2012-12-07 02:00:46 -05:00
|
|
|
|
2017-09-09 01:10:00 +02:00
|
|
|
int version_major;
|
|
|
|
int version_minor;
|
|
|
|
|
|
|
|
GLuint tex_mag_filter;
|
|
|
|
GLuint tex_min_filter;
|
|
|
|
GLuint fbo_feedback;
|
|
|
|
GLuint fbo_feedback_texture;
|
|
|
|
GLuint pbo;
|
|
|
|
GLuint *overlay_tex;
|
2014-06-10 02:15:29 +02:00
|
|
|
GLuint menu_texture;
|
2017-09-09 01:18:40 +02:00
|
|
|
GLuint pbo_readback[4];
|
|
|
|
GLuint texture[GFX_MAX_TEXTURES];
|
|
|
|
GLuint hw_render_fbo[GFX_MAX_TEXTURES];
|
2013-02-27 20:20:29 -05:00
|
|
|
|
2023-01-23 18:22:13 +01:00
|
|
|
uint32_t flags;
|
|
|
|
|
2019-08-13 12:14:33 +02:00
|
|
|
unsigned video_width;
|
|
|
|
unsigned video_height;
|
|
|
|
|
2017-09-09 01:10:00 +02:00
|
|
|
unsigned tex_index; /* For use with PREV. */
|
|
|
|
unsigned textures;
|
|
|
|
unsigned fbo_feedback_pass;
|
|
|
|
unsigned rotation;
|
|
|
|
unsigned vp_out_width;
|
|
|
|
unsigned vp_out_height;
|
|
|
|
unsigned tex_w;
|
|
|
|
unsigned tex_h;
|
|
|
|
unsigned base_size; /* 2 or 4 */
|
|
|
|
unsigned overlays;
|
|
|
|
unsigned pbo_readback_index;
|
2017-09-09 01:18:40 +02:00
|
|
|
unsigned last_width[GFX_MAX_TEXTURES];
|
|
|
|
unsigned last_height[GFX_MAX_TEXTURES];
|
2013-06-22 15:06:56 +02:00
|
|
|
|
2017-09-09 01:10:00 +02:00
|
|
|
float menu_texture_alpha;
|
|
|
|
|
2020-08-17 15:09:19 +02:00
|
|
|
GLenum internal_fmt;
|
|
|
|
GLenum texture_type; /* RGB565 or ARGB */
|
|
|
|
GLenum texture_fmt;
|
|
|
|
GLenum wrap_mode;
|
2017-09-09 01:10:00 +02:00
|
|
|
|
|
|
|
struct scaler_ctx pbo_readback_scaler;
|
2020-08-17 15:09:19 +02:00
|
|
|
struct video_viewport vp; /* int alignment */
|
2017-09-09 01:10:00 +02:00
|
|
|
math_matrix_4x4 mvp, mvp_no_rot;
|
2020-08-17 15:09:19 +02:00
|
|
|
struct video_coords coords; /* ptr alignment */
|
2017-09-09 01:10:00 +02:00
|
|
|
struct scaler_ctx scaler;
|
|
|
|
video_info_t video_info;
|
2020-08-17 15:09:19 +02:00
|
|
|
struct video_tex_info tex_info; /* unsigned int alignment */
|
|
|
|
struct video_tex_info prev_info[GFX_MAX_TEXTURES]; /* unsigned alignment */
|
|
|
|
struct video_fbo_rect fbo_rect[GFX_MAX_SHADERS]; /* unsigned alignment */
|
2017-09-09 01:10:00 +02:00
|
|
|
|
2023-09-06 03:08:48 +02:00
|
|
|
char device_str[128];
|
2020-08-17 15:09:19 +02:00
|
|
|
bool pbo_readback_valid[4];
|
2018-05-14 00:31:58 +02:00
|
|
|
};
|
2012-05-26 15:21:51 +02:00
|
|
|
|
2021-09-26 17:42:12 +02:00
|
|
|
bool gl2_load_luts(
|
2019-02-02 21:32:37 +01:00
|
|
|
const void *shader_data,
|
|
|
|
GLuint *textures_lut);
|
|
|
|
|
2017-04-11 18:54:26 +01:00
|
|
|
RETRO_END_DECLS
|
|
|
|
|
2014-10-02 13:32:42 +02:00
|
|
|
#endif
|