Browse Source

GL: expose Buffer::data()/subData() on WebGL 2.0

Since glGetBufferSubData() is only exposed on Emscripten 2.0.17 and up,
both functions are not available on older versions. This is to avoid any
accidental foot guns since it explodes at compile time. The webgl2 CI
will be upgraded to 2.0.17 in a later commit.
gltestlib-symbol-duplication
Pablo Escobar 4 years ago committed by Vladimír Vondruš
parent
commit
3ab4c74a66
  1. 8
      src/Magnum/GL/Buffer.cpp
  2. 22
      src/Magnum/GL/Buffer.h
  3. 2
      src/Magnum/GL/Implementation/BufferState.cpp
  4. 2
      src/Magnum/GL/Implementation/BufferState.h

8
src/Magnum/GL/Buffer.cpp

@ -329,7 +329,7 @@ Int Buffer::size() {
return size;
}
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
Containers::Array<char> Buffer::data() {
return subData(0, size());
}
@ -372,7 +372,7 @@ Buffer& Buffer::flushMappedRange(const GLintptr offset, const GLsizeiptr length)
bool Buffer::unmap() { return (this->*Context::current().state().buffer.unmapImplementation)(); }
#endif
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
Containers::Array<char> Buffer::subData(const GLintptr offset, const GLsizeiptr size) {
Containers::Array<char> data(size);
if(size) (this->*Context::current().state().buffer.getSubDataImplementation)(offset, size, data);
@ -468,11 +468,13 @@ void Buffer::getParameterImplementationDSA(const GLenum value, GLint* const data
}
#endif
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
void Buffer::getSubDataImplementationDefault(const GLintptr offset, const GLsizeiptr size, GLvoid* const data) {
glGetBufferSubData(GLenum(bindSomewhereInternal(_targetHint)), offset, size, data);
}
#endif
#ifndef MAGNUM_TARGET_GLES
void Buffer::getSubDataImplementationDSA(const GLintptr offset, const GLsizeiptr size, GLvoid* const data) {
glGetNamedBufferSubData(_id, offset, size, data);
}

22
src/Magnum/GL/Buffer.h

@ -1089,7 +1089,7 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
*/
Int size();
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
/**
* @brief Buffer data
*
@ -1101,9 +1101,11 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
* eventually @fn_gl{BindBuffer} and @fn_gl{GetBufferParameter}
* with @def_gl{BUFFER_SIZE}, then @fn_gl2_keyword{GetNamedBufferSubData,GetBufferSubData},
* eventually @fn_gl_keyword{GetBufferSubData}
* @requires_gl Buffer data queries are not available in OpenGL ES and
* WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
* in OpenGL ES instead.
* @requires_gl Buffer data queries are not available in OpenGL ES. Use
* @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
* instead.
* @requires_webgl20 Buffer data queries are not available in
* WebGL 1.0. Emscripten 2.0.17 or higher is required in WebGL2.
*/
Containers::Array<char> data();
@ -1119,9 +1121,11 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
* @see @ref size(), @ref data(), @ref setSubData(), @ref setTargetHint(),
* @fn_gl2_keyword{GetNamedBufferSubData,GetBufferSubData},
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{GetBufferSubData}
* @requires_gl Buffer data queries are not available in OpenGL ES and
* WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
* in OpenGL ES instead.
* @requires_gl Buffer data queries are not available in OpenGL ES. Use
* @ref map(), @ref mapRead() or @ref DebugTools::bufferData() in
* OpenGL ES instead.
* @requires_webgl20 Buffer data queries are not available in
* WebGL 1.0. Emscripten 2.0.17 or higher is required in WebGL2.
*/
Containers::Array<char> subData(GLintptr offset, GLsizeiptr size);
#endif
@ -1357,8 +1361,10 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
void MAGNUM_GL_LOCAL getParameterImplementationDSA(GLenum value, GLint* data);
#endif
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
void MAGNUM_GL_LOCAL getSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, GLvoid* data);
#endif
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_GL_LOCAL getSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, GLvoid* data);
#endif

2
src/Magnum/GL/Implementation/BufferState.cpp

@ -126,7 +126,7 @@ BufferState::BufferState(Context& context, Containers::StaticArrayView<Implement
storageImplementation = &Buffer::storageImplementationDefault;
#endif
getParameterImplementation = &Buffer::getParameterImplementationDefault;
#ifndef MAGNUM_TARGET_GLES
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
getSubDataImplementation = &Buffer::getSubDataImplementationDefault;
#endif
dataImplementation = &Buffer::dataImplementationDefault;

2
src/Magnum/GL/Implementation/BufferState.h

@ -59,7 +59,7 @@ struct BufferState {
void(Buffer::*storageImplementation)(Containers::ArrayView<const void>, Buffer::StorageFlags);
#endif
void(Buffer::*getParameterImplementation)(GLenum, GLint*);
#ifndef MAGNUM_TARGET_GLES2
#if !defined(MAGNUM_TARGET_GLES) || (defined(MAGNUM_TARGET_WEBGL) && !defined(MAGNUM_TARGET_GLES2) && __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20017)
void(Buffer::*getSubDataImplementation)(GLintptr, GLsizeiptr, GLvoid*);
#endif
void(Buffer::*dataImplementation)(GLsizeiptr, const GLvoid*, BufferUsage);

Loading…
Cancel
Save