From 95fa37b17845f7002fecf59c752c0d88cdf1df04 Mon Sep 17 00:00:00 2001 From: meancoot Date: Fri, 7 Dec 2012 02:00:46 -0500 Subject: [PATCH 1/2] (OpenGL ES) Pack texture rows manually instead of making multiple calls to glTexSubImage2D. --- gfx/gl.c | 28 +++++++++++++++++++++++----- gfx/gl_common.h | 6 ++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index bccfd634fe..2df33b9fa9 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -997,13 +997,27 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, un } else // Slower path. { - const uint8_t *src = (const uint8_t*)frame; - for (unsigned h = 0; h < height; h++, src += pitch) + const unsigned frame_bytes = width * height * gl->base_size; + const unsigned line_bytes = width * gl->base_size; + + if(gl->tex_pack_buf_size < frame_bytes) { - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, h, width, 1, gl->texture_type, - gl->texture_fmt, src); + free(gl->tex_pack_buf); + gl->tex_pack_buf = malloc(frame_bytes); + gl->tex_pack_buf_size = frame_bytes; } + + uint8_t* dst = gl->tex_pack_buf; + const uint8_t *src = (const uint8_t*)frame; + + for (unsigned h = 0; h < height; h++, src += pitch, dst += line_bytes) + { + memcpy(dst, src, line_bytes); + } + + glTexSubImage2D(GL_TEXTURE_2D, + 0, 0, 0, width, height, gl->texture_type, + gl->texture_fmt, gl->tex_pack_buf); } } #else @@ -1248,6 +1262,10 @@ static void gl_free(void *data) free(gl->empty_buf); free(gl->conv_buffer); +#if defined(HAVE_OPENGLES) + free(gl->tex_pack_buf); +#endif + free(gl); } diff --git a/gfx/gl_common.h b/gfx/gl_common.h index d2dc037f6c..5aa7354486 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -292,6 +292,12 @@ typedef struct gl unsigned pbo_readback_index; struct scaler_ctx pbo_readback_scaler; #endif + +#if defined(HAVE_OPENGLES) + uint8_t* tex_pack_buf; + unsigned tex_pack_buf_size; +#endif + } gl_t; // Windows ... <_< From a3ebec7f0797f4bbea7076d553c5571fc072e5cb Mon Sep 17 00:00:00 2001 From: meancoot Date: Fri, 7 Dec 2012 02:17:34 -0500 Subject: [PATCH 2/2] Style fix --- gfx/gl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/gl.c b/gfx/gl.c index 2df33b9fa9..ca99e10f49 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1000,7 +1000,7 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, un const unsigned frame_bytes = width * height * gl->base_size; const unsigned line_bytes = width * gl->base_size; - if(gl->tex_pack_buf_size < frame_bytes) + if (gl->tex_pack_buf_size < frame_bytes) { free(gl->tex_pack_buf); gl->tex_pack_buf = malloc(frame_bytes);