diff --git a/src/BufferTexture.cpp b/src/BufferTexture.cpp index 7ff447fa4..28688b929 100644 --- a/src/BufferTexture.cpp +++ b/src/BufferTexture.cpp @@ -29,11 +29,27 @@ #include "Context.h" #include "Extensions.h" +#include "Implementation/State.h" +#include "Implementation/TextureState.h" + namespace Magnum { BufferTexture::SetBufferImplementation BufferTexture::setBufferImplementation = &BufferTexture::setBufferImplementationDefault; BufferTexture::SetBufferRangeImplementation BufferTexture::setBufferRangeImplementation = &BufferTexture::setBufferRangeImplementationDefault; +Int BufferTexture::offsetAlignment() { + if(!Context::current()->isExtensionSupported()) + return 0; + + GLint& value = Context::current()->state().texture->bufferOffsetAlignment; + + /* Get the value, if not already cached */ + if(value == 0) + glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &value); + + return value; +} + void BufferTexture::initializeContextBasedFunctionality(Context& context) { if(context.isExtensionSupported()) { Debug() << "BufferTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; diff --git a/src/BufferTexture.h b/src/BufferTexture.h index 2981efa50..a322d649b 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -205,6 +205,16 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { /** @copydoc AbstractTexture::maxLabelLength() */ static Int maxLabelLength() { return AbstractTexture::maxLabelLength(); } + /** + * @brief Minimum required alignment for texture buffer offsets + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. If extension @extension{ARB,texture_buffer_range} + * (part of OpenGL 4.3) is not available, returns `0`. + * @see @fn_gl{Get} with @def_gl{TEXTURE_BUFFER_OFFSET_ALIGNMENT} + */ + static Int offsetAlignment(); + explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} /** @copydoc AbstractTexture::id() */ diff --git a/src/Implementation/TextureState.cpp b/src/Implementation/TextureState.cpp index 7c08ebceb..68e36264f 100644 --- a/src/Implementation/TextureState.cpp +++ b/src/Implementation/TextureState.cpp @@ -28,7 +28,7 @@ namespace Magnum { namespace Implementation { TextureState::TextureState(): maxAnisotropy(0.0f), currentLayer(0) #ifndef MAGNUM_TARGET_GLES - , maxColorSamples(0), maxDepthSamples(0), maxIntegerSamples(0) + , maxColorSamples(0), maxDepthSamples(0), maxIntegerSamples(0), bufferOffsetAlignment(0) #endif {} diff --git a/src/Implementation/TextureState.h b/src/Implementation/TextureState.h index 91875bc9e..54508124b 100644 --- a/src/Implementation/TextureState.h +++ b/src/Implementation/TextureState.h @@ -39,7 +39,8 @@ struct TextureState { #ifndef MAGNUM_TARGET_GLES GLint maxColorSamples, maxDepthSamples, - maxIntegerSamples; + maxIntegerSamples, + bufferOffsetAlignment; #endif std::vector bindings;