Add GL_SHADER_STOCK_BLEND.

Replace stock shader with a special shader which does not apply color.
This is a necessary on Android.
This commit is contained in:
Themaister 2013-04-20 15:46:50 +02:00
parent 4f7d3b5ea0
commit 6dd7ea935e
7 changed files with 58 additions and 23 deletions

View File

@ -243,7 +243,7 @@ static void setup_font(void *data, const char *msg, GLfloat scale, GLfloat pos_x
return;
if (gl->shader)
gl->shader->use(0);
gl->shader->use(GL_SHADER_STOCK_BLEND);
gl_set_viewport(gl, gl->win_width, gl->win_height, false, false);

View File

@ -1261,7 +1261,7 @@ static inline void gl_draw_texture(void *data)
glBindTexture(GL_TEXTURE_2D, gl->rgui_texture);
if (gl->shader)
gl->shader->use(0);
gl->shader->use(GL_SHADER_STOCK_BLEND);
gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);
glEnable(GL_BLEND);
@ -2205,7 +2205,7 @@ static void gl_render_overlay(void *data)
};
if (gl->shader)
gl->shader->use(0);
gl->shader->use(GL_SHADER_STOCK_BLEND);
glEnable(GL_BLEND);
gl->coords.vertex = gl->overlay_vertex_coord;

View File

