Browse Source

GL: avoid picking up variadic Mesh::addVertexBuffer() for dynamic attribs.

Huh, the SFINAE thing was extremely easy.
mousecapture
Vladimír Vondruš 6 years ago
parent
commit
84ac43d2ce
  1. 4
      doc/changelog.dox
  2. 37
      src/Magnum/GL/Mesh.h

4
doc/changelog.dox

@ -170,6 +170,10 @@ See also:
@subsection changelog-latest-bugfixes Bug fixes
- The variadic versions of @ref GL::Mesh::addVertexBuffer() and
@ref GL::Mesh::addVertexBufferInstanced() were sometimes errorneously
picked up instead of the @ref GL::DynamicAttribute overloads when stride
and offset were of a slightly different type.
- @ref Platform::Sdl2Application::viewportEvent() gets properly fired also
when window size changes programmatically (such as through
@ref Platform::Sdl2Application::setMinWindowSize() "setMinWindowSize()")

37
src/Magnum/GL/Mesh.h

@ -171,7 +171,14 @@ enum class MeshIndexType: GLenum {
*/
MAGNUM_GL_EXPORT MeshIndexType meshIndexType(Magnum::MeshIndexType type);
namespace Implementation { struct MeshState; }
namespace Implementation {
struct MeshState;
template<class...> struct IsDynamicAttribute: std::false_type {};
template<class T> struct IsDynamicAttribute<T, DynamicAttribute>: std::true_type {};
}
/**
@brief Mesh
@ -688,7 +695,12 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
* This is not required anywhere else, but doing so may have
* performance benefits.
*/
template<class ...T> inline Mesh& addVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) {
template<class ...T
#ifndef DOXYGEN_GENERATING_OUTPUT
/* So it doesn't clash with the DynamicAttribute overload */
, class = typename std::enable_if<!Implementation::IsDynamicAttribute<T...>::value>::type
#endif
> Mesh& addVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) {
addVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), 0, attributes...);
return *this;
}
@ -724,7 +736,12 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays}
* in WebGL 1.0.
*/
template<class ...T> inline Mesh& addVertexBufferInstanced(Buffer& buffer, UnsignedInt divisor, GLintptr offset, const T&... attributes) {
template<class ...T
#ifndef DOXYGEN_GENERATING_OUTPUT
/* So it doesn't clash with the DynamicAttribute overload */
, class = typename std::enable_if<!Implementation::IsDynamicAttribute<T...>::value>::type
#endif
> inline Mesh& addVertexBufferInstanced(Buffer& buffer, UnsignedInt divisor, GLintptr offset, const T&... attributes) {
addVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), divisor, attributes...);
return *this;
}
@ -763,7 +780,12 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
* this function takes ownership of @p buffer. See
* @ref GL-Mesh-buffer-ownership for more information.
*/
template<class ...T> inline Mesh& addVertexBuffer(Buffer&& buffer, GLintptr offset, const T&... attributes) {
template<class ...T
#ifndef DOXYGEN_GENERATING_OUTPUT
/* So it doesn't clash with the DynamicAttribute overload */
, class = typename std::enable_if<!Implementation::IsDynamicAttribute<T...>::value>::type
#endif
> inline Mesh& addVertexBuffer(Buffer&& buffer, GLintptr offset, const T&... attributes) {
addVertexBuffer<T...>(buffer, offset, attributes...);
acquireVertexBuffer(std::move(buffer));
return *this;
@ -777,7 +799,12 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
* this function takes ownership of @p buffer. See
* @ref GL-Mesh-buffer-ownership for more information.
*/
template<class ...T> inline Mesh& addVertexBufferInstanced(Buffer&& buffer, UnsignedInt divisor, GLintptr offset, const T&... attributes) {
template<class ...T
#ifndef DOXYGEN_GENERATING_OUTPUT
/* So it doesn't clash with the DynamicAttribute overload */
, class = typename std::enable_if<!Implementation::IsDynamicAttribute<T...>::value>::type
#endif
> inline Mesh& addVertexBufferInstanced(Buffer&& buffer, UnsignedInt divisor, GLintptr offset, const T&... attributes) {
addVertexBufferInstanced<T...>(buffer, divisor, offset, attributes...);
acquireVertexBuffer(std::move(buffer));
return *this;

Loading…
Cancel
Save