Refactor gl_set_texture_frame

This commit is contained in:
twinaphex 2015-02-11 16:05:11 +01:00
parent 118ce66dec
commit 821a3283dc
4 changed files with 24 additions and 38 deletions

View File

@ -2785,7 +2785,8 @@ static bool gl_overlay_load(void *data,
gl_load_texture_data(gl->overlay_tex[i], gl_load_texture_data(gl->overlay_tex[i],
RARCH_WRAP_EDGE, TEXTURE_FILTER_LINEAR, RARCH_WRAP_EDGE, TEXTURE_FILTER_LINEAR,
alignment, alignment,
images[i].width, images[i].height, images[i].pixels); images[i].width, images[i].height, images[i].pixels,
sizeof(uint32_t));
/* Default. Stretch to whole screen. */ /* Default. Stretch to whole screen. */
gl_overlay_tex_geom(gl, i, 0, 0, 1, 1); gl_overlay_tex_geom(gl, i, 0, 0, 1, 1);
@ -2991,7 +2992,7 @@ static void gl_set_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height, const void *frame, bool rgb32, unsigned width, unsigned height,
float alpha) float alpha)
{ {
unsigned base_size; unsigned base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
gl_t *gl = (gl_t*)data; gl_t *gl = (gl_t*)data;
if (!gl) if (!gl)
return; return;
@ -2999,38 +3000,18 @@ static void gl_set_texture_frame(void *data,
context_bind_hw_render(gl, false); context_bind_hw_render(gl, false);
if (!gl->menu_texture) if (!gl->menu_texture)
{
glGenTextures(1, &gl->menu_texture); glGenTextures(1, &gl->menu_texture);
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl_load_texture_data(gl->menu_texture,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); RARCH_WRAP_EDGE, TEXTURE_FILTER_LINEAR,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); video_pixel_get_alignment(width * base_size),
} width, height, frame,
else base_size);
glBindTexture(GL_TEXTURE_2D, gl->menu_texture);
gl->menu_texture_alpha = alpha; gl->menu_texture_alpha = alpha;
base_size = rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(width * base_size));
if (rgb32)
{
glTexImage2D(GL_TEXTURE_2D,
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
width, height,
0, driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
RARCH_GL_FORMAT32, frame);
}
else
{
glTexImage2D(GL_TEXTURE_2D,
0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4, frame);
}
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
context_bind_hw_render(gl, true); context_bind_hw_render(gl, true);
} }

View File

@ -21,11 +21,12 @@ void gl_load_texture_data(GLuint id,
enum texture_filter_type filter_type, enum texture_filter_type filter_type,
unsigned alignment, unsigned alignment,
unsigned width, unsigned height, unsigned width, unsigned height,
const void *frame) const void *frame, unsigned base_size)
{ {
GLint mag_filter, min_filter; GLint mag_filter, min_filter;
GLenum wrap; GLenum wrap;
bool want_mipmap = false; bool want_mipmap = false;
bool rgb32 = (base_size == (sizeof(uint32_t)));
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
@ -69,10 +70,10 @@ void gl_load_texture_data(GLuint id,
#endif #endif
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32, (driver.gfx_use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
width, height, 0, width, height, 0,
driver.gfx_use_rgba ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32, (driver.gfx_use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
RARCH_GL_FORMAT32, frame); (rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame);
if (want_mipmap) if (want_mipmap)
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
@ -122,7 +123,7 @@ bool gl_load_luts(const struct video_shader *generic_shader,
generic_shader->lut[i].wrap, generic_shader->lut[i].wrap,
filter_type, 4, filter_type, 4,
img.width, img.height, img.width, img.height,
img.pixels); img.pixels, sizeof(uint32_t));
texture_image_free(&img); texture_image_free(&img);
} }

View File

@ -408,7 +408,8 @@ void gl_load_texture_data(GLuint id,
enum texture_filter_type filter_type, enum texture_filter_type filter_type,
unsigned alignment, unsigned alignment,
unsigned width, unsigned height, unsigned width, unsigned height,
const void *frame); const void *frame,
unsigned base_size);
bool gl_load_luts(const struct video_shader *generic_shader, bool gl_load_luts(const struct video_shader *generic_shader,
GLuint *lut_textures); GLuint *lut_textures);

View File

@ -30,8 +30,11 @@ static void menu_texture_png_load_gl(struct texture_image *ti,
/* Generate the OpenGL texture object */ /* Generate the OpenGL texture object */
glGenTextures(1, id); glGenTextures(1, id);
gl_load_texture_data((GLuint)*id, gl_load_texture_data((GLuint)*id,
RARCH_WRAP_EDGE, filter_type, 4 /* TODO/FIXME - dehardcode */, RARCH_WRAP_EDGE, filter_type,
ti->width, ti->height, ti->pixels); 4 /* TODO/FIXME - dehardcode */,
ti->width, ti->height, ti->pixels,
sizeof(uint32_t) /* TODO/FIXME - dehardcode */
);
} }
#endif #endif