From bc8368fcf28488019963a43232964b7b5b53a7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Jan 2014 00:05:24 +0100 Subject: [PATCH] MeshTools: don't return naked pointer from fullScreenTriangle(). Also make it possible to specify version for which we want it. --- src/MeshTools/FullScreenTriangle.cpp | 14 +++++++++----- src/MeshTools/FullScreenTriangle.h | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/MeshTools/FullScreenTriangle.cpp b/src/MeshTools/FullScreenTriangle.cpp index 14ba470d1..ca8e19a77 100644 --- a/src/MeshTools/FullScreenTriangle.cpp +++ b/src/MeshTools/FullScreenTriangle.cpp @@ -33,19 +33,19 @@ namespace Magnum { namespace MeshTools { -std::pair fullScreenTriangle() { +std::pair, Mesh> fullScreenTriangle(Version version) { Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) .setVertexCount(3); - Buffer* buffer = nullptr; + std::unique_ptr buffer; #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isVersionSupported(Version::GL300)) + if(version < Version::GL300) #else - if(!Context::current()->isVersionSupported(Version::GLES300)) + if(version < Version::GLES300) #endif { - buffer = new Buffer; + buffer.reset(new Buffer); constexpr Vector2 triangle[] = { Vector2(-1.0, 1.0), Vector2(-1.0, -3.0), @@ -60,4 +60,8 @@ std::pair fullScreenTriangle() { return {std::move(buffer), std::move(mesh)}; } +std::pair, Mesh> fullScreenTriangle() { + return fullScreenTriangle(Context::current()->version()); +} + }} diff --git a/src/MeshTools/FullScreenTriangle.h b/src/MeshTools/FullScreenTriangle.h index 3067719ef..70290b48c 100644 --- a/src/MeshTools/FullScreenTriangle.h +++ b/src/MeshTools/FullScreenTriangle.h @@ -28,6 +28,7 @@ * @brief Function @ref Magnum::MeshTools::fullScreenTriangle() */ +#include #include #include "Magnum.h" @@ -49,11 +50,11 @@ computed from them. The vertex positions are, in order: \begin{pmatrix} 3 \\ 1 \end{pmatrix} @f] -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 `nullptr` is returned instead of -vertex buffer. +Based on @p version parameter, 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 +`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` @@ -76,11 +77,15 @@ void main() { #endif } @endcode +*/ +std::pair, Mesh> MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle(Version version); + +/** +@overload -@attention The implementation needs to check OpenGL version, so it expects - active context. +This function implicitly uses current context version. */ -std::pair MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle(); +std::pair, Mesh> MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle(); }}