diff --git a/src/MeshTools/FullScreenTriangle.cpp b/src/MeshTools/FullScreenTriangle.cpp index b3e560445..c2a810eba 100644 --- a/src/MeshTools/FullScreenTriangle.cpp +++ b/src/MeshTools/FullScreenTriangle.cpp @@ -32,25 +32,28 @@ namespace Magnum { namespace MeshTools { -std::pair fullScreenTriangle() { +std::pair fullScreenTriangle() { Mesh mesh; mesh.setPrimitive(Mesh::Primitive::Triangles) .setVertexCount(3); - Buffer buffer; + Buffer* buffer = nullptr; #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isVersionSupported(Version::GL300)) #else if(!Context::current()->isVersionSupported(Version::GLES300)) #endif { + buffer = new Buffer; constexpr Vector2 triangle[] = { Vector2(-1.0, 1.0), Vector2(-1.0, -3.0), Vector2( 3.0, 1.0) }; - buffer.setData(triangle, Buffer::Usage::StaticDraw); - mesh.addVertexBuffer(buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>()); + buffer->setData(triangle, Buffer::Usage::StaticDraw); + /** @todo Is it possible to attach moveable buffer here to avoid heap + allocation? OTOH this is more effective in most (modern) cases */ + mesh.addVertexBuffer(*buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>()); } return {std::move(buffer), std::move(mesh)}; diff --git a/src/MeshTools/FullScreenTriangle.h b/src/MeshTools/FullScreenTriangle.h index 02c041661..3067719ef 100644 --- a/src/MeshTools/FullScreenTriangle.h +++ b/src/MeshTools/FullScreenTriangle.h @@ -52,8 +52,8 @@ computed from them. The vertex positions are, in order: On OpenGL 2.1 and OpenGL ES 2.0 the vertex positions are passed explicitly as attribute `0`, contained in the buffer. On OpenGL 3.0+ and OpenGL ES 3.0+ the mesh is attribute-less and the vertex positions can be computed using -`gl_VertexID` builtin shader variable, thus the returned vertex buffer is empty -and basically useless. +`gl_VertexID` builtin shader variable, thus `nullptr` is returned instead of +vertex buffer. Computing positions in vertex shader in a portable way might be done like this. For OpenGL 2.1 and OpenGL ES 2.0 you then need to bind the location of `position` @@ -80,7 +80,7 @@ void main() { @attention The implementation needs to check OpenGL version, so it expects active context. */ -std::pair MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle(); +std::pair MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle(); }}