@ -122,12 +122,12 @@ struct cg_program
CGparameter frame_dir_v;
CGparameter mvp;
struct cg_fbo_params fbo[RARCH_CG_MAX_SHADERS];
struct cg_fbo_params fbo[GFX_MAX_SHADERS];
struct cg_fbo_params orig;
struct cg_fbo_params prev[PREV_TEXTURES];
};
static struct cg_program prg[RARCH_CG_MAX_SHADERS];
static struct cg_program prg[GFX_MAX_SHADERS];
static const char **cg_arguments;
static bool cg_active;
static CGprofile cgVProf, cgFProf;
@ -138,7 +138,7 @@ static struct gfx_shader *cg_shader;
static state_tracker_t *state_tracker;
static GLuint lut_textures[MAX_TEXTURES];
static CGparameter cg_attribs[PREV_TEXTURES + 1 + 4 + RARCH_CG_MAX_SHADERS];
static CGparameter cg_attribs[PREV_TEXTURES + 1 + 4 + GFX_MAX_SHADERS];
static unsigned cg_attrib_index;
static void gl_cg_reset_attrib(void)
@ -195,7 +195,7 @@ static void gl_cg_set_params(unsigned width, unsigned height,
const struct gl_tex_info *fbo_info,
unsigned fbo_info_cnt)
{
if (!cg_active || (active_index == 0))
if (!cg_active || (active_index == 0) || (active_index == GL_SHADER_STOCK_BLEND))
return;
// Set frame.
@ -332,7 +332,7 @@ static void gl_cg_deinit_progs(void)
cgGLUnbindProgram(cgVProf);
// Programs may alias [0].
for (unsigned i = 1; i < RARCH_CG_MAX_SHADERS; i++)
for (unsigned i = 1; i < GFX_MAX_SHADERS; i++)
{
if (prg[i].fprg && prg[i].fprg != prg[0].fprg)
cgDestroyProgram(prg[i].fprg);
@ -629,10 +629,10 @@ static bool load_preset(const char *path)
config_file_free(conf);
gfx_shader_resolve_relative(cg_shader, path);
if (cg_shader->passes > RARCH_CG_MAX_SHADERS - 3)
if (cg_shader->passes > GFX_MAX_SHADERS - 3)
{
RARCH_WARN("Too many shaders ... Capping shader amount to %d.\n", RARCH_CG_MAX_SHADERS - 3);
cg_shader->passes = RARCH_CG_MAX_SHADERS - 3;
RARCH_WARN("Too many shaders ... Capping shader amount to %d.\n", GFX_MAX_SHADERS - 3);
cg_shader->passes = GFX_MAX_SHADERS - 3;
}
for (unsigned i = 0; i < cg_shader->passes; i++)
{
@ -818,6 +818,9 @@ static bool gl_cg_init(const char *path)
// pass-through.
prg[cg_shader->passes + 1] = prg[0];
// No need to apply Android hack in Cg.
prg[GL_SHADER_STOCK_BLEND] = prg[0];
cgGLBindProgram(prg[1].fprg);
cgGLBindProgram(prg[1].vprg);

View File

@ -20,9 +20,7 @@
#include "shader_common.h"
#include <stdint.h>
#define RARCH_CG_MAX_SHADERS 16
void gl_cg_set_compiler_args(const char **argv);
void gl_cg_invalidate_context(void); // Call when resetting GL context on PS3.
extern const gl_shader_backend_t gl_cg_backend;

View File

@ -30,6 +30,8 @@
#include "shader_parse.h"
#include "math/matrix.h"
#define GL_SHADER_STOCK_BLEND (GFX_MAX_SHADERS - 1)
struct gl_shader_backend
{
bool (*init)(const char *path);

View File

@ -130,7 +130,7 @@ static GLuint gl_teximage[GFX_MAX_TEXTURES];
static state_tracker_t *gl_state_tracker;
static GLint gl_attribs[PREV_TEXTURES + 1 + 4 + RARCH_GLSL_MAX_SHADERS];
static GLint gl_attribs[PREV_TEXTURES + 1 + 4 + GFX_MAX_SHADERS];
static unsigned gl_attrib_index;
static gfx_ctx_proc_t (*glsl_get_proc_address)(const char*);
@ -162,17 +162,40 @@ struct shader_uniforms
int lut_texture[GFX_MAX_TEXTURES];
struct shader_uniforms_frame orig;
struct shader_uniforms_frame pass[RARCH_GLSL_MAX_SHADERS];
struct shader_uniforms_frame pass[GFX_MAX_SHADERS];
struct shader_uniforms_frame prev[PREV_TEXTURES];
};
static struct shader_uniforms gl_uniforms[RARCH_GLSL_MAX_SHADERS];
static struct shader_uniforms gl_uniforms[GFX_MAX_SHADERS];
static const char *glsl_prefixes[] = {
"",
"ruby",
};
// Need to duplicate these to work around broken stuff on Android.
// Must enforce alpha = 1.0 or 32-bit games can potentially go black.
static const char *stock_vertex_modern =
"attribute vec2 TexCoord;\n"
"attribute vec2 VertexCoord;\n"
"attribute vec4 Color;\n"
"uniform mat4 MVPMatrix;\n"
"varying vec2 tex_coord;\n"
"void main() {\n"
" gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0);\n"
" tex_coord = TexCoord;\n"
"}";
static const char *stock_fragment_modern =
"#ifdef GL_ES\n"
"precision mediump float;\n"
"#endif\n"
"uniform sampler2D Texture;\n"
"varying vec2 tex_coord;\n"
"void main() {\n"
" gl_FragColor = vec4(texture2D(Texture, tex_coord).rgb, 1.0);\n"
"}";
static const char *stock_vertex_legacy =
"varying vec4 color;\n"
"void main() {\n"
@ -188,7 +211,7 @@ static const char *stock_fragment_legacy =
" gl_FragColor = color * texture2D(Texture, gl_TexCoord[0].xy);\n"
"}";
static const char *stock_vertex_modern =
static const char *stock_vertex_modern_blend =
"attribute vec2 TexCoord;\n"
"attribute vec2 VertexCoord;\n"
"attribute vec4 Color;\n"
@ -201,7 +224,7 @@ static const char *stock_vertex_modern =
" color = Color;\n"
"}";
static const char *stock_fragment_modern =
static const char *stock_fragment_modern_blend =
"#ifdef GL_ES\n"
"precision mediump float;\n"
"#endif\n"
@ -718,6 +741,19 @@ static bool gl_glsl_init(const char *path)
gl_program[glsl_shader->passes + 1] = gl_program[0];
gl_uniforms[glsl_shader->passes + 1] = gl_uniforms[0];
if (glsl_shader->modern)
{
gl_program[GL_SHADER_STOCK_BLEND] = compile_program(stock_vertex_modern_blend,
stock_fragment_modern_blend, GL_SHADER_STOCK_BLEND);
find_uniforms(gl_program[GL_SHADER_STOCK_BLEND], &gl_uniforms[GL_SHADER_STOCK_BLEND]);
}
else
{
gl_program[GL_SHADER_STOCK_BLEND] = gl_program[0];
gl_uniforms[GL_SHADER_STOCK_BLEND] = gl_uniforms[0];
}
gl_glsl_reset_attrib();
return true;
@ -728,7 +764,7 @@ static void gl_glsl_deinit(void)
if (glsl_enable)
{
pglUseProgram(0);
for (unsigned i = 0; i <= glsl_shader->passes; i++)
for (unsigned i = 0; i < GFX_MAX_SHADERS; i++)
{
if (gl_program[i] == 0 || (i && gl_program[i] == gl_program[0]))
continue;

View File

@ -20,11 +20,7 @@
#include "../boolean.h"
#include "shader_common.h"
#define RARCH_GLSL_MAX_SHADERS 16
#define RARCH_GLSL_MENU_SHADER_INDEX (RARCH_GLSL_MAX_SHADERS - 1)
void gl_glsl_set_get_proc_address(gfx_ctx_proc_t (*proc)(const char*));
extern const gl_shader_backend_t gl_glsl_backend;
#endif