Browse Source

Updated OpenGL ES support in Buffer and related classes.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
bb2fe188db
  1. 14
      src/Buffer.cpp
  2. 60
      src/Buffer.h
  3. 2
      src/BufferedImage.h
  4. 4
      src/BufferedTexture.cpp
  5. 8
      src/BufferedTexture.h

14
src/Buffer.cpp

@ -24,11 +24,14 @@
namespace Magnum { namespace Magnum {
#ifndef MAGNUM_TARGET_GLES2
Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault; Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault;
#endif
Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault;
Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault;
void Buffer::initializeContextBasedFunctionality(Context* context) { void Buffer::initializeContextBasedFunctionality(Context* context) {
#ifndef MAGNUM_TARGET_GLES
if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) { if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) {
Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features";
@ -36,6 +39,9 @@ void Buffer::initializeContextBasedFunctionality(Context* context) {
setDataImplementation = &Buffer::setDataImplementationDSA; setDataImplementation = &Buffer::setDataImplementationDSA;
setSubDataImplementation = &Buffer::setSubDataImplementationDSA; setSubDataImplementation = &Buffer::setSubDataImplementationDSA;
} }
#else
static_cast<void>(context);
#endif
} }
Buffer::~Buffer() { Buffer::~Buffer() {
@ -76,28 +82,36 @@ Buffer::Target Buffer::bindInternal(Target hint) {
return hint; return hint;
} }
#ifndef MAGNUM_TARGET_GLES2
void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
glCopyBufferSubData(static_cast<GLenum>(read->bindInternal(Target::CopyRead)), static_cast<GLenum>(write->bindInternal(Target::CopyWrite)), readOffset, writeOffset, size); glCopyBufferSubData(static_cast<GLenum>(read->bindInternal(Target::CopyRead)), static_cast<GLenum>(write->bindInternal(Target::CopyWrite)), readOffset, writeOffset, size);
} }
#ifndef MAGNUM_TARGET_GLES
void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size); glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size);
} }
#endif
#endif
void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) {
glBufferData(static_cast<GLenum>(bindInternal(_targetHint)), size, data, static_cast<GLenum>(usage)); glBufferData(static_cast<GLenum>(bindInternal(_targetHint)), size, data, static_cast<GLenum>(usage));
} }
#ifndef MAGNUM_TARGET_GLES
void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) {
glNamedBufferDataEXT(_id, size, data, static_cast<GLenum>(usage)); glNamedBufferDataEXT(_id, size, data, static_cast<GLenum>(usage));
} }
#endif
void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) {
glBufferSubData(static_cast<GLenum>(bindInternal(_targetHint)), offset, size, data); glBufferSubData(static_cast<GLenum>(bindInternal(_targetHint)), offset, size, data);
} }
#ifndef MAGNUM_TARGET_GLES
void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) {
glNamedBufferSubDataEXT(_id, offset, size, data); glNamedBufferSubDataEXT(_id, offset, size, data);
} }
#endif
} }

60
src/Buffer.h

