Browse Source

DebugTools: make bufferData()/bufferSubData() default to Buffer::subData()

This avoids requiring any Desktop GL extensions and allows forwarding to
Buffer::subData() also on WebGL 2.0 (in a follow-up commit)
pull/560/head
Pablo Escobar 4 years ago
parent
commit
effebf390e
  1. 12
      src/Magnum/DebugTools/BufferData.h
  2. 10
      src/Magnum/DebugTools/Test/BufferDataGLTest.cpp

12
src/Magnum/DebugTools/BufferData.h

@ -47,7 +47,8 @@ namespace Implementation {
@brief Buffer subdata
Emulates @ref GL::Buffer::subData() call on platforms that don't support it
(such as OpenGL ES) by using @ref GL::Buffer::map().
(such as OpenGL ES) by using @ref GL::Buffer::mapRead(). On desktop GL it's
just an alias to @ref GL::Buffer::subData().
@note This function is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL "TARGET_GL" enabled (done by default). See
@ -58,16 +59,23 @@ Emulates @ref GL::Buffer::subData() call on platforms that don't support it
@requires_gles Buffer mapping is not available in WebGL.
*/
template<class T> Containers::Array<T> inline bufferSubData(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) {
#ifndef MAGNUM_TARGET_GLES
Containers::Array<char> data = buffer.subData(offset, size*sizeof(T));
CORRADE_INTERNAL_ASSERT(!data.deleter());
return Containers::Array<T>{reinterpret_cast<T*>(data.release()), std::size_t(size)};
#else
Containers::Array<T> data{std::size_t(size)};
if(size) Implementation::bufferSubData(buffer, offset, size*sizeof(T), data);
return data;
#endif
}
/**
@brief Buffer data
Emulates @ref GL::Buffer::data() call on platforms that don't support it (such
as OpenGL ES) by using @ref GL::Buffer::map().
as OpenGL ES) by using @ref GL::Buffer::mapRead(). On desktop GL it's just an
alias to @ref GL::Buffer::data().
@note This function is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL "TARGET_GL" enabled (done by default). See

10
src/Magnum/DebugTools/Test/BufferDataGLTest.cpp

@ -47,10 +47,7 @@ BufferDataGLTest::BufferDataGLTest() {
constexpr Int Data[] = {2, 7, 5, 13, 25};
void BufferDataGLTest::data() {
#ifndef MAGNUM_TARGET_GLES
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::map_buffer_range>())
CORRADE_SKIP(GL::Extensions::ARB::map_buffer_range::string() << "is not supported.");
#elif defined(MAGNUM_TARGET_GLES2)
#ifdef MAGNUM_TARGET_GLES2
if(!GL::Context::current().isExtensionSupported<GL::Extensions::EXT::map_buffer_range>())
CORRADE_SKIP(GL::Extensions::EXT::map_buffer_range::string() << "is not supported.");
#endif
@ -64,10 +61,7 @@ void BufferDataGLTest::data() {
}
void BufferDataGLTest::subData() {
#ifndef MAGNUM_TARGET_GLES
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::map_buffer_range>())
CORRADE_SKIP(GL::Extensions::ARB::map_buffer_range::string() << "is not supported.");
#elif defined(MAGNUM_TARGET_GLES2)
#ifdef MAGNUM_TARGET_GLES2
if(!GL::Context::current().isExtensionSupported<GL::Extensions::EXT::map_buffer_range>())
CORRADE_SKIP(GL::Extensions::EXT::map_buffer_range::string() << "is not supported.");
#endif

Loading…
Cancel
Save