2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-01-08 00:08:18 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
2011-01-05 18:07:12 +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
|
2011-01-05 18:07:12 +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;
|
2011-01-05 18:07:12 +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.
|
2011-01-05 18:07:12 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
#include "../boolean.h"
|
2011-01-05 18:07:12 +00:00
|
|
|
#include <string.h>
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../general.h"
|
2011-03-16 20:48:44 +00:00
|
|
|
#include "shader_glsl.h"
|
2012-03-16 22:26:57 +00:00
|
|
|
#include "../compat/strl.h"
|
|
|
|
#include "../compat/posix_string.h"
|
2012-04-07 10:17:40 +00:00
|
|
|
#include "state_tracker.h"
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../dynamic.h"
|
2012-11-18 16:08:28 +00:00
|
|
|
#include "../file.h"
|
2011-05-18 18:22:27 +00:00
|
|
|
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-01 20:48:19 +00:00
|
|
|
#if defined(__APPLE__) // Because they like to be "oh, so, special".
|
2011-02-04 12:46:51 +00:00
|
|
|
#include <OpenGL/gl.h>
|
2012-09-12 14:40:28 +00:00
|
|
|
#include <OpenGL/glext.h>
|
|
|
|
#elif defined(HAVE_PSGL)
|
|
|
|
#include <PSGL/psgl.h>
|
|
|
|
#include <PSGL/psglu.h>
|
|
|
|
#include <GLES/glext.h>
|
|
|
|
#elif defined(HAVE_OPENGL_MODERN)
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <GL3/gl3.h>
|
|
|
|
#include <GL3/gl3ext.h>
|
|
|
|
#elif defined(HAVE_OPENGLES2)
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#elif defined(HAVE_OPENGLES1)
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <GLES/glext.h>
|
2011-02-04 12:46:51 +00:00
|
|
|
#else
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
2011-01-05 18:07:12 +00:00
|
|
|
#include <GL/gl.h>
|
2011-02-04 12:46:51 +00:00
|
|
|
#include <GL/glext.h>
|
|
|
|
#endif
|
|
|
|
|
2012-05-26 02:47:24 +00:00
|
|
|
#include "gfx_context.h"
|
2011-01-05 18:07:12 +00:00
|
|
|
#include <stdlib.h>
|
2011-12-26 00:32:19 +00:00
|
|
|
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_XML
|
2011-01-05 18:07:12 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
2012-09-13 18:15:37 +00:00
|
|
|
#endif
|
2011-01-07 21:33:21 +00:00
|
|
|
|
2011-01-11 21:13:55 +00:00
|
|
|
#include "gl_common.h"
|
2011-05-18 18:22:27 +00:00
|
|
|
#include "image.h"
|
|
|
|
|
2012-10-01 20:48:19 +00:00
|
|
|
#if defined(HAVE_OPENGLES2) || defined(HAVE_OPENGL_MODERN) || defined(__APPLE__)
|
2012-09-15 13:17:34 +00:00
|
|
|
#define pglCreateProgram glCreateProgram
|
|
|
|
#define pglUseProgram glUseProgram
|
|
|
|
#define pglCreateShader glCreateShader
|
|
|
|
#define pglDeleteShader glDeleteShader
|
|
|
|
#define pglShaderSource glShaderSource
|
|
|
|
#define pglCompileShader glCompileShader
|
|
|
|
#define pglAttachShader glAttachShader
|
|
|
|
#define pglDetachShader glDetachShader
|
|
|
|
#define pglLinkProgram glLinkProgram
|
|
|
|
#define pglGetUniformLocation glGetUniformLocation
|
|
|
|
#define pglUniform1i glUniform1i
|
|
|
|
#define pglUniform1f glUniform1f
|
|
|
|
#define pglUniform2fv glUniform2fv
|
|
|
|
#define pglUniform4fv glUniform4fv
|
|
|
|
#define pglUniformMatrix4fv glUniformMatrix4fv
|
|
|
|
#define pglGetShaderiv glGetShaderiv
|
|
|
|
#define pglGetShaderInfoLog glGetShaderInfoLog
|
|
|
|
#define pglGetProgramiv glGetProgramiv
|
|
|
|
#define pglGetProgramInfoLog glGetProgramInfoLog
|
|
|
|
#define pglDeleteProgram glDeleteProgram
|
|
|
|
#define pglGetAttachedShaders glGetAttachedShaders
|
|
|
|
#define pglGetAttribLocation glGetAttribLocation
|
|
|
|
#define pglEnableVertexAttribArray glEnableVertexAttribArray
|
|
|
|
#define pglDisableVertexAttribArray glDisableVertexAttribArray
|
|
|
|
#define pglVertexAttribPointer glVertexAttribPointer
|
|
|
|
#else
|
2012-10-21 00:58:51 +00:00
|
|
|
static PFNGLCREATEPROGRAMPROC pglCreateProgram;
|
|
|
|
static PFNGLUSEPROGRAMPROC pglUseProgram;
|
|
|
|
static PFNGLCREATESHADERPROC pglCreateShader;
|
|
|
|
static PFNGLDELETESHADERPROC pglDeleteShader;
|
|
|
|
static PFNGLSHADERSOURCEPROC pglShaderSource;
|
|
|
|
static PFNGLCOMPILESHADERPROC pglCompileShader;
|
|
|
|
static PFNGLATTACHSHADERPROC pglAttachShader;
|
|
|
|
static PFNGLDETACHSHADERPROC pglDetachShader;
|
|
|
|
static PFNGLLINKPROGRAMPROC pglLinkProgram;
|
|
|
|
static PFNGLGETUNIFORMLOCATIONPROC pglGetUniformLocation;
|
|
|
|
static PFNGLUNIFORM1IPROC pglUniform1i;
|
|
|
|
static PFNGLUNIFORM1FPROC pglUniform1f;
|
|
|
|
static PFNGLUNIFORM2FVPROC pglUniform2fv;
|
|
|
|
static PFNGLUNIFORM4FVPROC pglUniform4fv;
|
|
|
|
static PFNGLUNIFORMMATRIX4FVPROC pglUniformMatrix4fv;
|
|
|
|
static PFNGLGETSHADERIVPROC pglGetShaderiv;
|
|
|
|
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog;
|
|
|
|
static PFNGLGETPROGRAMIVPROC pglGetProgramiv;
|
|
|
|
static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog;
|
|
|
|
static PFNGLDELETEPROGRAMPROC pglDeleteProgram;
|
|
|
|
static PFNGLGETATTACHEDSHADERSPROC pglGetAttachedShaders;
|
|
|
|
static PFNGLGETATTRIBLOCATIONPROC pglGetAttribLocation;
|
|
|
|
static PFNGLENABLEVERTEXATTRIBARRAYPROC pglEnableVertexAttribArray;
|
|
|
|
static PFNGLDISABLEVERTEXATTRIBARRAYPROC pglDisableVertexAttribArray;
|
|
|
|
static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer;
|
2012-09-15 13:17:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
#define BORDER_FUNC GL_CLAMP_TO_EDGE
|
|
|
|
#else
|
|
|
|
#define BORDER_FUNC GL_CLAMP_TO_BORDER
|
|
|
|
#endif
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-11-03 08:35:18 +00:00
|
|
|
#define MAX_VARIABLES 256
|
|
|
|
|
|
|
|
#ifdef RARCH_GPU_PERFORMANCE_MODE
|
|
|
|
#define MAX_PROGRAMS 8
|
|
|
|
#define MAX_TEXTURES 4
|
|
|
|
#define PREV_TEXTURES 3
|
|
|
|
#else
|
2011-03-12 14:30:57 +00:00
|
|
|
#define MAX_PROGRAMS 16
|
2011-05-18 18:27:27 +00:00
|
|
|
#define MAX_TEXTURES 8
|
2011-11-12 13:18:10 +00:00
|
|
|
#define PREV_TEXTURES 7
|
2012-11-03 08:35:18 +00:00
|
|
|
#endif
|
2011-03-12 14:30:57 +00:00
|
|
|
|
2011-03-14 20:28:30 +00:00
|
|
|
enum filter_type
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_GL_NOFORCE,
|
|
|
|
RARCH_GL_LINEAR,
|
|
|
|
RARCH_GL_NEAREST
|
2011-03-14 20:28:30 +00:00
|
|
|
};
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
static bool glsl_enable;
|
|
|
|
static bool glsl_modern;
|
|
|
|
static GLuint gl_program[MAX_PROGRAMS];
|
|
|
|
static enum filter_type gl_filter_type[MAX_PROGRAMS];
|
2011-03-14 21:51:03 +00:00
|
|
|
static struct gl_fbo_scale gl_scale[MAX_PROGRAMS];
|
2012-10-21 00:58:51 +00:00
|
|
|
static unsigned gl_num_programs;
|
|
|
|
static unsigned active_index;
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2011-05-18 18:22:27 +00:00
|
|
|
static GLuint gl_teximage[MAX_TEXTURES];
|
2012-10-21 00:58:51 +00:00
|
|
|
static unsigned gl_teximage_cnt;
|
2011-05-18 18:22:27 +00:00
|
|
|
static char gl_teximage_uniforms[MAX_TEXTURES][64];
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
static state_tracker_t *gl_state_tracker;
|
2012-04-07 10:17:40 +00:00
|
|
|
static struct state_tracker_uniform_info gl_tracker_info[MAX_VARIABLES];
|
2012-10-21 00:58:51 +00:00
|
|
|
static unsigned gl_tracker_info_cnt;
|
2012-01-02 12:32:25 +00:00
|
|
|
static char gl_tracker_script[PATH_MAX];
|
2011-06-06 16:50:36 +00:00
|
|
|
static char gl_tracker_script_class[64];
|
2012-09-13 18:15:37 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
static char *gl_script_program;
|
2011-05-25 13:58:12 +00:00
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
static GLint gl_attribs[PREV_TEXTURES + 1 + 4 + MAX_PROGRAMS];
|
2012-10-21 00:58:51 +00:00
|
|
|
static unsigned gl_attrib_index;
|
2011-11-12 17:20:54 +00:00
|
|
|
|
2012-09-24 23:26:22 +00:00
|
|
|
static gfx_ctx_proc_t (*glsl_get_proc_address)(const char*);
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
struct shader_program
|
|
|
|
{
|
|
|
|
char *vertex;
|
|
|
|
char *fragment;
|
2011-03-14 20:28:30 +00:00
|
|
|
enum filter_type filter;
|
2011-03-14 21:51:03 +00:00
|
|
|
|
|
|
|
float scale_x;
|
|
|
|
float scale_y;
|
2011-03-27 18:29:47 +00:00
|
|
|
unsigned abs_x;
|
|
|
|
unsigned abs_y;
|
|
|
|
enum gl_scale_type type_x;
|
|
|
|
enum gl_scale_type type_y;
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
bool valid_scale;
|
2011-03-12 14:30:57 +00:00
|
|
|
};
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
struct shader_uniforms_frame
|
|
|
|
{
|
|
|
|
int texture;
|
|
|
|
int input_size;
|
|
|
|
int texture_size;
|
|
|
|
int tex_coord;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct shader_uniforms
|
|
|
|
{
|
|
|
|
int mvp;
|
|
|
|
int tex_coord;
|
|
|
|
int vertex_coord;
|
|
|
|
int color;
|
|
|
|
int lut_tex_coord;
|
|
|
|
|
|
|
|
int input_size;
|
|
|
|
int output_size;
|
|
|
|
int texture_size;
|
|
|
|
|
|
|
|
int frame_count;
|
|
|
|
int frame_direction;
|
|
|
|
|
|
|
|
int lut_texture[MAX_TEXTURES];
|
|
|
|
|
|
|
|
struct shader_uniforms_frame orig;
|
|
|
|
struct shader_uniforms_frame pass[MAX_PROGRAMS];
|
|
|
|
struct shader_uniforms_frame prev[PREV_TEXTURES];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct shader_uniforms gl_uniforms[MAX_PROGRAMS];
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
static const char *stock_vertex_legacy =
|
2011-11-12 14:26:24 +00:00
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
|
|
|
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
|
|
|
" color = gl_Color;\n"
|
|
|
|
"}";
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
static const char *stock_fragment_legacy =
|
2011-11-12 14:26:24 +00:00
|
|
|
"uniform sampler2D rubyTexture;\n"
|
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" gl_FragColor = color * texture2D(rubyTexture, gl_TexCoord[0].xy);\n"
|
|
|
|
"}";
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
static const char *stock_vertex_modern =
|
|
|
|
"attribute vec2 rubyTexCoord;\n"
|
|
|
|
"attribute vec2 rubyVertexCoord;\n"
|
|
|
|
"attribute vec4 rubyColor;\n"
|
|
|
|
"uniform mat4 rubyMVPMatrix;\n"
|
|
|
|
"varying vec2 tex_coord;\n"
|
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" gl_Position = rubyMVPMatrix * vec4(rubyVertexCoord, 0.0, 1.0);\n"
|
|
|
|
" tex_coord = rubyTexCoord;\n"
|
|
|
|
" color = rubyColor;\n"
|
|
|
|
"}";
|
|
|
|
|
|
|
|
static const char *stock_fragment_modern =
|
2012-09-13 17:55:42 +00:00
|
|
|
"#ifdef GL_ES\n"
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"#endif\n"
|
2012-09-11 21:32:00 +00:00
|
|
|
"uniform sampler2D rubyTexture;\n"
|
|
|
|
"varying vec2 tex_coord;\n"
|
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main() {\n"
|
|
|
|
" gl_FragColor = color * texture2D(rubyTexture, tex_coord);\n"
|
|
|
|
"}";
|
|
|
|
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_XML
|
2011-03-29 21:45:10 +00:00
|
|
|
static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr)
|
2011-03-14 21:51:03 +00:00
|
|
|
{
|
|
|
|
prog->scale_x = 1.0;
|
|
|
|
prog->scale_y = 1.0;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = prog->type_y = RARCH_SCALE_INPUT;
|
2011-03-14 21:51:03 +00:00
|
|
|
prog->valid_scale = false;
|
|
|
|
|
|
|
|
// Check if shader forces a certain texture filtering.
|
|
|
|
xmlChar *attr = xmlGetProp(ptr, (const xmlChar*)"filter");
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
if (strcmp((const char*)attr, "nearest") == 0)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->filter = RARCH_GL_NEAREST;
|
|
|
|
RARCH_LOG("XML: Shader forces GL_NEAREST.\n");
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
|
|
|
else if (strcmp((const char*)attr, "linear") == 0)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->filter = RARCH_GL_LINEAR;
|
|
|
|
RARCH_LOG("XML: Shader forces GL_LINEAR.\n");
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
|
|
|
else
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("XML: Invalid property for filter.\n");
|
2011-03-14 21:51:03 +00:00
|
|
|
|
|
|
|
xmlFree(attr);
|
|
|
|
}
|
|
|
|
else
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->filter = RARCH_GL_NOFORCE;
|
2011-03-14 21:51:03 +00:00
|
|
|
|
2011-03-27 18:29:47 +00:00
|
|
|
// Check for scaling attributes *lots of code <_<*
|
2011-03-14 21:51:03 +00:00
|
|
|
xmlChar *attr_scale = xmlGetProp(ptr, (const xmlChar*)"scale");
|
|
|
|
xmlChar *attr_scale_x = xmlGetProp(ptr, (const xmlChar*)"scale_x");
|
|
|
|
xmlChar *attr_scale_y = xmlGetProp(ptr, (const xmlChar*)"scale_y");
|
2011-03-27 18:29:47 +00:00
|
|
|
xmlChar *attr_size = xmlGetProp(ptr, (const xmlChar*)"size");
|
|
|
|
xmlChar *attr_size_x = xmlGetProp(ptr, (const xmlChar*)"size_x");
|
|
|
|
xmlChar *attr_size_y = xmlGetProp(ptr, (const xmlChar*)"size_y");
|
|
|
|
xmlChar *attr_outscale = xmlGetProp(ptr, (const xmlChar*)"outscale");
|
|
|
|
xmlChar *attr_outscale_x = xmlGetProp(ptr, (const xmlChar*)"outscale_x");
|
|
|
|
xmlChar *attr_outscale_y = xmlGetProp(ptr, (const xmlChar*)"outscale_y");
|
2011-03-14 22:59:31 +00:00
|
|
|
|
2011-03-29 21:45:10 +00:00
|
|
|
unsigned x_attr_cnt = 0, y_attr_cnt = 0;
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
if (attr_scale)
|
|
|
|
{
|
|
|
|
float scale = strtod((const char*)attr_scale, NULL);
|
|
|
|
prog->scale_x = scale;
|
|
|
|
prog->scale_y = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = prog->type_y = RARCH_SCALE_INPUT;
|
|
|
|
RARCH_LOG("Got scale attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
|
|
|
y_attr_cnt++;
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
2011-03-14 22:59:31 +00:00
|
|
|
|
|
|
|
if (attr_scale_x)
|
2011-03-14 21:51:03 +00:00
|
|
|
{
|
2011-03-14 22:48:19 +00:00
|
|
|
float scale = strtod((const char*)attr_scale_x, NULL);
|
2011-03-14 21:51:03 +00:00
|
|
|
prog->scale_x = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = RARCH_SCALE_INPUT;
|
|
|
|
RARCH_LOG("Got scale_x attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
2011-03-14 22:59:31 +00:00
|
|
|
|
|
|
|
if (attr_scale_y)
|
2011-03-14 21:51:03 +00:00
|
|
|
{
|
2011-03-14 22:48:19 +00:00
|
|
|
float scale = strtod((const char*)attr_scale_y, NULL);
|
2011-03-14 21:51:03 +00:00
|
|
|
prog->scale_y = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_y = RARCH_SCALE_INPUT;
|
|
|
|
RARCH_LOG("Got scale_y attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
y_attr_cnt++;
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
2011-03-27 18:29:47 +00:00
|
|
|
if (attr_size)
|
|
|
|
{
|
2011-03-27 19:21:46 +00:00
|
|
|
prog->abs_x = prog->abs_y = strtoul((const char*)attr_size, NULL, 0);
|
2011-03-27 18:29:47 +00:00
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = prog->type_y = RARCH_SCALE_ABSOLUTE;
|
|
|
|
RARCH_LOG("Got size attr: %u\n", prog->abs_x);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
|
|
|
y_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_size_x)
|
|
|
|
{
|
|
|
|
prog->abs_x = strtoul((const char*)attr_size_x, NULL, 0);
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = RARCH_SCALE_ABSOLUTE;
|
|
|
|
RARCH_LOG("Got size_x attr: %u\n", prog->abs_x);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_size_y)
|
|
|
|
{
|
|
|
|
prog->abs_y = strtoul((const char*)attr_size_y, NULL, 0);
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_y = RARCH_SCALE_ABSOLUTE;
|
|
|
|
RARCH_LOG("Got size_y attr: %u\n", prog->abs_y);
|
2011-03-29 21:45:10 +00:00
|
|
|
y_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_outscale)
|
|
|
|
{
|
|
|
|
float scale = strtod((const char*)attr_outscale, NULL);
|
|
|
|
prog->scale_x = scale;
|
|
|
|
prog->scale_y = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = prog->type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
RARCH_LOG("Got outscale attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
|
|
|
y_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_outscale_x)
|
|
|
|
{
|
|
|
|
float scale = strtod((const char*)attr_outscale_x, NULL);
|
|
|
|
prog->scale_x = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_x = RARCH_SCALE_VIEWPORT;
|
|
|
|
RARCH_LOG("Got outscale_x attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
x_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr_outscale_y)
|
|
|
|
{
|
|
|
|
float scale = strtod((const char*)attr_outscale_y, NULL);
|
|
|
|
prog->scale_y = scale;
|
|
|
|
prog->valid_scale = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
prog->type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
RARCH_LOG("Got outscale_y attr: %.1f\n", scale);
|
2011-03-29 21:45:10 +00:00
|
|
|
y_attr_cnt++;
|
2011-03-27 18:29:47 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
if (attr_scale)
|
|
|
|
xmlFree(attr_scale);
|
|
|
|
if (attr_scale_x)
|
|
|
|
xmlFree(attr_scale_x);
|
|
|
|
if (attr_scale_y)
|
|
|
|
xmlFree(attr_scale_y);
|
2011-03-27 18:29:47 +00:00
|
|
|
if (attr_size)
|
|
|
|
xmlFree(attr_size);
|
|
|
|
if (attr_size_x)
|
|
|
|
xmlFree(attr_size_x);
|
|
|
|
if (attr_size_y)
|
|
|
|
xmlFree(attr_size_y);
|
|
|
|
if (attr_outscale)
|
|
|
|
xmlFree(attr_outscale);
|
|
|
|
if (attr_outscale_x)
|
|
|
|
xmlFree(attr_outscale_x);
|
|
|
|
if (attr_outscale_y)
|
|
|
|
xmlFree(attr_outscale_y);
|
|
|
|
|
2011-03-29 21:45:10 +00:00
|
|
|
if (x_attr_cnt > 1)
|
|
|
|
return false;
|
|
|
|
if (y_attr_cnt > 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 18:22:27 +00:00
|
|
|
static bool get_texture_image(const char *shader_path, xmlNodePtr ptr)
|
|
|
|
{
|
2011-05-18 18:27:27 +00:00
|
|
|
if (gl_teximage_cnt >= MAX_TEXTURES)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Too many texture images. Ignoring ...\n");
|
2011-05-18 18:27:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-18 18:22:27 +00:00
|
|
|
bool linear = true;
|
|
|
|
xmlChar *filename = xmlGetProp(ptr, (const xmlChar*)"file");
|
2012-11-18 16:08:28 +00:00
|
|
|
xmlChar *filter = xmlGetProp(ptr, (const xmlChar*)"filter");
|
|
|
|
xmlChar *id = xmlGetProp(ptr, (const xmlChar*)"id");
|
2011-12-24 12:46:12 +00:00
|
|
|
struct texture_image img;
|
2011-05-18 18:22:27 +00:00
|
|
|
|
|
|
|
if (!id)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Could not find ID in texture.\n");
|
2011-05-18 18:22:27 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Could not find filename in texture.\n");
|
2011-05-18 18:22:27 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter && strcmp((const char*)filter, "nearest") == 0)
|
|
|
|
linear = false;
|
|
|
|
|
2012-01-02 12:32:25 +00:00
|
|
|
char tex_path[PATH_MAX];
|
2012-11-18 16:08:28 +00:00
|
|
|
fill_pathname_resolve_relative(tex_path, shader_path, (const char*)filename, sizeof(tex_path));
|
2011-05-18 18:22:27 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading texture image from: \"%s\" ...\n", tex_path);
|
2011-05-18 18:22:27 +00:00
|
|
|
if (!texture_image_load(tex_path, &img))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load texture image from: \"%s\"\n", tex_path);
|
2011-05-18 18:22:27 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(gl_teximage_uniforms[gl_teximage_cnt], (const char*)id, sizeof(gl_teximage_uniforms[0]));
|
|
|
|
|
|
|
|
glGenTextures(1, &gl_teximage[gl_teximage_cnt]);
|
2011-05-18 20:11:34 +00:00
|
|
|
|
|
|
|
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
|
2011-05-18 18:22:27 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, gl_teximage[gl_teximage_cnt]);
|
2012-09-15 13:17:34 +00:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, BORDER_FUNC);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, BORDER_FUNC);
|
2011-05-18 18:22:27 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-10-19 23:12:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT32,
|
|
|
|
img.width, img.height, 0, RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img.pixels);
|
2011-05-18 18:22:27 +00:00
|
|
|
|
2011-05-18 20:11:34 +00:00
|
|
|
pglActiveTexture(GL_TEXTURE0);
|
2011-05-18 18:22:27 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
free(img.pixels);
|
|
|
|
|
|
|
|
xmlFree(filename);
|
|
|
|
xmlFree(id);
|
|
|
|
if (filter)
|
|
|
|
xmlFree(filter);
|
|
|
|
|
|
|
|
gl_teximage_cnt++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (filename)
|
|
|
|
xmlFree(filename);
|
|
|
|
if (filter)
|
|
|
|
xmlFree(filter);
|
|
|
|
if (filter)
|
|
|
|
xmlFree(id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-07 14:28:58 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
static bool get_script(const char *path, xmlNodePtr ptr)
|
2011-06-07 13:33:29 +00:00
|
|
|
{
|
2011-06-07 14:28:58 +00:00
|
|
|
if (*gl_tracker_script || gl_script_program)
|
2011-06-07 13:33:29 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Script already imported.\n");
|
2011-06-07 13:33:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlChar *script_class = xmlGetProp(ptr, (const xmlChar*)"class");
|
|
|
|
if (script_class)
|
|
|
|
{
|
|
|
|
strlcpy(gl_tracker_script_class, (const char*)script_class, sizeof(gl_tracker_script_class));
|
|
|
|
xmlFree(script_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlChar *language = xmlGetProp(ptr, (const xmlChar*)"language");
|
|
|
|
if (!language || strcmp((const char*)language, "python") != 0)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Script language is not Python.\n");
|
2011-06-07 13:33:29 +00:00
|
|
|
if (language)
|
|
|
|
xmlFree(language);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (language)
|
|
|
|
xmlFree(language);
|
|
|
|
|
2011-06-07 14:28:58 +00:00
|
|
|
xmlChar *src = xmlGetProp(ptr, (const xmlChar*)"src");
|
|
|
|
if (src)
|
2011-06-07 13:33:29 +00:00
|
|
|
{
|
2012-11-18 16:08:28 +00:00
|
|
|
fill_pathname_resolve_relative(gl_tracker_script, path, (const char*)src, sizeof(gl_tracker_script));
|
2011-06-07 14:28:58 +00:00
|
|
|
xmlFree(src);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlChar *script = xmlNodeGetContent(ptr);
|
|
|
|
if (!script)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No content in script.\n");
|
2011-06-07 14:28:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-13 18:15:37 +00:00
|
|
|
gl_script_program = strdup((const char*)script);
|
|
|
|
xmlFree(script);
|
2011-06-07 13:33:29 +00:00
|
|
|
}
|
2011-06-07 14:28:58 +00:00
|
|
|
|
2011-06-07 13:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-06-07 14:28:58 +00:00
|
|
|
#endif
|
2011-06-07 13:33:29 +00:00
|
|
|
|
2011-06-07 14:28:58 +00:00
|
|
|
static bool get_import_value(xmlNodePtr ptr)
|
2011-05-25 13:58:12 +00:00
|
|
|
{
|
2012-02-12 17:05:33 +00:00
|
|
|
bool ret = true;
|
2011-05-25 18:55:38 +00:00
|
|
|
if (gl_tracker_info_cnt >= MAX_VARIABLES)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Too many import variables ...\n");
|
2011-05-25 18:55:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-25 13:58:12 +00:00
|
|
|
xmlChar *id = xmlGetProp(ptr, (const xmlChar*)"id");
|
|
|
|
xmlChar *semantic = xmlGetProp(ptr, (const xmlChar*)"semantic");
|
|
|
|
xmlChar *wram = xmlGetProp(ptr, (const xmlChar*)"wram");
|
2011-06-11 18:02:17 +00:00
|
|
|
xmlChar *input = xmlGetProp(ptr, (const xmlChar*)"input_slot");
|
2011-05-29 21:58:04 +00:00
|
|
|
xmlChar *bitmask = xmlGetProp(ptr, (const xmlChar*)"mask");
|
2012-02-12 17:05:33 +00:00
|
|
|
xmlChar *bitequal = xmlGetProp(ptr, (const xmlChar*)"equal");
|
2011-05-25 13:58:12 +00:00
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
unsigned memtype;
|
2012-04-07 10:17:40 +00:00
|
|
|
enum state_tracker_type tracker_type;
|
2012-04-21 21:25:32 +00:00
|
|
|
enum state_ram_type ram_type = RARCH_STATE_NONE;
|
2011-12-24 12:46:12 +00:00
|
|
|
uint32_t addr = 0;
|
|
|
|
unsigned mask_value = 0;
|
2012-02-12 17:05:33 +00:00
|
|
|
unsigned mask_equal = 0;
|
2011-12-24 12:46:12 +00:00
|
|
|
|
2011-05-25 13:58:12 +00:00
|
|
|
if (!semantic || !id)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No semantic or ID for import value.\n");
|
2012-02-12 17:05:33 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
2011-06-06 16:50:36 +00:00
|
|
|
|
|
|
|
if (strcmp((const char*)semantic, "capture") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_CAPTURE;
|
2011-06-06 16:50:36 +00:00
|
|
|
else if (strcmp((const char*)semantic, "capture_previous") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_CAPTURE_PREV;
|
2011-06-06 16:50:36 +00:00
|
|
|
else if (strcmp((const char*)semantic, "transition") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION;
|
2011-06-06 19:32:10 +00:00
|
|
|
else if (strcmp((const char*)semantic, "transition_count") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION_COUNT;
|
2011-06-06 16:50:36 +00:00
|
|
|
else if (strcmp((const char*)semantic, "transition_previous") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION_PREV;
|
2011-06-06 16:50:36 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
else if (strcmp((const char*)semantic, "python") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_PYTHON;
|
2011-06-06 16:50:36 +00:00
|
|
|
#endif
|
2011-05-25 13:58:12 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Invalid semantic for import value.\n");
|
2012-02-12 17:05:33 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 16:50:36 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
2012-04-21 21:25:32 +00:00
|
|
|
if (tracker_type != RARCH_STATE_PYTHON)
|
2011-06-06 16:50:36 +00:00
|
|
|
#endif
|
2011-10-26 17:51:10 +00:00
|
|
|
{
|
2011-06-11 18:02:17 +00:00
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
unsigned slot = strtoul((const char*)input, NULL, 0);
|
|
|
|
switch (slot)
|
|
|
|
{
|
|
|
|
case 1:
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_INPUT_SLOT1;
|
2011-06-11 18:02:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_INPUT_SLOT2;
|
2011-06-11 18:02:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Invalid input slot for import.\n");
|
2012-02-12 17:05:33 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-06-11 18:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 10:17:40 +00:00
|
|
|
else if (wram)
|
|
|
|
{
|
|
|
|
addr = strtoul((const char*)wram, NULL, 16);
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_WRAM;
|
2012-04-07 10:17:40 +00:00
|
|
|
}
|
2011-06-06 16:50:36 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No RAM address specificed for import value.\n");
|
2012-02-12 17:05:33 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-06-06 16:50:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-25 13:58:12 +00:00
|
|
|
switch (ram_type)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_STATE_WRAM:
|
2012-04-07 10:17:40 +00:00
|
|
|
memtype = RETRO_MEMORY_SYSTEM_RAM;
|
2011-05-25 13:58:12 +00:00
|
|
|
break;
|
2011-06-06 16:50:36 +00:00
|
|
|
|
2011-05-25 13:58:12 +00:00
|
|
|
default:
|
2011-10-26 17:51:10 +00:00
|
|
|
memtype = -1u;
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
if ((memtype != -1u) && (addr >= pretro_get_memory_size(memtype)))
|
2011-05-28 13:06:46 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Address out of bounds.\n");
|
2012-02-12 17:05:33 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-28 13:06:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 21:58:04 +00:00
|
|
|
if (bitmask)
|
|
|
|
mask_value = strtoul((const char*)bitmask, NULL, 16);
|
2012-02-12 17:05:33 +00:00
|
|
|
if (bitequal)
|
|
|
|
mask_equal = strtoul((const char*)bitequal, NULL, 16);
|
2011-05-29 21:58:04 +00:00
|
|
|
|
2011-05-25 13:58:12 +00:00
|
|
|
strlcpy(gl_tracker_info[gl_tracker_info_cnt].id, (const char*)id, sizeof(gl_tracker_info[0].id));
|
|
|
|
gl_tracker_info[gl_tracker_info_cnt].addr = addr;
|
|
|
|
gl_tracker_info[gl_tracker_info_cnt].type = tracker_type;
|
|
|
|
gl_tracker_info[gl_tracker_info_cnt].ram_type = ram_type;
|
2011-05-29 21:58:04 +00:00
|
|
|
gl_tracker_info[gl_tracker_info_cnt].mask = mask_value;
|
2012-02-12 17:05:33 +00:00
|
|
|
gl_tracker_info[gl_tracker_info_cnt].equal = mask_equal;
|
2011-05-25 13:58:12 +00:00
|
|
|
gl_tracker_info_cnt++;
|
|
|
|
|
2012-02-12 17:05:33 +00:00
|
|
|
end:
|
2011-05-25 13:58:12 +00:00
|
|
|
if (id) xmlFree(id);
|
|
|
|
if (semantic) xmlFree(semantic);
|
|
|
|
if (wram) xmlFree(wram);
|
2011-06-11 18:02:17 +00:00
|
|
|
if (input) xmlFree(input);
|
2011-05-29 21:58:04 +00:00
|
|
|
if (bitmask) xmlFree(bitmask);
|
2012-02-12 17:05:33 +00:00
|
|
|
if (bitequal) xmlFree(bitequal);
|
|
|
|
return ret;
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-18 16:39:39 +00:00
|
|
|
static char *xml_replace_if_file(char *content, const char *path, xmlNodePtr node, const char *src_prop)
|
|
|
|
{
|
|
|
|
xmlChar *prop = xmlGetProp(node, (const xmlChar*)src_prop);
|
|
|
|
if (!prop)
|
|
|
|
return content;
|
|
|
|
|
|
|
|
free(content);
|
|
|
|
content = NULL;
|
|
|
|
|
|
|
|
char shader_path[PATH_MAX];
|
|
|
|
fill_pathname_resolve_relative(shader_path, path, (const char*)prop, sizeof(shader_path));
|
|
|
|
|
|
|
|
RARCH_LOG("Loading external source from \"%s\".\n", shader_path);
|
|
|
|
if (read_file(shader_path, (void**)&content) >= 0)
|
|
|
|
return content;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
static unsigned get_xml_shaders(const char *path, struct shader_program *prog, size_t size)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
|
|
|
LIBXML_TEST_VERSION;
|
|
|
|
|
|
|
|
xmlParserCtxtPtr ctx = xmlNewParserCtxt();
|
|
|
|
if (!ctx)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load libxml2 context.\n");
|
2011-01-05 18:07:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading XML shader: %s\n", path);
|
2011-01-05 18:07:12 +00:00
|
|
|
xmlDocPtr doc = xmlCtxtReadFile(ctx, path, NULL, 0);
|
2011-12-24 12:46:12 +00:00
|
|
|
xmlNodePtr head = NULL;
|
|
|
|
xmlNodePtr cur = NULL;
|
|
|
|
unsigned num = 0;
|
|
|
|
|
2011-01-05 18:07:12 +00:00
|
|
|
if (!doc)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to parse XML file: %s\n", path);
|
2011-01-05 18:07:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->valid == 0)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Cannot validate XML shader: %s\n", path);
|
2011-01-05 18:07:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
head = xmlDocGetRootElement(doc);
|
|
|
|
|
2011-01-05 18:07:12 +00:00
|
|
|
for (cur = head; cur; cur = cur->next)
|
|
|
|
{
|
2012-09-11 21:32:00 +00:00
|
|
|
if (cur->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
if (strcmp((const char*)cur->name, "shader") != 0)
|
|
|
|
continue;
|
2011-03-14 21:51:03 +00:00
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
xmlChar *attr;
|
|
|
|
attr = xmlGetProp(cur, (const xmlChar*)"language");
|
|
|
|
if (attr && strcmp((const char*)attr, "GLSL") != 0)
|
|
|
|
{
|
|
|
|
xmlFree(attr);
|
|
|
|
continue;
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
2012-09-11 21:32:00 +00:00
|
|
|
|
|
|
|
if (attr)
|
|
|
|
xmlFree(attr);
|
|
|
|
|
|
|
|
attr = xmlGetProp(cur, (const xmlChar*)"style");
|
|
|
|
glsl_modern = attr && (strcmp((const char*)attr, "GLES2") == 0);
|
|
|
|
if (attr)
|
|
|
|
xmlFree(attr);
|
|
|
|
|
|
|
|
if (glsl_modern)
|
|
|
|
RARCH_LOG("[GL]: Shader reports a GLES2 style shader.\n");
|
|
|
|
break;
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cur) // We couldn't find any GLSL shader :(
|
|
|
|
goto error;
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
memset(prog, 0, sizeof(struct shader_program) * size);
|
|
|
|
|
2011-01-05 18:07:12 +00:00
|
|
|
// Iterate to check if we find fragment and/or vertex shaders.
|
2011-03-12 14:30:57 +00:00
|
|
|
for (cur = cur->children; cur && num < size; cur = cur->next)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
|
|
|
if (cur->type != XML_ELEMENT_NODE)
|
|
|
|
continue;
|
|
|
|
|
2012-11-18 16:39:39 +00:00
|
|
|
xmlChar *content_ = xmlNodeGetContent(cur);
|
|
|
|
if (!content_)
|
|
|
|
continue;
|
|
|
|
char *content = strdup((const char*)content_);
|
|
|
|
xmlFree(content_);
|
2011-01-05 18:07:12 +00:00
|
|
|
if (!content)
|
|
|
|
continue;
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
if (strcmp((const char*)cur->name, "vertex") == 0)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2011-03-12 14:30:57 +00:00
|
|
|
if (prog[num].vertex)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Cannot have more than one vertex shader in a program.\n");
|
2012-11-18 16:39:39 +00:00
|
|
|
free(content);
|
2011-03-12 14:30:57 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-11-18 16:39:39 +00:00
|
|
|
content = xml_replace_if_file(content, path, cur, "src");
|
|
|
|
if (!content)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Shader source file was provided, but failed to read.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
prog[num].vertex = content;
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
else if (strcmp((const char*)cur->name, "fragment") == 0)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2012-09-12 18:46:38 +00:00
|
|
|
if (glsl_modern && !prog[num].vertex)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Modern GLSL was chosen and vertex shader was not provided. This is an error.\n");
|
2012-11-18 16:39:39 +00:00
|
|
|
free(content);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
content = xml_replace_if_file(content, path, cur, "src");
|
|
|
|
if (!content)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Shader source file was provided, but failed to read.\n");
|
2012-09-12 18:46:38 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2012-11-18 16:39:39 +00:00
|
|
|
prog[num].fragment = content;
|
2011-03-29 21:45:10 +00:00
|
|
|
if (!get_xml_attrs(&prog[num], cur))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("XML shader attributes do not comply with specifications.\n");
|
2011-03-29 21:45:10 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
num++;
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
2011-05-18 18:22:27 +00:00
|
|
|
else if (strcmp((const char*)cur->name, "texture") == 0)
|
|
|
|
{
|
2012-11-18 16:39:39 +00:00
|
|
|
free(content);
|
2011-05-18 18:22:27 +00:00
|
|
|
if (!get_texture_image(path, cur))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Texture image failed to load.\n");
|
2011-05-18 18:22:27 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2011-05-25 13:58:12 +00:00
|
|
|
else if (strcmp((const char*)cur->name, "import") == 0)
|
|
|
|
{
|
2012-11-18 16:39:39 +00:00
|
|
|
free(content);
|
2011-06-07 14:28:58 +00:00
|
|
|
if (!get_import_value(cur))
|
2011-05-25 13:58:12 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Import value is invalid.\n");
|
2011-05-25 13:58:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2011-06-07 14:28:58 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
2011-06-07 13:33:29 +00:00
|
|
|
else if (strcmp((const char*)cur->name, "script") == 0)
|
|
|
|
{
|
2012-11-18 16:39:39 +00:00
|
|
|
free(content);
|
2011-06-07 14:28:58 +00:00
|
|
|
if (!get_script(path, cur))
|
2011-06-07 13:33:29 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Script is invalid.\n");
|
2011-06-07 13:33:29 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2011-06-07 14:28:58 +00:00
|
|
|
#endif
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
if (num == 0)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Couldn't find vertex shader nor fragment shader in XML file.\n");
|
2011-01-05 18:07:12 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlFreeParserCtxt(ctx);
|
2011-03-12 14:30:57 +00:00
|
|
|
return num;
|
2011-01-05 18:07:12 +00:00
|
|
|
|
|
|
|
error:
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load XML shader ...\n");
|
2011-01-05 18:07:12 +00:00
|
|
|
if (doc)
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlFreeParserCtxt(ctx);
|
2011-03-12 14:30:57 +00:00
|
|
|
return 0;
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
2012-09-13 18:15:37 +00:00
|
|
|
#endif // HAVE_XML
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2011-01-07 20:41:11 +00:00
|
|
|
static void print_shader_log(GLuint obj)
|
|
|
|
{
|
2011-06-29 01:26:21 +00:00
|
|
|
GLint info_len = 0;
|
|
|
|
GLint max_len;
|
2011-01-07 20:41:11 +00:00
|
|
|
|
|
|
|
pglGetShaderiv(obj, GL_INFO_LOG_LENGTH, &max_len);
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
if (max_len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *info_log = (char*)malloc(max_len);
|
|
|
|
if (!info_log)
|
|
|
|
return;
|
|
|
|
|
2011-01-07 20:41:11 +00:00
|
|
|
pglGetShaderInfoLog(obj, max_len, &info_len, info_log);
|
|
|
|
|
|
|
|
if (info_len > 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Shader log: %s\n", info_log);
|
2011-12-24 12:46:12 +00:00
|
|
|
|
|
|
|
free(info_log);
|
2011-01-07 20:41:11 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 21:13:55 +00:00
|
|
|
static void print_linker_log(GLuint obj)
|
|
|
|
{
|
2011-06-29 01:26:21 +00:00
|
|
|
GLint info_len = 0;
|
|
|
|
GLint max_len;
|
2011-01-11 21:13:55 +00:00
|
|
|
|
|
|
|
pglGetProgramiv(obj, GL_INFO_LOG_LENGTH, &max_len);
|
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
if (max_len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *info_log = (char*)malloc(max_len);
|
|
|
|
if (!info_log)
|
|
|
|
return;
|
|
|
|
|
2011-01-11 21:13:55 +00:00
|
|
|
pglGetProgramInfoLog(obj, max_len, &info_len, info_log);
|
|
|
|
|
|
|
|
if (info_len > 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Linker log: %s\n", info_log);
|
2011-12-24 12:46:12 +00:00
|
|
|
|
|
|
|
free(info_log);
|
2011-01-11 21:13:55 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 11:49:22 +00:00
|
|
|
static bool compile_shader(GLuint shader, const char *program)
|
|
|
|
{
|
|
|
|
pglShaderSource(shader, 1, &program, 0);
|
|
|
|
pglCompileShader(shader);
|
|
|
|
|
|
|
|
GLint status;
|
|
|
|
pglGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
|
|
|
print_shader_log(shader);
|
|
|
|
|
|
|
|
return status == GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-07 13:58:30 +00:00
|
|
|
static bool link_program(GLuint prog)
|
|
|
|
{
|
|
|
|
pglLinkProgram(prog);
|
|
|
|
|
|
|
|
GLint status;
|
|
|
|
pglGetProgramiv(prog, GL_LINK_STATUS, &status);
|
|
|
|
print_linker_log(prog);
|
|
|
|
|
|
|
|
if (status == GL_TRUE)
|
|
|
|
{
|
|
|
|
pglUseProgram(prog);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-29 22:10:16 +00:00
|
|
|
static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size_t num)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2011-03-12 14:30:57 +00:00
|
|
|
for (unsigned i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
gl_prog[i] = pglCreateProgram();
|
|
|
|
|
2011-06-07 13:58:30 +00:00
|
|
|
if (gl_prog[i] == 0)
|
2011-03-30 09:05:56 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to create GL program #%u.\n", i);
|
2011-03-30 09:05:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
if (progs[i].vertex)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Found GLSL vertex shader.\n");
|
2011-03-12 14:30:57 +00:00
|
|
|
GLuint shader = pglCreateShader(GL_VERTEX_SHADER);
|
2011-06-02 11:49:22 +00:00
|
|
|
if (!compile_shader(shader, progs[i].vertex))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to compile vertex shader #%u\n", i);
|
2011-06-02 11:49:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
|
|
|
pglAttachShader(gl_prog[i], shader);
|
|
|
|
free(progs[i].vertex);
|
|
|
|
}
|
|
|
|
|
2011-03-12 15:33:01 +00:00
|
|
|
if (progs[i].fragment)
|
2011-03-12 14:30:57 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Found GLSL fragment shader.\n");
|
2011-03-12 14:30:57 +00:00
|
|
|
GLuint shader = pglCreateShader(GL_FRAGMENT_SHADER);
|
2011-06-02 11:49:22 +00:00
|
|
|
if (!compile_shader(shader, progs[i].fragment))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to compile fragment shader #%u\n", i);
|
2011-06-02 11:49:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
|
|
|
pglAttachShader(gl_prog[i], shader);
|
|
|
|
free(progs[i].fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progs[i].vertex || progs[i].fragment)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Linking GLSL program.\n");
|
2011-06-07 13:58:30 +00:00
|
|
|
if (!link_program(gl_prog[i]))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to link program #%u\n", i);
|
2011-06-07 13:58:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
|
|
|
GLint location = pglGetUniformLocation(gl_prog[i], "rubyTexture");
|
|
|
|
pglUniform1i(location, 0);
|
|
|
|
pglUseProgram(0);
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 22:10:16 +00:00
|
|
|
|
|
|
|
return true;
|
2011-03-12 14:30:57 +00:00
|
|
|
}
|
2011-02-22 22:43:00 +00:00
|
|
|
|
2011-11-12 17:20:54 +00:00
|
|
|
static void gl_glsl_reset_attrib(void)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < gl_attrib_index; i++)
|
|
|
|
pglDisableVertexAttribArray(gl_attribs[i]);
|
|
|
|
gl_attrib_index = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
static void find_uniforms_frame(GLuint prog, struct shader_uniforms_frame *frame, const char *base)
|
|
|
|
{
|
|
|
|
char texture[64];
|
|
|
|
char texture_size[64];
|
|
|
|
char input_size[64];
|
|
|
|
char tex_coord[64];
|
|
|
|
|
|
|
|
snprintf(texture, sizeof(texture), "%s%s", base, "Texture");
|
|
|
|
snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize");
|
|
|
|
snprintf(input_size, sizeof(input_size), "%s%s", base, "InputSize");
|
|
|
|
snprintf(tex_coord, sizeof(tex_coord), "%s%s", base, "TexCoord");
|
|
|
|
|
|
|
|
frame->texture = pglGetUniformLocation(prog, texture);
|
|
|
|
frame->texture_size = pglGetUniformLocation(prog, texture_size);
|
|
|
|
frame->input_size = pglGetUniformLocation(prog, input_size);
|
|
|
|
frame->tex_coord = pglGetAttribLocation(prog, tex_coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void find_uniforms(GLuint prog, struct shader_uniforms *uni)
|
|
|
|
{
|
|
|
|
pglUseProgram(prog);
|
|
|
|
|
|
|
|
uni->mvp = pglGetUniformLocation(prog, "rubyMVPMatrix");
|
|
|
|
uni->tex_coord = pglGetAttribLocation(prog, "rubyTexCoord");
|
|
|
|
uni->vertex_coord = pglGetAttribLocation(prog, "rubyVertexCoord");
|
|
|
|
uni->color = pglGetAttribLocation(prog, "rubyColor");
|
|
|
|
uni->lut_tex_coord = pglGetAttribLocation(prog, "rubyLUTTexCoord");
|
|
|
|
|
|
|
|
uni->input_size = pglGetUniformLocation(prog, "rubyInputSize");
|
|
|
|
uni->output_size = pglGetUniformLocation(prog, "rubyOutputSize");
|
|
|
|
uni->texture_size = pglGetUniformLocation(prog, "rubyTextureSize");
|
|
|
|
|
|
|
|
uni->frame_count = pglGetUniformLocation(prog, "rubyFrameCount");
|
|
|
|
uni->frame_direction = pglGetUniformLocation(prog, "rubyFrameDirection");
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < gl_teximage_cnt; i++)
|
|
|
|
uni->lut_texture[i] = pglGetUniformLocation(prog, gl_teximage_uniforms[i]);
|
|
|
|
|
|
|
|
find_uniforms_frame(prog, &uni->orig, "rubyOrig");
|
|
|
|
|
|
|
|
char frame_base[64];
|
|
|
|
for (unsigned i = 0; i < MAX_PROGRAMS; i++)
|
|
|
|
{
|
|
|
|
snprintf(frame_base, sizeof(frame_base), "rubyPass%u", i + 1);
|
|
|
|
find_uniforms_frame(prog, &uni->pass[i], frame_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
find_uniforms_frame(prog, &uni->prev[0], "rubyPrev");
|
|
|
|
for (unsigned i = 1; i < PREV_TEXTURES; i++)
|
|
|
|
{
|
|
|
|
snprintf(frame_base, sizeof(frame_base), "rubyPrev%u", i);
|
|
|
|
find_uniforms_frame(prog, &uni->prev[i], frame_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
pglUseProgram(0);
|
|
|
|
}
|
|
|
|
|
2012-09-14 19:30:04 +00:00
|
|
|
// Platforms with broken get_proc_address.
|
|
|
|
// Assume functions are available without proc_address.
|
2012-10-02 21:36:18 +00:00
|
|
|
#undef LOAD_GL_SYM
|
2012-09-12 07:30:36 +00:00
|
|
|
#define LOAD_GL_SYM(SYM) if (!pgl##SYM) { \
|
2012-09-24 23:26:22 +00:00
|
|
|
gfx_ctx_proc_t sym = glsl_get_proc_address("gl" #SYM); \
|
2012-09-12 07:30:36 +00:00
|
|
|
memcpy(&(pgl##SYM), &sym, sizeof(sym)); \
|
|
|
|
}
|
2011-03-30 09:05:56 +00:00
|
|
|
|
2011-03-12 14:30:57 +00:00
|
|
|
bool gl_glsl_init(const char *path)
|
|
|
|
{
|
2012-10-12 19:24:23 +00:00
|
|
|
#if !defined(HAVE_OPENGLES2) && !defined(HAVE_OPENGL_MODERN) && !defined(__APPLE__)
|
2011-01-05 18:07:12 +00:00
|
|
|
// Load shader functions.
|
2011-03-30 09:05:56 +00:00
|
|
|
LOAD_GL_SYM(CreateProgram);
|
|
|
|
LOAD_GL_SYM(UseProgram);
|
|
|
|
LOAD_GL_SYM(CreateShader);
|
|
|
|
LOAD_GL_SYM(DeleteShader);
|
|
|
|
LOAD_GL_SYM(ShaderSource);
|
|
|
|
LOAD_GL_SYM(CompileShader);
|
|
|
|
LOAD_GL_SYM(AttachShader);
|
|
|
|
LOAD_GL_SYM(DetachShader);
|
|
|
|
LOAD_GL_SYM(LinkProgram);
|
|
|
|
LOAD_GL_SYM(GetUniformLocation);
|
|
|
|
LOAD_GL_SYM(Uniform1i);
|
2011-10-26 08:26:09 +00:00
|
|
|
LOAD_GL_SYM(Uniform1f);
|
2011-03-30 09:05:56 +00:00
|
|
|
LOAD_GL_SYM(Uniform2fv);
|
|
|
|
LOAD_GL_SYM(Uniform4fv);
|
2012-09-11 21:32:00 +00:00
|
|
|
LOAD_GL_SYM(UniformMatrix4fv);
|
2011-03-30 09:05:56 +00:00
|
|
|
LOAD_GL_SYM(GetShaderiv);
|
|
|
|
LOAD_GL_SYM(GetShaderInfoLog);
|
|
|
|
LOAD_GL_SYM(GetProgramiv);
|
|
|
|
LOAD_GL_SYM(GetProgramInfoLog);
|
|
|
|
LOAD_GL_SYM(DeleteProgram);
|
|
|
|
LOAD_GL_SYM(GetAttachedShaders);
|
2011-05-23 15:41:52 +00:00
|
|
|
LOAD_GL_SYM(GetAttribLocation);
|
|
|
|
LOAD_GL_SYM(EnableVertexAttribArray);
|
2011-11-12 17:20:54 +00:00
|
|
|
LOAD_GL_SYM(DisableVertexAttribArray);
|
2011-05-23 15:41:52 +00:00
|
|
|
LOAD_GL_SYM(VertexAttribPointer);
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Checking GLSL shader support ...\n");
|
2011-01-07 20:02:46 +00:00
|
|
|
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
|
|
|
|
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
|
|
|
|
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
|
2012-09-11 21:32:00 +00:00
|
|
|
&& pglUniform1i && pglUniform1f && pglUniform2fv && pglUniform4fv && pglUniformMatrix4fv
|
2011-03-29 16:59:06 +00:00
|
|
|
&& pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog
|
2011-05-23 15:41:52 +00:00
|
|
|
&& pglDeleteProgram && pglGetAttachedShaders
|
2011-11-12 17:20:54 +00:00
|
|
|
&& pglGetAttribLocation && pglEnableVertexAttribArray && pglDisableVertexAttribArray
|
2011-05-23 15:41:52 +00:00
|
|
|
&& pglVertexAttribPointer;
|
2011-01-05 18:07:12 +00:00
|
|
|
|
|
|
|
if (!shader_support)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("GLSL shaders aren't supported by your OpenGL driver.\n");
|
2011-01-05 18:07:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-15 13:17:34 +00:00
|
|
|
#endif
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-09-15 13:37:08 +00:00
|
|
|
unsigned num_progs = 0;
|
|
|
|
struct shader_program progs[MAX_PROGRAMS] = {{0}};
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_XML
|
2012-09-15 13:37:08 +00:00
|
|
|
if (path)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2012-09-15 13:37:08 +00:00
|
|
|
num_progs = get_xml_shaders(path, progs, MAX_PROGRAMS - 1);
|
|
|
|
|
|
|
|
if (num_progs == 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Couldn't find any valid shaders in XML file.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
}
|
2012-09-15 13:37:08 +00:00
|
|
|
else
|
2012-09-13 18:15:37 +00:00
|
|
|
#endif
|
2012-09-15 13:37:08 +00:00
|
|
|
{
|
|
|
|
RARCH_WARN("[GL]: Stock GLSL shaders will be used.\n");
|
|
|
|
num_progs = 1;
|
|
|
|
progs[0].vertex = strdup(stock_vertex_modern);
|
|
|
|
progs[0].fragment = strdup(stock_fragment_modern);
|
|
|
|
glsl_modern = true;
|
|
|
|
}
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-09-15 13:46:02 +00:00
|
|
|
#ifdef HAVE_OPENGLES2
|
|
|
|
if (!glsl_modern)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[GL]: GLES context is used, but shader is not modern. Cannot use it.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
struct shader_program stock_prog = {0};
|
|
|
|
stock_prog.vertex = strdup(glsl_modern ? stock_vertex_modern : stock_vertex_legacy);
|
|
|
|
stock_prog.fragment = strdup(glsl_modern ? stock_fragment_modern : stock_fragment_legacy);
|
|
|
|
|
|
|
|
if (!compile_programs(&gl_program[0], &stock_prog, 1))
|
|
|
|
{
|
|
|
|
RARCH_ERR("GLSL stock programs failed to compile.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-14 20:28:30 +00:00
|
|
|
for (unsigned i = 0; i < num_progs; i++)
|
2011-03-14 21:51:03 +00:00
|
|
|
{
|
2012-09-11 21:32:00 +00:00
|
|
|
gl_filter_type[i + 1] = progs[i].filter;
|
|
|
|
gl_scale[i + 1].type_x = progs[i].type_x;
|
|
|
|
gl_scale[i + 1].type_y = progs[i].type_y;
|
2011-03-14 21:51:03 +00:00
|
|
|
gl_scale[i + 1].scale_x = progs[i].scale_x;
|
|
|
|
gl_scale[i + 1].scale_y = progs[i].scale_y;
|
2012-09-11 21:32:00 +00:00
|
|
|
gl_scale[i + 1].abs_x = progs[i].abs_x;
|
|
|
|
gl_scale[i + 1].abs_y = progs[i].abs_y;
|
|
|
|
gl_scale[i + 1].valid = progs[i].valid_scale;
|
2011-03-14 21:51:03 +00:00
|
|
|
}
|
2011-03-14 20:28:30 +00:00
|
|
|
|
2011-03-29 22:10:16 +00:00
|
|
|
if (!compile_programs(&gl_program[1], progs, num_progs))
|
|
|
|
return false;
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_XML
|
2012-04-21 21:13:50 +00:00
|
|
|
// RetroArch custom two-pass with two different files.
|
2011-09-26 20:45:28 +00:00
|
|
|
if (num_progs == 1 && *g_settings.video.second_pass_shader && g_settings.video.render_to_texture)
|
2011-03-12 14:30:57 +00:00
|
|
|
{
|
|
|
|
unsigned secondary_progs = get_xml_shaders(g_settings.video.second_pass_shader, progs, 1);
|
|
|
|
if (secondary_progs == 1)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2011-03-12 14:30:57 +00:00
|
|
|
compile_programs(&gl_program[2], progs, 1);
|
|
|
|
num_progs++;
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
else
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-09-13 18:15:37 +00:00
|
|
|
RARCH_ERR("Did not find exactly one valid shader in secondary shader file.\n");
|
2011-03-12 14:30:57 +00:00
|
|
|
return false;
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
2012-09-13 18:15:37 +00:00
|
|
|
#endif
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
for (unsigned i = 0; i <= num_progs; i++)
|
|
|
|
find_uniforms(gl_program[i], &gl_uniforms[i]);
|
|
|
|
|
2012-10-16 13:38:25 +00:00
|
|
|
#ifdef GLSL_DEBUG
|
|
|
|
if (!gl_check_error())
|
2012-10-21 00:58:51 +00:00
|
|
|
RARCH_WARN("Detected GL error in GLSL.\n");
|
2012-10-16 13:38:25 +00:00
|
|
|
#endif
|
2011-05-25 13:58:12 +00:00
|
|
|
|
2012-09-13 18:15:37 +00:00
|
|
|
#ifdef HAVE_XML
|
2011-05-25 13:58:12 +00:00
|
|
|
if (gl_tracker_info_cnt > 0)
|
|
|
|
{
|
2012-04-07 10:17:40 +00:00
|
|
|
struct state_tracker_info info = {0};
|
2012-09-11 21:32:00 +00:00
|
|
|
info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM);
|
|
|
|
info.info = gl_tracker_info;
|
2011-12-24 12:46:12 +00:00
|
|
|
info.info_elem = gl_tracker_info_cnt;
|
2011-06-07 13:33:29 +00:00
|
|
|
|
2011-06-06 16:50:36 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
2011-06-07 13:33:29 +00:00
|
|
|
if (*gl_tracker_script)
|
|
|
|
info.script = gl_tracker_script;
|
|
|
|
else if (gl_script_program)
|
2012-09-13 18:15:37 +00:00
|
|
|
info.script = gl_script_program;
|
2011-06-07 13:33:29 +00:00
|
|
|
else
|
|
|
|
info.script = NULL;
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
info.script_class = *gl_tracker_script_class ? gl_tracker_script_class : NULL;
|
2011-06-07 13:33:29 +00:00
|
|
|
info.script_is_file = *gl_tracker_script;
|
2011-06-06 16:50:36 +00:00
|
|
|
#endif
|
2011-06-07 13:33:29 +00:00
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
gl_state_tracker = state_tracker_init(&info);
|
|
|
|
if (!gl_state_tracker)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Failed to init state tracker.\n");
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
2012-09-13 18:15:37 +00:00
|
|
|
#endif
|
2011-01-11 21:13:55 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
glsl_enable = true;
|
|
|
|
gl_num_programs = num_progs;
|
|
|
|
gl_program[gl_num_programs + 1] = gl_program[0];
|
|
|
|
gl_uniforms[gl_num_programs + 1] = gl_uniforms[0];
|
2011-11-12 17:20:54 +00:00
|
|
|
|
|
|
|
gl_glsl_reset_attrib();
|
|
|
|
|
2011-01-05 18:07:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gl_glsl_deinit(void)
|
2011-03-29 16:59:06 +00:00
|
|
|
{
|
|
|
|
if (glsl_enable)
|
|
|
|
{
|
|
|
|
pglUseProgram(0);
|
2011-12-24 12:46:12 +00:00
|
|
|
for (unsigned i = 0; i <= gl_num_programs; i++)
|
2011-03-29 16:59:06 +00:00
|
|
|
{
|
2012-09-13 18:15:37 +00:00
|
|
|
if (gl_program[i] == 0 || (i && gl_program[i] == gl_program[0]))
|
2011-11-12 14:26:24 +00:00
|
|
|
continue;
|
2011-03-29 16:59:06 +00:00
|
|
|
|
|
|
|
GLsizei count;
|
|
|
|
GLuint shaders[2];
|
|
|
|
|
|
|
|
pglGetAttachedShaders(gl_program[i], 2, &count, shaders);
|
|
|
|
for (GLsizei j = 0; j < count; j++)
|
|
|
|
{
|
|
|
|
pglDetachShader(gl_program[i], shaders[j]);
|
|
|
|
pglDeleteShader(shaders[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pglDeleteProgram(gl_program[i]);
|
|
|
|
}
|
2011-05-18 18:22:27 +00:00
|
|
|
|
|
|
|
glDeleteTextures(gl_teximage_cnt, gl_teximage);
|
|
|
|
gl_teximage_cnt = 0;
|
|
|
|
memset(gl_teximage_uniforms, 0, sizeof(gl_teximage_uniforms));
|
2011-03-29 16:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(gl_program, 0, sizeof(gl_program));
|
2012-09-11 21:32:00 +00:00
|
|
|
glsl_enable = false;
|
2011-03-29 16:59:06 +00:00
|
|
|
active_index = 0;
|
2011-05-25 13:58:12 +00:00
|
|
|
|
|
|
|
gl_tracker_info_cnt = 0;
|
|
|
|
memset(gl_tracker_info, 0, sizeof(gl_tracker_info));
|
2011-06-06 16:50:36 +00:00
|
|
|
memset(gl_tracker_script, 0, sizeof(gl_tracker_script));
|
|
|
|
memset(gl_tracker_script_class, 0, sizeof(gl_tracker_script_class));
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2011-06-07 13:33:29 +00:00
|
|
|
if (gl_script_program)
|
|
|
|
{
|
2012-09-13 18:15:37 +00:00
|
|
|
free(gl_script_program);
|
2011-06-07 13:33:29 +00:00
|
|
|
gl_script_program = NULL;
|
|
|
|
}
|
2012-09-11 21:32:00 +00:00
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
if (gl_state_tracker)
|
2011-05-25 13:58:12 +00:00
|
|
|
{
|
2012-04-07 10:17:40 +00:00
|
|
|
state_tracker_free(gl_state_tracker);
|
|
|
|
gl_state_tracker = NULL;
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
2011-11-12 17:20:54 +00:00
|
|
|
|
|
|
|
gl_glsl_reset_attrib();
|
2011-03-29 16:59:06 +00:00
|
|
|
}
|
2011-01-05 18:07:12 +00:00
|
|
|
|
|
|
|
void gl_glsl_set_params(unsigned width, unsigned height,
|
|
|
|
unsigned tex_width, unsigned tex_height,
|
2011-05-11 11:24:59 +00:00
|
|
|
unsigned out_width, unsigned out_height,
|
2011-05-23 15:41:52 +00:00
|
|
|
unsigned frame_count,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *info,
|
2011-07-03 13:39:35 +00:00
|
|
|
const struct gl_tex_info *prev_info,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
|
2011-01-05 18:07:12 +00:00
|
|
|
{
|
2011-07-03 13:39:35 +00:00
|
|
|
// We enforce a certain layout for our various texture types in the texunits.
|
2012-09-15 21:15:19 +00:00
|
|
|
// - Regular frame (rubyTexture) (always bound).
|
2011-11-12 13:18:10 +00:00
|
|
|
// - LUT textures (always bound).
|
|
|
|
// - Original texture (always bound if meaningful).
|
|
|
|
// - FBO textures (always bound if available).
|
|
|
|
// - Previous textures.
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
if (!glsl_enable || (gl_program[active_index] == 0))
|
|
|
|
return;
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
const struct shader_uniforms *uni = &gl_uniforms[active_index];
|
|
|
|
|
|
|
|
float input_size[2] = {(float)width, (float)height};
|
|
|
|
float output_size[2] = {(float)out_width, (float)out_height};
|
|
|
|
float texture_size[2] = {(float)tex_width, (float)tex_height};
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->input_size >= 0)
|
|
|
|
pglUniform2fv(uni->input_size, 1, input_size);
|
2011-01-05 18:07:12 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->output_size >= 0)
|
|
|
|
pglUniform2fv(uni->output_size, 1, output_size);
|
2011-05-11 11:24:59 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->texture_size >= 0)
|
|
|
|
pglUniform2fv(uni->texture_size, 1, texture_size);
|
2011-05-18 18:22:27 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->frame_count >= 0)
|
|
|
|
pglUniform1i(uni->frame_count, frame_count);
|
2011-11-09 22:45:34 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->frame_direction >= 0)
|
|
|
|
pglUniform1i(uni->frame_direction, g_extern.frame_is_reverse ? -1 : 1);
|
2011-11-12 13:18:10 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < gl_teximage_cnt; i++)
|
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->lut_texture[i] >= 0)
|
|
|
|
pglUniform1i(uni->lut_texture[i], i + 1);
|
2011-11-12 13:18:10 +00:00
|
|
|
}
|
2011-05-23 15:41:52 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
unsigned texunit = gl_teximage_cnt + 1;
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
// Set original texture unless we're in first pass (pointless).
|
|
|
|
if (active_index > 1)
|
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->orig.texture >= 0)
|
|
|
|
{
|
|
|
|
// Bind original texture.
|
|
|
|
pglActiveTexture(GL_TEXTURE0 + texunit);
|
|
|
|
pglUniform1i(uni->orig.texture, texunit);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, info->tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
texunit++;
|
2011-11-12 13:18:10 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->orig.texture_size >= 0)
|
|
|
|
pglUniform2fv(uni->orig.texture_size, 1, info->tex_size);
|
2011-11-12 13:18:10 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->orig.input_size >= 0)
|
|
|
|
pglUniform2fv(uni->orig.input_size, 1, info->input_size);
|
2011-07-03 13:39:35 +00:00
|
|
|
|
|
|
|
// Pass texture coordinates.
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->orig.tex_coord >= 0)
|
2011-07-03 13:39:35 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->orig.tex_coord;
|
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, info->coord);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2011-07-03 13:39:35 +00:00
|
|
|
}
|
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
// Bind new texture in the chain.
|
|
|
|
if (fbo_info_cnt > 0)
|
2011-05-23 15:41:52 +00:00
|
|
|
{
|
2011-11-12 13:18:10 +00:00
|
|
|
pglActiveTexture(GL_TEXTURE0 + texunit + fbo_info_cnt - 1);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo_info[fbo_info_cnt - 1].tex);
|
|
|
|
}
|
2011-05-23 15:41:52 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
// Bind FBO textures.
|
|
|
|
for (unsigned i = 0; i < fbo_info_cnt; i++)
|
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->pass[i].texture)
|
|
|
|
pglUniform1i(uni->pass[i].texture, texunit);
|
2011-05-23 15:41:52 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
texunit++;
|
2011-05-23 15:41:52 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->pass[i].texture_size >= 0)
|
|
|
|
pglUniform2fv(uni->pass[i].texture_size, 1, fbo_info[i].tex_size);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->pass[i].input_size >= 0)
|
|
|
|
pglUniform2fv(uni->pass[i].input_size, 1, fbo_info[i].input_size);
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->pass[i].tex_coord >= 0)
|
2011-05-23 17:57:52 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->pass[i].tex_coord;
|
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, fbo_info[i].coord);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2011-05-23 17:57:52 +00:00
|
|
|
}
|
2011-05-23 15:41:52 +00:00
|
|
|
}
|
2011-11-12 13:18:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// First pass, so unbind everything to avoid collitions.
|
|
|
|
// Unbind ORIG.
|
|
|
|
pglActiveTexture(GL_TEXTURE0 + texunit);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
GLuint base_tex = texunit + 1;
|
|
|
|
// Unbind any lurking FBO passes.
|
|
|
|
// Rendering to a texture that is bound to a texture unit
|
|
|
|
// sounds very shaky ... ;)
|
|
|
|
for (unsigned i = 0; i < gl_num_programs; i++)
|
2011-05-23 15:41:52 +00:00
|
|
|
{
|
2011-11-12 13:18:10 +00:00
|
|
|
pglActiveTexture(GL_TEXTURE0 + base_tex + i);
|
2011-05-23 15:41:52 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2011-11-12 13:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2011-11-12 14:51:37 +00:00
|
|
|
// Set previous textures. Only bind if they're actually used.
|
2011-11-12 13:18:10 +00:00
|
|
|
for (unsigned i = 0; i < PREV_TEXTURES; i++)
|
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->prev[i].texture >= 0)
|
2011-11-12 13:18:10 +00:00
|
|
|
{
|
|
|
|
pglActiveTexture(GL_TEXTURE0 + texunit);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, prev_info[i].tex);
|
2012-10-21 00:58:51 +00:00
|
|
|
pglUniform1i(uni->prev[i].texture, texunit++);
|
2011-05-23 15:41:52 +00:00
|
|
|
}
|
2011-05-23 17:57:52 +00:00
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
texunit++;
|
|
|
|
|
|
|
|
if (uni->prev[i].texture_size >= 0)
|
|
|
|
pglUniform2fv(uni->prev[i].texture_size, 1, prev_info[i].tex_size);
|
|
|
|
|
|
|
|
if (uni->prev[i].input_size >= 0)
|
|
|
|
pglUniform2fv(uni->prev[i].input_size, 1, prev_info[i].input_size);
|
2011-05-25 13:58:12 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
// Pass texture coordinates.
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->prev[i].tex_coord >= 0)
|
2011-05-25 13:58:12 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->prev[i].tex_coord;
|
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, prev_info[i].coord);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2011-11-12 13:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:59:29 +00:00
|
|
|
|
2011-11-12 13:18:10 +00:00
|
|
|
pglActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
if (gl_state_tracker)
|
2011-11-12 13:18:10 +00:00
|
|
|
{
|
2012-04-07 10:17:40 +00:00
|
|
|
static struct state_tracker_uniform info[MAX_VARIABLES];
|
2011-11-12 13:18:10 +00:00
|
|
|
static unsigned cnt = 0;
|
|
|
|
|
|
|
|
if (active_index == 1)
|
2012-04-07 10:17:40 +00:00
|
|
|
cnt = state_get_uniform(gl_state_tracker, info, MAX_VARIABLES, frame_count);
|
2011-11-12 13:18:10 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < cnt; i++)
|
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int location = pglGetUniformLocation(gl_program[active_index], info[i].id);
|
2011-11-12 13:18:10 +00:00
|
|
|
pglUniform1f(location, info[i].value);
|
2011-05-25 13:58:12 +00:00
|
|
|
}
|
2011-01-05 18:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
bool gl_glsl_set_mvp(const math_matrix *mat)
|
|
|
|
{
|
|
|
|
if (!glsl_enable || !glsl_modern)
|
|
|
|
return false;
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = gl_uniforms[active_index].mvp;
|
2012-09-11 21:32:00 +00:00
|
|
|
if (loc >= 0)
|
|
|
|
pglUniformMatrix4fv(loc, 1, GL_FALSE, mat->data);
|
2012-10-21 00:58:51 +00:00
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gl_glsl_set_coords(const struct gl_coords *coords)
|
2012-08-09 20:33:32 +00:00
|
|
|
{
|
2012-09-11 21:32:00 +00:00
|
|
|
if (!glsl_enable || !glsl_modern)
|
|
|
|
return false;
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
const struct shader_uniforms *uni = &gl_uniforms[active_index];
|
|
|
|
if (uni->tex_coord >= 0)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->tex_coord;
|
2012-09-14 19:35:32 +00:00
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, coords->tex_coord);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2012-09-11 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->vertex_coord >= 0)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->vertex_coord;
|
2012-09-14 19:35:32 +00:00
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, coords->vertex);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2012-09-11 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->color >= 0)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->color;
|
2012-09-14 19:35:32 +00:00
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, 0, coords->color);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2012-09-11 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 00:58:51 +00:00
|
|
|
if (uni->lut_tex_coord >= 0)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2012-10-21 00:58:51 +00:00
|
|
|
int loc = uni->lut_tex_coord;
|
2012-09-14 19:35:32 +00:00
|
|
|
pglEnableVertexAttribArray(loc);
|
|
|
|
pglVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, coords->lut_tex_coord);
|
|
|
|
gl_attribs[gl_attrib_index++] = loc;
|
2012-09-11 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-08-09 20:33:32 +00:00
|
|
|
}
|
2011-01-22 23:48:47 +00:00
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
void gl_glsl_use(unsigned index)
|
2011-01-22 23:48:47 +00:00
|
|
|
{
|
|
|
|
if (glsl_enable)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2011-11-12 17:20:54 +00:00
|
|
|
gl_glsl_reset_attrib();
|
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
active_index = index;
|
|
|
|
pglUseProgram(gl_program[index]);
|
|
|
|
}
|
2011-01-22 23:48:47 +00:00
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
|
|
|
unsigned gl_glsl_num(void)
|
|
|
|
{
|
|
|
|
return gl_num_programs;
|
|
|
|
}
|
2011-03-14 20:28:30 +00:00
|
|
|
|
|
|
|
bool gl_glsl_filter_type(unsigned index, bool *smooth)
|
|
|
|
{
|
|
|
|
if (!glsl_enable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (gl_filter_type[index])
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_GL_NOFORCE:
|
2011-03-14 20:28:30 +00:00
|
|
|
return false;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_GL_NEAREST:
|
2011-03-14 20:28:30 +00:00
|
|
|
*smooth = false;
|
|
|
|
return true;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_GL_LINEAR:
|
2011-03-14 20:28:30 +00:00
|
|
|
*smooth = true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-03-14 21:09:35 +00:00
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
void gl_glsl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
|
2011-03-14 21:09:35 +00:00
|
|
|
{
|
2011-03-14 21:51:03 +00:00
|
|
|
if (glsl_enable)
|
|
|
|
*scale = gl_scale[index];
|
|
|
|
else
|
|
|
|
scale->valid = false;
|
2011-03-14 21:09:35 +00:00
|
|
|
}
|
2012-09-24 23:26:22 +00:00
|
|
|
|
|
|
|
void gl_glsl_set_get_proc_address(gfx_ctx_proc_t (*proc)(const char*))
|
|
|
|
{
|
|
|
|
glsl_get_proc_address = proc;
|
|
|
|
}
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
const gl_shader_backend_t gl_glsl_backend = {
|
|
|
|
gl_glsl_init,
|
|
|
|
gl_glsl_deinit,
|
|
|
|
gl_glsl_set_params,
|
|
|
|
gl_glsl_use,
|
|
|
|
gl_glsl_num,
|
|
|
|
gl_glsl_filter_type,
|
|
|
|
gl_glsl_shader_scale,
|
|
|
|
gl_glsl_set_coords,
|
|
|
|
gl_glsl_set_mvp,
|
|
|
|
};
|
|
|
|
|