mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-29 11:10:27 +00:00
Cleanups. PREV{1-6} for GLSL as well.
This commit is contained in:
parent
104fb4fb16
commit
ad67511483
5
gfx/gl.c
5
gfx/gl.c
@ -123,7 +123,12 @@ static inline bool load_gl_proc(void) { return true; }
|
||||
#endif
|
||||
|
||||
#define MAX_SHADERS 16
|
||||
|
||||
#if defined(HAVE_XML) || defined(HAVE_CG)
|
||||
#define TEXTURES 8
|
||||
#else
|
||||
#define TEXTURES 1
|
||||
#endif
|
||||
#define TEXTURES_MASK (TEXTURES - 1)
|
||||
|
||||
typedef struct gl
|
||||
|
@ -95,7 +95,7 @@ struct cg_fbo_params
|
||||
#define MAX_SHADERS 16
|
||||
#define MAX_TEXTURES 8
|
||||
#define MAX_VARIABLES 64
|
||||
#define PREV_TEXTURES 8
|
||||
#define PREV_TEXTURES 7
|
||||
|
||||
struct cg_program
|
||||
{
|
||||
@ -192,7 +192,7 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
}
|
||||
|
||||
// Set prev textures.
|
||||
for (unsigned i = 0; i < PREV_TEXTURES - 1; i++)
|
||||
for (unsigned i = 0; i < PREV_TEXTURES; i++)
|
||||
{
|
||||
param = prg[active_index].prev[i].tex;
|
||||
if (param)
|
||||
@ -990,35 +990,36 @@ bool gl_cg_init(const char *path)
|
||||
prg[i].orig.tex_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.texture_size");
|
||||
prg[i].orig.coord = cgGetNamedParameter(prg[i].vprg, "ORIG.tex_coord");
|
||||
|
||||
for (unsigned j = 0; j < PREV_TEXTURES - 1; j++)
|
||||
for (unsigned j = 0; j < PREV_TEXTURES; j++)
|
||||
{
|
||||
if (j == 0)
|
||||
{
|
||||
prg[i].prev[0].tex = cgGetNamedParameter(prg[i].fprg, "PREV.texture");
|
||||
prg[i].prev[0].vid_size_v = cgGetNamedParameter(prg[i].vprg, "PREV.video_size");
|
||||
prg[i].prev[0].vid_size_f = cgGetNamedParameter(prg[i].fprg, "PREV.video_size");
|
||||
prg[i].prev[0].tex_size_v = cgGetNamedParameter(prg[i].vprg, "PREV.texture_size");
|
||||
prg[i].prev[0].tex_size_f = cgGetNamedParameter(prg[i].fprg, "PREV.texture_size");
|
||||
prg[i].prev[0].coord = cgGetNamedParameter(prg[i].vprg, "PREV.tex_coord");
|
||||
}
|
||||
else
|
||||
{
|
||||
char attr_buf[64];
|
||||
char attr_buf_tex[64];
|
||||
char attr_buf_vid_size[64];
|
||||
char attr_buf_tex_size[64];
|
||||
char attr_buf_coord[64];
|
||||
static const char *prev_names[PREV_TEXTURES] = {
|
||||
"PREV",
|
||||
"PREV1",
|
||||
"PREV2",
|
||||
"PREV3",
|
||||
"PREV4",
|
||||
"PREV5",
|
||||
"PREV6",
|
||||
};
|
||||
|
||||
snprintf(attr_buf, sizeof(attr_buf), "PREV%u.texture", j);
|
||||
prg[i].prev[j].tex = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
||||
snprintf(attr_buf_tex, sizeof(attr_buf_tex), "%s.texture", prev_names[j]);
|
||||
snprintf(attr_buf_vid_size, sizeof(attr_buf_vid_size), "%s.video_size", prev_names[j]);
|
||||
snprintf(attr_buf_tex_size, sizeof(attr_buf_tex_size), "%s.texture_size", prev_names[j]);
|
||||
snprintf(attr_buf_coord, sizeof(attr_buf_coord), "%s.tex_coord", prev_names[j]);
|
||||
|
||||
snprintf(attr_buf, sizeof(attr_buf), "PREV%u.video_size", j);
|
||||
prg[i].prev[j].vid_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
||||
prg[i].prev[j].vid_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
||||
prg[i].prev[j].tex = cgGetNamedParameter(prg[i].fprg, attr_buf_tex);
|
||||
|
||||
snprintf(attr_buf, sizeof(attr_buf), "PREV%u.texture_size", j);
|
||||
prg[i].prev[j].tex_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
||||
prg[i].prev[j].tex_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
||||
prg[i].prev[j].vid_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf_vid_size);
|
||||
prg[i].prev[j].vid_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf_vid_size);
|
||||
|
||||
snprintf(attr_buf, sizeof(attr_buf), "PREV%u.tex_coord", j);
|
||||
prg[i].prev[j].coord = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
||||
}
|
||||
prg[i].prev[j].tex_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf_tex_size);
|
||||
prg[i].prev[j].tex_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf_tex_size);
|
||||
|
||||
prg[i].prev[j].coord = cgGetNamedParameter(prg[i].vprg, attr_buf_coord);
|
||||
}
|
||||
|
||||
for (unsigned j = 0; j < i - 1; j++)
|
||||
|
@ -96,6 +96,7 @@ static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer = NULL;
|
||||
#define MAX_PROGRAMS 16
|
||||
#define MAX_TEXTURES 8
|
||||
#define MAX_VARIABLES 256
|
||||
#define PREV_TEXTURES 7
|
||||
|
||||
enum filter_type
|
||||
{
|
||||
@ -1010,14 +1011,15 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
|
||||
{
|
||||
// We enforce a certain layout for our various texture types in the texunits.
|
||||
// Unit 0: Regular SNES frame (rubyTexture).
|
||||
// Unit 1-A: LUT textures.
|
||||
// Unit A+1: Previous texture.
|
||||
// Unit A+2: Original texture.
|
||||
// Unit A+3-B: FBO textures.
|
||||
// - Regular SNES frame (rubyTexture) (always bound).
|
||||
// - LUT textures (always bound).
|
||||
// - Original texture (always bound if meaningful).
|
||||
// - FBO textures (always bound if available).
|
||||
// - Previous textures.
|
||||
|
||||
if (!glsl_enable || (gl_program[active_index] == 0))
|
||||
return;
|
||||
|
||||
if (glsl_enable && gl_program[active_index] > 0)
|
||||
{
|
||||
GLint location;
|
||||
|
||||
float inputSize[2] = {width, height};
|
||||
@ -1044,34 +1046,17 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
pglUniform1i(location, i + 1);
|
||||
}
|
||||
|
||||
// Set previous texture.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, prev_info->tex);
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevTexture");
|
||||
pglUniform1i(location, gl_teximage_cnt + 1);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevTextureSize");
|
||||
pglUniform2fv(location, 1, prev_info->tex_size);
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevInputSize");
|
||||
pglUniform2fv(location, 1, prev_info->input_size);
|
||||
|
||||
// Pass texture coordinates.
|
||||
location = pglGetAttribLocation(gl_program[active_index], "rubyPrevTexCoord");
|
||||
if (location >= 0)
|
||||
{
|
||||
pglEnableVertexAttribArray(location);
|
||||
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, prev_info->coord);
|
||||
}
|
||||
unsigned texunit = gl_teximage_cnt + 1;
|
||||
|
||||
// Set original texture unless we're in first pass (pointless).
|
||||
if (active_index > 1)
|
||||
{
|
||||
// Bind original texture.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, info->tex);
|
||||
pglActiveTexture(GL_TEXTURE0 + texunit);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTexture");
|
||||
pglUniform1i(location, gl_teximage_cnt + 2);
|
||||
pglUniform1i(location, texunit++);
|
||||
glBindTexture(GL_TEXTURE_2D, info->tex);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTextureSize");
|
||||
pglUniform2fv(location, 1, info->tex_size);
|
||||
@ -1086,12 +1071,10 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, info->coord);
|
||||
}
|
||||
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 3;
|
||||
|
||||
// Bind new texture in the chain.
|
||||
if (fbo_info_cnt > 0)
|
||||
{
|
||||
pglActiveTexture(base_tex + fbo_info_cnt - 1);
|
||||
pglActiveTexture(GL_TEXTURE0 + texunit + fbo_info_cnt - 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_info[fbo_info_cnt - 1].tex);
|
||||
}
|
||||
|
||||
@ -1102,7 +1085,8 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
|
||||
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTexture", i + 1);
|
||||
location = pglGetUniformLocation(gl_program[active_index], attrib_buf);
|
||||
pglUniform1i(location, base_tex + i - GL_TEXTURE0);
|
||||
pglUniform1i(location, texunit);
|
||||
texunit++;
|
||||
|
||||
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTextureSize", i + 1);
|
||||
location = pglGetUniformLocation(gl_program[active_index], attrib_buf);
|
||||
@ -1125,10 +1109,10 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
{
|
||||
// First pass, so unbind everything to avoid collitions.
|
||||
// Unbind ORIG.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 2);
|
||||
pglActiveTexture(GL_TEXTURE0 + texunit);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 3;
|
||||
GLuint base_tex = texunit + 1;
|
||||
// Unbind any lurking FBO passes.
|
||||
// Rendering to a texture that is bound to a texture unit
|
||||
// sounds very shaky ... ;)
|
||||
@ -1139,6 +1123,50 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < PREV_TEXTURES; i++)
|
||||
{
|
||||
char attr_buf_tex[64];
|
||||
char attr_buf_tex_size[64];
|
||||
char attr_buf_input_size[64];
|
||||
char attr_buf_coord[64];
|
||||
static const char *prev_names[PREV_TEXTURES] = {
|
||||
"Prev",
|
||||
"Prev1",
|
||||
"Prev2",
|
||||
"Prev3",
|
||||
"Prev4",
|
||||
"Prev5",
|
||||
"Prev6",
|
||||
};
|
||||
|
||||
snprintf(attr_buf_tex, sizeof(attr_buf_tex), "ruby%sTexture", prev_names[i]);
|
||||
snprintf(attr_buf_tex_size, sizeof(attr_buf_tex), "ruby%sTextureSize", prev_names[i]);
|
||||
snprintf(attr_buf_input_size, sizeof(attr_buf_tex), "ruby%sInputSize", prev_names[i]);
|
||||
snprintf(attr_buf_coord, sizeof(attr_buf_tex), "ruby%sTexCoord", prev_names[i]);
|
||||
|
||||
// Set previous textures.
|
||||
location = pglGetUniformLocation(gl_program[active_index], attr_buf_tex);
|
||||
if (location >= 0)
|
||||
{
|
||||
pglActiveTexture(GL_TEXTURE0 + texunit);
|
||||
glBindTexture(GL_TEXTURE_2D, prev_info[i].tex);
|
||||
pglUniform1i(location, texunit++);
|
||||
}
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], attr_buf_tex_size);
|
||||
pglUniform2fv(location, 1, prev_info[i].tex_size);
|
||||
location = pglGetUniformLocation(gl_program[active_index], attr_buf_input_size);
|
||||
pglUniform2fv(location, 1, prev_info[i].input_size);
|
||||
|
||||
// Pass texture coordinates.
|
||||
location = pglGetAttribLocation(gl_program[active_index], attr_buf_coord);
|
||||
if (location >= 0)
|
||||
{
|
||||
pglEnableVertexAttribArray(location);
|
||||
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, prev_info[i].coord);
|
||||
}
|
||||
}
|
||||
|
||||
pglActiveTexture(GL_TEXTURE0);
|
||||
|
||||
if (gl_snes_tracker)
|
||||
@ -1156,7 +1184,6 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gl_glsl_set_proj_matrix(void)
|
||||
{}
|
||||
|
Loading…
Reference in New Issue
Block a user