Browse Source

Enabled new buffer functionality in ES 3.1.

pull/68/head
Vladimír Vondruš 12 years ago
parent
commit
ea164f697d
  1. 22
      src/Magnum/Buffer.cpp
  2. 46
      src/Magnum/Buffer.h
  3. 18
      src/Magnum/Implementation/BufferState.cpp
  4. 8
      src/Magnum/Implementation/BufferState.h

22
src/Magnum/Buffer.cpp

@ -48,9 +48,15 @@ Int Buffer::minMapAlignment() {
return value; return value;
} }
#endif
#ifndef MAGNUM_TARGET_GLES2
Int Buffer::maxAtomicCounterBindings() { Int Buffer::maxAtomicCounterBindings() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>()) if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0; return 0;
GLint& value = Context::current()->state().buffer->maxAtomicCounterBindings; GLint& value = Context::current()->state().buffer->maxAtomicCounterBindings;
@ -62,7 +68,11 @@ Int Buffer::maxAtomicCounterBindings() {
} }
Int Buffer::maxShaderStorageBindings() { Int Buffer::maxShaderStorageBindings() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>()) if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0; return 0;
GLint& value = Context::current()->state().buffer->maxShaderStorageBindings; GLint& value = Context::current()->state().buffer->maxShaderStorageBindings;
@ -74,7 +84,11 @@ Int Buffer::maxShaderStorageBindings() {
} }
Int Buffer::shaderStorageOffsetAlignment() { Int Buffer::shaderStorageOffsetAlignment() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>()) if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0; return 0;
GLint& value = Context::current()->state().buffer->shaderStorageOffsetAlignment; GLint& value = Context::current()->state().buffer->shaderStorageOffsetAlignment;
@ -396,14 +410,10 @@ Debug operator<<(Debug debug, Buffer::Target value) {
switch(value) { switch(value) {
#define _c(value) case Buffer::Target::value: return debug << "Buffer::Target::" #value; #define _c(value) case Buffer::Target::value: return debug << "Buffer::Target::" #value;
_c(Array) _c(Array)
#ifndef MAGNUM_TARGET_GLES
_c(AtomicCounter)
#endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
_c(AtomicCounter)
_c(CopyRead) _c(CopyRead)
_c(CopyWrite) _c(CopyWrite)
#endif
#ifndef MAGNUM_TARGET_GLES
_c(DispatchIndirect) _c(DispatchIndirect)
_c(DrawIndirect) _c(DrawIndirect)
#endif #endif
@ -411,9 +421,9 @@ Debug operator<<(Debug debug, Buffer::Target value) {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
_c(PixelPack) _c(PixelPack)
_c(PixelUnpack) _c(PixelUnpack)
_c(ShaderStorage)
#endif #endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
_c(ShaderStorage)
_c(Texture) _c(Texture)
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

46
src/Magnum/Buffer.h

@ -219,11 +219,12 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
/** Used for storing vertex attributes. */ /** Used for storing vertex attributes. */
Array = GL_ARRAY_BUFFER, Array = GL_ARRAY_BUFFER,
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES2
/** /**
* Used for storing atomic counters. * Used for storing atomic counters.
* @requires_gl42 %Extension @extension{ARB,shader_atomic_counters} * @requires_gl42 %Extension @extension{ARB,shader_atomic_counters}
* @requires_gl Atomic counters are not available in OpenGL ES. * @requires_gles31 Atomic counters are not available in OpenGL ES
* 3.0 and older.
*/ */
AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
#endif #endif
@ -246,18 +247,20 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
CopyWrite = GL_COPY_WRITE_BUFFER, CopyWrite = GL_COPY_WRITE_BUFFER,
#endif #endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES2
/** /**
* Indirect compute dispatch commands. * Indirect compute dispatch commands.
* @requires_gl43 %Extension @extension{ARB,compute_shader} * @requires_gl43 %Extension @extension{ARB,compute_shader}
* @requires_gl Compute shaders are not available in OpenGL ES. * @requires_gles31 Compute shaders are not available in OpenGL ES
* 3.0 and older.
*/ */
DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER,
/** /**
* Used for supplying arguments for indirect drawing. * Used for supplying arguments for indirect drawing.
* @requires_gl40 %Extension @extension{ARB,draw_indirect} * @requires_gl40 %Extension @extension{ARB,draw_indirect}
* @requires_gl Indirect drawing not available in OpenGL ES. * @requires_gles31 Indirect drawing not available in OpenGL ES 3.0
* and older.
*/ */
DrawIndirect = GL_DRAW_INDIRECT_BUFFER, DrawIndirect = GL_DRAW_INDIRECT_BUFFER,
#endif #endif
@ -283,14 +286,17 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
PixelUnpack = GL_PIXEL_UNPACK_BUFFER, PixelUnpack = GL_PIXEL_UNPACK_BUFFER,
#endif #endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES2
/** /**
* Used for shader storage. * Used for shader storage.
* @requires_gl43 %Extension @extension{ARB,shader_storage_buffer_object} * @requires_gl43 %Extension @extension{ARB,shader_storage_buffer_object}
* @requires_gl Shader storage is not available in OpenGL ES. * @requires_gles31 Shader storage is not available in OpenGL ES
* 3.0 and older.
*/ */
ShaderStorage = GL_SHADER_STORAGE_BUFFER, ShaderStorage = GL_SHADER_STORAGE_BUFFER,
#endif
#ifndef MAGNUM_TARGET_GLES
/** /**
* Source for texel fetches. See @ref BufferTexture. * Source for texel fetches. See @ref BufferTexture.
* @requires_gl31 %Extension @extension{ARB,texture_buffer_object} * @requires_gl31 %Extension @extension{ARB,texture_buffer_object}
@ -442,21 +448,23 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @brief Minimal supported mapping alignment * @brief Minimal supported mapping alignment
* *
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,map_buffer_alignment} is * OpenGL calls. If extension @extension{ARB,map_buffer_alignment}
* not available, returns `0`. * (part of OpenGL 4.2) is not available, returns `0`.
* @see @ref map(), @fn_gl{Get} with @def_gl{MIN_MAP_BUFFER_ALIGNMENT} * @see @ref map(), @fn_gl{Get} with @def_gl{MIN_MAP_BUFFER_ALIGNMENT}
* @requires_gl No minimal value is specified for OpenGL ES. * @requires_gl No minimal value is specified for OpenGL ES.
*/ */
static Int minMapAlignment(); static Int minMapAlignment();
#endif
#ifndef MAGNUM_TARGET_GLES2
/** /**
* @brief Max supported atomic counter buffer binding count * @brief Max supported atomic counter buffer binding count
* *
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} is * OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* not available, returns `0`. * (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_ATOMIC_COUNTER_BUFFER_BINDINGS} * @see @fn_gl{Get} with @def_gl{MAX_ATOMIC_COUNTER_BUFFER_BINDINGS}
* @requires_gl Atomic counters are not available in OpenGL ES. * @requires_gles30 Not defined in OpenGL ES 2.0
*/ */
static Int maxAtomicCounterBindings(); static Int maxAtomicCounterBindings();
@ -464,10 +472,10 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @brief Max supported shader storage buffer binding count * @brief Max supported shader storage buffer binding count
* *
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object} * OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
* is not available, returns `0`. * (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_SHADER_STORAGE_BUFFER_BINDINGS} * @see @fn_gl{Get} with @def_gl{MAX_SHADER_STORAGE_BUFFER_BINDINGS}
* @requires_gl Atomic counters are not available in OpenGL ES. * @requires_gles30 Not defined in OpenGL ES 2.0
*/ */
static Int maxShaderStorageBindings(); static Int maxShaderStorageBindings();
@ -475,10 +483,10 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @brief Alignment of shader storage buffer binding offset * @brief Alignment of shader storage buffer binding offset
* *
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object} * OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
* is not available, returns `0`. * (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT} * @see @fn_gl{Get} with @def_gl{SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT}
* @requires_gl Atomic counters are not available in OpenGL ES. * @requires_gles30 Not defined in OpenGL ES 2.0
*/ */
static Int shaderStorageOffsetAlignment(); static Int shaderStorageOffsetAlignment();
#endif #endif
@ -489,7 +497,7 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* *
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,uniform_buffer_object} * OpenGL calls. If extension @extension{ARB,uniform_buffer_object}
* is not available, returns `0`. * (part of OpenGL 3.1) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_UNIFORM_BUFFER_BINDINGS} * @see @fn_gl{Get} with @def_gl{MAX_UNIFORM_BUFFER_BINDINGS}
* @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0. * @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0.
*/ */