@ -100,7 +100,7 @@ class MAGNUM_EXPORT Buffer {
/** /**
* 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 * @requires_gl Atomic counters are not available in OpenGL ES.
*/ */
AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
#endif #endif
@ -108,14 +108,16 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Source for copies. See copy(). * Source for copies. See copy().
* @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gl31 Extension @extension{ARB,copy_buffer}
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Buffer copying is not available in OpenGL ES
* 2.0.
*/ */
CopyRead = GL_COPY_READ_BUFFER, CopyRead = GL_COPY_READ_BUFFER,
/** /**
* Target for copies. See copy(). * Target for copies. See copy().
* @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gl31 Extension @extension{ARB,copy_buffer}
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Buffer copying is not available in OpenGL ES
* 2.0.
*/ */
CopyWrite = GL_COPY_WRITE_BUFFER, CopyWrite = GL_COPY_WRITE_BUFFER,
@ -123,14 +125,14 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Indirect compute dispatch commands. * Indirect compute dispatch commands.
* @requires_gl43 Extension @extension{ARB,compute_shader} * @requires_gl43 Extension @extension{ARB,compute_shader}
* @requires_gl * @requires_gl Compute shaders are not available in OpenGL ES.
*/ */
DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER,
/** /**
* Used for supplying arguments for instanced drawing. * Used for supplying arguments for indirect drawing.
* @requires_gl
* @requires_gl40 Extension @extension{ARB,draw_indirect} * @requires_gl40 Extension @extension{ARB,draw_indirect}
* @requires_gl Indirect drawing not available in OpenGL ES.
*/ */
DrawIndirect = GL_DRAW_INDIRECT_BUFFER, DrawIndirect = GL_DRAW_INDIRECT_BUFFER,
#endif #endif
@ -140,13 +142,15 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Target for pixel pack operations. * Target for pixel pack operations.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Pixel buffer objects are not available in
* OpenGL ES 2.0.
*/ */
PixelPack = GL_PIXEL_PACK_BUFFER, PixelPack = GL_PIXEL_PACK_BUFFER,
/** /**
* Source for texture update operations. * Source for texture update operations.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Pixel buffer objects are not available in
* OpenGL ES 2.0.
*/ */
PixelUnpack = GL_PIXEL_UNPACK_BUFFER, PixelUnpack = GL_PIXEL_UNPACK_BUFFER,
@ -154,14 +158,14 @@ class MAGNUM_EXPORT Buffer {
/** /**
* 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 * @requires_gl Shader storage is not available in OpenGL ES.
*/ */
ShaderStorage = GL_SHADER_STORAGE_BUFFER, ShaderStorage = GL_SHADER_STORAGE_BUFFER,
/** /**
* Source for texel fetches. See BufferedTexture. * Source for texel fetches. See BufferedTexture.
* @requires_gl
* @requires_gl31 Extension @extension{ARB,texture_buffer_object} * @requires_gl31 Extension @extension{ARB,texture_buffer_object}
* @requires_gl Texture buffers are not available in OpenGL ES.
*/ */
Texture = GL_TEXTURE_BUFFER, Texture = GL_TEXTURE_BUFFER,
#endif #endif
@ -169,14 +173,16 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Target for transform feedback. * Target for transform feedback.
* @requires_gl30 Extension @extension{EXT,transform_feedback} * @requires_gl30 Extension @extension{EXT,transform_feedback}
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Transform feedback is not available in OpenGL
* ES 2.0.
*/ */
TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER,
/** /**
* Used for storing uniforms. * Used for storing uniforms.
* @requires_gl31 Extension @extension{ARB,uniform_buffer_object} * @requires_gl31 Extension @extension{ARB,uniform_buffer_object}
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Uniform buffers are not available in OpenGL ES
* 2.0.
*/ */
Uniform = GL_UNIFORM_BUFFER Uniform = GL_UNIFORM_BUFFER
}; };
@ -195,14 +201,16 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Set once as output from an OpenGL command and used infequently * Set once as output from an OpenGL command and used infequently
* for drawing. * for drawing.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StreamDraw"
* is available in OpenGL ES 2.0.
*/ */
StreamRead = GL_STREAM_READ, StreamRead = GL_STREAM_READ,
/** /**
* Set once as output from an OpenGL command and used infrequently * Set once as output from an OpenGL command and used infrequently
* for drawing or copying to other buffers. * for drawing or copying to other buffers.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StreamDraw"
* is available in OpenGL ES 2.0.
*/ */
StreamCopy = GL_STREAM_COPY, StreamCopy = GL_STREAM_COPY,
@ -214,14 +222,16 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Set once as output from an OpenGL command and queried many * Set once as output from an OpenGL command and queried many
* times by the application. * times by the application.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StaticDraw"
* is available in OpenGL ES 2.0.
*/ */
StaticRead = GL_STATIC_READ, StaticRead = GL_STATIC_READ,
/** /**
* Set once as output from an OpenGL command and used frequently * Set once as output from an OpenGL command and used frequently
* for drawing or copying to other buffers. * for drawing or copying to other buffers.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StaticDraw"
* is available in OpenGL ES 2.0.
*/ */
StaticCopy = GL_STATIC_COPY, StaticCopy = GL_STATIC_COPY,
@ -234,14 +244,16 @@ class MAGNUM_EXPORT Buffer {
/** /**
* Updated frequently as output from OpenGL command and queried * Updated frequently as output from OpenGL command and queried
* many times from the application. * many times from the application.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicDraw"
* is available in OpenGL ES 2.0.
*/ */
DynamicRead = GL_DYNAMIC_READ, DynamicRead = GL_DYNAMIC_READ,
/** /**
* Updated frequently as output from OpenGL command and used * Updated frequently as output from OpenGL command and used
* frequently for drawing or copying to other images. * frequently for drawing or copying to other images.
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicCopy"
* is available in OpenGL ES 2.0.
*/ */
DynamicCopy = GL_DYNAMIC_COPY DynamicCopy = GL_DYNAMIC_COPY
}; };
@ -254,6 +266,7 @@ class MAGNUM_EXPORT Buffer {
*/ */
inline static void unbind(Target target) { bind(target, 0); } inline static void unbind(Target target) { bind(target, 0); }
#ifndef MAGNUM_TARGET_GLES2
/** /**
* @brief Copy one buffer to another * @brief Copy one buffer to another
* @param read %Buffer from which to read * @param read %Buffer from which to read
@ -267,13 +280,14 @@ class MAGNUM_EXPORT Buffer {
* `Target::CopyRead` and `Target::CopyWrite` before the copy is * `Target::CopyRead` and `Target::CopyWrite` before the copy is
* performed. * performed.
* @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gl31 Extension @extension{ARB,copy_buffer}
* @requires_gles30 (no extension providing this functionality) * @requires_gles30 Buffer copying is not available in OpenGL ES 2.0.
* @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or
* @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} * @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access}
*/ */
inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
copyImplementation(read, write, readOffset, writeOffset, size); copyImplementation(read, write, readOffset, writeOffset, size);
} }
#endif
/** /**
* @brief Constructor * @brief Constructor
@ -419,19 +433,27 @@ class MAGNUM_EXPORT Buffer {
static void bind(Target hint, GLuint id); static void bind(Target hint, GLuint id);
Target MAGNUM_LOCAL bindInternal(Target hint); Target MAGNUM_LOCAL bindInternal(Target hint);
#ifndef MAGNUM_TARGET_GLES2
typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr); typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr);
static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
#endif
static CopyImplementation copyImplementation; static CopyImplementation copyImplementation;
#endif
typedef void(Buffer::*SetDataImplementation)(GLsizeiptr, const GLvoid*, Usage); typedef void(Buffer::*SetDataImplementation)(GLsizeiptr, const GLvoid*, Usage);
void MAGNUM_LOCAL setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Usage usage); void MAGNUM_LOCAL setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Usage usage);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Usage usage); void MAGNUM_LOCAL setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Usage usage);
#endif
static SetDataImplementation setDataImplementation; static SetDataImplementation setDataImplementation;
typedef void(Buffer::*SetSubDataImplementation)(GLintptr, GLsizeiptr, const GLvoid*); typedef void(Buffer::*SetSubDataImplementation)(GLintptr, GLsizeiptr, const GLvoid*);
void MAGNUM_LOCAL setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data); void MAGNUM_LOCAL setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data); void MAGNUM_LOCAL setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data);
#endif
static SetSubDataImplementation setSubDataImplementation; static SetSubDataImplementation setSubDataImplementation;
GLuint _id; GLuint _id;

2
src/BufferedImage.h

@ -34,7 +34,7 @@ Class for storing image data in GPU memory. Can be replaced with Image, which
stores image data in client memory, ImageWrapper, or for example with stores image data in client memory, ImageWrapper, or for example with
Trade::ImageData. Trade::ImageData.
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer
@requires_gles30 (no extension providing this functionality) @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0.
*/ */
template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public AbstractImage { template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public AbstractImage {
public: public:

4
src/BufferedTexture.cpp

@ -15,6 +15,7 @@
#include "BufferedTexture.h" #include "BufferedTexture.h"
#ifndef MAGNUM_TARGET_GLES
#include "Buffer.h" #include "Buffer.h"
#include "Context.h" #include "Context.h"
#include "Extensions.h" #include "Extensions.h"
@ -40,7 +41,6 @@ void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat
glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id()); glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id());
} }
#ifndef MAGNUM_TARGET_GLES
BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) { BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) {
#define internalFormatSwitch(c) switch(type) { \ #define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \ case ComponentType::UnsignedByte: \
@ -72,6 +72,6 @@ BufferedTexture::InternalFormat::InternalFormat(Components components, Component
internalFormatSwitch(RGBA) internalFormatSwitch(RGBA)
#undef internalFormatSwitch #undef internalFormatSwitch
} }
#endif
} }
#endif

