Browse Source

MeshTools: don't return naked pointer from fullScreenTriangle().

Also make it possible to specify version for which we want it.
pull/51/head
Vladimír Vondruš 13 years ago
parent
commit
bc8368fcf2
  1. 14
      src/MeshTools/FullScreenTriangle.cpp
  2. 21
      src/MeshTools/FullScreenTriangle.h

14
src/MeshTools/FullScreenTriangle.cpp

@ -33,19 +33,19 @@
namespace Magnum { namespace MeshTools {
std::pair<Buffer*, Mesh> fullScreenTriangle() {
std::pair<std::unique_ptr<Buffer>, Mesh> fullScreenTriangle(Version version) {
Mesh mesh;
mesh.setPrimitive(MeshPrimitive::Triangles)
.setVertexCount(3);
Buffer* buffer = nullptr;
std::unique_ptr<Buffer> 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<Buffer*, Mesh> fullScreenTriangle() {
return {std::move(buffer), std::move(mesh)};
}
std::pair<std::unique_ptr<Buffer>, Mesh> fullScreenTriangle() {
return fullScreenTriangle(Context::current()->version());
}
}}

21
src/MeshTools/FullScreenTriangle.h

@ -28,6 +28,7 @@
* @brief Function @ref Magnum::MeshTools::fullScreenTriangle()
*/
#include <memory>
#include <utility>
#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<std::unique_ptr<Buffer>, 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<Buffer*, Mesh> MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle();
std::pair<std::unique_ptr<Buffer>, Mesh> MAGNUM_MESHTOOLS_EXPORT fullScreenTriangle();
}}

Loading…
Cancel
Save