From 43c99480879a61aaf849444e4344036a764655b3 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 1 Oct 2014 20:37:52 +0200 Subject: [PATCH] (GL) Prevent memcpy on gl->tex_coords --- gfx/fonts/gl_raster_font.c | 2 +- gfx/gl.c | 31 ++++++++++++++----------------- gfx/gl_common.h | 2 +- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/gfx/fonts/gl_raster_font.c b/gfx/fonts/gl_raster_font.c index 69e3311d98..7a8f679e8f 100644 --- a/gfx/fonts/gl_raster_font.c +++ b/gfx/fonts/gl_raster_font.c @@ -189,7 +189,7 @@ static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, /* Post - Go back to old rendering path. */ gl->coords.vertex = gl->vertex_ptr; - gl->coords.tex_coord = gl->tex_coords; + gl->coords.tex_coord = gl->tex_info.coord; gl->coords.color = gl->white_color_ptr; gl->coords.vertices = 4; glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); diff --git a/gfx/gl.c b/gfx/gl.c index 6ee40dca4e..9010772c99 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1060,7 +1060,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) gl_shader_set_coords(gl, &gl->coords, &gl->mvp); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - gl->coords.tex_coord = gl->tex_coords; + gl->coords.tex_coord = gl->tex_info.coord; } #endif @@ -1106,7 +1106,7 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi { GLfloat xamt = (GLfloat)width / gl->tex_w; GLfloat yamt = (GLfloat)height / gl->tex_h; - set_texture_coords(gl->tex_coords, xamt, yamt); + set_texture_coords(gl->tex_info.coord, xamt, yamt); } } @@ -1436,7 +1436,7 @@ static inline void gl_draw_texture(gl_t *gl) glDisable(GL_BLEND); gl->coords.vertex = gl->vertex_ptr; - gl->coords.tex_coord = gl->tex_coords; + gl->coords.tex_coord = gl->tex_info.coord; gl->coords.color = gl->white_color_ptr; } #endif @@ -1543,14 +1543,11 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei } #endif - struct gl_tex_info tex_info = {0}; - tex_info.tex = gl->texture[gl->tex_index]; - tex_info.input_size[0] = width; - tex_info.input_size[1] = height; - tex_info.tex_size[0] = gl->tex_w; - tex_info.tex_size[1] = gl->tex_h; - - memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); + gl->tex_info.tex = gl->texture[gl->tex_index]; + gl->tex_info.input_size[0] = width; + gl->tex_info.input_size[1] = height; + gl->tex_info.tex_size[0] = gl->tex_w; + gl->tex_info.tex_size[1] = gl->tex_h; glClear(GL_COLOR_BUFFER_BIT); @@ -1559,7 +1556,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl->tex_w, gl->tex_h, gl->vp.width, gl->vp.height, g_extern.frame_count, - &tex_info, gl->prev_info, NULL, 0); + &gl->tex_info, gl->prev_info, NULL, 0); gl->coords.vertices = 4; gl_shader_set_coords(gl, &gl->coords, &gl->mvp); @@ -1567,10 +1564,10 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei #ifdef HAVE_FBO if (gl->fbo_inited) - gl_frame_fbo(gl, &tex_info); + gl_frame_fbo(gl, &gl->tex_info); #endif - gl_set_prev_texture(gl, &tex_info); + gl_set_prev_texture(gl, &gl->tex_info); #if defined(HAVE_MENU) if (g_extern.is_menu @@ -2306,9 +2303,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo glDisable(GL_CULL_FACE); glDisable(GL_DITHER); - memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); + memcpy(gl->tex_info.coord, tex_coords, sizeof(gl->tex_info.coord)); gl->coords.vertex = gl->vertex_ptr; - gl->coords.tex_coord = gl->tex_coords; + gl->coords.tex_coord = gl->tex_info.coord; gl->coords.color = gl->white_color_ptr; gl->coords.lut_tex_coord = tex_coords; gl->coords.vertices = 4; @@ -2817,7 +2814,7 @@ static void gl_render_overlay(void *data) glDisable(GL_BLEND); gl->coords.vertex = gl->vertex_ptr; - gl->coords.tex_coord = gl->tex_coords; + gl->coords.tex_coord = gl->tex_info.coord; gl->coords.color = gl->white_color_ptr; gl->coords.vertices = 4; if (gl->overlay_full_screen) diff --git a/gfx/gl_common.h b/gfx/gl_common.h index ed5d804de8..69663d24e5 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -206,6 +206,7 @@ typedef struct gl GLuint texture[MAX_TEXTURES]; unsigned tex_index; /* For use with PREV. */ unsigned textures; + struct gl_tex_info tex_info; struct gl_tex_info prev_info[MAX_TEXTURES]; GLuint tex_mag_filter; GLuint tex_min_filter; @@ -254,7 +255,6 @@ typedef struct gl unsigned last_width[MAX_TEXTURES]; unsigned last_height[MAX_TEXTURES]; unsigned tex_w, tex_h; - GLfloat tex_coords[8]; math_matrix mvp, mvp_no_rot; struct gl_coords coords;