From effebf390e453a3c09ca8464e598561a6daf295c Mon Sep 17 00:00:00 2001 From: Pablo Escobar Date: Mon, 2 May 2022 18:52:37 +0200 Subject: [PATCH] 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) --- src/Magnum/DebugTools/BufferData.h | 12 ++++++++++-- src/Magnum/DebugTools/Test/BufferDataGLTest.cpp | 10 ++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Magnum/DebugTools/BufferData.h b/src/Magnum/DebugTools/BufferData.h index ada62a5ed..dda64c3fd 100644 --- a/src/Magnum/DebugTools/BufferData.h +++ b/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 Containers::Array inline bufferSubData(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) { + #ifndef MAGNUM_TARGET_GLES + Containers::Array data = buffer.subData(offset, size*sizeof(T)); + CORRADE_INTERNAL_ASSERT(!data.deleter()); + return Containers::Array{reinterpret_cast(data.release()), std::size_t(size)}; + #else Containers::Array 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 diff --git a/src/Magnum/DebugTools/Test/BufferDataGLTest.cpp b/src/Magnum/DebugTools/Test/BufferDataGLTest.cpp index 6b2871e59..c1c31f51f 100644 --- a/src/Magnum/DebugTools/Test/BufferDataGLTest.cpp +++ b/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()) - 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()) 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()) - 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()) CORRADE_SKIP(GL::Extensions::EXT::map_buffer_range::string() << "is not supported."); #endif