diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 23d9665e47..a1d2f5567e 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -38,6 +38,7 @@ #include "../gl_common.h" #include "../video_viewport.h" +#include "../video_pixel_converter.h" #include "../video_context_driver.h" #include @@ -87,17 +88,6 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; -static inline unsigned get_alignment(unsigned pitch) -{ - if (pitch & 1) - return 1; - if (pitch & 2) - return 2; - if (pitch & 4) - return 4; - return 8; -} - static inline bool gl_query_extension(gl_t *gl, const char *ext) { bool ret = false; @@ -1084,7 +1074,7 @@ static void gl_update_input_size(gl_t *gl, unsigned width, if (clear) { glPixelStorei(GL_UNPACK_ALIGNMENT, - get_alignment(width * sizeof(uint32_t))); + video_pixel_get_alignment(width * sizeof(uint32_t))); #if defined(HAVE_PSGL) glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size, @@ -1292,7 +1282,7 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, else #endif { - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * gl->base_size)); + glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(width * gl->base_size)); /* Fallback for GLES devices without GL_BGRA_EXT. */ if (gl->base_size == 4 && driver.gfx_use_rgba) @@ -1355,7 +1345,7 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE); #else const GLvoid *data_buf = frame; - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch)); + glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(pitch)); if (gl->base_size == 2 && !gl->have_es2_compat) { @@ -1403,7 +1393,7 @@ static void gl_pbo_async_readback(gl_t *gl) glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_ALIGNMENT, - get_alignment(gl->vp.width * sizeof(uint32_t))); + video_pixel_get_alignment(gl->vp.width * sizeof(uint32_t))); /* Read asynchronously into PBO buffer. */ RARCH_PERFORMANCE_INIT(async_readback); @@ -2789,20 +2779,13 @@ static bool gl_overlay_load(void *data, for (i = 0; i < num_images; i++) { - glBindTexture(GL_TEXTURE_2D, gl->overlay_tex[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + unsigned alignment = video_pixel_get_alignment(images[i].width + * sizeof(uint32_t)); - glPixelStorei(GL_UNPACK_ALIGNMENT, - get_alignment(images[i].width * sizeof(uint32_t))); - - glTexImage2D(GL_TEXTURE_2D, 0, driver.gfx_use_rgba ? - GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, - images[i].width, images[i].height, 0, - driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, - RARCH_GL_FORMAT32, images[i].pixels); + gl_load_texture_data(gl->overlay_tex[i], + &images[i], + RARCH_WRAP_EDGE, TEXTURE_FILTER_LINEAR, + alignment); /* Default. Stretch to whole screen. */ gl_overlay_tex_geom(gl, i, 0, 0, 1, 1); @@ -3030,7 +3013,7 @@ static void gl_set_texture_frame(void *data, gl->menu_texture_alpha = alpha; base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(width * base_size)); + glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(width * base_size)); if (rgb32) { diff --git a/gfx/gl_common.c b/gfx/gl_common.c index 0d72fd7d2b..0c632a2778 100644 --- a/gfx/gl_common.c +++ b/gfx/gl_common.c @@ -19,7 +19,8 @@ void gl_load_texture_data(GLuint id, const struct texture_image *img, enum gfx_wrap_type wrap_type, - enum texture_filter_type filter_type) + enum texture_filter_type filter_type, + unsigned alignment) { GLint mag_filter, min_filter; GLenum wrap; @@ -63,7 +64,7 @@ void gl_load_texture_data(GLuint id, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); #ifndef HAVE_PSGL - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); #endif glTexImage2D(GL_TEXTURE_2D, 0, @@ -118,7 +119,7 @@ bool gl_load_luts(const struct video_shader *generic_shader, gl_load_texture_data(textures_lut[i], &img, generic_shader->lut[i].wrap, - filter_type); + filter_type, 4); texture_image_free(&img); } diff --git a/gfx/gl_common.h b/gfx/gl_common.h index a7b0261ee7..78efa3dc1e 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -406,7 +406,8 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, void gl_load_texture_data(GLuint id, const struct texture_image *img, enum gfx_wrap_type wrap_type, - enum texture_filter_type filter_type); + enum texture_filter_type filter_type, + unsigned alignment); bool gl_load_luts(const struct video_shader *generic_shader, GLuint *lut_textures); diff --git a/gfx/video_pixel_converter.c b/gfx/video_pixel_converter.c index 9a0bab90b8..6e2f979c4b 100644 --- a/gfx/video_pixel_converter.c +++ b/gfx/video_pixel_converter.c @@ -52,3 +52,14 @@ bool init_video_pixel_converter(unsigned size) return true; } + +unsigned video_pixel_get_alignment(unsigned pitch) +{ + if (pitch & 1) + return 1; + if (pitch & 2) + return 2; + if (pitch & 4) + return 4; + return 8; +} diff --git a/gfx/video_pixel_converter.h b/gfx/video_pixel_converter.h index d6a8d22f16..f08abed0c4 100644 --- a/gfx/video_pixel_converter.h +++ b/gfx/video_pixel_converter.h @@ -27,6 +27,8 @@ void deinit_pixel_converter(void); bool init_video_pixel_converter(unsigned size); +unsigned video_pixel_get_alignment(unsigned pitch); + #ifdef __cplusplus } #endif diff --git a/menu/menu_texture.c b/menu/menu_texture.c index 2b875cf6c8..1b020c6f66 100644 --- a/menu/menu_texture.c +++ b/menu/menu_texture.c @@ -17,6 +17,7 @@ #include "menu_texture.h" #include #include "../general.h" +#include "../gfx/video_pixel_converter.h" #include "../gfx/video_thread_wrapper.h" #ifdef HAVE_OPENGL @@ -29,7 +30,7 @@ static void menu_texture_png_load_gl(struct texture_image *ti, /* Generate the OpenGL texture object */ glGenTextures(1, id); gl_load_texture_data((GLuint)*id, - ti, RARCH_WRAP_EDGE, filter_type); + ti, RARCH_WRAP_EDGE, filter_type, 4 /* TODO/FIXME - dehardcode */); } #endif