8
src/BufferedTexture.h

@ -15,18 +15,20 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#ifndef MAGNUM_TARGET_GLES
/** @file /** @file
* @brief Class Magnum::BufferedTexture * @brief Class Magnum::BufferedTexture
*/ */
#endif
#include "AbstractTexture.h" #include "AbstractTexture.h"
#ifndef MAGNUM_TARGET_GLES
namespace Magnum { namespace Magnum {
class Buffer; class Buffer;
class Context; class Context;
#ifndef MAGNUM_TARGET_GLES
/** /**
@brief Buffered texture @brief Buffered texture
@ -46,8 +48,8 @@ uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and
"relevant section in AbstractTexture documentation" and respective function "relevant section in AbstractTexture documentation" and respective function
documentation for more information. documentation for more information.
@requires_gl
@requires_gl31 Extension @extension{ARB,texture_buffer_object} @requires_gl31 Extension @extension{ARB,texture_buffer_object}
@requires_gl Texture buffers are not available in OpenGL ES.
*/ */
class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { class MAGNUM_EXPORT BufferedTexture: private AbstractTexture {
friend class Context; friend class Context;
@ -169,8 +171,8 @@ inline BufferedTexture::InternalFormat operator|(BufferedTexture::Components com
inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) { inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) {
return BufferedTexture::InternalFormat(components, type); return BufferedTexture::InternalFormat(components, type);
} }
#endif
} }
#endif
#endif #endif

Loading…
Cancel
Save