gl33: use glTexStorage* and glInvalidateTexImage* when available
glTexStorage is mostly intended to work around a regression in ANGLE's Metal backend; see https://issues.chromium.org/issues/355605685 Potentially fixes #386
This commit is contained in:
parent
54f9a6daab
commit
5274cec283
3 changed files with 54 additions and 9 deletions
|
@ -229,28 +229,29 @@ static void gl33_texture_set(Texture *tex, uint mipmap, uint layer, const Pixmap
|
|||
|
||||
GLenum gl_target = target_from_class_and_layer(tex->params.class, layer);
|
||||
GLenum ifmt = tex->fmt_info->internal_format;
|
||||
GLenum xfmt = xfer->gl_format;
|
||||
GLenum xtype = xfer->gl_type;
|
||||
|
||||
if(tex->fmt_info->flags & GLTEX_COMPRESSED) {
|
||||
glCompressedTexImage2D(
|
||||
glCompressedTexSubImage2D(
|
||||
gl_target,
|
||||
mipmap,
|
||||
ifmt,
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
ifmt,
|
||||
image->data_size,
|
||||
image_data
|
||||
);
|
||||
} else {
|
||||
GLenum xfmt = xfer->gl_format;
|
||||
GLenum xtype = xfer->gl_type;
|
||||
glTexImage2D(
|
||||
glTexSubImage2D(
|
||||
gl_target,
|
||||
mipmap,
|
||||
tex->fmt_info->internal_format,
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
xfmt,
|
||||
xtype,
|
||||
image_data
|
||||
|
@ -394,7 +395,9 @@ Texture *gl33_texture_create(const TextureParams *params) {
|
|||
GLenum xfmt = xfer->gl_format;
|
||||
GLenum xtype = xfer->gl_type;
|
||||
|
||||
for(uint i = 0; i < p->mipmaps; ++i) {
|
||||
if(glext.texture_storage) {
|
||||
glTexStorage2D(gl_target, p->mipmaps, ifmt, p->width, p->height);
|
||||
} else for(uint i = 0; i < p->mipmaps; ++i) {
|
||||
uint w, h;
|
||||
gl33_texture_get_size(tex, i, &w, &h);
|
||||
|
||||
|
@ -457,6 +460,25 @@ void gl33_texture_invalidate(Texture *tex) {
|
|||
return;
|
||||
}
|
||||
|
||||
if(glext.texture_storage) {
|
||||
if(glext.invalidate_subdata) {
|
||||
#ifndef STATIC_GLES3
|
||||
gl33_bind_texture(tex, 0, -1);
|
||||
gl33_sync_texunit(tex->binding_unit, false, true);
|
||||
|
||||
for(uint i = 0; i < tex->params.mipmaps; ++i) {
|
||||
glInvalidateTexImage(tex->bind_target, i);
|
||||
}
|
||||
#else
|
||||
UNREACHABLE;
|
||||
#endif
|
||||
} else {
|
||||
log_debug("TODO/FIXME: can't invalidate immutable texture without GL_ARB_invalidate_subdata!");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
gl33_bind_texture(tex, 0, -1);
|
||||
gl33_sync_texunit(tex->binding_unit, false, true);
|
||||
|
||||
|
|
|
@ -650,6 +650,25 @@ static void glcommon_ext_texture_format_fxt1(void) {
|
|||
EXT_MISSING();
|
||||
}
|
||||
|
||||
static void glcommon_ext_texture_storage(void) {
|
||||
EXT_FLAG(texture_storage);
|
||||
|
||||
CHECK_CORE(GL_ATLEAST(4, 2));
|
||||
CHECK_CORE(GLES_ATLEAST(3, 0));
|
||||
CHECK_EXT(GL_ARB_texture_storage);
|
||||
|
||||
EXT_MISSING();
|
||||
}
|
||||
|
||||
static void glcommon_ext_invalidate_subdata(void) {
|
||||
EXT_FLAG(invalidate_subdata);
|
||||
|
||||
CHECK_CORE(GL_ATLEAST(4, 3));
|
||||
CHECK_EXT(GL_ARB_invalidate_subdata);
|
||||
|
||||
EXT_MISSING();
|
||||
}
|
||||
|
||||
static const char *get_unmasked_property(GLenum prop, bool fallback) {
|
||||
const char *val = NULL;
|
||||
|
||||
|
@ -933,6 +952,7 @@ void glcommon_check_capabilities(void) {
|
|||
glcommon_ext_float_blend();
|
||||
glcommon_ext_instanced_arrays();
|
||||
glcommon_ext_internalformat_query2();
|
||||
glcommon_ext_invalidate_subdata();
|
||||
glcommon_ext_pixel_buffer_object();
|
||||
glcommon_ext_seamless_cubemap();
|
||||
glcommon_ext_texture_filter_anisotropic();
|
||||
|
@ -942,6 +962,7 @@ void glcommon_check_capabilities(void) {
|
|||
glcommon_ext_texture_half_float_linear();
|
||||
glcommon_ext_texture_norm16();
|
||||
glcommon_ext_texture_rg();
|
||||
glcommon_ext_texture_storage();
|
||||
glcommon_ext_texture_swizzle();
|
||||
glcommon_ext_vertex_array_object();
|
||||
glcommon_ext_viewport_array();
|
||||
|
|
|
@ -168,6 +168,7 @@ struct glext_s {
|
|||
ext_flag_t float_blend;
|
||||
ext_flag_t instanced_arrays;
|
||||
ext_flag_t internalformat_query2;
|
||||
ext_flag_t invalidate_subdata;
|
||||
ext_flag_t pixel_buffer_object;
|
||||
ext_flag_t seamless_cubemap;
|
||||
ext_flag_t texture_filter_anisotropic;
|
||||
|
@ -177,6 +178,7 @@ struct glext_s {
|
|||
ext_flag_t texture_half_float_linear;
|
||||
ext_flag_t texture_norm16;
|
||||
ext_flag_t texture_rg;
|
||||
ext_flag_t texture_storage;
|
||||
ext_flag_t texture_swizzle;
|
||||
ext_flag_t vertex_array_object;
|
||||
ext_flag_t viewport_array;
|
||||
|
|
Loading…
Reference in a new issue