2014-05-08 17:39:12 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shader_common.h"
|
|
|
|
#include "../retroarch_logger.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
void gl_load_texture_data(GLuint obj, const struct texture_image *img,
|
|
|
|
GLenum wrap, bool linear, bool mipmap)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, obj);
|
|
|
|
|
2014-05-08 20:27:58 +00:00
|
|
|
#ifdef HAVE_PSGL
|
2014-05-08 20:40:00 +00:00
|
|
|
mipmap = false;
|
2014-05-08 17:39:12 +00:00
|
|
|
#endif
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
|
|
|
|
2014-05-11 17:02:01 +00:00
|
|
|
GLint mag_filter = linear ? GL_LINEAR : GL_NEAREST;
|
2014-05-11 15:52:36 +00:00
|
|
|
GLint min_filter = linear ? (mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) :
|
|
|
|
(mipmap ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
|
2014-05-08 17:39:12 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_PSGL
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
#endif
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, img->width, img->height,
|
|
|
|
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img->pixels);
|
2014-05-08 19:50:49 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2014-05-08 17:39:12 +00:00
|
|
|
if (mipmap)
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
2014-05-08 19:50:49 +00:00
|
|
|
#endif
|
2014-05-08 17:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gl_load_luts(const struct gfx_shader *generic_shader, GLuint *lut_textures)
|
|
|
|
{
|
2014-05-09 02:54:54 +00:00
|
|
|
unsigned i, num_luts;
|
|
|
|
|
|
|
|
num_luts = min(generic_shader->luts, GFX_MAX_TEXTURES);
|
|
|
|
|
2014-05-08 17:39:12 +00:00
|
|
|
if (!generic_shader->luts)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Original shader_glsl.c code only generated one texture handle. I assume
|
|
|
|
// it was a bug, but if not, replace num_luts with 1 when GLSL is used.
|
|
|
|
glGenTextures(num_luts, lut_textures);
|
|
|
|
for (i = 0; i < num_luts; i++)
|
|
|
|
{
|
2014-05-10 18:26:58 +00:00
|
|
|
bool ret = false;
|
2014-05-09 02:54:54 +00:00
|
|
|
struct texture_image img = {0};
|
2014-05-08 17:39:12 +00:00
|
|
|
RARCH_LOG("Loading texture image from: \"%s\" ...\n",
|
|
|
|
generic_shader->lut[i].path);
|
2014-05-10 18:26:58 +00:00
|
|
|
|
|
|
|
ret = driver.image && driver.image->load;
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
ret = driver.image->load(driver.video_data, generic_shader->lut[i].path, &img);
|
|
|
|
|
|
|
|
if (!ret)
|
2014-05-08 17:39:12 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to load texture image from: \"%s\"\n", generic_shader->lut[i].path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_load_texture_data(lut_textures[i], &img,
|
|
|
|
gl_wrap_type_to_enum(generic_shader->lut[i].wrap),
|
|
|
|
generic_shader->lut[i].filter != RARCH_FILTER_NEAREST,
|
|
|
|
generic_shader->lut[i].mipmap);
|
2014-05-10 18:26:58 +00:00
|
|
|
|
|
|
|
if (driver.image && driver.image->free)
|
|
|
|
driver.image->free(driver.video_data, &img);
|
2014-05-08 17:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // HAVE_OPENGL
|
|
|
|
|
|
|
|
|