Refactor SHADER_CTL_USE

This commit is contained in:
twinaphex 2016-04-15 07:37:06 +02:00
parent 0f65518118
commit 9d85afd358
9 changed files with 49 additions and 28 deletions

View File

@ -222,6 +222,7 @@ static void renderchain_set_vertices(void *data, unsigned pass,
shader_info.data = d3d;
shader_info.idx = pass;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);

View File

@ -1190,8 +1190,9 @@ static void gl_frame_fbo(gl_t *gl, uint64_t frame_count,
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, gl->fbo[i]);
shader_info.data = gl;
shader_info.idx = i + 1;
shader_info.data = gl;
shader_info.idx = i + 1;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]);
@ -1263,8 +1264,9 @@ static void gl_frame_fbo(gl_t *gl, uint64_t frame_count,
/* Render our FBO texture to back buffer. */
gl_bind_backbuffer();
shader_info.data = gl;
shader_info.idx = gl->fbo_pass + 1;
shader_info.data = gl;
shader_info.idx = gl->fbo_pass + 1;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
@ -1685,8 +1687,9 @@ static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx)
video_driver_get_size(&width, &height);
shader_info.data = gl;
shader_info.idx = idx;
shader_info.data = gl;
shader_info.idx = idx;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
gl_set_viewport(gl, width, height, false, true);
@ -1763,8 +1766,9 @@ static INLINE void gl_draw_texture(gl_t *gl)
gl->coords.color = color;
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
shader_info.data = gl;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.data = gl;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
@ -1833,9 +1837,9 @@ static bool gl_frame(void *data, const void *frame,
glBindVertexArray(gl->vao);
#endif
shader_info.data = gl;
shader_info.idx = 1;
shader_info.data = gl;
shader_info.idx = 1;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
@ -2015,8 +2019,9 @@ static bool gl_frame(void *data, const void *frame,
/* Reset state which could easily mess up libretro core. */
if (gl->hw_render_fbo_init)
{
shader_info.data = gl;
shader_info.idx = 0;
shader_info.data = gl;
shader_info.idx = 0;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
@ -3600,8 +3605,9 @@ static void gl_render_overlay(gl_t *gl)
glViewport(0, 0, width, height);
/* Ensure that we reset the attrib array. */
shader_info.data = gl;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.data = gl;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);

View File

@ -406,8 +406,9 @@ static void gl_raster_font_setup_viewport(gl_raster_t *font, bool full_screen)
glBindTexture(GL_TEXTURE_2D, font->tex);
shader_info.data = NULL;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.data = NULL;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
}

View File

@ -1600,21 +1600,19 @@ static bool gl_glsl_set_coords(void *handle_data, void *shader_data, const void
static void gl_glsl_use(void *data, void *shader_data, unsigned idx, bool set_active)
{
GLuint id;
glsl_shader_data_t *glsl = (glsl_shader_data_t*)shader_data;
(void)data;
if (!glsl)
return;
if (set_active)
{
glsl_shader_data_t *glsl = (glsl_shader_data_t*)shader_data;
if (!glsl)
return;
gl_glsl_reset_attrib(glsl);
glsl->glsl_active_index = idx;
id = glsl->prg[idx].id;
}
else
id = idx;
id = (GLuint)idx;
glUseProgram(id);
}

View File

@ -228,7 +228,7 @@ bool video_shader_driver_ctl(enum video_shader_driver_ctl_state state, void *dat
video_shader_ctx_info_t *shader_info = (video_shader_ctx_info_t*)data;
if (!current_shader || !shader_info)
return false;
current_shader->use(shader_info->data, shader_data, shader_info->idx, true);
current_shader->use(shader_info->data, shader_data, shader_info->idx, shader_info->set_active);
}
break;
case SHADER_CTL_WRAP_TYPE:

View File

@ -216,6 +216,7 @@ typedef struct video_shader_ctx_scale
typedef struct video_shader_ctx_info
{
bool set_active;
unsigned num;
unsigned idx;
void *data;

View File

@ -493,6 +493,7 @@ menu_ctx_driver_t menu_ctx_zr = {
NULL,
NULL,
NULL,
NULL,
"zahnrad",
zrmenu_environ,
NULL,

View File

@ -20,6 +20,7 @@
#include "zr_common.h"
#include "../menu_display.h"
#include "../../gfx/video_shader_driver.h"
struct zr_image zr_common_image_load(const char *filename)
{
@ -246,6 +247,7 @@ void zr_common_device_draw(struct zr_device *dev,
struct zr_context *ctx, int width, int height,
enum zr_anti_aliasing AA)
{
video_shader_ctx_info_t shader_info;
struct zr_buffer vbuf, ebuf;
struct zr_convert_config config;
const struct zr_draw_command *cmd = NULL;
@ -276,9 +278,15 @@ void zr_common_device_draw(struct zr_device *dev,
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glActiveTexture(GL_TEXTURE0);
#endif
/* setup program */
glUseProgram(dev->prog);
shader_info.data = NULL;
shader_info.idx = dev->prog;
shader_info.set_active = false;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
/* convert from command queue into draw list and draw to screen */
@ -335,9 +343,13 @@ void zr_common_device_draw(struct zr_device *dev,
}
zr_clear(ctx);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
/* restore old state */
glUseProgram((GLuint)last_prog);
shader_info.data = NULL;
shader_info.idx = last_prog;
shader_info.set_active = false;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glBindTexture(GL_TEXTURE_2D, (GLuint)last_tex);
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)last_vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (GLuint)last_ebo);

View File

@ -84,6 +84,7 @@ static void menu_display_gl_blend_begin(void)
shader_info.data = NULL;
shader_info.idx = GL_SHADER_STOCK_BLEND;
shader_info.set_active = true;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
}