2014-10-02 13:27:35 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* 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
|
|
|
*
|
2014-10-02 13:27:35 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-12-14 07:29:37 -08:00
|
|
|
#include <gfx/gl_capabilities.h>
|
2016-09-08 08:15:40 +02:00
|
|
|
|
2016-12-21 16:09:29 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 06:03:11 +01:00
|
|
|
#include "gl_common.h"
|
2016-12-14 07:29:37 -08:00
|
|
|
|
2016-12-21 15:47:19 +01:00
|
|
|
static void gl_size_format(GLint* internalFormat)
|
2016-12-20 08:57:13 -08:00
|
|
|
{
|
2016-12-21 16:06:24 +01:00
|
|
|
#ifndef HAVE_PSGL
|
2016-12-20 08:57:13 -08:00
|
|
|
switch (*internalFormat)
|
|
|
|
{
|
|
|
|
case GL_RGB:
|
2016-12-21 15:47:19 +01:00
|
|
|
/* FIXME: PS3 does not support this, neither does it have GL_RGB565_OES. */
|
2016-12-20 08:57:13 -08:00
|
|
|
*internalFormat = GL_RGB565;
|
|
|
|
break;
|
|
|
|
case GL_RGBA:
|
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
*internalFormat = GL_RGBA8_OES;
|
|
|
|
#else
|
2016-12-26 13:00:38 -07:00
|
|
|
*internalFormat = GL_RGBA8;
|
2016-12-20 08:57:13 -08:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2016-12-21 16:06:24 +01:00
|
|
|
#endif
|
2016-12-20 08:57:13 -08:00
|
|
|
}
|
2016-12-21 16:06:24 +01:00
|
|
|
|
2016-12-14 07:29:37 -08:00
|
|
|
/* This function should only be used without mipmaps
|
|
|
|
and when data == NULL */
|
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)
|
|
|
|
{
|
2018-12-30 00:11:53 +01:00
|
|
|
#if !defined(HAVE_PSGL) && !defined(ORBIS)
|
2016-12-14 07:29:37 -08:00
|
|
|
#ifdef HAVE_OPENGLES2
|
2016-12-30 21:14:30 -07:00
|
|
|
if (gl_check_capability(GL_CAPS_TEX_STORAGE_EXT) && internalFormat != GL_BGRA_EXT)
|
2016-12-14 19:29:14 +01:00
|
|
|
{
|
2016-12-21 15:47:19 +01:00
|
|
|
gl_size_format(&internalFormat);
|
2016-12-14 07:29:37 -08:00
|
|
|
glTexStorage2DEXT(target, 1, internalFormat, width, height);
|
2016-12-14 09:54:55 -08:00
|
|
|
}
|
2016-12-14 07:29:37 -08:00
|
|
|
#else
|
2016-12-30 10:42:26 -07:00
|
|
|
if (gl_check_capability(GL_CAPS_TEX_STORAGE) && internalFormat != GL_BGRA_EXT)
|
2016-12-14 19:29:14 +01:00
|
|
|
{
|
2016-12-21 15:47:19 +01:00
|
|
|
gl_size_format(&internalFormat);
|
2016-12-14 07:29:37 -08:00
|
|
|
glTexStorage2D(target, 1, internalFormat, width, height);
|
2016-12-14 09:54:55 -08:00
|
|
|
}
|
2016-12-14 07:29:37 -08:00
|
|
|
#endif
|
|
|
|
else
|
|
|
|
#endif
|
2016-12-20 08:57:13 -08:00
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENGLES
|
|
|
|
if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED))
|
|
|
|
#endif
|
2016-12-21 15:47:19 +01:00
|
|
|
gl_size_format(&internalFormat);
|
2019-02-02 17:25:27 +01:00
|
|
|
glTexImage2D(target, level, internalFormat, width,
|
|
|
|
height, border, format, type, data);
|
2016-12-20 08:57:13 -08:00
|
|
|
}
|
2016-12-14 07:29:37 -08:00
|
|
|
}
|
2019-02-02 17:25:27 +01:00
|
|
|
|
|
|
|
bool gl_add_lut(
|
|
|
|
const char *lut_path,
|
|
|
|
bool lut_mipmap,
|
|
|
|
unsigned lut_filter,
|
|
|
|
enum gfx_wrap_type lut_wrap_type,
|
|
|
|
unsigned i, void *textures_data)
|
|
|
|
{
|
|
|
|
struct texture_image img;
|
|
|
|
GLuint *textures_lut = (GLuint*)textures_data;
|
|
|
|
enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR;
|
|
|
|
|
|
|
|
img.width = 0;
|
|
|
|
img.height = 0;
|
|
|
|
img.pixels = NULL;
|
|
|
|
img.supports_rgba = video_driver_supports_rgba();
|
|
|
|
|
|
|
|
if (!image_texture_load(&img, lut_path))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: Failed to load texture image from: \"%s\"\n",
|
|
|
|
lut_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("[GL]: Loaded texture image from: \"%s\" ...\n",
|
|
|
|
lut_path);
|
|
|
|
|
|
|
|
if (lut_filter == RARCH_FILTER_NEAREST)
|
|
|
|
filter_type = TEXTURE_FILTER_NEAREST;
|
|
|
|
|
|
|
|
if (lut_mipmap)
|
|
|
|
{
|
|
|
|
if (filter_type == TEXTURE_FILTER_NEAREST)
|
|
|
|
filter_type = TEXTURE_FILTER_MIPMAP_NEAREST;
|
|
|
|
else
|
|
|
|
filter_type = TEXTURE_FILTER_MIPMAP_LINEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_load_texture_data(
|
|
|
|
textures_lut[i],
|
|
|
|
lut_wrap_type,
|
|
|
|
filter_type, 4,
|
|
|
|
img.width, img.height,
|
|
|
|
img.pixels, sizeof(uint32_t));
|
|
|
|
image_texture_free(&img);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|