Implement texture clears for buffer textures

This commit is contained in:
rdb 2015-08-23 17:13:12 +02:00
parent cbb3969017
commit 3ece15bba0
2 changed files with 39 additions and 7 deletions

View File

@ -818,13 +818,28 @@ reset() {
if (_glClearTexImage == NULL) {
GLCAT.warning()
<< "GL_ARB_clear_texture advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n";
<< "GL_ARB_clear_texture advertised as supported by OpenGL runtime, but could not get pointers to extension function.\n";
} else {
_supports_clear_texture = true;
}
}
#endif
_supports_clear_buffer = false;
#ifndef OPENGLES
if (is_at_least_gl_version(4, 3) || has_extension("GL_ARB_clear_buffer_object")) {
_glClearBufferData = (PFNGLCLEARBUFFERDATAPROC)
get_extension_func("glClearBufferData");
if (_glClearBufferData == NULL) {
GLCAT.warning()
<< "GL_ARB_clear_buffer_object advertised as supported by OpenGL runtime, but could not get pointers to extension function.\n";
} else {
_supports_clear_buffer = true;
}
}
#endif
_supports_2d_texture_array = false;
#ifndef OPENGLES
if (is_at_least_gl_version(3, 0)) {
@ -11303,13 +11318,25 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
// The texture has a clear color, so we should fill this mipmap
// level to a solid color.
#ifndef OPENGLES
if (_supports_clear_texture) {
// We can do that with the convenient glClearTexImage function.
string clear_data = tex->get_clear_data();
if (texture_target != GL_TEXTURE_BUFFER) {
if (_supports_clear_texture) {
// We can do that with the convenient glClearTexImage function.
string clear_data = tex->get_clear_data();
_glClearTexImage(gtc->_index, n - mipmap_bias, external_format,
component_type, (void *)clear_data.data());
continue;
_glClearTexImage(gtc->_index, n - mipmap_bias, external_format,
component_type, (void *)clear_data.data());
continue;
}
} else {
if (_supports_clear_buffer) {
// For buffer textures we need to clear the underlying storage.
string clear_data = tex->get_clear_data();
cerr << "clearing buffer data\n";
_glClearBufferData(GL_TEXTURE_BUFFER, internal_format, external_format,
component_type, (const void *)clear_data.data());
continue;
}
}
#endif // OPENGLES
// Ask the Texture class to create the mipmap level in RAM.

View File

@ -695,6 +695,11 @@ public:
PFNGLCLEARTEXIMAGEPROC _glClearTexImage;
#endif
bool _supports_clear_buffer;
#ifndef OPENGLES
PFNGLCLEARBUFFERDATAPROC _glClearBufferData;
#endif
PFNGLCOMPRESSEDTEXIMAGE1DPROC _glCompressedTexImage1D;
PFNGLCOMPRESSEDTEXIMAGE2DPROC _glCompressedTexImage2D;
PFNGLCOMPRESSEDTEXIMAGE3DPROC _glCompressedTexImage3D;