18
src/Magnum/Implementation/BufferState.cpp

@ -36,24 +36,22 @@ namespace Magnum { namespace Implementation {
const Buffer::Target BufferState::targetForIndex[] = { const Buffer::Target BufferState::targetForIndex[] = {
Buffer::Target::Array, Buffer::Target::Array,
Buffer::Target::ElementArray Buffer::Target::ElementArray,
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
,
Buffer::Target::CopyRead, Buffer::Target::CopyRead,
Buffer::Target::CopyWrite, Buffer::Target::CopyWrite,
Buffer::Target::PixelPack, Buffer::Target::PixelPack,
Buffer::Target::PixelUnpack, Buffer::Target::PixelUnpack,
Buffer::Target::TransformFeedback, Buffer::Target::TransformFeedback,
Buffer::Target::Uniform Buffer::Target::Uniform,
#endif
#ifndef MAGNUM_TARGET_GLES
,
Buffer::Target::AtomicCounter, Buffer::Target::AtomicCounter,
Buffer::Target::DispatchIndirect, Buffer::Target::DispatchIndirect,
Buffer::Target::DrawIndirect, Buffer::Target::DrawIndirect,
Buffer::Target::ShaderStorage, Buffer::Target::ShaderStorage,
#ifndef MAGNUM_TARGET_GLES
Buffer::Target::Texture Buffer::Target::Texture
#endif #endif
#endif
}; };
std::size_t BufferState::indexForTarget(Buffer::Target target) { std::size_t BufferState::indexForTarget(Buffer::Target target) {
@ -67,14 +65,14 @@ std::size_t BufferState::indexForTarget(Buffer::Target target) {
case Buffer::Target::PixelUnpack: return 6; case Buffer::Target::PixelUnpack: return 6;
case Buffer::Target::TransformFeedback: return 7; case Buffer::Target::TransformFeedback: return 7;
case Buffer::Target::Uniform: return 8; case Buffer::Target::Uniform: return 8;
#endif
#ifndef MAGNUM_TARGET_GLES
case Buffer::Target::AtomicCounter: return 9; case Buffer::Target::AtomicCounter: return 9;
case Buffer::Target::DispatchIndirect: return 10; case Buffer::Target::DispatchIndirect: return 10;
case Buffer::Target::DrawIndirect: return 11; case Buffer::Target::DrawIndirect: return 11;
case Buffer::Target::ShaderStorage: return 12; case Buffer::Target::ShaderStorage: return 12;
#ifndef MAGNUM_TARGET_GLES
case Buffer::Target::Texture: return 13; case Buffer::Target::Texture: return 13;
#endif #endif
#endif
} }
CORRADE_ASSERT_UNREACHABLE(); CORRADE_ASSERT_UNREACHABLE();
@ -83,9 +81,9 @@ std::size_t BufferState::indexForTarget(Buffer::Target target) {
BufferState::BufferState(Context& context, std::vector<std::string>& extensions): bindings() BufferState::BufferState(Context& context, std::vector<std::string>& extensions): bindings()
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
, minMapAlignment(0), maxAtomicCounterBindings(0), maxShaderStorageBindings(0), shaderStorageOffsetAlignment(0) , minMapAlignment(0)
#endif #endif
, maxUniformBindings(0) , maxAtomicCounterBindings(0), maxShaderStorageBindings(0), shaderStorageOffsetAlignment(0), maxUniformBindings(0)
#endif #endif
{ {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

8
src/Magnum/Implementation/BufferState.h

@ -32,13 +32,11 @@ namespace Magnum { namespace Implementation {
struct BufferState { struct BufferState {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
static const std::size_t TargetCount = 13+1; static const std::size_t TargetCount = 13+1;
#else #elif !defined(MAGNUM_TARGET_GLES2)
#ifndef MAGNUM_TARGET_GLES2 static const std::size_t TargetCount = 12+1;
static const std::size_t TargetCount = 8+1;
#else #else
static const std::size_t TargetCount = 2+1; static const std::size_t TargetCount = 2+1;
#endif #endif
#endif
/* Target <-> index mapping */ /* Target <-> index mapping */
static std::size_t indexForTarget(Buffer::Target target); static std::size_t indexForTarget(Buffer::Target target);
@ -72,10 +70,10 @@ struct BufferState {
GLint GLint
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
minMapAlignment, minMapAlignment,
#endif
maxAtomicCounterBindings, maxAtomicCounterBindings,
maxShaderStorageBindings, maxShaderStorageBindings,
shaderStorageOffsetAlignment, shaderStorageOffsetAlignment,
#endif
maxUniformBindings; maxUniformBindings;
#endif #endif
}; };

Loading…
Cancel
Save