diff --git a/gfx/common/gl_common.c b/gfx/common/gl_common.c index cd0e138db8..0af64ce5be 100644 --- a/gfx/common/gl_common.c +++ b/gfx/common/gl_common.c @@ -15,6 +15,7 @@ */ #include +#include #include "../drivers/gl_symlinks.h" #include "../video_coord_array.h" @@ -49,3 +50,28 @@ void gl_ff_matrix(const math_matrix_4x4 *mat) glLoadMatrixf(ident.data); #endif } + +/* This function should only be used without mipmaps + and when data == NULL */ +void loadTexture(GLenum target, + GLint level, + GLint internalFormat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const GLvoid * data) +{ +#ifndef HAVE_PSGL +#ifdef HAVE_OPENGLES2 + if (gl_check_capability(GL_CAPS_TEX_STORAGE_EXT)) + glTexStorage2DEXT(target, 1, internalFormat, width, height); +#else + if (gl_check_capability(GL_CAPS_TEX_STORAGE)) + glTexStorage2D(target, 1, internalFormat, width, height); +#endif + else +#endif + glTexImage2D(target, level, internalFormat, width, height, border, format, type, data); +} diff --git a/gfx/common/gl_common.h b/gfx/common/gl_common.h index 4face32555..a94e0759d4 100644 --- a/gfx/common/gl_common.h +++ b/gfx/common/gl_common.h @@ -177,5 +177,14 @@ static INLINE unsigned gl_wrap_type_to_enum(enum gfx_wrap_type type) bool gl_query_core_context_in_use(void); void gl_ff_vertex(const struct video_coords *coords); void gl_ff_matrix(const math_matrix_4x4 *mat); +void loadTexture(GLenum target, + GLint level, + GLint internalFormat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const GLvoid * data); #endif diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index be923d038d..8e796a6984 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -606,14 +606,9 @@ static void gl_init_textures_reference(gl_t *gl, unsigned i, if (gl->egl_images) return; -#ifndef HAVE_OPENGLES2 - if (gl_check_capability(GL_CAPS_TEX_STORAGE)) - glTexStorage2D(GL_TEXTURE_2D, 1, internal_fmt, gl->tex_w, gl->tex_h); - else -#endif - glTexImage2D(GL_TEXTURE_2D, - 0, internal_fmt, gl->tex_w, gl->tex_h, 0, texture_type, - texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); + loadTexture(GL_TEXTURE_2D, + 0, internal_fmt, gl->tex_w, gl->tex_h, 0, texture_type, + texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); #endif } diff --git a/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c b/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c index 8bb1bd8da7..1ffdfd7d51 100644 --- a/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c +++ b/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c @@ -163,18 +163,12 @@ static bool gl_recreate_fbo( glDeleteTextures(1, texture); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); -#if !defined(HAVE_OPENGLES2) && !defined(HAVE_PSGL) - if (gl_check_capability(GL_CAPS_TEX_STORAGE)) - glTexStorage2D(GL_TEXTURE_2D, 1, RARCH_GL_INTERNAL_FORMAT32, - fbo_rect->width, fbo_rect->height); - else -#endif - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT32, - fbo_rect->width, - fbo_rect->height, - 0, RARCH_GL_TEXTURE_TYPE32, - RARCH_GL_FORMAT32, NULL); + loadTexture(GL_TEXTURE_2D, + 0, RARCH_GL_INTERNAL_FORMAT32, + fbo_rect->width, + fbo_rect->height, + 0, RARCH_GL_TEXTURE_TYPE32, + RARCH_GL_FORMAT32, NULL); glFramebufferTexture2D(RARCH_GL_FRAMEBUFFER, RARCH_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, @@ -530,15 +524,9 @@ static void gl_create_fbo_texture(gl_t *gl, unsigned i, GLuint texture) if (fp_fbo && gl->has_fp_fbo) { RARCH_LOG("[GL]: FBO pass #%d is floating-point.\n", i); -#if !defined(HAVE_PSGL) - if (gl_check_capability(GL_CAPS_TEX_STORAGE)) - glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, - gl->fbo_rect[i].width, gl->fbo_rect[i].height); - else -#endif - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, - gl->fbo_rect[i].width, gl->fbo_rect[i].height, - 0, GL_RGBA, GL_FLOAT, NULL); + loadTexture(GL_TEXTURE_2D, 0, GL_RGBA32F, + gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, GL_RGBA, GL_FLOAT, NULL); } else #endif @@ -567,14 +555,10 @@ static void gl_create_fbo_texture(gl_t *gl, unsigned i, GLuint texture) gl->has_srgb_fbo_gles3 ? GL_RGBA : GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, NULL); #else - if (gl_check_capability(GL_CAPS_TEX_STORAGE)) - glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, - gl->fbo_rect[i].width, gl->fbo_rect[i].height); - else - glTexImage2D(GL_TEXTURE_2D, - 0, GL_SRGB8_ALPHA8, - gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + loadTexture(GL_TEXTURE_2D, + 0, GL_SRGB8_ALPHA8, + gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); #endif } else @@ -588,14 +572,10 @@ static void gl_create_fbo_texture(gl_t *gl, unsigned i, GLuint texture) #else /* Avoid potential performance * reductions on particular platforms. */ - if (gl_check_capability(GL_CAPS_TEX_STORAGE)) - glTexStorage2D(GL_TEXTURE_2D, 1, RARCH_GL_INTERNAL_FORMAT32, - gl->fbo_rect[i].width, gl->fbo_rect[i].height); - else - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT32, - gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, - RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, NULL); + loadTexture(GL_TEXTURE_2D, + 0, RARCH_GL_INTERNAL_FORMAT32, + gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, + RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, NULL); #endif } } diff --git a/libretro-common/gfx/gl_capabilities.c b/libretro-common/gfx/gl_capabilities.c index d89fff5a8e..2eb0b2febd 100644 --- a/libretro-common/gfx/gl_capabilities.c +++ b/libretro-common/gfx/gl_capabilities.c @@ -315,6 +315,10 @@ bool gl_check_capability(enum gl_capability_enum enum_idx) return true; #endif break; + case GL_CAPS_TEX_STORAGE_EXT: + if (gl_query_extension("EXT_texture_storage")) + return true; + break; case GL_CAPS_NONE: default: break; diff --git a/libretro-common/include/gfx/gl_capabilities.h b/libretro-common/include/gfx/gl_capabilities.h index 2c72593bc9..cf89c4a935 100644 --- a/libretro-common/include/gfx/gl_capabilities.h +++ b/libretro-common/include/gfx/gl_capabilities.h @@ -45,7 +45,8 @@ enum gl_capability_enum GL_CAPS_FP_FBO, GL_CAPS_BGRA8888, GL_CAPS_GLES3_SUPPORTED, - GL_CAPS_TEX_STORAGE + GL_CAPS_TEX_STORAGE, + GL_CAPS_TEX_STORAGE_EXT }; bool gl_check_error(char **error_string);