From e1c22b9ca20ad214a789c04645cffc846a304db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Sep 2012 18:04:02 +0200 Subject: [PATCH 001/256] Don't do anything OpenGL-related inside Camera itself. * The user might not want to call Framebuffer::clear(), because there could be something already rendered with another camera. * The user might not want to call Framebuffer::setViewport(), because there could be different framebuffer attached. --- src/SceneGraph/Camera.cpp | 4 ---- src/SceneGraph/Camera.h | 9 ++++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index aba491f2a..4d6d3f305 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -14,7 +14,6 @@ */ #include "Camera.h" -#include "Framebuffer.h" #include "Scene.h" using namespace std; @@ -49,7 +48,6 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons template Camera::Camera(ObjectType* parent): ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} template void Camera::setViewport(const Math::Vector2& size) { - Framebuffer::setViewport({0, 0}, size); _viewport = size; fixAspectRatio(); @@ -65,8 +63,6 @@ templatescene(); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); - Framebuffer::clear(); - /* Recursively draw child objects */ drawChildren(s, cameraMatrix()); } diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 2c29bd7f8..df3f82e61 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -112,17 +112,16 @@ template& size); /** * @brief Draw the scene * - * Calls Framebuffer::clear() and draws the scene using drawChildren(). + * Draws the scene using drawChildren(). */ virtual void draw(); From 268f6782217e55d6c3ffe3b4970876e88fa2dc42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Sep 2012 18:06:22 +0200 Subject: [PATCH 002/256] SceneGraph: Camera aspect ratio was not fixed after changing policy. Also added test for projectionSize(), which couldn't be added before because of gl*() calls. --- src/SceneGraph/Camera.cpp | 6 +++++- src/SceneGraph/Camera.h | 3 +-- src/SceneGraph/Test/CameraTest.cpp | 15 ++++++++++++++- src/SceneGraph/Test/CameraTest.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 4d6d3f305..13484dfdc 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -47,8 +47,12 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons template Camera::Camera(ObjectType* parent): ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template void Camera::setViewport(const Math::Vector2& size) { +template void Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { + _aspectRatioPolicy = policy; + fixAspectRatio(); +} +template void Camera::setViewport(const Math::Vector2& size) { _viewport = size; fixAspectRatio(); } diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index df3f82e61..b3104292c 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -73,7 +73,7 @@ template { void projection2D(); void orthographic(); void perspective(); + void projectionSizeViewport(); }; }}} From aeda5009df68653d73a206586b939ebc4101c75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Sep 2012 19:07:59 +0200 Subject: [PATCH 003/256] Inlined simple function. --- src/Framebuffer.cpp | 4 ---- src/Framebuffer.h | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index d0f1d4cd2..062bd51f2 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -32,10 +32,6 @@ void Framebuffer::setFeature(Feature feature, bool enabled) { enabled ? clearMask |= clearMaskChange : clearMask &= ~clearMaskChange; } -void Framebuffer::setViewport(const Math::Vector2& position, const Math::Vector2& size) { - glViewport(position.x(), position.y(), size.x(), size.y()); -} - #ifndef MAGNUM_TARGET_GLES void Framebuffer::mapDefaultForDraw(std::initializer_list attachments) { GLenum* _attachments = new GLenum[attachments.size()]; diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 4282e09ea..f66b93661 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -94,7 +94,9 @@ class MAGNUM_EXPORT Framebuffer { * Call when window size changes. * @see Camera::setViewport() */ - static void setViewport(const Math::Vector2& position, const Math::Vector2& size); + inline static void setViewport(const Math::Vector2& position, const Math::Vector2& size) { + glViewport(position.x(), position.y(), size.x(), size.y()); + } /*@}*/ From 685be07a8f8707f83d6c7bf238c993ff0ec46d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Sep 2012 19:08:17 +0200 Subject: [PATCH 004/256] Removed parameter-less clear() from Framebuffer. Automatic behavior could cause harm, as the stencil/depth test could be temporarily disabled for some parts of the scene (but enabled for the rest), causing clear() to leave stencil/depth buffer untouched. --- src/Framebuffer.cpp | 15 --------------- src/Framebuffer.h | 19 ++++--------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 062bd51f2..e6117caec 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -17,21 +17,6 @@ namespace Magnum { -Framebuffer::ClearMask Framebuffer::clearMask = Framebuffer::Clear::Color; - -void Framebuffer::setFeature(Feature feature, bool enabled) { - /* Enable or disable the feature */ - enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); - - /* Update clear mask, if needed */ - ClearMask clearMaskChange; - if(feature == Feature::DepthTest) clearMaskChange = Clear::Depth; - else if(feature == Feature::StencilTest) clearMaskChange = Clear::Stencil; - else return; - - enabled ? clearMask |= clearMaskChange : clearMask &= ~clearMaskChange; -} - #ifndef MAGNUM_TARGET_GLES void Framebuffer::mapDefaultForDraw(std::initializer_list attachments) { GLenum* _attachments = new GLenum[attachments.size()]; diff --git a/src/Framebuffer.h b/src/Framebuffer.h index f66b93661..002cb6872 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -86,7 +86,9 @@ class MAGNUM_EXPORT Framebuffer { }; /** @brief Set feature */ - static void setFeature(Feature feature, bool enabled); + inline static void setFeature(Feature feature, bool enabled) { + enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); + } /** * @brief Set viewport size @@ -115,21 +117,10 @@ class MAGNUM_EXPORT Framebuffer { typedef Corrade::Containers::EnumSet ClearMask; /**< @brief Mask for clearing */ - /** - * @brief Clear framebuffer - * - * Clears color buffer, depth and stencil buffer in currently active - * framebuffer. If depth or stencil test is not enabled, it doesn't - * clear these buffers. - * - * @see setFeature(), clear(ClearMask) - */ - inline static void clear() { glClear(static_cast(clearMask)); } - /** * @brief Clear specified buffers in framebuffer * - * @see clear() + * @see clear(), setClearColor(), setClearDepth(), setClearStencil() * @todo Clearing only given draw buffer */ inline static void clear(ClearMask mask) { glClear(static_cast(mask)); } @@ -1108,8 +1099,6 @@ class MAGNUM_EXPORT Framebuffer { /*@}*/ private: - static ClearMask clearMask; - GLuint framebuffer; }; From b9ed4159e0c304122c1b2f87e70d118670acfa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 2 Sep 2012 19:12:40 +0200 Subject: [PATCH 005/256] Framebuffer: don't allow invalid bits to be present in *Mask enum sets. Now ~Framebuffer::Clear::Color is equal to Framebuffer::Clear::Depth|Framebuffer::Clear::Stencil, which wasn't the case before, the same for BlitMask. --- src/Framebuffer.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 002cb6872..0ee1750bf 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -115,7 +115,9 @@ class MAGNUM_EXPORT Framebuffer { Stencil = GL_STENCIL_BUFFER_BIT /**< Stencil value */ }; - typedef Corrade::Containers::EnumSet ClearMask; /**< @brief Mask for clearing */ + /** @brief Mask for clearing */ + typedef Corrade::Containers::EnumSet ClearMask; /** * @brief Clear specified buffers in framebuffer @@ -1023,7 +1025,8 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - typedef Corrade::Containers::EnumSet BlitMask; + typedef Corrade::Containers::EnumSet BlitMask; /** * @brief Copy block of pixels from read to draw framebuffer From 6882cd9447be0c2928bd731e8d0fe7bb2c6e5f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Sep 2012 00:01:23 +0200 Subject: [PATCH 006/256] Fixed example (strongly typed enums) in AbstractShaderProgram. --- src/AbstractShaderProgram.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index f50d20040..bdcca5fbc 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -52,8 +52,8 @@ static const GLint SpecularTextureLayer = 1; @code MyShader() { // Load shaders from file and attach them to the program - attachShader(Shader::fromFile(Shader::Vertex, "PhongShader.vert")); - attachShader(Shader::fromFile(Shader::Fragment, "PhongShader.frag")); + attachShader(Shader::fromFile(Shader::Type::Vertex, "PhongShader.vert")); + attachShader(Shader::fromFile(Shader::Type::Fragment, "PhongShader.frag")); // Link link(); From 30032a5971d77a02da0b0160f78aa85adf19ad08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Sep 2012 00:03:57 +0200 Subject: [PATCH 007/256] Don't confuse vertices and vertex positions. Mesh consists of vertices, each vertex has position, texture coordinate, color, normal, etc. --- src/AbstractShaderProgram.h | 6 +-- src/MeshTools/GenerateFlatNormals.cpp | 6 +-- src/MeshTools/GenerateFlatNormals.h | 8 ++-- src/MeshTools/Interleave.h | 4 +- src/MeshTools/Test/CleanTest.cpp | 6 +-- .../Test/SubdivideCleanBenchmark.cpp | 42 +++++++++---------- src/MeshTools/Test/SubdivideTest.cpp | 16 +++---- src/Primitives/Capsule.cpp | 6 +-- src/Primitives/Cube.cpp | 2 +- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Icosphere.h | 2 +- src/Primitives/Test/CapsuleTest.cpp | 4 +- src/Primitives/Test/UVSphereTest.cpp | 4 +- src/Shaders/PhongShader.h | 2 +- src/Trade/MeshData.cpp | 2 +- src/Trade/MeshData.h | 22 +++++----- 16 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index bdcca5fbc..e9fc0d8ab 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -35,7 +35,7 @@ functions and properties: - %Attribute location typedefs defining locations and types for attribute binding with Mesh::bindAttribute(), for example: @code -typedef Attribute<0, Vector4> Vertex; +typedef Attribute<0, Vector4> Position; typedef Attribute<1, Vector3> Normal; typedef Attribute<2, Vector2> TextureCoords; @endcode @@ -82,7 +82,7 @@ shader code, e.g.: @code #version 330 // or #extension GL_ARB_explicit_attrib_location: enable -layout(location = 0) in vec4 vertex; +layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 textureCoords; @endcode @@ -110,7 +110,7 @@ attaching the shaders and linking the program: @code // Shaders attached... -bindAttributeLocation(Vertex::Location, "vertex"); +bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Normal::Location, "normal"); bindAttributeLocation(TextureCoords::Location, "textureCoords"); diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index e52e4379e..1e70162e7 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const std::vector< unsigned int >& indices, const vector< Vector4 >& vertices) { +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ @@ -30,8 +30,8 @@ tuple, vector> generateFlatNormals(const std::vect vector normals; normals.reserve(indices.size()/3); for(size_t i = 0; i != indices.size(); i += 3) { - Vector3 normal = Vector3::cross(vertices[indices[i+2]].xyz()-vertices[indices[i+1]].xyz(), - vertices[indices[i]].xyz()-vertices[indices[i+1]].xyz()).normalized(); + Vector3 normal = Vector3::cross(positions[indices[i+2]].xyz()-positions[indices[i+1]].xyz(), + positions[indices[i]].xyz()-positions[indices[i+1]].xyz()).normalized(); /* Use the same normal for all three vertices of the face */ normalIndices.push_back(normals.size()); diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index a5dfcbb9b..20a94b494 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -29,18 +29,18 @@ namespace Magnum { namespace MeshTools { /** @brief Generate flat normals @param indices Array of triangle face indexes -@param vertices Vertex array +@param positions Array of vertex positions @return Normal indices and vectors For each face generates one normal vector, removes duplicates before returning. Example usage: @code std::vector vertexIndices; -std::vector vertices; +std::vector positions; std::vector normalIndices; std::vector normals; -std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, vertices); +std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions); @endcode You can then use combineIndexedArrays() to combine normal and vertex array to use the same indices. @@ -48,7 +48,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& vertices); +std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 3c7408e52..64198e6fe 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -108,12 +108,12 @@ so data for each attribute are in continuous place in memory. Size of the data buffer can be computed from attribute count and stride, as shown below. Example usage: @code -std::vector vertices; +std::vector positions; std::vector textureCoordinates; size_t attributeCount; size_t stride; char* data; -std::tie(attributeCount, stride, data) = MeshTools::interleave(vertices, textureCoordinates); +std::tie(attributeCount, stride, data) = MeshTools::interleave(positions, textureCoordinates); size_t dataSize = attributeCount*stride; // ... delete[] data; diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index e8978e3c9..55f8b1bfc 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -28,12 +28,12 @@ CleanTest::CleanTest() { } void CleanTest::cleanMesh() { - vector vertices{1, 2, 1, 4}; + vector positions{1, 2, 1, 4}; vector indices{0, 1, 2, 1, 2, 3}; - MeshTools::clean(indices, vertices); + MeshTools::clean(indices, positions); /* Verify cleanup */ - CORRADE_VERIFY(vertices == (vector{1, 2, 4})); + CORRADE_VERIFY(positions == (vector{1, 2, 4})); CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); } diff --git a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp b/src/MeshTools/Test/SubdivideCleanBenchmark.cpp index 6d6ec7307..fd56ef292 100644 --- a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp +++ b/src/MeshTools/Test/SubdivideCleanBenchmark.cpp @@ -30,11 +30,11 @@ void SubdivideCleanBenchmark::subdivide() { Primitives::Icosphere<0> icosphere; /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); } } @@ -43,13 +43,13 @@ void SubdivideCleanBenchmark::subdivideAndCleanMeshAfter() { Primitives::Icosphere<0> icosphere; /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); } } @@ -58,16 +58,16 @@ void SubdivideCleanBenchmark::subdivideAndCleanMeshBetween() { Primitives::Icosphere<0> icosphere; /* Subdivide 5 times */ - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); - MeshTools::subdivide(*icosphere.indices(), *icosphere.vertices(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.vertices(0)); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); + MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); } } diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 611155a60..2e7153ef9 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -35,26 +35,26 @@ void SubdivideTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector vertices; + vector positions; vector indices{0, 1}; - MeshTools::subdivide(indices, vertices, interpolator); + MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); } void SubdivideTest::subdivide() { - vector vertices{0, 2, 6, 8}; + vector positions{0, 2, 6, 8}; vector indices{0, 1, 2, 1, 2, 3}; - MeshTools::subdivide(indices, vertices, interpolator); + MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); - CORRADE_VERIFY(vertices == (vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); + CORRADE_VERIFY(positions == (vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); CORRADE_COMPARE(indices, (vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); - MeshTools::clean(indices, vertices); + MeshTools::clean(indices, positions); - /* Vertices 0, 1, 2, 3, 4, 5, 6, 7, 8 */ - CORRADE_COMPARE(vertices.size(), 9); + /* Positions 0, 1, 2, 3, 4, 5, 6, 7, 8 */ + CORRADE_COMPARE(positions.size(), 9); } }}} diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 5df5b13f7..ccf2d2a9f 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -45,7 +45,7 @@ Capsule::Capsule(unsigned int rings, unsigned int segments, GLfloat length, Text } void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { - vertices(0)->push_back({0.0f, y, 0.0f}); + positions(0)->push_back({0.0f, y, 0.0f}); normals(0)->push_back({0.0f, normalY, 0.0f}); if(textureCoords == TextureCoords::Generate) @@ -62,7 +62,7 @@ void Capsule::vertexRings(unsigned int count, GLfloat centerY, GLfloat startRing for(unsigned int j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; - vertices(0)->push_back({x*sin(segmentAngle), centerY+y, z*cos(segmentAngle)}); + positions(0)->push_back({x*sin(segmentAngle), centerY+y, z*cos(segmentAngle)}); normals(0)->push_back({x*sin(segmentAngle), y, z*cos(segmentAngle)}); if(textureCoords == TextureCoords::Generate) @@ -71,7 +71,7 @@ void Capsule::vertexRings(unsigned int count, GLfloat centerY, GLfloat startRing /* Duplicate first segment in the ring for additional vertex for texture coordinate */ if(textureCoords == TextureCoords::Generate) { - vertices(0)->push_back((*vertices(0))[vertices(0)->size()-segments]); + positions(0)->push_back((*positions(0))[positions(0)->size()-segments]); normals(0)->push_back((*normals(0))[normals(0)->size()-segments]); textureCoords2D(0)->push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement}); } diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index ef908bf5c..467bfd942 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -42,7 +42,7 @@ Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector{ {-1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f} }}, {}) { - vertices(0)->assign(normals(0)->begin(), normals(0)->end()); + positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }} diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 7e667d141..640a360c1 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -54,7 +54,7 @@ Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vectorassign(normals(0)->begin(), normals(0)->end()); + positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }} diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 5cd011e03..eec4a50b1 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -57,7 +57,7 @@ template class Icosphere { }); MeshTools::clean(*indices(), *normals(0)); - vertices(0)->assign(normals(0)->begin(), normals(0)->end()); + positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }; diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index a2cc760dd..03194016d 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -34,7 +34,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 3, 1.0f); - CORRADE_COMPARE(*capsule.vertices(0), (vector{ + CORRADE_COMPARE(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.20711f, 0.707107f), @@ -90,7 +90,7 @@ void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withTextureCoords() { Capsule capsule(2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE(*capsule.vertices(0), (vector{ + CORRADE_COMPARE(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.20711f, 0.707107f), diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 3fb613c61..091e508fe 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -31,7 +31,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE(*sphere.vertices(0), (vector{ + CORRADE_COMPARE(*sphere.positions(0), (vector{ Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -0.5f, 0.866025f), @@ -69,7 +69,7 @@ void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE(*sphere.vertices(0), (vector{ + CORRADE_COMPARE(*sphere.positions(0), (vector{ Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -0.5f, 0.866025f), diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index ceb79af6b..da5201fee 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Shaders { */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - typedef Attribute<0, Vector4> Vertex; /**< @brief Vertex position */ + typedef Attribute<0, Vector4> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ /** @brief Constructor */ diff --git a/src/Trade/MeshData.cpp b/src/Trade/MeshData.cpp index 8c51fd064..4d735f80f 100644 --- a/src/Trade/MeshData.cpp +++ b/src/Trade/MeshData.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Trade { MeshData::~MeshData() { delete _indices; - for(auto i: _vertices) delete i; + for(auto i: _positions) delete i; for(auto i: _normals) delete i; for(auto i: _textureCoords2D) delete i; } diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData.h index 7617f56c3..4261913fb 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData.h @@ -42,13 +42,13 @@ class MAGNUM_EXPORT MeshData { * @param primitive Primitive * @param indices Array with indices or 0, if this is not * indexed mesh - * @param vertices Array with vertex arrays. At least one - * vertex array should be present. + * @param positions Array with vertex positions. At least one + * position array should be present. * @param normals Array with normal arrays or empty array * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> vertices, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _vertices(vertices), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData(); @@ -66,17 +66,17 @@ class MAGNUM_EXPORT MeshData { inline std::vector* indices() { return _indices; } inline const std::vector* indices() const { return _indices; } /**< @overload */ - /** @brief Count of vertex arrays */ - inline unsigned int vertexArrayCount() const { return _vertices.size(); } + /** @brief Count of vertex position arrays */ + inline unsigned int positionArrayCount() const { return _positions.size(); } /** - * @brief Vertices - * @param id ID of vertex data array - * @return Vertices or nullptr if there is no vertex array with given + * @brief Positions + * @param id ID of position data array + * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* vertices(unsigned int id) { return _vertices[id]; } - inline const std::vector* vertices(unsigned int id) const { return _vertices[id]; } /**< @overload */ + inline std::vector* positions(unsigned int id) { return _positions[id]; } + inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ inline unsigned int normalArrayCount() const { return _normals.size(); } @@ -106,7 +106,7 @@ class MAGNUM_EXPORT MeshData { std::string _name; Mesh::Primitive _primitive; std::vector* _indices; - std::vector*> _vertices; + std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; }; From d12ce5b2b49e92cc5c75a9d1bae6840a06958cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Sep 2012 00:05:04 +0200 Subject: [PATCH 008/256] Fixed copy-pasta documentation. --- src/Trade/MeshData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData.h index 4261913fb..d39afacc1 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData.h @@ -84,7 +84,7 @@ class MAGNUM_EXPORT MeshData { /** * @brief Normals * @param id ID of normal data array - * @return Vertices or nullptr if there is no normal array with given + * @return Normals or nullptr if there is no normal array with given * ID. */ inline std::vector* normals(unsigned int id) { return _normals[id]; } From de2b1b77d52a0b582cb566baab009ad72c4cf97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Sep 2012 21:42:21 +0200 Subject: [PATCH 009/256] Using Compare::Containers in primitive unit tests. --- src/Primitives/Test/CapsuleTest.cpp | 27 +++++++++++++++------------ src/Primitives/Test/UVSphereTest.cpp | 27 +++++++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 03194016d..4e23ce175 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -16,11 +16,14 @@ /* Less precision */ #define FLOAT_EQUALITY_PRECISION 1.0e-5 +#include + #include "CapsuleTest.h" #include "Primitives/Capsule.h" using namespace std; +using Corrade::TestSuite::Compare::Container; CORRADE_TEST_MAIN(Magnum::Primitives::Test::CapsuleTest) @@ -34,7 +37,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 3, 1.0f); - CORRADE_COMPARE(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.20711f, 0.707107f), @@ -54,9 +57,9 @@ void CapsuleTest::withoutTextureCoords() { Vector4(-0.612372f, 1.20711f, -0.353553f), Vector4(0.0f, 1.5f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*capsule.normals(0), (vector{ + CORRADE_COMPARE_AS(*capsule.normals(0), (vector{ Vector3(0.0f, -1.0f, 0.0f), Vector3(0.0f, -0.707107f, 0.707107f), @@ -76,21 +79,21 @@ void CapsuleTest::withoutTextureCoords() { Vector3(-0.612372f, 0.707107f, -0.353553f), Vector3(0.0f, 1.0f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, 7, 8, 11, 7, 11, 10, 8, 9, 12, 8, 12, 11, 9, 7, 10, 9, 10, 12, 10, 11, 13, 11, 12, 13, 12, 10, 13 - })); + }), Container); } void CapsuleTest::withTextureCoords() { Capsule capsule(2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.20711f, 0.707107f), @@ -114,9 +117,9 @@ void CapsuleTest::withTextureCoords() { Vector4(0.0f, 1.20711f, 0.707107f), Vector4(0.0f, 1.5f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*capsule.textureCoords2D(0), (vector{ + CORRADE_COMPARE_AS(*capsule.textureCoords2D(0), (vector{ Vector2(0.5f, 0.0f), Vector2(0.0f, 0.166667f), @@ -140,15 +143,15 @@ void CapsuleTest::withTextureCoords() { Vector2(1.0f, 0.833333f), Vector2(0.5f, 1.0f) - })); + }), Container); - CORRADE_COMPARE(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, 9, 10, 14, 9, 14, 13, 10, 11, 15, 10, 15, 14, 11, 12, 16, 11, 16, 15, 13, 14, 17, 14, 15, 17, 15, 16, 17 - })); + }), Container); } }}} diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 091e508fe..71321865c 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -15,9 +15,12 @@ #include "UVSphereTest.h" +#include + #include "Primitives/UVSphere.h" using namespace std; +using Corrade::TestSuite::Compare::Container; CORRADE_TEST_MAIN(Magnum::Primitives::Test::UVSphereTest) @@ -31,7 +34,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -0.5f, 0.866025f), @@ -43,9 +46,9 @@ void UVSphereTest::withoutTextureCoords() { Vector4(-0.75f, 0.5f, -0.433013f), Vector4(0.0f, 1.0f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*sphere.normals(0), (vector{ + CORRADE_COMPARE_AS(*sphere.normals(0), (vector{ Vector3(0.0f, -1.0f, 0.0f), Vector3(0.0f, -0.5f, 0.866025f), @@ -57,19 +60,19 @@ void UVSphereTest::withoutTextureCoords() { Vector3(-0.75f, 0.5f, -0.433013f), Vector3(0.0f, 1.0f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 - })); + }), Container); } void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -0.5f, 0.866025f), @@ -83,9 +86,9 @@ void UVSphereTest::withTextureCoords() { Vector4(0.0f, 0.5f, 0.866025f), Vector4(0.0f, 1.0f, 0.0f) - })); + }), Container); - CORRADE_COMPARE(*sphere.textureCoords2D(0), (vector{ + CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (vector{ Vector2(0.5f, 0.0f), Vector2(0.0f, 0.333333f), @@ -99,13 +102,13 @@ void UVSphereTest::withTextureCoords() { Vector2(1.0f, 0.666667f), Vector2(0.5f, 1.0f) - })); + }), Container); - CORRADE_COMPARE(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 - })); + }), Container); } }}} From e17835e3b6af11ed87501d9082c1c4611b5a1eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Sep 2012 22:30:23 +0200 Subject: [PATCH 010/256] Primitives: Ability to specify number of cylinder rings on Capsule. --- src/Primitives/Capsule.cpp | 42 +++++++++++++++++++++++------ src/Primitives/Capsule.h | 9 ++++--- src/Primitives/Test/CapsuleTest.cpp | 28 ++++++++++++++++--- src/Primitives/UVSphere.cpp | 2 +- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index ccf2d2a9f..30b5f5def 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -19,28 +19,31 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int rings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { - CORRADE_ASSERT(rings >= 1 && segments >= 3, "Capsule must have at least one ring and three segments", ); +Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { + CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; - GLfloat textureCoordsVIncrement = 1.0f/(rings*height); - GLfloat ringAngleIncrement = Math::Constants::pi()/(2*rings); + GLfloat hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); + GLfloat hemisphereRingAngleIncrement = Math::Constants::pi()/(2*hemisphereRings); /* Bottom cap vertex */ capVertex(-height/2, -1.0f, 0.0f); /* Rings of bottom hemisphere */ - vertexRings(rings, -length/2, -Math::Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + hemisphereVertexRings(hemisphereRings-1, -length/2, -Math::Constants::pi()/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); + + /* Rings of cylinder */ + cylinderVertexRings(cylinderRings+1, -length/2, length/cylinderRings, 1.0f/height, length/(cylinderRings*height)); /* Rings of top hemisphere */ - vertexRings(rings, length/2, 0.0f, ringAngleIncrement, (1.0f + length)/height, textureCoordsVIncrement); + hemisphereVertexRings(hemisphereRings-1, length/2, hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, (1.0f + length)/height+hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); /* Top cap vertex */ capVertex(height/2, 1.0f, 1.0f); /* Faces */ bottomFaceRing(); - faceRings(rings*2-1); + faceRings(hemisphereRings*2-2+cylinderRings); topFaceRing(); } @@ -52,7 +55,7 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::vertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; GLfloat x, y, z; for(unsigned int i = 0; i != count; ++i) { @@ -78,6 +81,29 @@ void Capsule::vertexRings(unsigned int count, GLfloat centerY, GLfloat startRing } } +void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { + GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; + for(unsigned int i = 0; i != count; ++i) { + for(unsigned int j = 0; j != segments; ++j) { + GLfloat segmentAngle = j*segmentAngleIncrement; + positions(0)->push_back({sin(segmentAngle), startY, cos(segmentAngle)}); + normals(0)->push_back({sin(segmentAngle), 0.0f, cos(segmentAngle)}); + + if(textureCoords == TextureCoords::Generate) + textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement}); + } + + /* Duplicate first segment in the ring for additional vertex for texture coordinate */ + if(textureCoords == TextureCoords::Generate) { + positions(0)->push_back((*positions(0))[positions(0)->size()-segments]); + normals(0)->push_back((*normals(0))[normals(0)->size()-segments]); + textureCoords2D(0)->push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement}); + } + + startY += yIncrement; + } +} + void Capsule::bottomFaceRing() { for(unsigned int j = 0; j != segments; ++j) { /* Bottom vertex */ diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 3923beba1..f487a9ae5 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -40,8 +40,10 @@ class Capsule: public Trade::MeshData { /** * @brief Constructor - * @param rings Number of (face) rings for each hemisphere. + * @param hemisphereRings Number of (face) rings for each hemisphere. * Must be larger or equal to 1. + * @param cylinderRings Number of (face) rings for cylinder. Must be + * larger or equal to 1. * @param segments Number of (face) segments. Must be larger or equal to 3. * @param length Length of the capsule, excluding hemispheres. * @param textureCoords Whether to generate texture coordinates. @@ -49,13 +51,14 @@ class Capsule: public Trade::MeshData { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Capsule(unsigned int rings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: inline Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); - void vertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void bottomFaceRing(); void faceRings(unsigned int count); void topFaceRing(); diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 4e23ce175..d0b743714 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -35,7 +35,7 @@ CapsuleTest::CapsuleTest() { } void CapsuleTest::withoutTextureCoords() { - Capsule capsule(2, 3, 1.0f); + Capsule capsule(2, 2, 3, 1.0f); CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), @@ -48,6 +48,10 @@ void CapsuleTest::withoutTextureCoords() { Vector4(0.866025f, -0.5f, -0.5f), Vector4(-0.866025f, -0.5f, -0.5f), + Vector4(0.0f, 0.0f, 1.0f), + Vector4(0.866025f, 0.0f, -0.5f), + Vector4(-0.866025f, 0.0f, -0.5f), + Vector4(0.0f, 0.5f, 1.0f), Vector4(0.866025f, 0.5f, -0.5f), Vector4(-0.866025f, 0.5f, -0.5f), @@ -74,6 +78,10 @@ void CapsuleTest::withoutTextureCoords() { Vector3(0.866025f, 0.0f, -0.5f), Vector3(-0.866025f, 0.0f, -0.5f), + Vector3(0.0f, 0.0f, 1.0f), + Vector3(0.866025f, 0.0f, -0.5f), + Vector3(-0.866025f, 0.0f, -0.5f), + Vector3(0.0f, 0.707107f, 0.707107f), Vector3(0.612372f, 0.707107f, -0.353553f), Vector3(-0.612372f, 0.707107f, -0.353553f), @@ -86,12 +94,13 @@ void CapsuleTest::withoutTextureCoords() { 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, 7, 8, 11, 7, 11, 10, 8, 9, 12, 8, 12, 11, 9, 7, 10, 9, 10, 12, - 10, 11, 13, 11, 12, 13, 12, 10, 13 + 10, 11, 14, 10, 14, 13, 11, 12, 15, 11, 15, 14, 12, 10, 13, 12, 13, 15, + 13, 14, 16, 14, 15, 16, 15, 13, 16 }), Container); } void CapsuleTest::withTextureCoords() { - Capsule capsule(2, 3, 1.0f, Capsule::TextureCoords::Generate); + Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ Vector4(0.0f, -1.5f, 0.0f), @@ -106,6 +115,11 @@ void CapsuleTest::withTextureCoords() { Vector4(-0.866025f, -0.5f, -0.5f), Vector4(0.0f, -0.5f, 1.0f), + Vector4(0.0f, 0.0f, 1.0f), + Vector4(0.866025f, 0.0f, -0.5f), + Vector4(-0.866025f, 0.0f, -0.5f), + Vector4(0.0f, 0.0f, 1.0f), + Vector4(0.0f, 0.5f, 1.0f), Vector4(0.866025f, 0.5f, -0.5f), Vector4(-0.866025f, 0.5f, -0.5f), @@ -132,6 +146,11 @@ void CapsuleTest::withTextureCoords() { Vector2(0.666667f, 0.333333f), Vector2(1.0f, 0.333333f), + Vector2(0.0f, 0.5f), + Vector2(0.333333f, 0.5f), + Vector2(0.666667f, 0.5f), + Vector2(1.0f, 0.5f), + Vector2(0.0f, 0.666667f), Vector2(0.333333f, 0.666667f), Vector2(0.666667f, 0.666667f), @@ -150,7 +169,8 @@ void CapsuleTest::withTextureCoords() { 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, 9, 10, 14, 9, 14, 13, 10, 11, 15, 10, 15, 14, 11, 12, 16, 11, 16, 15, - 13, 14, 17, 14, 15, 17, 15, 16, 17 + 13, 14, 18, 13, 18, 17, 14, 15, 19, 14, 19, 18, 15, 16, 20, 15, 20, 19, + 17, 18, 21, 18, 19, 21, 19, 20, 21 }), Container); } diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 825a5ee26..724242a03 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -29,7 +29,7 @@ UVSphere::UVSphere(unsigned int rings, unsigned int segments, TextureCoords text capVertex(-1.0f, -1.0f, 0.0f); /* Vertex rings */ - vertexRings(rings-1, 0.0f, -Math::Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + hemisphereVertexRings(rings-1, 0.0f, -Math::Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); /* Top cap vertex */ capVertex(1.0f, 1.0f, 1.0f); From 7fbf28f4a157a2291404ec9bfbeacb8e28f5b98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 17:20:16 +0200 Subject: [PATCH 011/256] Added Cylinder primitive. --- src/Primitives/CMakeLists.txt | 2 + src/Primitives/Capsule.cpp | 6 +- src/Primitives/Capsule.h | 3 +- src/Primitives/Cylinder.cpp | 69 +++++++++++ src/Primitives/Cylinder.h | 65 ++++++++++ src/Primitives/Test/CMakeLists.txt | 1 + src/Primitives/Test/CylinderTest.cpp | 175 +++++++++++++++++++++++++++ src/Primitives/Test/CylinderTest.h | 32 +++++ 8 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 src/Primitives/Cylinder.cpp create mode 100644 src/Primitives/Cylinder.h create mode 100644 src/Primitives/Test/CylinderTest.cpp create mode 100644 src/Primitives/Test/CylinderTest.h diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index 28d2aa07d..e554119cb 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -1,12 +1,14 @@ set(MagnumPrimitives_SRCS Capsule.cpp Cube.cpp + Cylinder.cpp Icosphere.cpp Plane.cpp UVSphere.cpp) set(MagnumPrimitives_HEADERS Capsule.h Cube.h + Cylinder.h Icosphere.h Plane.h UVSphere.h) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 30b5f5def..24b9967d4 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -118,14 +118,14 @@ void Capsule::bottomFaceRing() { } } -void Capsule::faceRings(unsigned int count) { +void Capsule::faceRings(unsigned int count, unsigned int offset) { unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); for(unsigned int i = 0; i != count; ++i) { for(unsigned int j = 0; j != segments; ++j) { - unsigned int bottomLeft = i*vertexSegments+j+1; + unsigned int bottomLeft = i*vertexSegments+j+offset; unsigned int bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? - i*vertexSegments+j+2 : i*segments+1); + i*vertexSegments+j+1+offset : i*segments+offset); unsigned int topLeft = bottomLeft+vertexSegments; unsigned int topRight = bottomRight+vertexSegments; diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index f487a9ae5..9bb2820d1 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -30,6 +30,7 @@ Cylinder along Y axis with hemispheres instead of caps. */ class Capsule: public Trade::MeshData { friend class UVSphere; + friend class Cylinder; public: /** @brief Whether to generate texture coordinates */ @@ -60,7 +61,7 @@ class Capsule: public Trade::MeshData { void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void bottomFaceRing(); - void faceRings(unsigned int count); + void faceRings(unsigned int count, unsigned int offset = 1); void topFaceRing(); unsigned int segments; diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp new file mode 100644 index 000000000..19c85f8b1 --- /dev/null +++ b/src/Primitives/Cylinder.cpp @@ -0,0 +1,69 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Cylinder.h" + +using namespace std; + +namespace Magnum { namespace Primitives { + +Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { + CORRADE_ASSERT(rings >= 1 && segments >= 3, "Cylinder must have at least one ring and three segments", ); + + GLfloat y = length*0.5f; + GLfloat textureCoordsV = flags & Flag::CapEnds ? 1.0f/(length+2.0f) : 0.0f; + + /* Bottom cap */ + if(flags & Flag::CapEnds) { + capVertex(-y, -1.0f, 0.0f); + capVertexRing(-y, textureCoordsV, Vector3::yAxis(-1.0f)); + } + + /* Vertex rings */ + cylinderVertexRings(rings+1, -y, length/rings, textureCoordsV, length/(rings*(flags & Flag::CapEnds ? length + 2.0f : length))); + + /* Top cap */ + if(flags & Flag::CapEnds) { + capVertexRing(y, 1.0f - textureCoordsV, Vector3::yAxis(1.0f)); + capVertex(y, 1.0f, 1.0f); + } + + /* Faces */ + if(flags & Flag::CapEnds) bottomFaceRing(); + faceRings(rings, flags & Flag::CapEnds ? 1 : 0); + if(flags & Flag::CapEnds) topFaceRing(); +} + +void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { + GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; + + for(unsigned int i = 0; i != segments; ++i) { + GLfloat segmentAngle = i*segmentAngleIncrement; + positions(0)->push_back({sin(segmentAngle), y, cos(segmentAngle)}); + normals(0)->push_back(normal); + + if(textureCoords == TextureCoords::Generate) + textureCoords2D(0)->push_back({i*1.0f/segments, textureCoordsV}); + } + + /* Duplicate first segment in the ring for additional vertex for texture coordinate */ + if(textureCoords == TextureCoords::Generate) { + positions(0)->push_back((*positions(0))[positions(0)->size()-segments]); + normals(0)->push_back(normal); + textureCoords2D(0)->push_back({1.0f, textureCoordsV}); + } +} + +}} diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h new file mode 100644 index 000000000..260b3c021 --- /dev/null +++ b/src/Primitives/Cylinder.h @@ -0,0 +1,65 @@ +#ifndef Magnum_Primitives_Cylinder_h +#define Magnum_Primitives_Cylinder_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Primitives::UVSphere + */ + +#include "Primitives/Capsule.h" +#include + +namespace Magnum { namespace Primitives { + +/** @brief Cylinder primitive */ +class Cylinder: public Capsule { + public: + /** + * @brief %Flags + * + * @see Flags, Cylinder() + */ + enum class Flag { + GenerateTextureCoords = 1, /**< @brief Generate texture coordinates */ + CapEnds /**< @brief Cap ends */ + }; + + /** @brief %Flags */ + typedef Corrade::Containers::EnumSet Flags; + + /** + * @brief Constructor + * @param rings Number of (face) rings. Must be larger or + * equal to 1. + * @param segments Number of (face) segments. Must be larger or + * equal to 3. + * @param length Cylinder length + * @param flags Flags + * + * If texture coordinates are generated, vertices of one segment are + * duplicated for texture wrapping. + */ + Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags = Flags()); + + private: + void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); +}; + +CORRADE_ENUMSET_OPERATORS(Cylinder::Flags) + +}} + +#endif diff --git a/src/Primitives/Test/CMakeLists.txt b/src/Primitives/Test/CMakeLists.txt index e30186313..c8374ccd0 100644 --- a/src/Primitives/Test/CMakeLists.txt +++ b/src/Primitives/Test/CMakeLists.txt @@ -1,2 +1,3 @@ corrade_add_test2(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test2(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives) +corrade_add_test2(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives) diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp new file mode 100644 index 000000000..28a89641b --- /dev/null +++ b/src/Primitives/Test/CylinderTest.cpp @@ -0,0 +1,175 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "CylinderTest.h" + +#include + +#include "Primitives/Cylinder.h" + +using namespace std; +using Corrade::TestSuite::Compare::Container; + +CORRADE_TEST_MAIN(Magnum::Primitives::Test::CylinderTest) + +namespace Magnum { namespace Primitives { namespace Test { + +CylinderTest::CylinderTest() { + addTests(&CylinderTest::withoutAnything, + &CylinderTest::withTextureCoordsAndCaps); +} + +void CylinderTest::withoutAnything() { + Cylinder cylinder(2, 3, 3.0f); + + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + {0.0f, -1.5f, 1.0f}, + {0.866025f, -1.5f, -0.5f}, + {-0.866025f, -1.5f, -0.5f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + + {0.0f, 1.5f, 1.0f}, + {0.866025f, 1.5f, -0.5f}, + {-0.866025f, 1.5f, -0.5f} + }), Container); + + CORRADE_COMPARE_AS(*cylinder.normals(0), (vector{ + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f} + }), Container); + + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, + 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 + }), Container); +} + +void CylinderTest::withTextureCoordsAndCaps() { + Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); + + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + {0.0f, -1.5f, 0.0f}, + + {0.0f, -1.5f, 1.0f}, + {0.866025f, -1.5f, -0.5f}, + {-0.866025f, -1.5f, -0.5f}, + {0.0f, -1.5f, 1.0f}, + + {0.0f, -1.5f, 1.0f}, + {0.866025f, -1.5f, -0.5f}, + {-0.866025f, -1.5f, -0.5f}, + {0.0f, -1.5f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 1.5f, 1.0f}, + {0.866025f, 1.5f, -0.5f}, + {-0.866025f, 1.5f, -0.5f}, + {0.0f, 1.5f, 1.0f}, + + {0.0f, 1.5f, 1.0f}, + {0.866025f, 1.5f, -0.5f}, + {-0.866025f, 1.5f, -0.5f}, + {0.0f, 1.5f, 1.0f}, + + {0.0f, 1.5f, 0.0f} + }), Container); + + CORRADE_COMPARE_AS(*cylinder.normals(0), (vector{ + {0.0f, -1.0f, 0.0f}, + + {0.0f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + + {0.0f, 1.0f, 0.0f}, + }), Container); + + CORRADE_COMPARE_AS(*cylinder.textureCoords2D(0), (vector{ + {0.5f, 0.0f}, + + {0.0f, 0.2f}, + {0.333333f, 0.2f}, + {0.666667f, 0.2f}, + {1.0f, 0.2f}, + + {0.0f, 0.2f}, + {0.333333f, 0.2f}, + {0.666667f, 0.2f}, + {1.0f, 0.2f}, + + {0.0f, 0.5f}, + {0.333333f, 0.5f}, + {0.666667f, 0.5f}, + {1.0f, 0.5f}, + + {0.0f, 0.8f}, + {0.333333f, 0.8f}, + {0.666667f, 0.8f}, + {1.0f, 0.8f}, + + {0.0f, 0.8f}, + {0.333333f, 0.8f}, + {0.666667f, 0.8f}, + {1.0f, 0.8f}, + + {0.5f, 1.0f} + }), Container); + + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + 0, 2, 1, 0, 3, 2, 0, 4, 3, + 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, + 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, + 12, 11, 17, 18, 21, 18, 19, 21, 19, 20, 21 + }), Container); +} + +}}} diff --git a/src/Primitives/Test/CylinderTest.h b/src/Primitives/Test/CylinderTest.h new file mode 100644 index 000000000..0d575bc23 --- /dev/null +++ b/src/Primitives/Test/CylinderTest.h @@ -0,0 +1,32 @@ +#ifndef Magnum_Primitives_Test_CylinderTest_h +#define Magnum_Primitives_Test_CylinderTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Primitives { namespace Test { + +class CylinderTest: public Corrade::TestSuite::Tester { + public: + CylinderTest(); + + void withoutAnything(); + void withTextureCoordsAndCaps(); +}; + +}}} + +#endif From c78cc95284d9f352cfd05f7b32660c0206048ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 19:31:54 +0200 Subject: [PATCH 012/256] Physics: Moved Point constructor to source file. Point has virtual functions, this avoids creating vtable for it in every compilation unit. --- src/Physics/CMakeLists.txt | 1 + src/Physics/Point.cpp | 26 ++++++++++++++++++++++++++ src/Physics/Point.h | 6 ++---- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/Physics/Point.cpp diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 8201d490b..a42842084 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -4,6 +4,7 @@ set(MagnumPhysics_SRCS Capsule.cpp Line.cpp Plane.cpp + Point.cpp ShapeGroup.cpp Sphere.cpp) set(MagnumPhysics_HEADERS diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp new file mode 100644 index 000000000..eef45829f --- /dev/null +++ b/src/Physics/Point.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Point.h" + +#include "Math/Matrix4.h" + +namespace Magnum { namespace Physics { + +void Point::applyTransformation(const Matrix4& transformation) { + _transformedPosition = (transformation*Vector4(_position)).xyz(); +} + +}} diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 80e465fbc..32f5e5d4b 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -24,14 +24,12 @@ namespace Magnum { namespace Physics { /** @brief %Point */ -class Point: public AbstractShape { +class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline Point(const Vector3& position): _position(position), _transformedPosition(position) {} - inline void applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); - } + void applyTransformation(const Matrix4& transformation); /** @brief Position */ inline Vector3 position() const { return _position; } From fe62f547deabfcce6c80ca29d9691d7f9dba148b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 19:40:05 +0200 Subject: [PATCH 013/256] Reduced #includes in headers. Magnum.h now doesn't include anything except OpenGL headers, thus changes in Math library don't trigger recompilation of everything, but only of things really depending on it. Math constants moved to separate file for similar reasons, de-inlined some functions to remove the need for some #includes. --- src/AbstractImage.h | 2 + src/AbstractShaderProgram.cpp | 2 + src/AbstractShaderProgram.h | 8 +- src/Buffer.h | 2 + src/Contexts/AbstractXContext.h | 5 +- src/Contexts/ExtensionWrangler.cpp | 2 + src/Contexts/GlutContext.h | 4 + src/Contexts/GlxInterface.cpp | 1 + src/Contexts/Sdl2Context.h | 2 + src/Framebuffer.cpp | 3 + src/Framebuffer.h | 14 +++- src/IndexedMesh.cpp | 2 + src/Magnum.h | 20 ++++- src/Math/CMakeLists.txt | 1 + src/Math/Constants.h | 79 +++++++++++++++++++ src/Math/Geometry/Test/DistanceTest.cpp | 2 +- src/Math/Math.h | 48 +---------- src/Math/Test/CMakeLists.txt | 4 +- src/Math/Test/ConstantsTest.cpp | 46 +++++++++++ src/Math/Test/ConstantsTest.h | 32 ++++++++ src/Math/Test/MathTest.cpp | 18 +---- src/Math/Test/MathTest.h | 2 - src/Math/Test/Matrix3Test.cpp | 2 +- src/Math/Test/Matrix4Test.cpp | 2 +- src/Math/Test/VectorTest.cpp | 2 +- src/Mesh.cpp | 3 + src/MeshTools/Clean.h | 1 + src/MeshTools/FlipNormals.cpp | 2 + src/MeshTools/FlipNormals.h | 3 + src/MeshTools/GenerateFlatNormals.cpp | 1 + src/MeshTools/GenerateFlatNormals.h | 2 + src/MeshTools/Test/FlipNormalsTest.cpp | 1 + .../Test/GenerateFlatNormalsTest.cpp | 2 +- src/Physics/AbstractShape.h | 1 + src/Physics/AxisAlignedBox.cpp | 2 + src/Physics/AxisAlignedBox.h | 1 + src/Physics/Capsule.cpp | 5 ++ src/Physics/Capsule.h | 6 +- src/Physics/Line.cpp | 2 + src/Physics/Line.h | 1 + src/Physics/Plane.cpp | 2 + src/Physics/Plane.h | 7 +- src/Physics/Point.h | 1 + src/Physics/ShapeGroup.h | 3 + src/Physics/Sphere.cpp | 5 ++ src/Physics/Sphere.h | 8 +- src/Physics/Test/AbstractShapeTest.h | 1 + src/Physics/Test/AxisAlignedBoxTest.cpp | 2 + src/Physics/Test/CapsuleTest.cpp | 3 + src/Physics/Test/LineTest.cpp | 2 + src/Physics/Test/PlaneTest.cpp | 3 + src/Physics/Test/PointTest.cpp | 1 + src/Physics/Test/ShapeGroupTest.cpp | 1 + src/Physics/Test/SphereTest.cpp | 3 + src/Primitives/Capsule.cpp | 5 ++ src/Primitives/Capsule.h | 2 +- src/Primitives/Cube.cpp | 2 + src/Primitives/Cylinder.cpp | 3 + src/Primitives/Cylinder.h | 3 +- src/Primitives/Icosphere.cpp | 2 + src/Primitives/Icosphere.h | 3 +- src/Primitives/Plane.cpp | 2 + src/Primitives/Test/CapsuleTest.cpp | 5 +- src/Primitives/Test/CylinderTest.cpp | 1 + src/Primitives/Test/UVSphereTest.cpp | 1 + src/Primitives/UVSphere.cpp | 4 + src/Query.h | 2 + src/Renderbuffer.h | 3 + src/SceneGraph/Object.h | 1 + src/SceneGraph/Test/CameraTest.cpp | 1 + src/SceneGraph/Test/ObjectTest.cpp | 6 +- src/Shader.cpp | 1 + src/Shader.h | 6 +- src/Shaders/PhongShader.cpp | 2 + src/Shaders/PhongShader.h | 1 + src/SizeTraits.h | 3 + src/Trade/AbstractImporter.cpp | 3 + src/Trade/AbstractImporter.h | 7 +- src/Trade/ImageData.h | 1 + src/Trade/MeshData.cpp | 2 + src/Trade/MeshData.h | 2 + src/Trade/ObjectData.h | 1 + src/Trade/PhongMaterialData.h | 1 + src/TypeTraits.h | 6 ++ 84 files changed, 363 insertions(+), 99 deletions(-) create mode 100644 src/Math/Constants.h create mode 100644 src/Math/Test/ConstantsTest.cpp create mode 100644 src/Math/Test/ConstantsTest.h diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 1a86e4313..a71b06e81 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -21,6 +21,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 47ea3eeb4..eb7541f9d 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -17,6 +17,8 @@ #include +#include "Shader.h" + #define LINKER_MESSAGE_MAX_LENGTH 1024 using namespace std; diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index e9fc0d8ab..510850e18 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -21,10 +21,16 @@ #include -#include "Shader.h" +#include "Math/Matrix4.h" +#include "Math/Vector4.h" +#include "Magnum.h" + +#include "magnumVisibility.h" namespace Magnum { +class Shader; + /** @brief Base class for shaders diff --git a/src/Buffer.h b/src/Buffer.h index 54af31cf4..4c3607234 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Buffer */ +#include + #include "Magnum.h" namespace Magnum { diff --git a/src/Contexts/AbstractXContext.h b/src/Contexts/AbstractXContext.h index 620a777ac..622e81ef3 100644 --- a/src/Contexts/AbstractXContext.h +++ b/src/Contexts/AbstractXContext.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Contexts::AbstractXContext */ +#include + #include "Magnum.h" #include @@ -27,8 +29,7 @@ #undef None #undef Always -#include - +#include "Math/Vector2.h" #include "AbstractContext.h" #include "AbstractGlInterface.h" diff --git a/src/Contexts/ExtensionWrangler.cpp b/src/Contexts/ExtensionWrangler.cpp index f9c6dc47e..927b66628 100644 --- a/src/Contexts/ExtensionWrangler.cpp +++ b/src/Contexts/ExtensionWrangler.cpp @@ -15,6 +15,8 @@ #include "ExtensionWrangler.h" +#include + #include "Magnum.h" namespace Magnum { namespace Contexts { diff --git a/src/Contexts/GlutContext.h b/src/Contexts/GlutContext.h index 73e32569f..960775a94 100644 --- a/src/Contexts/GlutContext.h +++ b/src/Contexts/GlutContext.h @@ -19,7 +19,11 @@ * @brief Class Magnum::Contexts::GlutContext */ +#include + +#include "Math/Vector2.h" #include "Magnum.h" + #include #include "AbstractContext.h" diff --git a/src/Contexts/GlxInterface.cpp b/src/Contexts/GlxInterface.cpp index a8fb92680..a9ce9aba0 100644 --- a/src/Contexts/GlxInterface.cpp +++ b/src/Contexts/GlxInterface.cpp @@ -16,6 +16,7 @@ #include "GlxInterface.h" #include +#include namespace Magnum { namespace Contexts { diff --git a/src/Contexts/Sdl2Context.h b/src/Contexts/Sdl2Context.h index 112b434b8..5f91d9e75 100644 --- a/src/Contexts/Sdl2Context.h +++ b/src/Contexts/Sdl2Context.h @@ -19,7 +19,9 @@ * @brief Class Magnum::Contexts::Sdl2Context */ +#include "Math/Vector2.h" #include "Magnum.h" + #include #include diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index e6117caec..d0e158e08 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -15,6 +15,9 @@ #include "Framebuffer.h" +#include "BufferedImage.h" +#include "Image.h" + namespace Magnum { #ifndef MAGNUM_TARGET_GLES diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 0ee1750bf..f9eb59fce 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -21,14 +21,24 @@ #include -#include "BufferedImage.h" +#include "AbstractImage.h" +#include "Buffer.h" #include "CubeMapTexture.h" #include "Color.h" -#include "Image.h" #include "Renderbuffer.h" namespace Magnum { +template class BufferedImage; +template class Image; + +typedef BufferedImage<1> BufferedImage1D; +typedef BufferedImage<2> BufferedImage2D; +typedef BufferedImage<3> BufferedImage3D; +typedef Image<1> Image1D; +typedef Image<2> Image2D; +typedef Image<3> Image3D; + /** @nosubgrouping @brief %Framebuffer diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 05a9b009a..6e9e96549 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -15,6 +15,8 @@ #include "IndexedMesh.h" +#include + namespace Magnum { void IndexedMesh::draw() { diff --git a/src/Magnum.h b/src/Magnum.h index 630b962c7..03f25bcf5 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -27,11 +27,25 @@ #include #endif -#include "Math/Math.h" -#include "Math/Matrix4.h" -#include "Math/Vector2.h" +namespace Corrade { + namespace Utility { + class Debug; + class Warning; + class Error; + } +} namespace Magnum { + namespace Math { + template class Vector2; + template class Vector3; + template class Vector4; + template class Matrix3; + template class Matrix4; + + template constexpr T deg(T value); + template constexpr T rad(T value); + } /* Bring debugging facility from Corrade::Utility namespace */ using Corrade::Utility::Debug; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index cf24e5d0b..edcfe14ac 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(MagnumMath_HEADERS + Constants.h Math.h MathTypeTraits.h Matrix.h diff --git a/src/Math/Constants.h b/src/Math/Constants.h new file mode 100644 index 000000000..a4c8a50e5 --- /dev/null +++ b/src/Math/Constants.h @@ -0,0 +1,79 @@ +#ifndef Magnum_Math_Constants_h +#define Magnum_Math_Constants_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Constants, functions Magnum::Math::deg(), Magnum::Math::rad() + */ + +namespace Magnum { namespace Math { + +/** +@brief Numeric constants + +@internal See MathTypeTraits class for implementation notes. +*/ +template struct Constants { + #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Pi + * + * @see deg(), rad() + */ + static inline constexpr T pi(); + + static inline constexpr T sqrt2(); /**< @brief Square root of 2 */ + static inline constexpr T sqrt3(); /**< @brief Square root of 3 */ + #endif +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +template<> struct Constants { + static inline constexpr double pi() { return 3.141592653589793; } + static inline constexpr double sqrt2() { return 1.414213562373095; } + static inline constexpr double sqrt3() { return 1.732050807568877; } +}; +template<> struct Constants { + static inline constexpr float pi() { return 3.141592654f; } + static inline constexpr float sqrt2() { return 1.414213562f; } + static inline constexpr float sqrt3() { return 1.732050808f; } +}; +#endif + +/** +@brief Angle in degrees + +Function to make angle entering less error-prone. Converts the value to +radians at compile time. For example `deg(180.0f)` is converted to `3.14f`. + +Usable for entering e.g. rotation: +@code +Matrix4::rotation(deg(30.0f), Vector3::yAxis()); +@endcode +@see Constants, rad() + */ +template inline constexpr T deg(T value) { return value*Constants::pi()/180; } + +/** + * @brief Angle in radians + * + * See deg() for more information. + */ +template inline constexpr T rad(T value) { return value; } + +}} + +#endif diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 5f14c0aa4..240ad21eb 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math.h" +#include "Constants.h" #include "Distance.h" CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::DistanceTest) diff --git a/src/Math/Math.h b/src/Math/Math.h index 8c37df308..5f475d598 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -15,7 +15,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include #include #include #include @@ -24,7 +23,7 @@ #include "magnumVisibility.h" /** @file - * @brief Math constants and utilities + * @brief Math utilities */ namespace Magnum { namespace Math { @@ -36,31 +35,7 @@ namespace Magnum { namespace Math { matrices) */ -/** -@brief Numeric constants - -@internal See MathTypeTraits class for implementation notes. -*/ -template struct Constants { - #ifdef DOXYGEN_GENERATING_OUTPUT - static inline constexpr T pi(); /**< @brief Pi */ - static inline constexpr T sqrt2(); /**< @brief Square root of 2 */ - static inline constexpr T sqrt3(); /**< @brief Square root of 3 */ - #endif -}; - #ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct Constants { - static inline constexpr double pi() { return 3.141592653589793; } - static inline constexpr double sqrt2() { return 1.414213562373095; } - static inline constexpr double sqrt3() { return 1.732050807568877; } -}; -template<> struct Constants { - static inline constexpr float pi() { return 3.141592654f; } - static inline constexpr float sqrt2() { return 1.414213562f; } - static inline constexpr float sqrt3() { return 1.732050808f; } -}; - namespace Implementation { template struct Pow { template inline constexpr T operator()(T base) const { @@ -135,27 +110,6 @@ template inline T clamp(T value, T min, T max) { return std::min(std::max(value, min), max); } -/** -@brief Angle in degrees - -Function to make angle entering less error-prone. Converts the value to -radians at compile time. For example `deg(180.0f)` is converted to `3.14f`. - -Usable for entering e.g. rotation: -@code -Matrix4::rotation(deg(30.0f), Vector3::yAxis()); -@endcode -@see rad() - */ -template inline constexpr T deg(T value) { return value*Constants::pi()/180; } - -/** - * @brief Angle in radians - * - * See deg() for more information. - */ -template inline constexpr T rad(T value) { return value; } - }} #endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 784a73776..8f3690ea8 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,3 +1,5 @@ +corrade_add_test2(MathConstantsTest ConstantsTest.cpp) +corrade_add_test2(MathTest MathTest.cpp $) corrade_add_test2(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) corrade_add_test2(MathRectangularMatrixTest RectangularMatrixTest.cpp) @@ -11,5 +13,3 @@ corrade_add_test2(MathVector4Test Vector4Test.cpp) corrade_add_test2(MathMatrixTest MatrixTest.cpp) corrade_add_test2(MathMatrix3Test Matrix3Test.cpp) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) - -corrade_add_test2(MathTest MathTest.cpp $) diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp new file mode 100644 index 000000000..fb24fd8be --- /dev/null +++ b/src/Math/Test/ConstantsTest.cpp @@ -0,0 +1,46 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ConstantsTest.h" + +#include "Constants.h" +#include "Math.h" + +using namespace std; + +CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) + +namespace Magnum { namespace Math { namespace Test { + +ConstantsTest::ConstantsTest() { + addTests(&ConstantsTest::constants, + &ConstantsTest::degrad); +} + +void ConstantsTest::constants() { + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0f); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0f); + + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); +} + +void ConstantsTest::degrad() { + CORRADE_COMPARE(deg(90.0), Constants::pi()/2); + CORRADE_COMPARE(deg(90.0f), Constants::pi()/2); + CORRADE_COMPARE(rad(Constants::pi()/2), Constants::pi()/2); +} + +}}} diff --git a/src/Math/Test/ConstantsTest.h b/src/Math/Test/ConstantsTest.h new file mode 100644 index 000000000..a52c49543 --- /dev/null +++ b/src/Math/Test/ConstantsTest.h @@ -0,0 +1,32 @@ +#ifndef Magnum_Math_Test_ConstantsTest_h +#define Magnum_Math_Test_ConstantsTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class ConstantsTest: public Corrade::TestSuite::Tester { + public: + ConstantsTest(); + + void constants(); + void degrad(); +}; + +}}} + +#endif diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index cfdc49243..862f1a15b 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -24,29 +24,13 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) namespace Magnum { namespace Math { namespace Test { MathTest::MathTest() { - addTests(&MathTest::constants, - &MathTest::degrad, - &MathTest::normalize, + addTests(&MathTest::normalize, &MathTest::denormalize, &MathTest::clamp, &MathTest::pow, &MathTest::log); } -void MathTest::constants() { - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0f); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0f); - - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); -} - -void MathTest::degrad() { - CORRADE_COMPARE(deg(90.0), Constants::pi()/2); - CORRADE_COMPARE(deg(90.0f), Constants::pi()/2); - CORRADE_COMPARE(rad(Constants::pi()/2), Constants::pi()/2); -} - void MathTest::normalize() { /* Range for signed and unsigned */ CORRADE_COMPARE((Math::normalize(-128)), 0.0f); diff --git a/src/Math/Test/MathTest.h b/src/Math/Test/MathTest.h index 568c0b148..658d47690 100644 --- a/src/Math/Test/MathTest.h +++ b/src/Math/Test/MathTest.h @@ -23,8 +23,6 @@ class MathTest: public Corrade::TestSuite::Tester { public: MathTest(); - void constants(); - void degrad(); void normalize(); void denormalize(); void clamp(); diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 840e75c92..225b62171 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -17,8 +17,8 @@ #include +#include "Constants.h" #include "Matrix3.h" -#include "Math.h" CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test) diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 9cc253cc6..03111d207 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -17,8 +17,8 @@ #include +#include "Constants.h" #include "Matrix4.h" -#include "Math.h" CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Test) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 4e18e3b69..7a3ef084b 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -17,8 +17,8 @@ #include +#include "Constants.h" #include "Vector.h" -#include "Math.h" CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 93d789c0c..bd763af43 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -14,6 +14,9 @@ */ #include "Mesh.h" + +#include + #include "Buffer.h" using namespace std; diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index bca23aeb9..9a4a0d6b8 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -23,6 +23,7 @@ #include #include +#include "Math/Vector.h" #include "TypeTraits.h" namespace Magnum { namespace MeshTools { diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index 1a38ede06..ddfe16dd0 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -15,6 +15,8 @@ #include "FlipNormals.h" +#include "Math/Vector3.h" + using namespace std; namespace Magnum { namespace MeshTools { diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 191177945..673b43a32 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -19,7 +19,10 @@ * @brief Function Magnum::MeshTools::flipNormals() */ +#include + #include "Magnum.h" + #include "magnumMeshToolsVisibility.h" namespace Magnum { namespace MeshTools { diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 1e70162e7..50866eb18 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -15,6 +15,7 @@ #include "GenerateFlatNormals.h" +#include "Math/Vector4.h" #include "MeshTools/Clean.h" using namespace std; diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 20a94b494..48f289e19 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -20,8 +20,10 @@ */ #include +#include #include "Magnum.h" + #include "magnumMeshToolsVisibility.h" namespace Magnum { namespace MeshTools { diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index ec97f1da5..59f3a757d 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -17,6 +17,7 @@ #include +#include "Math/Vector3.h" #include "MeshTools/FlipNormals.h" CORRADE_TEST_MAIN(Magnum::MeshTools::Test::FlipNormalsTest) diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 8b4cec77f..8cf127a46 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -17,6 +17,7 @@ #include +#include "Math/Vector4.h" #include "MeshTools/GenerateFlatNormals.h" CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) @@ -58,7 +59,6 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (vector{ 0, 0, 0, 1, 1, 1 diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 2af5cda40..363a685be 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -20,6 +20,7 @@ */ #include "Magnum.h" + #include "magnumPhysicsVisibility.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index faa81e229..b0ef33339 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -15,6 +15,8 @@ #include "AxisAlignedBox.h" +#include "Math/Matrix4.h" + namespace Magnum { namespace Physics { void AxisAlignedBox::applyTransformation(const Matrix4& transformation) { diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index a9ef1c13b..ce3505582 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Physics::AxisAlignedBox */ +#include "Math/Vector3.h" #include "AbstractShape.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 7c40dc206..3f7936901 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -15,7 +15,12 @@ #include "Capsule.h" +#include "Math/Constants.h" +#include "Math/Math.h" +#include "Math/Matrix4.h" #include "Math/Geometry/Distance.h" +#include "Point.h" +#include "Sphere.h" using namespace Magnum::Math::Geometry; diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 25ced6b53..d85cef641 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -19,12 +19,14 @@ * @brief Class Magnum::Physics::Capsule */ +#include "Math/Vector3.h" #include "AbstractShape.h" -#include "Point.h" -#include "Sphere.h" namespace Magnum { namespace Physics { +class Point; +class Sphere; + /** @brief %Capsule defined by cylinder start and end point and radius diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 0cf2ecc15..010cf5c37 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -15,6 +15,8 @@ #include "Line.h" +#include "Math/Matrix4.h" + namespace Magnum { namespace Physics { void Line::applyTransformation(const Matrix4& transformation) { diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 05b5c7f16..22897adf5 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Physics::Line */ +#include "Math/Vector3.h" #include "AbstractShape.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index f8529bbf1..5ca9d49c3 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -17,7 +17,9 @@ #include +#include "Math/Matrix4.h" #include "Math/Geometry/Intersection.h" +#include "LineSegment.h" using namespace std; using namespace Magnum::Math::Geometry; diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 883fc899e..dd363b1c7 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -19,13 +19,14 @@ * @brief Class Magnum::Physics::Plane */ +#include "Math/Vector3.h" #include "AbstractShape.h" -#include "Line.h" -#include "LineSegment.h" - namespace Magnum { namespace Physics { +class Line; +class LineSegment; + /** @brief Infinite plane, defined by position and normal */ class PHYSICS_EXPORT Plane: public AbstractShape { public: diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 32f5e5d4b..787236b6b 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Physics::Point */ +#include "Math/Vector3.h" #include "AbstractShape.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 074474719..35be57000 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -21,6 +21,9 @@ #include "AbstractShape.h" +#include +#include + namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 334982b07..54a656168 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -15,7 +15,12 @@ #include "Sphere.h" +#include "Math/Constants.h" +#include "Math/Math.h" +#include "Math/Matrix4.h" #include "Math/Geometry/Distance.h" +#include "LineSegment.h" +#include "Point.h" using namespace Magnum::Math::Geometry; diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 20961d6b7..ddc317603 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -19,13 +19,15 @@ * @brief Class Magnum::Physics::Sphere */ +#include "Math/Vector3.h" #include "AbstractShape.h" -#include "Point.h" -#include "Line.h" -#include "LineSegment.h" namespace Magnum { namespace Physics { +class Line; +class LineSegment; +class Point; + /** @brief %Sphere defined by position and radius diff --git a/src/Physics/Test/AbstractShapeTest.h b/src/Physics/Test/AbstractShapeTest.h index 6d2096ae1..ea8d1ff06 100644 --- a/src/Physics/Test/AbstractShapeTest.h +++ b/src/Physics/Test/AbstractShapeTest.h @@ -17,6 +17,7 @@ #include +#include "Math/Matrix4.h" #include "Magnum.h" namespace Magnum { namespace Physics { namespace Test { diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index e62e3df6f..81d6eba57 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -15,6 +15,8 @@ #include "AxisAlignedBoxTest.h" +#include "Math/Constants.h" +#include "Math/Matrix4.h" #include "Physics/AxisAlignedBox.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 3c4d2ba8d..17feb9204 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -15,7 +15,10 @@ #include "CapsuleTest.h" +#include "Math/Constants.h" #include "Physics/Capsule.h" +#include "Physics/Point.h" +#include "Physics/Sphere.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::CapsuleTest) diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index b4badfba4..1e06ccb4b 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -15,6 +15,8 @@ #include "LineTest.h" +#include "Math/Constants.h" +#include "Math/Matrix4.h" #include "Physics/Line.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::LineTest) diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 8b8e4ac4c..f2f799189 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -15,6 +15,9 @@ #include "PlaneTest.h" +#include "Math/Constants.h" +#include "Physics/LineSegment.h" +#include "Physics/Point.h" #include "Physics/Plane.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::PlaneTest) diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index 5edff1469..ed191dfc5 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -15,6 +15,7 @@ #include "PointTest.h" +#include "Math/Matrix4.h" #include "Physics/Point.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::PointTest) diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index 866a52cbd..a78ddc9d6 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -15,6 +15,7 @@ #include "ShapeGroupTest.h" +#include "Math/Matrix4.h" #include "Physics/Point.h" #include "Physics/Sphere.h" #include "Physics/ShapeGroup.h" diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index 432c99db7..d78291a2c 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -15,6 +15,9 @@ #include "SphereTest.h" +#include "Math/Constants.h" +#include "Physics/LineSegment.h" +#include "Physics/Point.h" #include "Physics/Sphere.h" CORRADE_TEST_MAIN(Magnum::Physics::Test::SphereTest) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 24b9967d4..11fa8f9f0 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -15,6 +15,9 @@ #include "Capsule.h" +#include "Math/Constants.h" +#include "Math/Vector4.h" + using namespace std; namespace Magnum { namespace Primitives { @@ -47,6 +50,8 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} + void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); normals(0)->push_back({0.0f, normalY, 0.0f}); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 9bb2820d1..bb496ea00 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -55,7 +55,7 @@ class Capsule: public Trade::MeshData { Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: - inline Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} + Capsule(unsigned int segments, TextureCoords textureCoords); void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 467bfd942..c524fb77e 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -15,6 +15,8 @@ #include "Cube.h" +#include "Math/Vector4.h" + using namespace std; namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 19c85f8b1..30a031538 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -15,6 +15,9 @@ #include "Cylinder.h" +#include "Math/Constants.h" +#include "Math/Vector4.h" + using namespace std; namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index 260b3c021..f68993b70 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -19,9 +19,10 @@ * @brief Class Magnum::Primitives::UVSphere */ -#include "Primitives/Capsule.h" #include +#include "Primitives/Capsule.h" + namespace Magnum { namespace Primitives { /** @brief Cylinder primitive */ diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 640a360c1..436937906 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -15,6 +15,8 @@ #include "Icosphere.h" +#include "Math/Vector4.h" + using namespace std; namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index eec4a50b1..22d854576 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -19,9 +19,10 @@ * @brief Class Magnum::Primitives::Icosphere */ -#include "Trade/MeshData.h" +#include "Math/Vector3.h" #include "MeshTools/Subdivide.h" #include "MeshTools/Clean.h" +#include "Trade/MeshData.h" namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index e6216bf37..6db0eec5c 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -15,6 +15,8 @@ #include "Plane.h" +#include "Math/Vector4.h" + using namespace std; namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index d0b743714..983a8ed1f 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -16,10 +16,11 @@ /* Less precision */ #define FLOAT_EQUALITY_PRECISION 1.0e-5 -#include - #include "CapsuleTest.h" +#include + +#include "Math/Vector4.h" #include "Primitives/Capsule.h" using namespace std; diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 28a89641b..43efb5845 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -17,6 +17,7 @@ #include +#include "Math/Vector4.h" #include "Primitives/Cylinder.h" using namespace std; diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 71321865c..3ffd66937 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -17,6 +17,7 @@ #include +#include "Math/Vector4.h" #include "Primitives/UVSphere.h" using namespace std; diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 724242a03..7a881cd43 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -15,6 +15,10 @@ #include "UVSphere.h" +#include + +#include "Math/Constants.h" + using namespace std; namespace Magnum { namespace Primitives { diff --git a/src/Query.h b/src/Query.h index 32413b2bf..41c59415c 100644 --- a/src/Query.h +++ b/src/Query.h @@ -21,6 +21,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { #ifndef MAGNUM_TARGET_GLES diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 35854aba3..5a255ee5c 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -19,8 +19,11 @@ * @brief Class Magnum::Renderbuffer */ +#include "Math/Vector2.h" #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index b6a0d3861..e4afc6814 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -21,6 +21,7 @@ #include +#include "Math/Matrix4.h" #include "Magnum.h" #include "magnumSceneGraphVisibility.h" diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 09e58dd7c..f7a111cf1 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -15,6 +15,7 @@ #include "CameraTest.h" +#include "Math/Constants.h" #include "SceneGraph/Camera.h" CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::CameraTest) diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 77f5a7afa..c838704f8 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -14,11 +14,13 @@ */ #include "ObjectTest.h" -#include "SceneGraph/Camera.h" -#include "SceneGraph/Scene.h" #include +#include "Math/Constants.h" +#include "SceneGraph/Camera.h" +#include "SceneGraph/Scene.h" + using namespace std; CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) diff --git a/src/Shader.cpp b/src/Shader.cpp index 6646b2d47..2bf2bf948 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -16,6 +16,7 @@ #include "Shader.h" #include +#include #define COMPILER_MESSAGE_MAX_LENGTH 1024 diff --git a/src/Shader.h b/src/Shader.h index cdb19b456..75c3a0f63 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -19,11 +19,13 @@ * @brief Class Magnum::Shader */ -#include "Magnum.h" - #include #include +#include "Magnum.h" + +#include "magnumVisibility.h" + namespace Magnum { /** diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 378a3e664..bf2ce456e 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -17,6 +17,8 @@ #include +#include "Shader.h" + namespace Magnum { namespace Shaders { PhongShader::PhongShader() { diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index da5201fee..a27b5d047 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -20,6 +20,7 @@ */ #include "AbstractShaderProgram.h" + #include "magnumShadersVisibility.h" namespace Magnum { namespace Shaders { diff --git a/src/SizeTraits.h b/src/SizeTraits.h index 5b156c576..62f984d39 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -19,6 +19,9 @@ * @brief Class Magnum::SizeTraits, Magnum::SizeBasedCall, Magnum::Pow, Magnum::Log */ +#include + +#include "Math/Math.h" #include "Magnum.h" namespace Magnum { diff --git a/src/Trade/AbstractImporter.cpp b/src/Trade/AbstractImporter.cpp index cfd07c7a3..ec68d9c21 100644 --- a/src/Trade/AbstractImporter.cpp +++ b/src/Trade/AbstractImporter.cpp @@ -15,7 +15,10 @@ #include "AbstractImporter.h" +#include + using namespace std; +using namespace Corrade::Utility; namespace Magnum { namespace Trade { diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 2b7ed2528..e39fada1f 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -22,18 +22,23 @@ #include #include -#include "ImageData.h" +#include "magnumVisibility.h" namespace Magnum { namespace Trade { class AbstractMaterialData; class CameraData; +template class ImageData; class LightData; class MeshData; class ObjectData; class SceneData; class TextureData; +typedef ImageData<1> ImageData1D; +typedef ImageData<2> ImageData2D; +typedef ImageData<3> ImageData3D; + /** @brief Base class for importer plugins diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index f054f6464..98a4345a4 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Trade::ImageData */ +#include "Math/Vector.h" #include "AbstractImage.h" #include "TypeTraits.h" diff --git a/src/Trade/MeshData.cpp b/src/Trade/MeshData.cpp index 4d735f80f..24f2043fe 100644 --- a/src/Trade/MeshData.cpp +++ b/src/Trade/MeshData.cpp @@ -15,6 +15,8 @@ #include "MeshData.h" +#include "Math/Vector4.h" + namespace Magnum { namespace Trade { MeshData::~MeshData() { diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData.h index d39afacc1..daf4f3cfa 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Trade::MeshData */ +#include + #include "Mesh.h" namespace Magnum { namespace Trade { diff --git a/src/Trade/ObjectData.h b/src/Trade/ObjectData.h index 3da9cd9ad..53da3f783 100644 --- a/src/Trade/ObjectData.h +++ b/src/Trade/ObjectData.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Trade::ObjectData */ +#include "Math/Matrix4.h" #include "Magnum.h" namespace Magnum { namespace Trade { diff --git a/src/Trade/PhongMaterialData.h b/src/Trade/PhongMaterialData.h index 7aa7cf453..21896cba3 100644 --- a/src/Trade/PhongMaterialData.h +++ b/src/Trade/PhongMaterialData.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Trade::PhongMaterialData */ +#include "Math/Vector3.h" #include "Magnum.h" #include "AbstractMaterialData.h" diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 3e95eec12..11dfea0c4 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -19,10 +19,16 @@ * @brief Enum Magnum::Type, class Magnum::TypeOf, Magnum::TypeInfo, Magnum::TypeTraits */ +#include "Math/MathTypeTraits.h" #include "AbstractImage.h" namespace Magnum { +namespace Math { + template class Vector; + template class Matrix; +} + /** @brief Traits class for plain OpenGL types From 08c869697816c16593f5ff544afeff3c96bd8e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 20:06:03 +0200 Subject: [PATCH 014/256] Doc++, added missing inline. --- src/Contexts/AbstractContext.h | 2 +- src/Math/Algorithms/GaussJordan.h | 2 +- src/Profiler.h | 2 +- src/Renderbuffer.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Contexts/AbstractContext.h b/src/Contexts/AbstractContext.h index 74d42e530..f754d1012 100644 --- a/src/Contexts/AbstractContext.h +++ b/src/Contexts/AbstractContext.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::GlutContext + * @brief Class Magnum::Contexts::AbstractContext */ namespace Magnum { namespace Contexts { diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index d98bf89c8..a3e9fafb4 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class GaussJordan + * @brief Class Magnum::Math::Algorithms::GaussJordan */ #include "Math/RectangularMatrix.h" diff --git a/src/Profiler.h b/src/Profiler.h index a3da6ef56..b4f7f6306 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Profiler + * @brief Class Magnum::Profiler */ #include diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 5a255ee5c..ebba60801 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -185,7 +185,7 @@ class Renderbuffer { * * Generates new OpenGL renderbuffer. */ - Renderbuffer() { + inline Renderbuffer() { glGenRenderbuffers(1, &renderbuffer); } @@ -194,7 +194,7 @@ class Renderbuffer { * * Deletes associated OpenGL renderbuffer. */ - ~Renderbuffer() { + inline ~Renderbuffer() { glDeleteRenderbuffers(1, &renderbuffer); } From b7d6a7e67defaed3bd0b0b14bd5e0858002a4757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 20:19:09 +0200 Subject: [PATCH 015/256] De-inlined MeshTools::CompressIndices. The class doesn't export anything templated in its API, so it's a waste to have everything in the header. --- src/MeshTools/CMakeLists.txt | 1 + src/MeshTools/CompressIndices.cpp | 61 +++++++++++++++++++++++++++++++ src/MeshTools/CompressIndices.h | 45 +++++++---------------- src/MeshTools/Test/CMakeLists.txt | 2 +- 4 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 src/MeshTools/CompressIndices.cpp diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index e2b347f4b..095431bf7 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -1,5 +1,6 @@ # Files shared between main library and unit test library set(MagnumMeshTools_SRCS + CompressIndices.cpp Tipsify.cpp) set(MagnumMeshTools_HEADERS Clean.h diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp new file mode 100644 index 000000000..445f5378f --- /dev/null +++ b/src/MeshTools/CompressIndices.cpp @@ -0,0 +1,61 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "CompressIndices.h" + +#include +#include +#include + +#include "IndexedMesh.h" +#include "SizeTraits.h" + +namespace Magnum { namespace MeshTools { + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +std::tuple CompressIndices::operator()() const { + return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); +} + +void CompressIndices::operator()(IndexedMesh* mesh, Buffer::Usage usage) const { + size_t indexCount; + Type indexType; + char* data; + std::tie(indexCount, indexType, data) = operator()(); + + mesh->setIndexType(indexType); + mesh->setIndexCount(indices.size()); + mesh->indexBuffer()->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + + delete[] data; +} + +template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { + /* Create smallest possible version of index buffer */ + char* buffer = new char[indices.size()*sizeof(IndexType)]; + for(size_t i = 0; i != indices.size(); ++i) { + IndexType index = indices[i]; + memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); + } + + return std::make_tuple(indices.size(), TypeTraits::indexType(), buffer); +} + +} +#endif + +}} diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 4a6b2ac48..709041000 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -19,52 +19,33 @@ * @brief Function Magnum::MeshTools::compressIndices() */ -#include -#include -#include +#include +#include "Buffer.h" #include "TypeTraits.h" -#include "SizeTraits.h" -#include "IndexedMesh.h" -namespace Magnum { namespace MeshTools { +#include "magnumMeshToolsVisibility.h" + +namespace Magnum { + +class IndexedMesh; + +namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -class CompressIndices { +class MESHTOOLS_EXPORT CompressIndices { public: CompressIndices(const std::vector& indices): indices(indices) {} - inline std::tuple operator()() const { - return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); - } - - void operator()(IndexedMesh* mesh, Buffer::Usage usage) const { - size_t indexCount; - Type indexType; - char* data; - std::tie(indexCount, indexType, data) = operator()(); - - mesh->setIndexType(indexType); - mesh->setIndexCount(indices.size()); - mesh->indexBuffer()->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + std::tuple operator()() const; - delete[] data; - } + void operator()(IndexedMesh* mesh, Buffer::Usage usage) const; private: struct Compressor { - template static std::tuple run(const std::vector& indices) { - /* Create smallest possible version of index buffer */ - char* buffer = new char[indices.size()*sizeof(IndexType)]; - for(size_t i = 0; i != indices.size(); ++i) { - IndexType index = indices[i]; - memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); - } - - return std::make_tuple(indices.size(), TypeTraits::indexType(), buffer); - } + template static std::tuple run(const std::vector& indices); }; const std::vector& indices; diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index 830207055..0a4608faf 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -1,6 +1,6 @@ corrade_add_test2(MeshToolsCleanTest CleanTest.cpp) corrade_add_test2(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) -corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES Magnum) +corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test2(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsInterleaveTest InterleaveTest.cpp) From b8d18d01ece4c2c6cfaadd2168a4f5f6ac597527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Sep 2012 21:39:37 +0200 Subject: [PATCH 016/256] Using initializer lists in Primitives tests. --- src/Primitives/Test/CapsuleTest.cpp | 180 +++++++++++++-------------- src/Primitives/Test/UVSphereTest.cpp | 72 +++++------ 2 files changed, 126 insertions(+), 126 deletions(-) diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 983a8ed1f..45e16738f 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -39,55 +39,55 @@ void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 2, 3, 1.0f); CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ - Vector4(0.0f, -1.5f, 0.0f), + {0.0f, -1.5f, 0.0f}, - Vector4(0.0f, -1.20711f, 0.707107f), - Vector4(0.612372f, -1.20711f, -0.353553f), - Vector4(-0.612373f, -1.20711f, -0.353553f), + {0.0f, -1.20711f, 0.707107f}, + {0.612372f, -1.20711f, -0.353553f}, + {-0.612373f, -1.20711f, -0.353553f}, - Vector4(0.0f, -0.5f, 1.0f), - Vector4(0.866025f, -0.5f, -0.5f), - Vector4(-0.866025f, -0.5f, -0.5f), + {0.0f, -0.5f, 1.0f}, + {0.866025f, -0.5f, -0.5f}, + {-0.866025f, -0.5f, -0.5f}, - Vector4(0.0f, 0.0f, 1.0f), - Vector4(0.866025f, 0.0f, -0.5f), - Vector4(-0.866025f, 0.0f, -0.5f), + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, - Vector4(0.0f, 0.5f, 1.0f), - Vector4(0.866025f, 0.5f, -0.5f), - Vector4(-0.866025f, 0.5f, -0.5f), + {0.0f, 0.5f, 1.0f}, + {0.866025f, 0.5f, -0.5f}, + {-0.866025f, 0.5f, -0.5f}, - Vector4(0.0f, 1.20711f, 0.707107f), - Vector4(0.612372f, 1.20711f, -0.353553f), - Vector4(-0.612372f, 1.20711f, -0.353553f), + {0.0f, 1.20711f, 0.707107f}, + {0.612372f, 1.20711f, -0.353553f}, + {-0.612372f, 1.20711f, -0.353553f}, - Vector4(0.0f, 1.5f, 0.0f) + {0.0f, 1.5f, 0.0f} }), Container); CORRADE_COMPARE_AS(*capsule.normals(0), (vector{ - Vector3(0.0f, -1.0f, 0.0f), + {0.0f, -1.0f, 0.0f}, - Vector3(0.0f, -0.707107f, 0.707107f), - Vector3(0.612372f, -0.707107f, -0.353553f), - Vector3(-0.612373f, -0.707107f, -0.353553f), + {0.0f, -0.707107f, 0.707107f}, + {0.612372f, -0.707107f, -0.353553f}, + {-0.612373f, -0.707107f, -0.353553f}, - Vector3(0.0f, 0.0f, 1.0f), - Vector3(0.866025f, 0.0f, -0.5f), - Vector3(-0.866025f, 0.0f, -0.5f), + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, - Vector3(0.0f, 0.0f, 1.0f), - Vector3(0.866025f, 0.0f, -0.5f), - Vector3(-0.866025f, 0.0f, -0.5f), + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, - Vector3(0.0f, 0.0f, 1.0f), - Vector3(0.866025f, 0.0f, -0.5f), - Vector3(-0.866025f, 0.0f, -0.5f), + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, - Vector3(0.0f, 0.707107f, 0.707107f), - Vector3(0.612372f, 0.707107f, -0.353553f), - Vector3(-0.612372f, 0.707107f, -0.353553f), + {0.0f, 0.707107f, 0.707107f}, + {0.612372f, 0.707107f, -0.353553f}, + {-0.612372f, 0.707107f, -0.353553f}, - Vector3(0.0f, 1.0f, 0.0f) + {0.0f, 1.0f, 0.0f} }), Container); CORRADE_COMPARE_AS(*capsule.indices(), (vector{ @@ -104,65 +104,65 @@ void CapsuleTest::withTextureCoords() { Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ - Vector4(0.0f, -1.5f, 0.0f), - - Vector4(0.0f, -1.20711f, 0.707107f), - Vector4(0.612372f, -1.20711f, -0.353553f), - Vector4(-0.612373f, -1.20711f, -0.353553f), - Vector4(0.0f, -1.20711f, 0.707107f), - - Vector4(0.0f, -0.5f, 1.0f), - Vector4(0.866025f, -0.5f, -0.5f), - Vector4(-0.866025f, -0.5f, -0.5f), - Vector4(0.0f, -0.5f, 1.0f), - - Vector4(0.0f, 0.0f, 1.0f), - Vector4(0.866025f, 0.0f, -0.5f), - Vector4(-0.866025f, 0.0f, -0.5f), - Vector4(0.0f, 0.0f, 1.0f), - - Vector4(0.0f, 0.5f, 1.0f), - Vector4(0.866025f, 0.5f, -0.5f), - Vector4(-0.866025f, 0.5f, -0.5f), - Vector4(0.0f, 0.5f, 1.0f), - - Vector4(0.0f, 1.20711f, 0.707107f), - Vector4(0.612372f, 1.20711f, -0.353553f), - Vector4(-0.612372f, 1.20711f, -0.353553f), - Vector4(0.0f, 1.20711f, 0.707107f), - - Vector4(0.0f, 1.5f, 0.0f) + {0.0f, -1.5f, 0.0f}, + + {0.0f, -1.20711f, 0.707107f}, + {0.612372f, -1.20711f, -0.353553f}, + {-0.612373f, -1.20711f, -0.353553f}, + {0.0f, -1.20711f, 0.707107f}, + + {0.0f, -0.5f, 1.0f}, + {0.866025f, -0.5f, -0.5f}, + {-0.866025f, -0.5f, -0.5f}, + {0.0f, -0.5f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.866025f, 0.0f, -0.5f}, + {-0.866025f, 0.0f, -0.5f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.5f, 1.0f}, + {0.866025f, 0.5f, -0.5f}, + {-0.866025f, 0.5f, -0.5f}, + {0.0f, 0.5f, 1.0f}, + + {0.0f, 1.20711f, 0.707107f}, + {0.612372f, 1.20711f, -0.353553f}, + {-0.612372f, 1.20711f, -0.353553f}, + {0.0f, 1.20711f, 0.707107f}, + + {0.0f, 1.5f, 0.0f} }), Container); CORRADE_COMPARE_AS(*capsule.textureCoords2D(0), (vector{ - Vector2(0.5f, 0.0f), - - Vector2(0.0f, 0.166667f), - Vector2(0.333333f, 0.166667f), - Vector2(0.666667f, 0.166667f), - Vector2(1.0f, 0.166667f), - - Vector2(0.0f, 0.333333f), - Vector2(0.333333f, 0.333333f), - Vector2(0.666667f, 0.333333f), - Vector2(1.0f, 0.333333f), - - Vector2(0.0f, 0.5f), - Vector2(0.333333f, 0.5f), - Vector2(0.666667f, 0.5f), - Vector2(1.0f, 0.5f), - - Vector2(0.0f, 0.666667f), - Vector2(0.333333f, 0.666667f), - Vector2(0.666667f, 0.666667f), - Vector2(1.0f, 0.666667f), - - Vector2(0.0f, 0.833333f), - Vector2(0.333333f, 0.833333f), - Vector2(0.666667f, 0.833333f), - Vector2(1.0f, 0.833333f), - - Vector2(0.5f, 1.0f) + {0.5f, 0.0f}, + + {0.0f, 0.166667f}, + {0.333333f, 0.166667f}, + {0.666667f, 0.166667f}, + {1.0f, 0.166667f}, + + {0.0f, 0.333333f}, + {0.333333f, 0.333333f}, + {0.666667f, 0.333333f}, + {1.0f, 0.333333f}, + + {0.0f, 0.5f}, + {0.333333f, 0.5f}, + {0.666667f, 0.5f}, + {1.0f, 0.5f}, + + {0.0f, 0.666667f}, + {0.333333f, 0.666667f}, + {0.666667f, 0.666667f}, + {1.0f, 0.666667f}, + + {0.0f, 0.833333f}, + {0.333333f, 0.833333f}, + {0.666667f, 0.833333f}, + {1.0f, 0.833333f}, + + {0.5f, 1.0f} }), Container); CORRADE_COMPARE_AS(*capsule.indices(), (vector{ diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 3ffd66937..269c52419 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -36,31 +36,31 @@ void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ - Vector4(0.0f, -1.0f, 0.0f), + {0.0f, -1.0f, 0.0f}, - Vector4(0.0f, -0.5f, 0.866025f), - Vector4(0.75f, -0.5f, -0.433013f), - Vector4(-0.75f, -0.5f, -0.433013f), + {0.0f, -0.5f, 0.866025f}, + {0.75f, -0.5f, -0.433013f}, + {-0.75f, -0.5f, -0.433013f}, - Vector4(0, 0.5f, 0.866025f), - Vector4(0.75f, 0.5f, -0.433013f), - Vector4(-0.75f, 0.5f, -0.433013f), + {0, 0.5f, 0.866025f}, + {0.75f, 0.5f, -0.433013f}, + {-0.75f, 0.5f, -0.433013f}, - Vector4(0.0f, 1.0f, 0.0f) + {0.0f, 1.0f, 0.0f} }), Container); CORRADE_COMPARE_AS(*sphere.normals(0), (vector{ - Vector3(0.0f, -1.0f, 0.0f), + {0.0f, -1.0f, 0.0f}, - Vector3(0.0f, -0.5f, 0.866025f), - Vector3(0.75f, -0.5f, -0.433013f), - Vector3(-0.75f, -0.5f, -0.433013f), + {0.0f, -0.5f, 0.866025f}, + {0.75f, -0.5f, -0.433013f}, + {-0.75f, -0.5f, -0.433013f}, - Vector3(0, 0.5f, 0.866025f), - Vector3(0.75f, 0.5f, -0.433013f), - Vector3(-0.75f, 0.5f, -0.433013f), + {0, 0.5f, 0.866025f}, + {0.75f, 0.5f, -0.433013f}, + {-0.75f, 0.5f, -0.433013f}, - Vector3(0.0f, 1.0f, 0.0f) + {0.0f, 1.0f, 0.0f} }), Container); CORRADE_COMPARE_AS(*sphere.indices(), (vector{ @@ -74,35 +74,35 @@ void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ - Vector4(0.0f, -1.0f, 0.0f), + {0.0f, -1.0f, 0.0f}, - Vector4(0.0f, -0.5f, 0.866025f), - Vector4(0.75f, -0.5f, -0.433013f), - Vector4(-0.75f, -0.5f, -0.433013f), - Vector4(0.0f, -0.5f, 0.866025f), + {0.0f, -0.5f, 0.866025f}, + {0.75f, -0.5f, -0.433013f}, + {-0.75f, -0.5f, -0.433013f}, + {0.0f, -0.5f, 0.866025f}, - Vector4(0.0f, 0.5f, 0.866025f), - Vector4(0.75f, 0.5f, -0.433013f), - Vector4(-0.75f, 0.5f, -0.433013f), - Vector4(0.0f, 0.5f, 0.866025f), + {0.0f, 0.5f, 0.866025f}, + {0.75f, 0.5f, -0.433013f}, + {-0.75f, 0.5f, -0.433013f}, + {0.0f, 0.5f, 0.866025f}, - Vector4(0.0f, 1.0f, 0.0f) + {0.0f, 1.0f, 0.0f} }), Container); CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (vector{ - Vector2(0.5f, 0.0f), + {0.5f, 0.0f}, - Vector2(0.0f, 0.333333f), - Vector2(0.333333f, 0.333333f), - Vector2(0.666667f, 0.333333f), - Vector2(1.0f, 0.333333f), + {0.0f, 0.333333f}, + {0.333333f, 0.333333f}, + {0.666667f, 0.333333f}, + {1.0f, 0.333333f}, - Vector2(0.0f, 0.666667f), - Vector2(0.333333f, 0.666667f), - Vector2(0.666667f, 0.666667f), - Vector2(1.0f, 0.666667f), + {0.0f, 0.666667f}, + {0.333333f, 0.666667f}, + {0.666667f, 0.666667f}, + {1.0f, 0.666667f}, - Vector2(0.5f, 1.0f) + {0.5f, 1.0f} }), Container); CORRADE_COMPARE_AS(*sphere.indices(), (vector{ From 6b5c20bc835c375e8745c6c154485f1a763a8ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 01:21:38 +0200 Subject: [PATCH 017/256] Grouped global mesh settings together. --- src/Mesh.h | 96 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index e02b026c1..690612fb3 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -51,6 +51,8 @@ class MAGNUM_EXPORT Mesh { Mesh& operator=(const Mesh& other) = delete; public: + /** @name Polygon drawing settings */ + #ifndef MAGNUM_TARGET_GLES /** * @brief Polygon mode @@ -77,6 +79,54 @@ class MAGNUM_EXPORT Mesh { }; #endif + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Set polygon drawing mode + * + * Initial value is PolygonMode::Fill. + * @requires_gl + */ + inline static void setPolygonMode(PolygonMode mode) { + glPolygonMode(GL_FRONT_AND_BACK, static_cast(mode)); + } + #endif + + /** + * @brief Set line width + * + * Initial value is 1. + */ + inline static void setLineWidth(GLfloat width) { + glLineWidth(width); + } + + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Set point size + * + * @see setProgramPointSize() + * @requires_gl Set directly in vertex shader using @c gl_PointSize + * builtin variable. + */ + inline static void setPointSize(GLfloat size) { + glPointSize(size); + } + + /** + * @brief Enable/disable programmable point size + * + * If enabled, the point size is taken from vertex/geometry shader + * builtin `gl_PointSize`. + * @see setPointSize() + * @requires_gl Always enabled. + */ + inline static void setProgramPointSize(bool enabled) { + enabled ? glEnable(GL_PROGRAM_POINT_SIZE) : glDisable(GL_PROGRAM_POINT_SIZE); + } + #endif + + /*@}*/ + /** * @brief Primitive type * @@ -136,52 +186,6 @@ class MAGNUM_EXPORT Mesh { NonInterleaved /**< Non-interleaved buffer */ }; - #ifndef MAGNUM_TARGET_GLES - /** - * @brief Set polygon drawing mode - * - * Initial value is PolygonMode::Fill. - * @requires_gl - */ - inline static void setPolygonMode(PolygonMode mode) { - glPolygonMode(GL_FRONT_AND_BACK, static_cast(mode)); - } - #endif - - /** - * @brief Set line width - * - * Initial value is 1. - */ - inline static void setLineWidth(GLfloat width) { - glLineWidth(width); - } - - #ifndef MAGNUM_TARGET_GLES - /** - * @brief Set point size - * - * @see setProgramPointSize() - * @requires_gl Set directly in vertex shader using @c gl_PointSize - * builtin variable. - */ - inline static void setPointSize(GLfloat size) { - glPointSize(size); - } - - /** - * @brief Enable/disable programmable point size - * - * If enabled, the point size is taken from vertex/geometry shader - * builtin `gl_PointSize`. - * @see setPointSize() - * @requires_gl Always enabled. - */ - inline static void setProgramPointSize(bool enabled) { - enabled ? glEnable(GL_PROGRAM_POINT_SIZE) : glDisable(GL_PROGRAM_POINT_SIZE); - } - #endif - /** * @brief Implicit constructor * @param primitive Primitive type From 7d3435f4831782fcde6c6a1027eb61537cb7e2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 01:22:14 +0200 Subject: [PATCH 018/256] SceneGraph: method chaining also for Camera. Mention it also in documentation to hint users to use it. --- src/SceneGraph/Camera.cpp | 12 ++++++++---- src/SceneGraph/Camera.h | 16 +++++++++++----- src/SceneGraph/Object.h | 7 +++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 13484dfdc..b73cb61d2 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -47,9 +47,10 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons template Camera::Camera(ObjectType* parent): ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template void Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template CameraType* Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); + return static_cast(this); } template void Camera::setViewport(const Math::Vector2& size) { @@ -82,14 +83,15 @@ templateCorrade::Containers::LinkedList::move(this, under); @@ -333,6 +337,7 @@ class SCENEGRAPH_EXPORT Object3D: public Object Date: Fri, 7 Sep 2012 01:35:34 +0200 Subject: [PATCH 019/256] Doc++ * Workarounds for unsupported features in OpenGL ES. * Initial values for some states. --- src/Mesh.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index 690612fb3..79862c109 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -58,11 +58,13 @@ class MAGNUM_EXPORT Mesh { * @brief Polygon mode * * @see setPolygonMode() - * @requires_gl + * @requires_gl OpenGL ES behaves always like + * PolygonMode::%Fill. See setPrimitive() for possible + * workaround. */ enum class PolygonMode: GLenum { /** - * Interior of the polygon is filled. + * Interior of the polygon is filled (default). */ Fill = GL_FILL, @@ -83,8 +85,9 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set polygon drawing mode * - * Initial value is PolygonMode::Fill. - * @requires_gl + * Initial value is `PolygonMode::%Fill`. + * @requires_gl OpenGL ES behaves always like the default. See + * setPrimitive() for possible workaround. */ inline static void setPolygonMode(PolygonMode mode) { glPolygonMode(GL_FRONT_AND_BACK, static_cast(mode)); @@ -104,6 +107,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set point size * + * Initial value is `1.0f`. * @see setProgramPointSize() * @requires_gl Set directly in vertex shader using @c gl_PointSize * builtin variable. @@ -116,9 +120,9 @@ class MAGNUM_EXPORT Mesh { * @brief Enable/disable programmable point size * * If enabled, the point size is taken from vertex/geometry shader - * builtin `gl_PointSize`. + * builtin `gl_PointSize`. Initially disabled on desktop OpenGL. * @see setPointSize() - * @requires_gl Always enabled. + * @requires_gl Always enabled on OpenGL ES. */ inline static void setProgramPointSize(bool enabled) { enabled ? glEnable(GL_PROGRAM_POINT_SIZE) : glDisable(GL_PROGRAM_POINT_SIZE); From fd1ae3f775a9fb0d72715b03f594f9bdde056756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 02:25:09 +0200 Subject: [PATCH 020/256] Mesh: added support for provoking vertex selection. --- src/Mesh.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Mesh.h b/src/Mesh.h index 79862c109..532902454 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -39,7 +39,6 @@ VAOs are used for desktop OpenGL (not in OpenGL ES). @todo Support for normalized values (e.g. for color as char[4] passed to shader as floating-point vec4) -@todo Support for provoking vertex (OpenGL 3.2, @extension{ARB,provoking_vertex}) @todo Support for packed unsigned integer types for attributes (OpenGL 3.3, @extension{ARB,vertex_type_2_10_10_10_rev}) @todo Support for fixed precision type for attributes (OpenGL 4.1, @extension{ARB,ES2_compatibility}) @todo Support for double type for attributes (OpenGL 4.1, @extension{ARB,vertex_attrib_64bit}) @@ -53,6 +52,36 @@ class MAGNUM_EXPORT Mesh { public: /** @name Polygon drawing settings */ + /** + * @brief Provoking vertex + * + * @see setProvokingVertex() + * @requires_gl OpenGL ES behaves always like + * ProvokingMode::%LastVertexConvention. + * @requires_gl32 Extension @extension{ARB,provoking_vertex}. Older + * versions behave always like + * ProvokingMode::%LastVertexConvention. + */ + enum class ProvokingVertex: GLenum { + /** @brief Use first vertex of each polygon. */ + FirstVertexConvention = GL_FIRST_VERTEX_CONVENTION, + + /** @brief Use last vertex of each polygon (default). */ + LastVertexConvention = GL_LAST_VERTEX_CONVENTION + }; + + /** + * @brief Set provoking vertex + * + * Initial value is ProvokingMode::%LastVertexConvention. + * @requires_gl OpenGL ES behaves always like the default. + * @requires_gl32 Extension @extension{ARB,provoking_vertex}. Older + * versions behave always like the default. + */ + inline static void setProvokingVertex(ProvokingVertex mode) { + glProvokingVertex(static_cast(mode)); + } + #ifndef MAGNUM_TARGET_GLES /** * @brief Polygon mode From d5614a2f2c0ecfb666a80df9553562bf60ec633a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 02:25:29 +0200 Subject: [PATCH 021/256] Mesh: added support for polygon offset. --- src/Mesh.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/Mesh.h b/src/Mesh.h index 532902454..d4bd94987 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -123,6 +123,50 @@ class MAGNUM_EXPORT Mesh { } #endif + /** + * @brief Mode affected by polygon offset + * + * @see setPolygonOffsetMode(), setPolygonOffset() + */ + enum class PolygonOffsetMode: GLenum { + /** Offset filled polygons. */ + Fill = GL_POLYGON_OFFSET_FILL, + + /** + * Offset lines. + * @requires_gl Only PolygonOffset::%Fill is supported. + */ + Line = GL_POLYGON_OFFSET_LINE, + + /** + * Offset points. + * @requires_gl Only PolygonOffset::%Fill is supported. + */ + Point = GL_POLYGON_OFFSET_POINT + }; + + /** + * @brief Enable/disable polygon offset for given mode + * + * Initially disabled for all modes. + * @see setPolygonOffset() + */ + inline static void setPolygonOffsetMode(PolygonOffsetMode mode, bool enabled) { + enabled ? glEnable(static_cast(mode)) : glDisable(static_cast(mode)); + } + + /** + * @brief Set polygon offset + * @param factor Scale factor + * @param units Offset units + * + * @attention You have to call setPolygonOffsetMode() to enable + * polygon offset for desired polygon modes. + */ + inline static void setPolygonOffset(GLfloat factor, GLfloat units) { + glPolygonOffset(factor, units); + } + /** * @brief Set line width * From dfb4e0f8076528d3668a910f0456628d923a1381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 02:43:00 +0200 Subject: [PATCH 022/256] Mesh: ability to specify which polygons are front facing. --- src/Mesh.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Mesh.h b/src/Mesh.h index d4bd94987..dd7972adf 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -52,6 +52,28 @@ class MAGNUM_EXPORT Mesh { public: /** @name Polygon drawing settings */ + /** + * @brief Front facing polygon winding + * + * @see setFrontFace() + */ + enum FrontFace: GLenum { + /** @brief Counterclockwise polygons are front facing (default). */ + CounterClockWise = GL_CCW, + + /** @brief Clockwise polygons are front facing. */ + ClockWise = GL_CW + }; + + /** + * @brief Set front-facing polygon winding + * + * Initial value is `FrontFace::%CounterClockWise`. + */ + void setFrontFace(FrontFace mode) { + glFrontFace(static_cast(mode)); + } + /** * @brief Provoking vertex * From 0bf1b620803ee902a22cec03419dd2558a35a0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 02:42:35 +0200 Subject: [PATCH 023/256] Framebuffer: ability to specify which polygon facing to cull --- src/Framebuffer.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index f9eb59fce..268714b0d 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -53,6 +53,20 @@ class MAGNUM_EXPORT Framebuffer { Framebuffer& operator=(Framebuffer&& other) = delete; public: + /** + * @brief Affected polygon facing for culling, stencil operations and masks + * + * @see setFaceCullingMode(), + * setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint), + * setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation), + * setStencilMask(PolygonFacing, GLuint) + */ + enum class PolygonFacing: GLenum { + Front = GL_FRONT, /**< Front-facing polygons */ + Back = GL_BACK, /**< Back-facing polygons */ + FrontAndBack = GL_FRONT_AND_BACK /**< Front- and back-facing polygons */ + }; + /** @{ @name Framebuffer features */ /** @@ -100,6 +114,17 @@ class MAGNUM_EXPORT Framebuffer { enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); } + /** + * @brief Which polygon facing to cull + * + * Initial value is `PolygonFacing::Back`. If set to both front and + * back, only points and lines are drawn. + * @attention You have to also enable face culling with setFeature(). + */ + inline static void setFaceCullingMode(PolygonFacing mode) { + glCullFace(static_cast(mode)); + } + /** * @brief Set viewport size * @@ -190,19 +215,6 @@ class MAGNUM_EXPORT Framebuffer { /** @{ @name Stencil operations */ - /** - * @brief Affected polygon facing for stencil operations and masks - * - * @see setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint), - * setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation), - * setStencilMask(PolygonFacing, GLuint) - */ - enum class PolygonFacing: GLenum { - Front = GL_FRONT, /**< Front-facing polygons */ - Back = GL_BACK, /**< Back-facing polygons */ - FrontAndBack = GL_FRONT_AND_BACK /**< Front- and back-facing polygons */ - }; - /** * @brief Stencil function * From f3a07f82f4a67c66d234b2b9a1d868a00d68ca77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 03:07:01 +0200 Subject: [PATCH 024/256] Method chaining for textures. --- src/AbstractTexture.cpp | 10 ++++++---- src/AbstractTexture.h | 18 +++++++++++++----- src/CubeMapTexture.h | 11 ++++++++--- src/CubeMapTextureArray.h | 14 ++++++++++---- src/Texture.h | 12 +++++++++--- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index fdce8c9ea..8def7f62b 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -48,23 +48,25 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() { } #endif -void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { +AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", ); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif bind(); glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, static_cast(filter)|static_cast(mipmap)); + return this; } -void AbstractTexture::generateMipmap() { +AbstractTexture* AbstractTexture::generateMipmap() { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", ); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif bind(); glGenerateMipmap(_target); + return this; } #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 5dd213d17..c3dec918a 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -587,6 +587,7 @@ class MAGNUM_EXPORT AbstractTexture { * @param mipmap Mipmap filtering. If set to anything else than * BaseMipLevel, make sure textures for all mip levels are set or * call generateMipmap(). + * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is smaller than the * texture size. @@ -595,55 +596,62 @@ class MAGNUM_EXPORT AbstractTexture { * @ref AbstractTexture::Mipmap "Mipmap" documentation for more * information. */ - void setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); + AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); /** * @brief Set magnification filter * @param filter Filter + * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is larger than largest * texture size. */ - inline void setMagnificationFilter(Filter filter) { + inline AbstractTexture* setMagnificationFilter(Filter filter) { bind(); glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast(filter)); + return this; } #ifndef MAGNUM_TARGET_GLES /** * @brief Set border color + * @return Pointer to self (for method chaining) * * Border color when @ref AbstractTexture::Wrapping "wrapping" is set * to `ClampToBorder`. * @requires_gl */ - inline void setBorderColor(const Color4& color) { + inline AbstractTexture* setBorderColor(const Color4& color) { bind(); glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); + return this; } /** * @brief Set max anisotropy + * @return Pointer to self (for method chaining) * * Default value is `1.0`, which means no anisotropy. Set to value * greater than `1.0` for anisotropic filtering. * @see maxSupportedAnisotropy() * @requires_extension @extension{EXT,texture_filter_anisotropic} */ - inline void setMaxAnisotropy(GLfloat anisotropy) { + inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { bind(); glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); + return this; } #endif /** * @brief Generate mipmap + * @return Pointer to self (for method chaining) * * Can not be used for rectangle textures. * @see setMinificationFilter() * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - void generateMipmap(); + AbstractTexture* generateMipmap(); protected: #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 44ae71fce..9ce2ae96d 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -81,27 +81,32 @@ class CubeMapTexture: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { bind(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); + return this; } /** * @copydoc Texture::setData(GLint, InternalFormat, Image*) * @param coordinate Coordinate + * @return Pointer to self (for method chaining) */ - template inline void setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); + return this; } /** * @copydoc Texture::setSubData(GLint, const Math::Vector&, Image*) * @param coordinate Coordinate + * @return Pointer to self (for method chaining) */ - template inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { bind(); DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); + return this; } }; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0a1f0ebca..2f5801147 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -66,9 +66,10 @@ class CubeMapTextureArray: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { bind(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); + return this; } /** @@ -78,9 +79,10 @@ class CubeMapTextureArray: public AbstractTexture { * for all layers. Each group of 6 2D images is one cube map layer. * The images are ordered the same way as Coordinate enum. */ - template inline void setData(GLint mipLevel, InternalFormat internalFormat, T* image) { + template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { bind(); DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + return this; } /** @@ -89,6 +91,7 @@ class CubeMapTextureArray: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Three-dimensional Image, BufferedImage or for * example Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. @@ -100,9 +103,10 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ - template inline void setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { + template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { bind(); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + return this; } /** @@ -113,15 +117,17 @@ class CubeMapTextureArray: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Two-dimensional Image, BufferedImage or for * example Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. * * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ - template inline void setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { bind(); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + return this; } }; diff --git a/src/Texture.h b/src/Texture.h index d31d2039b..61f1013b3 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -114,6 +114,7 @@ template class Texture: public AbstractTexture { /** * @brief Set wrapping * @param wrapping Wrapping type for all texture dimensions + * @return Pointer to self (for method chaining) * * Sets wrapping type for coordinates out of range (0, 1) for normal * textures and (0, textureSizeInGivenDirection-1) for rectangle @@ -122,9 +123,10 @@ template class Texture: public AbstractTexture { * see @ref AbstractTexture::Wrapping "Wrapping" documentation for * more information. */ - inline void setWrapping(const Math::Vector& wrapping) { + inline Texture* setWrapping(const Math::Vector& wrapping) { bind(); DataHelper::setWrapping(_target, wrapping); + return this; } /** @@ -133,13 +135,15 @@ template class Texture: public AbstractTexture { * @param internalFormat Internal texture format * @param image Image, BufferedImage or for example * Trade::ImageData of the same dimension count + * @return Pointer to self (for method chaining) * * Sets texture data from given image. The image is not deleted * afterwards. */ - template inline void setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); DataHelper::set(_target, mipLevel, internalFormat, image); + return this; } /** @@ -148,6 +152,7 @@ template class Texture: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Image, BufferedImage or for example * Trade::ImageData + * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted * afterwards. The image can have either the same dimension count or @@ -158,9 +163,10 @@ template class Texture: public AbstractTexture { * for e.g. updating 3D texture with multiple 2D images or for filling * 1D texture array (which is two-dimensional) with 1D images. */ - template inline void setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { + template inline Texture* setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { bind(); DataHelper::setSub(_target, mipLevel, offset, image); + return this; } }; From 035bd4d376a43db0efb8a7c1cb73897c05436409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 15:42:02 +0200 Subject: [PATCH 025/256] Links to documentation of related gl*() function. Each function touching OpenGL now has list of all related functions touching OpenGL. --- Doxyfile | 2 + src/AbstractShaderProgram.h | 32 +++++++++++----- src/AbstractTexture.h | 15 ++++++-- src/Buffer.h | 26 ++++++++++++- src/BufferedImage.h | 7 ++++ src/BufferedTexture.h | 19 ++++++++-- src/CubeMapTexture.h | 2 + src/CubeMapTextureArray.h | 2 + src/Framebuffer.h | 76 ++++++++++++++++++++++++++++--------- src/IndexedMesh.h | 14 ++++++- src/Mesh.h | 41 +++++++++++++++----- src/Query.h | 16 +++++++- src/Renderbuffer.h | 10 ++++- src/Shader.h | 7 +++- src/Texture.h | 4 ++ 15 files changed, 221 insertions(+), 52 deletions(-) diff --git a/Doxyfile b/Doxyfile index a9b8a684f..d534db6af 100644 --- a/Doxyfile +++ b/Doxyfile @@ -200,6 +200,8 @@ ALIASES = \ "configurationvalue{1}=@brief %Configuration value parser and writer @xrefitem configurationvalues \"Configuration value parser and writer\" \"Configuration value parsers and writers for custom types\" Allows parsing and writing \1 from and to Corrade::Utility::Configuration." \ "collisionoperator{2}=@relates \1\n@brief Collision of %\1 and %\2\n@see \2::operator%(const \1&) const" \ "todoc=@xrefitem todoc \"Documentation todo\" \"Documentation-related todo list\"" \ + "fn_gl{1}=gl\1()" \ + "def_gl{1}=`GL_\1`" \ "requires_gl=@xrefitem requires-gl \"Requires desktop OpenGL\" \"Functionality requiring desktop OpenGL (not available on OpenGL ES)\" Not available on OpenGL ES." \ "requires_gl30=@xrefitem requires-gl30 \"Requires OpenGL 3.0\" \"Functionality requiring OpenGL 3.0\"" \ "requires_gl31=@xrefitem requires-gl31 \"Requires OpenGL 3.1\" \"Functionality requiring OpenGL 3.1\"" \ diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 510850e18..33be5bb23 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -192,6 +192,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @brief Constructor * * Creates one OpenGL shader program. + * @see @fn_gl{CreateProgram} */ inline AbstractShaderProgram(): state(Initialized) { program = glCreateProgram(); @@ -201,6 +202,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @brief Destructor * * Deletes associated OpenGL shader program. + * @see @fn_gl{DeleteProgram} */ virtual ~AbstractShaderProgram() = 0; @@ -208,6 +210,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @brief Use shader * @return False if the program wasn't successfully linked, true * otherwise. + * + * @see @fn_gl{UseProgram} */ bool use(); @@ -216,11 +220,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @brief Allow retrieving program binary * - * Disabled by default. - * @requires_gl - * @requires_gl41 Extension @extension{ARB,get_program_binary} + * Initially disabled. * @note This function should be called after attachShader() calls and * before link(). + * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_BINARY_RETRIEVABLE_HINT} + * @requires_gl + * @requires_gl41 Extension @extension{ARB,get_program_binary} */ inline void setRetrievableBinary(bool enabled) { glProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, enabled ? GL_TRUE : GL_FALSE); @@ -229,11 +234,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @brief Allow the program to be bound to individual pipeline stages * - * Disabled by default. - * @requires_gl - * @requires_gl41 Extension @extension{ARB,separate_shader_objects} + * Initially disabled. * @note This function should be called after attachShader() calls and * before link(). + * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_SEPARABLE} + * @requires_gl + * @requires_gl41 Extension @extension{ARB,separate_shader_objects} */ inline void setSeparable(bool enabled) { glProgramParameteri(program, GL_PROGRAM_SEPARABLE, enabled ? GL_TRUE : GL_FALSE); @@ -247,10 +253,11 @@ class MAGNUM_EXPORT AbstractShaderProgram { * * Compiles the shader, if it is not already, and prepares it for * linking. + * @see Shader::compile(), @fn_gl{AttachShader} */ bool attachShader(Shader& shader); - /** @copydoc attachShader(Shader&) */ + /** @overload */ inline bool attachShader(Shader&& shader) { return attachShader(shader); } @@ -268,6 +275,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * explicitly in the shader instead of using this function. See * @ref AbstractShaderProgram-attribute-location "class documentation" * for more information. + * @see @fn_gl{BindAttribLocation} */ void bindAttributeLocation(GLuint location, const std::string& name); @@ -281,14 +289,15 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Binds fragment data to location which is used later for framebuffer * operations. See also Framebuffer::BlendFunction for more * information about using color input index. - * @requires_gl - * @requires_gl33 Extension @extension{ARB,blend_func_extended} * @note This function should be called after attachShader() calls and * before link(). * @deprecated Preferred usage is to specify attribute location * explicitly in the shader instead of using this function. See * @ref AbstractShaderProgram-attribute-location "class documentation" * for more information. + * @see @fn_gl{BindFragDataLocationIndexed} + * @requires_gl + * @requires_gl33 Extension @extension{ARB,blend_func_extended} */ void bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name); @@ -299,6 +308,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * * The same as bindFragmentDataLocationIndexed(), but with `index` set * to `0`. + * @see @fn_gl{BindFragDataLocation} * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} */ @@ -310,6 +320,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * * Binds previously specified attributes to given indexes and links the * shader program together. + * @see @fn_gl{LinkProgram}, @fn_gl{GetProgram} with + * @def_gl{LINK_STATUS}, @fn_gl{GetProgramInfoLog} */ void link(); @@ -318,6 +330,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @param name Uniform name * * @note This function should be called after link(). + * @see @fn_gl{GetUniformLocation} */ GLint uniformLocation(const std::string& name); @@ -327,6 +340,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @param value Value * * @attention This function doesn't check whether this shader is in use! + * @see @fn_gl{Uniform} */ inline void setUniform(GLint location, GLfloat value) { glUniform1f(location, value); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index c3dec918a..3549b2343 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -535,7 +535,7 @@ class MAGNUM_EXPORT AbstractTexture { * @brief Max supported layer count * * At least 48. - * @see bind(GLint) + * @see bind(GLint), @fn_gl{Get} with @def_gl{MAX_COMBINED_TEXTURE_IMAGE_UNITS} */ static GLint maxSupportedLayerCount(); @@ -543,7 +543,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * @brief Max supported anisotropy * - * @see setMaxAnisotropy() + * @see setMaxAnisotropy(), @fn_gl{Get} with @def_gl{MAX_TEXTURE_MAX_ANISOTROPY_EXT} * @requires_extension @extension{EXT,texture_filter_anisotropic} */ static GLfloat maxSupportedAnisotropy(); @@ -554,6 +554,7 @@ class MAGNUM_EXPORT AbstractTexture { * @param target Target, e.g. `GL_TEXTURE_2D`. * * Creates one OpenGL texture. + * @see @fn_gl{GenTextures} */ inline AbstractTexture(GLenum target): _target(target) { glGenTextures(1, &texture); @@ -563,6 +564,7 @@ class MAGNUM_EXPORT AbstractTexture { * @brief Destructor * * Deletes assigned OpenGL texture. + * @see @fn_gl{DeleteTextures} */ virtual ~AbstractTexture() = 0; @@ -575,6 +577,7 @@ class MAGNUM_EXPORT AbstractTexture { * Sets current texture as active in given layer. The layer must be * between 0 and maxSupportedLayerCount(). Note that only one texture * can be bound to given layer. + * @see bind(), @fn_gl{ActiveTexture} */ inline void bind(GLint layer) { glActiveTexture(GL_TEXTURE0 + layer); @@ -595,6 +598,7 @@ class MAGNUM_EXPORT AbstractTexture { * see @ref AbstractTexture::Filter "Filter" and * @ref AbstractTexture::Mipmap "Mipmap" documentation for more * information. + * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MIN_FILTER} */ AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); @@ -605,6 +609,7 @@ class MAGNUM_EXPORT AbstractTexture { * * Sets filter used when the object pixel size is larger than largest * texture size. + * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAG_FILTER} */ inline AbstractTexture* setMagnificationFilter(Filter filter) { bind(); @@ -619,6 +624,7 @@ class MAGNUM_EXPORT AbstractTexture { * * Border color when @ref AbstractTexture::Wrapping "wrapping" is set * to `ClampToBorder`. + * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_BORDER_COLOR} * @requires_gl */ inline AbstractTexture* setBorderColor(const Color4& color) { @@ -633,7 +639,7 @@ class MAGNUM_EXPORT AbstractTexture { * * Default value is `1.0`, which means no anisotropy. Set to value * greater than `1.0` for anisotropic filtering. - * @see maxSupportedAnisotropy() + * @see maxSupportedAnisotropy(), bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} * @requires_extension @extension{EXT,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { @@ -648,7 +654,7 @@ class MAGNUM_EXPORT AbstractTexture { * @return Pointer to self (for method chaining) * * Can not be used for rectangle textures. - * @see setMinificationFilter() + * @see setMinificationFilter(), @fn_gl{GenerateMipmap} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ AbstractTexture* generateMipmap(); @@ -665,6 +671,7 @@ class MAGNUM_EXPORT AbstractTexture { * * Unlike bind(GLint) doesn't bind the texture to any particular * layer, thus unusable for binding for rendering. + * @see @fn_gl{BindTexture} */ inline void bind() { glBindTexture(_target, texture); diff --git a/src/Buffer.h b/src/Buffer.h index 4c3607234..15ccda925 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -109,7 +109,7 @@ class Buffer { #endif }; - /** @brief Buffer usage */ + /** @brief %Buffer usage */ enum class Usage: GLenum { /** * Set once by the application and used infrequently for drawing. @@ -181,6 +181,8 @@ class Buffer { /** * @brief Unbind any buffer from given target * @param target %Target + * + * @see @fn_gl{BindBuffer} */ inline static void unbind(Target target) { glBindBuffer(static_cast(target), 0); @@ -192,6 +194,7 @@ class Buffer { * without parameter) * * Generates new OpenGL buffer. + * @see @fn_gl{GenBuffers} */ inline Buffer(Target defaultTarget): _defaultTarget(defaultTarget) { glGenBuffers(1, &buffer); @@ -201,6 +204,7 @@ class Buffer { * @brief Destructor * * Deletes associated OpenGL buffer. + * @see @fn_gl{DeleteBuffers} */ inline virtual ~Buffer() { glDeleteBuffers(1, &buffer); @@ -216,12 +220,15 @@ class Buffer { * @brief Bind buffer * * Binds buffer with default target. + * @see bind(Target) */ inline void bind() { bind(_defaultTarget); } /** * @brief Bind buffer * @param target %Target + * + * @see @fn_gl{BindBuffer} */ inline void bind(Target target) { glBindBuffer(static_cast(target), buffer); @@ -234,6 +241,7 @@ class Buffer { * @param usage %Buffer usage * * Sets buffer data with default target. + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { setData(_defaultTarget, size, data, usage); @@ -247,6 +255,7 @@ class Buffer { * Sets buffer data with default target. More convenient for setting * data from fixed-size arrays than * setData(GLsizeiptr, const GLvoid*, Usage). + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ template inline void setData(const T(&data)[size], Usage usage) { setData(_defaultTarget, data, usage); @@ -258,6 +267,7 @@ class Buffer { * @param usage %Buffer usage * * Sets buffer data with default target. + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ template inline void setData(const std::vector& data, Usage usage) { setData(_defaultTarget, data, usage); @@ -269,6 +279,8 @@ class Buffer { * @param size Data size * @param data Pointer to data * @param usage %Buffer usage + * + * @see bind(Target), @fn_gl{BufferData} */ inline void setData(Target target, GLsizeiptr size, const GLvoid* data, Usage usage) { bind(target); @@ -283,6 +295,8 @@ class Buffer { * * More convenient for setting data from fixed-size arrays than * setData(Target, GLsizeiptr, const GLvoid*, Usage). + * + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ template inline void setData(Target target, const T(&data)[size], Usage usage) { setData(target, size*sizeof(T), data, usage); @@ -293,6 +307,8 @@ class Buffer { * @param target %Target * @param data Vector with data * @param usage %Buffer usage + * + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ template inline void setData(Target target, const std::vector& data, Usage usage) { setData(target, data.size()*sizeof(T), data.data(), usage); @@ -305,6 +321,7 @@ class Buffer { * @param data Pointer to data * * Sets buffer subdata with default target. + * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { setSubData(_defaultTarget, offset, size, data); @@ -318,6 +335,7 @@ class Buffer { * Sets buffer subdata with default target. More convenient for * setting data from fixed-size arrays than * setSubData(GLintptr, GLsizeiptr, const GLvoid*). + * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(GLintptr offset, const T(&data)[size]) { setSubData(_defaultTarget, offset, data); @@ -329,6 +347,7 @@ class Buffer { * @param data Vector with data * * Sets buffer subdata with default target. + * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(GLintptr offset, const std::vector& data) { setSubData(_defaultTarget, offset, data); @@ -340,6 +359,8 @@ class Buffer { * @param offset Offset * @param size Data size * @param data Pointer to data + * + * @see bind(Target), @fn_gl{BufferSubData} */ inline void setSubData(Target target, GLintptr offset, GLsizeiptr size, const GLvoid* data) { bind(target); @@ -354,6 +375,7 @@ class Buffer { * * More convenient for setting data from fixed-size arrays than * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*). + * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) { setSubData(target, offset, size*sizeof(T), data); @@ -364,6 +386,8 @@ class Buffer { * @param target %Target * @param offset Offset * @param data Vector with data + * + * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(Target target, GLintptr offset, const std::vector& data) { setSubData(target, offset, data.size()*sizeof(T), data.data()); diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 5489716df..0ee2ce696 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -32,6 +32,7 @@ namespace Magnum { Class for storing image data in GPU memory. Can be replaced with Image, which stores image data in client memory, ImageWrapper, or for example with Trade::ImageData. +@see Buffer @requires_gl */ template class BufferedImage: public AbstractImage { @@ -57,6 +58,8 @@ template class BufferedImage: public AbstractImage { * Binds the buffer to @ref Buffer::Target "pixel unpack * target" and returns nullptr, so it can be used for texture updating * functions the same way as Image::data(). + * + * @see Buffer::bind(Target) */ void* data() { _buffer.bind(Buffer::Target::PixelUnpack); @@ -76,6 +79,8 @@ template class BufferedImage: public AbstractImage { * * Updates the image buffer with given data. The data are not deleted * after filling the buffer. + * + * @see setData(const Math::Vector&, Components, ComponentType, const GLvoid*, Buffer::Usage) */ template inline void setData(const Math::Vector& dimensions, Components components, const T* data, Buffer::Usage usage) { setData(dimensions, components, TypeTraits::imageType(), data, usage); @@ -91,6 +96,8 @@ template class BufferedImage: public AbstractImage { * * Updates the image buffer with given data. The data are not deleted * after filling the buffer. + * + * @see Buffer::setData() */ void setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index 12f2b05c0..8ae1a5b7a 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -121,17 +121,30 @@ class BufferedTexture { * @brief Constructor * * Creates one OpenGL texture. + * @see @fn_gl{GenTextures} */ inline BufferedTexture() { glGenTextures(1, &texture); } - /** @copydoc AbstractTexture::~AbstractTexture() */ + /** + * @brief Destructor + * + * Deletes assigned OpenGL texture. + * @see @fn_gl{DeleteTextures} + */ inline virtual ~BufferedTexture() { glDeleteTextures(1, &texture); } - /** @copydoc AbstractTexture::bind(GLint) */ + /** + * @brief Bind texture for rendering + * + * Sets current texture as active in given layer. The layer must be + * between 0 and maxSupportedLayerCount(). Note that only one texture + * can be bound to given layer. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} + */ inline void bind(GLint layer) { glActiveTexture(GL_TEXTURE0 + layer); bind(); @@ -145,6 +158,7 @@ class BufferedTexture { * Binds given buffer to this texture. The buffer itself can be then * filled with data of proper format at any time using Buffer own data * setting functions. + * @see @fn_gl{BindTexture}, @fn_gl{TexBuffer} */ void setBuffer(InternalFormat internalFormat, Buffer* buffer) { bind(); @@ -154,7 +168,6 @@ class BufferedTexture { private: GLuint texture; - /** @copydoc AbstractTexture::bind() */ inline void bind() { glBindTexture(GL_TEXTURE_BUFFER, texture); } diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 9ce2ae96d..9ff62d0cf 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -63,6 +63,7 @@ class CubeMapTexture: public AbstractTexture { /** * @brief Enable/disable seamless cube map textures * + * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} * @requires_gl * @requires_gl32 Extension @extension{ARB,seamless_cube_map} */ @@ -75,6 +76,7 @@ class CubeMapTexture: public AbstractTexture { * @brief Constructor * * Creates one cube map OpenGL texture. + * @see @def_gl{TEXTURE_CUBE_MAP} */ inline CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {} diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 2f5801147..4569c1ad1 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -50,6 +50,7 @@ class CubeMapTextureArray: public AbstractTexture { /** * @brief Enable/disable seamless cube map textures * + * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} * @requires_gl32 Extension @extension{ARB,seamless_cube_map} */ inline static void setSeamless(bool enabled) { @@ -60,6 +61,7 @@ class CubeMapTextureArray: public AbstractTexture { * @brief Constructor * * Creates one cube map OpenGL texture. + * @see @def_gl{TEXTURE_CUBE_MAP_ARRAY} */ inline CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 268714b0d..d1278ff86 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -109,7 +109,11 @@ class MAGNUM_EXPORT Framebuffer { FaceCulling = GL_CULL_FACE /**< Back face culling */ }; - /** @brief Set feature */ + /** + * @brief Set feature + * + * @see @fn_gl{Enable}/@fn_gl{Disable} + */ inline static void setFeature(Feature feature, bool enabled) { enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); } @@ -120,6 +124,7 @@ class MAGNUM_EXPORT Framebuffer { * Initial value is `PolygonFacing::Back`. If set to both front and * back, only points and lines are drawn. * @attention You have to also enable face culling with setFeature(). + * @see @fn_gl{CullFace} */ inline static void setFaceCullingMode(PolygonFacing mode) { glCullFace(static_cast(mode)); @@ -129,7 +134,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Set viewport size * * Call when window size changes. - * @see Camera::setViewport() + * @see @fn_gl{Viewport} */ inline static void setViewport(const Math::Vector2& position, const Math::Vector2& size) { glViewport(position.x(), position.y(), size.x(), size.y()); @@ -157,7 +162,8 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Clear specified buffers in framebuffer * - * @see clear(), setClearColor(), setClearDepth(), setClearStencil() + * @see clear(), setClearColor(), setClearDepth(), setClearStencil(), + * @fn_gl{Clear} * @todo Clearing only given draw buffer */ inline static void clear(ClearMask mask) { glClear(static_cast(mask)); } @@ -166,6 +172,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Set clear color * * Initial value is `{0.0f, 0.0f, 0.0f, 1.0f}`. + * @see @fn_gl{ClearColor} */ inline static void setClearColor(const Color4& color) { glClearColor(color.r(), color.g(), color.b(), color.a()); @@ -176,6 +183,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Set clear depth * * Initial value is `1.0`. + * @see @fn_gl{ClearDepth} * @requires_gl See setClearDepth(GLfloat), which is supported in OpenGL ES. */ inline static void setClearDepth(GLdouble depth) { glClearDepth(depth); } @@ -184,6 +192,7 @@ class MAGNUM_EXPORT Framebuffer { /** * @overload * + * @see @fn_gl{ClearDepth} * @requires_gl41 Extension @extension{ARB,ES2_compatibility} */ inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } @@ -192,6 +201,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Set clear stencil * * Initial value is `0`. + * @see @fn_gl{ClearStencil} */ inline static void setClearStencil(GLint stencil) { glClearStencil(stencil); } @@ -205,7 +215,9 @@ class MAGNUM_EXPORT Framebuffer { * @param size Scissor rectangle size. Initial value is * size of the window when the context is first attached to a * window. + * * @attention You have to enable scissoring with setFeature() first. + * @see @fn_gl{Scissor} */ inline static void setScissor(const Math::Vector2& bottomLeft, const Math::Vector2& size) { glScissor(bottomLeft.x(), bottomLeft.y(), size.x(), size.y()); @@ -286,7 +298,8 @@ class MAGNUM_EXPORT Framebuffer { * Initial value is all `1`s. * * @attention You have to enable stencil test with setFeature() first. - * @see setStencilFunction(StencilFunction, GLint, GLuint) + * @see setStencilFunction(StencilFunction, GLint, GLuint), + * @fn_gl{StencilFuncSeparate} */ inline static void setStencilFunction(PolygonFacing facing, StencilFunction function, GLint referenceValue, GLuint mask) { glStencilFuncSeparate(static_cast(facing), static_cast(function), referenceValue, mask); @@ -297,6 +310,7 @@ class MAGNUM_EXPORT Framebuffer { * * The same as setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint) * with `facing` set to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilFunc} */ inline static void setStencilFunction(StencilFunction function, GLint referenceValue, GLuint mask) { glStencilFunc(static_cast(function), referenceValue, mask); @@ -313,7 +327,8 @@ class MAGNUM_EXPORT Framebuffer { * * Initial value for all fields is `StencilOperation::Keep`. * @attention You have to enable stencil test with setFeature() first. - * @see setStencilOperation(StencilOperation, StencilOperation, StencilOperation) + * @see setStencilOperation(StencilOperation, StencilOperation, StencilOperation), + * @fn_gl{StencilOpSeparate} */ inline static void setStencilOperation(PolygonFacing facing, StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { glStencilOpSeparate(static_cast(facing), static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); @@ -324,6 +339,7 @@ class MAGNUM_EXPORT Framebuffer { * * The same as setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation) * with `facing` set to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilOp} */ inline static void setStencilOperation(StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { glStencilOp(static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); @@ -345,6 +361,7 @@ class MAGNUM_EXPORT Framebuffer { * * Initial value is `DepthFunction::Less`. * @attention You have to enable depth test with setFeature() first. + * @see @fn_gl{DepthFunc} */ inline static void setDepthFunction(DepthFunction function) { glDepthFunc(static_cast(function)); @@ -359,6 +376,7 @@ class MAGNUM_EXPORT Framebuffer { * * Set to `false` to disallow writing to given color channel. Initial * values are all `true`. + * @see @fn_gl{ColorMask} * @todo Masking only given draw buffer */ inline static void setColorMask(GLboolean allowRed, GLboolean allowGreen, GLboolean allowBlue, GLboolean allowAlpha) { @@ -370,6 +388,7 @@ class MAGNUM_EXPORT Framebuffer { * * Set to `false` to disallow writing to depth buffer. Initial value * is `true`. + * @see @fn_gl{DepthMask} */ inline static void setDepthMask(GLboolean allow) { glDepthMask(allow); @@ -380,7 +399,7 @@ class MAGNUM_EXPORT Framebuffer { * * Set given bit to `0` to disallow writing stencil value for given * faces to it. Initial value is all `1`s. - * @see setStencilMask(GLuint) + * @see setStencilMask(GLuint), @fn_gl{StencilMaskSeparate} */ inline static void setStencilMask(PolygonFacing facing, GLuint allowBits) { glStencilMaskSeparate(static_cast(facing), allowBits); @@ -391,6 +410,7 @@ class MAGNUM_EXPORT Framebuffer { * * The same as setStencilMask(PolygonFacing, GLuint) with `facing` set * to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilMask} */ inline static void setStencilMask(GLuint allowBits) { glStencilMask(allowBits); @@ -561,7 +581,8 @@ class MAGNUM_EXPORT Framebuffer { * How to combine source color (pixel value) with destination color * (framebuffer). Initial value is `BlendEquation::Add`. * @attention You have to enable blending with setFeature() first. - * @see setBlendEquation(BlendEquation, BlendEquation) + * @see setBlendEquation(BlendEquation, BlendEquation), + * @fn_gl{BlendEquation} */ inline static void setBlendEquation(BlendEquation equation) { glBlendEquation(static_cast(equation)); @@ -572,6 +593,7 @@ class MAGNUM_EXPORT Framebuffer { * * See setBlendEquation(BlendEquation) for more information. * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendEquationSeparate} */ inline static void setBlendEquation(BlendEquation rgb, BlendEquation alpha) { glBlendEquationSeparate(static_cast(rgb), static_cast(alpha)); @@ -586,7 +608,8 @@ class MAGNUM_EXPORT Framebuffer { * `BlendFunction::Zero`. * * @attention You have to enable blending with setFeature() first. - * @see setBlendFunction(BlendFunction, BlendFunction, BlendFunction, BlendFunction) + * @see setBlendFunction(BlendFunction, BlendFunction, BlendFunction, BlendFunction), + * @fn_gl{BlendFunc} */ inline static void setBlendFunction(BlendFunction source, BlendFunction destination) { glBlendFunc(static_cast(source), static_cast(destination)); @@ -597,6 +620,7 @@ class MAGNUM_EXPORT Framebuffer { * * See setBlendFunction(BlendFunction, BlendFunction) for more information. * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendFuncSeparate} */ inline static void setBlendFunction(BlendFunction sourceRgb, BlendFunction destinationRgb, BlendFunction sourceAlpha, BlendFunction destinationAlpha) { glBlendFuncSeparate(static_cast(sourceRgb), static_cast(destinationRgb), static_cast(sourceAlpha), static_cast(destinationAlpha)); @@ -611,6 +635,7 @@ class MAGNUM_EXPORT Framebuffer { * `BlendFunction::ConstantAlpha` and * `BlendFunction::OneMinusConstantAlpha`. * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendColor} */ inline static void setBlendColor(const Color4& color) { glBlendColor(color.r(), color.g(), color.b(), color.a()); @@ -650,6 +675,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Set logical operation * * @attention You have to enable logical operation with setFeature() first. + * @see @fn_gl{LogicOp} * @requires_gl Logic operations on framebuffer are in desktop OpenGL only. */ inline static void setLogicOperation(LogicOperation operation) { @@ -727,6 +753,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Constructor * * Generates new OpenGL framebuffer. + * @see @fn_gl{GenFramebuffers} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline Framebuffer() { glGenFramebuffers(1, &framebuffer); } @@ -735,6 +762,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Destructor * * Deletes associated OpenGL framebuffer. + * @see @fn_gl{DeleteFramebuffers} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline ~Framebuffer() { glDeleteFramebuffers(1, &framebuffer); } @@ -743,6 +771,7 @@ class MAGNUM_EXPORT Framebuffer { * @brief Bind default framebuffer to given target * @param target %Target * + * @see @fn_gl{BindFramebuffer} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline static void bindDefault(Target target) { @@ -752,6 +781,7 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Bind framebuffer * + * @see @fn_gl{BindFramebuffer} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void bind(Target target) { @@ -769,7 +799,7 @@ class MAGNUM_EXPORT Framebuffer { * If used for blit(), the order is not important. Each used attachment * should have either renderbuffer or texture attached for writing to * work properly. - * @see mapForDraw(), mapDefaultForRead() + * @see mapForDraw(), mapDefaultForRead(), bindDefault(), @fn_gl{DrawBuffers} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -785,7 +815,7 @@ class MAGNUM_EXPORT Framebuffer { * If used for blit(), the order is not important. Each used attachment * should have either renderbuffer or texture attached for writing to * work properly. - * @see mapDefaultForDraw(), mapForRead() + * @see mapDefaultForDraw(), mapForRead(), bind(), @fn_gl{DrawBuffers} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -797,7 +827,7 @@ class MAGNUM_EXPORT Framebuffer { * * Each used attachment should have either renderbuffer or texture * attached to work properly. - * @see mapForRead(), mapDefaultForDraw() + * @see mapForRead(), mapDefaultForDraw(), bindDefault(), @fn_gl{ReadBuffer} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -812,7 +842,7 @@ class MAGNUM_EXPORT Framebuffer { * * The color attachment should have either renderbuffer or texture * attached for reading to work properly. - * @see mapDefaultForRead(), mapForDraw() + * @see mapDefaultForRead(), mapForDraw(), bind(), @fn_gl{ReadBuffer} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -854,8 +884,9 @@ class MAGNUM_EXPORT Framebuffer { * @brief Attach renderbuffer to given framebuffer depth/stencil attachment * @param target %Target * @param depthStencilAttachment Depth/stencil attachment - * @param renderbuffer Renderbuffer + * @param renderbuffer %Renderbuffer * + * @see bind(), @fn_gl{FramebufferRenderbuffer} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { @@ -868,8 +899,9 @@ class MAGNUM_EXPORT Framebuffer { * @brief Attach renderbuffer to given framebuffer color attachment * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) - * @param renderbuffer Renderbuffer + * @param renderbuffer %Renderbuffer * + * @see bind(), @fn_gl{FramebufferRenderbuffer} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachRenderbuffer(Target target, unsigned int colorAttachment, Renderbuffer* renderbuffer) { @@ -886,6 +918,7 @@ class MAGNUM_EXPORT Framebuffer { * @param texture 1D texture * @param mipLevel Mip level * + * @see bind(), @fn_gl{FramebufferTexture} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -903,6 +936,7 @@ class MAGNUM_EXPORT Framebuffer { * @param texture 1D texture * @param mipLevel Mip level * + * @see bind(), @fn_gl{FramebufferTexture} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -922,7 +956,7 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture() + * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { @@ -940,7 +974,7 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture() + * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachTexture2D(Target target, unsigned int colorAttachment, Texture2D* texture, GLint mipLevel) { @@ -958,7 +992,7 @@ class MAGNUM_EXPORT Framebuffer { * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D() + * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { @@ -975,7 +1009,7 @@ class MAGNUM_EXPORT Framebuffer { * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D() + * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachCubeMapTexture(Target target, unsigned int colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { @@ -993,6 +1027,7 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture * + * @see bind(), @fn_gl{FramebufferTexture} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -1011,6 +1046,7 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture. * + * @see bind(), @fn_gl{FramebufferTexture} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ @@ -1065,6 +1101,7 @@ class MAGNUM_EXPORT Framebuffer { * mapDefaultForDraw() for binding particular framebuffer for reading * and drawing. If multiple attachments are specified in mapForDraw() * / mapDefaultForDraw(), the data are written to each of them. + * @see @fn_gl{BlitFramebuffer} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} */ @@ -1085,6 +1122,7 @@ class MAGNUM_EXPORT Framebuffer { * no interpolation is needed and thus * AbstractTexture::Filter::NearestNeighbor filtering is used by * default. + * @see @fn_gl{BlitFramebuffer} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} */ @@ -1101,6 +1139,7 @@ class MAGNUM_EXPORT Framebuffer { * @param type Data type * @param image %Image where to put the data * + * @see @fn_gl{ReadPixels} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ static void read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); @@ -1115,6 +1154,7 @@ class MAGNUM_EXPORT Framebuffer { * @param image Buffered image where to put the data * @param usage %Buffer usage * + * @see Buffer::bind(Target), @fn_gl{ReadPixels} * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 7250357b2..f7ad05992 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -69,12 +69,22 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ inline Buffer* indexBuffer() { return &_indexBuffer; } + /** + * @brief Draw the mesh + * + * Expects an active shader with all uniforms set. + * @see Buffer::bind(), bind(), unbind(), finalize(), @fn_gl{DrawElements} + * @todo Index buffer bound every time?! + */ void draw(); protected: - #ifndef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Finalize the mesh + * + * @see Mesh::finalize(), Buffer::bind() + */ MAGNUM_LOCAL void finalize(); - #endif private: Buffer _indexBuffer; diff --git a/src/Mesh.h b/src/Mesh.h index dd7972adf..450c44619 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -69,6 +69,7 @@ class MAGNUM_EXPORT Mesh { * @brief Set front-facing polygon winding * * Initial value is `FrontFace::%CounterClockWise`. + * @see @fn_gl{FrontFace} */ void setFrontFace(FrontFace mode) { glFrontFace(static_cast(mode)); @@ -96,6 +97,7 @@ class MAGNUM_EXPORT Mesh { * @brief Set provoking vertex * * Initial value is ProvokingMode::%LastVertexConvention. + * @see @fn_gl{ProvokingVertex} * @requires_gl OpenGL ES behaves always like the default. * @requires_gl32 Extension @extension{ARB,provoking_vertex}. Older * versions behave always like the default. @@ -137,6 +139,7 @@ class MAGNUM_EXPORT Mesh { * @brief Set polygon drawing mode * * Initial value is `PolygonMode::%Fill`. + * @see @fn_gl{PolygonMode} * @requires_gl OpenGL ES behaves always like the default. See * setPrimitive() for possible workaround. */ @@ -171,7 +174,7 @@ class MAGNUM_EXPORT Mesh { * @brief Enable/disable polygon offset for given mode * * Initially disabled for all modes. - * @see setPolygonOffset() + * @see setPolygonOffset(), @fn_gl{Enable}/@fn_gl{Disable} */ inline static void setPolygonOffsetMode(PolygonOffsetMode mode, bool enabled) { enabled ? glEnable(static_cast(mode)) : glDisable(static_cast(mode)); @@ -184,6 +187,7 @@ class MAGNUM_EXPORT Mesh { * * @attention You have to call setPolygonOffsetMode() to enable * polygon offset for desired polygon modes. + * @see @fn_gl{PolygonOffset} */ inline static void setPolygonOffset(GLfloat factor, GLfloat units) { glPolygonOffset(factor, units); @@ -192,7 +196,8 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set line width * - * Initial value is 1. + * Initial value is `1.0f`. + * @see @fn_gl{LineWidth} */ inline static void setLineWidth(GLfloat width) { glLineWidth(width); @@ -203,7 +208,7 @@ class MAGNUM_EXPORT Mesh { * @brief Set point size * * Initial value is `1.0f`. - * @see setProgramPointSize() + * @see setProgramPointSize(), @fn_gl{PointSize} * @requires_gl Set directly in vertex shader using @c gl_PointSize * builtin variable. */ @@ -216,7 +221,7 @@ class MAGNUM_EXPORT Mesh { * * If enabled, the point size is taken from vertex/geometry shader * builtin `gl_PointSize`. Initially disabled on desktop OpenGL. - * @see setPointSize() + * @see setPointSize(), @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{PROGRAM_POINT_SIZE} * @requires_gl Always enabled on OpenGL ES. */ inline static void setProgramPointSize(bool enabled) { @@ -272,7 +277,7 @@ class MAGNUM_EXPORT Mesh { }; /** - * @brief Buffer type + * @brief %Buffer type * * If storing more than one attribute data in the buffer, the data of * one attribute can be either kept together or interleaved with data @@ -292,6 +297,7 @@ class MAGNUM_EXPORT Mesh { * Allows creating the object without knowing anything about mesh * data. Note that you have to call setVertexCount() manually for mesh * to draw properly. + * @see @fn_gl{GenVertexArrays} */ inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0), finalized(false) { #ifndef MAGNUM_TARGET_GLES @@ -303,6 +309,8 @@ class MAGNUM_EXPORT Mesh { * @brief Constructor * @param primitive Primitive type * @param vertexCount Vertex count + * + * @see @fn_gl{GenVertexArrays} */ inline Mesh(Primitive primitive, GLsizei vertexCount): _primitive(primitive), _vertexCount(vertexCount), finalized(false) { #ifndef MAGNUM_TARGET_GLES @@ -317,6 +325,7 @@ class MAGNUM_EXPORT Mesh { * @brief Destructor * * Deletes all associated buffers. + * @see @fn_gl{DeleteVertexArrays} */ inline virtual ~Mesh() { destroy(); } @@ -391,18 +400,30 @@ class MAGNUM_EXPORT Mesh { * @brief Draw the mesh * * Expects an active shader with all uniforms set. + * @see bind(), unbind(), finalize(), @fn_gl{DrawArrays} */ virtual void draw(); protected: - #ifndef DOXYGEN_GENERATING_OUTPUT - /** @brief Bind all buffers */ + /** + * @brief Bind all buffers + * + * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{VertexAttribPointer} + */ void bindBuffers(); - /** @brief Bind vertex array or all buffers */ + /** + * @brief Bind vertex array or all buffers + * + * @see @fn_gl{BindVertexArray} or bindBuffers() + */ void bind(); - /** @brief Unbind vertex array or all buffers */ + /** + * @brief Unbind vertex array or all buffers + * + * @see @fn_gl{BindVertexArray} or @fn_gl{DisableVertexAttribArray} + */ void unbind(); /** @@ -410,9 +431,9 @@ class MAGNUM_EXPORT Mesh { * * Computes location and stride of each attribute in its buffer. After * this function is called, no new attribute can be bound. + * @see bindBuffers() */ MAGNUM_LOCAL void finalize(); - #endif private: /** @brief Vertex attribute */ diff --git a/src/Query.h b/src/Query.h index 41c59415c..bfa5c94fb 100644 --- a/src/Query.h +++ b/src/Query.h @@ -39,6 +39,7 @@ class MAGNUM_EXPORT AbstractQuery { * @brief Constructor * * Generates one OpenGL query. + * @see @fn_gl{GenQueries} */ inline AbstractQuery() { glGenQueries(1, &query); } @@ -46,11 +47,14 @@ class MAGNUM_EXPORT AbstractQuery { * @brief Destructor * * Deletes assigned OpenGL query. + * @see @fn_gl{DeleteQueries} */ virtual inline ~AbstractQuery() { glDeleteQueries(1, &query); } /** * @brief Whether the result is available + * + * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT_AVAILABLE} */ bool resultAvailable(); @@ -61,7 +65,7 @@ class MAGNUM_EXPORT AbstractQuery { * * Note that this function is blocking until the result is available. * See resultAvailable(). - * + * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} * @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`) */ template T result(); @@ -130,6 +134,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery { * @brief Begin query * * Begins counting of given @p target until end() is called. + * @see @fn_gl{BeginQuery} */ void begin(Target target); @@ -137,6 +142,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery { * @brief End query * * The result can be then retrieved by calling result(). + * @see @fn_gl{EndQuery} */ void end(); @@ -239,6 +245,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** * @brief Begin conditional rendering based on result value * + * @see @fn_gl{BeginConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} */ inline void beginConditionalRender(ConditionalRenderMode mode) { @@ -248,6 +255,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** * @brief End conditional render * + * @see @fn_gl{EndConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} */ inline void endConditionalRender() { @@ -293,7 +301,11 @@ Using this query results in fewer OpenGL calls when doing more measures. */ class TimeQuery: public AbstractQuery { public: - /** @brief Query timestamp */ + /** + * @brief Query timestamp + * + * @see @fn_gl{QueryCounter} with @def_gl{TIMESTAMP} + */ inline void timestamp() { glQueryCounter(query, GL_TIMESTAMP); } diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index ebba60801..9ff67f01d 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -184,6 +184,7 @@ class Renderbuffer { * @brief Constructor * * Generates new OpenGL renderbuffer. + * @see @fn_gl{GenRenderbuffers} */ inline Renderbuffer() { glGenRenderbuffers(1, &renderbuffer); @@ -193,6 +194,7 @@ class Renderbuffer { * @brief Destructor * * Deletes associated OpenGL renderbuffer. + * @see @fn_gl{DeleteRenderbuffers} */ inline ~Renderbuffer() { glDeleteRenderbuffers(1, &renderbuffer); @@ -201,7 +203,11 @@ class Renderbuffer { /** @brief OpenGL internal renderbuffer ID */ inline GLuint id() const { return renderbuffer; } - /** @brief Bind renderbuffer */ + /** + * @brief Bind renderbuffer + * + * @see @fn_gl{BindRenderbuffer} + */ inline void bind() { glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); } @@ -210,6 +216,8 @@ class Renderbuffer { * @brief Set renderbuffer storage * @param internalFormat Internal format * @param size Renderbuffer size + * + * @see bind(), @fn_gl{RenderbufferStorage} */ inline void setStorage(InternalFormat internalFormat, const Math::Vector2& size) { bind(); diff --git a/src/Shader.h b/src/Shader.h index 75c3a0f63..4cd0cada9 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -122,7 +122,7 @@ class MAGNUM_EXPORT Shader { * * Creates empty OpenGL shader. Sources can be added with addSource() * or addFile(). - * @see fromData(), fromFile() + * @see fromData(), fromFile(), @fn_gl{CreateShader} */ inline Shader(Type type): _type(type), _state(State::Initialized), shader(0) { shader = glCreateShader(static_cast(_type)); @@ -132,6 +132,7 @@ class MAGNUM_EXPORT Shader { * @brief Destructor * * Deletes associated OpenGL shader. + * @see @fn_gl{DeleteShader} */ inline ~Shader() { if(shader) glDeleteShader(shader); } @@ -185,7 +186,9 @@ class MAGNUM_EXPORT Shader { * before, it tries to compile it. If compilation fails or no sources * are present, returns 0. If the shader was compiled already, returns * already existing shader. - * @see state() + * @see state(), @fn_gl{ShaderSource}, @fn_gl{CompileShader}, + * @fn_gl{GetShader} with @def_gl{COMPILE_STATUS}, + * @fn_gl{GetShaderInfoLog} */ GLuint compile(); diff --git a/src/Texture.h b/src/Texture.h index 61f1013b3..6e6f73c05 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -122,6 +122,8 @@ template class Texture: public AbstractTexture { * @attention For rectangle textures only some modes are supported, * see @ref AbstractTexture::Wrapping "Wrapping" documentation for * more information. + * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_WRAP_S}, + * @def_gl{TEXTURE_WRAP_T}, @def_gl{TEXTURE_WRAP_R} */ inline Texture* setWrapping(const Math::Vector& wrapping) { bind(); @@ -139,6 +141,7 @@ template class Texture: public AbstractTexture { * * Sets texture data from given image. The image is not deleted * afterwards. + * @see bind(), @fn_gl{TexImage1D}, @fn_gl{TexImage2D}, @fn_gl{TexImage3D} */ template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { bind(); @@ -162,6 +165,7 @@ template class Texture: public AbstractTexture { * taken as if it had the last dimension equal to 1. It can be used * for e.g. updating 3D texture with multiple 2D images or for filling * 1D texture array (which is two-dimensional) with 1D images. + * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} */ template inline Texture* setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { bind(); From 23f93cd65eaeb8340334bc6f4718e5004ea64b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 15:50:12 +0200 Subject: [PATCH 026/256] Mention @fn_gl and @def_gl in Coding Style manual. --- doc/coding-style.dox | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/coding-style.dox b/doc/coding-style.dox index 09fbdcb80..ad4b75de4 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -49,6 +49,21 @@ the operator is implemented (not of class in which the operator is implemented), thus efficiently connecting the two classes together in the documentation. +@subsubsection documentation-commands-ref_gl Links to related OpenGL functions and definitions + +If an function touches OpenGL, related OpenGL functions should be documented +in @c \@see block with @c \@fn_gl command. If only specific definition is used +in the function, document it with @c \@def_gl command. Example usage: +@code +// @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} +inline static void setSeamless(bool enabled) { + enabled ? glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) : glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); +} +@endcode + +It produces link to the online manual, in this case @fn_gl{Enable}/@fn_gl{Disable} +with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS}. + @subsubsection documentation-commands-extension Links to OpenGL extensions If an OpenGL extension is referenced in the documentation, it should be done From d88171aaae6379d37bcd9263a4198c16794a900a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 18:38:17 +0200 Subject: [PATCH 027/256] Simplified linking step. --- src/CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ea37af81..cc35b4470 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,12 +72,18 @@ set_target_properties(MagnumObjects MagnumMathObjects PROPERTIES COMPILE_FLAGS " add_library(Magnum SHARED $ $) -target_link_libraries(Magnum ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) +set(Magnum_LIBS + ${CORRADE_UTILITY_LIBRARY} + ${CORRADE_PLUGINMANAGER_LIBRARY}) if(NOT TARGET_GLES) - target_link_libraries(Magnum ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) + set(Magnum_LIBS ${Magnum_LIBS} + ${OPENGL_gl_LIBRARY} + ${GLEW_LIBRARY}) else() - target_link_libraries(Magnum ${OPENGLES2_LIBRARY}) + set(Magnum_LIBS ${Magnum_LIBS} + ${OPENGLES2_LIBRARY}) endif() +target_link_libraries(Magnum ${Magnum_LIBS}) install(TARGETS Magnum DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${Magnum_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) @@ -116,12 +122,7 @@ if(BUILD_TESTS) add_library(MagnumTestLib SHARED $) set_target_properties(MagnumTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) - target_link_libraries(MagnumTestLib ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) - if(NOT TARGET_GLES) - target_link_libraries(MagnumTestLib ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY}) - else() - target_link_libraries(MagnumTestLib ${OPENGLES2_LIBRARY}) - endif() + target_link_libraries(MagnumTestLib ${Magnum_LIBS}) add_subdirectory(Test) endif() From e213979559b15c001a7eb28259bd50270d15fcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 20:03:21 +0200 Subject: [PATCH 028/256] Fixed compilation on OpenGL ES. --- src/AbstractImage.h | 2 ++ src/Buffer.h | 1 + src/Mesh.h | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index a71b06e81..f32b17e03 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -19,6 +19,8 @@ * @brief Class Magnum::AbstractImage */ +#include + #include "Magnum.h" #include "magnumVisibility.h" diff --git a/src/Buffer.h b/src/Buffer.h index 15ccda925..28612617e 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Buffer */ +#include #include #include "Magnum.h" diff --git a/src/Mesh.h b/src/Mesh.h index 450c44619..faeaf4642 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -75,6 +75,7 @@ class MAGNUM_EXPORT Mesh { glFrontFace(static_cast(mode)); } + #ifndef MAGNUM_TARGET_GLES /** * @brief Provoking vertex * @@ -105,6 +106,7 @@ class MAGNUM_EXPORT Mesh { inline static void setProvokingVertex(ProvokingVertex mode) { glProvokingVertex(static_cast(mode)); } + #endif #ifndef MAGNUM_TARGET_GLES /** @@ -155,7 +157,10 @@ class MAGNUM_EXPORT Mesh { */ enum class PolygonOffsetMode: GLenum { /** Offset filled polygons. */ - Fill = GL_POLYGON_OFFSET_FILL, + Fill = GL_POLYGON_OFFSET_FILL + + #ifndef MAGNUM_TARGET_GLES + , /** * Offset lines. @@ -168,6 +173,7 @@ class MAGNUM_EXPORT Mesh { * @requires_gl Only PolygonOffset::%Fill is supported. */ Point = GL_POLYGON_OFFSET_POINT + #endif }; /** From e378195d209501c1d36d3dd769b8a56d93bf10f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 01:31:21 +0200 Subject: [PATCH 029/256] Added headers for OpenGL 4.3 and OpenGL ES 3.0. --- CMakeLists.txt | 3 + external/CMakeLists.txt | 6 + external/GL/CMakeLists.txt | 1 + external/GL/glcorearb.h | 4552 +++++++++++++++++++++++++++++++++ external/GLES3/CMakeLists.txt | 1 + external/GLES3/gl3.h | 1063 ++++++++ external/GLES3/gl3platform.h | 30 + external/KHR/CMakeLists.txt | 1 + external/KHR/khrplatform.h | 269 ++ modules/FindMagnum.cmake | 1 + src/Magnum.h | 3 +- 11 files changed, 5929 insertions(+), 1 deletion(-) create mode 100644 external/CMakeLists.txt create mode 100644 external/GL/CMakeLists.txt create mode 100644 external/GL/glcorearb.h create mode 100644 external/GLES3/CMakeLists.txt create mode 100644 external/GLES3/gl3.h create mode 100644 external/GLES3/gl3platform.h create mode 100644 external/KHR/CMakeLists.txt create mode 100644 external/KHR/khrplatform.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 53bc48175..99d68ef86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,5 +49,8 @@ set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum) +include_directories(${CMAKE_SOURCE_DIR}/external) + +add_subdirectory(external) add_subdirectory(modules) add_subdirectory(src) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 000000000..a24503e8b --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,6 @@ +if(NOT TARGET_GLES) + add_subdirectory(GL) +else() + add_subdirectory(GLES3) + add_subdirectory(KHR) +endif() diff --git a/external/GL/CMakeLists.txt b/external/GL/CMakeLists.txt new file mode 100644 index 000000000..a24337831 --- /dev/null +++ b/external/GL/CMakeLists.txt @@ -0,0 +1 @@ +install(FILES glcorearb.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GL) diff --git a/external/GL/glcorearb.h b/external/GL/glcorearb.h new file mode 100644 index 000000000..e8474135e --- /dev/null +++ b/external/GL/glcorearb.h @@ -0,0 +1,4552 @@ +#ifndef __glcorearb_h_ +#define __glcorearb_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* glcorearb.h replaces gl3.h. It is for use with OpenGL core + * profile implementations. + * + * glcorearb.h last updated on $Date: 2012-08-13 16:18:01 -0700 (Mon, 13 Aug 2012) $ + * + * RELEASE NOTES - 2012/08/13 + * + * glcorearb.h should be placed in the same directory as gl.h and + * included as + * ''. + * + * gl3.h includes only APIs in the latest OpenGL core profile + * implementation together with APIs in newer ARB extensions which can be + * can be supported by the core profile. It does not, and never will + * include functionality removed from the core profile, such as + * fixed-function vertex and fragment processing. + * + * It is not possible to #include both and either of + * or in the same source file. + * + * Feedback can be given by register for the Khronos Bugzilla + * (www.khronos.org/bugzilla) and filing issues there under product + * "OpenGL", category "Registry". + */ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/* Base GL types */ + +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef signed char GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef unsigned char GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef unsigned short GLhalf; +typedef float GLfloat; +typedef float GLclampf; +typedef double GLdouble; +typedef double GLclampd; +typedef void GLvoid; + +/*************************************************************/ + +#ifndef GL_VERSION_1_1 +/* AttribMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +/* BlendingFactorSrc */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* DrawBufferMode */ +#define GL_NONE 0 +#define GL_FRONT_LEFT 0x0400 +#define GL_FRONT_RIGHT 0x0401 +#define GL_BACK_LEFT 0x0402 +#define GL_BACK_RIGHT 0x0403 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_LEFT 0x0406 +#define GL_RIGHT 0x0407 +#define GL_FRONT_AND_BACK 0x0408 +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +/* GetPName */ +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_RANGE 0x0B12 +#define GL_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_RANGE 0x0B22 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_TEST 0x0B71 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_TEST 0x0B90 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_VIEWPORT 0x0BA2 +#define GL_DITHER 0x0BD0 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND 0x0BE2 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_READ_BUFFER 0x0C02 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_DOUBLEBUFFER 0x0C32 +#define GL_STEREO 0x0C33 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_POLYGON_SMOOTH_HINT 0x0C53 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +/* GetTextureParameter */ +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_DOUBLE 0x140A +/* ErrorCode */ +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F +/* MatrixMode (for gl3.h, FBO attachment type) */ +#define GL_TEXTURE 0x1702 +/* PixelCopyType */ +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +/* PixelFormat */ +#define GL_STENCIL_INDEX 0x1901 +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +/* PolygonMode */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +/* StencilOp */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 +/* TextureMinFilter */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +/* TextureTarget */ +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +/* PixelInternalFormat */ +#define GL_R3_G3_B2 0x2A10 +#define GL_RGB4 0x804F +#define GL_RGB5 0x8050 +#define GL_RGB8 0x8051 +#define GL_RGB10 0x8052 +#define GL_RGB12 0x8053 +#define GL_RGB16 0x8054 +#define GL_RGBA2 0x8055 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA12 0x805A +#define GL_RGBA16 0x805B +#endif + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_VERSION_2_1 +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB_ALPHA 0x8C42 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 +#endif + +#ifndef GL_VERSION_3_0 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_CLIP_DISTANCE0 0x3000 +#define GL_CLIP_DISTANCE1 0x3001 +#define GL_CLIP_DISTANCE2 0x3002 +#define GL_CLIP_DISTANCE3 0x3003 +#define GL_CLIP_DISTANCE4 0x3004 +#define GL_CLIP_DISTANCE5 0x3005 +#define GL_CLIP_DISTANCE6 0x3006 +#define GL_CLIP_DISTANCE7 0x3007 +#define GL_MAX_CLIP_DISTANCES 0x0D32 +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_CONTEXT_FLAGS 0x821E +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 +#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_CLAMP_READ_COLOR 0x891C +#define GL_FIXED_ONLY 0x891D +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_1D_ARRAY 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TEXTURE_SHARED_SIZE 0x8C3F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_PRIMITIVES_GENERATED 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_GREEN_INTEGER 0x8D95 +#define GL_BLUE_INTEGER 0x8D96 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_BGR_INTEGER 0x8D9A +#define GL_BGRA_INTEGER 0x8D9B +#define GL_SAMPLER_1D_ARRAY 0x8DC0 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_1D 0x8DC9 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_QUERY_WAIT 0x8E13 +#define GL_QUERY_NO_WAIT 0x8E14 +#define GL_QUERY_BY_REGION_WAIT 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +/* Reuse tokens from ARB_depth_buffer_float */ +/* reuse GL_DEPTH_COMPONENT32F */ +/* reuse GL_DEPTH32F_STENCIL8 */ +/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_DEFAULT */ +/* reuse GL_FRAMEBUFFER_UNDEFINED */ +/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ +/* reuse GL_INDEX */ +/* reuse GL_MAX_RENDERBUFFER_SIZE */ +/* reuse GL_DEPTH_STENCIL */ +/* reuse GL_UNSIGNED_INT_24_8 */ +/* reuse GL_DEPTH24_STENCIL8 */ +/* reuse GL_TEXTURE_STENCIL_SIZE */ +/* reuse GL_TEXTURE_RED_TYPE */ +/* reuse GL_TEXTURE_GREEN_TYPE */ +/* reuse GL_TEXTURE_BLUE_TYPE */ +/* reuse GL_TEXTURE_ALPHA_TYPE */ +/* reuse GL_TEXTURE_DEPTH_TYPE */ +/* reuse GL_UNSIGNED_NORMALIZED */ +/* reuse GL_FRAMEBUFFER_BINDING */ +/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_BINDING */ +/* reuse GL_READ_FRAMEBUFFER */ +/* reuse GL_DRAW_FRAMEBUFFER */ +/* reuse GL_READ_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_SAMPLES */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* reuse GL_FRAMEBUFFER_COMPLETE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ +/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ +/* reuse GL_MAX_COLOR_ATTACHMENTS */ +/* reuse GL_COLOR_ATTACHMENT0 */ +/* reuse GL_COLOR_ATTACHMENT1 */ +/* reuse GL_COLOR_ATTACHMENT2 */ +/* reuse GL_COLOR_ATTACHMENT3 */ +/* reuse GL_COLOR_ATTACHMENT4 */ +/* reuse GL_COLOR_ATTACHMENT5 */ +/* reuse GL_COLOR_ATTACHMENT6 */ +/* reuse GL_COLOR_ATTACHMENT7 */ +/* reuse GL_COLOR_ATTACHMENT8 */ +/* reuse GL_COLOR_ATTACHMENT9 */ +/* reuse GL_COLOR_ATTACHMENT10 */ +/* reuse GL_COLOR_ATTACHMENT11 */ +/* reuse GL_COLOR_ATTACHMENT12 */ +/* reuse GL_COLOR_ATTACHMENT13 */ +/* reuse GL_COLOR_ATTACHMENT14 */ +/* reuse GL_COLOR_ATTACHMENT15 */ +/* reuse GL_DEPTH_ATTACHMENT */ +/* reuse GL_STENCIL_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_RENDERBUFFER_WIDTH */ +/* reuse GL_RENDERBUFFER_HEIGHT */ +/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ +/* reuse GL_STENCIL_INDEX1 */ +/* reuse GL_STENCIL_INDEX4 */ +/* reuse GL_STENCIL_INDEX8 */ +/* reuse GL_STENCIL_INDEX16 */ +/* reuse GL_RENDERBUFFER_RED_SIZE */ +/* reuse GL_RENDERBUFFER_GREEN_SIZE */ +/* reuse GL_RENDERBUFFER_BLUE_SIZE */ +/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ +/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ +/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ +/* reuse GL_MAX_SAMPLES */ +/* Reuse tokens from ARB_framebuffer_sRGB */ +/* reuse GL_FRAMEBUFFER_SRGB */ +/* Reuse tokens from ARB_half_float_vertex */ +/* reuse GL_HALF_FLOAT */ +/* Reuse tokens from ARB_map_buffer_range */ +/* reuse GL_MAP_READ_BIT */ +/* reuse GL_MAP_WRITE_BIT */ +/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ +/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ +/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ +/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ +/* Reuse tokens from ARB_texture_compression_rgtc */ +/* reuse GL_COMPRESSED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_RG_RGTC2 */ +/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ +/* Reuse tokens from ARB_texture_rg */ +/* reuse GL_RG */ +/* reuse GL_RG_INTEGER */ +/* reuse GL_R8 */ +/* reuse GL_R16 */ +/* reuse GL_RG8 */ +/* reuse GL_RG16 */ +/* reuse GL_R16F */ +/* reuse GL_R32F */ +/* reuse GL_RG16F */ +/* reuse GL_RG32F */ +/* reuse GL_R8I */ +/* reuse GL_R8UI */ +/* reuse GL_R16I */ +/* reuse GL_R16UI */ +/* reuse GL_R32I */ +/* reuse GL_R32UI */ +/* reuse GL_RG8I */ +/* reuse GL_RG8UI */ +/* reuse GL_RG16I */ +/* reuse GL_RG16UI */ +/* reuse GL_RG32I */ +/* reuse GL_RG32UI */ +/* Reuse tokens from ARB_vertex_array_object */ +/* reuse GL_VERTEX_ARRAY_BINDING */ +#endif + +#ifndef GL_VERSION_3_1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#define GL_TEXTURE_BUFFER 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E +#define GL_TEXTURE_RECTANGLE 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 +#define GL_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_R16_SNORM 0x8F98 +#define GL_RG16_SNORM 0x8F99 +#define GL_RGB16_SNORM 0x8F9A +#define GL_RGBA16_SNORM 0x8F9B +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART 0x8F9D +#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E +/* Reuse tokens from ARB_copy_buffer */ +/* reuse GL_COPY_READ_BUFFER */ +/* reuse GL_COPY_WRITE_BUFFER */ +/* Reuse tokens from ARB_draw_instanced (none) */ +/* Reuse tokens from ARB_uniform_buffer_object */ +/* reuse GL_UNIFORM_BUFFER */ +/* reuse GL_UNIFORM_BUFFER_BINDING */ +/* reuse GL_UNIFORM_BUFFER_START */ +/* reuse GL_UNIFORM_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ +/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ +/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ +/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ +/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ +/* reuse GL_UNIFORM_TYPE */ +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_INDEX */ +/* reuse GL_UNIFORM_OFFSET */ +/* reuse GL_UNIFORM_ARRAY_STRIDE */ +/* reuse GL_UNIFORM_MATRIX_STRIDE */ +/* reuse GL_UNIFORM_IS_ROW_MAJOR */ +/* reuse GL_UNIFORM_BLOCK_BINDING */ +/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ +/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_INVALID_INDEX */ +#endif + +#ifndef GL_VERSION_3_2 +#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_LINES_ADJACENCY 0x000A +#define GL_LINE_STRIP_ADJACENCY 0x000B +#define GL_TRIANGLES_ADJACENCY 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D +#define GL_PROGRAM_POINT_SIZE 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 +#define GL_GEOMETRY_SHADER 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT 0x8916 +#define GL_GEOMETRY_INPUT_TYPE 0x8917 +#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 +#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_CONTEXT_PROFILE_MASK 0x9126 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* Reuse tokens from ARB_depth_clamp */ +/* reuse GL_DEPTH_CLAMP */ +/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ +/* Reuse tokens from ARB_fragment_coord_conventions (none) */ +/* Reuse tokens from ARB_provoking_vertex */ +/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +/* Reuse tokens from ARB_seamless_cube_map */ +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +/* Reuse tokens from ARB_sync */ +/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ +/* reuse GL_OBJECT_TYPE */ +/* reuse GL_SYNC_CONDITION */ +/* reuse GL_SYNC_STATUS */ +/* reuse GL_SYNC_FLAGS */ +/* reuse GL_SYNC_FENCE */ +/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ +/* reuse GL_UNSIGNALED */ +/* reuse GL_SIGNALED */ +/* reuse GL_ALREADY_SIGNALED */ +/* reuse GL_TIMEOUT_EXPIRED */ +/* reuse GL_CONDITION_SATISFIED */ +/* reuse GL_WAIT_FAILED */ +/* reuse GL_TIMEOUT_IGNORED */ +/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ +/* reuse GL_TIMEOUT_IGNORED */ +/* Reuse tokens from ARB_texture_multisample */ +/* reuse GL_SAMPLE_POSITION */ +/* reuse GL_SAMPLE_MASK */ +/* reuse GL_SAMPLE_MASK_VALUE */ +/* reuse GL_MAX_SAMPLE_MASK_WORDS */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_SAMPLES */ +/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ +/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ +/* reuse GL_MAX_INTEGER_SAMPLES */ +/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +/* Reuse tokens from ARB_blend_func_extended */ +/* reuse GL_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_ALPHA */ +/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ +/* Reuse tokens from ARB_explicit_attrib_location (none) */ +/* Reuse tokens from ARB_occlusion_query2 */ +/* reuse GL_ANY_SAMPLES_PASSED */ +/* Reuse tokens from ARB_sampler_objects */ +/* reuse GL_SAMPLER_BINDING */ +/* Reuse tokens from ARB_shader_bit_encoding (none) */ +/* Reuse tokens from ARB_texture_rgb10_a2ui */ +/* reuse GL_RGB10_A2UI */ +/* Reuse tokens from ARB_texture_swizzle */ +/* reuse GL_TEXTURE_SWIZZLE_R */ +/* reuse GL_TEXTURE_SWIZZLE_G */ +/* reuse GL_TEXTURE_SWIZZLE_B */ +/* reuse GL_TEXTURE_SWIZZLE_A */ +/* reuse GL_TEXTURE_SWIZZLE_RGBA */ +/* Reuse tokens from ARB_timer_query */ +/* reuse GL_TIME_ELAPSED */ +/* reuse GL_TIMESTAMP */ +/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ +/* reuse GL_INT_2_10_10_10_REV */ +#endif + +#ifndef GL_VERSION_4_0 +#define GL_SAMPLE_SHADING 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F +#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +/* Reuse tokens from ARB_texture_query_lod (none) */ +/* Reuse tokens from ARB_draw_buffers_blend (none) */ +/* Reuse tokens from ARB_draw_indirect */ +/* reuse GL_DRAW_INDIRECT_BUFFER */ +/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_gpu_shader5 */ +/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +/* Reuse tokens from ARB_gpu_shader_fp64 */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +/* Reuse tokens from ARB_shader_subroutine */ +/* reuse GL_ACTIVE_SUBROUTINES */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ +/* reuse GL_MAX_SUBROUTINES */ +/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +/* Reuse tokens from ARB_tessellation_shader */ +/* reuse GL_PATCHES */ +/* reuse GL_PATCH_VERTICES */ +/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ +/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ +/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ +/* reuse GL_TESS_GEN_MODE */ +/* reuse GL_TESS_GEN_SPACING */ +/* reuse GL_TESS_GEN_VERTEX_ORDER */ +/* reuse GL_TESS_GEN_POINT_MODE */ +/* reuse GL_ISOLINES */ +/* reuse GL_FRACTIONAL_ODD */ +/* reuse GL_FRACTIONAL_EVEN */ +/* reuse GL_MAX_PATCH_VERTICES */ +/* reuse GL_MAX_TESS_GEN_LEVEL */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_CONTROL_SHADER */ +/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ +/* Reuse tokens from ARB_transform_feedback2 */ +/* reuse GL_TRANSFORM_FEEDBACK */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ +/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ +/* Reuse tokens from ARB_transform_feedback3 */ +/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_VERSION_4_1 +/* Reuse tokens from ARB_ES2_compatibility */ +/* reuse GL_FIXED */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ +/* reuse GL_LOW_FLOAT */ +/* reuse GL_MEDIUM_FLOAT */ +/* reuse GL_HIGH_FLOAT */ +/* reuse GL_LOW_INT */ +/* reuse GL_MEDIUM_INT */ +/* reuse GL_HIGH_INT */ +/* reuse GL_SHADER_COMPILER */ +/* reuse GL_NUM_SHADER_BINARY_FORMATS */ +/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ +/* reuse GL_MAX_VARYING_VECTORS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ +/* reuse GL_RGB565 */ +/* Reuse tokens from ARB_get_program_binary */ +/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ +/* reuse GL_PROGRAM_BINARY_LENGTH */ +/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ +/* reuse GL_PROGRAM_BINARY_FORMATS */ +/* Reuse tokens from ARB_separate_shader_objects */ +/* reuse GL_VERTEX_SHADER_BIT */ +/* reuse GL_FRAGMENT_SHADER_BIT */ +/* reuse GL_GEOMETRY_SHADER_BIT */ +/* reuse GL_TESS_CONTROL_SHADER_BIT */ +/* reuse GL_TESS_EVALUATION_SHADER_BIT */ +/* reuse GL_ALL_SHADER_BITS */ +/* reuse GL_PROGRAM_SEPARABLE */ +/* reuse GL_ACTIVE_PROGRAM */ +/* reuse GL_PROGRAM_PIPELINE_BINDING */ +/* Reuse tokens from ARB_shader_precision (none) */ +/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ +/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ +/* reuse GL_MAX_VIEWPORTS */ +/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ +/* reuse GL_VIEWPORT_BOUNDS_RANGE */ +/* reuse GL_LAYER_PROVOKING_VERTEX */ +/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ +/* reuse GL_UNDEFINED_VERTEX */ +#endif + +#ifndef GL_VERSION_4_2 +/* Reuse tokens from ARB_base_instance (none) */ +/* Reuse tokens from ARB_shading_language_420pack (none) */ +/* Reuse tokens from ARB_transform_feedback_instanced (none) */ +/* Reuse tokens from ARB_compressed_texture_pixel_storage */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_DEPTH */ +/* reuse GL_UNPACK_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_PACK_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_PACK_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_PACK_COMPRESSED_BLOCK_DEPTH */ +/* reuse GL_PACK_COMPRESSED_BLOCK_SIZE */ +/* Reuse tokens from ARB_conservative_depth (none) */ +/* Reuse tokens from ARB_internalformat_query */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* Reuse tokens from ARB_map_buffer_alignment */ +/* reuse GL_MIN_MAP_BUFFER_ALIGNMENT */ +/* Reuse tokens from ARB_shader_atomic_counters */ +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_BINDING */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_START */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_SIZE */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_VERTEX_ATOMIC_COUNTERS */ +/* reuse GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS */ +/* reuse GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS */ +/* reuse GL_MAX_GEOMETRY_ATOMIC_COUNTERS */ +/* reuse GL_MAX_FRAGMENT_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_ATOMIC_COUNTERS */ +/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE */ +/* reuse GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS */ +/* reuse GL_ACTIVE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_UNSIGNED_INT_ATOMIC_COUNTER */ +/* Reuse tokens from ARB_shader_image_load_store */ +/* reuse GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT */ +/* reuse GL_ELEMENT_ARRAY_BARRIER_BIT */ +/* reuse GL_UNIFORM_BARRIER_BIT */ +/* reuse GL_TEXTURE_FETCH_BARRIER_BIT */ +/* reuse GL_SHADER_IMAGE_ACCESS_BARRIER_BIT */ +/* reuse GL_COMMAND_BARRIER_BIT */ +/* reuse GL_PIXEL_BUFFER_BARRIER_BIT */ +/* reuse GL_TEXTURE_UPDATE_BARRIER_BIT */ +/* reuse GL_BUFFER_UPDATE_BARRIER_BIT */ +/* reuse GL_FRAMEBUFFER_BARRIER_BIT */ +/* reuse GL_TRANSFORM_FEEDBACK_BARRIER_BIT */ +/* reuse GL_ATOMIC_COUNTER_BARRIER_BIT */ +/* reuse GL_ALL_BARRIER_BITS */ +/* reuse GL_MAX_IMAGE_UNITS */ +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +/* reuse GL_IMAGE_BINDING_NAME */ +/* reuse GL_IMAGE_BINDING_LEVEL */ +/* reuse GL_IMAGE_BINDING_LAYERED */ +/* reuse GL_IMAGE_BINDING_LAYER */ +/* reuse GL_IMAGE_BINDING_ACCESS */ +/* reuse GL_IMAGE_1D */ +/* reuse GL_IMAGE_2D */ +/* reuse GL_IMAGE_3D */ +/* reuse GL_IMAGE_2D_RECT */ +/* reuse GL_IMAGE_CUBE */ +/* reuse GL_IMAGE_BUFFER */ +/* reuse GL_IMAGE_1D_ARRAY */ +/* reuse GL_IMAGE_2D_ARRAY */ +/* reuse GL_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_IMAGE_1D */ +/* reuse GL_INT_IMAGE_2D */ +/* reuse GL_INT_IMAGE_3D */ +/* reuse GL_INT_IMAGE_2D_RECT */ +/* reuse GL_INT_IMAGE_CUBE */ +/* reuse GL_INT_IMAGE_BUFFER */ +/* reuse GL_INT_IMAGE_1D_ARRAY */ +/* reuse GL_INT_IMAGE_2D_ARRAY */ +/* reuse GL_INT_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_INT_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_1D */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D */ +/* reuse GL_UNSIGNED_INT_IMAGE_3D */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_RECT */ +/* reuse GL_UNSIGNED_INT_IMAGE_CUBE */ +/* reuse GL_UNSIGNED_INT_IMAGE_BUFFER */ +/* reuse GL_UNSIGNED_INT_IMAGE_1D_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_IMAGE_SAMPLES */ +/* reuse GL_IMAGE_BINDING_FORMAT */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE */ +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS */ +/* reuse GL_MAX_VERTEX_IMAGE_UNIFORMS */ +/* reuse GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS */ +/* reuse GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS */ +/* reuse GL_MAX_GEOMETRY_IMAGE_UNIFORMS */ +/* reuse GL_MAX_FRAGMENT_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMBINED_IMAGE_UNIFORMS */ +/* Reuse tokens from ARB_shading_language_packing (none) */ +/* Reuse tokens from ARB_texture_storage */ +/* reuse GL_TEXTURE_IMMUTABLE_FORMAT */ +#endif + +#ifndef GL_VERSION_4_3 +#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9 +#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E +/* Reuse tokens from ARB_arrays_of_arrays (none, GLSL only) */ +/* Reuse tokens from ARB_fragment_layer_viewport (none, GLSL only) */ +/* Reuse tokens from ARB_shader_image_size (none, GLSL only) */ +/* Reuse tokens from ARB_ES3_compatibility */ +/* reuse GL_COMPRESSED_RGB8_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_ETC2 */ +/* reuse GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 */ +/* reuse GL_COMPRESSED_RGBA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ +/* reuse GL_COMPRESSED_R11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_R11_EAC */ +/* reuse GL_COMPRESSED_RG11_EAC */ +/* reuse GL_COMPRESSED_SIGNED_RG11_EAC */ +/* reuse GL_PRIMITIVE_RESTART_FIXED_INDEX */ +/* reuse GL_ANY_SAMPLES_PASSED_CONSERVATIVE */ +/* reuse GL_MAX_ELEMENT_INDEX */ +/* Reuse tokens from ARB_clear_buffer_object (none) */ +/* Reuse tokens from ARB_compute_shader */ +/* reuse GL_COMPUTE_SHADER */ +/* reuse GL_MAX_COMPUTE_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_COMPUTE_IMAGE_UNIFORMS */ +/* reuse GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */ +/* reuse GL_MAX_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS */ +/* reuse GL_MAX_COMPUTE_ATOMIC_COUNTERS */ +/* reuse GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMPUTE_LOCAL_INVOCATIONS */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_COUNT */ +/* reuse GL_MAX_COMPUTE_WORK_GROUP_SIZE */ +/* reuse GL_COMPUTE_LOCAL_WORK_SIZE */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER */ +/* reuse GL_DISPATCH_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_copy_image (none) */ +/* Reuse tokens from KHR_debug */ +/* reuse GL_DEBUG_OUTPUT_SYNCHRONOUS */ +/* reuse GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH */ +/* reuse GL_DEBUG_CALLBACK_FUNCTION */ +/* reuse GL_DEBUG_CALLBACK_USER_PARAM */ +/* reuse GL_DEBUG_SOURCE_API */ +/* reuse GL_DEBUG_SOURCE_WINDOW_SYSTEM */ +/* reuse GL_DEBUG_SOURCE_SHADER_COMPILER */ +/* reuse GL_DEBUG_SOURCE_THIRD_PARTY */ +/* reuse GL_DEBUG_SOURCE_APPLICATION */ +/* reuse GL_DEBUG_SOURCE_OTHER */ +/* reuse GL_DEBUG_TYPE_ERROR */ +/* reuse GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR */ +/* reuse GL_DEBUG_TYPE_PORTABILITY */ +/* reuse GL_DEBUG_TYPE_PERFORMANCE */ +/* reuse GL_DEBUG_TYPE_OTHER */ +/* reuse GL_MAX_DEBUG_MESSAGE_LENGTH */ +/* reuse GL_MAX_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_LOGGED_MESSAGES */ +/* reuse GL_DEBUG_SEVERITY_HIGH */ +/* reuse GL_DEBUG_SEVERITY_MEDIUM */ +/* reuse GL_DEBUG_SEVERITY_LOW */ +/* reuse GL_DEBUG_TYPE_MARKER */ +/* reuse GL_DEBUG_TYPE_PUSH_GROUP */ +/* reuse GL_DEBUG_TYPE_POP_GROUP */ +/* reuse GL_DEBUG_SEVERITY_NOTIFICATION */ +/* reuse GL_MAX_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_DEBUG_GROUP_STACK_DEPTH */ +/* reuse GL_BUFFER */ +/* reuse GL_SHADER */ +/* reuse GL_PROGRAM */ +/* reuse GL_QUERY */ +/* reuse GL_PROGRAM_PIPELINE */ +/* reuse GL_SAMPLER */ +/* reuse GL_DISPLAY_LIST */ +/* reuse GL_MAX_LABEL_LENGTH */ +/* reuse GL_DEBUG_OUTPUT */ +/* reuse GL_CONTEXT_FLAG_DEBUG_BIT */ +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +/* Reuse tokens from ARB_explicit_uniform_location */ +/* reuse GL_MAX_UNIFORM_LOCATIONS */ +/* Reuse tokens from ARB_framebuffer_no_attachments */ +/* reuse GL_FRAMEBUFFER_DEFAULT_WIDTH */ +/* reuse GL_FRAMEBUFFER_DEFAULT_HEIGHT */ +/* reuse GL_FRAMEBUFFER_DEFAULT_LAYERS */ +/* reuse GL_FRAMEBUFFER_DEFAULT_SAMPLES */ +/* reuse GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_MAX_FRAMEBUFFER_WIDTH */ +/* reuse GL_MAX_FRAMEBUFFER_HEIGHT */ +/* reuse GL_MAX_FRAMEBUFFER_LAYERS */ +/* reuse GL_MAX_FRAMEBUFFER_SAMPLES */ +/* Reuse tokens from ARB_internalformat_query2 */ +/* reuse GL_INTERNALFORMAT_SUPPORTED */ +/* reuse GL_INTERNALFORMAT_PREFERRED */ +/* reuse GL_INTERNALFORMAT_RED_SIZE */ +/* reuse GL_INTERNALFORMAT_GREEN_SIZE */ +/* reuse GL_INTERNALFORMAT_BLUE_SIZE */ +/* reuse GL_INTERNALFORMAT_ALPHA_SIZE */ +/* reuse GL_INTERNALFORMAT_DEPTH_SIZE */ +/* reuse GL_INTERNALFORMAT_STENCIL_SIZE */ +/* reuse GL_INTERNALFORMAT_SHARED_SIZE */ +/* reuse GL_INTERNALFORMAT_RED_TYPE */ +/* reuse GL_INTERNALFORMAT_GREEN_TYPE */ +/* reuse GL_INTERNALFORMAT_BLUE_TYPE */ +/* reuse GL_INTERNALFORMAT_ALPHA_TYPE */ +/* reuse GL_INTERNALFORMAT_DEPTH_TYPE */ +/* reuse GL_INTERNALFORMAT_STENCIL_TYPE */ +/* reuse GL_MAX_WIDTH */ +/* reuse GL_MAX_HEIGHT */ +/* reuse GL_MAX_DEPTH */ +/* reuse GL_MAX_LAYERS */ +/* reuse GL_MAX_COMBINED_DIMENSIONS */ +/* reuse GL_COLOR_COMPONENTS */ +/* reuse GL_DEPTH_COMPONENTS */ +/* reuse GL_STENCIL_COMPONENTS */ +/* reuse GL_COLOR_RENDERABLE */ +/* reuse GL_DEPTH_RENDERABLE */ +/* reuse GL_STENCIL_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE */ +/* reuse GL_FRAMEBUFFER_RENDERABLE_LAYERED */ +/* reuse GL_FRAMEBUFFER_BLEND */ +/* reuse GL_READ_PIXELS */ +/* reuse GL_READ_PIXELS_FORMAT */ +/* reuse GL_READ_PIXELS_TYPE */ +/* reuse GL_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_TEXTURE_IMAGE_TYPE */ +/* reuse GL_GET_TEXTURE_IMAGE_FORMAT */ +/* reuse GL_GET_TEXTURE_IMAGE_TYPE */ +/* reuse GL_MIPMAP */ +/* reuse GL_MANUAL_GENERATE_MIPMAP */ +/* reuse GL_AUTO_GENERATE_MIPMAP */ +/* reuse GL_COLOR_ENCODING */ +/* reuse GL_SRGB_READ */ +/* reuse GL_SRGB_WRITE */ +/* reuse GL_FILTER */ +/* reuse GL_VERTEX_TEXTURE */ +/* reuse GL_TESS_CONTROL_TEXTURE */ +/* reuse GL_TESS_EVALUATION_TEXTURE */ +/* reuse GL_GEOMETRY_TEXTURE */ +/* reuse GL_FRAGMENT_TEXTURE */ +/* reuse GL_COMPUTE_TEXTURE */ +/* reuse GL_TEXTURE_SHADOW */ +/* reuse GL_TEXTURE_GATHER */ +/* reuse GL_TEXTURE_GATHER_SHADOW */ +/* reuse GL_SHADER_IMAGE_LOAD */ +/* reuse GL_SHADER_IMAGE_STORE */ +/* reuse GL_SHADER_IMAGE_ATOMIC */ +/* reuse GL_IMAGE_TEXEL_SIZE */ +/* reuse GL_IMAGE_COMPATIBILITY_CLASS */ +/* reuse GL_IMAGE_PIXEL_FORMAT */ +/* reuse GL_IMAGE_PIXEL_TYPE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE */ +/* reuse GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_WIDTH */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT */ +/* reuse GL_TEXTURE_COMPRESSED_BLOCK_SIZE */ +/* reuse GL_CLEAR_BUFFER */ +/* reuse GL_TEXTURE_VIEW */ +/* reuse GL_VIEW_COMPATIBILITY_CLASS */ +/* reuse GL_FULL_SUPPORT */ +/* reuse GL_CAVEAT_SUPPORT */ +/* reuse GL_IMAGE_CLASS_4_X_32 */ +/* reuse GL_IMAGE_CLASS_2_X_32 */ +/* reuse GL_IMAGE_CLASS_1_X_32 */ +/* reuse GL_IMAGE_CLASS_4_X_16 */ +/* reuse GL_IMAGE_CLASS_2_X_16 */ +/* reuse GL_IMAGE_CLASS_1_X_16 */ +/* reuse GL_IMAGE_CLASS_4_X_8 */ +/* reuse GL_IMAGE_CLASS_2_X_8 */ +/* reuse GL_IMAGE_CLASS_1_X_8 */ +/* reuse GL_IMAGE_CLASS_11_11_10 */ +/* reuse GL_IMAGE_CLASS_10_10_10_2 */ +/* reuse GL_VIEW_CLASS_128_BITS */ +/* reuse GL_VIEW_CLASS_96_BITS */ +/* reuse GL_VIEW_CLASS_64_BITS */ +/* reuse GL_VIEW_CLASS_48_BITS */ +/* reuse GL_VIEW_CLASS_32_BITS */ +/* reuse GL_VIEW_CLASS_24_BITS */ +/* reuse GL_VIEW_CLASS_16_BITS */ +/* reuse GL_VIEW_CLASS_8_BITS */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGB */ +/* reuse GL_VIEW_CLASS_S3TC_DXT1_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT3_RGBA */ +/* reuse GL_VIEW_CLASS_S3TC_DXT5_RGBA */ +/* reuse GL_VIEW_CLASS_RGTC1_RED */ +/* reuse GL_VIEW_CLASS_RGTC2_RG */ +/* reuse GL_VIEW_CLASS_BPTC_UNORM */ +/* reuse GL_VIEW_CLASS_BPTC_FLOAT */ +/* Reuse tokens from ARB_invalidate_subdata (none) */ +/* Reuse tokens from ARB_multi_draw_indirect (none) */ +/* Reuse tokens from ARB_program_interface_query */ +/* reuse GL_UNIFORM */ +/* reuse GL_UNIFORM_BLOCK */ +/* reuse GL_PROGRAM_INPUT */ +/* reuse GL_PROGRAM_OUTPUT */ +/* reuse GL_BUFFER_VARIABLE */ +/* reuse GL_SHADER_STORAGE_BLOCK */ +/* reuse GL_VERTEX_SUBROUTINE */ +/* reuse GL_TESS_CONTROL_SUBROUTINE */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE */ +/* reuse GL_GEOMETRY_SUBROUTINE */ +/* reuse GL_FRAGMENT_SUBROUTINE */ +/* reuse GL_COMPUTE_SUBROUTINE */ +/* reuse GL_VERTEX_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_CONTROL_SUBROUTINE_UNIFORM */ +/* reuse GL_TESS_EVALUATION_SUBROUTINE_UNIFORM */ +/* reuse GL_GEOMETRY_SUBROUTINE_UNIFORM */ +/* reuse GL_FRAGMENT_SUBROUTINE_UNIFORM */ +/* reuse GL_COMPUTE_SUBROUTINE_UNIFORM */ +/* reuse GL_TRANSFORM_FEEDBACK_VARYING */ +/* reuse GL_ACTIVE_RESOURCES */ +/* reuse GL_MAX_NAME_LENGTH */ +/* reuse GL_MAX_NUM_ACTIVE_VARIABLES */ +/* reuse GL_MAX_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_NAME_LENGTH */ +/* reuse GL_TYPE */ +/* reuse GL_ARRAY_SIZE */ +/* reuse GL_OFFSET */ +/* reuse GL_BLOCK_INDEX */ +/* reuse GL_ARRAY_STRIDE */ +/* reuse GL_MATRIX_STRIDE */ +/* reuse GL_IS_ROW_MAJOR */ +/* reuse GL_ATOMIC_COUNTER_BUFFER_INDEX */ +/* reuse GL_BUFFER_BINDING */ +/* reuse GL_BUFFER_DATA_SIZE */ +/* reuse GL_NUM_ACTIVE_VARIABLES */ +/* reuse GL_ACTIVE_VARIABLES */ +/* reuse GL_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_REFERENCED_BY_GEOMETRY_SHADER */ +/* reuse GL_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_REFERENCED_BY_COMPUTE_SHADER */ +/* reuse GL_TOP_LEVEL_ARRAY_SIZE */ +/* reuse GL_TOP_LEVEL_ARRAY_STRIDE */ +/* reuse GL_LOCATION */ +/* reuse GL_LOCATION_INDEX */ +/* reuse GL_IS_PER_PATCH */ +/* Reuse tokens from ARB_robust_buffer_access_behavior (none) */ +/* Reuse tokens from ARB_shader_storage_buffer_object */ +/* reuse GL_SHADER_STORAGE_BUFFER */ +/* reuse GL_SHADER_STORAGE_BUFFER_BINDING */ +/* reuse GL_SHADER_STORAGE_BUFFER_START */ +/* reuse GL_SHADER_STORAGE_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS */ +/* reuse GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS */ +/* reuse GL_MAX_SHADER_STORAGE_BLOCK_SIZE */ +/* reuse GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_SHADER_STORAGE_BARRIER_BIT */ +/* reuse GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES */ +/* Reuse tokens from ARB_stencil_texturing */ +/* reuse GL_DEPTH_STENCIL_TEXTURE_MODE */ +/* Reuse tokens from ARB_texture_buffer_range */ +/* reuse GL_TEXTURE_BUFFER_OFFSET */ +/* reuse GL_TEXTURE_BUFFER_SIZE */ +/* reuse GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT */ +/* Reuse tokens from ARB_texture_query_levels (none) */ +/* Reuse tokens from ARB_texture_storage_multisample (none) */ +/* Reuse tokens from ARB_texture_view */ +/* reuse GL_TEXTURE_VIEW_MIN_LEVEL */ +/* reuse GL_TEXTURE_VIEW_NUM_LEVELS */ +/* reuse GL_TEXTURE_VIEW_MIN_LAYER */ +/* reuse GL_TEXTURE_VIEW_NUM_LAYERS */ +/* reuse GL_TEXTURE_IMMUTABLE_LEVELS */ +/* Reuse tokens from ARB_vertex_attrib_binding */ +/* reuse GL_VERTEX_ATTRIB_BINDING */ +/* reuse GL_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_VERTEX_BINDING_DIVISOR */ +/* reuse GL_VERTEX_BINDING_OFFSET */ +/* reuse GL_VERTEX_BINDING_STRIDE */ +/* reuse GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET */ +/* reuse GL_MAX_VERTEX_ATTRIB_BINDINGS */ +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_HALF_FLOAT 0x140B +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE +#endif + +#ifndef GL_ARB_texture_rg +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_R16 0x822A +#define GL_RG8 0x822B +#define GL_RG16 0x822C +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_COPY_READ_BUFFER_BINDING 0x8F36 +#define GL_COPY_READ_BUFFER GL_COPY_READ_BUFFER_BINDING +#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37 +#define GL_COPY_WRITE_BUFFER GL_COPY_WRITE_BUFFER_BINDING +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_DEPTH_CLAMP 0x864F +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#define GL_LAST_VERTEX_CONVENTION 0x8E4E +#define GL_PROVOKING_VERTEX 0x8E4F +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif + +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_SAMPLE_POSITION 0x8E50 +#define GL_SAMPLE_MASK 0x8E51 +#define GL_SAMPLE_MASK_VALUE 0x8E52 +#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 +#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 +#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 +#define GL_TEXTURE_SAMPLES 0x9106 +#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E +#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F +#define GL_MAX_INTEGER_SAMPLES 0x9110 +#endif + +#ifndef GL_ARB_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_ARB_draw_buffers_blend +#endif + +#ifndef GL_ARB_sample_shading +#define GL_SAMPLE_SHADING_ARB 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F +#endif + +#ifndef GL_ARB_texture_gather +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F +#endif + +#ifndef GL_ARB_texture_query_lod +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_SHADER_INCLUDE_ARB 0x8DAE +#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 +#define GL_NAMED_STRING_TYPE_ARB 0x8DEA +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_SRC1_COLOR 0x88F9 +/* reuse GL_SRC1_ALPHA */ +#define GL_ONE_MINUS_SRC1_COLOR 0x88FA +#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB +#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC +#endif + +#ifndef GL_ARB_explicit_attrib_location +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_SAMPLER_BINDING 0x8919 +#endif + +#ifndef GL_ARB_shader_bit_encoding +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_RGB10_A2UI 0x906F +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +#endif + +#ifndef GL_ARB_timer_query +#define GL_TIME_ELAPSED 0x88BF +#define GL_TIMESTAMP 0x8E28 +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ +#define GL_INT_2_10_10_10_REV 0x8D9F +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F +#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C +#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +/* reuse GL_DOUBLE */ +#define GL_DOUBLE_VEC2 0x8FFC +#define GL_DOUBLE_VEC3 0x8FFD +#define GL_DOUBLE_VEC4 0x8FFE +#define GL_DOUBLE_MAT2 0x8F46 +#define GL_DOUBLE_MAT3 0x8F47 +#define GL_DOUBLE_MAT4 0x8F48 +#define GL_DOUBLE_MAT2x3 0x8F49 +#define GL_DOUBLE_MAT2x4 0x8F4A +#define GL_DOUBLE_MAT3x2 0x8F4B +#define GL_DOUBLE_MAT3x4 0x8F4C +#define GL_DOUBLE_MAT4x2 0x8F4D +#define GL_DOUBLE_MAT4x3 0x8F4E +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ACTIVE_SUBROUTINES 0x8DE5 +#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 +#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 +#define GL_MAX_SUBROUTINES 0x8DE7 +#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 +#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A +#define GL_COMPATIBLE_SUBROUTINES 0x8E4B +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_PATCHES 0x000E +#define GL_PATCH_VERTICES 0x8E72 +#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 +#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 +#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 +#define GL_TESS_GEN_MODE 0x8E76 +#define GL_TESS_GEN_SPACING 0x8E77 +#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 +#define GL_TESS_GEN_POINT_MODE 0x8E79 +/* reuse GL_TRIANGLES */ +/* reuse GL_QUADS */ +#define GL_ISOLINES 0x8E7A +/* reuse GL_EQUAL */ +#define GL_FRACTIONAL_ODD 0x8E7B +#define GL_FRACTIONAL_EVEN 0x8E7C +/* reuse GL_CCW */ +/* reuse GL_CW */ +#define GL_MAX_PATCH_VERTICES 0x8E7D +#define GL_MAX_TESS_GEN_LEVEL 0x8E7E +#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F +#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 +#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 +#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 +#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 +#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 +#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 +#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 +#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 +#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A +#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C +#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D +#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E +#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 +#define GL_TESS_EVALUATION_SHADER 0x8E87 +#define GL_TESS_CONTROL_SHADER 0x8E88 +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +/* reuse GL_RGB32F */ +/* reuse GL_RGB32UI */ +/* reuse GL_RGB32I */ +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED GL_TRANSFORM_FEEDBACK_PAUSED +#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE GL_TRANSFORM_FEEDBACK_ACTIVE +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 +#define GL_MAX_VERTEX_STREAMS 0x8E71 +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_FIXED 0x140C +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 +#define GL_SHADER_COMPILER 0x8DFA +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_RGB565 0x8D62 +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_VERTEX_SHADER_BIT 0x00000001 +#define GL_FRAGMENT_SHADER_BIT 0x00000002 +#define GL_GEOMETRY_SHADER_BIT 0x00000004 +#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 +#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 +#define GL_ALL_SHADER_BITS 0xFFFFFFFF +#define GL_PROGRAM_SEPARABLE 0x8258 +#define GL_ACTIVE_PROGRAM 0x8259 +#define GL_PROGRAM_PIPELINE_BINDING 0x825A +#endif + +#ifndef GL_ARB_shader_precision +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +/* reuse GL_RGB32I */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +#endif + +#ifndef GL_ARB_viewport_array +/* reuse GL_SCISSOR_BOX */ +/* reuse GL_VIEWPORT */ +/* reuse GL_DEPTH_RANGE */ +/* reuse GL_SCISSOR_TEST */ +#define GL_MAX_VIEWPORTS 0x825B +#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C +#define GL_VIEWPORT_BOUNDS_RANGE 0x825D +#define GL_LAYER_PROVOKING_VERTEX 0x825E +#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F +#define GL_UNDEFINED_VERTEX 0x8260 +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +#endif + +#ifndef GL_ARB_cl_event +#define GL_SYNC_CL_EVENT_ARB 0x8240 +#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 +#endif + +#ifndef GL_ARB_debug_output +#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 +#define GL_DEBUG_SOURCE_API_ARB 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A +#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B +#define GL_DEBUG_TYPE_ERROR_ARB 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E +#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 +#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 +#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 +#endif + +#ifndef GL_ARB_robustness +/* reuse GL_NO_ERROR */ +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GL_ARB_shader_stencil_export +#endif + +#ifndef GL_ARB_base_instance +#endif + +#ifndef GL_ARB_shading_language_420pack +#endif + +#ifndef GL_ARB_transform_feedback_instanced +#endif + +#ifndef GL_ARB_compressed_texture_pixel_storage +#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127 +#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128 +#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129 +#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A +#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B +#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C +#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D +#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E +#endif + +#ifndef GL_ARB_conservative_depth +#endif + +#ifndef GL_ARB_internalformat_query +#define GL_NUM_SAMPLE_COUNTS 0x9380 +#endif + +#ifndef GL_ARB_map_buffer_alignment +#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC +#endif + +#ifndef GL_ARB_shader_atomic_counters +#define GL_ATOMIC_COUNTER_BUFFER 0x92C0 +#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1 +#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2 +#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3 +#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5 +#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9 +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB +#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE +#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF +#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0 +#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1 +#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2 +#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3 +#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4 +#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5 +#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6 +#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8 +#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC +#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9 +#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA +#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB +#endif + +#ifndef GL_ARB_shader_image_load_store +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020 +#define GL_COMMAND_BARRIER_BIT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000 +#define GL_ALL_BARRIER_BITS 0xFFFFFFFF +#define GL_MAX_IMAGE_UNITS 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39 +#define GL_IMAGE_BINDING_NAME 0x8F3A +#define GL_IMAGE_BINDING_LEVEL 0x8F3B +#define GL_IMAGE_BINDING_LAYERED 0x8F3C +#define GL_IMAGE_BINDING_LAYER 0x8F3D +#define GL_IMAGE_BINDING_ACCESS 0x8F3E +#define GL_IMAGE_1D 0x904C +#define GL_IMAGE_2D 0x904D +#define GL_IMAGE_3D 0x904E +#define GL_IMAGE_2D_RECT 0x904F +#define GL_IMAGE_CUBE 0x9050 +#define GL_IMAGE_BUFFER 0x9051 +#define GL_IMAGE_1D_ARRAY 0x9052 +#define GL_IMAGE_2D_ARRAY 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056 +#define GL_INT_IMAGE_1D 0x9057 +#define GL_INT_IMAGE_2D 0x9058 +#define GL_INT_IMAGE_3D 0x9059 +#define GL_INT_IMAGE_2D_RECT 0x905A +#define GL_INT_IMAGE_CUBE 0x905B +#define GL_INT_IMAGE_BUFFER 0x905C +#define GL_INT_IMAGE_1D_ARRAY 0x905D +#define GL_INT_IMAGE_2D_ARRAY 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C +#define GL_MAX_IMAGE_SAMPLES 0x906D +#define GL_IMAGE_BINDING_FORMAT 0x906E +#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8 +#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9 +#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA +#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB +#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC +#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD +#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE +#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF +#endif + +#ifndef GL_ARB_shading_language_packing +#endif + +#ifndef GL_ARB_texture_storage +#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD +#endif + +#ifndef GL_KHR_debug +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_BUFFER 0x82E0 +#define GL_SHADER 0x82E1 +#define GL_PROGRAM 0x82E2 +#define GL_QUERY 0x82E3 +#define GL_PROGRAM_PIPELINE 0x82E4 +#define GL_SAMPLER 0x82E6 +#define GL_DISPLAY_LIST 0x82E7 +/* DISPLAY_LIST used in compatibility profile only */ +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 +/* reuse GL_STACK_UNDERFLOW */ +/* reuse GL_STACK_OVERFLOW */ +#endif + +#ifndef GL_ARB_arrays_of_arrays +#endif + +#ifndef GL_ARB_clear_buffer_object +#endif + +#ifndef GL_ARB_compute_shader +#define GL_COMPUTE_SHADER 0x91B9 +#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB +#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC +#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD +#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262 +#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263 +#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264 +#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265 +#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266 +#define GL_MAX_COMPUTE_LOCAL_INVOCATIONS 0x90EB +#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE +#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF +#define GL_COMPUTE_LOCAL_WORK_SIZE 0x8267 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC +#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED +#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF +#define GL_COMPUTE_SHADER_BIT 0x00000020 +#endif + +#ifndef GL_ARB_copy_image +#endif + +#ifndef GL_ARB_texture_view +#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB +#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC +#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD +#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_VERTEX_ATTRIB_BINDING 0x82D4 +#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5 +#define GL_VERTEX_BINDING_DIVISOR 0x82D6 +#define GL_VERTEX_BINDING_OFFSET 0x82D7 +#define GL_VERTEX_BINDING_STRIDE 0x82D8 +#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9 +#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA +#endif + +#ifndef GL_ARB_robustness_isolation +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_MAX_UNIFORM_LOCATIONS 0x826E +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310 +#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311 +#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312 +#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313 +#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314 +#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315 +#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316 +#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317 +#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318 +#endif + +#ifndef GL_ARB_internalformat_query2 +/* reuse GL_IMAGE_FORMAT_COMPATIBILITY_TYPE */ +/* reuse GL_NUM_SAMPLE_COUNTS */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_SAMPLES */ +/* reuse GL_TEXTURE_1D */ +/* reuse GL_TEXTURE_1D_ARRAY */ +/* reuse GL_TEXTURE_2D */ +/* reuse GL_TEXTURE_2D_ARRAY */ +/* reuse GL_TEXTURE_3D */ +/* reuse GL_TEXTURE_CUBE_MAP */ +/* reuse GL_TEXTURE_CUBE_MAP_ARRAY */ +/* reuse GL_TEXTURE_RECTANGLE */ +/* reuse GL_TEXTURE_BUFFER */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_COMPRESSED */ +#define GL_INTERNALFORMAT_SUPPORTED 0x826F +#define GL_INTERNALFORMAT_PREFERRED 0x8270 +#define GL_INTERNALFORMAT_RED_SIZE 0x8271 +#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272 +#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273 +#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274 +#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275 +#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276 +#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277 +#define GL_INTERNALFORMAT_RED_TYPE 0x8278 +#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279 +#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A +#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B +#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C +#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D +#define GL_MAX_WIDTH 0x827E +#define GL_MAX_HEIGHT 0x827F +#define GL_MAX_DEPTH 0x8280 +#define GL_MAX_LAYERS 0x8281 +#define GL_MAX_COMBINED_DIMENSIONS 0x8282 +#define GL_COLOR_COMPONENTS 0x8283 +#define GL_DEPTH_COMPONENTS 0x8284 +#define GL_STENCIL_COMPONENTS 0x8285 +#define GL_COLOR_RENDERABLE 0x8286 +#define GL_DEPTH_RENDERABLE 0x8287 +#define GL_STENCIL_RENDERABLE 0x8288 +#define GL_FRAMEBUFFER_RENDERABLE 0x8289 +#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A +#define GL_FRAMEBUFFER_BLEND 0x828B +#define GL_READ_PIXELS 0x828C +#define GL_READ_PIXELS_FORMAT 0x828D +#define GL_READ_PIXELS_TYPE 0x828E +#define GL_TEXTURE_IMAGE_FORMAT 0x828F +#define GL_TEXTURE_IMAGE_TYPE 0x8290 +#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291 +#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292 +#define GL_MIPMAP 0x8293 +#define GL_MANUAL_GENERATE_MIPMAP 0x8294 +#define GL_AUTO_GENERATE_MIPMAP 0x8295 +#define GL_COLOR_ENCODING 0x8296 +#define GL_SRGB_READ 0x8297 +#define GL_SRGB_WRITE 0x8298 +#define GL_SRGB_DECODE_ARB 0x8299 +#define GL_FILTER 0x829A +#define GL_VERTEX_TEXTURE 0x829B +#define GL_TESS_CONTROL_TEXTURE 0x829C +#define GL_TESS_EVALUATION_TEXTURE 0x829D +#define GL_GEOMETRY_TEXTURE 0x829E +#define GL_FRAGMENT_TEXTURE 0x829F +#define GL_COMPUTE_TEXTURE 0x82A0 +#define GL_TEXTURE_SHADOW 0x82A1 +#define GL_TEXTURE_GATHER 0x82A2 +#define GL_TEXTURE_GATHER_SHADOW 0x82A3 +#define GL_SHADER_IMAGE_LOAD 0x82A4 +#define GL_SHADER_IMAGE_STORE 0x82A5 +#define GL_SHADER_IMAGE_ATOMIC 0x82A6 +#define GL_IMAGE_TEXEL_SIZE 0x82A7 +#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8 +#define GL_IMAGE_PIXEL_FORMAT 0x82A9 +#define GL_IMAGE_PIXEL_TYPE 0x82AA +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD +#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE +#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF +#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1 +#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2 +#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3 +#define GL_CLEAR_BUFFER 0x82B4 +#define GL_TEXTURE_VIEW 0x82B5 +#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6 +#define GL_FULL_SUPPORT 0x82B7 +#define GL_CAVEAT_SUPPORT 0x82B8 +#define GL_IMAGE_CLASS_4_X_32 0x82B9 +#define GL_IMAGE_CLASS_2_X_32 0x82BA +#define GL_IMAGE_CLASS_1_X_32 0x82BB +#define GL_IMAGE_CLASS_4_X_16 0x82BC +#define GL_IMAGE_CLASS_2_X_16 0x82BD +#define GL_IMAGE_CLASS_1_X_16 0x82BE +#define GL_IMAGE_CLASS_4_X_8 0x82BF +#define GL_IMAGE_CLASS_2_X_8 0x82C0 +#define GL_IMAGE_CLASS_1_X_8 0x82C1 +#define GL_IMAGE_CLASS_11_11_10 0x82C2 +#define GL_IMAGE_CLASS_10_10_10_2 0x82C3 +#define GL_VIEW_CLASS_128_BITS 0x82C4 +#define GL_VIEW_CLASS_96_BITS 0x82C5 +#define GL_VIEW_CLASS_64_BITS 0x82C6 +#define GL_VIEW_CLASS_48_BITS 0x82C7 +#define GL_VIEW_CLASS_32_BITS 0x82C8 +#define GL_VIEW_CLASS_24_BITS 0x82C9 +#define GL_VIEW_CLASS_16_BITS 0x82CA +#define GL_VIEW_CLASS_8_BITS 0x82CB +#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC +#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD +#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE +#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF +#define GL_VIEW_CLASS_RGTC1_RED 0x82D0 +#define GL_VIEW_CLASS_RGTC2_RG 0x82D1 +#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2 +#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3 +#endif + +#ifndef GL_ARB_invalidate_subdata +#endif + +#ifndef GL_ARB_multi_draw_indirect +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_UNIFORM 0x92E1 +#define GL_UNIFORM_BLOCK 0x92E2 +#define GL_PROGRAM_INPUT 0x92E3 +#define GL_PROGRAM_OUTPUT 0x92E4 +#define GL_BUFFER_VARIABLE 0x92E5 +#define GL_SHADER_STORAGE_BLOCK 0x92E6 +/* reuse GL_ATOMIC_COUNTER_BUFFER */ +#define GL_VERTEX_SUBROUTINE 0x92E8 +#define GL_TESS_CONTROL_SUBROUTINE 0x92E9 +#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA +#define GL_GEOMETRY_SUBROUTINE 0x92EB +#define GL_FRAGMENT_SUBROUTINE 0x92EC +#define GL_COMPUTE_SUBROUTINE 0x92ED +#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE +#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF +#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0 +#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1 +#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2 +#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3 +#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4 +#define GL_ACTIVE_RESOURCES 0x92F5 +#define GL_MAX_NAME_LENGTH 0x92F6 +#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7 +#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8 +#define GL_NAME_LENGTH 0x92F9 +#define GL_TYPE 0x92FA +#define GL_ARRAY_SIZE 0x92FB +#define GL_OFFSET 0x92FC +#define GL_BLOCK_INDEX 0x92FD +#define GL_ARRAY_STRIDE 0x92FE +#define GL_MATRIX_STRIDE 0x92FF +#define GL_IS_ROW_MAJOR 0x9300 +#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301 +#define GL_BUFFER_BINDING 0x9302 +#define GL_BUFFER_DATA_SIZE 0x9303 +#define GL_NUM_ACTIVE_VARIABLES 0x9304 +#define GL_ACTIVE_VARIABLES 0x9305 +#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306 +#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307 +#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308 +#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309 +#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A +#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B +#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C +#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D +#define GL_LOCATION 0x930E +#define GL_LOCATION_INDEX 0x930F +#define GL_IS_PER_PATCH 0x92E7 +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#endif + +#ifndef GL_ARB_shader_image_size +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_SHADER_STORAGE_BUFFER 0x90D2 +#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3 +#define GL_SHADER_STORAGE_BUFFER_START 0x90D4 +#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5 +#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6 +#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7 +#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8 +#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9 +#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA +#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB +#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC +#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD +#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE +#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF +#define GL_SHADER_STORAGE_BARRIER_BIT 0x2000 +#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS +/* reuse GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS */ +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_TEXTURE_BUFFER_OFFSET 0x919D +#define GL_TEXTURE_BUFFER_SIZE 0x919E +#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F +#endif + +#ifndef GL_ARB_texture_query_levels +#endif + +#ifndef GL_ARB_texture_storage_multisample +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for program/shader text and shader object handles */ +typedef char GLcharARB; +typedef unsigned int GLhandleARB; +#endif + +/* GL type for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#ifndef GL_ARB_sync +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_ARB_cl_event +/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ +struct _cl_context; +struct _cl_event; +#endif + +#ifndef GL_ARB_debug_output +typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_AMD_debug_output +typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_KHR_debug +typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_NV_vdpau_interop +typedef GLintptr GLvdpauSurfaceNV; +#endif + +#ifndef GL_VERSION_1_0 +#define GL_VERSION_1_0 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCullFace (GLenum mode); +GLAPI void APIENTRY glFrontFace (GLenum mode); +GLAPI void APIENTRY glHint (GLenum target, GLenum mode); +GLAPI void APIENTRY glLineWidth (GLfloat width); +GLAPI void APIENTRY glPointSize (GLfloat size); +GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); +GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glDrawBuffer (GLenum mode); +GLAPI void APIENTRY glClear (GLbitfield mask); +GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GLAPI void APIENTRY glClearStencil (GLint s); +GLAPI void APIENTRY glClearDepth (GLdouble depth); +GLAPI void APIENTRY glStencilMask (GLuint mask); +GLAPI void APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GLAPI void APIENTRY glDepthMask (GLboolean flag); +GLAPI void APIENTRY glDisable (GLenum cap); +GLAPI void APIENTRY glEnable (GLenum cap); +GLAPI void APIENTRY glFinish (void); +GLAPI void APIENTRY glFlush (void); +GLAPI void APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GLAPI void APIENTRY glLogicOp (GLenum opcode); +GLAPI void APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GLAPI void APIENTRY glDepthFunc (GLenum func); +GLAPI void APIENTRY glPixelStoref (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); +GLAPI void APIENTRY glReadBuffer (GLenum mode); +GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +GLAPI void APIENTRY glGetDoublev (GLenum pname, GLdouble *params); +GLAPI GLenum APIENTRY glGetError (void); +GLAPI void APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *params); +GLAPI const GLubyte * APIENTRY glGetString (GLenum name); +GLAPI void APIENTRY glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); +GLAPI void APIENTRY glDepthRange (GLdouble near, GLdouble far); +GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLFRONTFACEPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLHINTPROC) (GLenum target, GLenum mode); +typedef void (APIENTRYP PFNGLLINEWIDTHPROC) (GLfloat width); +typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size); +typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXIMAGE1DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLDRAWBUFFERPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s); +typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask); +typedef void (APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag); +typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLFINISHPROC) (void); +typedef void (APIENTRYP PFNGLFLUSHPROC) (void); +typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor); +typedef void (APIENTRYP PFNGLLOGICOPPROC) (GLenum opcode); +typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass); +typedef void (APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func); +typedef void (APIENTRYP PFNGLPIXELSTOREFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLREADBUFFERPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETBOOLEANVPROC) (GLenum pname, GLboolean *params); +typedef void (APIENTRYP PFNGLGETDOUBLEVPROC) (GLenum pname, GLdouble *params); +typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); +typedef void (APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); +typedef void (APIENTRYP PFNGLGETTEXIMAGEPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERFVPROC) (GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERIVPROC) (GLenum target, GLint level, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLDEPTHRANGEPROC) (GLdouble near, GLdouble far); +typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_1 +#define GL_VERSION_1_1 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glGetPointerv (GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GLAPI void APIENTRY glCopyTexImage1D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); +GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GLAPI GLboolean APIENTRY glIsTexture (GLuint texture); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLGETPOINTERVPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat units); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREPROC) (GLuint texture); +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GLAPI void APIENTRY glBlendEquation (GLenum mode); +GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum texture); +GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); +GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQuery (GLuint id); +GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQuery (GLenum target); +GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); +GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); +GLAPI void APIENTRY glCompileShader (GLuint shader); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum type); +GLAPI void APIENTRY glDeleteProgram (GLuint program); +GLAPI void APIENTRY glDeleteShader (GLuint shader); +GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); +GLAPI GLboolean APIENTRY glIsShader (GLuint shader); +GLAPI void APIENTRY glLinkProgram (GLuint program); +GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); +GLAPI void APIENTRY glUseProgram (GLuint program); +GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glValidateProgram (GLuint program); +GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +/* OpenGL 3.0 also reuses entry points from these extensions: */ +/* ARB_framebuffer_object */ +/* ARB_map_buffer_range */ +/* ARB_vertex_array_object */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); +GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); +GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); +GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* const *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +#endif + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +/* OpenGL 3.1 also reuses entry points from these extensions: */ +/* ARB_copy_buffer */ +/* ARB_uniform_buffer_object */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); +GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +#endif + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +/* OpenGL 3.2 also reuses entry points from these extensions: */ +/* ARB_draw_elements_base_vertex */ +/* ARB_provoking_vertex */ +/* ARB_sync */ +/* ARB_texture_multisample */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERSION_3_3 1 +/* OpenGL 3.3 also reuses entry points from these extensions: */ +/* ARB_blend_func_extended */ +/* ARB_sampler_objects */ +/* ARB_explicit_attrib_location, but it has none */ +/* ARB_occlusion_query2 (no entry points) */ +/* ARB_shader_bit_encoding (no entry points) */ +/* ARB_texture_rgb10_a2ui (no entry points) */ +/* ARB_texture_swizzle (no entry points) */ +/* ARB_timer_query */ +/* ARB_vertex_type_2_10_10_10_rev */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_VERSION_4_0 +#define GL_VERSION_4_0 1 +/* OpenGL 4.0 also reuses entry points from these extensions: */ +/* ARB_texture_query_lod (no entry points) */ +/* ARB_draw_indirect */ +/* ARB_gpu_shader5 (no entry points) */ +/* ARB_gpu_shader_fp64 */ +/* ARB_shader_subroutine */ +/* ARB_tessellation_shader */ +/* ARB_texture_buffer_object_rgb32 (no entry points) */ +/* ARB_texture_cube_map_array (no entry points) */ +/* ARB_texture_gather (no entry points) */ +/* ARB_transform_feedback2 */ +/* ARB_transform_feedback3 */ +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLfloat value); +GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value); +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_VERSION_4_1 +#define GL_VERSION_4_1 1 +/* OpenGL 4.1 reuses entry points from these extensions: */ +/* ARB_ES2_compatibility */ +/* ARB_get_program_binary */ +/* ARB_separate_shader_objects */ +/* ARB_shader_precision (no entry points) */ +/* ARB_vertex_attrib_64bit */ +/* ARB_viewport_array */ +#endif + +#ifndef GL_VERSION_4_2 +#define GL_VERSION_4_2 1 +/* OpenGL 4.2 reuses entry points from these extensions: */ +/* ARB_base_instance */ +/* ARB_shading_language_420pack (no entry points) */ +/* ARB_transform_feedback_instanced */ +/* ARB_compressed_texture_pixel_storage (no entry points) */ +/* ARB_conservative_depth (no entry points) */ +/* ARB_internalformat_query */ +/* ARB_map_buffer_alignment (no entry points) */ +/* ARB_shader_atomic_counters */ +/* ARB_shader_image_load_store */ +/* ARB_shading_language_packing (no entry points) */ +/* ARB_texture_storage */ +#endif + +#ifndef GL_VERSION_4_3 +#define GL_VERSION_4_3 1 +/* OpenGL 4.3 reuses entry points from these extensions: */ +/* ARB_arrays_of_arrays (no entry points, GLSL only) */ +/* ARB_fragment_layer_viewport (no entry points, GLSL only) */ +/* ARB_shader_image_size (no entry points, GLSL only) */ +/* ARB_ES3_compatibility (no entry points) */ +/* ARB_clear_buffer_object */ +/* ARB_compute_shader */ +/* ARB_copy_image */ +/* KHR_debug (includes ARB_debug_output commands promoted to KHR without suffixes) */ +/* ARB_explicit_uniform_location (no entry points) */ +/* ARB_framebuffer_no_attachments */ +/* ARB_internalformat_query2 */ +/* ARB_invalidate_subdata */ +/* ARB_multi_draw_indirect */ +/* ARB_program_interface_query */ +/* ARB_robust_buffer_access_behavior (no entry points) */ +/* ARB_shader_storage_buffer_object */ +/* ARB_stencil_texturing (no entry points) */ +/* ARB_texture_buffer_range */ +/* ARB_texture_query_levels (no entry points) */ +/* ARB_texture_storage_multisample */ +/* ARB_texture_view */ +/* ARB_vertex_attrib_binding */ +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmap (GLenum target); +GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindVertexArray (GLuint array); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* const *uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instancecount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint *basevertex); +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glProvokingVertex (GLenum mode); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); +#endif + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value); +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#endif + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#endif + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_ARB_shading_language_include 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_ARB_texture_compression_bptc 1 +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_ARB_blend_func_extended 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); +#endif + +#ifndef GL_ARB_explicit_attrib_location +#define GL_ARB_explicit_attrib_location 1 +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ARB_occlusion_query2 1 +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_ARB_sampler_objects 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); +GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); +GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); +GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); +GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); +typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); +typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); +typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_bit_encoding +#define GL_ARB_shader_bit_encoding 1 +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_ARB_texture_rgb10_a2ui 1 +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_ARB_texture_swizzle 1 +#endif + +#ifndef GL_ARB_timer_query +#define GL_ARB_timer_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); +GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +#define GL_ARB_vertex_type_2_10_10_10_rev 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_ARB_draw_indirect 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); +GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_ARB_gpu_shader5 1 +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_ARB_gpu_shader_fp64 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); +GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ARB_shader_subroutine 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); +GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); +GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); +typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_ARB_tessellation_shader 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); +GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +#define GL_ARB_texture_buffer_object_rgb32 1 +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_ARB_transform_feedback2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedback (void); +GLAPI void APIENTRY glResumeTransformFeedback (void); +GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_ARB_transform_feedback3 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); +GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); +GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); +GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); +typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_ARB_ES2_compatibility 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glReleaseShaderCompiler (void); +GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f); +GLAPI void APIENTRY glClearDepthf (GLfloat d); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); +typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f); +typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d); +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_ARB_get_program_binary 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_ARB_separate_shader_objects 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); +GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* const *strings); +GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); +GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); +GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); +GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* const *strings); +typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); +typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +#define GL_ARB_vertex_attrib_64bit 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); +#endif + +#ifndef GL_ARB_viewport_array +#define GL_ARB_viewport_array 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); +GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); +GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f); +GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f); +typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); +#endif + +#ifndef GL_ARB_cl_event +#define GL_ARB_cl_event 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif + +#ifndef GL_ARB_debug_output +#define GL_ARB_debug_output 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif + +#ifndef GL_ARB_robustness +#define GL_ARB_robustness 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); +GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); +GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); +GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); +GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); +GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); +typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); +typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); +typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_stencil_export +#define GL_ARB_shader_stencil_export 1 +#endif + +#ifndef GL_ARB_base_instance +#define GL_ARB_base_instance 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); +#endif + +#ifndef GL_ARB_shading_language_420pack +#define GL_ARB_shading_language_420pack 1 +#endif + +#ifndef GL_ARB_transform_feedback_instanced +#define GL_ARB_transform_feedback_instanced 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount); +GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); +#endif + +#ifndef GL_ARB_compressed_texture_pixel_storage +#define GL_ARB_compressed_texture_pixel_storage 1 +#endif + +#ifndef GL_ARB_conservative_depth +#define GL_ARB_conservative_depth 1 +#endif + +#ifndef GL_ARB_internalformat_query +#define GL_ARB_internalformat_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params); +#endif + +#ifndef GL_ARB_map_buffer_alignment +#define GL_ARB_map_buffer_alignment 1 +#endif + +#ifndef GL_ARB_shader_atomic_counters +#define GL_ARB_shader_atomic_counters 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_shader_image_load_store +#define GL_ARB_shader_image_load_store 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); +typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); +#endif + +#ifndef GL_ARB_shading_language_packing +#define GL_ARB_shading_language_packing 1 +#endif + +#ifndef GL_ARB_texture_storage +#define GL_ARB_texture_storage 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GL_KHR_texture_compression_astc_ldr +#define GL_KHR_texture_compression_astc_ldr 1 +#endif + +#ifndef GL_KHR_debug +#define GL_KHR_debug 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message); +GLAPI void APIENTRY glPopDebugGroup (void); +GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); +GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); +typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); +typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label); +typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); +typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); +#endif + +#ifndef GL_ARB_arrays_of_arrays +#define GL_ARB_arrays_of_arrays 1 +#endif + +#ifndef GL_ARB_clear_buffer_object +#define GL_ARB_clear_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); +typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, GLsizeiptr offset, GLsizeiptr size, const void *data); +#endif + +#ifndef GL_ARB_compute_shader +#define GL_ARB_compute_shader 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); +typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); +#endif + +#ifndef GL_ARB_copy_image +#define GL_ARB_copy_image 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +#endif + +#ifndef GL_ARB_texture_view +#define GL_ARB_texture_view 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); +#endif + +#ifndef GL_ARB_vertex_attrib_binding +#define GL_ARB_vertex_attrib_binding 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor); +GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor); +typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor); +#endif + +#ifndef GL_ARB_robustness_isolation +#define GL_ARB_robustness_isolation 1 +#endif + +#ifndef GL_ARB_ES3_compatibility +#define GL_ARB_ES3_compatibility 1 +#endif + +#ifndef GL_ARB_explicit_uniform_location +#define GL_ARB_explicit_uniform_location 1 +#endif + +#ifndef GL_ARB_fragment_layer_viewport +#define GL_ARB_fragment_layer_viewport 1 +#endif + +#ifndef GL_ARB_framebuffer_no_attachments +#define GL_ARB_framebuffer_no_attachments 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param); +GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_internalformat_query2 +#define GL_ARB_internalformat_query2 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params); +#endif + +#ifndef GL_ARB_invalidate_subdata +#define GL_ARB_invalidate_subdata 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level); +GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer); +GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments); +GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth); +typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_ARB_multi_draw_indirect +#define GL_ARB_multi_draw_indirect 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +#endif + +#ifndef GL_ARB_program_interface_query +#define GL_ARB_program_interface_query 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name); +GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params); +typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name); +#endif + +#ifndef GL_ARB_robust_buffer_access_behavior +#define GL_ARB_robust_buffer_access_behavior 1 +#endif + +#ifndef GL_ARB_shader_image_size +#define GL_ARB_shader_image_size 1 +#endif + +#ifndef GL_ARB_shader_storage_buffer_object +#define GL_ARB_shader_storage_buffer_object 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding); +#endif + +#ifndef GL_ARB_stencil_texturing +#define GL_ARB_stencil_texturing 1 +#endif + +#ifndef GL_ARB_texture_buffer_range +#define GL_ARB_texture_buffer_range 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_texture_query_levels +#define GL_ARB_texture_query_levels 1 +#endif + +#ifndef GL_ARB_texture_storage_multisample +#define GL_ARB_texture_storage_multisample 1 +#ifdef GLCOREARB_PROTOTYPES +GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif /* GLCOREARB_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/GLES3/CMakeLists.txt b/external/GLES3/CMakeLists.txt new file mode 100644 index 000000000..420ee834b --- /dev/null +++ b/external/GLES3/CMakeLists.txt @@ -0,0 +1 @@ +install(FILES gl3.h gl3platform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GLES3) diff --git a/external/GLES3/gl3.h b/external/GLES3/gl3.h new file mode 100644 index 000000000..738232eaa --- /dev/null +++ b/external/GLES3/gl3.h @@ -0,0 +1,1063 @@ +#ifndef __gl3_h_ +#define __gl3_h_ + +/* + * gl3.h last updated on $Date: 2012-07-23 03:53:52 -0700 (Mon, 23 Jul 2012) $ + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/*------------------------------------------------------------------------- + * Data type definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES 2.0 */ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +/* OpenGL ES 3.0 */ + +typedef unsigned short GLhalf; +typedef khronos_int64_t GLint64; +typedef khronos_uint64_t GLuint64; +typedef struct __GLsync *GLsync; + +/*------------------------------------------------------------------------- + * Token definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES core versions */ +#define GL_ES_VERSION_3_0 1 +#define GL_ES_VERSION_2_0 1 + +/* OpenGL ES 2.0 */ + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* BlendEquationSeparate */ +#define GL_FUNC_ADD 0x8006 +#define GL_BLEND_EQUATION 0x8009 +#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ +#define GL_BLEND_EQUATION_ALPHA 0x883D + +/* BlendSubtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* Separate Blend Functions */ +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_BLEND 0x0BE2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_LINE_WIDTH 0x0B21 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VIEWPORT 0x0BA2 +#define GL_SCISSOR_BOX 0x0C10 +/* GL_SCISSOR_TEST */ +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +/* GL_POLYGON_OFFSET_FILL */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* PixelFormat */ +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* Shaders */ +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D + +/* StencilFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +#define GL_INVERT 0x150A +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ +#define GL_TEXTURE 0x1702 + +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MIRRORED_REPEAT 0x8370 + +/* Uniform Types */ +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +/* Vertex Arrays */ +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +/* Read Format */ +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B + +/* Shader Source */ +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Framebuffer Object. */ +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 + +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGB565 0x8D62 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_STENCIL_INDEX8 0x8D48 + +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 + +#define GL_NONE 0 + +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + +/* OpenGL ES 3.0 */ + +#define GL_READ_BUFFER 0x0C02 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +#define GL_RED 0x1903 +#define GL_RGB8 0x8051 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#define GL_HALF_FLOAT 0x140B +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_RG8 0x822B +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#define GL_COPY_READ_BUFFER_BINDING GL_COPY_READ_BUFFER +#define GL_COPY_WRITE_BUFFER_BINDING GL_COPY_WRITE_BUFFER +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A +#define GL_SAMPLER_BINDING 0x8919 +#define GL_RGB10_A2UI 0x906F +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_INT_2_10_10_10_REV 0x8D9F +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#define GL_COMPRESSED_R11_EAC 0x9270 +#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 +#define GL_COMPRESSED_RG11_EAC 0x9272 +#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 +#define GL_COMPRESSED_RGB8_ETC2 0x9274 +#define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 +#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 +#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 +#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F +#define GL_MAX_ELEMENT_INDEX 0x8D6B +#define GL_NUM_SAMPLE_COUNTS 0x9380 +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x8D63 + +/*------------------------------------------------------------------------- + * Entrypoint definitions + *-----------------------------------------------------------------------*/ + +/* OpenGL ES 2.0 */ + +GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); +GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); +GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_APICALL void GL_APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_APICALL void GL_APIENTRY glBlendEquation (GLenum mode); +GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); +GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target); +GL_APICALL void GL_APIENTRY glClear (GLbitfield mask); +GL_APICALL void GL_APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_APICALL void GL_APIENTRY glClearDepthf (GLfloat depth); +GL_APICALL void GL_APIENTRY glClearStencil (GLint s); +GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader); +GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL GLuint GL_APIENTRY glCreateProgram (void); +GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type); +GL_APICALL void GL_APIENTRY glCullFace (GLenum mode); +GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers); +GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program); +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader); +GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures); +GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func); +GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag); +GL_APICALL void GL_APIENTRY glDepthRangef (GLfloat n, GLfloat f); +GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glDisable (GLenum cap); +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glEnable (GLenum cap); +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glFinish (void); +GL_APICALL void GL_APIENTRY glFlush (void); +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode); +GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers); +GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target); +GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); +GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); +GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); +GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL GLenum GL_APIENTRY glGetError (void); +GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); +GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name); +GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); +GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); +GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); +GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program); +GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); +GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glSampleCoverage (GLfloat value, GLboolean invert); +GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length); +GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params); +GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params); +GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x); +GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUseProgram (GLuint program); +GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program); +GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); +GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); +GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +/* OpenGL ES 3.0 */ + +GL_APICALL void GL_APIENTRY glReadBuffer (GLenum mode); +GL_APICALL void GL_APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glGenQueries (GLsizei n, GLuint* ids); +GL_APICALL void GL_APIENTRY glDeleteQueries (GLsizei n, const GLuint* ids); +GL_APICALL GLboolean GL_APIENTRY glIsQuery (GLuint id); +GL_APICALL void GL_APIENTRY glBeginQuery (GLenum target, GLuint id); +GL_APICALL void GL_APIENTRY glEndQuery (GLenum target); +GL_APICALL void GL_APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint* params); +GL_APICALL GLboolean GL_APIENTRY glUnmapBuffer (GLenum target); +GL_APICALL void GL_APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid** params); +GL_APICALL void GL_APIENTRY glDrawBuffers (GLsizei n, const GLenum* bufs); +GL_APICALL void GL_APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GL_APICALL GLvoid* GL_APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GL_APICALL void GL_APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +GL_APICALL void GL_APIENTRY glBindVertexArray (GLuint array); +GL_APICALL void GL_APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint* arrays); +GL_APICALL void GL_APIENTRY glGenVertexArrays (GLsizei n, GLuint* arrays); +GL_APICALL GLboolean GL_APIENTRY glIsVertexArray (GLuint array); +GL_APICALL void GL_APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint* data); +GL_APICALL void GL_APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GL_APICALL void GL_APIENTRY glEndTransformFeedback (void); +GL_APICALL void GL_APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GL_APICALL void GL_APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GL_APICALL void GL_APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode); +GL_APICALL void GL_APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); +GL_APICALL void GL_APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint* params); +GL_APICALL void GL_APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GL_APICALL void GL_APIENTRY glVertexAttribI4iv (GLuint index, const GLint* v); +GL_APICALL void GL_APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint* v); +GL_APICALL void GL_APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint* params); +GL_APICALL GLint GL_APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GL_APICALL void GL_APIENTRY glUniform1ui (GLint location, GLuint v0); +GL_APICALL void GL_APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GL_APICALL void GL_APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GL_APICALL void GL_APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GL_APICALL void GL_APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint* value); +GL_APICALL void GL_APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint* value); +GL_APICALL void GL_APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint* value); +GL_APICALL void GL_APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat* value); +GL_APICALL void GL_APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GL_APICALL const GLubyte* GL_APIENTRY glGetStringi (GLenum name, GLuint index); +GL_APICALL void GL_APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GL_APICALL void GL_APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices); +GL_APICALL void GL_APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params); +GL_APICALL GLuint GL_APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar* uniformBlockName); +GL_APICALL void GL_APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName); +GL_APICALL void GL_APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +GL_APICALL void GL_APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instanceCount); +GL_APICALL void GL_APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount); +GL_APICALL GLsync GL_APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GL_APICALL GLboolean GL_APIENTRY glIsSync (GLsync sync); +GL_APICALL void GL_APIENTRY glDeleteSync (GLsync sync); +GL_APICALL GLenum GL_APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GL_APICALL void GL_APIENTRY glGetInteger64v (GLenum pname, GLint64* params); +GL_APICALL void GL_APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values); +GL_APICALL void GL_APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64* data); +GL_APICALL void GL_APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64* params); +GL_APICALL void GL_APIENTRY glGenSamplers (GLsizei count, GLuint* samplers); +GL_APICALL void GL_APIENTRY glDeleteSamplers (GLsizei count, const GLuint* samplers); +GL_APICALL GLboolean GL_APIENTRY glIsSampler (GLuint sampler); +GL_APICALL void GL_APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GL_APICALL void GL_APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint* param); +GL_APICALL void GL_APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat* param); +GL_APICALL void GL_APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +GL_APICALL void GL_APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GL_APICALL void GL_APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); +GL_APICALL void GL_APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint* ids); +GL_APICALL GLboolean GL_APIENTRY glIsTransformFeedback (GLuint id); +GL_APICALL void GL_APIENTRY glPauseTransformFeedback (void); +GL_APICALL void GL_APIENTRY glResumeTransformFeedback (void); +GL_APICALL void GL_APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary); +GL_APICALL void GL_APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +GL_APICALL void GL_APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* attachments); +GL_APICALL void GL_APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); +GL_APICALL void GL_APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/external/GLES3/gl3platform.h b/external/GLES3/gl3platform.h new file mode 100644 index 000000000..1bd1a850f --- /dev/null +++ b/external/GLES3/gl3platform.h @@ -0,0 +1,30 @@ +#ifndef __gl3platform_h_ +#define __gl3platform_h_ + +/* $Revision: 18437 $ on $Date:: 2012-07-08 23:31:39 -0700 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 3.X gl3.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_APICALL +#define GL_APICALL KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __gl3platform_h_ */ diff --git a/external/KHR/CMakeLists.txt b/external/KHR/CMakeLists.txt new file mode 100644 index 000000000..19c9ed8d8 --- /dev/null +++ b/external/KHR/CMakeLists.txt @@ -0,0 +1 @@ +install(FILES khrplatform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/KHR) diff --git a/external/KHR/khrplatform.h b/external/KHR/khrplatform.h new file mode 100644 index 000000000..8ec0d199f --- /dev/null +++ b/external/KHR/khrplatform.h @@ -0,0 +1,269 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by sending them to the public Khronos Bugzilla + * (http://khronos.org/bugzilla) by filing a bug against product + * "Khronos (general)" component "Registry". + * + * A predefined template which fills in some of the bug fields can be + * reached using http://tinyurl.com/khrplatform-h-bugreport, but you + * must create a Bugzilla login first. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(_WIN32) && !defined(__SCITECH_SNAP__) +# define KHRONOS_APICALL __declspec(dllimport) +#elif defined (__SYMBIAN32__) +# define KHRONOS_APICALL IMPORT_C +#else +# define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define KHRONOS_APIENTRY __stdcall +#else +# define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined (__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__VMS ) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum { + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index fada6ad10..5568c5999 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -186,6 +186,7 @@ find_package_handle_standard_args(Magnum # Dependent libraries and includes set(MAGNUM_INCLUDE_DIRS ${MAGNUM_INCLUDE_DIR} + ${MAGNUM_INCLUDE_DIR}/external ${CORRADE_INCLUDE_DIR}) set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} diff --git a/src/Magnum.h b/src/Magnum.h index 03f25bcf5..49fe94f59 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -23,8 +23,9 @@ #ifndef MAGNUM_TARGET_GLES #include +#include #else -#include +#include #endif namespace Corrade { From 5310326e699c663f5b07d6cbbd47d330582b117a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 03:09:19 +0200 Subject: [PATCH 030/256] Enabled RGB565 and BPTC textures, as they are now in headers. --- src/AbstractTexture.h | 12 ++---------- src/Renderbuffer.h | 2 -- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 3549b2343..2e9899d5d 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -319,29 +319,23 @@ class MAGNUM_EXPORT AbstractTexture { * Four-component RGBA, unsigned normalized, each component 4bit, * 16bit total. */ - RGBA4 = GL_RGBA4 + RGBA4 = GL_RGBA4, #ifndef MAGNUM_TARGET_GLES - , - /** * Three-component RGB, float, red and green 11bit, blue 10bit, * 32bit total. * @requires_gl * @requires_gl30 Extension @extension{EXT,packed_float} */ - RG11B10Float = GL_R11F_G11F_B10F + RG11B10Float = GL_R11F_G11F_B10F, #endif - #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) - , - /** * Three-component RGB, unsigned normalized, red and blue 5bit, * green 6bit, 16bit total. */ RGB565 = GL_RGB565 - #endif #ifndef MAGNUM_TARGET_GLES , @@ -408,7 +402,6 @@ class MAGNUM_EXPORT AbstractTexture { */ CompressedRtgcSignedRedGreen = GL_COMPRESSED_SIGNED_RG_RGTC2, - #if defined(GL_COMPRESSED_RGBA_BPTC_UNORM) || defined(DOXYGEN_GENERATING_OUTPUT) /** * BPTC compressed RGBA, unsigned normalized. * @requires_gl @@ -436,7 +429,6 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} */ CompressedBptcRGBUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, - #endif /** * Depth component, at least 16bit. diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 9ff67f01d..59e3565ab 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -91,9 +91,7 @@ class Renderbuffer { RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F, #endif - #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) RGB565 = GL_RGB565, - #endif #ifndef MAGNUM_TARGET_GLES /** From 3271896b157acbb276fd6f1bff3cbbc4cdf2b818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 15:36:27 +0200 Subject: [PATCH 031/256] Deprecated uniformLocation() in favor of GL 4.3 explicit uniform location. --- src/AbstractShaderProgram.h | 45 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 33be5bb23..1422088c5 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -52,6 +52,14 @@ typedef Attribute<2, Vector2> TextureCoords; @code static const GLint DiffuseTextureLayer = 0; static const GLint SpecularTextureLayer = 1; +@endcode + - **Uniform locations** for setting uniform data (see below) (private + constants), for example: +@code +static const GLint TransformationMatrixUniform = 0; +static const GLint ProjectionMatrixUniform = 1; +static const GLint DiffuseTextureUniform = 2; +static const GLint SpecularTextureUniform = 3; @endcode - **Constructor**, which attaches particular shaders, links the program and gets uniform locations, for example: @@ -63,21 +71,16 @@ MyShader() { // Link link(); - - // Get locations of uniforms - transformationMatrixUniform = uniformLocation("transformationMatrix"); - projectionMatrixUniform = uniformLocation("projectionMatrix"); - // more uniforms like light location, colors etc. } @endcode - **Uniform setting functions**, which will provide public interface for protected setUniform() functions. Example: @code void setTransformationMatrixUniform(const Matrix4& matrix) { - setUniform(transformationMatrixUniform, matrix); + setUniform(TransformationMatrixUniform, matrix); } void setProjectionMatrixUniform(const Matrix4& matrix) { - setUniform(projectionMatrixUniform, matrix); + setUniform(ProjectionMatrixUniform, matrix); } @endcode @@ -126,6 +129,26 @@ bindFragmentDataLocationIndexed(1, 1, "ambient"); // Link... @endcode +@subsection AbstractShaderProgram-uniform-location Uniform locations +The preferred workflow is to specify uniform locations directly in the shader +code, e.g.: +@code +#version 430 +// or #extension GL_ARB_explicit_uniform_location: enable +layout(location = 0) uniform mat4 transformationMatrix; +layout(location = 1) uniform mat4 projectionMatrix; +@endcode +@requires_gl (for explicit uniform location instead of using uniformLocation()) +@requires_gl43 Extension @extension{ARB,explicit_uniform_location} (for + explicit uniform location instead of using uniformLocation()) + +If you don't have the required extension, you can get uniform location using +uniformLocation() after linking stage: +@code +GLint transformationMatrixUniform = uniformLocation("transformationMatrix"); +GLint projectionMatrixUniform = uniformLocation("projectionMatrix"); +@endcode + @subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms The preferred workflow is to specify texture layers directly in the shader code, e.g.: @@ -144,8 +167,8 @@ If you don't have the required extension (or if you want to change the layer later), you can set the texture layer uniform using setUniform(GLint, GLint): @code use(); -setUniform(uniformLocation("diffuseTexture"), DiffuseTextureLayer); -setUniform(uniformLocation("specularTexture"), SpecularTextureLayer); +setUniform(DiffuseTextureUniform, DiffuseTextureLayer); +setUniform(SpecularTextureUniform, SpecularTextureLayer); @endcode @section AbstractShaderProgram-rendering-workflow Rendering workflow @@ -330,6 +353,10 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @param name Uniform name * * @note This function should be called after link(). + * @deprecated Preferred usage is to specify uniform location + * explicitly in the shader instead of using this function. See + * @ref AbstractShaderProgram-uniform-location "class documentation" + * for more information. * @see @fn_gl{GetUniformLocation} */ GLint uniformLocation(const std::string& name); From b067a6d1dc5afd5398ddaff213fbc3661871b3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 15:57:08 +0200 Subject: [PATCH 032/256] Several new buffer targets and usages are available on OpenGL ES 3.0. In turn also BufferedImage is now available on OpenGL ES 3.0. --- src/Buffer.h | 48 +++++++++++++++++++-------------------------- src/BufferedImage.h | 4 +--- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 28612617e..5a35d152b 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -44,40 +44,36 @@ class Buffer { /** Used for storing vertex attributes. */ Array = GL_ARRAY_BUFFER, - #ifndef MAGNUM_TARGET_GLES /** * Source for copies. - * @requires_gl * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gles30 (no extension providing this functionality) */ CopyRead = GL_COPY_READ_BUFFER, /** * Target for copies. - * @requires_gl * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gles30 (no extension providing this functionality) */ CopyWrite = GL_COPY_WRITE_BUFFER, - #endif /** Used for storing vertex indices. */ - ElementArray = GL_ELEMENT_ARRAY_BUFFER - - #ifndef MAGNUM_TARGET_GLES - , + ElementArray = GL_ELEMENT_ARRAY_BUFFER, /** * Source for texture update operations. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ PixelUnpack = GL_PIXEL_UNPACK_BUFFER, /** * Target for pixel pack operations. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ PixelPack = GL_PIXEL_PACK_BUFFER, + #ifndef MAGNUM_TARGET_GLES /** * Source for texel fetches. * @@ -86,20 +82,24 @@ class Buffer { * @requires_gl31 Extension @extension{ARB,texture_buffer_object} */ Texture = GL_TEXTURE_BUFFER, + #endif /** * Target for transform feedback. - * @requires_gl * @requires_gl30 Extension @extension{EXT,transform_feedback} + * @requires_gles30 (no extension providing this functionality) */ TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, /** * Used for storing uniforms. - * @requires_gl * @requires_gl31 Extension @extension{ARB,uniform_buffer_object} + * @requires_gles30 (no extension providing this functionality) */ - Uniform = GL_UNIFORM_BUFFER, + Uniform = GL_UNIFORM_BUFFER + + #ifndef MAGNUM_TARGET_GLES + , /** * Used for supplying arguments for instanced drawing. @@ -117,66 +117,58 @@ class Buffer { */ StreamDraw = GL_STREAM_DRAW, - #ifndef MAGNUM_TARGET_GLES /** * Set once as output from an OpenGL command and used infequently * for drawing. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ StreamRead = GL_STREAM_READ, /** * Set once as output from an OpenGL command and used infrequently * for drawing or copying to other buffers. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ StreamCopy = GL_STREAM_COPY, - #endif /** * Set once by the application and used frequently for drawing. */ StaticDraw = GL_STATIC_DRAW, - #ifndef MAGNUM_TARGET_GLES /** * Set once as output from an OpenGL command and queried many * times by the application. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ StaticRead = GL_STATIC_READ, /** * Set once as output from an OpenGL command and used frequently * for drawing or copying to other buffers. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ StaticCopy = GL_STATIC_COPY, - #endif /** * Updated frequently by the application and used frequently * for drawing or copying to other images. */ - DynamicDraw = GL_DYNAMIC_DRAW - - #ifndef MAGNUM_TARGET_GLES - , + DynamicDraw = GL_DYNAMIC_DRAW, /** * Updated frequently as output from OpenGL command and queried * many times from the application. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ DynamicRead = GL_DYNAMIC_READ, /** * Updated frequently as output from OpenGL command and used * frequently for drawing or copying to other images. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ DynamicCopy = GL_DYNAMIC_COPY - #endif }; /** diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 0ee2ce696..34a767abb 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -25,7 +25,6 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES /** @brief %Buffered image @@ -33,7 +32,7 @@ Class for storing image data in GPU memory. Can be replaced with Image, which stores image data in client memory, ImageWrapper, or for example with Trade::ImageData. @see Buffer -@requires_gl +@requires_gles30 (no extension providing this functionality) */ template class BufferedImage: public AbstractImage { public: @@ -119,7 +118,6 @@ typedef BufferedImage<2> BufferedImage2D; /** @brief Three-dimensional buffered image */ typedef BufferedImage<3> BufferedImage3D; -#endif } From 6c244eb70374fbd2d6b45ba40a8bee072ed4b5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 16:01:54 +0200 Subject: [PATCH 033/256] CubeMapTexture is always seamless on OpenGL ES 3.0. --- src/CubeMapTexture.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 9ff62d0cf..edf64830a 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -63,8 +63,10 @@ class CubeMapTexture: public AbstractTexture { /** * @brief Enable/disable seamless cube map textures * + * Initially disabled on desktop OpenGL. * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} - * @requires_gl + * @requires_gl Not available in OpenGL ES 2.0, always enabled in + * OpenGL ES 3.0. * @requires_gl32 Extension @extension{ARB,seamless_cube_map} */ inline static void setSeamless(bool enabled) { From 1c8bda59b28ca44eeba2de4f62c9145831fba801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 16:11:23 +0200 Subject: [PATCH 034/256] Unsigned uniforms and retrievable hint supported in OpenGL ES 3.0. --- src/AbstractShaderProgram.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 1422088c5..831f6593b 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -104,14 +104,16 @@ layout(location = 1, index = 1) out vec4 ambient; @endcode @requires_gl (for explicit input attribute location instead of using bindAttributeLocation()) -@requires_gl (for explicit output attribute location or using - bindFragmentDataLocation() / bindFragmentDataLocationIndexed()) +@requires_gl (for using bindFragmentDataLocation() / + bindFragmentDataLocationIndexed()) @requires_gl30 Extension @extension{EXT,gpu_shader4} (for using bindFragmentDataLocation()) @requires_gl33 Extension @extension{ARB,blend_func_extended} (for using bindFragmentDataLocationIndexed()) @requires_gl33 Extension @extension{ARB,explicit_attrib_location} (for explicit attribute location instead of using bindAttributeLocation()) +@requires_gles30 (no extension providing this functionality) (for explicit + input and output attribute location) If you don't have the required extension, you can use functions bindAttributeLocation() and bindFragmentDataLocation() / bindFragmentDataLocationIndexed() between @@ -239,7 +241,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { bool use(); protected: - #ifndef MAGNUM_TARGET_GLES /** * @brief Allow retrieving program binary * @@ -249,11 +250,13 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_BINARY_RETRIEVABLE_HINT} * @requires_gl * @requires_gl41 Extension @extension{ARB,get_program_binary} + * @requires_gles30 (no extension providing this functionality) */ inline void setRetrievableBinary(bool enabled) { glProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, enabled ? GL_TRUE : GL_FALSE); } + #ifndef MAGNUM_TARGET_GLES /** * @brief Allow the program to be bound to individual pipeline stages * @@ -408,11 +411,10 @@ class MAGNUM_EXPORT AbstractShaderProgram { glUniform4iv(location, 1, value.data()); } - #ifndef MAGNUM_TARGET_GLES /** * @copydoc setUniform(GLint, GLint) - * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, GLuint value) { glUniform1ui(location, value); @@ -420,8 +422,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLint) - * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::Vector2& value) { glUniform2uiv(location, 1, value.data()); @@ -429,8 +431,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLint) - * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::Vector3& value) { glUniform3uiv(location, 1, value.data()); @@ -438,13 +440,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLuint) - * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::Vector4& value) { glUniform4uiv(location, 1, value.data()); } - #endif /** @copydoc setUniform(GLint, GLint) */ inline void setUniform(GLint location, const Matrix3& value) { From ac3a8b55d6fd4432ec61819b2c4653fbafe105e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Aug 2012 16:12:06 +0200 Subject: [PATCH 035/256] New Compute shader stage in OpenGL 4.3. --- src/Shader.cpp | 5 ++--- src/Shader.h | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Shader.cpp b/src/Shader.cpp index 2bf2bf948..2a6fe17f5 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -106,12 +106,11 @@ GLuint Shader::compile() { case Type::Vertex: err << "vertex"; break; #ifndef MAGNUM_TARGET_GLES case Type::Geometry: err << "geometry"; break; - #endif - case Type::Fragment: err << "fragment"; break; - #ifndef MAGNUM_TARGET_GLES case Type::TessellationControl: err << "tessellation control"; break; case Type::TessellationEvaluation: err << "tessellation evaluation"; break; + case Type::Compute: err << "compute"; break; #endif + case Type::Fragment: err << "fragment"; break; } /* Show error log and delete shader */ diff --git a/src/Shader.h b/src/Shader.h index 4cd0cada9..f25a50e19 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -65,6 +65,13 @@ class MAGNUM_EXPORT Shader { * @requires_gl32 Extension @extension{ARB,geometry_shader4} */ Geometry = GL_GEOMETRY_SHADER, + + /** + * Compute shader + * @requires_gl + * @requires_gl43 Extension @extension{ARB,compute_shader} + */ + Compute = GL_COMPUTE_SHADER, #endif Fragment = GL_FRAGMENT_SHADER /**< Fragment shader */ From 7a066672cd19f29df39dfa39445bd601650ca930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Aug 2012 23:07:38 +0200 Subject: [PATCH 036/256] Queries (except for timing ones) are available in OpenGL ES 3.0. --- src/Query.cpp | 4 ++-- src/Query.h | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Query.cpp b/src/Query.cpp index e0889ac68..9f23448b5 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -17,7 +17,6 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES bool AbstractQuery::resultAvailable() { GLuint result; glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result); @@ -36,6 +35,7 @@ template<> GLuint AbstractQuery::result() { return result; } +#ifndef MAGNUM_TARGET_GLES template<> GLint AbstractQuery::result() { GLint result; glGetQueryObjectiv(query, GL_QUERY_RESULT, &result); @@ -53,6 +53,7 @@ template<> GLint64 AbstractQuery::result() { glGetQueryObjecti64v(query, GL_QUERY_RESULT, &result); return result; } +#endif void Query::begin(Query::Target target) { glBeginQuery(static_cast(target), query); @@ -79,6 +80,5 @@ void SampleQuery::end() { delete target; target = nullptr; } -#endif } diff --git a/src/Query.h b/src/Query.h index bfa5c94fb..d7ea2fab9 100644 --- a/src/Query.h +++ b/src/Query.h @@ -25,13 +25,12 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES /** @brief Base class for queries See Query, SampleQuery, TimeQuery documentation for more information. @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) -@requires_gl +@requires_gles30 (no extension providing this functionality) */ class MAGNUM_EXPORT AbstractQuery { public: @@ -66,6 +65,7 @@ class MAGNUM_EXPORT AbstractQuery { * Note that this function is blocking until the result is available. * See resultAvailable(). * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} + * @requires_gl Result type `GLint`, `GLuint64`, `GLint64` * @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`) */ template T result(); @@ -78,10 +78,12 @@ class MAGNUM_EXPORT AbstractQuery { #ifndef DOXYGEN_GENERATING_OUTPUT template<> bool MAGNUM_EXPORT AbstractQuery::result(); template<> GLuint MAGNUM_EXPORT AbstractQuery::result(); +#ifndef MAGNUM_TARGET_GLES template<> GLint MAGNUM_EXPORT AbstractQuery::result(); template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result(); template<> GLint64 MAGNUM_EXPORT AbstractQuery::result(); #endif +#endif /** @brief %Query for primitives and elapsed time @@ -102,28 +104,35 @@ if(!q.resultAvailable()) { // ...or block until the result is available GLuint primitiveCount = q.result(); @endcode -@requires_gl @requires_gl30 Extension @extension{EXT,transform_feedback} +@requires_gles30 (no extension providing this functionality) */ class MAGNUM_EXPORT Query: public AbstractQuery { public: /** @brief %Query target */ enum Target: GLenum { + #ifndef MAGNUM_TARGET_GLES /** * Count of primitives generated from vertex shader or geometry * shader. + * @requires_gl */ PrimitivesGenerated = GL_PRIMITIVES_GENERATED, + #endif /** Count of primitives written to transform feedback buffer. */ - TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, + TransformFeedbackPrimitivesWritten = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN + + #ifndef MAGNUM_TARGET_GLES + , /** * Elapsed time - * + * @requires_gl * @requires_gl33 Extension @extension{ARB,timer_query} */ TimeElapsed = GL_TIME_ELAPSED + #endif }; inline Query(): target(nullptr) {} @@ -184,26 +193,41 @@ q.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait); // render full version of the object only if the query returns nonzero result q.endConditionalRender(); @endcode -@requires_gl +@requires_gles30 (no extension providing this functionality) */ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { public: /** @brief %Query target */ enum Target: GLenum { - /** Count of samples passed from fragment shader */ + #ifndef MAGNUM_TARGET_GLES + /** + * Count of samples passed from fragment shader + * @requires_gl + */ SamplesPassed = GL_SAMPLES_PASSED, + #endif /** * Whether any samples passed from fragment shader - * * @requires_gl33 Extension @extension{ARB,occlusion_query2} */ - AnySamplesPassed = GL_ANY_SAMPLES_PASSED + AnySamplesPassed = GL_ANY_SAMPLES_PASSED, + + /** + * Whether any samples passed from fragment shader (conservative) + * + * An implementation may choose a less precise version of the + * test at the expense of some false positives. + * @requires_gl43 Extension @extension{ARB,ES3_compatibility} + */ + AnySamplesPassedConservative = GL_ANY_SAMPLES_PASSED_CONSERVATIVE }; + #ifndef MAGNUM_TARGET_GLES /** * @brief Conditional render mode * + * @requires_gl * @requires_gl30 Extension @extension{NV,conditional_render} */ enum class ConditionalRenderMode: GLenum { @@ -231,6 +255,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { */ ByRegionNoWait = GL_QUERY_BY_REGION_NO_WAIT }; + #endif inline SampleQuery(): target(nullptr) {} @@ -242,6 +267,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** @copydoc Query::end() */ void end(); + #ifndef MAGNUM_TARGET_GLES /** * @brief Begin conditional rendering based on result value * @@ -261,11 +287,13 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { inline void endConditionalRender() { glEndConditionalRender(); } + #endif private: Target* target; }; +#ifndef MAGNUM_TARGET_GLES /** @brief %Query for elapsed time @@ -310,7 +338,6 @@ class TimeQuery: public AbstractQuery { glQueryCounter(query, GL_TIMESTAMP); } }; - #endif } From f15906b28b8e6d7351e5c4ad50437f1f287e5dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 20:11:30 +0200 Subject: [PATCH 037/256] Fixed linking errors when only OpenGL ES 2 is available. This is currently toggled with TARGET_OPENGLES2 option, which is enabled by default when TARGET_OPENGLES is enabled. --- CMakeLists.txt | 3 ++- src/CMakeLists.txt | 3 +++ src/Query.cpp | 2 ++ src/Query.h | 2 ++ src/magnumConfigure.h.cmake | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99d68ef86..d40938c9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,8 @@ project(Magnum) include(CMakeDependentOption) -option(TARGET_GLES "Build for OpenGL ES 2 instead of desktop OpenGL" OFF) +option(TARGET_GLES "Build for OpenGL ES instead of desktop OpenGL" OFF) +cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF) # Parts of the library option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc35b4470..02f4084c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,9 @@ endif() if(TARGET_GLES) set(MAGNUM_TARGET_GLES 1) endif() +if(TARGET_GLES2) + set(MAGNUM_TARGET_GLES2 1) +endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumConfigure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h) diff --git a/src/Query.cpp b/src/Query.cpp index 9f23448b5..928e2a701 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -17,6 +17,7 @@ namespace Magnum { +#ifndef MAGNUM_TARGET_GLES2 bool AbstractQuery::resultAvailable() { GLuint result; glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result); @@ -80,5 +81,6 @@ void SampleQuery::end() { delete target; target = nullptr; } +#endif } diff --git a/src/Query.h b/src/Query.h index d7ea2fab9..e88f2af0a 100644 --- a/src/Query.h +++ b/src/Query.h @@ -25,6 +25,7 @@ namespace Magnum { +#ifndef MAGNUM_TARGET_GLES2 /** @brief Base class for queries @@ -339,6 +340,7 @@ class TimeQuery: public AbstractQuery { } }; #endif +#endif } diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index 9e8a3c7e8..7b42510db 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -1 +1,2 @@ #cmakedefine MAGNUM_TARGET_GLES +#cmakedefine MAGNUM_TARGET_GLES2 From bd665cb280d37fe3c280009ba7a1a4cfb52a6066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Aug 2012 23:32:45 +0200 Subject: [PATCH 038/256] More texture and renderbuffer internal formats supported in OpenGL ES 3.0. --- src/AbstractTexture.cpp | 27 +++++++++++++++-- src/AbstractTexture.h | 67 +++++++++++++++++------------------------ src/Renderbuffer.cpp | 25 +++++++++++++-- src/Renderbuffer.h | 36 ++++++++-------------- src/Texture.h | 8 ++--- 5 files changed, 92 insertions(+), 71 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 8def7f62b..87af0d7b0 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -69,8 +69,8 @@ AbstractTexture* AbstractTexture::generateMipmap() { return this; } -#ifndef MAGNUM_TARGET_GLES AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) { + #ifndef MAGNUM_TARGET_GLES #define internalFormatSwitch(c) switch(type) { \ case ComponentType::UnsignedByte: \ internalFormat = GL_##c##8UI; break; \ @@ -97,6 +97,30 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp case ComponentType::NormalizedShort: \ internalFormat = GL_##c##16_SNORM; break; \ } + #else + #define internalFormatSwitch(c) switch(type) { \ + case ComponentType::UnsignedByte: \ + internalFormat = GL_##c##8UI; break; \ + case ComponentType::Byte: \ + internalFormat = GL_##c##8I; break; \ + case ComponentType::UnsignedShort: \ + internalFormat = GL_##c##16UI; break; \ + case ComponentType::Short: \ + internalFormat = GL_##c##16I; break; \ + case ComponentType::UnsignedInt: \ + internalFormat = GL_##c##32UI; break; \ + case ComponentType::Int: \ + internalFormat = GL_##c##32I; break; \ + case ComponentType::Half: \ + internalFormat = GL_##c##16F; break; \ + case ComponentType::Float: \ + internalFormat = GL_##c##32F; break; \ + case ComponentType::NormalizedUnsignedByte: \ + internalFormat = GL_##c##8; break; \ + case ComponentType::NormalizedByte: \ + internalFormat = GL_##c##8_SNORM; break; \ + } + #endif if(components == Components::Red) internalFormatSwitch(R) else if(components == Components::RedGreen) @@ -107,7 +131,6 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp internalFormatSwitch(RGBA) #undef internalFormatSwitch } -#endif #ifndef DOXYGEN_GENERATING_OUTPUT void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) { diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 2e9899d5d..ed3e365a3 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -113,10 +113,10 @@ class MAGNUM_EXPORT AbstractTexture { /** @{ @name Internal texture formats */ - #ifndef MAGNUM_TARGET_GLES /** * @brief Color components - * @requires_gl + * + * @requires_gles30 (no extension providing this functionality) */ enum class Components { /** @@ -142,7 +142,7 @@ class MAGNUM_EXPORT AbstractTexture { * * `NormalizedUnsignedByte` and `NormalizedUnsignedShort` are the * main ones for general usage. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ enum class ComponentType { /** @@ -206,20 +206,23 @@ class MAGNUM_EXPORT AbstractTexture { */ NormalizedByte, + #ifndef MAGNUM_TARGET_GLES /** * Normalized unsigned short, i.e. values from range @f$ [0; 65536] @f$ * are converted to range @f$ [0.0; 1.0] @f$. + * @requires_gl */ NormalizedUnsignedShort, /** * Normalized signed short, i.e. values from range @f$ [-32768; 32767] @f$ * are converted to range @f$ [-1.0; 1.0] @f$. + * @requires_gl * @requires_gl31 Extension @extension{EXT,texture_snorm} */ NormalizedShort + #endif }; - #endif /** * @brief Internal format @@ -228,23 +231,21 @@ class MAGNUM_EXPORT AbstractTexture { * normalization see enums Components and ComponentType. */ enum class Format: GLenum { - #ifndef MAGNUM_TARGET_GLES /** * One-component (red channel), unsigned normalized, probably * 8bit. - * @requires_gl * @requires_gl30 Extension @extension{ARB,texture_rg} + * @requires_gles30 (no extension providing this functionality) */ Red = GL_RED, /** * Two-component (red and green channel), unsigned normalized, * each component probably 8bit, 16bit total. - * @requires_gl * @requires_gl30 Extension @extension{ARB,texture_rg} + * @requires_gles30 (no extension providing this functionality) */ RedGreen = GL_RG, - #endif /** * Three-component RGB, unsigned normalized, each component @@ -278,36 +279,36 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_gl */ BGRA = GL_BGRA, + #endif /** * Four-component sRGBA, unsigned normalized, each component * 8bit, 32bit total. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ SRGBA8 = GL_SRGB8_ALPHA8, /** * Three-component sRGB, unsigned normalized, each component * 8bit, 24bit total. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ SRGB8 = GL_SRGB8, /** * Four-component RGBA, unsigned normalized, each RGB component * 10bit, alpha 2bit, 32bit total. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ RGB10Alpha2 = GL_RGB10_A2, /** * Four-component RGBA, unsigned non-normalized, each RGB * component 10bit, alpha channel 2bit, 32bit total. - * @requires_gl * @requires_gl33 Extension @extension{ARB,texture_rgb10_a2ui} + * @requires_gles30 (no extension providing this functionality) */ RGB10Alpha2Unsigned = GL_RGB10_A2UI, - #endif /** * Four-component RGBA, unsigned normalized, each RGB component @@ -321,33 +322,29 @@ class MAGNUM_EXPORT AbstractTexture { */ RGBA4 = GL_RGBA4, - #ifndef MAGNUM_TARGET_GLES /** * Three-component RGB, float, red and green 11bit, blue 10bit, * 32bit total. - * @requires_gl * @requires_gl30 Extension @extension{EXT,packed_float} + * @requires_gles30 (no extension providing this functionality) */ RG11B10Float = GL_R11F_G11F_B10F, - #endif /** * Three-component RGB, unsigned normalized, red and blue 5bit, * green 6bit, 16bit total. */ - RGB565 = GL_RGB565 - - #ifndef MAGNUM_TARGET_GLES - , + RGB565 = GL_RGB565, /** * Three-component RGB, unsigned with exponent, each component * 9bit, exponent 5bit, 32bit total. - * @requires_gl * @requires_gl30 Extension @extension{EXT,texture_shared_exponent} + * @requires_gles30 (no extension providing this functionality) */ RGB9Exponent5 = GL_RGB9_E5, + #ifndef MAGNUM_TARGET_GLES /** * Compressed red channel, unsigned normalized. * @requires_gl @@ -448,40 +445,40 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_gl */ DepthStencil = GL_DEPTH_STENCIL, + #endif /** * 16bit depth component. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ Depth16 = GL_DEPTH_COMPONENT16, /** * 24bit depth component. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ Depth24 = GL_DEPTH_COMPONENT24, /** * 32bit float depth component. - * @requires_gl * @requires_gl30 Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 (no extension providing this functionality) */ Depth32Float = GL_DEPTH_COMPONENT32F, /** * 24bit depth and 8bit stencil component. - * @requires_gl * @requires_gl30 Extension @extension{EXT,packed_depth_stencil} + * @requires_gles30 (no extension providing this functionality) */ Depth24Stencil8 = GL_DEPTH24_STENCIL8, /** * 32bit float depth component and 8bit stencil component. - * @requires_gl * @requires_gl30 Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 (no extension providing this functionality) */ Depth32FloatStencil8 = GL_DEPTH32F_STENCIL8 - #endif }; /** @@ -502,14 +499,12 @@ class MAGNUM_EXPORT AbstractTexture { */ class MAGNUM_EXPORT InternalFormat { public: - #ifndef MAGNUM_TARGET_GLES /** * @brief Constructor from component count and data type per component * - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ InternalFormat(Components components, ComponentType type); - #endif /** @brief Constructor from named internal format */ inline constexpr InternalFormat(Format format): internalFormat(static_cast(format)) {} @@ -536,6 +531,7 @@ class MAGNUM_EXPORT AbstractTexture { * @brief Max supported anisotropy * * @see setMaxAnisotropy(), @fn_gl{Get} with @def_gl{MAX_TEXTURE_MAX_ANISOTROPY_EXT} + * @requires_gl * @requires_extension @extension{EXT,texture_filter_anisotropic} */ static GLfloat maxSupportedAnisotropy(); @@ -632,6 +628,7 @@ class MAGNUM_EXPORT AbstractTexture { * Default value is `1.0`, which means no anisotropy. Set to value * greater than `1.0` for anisotropic filtering. * @see maxSupportedAnisotropy(), bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} + * @requires_gl * @requires_extension @extension{EXT,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { @@ -675,11 +672,10 @@ class MAGNUM_EXPORT AbstractTexture { inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &texture); } -#ifndef MAGNUM_TARGET_GLES /** @relates AbstractTexture @brief Convertor of component count and data type to InternalFormat -@requires_gl +@requires_gles30 (no extension providing this functionality) */ inline AbstractTexture::InternalFormat operator|(AbstractTexture::Components components, AbstractTexture::ComponentType type) { return AbstractTexture::InternalFormat(components, type); @@ -691,7 +687,6 @@ inline AbstractTexture::InternalFormat operator|(AbstractTexture::Components com inline AbstractTexture::InternalFormat operator|(AbstractTexture::ComponentType type, AbstractTexture::Components components) { return AbstractTexture::InternalFormat(components, type); } -#endif #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_GLES @@ -743,19 +738,14 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { enum class Target: GLenum { - #ifndef MAGNUM_TARGET_GLES Texture3D = GL_TEXTURE_3D, Texture2DArray = GL_TEXTURE_2D_ARRAY - #endif }; - #ifndef MAGNUM_TARGET_GLES inline constexpr static Target target() { return Target::Texture3D; } - #endif static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping); - #ifndef MAGNUM_TARGET_GLES template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } @@ -767,7 +757,6 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } - #endif }; #endif diff --git a/src/Renderbuffer.cpp b/src/Renderbuffer.cpp index f7d2c4f11..aa08c7b63 100644 --- a/src/Renderbuffer.cpp +++ b/src/Renderbuffer.cpp @@ -17,8 +17,8 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentType type) { + #ifndef MAGNUM_TARGET_GLES #define internalFormatSwitch(c) switch(type) { \ case ComponentType::UnsignedByte: \ internalFormat = GL_##c##8UI; break; \ @@ -41,6 +41,28 @@ Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentTyp case ComponentType::NormalizedUnsignedShort: \ internalFormat = GL_##c##16; break; \ } + #else + #define internalFormatSwitch(c) switch(type) { \ + case ComponentType::UnsignedByte: \ + internalFormat = GL_##c##8UI; break; \ + case ComponentType::Byte: \ + internalFormat = GL_##c##8I; break; \ + case ComponentType::UnsignedShort: \ + internalFormat = GL_##c##16UI; break; \ + case ComponentType::Short: \ + internalFormat = GL_##c##16I; break; \ + case ComponentType::UnsignedInt: \ + internalFormat = GL_##c##32UI; break; \ + case ComponentType::Int: \ + internalFormat = GL_##c##32I; break; \ + case ComponentType::Half: \ + internalFormat = GL_##c##16F; break; \ + case ComponentType::Float: \ + internalFormat = GL_##c##32F; break; \ + case ComponentType::NormalizedUnsignedByte: \ + internalFormat = GL_##c##8; break; \ + } + #endif if(components == Components::Red) internalFormatSwitch(R) else if(components == Components::RedGreen) @@ -49,6 +71,5 @@ Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentTyp internalFormatSwitch(RGBA) #undef internalFormatSwitch } -#endif } diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 59e3565ab..86b1c8594 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -42,12 +42,11 @@ class Renderbuffer { public: /** @{ @name Internal renderbuffer formats */ - #ifndef MAGNUM_TARGET_GLES /** * @copybrief AbstractTexture::Components * * Like AbstractTexture::Components, without three-component RGB. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ enum class Components { Red, RedGreen, RGBA @@ -58,13 +57,16 @@ class Renderbuffer { * * Like AbstractTexture::ComponentType, without normalized signed * types. - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ enum class ComponentType { UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half, - Float, NormalizedUnsignedByte, NormalizedUnsignedShort + Float, NormalizedUnsignedByte + + #ifndef MAGNUM_TARGET_GLES + , NormalizedUnsignedShort + #endif }; - #endif /** * @copybrief AbstractTexture::Format @@ -74,23 +76,15 @@ class Renderbuffer { * compressed formats, but with added separate stencil index. */ enum class Format: GLenum { - #ifndef MAGNUM_TARGET_GLES - Red = GL_RED, RedGreen = GL_RG, - #endif - - RGBA = GL_RGBA, + Red = GL_RED, RedGreen = GL_RG, RGBA = GL_RGBA, #ifndef MAGNUM_TARGET_GLES - BGRA = GL_BGRA, SRGBA = GL_SRGB8_ALPHA8, - RGB10Alpha2 = GL_RGB10_A2, RGB10AlphaUnsigned2 = GL_RGB10_A2UI, - #endif - - RGB5Alpha1 = GL_RGB5_A1, RGBA4 = GL_RGBA4, - - #ifndef MAGNUM_TARGET_GLES - RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F, + BGRA = GL_BGRA, #endif + SRGBA = GL_SRGB8_ALPHA8, RGB10Alpha2 = GL_RGB10_A2, + RGB10AlphaUnsigned2 = GL_RGB10_A2UI, RGB5Alpha1 = GL_RGB5_A1, + RGBA4 = GL_RGBA4, RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F, RGB565 = GL_RGB565, #ifndef MAGNUM_TARGET_GLES @@ -157,10 +151,8 @@ class Renderbuffer { /** @copydoc AbstractTexture::InternalFormat */ class MAGNUM_EXPORT InternalFormat { public: - #ifndef MAGNUM_TARGET_GLES /** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */ InternalFormat(Components components, ComponentType type); - #endif /** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */ inline constexpr InternalFormat(Format format): internalFormat(static_cast(format)) {} @@ -226,11 +218,10 @@ class Renderbuffer { GLuint renderbuffer; }; -#ifndef MAGNUM_TARGET_GLES /** @relates Renderbuffer @brief Convertor of component count and data type to InternalFormat -@requires_gl +@requires_gles30 (no extension providing this functionality) */ inline Renderbuffer::InternalFormat operator|(Renderbuffer::Components components, Renderbuffer::ComponentType type) { return Renderbuffer::InternalFormat(components, type); @@ -241,7 +232,6 @@ inline Renderbuffer::InternalFormat operator|(Renderbuffer::Components component inline Renderbuffer::InternalFormat operator|(Renderbuffer::ComponentType type, Renderbuffer::Components components) { return Renderbuffer::InternalFormat(components, type); } -#endif } diff --git a/src/Texture.h b/src/Texture.h index 6e6f73c05..8faed911a 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -69,7 +69,7 @@ template class Texture: public AbstractTexture { /** * Three-dimensional texture - * @requires_gl + * @requires_gles30 (no extension providing this functionality) */ Texture3D = GL_TEXTURE_3D, @@ -82,8 +82,8 @@ template class Texture: public AbstractTexture { /** * Two-dimensional texture array (i.e. three dimensions in total) - * @requires_gl * @requires_gl30 Extension @extension{EXT,texture_array} + * @requires_gles30 (no extension providing this functionality) */ Texture2DArray = GL_TEXTURE_2D_ARRAY, @@ -186,14 +186,12 @@ typedef Texture<1> Texture1D; /** @brief Two-dimensional texture */ typedef Texture<2> Texture2D; -#ifndef MAGNUM_TARGET_GLES /** @brief Three-dimensional texture -@requires_gl +@requires_gles30 (no extension providing this functionality) */ typedef Texture<3> Texture3D; -#endif } From a5ab6253b73762bc17119bab6bda76eaff8e8246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Sep 2012 22:13:08 +0200 Subject: [PATCH 039/256] Contexts refactoring. Contexts attached to window are now *WindowContext, pure contexts are just *Context. --- modules/FindMagnum.cmake | 20 +++--- src/Contexts/AbstractContext.h | 52 +++++++++------ src/Contexts/AbstractGlInterface.h | 64 ------------------ src/Contexts/AbstractWindowContext.h | 52 +++++++++++++++ ...Context.cpp => AbstractXWindowContext.cpp} | 8 +-- ...actXContext.h => AbstractXWindowContext.h} | 38 +++++------ src/Contexts/CMakeLists.txt | 60 ++++++++--------- .../{EglInterface.cpp => EglContext.cpp} | 8 +-- src/Contexts/{EglInterface.h => EglContext.h} | 14 ++-- ...{GlutContext.cpp => GlutWindowContext.cpp} | 6 +- .../{GlutContext.h => GlutWindowContext.h} | 22 +++---- .../{GlxInterface.cpp => GlxContext.cpp} | 14 ++-- src/Contexts/GlxContext.h | 49 +++++++++----- src/Contexts/GlxInterface.h | 66 ------------------- src/Contexts/GlxWindowContext.h | 49 ++++++++++++++ ...{Sdl2Context.cpp => Sdl2WindowContext.cpp} | 8 +-- .../{Sdl2Context.h => Sdl2WindowContext.h} | 34 +++++----- .../{XEglContext.h => XEglWindowContext.h} | 16 ++--- 18 files changed, 290 insertions(+), 290 deletions(-) delete mode 100644 src/Contexts/AbstractGlInterface.h create mode 100644 src/Contexts/AbstractWindowContext.h rename src/Contexts/{AbstractXContext.cpp => AbstractXWindowContext.cpp} (92%) rename src/Contexts/{AbstractXContext.h => AbstractXWindowContext.h} (87%) rename src/Contexts/{EglInterface.cpp => EglContext.cpp} (92%) rename src/Contexts/{EglInterface.h => EglContext.h} (82%) rename src/Contexts/{GlutContext.cpp => GlutWindowContext.cpp} (83%) rename src/Contexts/{GlutContext.h => GlutWindowContext.h} (90%) rename src/Contexts/{GlxInterface.cpp => GlxContext.cpp} (86%) delete mode 100644 src/Contexts/GlxInterface.h create mode 100644 src/Contexts/GlxWindowContext.h rename src/Contexts/{Sdl2Context.cpp => Sdl2WindowContext.cpp} (94%) rename src/Contexts/{Sdl2Context.h => Sdl2WindowContext.h} (81%) rename src/Contexts/{XEglContext.h => XEglWindowContext.h} (66%) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 5568c5999..70b874ff9 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -86,13 +86,13 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX ${component}) - # Contexts - if(${component} MATCHES .+Context) + # Window contexts + if(${component} MATCHES .+WindowContext) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Contexts) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h) - # GLUT context dependencies - if(${component} STREQUAL GlutContext) + # GLUT window context dependencies + if(${component} STREQUAL GlutWindowContext) find_package(GLUT) if(GLUT_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES}) @@ -101,8 +101,8 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # SDL2 context dependencies - if(${component} STREQUAL Sdl2Context) + # SDL2 window context dependencies + if(${component} STREQUAL Sdl2WindowContext) find_package(SDL2) if(SDL2_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY}) @@ -112,8 +112,8 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # GLX context dependencies - if(${component} STREQUAL GlxContext) + # GLX window context dependencies + if(${component} STREQUAL GlxWindowContext) find_package(X11) if(X11_FOUND) set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES}) @@ -122,8 +122,8 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # X/EGL context dependencies - if(${component} STREQUAL XEglContext) + # X/EGL window context dependencies + if(${component} STREQUAL XEglWindowContext) find_package(EGL) find_package(X11) if(EGL_FOUND AND X11_FOUND) diff --git a/src/Contexts/AbstractContext.h b/src/Contexts/AbstractContext.h index f754d1012..93aeb121e 100644 --- a/src/Contexts/AbstractContext.h +++ b/src/Contexts/AbstractContext.h @@ -19,32 +19,44 @@ * @brief Class Magnum::Contexts::AbstractContext */ -namespace Magnum { namespace Contexts { +#include "ExtensionWrangler.h" -/** -@brief Base class for context creation +namespace Magnum { namespace Contexts { -See subclasses documentation for more information. Context classes subclasses -are meant to be used directly in `main()`, for example: -@code -class MyContext: public Magnum::Contexts::GlutContext { - // implement required methods... -}; -int main(int argc, char** argv) { - MyContext c(argc, argv); - return c.exec(); -} -@endcode -*/ -class AbstractContext { +/** @brief Base for OpenGL contexts */ +template class AbstractContext { public: - virtual inline ~AbstractContext() {} + /** + * @brief Get visual ID + * + * Initializes the interface on given display and returns visual ID. + */ + virtual VisualId getVisualId(Display nativeDisplay) = 0; /** - * @brief Execute main loop - * @return Value for returning from `main()`. + * @brief Destructor + * + * Finalizes and closes the interface. */ - virtual int exec() = 0; + virtual ~AbstractContext() {} + + /** @brief Create context */ + virtual void createContext(Window nativeWindow) = 0; + + /** + * @brief Whether to enable experimental extension wrangler features + * + * Default is to disable. + */ + virtual inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const { + return ExtensionWrangler::ExperimentalFeatures::Disable; + } + + /** @brief Make the context current */ + virtual void makeCurrent() = 0; + + /** @brief Swap buffers */ + virtual void swapBuffers() = 0; }; }} diff --git a/src/Contexts/AbstractGlInterface.h b/src/Contexts/AbstractGlInterface.h deleted file mode 100644 index 3f6d14ef6..000000000 --- a/src/Contexts/AbstractGlInterface.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef Magnum_Contexts_AbstractGlInterface_h -#define Magnum_Contexts_AbstractGlInterface_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Contexts::AbstractGlInterface - */ - -#include "ExtensionWrangler.h" - -namespace Magnum { namespace Contexts { - -/** @brief Base for OpenGL interfaces */ -template class AbstractGlInterface { - public: - /** - * @brief Get visual ID - * - * Initializes the interface on given display and returns visual ID. - */ - virtual VisualId getVisualId(Display nativeDisplay) = 0; - - /** - * @brief Destructor - * - * Finalizes and closes the interface. - */ - virtual ~AbstractGlInterface() {} - - /** @brief Create context */ - virtual void createContext(Window nativeWindow) = 0; - - /** - * @brief Whether to enable experimental extension wrangler features - * - * Default is to disable. - */ - virtual inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const { - return ExtensionWrangler::ExperimentalFeatures::Disable; - } - - /** @brief Make the context current */ - virtual void makeCurrent() = 0; - - /** @brief Swap buffers */ - virtual void swapBuffers() = 0; -}; - -}} - -#endif diff --git a/src/Contexts/AbstractWindowContext.h b/src/Contexts/AbstractWindowContext.h new file mode 100644 index 000000000..8d5b0ba78 --- /dev/null +++ b/src/Contexts/AbstractWindowContext.h @@ -0,0 +1,52 @@ +#ifndef Magnum_Contexts_AbstractWindowContext_h +#define Magnum_Contexts_AbstractWindowContext_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Contexts::AbstractWindowContext + */ + +namespace Magnum { namespace Contexts { + +/** +@brief Base class for context creation + +See subclasses documentation for more information. Context classes subclasses +are meant to be used directly in `main()`, for example: +@code +class MyContext: public Magnum::Contexts::GlutWindowContext { + // implement required methods... +}; +int main(int argc, char** argv) { + MyContext c(argc, argv); + return c.exec(); +} +@endcode +*/ +class AbstractWindowContext { + public: + virtual inline ~AbstractWindowContext() {} + + /** + * @brief Execute main loop + * @return Value for returning from `main()`. + */ + virtual int exec() = 0; +}; + +}} + +#endif diff --git a/src/Contexts/AbstractXContext.cpp b/src/Contexts/AbstractXWindowContext.cpp similarity index 92% rename from src/Contexts/AbstractXContext.cpp rename to src/Contexts/AbstractXWindowContext.cpp index 9c0747aaf..061111f5d 100644 --- a/src/Contexts/AbstractXContext.cpp +++ b/src/Contexts/AbstractXWindowContext.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractXContext.h" +#include "AbstractXWindowContext.h" #include "ExtensionWrangler.h" @@ -26,7 +26,7 @@ using namespace std; namespace Magnum { namespace Contexts { -AbstractXContext::AbstractXContext(AbstractGlInterface* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { +AbstractXWindowContext::AbstractXWindowContext(AbstractContext* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); @@ -72,7 +72,7 @@ AbstractXContext::AbstractXContext(AbstractGlInterfaceexperimentalExtensionWranglerFeatures()); } -AbstractXContext::~AbstractXContext() { +AbstractXWindowContext::~AbstractXWindowContext() { /* Shut down the interface */ delete glInterface; @@ -81,7 +81,7 @@ AbstractXContext::~AbstractXContext() { XCloseDisplay(display); } -int AbstractXContext::exec() { +int AbstractXWindowContext::exec() { /* Show window */ XMapWindow(display, window); diff --git a/src/Contexts/AbstractXContext.h b/src/Contexts/AbstractXWindowContext.h similarity index 87% rename from src/Contexts/AbstractXContext.h rename to src/Contexts/AbstractXWindowContext.h index 622e81ef3..c94eb34bd 100644 --- a/src/Contexts/AbstractXContext.h +++ b/src/Contexts/AbstractXWindowContext.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_AbstractXContext_h -#define Magnum_Contexts_AbstractXContext_h +#ifndef Magnum_Contexts_AbstractXWindowContext_h +#define Magnum_Contexts_AbstractXWindowContext_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::AbstractXContext + * @brief Class Magnum::Contexts::AbstractXWindowContext */ #include @@ -30,8 +30,8 @@ #undef Always #include "Math/Vector2.h" +#include "AbstractWindowContext.h" #include "AbstractContext.h" -#include "AbstractGlInterface.h" namespace Magnum { namespace Contexts { @@ -42,7 +42,7 @@ Supports keyboard and mouse handling. @note Not meant to be used directly, see subclasses. */ -class AbstractXContext: public AbstractContext { +class AbstractXWindowContext: public AbstractWindowContext { public: /** * @brief Constructor @@ -54,14 +54,14 @@ class AbstractXContext: public AbstractContext { * * Creates window with double-buffered OpenGL ES 2 context. */ - AbstractXContext(AbstractGlInterface* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); + AbstractXWindowContext(AbstractContext* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); /** * @brief Destructor * * Deletes context and destroys the window. */ - virtual ~AbstractXContext() = 0; + virtual ~AbstractXWindowContext() = 0; int exec(); @@ -71,16 +71,16 @@ class AbstractXContext: public AbstractContext { /** @{ @name Drawing functions */ protected: - /** @copydoc GlutContext::viewportEvent() */ + /** @copydoc GlutWindowContext::viewportEvent() */ virtual void viewportEvent(const Math::Vector2& size) = 0; - /** @copydoc GlutContext::drawEvent() */ + /** @copydoc GlutWindowContext::drawEvent() */ virtual void drawEvent() = 0; - /** @copydoc GlutContext::swapBuffers() */ + /** @copydoc GlutWindowContext::swapBuffers() */ inline void swapBuffers() { glInterface->swapBuffers(); } - /** @copydoc GlutContext::redraw() */ + /** @copydoc GlutWindowContext::redraw() */ inline void redraw() { flags |= Flag::Redraw; } /*@}*/ @@ -277,7 +277,7 @@ class AbstractXContext: public AbstractContext { Window window; Atom deleteWindow; - AbstractGlInterface* glInterface; + AbstractContext* glInterface; /** @todo Get this from the created window */ Math::Vector2 viewportSize; @@ -285,15 +285,15 @@ class AbstractXContext: public AbstractContext { Flags flags; }; -CORRADE_ENUMSET_OPERATORS(AbstractXContext::Modifiers) -CORRADE_ENUMSET_OPERATORS(AbstractXContext::Flags) +CORRADE_ENUMSET_OPERATORS(AbstractXWindowContext::Modifiers) +CORRADE_ENUMSET_OPERATORS(AbstractXWindowContext::Flags) /* Implementations for inline functions with unused parameters */ -inline void AbstractXContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} }} diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index 7d5cd8fe0..715bb4e5a 100644 --- a/src/Contexts/CMakeLists.txt +++ b/src/Contexts/CMakeLists.txt @@ -3,7 +3,7 @@ add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp) set(MagnumContexts_HEADERS AbstractContext.h - AbstractGlInterface.h + AbstractWindowContext.h ExtensionWrangler.h) install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) @@ -11,13 +11,13 @@ install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR if(WITH_GLUTCONTEXT) find_package(GLUT) if(GLUT_FOUND) - add_library(MagnumGlutContext STATIC - GlutContext.cpp + add_library(MagnumGlutWindowContext STATIC + GlutWindowContext.cpp $) - install(FILES GlutContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) - install(TARGETS MagnumGlutContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + install(FILES GlutWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + install(TARGETS MagnumGlutWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "GLUT library, required by GlutContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.") + message(FATAL_ERROR "GLUT library, required by GlutWindowContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.") endif() endif() @@ -26,13 +26,13 @@ if(WITH_SDL2CONTEXT) find_package(SDL2) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) - add_library(MagnumSdl2Context STATIC - Sdl2Context.cpp + add_library(MagnumSdl2WindowContext STATIC + Sdl2WindowContext.cpp $) - install(FILES Sdl2Context.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) - install(TARGETS MagnumSdl2Context DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + install(FILES Sdl2WindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + install(TARGETS MagnumSdl2WindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "SDL2 library, required by Sdl2Context, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.") + message(FATAL_ERROR "SDL2 library, required by Sdl2WindowContext, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.") endif() endif() @@ -40,24 +40,24 @@ endif() if(WITH_GLXCONTEXT) set(NEED_ABSTRACTXCONTEXT 1) set(NEED_GLXINTERFACE 1) - add_library(MagnumGlxContext STATIC - $ - $ + add_library(MagnumGlxWindowContext STATIC + $ + $ $) - install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) - install(TARGETS MagnumGlxContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() # X/EGL context if(WITH_XEGLCONTEXT) set(NEED_ABSTRACTXCONTEXT 1) set(NEED_EGLINTERFACE 1) - add_library(MagnumXEglContext STATIC - $ - $ + add_library(MagnumXEglWindowContext STATIC + $ + $ $) - install(FILES XEglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) - install(TARGETS MagnumXEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) + install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() # Abstract X context @@ -66,18 +66,18 @@ if(NEED_ABSTRACTXCONTEXT) if(NOT X11_FOUND) message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*CONTEXT to OFF to skip building them.") endif() - add_library(MagnumAbstractXContext OBJECT AbstractXContext.cpp) + add_library(MagnumAbstractXWindowContext OBJECT AbstractXWindowContext.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumAbstractXContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES AbstractXContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + set_target_properties(MagnumAbstractXWindowContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES AbstractXWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() # GLX interface if(NEED_GLXINTERFACE) - add_library(MagnumGlxInterface OBJECT GlxInterface.cpp) + add_library(MagnumGlxContext OBJECT GlxContext.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumGlxInterface PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES GlxInterface.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() # EGL interface @@ -86,8 +86,8 @@ if(NEED_EGLINTERFACE) if(NOT EGL_FOUND) message(FATAL_ERROR "EGL library, required by some contexts, was not found. Set WITH_*EGL*CONTEXT to OFF to skip building them.") endif() - add_library(MagnumEglInterface OBJECT EglInterface.cpp) + add_library(MagnumEglContext OBJECT EglContext.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumEglInterface PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES EglInterface.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + set_target_properties(MagnumEglContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() diff --git a/src/Contexts/EglInterface.cpp b/src/Contexts/EglContext.cpp similarity index 92% rename from src/Contexts/EglInterface.cpp rename to src/Contexts/EglContext.cpp index 609f37322..323e880e1 100644 --- a/src/Contexts/EglInterface.cpp +++ b/src/Contexts/EglContext.cpp @@ -13,17 +13,17 @@ GNU Lesser General Public License version 3 for more details. */ -#include "EglInterface.h" +#include "EglContext.h" namespace Magnum { namespace Contexts { -EglInterface::~EglInterface() { +EglContext::~EglContext() { eglDestroyContext(display, context); eglDestroySurface(display, surface); eglTerminate(display); } -VisualId EglInterface::getVisualId(EGLNativeDisplayType nativeDisplay) { +VisualId EglContext::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Initialize */ display = eglGetDisplay(nativeDisplay); eglInitialize(display, 0, 0); @@ -62,7 +62,7 @@ VisualId EglInterface::getVisualId(EGLNativeDisplayType nativeDisplay) { return visualId; } -void EglInterface::createContext(EGLNativeWindowType window) { +void EglContext::createContext(EGLNativeWindowType window) { static const EGLint contextAttributes[] = { #ifdef MAGNUM_TARGET_GLES EGL_CONTEXT_CLIENT_VERSION, 2, diff --git a/src/Contexts/EglInterface.h b/src/Contexts/EglContext.h similarity index 82% rename from src/Contexts/EglInterface.h rename to src/Contexts/EglContext.h index 671d6df18..0190fa299 100644 --- a/src/Contexts/EglInterface.h +++ b/src/Contexts/EglContext.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_EglInterface_h -#define Magnum_Contexts_EglInterface_h +#ifndef Magnum_Contexts_EglContext_h +#define Magnum_Contexts_EglContext_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::EglInterface + * @brief Class Magnum::Contexts::EglContext */ #include "Magnum.h" @@ -26,7 +26,7 @@ #endif #include -#include "AbstractGlInterface.h" +#include "AbstractContext.h" namespace Magnum { namespace Contexts { @@ -42,11 +42,11 @@ typedef EGLInt VisualId; /** @brief EGL interface -Used in XEglContext. +Used in XEglWindowContext. */ -class EglInterface: public AbstractGlInterface { +class EglContext: public AbstractContext { public: - ~EglInterface(); + ~EglContext(); VisualId getVisualId(EGLNativeDisplayType nativeDisplay); void createContext(EGLNativeWindowType nativeWindow); diff --git a/src/Contexts/GlutContext.cpp b/src/Contexts/GlutWindowContext.cpp similarity index 83% rename from src/Contexts/GlutContext.cpp rename to src/Contexts/GlutWindowContext.cpp index 01307482d..785bbda0c 100644 --- a/src/Contexts/GlutContext.cpp +++ b/src/Contexts/GlutWindowContext.cpp @@ -13,15 +13,15 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GlutContext.h" +#include "GlutWindowContext.h" #include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { -GlutContext* GlutContext::instance = nullptr; +GlutWindowContext* GlutWindowContext::instance = nullptr; -GlutContext::GlutContext(int& argc, char** argv, const std::string& title, const Math::Vector2& size): argc(argc), argv(argv) { +GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string& title, const Math::Vector2& size): argc(argc), argv(argv) { /* Save global instance */ instance = this; diff --git a/src/Contexts/GlutContext.h b/src/Contexts/GlutWindowContext.h similarity index 90% rename from src/Contexts/GlutContext.h rename to src/Contexts/GlutWindowContext.h index 960775a94..ad46a4100 100644 --- a/src/Contexts/GlutContext.h +++ b/src/Contexts/GlutWindowContext.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_GlutContext_h -#define Magnum_Contexts_GlutContext_h +#ifndef Magnum_Contexts_GlutWindowContext_h +#define Magnum_Contexts_GlutWindowContext_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::GlutContext + * @brief Class Magnum::Contexts::GlutWindowContext */ #include @@ -26,7 +26,7 @@ #include -#include "AbstractContext.h" +#include "AbstractWindowContext.h" namespace Magnum { namespace Contexts { @@ -39,7 +39,7 @@ support for changing cursor and mouse tracking and warping. You need to implement at least drawEvent() and viewportEvent() to be able to draw on the screen. */ -class GlutContext: public AbstractContext { +class GlutWindowContext: public AbstractWindowContext { public: /** * @brief Constructor @@ -50,7 +50,7 @@ class GlutContext: public AbstractContext { * * Creates double-buffered RGBA window with depth and stencil buffers. */ - GlutContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2& size = Math::Vector2(800, 600)); + GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2& size = Math::Vector2(800, 600)); inline int exec() { glutMainLoop(); @@ -242,17 +242,17 @@ class GlutContext: public AbstractContext { instance->drawEvent(); } - static GlutContext* instance; + static GlutWindowContext* instance; int& argc; char** argv; }; /* Implementations for inline functions with unused parameters */ -inline void GlutContext::keyPressEvent(Key, const Math::Vector2&) {} -inline void GlutContext::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void GlutContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void GlutContext::mouseMotionEvent(const Math::Vector2&) {} +inline void GlutWindowContext::keyPressEvent(Key, const Math::Vector2&) {} +inline void GlutWindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} +inline void GlutWindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} +inline void GlutWindowContext::mouseMotionEvent(const Math::Vector2&) {} }} diff --git a/src/Contexts/GlxInterface.cpp b/src/Contexts/GlxContext.cpp similarity index 86% rename from src/Contexts/GlxInterface.cpp rename to src/Contexts/GlxContext.cpp index a9ce9aba0..328edffd7 100644 --- a/src/Contexts/GlxInterface.cpp +++ b/src/Contexts/GlxContext.cpp @@ -13,21 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GlxInterface.h" +#include "GlxContext.h" #include #include namespace Magnum { namespace Contexts { -VisualID GlxInterface::getVisualId(Display* nativeDisplay) { +VisualID GlxContext::getVisualId(Display* nativeDisplay) { display = nativeDisplay; /* Check version */ int major, minor; glXQueryVersion(nativeDisplay, &major, &minor); if(major == 1 && minor < 4) { - Error() << "GlxInterface: GLX version 1.4 or greater is required."; + Error() << "GlxContext: GLX version 1.4 or greater is required."; exit(1); } @@ -45,7 +45,7 @@ VisualID GlxInterface::getVisualId(Display* nativeDisplay) { }; configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount); if(!configCount) { - Error() << "GlxInterface: no supported framebuffer configuration found."; + Error() << "GlxContext: no supported framebuffer configuration found."; exit(1); } @@ -57,7 +57,7 @@ VisualID GlxInterface::getVisualId(Display* nativeDisplay) { return visualId; } -void GlxInterface::createContext(Window nativeWindow) { +void GlxContext::createContext(Window nativeWindow) { window = nativeWindow; GLint attributes[] = { @@ -78,12 +78,12 @@ void GlxInterface::createContext(Window nativeWindow) { context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes); XFree(configs); if(!context) { - Error() << "GlxInterface: cannot create context."; + Error() << "GlxContext: cannot create context."; exit(1); } } -GlxInterface::~GlxInterface() { +GlxContext::~GlxContext() { glXMakeCurrent(display, None, nullptr); glXDestroyContext(display, context); } diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContext.h index a11b503c7..4f5cc775b 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContext.h @@ -19,29 +19,46 @@ * @brief Class Magnum::Contexts::GlxContext */ -#include "AbstractXContext.h" -#include "GlxInterface.h" +#include "Magnum.h" +#include + +#include "AbstractContext.h" namespace Magnum { namespace Contexts { /** -@brief GLX context +@brief GLX interface + +Creates OpenGL 3.3 core context or OpenGL ES 2.0 context, if targetting +OpenGL ES. -Uses GlxInterface. +Used in GlxWindowContext. */ -class GlxContext: public AbstractXContext { +class GlxContext: public AbstractContext { public: - /** - * @brief Constructor - * @param argc Count of arguments of `main()` function - * @param argv Arguments of `main()` function - * @param title Window title - * @param size Window size - * - * Creates window with double-buffered OpenGL 3.3 core context or - * OpenGL ES 2.0 context, if targetting OpenGL ES. - */ - inline GlxContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXContext(new GlxInterface, argc, argv, title, size) {} + ~GlxContext(); + + VisualID getVisualId(Display* nativeDisplay); + void createContext(Window nativeWindow); + + /* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */ + inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const { + return ExtensionWrangler::ExperimentalFeatures::Enable; + } + + inline void makeCurrent() { + glXMakeCurrent(display, window, context); + } + + inline void swapBuffers() { + glXSwapBuffers(display, window); + } + + private: + Display* display; + Window window; + GLXFBConfig* configs; + GLXContext context; }; }} diff --git a/src/Contexts/GlxInterface.h b/src/Contexts/GlxInterface.h deleted file mode 100644 index e9f3177d8..000000000 --- a/src/Contexts/GlxInterface.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef Magnum_Contexts_EglInterface_h -#define Magnum_Contexts_EglInterface_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Contexts::GlxInterface - */ - -#include "Magnum.h" -#include - -#include "AbstractGlInterface.h" - -namespace Magnum { namespace Contexts { - -/** -@brief GLX interface - -Creates OpenGL 3.3 core context or OpenGL ES 2.0 context, if targetting -OpenGL ES. - -Used in GlxContext. -*/ -class GlxInterface: public AbstractGlInterface { - public: - ~GlxInterface(); - - VisualID getVisualId(Display* nativeDisplay); - void createContext(Window nativeWindow); - - /* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */ - inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const { - return ExtensionWrangler::ExperimentalFeatures::Enable; - } - - inline void makeCurrent() { - glXMakeCurrent(display, window, context); - } - - inline void swapBuffers() { - glXSwapBuffers(display, window); - } - - private: - Display* display; - Window window; - GLXFBConfig* configs; - GLXContext context; -}; - -}} - -#endif diff --git a/src/Contexts/GlxWindowContext.h b/src/Contexts/GlxWindowContext.h new file mode 100644 index 000000000..65f68da50 --- /dev/null +++ b/src/Contexts/GlxWindowContext.h @@ -0,0 +1,49 @@ +#ifndef Magnum_Contexts_GlxWindowContext_h +#define Magnum_Contexts_GlxWindowContext_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Contexts::GlxWindowContext + */ + +#include "AbstractXWindowContext.h" +#include "GlxContext.h" + +namespace Magnum { namespace Contexts { + +/** +@brief GLX context + +Uses GlxContext. +*/ +class GlxWindowContext: public AbstractXWindowContext { + public: + /** + * @brief Constructor + * @param argc Count of arguments of `main()` function + * @param argv Arguments of `main()` function + * @param title Window title + * @param size Window size + * + * Creates window with double-buffered OpenGL 3.3 core context or + * OpenGL ES 2.0 context, if targetting OpenGL ES. + */ + inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContext, argc, argv, title, size) {} +}; + +}} + +#endif diff --git a/src/Contexts/Sdl2Context.cpp b/src/Contexts/Sdl2WindowContext.cpp similarity index 94% rename from src/Contexts/Sdl2Context.cpp rename to src/Contexts/Sdl2WindowContext.cpp index f55fa6125..8edc77190 100644 --- a/src/Contexts/Sdl2Context.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -13,12 +13,12 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Sdl2Context.h" +#include "Sdl2WindowContext.h" #include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { -Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vector2& size): _redraw(true) { +Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const Math::Vector2& size): _redraw(true) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; exit(1); @@ -54,13 +54,13 @@ Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vecto SDL_PushEvent(sizeEvent); } -Sdl2Context::~Sdl2Context() { +Sdl2WindowContext::~Sdl2WindowContext() { SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); } -int Sdl2Context::exec() { +int Sdl2WindowContext::exec() { for(;;) { SDL_Event event; diff --git a/src/Contexts/Sdl2Context.h b/src/Contexts/Sdl2WindowContext.h similarity index 81% rename from src/Contexts/Sdl2Context.h rename to src/Contexts/Sdl2WindowContext.h index 5f91d9e75..ca80ec681 100644 --- a/src/Contexts/Sdl2Context.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_Sdl2Context_h -#define Magnum_Contexts_Sdl2Context_h +#ifndef Magnum_Contexts_Sdl2WindowContext_h +#define Magnum_Contexts_Sdl2WindowContext_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::Sdl2Context + * @brief Class Magnum::Contexts::Sdl2WindowContext */ #include "Math/Vector2.h" @@ -25,7 +25,7 @@ #include #include -#include "AbstractContext.h" +#include "AbstractWindowContext.h" namespace Magnum { namespace Contexts { @@ -37,7 +37,7 @@ Supports keyboard and mouse handling. You need to implement at least drawEvent() and viewportEvent() to be able to draw on the screen. */ -class Sdl2Context: public AbstractContext { +class Sdl2WindowContext: public AbstractWindowContext { public: /** * @brief Constructor @@ -49,30 +49,30 @@ class Sdl2Context: public AbstractContext { * Creates centered non-resizable window with double-buffered * OpenGL 3.3 context with 24bit depth buffer. */ - Sdl2Context(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2& size = Math::Vector2(800, 600)); + Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2& size = Math::Vector2(800, 600)); /** * @brief Destructor * * Deletes context and destroys the window. */ - ~Sdl2Context(); + ~Sdl2WindowContext(); int exec(); /** @{ @name Drawing functions */ protected: - /** @copydoc GlutContext::viewportEvent() */ + /** @copydoc GlutWindowContext::viewportEvent() */ virtual void viewportEvent(const Math::Vector2& size) = 0; - /** @copydoc GlutContext::drawEvent() */ + /** @copydoc GlutWindowContext::drawEvent() */ virtual void drawEvent() = 0; - /** @copydoc GlutContext::swapBuffers() */ + /** @copydoc GlutWindowContext::swapBuffers() */ inline void swapBuffers() { SDL_GL_SwapWindow(window); } - /** @copydoc GlutContext::redraw() */ + /** @copydoc GlutWindowContext::redraw() */ inline void redraw() { _redraw = true; } /*@}*/ @@ -183,12 +183,12 @@ class Sdl2Context: public AbstractContext { }; /* Implementations for inline functions with unused parameters */ -inline void Sdl2Context::keyPressEvent(Key, Uint8) {} -inline void Sdl2Context::keyReleaseEvent(Key) {} -inline void Sdl2Context::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2Context::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2Context::mouseWheelEvent(const Math::Vector2&) {} -inline void Sdl2Context::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {} +inline void Sdl2WindowContext::keyReleaseEvent(Key) {} +inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} }} diff --git a/src/Contexts/XEglContext.h b/src/Contexts/XEglWindowContext.h similarity index 66% rename from src/Contexts/XEglContext.h rename to src/Contexts/XEglWindowContext.h index fb368c1db..131c5498c 100644 --- a/src/Contexts/XEglContext.h +++ b/src/Contexts/XEglWindowContext.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_XEglContext_h -#define Magnum_Contexts_XEglContext_h +#ifndef Magnum_Contexts_XEglWindowContext_h +#define Magnum_Contexts_XEglWindowContext_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,20 +16,20 @@ */ /** @file - * @brief Class Magnum::Contexts::XEglContext + * @brief Class Magnum::Contexts::XEglWindowContext */ -#include "AbstractXContext.h" -#include "EglInterface.h" +#include "AbstractXWindowContext.h" +#include "EglContext.h" namespace Magnum { namespace Contexts { /** @brief X/EGL context -Uses EglInterface. +Uses EglContext. */ -class XEglContext: public AbstractXContext { +class XEglWindowContext: public AbstractXWindowContext { public: /** * @brief Constructor @@ -40,7 +40,7 @@ class XEglContext: public AbstractXContext { * * Creates window with double-buffered OpenGL ES 2 context. */ - inline XEglContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXContext(new EglInterface, argc, argv, title, size) {} + inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContext, argc, argv, title, size) {} }; }} From ae28de197bc3d9e46b7c57721bad7a3f30bf3b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 10 Sep 2012 01:59:47 +0200 Subject: [PATCH 040/256] Classes for handling version and extension information. --- src/CMakeLists.txt | 3 + src/Context.cpp | 188 +++++++++++++++++++++++++++++++++++++++ src/Context.h | 216 +++++++++++++++++++++++++++++++++++++++++++++ src/Extensions.h | 141 +++++++++++++++++++++++++++++ 4 files changed, 548 insertions(+) create mode 100644 src/Context.cpp create mode 100644 src/Context.h create mode 100644 src/Extensions.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02f4084c7..390eeb583 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(Magnum_SRCS AbstractTexture.cpp AbstractShaderProgram.cpp BufferedTexture.cpp + Context.cpp Framebuffer.cpp IndexedMesh.cpp Mesh.cpp @@ -42,8 +43,10 @@ set(Magnum_HEADERS BufferedTexture.h Buffer.h Color.h + Context.h CubeMapTextureArray.h CubeMapTexture.h + Extensions.h Framebuffer.h Image.h ImageWrapper.h diff --git a/src/Context.cpp b/src/Context.cpp new file mode 100644 index 000000000..bb484f8dc --- /dev/null +++ b/src/Context.cpp @@ -0,0 +1,188 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Context.h" + +#include +#include +#include + +#include "Extensions.h" + +using namespace std; + +namespace Magnum { + +const std::vector& Extension::extensions(Version version) { + #define _extension(prefix, vendor, extension) \ + {Extensions::prefix::vendor::extension::Index, Extensions::prefix::vendor::extension::requiredVersion(), Extensions::prefix::vendor::extension::coreVersion(), Extensions::prefix::vendor::extension::string()} + static std::vector empty; + static std::vector extensions{ + _extension(GL,EXT,texture_filter_anisotropic)}; + static std::vector extensions300{ + _extension(GL,APPLE,flush_buffer_range), + _extension(GL,APPLE,vertex_array_object), + _extension(GL,ARB,color_buffer_float), + _extension(GL,ARB,half_float_pixel), + _extension(GL,ARB,texture_float), + _extension(GL,ARB,depth_buffer_float), + _extension(GL,ARB,texture_rg), + _extension(GL,EXT,framebuffer_object), + _extension(GL,EXT,packed_depth_stencil), + _extension(GL,EXT,framebuffer_blit), + _extension(GL,EXT,framebuffer_multisample), + _extension(GL,EXT,gpu_shader4), + _extension(GL,EXT,packed_float), + _extension(GL,EXT,texture_array), + _extension(GL,EXT,texture_compression_rgtc), + _extension(GL,EXT,texture_shared_exponent), + _extension(GL,EXT,framebuffer_sRGB), + _extension(GL,EXT,draw_buffers2), + _extension(GL,EXT,texture_integer), + _extension(GL,EXT,transform_feedback), + _extension(GL,NV,half_float), + _extension(GL,NV,depth_buffer_float), + _extension(GL,NV,conditional_render)}; + static std::vector extensions310{ + _extension(GL,ARB,texture_rectangle), + _extension(GL,ARB,draw_instanced), + _extension(GL,ARB,texture_buffer_object), + _extension(GL,ARB,uniform_buffer_object), + _extension(GL,ARB,copy_buffer), + _extension(GL,EXT,texture_snorm), + _extension(GL,NV,primitive_restart)}; + static std::vector extensions320{ + _extension(GL,ARB,geometry_shader4), + _extension(GL,ARB,depth_clamp), + _extension(GL,ARB,draw_elements_base_vertex), + _extension(GL,ARB,fragment_coord_conventions), + _extension(GL,ARB,provoking_vertex), + _extension(GL,ARB,seamless_cube_map), + _extension(GL,ARB,sync), + _extension(GL,ARB,texture_multisample), + _extension(GL,ARB,vertex_array_bgra)}; + static std::vector extensions330{ + _extension(GL,ARB,instanced_arrays), + _extension(GL,ARB,blend_func_extended), + _extension(GL,ARB,explicit_attrib_location), + _extension(GL,ARB,occlusion_query2), + _extension(GL,ARB,sampler_objects), + _extension(GL,ARB,shader_bit_encoding), + _extension(GL,ARB,texture_rgb10_a2ui), + _extension(GL,ARB,texture_swizzle), + _extension(GL,ARB,timer_query), + _extension(GL,ARB,vertex_type_2_10_10_10_rev)}; + static std::vector extensions400{ + _extension(GL,ARB,draw_buffers_blend), + _extension(GL,ARB,sample_shading), + _extension(GL,ARB,texture_cube_map_array), + _extension(GL,ARB,texture_gather), + _extension(GL,ARB,texture_query_lod), + _extension(GL,ARB,draw_indirect), + _extension(GL,ARB,gpu_shader5), + _extension(GL,ARB,gpu_shader_fp64), + _extension(GL,ARB,shader_subroutine), + _extension(GL,ARB,tessellation_shader), + _extension(GL,ARB,texture_buffer_object_rgb32), + _extension(GL,ARB,transform_feedback2), + _extension(GL,ARB,transform_feedback3)}; + static std::vector extensions410{ + _extension(GL,ARB,ES2_compatibility), + _extension(GL,ARB,get_program_binary), + _extension(GL,ARB,separate_shader_objects), + _extension(GL,ARB,shader_precision), + _extension(GL,ARB,vertex_attrib_64bit), + _extension(GL,ARB,viewport_array)}; + static std::vector extensions420{ + _extension(GL,ARB,texture_compression_bptc), + _extension(GL,ARB,base_instance), + _extension(GL,ARB,shading_language_420pack), + _extension(GL,ARB,transform_feedback_instanced), + _extension(GL,ARB,compressed_texture_pixel_storage), + _extension(GL,ARB,conservative_depth), + _extension(GL,ARB,internalformat_query), + _extension(GL,ARB,map_buffer_alignment), + _extension(GL,ARB,shader_atomic_counters), + _extension(GL,ARB,shader_image_load_store), + _extension(GL,ARB,texture_storage)}; + static std::vector extensions430; + #undef _extension + + switch(version) { + case Version::None: return extensions; + case Version::GL300: return extensions300; + case Version::GL310: return extensions310; + case Version::GL320: return extensions320; + case Version::GL330: return extensions330; + case Version::GL400: return extensions400; + case Version::GL410: return extensions410; + case Version::GL420: return extensions420; + case Version::GL430: return extensions430; + default: return empty; + } +} + +Context* Context::_current = nullptr; + +Context::Context() { + /* Version */ + glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion); + glGetIntegerv(GL_MINOR_VERSION, &_minorVersion); + _version = static_cast(_majorVersion*100+_minorVersion*10); + + /* Future versions */ + vector versions{ + Version::GL300, + Version::GL310, + Version::GL320, + Version::GL330, + Version::GL400, + Version::GL410, + Version::GL420, + Version::GL430, + Version::None + }; + size_t future = 0; + while(versions[future] != Version::None && versions[future] < _version) + ++future; + + /* Extensions */ + unordered_map futureExtensions; + for(size_t i = future; i != versions.size(); ++i) + for(const Extension& extension: Extension::extensions(versions[i])) + futureExtensions.insert(make_pair(extension._string, extension)); + + /* Check for presence of extensions in future versions */ + GLuint index = 0; + const char* extension; + while((extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, index++)))) { + auto found = futureExtensions.find(extension); + if(found != futureExtensions.end()) { + _supportedExtensions.push_back(found->second); + extensionStatus.set(found->second._index); + } + } + + /* Set this context as current */ + CORRADE_ASSERT(!_current, "Context: Another context currently active", ); + _current = this; +} + +Context::~Context() { + CORRADE_ASSERT(_current == this, "Context: Cannot destroy context which is not currently active", ); + _current = nullptr; +} + +} diff --git a/src/Context.h b/src/Context.h new file mode 100644 index 000000000..1b9dd0b8d --- /dev/null +++ b/src/Context.h @@ -0,0 +1,216 @@ +#ifndef Magnum_Context_h +#define Magnum_Context_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Enum Version, class Magnum::Context, Magnum::Extension + */ + +#include +#include + +#include "Magnum.h" + +#include "magnumVisibility.h" + +namespace Magnum { + +/** @brief OpenGL version */ +enum class Version: GLint { + None = 0, /**< @brief Unspecified */ + #ifndef MAGNUM_TARGET_GLES + GL210 = 210, /**< @brief OpenGL 2.1 / GLSL 1.20 */ + GL300 = 300, /**< @brief OpenGL 3.0 / GLSL 1.30 */ + GL310 = 310, /**< @brief OpenGL 3.1 / GLSL 1.40 */ + GL320 = 320, /**< @brief OpenGL 3.2 / GLSL 1.50 */ + GL330 = 330, /**< @brief OpenGL 3.3, GLSL 3.30 */ + GL400 = 400, /**< @brief OpenGL 4.0, GLSL 4.00 */ + GL410 = 410, /**< @brief OpenGL 4.1, GLSL 4.10 */ + GL420 = 420, /**< @brief OpenGL 4.2, GLSL 4.20 */ + GL430 = 430 /**< @brief OpenGL 4.3, GLSL 4.30 */ + #else + GLES200 = 200, /**< @brief OpenGL ES 2.0, GLSL ES 1.00 */ + GLES300 = 300 /**< @brief OpenGL ES 3.0, GLSL ES 3.00 */ + #endif +}; + +/** +@brief Run-time information about OpenGL extension + +Encapsulates runtime information about OpenGL extension, such as name string, +minimal required OpenGL version and version in which the extension was adopted +to core. + +See also Extensions namespace, which contain compile-time information about +OpenGL extensions. +*/ +class MAGNUM_EXPORT Extension { + friend class Context; + + public: + /** @brief All extensions for given OpenGL version */ + static const std::vector& extensions(Version version); + + /** @brief Minimal version required by this extension */ + inline constexpr Version requiredVersion() const { return _requiredVersion; } + + /** @brief Version in which this extension was adopted to core */ + inline constexpr Version coreVersion() const { return _coreVersion; } + + /** @brief %Extension string */ + inline constexpr const char* string() const { return _string; } + + private: + const size_t _index; + const Version _requiredVersion; + const Version _coreVersion; + const char* const _string; + + inline constexpr Extension(size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} +}; + +/** +@brief OpenGL context + +Provides access to version and extension information. +*/ +class MAGNUM_EXPORT Context { + Context(const Context&) = delete; + Context(Context&&) = delete; + Context& operator=(const Context&) = delete; + Context& operator=(Context&&) = delete; + + public: + /** + * @brief Constructor + * + * @see @fn_gl{Get} with @def_gl{MAJOR_VERSION}, @def_gl{MINOR_VERSION}, + * @fn_gl{GetString} with @def_gl{EXTENSIONS} + */ + Context(); + ~Context(); + + /** @brief Current context */ + inline static Context* current() { return _current; } + + /** @brief OpenGL version */ + inline Version version() const { return _version; } + + /** @brief Major OpenGL version (e.g. `4`) */ + inline GLint majorVersion() const { return _majorVersion; } + + /** @brief Minor OpenGL version (e.g. `3`) */ + inline GLint minorVersion() const { return _minorVersion; } + + /** + * @brief Vendor string + * + * @see @fn_gl{GetString} with @def_gl{VENDOR} + */ + inline std::string vendorString() const { + return reinterpret_cast(glGetString(GL_VENDOR)); + } + + /** + * @brief Renderer string + * + * @see @fn_gl{GetString} with @def_gl{RENDERER} + */ + inline std::string rendererString() const { + return reinterpret_cast(glGetString(GL_RENDERER)); + } + + /** + * @brief Version string + * + * @see @fn_gl{GetString} with @def_gl{VERSION} + */ + inline std::string versionString() const { + return reinterpret_cast(glGetString(GL_VERSION)); + } + + /** + * @brief Shading language version string + * + * @see @fn_gl{GetString} with @def_gl{SHADING_LANGUAGE_VERSION} + */ + inline std::string shadingLanguageVersionString() const { + return reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); + } + + /** + * @brief Supported extensions + * + * The list contains only extensions from OpenGL versions newer than + * the current. + * + * @see isExtensionSupported(), Extension::extensions() + */ + inline const std::vector& supportedExtensions() const { + return _supportedExtensions; + } + + /** @brief Whether given OpenGL version is supported */ + inline bool isVersionSupported(Version version) const { + return _version >= version; + } + + /** + * @brief Whether given extension is supported + * + * %Extensions usable with this function are listed in Extensions + * namespace in header Extensions.h. Example usage: + * @code + * if(Context::current()->isExtensionSupported()) { + * // draw fancy detailed model + * } else { + * // texture fallback + * } + * @endcode + * + * @see isExtensionSupported(const Extension&) const + */ + template inline bool isExtensionSupported() const { + return _version >= T::coreVersion() || (_version >= T::requiredVersion() && extensionStatus[T::Index]); + } + + /** + * @brief Whether given extension is supported + * + * Can be used e.g. for listing extensions available on current + * hardware, but for general usage prefer isExtensionSupported() const, + * as it does most operations in compile time. + * + * @see supportedExtensions(), Extension::extensions() + */ + inline bool isExtensionSupported(const Extension& extension) const { + return _version >= extension._coreVersion || (_version >= extension._requiredVersion && extensionStatus[extension._index]); + } + + private: + static Context* _current; + + Version _version; + GLint _majorVersion; + GLint _minorVersion; + + std::bitset<128> extensionStatus; + std::vector _supportedExtensions; +}; + +} + +#endif diff --git a/src/Extensions.h b/src/Extensions.h new file mode 100644 index 000000000..44385b8be --- /dev/null +++ b/src/Extensions.h @@ -0,0 +1,141 @@ +#ifndef Magnum_Extensions_h +#define Magnum_Extensions_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Namespace Magnum::Extensions + */ + +#include "Context.h" + +namespace Magnum { + +/** +@brief Compile-time information about OpenGL extensions + +Each extension is `struct` named hierarchically by prefix, vendor and +extension name, for example `GL::APPLE::vertex_array_object`. Each struct has +the same public methods as Extension class (requiredVersion(), coreVersion() +and string(), but these structs are better suited for compile-time decisions +rather than Extension instances. See Context::isExtensionSupported() for +example usage. +*/ +namespace Extensions { + +#ifndef DOXYGEN_GENERATING_OUTPUT +#define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ + struct extension { \ + enum: size_t { Index = __LINE__-1 }; \ + constexpr static Version requiredVersion() { return Version::_requiredVersion; } \ + constexpr static Version coreVersion() { return Version::_coreVersion; } \ + constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \ + }; +namespace GL { + #line 1 + namespace APPLE { + _extension(GL,APPLE,flush_buffer_range, GL210, GL300) // #321 + _extension(GL,APPLE,vertex_array_object, GL210, GL300) // #273 + } namespace ARB { + _extension(GL,ARB,texture_rectangle, GL210, GL310) // #38 + _extension(GL,ARB,color_buffer_float, GL210, GL300) // #39 + _extension(GL,ARB,half_float_pixel, GL210, GL300) // #40 + _extension(GL,ARB,texture_float, GL210, GL300) // #41 + _extension(GL,ARB,depth_buffer_float, GL210, GL300) // #43 + _extension(GL,ARB,draw_instanced, GL210, GL310) // #44 + _extension(GL,ARB,geometry_shader4, GL210, GL320) // #47 + _extension(GL,ARB,instanced_arrays, GL210, GL330) // #49 + _extension(GL,ARB,texture_buffer_object, GL210, GL310) // #51 + _extension(GL,ARB,texture_rg, GL210, GL300) // #53 + _extension(GL,ARB,uniform_buffer_object, GL210, GL310) // #57 + _extension(GL,ARB,copy_buffer, /*?*/ GL210, GL310) // #59 + _extension(GL,ARB,depth_clamp, /*?*/ GL210, GL320) // #61 + _extension(GL,ARB,draw_elements_base_vertex, /*?*/ GL210, GL320) // #62 + _extension(GL,ARB,fragment_coord_conventions, /*?*/ GL210, GL320) // #63 + _extension(GL,ARB,provoking_vertex, /*?*/ GL210, GL320) // #64 + _extension(GL,ARB,seamless_cube_map, GL210, GL320) // #65 + _extension(GL,ARB,sync, GL310, GL320) // #66 + _extension(GL,ARB,texture_multisample, /*?*/ GL210, GL320) // #67 + _extension(GL,ARB,vertex_array_bgra, GL210, GL320) // #68 + _extension(GL,ARB,draw_buffers_blend, GL210, GL400) // #69 + _extension(GL,ARB,sample_shading, GL210, GL400) // #70 + _extension(GL,ARB,texture_cube_map_array, /*?*/ GL210, GL400) // #71 + _extension(GL,ARB,texture_gather, GL210, GL400) // #72 + _extension(GL,ARB,texture_query_lod, GL210, GL400) // #73 + _extension(GL,ARB,texture_compression_bptc, GL310, GL420) // #77 + _extension(GL,ARB,blend_func_extended, GL210, GL330) // #78 + _extension(GL,ARB,explicit_attrib_location, GL210, GL330) // #79 + _extension(GL,ARB,occlusion_query2, GL210, GL330) // #80 + _extension(GL,ARB,sampler_objects, GL210, GL330) // #81 + _extension(GL,ARB,shader_bit_encoding, /*?*/ GL210, GL330) // #82 + _extension(GL,ARB,texture_rgb10_a2ui, GL210, GL330) // #83 + _extension(GL,ARB,texture_swizzle, /*?*/ GL210, GL330) // #84 + _extension(GL,ARB,timer_query, /*?*/ GL210, GL330) // #85 + _extension(GL,ARB,vertex_type_2_10_10_10_rev, GL210, GL330) // #86 + _extension(GL,ARB,draw_indirect, GL310, GL400) // #87 + _extension(GL,ARB,gpu_shader5, GL320, GL400) // #88 + _extension(GL,ARB,gpu_shader_fp64, GL320, GL400) // #89 + _extension(GL,ARB,shader_subroutine, GL320, GL400) // #90 + _extension(GL,ARB,tessellation_shader, GL320, GL400) // #91 + _extension(GL,ARB,texture_buffer_object_rgb32, /*?*/ GL210, GL400) // #92 + _extension(GL,ARB,transform_feedback2, GL210, GL400) // #93 + _extension(GL,ARB,transform_feedback3, GL210, GL400) // #94 + _extension(GL,ARB,ES2_compatibility, /*?*/ GL210, GL410) // #95 + _extension(GL,ARB,get_program_binary, GL300, GL410) // #96 + _extension(GL,ARB,separate_shader_objects, GL210, GL410) // #97 + _extension(GL,ARB,shader_precision, GL400, GL410) // #98 + _extension(GL,ARB,vertex_attrib_64bit, GL300, GL410) // #99 + _extension(GL,ARB,viewport_array, GL210, GL410) // #100 + _extension(GL,ARB,base_instance, GL210, GL420) // #107 + _extension(GL,ARB,shading_language_420pack, GL300, GL420) // #108 + _extension(GL,ARB,transform_feedback_instanced, GL210, GL420) // #109 + _extension(GL,ARB,compressed_texture_pixel_storage, GL210, GL420) // #110 + _extension(GL,ARB,conservative_depth, GL300, GL420) // #111 + _extension(GL,ARB,internalformat_query, GL210, GL420) // #112 + _extension(GL,ARB,map_buffer_alignment, GL210, GL420) // #113 + _extension(GL,ARB,shader_atomic_counters, GL300, GL420) // #114 + _extension(GL,ARB,shader_image_load_store, GL300, GL420) // #115 + _extension(GL,ARB,texture_storage, GL210, GL420) // #117 + } namespace EXT { + _extension(GL,EXT,texture_filter_anisotropic, GL210, None) // #187 + _extension(GL,EXT,framebuffer_object, GL210, GL300) // #310 + _extension(GL,EXT,packed_depth_stencil, GL210, GL300) // #312 + _extension(GL,EXT,framebuffer_blit, GL210, GL300) // #316 + _extension(GL,EXT,framebuffer_multisample, GL210, GL300) // #317 + _extension(GL,EXT,gpu_shader4, GL210, GL300) // #326 + _extension(GL,EXT,packed_float, GL210, GL300) // #328 + _extension(GL,EXT,texture_array, GL210, GL300) // #329 + _extension(GL,EXT,texture_compression_rgtc, GL210, GL300) // #332 + _extension(GL,EXT,texture_shared_exponent, GL210, GL300) // #333 + _extension(GL,EXT,framebuffer_sRGB, GL210, GL300) // #337 + _extension(GL,EXT,draw_buffers2, GL210, GL300) // #340 + _extension(GL,EXT,texture_integer, GL210, GL300) // #343 + _extension(GL,EXT,transform_feedback, GL210, GL300) // #352 + _extension(GL,EXT,texture_snorm, GL300, GL310) // #365 + } namespace NV { + _extension(GL,NV,half_float, GL210, GL300) // #283 + _extension(GL,NV,primitive_restart, GL210, GL310) // #285 + _extension(GL,NV,depth_buffer_float, GL210, GL300) // #334 + _extension(GL,NV,conditional_render, GL210, GL300) // #346 + } +} +#undef _extension +#endif + +} + +} + +#endif From c2949d6b595dfdb432530a6ef426165083fae9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 10 Sep 2012 02:01:16 +0200 Subject: [PATCH 041/256] More Xlib workarounds... --- src/Contexts/GlxContext.cpp | 2 ++ src/Contexts/GlxContext.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/Contexts/GlxContext.cpp b/src/Contexts/GlxContext.cpp index 328edffd7..8d36d6f8a 100644 --- a/src/Contexts/GlxContext.cpp +++ b/src/Contexts/GlxContext.cpp @@ -18,6 +18,8 @@ #include #include +#define None 0L // redef Xlib nonsense + namespace Magnum { namespace Contexts { VisualID GlxContext::getVisualId(Display* nativeDisplay) { diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContext.h index 4f5cc775b..5612b3831 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContext.h @@ -21,6 +21,9 @@ #include "Magnum.h" #include +/* undef Xlib nonsense to avoid conflicts */ +#undef None +#undef Always #include "AbstractContext.h" From 13bb600c3e05802773fc180a834233be8af5da76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 10 Sep 2012 02:01:44 +0200 Subject: [PATCH 042/256] Creating Context instance in all *Context classes. The naming is now kinda schizofrenic, hope I come up with something better. --- src/Contexts/EglContext.cpp | 6 ++++++ src/Contexts/EglContext.h | 8 +++++++- src/Contexts/GlutWindowContext.cpp | 7 +++++++ src/Contexts/GlutWindowContext.h | 10 +++++++++- src/Contexts/GlxContext.cpp | 6 ++++++ src/Contexts/GlxContext.h | 8 +++++++- src/Contexts/Sdl2WindowContext.cpp | 6 ++++++ src/Contexts/Sdl2WindowContext.h | 8 +++++++- 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/Contexts/EglContext.cpp b/src/Contexts/EglContext.cpp index 323e880e1..96cb8dd4d 100644 --- a/src/Contexts/EglContext.cpp +++ b/src/Contexts/EglContext.cpp @@ -15,9 +15,13 @@ #include "EglContext.h" +#include "Context.h" + namespace Magnum { namespace Contexts { EglContext::~EglContext() { + delete c; + eglDestroyContext(display, context); eglDestroySurface(display, surface); eglTerminate(display); @@ -81,6 +85,8 @@ void EglContext::createContext(EGLNativeWindowType window) { } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ + + context = new Context; } }} diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index 0190fa299..f0e657690 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -28,7 +28,11 @@ #include "AbstractContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { #ifndef DOXYGEN_GENERATING_OUTPUT /* EGL returns visual ID as int, but Xorg expects long unsigned int */ @@ -64,6 +68,8 @@ class EglContext: public AbstractContext& size = Math::Vector2(800, 600)); + ~GlutWindowContext(); + inline int exec() { glutMainLoop(); return 0; @@ -246,6 +252,8 @@ class GlutWindowContext: public AbstractWindowContext { int& argc; char** argv; + + Context* c; }; /* Implementations for inline functions with unused parameters */ diff --git a/src/Contexts/GlxContext.cpp b/src/Contexts/GlxContext.cpp index 8d36d6f8a..76799d5e6 100644 --- a/src/Contexts/GlxContext.cpp +++ b/src/Contexts/GlxContext.cpp @@ -18,6 +18,8 @@ #include #include +#include "Context.h" + #define None 0L // redef Xlib nonsense namespace Magnum { namespace Contexts { @@ -83,9 +85,13 @@ void GlxContext::createContext(Window nativeWindow) { Error() << "GlxContext: cannot create context."; exit(1); } + + c = new Context; } GlxContext::~GlxContext() { + delete c; + glXMakeCurrent(display, None, nullptr); glXDestroyContext(display, context); } diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContext.h index 5612b3831..3c579ad03 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContext.h @@ -27,7 +27,11 @@ #include "AbstractContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { /** @brief GLX interface @@ -62,6 +66,8 @@ class GlxContext: public AbstractContext { Window window; GLXFBConfig* configs; GLXContext context; + + Context* c; }; }} diff --git a/src/Contexts/Sdl2WindowContext.cpp b/src/Contexts/Sdl2WindowContext.cpp index 8edc77190..2c2677bfc 100644 --- a/src/Contexts/Sdl2WindowContext.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -14,6 +14,8 @@ */ #include "Sdl2WindowContext.h" + +#include "Context.h" #include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { @@ -52,9 +54,13 @@ Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const sizeEvent->window.data1 = size.x(); sizeEvent->window.data2 = size.y(); SDL_PushEvent(sizeEvent); + + c = new Context; } Sdl2WindowContext::~Sdl2WindowContext() { + delete c; + SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index ca80ec681..c0d0f916d 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -27,7 +27,11 @@ #include "AbstractWindowContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { /** @nosubgrouping @brief SDL2 context @@ -179,6 +183,8 @@ class Sdl2WindowContext: public AbstractWindowContext { SDL_Window* window; SDL_GLContext context; + Context* c; + bool _redraw; }; From 4152e1fc9d1acc7859dc307d158ed68d4e4858dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 10 Sep 2012 02:37:07 +0200 Subject: [PATCH 043/256] Better ability to create portable shaders. Now the #version string is added from Shader class itself, making it possible to do workarounds for older versions more conveniently. As a consequence, #version must not be part of shader source anymore. --- src/AbstractShaderProgram.h | 4 ++-- src/Shader.cpp | 23 +++++++++++++++++++++++ src/Shader.h | 27 +++++++++++++++------------ src/Shaders/PhongShader.cpp | 4 ++-- src/Shaders/PhongShader.frag | 2 -- src/Shaders/PhongShader.vert | 2 -- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 831f6593b..8078c9e6f 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -66,8 +66,8 @@ static const GLint SpecularTextureUniform = 3; @code MyShader() { // Load shaders from file and attach them to the program - attachShader(Shader::fromFile(Shader::Type::Vertex, "PhongShader.vert")); - attachShader(Shader::fromFile(Shader::Type::Fragment, "PhongShader.frag")); + attachShader(Shader::fromFile(Version::430, Shader::Type::Vertex, "PhongShader.vert")); + attachShader(Shader::fromFile(Version::430, Shader::Type::Fragment, "PhongShader.frag")); // Link link(); diff --git a/src/Shader.cpp b/src/Shader.cpp index 2a6fe17f5..ea4004814 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -29,6 +29,29 @@ using namespace std; namespace Magnum { +Shader::Shader(Version version, Type type): _type(type), _state(State::Initialized), shader(0) { + shader = glCreateShader(static_cast(_type)); + + switch(version) { + #ifndef MAGNUM_TARGET_GLES + case Version::GL210: addSource("#version 120\n"); break; + case Version::GL300: addSource("#version 130\n"); break; + case Version::GL310: addSource("#version 140\n"); break; + case Version::GL320: addSource("#version 150\n"); break; + case Version::GL330: addSource("#version 330\n"); break; + case Version::GL400: addSource("#version 400\n"); break; + case Version::GL410: addSource("#version 410\n"); break; + case Version::GL420: addSource("#version 420\n"); break; + case Version::GL430: addSource("#version 430\n"); break; + #else + case Version::GLES200: addSource("#version 100\n"); break; + case Version::GLES300: addSource("#version 300\n"); break; + #endif + + default: break; + } +} + Shader::Shader(Shader&& other): _type(other._type), _state(other._state), sources(other.sources), shader(other.shader) { other.shader = 0; } diff --git a/src/Shader.h b/src/Shader.h index f25a50e19..7da337718 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -23,6 +23,7 @@ #include #include "Magnum.h" +#include "Context.h" #include "magnumVisibility.h" @@ -86,54 +87,56 @@ class MAGNUM_EXPORT Shader { /** * @brief Load shader from source + * @param version Target version * @param type %Shader type * @param source %Shader source * @return Shader instance * * Loads the shader from one source. Shorthand for * @code - * Shader s(type); + * Shader s(version, type); * s.addData(data); * @endcode * Note that it is also possible to create shader from more than one * source. */ - inline static Shader fromData(Type type, const std::string& source) { - Shader s(type); + inline static Shader fromData(Version version, Type type, const std::string& source) { + Shader s(version, type); s.addSource(source); return s; } /** * @brief Load shader from file + * @param version Target version * @param type %Shader type - * @param filename %Source filename + * @param filename Source filename * @return Shader instance * * Loads the shader from from one file. Shorthand for * @code - * Shader s(type); + * Shader s(version, type); * s.addFile(filename); * @endcode * Note that it is also possible to create shader from more than one * source. */ - inline static Shader fromFile(Type type, const char* filename) { - Shader s(type); + inline static Shader fromFile(Version version, Type type, const char* filename) { + Shader s(version, type); s.addFile(filename); return s; } /** * @brief Constructor + * @param version Target version + * @param type %Shader type * - * Creates empty OpenGL shader. Sources can be added with addSource() - * or addFile(). + * Creates empty OpenGL shader and adds @c \#version directive at the + * beginning. Sources can be added with addSource() or addFile(). * @see fromData(), fromFile(), @fn_gl{CreateShader} */ - inline Shader(Type type): _type(type), _state(State::Initialized), shader(0) { - shader = glCreateShader(static_cast(_type)); - } + Shader(Version version, Type type); /** * @brief Destructor diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index bf2ce456e..382648f2c 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -23,8 +23,8 @@ namespace Magnum { namespace Shaders { PhongShader::PhongShader() { Corrade::Utility::Resource rs("MagnumShaders"); - attachShader(Shader::fromData(Shader::Type::Vertex, rs.get("PhongShader.vert"))); - attachShader(Shader::fromData(Shader::Type::Fragment, rs.get("PhongShader.frag"))); + attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, rs.get("PhongShader.vert"))); + attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, rs.get("PhongShader.frag"))); link(); diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index 230af1736..16a100336 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -1,5 +1,3 @@ -#version 330 - uniform vec3 ambientColor = vec3(0.0, 0.0, 0.0); uniform vec3 diffuseColor; uniform vec3 specularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 19755516a..228cbad97 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -1,5 +1,3 @@ -#version 330 - uniform mat4 transformationMatrix; uniform mat4 projectionMatrix; uniform vec3 light; From 75d0505a60c942264d159f9185c75ead9af1198f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Sep 2012 00:11:40 +0200 Subject: [PATCH 044/256] Overflow test for large types in Math::normalize() started working. I don't know what caused that... :-) --- src/Math/Test/MathTest.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 862f1a15b..98b4c9034 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -73,12 +73,8 @@ void MathTest::denormalize() { CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - - { - CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); - } + CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); + CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); } void MathTest::clamp() { From 1cc13db704973da549ab911f76073fedca218cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Sep 2012 22:51:16 +0200 Subject: [PATCH 045/256] Timeline class. --- src/CMakeLists.txt | 2 + src/Timeline.cpp | 53 +++++++++++++++++++++++++++ src/Timeline.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/Timeline.cpp create mode 100644 src/Timeline.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 390eeb583..ade850775 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(Magnum_SRCS Renderbuffer.cpp Shader.cpp SizeTraits.cpp + Timeline.cpp TypeTraits.cpp Trade/AbstractImporter.cpp @@ -60,6 +61,7 @@ set(Magnum_HEADERS SizeTraits.h Swizzle.h Texture.h + Timeline.h TypeTraits.h magnumVisibility.h) diff --git a/src/Timeline.cpp b/src/Timeline.cpp new file mode 100644 index 000000000..306ce4ac7 --- /dev/null +++ b/src/Timeline.cpp @@ -0,0 +1,53 @@ +#include "Timeline.h" +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +using namespace std::chrono; +using namespace Corrade::Utility; + +namespace Magnum { + +void Timeline::start() { + running = true; + previousFrameTime = high_resolution_clock::now(); + _previousFrameDuration = 0; +} + +void Timeline::stop() { + running = false; + previousFrameTime = high_resolution_clock::time_point(); + _previousFrameDuration = 0; +} + +void Timeline::nextFrame() { + if(!running) return; + + auto now = high_resolution_clock::now(); + unsigned int duration = duration_cast(now-previousFrameTime).count(); + _previousFrameDuration = duration/1e6f; + + if(_previousFrameDuration < _minimalFrameTime) { + sleep(duration/1000); + now = high_resolution_clock::now(); + _previousFrameDuration = duration_cast(now-previousFrameTime).count()/1e6f; + } + + previousFrameTime = now; +} + +} diff --git a/src/Timeline.h b/src/Timeline.h new file mode 100644 index 000000000..093191677 --- /dev/null +++ b/src/Timeline.h @@ -0,0 +1,91 @@ +#ifndef Magnum_Timeline_h +#define Magnum_Timeline_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Magnum.h" + +#include "magnumVisibility.h" + +/** @file + * @brief Class Magnum::Timeline + */ + +namespace Magnum { + +/** @brief %Timeline */ +class MAGNUM_EXPORT Timeline { + public: + /** + * @brief Constructor + * + * Constructs stopped timeline. + * @see start() + */ + inline constexpr Timeline(): _minimalFrameTime(0), _previousFrameDuration(0), running(false) {} + + /** @brief Minimal frame time (in seconds) */ + GLfloat minimalFrameTime() const { return _minimalFrameTime; } + + /** + * @brief Set minimal frame time + * + * @see nextFrame() + */ + void setMinimalFrameTime(GLfloat seconds) { + _minimalFrameTime = seconds; + } + + /** + * @brief Start timeline + * + * Sets previous frame duration to `0`. + * @see stop(), previousFrameDuration() + */ + void start(); + + /** + * @brief Stop timeline + */ + void stop(); + + /** + * @brief Advance to next frame + * + * If current frame time is smaller than minimal frame time, pauses + * the execution for remaining time. + * @note This function does nothing if the timeline is stopped. + * @see setMinimalFrameTime() + */ + void nextFrame(); + + /** @brief Duration of previous frame */ + inline constexpr GLfloat previousFrameDuration() const { + return _previousFrameDuration; + } + + private: + std::chrono::high_resolution_clock::time_point previousFrameTime; + GLfloat _minimalFrameTime; + GLfloat _previousFrameDuration; + + bool running; +}; + +} + +#endif From 4927be44cf200a6f53b29272670dc1e0d0e5c254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Sep 2012 23:41:31 +0200 Subject: [PATCH 046/256] Context class must be instantiated after initializing extensions. --- src/Contexts/AbstractXWindowContext.cpp | 5 +++++ src/Contexts/AbstractXWindowContext.h | 8 +++++++- src/Contexts/EglContext.cpp | 4 ---- src/Contexts/EglContext.h | 8 +------- src/Contexts/GlxContext.cpp | 4 ---- src/Contexts/GlxContext.h | 8 +------- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Contexts/AbstractXWindowContext.cpp b/src/Contexts/AbstractXWindowContext.cpp index 061111f5d..b0087b4ad 100644 --- a/src/Contexts/AbstractXWindowContext.cpp +++ b/src/Contexts/AbstractXWindowContext.cpp @@ -15,6 +15,7 @@ #include "AbstractXWindowContext.h" +#include "Context.h" #include "ExtensionWrangler.h" #define None 0L // redef Xlib nonsense @@ -70,9 +71,13 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContextexperimentalExtensionWranglerFeatures()); + + c = new Context; } AbstractXWindowContext::~AbstractXWindowContext() { + delete c; + /* Shut down the interface */ delete glInterface; diff --git a/src/Contexts/AbstractXWindowContext.h b/src/Contexts/AbstractXWindowContext.h index c94eb34bd..6415cacfd 100644 --- a/src/Contexts/AbstractXWindowContext.h +++ b/src/Contexts/AbstractXWindowContext.h @@ -33,7 +33,11 @@ #include "AbstractWindowContext.h" #include "AbstractContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { /** @nosubgrouping @brief Base for X11-based contexts @@ -279,6 +283,8 @@ class AbstractXWindowContext: public AbstractWindowContext { AbstractContext* glInterface; + Context* c; + /** @todo Get this from the created window */ Math::Vector2 viewportSize; diff --git a/src/Contexts/EglContext.cpp b/src/Contexts/EglContext.cpp index 96cb8dd4d..fe9d7975d 100644 --- a/src/Contexts/EglContext.cpp +++ b/src/Contexts/EglContext.cpp @@ -20,8 +20,6 @@ namespace Magnum { namespace Contexts { EglContext::~EglContext() { - delete c; - eglDestroyContext(display, context); eglDestroySurface(display, surface); eglTerminate(display); @@ -85,8 +83,6 @@ void EglContext::createContext(EGLNativeWindowType window) { } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ - - context = new Context; } }} diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index f0e657690..0190fa299 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -28,11 +28,7 @@ #include "AbstractContext.h" -namespace Magnum { - -class Context; - -namespace Contexts { +namespace Magnum { namespace Contexts { #ifndef DOXYGEN_GENERATING_OUTPUT /* EGL returns visual ID as int, but Xorg expects long unsigned int */ @@ -68,8 +64,6 @@ class EglContext: public AbstractContext { Window window; GLXFBConfig* configs; GLXContext context; - - Context* c; }; }} From 5121d8ba998a07fa1402df85f5b72437aa415c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Sep 2012 23:51:02 +0200 Subject: [PATCH 047/256] Removed last trace of QtTest library. --- src/MeshTools/Test/TipsifyTest.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 40a2fbf6c..a44a26507 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -15,8 +15,6 @@ #include "TipsifyTest.h" -#include - #include "MeshTools/Tipsify.h" CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest) From e95c31720eec1647a35daa776c3fecc07db9a9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Sep 2012 23:56:03 +0200 Subject: [PATCH 048/256] GCC 4.6 compatibility of Extension class. It doesn't like const members, as std::vector doesn't have proper move semantic yet. --- src/Context.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Context.h b/src/Context.h index 1b9dd0b8d..f603889b1 100644 --- a/src/Context.h +++ b/src/Context.h @@ -74,10 +74,12 @@ class MAGNUM_EXPORT Extension { inline constexpr const char* string() const { return _string; } private: - const size_t _index; - const Version _requiredVersion; - const Version _coreVersion; - const char* const _string; + /* GCC 4.6 doesn't like const members, as std::vector doesn't have + proper move semantic yet */ + size_t _index; + Version _requiredVersion; + Version _coreVersion; + const char* _string; inline constexpr Extension(size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} }; From 3d778855559223da15928e46438ac2ba3bbc3944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 00:00:41 +0200 Subject: [PATCH 049/256] Revert "Overflow test for large types in Math::normalize() started working." It was working because of some weird state of my build dir, expecting fail again. This reverts commit 75d0505a60c942264d159f9185c75ead9af1198f. --- src/Math/Test/MathTest.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 98b4c9034..862f1a15b 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -73,8 +73,12 @@ void MathTest::denormalize() { CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); + + { + CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); + CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); + CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); + } } void MathTest::clamp() { From fa774370aa50cd9ea8e376c83fab0be03af3021b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 00:04:32 +0200 Subject: [PATCH 050/256] GCC 4.6 doesn't support template aliases. --- src/Test/SwizzleTest.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 299603280..00be3d7ea 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -27,8 +27,6 @@ typedef Math::Vector2 Vector2; typedef Math::Vector3 Vector3; typedef Math::Vector4 Vector4; -template using Vector = Math::Vector; - SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::xyzw, &SwizzleTest::rgba, @@ -81,10 +79,10 @@ void SwizzleTest::type() { void SwizzleTest::defaultType() { Vector4 orig(1, 2, 3, 4); - CORRADE_COMPARE(swizzle<'b'>(orig), Vector<1>(3)); - CORRADE_COMPARE(swizzle(orig, "b"), Vector<1>(3)); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), Vector<7>(3, 1, 4, 2, 3, 2, 1)); - CORRADE_COMPARE(swizzle(orig, "bragzyx"), Vector<7>(3, 1, 4, 2, 3, 2, 1)); + CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int>(3))); + CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int>(3))); + CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); } }} From ad19b2734bce9f3eb7686e72d7da98593bafc34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 00:22:19 +0200 Subject: [PATCH 051/256] More renaming: Context -> WindowContext. --- CMakeLists.txt | 8 +++---- src/Contexts/CMakeLists.txt | 44 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d40938c9f..bb3f414e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,10 +15,10 @@ option(WITH_PRIMITIVES "Builf Primitives library" OFF) option(WITH_SCENEGRAPH "Build SceneGraph library" OFF) option(WITH_SHADERS "Build Shaders library" OFF) -option(WITH_GLXCONTEXT "Build GlxContext library" OFF) -cmake_dependent_option(WITH_XEGLCONTEXT "Build XEglContext library" OFF "TARGET_GLES" OFF) -cmake_dependent_option(WITH_GLUTCONTEXT "Build GlutContext library" OFF "NOT TARGET_GLES" OFF) -option(WITH_SDL2CONTEXT "Build Sdl2Context library" OFF) +option(WITH_GLXWINDOWCONTEXT "Build GlxWindowContext library" OFF) +cmake_dependent_option(WITH_XEGLWINDOWCONTEXT "Build XEglWindowContext library" OFF "TARGET_GLES" OFF) +cmake_dependent_option(WITH_GLUTWINDOWCONTEXT "Build GlutWindowContext library" OFF "NOT TARGET_GLES" OFF) +option(WITH_SDL2WINDOWCONTEXT "Build Sdl2WindowContext library" OFF) option(BUILD_TESTS "Build unit tests." OFF) diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index 715bb4e5a..85b27204c 100644 --- a/src/Contexts/CMakeLists.txt +++ b/src/Contexts/CMakeLists.txt @@ -7,8 +7,8 @@ set(MagnumContexts_HEADERS ExtensionWrangler.h) install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) -# GLUT context -if(WITH_GLUTCONTEXT) +# GLUT window context +if(WITH_GLUTWINDOWCONTEXT) find_package(GLUT) if(GLUT_FOUND) add_library(MagnumGlutWindowContext STATIC @@ -17,12 +17,12 @@ if(WITH_GLUTCONTEXT) install(FILES GlutWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumGlutWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "GLUT library, required by GlutWindowContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.") + message(FATAL_ERROR "GLUT library, required by GlutWindowContext, was not found. Set WITH_GLUTWINDOWCONTEXT to OFF to skip building it.") endif() endif() -# SDL2 context -if(WITH_SDL2CONTEXT) +# SDL2 window context +if(WITH_SDL2WINDOWCONTEXT) find_package(SDL2) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) @@ -32,14 +32,14 @@ if(WITH_SDL2CONTEXT) install(FILES Sdl2WindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumSdl2WindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "SDL2 library, required by Sdl2WindowContext, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.") + message(FATAL_ERROR "SDL2 library, required by Sdl2WindowContext, was not found. Set WITH_SDL2WINDOWCONTEXT to OFF to skip building it.") endif() endif() -# GLX context -if(WITH_GLXCONTEXT) - set(NEED_ABSTRACTXCONTEXT 1) - set(NEED_GLXINTERFACE 1) +# GLX window context +if(WITH_GLXWINDOWCONTEXT) + set(NEED_ABSTRACTXWINDOWCONTEXT 1) + set(NEED_GLXCONTEXT 1) add_library(MagnumGlxWindowContext STATIC $ $ @@ -48,10 +48,10 @@ if(WITH_GLXCONTEXT) install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() -# X/EGL context -if(WITH_XEGLCONTEXT) - set(NEED_ABSTRACTXCONTEXT 1) - set(NEED_EGLINTERFACE 1) +# X/EGL window context +if(WITH_XEGLWINDOWCONTEXT) + set(NEED_ABSTRACTXWINDOWCONTEXT 1) + set(NEED_EGLCONTEXT 1) add_library(MagnumXEglWindowContext STATIC $ $ @@ -60,11 +60,11 @@ if(WITH_XEGLCONTEXT) install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() -# Abstract X context -if(NEED_ABSTRACTXCONTEXT) +# Abstract X window context +if(NEED_ABSTRACTXWINDOWCONTEXT) find_package(X11) if(NOT X11_FOUND) - message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*CONTEXT to OFF to skip building them.") + message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*WINDOWCONTEXT to OFF to skip building them.") endif() add_library(MagnumAbstractXWindowContext OBJECT AbstractXWindowContext.cpp) # X11 macros are a mess, disable warnings for C-style casts @@ -72,19 +72,19 @@ if(NEED_ABSTRACTXCONTEXT) install(FILES AbstractXWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() -# GLX interface -if(NEED_GLXINTERFACE) +# GLX window context +if(NEED_GLXCONTEXT) add_library(MagnumGlxContext OBJECT GlxContext.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() -# EGL interface -if(NEED_EGLINTERFACE) +# EGL context +if(NEED_EGLCONTEXT) find_package(EGL) if(NOT EGL_FOUND) - message(FATAL_ERROR "EGL library, required by some contexts, was not found. Set WITH_*EGL*CONTEXT to OFF to skip building them.") + message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*WINDOWCONTEXT to OFF to skip building them.") endif() add_library(MagnumEglContext OBJECT EglContext.cpp) # X11 macros are a mess, disable warnings for C-style casts From 07df630b24c924ed68d37b39976cc11e990bdd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 00:23:32 +0200 Subject: [PATCH 052/256] Modified Sdl2WindowContext for source compatibility with others. Stripped off key repeat and separate function for mouse wheel handling. --- src/Contexts/Sdl2WindowContext.cpp | 14 +++---- src/Contexts/Sdl2WindowContext.h | 62 ++++++++++++++++++------------ 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/Contexts/Sdl2WindowContext.cpp b/src/Contexts/Sdl2WindowContext.cpp index 2c2677bfc..905ef61da 100644 --- a/src/Contexts/Sdl2WindowContext.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -83,23 +83,23 @@ int Sdl2WindowContext::exec() { break; } break; case SDL_KEYDOWN: - keyPressEvent(static_cast(event.key.keysym.sym), event.key.repeat); + keyPressEvent(static_cast(event.key.keysym.sym), Modifiers(), {}); break; case SDL_KEYUP: - keyReleaseEvent(static_cast(event.key.keysym.sym)); + keyReleaseEvent(static_cast(event.key.keysym.sym), Modifiers(), {}); break; case SDL_MOUSEBUTTONDOWN: - mousePressEvent(static_cast(event.button.button), {event.button.x, event.button.y}); + mousePressEvent(static_cast(event.button.button), Modifiers(), {event.button.x, event.button.y}); break; case SDL_MOUSEBUTTONUP: - mouseReleaseEvent(static_cast(event.button.button), {event.button.x, event.button.y}); + mouseReleaseEvent(static_cast(event.button.button), Modifiers(), {event.button.x, event.button.y}); break; case SDL_MOUSEWHEEL: - mouseWheelEvent({event.wheel.x, event.wheel.y}); + if(event.wheel.y != 0) + mousePressEvent(event.wheel.y < 0 ? MouseButton::WheelUp : MouseButton::WheelDown, Modifiers(), {event.wheel.x, event.wheel.y}); break; case SDL_MOUSEMOTION: - mouseMotionEvent({event.motion.x, event.motion.y}, - {event.motion.xrel, event.motion.yrel}); + mouseMotionEvent(Modifiers(), {event.motion.x, event.motion.y}); break; case SDL_QUIT: return 0; diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index c0d0f916d..3117270c9 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -24,6 +24,7 @@ #include #include +#include #include "AbstractWindowContext.h" @@ -83,6 +84,21 @@ class Sdl2WindowContext: public AbstractWindowContext { /** @{ @name Keyboard handling */ public: + /** + * @brief %Modifier + * + * @see Modifiers, keyPressEvent(), keyReleaseEvent(), + * mousePressEvent(), mouseReleaseEvent(), mouseMotionEvent() + */ + enum class Modifier: unsigned int {}; + + /** + * @brief Set of modifiers + * + * @see keyPressEvent(), keyReleaseEvent() + */ + typedef Corrade::Containers::EnumSet Modifiers; + /** * @brief Key * @@ -101,15 +117,18 @@ class Sdl2WindowContext: public AbstractWindowContext { /** * @brief Key press event * @param key Key pressed - * @param repeat Non-zero if this is a key repeat + * @param modifiers Active modifiers (not yet implemented) + * @param position Cursor position (not yet implemented) */ - virtual void keyPressEvent(Key key, Uint8 repeat); + virtual void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /** * @brief Key release event * @param key Key released + * @param modifiers Active modifiers (not yet implemented) + * @param position Cursor position (not yet implemented) */ - virtual void keyReleaseEvent(Key key); + virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -124,7 +143,9 @@ class Sdl2WindowContext: public AbstractWindowContext { enum class MouseButton: Uint8 { Left = SDL_BUTTON_LEFT, /**< Left button */ Middle = SDL_BUTTON_MIDDLE, /**< Middle button */ - Right = SDL_BUTTON_RIGHT /**< Right button */ + Right = SDL_BUTTON_RIGHT, /**< Right button */ + WheelUp = 4, /**< Wheel up */ + WheelDown = 5 /**< Wheel down */ }; /** @@ -141,41 +162,33 @@ class Sdl2WindowContext: public AbstractWindowContext { /** * @brief Mouse press event * @param button Button pressed + * @param modifiers Active modifiers (not yet implemented) * @param position Cursor position * * Called when mouse button is pressed. Default implementation does * nothing. */ - virtual void mousePressEvent(MouseButton button, const Math::Vector2& position); + virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); /** * @brief Mouse release event * @param button Button released + * @param modifiers Active modifiers (not yet implemented) * @param position Cursor position * * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); - - /** - * @brief Mouse wheel event - * @param direction Wheel rotation direction. Negative Y is up and - * positive X is right. - * - * Called when mouse wheel is rotated. Default implementation does - * nothing. - */ - virtual void mouseWheelEvent(const Math::Vector2& direction); + virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); /** * @brief Mouse motion event + * @param modifiers Active modifiers (not yet implemented) * @param position Mouse position relative to the window - * @param delta Mouse position relative to last motion event * * Called when mouse is moved. Default implementation does nothing. */ - virtual void mouseMotionEvent(const Math::Vector2& position, const Math::Vector2& delta); + virtual void mouseMotionEvent(Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -188,13 +201,14 @@ class Sdl2WindowContext: public AbstractWindowContext { bool _redraw; }; +CORRADE_ENUMSET_OPERATORS(Sdl2WindowContext::Modifiers) + /* Implementations for inline functions with unused parameters */ -inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {} -inline void Sdl2WindowContext::keyReleaseEvent(Key) {} -inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} }} From 141b20a612565bf83d8be65ea2c81fc458de60a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 00:55:02 +0200 Subject: [PATCH 053/256] Renamed Contexts::*Context to *ContextHandler. Finally (and hopefully) consistent and non-confusing naming. --- ...tractContext.h => AbstractContextHandler.h} | 16 ++++++++-------- src/Contexts/AbstractXWindowContext.cpp | 14 +++++++------- src/Contexts/AbstractXWindowContext.h | 10 +++++----- src/Contexts/CMakeLists.txt | 18 +++++++++--------- .../{EglContext.cpp => EglContextHandler.cpp} | 8 ++++---- .../{EglContext.h => EglContextHandler.h} | 12 ++++++------ .../{GlxContext.cpp => GlxContextHandler.cpp} | 14 +++++++------- .../{GlxContext.h => GlxContextHandler.h} | 12 ++++++------ src/Contexts/GlxWindowContext.h | 6 +++--- src/Contexts/XEglWindowContext.h | 6 +++--- 10 files changed, 58 insertions(+), 58 deletions(-) rename src/Contexts/{AbstractContext.h => AbstractContextHandler.h} (79%) rename src/Contexts/{EglContext.cpp => EglContextHandler.cpp} (91%) rename src/Contexts/{EglContext.h => EglContextHandler.h} (82%) rename src/Contexts/{GlxContext.cpp => GlxContextHandler.cpp} (85%) rename src/Contexts/{GlxContext.h => GlxContextHandler.h} (84%) diff --git a/src/Contexts/AbstractContext.h b/src/Contexts/AbstractContextHandler.h similarity index 79% rename from src/Contexts/AbstractContext.h rename to src/Contexts/AbstractContextHandler.h index 93aeb121e..ba73aa940 100644 --- a/src/Contexts/AbstractContext.h +++ b/src/Contexts/AbstractContextHandler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_AbstractContext_h -#define Magnum_Contexts_AbstractContext_h +#ifndef Magnum_Contexts_AbstractContextHandler_h +#define Magnum_Contexts_AbstractContextHandler_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,29 +16,29 @@ */ /** @file - * @brief Class Magnum::Contexts::AbstractContext + * @brief Class Magnum::Contexts::AbstractContextHandler */ #include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { -/** @brief Base for OpenGL contexts */ -template class AbstractContext { +/** @brief Base for OpenGL context handlers */ +template class AbstractContextHandler { public: /** * @brief Get visual ID * - * Initializes the interface on given display and returns visual ID. + * Initializes the handler on given display and returns visual ID. */ virtual VisualId getVisualId(Display nativeDisplay) = 0; /** * @brief Destructor * - * Finalizes and closes the interface. + * Finalizes and closes the handler. */ - virtual ~AbstractContext() {} + virtual ~AbstractContextHandler() {} /** @brief Create context */ virtual void createContext(Window nativeWindow) = 0; diff --git a/src/Contexts/AbstractXWindowContext.cpp b/src/Contexts/AbstractXWindowContext.cpp index b0087b4ad..0fbb95a9e 100644 --- a/src/Contexts/AbstractXWindowContext.cpp +++ b/src/Contexts/AbstractXWindowContext.cpp @@ -27,12 +27,12 @@ using namespace std; namespace Magnum { namespace Contexts { -AbstractXWindowContext::AbstractXWindowContext(AbstractContext* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { +AbstractXWindowContext::AbstractXWindowContext(AbstractContextHandler* contextHandler, int&, char**, const string& title, const Math::Vector2& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); /* Get visual ID */ - VisualID visualId = glInterface->getVisualId(display); + VisualID visualId = contextHandler->getVisualId(display); /* Get visual info */ XVisualInfo *visInfo, visTemplate; @@ -61,16 +61,16 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContextcreateContext(window); + contextHandler->createContext(window); /* Capture exposure, keyboard and mouse button events */ XSelectInput(display, window, INPUT_MASK); /* Set OpenGL context as current */ - glInterface->makeCurrent(); + contextHandler->makeCurrent(); /* Initialize extension wrangler */ - ExtensionWrangler::initialize(glInterface->experimentalExtensionWranglerFeatures()); + ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures()); c = new Context; } @@ -78,8 +78,8 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContext* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); + AbstractXWindowContext(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); /** * @brief Destructor @@ -82,7 +82,7 @@ class AbstractXWindowContext: public AbstractWindowContext { virtual void drawEvent() = 0; /** @copydoc GlutWindowContext::swapBuffers() */ - inline void swapBuffers() { glInterface->swapBuffers(); } + inline void swapBuffers() { contextHandler->swapBuffers(); } /** @copydoc GlutWindowContext::redraw() */ inline void redraw() { flags |= Flag::Redraw; } @@ -281,7 +281,7 @@ class AbstractXWindowContext: public AbstractWindowContext { Window window; Atom deleteWindow; - AbstractContext* glInterface; + AbstractContextHandler* contextHandler; Context* c; diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index 85b27204c..7a3fd095f 100644 --- a/src/Contexts/CMakeLists.txt +++ b/src/Contexts/CMakeLists.txt @@ -2,7 +2,7 @@ add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp) set(MagnumContexts_HEADERS - AbstractContext.h + AbstractContextHandler.h AbstractWindowContext.h ExtensionWrangler.h) install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) @@ -42,7 +42,7 @@ if(WITH_GLXWINDOWCONTEXT) set(NEED_GLXCONTEXT 1) add_library(MagnumGlxWindowContext STATIC $ - $ + $ $) install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) @@ -54,7 +54,7 @@ if(WITH_XEGLWINDOWCONTEXT) set(NEED_EGLCONTEXT 1) add_library(MagnumXEglWindowContext STATIC $ - $ + $ $) install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) @@ -74,10 +74,10 @@ endif() # GLX window context if(NEED_GLXCONTEXT) - add_library(MagnumGlxContext OBJECT GlxContext.cpp) + add_library(MagnumGlxContextHandler OBJECT GlxContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + set_target_properties(MagnumGlxContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES GlxContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() # EGL context @@ -86,8 +86,8 @@ if(NEED_EGLCONTEXT) if(NOT EGL_FOUND) message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*WINDOWCONTEXT to OFF to skip building them.") endif() - add_library(MagnumEglContext OBJECT EglContext.cpp) + add_library(MagnumEglContextHandler OBJECT EglContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts - set_target_properties(MagnumEglContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) + set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES EglContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() diff --git a/src/Contexts/EglContext.cpp b/src/Contexts/EglContextHandler.cpp similarity index 91% rename from src/Contexts/EglContext.cpp rename to src/Contexts/EglContextHandler.cpp index fe9d7975d..c21b1ecf7 100644 --- a/src/Contexts/EglContext.cpp +++ b/src/Contexts/EglContextHandler.cpp @@ -13,19 +13,19 @@ GNU Lesser General Public License version 3 for more details. */ -#include "EglContext.h" +#include "EglContextHandler.h" #include "Context.h" namespace Magnum { namespace Contexts { -EglContext::~EglContext() { +EglContextHandler::~EglContextHandler() { eglDestroyContext(display, context); eglDestroySurface(display, surface); eglTerminate(display); } -VisualId EglContext::getVisualId(EGLNativeDisplayType nativeDisplay) { +VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Initialize */ display = eglGetDisplay(nativeDisplay); eglInitialize(display, 0, 0); @@ -64,7 +64,7 @@ VisualId EglContext::getVisualId(EGLNativeDisplayType nativeDisplay) { return visualId; } -void EglContext::createContext(EGLNativeWindowType window) { +void EglContextHandler::createContext(EGLNativeWindowType window) { static const EGLint contextAttributes[] = { #ifdef MAGNUM_TARGET_GLES EGL_CONTEXT_CLIENT_VERSION, 2, diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContextHandler.h similarity index 82% rename from src/Contexts/EglContext.h rename to src/Contexts/EglContextHandler.h index 0190fa299..824aa0177 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContextHandler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_EglContext_h -#define Magnum_Contexts_EglContext_h +#ifndef Magnum_Contexts_EglContextHandler_h +#define Magnum_Contexts_EglContextHandler_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::EglContext + * @brief Class Magnum::Contexts::EglContextHandler */ #include "Magnum.h" @@ -26,7 +26,7 @@ #endif #include -#include "AbstractContext.h" +#include "AbstractContextHandler.h" namespace Magnum { namespace Contexts { @@ -44,9 +44,9 @@ typedef EGLInt VisualId; Used in XEglWindowContext. */ -class EglContext: public AbstractContext { +class EglContextHandler: public AbstractContextHandler { public: - ~EglContext(); + ~EglContextHandler(); VisualId getVisualId(EGLNativeDisplayType nativeDisplay); void createContext(EGLNativeWindowType nativeWindow); diff --git a/src/Contexts/GlxContext.cpp b/src/Contexts/GlxContextHandler.cpp similarity index 85% rename from src/Contexts/GlxContext.cpp rename to src/Contexts/GlxContextHandler.cpp index 3f5ada4ac..81fc2ccdd 100644 --- a/src/Contexts/GlxContext.cpp +++ b/src/Contexts/GlxContextHandler.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GlxContext.h" +#include "GlxContextHandler.h" #include #include @@ -24,14 +24,14 @@ namespace Magnum { namespace Contexts { -VisualID GlxContext::getVisualId(Display* nativeDisplay) { +VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) { display = nativeDisplay; /* Check version */ int major, minor; glXQueryVersion(nativeDisplay, &major, &minor); if(major == 1 && minor < 4) { - Error() << "GlxContext: GLX version 1.4 or greater is required."; + Error() << "GlxContextHandler: GLX version 1.4 or greater is required."; exit(1); } @@ -49,7 +49,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) { }; configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount); if(!configCount) { - Error() << "GlxContext: no supported framebuffer configuration found."; + Error() << "GlxContextHandler: no supported framebuffer configuration found."; exit(1); } @@ -61,7 +61,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) { return visualId; } -void GlxContext::createContext(Window nativeWindow) { +void GlxContextHandler::createContext(Window nativeWindow) { window = nativeWindow; GLint attributes[] = { @@ -82,12 +82,12 @@ void GlxContext::createContext(Window nativeWindow) { context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes); XFree(configs); if(!context) { - Error() << "GlxContext: cannot create context."; + Error() << "GlxContextHandler: cannot create context."; exit(1); } } -GlxContext::~GlxContext() { +GlxContextHandler::~GlxContextHandler() { glXMakeCurrent(display, None, nullptr); glXDestroyContext(display, context); } diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContextHandler.h similarity index 84% rename from src/Contexts/GlxContext.h rename to src/Contexts/GlxContextHandler.h index 5612b3831..52f4b8229 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContextHandler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Contexts_GlxContext_h -#define Magnum_Contexts_GlxContext_h +#ifndef Magnum_Contexts_GlxContextHandler_h +#define Magnum_Contexts_GlxContextHandler_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::GlxContext + * @brief Class Magnum::Contexts::GlxContextHandler */ #include "Magnum.h" @@ -25,7 +25,7 @@ #undef None #undef Always -#include "AbstractContext.h" +#include "AbstractContextHandler.h" namespace Magnum { namespace Contexts { @@ -37,9 +37,9 @@ OpenGL ES. Used in GlxWindowContext. */ -class GlxContext: public AbstractContext { +class GlxContextHandler: public AbstractContextHandler { public: - ~GlxContext(); + ~GlxContextHandler(); VisualID getVisualId(Display* nativeDisplay); void createContext(Window nativeWindow); diff --git a/src/Contexts/GlxWindowContext.h b/src/Contexts/GlxWindowContext.h index 65f68da50..4813b7d02 100644 --- a/src/Contexts/GlxWindowContext.h +++ b/src/Contexts/GlxWindowContext.h @@ -20,14 +20,14 @@ */ #include "AbstractXWindowContext.h" -#include "GlxContext.h" +#include "GlxContextHandler.h" namespace Magnum { namespace Contexts { /** @brief GLX context -Uses GlxContext. +Uses GlxContextHandler. */ class GlxWindowContext: public AbstractXWindowContext { public: @@ -41,7 +41,7 @@ class GlxWindowContext: public AbstractXWindowContext { * Creates window with double-buffered OpenGL 3.3 core context or * OpenGL ES 2.0 context, if targetting OpenGL ES. */ - inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContext, argc, argv, title, size) {} + inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Contexts/XEglWindowContext.h b/src/Contexts/XEglWindowContext.h index 131c5498c..1f5edcc41 100644 --- a/src/Contexts/XEglWindowContext.h +++ b/src/Contexts/XEglWindowContext.h @@ -20,14 +20,14 @@ */ #include "AbstractXWindowContext.h" -#include "EglContext.h" +#include "EglContextHandler.h" namespace Magnum { namespace Contexts { /** @brief X/EGL context -Uses EglContext. +Uses EglContextHandler. */ class XEglWindowContext: public AbstractXWindowContext { public: @@ -40,7 +40,7 @@ class XEglWindowContext: public AbstractXWindowContext { * * Creates window with double-buffered OpenGL ES 2 context. */ - inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContext, argc, argv, title, size) {} + inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContextHandler, argc, argv, title, size) {} }; }} From 11823f66006f4e0686e39544492c5569b47ac8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 01:20:38 +0200 Subject: [PATCH 054/256] Context: use glGetString(GL_EXTENSIONS) on GL 2.1. glGetStringi() is since GL 3.0. --- src/Context.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index bb484f8dc..f6bdfd1ad 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -165,13 +165,26 @@ Context::Context() { futureExtensions.insert(make_pair(extension._string, extension)); /* Check for presence of extensions in future versions */ - GLuint index = 0; - const char* extension; - while((extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, index++)))) { - auto found = futureExtensions.find(extension); - if(found != futureExtensions.end()) { - _supportedExtensions.push_back(found->second); - extensionStatus.set(found->second._index); + if(isVersionSupported(Version::GL300)) { + GLuint index = 0; + const char* extension; + while((extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, index++)))) { + auto found = futureExtensions.find(extension); + if(found != futureExtensions.end()) { + _supportedExtensions.push_back(found->second); + extensionStatus.set(found->second._index); + } + } + + /* OpenGL 2.1 doesn't have glGetStringi() */ + } else { + vector extensions = Corrade::Utility::split(reinterpret_cast(glGetString(GL_EXTENSIONS)), ' '); + for(const string& extension: extensions) { + auto found = futureExtensions.find(extension); + if(found != futureExtensions.end()) { + _supportedExtensions.push_back(found->second); + extensionStatus.set(found->second._index); + } } } From 0646a6a12e928a4c688f878c3a7cda1c73d482de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 01:45:30 +0200 Subject: [PATCH 055/256] Contexts: updated default window names. --- src/Contexts/AbstractXWindowContext.h | 2 +- src/Contexts/GlutWindowContext.h | 2 +- src/Contexts/GlxWindowContext.h | 2 +- src/Contexts/Sdl2WindowContext.h | 2 +- src/Contexts/XEglWindowContext.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Contexts/AbstractXWindowContext.h b/src/Contexts/AbstractXWindowContext.h index 3654c255a..75e8eccd2 100644 --- a/src/Contexts/AbstractXWindowContext.h +++ b/src/Contexts/AbstractXWindowContext.h @@ -58,7 +58,7 @@ class AbstractXWindowContext: public AbstractWindowContext { * * Creates window with double-buffered OpenGL ES 2 context. */ - AbstractXWindowContext(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); + AbstractXWindowContext(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X window context", const Math::Vector2& size = Math::Vector2(800, 600)); /** * @brief Destructor diff --git a/src/Contexts/GlutWindowContext.h b/src/Contexts/GlutWindowContext.h index a96e71b7c..f4dff7120 100644 --- a/src/Contexts/GlutWindowContext.h +++ b/src/Contexts/GlutWindowContext.h @@ -54,7 +54,7 @@ class GlutWindowContext: public AbstractWindowContext { * * Creates double-buffered RGBA window with depth and stencil buffers. */ - GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2& size = Math::Vector2(800, 600)); + GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT window context", const Math::Vector2& size = Math::Vector2(800, 600)); ~GlutWindowContext(); diff --git a/src/Contexts/GlxWindowContext.h b/src/Contexts/GlxWindowContext.h index 4813b7d02..df3661af8 100644 --- a/src/Contexts/GlxWindowContext.h +++ b/src/Contexts/GlxWindowContext.h @@ -41,7 +41,7 @@ class GlxWindowContext: public AbstractXWindowContext { * Creates window with double-buffered OpenGL 3.3 core context or * OpenGL ES 2.0 context, if targetting OpenGL ES. */ - inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContextHandler, argc, argv, title, size) {} + inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX window context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index 3117270c9..19c2cc1d6 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -54,7 +54,7 @@ class Sdl2WindowContext: public AbstractWindowContext { * Creates centered non-resizable window with double-buffered * OpenGL 3.3 context with 24bit depth buffer. */ - Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2& size = Math::Vector2(800, 600)); + Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 window context", const Math::Vector2& size = Math::Vector2(800, 600)); /** * @brief Destructor diff --git a/src/Contexts/XEglWindowContext.h b/src/Contexts/XEglWindowContext.h index 1f5edcc41..94f0ac034 100644 --- a/src/Contexts/XEglWindowContext.h +++ b/src/Contexts/XEglWindowContext.h @@ -40,7 +40,7 @@ class XEglWindowContext: public AbstractXWindowContext { * * Creates window with double-buffered OpenGL ES 2 context. */ - inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContextHandler, argc, argv, title, size) {} + inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL window context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContextHandler, argc, argv, title, size) {} }; }} From 2c0b75df8b9f199756f8f1beff99e156c2bb3615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 01:46:01 +0200 Subject: [PATCH 056/256] Request OpenGL 3.2 rather than 3.3. Not all 3.x drivers have the latest version, even if it is five years old. --- src/Contexts/GlxContextHandler.cpp | 2 +- src/Contexts/GlxContextHandler.h | 2 +- src/Contexts/GlxWindowContext.h | 2 +- src/Contexts/Sdl2WindowContext.cpp | 4 ++-- src/Contexts/Sdl2WindowContext.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Contexts/GlxContextHandler.cpp b/src/Contexts/GlxContextHandler.cpp index 81fc2ccdd..ebc478b6c 100644 --- a/src/Contexts/GlxContextHandler.cpp +++ b/src/Contexts/GlxContextHandler.cpp @@ -67,7 +67,7 @@ void GlxContextHandler::createContext(Window nativeWindow) { GLint attributes[] = { #ifndef MAGNUM_TARGET_GLES GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 2, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, #else GLX_CONTEXT_MAJOR_VERSION_ARB, 2, diff --git a/src/Contexts/GlxContextHandler.h b/src/Contexts/GlxContextHandler.h index 52f4b8229..671a3e11e 100644 --- a/src/Contexts/GlxContextHandler.h +++ b/src/Contexts/GlxContextHandler.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Contexts { /** @brief GLX interface -Creates OpenGL 3.3 core context or OpenGL ES 2.0 context, if targetting +Creates OpenGL 3.2 core context or OpenGL ES 2.0 context, if targetting OpenGL ES. Used in GlxWindowContext. diff --git a/src/Contexts/GlxWindowContext.h b/src/Contexts/GlxWindowContext.h index df3661af8..f69f6f7d7 100644 --- a/src/Contexts/GlxWindowContext.h +++ b/src/Contexts/GlxWindowContext.h @@ -38,7 +38,7 @@ class GlxWindowContext: public AbstractXWindowContext { * @param title Window title * @param size Window size * - * Creates window with double-buffered OpenGL 3.3 core context or + * Creates window with double-buffered OpenGL 3.2 core context or * OpenGL ES 2.0 context, if targetting OpenGL ES. */ inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX window context", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContextHandler, argc, argv, title, size) {} diff --git a/src/Contexts/Sdl2WindowContext.cpp b/src/Contexts/Sdl2WindowContext.cpp index 905ef61da..f87e33b06 100644 --- a/src/Contexts/Sdl2WindowContext.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -26,9 +26,9 @@ Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const exit(1); } - /* Request OpenGL 3.3 */ + /* Request OpenGL 3.2 */ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); /* Enable double buffering and 24bt depth buffer */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index 19c2cc1d6..49a392564 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -52,7 +52,7 @@ class Sdl2WindowContext: public AbstractWindowContext { * @param size Window size * * Creates centered non-resizable window with double-buffered - * OpenGL 3.3 context with 24bit depth buffer. + * OpenGL 3.2 context with 24bit depth buffer. */ Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 window context", const Math::Vector2& size = Math::Vector2(800, 600)); From b0f640072cd25d681c7e9abdf2a276404b1a89a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 02:46:11 +0200 Subject: [PATCH 057/256] Timeline: sleep for _the rest_ of the frame. This wasn't well tested class. --- src/Timeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 306ce4ac7..5ecc485b3 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -42,7 +42,7 @@ void Timeline::nextFrame() { _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { - sleep(duration/1000); + sleep(_minimalFrameTime*1000 - duration/1000); now = high_resolution_clock::now(); _previousFrameDuration = duration_cast(now-previousFrameTime).count()/1e6f; } From 00cc00311b96640230656a92e764106e0bc500b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 11:28:57 +0200 Subject: [PATCH 058/256] Workarounds for old GLEW versions (tested on 1.6). GLEW defines some extensions on its own and is making mistakes, which aren't later resolved by including the official header, because the extension is already defined in glew.h. Hopefully these are the first and last errors found. --- src/AbstractTexture.h | 18 ++++++++++++++---- src/Renderbuffer.h | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index ed3e365a3..32b0900fd 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -330,11 +330,15 @@ class MAGNUM_EXPORT AbstractTexture { */ RG11B10Float = GL_R11F_G11F_B10F, + /* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is + GL_ARB_ES2_compatibility */ + #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) /** * Three-component RGB, unsigned normalized, red and blue 5bit, * green 6bit, 16bit total. */ RGB565 = GL_RGB565, + #endif /** * Three-component RGB, unsigned with exponent, each component @@ -399,33 +403,39 @@ class MAGNUM_EXPORT AbstractTexture { */ CompressedRtgcSignedRedGreen = GL_COMPRESSED_SIGNED_RG_RGTC2, + /* These are named with _ARB suffix, because glcorearb.h doesn't + have suffixless version (?!) and GLEW has it without suffix as + late as of 1.8.0 { */ + /** * BPTC compressed RGBA, unsigned normalized. * @requires_gl * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} */ - CompressedBptcRGBA = GL_COMPRESSED_RGBA_BPTC_UNORM, + CompressedBptcRGBA = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, /** * BPTC compressed sRGBA, unsigned normalized. * @requires_gl * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} */ - CompressedBptcSRGBA = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, + CompressedBptcSRGBA = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, /** * BPTC compressed RGB, signed float. * @requires_gl * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} */ - CompressedBptcRGBSignedFloat = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, + CompressedBptcRGBSignedFloat = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, /** * BPTC compressed RGB, unsigned float. * @requires_gl * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} */ - CompressedBptcRGBUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, + CompressedBptcRGBUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, + + /*}*/ /** * Depth component, at least 16bit. diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 86b1c8594..a2da42736 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -85,7 +85,12 @@ class Renderbuffer { SRGBA = GL_SRGB8_ALPHA8, RGB10Alpha2 = GL_RGB10_A2, RGB10AlphaUnsigned2 = GL_RGB10_A2UI, RGB5Alpha1 = GL_RGB5_A1, RGBA4 = GL_RGBA4, RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F, + + /* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is + GL_ARB_ES2_compatibility */ + #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) RGB565 = GL_RGB565, + #endif #ifndef MAGNUM_TARGET_GLES /** From d4ea960767a67f4a260f149a4dd83503a28ba9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Sep 2012 22:09:44 +0200 Subject: [PATCH 059/256] Fixed ambiguous function call. Probably only on GCC 4.6, though. --- src/Timeline.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 5ecc485b3..ccc8fbebe 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -18,7 +18,6 @@ #include using namespace std::chrono; -using namespace Corrade::Utility; namespace Magnum { @@ -42,7 +41,7 @@ void Timeline::nextFrame() { _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { - sleep(_minimalFrameTime*1000 - duration/1000); + Corrade::Utility::sleep(_minimalFrameTime*1000 - duration/1000); now = high_resolution_clock::now(); _previousFrameDuration = duration_cast(now-previousFrameTime).count()/1e6f; } From cef2a19b078d25472e1af1b8d9b1f53214d93cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 00:56:43 +0200 Subject: [PATCH 060/256] Moved template list of SceneGraph objects into traits class. Beside better readability it is now more future proof, as objects with double types etc. and new templated types can be added more easily. --- src/SceneGraph/Camera.cpp | 28 +++++++------- src/SceneGraph/Camera.h | 32 ++++++++-------- src/SceneGraph/Object.cpp | 16 ++++---- src/SceneGraph/Object.h | 79 +++++++++++++++++++++++++++++---------- src/SceneGraph/Scene.h | 20 +++++----- 5 files changed, 108 insertions(+), 67 deletions(-) diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index b73cb61d2..5e5693261 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -45,40 +45,40 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons } #endif -template Camera::Camera(ObjectType* parent): ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} +template Camera::Camera(typename Object::ObjectType* parent): Object::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template CameraType* Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template typename Object::CameraType* Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); - return static_cast(this); + return static_cast::CameraType*>(this); } -template void Camera::setViewport(const Math::Vector2& size) { +template void Camera::setViewport(const Math::Vector2& size) { _viewport = size; fixAspectRatio(); } -template void Camera::clean(const MatrixType& absoluteTransformation) { - ObjectType::clean(absoluteTransformation); +template void Camera::clean(const typename Object::MatrixType& absoluteTransformation) { + Object::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); } -template void Camera::draw() { - SceneType* s = this->scene(); +template void Camera::draw() { + typename Object::SceneType* s = this->scene(); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); /* Recursively draw child objects */ drawChildren(s, cameraMatrix()); } -template void Camera::drawChildren(ObjectType* object, const MatrixType& transformationMatrix) { - for(ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { +template void Camera::drawChildren(typename Object::ObjectType* object, const typename Object::MatrixType& transformationMatrix) { + for(typename Object::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ - MatrixType matrix = transformationMatrix*i->transformation(); + typename Object::MatrixType matrix = transformationMatrix*i->transformation(); /* Draw the object and its children */ - i->draw(matrix, static_cast(this)); + i->draw(matrix, static_cast::CameraType*>(this)); drawChildren(i, matrix); } } @@ -128,7 +128,7 @@ Camera3D* Camera3D::setPerspective(GLfloat fov, GLfloat near, GLfloat far) { } /* Explicitly instantiate the templates */ -template class Camera; -template class Camera; +template class Camera<2>; +template class Camera<3>; }} diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index a335beb77..d4541ed1e 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -49,7 +49,7 @@ namespace Implementation { /** @brief %Camera object */ -template class SCENEGRAPH_EXPORT Camera: public ObjectType { +template class SCENEGRAPH_EXPORT Camera: public Object::ObjectType { public: /** * @brief Aspect ratio policy @@ -67,7 +67,7 @@ template::ObjectType* parent = nullptr); /** @brief Aspect ratio policy */ inline AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; } @@ -76,7 +76,7 @@ template::CameraType* setAspectRatioPolicy(AspectRatioPolicy policy); /** * @brief Camera matrix @@ -84,7 +84,7 @@ template::MatrixType cameraMatrix() { this->setClean(); return _cameraMatrix; } @@ -96,7 +96,7 @@ template::MatrixType projectionMatrix() const { return _projectionMatrix; } /** * @brief Size of (near) XY plane in current projection @@ -127,41 +127,41 @@ template::ObjectType::draw; /* Don't hide Object's draw() */ protected: /** * Recalculates camera matrix. */ - void clean(const MatrixType& absoluteTransformation); + void clean(const typename Object::MatrixType& absoluteTransformation); /** * @brief Draw object children * * Recursively draws all children of the object. */ - void drawChildren(ObjectType* object, const MatrixType& transformationMatrix); + void drawChildren(typename Object::ObjectType* object, const typename Object::MatrixType& transformationMatrix); #ifndef DOXYGEN_GENERATING_OUTPUT inline void fixAspectRatio() { - _projectionMatrix = Implementation::aspectRatioFix(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; + _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; } - MatrixType rawProjectionMatrix; + typename Object::MatrixType rawProjectionMatrix; AspectRatioPolicy _aspectRatioPolicy; #endif private: - MatrixType _projectionMatrix; - MatrixType _cameraMatrix; + typename Object::MatrixType _projectionMatrix; + typename Object::MatrixType _cameraMatrix; Math::Vector2 _viewport; }; #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT Camera; -extern template class SCENEGRAPH_EXPORT Camera; +extern template class SCENEGRAPH_EXPORT Camera<2>; +extern template class SCENEGRAPH_EXPORT Camera<3>; namespace Implementation { template<> class Camera<2> { @@ -180,7 +180,7 @@ namespace Implementation { #endif /** @brief %Camera for two-dimensional scenes */ -class SCENEGRAPH_EXPORT Camera2D: public Camera { +class SCENEGRAPH_EXPORT Camera2D: public Camera<2> { public: /** * @brief Constructor @@ -203,7 +203,7 @@ class SCENEGRAPH_EXPORT Camera2D: public Camera { +class SCENEGRAPH_EXPORT Camera3D: public Camera<3> { public: /** * @brief Constructor diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index f3de86b1c..5b437a14e 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -25,7 +25,7 @@ using namespace Magnum::Math; namespace Magnum { namespace SceneGraph { -template ObjectType* Object::setParent(ObjectType* parent) { +template typename Object::ObjectType* Object::setParent(ObjectType* parent) { /* Skip if nothing to do or this is scene */ if(this->parent() == parent || isScene()) return static_cast(this); @@ -49,7 +49,7 @@ template(this); } -template MatrixType Object::absoluteTransformation(CameraType* camera) { +template typename Object::MatrixType Object::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ if(camera == this) return MatrixType(); @@ -77,7 +77,7 @@ template SceneType* Object::scene() { +template typename Object::SceneType* Object::scene() { /* Goes up the family tree until it finds object which is parent of itself (that's the scene) */ ObjectType* p = parent(); @@ -89,7 +89,7 @@ template ObjectType* Object::setTransformation(const MatrixType& transformation) { +template typename Object::ObjectType* Object::setTransformation(const MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -99,7 +99,7 @@ template(this); } -template void Object::setDirty() { +template void Object::setDirty() { /* The object (and all its children) are already dirty, nothing to do */ if(dirty) return; @@ -110,7 +110,7 @@ templatesetDirty(); } -template void Object::setClean() { +template void Object::setClean() { /* The object (and all its parents) are already clean, nothing to do */ if(!dirty) return; @@ -141,7 +141,7 @@ template; -template class Object; +template class Object<2>; +template class Object<3>; }} diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 33afb906a..4890ee622 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -28,6 +28,38 @@ namespace Magnum { namespace SceneGraph { +class Camera2D; +class Camera3D; +class Object2D; +class Object3D; +template class Scene; +typedef Scene<2> Scene2D; +typedef Scene<3> Scene3D; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct ObjectDimensionTraits {}; + + template<> struct ObjectDimensionTraits<2> { + static const size_t Dimensions = 2; + typedef Vector2 VectorType; + typedef Matrix3 MatrixType; + typedef Object2D ObjectType; + typedef Camera2D CameraType; + typedef Scene2D SceneType; + }; + + template<> struct ObjectDimensionTraits<3> { + static const size_t Dimensions = 3; + typedef Vector3 VectorType; + typedef Matrix4 MatrixType; + typedef Object3D ObjectType; + typedef Camera3D CameraType; + typedef Scene3D SceneType; + }; +} +#endif + /** @todo User-specified Object implementation: - for front-to-back sorting, LoD changes etc. @@ -44,15 +76,32 @@ namespace Magnum { namespace SceneGraph { * @todo Transform transformation when changing parent, so the object stays in * place. */ -template class SCENEGRAPH_EXPORT Object: public Corrade::Containers::LinkedList, public Corrade::Containers::LinkedListItem { +template class SCENEGRAPH_EXPORT Object: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { #ifndef DOXYGEN_GENERATING_OUTPUT - Object(const Object& other) = delete; - Object(Object&& other) = delete; - Object& operator=(const Object& other) = delete; - Object& operator=(Object&& other) = delete; + Object(const Object& other) = delete; + Object(Object&& other) = delete; + Object& operator=(const Object& other) = delete; + Object& operator=(Object&& other) = delete; #endif public: + static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ + + /** @brief %Vector type for given dimension count */ + typedef typename Implementation::ObjectDimensionTraits::VectorType VectorType; + + /** @brief %Matrix type for given dimension count */ + typedef typename Implementation::ObjectDimensionTraits::MatrixType MatrixType; + + /** @brief %Object type for given dimension count */ + typedef typename Implementation::ObjectDimensionTraits::ObjectType ObjectType; + + /** @brief %Camera type for given dimension count */ + typedef typename Implementation::ObjectDimensionTraits::CameraType CameraType; + + /** @brief %Scene type for given dimension count */ + typedef typename Implementation::ObjectDimensionTraits::SceneType SceneType; + /** * @brief Constructor * @param parent Parent object @@ -261,25 +310,17 @@ template inline void Object::draw(const MatrixType&, CameraType*) {} -template inline void Object::clean(const MatrixType&) { dirty = false; } - -class Camera2D; -class Camera3D; -class Object2D; -class Object3D; -template class Scene; -typedef Scene Scene2D; -typedef Scene Scene3D; +template inline void Object::draw(const MatrixType&, CameraType*) {} +template inline void Object::clean(const MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT Object; -extern template class SCENEGRAPH_EXPORT Object; +extern template class SCENEGRAPH_EXPORT Object<2>; +extern template class SCENEGRAPH_EXPORT Object<3>; #endif /** @brief Two-dimensional object */ -class SCENEGRAPH_EXPORT Object2D: public Object { +class SCENEGRAPH_EXPORT Object2D: public Object<2> { public: /** @copydoc Object::Object */ inline Object2D(Object2D* parent = nullptr): Object(parent) {} @@ -330,7 +371,7 @@ class SCENEGRAPH_EXPORT Object2D: public Object { +class SCENEGRAPH_EXPORT Object3D: public Object<3> { public: /** @copydoc Object::Object */ inline Object3D(Object3D* parent = nullptr): Object(parent) {} diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 2fd2e6fe9..9874f40c4 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -24,30 +24,30 @@ namespace Magnum { namespace SceneGraph { /** @brief %Scene */ -template class SCENEGRAPH_EXPORT Scene: public ObjectType { +template class SCENEGRAPH_EXPORT Scene: public Object::ObjectType { public: /** @copydoc Object::isScene() */ inline bool isScene() const { return true; } /** @todo Some deleted functions belong only to Scene2D, some only to Scene3D - what to do? */ #ifndef DOXYGEN_GENERATING_OUTPUT - void setParent(ObjectType* parent) = delete; - void setTransformation(const MatrixType& transformation) = delete; - void multiplyTransformation(const MatrixType& transformation, typename ObjectType::Transformation type = ObjectType::Transformation::Global) = delete; - void translate(const VectorType& vec, typename ObjectType::Transformation type = ObjectType::Transformation::Global) = delete; - void scale(const VectorType& vec, typename ObjectType::Transformation type = ObjectType::Transformation::Global) = delete; - void rotate(GLfloat angle, const VectorType& vec, typename ObjectType::Transformation type = ObjectType::Transformation::Global) = delete; + void setParent(typename Object::ObjectType* parent) = delete; + void setTransformation(const typename Object::MatrixType& transformation) = delete; + void multiplyTransformation(const typename Object::MatrixType& transformation, typename Object::Transformation type = Object::Transformation::Global) = delete; + void translate(const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; + void scale(const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; + void rotate(GLfloat angle, const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; #endif private: - inline void draw(const MatrixType&, CameraType*) {} + inline void draw(const typename Object::MatrixType&, typename Object::CameraType*) {} }; /** @brief Two-dimensional scene */ -typedef Scene Scene2D; +typedef Scene<2> Scene2D; /** @brief Three-dimensional scene */ -typedef Scene Scene3D; +typedef Scene<3> Scene3D; }} From dfe566886a0ff60bd8bf0851424c6702648ceee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 01:17:52 +0200 Subject: [PATCH 061/256] SceneGraph: disallow instantiation of Object and Camera base classes. Renamed them to AbstractObject and AbstractCamera to make this more evident to end user. --- src/SceneGraph/Camera.cpp | 28 ++++++++++++------------- src/SceneGraph/Camera.h | 44 +++++++++++++++++++++------------------ src/SceneGraph/Light.cpp | 2 +- src/SceneGraph/Object.cpp | 16 +++++++------- src/SceneGraph/Object.h | 38 +++++++++++++++++---------------- src/SceneGraph/Scene.h | 18 ++++++++-------- 6 files changed, 76 insertions(+), 70 deletions(-) diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 5e5693261..4b9cba14b 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -45,40 +45,40 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons } #endif -template Camera::Camera(typename Object::ObjectType* parent): Object::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} +template AbstractCamera::AbstractCamera(typename AbstractObject::ObjectType* parent): AbstractObject::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template typename Object::CameraType* Camera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template typename AbstractObject::CameraType* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); - return static_cast::CameraType*>(this); + return static_cast::CameraType*>(this); } -template void Camera::setViewport(const Math::Vector2& size) { +template void AbstractCamera::setViewport(const Math::Vector2& size) { _viewport = size; fixAspectRatio(); } -template void Camera::clean(const typename Object::MatrixType& absoluteTransformation) { - Object::ObjectType::clean(absoluteTransformation); +template void AbstractCamera::clean(const typename AbstractObject::MatrixType& absoluteTransformation) { + AbstractObject::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); } -template void Camera::draw() { - typename Object::SceneType* s = this->scene(); +template void AbstractCamera::draw() { + typename AbstractObject::SceneType* s = this->scene(); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); /* Recursively draw child objects */ drawChildren(s, cameraMatrix()); } -template void Camera::drawChildren(typename Object::ObjectType* object, const typename Object::MatrixType& transformationMatrix) { - for(typename Object::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { +template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix) { + for(typename AbstractObject::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ - typename Object::MatrixType matrix = transformationMatrix*i->transformation(); + typename AbstractObject::MatrixType matrix = transformationMatrix*i->transformation(); /* Draw the object and its children */ - i->draw(matrix, static_cast::CameraType*>(this)); + i->draw(matrix, static_cast::CameraType*>(this)); drawChildren(i, matrix); } } @@ -128,7 +128,7 @@ Camera3D* Camera3D::setPerspective(GLfloat fov, GLfloat near, GLfloat far) { } /* Explicitly instantiate the templates */ -template class Camera<2>; -template class Camera<3>; +template class AbstractCamera<2>; +template class AbstractCamera<3>; }} diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index d4541ed1e..97507ab21 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::Camera, Magnum::SceneGraph::Camera2D, Magnum::SceneGraph::Camera3D + * @brief Class Magnum::SceneGraph::AbstractCamera, Magnum::SceneGraph::Camera2D, Magnum::SceneGraph::Camera3D */ #include "Object.h" @@ -49,7 +49,7 @@ namespace Implementation { /** @brief %Camera object */ -template class SCENEGRAPH_EXPORT Camera: public Object::ObjectType { +template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject::ObjectType { public: /** * @brief Aspect ratio policy @@ -66,8 +66,10 @@ template class SCENEGRAPH_EXPORT Camera: public Object::ObjectType* parent = nullptr); + /** @copydoc AbstractObject::AbstractObject() */ + AbstractCamera(typename AbstractObject::ObjectType* parent = nullptr); + + virtual ~AbstractCamera() = 0; /** @brief Aspect ratio policy */ inline AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; } @@ -76,7 +78,7 @@ template class SCENEGRAPH_EXPORT Camera: public Object::CameraType* setAspectRatioPolicy(AspectRatioPolicy policy); + typename AbstractObject::CameraType* setAspectRatioPolicy(AspectRatioPolicy policy); /** * @brief Camera matrix @@ -84,7 +86,7 @@ template class SCENEGRAPH_EXPORT Camera: public Object::MatrixType cameraMatrix() { + inline typename AbstractObject::MatrixType cameraMatrix() { this->setClean(); return _cameraMatrix; } @@ -96,7 +98,7 @@ template class SCENEGRAPH_EXPORT Camera: public Object::MatrixType projectionMatrix() const { return _projectionMatrix; } + inline typename AbstractObject::MatrixType projectionMatrix() const { return _projectionMatrix; } /** * @brief Size of (near) XY plane in current projection @@ -127,41 +129,43 @@ template class SCENEGRAPH_EXPORT Camera: public Object::ObjectType::draw; /* Don't hide Object's draw() */ + using AbstractObject::ObjectType::draw; /* Don't hide Object's draw() */ protected: /** * Recalculates camera matrix. */ - void clean(const typename Object::MatrixType& absoluteTransformation); + void clean(const typename AbstractObject::MatrixType& absoluteTransformation); /** * @brief Draw object children * * Recursively draws all children of the object. */ - void drawChildren(typename Object::ObjectType* object, const typename Object::MatrixType& transformationMatrix); + void drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix); #ifndef DOXYGEN_GENERATING_OUTPUT inline void fixAspectRatio() { - _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; + _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; } - typename Object::MatrixType rawProjectionMatrix; + typename AbstractObject::MatrixType rawProjectionMatrix; AspectRatioPolicy _aspectRatioPolicy; #endif private: - typename Object::MatrixType _projectionMatrix; - typename Object::MatrixType _cameraMatrix; + typename AbstractObject::MatrixType _projectionMatrix; + typename AbstractObject::MatrixType _cameraMatrix; Math::Vector2 _viewport; }; +template inline AbstractCamera::~AbstractCamera() {} + #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT Camera<2>; -extern template class SCENEGRAPH_EXPORT Camera<3>; +extern template class SCENEGRAPH_EXPORT AbstractCamera<2>; +extern template class SCENEGRAPH_EXPORT AbstractCamera<3>; namespace Implementation { template<> class Camera<2> { @@ -180,7 +184,7 @@ namespace Implementation { #endif /** @brief %Camera for two-dimensional scenes */ -class SCENEGRAPH_EXPORT Camera2D: public Camera<2> { +class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2> { public: /** * @brief Constructor @@ -189,7 +193,7 @@ class SCENEGRAPH_EXPORT Camera2D: public Camera<2> { * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). * @see setOrthographic() */ - inline Camera2D(Object2D* parent = nullptr): Camera(parent) {} + inline Camera2D(Object2D* parent = nullptr): AbstractCamera(parent) {} /** * @brief Set projection @@ -203,7 +207,7 @@ class SCENEGRAPH_EXPORT Camera2D: public Camera<2> { }; /** @brief %Camera for three-dimensional scenes */ -class SCENEGRAPH_EXPORT Camera3D: public Camera<3> { +class SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3> { public: /** * @brief Constructor @@ -212,7 +216,7 @@ class SCENEGRAPH_EXPORT Camera3D: public Camera<3> { * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). * @see setOrthographic(), setPerspective() */ - inline Camera3D(Object3D* parent = nullptr): Camera(parent), _near(0.0f), _far(0.0f) {} + inline Camera3D(Object3D* parent = nullptr): AbstractCamera(parent), _near(0.0f), _far(0.0f) {} /** * @brief Set orthographic projection diff --git a/src/SceneGraph/Light.cpp b/src/SceneGraph/Light.cpp index 9b5eb5860..385c6efc4 100644 --- a/src/SceneGraph/Light.cpp +++ b/src/SceneGraph/Light.cpp @@ -18,7 +18,7 @@ namespace Magnum { namespace SceneGraph { void Light::clean(const Matrix4& absoluteTransformation) { - Object::clean(absoluteTransformation); + Object3D::clean(absoluteTransformation); _position = absoluteTransformation[3]; } diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index 5b437a14e..a0a02922a 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -25,7 +25,7 @@ using namespace Magnum::Math; namespace Magnum { namespace SceneGraph { -template typename Object::ObjectType* Object::setParent(ObjectType* parent) { +template typename AbstractObject::ObjectType* AbstractObject::setParent(ObjectType* parent) { /* Skip if nothing to do or this is scene */ if(this->parent() == parent || isScene()) return static_cast(this); @@ -49,7 +49,7 @@ template typename Object::ObjectType* Object(this); } -template typename Object::MatrixType Object::absoluteTransformation(CameraType* camera) { +template typename AbstractObject::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ if(camera == this) return MatrixType(); @@ -77,7 +77,7 @@ template typename Object::MatrixType Object typename Object::SceneType* Object::scene() { +template typename AbstractObject::SceneType* AbstractObject::scene() { /* Goes up the family tree until it finds object which is parent of itself (that's the scene) */ ObjectType* p = parent(); @@ -89,7 +89,7 @@ template typename Object::SceneType* Object typename Object::ObjectType* Object::setTransformation(const MatrixType& transformation) { +template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -99,7 +99,7 @@ template typename Object::ObjectType* Object(this); } -template void Object::setDirty() { +template void AbstractObject::setDirty() { /* The object (and all its children) are already dirty, nothing to do */ if(dirty) return; @@ -110,7 +110,7 @@ template void Object::setDirty() { i->setDirty(); } -template void Object::setClean() { +template void AbstractObject::setClean() { /* The object (and all its parents) are already clean, nothing to do */ if(!dirty) return; @@ -141,7 +141,7 @@ template void Object::setClean() { } /* Explicitly instantiate the templates */ -template class Object<2>; -template class Object<3>; +template class AbstractObject<2>; +template class AbstractObject<3>; }} diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 4890ee622..b8422a84e 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::Object, Magnum::SceneGraph::Object2D, Magnum::SceneGraph::Object3D + * @brief Class Magnum::SceneGraph::AbstractObject, Magnum::SceneGraph::Object2D, Magnum::SceneGraph::Object3D */ #include @@ -76,12 +76,12 @@ namespace Implementation { * @todo Transform transformation when changing parent, so the object stays in * place. */ -template class SCENEGRAPH_EXPORT Object: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { +template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { #ifndef DOXYGEN_GENERATING_OUTPUT - Object(const Object& other) = delete; - Object(Object&& other) = delete; - Object& operator=(const Object& other) = delete; - Object& operator=(Object&& other) = delete; + AbstractObject(const AbstractObject& other) = delete; + AbstractObject(AbstractObject&& other) = delete; + AbstractObject& operator=(const AbstractObject& other) = delete; + AbstractObject& operator=(AbstractObject&& other) = delete; #endif public: @@ -108,7 +108,7 @@ template class SCENEGRAPH_EXPORT Object: public Corrade::Cont * * Sets all transformations to their default values. */ - inline Object(ObjectType* parent = nullptr): dirty(true) { + inline AbstractObject(ObjectType* parent = nullptr): dirty(true) { setParent(parent); } @@ -118,7 +118,7 @@ template class SCENEGRAPH_EXPORT Object: public Corrade::Cont * Removes itself from parent's children list and destroys all own * children. */ - virtual inline ~Object() {} + virtual ~AbstractObject() = 0; /** @{ @name Scene hierarchy */ @@ -309,21 +309,23 @@ template class SCENEGRAPH_EXPORT Object: public Corrade::Cont bool dirty; }; +template inline AbstractObject::~AbstractObject() {} + /* Implementations for inline functions with unused parameters */ -template inline void Object::draw(const MatrixType&, CameraType*) {} -template inline void Object::clean(const MatrixType&) { dirty = false; } +template inline void AbstractObject::draw(const MatrixType&, CameraType*) {} +template inline void AbstractObject::clean(const MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT Object<2>; -extern template class SCENEGRAPH_EXPORT Object<3>; +extern template class SCENEGRAPH_EXPORT AbstractObject<2>; +extern template class SCENEGRAPH_EXPORT AbstractObject<3>; #endif /** @brief Two-dimensional object */ -class SCENEGRAPH_EXPORT Object2D: public Object<2> { +class SCENEGRAPH_EXPORT Object2D: public AbstractObject<2> { public: - /** @copydoc Object::Object */ - inline Object2D(Object2D* parent = nullptr): Object(parent) {} + /** @copydoc AbstractObject::AbstractObject() */ + inline Object2D(Object2D* parent = nullptr): AbstractObject(parent) {} /** * @brief Translate object @@ -371,10 +373,10 @@ class SCENEGRAPH_EXPORT Object2D: public Object<2> { }; /** @brief Three-dimensional object */ -class SCENEGRAPH_EXPORT Object3D: public Object<3> { +class SCENEGRAPH_EXPORT Object3D: public AbstractObject<3> { public: - /** @copydoc Object::Object */ - inline Object3D(Object3D* parent = nullptr): Object(parent) {} + /** @copydoc AbstractObject::AbstractObject() */ + inline Object3D(Object3D* parent = nullptr): AbstractObject(parent) {} /** * @brief Translate object diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 9874f40c4..f3cfde551 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -24,23 +24,23 @@ namespace Magnum { namespace SceneGraph { /** @brief %Scene */ -template class SCENEGRAPH_EXPORT Scene: public Object::ObjectType { +template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { public: - /** @copydoc Object::isScene() */ + /** @copydoc AbstractObject::isScene() */ inline bool isScene() const { return true; } /** @todo Some deleted functions belong only to Scene2D, some only to Scene3D - what to do? */ #ifndef DOXYGEN_GENERATING_OUTPUT - void setParent(typename Object::ObjectType* parent) = delete; - void setTransformation(const typename Object::MatrixType& transformation) = delete; - void multiplyTransformation(const typename Object::MatrixType& transformation, typename Object::Transformation type = Object::Transformation::Global) = delete; - void translate(const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; - void scale(const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; - void rotate(GLfloat angle, const typename Object::VectorType& vec, typename Object::Transformation type = Object::Transformation::Global) = delete; + void setParent(typename AbstractObject::ObjectType* parent) = delete; + void setTransformation(const typename AbstractObject::MatrixType& transformation) = delete; + void multiplyTransformation(const typename AbstractObject::MatrixType& transformation, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void translate(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void scale(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void rotate(GLfloat angle, const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; #endif private: - inline void draw(const typename Object::MatrixType&, typename Object::CameraType*) {} + inline void draw(const typename AbstractObject::MatrixType&, typename AbstractObject::CameraType*) {} }; /** @brief Two-dimensional scene */ From 823b39133ade261e7030b446d639862653cd14ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 11:48:00 +0200 Subject: [PATCH 062/256] Doc: run `ctest` with `--output-on-failure` rather than `-V`. --- README.md | 2 +- doc/building.dox | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07fde48cf..d5dc7bcab 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ If you want to build also unit tests (which are not built by default), pass `-DBUILD_TESTS=True` to CMake. Unit tests use Corrade's TestSuite framework and can be run using - ctest -V + ctest --output-on-failure in build directory. Everything should pass ;-) diff --git a/doc/building.dox b/doc/building.dox index 5153bf4b4..9b6b57782 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -81,7 +81,7 @@ If you want to build also unit tests (which are not built by default), pass `-DBUILD_TESTS=True` to CMake. Unit tests use Corrade's @ref Corrade::TestSuite "TestSuite" framework and can be run using - ctest -V + ctest --output-on-failure in build directory. Everything should pass ;-) From 9a391beb96ef6ae9e259b89b01d07a73053d555c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 11:49:06 +0200 Subject: [PATCH 063/256] Doc: updated window context building options. --- README.md | 2 +- doc/building.dox | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d5dc7bcab..67f4ead37 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ these four commands: mkdir -p build && cd build cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr \ - -DWITH_GLUTCONTEXT=ON + -DWITH_GLUTWINDOWCONTEXT=ON make make install diff --git a/doc/building.dox b/doc/building.dox index 9b6b57782..a3beb30d6 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -37,13 +37,14 @@ subdirectory: git submodule update @section building-compilation Compilation, installation -The library (for example with GLUT context) can be built and installed using -these four commands. See below for more information about optional features. +The library (for example with GLUT window context) can be built and installed +using these four commands. See below for more information about optional +features. mkdir -p build && cd build cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr \ - -DWITH_GLUTCONTEXT=ON + -DWITH_GLUTWINDOWCONTEXT=ON make make install @@ -59,22 +60,24 @@ By default the engine is built with everything except @ref Contexts "context libraries". Using `WITH_*` CMake parameters you can specify which parts will be built and which not: - - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except contexts. If - set to `OFF`, only the main library is built and you can select additional - libraries with the following: + - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except window + contexts. If set to `OFF`, only the main library is built and you can + select additional libraries with the following: - `WITH_MESHTOOLS` - MeshTools library. - `WITH_PHYSICS` - Physics library. - `WITH_PRIMITIVES` - Primitives library. - `WITH_SHADERS` - Shaders library. -None of the context libraries is built by default, regardless to +None of the window context libraries is built by default, regardless to `WITH_EVERYTHING` is enabled or not: - - `WITH_EGLCONTEXT` - X/EGL context, available only if targeting OpenGL ES - (see above). Requires **X11** and **EGL** libraries. - - `WITH_GLUTCONTEXT` - GLUT context, available only if targeting desktop - OpenGL. Requires **GLUT** library. - - `WITH_SDL2CONTEXT` - SDL2 context. Requires **SDL2** library. + - `WITH_XEGLWINDOWCONTEXT` - X/EGL window context, available only if + targeting OpenGL ES (see above). Requires **X11** and **EGL** libraries. + - `WITH_GLXWINDOWCONTEXT` - GLX window context. Requires **X11** and **GLX** + libraries. + - `WITH_GLUTWINDOWCONTEXT` - GLUT window context, available only if targeting + desktop OpenGL. Requires **GLUT** library. + - `WITH_SDL2WINDOWCONTEXT` - SDL2 window context. Requires **SDL2** library. @subsection building-tests Building and running unit tests If you want to build also unit tests (which are not built by default), pass From 3b333be0f29e9da5ca270f57507832deb550b267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 11:49:45 +0200 Subject: [PATCH 064/256] Doc: updated feature list and "Getting started" section. --- README.md | 13 ++++++++----- doc/mainpage.dox | 34 ++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 67f4ead37..bb05a977f 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,18 @@ Features: * Easy-to-use templated mathematical library for matrix/vector calculations and geometry. + * Classes wrapping OpenGL objects and simplifying their usage - shaders, + buffers, meshes and textures. Access to framebuffer and occlusion queries. + * Mesh tools for cleaning, optimizing and generating meshes, utility classes + for color conversion, timeline and profiling. * Hierarchical scene graph which supports transformation caching for better - performance, classes for convenient usage of shaders, buffers and textures. - Access to framebuffer and occlusion queries. - * Physics library for collision detection and rigid body dynamics. Mesh tools - for cleaning, optimizing and generating meshes. + performance, physics library for collision detection and rigid body + dynamics. * Plugin-based data exchange framework for importing image, mesh, material and scene data in various formats. * Collection of pre-made graphic primitives and shaders for testing purposes. - * Classes for easy creation of OpenGL context with various toolkits. + * Classes for easy creation of OpenGL context with various toolkits, methods + for querying supported OpenGL version and available extensions. * Comprehensive use of C++11 features for safety, performance and ease of development. All code which doesn't directly interact with OpenGL is covered with unit tests. diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 093bcf0ce..c0838794f 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -6,20 +6,23 @@ Features: - Easy-to-use templated @ref Math "mathematical library" for matrix/vector calculations and @ref Math::Geometry "geometry". +- Classes wrapping OpenGL objects and simplifying their usage - + @ref AbstractShaderProgram "shaders", @ref Buffer "buffers", + @ref Mesh "meshes" and @ref AbstractTexture "textures". Access to + @ref Framebuffer "framebuffer" and @ref AbstractQuery "occlusion queries". +- @ref MeshTools "Mesh tools" for cleaning, optimizing and generating meshes, + utility classes for @ref Color.h "color conversion", @ref Timeline "timeline" + and @ref Profiler "profiling". - Hierarchical @ref SceneGraph "scene graph" which supports transformation - caching for better performance, classes for convenient usage of - @ref AbstractShaderProgram "shaders", @ref Buffer "buffers" and - @ref AbstractTexture "textures". Access to @ref Framebuffer "framebuffer" - and @ref AbstractQuery "occlusion queries". -- @ref Physics "Physics library" for collision detection and rigid body - dynamics, @ref MeshTools "Mesh tools" for cleaning, optimizing and - generating meshes. + caching for better performance, @ref Physics "physics library" for collision + detection and rigid body dynamics. - Plugin-based @ref Trade "data exchange framework" for importing image, mesh, material and scene data in various formats. - Collection of pre-made @ref Primitives "graphic primitives" and @ref Shaders "shaders" for testing purposes. - Classes for easy creation of OpenGL context with @ref Contexts - "various toolkits". + "various toolkits", methods for querying + @ref Context "supported OpenGL version and available extensions". - Comprehensive use of C++11 features for safety, performance and ease of development. All code which doesn't directly interact with OpenGL is covered with unit tests. @@ -34,14 +37,13 @@ Guide @ref building "how to download and build Magnum" on different platforms. @section getting-started Getting started -Applications using %Magnum have at least two parts. One part manages OpenGL -context using some toolkit and takes care of window resizing, mouse and -keyboard input, while the other manages the scene and does the rendering. -While it is possible for you to manage the OpenGL context and events on your -own, %Magnum provides implementations for the most common toolkits (such as -GLUT, SDL or Qt) in Contexts namespace. %Scene in %Magnum is composed of -hierarchically connected object instances. To build the scene you need Scene -object with assigned camera and at least one Object instance. +To get up and running, you must first subclass one of the provided window +context classes and implement required functions. %Magnum provides +implementations for the most common toolkits (such as GLUT, Xlib, or SDL2) in +Contexts namespace. + +Then you can either draw your meshes directly or use SceneGraph which will +help you with object hierarchy, transformations and resource management. @subsection getting-started-examples Tutorials and examples From c50d68c21187fe10cf58afc5fcc0eabd5eeee6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 11:59:24 +0200 Subject: [PATCH 065/256] Fixed documentation link so it's not redirected to another domain. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb05a977f..bc33fd8b4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Features: development. All code which doesn't directly interact with OpenGL is covered with unit tests. * Actively maintained Doxygen documentation. Occasionally updated snapshot is - also available online at http://mosra.cz/blog/magnum-doc . + also available online at http://mosra.cz/blog/magnum-doc/ . INSTALLATION ============ From c813a8ae346d634a5161851753192ab49f82210d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 12:02:50 +0200 Subject: [PATCH 066/256] More README updates. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bc33fd8b4..9ed0bed4f 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,13 @@ Minimal dependencies **OpenGL ES 2** headers, if targeting OpenGL ES. * **GLEW** - OpenGL extension wrangler * **Corrade** - Plugin management and utility library. You can get it at - http://mosra.cz/blog/corrade.php + http://github.com/mosra/corrade or at http://mosra.cz/blog/corrade.php. Compilation, installation ------------------------- -The library (for example with GLUT context) can be built and installed using -these four commands: +The library (for example with GLUT window context) can be built and installed +using these four commands: mkdir -p build && cd build cmake .. \ From 4d46fd12cfcb7c985c4b2c83850a0241694beac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 18:22:33 +0200 Subject: [PATCH 067/256] Returning references from vector component accessors. Before it has to be done with overly verbose and cumbersome Java-style: Vector4 vec; vec.setX(vec.x() + 5); vec = Vector4(vec.xyz()*2, vec.w()); Now it can be done this way: vec.x() += 5; vec.xyz() *= 2; --- src/Color.h | 33 ++++++++++++++++----------------- src/Math/Vector2.h | 9 ++++----- src/Math/Vector3.h | 16 ++++++++-------- src/Math/Vector4.h | 23 ++++++++++++----------- src/Test/SwizzleTest.cpp | 3 ++- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Color.h b/src/Color.h index 304c5408e..30b5af324 100644 --- a/src/Color.h +++ b/src/Color.h @@ -224,13 +224,12 @@ template class Color3: public Math::Vector3 { */ inline constexpr Color3(T r, T g, T b): Math::Vector3(r, g, b) {} - inline constexpr T r() const { return Math::Vector3::x(); } /**< @brief R component */ - inline constexpr T g() const { return Math::Vector3::y(); } /**< @brief G component */ - inline constexpr T b() const { return Math::Vector3::z(); } /**< @brief B component */ - - inline void setR(T value) { Math::Vector3::setX(value); } /**< @brief Set R component */ - inline void setG(T value) { Math::Vector3::setY(value); } /**< @brief Set G component */ - inline void setB(T value) { Math::Vector3::setZ(value); } /**< @brief Set B component */ + inline T& r() { return Math::Vector3::x(); } /**< @brief R component */ + inline constexpr T r() const { return Math::Vector3::x(); } /**< @overload */ + inline T& g() { return Math::Vector3::y(); } /**< @brief G component */ + inline constexpr T g() const { return Math::Vector3::y(); } /**< @overload */ + inline T& b() { return Math::Vector3::z(); } /**< @brief B component */ + inline constexpr T b() const { return Math::Vector3::z(); } /**< @overload */ /** * @brief Convert to HSV @@ -362,15 +361,14 @@ template class Color4: public Math::Vector4 { is fairly common, nearly always with A set to 1 */ inline constexpr Color4(const Math::Vector<3, T>& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} - inline constexpr T r() const { return Math::Vector4::x(); } /**< @brief R component */ - inline constexpr T g() const { return Math::Vector4::y(); } /**< @brief G component */ - inline constexpr T b() const { return Math::Vector4::z(); } /**< @brief B component */ - inline constexpr T a() const { return Math::Vector4::w(); } /**< @brief A component */ - - inline void setR(T value) { Math::Vector4::setX(value); } /**< @brief Set R component */ - inline void setG(T value) { Math::Vector4::setY(value); } /**< @brief Set G component */ - inline void setB(T value) { Math::Vector4::setZ(value); } /**< @brief Set B component */ - inline void setA(T value) { Math::Vector4::setW(value); } /**< @brief Set A component */ + inline T& r() { return Math::Vector4::x(); } /**< @brief R component */ + inline constexpr T r() const { return Math::Vector4::x(); } /**< @overload */ + inline T& g() { return Math::Vector4::y(); } /**< @brief G component */ + inline constexpr T g() const { return Math::Vector4::y(); } /**< @overload */ + inline T& b() { return Math::Vector4::z(); } /**< @brief B component */ + inline constexpr T b() const { return Math::Vector4::z(); } /**< @overload */ + inline T& a() { return Math::Vector4::w(); } /**< @brief A component */ + inline constexpr T a() const { return Math::Vector4::w(); } /**< @overload */ /** * @brief RGB part of the vector @@ -378,7 +376,8 @@ template class Color4: public Math::Vector4 { * * @see swizzle() */ - inline constexpr Color3 rgb() const { return Math::Vector4::xyz(); } + inline Color3& rgb() { return Math::Vector4::xyz(); } + inline constexpr Color3 rgb() const { return Math::Vector4::xyz(); } /**< @overload */ /** @copydoc Color3::toHSV() */ inline constexpr HSV toHSV() const { diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index d67e8b0c7..6c72d25f4 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -81,11 +81,10 @@ template class Vector2: public Vector<2, T> { */ inline constexpr Vector2(T x, T y): Vector<2, T>(x, y) {} - inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */ - inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */ - - inline void setX(T value) { (*this)[0] = value; } /**< @brief Set X component */ - inline void setY(T value) { (*this)[1] = value; } /**< @brief Set Y component */ + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ + inline T& y() { return (*this)[1]; } /**< @brief Y component */ + inline constexpr T y() const { return (*this)[1]; } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector2, 2) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 2, Vector2) diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 623bb2c33..001d615a7 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -123,13 +123,12 @@ template class Vector3: public Vector<3, T> { */ inline constexpr Vector3(const Vector<2, T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} - inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */ - inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */ - inline constexpr T z() const { return (*this)[2]; } /**< @brief Z component */ - - inline void setX(T value) { (*this)[0] = value; } /**< @brief Set X component */ - inline void setY(T value) { (*this)[1] = value; } /**< @brief Set Y component */ - inline void setZ(T value) { (*this)[2] = value; } /**< @brief Set Z component */ + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ + inline T& y() { return (*this)[1]; } /**< @brief Y component */ + inline constexpr T y() const { return (*this)[1]; } /**< @overload */ + inline T& z() { return (*this)[2]; } /**< @brief Z component */ + inline constexpr T z() const { return (*this)[2]; } /**< @overload */ /** * @brief XY part of the vector @@ -137,7 +136,8 @@ template class Vector3: public Vector<3, T> { * * @see swizzle() */ - inline constexpr Vector2 xy() const { return Vector2::from(Vector<3, T>::data()); } + inline Vector2& xy() { return Vector2::from(Vector<3, T>::data()); } + inline constexpr Vector2 xy() const { return Vector2::from(Vector<3, T>::data()); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector3, 3) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Vector3) diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 5adfe60ee..e25c85fea 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -61,15 +61,14 @@ template class Vector4: public Vector<4, T> { is fairly common, nearly always with W set to 1 */ inline constexpr Vector4(const Vector<3, T>& xyz, T w = T(1)): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} - inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */ - inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */ - inline constexpr T z() const { return (*this)[2]; } /**< @brief Z component */ - inline constexpr T w() const { return (*this)[3]; } /**< @brief W component */ - - inline void setX(T value) { (*this)[0] = value; } /**< @brief Set X component */ - inline void setY(T value) { (*this)[1] = value; } /**< @brief Set Y component */ - inline void setZ(T value) { (*this)[2] = value; } /**< @brief Set Z component */ - inline void setW(T value) { (*this)[3] = value; } /**< @brief Set W component */ + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ + inline T& y() { return (*this)[1]; } /**< @brief Y component */ + inline constexpr T y() const { return (*this)[1]; } /**< @overload */ + inline T& z() { return (*this)[2]; } /**< @brief Z component */ + inline constexpr T z() const { return (*this)[2]; } /**< @overload */ + inline T& w() { return (*this)[3]; } /**< @brief W component */ + inline constexpr T w() const { return (*this)[3]; } /**< @overload */ /** * @brief XYZ part of the vector @@ -77,7 +76,8 @@ template class Vector4: public Vector<4, T> { * * @see swizzle() */ - inline constexpr Vector3 xyz() const { return Vector3::from(Vector<4, T>::data()); } + inline Vector3& xyz() { return Vector3::from(Vector<4, T>::data()); } + inline constexpr Vector3 xyz() const { return Vector3::from(Vector<4, T>::data()); } /**< @overload */ /** * @brief XY part of the vector @@ -85,7 +85,8 @@ template class Vector4: public Vector<4, T> { * * @see swizzle() */ - inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } + inline Vector2& xy() { return Vector2::from(Vector<4, T>::data()); } + inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector4, 4) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Vector4) diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 00be3d7ea..561b53fcf 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -52,7 +52,8 @@ void SwizzleTest::rgba() { void SwizzleTest::fromSmall() { /* Force compile-time evaluation for both */ constexpr Vector2 orig(1, 2); - CORRADE_VERIFY((integral_constant::value)); + constexpr Vector3 swizzled(swizzle(orig, "gxr")); + CORRADE_VERIFY((integral_constant::value)); CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(orig)), Vector3(2, 1, 1)); } From 6a4b68410cb10b43bd36e6cb0c3b501432c0d733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 21:17:56 +0200 Subject: [PATCH 068/256] Doc: brief introduction to matrix and vector classes. DDD - documentation driven development. Not all advertised features are available right now, but they will come. --- doc/mainpage.dox | 5 +- doc/matrix-vector.dox | 181 +++++++++++++++++++++++++++++++++++ doc/namespaces.dox | 3 +- src/Math/Matrix.h | 6 +- src/Math/Matrix3.h | 5 +- src/Math/Matrix4.h | 5 +- src/Math/RectangularMatrix.h | 4 +- src/Math/Vector.h | 3 + src/Math/Vector2.h | 2 + src/Math/Vector3.h | 2 + src/Math/Vector4.h | 2 + src/Swizzle.h | 6 +- 12 files changed, 211 insertions(+), 13 deletions(-) create mode 100644 doc/matrix-vector.dox diff --git a/doc/mainpage.dox b/doc/mainpage.dox index c0838794f..fd394ae85 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -4,8 +4,9 @@ namespace Magnum { %Magnum is 3D graphics engine written in C++11 and OpenGL 3 Core Profile. Features: -- Easy-to-use templated @ref Math "mathematical library" for matrix/vector - calculations and @ref Math::Geometry "geometry". +- Easy-to-use templated @ref Math "mathematical library" for + @ref matrix-vector "matrix/vector calculations" and + @ref Math::Geometry "geometry". - Classes wrapping OpenGL objects and simplifying their usage - @ref AbstractShaderProgram "shaders", @ref Buffer "buffers", @ref Mesh "meshes" and @ref AbstractTexture "textures". Access to diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox new file mode 100644 index 000000000..795f5619c --- /dev/null +++ b/doc/matrix-vector.dox @@ -0,0 +1,181 @@ +namespace Magnum { namespace Math { +/** @page matrix-vector Operations with matrices and vectors + +@brief Introduction to essential classes of the graphics pipeline. + +@tableofcontents + +Matrices and vectors are the most important part of graphics programming and +one of goals of %Magnum is to make their usage as intuitive as possible. This +page will overview their usage and introduce some tricks to make your life +easier. + +@section matrix-vector-hierarchy Matrix and vector classes + +%Magnum has three main matrix and vector classes: RectangularMatrix, (square) +Matrix and Vector. To achieve greatest code reuse, %Matrix is internally +square %RectangularMatrix and %Vector is internally one-column +%RectangularMatrix. Both vectors and matrices can have arbitrary size (known +at compile time) and can store any meaningful type. + +Each subclass brings some specialization to its superclass and for most common +vector and matrix sizes there are specialized classes Matrix3 and Matrix4, +implementing various transformation in 2D and 3D, Vector2, Vector3 and Vector4, +implementing direct access to named components. Functions of each class try to +return the most specialized type known to make subsequent operations more +convenient - columns of %RectangularMatrix are returned as %Vector, but when +accessing columns of e.g. %Matrix3, they are returned as %Vector3. + +There are also even more specialized subclasses - Point2D, Point3D for +creating points with homogeneous coordinates and Color3, Color4 for color +handling and conversion. + +@section matrix-vector-construction Constructing matrices and vectors + +Default constructors of RectangularMatrix and Vector (and Vector2, Vector3, +Vector4, Color3) create zero-filled objects. Matrix (and Matrix3, Matrix4) is +by default constructed as identity matrix. Point2D and Point3D have +homogeneous component set to one, Color4 has alpha value set to opaque. +@code +RectangularMatrix<2, 3, int> a; // zero-filled +Vector<3, int> b; // zero-filled + +Matrix<3, int> identity; // diagonal set to 1 +Matrix<3, int> zero(Matrix<3, int>::Zero); // zero-filled + +Point2D c; // {0, 0, 1} +Point3D d; // {0, 0, 0, 1} + +Color4 black1; // {0.0f, 0.0f, 0.0f, 1.0f} +Color4 black2; // {0, 0, 0, 255} +@endcode + +Most common and most efficient way to create matrix or vector is to pass +values of all components to the constructor. +@code +Matrix3 mat(0, 1, 2, + 3, 4, 5, + 6, 7, 8); // column-major (see explanation why below) + +Vector3 vec(0, 1, 2); +@endcode +All constructors check number of passed arguments and the errors are catched +at compile time. + +You can specify all components of vector or whole diagonal of square matrix at +once: +@code +Matrix3 diag(Matrix3::Identity, 2); // diagonal set to 2, zeros elsewhere +Vector3 fill(10); // {10, 10, 10} +@endcode + +Vectors are commonly used to specify various axes and scaling coefficients in +transformations, you can use convenience functions instead of typing out all +other elements: +@code +Matrix4::rotation(deg(5.0f), Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} +Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f} +Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f} +@endcode + +It is possible to create matrices from other matrices and vectors with the +same row count; vectors from vector and scalar: +@code +RectangularMatrix<2, 3, int> a; +Vector3 b, c; +Matrix3 mat = Matrix3::from(b, a, c); +Vector<8, int> vec = Vector<8, int>::from(1, b, 2, c); +@endcode + +It is also possible to create them from an C-style array. The function does +simple type cast without any copying, so it's possible to conveniently operate +on the array itself: +@code +int[] mat = { 2, 4, 6, + 1, 3, 5 }; +RectangularMatrix<2, 3, int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 } +@endcode +Note that unlike constructors, this function has no way to check whether the +array is long enough to contain all elements, so use with caution. + +You can also convert between data types: +@code +Vector4 floating(1.3f, 2.7f, -15.0f, 7.0f); +Vector4 integral(Vector4::from(floating)); // {1, 2, -15, 7} +@endcode + +@section matrix-vector-component-access Accessing matrix and vector components + +Column vectors of matrices and vector components can be accessed using square +brackets, there is also round bracket operator for accessing matrix components +directly: +@code +RectangularMatrix<3, 2, int> a; +a[2] /= 2; // third column (column major indexing, see explanation below) +a[0][1] = 5; // first column, second element +a(0, 1) += 3; // first column, second element (preferred) + +Vector<3, int> b; +b[1] = 1; // second element +@endcode +For accessing matrix element prefer round bracket operator, as it is possibly +faster than the double square brackets (but never slower) and isn't prone to +compiler mis-optimizations. + +Fixed-size vector subclasses have functions for accessing named components +and subparts: +@code +Vector4 a; +int x = a.x(); +a.y() += 5; + +Vector3 xyz = a.xyz(); +xyz.xy() *= 5; +@endcode +Color3 and Color4 name their components `rgba` instead of `xyzw`. + +For more involved operations with components there are two swizzle() functions, +they have the same features, but one is guaranteed to do most of the work at +compile-time, while the second has more convenient syntax: +@code +Vector4 original(1, 2, 3, 4); +Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, 1, 4 } +Vector<6, int> a10rgb = swizzle(original, "a10rgb"); // { 4, 1, 0, 1, 2, 3 } +@endcode + +@section matrix-vector-column-major Matrices are column-major and vectors are columns + +OpenGL matrices are column-major, thus it is reasonable to have matrices in +%Magnum also column major (and vectors as columns). This has naturally some +implications and it may differ from what is common in mathematics: + +- Order of template arguments in specification of RectangularMatrix is also + column-major: +@code +RectangularMatrix<2, 3, int> mat; // two columns, three rows +@endcode +- Order of components in matrix constructors is also column-major, so the + elements passed in constructor doesn't need to be reordered internally + before putting them into data array: +@code +Matrix3 mat(0, 1, 2, + 3, 4, 5, + 6, 7, 8); // first column is {0, 1, 2} +@endcode +- Element accessing order is also column-major. It costs virtually no time to + return reference to portion of data array as column vector, thus the bracket + operator is accessing columns. Returned vector has also its own bracket + operator, which is indexing rows. To avoid confusion, first parameter of + round bracket operator is thus also column index. +@code +mat[0] *= 2; // first column +mat[2][0] = 5; // first element of first column vector +mat(2, 0) += 3; // first element of first column +@endcode +- Various algorithms which commonly operate on matrix rows (such as + @ref Algorithms::GaussJordan "Gauss-Jordan elimination") have faster + alternatives which operate on columns. It's then up to user decision to + operate with transposed matrices or use the slower non-transposed + alternative of the algorithm. +*/ +}} diff --git a/doc/namespaces.dox b/doc/namespaces.dox index faf2cb178..ff7bf5656 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -25,7 +25,8 @@ Base classes for creating OpenGL contexts with various toolkits. /** @namespace Magnum::Math @brief %Math library -Template classes for matrix and vector calculations. +Template classes for matrix and vector calculations. See @ref matrix-vector +for brief introduction. */ /** @dir Math/Algorithms diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 2273ce3b1..30e6c1e2e 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -32,6 +32,9 @@ namespace Implementation { /** @brief Square matrix @tparam s %Matrix size +@tparam T Data type + +See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} @todo @c PERFORMANCE - loop unrolling for Matrix<3, T> and Matrix<4, T> @@ -228,7 +231,6 @@ namespace Implementation { template class MatrixDeterminant { public: - /** @brief Functor */ T operator()(const Matrix& m) { T out(0); @@ -241,7 +243,6 @@ template class MatrixDeterminant { template class MatrixDeterminant<2, T> { public: - /** @brief Functor */ inline constexpr T operator()(const Matrix<2, T>& m) { return m(0, 0)*m(1, 1) - m(1, 0)*m(0, 1); } @@ -249,7 +250,6 @@ template class MatrixDeterminant<2, T> { template class MatrixDeterminant<1, T> { public: - /** @brief Functor */ inline constexpr T operator()(const Matrix<1, T>& m) { return m(0, 0); } diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index e537de58a..fd2af1d4d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -26,9 +26,10 @@ namespace Magnum { namespace Math { /** @brief 3x3 matrix +@tparam T Data type -Provides functions for transformations in 2D. See also Matrix4 for 3D -transformations. +Provides functions for transformations in 2D. See Matrix4 for 3D +transformations. See also @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix3} */ template class Matrix3: public Matrix<3, T> { diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index e0cfceb07..2e10dda97 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -26,9 +26,10 @@ namespace Magnum { namespace Math { /** @brief 4x4 matrix +@tparam T Data type -Provides functions for transformations in 3D. See also Matrix3 for 2D -transformations. +Provides functions for transformations in 3D. See Matrix3 for 2D +transformations. See also @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix4} @todo Shearing @todo Reflection diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 6c52764a8..770862565 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -48,8 +48,10 @@ template class Vector; @brief Rectangular matrix @tparam c Column count @tparam r Row count +@tparam T Data type -See also Matrix (square) and Vector. +See @ref matrix-vector for brief introduction. See also Matrix (square) and +Vector. */ template class RectangularMatrix { static_assert(c != 0 && r != 0, "Matrix cannot have zero elements"); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index da1372ee2..9d78a10ca 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -36,7 +36,10 @@ namespace Implementation { /** @brief %Vector +@tparam s %Vector size +@tparam T Data type +See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} @todo Constexprize all for loops */ diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 6c72d25f4..2b477a1f6 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -25,7 +25,9 @@ namespace Magnum { namespace Math { /** @brief Two-component vector +@tparam T Data type +See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector2} */ template class Vector2: public Vector<2, T> { diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 001d615a7..095b053fd 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -25,7 +25,9 @@ namespace Magnum { namespace Math { /** @brief Three-component vector +@tparam T Data type +See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector3} */ template class Vector3: public Vector<3, T> { diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index e25c85fea..41e24f313 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -25,7 +25,9 @@ namespace Magnum { namespace Math { /** @brief Four-component vector +@tparam T Data type +See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector4} */ template class Vector4: public Vector<4, T> { diff --git a/src/Swizzle.h b/src/Swizzle.h index 8f30f96a5..d61ae1cdb 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -97,7 +97,8 @@ swizzle(const T&, const char(&)[newSize]), but the evaluation of the swizzling operation is guaranteed to be always done at compile time instead of at runtime. -@see Vector4::xyz(), Vector4::rgb(), Vector4::xy(), Vector3::xy() +@see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), + Vector4::xy(), Vector3::xy() */ template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector) { return {vector[Implementation::GetComponent::value()]...}; @@ -123,7 +124,8 @@ swizzle(const T&), but unless the result is marked with `constexpr`, the evaluation of the swizzling operation probably won't be evaluated at compile time, but at runtime. -@see Vector4::xyz(), Vector4::rgb(), Vector4::xy(), Vector3::xy() +@see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), + Vector4::xy(), Vector3::xy() */ template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector, const char(&components)[newSize]) { return Implementation::swizzleFrom(typename Implementation::GenerateSequence::Type(), vector, components); From 619f44347cb047f0b0368aa44ea7c61a6038d791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Sep 2012 21:57:08 +0200 Subject: [PATCH 069/256] Doxygen documentation workarounds. --- src/Math/Geometry/Distance.h | 12 ++++-------- src/Math/Geometry/Intersection.h | 6 ++---- src/Math/Matrix.h | 20 ++++++++------------ src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- src/Math/Vector4.h | 1 - 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index 143ab8784..b86b5aa71 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -33,8 +33,7 @@ class Distance { * @param point Point * * The distance *d* is computed from point **p** and line defined by **a** - * and **b** using @ref Vector3::cross() "cross product": - * @f[ + * and **b** using @ref Vector3::cross() "cross product": @f[ * d = \frac{|(\boldsymbol p - \boldsymbol a) \times (\boldsymbol p - \boldsymbol b)|} * {|\boldsymbol b - \boldsymbol a|} * @f] @@ -66,19 +65,16 @@ class Distance { * * Determining whether the point lies next to line segment or outside * is done using Pythagorean theorem. If the following equation - * applies, the point **p** lies outside line segment closer to **a**: - * @f[ + * applies, the point **p** lies outside line segment closer to **a**: @f[ * |\boldsymbol p - \boldsymbol b|^2 > |\boldsymbol b - \boldsymbol a|^2 + |\boldsymbol p - \boldsymbol a|^2 * @f] * On the other hand, if the following equation applies, the point - * lies outside line segment closer to **b**: - * @f[ + * lies outside line segment closer to **b**: @f[ * |\boldsymbol p - \boldsymbol a|^2 > |\boldsymbol b - \boldsymbol a|^2 + |\boldsymbol p - \boldsymbol b|^2 * @f] * The last alternative is when the following equation applies. The * point then lies between **a** and **b** and the distance is - * computed the same way as in linePoint(). - * @f[ + * computed the same way as in linePoint(). @f[ * |\boldsymbol b - \boldsymbol a|^2 > |\boldsymbol p - \boldsymbol a|^2 + |\boldsymbol p - \boldsymbol b|^2 * @f] * diff --git a/src/Math/Geometry/Intersection.h b/src/Math/Geometry/Intersection.h index b4cee3f72..6eeba75bc 100644 --- a/src/Math/Geometry/Intersection.h +++ b/src/Math/Geometry/Intersection.h @@ -39,14 +39,12 @@ class Intersection { * is inside the line segment defined by `a` and `b`. * * First the parameter *f* of parametric equation of the plane - * is computed from plane normal **n** and plane position: - * @f[ + * is computed from plane normal **n** and plane position: @f[ * \begin{pmatrix} n_0 \\ n_1 \\ n_2 \end{pmatrix} \cdot * \begin{pmatrix} x \\ y \\ z \end{pmatrix} - f = 0 * @f] * Using plane normal **n**, parameter *f* and points **a** and **b**, - * value of *t* is computed and returned. - * @f[ + * value of *t* is computed and returned. @f[ * \begin{array}{rcl} * \Delta \boldsymbol b & = & \boldsymbol b - \boldsymbol a \\ * f & = & \boldsymbol n \cdot (\boldsymbol a + \Delta \boldsymbol b \cdot t) \\ diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 30e6c1e2e..e799591da 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -69,7 +69,7 @@ template class Matrix: public RectangularMatrix { (*this)(i, i) = value; } - /** @copydoc RectangularMatrix::RectangularMatrix(T, U...) */ + /** @copydoc RectangularMatrix::RectangularMatrix */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr Matrix(T first, U... next): RectangularMatrix(first, next...) {} #else @@ -115,15 +115,12 @@ template class Matrix: public RectangularMatrix { /** * @brief Determinant * - * Computed recursively using Laplace's formula: - * @f[ - * \det(A) = \sum_{j=1}^n (-1)^{i+j} a_{i,j} \det(A^{i,j}) - * @f] - * @f$ A^{i, j} @f$ is matrix without i-th row and j-th column, see + * Computed recursively using Laplace's formula: @f[ + * \det(A) = \sum_{j=1}^n (-1)^{i+j} a_{i,j} \det(A^{i,j}) + * @f] @f$ A^{i, j} @f$ is matrix without i-th row and j-th column, see * ij(). The formula is expanded down to 2x2 matrix, where the - * determinant is computed directly: - * @f[ - * \det(A) = a_{0, 0} a_{1, 1} - a_{1, 0} a_{0, 1} + * determinant is computed directly: @f[ + * \det(A) = a_{0, 0} a_{1, 1} - a_{1, 0} a_{0, 1} * @f] */ inline T determinant() const { return Implementation::MatrixDeterminant()(*this); } @@ -131,9 +128,8 @@ template class Matrix: public RectangularMatrix { /** * @brief Inverted matrix * - * Computed using Cramer's rule: - * @f[ - * A^{-1} = \frac{1}{\det(A)} Adj(A) + * Computed using Cramer's rule: @f[ + * A^{-1} = \frac{1}{\det(A)} Adj(A) * @f] */ Matrix inverted() const { diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index fd2af1d4d..09dacfddb 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -86,7 +86,7 @@ template class Matrix3: public Matrix<3, T> { T(0), T(0), value ) {} - /** @copydoc Matrix::Matrix(T, U...) */ + /** @copydoc Matrix::Matrix */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr Matrix3(T first, U... next): Matrix<3, T>(first, next...) {} #else diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 2e10dda97..487a6baa9 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -116,7 +116,7 @@ template class Matrix4: public Matrix<4, T> { T(0), T(0), T(0), value ) {} - /** @copydoc Matrix::Matrix(T, U...) */ + /** @copydoc Matrix::Matrix */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr Matrix4(T first, U... next): Matrix<4, T>(first, next...) {} #else diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 41e24f313..2111e744e 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -34,7 +34,6 @@ template class Vector4: public Vector<4, T> { public: /** * @copydoc Vector::Vector - * * W component is set to one. */ inline constexpr Vector4(): Vector<4, T>(T(0), T(0), T(0), T(1)) {} From 7a13e5c873d4352a0446ec76fbd3314253be3576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:00:35 +0200 Subject: [PATCH 070/256] Added Color3 and Color4 to TypeTraits. --- src/TypeTraits.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 11dfea0c4..00d590078 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -29,6 +29,9 @@ namespace Math { template class Matrix; } +template class Color3; +template class Color4; + /** @brief Traits class for plain OpenGL types @@ -239,6 +242,8 @@ template struct TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits> { inline constexpr static Type type() { return TypeTraits::type(); } From ce15175c70ae825a040a0b0bf8061cc15f35d272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:00:56 +0200 Subject: [PATCH 071/256] Don't show dependent options in CMake if WITH_EVERYTHING is set to ON. --- CMakeLists.txt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb3f414e1..76eed8cbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,11 @@ cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF # Parts of the library option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) -option(WITH_MESHTOOLS "Build MeshTools library" OFF) -option(WITH_PHYSICS "Build Physics library" OFF) -option(WITH_PRIMITIVES "Builf Primitives library" OFF) -option(WITH_SCENEGRAPH "Build SceneGraph library" OFF) -option(WITH_SHADERS "Build Shaders library" OFF) +cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING" ON) option(WITH_GLXWINDOWCONTEXT "Build GlxWindowContext library" OFF) cmake_dependent_option(WITH_XEGLWINDOWCONTEXT "Build XEglWindowContext library" OFF "TARGET_GLES" OFF) @@ -22,14 +22,6 @@ option(WITH_SDL2WINDOWCONTEXT "Build Sdl2WindowContext library" OFF) option(BUILD_TESTS "Build unit tests." OFF) -if(WITH_EVERYTHING) - set(WITH_MESHTOOLS ON) - set(WITH_PHYSICS ON) - set(WITH_PRIMITIVES ON) - set(WITH_SCENEGRAPH ON) - set(WITH_SHADERS ON) -endif() - if(BUILD_TESTS) enable_testing() endif() From 7acda40a674da895f23d368ac724715a9119b7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:02:26 +0200 Subject: [PATCH 072/256] Doc++ (vector components, not values). --- src/Math/Vector3.h | 10 +++++----- src/Math/Vector4.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 095b053fd..990a6cba2 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -112,16 +112,16 @@ template class Vector3: public Vector<3, T> { /** * @brief Constructor - * @param x X value - * @param y Y value - * @param z Z value + * @param x X component + * @param y Y component + * @param z Z component */ inline constexpr Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {} /** * @brief Constructor - * @param xy Two component vector - * @param z Z value + * @param xy Two-component vector + * @param z Z component */ inline constexpr Vector3(const Vector<2, T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 2111e744e..2fc35f9de 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -46,17 +46,17 @@ template class Vector4: public Vector<4, T> { /** * @brief Constructor - * @param x X value - * @param y Y value - * @param z Z value - * @param w W value + * @param x X component + * @param y Y component + * @param z Z component + * @param w W component */ inline constexpr Vector4(T x, T y, T z, T w = T(1)): Vector<4, T>(x, y, z, w) {} /** * @brief Constructor - * @param xyz Three component vector - * @param w W value + * @param xyz Three-component vector + * @param w W component */ /* Not marked as explicit, because conversion from Vector3 to Vector4 is fairly common, nearly always with W set to 1 */ From eb803200d656521a602fca48ea4b6d97c92b5be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:03:01 +0200 Subject: [PATCH 073/256] Disabled denormalization test for long double altogether. Fails in Debug, but passes in Release mode on my GCC 4.7 @ x86_64. Not sure what to do about it. --- src/Math/Math.h | 2 ++ src/Math/Test/MathTest.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Math/Math.h b/src/Math/Math.h index 5f475d598..47f345327 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -98,6 +98,8 @@ integral type. resulting `Integral` type (e.g. `double` to `int`, `long double` to `long long`). @todo Signed normalization to [-1.0, 1.0] like in OpenGL? +@todo Stable behavior (working/broken) for long double and long long + (currently fails in Debug builds, but passes in Release on GCC 4.7) */ template inline constexpr typename std::enable_if::value && std::is_integral::value, Integral>::type denormalize(FloatingPoint value) { return std::numeric_limits::min() + diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 862f1a15b..027f09c35 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -74,11 +74,11 @@ void MathTest::denormalize() { CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - { - CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); - CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); - } +// { +// CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); +// CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); +// CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); +// } } void MathTest::clamp() { From b90ba53f2eb62d911951d6c0999766ba9ff1fa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:05:04 +0200 Subject: [PATCH 074/256] Doc++ (positions, not vertices). --- src/MeshTools/CombineIndexedArrays.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 612e8fce3..6f4f8f699 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -106,18 +106,18 @@ of some STL functions like shown below. Also if one index array is shader by more than one attribute array, just pass the index array more times. Example: @code std::vector vertexIndices; -std::vector vertices; +std::vector positions; std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; std::vector indices = MeshTools::combineIndexedArrays( - std::make_tuple(std::cref(vertexIndices), std::ref(vertices)), + std::make_tuple(std::cref(vertexIndices), std::ref(positions)), std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)), std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates)) ); @endcode -`vertices`, `normals` and `textureCoordinates` will then contain combined +`positions`, `normals` and `textureCoordinates` will then contain combined attributes indexed with `indices`. @attention All index arrays should have the same size, otherwise zero-length From 071afa0b7ad29953faaf056ca14e0552926dd108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:07:52 +0200 Subject: [PATCH 075/256] Point*D Vector* subclasses for homogeneous coordinates. Vector4 doesn't set W component to one by default anymore, this is now handled by Point*D itself. This finally allows creating of 2D primitives and 2D position vectors without messing explicitly with Z = 1. All classes which should use Point instead of Vector were updated to use Point instead. --- src/AbstractShaderProgram.h | 2 +- src/Magnum.h | 8 ++ src/Math/CMakeLists.txt | 2 + src/Math/Point2D.h | 74 ++++++++++++++++++ src/Math/Point3D.h | 75 +++++++++++++++++++ src/Math/Test/CMakeLists.txt | 3 + src/Math/Test/Point2DTest.cpp | 56 ++++++++++++++ src/Math/Test/Point2DTest.h | 33 ++++++++ src/Math/Test/Point3DTest.cpp | 56 ++++++++++++++ src/Math/Test/Point3DTest.h | 33 ++++++++ src/Math/Test/Vector3Test.cpp | 1 + src/Math/Test/Vector4Test.cpp | 2 +- src/Math/Vector3.h | 3 +- src/Math/Vector4.h | 16 ++-- src/MeshTools/CombineIndexedArrays.h | 2 +- src/MeshTools/GenerateFlatNormals.cpp | 4 +- src/MeshTools/GenerateFlatNormals.h | 4 +- .../Test/GenerateFlatNormalsTest.cpp | 2 +- src/Physics/AxisAlignedBox.cpp | 3 +- src/Physics/Capsule.cpp | 5 +- src/Physics/Line.cpp | 5 +- src/Physics/Plane.cpp | 3 +- src/Physics/Point.cpp | 3 +- src/Physics/Sphere.cpp | 3 +- src/Primitives/Capsule.cpp | 6 +- src/Primitives/Cube.cpp | 4 +- src/Primitives/Cylinder.cpp | 1 - src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Plane.cpp | 4 +- src/Primitives/Test/CapsuleTest.cpp | 6 +- src/Primitives/Test/CylinderTest.cpp | 6 +- src/Primitives/Test/UVSphereTest.cpp | 6 +- src/SceneGraph/Light.h | 5 +- src/Shaders/PhongShader.h | 2 +- src/Trade/MeshData.h | 9 ++- src/TypeTraits.h | 2 + 36 files changed, 399 insertions(+), 52 deletions(-) create mode 100644 src/Math/Point2D.h create mode 100644 src/Math/Point3D.h create mode 100644 src/Math/Test/Point2DTest.cpp create mode 100644 src/Math/Test/Point2DTest.h create mode 100644 src/Math/Test/Point3DTest.cpp create mode 100644 src/Math/Test/Point3DTest.h diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 8078c9e6f..2d5b410b9 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -41,7 +41,7 @@ functions and properties: - %Attribute location typedefs defining locations and types for attribute binding with Mesh::bindAttribute(), for example: @code -typedef Attribute<0, Vector4> Position; +typedef Attribute<0, Point3D> Position; typedef Attribute<1, Vector3> Normal; typedef Attribute<2, Vector2> TextureCoords; @endcode diff --git a/src/Magnum.h b/src/Magnum.h index 49fe94f59..63bcc00c7 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -41,6 +41,8 @@ namespace Magnum { template class Vector2; template class Vector3; template class Vector4; + template class Point2D; + template class Point3D; template class Matrix3; template class Matrix4; @@ -62,6 +64,12 @@ typedef Math::Vector3 Vector3; /** @brief Four-component floating-point vector */ typedef Math::Vector4 Vector4; +/** @brief Two-dimensional floating-point homogeneous coordinates */ +typedef Math::Point2D Point2D; + +/** @brief Three-dimensional floating-point homogeneous coordinates */ +typedef Math::Point3D Point3D; + /** @brief 3x3 floating-point matrix */ typedef Math::Matrix3 Matrix3; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index edcfe14ac..a92da34c4 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -7,6 +7,8 @@ set(MagnumMath_HEADERS Matrix.h Matrix3.h Matrix4.h + Point2D.h + Point3D.h RectangularMatrix.h Vector.h Vector2.h diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h new file mode 100644 index 000000000..953438d51 --- /dev/null +++ b/src/Math/Point2D.h @@ -0,0 +1,74 @@ +#ifndef Magnum_Math_Point2D_h +#define Magnum_Math_Point2D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Point2D + */ + +#include "Vector3.h" + +namespace Magnum { namespace Math { + +/** +@brief Two-dimensional homogeneous coordinates +@tparam T Data type + +Same as Vector3, except that constructors have default value for Z component +set to one. See also @ref matrix-vector for brief introduction. +@configurationvalueref{Magnum::Math::Point2D} +*/ +template class Point2D: public Vector3 { + public: + /** + * @brief Default constructor + * + * X and Y components are set to zero, Z is set to one. + */ + inline constexpr Point2D(): Vector3(T(0), T(0), T(1)) {} + + /** @brief Copy constructor */ + inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3(other) {} + + /** + * @brief Constructor + * @param x X component + * @param y Y component + * @param z Z component + */ + inline constexpr Point2D(T x, T y, T z = T(1)): Vector3(x, y, z) {} + + /** + * @brief Constructor + * @param xy Two-component vector + * @param z Z component + */ + inline constexpr Point2D(const Vector<2, T>& xy, T z = T(1)): Vector3(xy, z) {} +}; + +/** @debugoperator{Magnum::Math::Point2D} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { + return debug << static_cast&>(value); +} + +}} + +namespace Corrade { namespace Utility { + /** @configurationvalue{Magnum::Math::Point2D} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; +}} + +#endif diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h new file mode 100644 index 000000000..e92e1e7b1 --- /dev/null +++ b/src/Math/Point3D.h @@ -0,0 +1,75 @@ +#ifndef Magnum_Math_Point3D_h +#define Magnum_Math_Point3D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Point3D + */ + +#include "Vector4.h" + +namespace Magnum { namespace Math { + +/** +@brief Three-dimensional homogeneous coordinates +@tparam T Data type + +Same as Vector4, except that constructors have default value for W component +set to one. See also @ref matrix-vector for brief introduction. +@configurationvalueref{Magnum::Math::Point3D} +*/ +template class Point3D: public Vector4 { + public: + /** + * @brief Default constructor + * + * X, Y and Z components are set to zero, W is set to one. + */ + inline constexpr Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} + + /** @brief Copy constructor */ + inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4(other) {} + + /** + * @brief Constructor + * @param x X component + * @param y Y component + * @param z Z component + * @param w W component + */ + inline constexpr Point3D(T x, T y, T z, T w = T(1)): Vector4(x, y, z, w) {} + + /** + * @brief Constructor + * @param xyz Three-component vector + * @param w W component + */ + inline constexpr Point3D(const Vector<3, T>& xyz, T w = T(1)): Vector4(xyz, w) {} +}; + +/** @debugoperator{Magnum::Math::Point3D} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { + return debug << static_cast&>(value); +} + +}} + +namespace Corrade { namespace Utility { + /** @configurationvalue{Magnum::Math::Point3D} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; +}} + +#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 8f3690ea8..a62ecefca 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -10,6 +10,9 @@ corrade_add_test2(MathVector2Test Vector2Test.cpp) corrade_add_test2(MathVector3Test Vector3Test.cpp) corrade_add_test2(MathVector4Test Vector4Test.cpp) +corrade_add_test2(MathPoint2DTest Point2DTest.cpp) +corrade_add_test2(MathPoint3DTest Point3DTest.cpp) + corrade_add_test2(MathMatrixTest MatrixTest.cpp) corrade_add_test2(MathMatrix3Test Matrix3Test.cpp) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp new file mode 100644 index 000000000..64d5540bc --- /dev/null +++ b/src/Math/Test/Point2DTest.cpp @@ -0,0 +1,56 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Point2DTest.h" + +#include + +#include "Point2D.h" + +CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest) + +using namespace std; +using namespace Corrade::Utility; + +namespace Magnum { namespace Math { namespace Test { + +typedef Math::Point2D Point2D; + +Point2DTest::Point2DTest() { + addTests(&Point2DTest::construct, + &Point2DTest::debug, + &Point2DTest::configuration); +} + +void Point2DTest::construct() { + CORRADE_COMPARE(Point2D(), (Vector<3, float>(0.0f, 0.0f, 1.0f))); + CORRADE_COMPARE(Point2D(1, 2), (Vector<3, float>(1.0f, 2.0f, 1.0f))); + CORRADE_COMPARE(Point2D(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); +} + +void Point2DTest::debug() { + ostringstream o; + Debug(&o) << Point2D(0.5f, 15.0f, 1.0f); + CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n"); +} + +void Point2DTest::configuration() { + Point2D vec(3.0f, 3.125f, 9.55f); + string value("3 3.125 9.55"); + CORRADE_COMPARE(ConfigurationValue::toString(vec), value); + CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); +} + +}}} diff --git a/src/Math/Test/Point2DTest.h b/src/Math/Test/Point2DTest.h new file mode 100644 index 000000000..39ec72d3b --- /dev/null +++ b/src/Math/Test/Point2DTest.h @@ -0,0 +1,33 @@ +#ifndef Magnum_Math_Test_Point2DTest_h +#define Magnum_Math_Test_Point2DTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class Point2DTest: public Corrade::TestSuite::Tester { + public: + Point2DTest(); + + void construct(); + void debug(); + void configuration(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp new file mode 100644 index 000000000..092f5a0f0 --- /dev/null +++ b/src/Math/Test/Point3DTest.cpp @@ -0,0 +1,56 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Point3DTest.h" + +#include + +#include "Point3D.h" + +CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest) + +using namespace std; +using namespace Corrade::Utility; + +namespace Magnum { namespace Math { namespace Test { + +typedef Math::Point3D Point3D; + +Point3DTest::Point3DTest() { + addTests(&Point3DTest::construct, + &Point3DTest::debug, + &Point3DTest::configuration); +} + +void Point3DTest::construct() { + CORRADE_COMPARE(Point3D(), Point3D(0.0f, 0.0f, 0.0f, 1.0f)); + CORRADE_COMPARE(Point3D(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); + CORRADE_COMPARE(Point3D(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); +} + +void Point3DTest::debug() { + ostringstream o; + Debug(&o) << Point3D(0.5f, 15.0f, 1.0f, 1.0f); + CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); +} + +void Point3DTest::configuration() { + Point3D vec(3.0f, 3.125f, 9.0f, 9.55f); + string value("3 3.125 9 9.55"); + CORRADE_COMPARE(ConfigurationValue::toString(vec), value); + CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); +} + +}}} diff --git a/src/Math/Test/Point3DTest.h b/src/Math/Test/Point3DTest.h new file mode 100644 index 000000000..9560e01d5 --- /dev/null +++ b/src/Math/Test/Point3DTest.h @@ -0,0 +1,33 @@ +#ifndef Magnum_Math_Test_Point3DTest_h +#define Magnum_Math_Test_Point3DTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class Point3DTest: public Corrade::TestSuite::Tester { + public: + Point3DTest(); + + void construct(); + void debug(); + void configuration(); +}; + +}}} + +#endif diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 710c60cd0..6ffdc267d 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -40,6 +40,7 @@ Vector3Test::Vector3Test() { } void Vector3Test::construct() { + CORRADE_COMPARE(Vector3(), Vector3(0.0f, 0.0f, 0.0f)); CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); } diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index b8765b65b..c12838a20 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -39,7 +39,7 @@ Vector4Test::Vector4Test() { } void Vector4Test::construct() { - CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); + CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); } diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 990a6cba2..79a3a9075 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -27,7 +27,8 @@ namespace Magnum { namespace Math { @brief Three-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. +See @ref matrix-vector for brief introduction. See also Point2D for +homogeneous two-dimensional coordinates. @configurationvalueref{Magnum::Math::Vector3} */ template class Vector3: public Vector<3, T> { diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 2fc35f9de..0df339f24 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -27,16 +27,14 @@ namespace Magnum { namespace Math { @brief Four-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. +See @ref matrix-vector for brief introduction. See also Point3D for +homogeneous three-dimensional coordinates. @configurationvalueref{Magnum::Math::Vector4} */ template class Vector4: public Vector<4, T> { public: - /** - * @copydoc Vector::Vector - * W component is set to one. - */ - inline constexpr Vector4(): Vector<4, T>(T(0), T(0), T(0), T(1)) {} + /** @copydoc Vector::Vector() */ + inline constexpr Vector4() {} /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} @@ -51,16 +49,14 @@ template class Vector4: public Vector<4, T> { * @param z Z component * @param w W component */ - inline constexpr Vector4(T x, T y, T z, T w = T(1)): Vector<4, T>(x, y, z, w) {} + inline constexpr Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {} /** * @brief Constructor * @param xyz Three-component vector * @param w W component */ - /* Not marked as explicit, because conversion from Vector3 to Vector4 - is fairly common, nearly always with W set to 1 */ - inline constexpr Vector4(const Vector<3, T>& xyz, T w = T(1)): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} + inline constexpr Vector4(const Vector<3, T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 6f4f8f699..25a8cca4e 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -106,7 +106,7 @@ of some STL functions like shown below. Also if one index array is shader by more than one attribute array, just pass the index array more times. Example: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 50866eb18..5d4868a3b 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -15,14 +15,14 @@ #include "GenerateFlatNormals.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "MeshTools/Clean.h" using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 48f289e19..bdbcca05a 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -38,7 +38,7 @@ For each face generates one normal vector, removes duplicates before returning. Example usage: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalIndices; std::vector normals; @@ -50,7 +50,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 8cf127a46..1de255976 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "MeshTools/GenerateFlatNormals.h" CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index b0ef33339..30ad3551b 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -16,11 +16,12 @@ #include "AxisAlignedBox.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void AxisAlignedBox::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 3f7936901..b6d175f7d 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -18,6 +18,7 @@ #include "Math/Constants.h" #include "Math/Math.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "Point.h" #include "Sphere.h" @@ -27,8 +28,8 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Capsule::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Vector4(_a)).xyz(); - _transformedB = (transformation*Vector4(_b)).xyz(); + _transformedA = (transformation*Point3D(_a)).xyz(); + _transformedB = (transformation*Point3D(_b)).xyz(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 010cf5c37..3dec9a602 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -16,12 +16,13 @@ #include "Line.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void Line::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Vector4(_a)).xyz(); - _transformedB = (transformation*Vector4(_b)).xyz(); + _transformedA = (transformation*Point3D(_a)).xyz(); + _transformedB = (transformation*Point3D(_b)).xyz(); } }} diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 5ca9d49c3..124b28ccf 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -18,6 +18,7 @@ #include #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Intersection.h" #include "LineSegment.h" @@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Plane::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); _transformedNormal = transformation.rotation()*_normal; } diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index eef45829f..6ec43579b 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -16,11 +16,12 @@ #include "Point.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Physics { void Point::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); } }} diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 54a656168..f3b0579b1 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -18,6 +18,7 @@ #include "Math/Constants.h" #include "Math/Math.h" #include "Math/Matrix4.h" +#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "LineSegment.h" #include "Point.h" @@ -27,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Sphere::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Vector4(_position)).xyz(); + _transformedPosition = (transformation*Point3D(_position)).xyz(); float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 11fa8f9f0..c65c87d36 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -16,13 +16,13 @@ #include "Capsule.h" #include "Math/Constants.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index c524fb77e..ec1917c5f 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -15,7 +15,7 @@ #include "Cube.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; @@ -34,7 +34,7 @@ Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector{ 2, 6, 7, 4, 1, 5, 4, 0, 1 -}, {new vector}, {new vector{ +}, {new vector}, {new vector{ {-1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 30a031538..709c7dfb9 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -16,7 +16,6 @@ #include "Cylinder.h" #include "Math/Constants.h" -#include "Math/Vector4.h" using namespace std; diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 436937906..100858b8f 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -42,7 +42,7 @@ Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector}, {new vector{ +}, {new vector}, {new vector{ Vector3(0, -0.525731f, 0.850651f), Vector3(0.850651f, 0, 0.525731f), Vector3(0.850651f, 0, -0.525731f), diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 6db0eec5c..74d9a2054 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -15,13 +15,13 @@ #include "Plane.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" using namespace std; namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 45e16738f..7d95515c3 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -20,7 +20,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/Capsule.h" using namespace std; @@ -38,7 +38,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 2, 3, 1.0f); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, @@ -103,7 +103,7 @@ void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withTextureCoords() { Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 43efb5845..cb94fa6d7 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/Cylinder.h" using namespace std; @@ -35,7 +35,7 @@ CylinderTest::CylinderTest() { void CylinderTest::withoutAnything() { Cylinder cylinder(2, 3, 3.0f); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ {0.0f, -1.5f, 1.0f}, {0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f}, @@ -72,7 +72,7 @@ void CylinderTest::withoutAnything() { void CylinderTest::withTextureCoordsAndCaps() { Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 1.0f}, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 269c52419..cff3f77b9 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -17,7 +17,7 @@ #include -#include "Math/Vector4.h" +#include "Math/Point3D.h" #include "Primitives/UVSphere.h" using namespace std; @@ -35,7 +35,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -73,7 +73,7 @@ void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, diff --git a/src/SceneGraph/Light.h b/src/SceneGraph/Light.h index 3e604f584..74070122c 100644 --- a/src/SceneGraph/Light.h +++ b/src/SceneGraph/Light.h @@ -19,6 +19,7 @@ * @brief Class Magnum::SceneGraph::Light */ +#include "Math/Point3D.h" #include "Object.h" namespace Magnum { namespace SceneGraph { @@ -39,7 +40,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D { /** * @brief Light position relative to root object (scene) */ - inline Vector4 position() { + inline Point3D position() { setClean(); return _position; } @@ -51,7 +52,7 @@ class SCENEGRAPH_EXPORT Light: public Object3D { void clean(const Matrix4& absoluteTransformation); private: - Vector4 _position; + Point3D _position; }; }} diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index a27b5d047..a6dd5c6dc 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders { */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - typedef Attribute<0, Vector4> Position; /**< @brief Vertex position */ + typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ /** @brief Constructor */ diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData.h index daf4f3cfa..d3b19bb2e 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData.h @@ -21,6 +21,7 @@ #include +#include "Math/Point3D.h" #include "Mesh.h" namespace Magnum { namespace Trade { @@ -50,7 +51,7 @@ class MAGNUM_EXPORT MeshData { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData(); @@ -77,8 +78,8 @@ class MAGNUM_EXPORT MeshData { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(unsigned int id) { return _positions[id]; } - inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(unsigned int id) { return _positions[id]; } + inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ inline unsigned int normalArrayCount() const { return _normals.size(); } @@ -108,7 +109,7 @@ class MAGNUM_EXPORT MeshData { std::string _name; Mesh::Primitive _primitive; std::vector* _indices; - std::vector*> _positions; + std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; }; diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 00d590078..5b15c9832 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -242,6 +242,8 @@ template struct TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; From 90a3b76e055704030bc79ef52b788b59f9ce9009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:32:28 +0200 Subject: [PATCH 076/256] Have both 2D and 3D alternatives of mesh and object data in Trade. --- src/CMakeLists.txt | 3 +- src/Primitives/Capsule.cpp | 4 +- src/Primitives/Capsule.h | 4 +- src/Primitives/Cube.cpp | 2 +- src/Primitives/Cube.h | 4 +- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Icosphere.h | 4 +- src/Primitives/Plane.cpp | 2 +- src/Primitives/Plane.h | 4 +- src/Trade/AbstractImporter.h | 87 +++++++++++---- src/Trade/CMakeLists.txt | 9 +- src/Trade/MeshData2D.cpp | 26 +++++ src/Trade/MeshData2D.h | 105 ++++++++++++++++++ src/Trade/{MeshData.cpp => MeshData3D.cpp} | 6 +- src/Trade/{MeshData.h => MeshData3D.h} | 22 ++-- .../{MeshObjectData.h => MeshObjectData2D.h} | 22 ++-- src/Trade/MeshObjectData3D.h | 59 ++++++++++ src/Trade/ObjectData2D.h | 103 +++++++++++++++++ src/Trade/{ObjectData.h => ObjectData3D.h} | 30 ++--- src/Trade/SceneData.h | 19 ++-- 20 files changed, 431 insertions(+), 86 deletions(-) create mode 100644 src/Trade/MeshData2D.cpp create mode 100644 src/Trade/MeshData2D.h rename src/Trade/{MeshData.cpp => MeshData3D.cpp} (91%) rename src/Trade/{MeshData.h => MeshData3D.h} (82%) rename src/Trade/{MeshObjectData.h => MeshObjectData2D.h} (61%) create mode 100644 src/Trade/MeshObjectData3D.h create mode 100644 src/Trade/ObjectData2D.h rename src/Trade/{ObjectData.h => ObjectData3D.h} (68%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ade850775..651eabbdb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,8 @@ set(Magnum_SRCS TypeTraits.cpp Trade/AbstractImporter.cpp - Trade/MeshData.cpp) + Trade/MeshData2D.cpp + Trade/MeshData3D.cpp) set(Magnum_HEADERS AbstractImage.h AbstractShaderProgram.h diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index c65c87d36..d339f04f5 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index bb496ea00..570a1ede0 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Primitives::Capsule */ -#include "Trade/MeshData.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { @@ -28,7 +28,7 @@ namespace Magnum { namespace Primitives { Cylinder along Y axis with hemispheres instead of caps. */ -class Capsule: public Trade::MeshData { +class Capsule: public Trade::MeshData3D { friend class UVSphere; friend class Cylinder; diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index ec1917c5f..48b99c491 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index bacc1829c..e44368f58 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -19,12 +19,12 @@ * @brief Class Magnum::Primitives::Cube */ -#include "Trade/MeshData.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { /** @brief %Cube primitive */ -class Cube: public Trade::MeshData { +class Cube: public Trade::MeshData3D { public: /** @brief Constructor */ Cube(); diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 100858b8f..f2ee23068 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData("", Mesh::Primitive::Triangles, new vector{ +Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 22d854576..a31c887d2 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -22,7 +22,7 @@ #include "Math/Vector3.h" #include "MeshTools/Subdivide.h" #include "MeshTools/Clean.h" -#include "Trade/MeshData.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { @@ -34,7 +34,7 @@ template class Icosphere; @todo Use own computed (and more precise) icosahedron data, not these stolen from Blender. */ -template<> class Icosphere<0>: public Trade::MeshData { +template<> class Icosphere<0>: public Trade::MeshData3D { public: /** @brief Constructor */ Icosphere(); diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 74d9a2054..99627bab1 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index d21eee942..7f1693284 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Primitives::Plane */ -#include "Trade/MeshData.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { @@ -28,7 +28,7 @@ namespace Magnum { namespace Primitives { 2x2 plane with normals in positive Z direction. */ -class Plane: public Trade::MeshData { +class Plane: public Trade::MeshData3D { public: /** @brief Constructor */ Plane(); diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index e39fada1f..43877f14d 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -30,8 +30,10 @@ class AbstractMaterialData; class CameraData; template class ImageData; class LightData; -class MeshData; -class ObjectData; +class MeshData2D; +class MeshData3D; +class ObjectData2D; +class ObjectData3D; class SceneData; class TextureData; @@ -176,44 +178,83 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { */ virtual CameraData* camera(unsigned int id); - /** @brief %Object count */ - virtual inline unsigned int objectCount() const { return 0; } + /** @brief Two-dimensional object count */ + virtual inline unsigned int object2DCount() const { return 0; } /** - * @brief %Object ID for given name + * @brief Two-dimensional object ID for given name * * If no scene for given name exists, returns -1. - * @see ObjectData::name() + * @see ObjectData2D::name() */ - virtual int objectForName(const std::string& name); + virtual int object2DForName(const std::string& name); /** - * @brief %Object - * @param id %Object ID, from range [0, objectCount()). + * @brief Two-dimensional object + * @param id %Object ID, from range [0, object2DCount()). * * Returns pointer to given object or nullptr, if no such object * exists. */ - virtual ObjectData* object(unsigned int id); + virtual ObjectData2D* object2D(unsigned int id); - /** @brief %Mesh count */ - virtual inline unsigned int meshCount() const { return 0; } + /** @brief Three-dimensional object count */ + virtual inline unsigned int object3DCount() const { return 0; } /** - * @brief %Mesh ID for given name + * @brief Three-dimensional object ID for given name + * + * If no scene for given name exists, returns -1. + * @see ObjectData3D::name() + */ + virtual int object3DForName(const std::string& name); + + /** + * @brief Three-dimensional object + * @param id %Object ID, from range [0, object3DCount()). + * + * Returns pointer to given object or nullptr, if no such object + * exists. + */ + virtual ObjectData3D* object3D(unsigned int id); + + /** @brief Two-dimensional mesh count */ + virtual inline unsigned int mesh2DCount() const { return 0; } + + /** + * @brief Two-dimensional mesh ID for given name + * + * If no mesh for given name exists, returns -1. + * @see MeshData2D::name() + */ + virtual int mesh2DForName(const std::string& name); + + /** + * @brief Two-dimensional mesh + * @param id %Mesh ID, from range [0, meshCount()). + * + * Returns pointer to given mesh or nullptr, if no such mesh exists. + */ + virtual MeshData2D* mesh2D(unsigned int id); + + /** @brief Three-dimensional mesh count */ + virtual inline unsigned int mesh3DCount() const { return 0; } + + /** + * @brief Three-dimensional mesh ID for given name * * If no mesh for given name exists, returns -1. - * @see MeshData::name() + * @see MeshData3D::name() */ - virtual int meshForName(const std::string& name); + virtual int mesh3DForName(const std::string& name); /** - * @brief %Mesh + * @brief Three-dimensional mesh * @param id %Mesh ID, from range [0, meshCount()). * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ - virtual MeshData* mesh(unsigned int id); + virtual MeshData3D* mesh3D(unsigned int id); /** @brief Material count */ virtual inline unsigned int materialCount() const { return 0; } @@ -324,10 +365,14 @@ inline int AbstractImporter::lightForName(const std::string&) { return -1; } inline LightData* AbstractImporter::light(unsigned int) { return nullptr; } inline int AbstractImporter::cameraForName(const std::string&) { return -1; } inline CameraData* AbstractImporter::camera(unsigned int) { return nullptr; } -inline int AbstractImporter::objectForName(const std::string&) { return -1; } -inline ObjectData* AbstractImporter::object(unsigned int) { return nullptr; } -inline int AbstractImporter::meshForName(const std::string&) { return -1; } -inline MeshData* AbstractImporter::mesh(unsigned int) { return nullptr; } +inline int AbstractImporter::object2DForName(const std::string&) { return -1; } +inline ObjectData2D* AbstractImporter::object2D(unsigned int) { return nullptr; } +inline int AbstractImporter::object3DForName(const std::string&) { return -1; } +inline ObjectData3D* AbstractImporter::object3D(unsigned int) { return nullptr; } +inline int AbstractImporter::mesh2DForName(const std::string&) { return -1; } +inline MeshData2D* AbstractImporter::mesh2D(unsigned int) { return nullptr; } +inline int AbstractImporter::mesh3DForName(const std::string&) { return -1; } +inline MeshData3D* AbstractImporter::mesh3D(unsigned int) { return nullptr; } inline int AbstractImporter::materialForName(const std::string&) { return -1; } inline AbstractMaterialData* AbstractImporter::material(unsigned int) { return nullptr; } inline int AbstractImporter::textureForName(const std::string&) { return -1; } diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 9ef1442be..12b1fd60d 100644 --- a/src/Trade/CMakeLists.txt +++ b/src/Trade/CMakeLists.txt @@ -4,9 +4,12 @@ set(MagnumTrade_HEADERS CameraData.h ImageData.h LightData.h - MeshData.h - MeshObjectData.h - ObjectData.h + MeshData2D.h + MeshData3D.h + MeshObjectData2D.h + MeshObjectData3D.h + ObjectData2D.h + ObjectData3D.h PhongMaterialData.h SceneData.h TextureData.h) diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp new file mode 100644 index 000000000..8fee8177d --- /dev/null +++ b/src/Trade/MeshData2D.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "MeshData2D.h" + +namespace Magnum { namespace Trade { + +MeshData2D::~MeshData2D() { + delete _indices; + for(auto i: _positions) delete i; + for(auto i: _textureCoords2D) delete i; +} + +}} diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h new file mode 100644 index 000000000..3a7663e44 --- /dev/null +++ b/src/Trade/MeshData2D.h @@ -0,0 +1,105 @@ +#ifndef Magnum_Trade_MeshData2D_h +#define Magnum_Trade_MeshData2D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Trade::MeshData2D + */ + +#include + +#include "Math/Point2D.h" +#include "Mesh.h" + +namespace Magnum { namespace Trade { + +/** +@brief Two-dimensional mesh data + +Provides access to mesh data and additional information, such as primitive +type. +*/ +class MAGNUM_EXPORT MeshData2D { + MeshData2D(const MeshData2D& other) = delete; + MeshData2D(MeshData2D&& other) = delete; + MeshData2D& operator=(const MeshData2D& other) = delete; + MeshData2D& operator=(MeshData2D&& other) = delete; + + public: + /** + * @brief Constructor + * @param name %Mesh name + * @param primitive Primitive + * @param indices Array with indices or 0, if this is not + * indexed mesh + * @param positions Array with vertex positions. At least one + * position array should be present. + * @param textureCoords2D Array with two-dimensional texture + * coordinate arrays or empty array + */ + inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + + /** @brief Destructor */ + ~MeshData2D(); + + /** @brief %Mesh name */ + inline std::string name() const { return _name; } + + /** @brief Primitive */ + inline Mesh::Primitive primitive() const { return _primitive; } + + /** + * @brief Indices + * @return Indices or nullptr if the mesh is not indexed. + */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ + + /** @brief Count of vertex position arrays */ + inline unsigned int positionArrayCount() const { return _positions.size(); } + + /** + * @brief Positions + * @param id ID of position data array + * @return Positions or nullptr if there is no vertex array with given + * ID. + */ + inline std::vector* positions(unsigned int id) { return _positions[id]; } + inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ + + /** @brief Count of 2D texture coordinate arrays */ + inline unsigned int textureCoords2DArrayCount() const { return _textureCoords2D.size(); } + + /** + * @brief 2D texture coordinates + * @param id ID of texture coordinates array + * @return %Texture coordinates or nullptr if there is no texture + * coordinates array with given ID. + */ + inline std::vector* textureCoords2D(unsigned int id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(unsigned int id) const { return _textureCoords2D[id]; } /**< @overload */ + + private: + std::string _name; + Mesh::Primitive _primitive; + std::vector* _indices; + std::vector*> _positions; + std::vector*> _textureCoords2D; +}; + +}} + +#endif diff --git a/src/Trade/MeshData.cpp b/src/Trade/MeshData3D.cpp similarity index 91% rename from src/Trade/MeshData.cpp rename to src/Trade/MeshData3D.cpp index 24f2043fe..65d59fbd9 100644 --- a/src/Trade/MeshData.cpp +++ b/src/Trade/MeshData3D.cpp @@ -13,13 +13,11 @@ GNU Lesser General Public License version 3 for more details. */ -#include "MeshData.h" - -#include "Math/Vector4.h" +#include "MeshData3D.h" namespace Magnum { namespace Trade { -MeshData::~MeshData() { +MeshData3D::~MeshData3D() { delete _indices; for(auto i: _positions) delete i; for(auto i: _normals) delete i; diff --git a/src/Trade/MeshData.h b/src/Trade/MeshData3D.h similarity index 82% rename from src/Trade/MeshData.h rename to src/Trade/MeshData3D.h index d3b19bb2e..371bd4a59 100644 --- a/src/Trade/MeshData.h +++ b/src/Trade/MeshData3D.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_MeshData_h -#define Magnum_Trade_MeshData_h +#ifndef Magnum_Trade_MeshData3D_h +#define Magnum_Trade_MeshData3D_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Trade::MeshData + * @brief Class Magnum::Trade::MeshData3D */ #include @@ -27,16 +27,16 @@ namespace Magnum { namespace Trade { /** -@brief %Mesh data +@brief Three-dimensional mesh data Provides access to mesh data and additional information, such as primitive type. */ -class MAGNUM_EXPORT MeshData { - MeshData(const MeshData& other) = delete; - MeshData(MeshData&& other) = delete; - MeshData& operator=(const MeshData& other) = delete; - MeshData& operator=(MeshData&& other) = delete; +class MAGNUM_EXPORT MeshData3D { + MeshData3D(const MeshData3D& other) = delete; + MeshData3D(MeshData3D&& other) = delete; + MeshData3D& operator=(const MeshData3D& other) = delete; + MeshData3D& operator=(MeshData3D&& other) = delete; public: /** @@ -51,10 +51,10 @@ class MAGNUM_EXPORT MeshData { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ - ~MeshData(); + ~MeshData3D(); /** @brief %Mesh name */ inline std::string name() const { return _name; } diff --git a/src/Trade/MeshObjectData.h b/src/Trade/MeshObjectData2D.h similarity index 61% rename from src/Trade/MeshObjectData.h rename to src/Trade/MeshObjectData2D.h index e8b9568e3..c733c53a4 100644 --- a/src/Trade/MeshObjectData.h +++ b/src/Trade/MeshObjectData2D.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_MeshObjectData_h -#define Magnum_Trade_MeshObjectData_h +#ifndef Magnum_Trade_MeshObjectData2D_h +#define Magnum_Trade_MeshObjectData2D_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,23 +16,23 @@ */ /** @file - * @brief Class Magnum::Trade::MeshObjectData + * @brief Class Magnum::Trade::MeshObjectData2D */ -#include "ObjectData.h" +#include "ObjectData2D.h" namespace Magnum { namespace Trade { /** -@brief %Mesh object data +@brief Two-dimensional mesh object data Provides access to material information for given mesh instance. */ -class MeshObjectData: public ObjectData { - MeshObjectData(const MeshObjectData& other) = delete; - MeshObjectData(MeshObjectData&& other) = delete; - MeshObjectData& operator=(const MeshObjectData& other) = delete; - MeshObjectData& operator=(MeshObjectData&& other) = delete; +class MeshObjectData2D: public ObjectData2D { + MeshObjectData2D(const MeshObjectData2D& other) = delete; + MeshObjectData2D(MeshObjectData2D&& other) = delete; + MeshObjectData2D& operator=(const MeshObjectData2D& other) = delete; + MeshObjectData2D& operator=(MeshObjectData2D&& other) = delete; public: /** @@ -45,7 +45,7 @@ class MeshObjectData: public ObjectData { * * Creates object with mesh instance type. */ - inline MeshObjectData(const std::string& name, const std::vector& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData2D(const std::string& name, const std::vector& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData2D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ inline unsigned int material() const { return _material; } diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h new file mode 100644 index 000000000..4dbfef017 --- /dev/null +++ b/src/Trade/MeshObjectData3D.h @@ -0,0 +1,59 @@ +#ifndef Magnum_Trade_MeshObjectData3D_h +#define Magnum_Trade_MeshObjectData3D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Trade::MeshObjectData3D + */ + +#include "ObjectData3D.h" + +namespace Magnum { namespace Trade { + +/** +@brief Three-dimensional mesh object data + +Provides access to material information for given mesh instance. +*/ +class MeshObjectData3D: public ObjectData3D { + MeshObjectData3D(const MeshObjectData3D& other) = delete; + MeshObjectData3D(MeshObjectData3D&& other) = delete; + MeshObjectData3D& operator=(const MeshObjectData3D& other) = delete; + MeshObjectData3D& operator=(MeshObjectData3D&& other) = delete; + + public: + /** + * @brief Constructor + * @param name %Mesh object name + * @param children Child objects + * @param transformation Transformation (relative to parent) + * @param instance Instance ID + * @param material Material ID + * + * Creates object with mesh instance type. + */ + inline MeshObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData3D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + + /** @brief Material ID */ + inline unsigned int material() const { return _material; } + + private: + unsigned int _material; +}; + +}} + +#endif diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h new file mode 100644 index 000000000..7610087eb --- /dev/null +++ b/src/Trade/ObjectData2D.h @@ -0,0 +1,103 @@ +#ifndef Magnum_Trade_ObjectData2D_h +#define Magnum_Trade_ObjectData2D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Trade::ObjectData2D + */ + +#include "Math/Matrix4.h" +#include "Magnum.h" + +namespace Magnum { namespace Trade { + +/** +@brief Two-dimensional object data + +Provides access to object transformation and hierarchy. See also +MeshObjectData2D, which is specialized for objects with mesh instance type. +*/ +class ObjectData2D { + ObjectData2D(const ObjectData2D& other) = delete; + ObjectData2D(ObjectData2D&& other) = delete; + ObjectData2D& operator=(const ObjectData2D& other) = delete; + ObjectData2D& operator=(ObjectData2D&& other) = delete; + + public: + /** @brief Instance type */ + enum class InstanceType { + Camera, /**< Camera instance (see CameraData) */ + Mesh, /**< Three-dimensional mesh instance (see MeshData2D) */ + Empty /**< Empty */ + }; + + /** + * @brief Constructor + * @param name Object name + * @param children Child objects + * @param transformation Transformation (relative to parent) + * @param instanceType Instance type + * @param instanceId Instance ID + */ + inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + + /** + * @brief Constructor for empty instance + * @param name Object name + * @param children Child objects + * @param transformation Transformation (relative to parent) + */ + inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + + /** @brief Destructor */ + inline virtual ~ObjectData2D() {} + + /** @brief %Object name */ + inline std::string name() const { return _name; } + + /** @brief Child objects */ + inline std::vector& children() { return _children; } + + /** @brief Transformation (relative to parent) */ + inline Matrix3 transformation() const { return _transformation; } + + /** + * @brief Instance type + * @return Type of instance held by this object + * + * If the instance is of type InstanceType::Mesh, the instance can be + * casted to MeshObjectData2D and provide more information. + */ + inline InstanceType instanceType() const { return _instanceType; } + + /** + * @brief Instance ID + * @return ID of given camera / light / mesh etc., specified by + * instanceType() + */ + inline int instanceId() const { return _instanceId; } + + private: + std::string _name; + std::vector _children; + Matrix3 _transformation; + InstanceType _instanceType; + int _instanceId; +}; + +}} + +#endif diff --git a/src/Trade/ObjectData.h b/src/Trade/ObjectData3D.h similarity index 68% rename from src/Trade/ObjectData.h rename to src/Trade/ObjectData3D.h index 53da3f783..189560254 100644 --- a/src/Trade/ObjectData.h +++ b/src/Trade/ObjectData3D.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_ObjectData_h -#define Magnum_Trade_ObjectData_h +#ifndef Magnum_Trade_ObjectData3D_h +#define Magnum_Trade_ObjectData3D_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Trade::ObjectData + * @brief Class Magnum::Trade::ObjectData3D */ #include "Math/Matrix4.h" @@ -25,23 +25,23 @@ namespace Magnum { namespace Trade { /** -@brief %Object data +@brief Three-dimensional object data Provides access to object transformation and hierarchy. See also -MeshObjectData, which is specialized for objects with mesh instance type. +MeshObjectData3D, which is specialized for objects with mesh instance type. */ -class ObjectData { - ObjectData(const ObjectData& other) = delete; - ObjectData(ObjectData&& other) = delete; - ObjectData& operator=(const ObjectData& other) = delete; - ObjectData& operator=(ObjectData&& other) = delete; +class ObjectData3D { + ObjectData3D(const ObjectData3D& other) = delete; + ObjectData3D(ObjectData3D&& other) = delete; + ObjectData3D& operator=(const ObjectData3D& other) = delete; + ObjectData3D& operator=(ObjectData3D&& other) = delete; public: /** @brief Instance type */ enum class InstanceType { Camera, /**< Camera instance (see CameraData) */ Light, /**< Light instance (see LightData) */ - Mesh, /**< Mesh instance (see MeshData) */ + Mesh, /**< Three-dimensional mesh instance (see MeshData3D) */ Empty /**< Empty */ }; @@ -53,7 +53,7 @@ class ObjectData { * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData(const std::string& name, const std::vector& children, const Matrix4& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance @@ -61,10 +61,10 @@ class ObjectData { * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData(const std::string& name, const std::vector& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ - inline virtual ~ObjectData() {} + inline virtual ~ObjectData3D() {} /** @brief %Object name */ inline std::string name() const { return _name; } @@ -80,7 +80,7 @@ class ObjectData { * @return Type of instance held by this object * * If the instance is of type InstanceType::Mesh, the instance can be - * casted to MeshObjectData and provide more information. + * casted to MeshObjectData3D and provide more information. */ inline InstanceType instanceType() const { return _instanceType; } diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index 678243208..84a5aa348 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -36,20 +36,25 @@ class MAGNUM_EXPORT SceneData { public: /** * @brief Constructor - * @param name %Scene name - * @param children Child objects + * @param name Scene name + * @param children2D Two-dimensional child objects + * @param children3D Three-dimensional child objects */ - inline SceneData(const std::string& name, const std::vector& children): _name(name), _children(children) {} + inline SceneData(const std::string& name, const std::vector& children2D, const std::vector& children3D): _name(name), _children2D(children2D), _children3D(children3D) {} - /** @brief %Scene name */ + /** @brief Scene name */ inline std::string name() const { return _name; } - /** @brief Child objects */ - inline const std::vector& children() const { return _children; } + /** @brief Two-dimensional child objects */ + inline const std::vector& children2D() const { return _children2D; } + + /** @brief Three-dimensional child objects */ + inline const std::vector& children3D() const { return _children3D; } private: std::string _name; - std::vector _children; + std::vector _children2D, + _children3D; }; }} From b43a6ee5868fcec39d13495b990f1c905be50b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 02:37:13 +0200 Subject: [PATCH 077/256] Square primitive. --- src/Primitives/CMakeLists.txt | 2 ++ src/Primitives/Square.cpp | 31 ++++++++++++++++++++++++++++ src/Primitives/Square.h | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/Primitives/Square.cpp create mode 100644 src/Primitives/Square.h diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index e554119cb..d154d79c6 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -4,6 +4,7 @@ set(MagnumPrimitives_SRCS Cylinder.cpp Icosphere.cpp Plane.cpp + Square.cpp UVSphere.cpp) set(MagnumPrimitives_HEADERS Capsule.h @@ -11,6 +12,7 @@ set(MagnumPrimitives_HEADERS Cylinder.h Icosphere.h Plane.h + Square.h UVSphere.h) add_library(MagnumPrimitives STATIC ${MagnumPrimitives_SRCS}) diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp new file mode 100644 index 000000000..1855bcd6e --- /dev/null +++ b/src/Primitives/Square.cpp @@ -0,0 +1,31 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Square.h" + +#include "Math/Point2D.h" + +using namespace std; + +namespace Magnum { namespace Primitives { + +Square::Square(): MeshData2D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ + {1.0f, -1.0f}, + {1.0f, 1.0f}, + {-1.0f, -1.0f}, + {-1.0f, 1.0f} +}}, {}) {} + +}} diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h new file mode 100644 index 000000000..67ad3ad5e --- /dev/null +++ b/src/Primitives/Square.h @@ -0,0 +1,39 @@ +#ifndef Magnum_Primitives_Square_h +#define Magnum_Primitives_Square_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Primitives::Square + */ + +#include "Trade/MeshData2D.h" + +namespace Magnum { namespace Primitives { + +/** +@brief %Square primitive + +2x2 square. +*/ +class Square: public Trade::MeshData2D { + public: + /** @brief Constructor */ + Square(); +}; + +}} + +#endif From 7c17871c906da2249ae8d2cb21caa8dcc767aac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 13:44:31 +0200 Subject: [PATCH 078/256] Assuming the vectors are normalized in Matrix4::rotation(). --- src/Math/Matrix4.h | 35 +++++++++++++++++++---------------- src/Math/Test/CMakeLists.txt | 3 ++- src/Math/Test/Matrix4Test.cpp | 22 ++++++++++++++-------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 487a6baa9..ac4ad1639 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -69,36 +69,39 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D rotation matrix * @param angle Rotation angle (counterclockwise, in radians) - * @param vec Rotation vector + * @param vec Normalized rotation vector * - * @see Matrix3::rotation(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), deg(), rad() - * @todo optimize - Assume the vectors are normalized? + * @see Matrix3::rotation(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis(), deg(), rad() + * @attention Assertion fails on non-normalized rotation vector and + * identity matrix is returned. */ static Matrix4 rotation(T angle, const Vector3& vec) { - Vector3 vn = vec.normalized(); + CORRADE_ASSERT(MathTypeTraits::equals(vec.dot(), T(1)), + "Math::Matrix4::rotation(): vector must be normalized", {}); T sine = std::sin(angle); T cosine = std::cos(angle); T oneMinusCosine = T(1) - cosine; - T xx = vn.x()*vn.x(); - T xy = vn.x()*vn.y(); - T xz = vn.x()*vn.z(); - T yy = vn.y()*vn.y(); - T yz = vn.y()*vn.z(); - T zz = vn.z()*vn.z(); + T xx = vec.x()*vec.x(); + T xy = vec.x()*vec.y(); + T xz = vec.x()*vec.z(); + T yy = vec.y()*vec.y(); + T yz = vec.y()*vec.z(); + T zz = vec.z()*vec.z(); return Matrix4( /* Column-major! */ cosine + xx*oneMinusCosine, - xy*oneMinusCosine + vn.z()*sine, - xz*oneMinusCosine - vn.y()*sine, + xy*oneMinusCosine + vec.z()*sine, + xz*oneMinusCosine - vec.y()*sine, T(0), - xy*oneMinusCosine - vn.z()*sine, + xy*oneMinusCosine - vec.z()*sine, cosine + yy*oneMinusCosine, - yz*oneMinusCosine + vn.x()*sine, + yz*oneMinusCosine + vec.x()*sine, T(0), - xz*oneMinusCosine + vn.y()*sine, - yz*oneMinusCosine - vn.x()*sine, + xz*oneMinusCosine + vec.y()*sine, + yz*oneMinusCosine - vec.x()*sine, cosine + zz*oneMinusCosine, T(0), T(0), T(0), T(0), T(1) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index a62ecefca..0f1e08a80 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -5,7 +5,6 @@ corrade_add_test2(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) corrade_add_test2(MathRectangularMatrixTest RectangularMatrixTest.cpp) corrade_add_test2(MathVectorTest VectorTest.cpp) -set_target_properties(MathVectorTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) corrade_add_test2(MathVector2Test Vector2Test.cpp) corrade_add_test2(MathVector3Test Vector3Test.cpp) corrade_add_test2(MathVector4Test Vector4Test.cpp) @@ -16,3 +15,5 @@ corrade_add_test2(MathPoint3DTest Point3DTest.cpp) corrade_add_test2(MathMatrixTest MatrixTest.cpp) corrade_add_test2(MathMatrix3Test Matrix3Test.cpp) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) + +set_target_properties(MathVectorTest MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 03111d207..6451585f1 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { namespace Test { typedef Math::Matrix4 Matrix4; typedef Math::Matrix3 Matrix3; +typedef Math::Vector3 Vector3; Matrix4Test::Matrix4Test() { addTests(&Matrix4Test::constructIdentity, @@ -88,14 +89,19 @@ void Matrix4Test::scaling() { } void Matrix4Test::rotation() { + ostringstream o; + Error::setOutput(&o); + + CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); + CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): vector must be normalized\n"); + Matrix4 matrix( - 0.35612214f, -0.80181062f, 0.47987163f, 0.0f, - 0.47987163f, 0.59757638f, 0.6423595f, 0.0f, - -0.80181062f, 0.0015183985f, 0.59757638f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f + 0.35612214f, -0.80181062f, 0.47987163f, 0.0f, + 0.47987163f, 0.59757638f, 0.6423595f, 0.0f, + -0.80181062f, 0.0015183985f, 0.59757638f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f ); - - CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), matrix); + CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); } void Matrix4Test::rotationScalingPart() { @@ -122,10 +128,10 @@ void Matrix4Test::rotationPart() { -0.80181062f, 0.0015183985f, 0.59757638f ); - Matrix4 rotation = Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}); + Matrix4 rotation = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); - Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3(9.0f)); + Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3(9.0f)); CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); } From 03f135e696fb7dd28a94c15f46d99d9b5b1e9057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 13:45:35 +0200 Subject: [PATCH 079/256] Documentation clarification, assertion update. Don't yell at the user all the time. --- src/Math/Test/VectorTest.cpp | 2 +- src/Math/Vector.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 7a3ef084b..5a93d3924 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -110,7 +110,7 @@ void VectorTest::angle() { Error::setOutput(&o); /* Both vectors must be normalized, otherwise NaN is returned */ CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), numeric_limits::quiet_NaN()); - CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized!\n"); + CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), numeric_limits::quiet_NaN()); CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), rad(1.162514f)); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 9d78a10ca..b3ec031a2 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -85,12 +85,12 @@ template class Vector: public RectangularMatrix<1, s, T> { * @f[ * \phi = \frac{a \cdot b}{|a| \cdot |b|} * @f] - * @attention If any of the parameters is not normalized (and - * assertions are enabled), returns NaN. + * @attention Assertion fails on non-normalized vectors and NaN is + * returned. */ inline static T angle(const Vector& a, const Vector& b) { CORRADE_ASSERT(MathTypeTraits::equals(a.dot(), T(1)) && MathTypeTraits::equals(b.dot(), T(1)), - "Math::Vector::angle(): vectors must be normalized!", std::numeric_limits::quiet_NaN()); + "Math::Vector::angle(): vectors must be normalized", std::numeric_limits::quiet_NaN()); return std::acos(dot(a, b)); } From 391e721ac6a14eeabb76bd5671b4dc3450a1578e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 14:50:14 +0200 Subject: [PATCH 080/256] Cache-oblivious traversing order in Matrix functions. Loop through all cols, then rows, so the memory is accessed continuously. --- src/Math/Matrix.h | 9 ++++----- src/Math/RectangularMatrix.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index e799591da..3e4da4b59 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -38,7 +38,6 @@ See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} @todo @c PERFORMANCE - loop unrolling for Matrix<3, T> and Matrix<4, T> -@todo first col, then row (cache adjacency) */ template class Matrix: public RectangularMatrix { public: @@ -104,8 +103,8 @@ template class Matrix: public RectangularMatrix { Matrix ij(size_t skipCol, size_t skipRow) const { Matrix out(Matrix::Zero); - for(size_t row = 0; row != size-1; ++row) - for(size_t col = 0; col != size-1; ++col) + for(size_t col = 0; col != size-1; ++col) + for(size_t row = 0; row != size-1; ++row) out(col, row) = (*this)(col + (col >= skipCol), row + (row >= skipRow)); @@ -137,8 +136,8 @@ template class Matrix: public RectangularMatrix { T _determinant = determinant(); - for(size_t row = 0; row != size; ++row) - for(size_t col = 0; col != size; ++col) + for(size_t col = 0; col != size; ++col) + for(size_t row = 0; row != size; ++row) out(col, row) = (((row+col) & 1) ? -1 : 1)*ij(row, col).determinant()/_determinant; return out; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 770862565..ef195df05 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -281,8 +281,8 @@ template class RectangularMatrix { template RectangularMatrix operator*(const RectangularMatrix& other) const { RectangularMatrix out; - for(size_t row = 0; row != rows; ++row) - for(size_t col = 0; col != size; ++col) /** @todo swap */ + for(size_t col = 0; col != size; ++col) + for(size_t row = 0; row != rows; ++row) for(size_t pos = 0; pos != cols; ++pos) out(col, row) += (*this)(pos, row)*other(col, pos); From 5d639095ee9fc13db68bf7095d282d2588b0ce83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 14:53:15 +0200 Subject: [PATCH 081/256] Removed "wontfix" TODOs. Loop unrolling is better to leave up to the compiler, as it will do it automatically and it doesn't add any maintenance burden. Constexpr addition, multiplication etc. of Vector would be nice, but will that be really useful? Maybe once if at all? --- src/Math/Matrix.h | 1 - src/Math/Vector.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 3e4da4b59..4f9d71907 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -37,7 +37,6 @@ namespace Implementation { See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} -@todo @c PERFORMANCE - loop unrolling for Matrix<3, T> and Matrix<4, T> */ template class Matrix: public RectangularMatrix { public: diff --git a/src/Math/Vector.h b/src/Math/Vector.h index b3ec031a2..27d0c587a 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -41,7 +41,6 @@ namespace Implementation { See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} -@todo Constexprize all for loops */ template class Vector: public RectangularMatrix<1, s, T> { public: From a385441c02a7c01558b7ce1043165aeb296515d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 15:09:21 +0200 Subject: [PATCH 082/256] Moved type conversion constructor from Vector to RectangularMatrix. --- src/Math/RectangularMatrix.h | 25 ++++++++++++++++++++++++ src/Math/Test/RectangularMatrixTest.cpp | 12 ++++++++++++ src/Math/Test/RectangularMatrixTest.h | 1 + src/Math/Test/VectorTest.cpp | 11 ----------- src/Math/Test/VectorTest.h | 1 - src/Math/Vector.h | 26 ------------------------- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index ef195df05..044574fa5 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -28,6 +28,8 @@ namespace Magnum { namespace Math { +template class RectangularMatrix; + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Sequence {}; @@ -39,6 +41,11 @@ namespace Implementation { template struct GenerateSequence<0, sequence...> { typedef Sequence Type; }; + + /* Implementation for RectangularMatrix::from(const RectangularMatrix&) */ + template inline constexpr Math::RectangularMatrix rectangularMatrixFrom(Sequence, const Math::RectangularMatrix& matrix) { + return {T(matrix.data()[sequence])...}; + } } #endif @@ -89,6 +96,21 @@ template class RectangularMatrix { return from(typename Implementation::GenerateSequence::Type(), first, next...); } + /** + * @brief %Matrix from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * RectangularMatrix<4, 1, int> integral(RectangularMatrix<4, 1, int>::from(floatingPoint)); + * // integral == {1, 2, -15, 7} + * @endcode + */ + template inline constexpr static RectangularMatrix from(const RectangularMatrix& other) { + return Implementation::rectangularMatrixFrom(typename Implementation::GenerateSequence::Type(), other); + } + /** @brief Zero-filled matrix constructor */ inline constexpr RectangularMatrix(): _data() {} @@ -383,6 +405,9 @@ template Corrade::Utility::Debug operator<<(C } \ template inline constexpr static __VA_ARGS__ from(const Math::Vector& first, const U&... next) { \ return Math::RectangularMatrix::from(first, next...); \ + } \ + template inline constexpr static RectangularMatrix from(const Math::RectangularMatrix& other) { \ + return Math::RectangularMatrix::from(other); \ } \ \ inline __VA_ARGS__& operator=(const Math::RectangularMatrix& other) { \ diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index da0762179..b575941c7 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -29,11 +29,13 @@ namespace Magnum { namespace Math { namespace Test { typedef RectangularMatrix<4, 3, float> Matrix4x3; typedef RectangularMatrix<3, 4, float> Matrix3x4; typedef RectangularMatrix<2, 2, float> Matrix2; +typedef RectangularMatrix<2, 2, int> Matrix2i; typedef Vector<4, float> Vector4; RectangularMatrixTest::RectangularMatrixTest() { addTests(&RectangularMatrixTest::construct, &RectangularMatrixTest::constructFromVectors, + &RectangularMatrixTest::constructFrom, &RectangularMatrixTest::constructZero, &RectangularMatrixTest::data, @@ -76,6 +78,16 @@ void RectangularMatrixTest::constructFromVectors() { CORRADE_COMPARE(actual, expected); } + +void RectangularMatrixTest::constructFrom() { + Matrix2 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + Matrix2 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); + Matrix2i integral(1, 2, -15, 7); + + CORRADE_COMPARE(Matrix2i::from(floatingPoint), integral); + CORRADE_COMPARE(Matrix2::from(integral), floatingPointRounded); +} + void RectangularMatrixTest::constructZero() { Matrix4x3 zero; diff --git a/src/Math/Test/RectangularMatrixTest.h b/src/Math/Test/RectangularMatrixTest.h index 0eae0204a..469762177 100644 --- a/src/Math/Test/RectangularMatrixTest.h +++ b/src/Math/Test/RectangularMatrixTest.h @@ -25,6 +25,7 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester Vector4; -typedef Vector<4, int> Vector4i; typedef Vector<3, float> Vector3; VectorTest::VectorTest() { addTests(&VectorTest::construct, - &VectorTest::constructFrom, &VectorTest::dot, &VectorTest::multiplyDivideComponentWise, &VectorTest::dotSelf, @@ -55,15 +53,6 @@ void VectorTest::construct() { CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f)); } -void VectorTest::constructFrom() { - Vector4 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); - Vector4i integral(1, 2, -15, 7); - - CORRADE_COMPARE(Vector4i::from(floatingPoint), integral); - CORRADE_COMPARE(Vector4::from(integral), floatingPointRounded); -} - void VectorTest::dot() { CORRADE_COMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f); } diff --git a/src/Math/Test/VectorTest.h b/src/Math/Test/VectorTest.h index e31af0aa0..1af4b7122 100644 --- a/src/Math/Test/VectorTest.h +++ b/src/Math/Test/VectorTest.h @@ -24,7 +24,6 @@ class VectorTest: public Corrade::TestSuite::Tester { VectorTest(); void construct(); - void constructFrom(); void dot(); void multiplyDivideComponentWise(); void dotSelf(); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 27d0c587a..e427c6098 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -23,17 +23,6 @@ namespace Magnum { namespace Math { -template class Vector; - -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - /* Implementation for Vector::from(const Vector&) */ - template inline constexpr Math::Vector vectorFrom(Sequence, const Math::Vector& vector) { - return {T(vector[sequence])...}; - } -} -#endif - /** @brief %Vector @tparam s %Vector size @@ -46,21 +35,6 @@ template class Vector: public RectangularMatrix<1, s, T> { public: const static size_t size = s; /**< @brief %Vector size */ - /** - * @brief %Vector from another of different type - * - * Performs only default casting on the values, no rounding or - * anything else. Example usage: - * @code - * Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * Vector<4, int> integral(Vector<4, int>::from(floatingPoint)); - * // integral == {1, 2, -15, 7} - * @endcode - */ - template inline constexpr static Vector from(const Vector& other) { - return Implementation::vectorFrom(typename Implementation::GenerateSequence::Type(), other); - } - /** * @brief Dot product * From 67c83507be9d05535330025c1c679db5d36f9fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Sep 2012 11:20:15 +0200 Subject: [PATCH 083/256] Added simple guide for contributions. --- CONTRIBUTING.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..d55a03a71 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,49 @@ +Bug reports, feature requests or code contributions are always very welcome. +To make things easier, here are a few tips: + +Reporting bugs, requesting features +----------------------------------- + +- Best way to report bugs and request new features is to use GitHub + [issues](https://github.com/mosra/magnum/issues), but you can contact me + also any other way. + +Code contribution +----------------- + +- Building and installing Magnum is described in the + [documentation](http://mosra.cz/blog/magnum-doc/building.html). +- Follow the project coding guidelines. In short - try to match style of + surrounding code and avoid any trailing whitespace. When in doubt, consult + coding guidelines, which are available also + [online](http://mosra.cz/blog/magnum-doc/coding-style.html). +- Document your code. When updating or adding new API, make sure that Doxygen + documentation is up to date. Run + + doxygen + + in project root to generate the documentation and check that your + modifications didn't add any warnings. +- Build unit tests (`-DBUILD_TESTS=ON` parameter to CMake) and run them + using + + ctest --output-on-failure + + in build directory. All tests should always pass. Add new tests or modify + the existing to make sure new code is properly covered (if possible). Here + is a [short tutorial](http://mosra.cz/blog/corrade-doc/unit-testing.html) to + help you with creating unit tests. +- Best way to contribute is by using GitHub + [pull requests](https://github.com/mosra/magnum/pulls) - fork the repository + and make pull request from feature branch. You can also send patches via + e-mail or contact me any other way. +- All your code will be released under license of the project, so make sure + you (or your employers) have no problems with it. + +Contact +------- + +- Website - http://mosra.cz/blog/ +- GitHub - https://github.com/mosra/magnum +- E-mail - mosra@centrum.cz +- Jabber - mosra@jabbim.cz From 04829da616dd4c48a293eff726605c7804695705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Sep 2012 22:44:45 +0200 Subject: [PATCH 084/256] Mesh::setFrontFace() should be static (and inline). --- src/Mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mesh.h b/src/Mesh.h index faeaf4642..61001fcfe 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -71,7 +71,7 @@ class MAGNUM_EXPORT Mesh { * Initial value is `FrontFace::%CounterClockWise`. * @see @fn_gl{FrontFace} */ - void setFrontFace(FrontFace mode) { + inline static void setFrontFace(FrontFace mode) { glFrontFace(static_cast(mode)); } From 02f0de619a3ca60a8eb9c78128aa066f84c56dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Sep 2012 23:38:36 +0200 Subject: [PATCH 085/256] Method chaining for Mesh. --- src/IndexedMesh.h | 23 ++++++++++++++++++----- src/Mesh.h | 18 ++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index f7ad05992..aba64e2d8 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -51,15 +51,28 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } - /** @brief Set index count */ - /** @todo definalize after that? */ - inline void setIndexCount(GLsizei count) { _indexCount = count; } + /** + * @brief Set index count + * @return Pointer to self (for method chaining) + * + * @todo definalize after that? + */ + inline IndexedMesh* setIndexCount(GLsizei count) { + _indexCount = count; + return this; + } /** @brief Index type */ inline Type indexType() const { return _indexType; } - /** @brief Set index type */ - inline void setIndexType(Type type) { _indexType = type; } + /** + * @brief Set index type + * @return Pointer to self (for method chaining) + */ + inline IndexedMesh* setIndexType(Type type) { + _indexType = type; + return this; + } /** * @brief Index buffer diff --git a/src/Mesh.h b/src/Mesh.h index 61001fcfe..a9cf40985 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -348,20 +348,28 @@ class MAGNUM_EXPORT Mesh { /** @brief Primitive type */ inline Primitive primitive() const { return _primitive; } - /** @brief Set primitive type */ - inline void setPrimitive(Primitive primitive) { _primitive = primitive; } + /** + * @brief Set primitive type + * @return Pointer to self (for method chaining) + */ + inline Mesh* setPrimitive(Primitive primitive) { + _primitive = primitive; + return this; + } /** @brief Vertex count */ inline GLsizei vertexCount() const { return _vertexCount; } /** * @brief Set vertex count + * @return Pointer to self (for method chaining) * * This forces recalculation of attribute positions upon next drawing. */ - inline void setVertexCount(GLsizei vertexCount) { + inline Mesh* setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; finalized = false; + return this; } /** @@ -392,14 +400,16 @@ class MAGNUM_EXPORT Mesh { * @tparam attribute Attribute, defined in the shader * @param buffer Buffer where bind the attribute to (pointer * returned by addBuffer()) + * @return Pointer to self (for method chaining) * * Binds attribute of given type with given buffer. If the attribute is * already bound, given buffer isn't managed with this mesh (wasn't * initialized with addBuffer) or the mesh was already drawn, the * function does nothing. */ - template inline void bindAttribute(Buffer* buffer) { + template inline Mesh* bindAttribute(Buffer* buffer) { bindAttribute(buffer, Attribute::Location, TypeTraits::count(), TypeTraits::type()); + return this; } /** From e99a63f38e7cd673453dbbffec78c377f2770ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Sep 2012 23:42:09 +0200 Subject: [PATCH 086/256] Doc++ --- src/SceneGraph/Object.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index b8422a84e..ffbf86042 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -127,7 +127,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra /** * @brief %Scene - * @return If the object is not assigned to any scene, returns nullptr. + * @return %Scene or `nullptr`, if the object is not part of any scene. */ SceneType* scene(); @@ -149,7 +149,10 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra /** @brief Last child object or `nullptr`, if this object has no children */ inline ObjectType* lastChild() { return Corrade::Containers::LinkedList::last(); } - /** @brief Set parent object */ + /** + * @brief Set parent object + * @return Pointer to self (for method chaining) + */ ObjectType* setParent(ObjectType* parent); /*@}*/ @@ -187,13 +190,17 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra */ virtual MatrixType absoluteTransformation(CameraType* camera = nullptr); - /** @brief Set transformation */ + /** + * @brief Set transformation + * @return Pointer to self (for method chaining) + */ ObjectType* setTransformation(const MatrixType& transformation); /** * @brief Multiply transformation * @param transformation Transformation * @param type Transformation type + * @return Pointer to self (for method chaining) */ inline ObjectType* multiplyTransformation(const MatrixType& transformation, Transformation type = Transformation::Global) { setTransformation(type == Transformation::Global ? From f6371067276cad0381ad692768cb3a6f33db1ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 21 Sep 2012 14:27:04 +0200 Subject: [PATCH 087/256] Initial version of resource manager. --- src/CMakeLists.txt | 1 + src/ResourceManager.h | 540 +++++++++++++++++++++++++++++++ src/Test/CMakeLists.txt | 3 + src/Test/ResourceManagerTest.cpp | 119 +++++++ src/Test/ResourceManagerTest.h | 51 +++ 5 files changed, 714 insertions(+) create mode 100644 src/ResourceManager.h create mode 100644 src/Test/ResourceManagerTest.cpp create mode 100644 src/Test/ResourceManagerTest.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 651eabbdb..debd4c69e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,7 @@ set(Magnum_HEADERS Profiler.h Query.h Renderbuffer.h + ResourceManager.h Shader.h SizeTraits.h Swizzle.h diff --git a/src/ResourceManager.h b/src/ResourceManager.h new file mode 100644 index 000000000..06ac7a99c --- /dev/null +++ b/src/ResourceManager.h @@ -0,0 +1,540 @@ +#ifndef Magnum_ResourceManager_h +#define Magnum_ResourceManager_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::ResourceManager, Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState, Magnum::ResourceDataState, Magnum::ResourcePolicy + */ + +#include +#include + +namespace Magnum { + +/** + * @brief %Resource state + * + * @see Resource::state(), ResourceManager::state() + */ +enum class ResourceState { + /** The resource is not yet loaded. */ + NotLoaded, + + /** The resource is not yet loaded and fallback resource is used instead. */ + Fallback, + + /** The resource is loaded, but can be changed by the manager at any time. */ + Mutable, + + /** The resource is loaded and won't be changed by the manager anymore. */ + Final +}; + +/** + * @brief %Resource data state + * + * @see ResourceManager::set() + */ +enum class ResourceDataState { + /** + * The resource can be changed by the manager in the future. This is + * slower, as Resource needs to ask the manager for new version every time + * the data are accessed, but allows changing the data for e.g. debugging + * purposes. + */ + Mutable = ResourceState::Mutable, + + /** + * The resource cannot be changed by the manager in the future. This is + * faster, as Resource instances will ask for the data only one time, thus + * suitable for production code. + */ + Final = ResourceState::Final +}; + +/** +@brief %Resource policy + +@see ResourceManager::set(), ResourceManager::free() + */ +enum class ResourcePolicy { + /** The resource will stay resident for whole lifetime of resource manager. */ + Resident, + + /** + * The resource will be unloaded when manually calling + * ResourceManager::free() if nothing references it. + */ + Manual, + + /** The resource will be unloaded when last reference to it is gone. */ + ReferenceCounted +}; + +/** +@brief Key for accessing resource + +@see ResourceManager::referenceCount(), ResourceManager::state(), + ResourceManager::get(), ResourceManager::set() +*/ +class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { + public: + /** + * @brief Default constructor + * + * The same as calling other constructors with empty string. + */ + inline ResourceKey(): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()("")) {} + + /** @brief Constructor */ + inline ResourceKey(const std::string& key): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} + + /** + * @brief Constructor + * @todo constexpr + */ + template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} +}; + +template class Resource; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + struct ResourceKeyHash { + inline size_t operator()(ResourceKey key) const { + return *reinterpret_cast(key.byteArray()); + } + }; + + template class ResourceManagerData { + ResourceManagerData(const ResourceManagerData&) = delete; + ResourceManagerData(ResourceManagerData&&) = delete; + ResourceManagerData& operator=(const ResourceManagerData&) = delete; + ResourceManagerData& operator=(ResourceManagerData&&) = delete; + + public: + struct Data { + Data(const Data&) = delete; + Data& operator=(const Data&) = delete; + Data& operator=(Data&&) = delete; + + inline Data(): data(nullptr), state(ResourceDataState::Mutable), policy(ResourcePolicy::Manual), referenceCount(0) {} + + Data(Data&& other): data(other.data), state(other.state), policy(other.policy), referenceCount(other.referenceCount) { + other.data = nullptr; + other.referenceCount = 0; + } + + ~Data() { + CORRADE_ASSERT(referenceCount == 0, "ResourceManager: cannot destruct it while data are still referenced", ); + delete data; + } + + T* data; + ResourceDataState state; + ResourcePolicy policy; + size_t referenceCount; + }; + + inline virtual ~ResourceManagerData() { + delete _fallback; + } + + inline size_t lastChange() const { return _lastChange; } + + inline size_t count() const { return _data.size(); } + + size_t referenceCount(ResourceKey key) const { + auto it = _data.find(key); + if(it == _data.end()) return 0; + return it->second.referenceCount; + } + + ResourceState state(ResourceKey key) const { + auto it = _data.find(key); + if(it == _data.end() || !it->second.data) + return _fallback ? ResourceState::Fallback : ResourceState::NotLoaded; + else + return static_cast(it->second.state); + } + + template inline Resource get(ResourceKey key) { + return Resource(this, key); + } + + void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { + auto it = _data.find(key); + + /* Cannot change resource with already final state */ + CORRADE_ASSERT(it == _data.end() || it->second.state != ResourceDataState::Final, "ResourceManager: cannot change already final resource", ); + + /* If nothing is referencing reference-counted resource, we're done */ + if(policy == ResourcePolicy::ReferenceCounted && (it == _data.end() || it->second.referenceCount == 0)) { + Corrade::Utility::Warning() << "ResourceManager: Reference-counted resource with key" << key << "isn't referenced from anywhere, deleting it immediately"; + delete data; + + /* Delete also already present resource (it could be here + because previous policy could be other than + ReferenceCounted) */ + if(it != _data.end()) _data.erase(it); + + return; + + /* Insert it, if not already here */ + } else if(it == _data.end()) + it = _data.insert(std::make_pair(key, Data())).first; + + /* Replace previous data */ + delete it->second.data; + it->second.data = data; + it->second.state = state; + it->second.policy = policy; + ++_lastChange; + } + + inline void setFallback(T* data) { + delete _fallback; + _fallback = data; + } + + void free() { + /* Delete all non-referenced non-resident resources */ + for(auto it = _data.begin(); it != _data.end(); ) { + if(it->second.policy != ResourcePolicy::Resident && !it->second.referenceCount) + it = _data.erase(it); + else ++it; + } + } + + inline T* fallback() const { return _fallback; } + + inline const Data& data(ResourceKey key) { + return _data[key]; + } + + inline void incrementReferenceCount(ResourceKey key) { + ++_data[key].referenceCount; + } + + inline void decrementReferenceCount(ResourceKey key) { + auto it = _data.find(key); + + /* Free the resource if it is reference counted */ + if(--it->second.referenceCount == 0 && it->second.policy == ResourcePolicy::ReferenceCounted) + _data.erase(it); + } + + protected: + inline ResourceManagerData(): _fallback(nullptr), _lastChange(0) {} + + private: + std::unordered_map _data; + T* _fallback; + size_t _lastChange; + }; +} +#endif + +/** +@brief %Resource reference + +See ResourceManager for more information. +*/ +template class Resource { + friend class Implementation::ResourceManagerData; + + public: + /** + * @brief Default constructor + * + * Creates empty resource. Resources are acquired from the manager by + * calling ResourceManager::get(). + */ + inline Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {} + + /** @brief Copy constructor */ + inline Resource(const Resource& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + if(manager) manager->incrementReferenceCount(key); + } + + /** @brief Destructor */ + inline ~Resource() { + if(manager) manager->decrementReferenceCount(key); + } + + /** @brief Assignment operator */ + Resource& operator=(const Resource& other) { + if(manager) manager->decrementReferenceCount(key); + + manager = other.manager; + key = other.key; + lastCheck = other.lastCheck; + _state = other._state; + data = other.data; + + if(manager) manager->incrementReferenceCount(key); + return *this; + } + + /** + * @brief %Resource state + * + * @see operator bool() + */ + inline ResourceState state() { + acquire(); + return _state; + } + + /** + * @brief Whether the resource is available + * @return False when resource is not loaded and no fallback is + * available, true otherwise. + * + * @see state() + */ + inline operator bool() { + acquire(); + return data; + } + + /** @brief %Resource data */ + inline U& operator*() { + acquire(); + return *static_cast(data); + } + + /** @brief %Resource data */ + inline U* operator->() { + acquire(); + return static_cast(data); + } + + private: + inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), key(key), lastCheck(0) { + manager->incrementReferenceCount(key); + } + + void acquire() { + /* The data are already final, nothing to do */ + if(_state == ResourceState::Final) return; + + /* Nothing changed since last check */ + if(manager->lastChange() < lastCheck) return; + + /* Acquire new data and save last check time */ + const typename Implementation::ResourceManagerData::Data& d = manager->data(key); + lastCheck = manager->lastChange(); + + /* Try to get the data */ + if((data = d.data)) + _state = static_cast(d.state); + else if((data = manager->fallback())) + _state = ResourceState::Fallback; + else + _state = ResourceState::NotLoaded; + } + + Implementation::ResourceManagerData* manager; + ResourceKey key; + size_t lastCheck; + ResourceState _state; + T* data; +}; + +/** +@brief %Resource manager + +Provides storage for arbitrary set of types, accessible globally using +instance(). + +Each resource is referenced from Resource class. For optimizing performance, +each resource can be set as mutable or final. Mutable resources can be +modified by the manager and thus each %Resource instance asks the manager for +modifications on each access. On the other hand, final resources cannot be +modified by the manager, so %Resource instances don't have to ask the manager +every time, which is faster. + +It's possible to provide fallback for resources which are not available using +setFallback(). Accessing data of such resources will access the fallback +instead of failing on null pointer dereference. Availability and state of each +resource can be queried through function state() on the manager or +Resource::state() on each resource. + +The resources can be managed in three ways - resident resources, which stay in +memory for whole lifetime of the manager, manually managed resources, which +can be deleted by calling free() if nothing references them anymore, and +reference counted resources, which are deleted as soon as the last reference +to them is removed. + +%Resource state and policy is configured when setting the resource data in +set() and can be changed each time the data are updated, although already +final resources cannot obviously be set as mutable again. + +Basic usage is: +- Typedef'ing manager of desired types, creating its instance. +@code +typedef ResourceManager MyResourceManager; +MyResourceManager manager; +@endcode +- Filling the manager with resource data and acquiring the resources. Note + that a resource can be acquired with get() even before the manager contains + the data for it, as long as the resource data are not accessed (or fallback + is provided). +@code +MyResourceManager* manager = MyResourceManager::instance(); +Resource texture(manager->get("texture")); +Resource shader(manager->get("shader")); +Resource cube(manager->get("cube")); + +// The manager doesn't have data for the mesh yet, add them +if(!mesh) { + Mesh* mesh = new Mesh; + // ... + manager->set("cube", mesh, ResourceDataState::Final, ResourcePolicy::Resident); +} +@endcode +- Using the resource data. +@code +shader->use(); +texture->bind(); +cube->draw(); +@endcode +- Destroying resource references and deleting manager instance when nothing + references the resources anymore. +*/ +template class ResourceManager: protected Implementation::ResourceManagerData... { + public: + /** @brief Global instance */ + inline static ResourceManager* instance() { return _instance; } + + /** + * @brief Constructor + * + * Sets global instance pointer to itself. + * @attention Only one instance of given ResourceManager type can be + * created. + * @see instance() + */ + inline ResourceManager() { + CORRADE_ASSERT(!_instance, "ResourceManager: another instance is already created!", ); + _instance = this; + } + + /** + * @brief Destructor + * + * Sets global instance pointer to `nullptr`. + * @see instance() + */ + inline ~ResourceManager() { _instance = nullptr; } + + /** @brief Count of resources of given type */ + template inline size_t count() { + return this->Implementation::ResourceManagerData::count(); + } + + /** + * @brief Get resource reference + * + * In some cases it's desirable to store various different types under + * one base type for memory efficiency reasons. To avoid putting the + * responsibility of proper casting on the user, the acquired resource + * can be defined to cast the type automatically when accessing the + * data. This is commonly used for shaders, e.g.: + * @code + * Resource shader = manager->get("shader"); + * @endcode + */ + template inline Resource get(ResourceKey key) { + return this->Implementation::ResourceManagerData::template get(key); + } + + /** + * @brief Reference count of given resource + * + * @see set() + */ + template inline size_t referenceCount(ResourceKey key) const { + return this->Implementation::ResourceManagerData::referenceCount(key); + } + + /** + * @brief %Resource state + * + * @see set(), Resource::state() + */ + template inline ResourceState state(ResourceKey key) const { + return this->Implementation::ResourceManagerData::state(key); + } + + /** + * @brief Set resource data + * + * If @p policy is set to `ResourcePolicy::ReferenceCounted`, there + * must be already at least one reference to given resource, otherwise + * the data will be deleted immediately and no resource will be + * added. To avoid spending unnecessary loading time, add + * reference-counted resources only if they are already referenced: + * @code + * if(manager.referenceCount("myresource")) { + * // load data... + * manager.set("myresource", data, state, ResourcePolicy::ReferenceCounted); + * } + * @endcode + * @attention If resource state is already `ResourceState::Final`, + * subsequent updates are not possible. + * @see referenceCount(), state() + */ + template inline void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { + this->Implementation::ResourceManagerData::set(key, data, state, policy); + } + + /** @brief Set fallback for not found resources */ + template inline void setFallback(T* data) { + return this->Implementation::ResourceManagerData::setFallback(data); + } + + /** @brief Free all resources of given type which are not referenced */ + template inline void free() { + return this->Implementation::ResourceManagerData::free(); + } + + /** @brief Free all resources which are not referenced */ + inline void free() { + freeInternal(std::common_type()...); + } + + private: + template inline void freeInternal(std::common_type, std::common_type... t) { + free(); + freeInternal(t...); + } + inline void freeInternal() const {} + + static ResourceManager* _instance; +}; + +/** @debugoperator{Magnum::ResourceKey} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { + return debug << static_cast&>(value); +} + +template ResourceManager* ResourceManager::_instance(nullptr); + +} + +#endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index f86d239e8..87e9f71e2 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,2 +1,5 @@ corrade_add_test2(ColorTest ColorTest.cpp) +corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp) corrade_add_test2(SwizzleTest SwizzleTest.cpp) + +set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp new file mode 100644 index 000000000..872dfefa1 --- /dev/null +++ b/src/Test/ResourceManagerTest.cpp @@ -0,0 +1,119 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ResourceManagerTest.h" + +#include + +#include "ResourceManager.h" + +using namespace std; +using namespace Corrade::Utility; + +CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest) + +namespace Magnum { namespace Test { + +size_t Data::count = 0; + +ResourceManagerTest::ResourceManagerTest() { + rm = new ResourceManager; + + addTests(&ResourceManagerTest::state, + &ResourceManagerTest::referenceCountedPolicy, + &ResourceManagerTest::manualPolicy, + &ResourceManagerTest::destroy); +} + +void ResourceManagerTest::state() { + ResourceKey questionKey("the-question"); + rm->set(questionKey, new int(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + Resource theQuestion = rm->get(questionKey); + CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); + CORRADE_COMPARE(*theQuestion, 10); + + /* Check that hash function is working properly */ + ResourceKey answerKey("the-answer"); + rm->set(answerKey, new int(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theAnswer = rm->get(answerKey); + CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); + CORRADE_COMPARE(*theAnswer, 42); + + CORRADE_COMPARE(rm->count(), 2); + + /* Cannot change already final resource */ + stringstream out; + Error::setOutput(&out); + rm->set(answerKey, new int(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + CORRADE_COMPARE(*theAnswer, 42); + CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n"); + + /* Check non-final resource changes */ + rm->set(questionKey, new int(20), ResourceDataState::Final, ResourcePolicy::Resident); + CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); + CORRADE_COMPARE(*theQuestion, 20); +} + +void ResourceManagerTest::referenceCountedPolicy() { + ResourceKey dataRefCountKey("dataRefCount"); + + /* Reference counted resources must be requested first */ + { + rm->set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); + CORRADE_COMPARE(rm->count(), 0); + Resource data = rm->get(dataRefCountKey); + CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + CORRADE_COMPARE(Data::count, 0); + } { + Resource data = rm->get(dataRefCountKey); + CORRADE_COMPARE(rm->count(), 1); + CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + rm->set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); + CORRADE_VERIFY(data.state() == ResourceState::Final); + CORRADE_COMPARE(Data::count, 1); + } + + CORRADE_COMPARE(rm->count(), 0); + CORRADE_COMPARE(Data::count, 0); +} + +void ResourceManagerTest::manualPolicy() { + ResourceKey dataKey("data"); + + /* Manual free */ + { + rm->set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); + Resource data = rm->get(dataKey); + rm->free(); + } + + CORRADE_COMPARE(rm->count(), 1); + CORRADE_COMPARE(Data::count, 1); + rm->free(); + CORRADE_COMPARE(rm->count(), 0); + CORRADE_COMPARE(Data::count, 0); + + rm->set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); + CORRADE_COMPARE(rm->count(), 1); + CORRADE_COMPARE(Data::count, 1); +} + +void ResourceManagerTest::destroy() { + delete rm; + rm = nullptr; + CORRADE_COMPARE(Data::count, 0); +} + +}} diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h new file mode 100644 index 000000000..2f5ba5243 --- /dev/null +++ b/src/Test/ResourceManagerTest.h @@ -0,0 +1,51 @@ +#ifndef Magnum_Test_ResourceManagerTest_h +#define Magnum_Test_ResourceManagerTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { + +template class ResourceManager; + +namespace Test { + +class Data { + public: + static size_t count; + + inline Data() { ++count; } + inline ~Data() { --count; } +}; + +typedef Magnum::ResourceManager ResourceManager; + +class ResourceManagerTest: public Corrade::TestSuite::Tester { + public: + ResourceManagerTest(); + + void state(); + void referenceCountedPolicy(); + void manualPolicy(); + void destroy(); + + private: + ResourceManager* rm; +}; + +}} + +#endif From 71784a777c922f932a45e1d0e4416a099ae6e1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Sep 2012 12:28:32 +0200 Subject: [PATCH 088/256] Functions for getting 2D rotation and scaling part of 3x3 matrix. Crosslinked the documentation with 2D/3D alternatives and "setters"/"getters". --- src/Math/Matrix3.h | 30 ++++++++++++++++++++++++++++-- src/Math/Matrix4.h | 23 ++++++++++++++++++----- src/Math/Test/Matrix3Test.cpp | 32 ++++++++++++++++++++++++++++++++ src/Math/Test/Matrix3Test.h | 2 ++ 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 09dacfddb..2b00d3239 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -52,7 +52,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D scaling matrix * @param vec Scaling vector * - * @see Matrix4::scaling(), Vector2::xScale(), Vector2::yScale() + * @see rotationScaling() const, Matrix4::scaling(const Vector3&), + * Vector2::xScale(), Vector2::yScale() */ inline constexpr static Matrix3 scaling(const Vector2& vec) { return Matrix3( /* Column-major! */ @@ -66,7 +67,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 3D rotation matrix * @param angle Rotation angle (counterclockwise, in radians) * - * @see Matrix4::rotation(), deg(), rad() + * @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), + * rad() */ static Matrix3 rotation(T angle) { return Matrix3( /* Column-major! */ @@ -96,6 +98,30 @@ template class Matrix3: public Matrix<3, T> { /** @brief Copy constructor */ inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} + /** + * @brief 2D rotation and scaling part of the matrix + * + * Upper-left 2x2 part of the matrix. + * @see rotation() const, rotation(T), Matrix4::rotationScaling() const + */ + inline Matrix<2, T> rotationScaling() const { + return Matrix<2, T>::from( + (*this)[0].xy(), + (*this)[1].xy()); + } + + /** + * @brief 2D rotation part of the matrix + * + * Normalized upper-left 2x2 part of the matrix. + * @see rotationScaling() const, rotation(T), Matrix4::rotation() const + */ + inline Matrix<2, T> rotation() const { + return Matrix<2, T>::from( + (*this)[0].xy().normalized(), + (*this)[1].xy().normalized()); + } + MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(3, 3, Matrix3) }; diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index ac4ad1639..1090974db 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -55,7 +55,8 @@ template class Matrix4: public Matrix<4, T> { * @brief 3D scaling matrix * @param vec Scaling vector * - * @see Matrix3::scaling(), Vector3::xScale(), Vector3::yScale(), Vector3::zScale() + * @see rotationScaling() const, Matrix3::scaling(const Vector2&), + * Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ inline constexpr static Matrix4 scaling(const Vector3& vec) { return Matrix4( /* Column-major! */ @@ -71,8 +72,8 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * @param vec Normalized rotation vector * - * @see Matrix3::rotation(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis(), deg(), rad() + * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() * @attention Assertion fails on non-normalized rotation vector and * identity matrix is returned. */ @@ -132,7 +133,13 @@ template class Matrix4: public Matrix<4, T> { /** @copydoc Matrix::ij() */ inline Matrix3 ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); } - /** @brief Rotation and scaling part of the matrix */ + /** + * @brief 3D rotation and scaling part of the matrix + * + * Upper-left 3x3 part of the matrix. + * @see rotation() const, rotation(T, const Vector3&), + * Matrix3::rotationScaling() const + */ inline Matrix3 rotationScaling() const { return Matrix3::from( (*this)[0].xyz(), @@ -140,7 +147,13 @@ template class Matrix4: public Matrix<4, T> { (*this)[2].xyz()); } - /** @brief Rotation part of the matrix */ + /** + * @brief 3D rotation part of the matrix + * + * Normalized upper-left 3x3 part of the matrix. + * @see rotationScaling() const, rotation(T, const Vector3&), + * Matrix3::rotation() const + */ inline Matrix3 rotation() const { return Matrix3::from( (*this)[0].xyz().normalized(), diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 225b62171..cdffde3bf 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -28,12 +28,16 @@ using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { typedef Math::Matrix3 Matrix3; +typedef Math::Matrix<2, float> Matrix2; +typedef Math::Vector2 Vector2; Matrix3Test::Matrix3Test() { addTests(&Matrix3Test::constructIdentity, &Matrix3Test::translation, &Matrix3Test::scaling, &Matrix3Test::rotation, + &Matrix3Test::rotationScalingPart, + &Matrix3Test::rotationPart, &Matrix3Test::debug, &Matrix3Test::configuration); } @@ -90,6 +94,34 @@ void Matrix3Test::rotation() { CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix); } +void Matrix3Test::rotationScalingPart() { + Matrix3 m( + 3.0f, 5.0f, 8.0f, + 4.0f, 4.0f, 7.0f, + 7.0f, -1.0f, 8.0f + ); + + Matrix2 expected( + 3.0f, 5.0f, + 4.0f, 4.0f + ); + + CORRADE_COMPARE(m.rotationScaling(), expected); +} + +void Matrix3Test::rotationPart() { + Matrix2 expectedRotationPart( + 0.965926f, 0.258819f, + -0.258819f, 0.965926f + ); + + Matrix3 rotation = Matrix3::rotation(deg(15.0f)); + CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); + + Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f)); + CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); +} + void Matrix3Test::debug() { Matrix3 m( 3.0f, 5.0f, 8.0f, diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index 2402fbc93..6f71f41e3 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -28,6 +28,8 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void translation(); void scaling(); void rotation(); + void rotationScalingPart(); + void rotationPart(); void debug(); void configuration(); From fb70ef046ab18ff5b41660b9e430f30d77ab763d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Sep 2012 12:30:11 +0200 Subject: [PATCH 089/256] Functions for getting translation part of the matrix. --- src/Math/Matrix3.h | 18 +++++++++++++++++- src/Math/Matrix4.h | 18 +++++++++++++++++- src/Math/Test/Matrix3Test.cpp | 9 +++++++++ src/Math/Test/Matrix3Test.h | 1 + src/Math/Test/Matrix4Test.cpp | 10 ++++++++++ src/Math/Test/Matrix4Test.h | 1 + 6 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 2b00d3239..364d120fd 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -38,7 +38,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D translation matrix * @param vec Translation vector * - * @see Matrix4::translation(), Vector2::xAxis(), Vector2::yAxis() + * @see translation(), Matrix4::translation(const Vector3&), + * Vector2::xAxis(), Vector2::yAxis() */ inline constexpr static Matrix3 translation(const Vector2& vec) { return Matrix3( /* Column-major! */ @@ -122,6 +123,21 @@ template class Matrix3: public Matrix<3, T> { (*this)[1].xy().normalized()); } + /** + * @brief 2D translation part of the matrix + * + * First two elements of last column. + * @see translation(const Vector2&), Matrix4::translation() + */ + inline Vector2& translation() { + return (*this)[2].xy(); + } + + /** @overload */ + inline constexpr Vector3 translation() const { + return (*this)[2].xy(); + } + MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(3, 3, Matrix3) }; diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 1090974db..f39aa9c90 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -40,7 +40,8 @@ template class Matrix4: public Matrix<4, T> { * @brief 3D translation matrix * @param vec Translation vector * - * @see Matrix3::translation(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() + * @see translation(), Matrix3::translation(const Vector2&), + * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() */ inline constexpr static Matrix4 translation(const Vector3& vec) { return Matrix4( /* Column-major! */ @@ -161,6 +162,21 @@ template class Matrix4: public Matrix<4, T> { (*this)[2].xyz().normalized()); } + /** + * @brief 3D translation part of the matrix + * + * First three elements of last column. + * @see translation(const Vector3&), Matrix3::translation() + */ + inline Vector3& translation() { + return (*this)[3].xyz(); + } + + /** @overload */ + inline constexpr Vector3 translation() const { + return (*this)[3].xyz(); + } + MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(4, 4, Matrix4) }; diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index cdffde3bf..e2e8b8975 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -38,6 +38,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::rotation, &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, + &Matrix3Test::translationPart, &Matrix3Test::debug, &Matrix3Test::configuration); } @@ -122,6 +123,14 @@ void Matrix3Test::rotationPart() { CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); } +void Matrix3Test::translationPart() { + Matrix3 m(1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + -5.0f, 12.0f, 1.0f); + Vector2 expected(-5.0f, 12.0f); + CORRADE_COMPARE(m.translation(), expected); +} + void Matrix3Test::debug() { Matrix3 m( 3.0f, 5.0f, 8.0f, diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index 6f71f41e3..c76040678 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -30,6 +30,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void rotation(); void rotationScalingPart(); void rotationPart(); + void translationPart(); void debug(); void configuration(); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 6451585f1..fdb051277 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -38,6 +38,7 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotation, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, + &Matrix4Test::translationPart, &Matrix4Test::debug, &Matrix4Test::configuration); } @@ -135,6 +136,15 @@ void Matrix4Test::rotationPart() { CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); } +void Matrix4Test::translationPart() { + Matrix4 m(1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + -5.0f, 12.0f, 0.5f, 1.0f); + Vector3 expected(-5.0f, 12.0f, 0.5f); + CORRADE_COMPARE(m.translation(), expected); +} + void Matrix4Test::debug() { Matrix4 m( 3.0f, 5.0f, 8.0f, 4.0f, diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index a49cfddb1..9bc8dbe2b 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -30,6 +30,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotation(); void rotationScalingPart(); void rotationPart(); + void translationPart(); void debug(); void configuration(); From 55d9b5ae84954d369b58fc5334e75d86bf09aac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Sep 2012 20:02:55 +0200 Subject: [PATCH 090/256] MeshTools::interleave(): specialization for only one attribute array. Also minor documentation fixes. --- src/MeshTools/Interleave.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 64198e6fe..4f66df056 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -63,6 +63,12 @@ class Interleave { delete[] _data; } + /* Specialization for only one attribute array */ + template void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T& attribute) { + mesh->setVertexCount(attribute.size()); + buffer->setData(attribute, usage); + } + template inline static size_t attributeCount(const T& first, const U&... next) { CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0); @@ -124,7 +130,7 @@ The only requirements to attribute array type is that it must have typedef function `size()` returning count of elements. In most cases it will be `std::vector` or `std::array`. -See also interleave(Mesh*, Buffer*, Buffer::Usage, const std::vector&...), +See also interleave(Mesh*, Buffer*, Buffer::Usage, const T&...), which writes the interleaved array directly into buffer of given mesh. @attention Each passed array should have the same size, if not, resulting @@ -142,12 +148,20 @@ template inline typename std::enable_ifsetData(attribute, usage); +mesh->setVertexCount(attribute.size()); +@endcode -@attention The buffer must be set as interleaved (see Mesh::addBuffer()), - otherwise this function does nothing. Binding the attributes to shader is - left to user. +@attention If there is more than one attribute array, the buffer must be set + as interleaved (see Mesh::addBuffer()), otherwise this function does + nothing. */ template inline void interleave(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { return Implementation::Interleave()(mesh, buffer, usage, attributes...); From b53759fb213bc9d275635fb0fb46fb58ae4f21be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 00:01:43 +0200 Subject: [PATCH 091/256] Doc++ * Grouping lengthy documentation into "Feature overview" page. * Link only to example index, where all the disclaimers are. * Also minor documentation updates. --- doc/features.dox | 8 ++++++++ doc/mainpage.dox | 8 ++++---- doc/namespaces.dox | 2 +- doc/physics.dox | 7 ------- src/AbstractShaderProgram.h | 1 + 5 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 doc/features.dox delete mode 100644 doc/physics.dox diff --git a/doc/features.dox b/doc/features.dox new file mode 100644 index 000000000..27da4a060 --- /dev/null +++ b/doc/features.dox @@ -0,0 +1,8 @@ +namespace Magnum { +/** @page features Feature overview +@brief Fundamental principles and design goals + +- @subpage matrix-vector - @copybrief matrix-vector +- @subpage collision-detection - @copybrief collision-detection +*/ +} diff --git a/doc/mainpage.dox b/doc/mainpage.dox index fd394ae85..3894d8a1f 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -48,10 +48,10 @@ help you with object hierarchy, transformations and resource management. @subsection getting-started-examples Tutorials and examples -The best way to get started is to @ref examples-triangle "render your first triangle" -in step-by-step tutorial. Then you can dig deeper and try @ref example-index -"other examples", read about fundamental principles in the documentation or -start experimenting on your own! +The best way to get started is to render your first triangle in +@ref example-index "step-by-step tutorial". Then you can dig deeper and try +other examples, read about @ref features "fundamental principles" in the +documentation or start experimenting on your own! @subsection getting-started-hacking Hacking Magnum diff --git a/doc/namespaces.dox b/doc/namespaces.dox index ff7bf5656..6c1ff042a 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -90,7 +90,7 @@ Collection of shaders for testing purposes. /** @namespace Magnum::Physics @brief %Physics library -Collision detection system and rigid body objects. See @ref physics +Collision detection system and rigid body objects. See @ref collision-detection for introduction. */ diff --git a/doc/physics.dox b/doc/physics.dox deleted file mode 100644 index 6a914c457..000000000 --- a/doc/physics.dox +++ /dev/null @@ -1,7 +0,0 @@ -namespace Magnum { namespace Physics { -/** @page physics Physics library -@brief Collision detection and rigid body dynamics. - -@subpage collision-detection -*/ -}} diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 2d5b410b9..b52513f3a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -47,6 +47,7 @@ typedef Attribute<2, Vector2> TextureCoords; @endcode @todoc Output attribute location (for bindFragmentDataLocationIndexed(), referenced also from Framebuffer::mapDefaultForDraw() / Framebuffer::mapForDraw()) + - **Layers for texture uniforms** to which the textures will be bound before rendering, for example: @code From b2679d32f8e2893f063518bb5d3057f28d7f1b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 00:30:05 +0200 Subject: [PATCH 092/256] MeshTools: added transform() function. In the future it will use multithreading/GPU transform feedback for large arrays. --- src/MeshTools/CMakeLists.txt | 1 + src/MeshTools/Transform.h | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/MeshTools/Transform.h diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index 095431bf7..4fb800958 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -11,6 +11,7 @@ set(MagnumMeshTools_HEADERS Interleave.h Subdivide.h Tipsify.h + Transform.h magnumMeshToolsVisibility.h) add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h new file mode 100644 index 000000000..7e09e59ae --- /dev/null +++ b/src/MeshTools/Transform.h @@ -0,0 +1,44 @@ +#ifndef Magnum_MeshTools_Transform_h +#define Magnum_MeshTools_Transform_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::MeshTools::transform() + */ + +#include "Math/Matrix.h" + +namespace Magnum { namespace MeshTools { + +/** +@brief Transform vertices using given matrix + +Usable for mesh transformations that would otherwise negatively affect +dependent objects, such as (uneven) scaling. Example usage: + +@code +std::vector vertices; +MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices); +@endcode +*/ +template inline void transform(const Math::Matrix& matrix, U& vertices) { + for(Math::Vector& vertex: vertices) + vertex = matrix*vertex; +} + +}} + +#endif From 04d58b3dbd08fab221cec0ebe301ea27360818a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 01:53:33 +0200 Subject: [PATCH 093/256] Fixed collision detection boolean/logical operations confusion. Current implementation provided logical operations as if it were boolean operations, which is wrong. Booleans might (or might not) be implemented in the future, but currently the logical are enough. --- doc/collision-detection.dox | 60 +++++++------- src/Physics/ShapeGroup.cpp | 8 +- src/Physics/ShapeGroup.h | 119 ++++++++++++++++++---------- src/Physics/Test/ShapeGroupTest.cpp | 12 +-- 4 files changed, 120 insertions(+), 79 deletions(-) diff --git a/doc/collision-detection.dox b/doc/collision-detection.dox index bde0bd606..1544e9157 100644 --- a/doc/collision-detection.dox +++ b/doc/collision-detection.dox @@ -5,13 +5,13 @@ namespace Magnum { namespace Physics { The essential thing in collision detection is to define a complex object with collection of simple shapes, for which it is easy to detect collisions. These shapes can be either one-, two- or three-dimensional and they can be grouped -together using five different set operations. +together using various operations. @tableofcontents -@section CollisionDetectionShapeCollection Available shapes +@section collision-detection-shape-collection Available shapes -@subsection CollisionDetectionShapes1D One-dimensional shapes +@subsection collision-detection-shapes1D One-dimensional shapes - Physics::Point - @copybrief Physics::Point - Physics::Line - @copybrief Physics::Line @@ -20,11 +20,11 @@ together using five different set operations. One-dimensional shapes don't provide collision detection with each other because of numerical instability. -@subsection CollisionDetectionShapes2D Two-dimensional shapes +@subsection collision-detection-shapes2D Two-dimensional shapes - Physics::Plane - @copybrief Physics::Plane -@subsection CollisionDetectionShapes3D Three-dimensional shapes +@subsection collision-detection-shapes3D Three-dimensional shapes - Physics::Sphere - @copybrief Physics::Sphere - Physics::Capsule - @copybrief Physics::Capsule @@ -35,26 +35,30 @@ The easiest (and most efficient) shape combination for detecting collisions is point and sphere, followed by two spheres. Computing collision of two boxes is least efficient. -@section CollisionDetectionShapeGroups Creating hierarchic groups of shapes +@section collision-detection-shape-groups Creating hierarchic groups of shapes -Shapes can be grouped together using one of five set operations: complement, -union, intersection, difference and XOR. These operations are mapped to -operator~(), operator|(), operator&(), operator-() and operator^(), so for -example creating complement of union of sphere and box is simple as this: +Shapes can be grouped together using one of three available logical +operations: AND, OR and NOT. These operations are mapped to operator&&(), +operator||() and operator!(), so for example creating negation of logical OR +of line segment and point is simple as this: @code -Physics::Sphere sphere; -Physics::Box box; +Physics::LineSegment segment; +Physics::Point point; -Physics::ShapeGroup group = ~(sphere|box); +Physics::ShapeGroup group = !(segment || point); @endcode +@note Logical operations are not the same as set operations -- intersection of + two spheres will not generate any collision if they are disjoint, but + logical AND will if the object collides with both of them. + The resulting object internally stores copies of both shapes, so the original instances can be destroyed. For simple combinations appropriate resulting -shape is generated (e.g. intersection of line and three-dimensional object -can be a line segment) and stored inside ShapeGroup instead of two original +shape is generated (e.g. logical OR of point and sphere can be only the sphere, +if the point lies inside) and stored inside ShapeGroup instead of two original objects. -@subsection CollisionDetectionShapeReference Referencing the shapes for later changes +@subsection collision-detection-shape-reference Referencing the shapes for later changes Sometimes you may want to modify the shape based on changes of the object itself. In previous example all the shapes were copied into ShapeGroup, so it @@ -62,34 +66,36 @@ was not possible to change their properties such as sphere radius without recreating the group again. You can, however, explicitly pass a reference to original object, so you can change it later: @code -Physics::Sphere sphere; -Physics::Box box; +Physics::LineSegment segment; +Physics::Point point; -Physics::ShapeGroup group = ~(std::ref(sphere)|box); +Physics::ShapeGroup group = !(segment || std::ref(point)); -sphere.setRadius(2.0f); +point.setPosition({1.0f, -6.0f, 0.5f}); @endcode Note that passing a reference implies that you must not destroy the original -instance (in this case the sphere). Also because the referenced instance could +instance (in this case the point). Also because the referenced instance could change, there are no shape optimizations done, unlike above. -@subsection CollisionDetectionShapeSimplification Providing simplified version of shape for better performance +@subsection collision-detection-shape-simplification Providing simplified version of shape for better performance If there are many shapes grouped together, it might hurt performance of collision detection, because it might be testing collision with more shapes than necessary. It's then good to specify simplified version of such shape, so the collision detection is done on the original if and only if collision -was detected with the simplified shape. It is in fact intersection group - -the collision is initially detected on first (simplified) shape and then on -the other: +was detected with the simplified shape. It is in fact logical AND using +operator&&() - the collision is initially detected on first (simplified) shape +and then on the other: @code +Physics::Sphere sphere; +Physics::Box box; Physics::AxisAlignedBox simplified; -Physics::ShapeGroup object = simplified & (sphere|box); +Physics::ShapeGroup object = simplified && (sphere || box); @endcode -@section CollisionDetectionShapeCollisions Detecting shape collisions +@section collision-detection-shape-collisions Detecting shape collisions Shape pairs which have collision detection implemented can be tested for collision using operator%(), for example: diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 32aaeaeb5..4f70f0b9e 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -50,11 +50,9 @@ void ShapeGroup::applyTransformation(const Matrix4& transformation) { bool ShapeGroup::collides(const AbstractShape* other) const { switch(operation & ~RefAB) { - case Complement: return !a->collides(other); - case Union: return a->collides(other) || b->collides(other); - case Intersection: return a->collides(other) && b->collides(other); - case Difference: return a->collides(other) && !b->collides(other); - case Xor: return a->collides(other) != b->collides(other); + case And: return a->collides(other) && b->collides(other); + case Or: return a->collides(other) || b->collides(other); + case Not: return !a->collides(other); case FirstObjectOnly: return a->collides(other); default: diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 35be57000..4b56a8cb8 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -32,16 +32,19 @@ namespace Magnum { namespace Physics { #endif /** -@brief Collider group with defined set operation +@brief Shape group -Result of union, intersection, subtraction or XOR of two collider objects. +Result of logical operations on shapes. See @ref collision-detection for brief introduction. */ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT - template friend constexpr enableIfIsBaseType operator~(const T& a); - template friend constexpr enableIfIsBaseType operator~(T&& a); - template friend constexpr enableIfIsBaseType operator~(T& a); +// template friend constexpr enableIfIsBaseType operator~(const T& a); +// template friend constexpr enableIfIsBaseType operator~(T&& a); +// template friend constexpr enableIfIsBaseType operator~(T& a); + template friend constexpr enableIfIsBaseType operator!(const T& a); + template friend constexpr enableIfIsBaseType operator!(T&& a); + template friend constexpr enableIfIsBaseType operator!(T& a); #define friendOp(char) \ template friend constexpr enableIfAreBaseType operator char(const T& a, const U& b); \ @@ -53,10 +56,12 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, const U& b); \ template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, U&& b); \ template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, std::reference_wrapper b); - friendOp(|) - friendOp(&) - friendOp(-) - friendOp(^) +// friendOp(|) +// friendOp(&) +// friendOp(-) +// friendOp(^) + friendOp(&&) + friendOp(||) #undef friendOp #endif @@ -68,13 +73,16 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { RefA = 0x01, RefB = 0x02, RefAB = 0x03, - Complement = 1 << 2, - Union = 2 << 2, - Intersection = 3 << 2, - Difference = 4 << 2, - Xor = 5 << 2, - FirstObjectOnly = 6 << 2, - AlwaysFalse = 7 << 2 +// Complement = 1 << 2, +// Union = 2 << 2, +// Intersection = 3 << 2, +// Difference = 4 << 2, +// Xor = 5 << 2, + And = 6 << 2, + Or = 7 << 2, + Not = 8 << 2, + FirstObjectOnly = 9 << 2, + AlwaysFalse = 10 << 2 }; public: @@ -105,37 +113,64 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { AbstractShape* b; }; -/** @brief Complement of shape */ -template inline constexpr enableIfIsBaseType operator~(const T& a) { - return ShapeGroup(ShapeGroup::Complement, new T(a), nullptr); +// /* @brief Complement of shape */ +// template inline constexpr enableIfIsBaseType operator~(const T& a) { +// return ShapeGroup(ShapeGroup::Complement, new T(a), nullptr); +// } +// #ifndef DOXYGEN_GENERATING_OUTPUT +// template inline constexpr enableIfIsBaseType operator~(T&& a) { +// return ShapeGroup(ShapeGroup::Complement, new T(std::forward(a)), nullptr); +// } +// template inline constexpr enableIfIsBaseType operator~(T& a) { +// return ShapeGroup(ShapeGroup::Complement|ShapeGroup::RefA, &a.get(), nullptr); +// } +// #endif + +/** @relates ShapeGroup +@brief Logical NOT of shape +*/ +template inline constexpr enableIfIsBaseType operator!(const T& a) { + return ShapeGroup(ShapeGroup::Not, new T(a), nullptr); } #ifndef DOXYGEN_GENERATING_OUTPUT -template inline constexpr enableIfIsBaseType operator~(T&& a) { - return ShapeGroup(ShapeGroup::Complement, new T(std::forward(a)), nullptr); +template inline constexpr enableIfIsBaseType operator!(T&& a) { + return ShapeGroup(ShapeGroup::Not, new T(std::forward(a)), nullptr); } -template inline constexpr enableIfIsBaseType operator~(T& a) { - return ShapeGroup(ShapeGroup::Complement|ShapeGroup::RefA, &a.get(), nullptr); +template inline constexpr enableIfIsBaseType operator!(T& a) { + return ShapeGroup(ShapeGroup::Not|ShapeGroup::RefA, &a.get(), nullptr); } #endif #ifdef DOXYGEN_GENERATING_OUTPUT -/** @brief Union of two shapes */ -template inline constexpr ShapeGroup operator&(T a, U b); - -/** -@brief Intersection of two shapes - -Collision with @p a is computed first, so this operation can be also used for -providing simplified version for shape @p b. See @ref CollisionDetectionShapeGroups -for an example. +// /* @brief Union of two shapes */ +// template inline constexpr ShapeGroup operator&(T a, U b); +// +// /* @brief Intersection of two shapes */ +// template inline constexpr ShapeGroup operator&(T a, U b); +// +// /* @brief Difference of two shapes */ +// template inline constexpr ShapeGroup operator-(T a, U b); +// +// /* @brief XOR of two shapes */ +// template inline constexpr ShapeGroup operator^(T a, U b); +/** @relates ShapeGroup +@brief Logical AND of two shapes + +[Short-circuit evaluation](http://en.wikipedia.org/wiki/Short-circuit_evaluation) +is used here, so this operation can be used for providing simplified shape +version, because collision with @p b is computed only if @p a collides. +See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); -/** @brief Difference of two shapes */ -template inline constexpr ShapeGroup operator-(T a, U b); +/** @relates ShapeGroup +@brief Logical OR of two shapes -/** @brief XOR of two shapes */ -template inline constexpr ShapeGroup operator^(T a, U b); +[Short-circuit evaluation](http://en.wikipedia.org/wiki/Short-circuit_evaluation) +is used, so if collision with @p a is detected, collision with @p b is not +computed. +*/ +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ template inline constexpr enableIfAreBaseType operator char(const T& a, const U& b) { \ @@ -165,10 +200,12 @@ template inline constexpr enableIfAreBaseType operator char(st template inline constexpr enableIfAreBaseType operator char(std::reference_wrapper a, std::reference_wrapper b) { \ return ShapeGroup(ShapeGroup::type|ShapeGroup::RefAB, &a.get(), &b.get()); \ } -op(Union, |) -op(Intersection, &) -op(Difference, -) -op(Xor, ^) +// op(Union, |) +// op(Intersection, &) +// op(Difference, -) +// op(Xor, ^) +op(And, &&) +op(Or, ||) #undef op #endif diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index a78ddc9d6..69eaffa13 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -17,7 +17,7 @@ #include "Math/Matrix4.h" #include "Physics/Point.h" -#include "Physics/Sphere.h" +#include "Physics/LineSegment.h" #include "Physics/ShapeGroup.h" using namespace std; @@ -35,9 +35,9 @@ void ShapeGroupTest::copy() { ShapeGroup group; { Physics::Point point({1.0f, 2.0f, 3.0f}); - Physics::Sphere sphere({2.0f, 1.0f, 30.0f}, 1.0f); + Physics::LineSegment segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); - group = ~(point|sphere); + group = !(point || segment); } /* Just to test that it doesn't crash */ @@ -48,14 +48,14 @@ void ShapeGroupTest::copy() { void ShapeGroupTest::reference() { Physics::Point point({1.0f, 2.0f, 3.0f}); - Physics::Sphere sphere({2.0f, 1.0f, 30.0f}, 1.0f); + Physics::LineSegment segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); - ShapeGroup group = ~(ref(point)|ref(sphere)); + ShapeGroup group = !(ref(point) || ref(segment)); group.applyTransformation(Matrix4::translation(Vector3(1.0f))); CORRADE_VERIFY((point.transformedPosition() == Vector3(2.0f, 3.0f, 4.0f))); - CORRADE_VERIFY((sphere.transformedPosition() == Vector3(3.0f, 2.0f, 31.0f))); + CORRADE_VERIFY((segment.transformedA() == Vector3(3.0f, 2.0f, 31.0f))); } }}} From e114fc12dfe959d717f01c91f8a8f925cb70c883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 02:15:14 +0200 Subject: [PATCH 094/256] Hide Matrix::ij() reimplementation from documentation. --- src/Math/Matrix4.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index f39aa9c90..72260b9f5 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -131,9 +131,6 @@ template class Matrix4: public Matrix<4, T> { /** @brief Copy constructor */ inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} - /** @copydoc Matrix::ij() */ - inline Matrix3 ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); } - /** * @brief 3D rotation and scaling part of the matrix * @@ -177,6 +174,10 @@ template class Matrix4: public Matrix<4, T> { return (*this)[3].xyz(); } + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Matrix3 ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); } + #endif + MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(4, 4, Matrix4) }; From f4bc8b6174d2ade6dc36a660d2f3923f3bcb8845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 10:06:10 +0200 Subject: [PATCH 095/256] Physics: Fixed Box shape compilation, added missing unit test. --- src/Physics/Box.cpp | 27 +++++++++++++++++++++++++ src/Physics/Box.h | 15 +++++++------- src/Physics/CMakeLists.txt | 1 + src/Physics/Test/BoxTest.cpp | 36 +++++++++++++++++++++++++++++++++ src/Physics/Test/BoxTest.h | 31 ++++++++++++++++++++++++++++ src/Physics/Test/CMakeLists.txt | 1 + 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 src/Physics/Box.cpp create mode 100644 src/Physics/Test/BoxTest.cpp create mode 100644 src/Physics/Test/BoxTest.h diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp new file mode 100644 index 000000000..36c230870 --- /dev/null +++ b/src/Physics/Box.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Box.h" + +#include "Math/Matrix4.h" +#include "Math/Point3D.h" + +namespace Magnum { namespace Physics { + +void Box::applyTransformation(const Matrix4& transformation) { + _transformedTransformation = (transformation*_transformation); +} + +}} diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 34535e7a6..f1c3286ff 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -19,30 +19,29 @@ * @brief Class Magnum::Physics::Box */ +#include "Math/Matrix4.h" #include "AbstractShape.h" namespace Magnum { namespace Physics { /** @brief Unit size box with assigned transformation matrix */ -class Box: public AbstractShape { +class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline Box(const Matrix4& transformation): _transformation(transformation), _transformedTransformation(transformation) {} - inline void applyTransformation(const Matrix4& transformation) { - _transformedTransformation = transformation*_transformation; - } + void applyTransformation(const Matrix4& transformation); /** @brief Transformation */ - inline constexpr Matrix4 transformation() const { return _transformation; } + inline Matrix4 transformation() const { return _transformation; } /** @brief Set transformation */ - inline Vector3 setTransformation(const Matrix4& transformation) { + inline void setTransformation(const Matrix4& transformation) { _transformation = transformation; } /** @brief Transformed transformation */ - inline constexpr Vector3 transformedTransformation() const { + inline Matrix4 transformedTransformation() const { return _transformedTransformation; } @@ -50,7 +49,7 @@ class Box: public AbstractShape { inline Type type() const { return Type::Box; } private: - Vector3 _transformation, _transformedTransformation; + Matrix4 _transformation, _transformedTransformation; }; }} diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index a42842084..430587b7d 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,6 +1,7 @@ set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp + Box.cpp Capsule.cpp Line.cpp Plane.cpp diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp new file mode 100644 index 000000000..e844e4d2e --- /dev/null +++ b/src/Physics/Test/BoxTest.cpp @@ -0,0 +1,36 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "BoxTest.h" + +#include "Math/Matrix4.h" +#include "Physics/Box.h" + +CORRADE_TEST_MAIN(Magnum::Physics::Test::BoxTest) + +namespace Magnum { namespace Physics { namespace Test { + +BoxTest::BoxTest() { + addTests(&BoxTest::applyTransformation); +} + +void BoxTest::applyTransformation() { + Physics::Box box(Matrix4::translation({1.0f, 2.0f, -3.0f})); + + box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); + CORRADE_COMPARE(box.transformedTransformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f})); +} + +}}} diff --git a/src/Physics/Test/BoxTest.h b/src/Physics/Test/BoxTest.h new file mode 100644 index 000000000..48781ad08 --- /dev/null +++ b/src/Physics/Test/BoxTest.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Physics_Test_BoxTest_h +#define Magnum_Physics_Test_BoxTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Physics { namespace Test { + +class BoxTest: public Corrade::TestSuite::Tester { + public: + BoxTest(); + + void applyTransformation(); +}; + +}}} + +#endif diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index b182873a0..4f8130a83 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -1,4 +1,5 @@ corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) From 2c0995cf26d7c44b7368c349dc627af972d56c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:15:53 +0200 Subject: [PATCH 096/256] 2D equivalents of Geometry::Distance functions. Also using std::sqrt() instead of sqrt() (has overloads for float). --- src/Math/Geometry/Distance.h | 114 +++++++++++++++++++++--- src/Math/Geometry/Test/DistanceTest.cpp | 60 ++++++++++++- src/Math/Geometry/Test/DistanceTest.h | 6 +- 3 files changed, 163 insertions(+), 17 deletions(-) diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index b86b5aa71..9073520a8 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Math::Geometry::Distance */ +#include "Math/Math.h" +#include "Math/Matrix.h" #include "Math/Vector3.h" namespace Magnum { namespace Math { namespace Geometry { @@ -27,7 +29,39 @@ namespace Magnum { namespace Math { namespace Geometry { class Distance { public: /** - * @brief %Distance of line and point + * @brief %Distance of line and point in 2D + * @param a First point of the line + * @param b Second point of the line + * @param point Point + * + * The distance *d* is computed from point **p** and line defined by **a** + * and **b** using @ref Matrix::determinant() "determinant": @f[ + * d = \frac{|det(b - a a - point)|} {|b - a|} + * @f] + * Source: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html + * @see linePointSquared(const Vector2&, const Vector2&, const Vector2&) + */ + template inline static T linePoint(const Vector2& a, const Vector2& b, const Vector2& point) { + return std::abs(Matrix<2, T>::from(b - a, a - point).determinant())/(b - a).length(); + } + + /** + * @brief %Distance of line and point in 2D, squared + * @param a First point of the line + * @param b Second point of the line + * @param point Point + * + * More efficient than linePoint(const Vector2&, const Vector2&, const Vector2&) + * for comparing distance with other values, because it doesn't + * compute the square root. + */ + template inline static T linePointSquared(const Vector2& a, const Vector2& b, const Vector2& point) { + Vector2 bMinusA = b - a; + return Math::pow<2>(Matrix<2, T>::from(bMinusA, a - point).determinant())/bMinusA.dot(); + } + + /** + * @brief %Distance of line and point in 3D * @param a First point of the line * @param b Second point of the line * @param point Point @@ -37,25 +71,26 @@ class Distance { * d = \frac{|(\boldsymbol p - \boldsymbol a) \times (\boldsymbol p - \boldsymbol b)|} * {|\boldsymbol b - \boldsymbol a|} * @f] - * - * @see linePointSquared() + * Source: http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html + * @see linePointSquared(const Vector3&, const Vector3&, const Vector3&) */ template inline static T linePoint(const Vector3& a, const Vector3& b, const Vector3& point) { - return sqrt(linePointSquared(a, b, point)); + return std::sqrt(linePointSquared(a, b, point)); } /** - * @brief %Distance of line and point, squared + * @brief %Distance of line and point in 3D, squared * - * More efficient than linePoint() for comparing distance with other - * values, because it doesn't compute the square root. + * More efficient than linePoint(const Vector3&, const Vector3&, const Vector3&) + * for comparing distance with other values, because it doesn't + * compute the square root. */ template static T linePointSquared(const Vector3& a, const Vector3& b, const Vector3& point) { return Vector3::cross(point - a, point - b).dot()/(b - a).dot(); } /** - * @brief %Dístance of point from line segment + * @brief %Dístance of point from line segment in 2D * @param a Starting point of the line * @param b Ending point of the line * @param point Point @@ -80,16 +115,73 @@ class Distance { * * @see lineSegmentPointSquared() */ - template inline static T lineSegmentPoint(const Vector3& a, const Vector3& b, const Vector3& point) { - return sqrt(lineSegmentPointSquared(a, b, point)); + template inline static T lineSegmentPoint(const Vector2& a, const Vector2& b, const Vector2& point) { + Vector2 pointMinusA = point - a; + Vector2 pointMinusB = point - b; + Vector2 bMinusA = b - a; + T pointDistanceA = pointMinusA.dot(); + T pointDistanceB = pointMinusB.dot(); + T bDistanceA = bMinusA.dot(); + + /* Point is before A */ + if(pointDistanceB > bDistanceA + pointDistanceA) + return std::sqrt(pointDistanceA); + + /* Point is after B */ + if(pointDistanceA > bDistanceA + pointDistanceB) + return std::sqrt(pointDistanceB); + + /* Between A and B */ + return std::abs(Matrix<2, T>::from(bMinusA, -pointMinusA).determinant())/std::sqrt(bDistanceA); } /** - * @brief %Distance of point from line segment, squared + * @brief %Distance of point from line segment in 2D, squared * * More efficient than lineSegmentPoint() for comparing distance with * other values, because it doesn't compute the square root. */ + template static T lineSegmentPointSquared(const Vector2& a, const Vector2& b, const Vector2& point) { + Vector2 pointMinusA = point - a; + Vector2 pointMinusB = point - b; + Vector2 bMinusA = b - a; + T pointDistanceA = pointMinusA.dot(); + T pointDistanceB = pointMinusB.dot(); + T bDistanceA = bMinusA.dot(); + + /* Point is before A */ + if(pointDistanceB > bDistanceA + pointDistanceA) + return pointDistanceA; + + /* Point is after B */ + if(pointDistanceA > bDistanceA + pointDistanceB) + return pointDistanceB; + + /* Between A and B */ + return Math::pow<2>(Matrix<2, T>::from(bMinusA, -pointMinusA).determinant())/bDistanceA; + } + + /** + * @brief %Dístance of point from line segment in 3D + * @param a Starting point of the line + * @param b Ending point of the line + * @param point Point + * + * Similar to 2D implementation + * lineSegmentPoint(const Vector2&, const Vector2&, const Vector2&). + * + * @see lineSegmentPointSquared(const Vector3&, const Vector3&, const Vector3&) + */ + template inline static T lineSegmentPoint(const Vector3& a, const Vector3& b, const Vector3& point) { + return std::sqrt(lineSegmentPointSquared(a, b, point)); + } + + /** + * @brief %Distance of point from line segment in 3D, squared + * + * More efficient than lineSegmentPoint(const Vector3&, const Vector3&, const Vector3&) for comparing distance with + * other values, because it doesn't compute the square root. + */ template static T lineSegmentPointSquared(const Vector3& a, const Vector3& b, const Vector3& point) { Vector3 pointMinusA = point - a; Vector3 pointMinusB = point - b; diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 240ad21eb..ace9c485a 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -26,14 +26,35 @@ using namespace std; namespace Magnum { namespace Math { namespace Geometry { namespace Test { +typedef Magnum::Math::Vector2 Vector2; typedef Magnum::Math::Vector3 Vector3; DistanceTest::DistanceTest() { - addTests(&DistanceTest::linePoint, - &DistanceTest::lineSegmentPoint); + addTests(&DistanceTest::linePoint2D, + &DistanceTest::linePoint3D, + &DistanceTest::lineSegmentPoint2D, + &DistanceTest::lineSegmentPoint3D); } -void DistanceTest::linePoint() { +void DistanceTest::linePoint2D() { + Vector2 a(0.0f); + Vector2 b(1.0f); + + /* Point on the line */ + CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(0.25f))), 0.0f); + + /* The distance should be the same for all equidistant points */ + CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f))), + 1.0f/Constants::sqrt2()); + CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f)+Vector2(100.0f))), + 1.0f/Constants::sqrt2()); + + /* Be sure that *Squared() works the same, as it has slightly different implementation */ + CORRADE_COMPARE((Distance::linePointSquared(a, b, Vector2(1.0f, 0.0f))), + 0.5f); +} + +void DistanceTest::linePoint3D() { Vector3 a(0.0f); Vector3 b(1.0f); @@ -47,7 +68,38 @@ void DistanceTest::linePoint() { Constants::sqrt2()/Constants::sqrt3()); } -void DistanceTest::lineSegmentPoint() { +void DistanceTest::lineSegmentPoint2D() { + Vector2 a(0.0f); + Vector2 b(1.0f); + + /* Point on the line segment */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(0.25f))), 0.0f); + + /* Point on the line, outside the segment, closer to A */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(-1.0f))), Constants::sqrt2()); + /* Be sure that *Squared() works the same, as it has slightly different implementation */ + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(-1.0f))), 2.0f); + + /* Point on the line, outside the segment, closer to B */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); + + /* Point next to the line segment */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f))), + 1.0f/Constants::sqrt2()); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f, 0.0f))), + 0.5f); + + /* Point outside the line segment, closer to A */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f)-Vector2(1.0f, 0.5f))), 0.5f); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f, 0.0f)-Vector2(1.0f, 0.5f))), 0.25f); + + /* Point outside the line segment, closer to B */ + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f)+Vector2(0.5f, 1.0f))), 0.5f); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f, 0.0f)+Vector2(0.5f, 1.0f))), 0.25f); +} + +void DistanceTest::lineSegmentPoint3D() { Vector3 a(0.0f); Vector3 b(1.0f); diff --git a/src/Math/Geometry/Test/DistanceTest.h b/src/Math/Geometry/Test/DistanceTest.h index 0cae07036..dc7c7bc88 100644 --- a/src/Math/Geometry/Test/DistanceTest.h +++ b/src/Math/Geometry/Test/DistanceTest.h @@ -23,8 +23,10 @@ class DistanceTest: public Corrade::TestSuite::Tester { public: DistanceTest(); - void linePoint(); - void lineSegmentPoint(); + void linePoint2D(); + void linePoint3D(); + void lineSegmentPoint2D(); + void lineSegmentPoint3D(); }; }}}} From 5b7ffedce3cad8f51e0dd5771e25fd09e36b0476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:31:56 +0200 Subject: [PATCH 097/256] Fixed serious copypasta error. It's weird that it was working until now. --- src/Math/Vector4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 0df339f24..e7b21e320 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -86,7 +86,7 @@ template class Vector4: public Vector<4, T> { inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector4, 4) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Vector4) + MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Vector4) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector4, 4) From 9feb8d32a544005c17964cdc733507867cbe1cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:33:12 +0200 Subject: [PATCH 098/256] Overloaded operators also for Point2D and Point3D. --- src/Math/Point2D.h | 5 +++++ src/Math/Point3D.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 953438d51..35ab1ff86 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -57,8 +57,13 @@ template class Point2D: public Vector3 { * @param z Z component */ inline constexpr Point2D(const Vector<2, T>& xy, T z = T(1)): Vector3(xy, z) {} + + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3) + MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Point2D) }; +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) + /** @debugoperator{Magnum::Math::Point2D} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { return debug << static_cast&>(value); diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index e92e1e7b1..a1e8eda88 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -58,8 +58,13 @@ template class Point3D: public Vector4 { * @param w W component */ inline constexpr Point3D(const Vector<3, T>& xyz, T w = T(1)): Vector4(xyz, w) {} + + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4) + MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Point3D) }; +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) + /** @debugoperator{Magnum::Math::Point3D} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { return debug << static_cast&>(value); From 6aa7e3e806920bed846950c4fcffcef093cb80ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:33:44 +0200 Subject: [PATCH 099/256] Added Point*D::vector() function. Equivalent to xy() and xyz(), useful for seamless 2D/3D integration. --- src/Math/Point2D.h | 9 +++++++++ src/Math/Point3D.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 35ab1ff86..f0c85186a 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -58,6 +58,15 @@ template class Point2D: public Vector3 { */ inline constexpr Point2D(const Vector<2, T>& xy, T z = T(1)): Vector3(xy, z) {} + /** + * @brief Vector part of the point + * + * Equivalent to calling xy(). Useful for seamless 2D/3D integration. + * @see Point3D::vector() + */ + inline Vector2& vector() { return Vector3::xy(); } + inline constexpr Vector2 vector() const { return Vector3::xy(); } /**< @overload */ + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Point2D) }; diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index a1e8eda88..428a91395 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -59,6 +59,15 @@ template class Point3D: public Vector4 { */ inline constexpr Point3D(const Vector<3, T>& xyz, T w = T(1)): Vector4(xyz, w) {} + /** + * @brief Vector part of the point + * + * Equivalent to calling xyz(). Useful for seamless 2D/3D integration. + * @see Point2D::vector() + */ + inline Vector3& vector() { return Vector4::xyz(); } + inline constexpr Vector3 vector() const { return Vector4::xyz(); } /**< @overload */ + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Point3D) }; From c820cbeee68b42be229c03de5e75629c109a03b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:38:50 +0200 Subject: [PATCH 100/256] Point*D overload for Matrix subclasses. --- src/Math/Matrix3.h | 8 +++++++- src/Math/Matrix4.h | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 364d120fd..f9a1f75de 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -20,7 +20,7 @@ */ #include "Matrix.h" -#include "Vector3.h" +#include "Point2D.h" namespace Magnum { namespace Math { @@ -138,6 +138,12 @@ template class Matrix3: public Matrix<3, T> { return (*this)[2].xy(); } + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Point2D operator*(const Point2D& other) const { + return Matrix<3, T>::operator*(other); + } + #endif + MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(3, 3, Matrix3) }; diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 72260b9f5..1d72ee70a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -20,7 +20,7 @@ */ #include "Matrix3.h" -#include "Vector4.h" +#include "Point3D.h" namespace Magnum { namespace Math { @@ -176,6 +176,10 @@ template class Matrix4: public Matrix<4, T> { #ifndef DOXYGEN_GENERATING_OUTPUT inline Matrix3 ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); } + + inline Point3D operator*(const Point3D& other) const { + return Matrix<4, T>::operator*(other); + } #endif MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4) From b68a168fcb5f48e41d4764b8f5fcfc89279b72d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 20:40:52 +0200 Subject: [PATCH 101/256] Doc: crosslinking 1D/2D/3D alternatives. --- src/BufferedImage.h | 2 +- src/Image.h | 1 + src/Math/Point2D.h | 1 + src/Math/Point3D.h | 1 + src/SceneGraph/Camera.h | 12 ++++++++++-- src/SceneGraph/Object.h | 20 ++++++++++++++------ src/SceneGraph/Scene.h | 6 +++++- src/Texture.h | 2 +- src/Trade/MeshData2D.h | 1 + src/Trade/MeshData3D.h | 1 + src/Trade/MeshObjectData2D.h | 1 + src/Trade/MeshObjectData3D.h | 1 + src/Trade/ObjectData2D.h | 1 + src/Trade/ObjectData3D.h | 1 + 14 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 34a767abb..8b04bd615 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -31,7 +31,7 @@ namespace Magnum { Class for storing image data in GPU memory. Can be replaced with Image, which stores image data in client memory, ImageWrapper, or for example with Trade::ImageData. -@see Buffer +@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ template class BufferedImage: public AbstractImage { diff --git a/src/Image.h b/src/Image.h index fd83832a7..472af324a 100644 --- a/src/Image.h +++ b/src/Image.h @@ -30,6 +30,7 @@ namespace Magnum { Class for storing image data on client memory. Can be replaced with ImageWrapper, BufferedImage, which stores image data in GPU memory, or for example with Trade::ImageData. +@see Image1D, Image2D, Image3D */ template class Image: public AbstractImage { public: diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index f0c85186a..a882e68ab 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { Same as Vector3, except that constructors have default value for Z component set to one. See also @ref matrix-vector for brief introduction. +@see Point3D @configurationvalueref{Magnum::Math::Point2D} */ template class Point2D: public Vector3 { diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 428a91395..19c89aa75 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { Same as Vector4, except that constructors have default value for W component set to one. See also @ref matrix-vector for brief introduction. +@see Point2D @configurationvalueref{Magnum::Math::Point3D} */ template class Point3D: public Vector4 { diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 97507ab21..18f5c016c 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -183,7 +183,11 @@ namespace Implementation { } #endif -/** @brief %Camera for two-dimensional scenes */ +/** +@brief %Camera for two-dimensional scenes + +@see Camera3D +*/ class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2> { public: /** @@ -206,7 +210,11 @@ class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2> { Camera2D* setProjection(const Vector2& size); }; -/** @brief %Camera for three-dimensional scenes */ +/** +@brief %Camera for three-dimensional scenes + +@see Camera2D +*/ class SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3> { public: /** diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index ffbf86042..cdeaf5a69 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -71,10 +71,10 @@ namespace Implementation { */ /** - * @brief Base for all positioned objects - * - * @todo Transform transformation when changing parent, so the object stays in - * place. +@brief Base for all positioned objects + +@todo Transform transformation when changing parent, so the object stays in +place. */ template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -328,7 +328,11 @@ extern template class SCENEGRAPH_EXPORT AbstractObject<2>; extern template class SCENEGRAPH_EXPORT AbstractObject<3>; #endif -/** @brief Two-dimensional object */ +/** +@brief Two-dimensional object + +@see Object3D +*/ class SCENEGRAPH_EXPORT Object2D: public AbstractObject<2> { public: /** @copydoc AbstractObject::AbstractObject() */ @@ -379,7 +383,11 @@ class SCENEGRAPH_EXPORT Object2D: public AbstractObject<2> { } }; -/** @brief Three-dimensional object */ +/** +@brief Three-dimensional object + +@see Object2D +*/ class SCENEGRAPH_EXPORT Object3D: public AbstractObject<3> { public: /** @copydoc AbstractObject::AbstractObject() */ diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index f3cfde551..092f85e73 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -23,7 +23,11 @@ namespace Magnum { namespace SceneGraph { -/** @brief %Scene */ +/** +@brief %Scene + +@see Scene2D, Scene3D +*/ template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { public: /** @copydoc AbstractObject::isScene() */ diff --git a/src/Texture.h b/src/Texture.h index 8faed911a..ca8d54a4b 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -46,7 +46,7 @@ for more information. @requires_gl (rectangle textures) @requires_gl31 Extension @extension{ARB,texture_rectangle} (rectangle textures) -@see CubeMapTexture, CubeMapTextureArray +@see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray */ template class Texture: public AbstractTexture { public: diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 3a7663e44..cc650a213 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -31,6 +31,7 @@ namespace Magnum { namespace Trade { Provides access to mesh data and additional information, such as primitive type. +@see MeshData3D */ class MAGNUM_EXPORT MeshData2D { MeshData2D(const MeshData2D& other) = delete; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 371bd4a59..159a6ebcf 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -31,6 +31,7 @@ namespace Magnum { namespace Trade { Provides access to mesh data and additional information, such as primitive type. +@see MeshData2D */ class MAGNUM_EXPORT MeshData3D { MeshData3D(const MeshData3D& other) = delete; diff --git a/src/Trade/MeshObjectData2D.h b/src/Trade/MeshObjectData2D.h index c733c53a4..8eda1d68f 100644 --- a/src/Trade/MeshObjectData2D.h +++ b/src/Trade/MeshObjectData2D.h @@ -27,6 +27,7 @@ namespace Magnum { namespace Trade { @brief Two-dimensional mesh object data Provides access to material information for given mesh instance. +@see MeshObjectData3D */ class MeshObjectData2D: public ObjectData2D { MeshObjectData2D(const MeshObjectData2D& other) = delete; diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h index 4dbfef017..c133f2ed7 100644 --- a/src/Trade/MeshObjectData3D.h +++ b/src/Trade/MeshObjectData3D.h @@ -27,6 +27,7 @@ namespace Magnum { namespace Trade { @brief Three-dimensional mesh object data Provides access to material information for given mesh instance. +@see MeshObjectData2D */ class MeshObjectData3D: public ObjectData3D { MeshObjectData3D(const MeshObjectData3D& other) = delete; diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index 7610087eb..2db556f08 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Trade { Provides access to object transformation and hierarchy. See also MeshObjectData2D, which is specialized for objects with mesh instance type. +@see ObjectData3D */ class ObjectData2D { ObjectData2D(const ObjectData2D& other) = delete; diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index 189560254..ec048e194 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Trade { Provides access to object transformation and hierarchy. See also MeshObjectData3D, which is specialized for objects with mesh instance type. +@see ObjectData2D */ class ObjectData3D { ObjectData3D(const ObjectData3D& other) = delete; From 77c0ab9cd47ccb141aa9b79ec6bc13c8976e5e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 27 Sep 2012 18:14:20 +0200 Subject: [PATCH 102/256] 2D/3D alternatives of collision detection shapes. --- doc/collision-detection.dox | 42 +++---- src/Physics/AbstractShape.cpp | 5 +- src/Physics/AbstractShape.h | 93 ++++++++++++-- src/Physics/AxisAlignedBox.cpp | 7 +- src/Physics/AxisAlignedBox.h | 49 ++++++-- src/Physics/Box.cpp | 5 +- src/Physics/Box.h | 44 +++++-- src/Physics/Capsule.cpp | 27 +++-- src/Physics/Capsule.h | 74 +++++++++--- src/Physics/Line.cpp | 10 +- src/Physics/Line.h | 72 ++++++++--- src/Physics/LineSegment.h | 20 ++- src/Physics/Plane.cpp | 10 +- src/Physics/Plane.h | 24 ++-- src/Physics/Point.cpp | 7 +- src/Physics/Point.h | 41 +++++-- src/Physics/ShapeGroup.cpp | 35 +++--- src/Physics/ShapeGroup.h | 154 +++++++++++++----------- src/Physics/Sphere.cpp | 51 +++++--- src/Physics/Sphere.h | 63 +++++++--- src/Physics/Test/AxisAlignedBoxTest.cpp | 2 +- src/Physics/Test/BoxTest.cpp | 2 +- src/Physics/Test/CapsuleTest.cpp | 18 +-- src/Physics/Test/LineTest.cpp | 2 +- src/Physics/Test/PlaneTest.cpp | 12 +- src/Physics/Test/PointTest.cpp | 2 +- src/Physics/Test/ShapeGroupTest.cpp | 12 +- src/Physics/Test/SphereTest.cpp | 26 ++-- 28 files changed, 607 insertions(+), 302 deletions(-) diff --git a/doc/collision-detection.dox b/doc/collision-detection.dox index 1544e9157..033f7607d 100644 --- a/doc/collision-detection.dox +++ b/doc/collision-detection.dox @@ -13,12 +13,12 @@ together using various operations. @subsection collision-detection-shapes1D One-dimensional shapes -- Physics::Point - @copybrief Physics::Point -- Physics::Line - @copybrief Physics::Line -- Physics::LineSegment - @copybrief Physics::LineSegment +- @ref Physics::Point "Physics::Point*D" - @copybrief Physics::Point +- @ref Physics::Line "Physics::Line*D" - @copybrief Physics::Line +- @ref Physics::LineSegment "Physics::LineSegment*D" - @copybrief Physics::LineSegment -One-dimensional shapes don't provide collision detection with each other -because of numerical instability. +Because of numerical instability it's not possible to detect collisions of +line and point. Collision of two lines can be detected only in 2D. @subsection collision-detection-shapes2D Two-dimensional shapes @@ -26,10 +26,10 @@ because of numerical instability. @subsection collision-detection-shapes3D Three-dimensional shapes -- Physics::Sphere - @copybrief Physics::Sphere -- Physics::Capsule - @copybrief Physics::Capsule -- Physics::AxisAlignedBox - @copybrief Physics::AxisAlignedBox -- Physics::Box - @copybrief Physics::Box +- @ref Physics::Sphere "Physics::Sphere*D" - @copybrief Physics::Sphere +- @ref Physics::Capsule "Physics::Capsule*D" - @copybrief Physics::Capsule +- @ref Physics::AxisAlignedBox "Physics::AxisAlignedBox*D" - @copybrief Physics::AxisAlignedBox +- @ref Physics::Box "Physics::Box*D" - @copybrief Physics::Box The easiest (and most efficient) shape combination for detecting collisions is point and sphere, followed by two spheres. Computing collision of two boxes @@ -42,10 +42,10 @@ operations: AND, OR and NOT. These operations are mapped to operator&&(), operator||() and operator!(), so for example creating negation of logical OR of line segment and point is simple as this: @code -Physics::LineSegment segment; -Physics::Point point; +Physics::LineSegment3D segment; +Physics::Point3D point; -Physics::ShapeGroup group = !(segment || point); +Physics::ShapeGroup3D group = !(segment || point); @endcode @note Logical operations are not the same as set operations -- intersection of @@ -66,10 +66,10 @@ was not possible to change their properties such as sphere radius without recreating the group again. You can, however, explicitly pass a reference to original object, so you can change it later: @code -Physics::LineSegment segment; -Physics::Point point; +Physics::LineSegment3D segment; +Physics::Point3D point; -Physics::ShapeGroup group = !(segment || std::ref(point)); +Physics::ShapeGroup3D group = !(segment || std::ref(point)); point.setPosition({1.0f, -6.0f, 0.5f}); @endcode @@ -88,11 +88,11 @@ was detected with the simplified shape. It is in fact logical AND using operator&&() - the collision is initially detected on first (simplified) shape and then on the other: @code -Physics::Sphere sphere; -Physics::Box box; -Physics::AxisAlignedBox simplified; +Physics::Sphere3D sphere; +Physics::Box3D box; +Physics::AxisAlignedBox3D simplified; -Physics::ShapeGroup object = simplified && (sphere || box); +Physics::ShapeGroup3D object = simplified && (sphere || box); @endcode @section collision-detection-shape-collisions Detecting shape collisions @@ -100,8 +100,8 @@ Physics::ShapeGroup object = simplified && (sphere || box); Shape pairs which have collision detection implemented can be tested for collision using operator%(), for example: @code -Physics::Point point; -Physics::Sphere sphere; +Physics::Point3D point; +Physics::Sphere3D sphere; bool collide = point % sphere; @endcode diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index da42b21b7..cb920047e 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -17,7 +17,7 @@ namespace Magnum { namespace Physics { -bool AbstractShape::collides(const AbstractShape* other) const { +template bool AbstractShape::collides(const AbstractShape* other) const { /* Operate only with simpler types than this */ if(static_cast(other->type()) > static_cast(type())) return other->collides(this); @@ -25,4 +25,7 @@ bool AbstractShape::collides(const AbstractShape* other) const { return false; } +template class AbstractShape<2>; +template class AbstractShape<3>; + }} diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 363a685be..f4b8ea370 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -25,13 +25,67 @@ namespace Magnum { namespace Physics { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct ShapeDimensionTraits {}; + + template<> struct ShapeDimensionTraits<2> { + typedef Vector2 VectorType; + typedef Point2D PointType; + typedef Matrix3 MatrixType; + + enum class Type { + Point, + Line, + LineSegment, + Sphere, + Capsule, + AxisAlignedBox, + Box, + ShapeGroup + }; + }; + + template<> struct ShapeDimensionTraits<3> { + typedef Vector3 VectorType; + typedef Point3D PointType; + typedef Matrix4 MatrixType; + + enum class Type { + Point, + Line, + LineSegment, + Sphere, + Capsule, + AxisAlignedBox, + Box, + ShapeGroup, + Plane + }; + }; +} +#endif + /** @brief Base class for shapes See @ref collision-detection for brief introduction. +@see AbstractShape2D, AbstractShape3D */ -class PHYSICS_EXPORT AbstractShape { +template class PHYSICS_EXPORT AbstractShape { public: + /** @brief %Vector type for given dimension count */ + typedef typename Implementation::ShapeDimensionTraits::VectorType VectorType; + + /** @brief %Point type for given dimension count */ + typedef typename Implementation::ShapeDimensionTraits::PointType PointType; + + /** @brief %Matrix type for given dimension count */ + typedef typename Implementation::ShapeDimensionTraits::MatrixType MatrixType; + + /** @brief Dimension count */ + static const size_t Dimensions = dimensions; + /** * @brief Shape type * @@ -39,17 +93,21 @@ class PHYSICS_EXPORT AbstractShape { * the list provides collision detection for previous shapes, not * the other way around. */ + #ifdef DOXYGEN_GENERATING_OUTPUT enum class Type { - Point, - Line, - LineSegment, - Plane, - Sphere, - Capsule, - AxisAlignedBox, - Box, - ShapeGroup + Point, /**< Point */ + Line, /**< Line */ + LineSegment, /**< @ref LineSegment "Line segment" */ + Sphere, /**< Sphere */ + Capsule, /**< Capsule */ + AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ + Box, /**< Box */ + ShapeGroup, /**< @ref ShapeGroup "Shape group" */ + Plane /**< Plane (3D only) */ }; + #else + typedef typename Implementation::ShapeDimensionTraits::Type Type; + #endif /** @brief Destructor */ virtual inline ~AbstractShape() {} @@ -63,7 +121,7 @@ class PHYSICS_EXPORT AbstractShape { * Applies transformation to user-defined shape properties and caches * them for later usage in collision detection. */ - virtual void applyTransformation(const Matrix4& transformation) = 0; + virtual void applyTransformation(const MatrixType& transformation) = 0; /** * @brief Detect collision with other shape @@ -73,9 +131,20 @@ class PHYSICS_EXPORT AbstractShape { * @internal If other shape is more complex than this, returns * `other->collides(this)`. */ - virtual bool collides(const AbstractShape* other) const; + virtual bool collides(const AbstractShape* other) const; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT AbstractShape<2>; +extern template class PHYSICS_EXPORT AbstractShape<3>; +#endif + +/** @brief Abstract two-dimensional shape */ +typedef AbstractShape<2> AbstractShape2D; + +/** @brief Abstract three-dimensional shape */ +typedef AbstractShape<3> AbstractShape3D; + }} #endif diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 30ad3551b..e9e9c254e 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,9 +20,12 @@ namespace Magnum { namespace Physics { -void AxisAlignedBox::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Point3D(_position)).xyz(); +template void AxisAlignedBox::applyTransformation(const typename AbstractShape::MatrixType& transformation) { + _transformedPosition = (transformation*typename AxisAlignedBox::PointType(_position)).vector(); _transformedSize = transformation.rotationScaling()*_size; } +template class AxisAlignedBox<2>; +template class AxisAlignedBox<3>; + }} diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index ce3505582..45dab8f70 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::AxisAlignedBox + * @brief Class Magnum::Physics::AxisAlignedBox, typedef Magnum::Physics::AxisAlignedBox2D, Magnum::Physics.:AxisAlignedBox3D */ #include "Math/Vector3.h" @@ -24,48 +24,71 @@ namespace Magnum { namespace Physics { -/** @brief Axis aligned box */ -class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +/** +@brief Axis-aligned box + +@see AxisAlignedBox2D, AxisAlignedBox3D +*/ +template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ - inline AxisAlignedBox(const Vector3& position, const Vector3& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline AxisAlignedBox(const typename AbstractShape::VectorType& position, const typename AbstractShape::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif /** @brief Position */ - inline Vector3 position() const { return _position; } + inline typename AbstractShape::VectorType position() const { + return _position; + } /** @brief Set position */ - inline void setPosition(const Vector3& position) { + inline void setPosition(const typename AbstractShape::VectorType& position) { _position = position; } /** @brief Size */ - inline Vector3 size() const { return _size; } + inline typename AbstractShape::VectorType size() const { return _size; } /** @brief Set size */ - inline void setSize(const Vector3& size) { + inline void setSize(const typename AbstractShape::VectorType& size) { _size = size; } /** @brief Transformed position */ - inline Vector3 transformedPosition() const { + inline typename AbstractShape::VectorType transformedPosition() const { return _transformedPosition; } /** @brief Transformed size */ - inline Vector3 transformedSize() const { + inline typename AbstractShape::VectorType transformedSize() const { return _transformedSize; } protected: - inline Type type() const { return Type::AxisAlignedBox; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::AxisAlignedBox; + } private: - Vector3 _position, _transformedPosition, + typename AbstractShape::VectorType _position, _transformedPosition, _size, _transformedSize; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT AxisAlignedBox<2>; +extern template class PHYSICS_EXPORT AxisAlignedBox<3>; +#endif + +/** @brief Two-dimensional axis-aligned box */ +typedef AxisAlignedBox<2> AxisAlignedBox2D; + +/** @brief Three-dimensional axis-aligned box */ +typedef AxisAlignedBox<3> AxisAlignedBox3D; + }} #endif diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 36c230870..cc5d292bd 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,8 +20,11 @@ namespace Magnum { namespace Physics { -void Box::applyTransformation(const Matrix4& transformation) { +template void Box::applyTransformation(const typename AbstractShape::MatrixType& transformation) { _transformedTransformation = (transformation*_transformation); } +template class Box<2>; +template class Box<3>; + }} diff --git a/src/Physics/Box.h b/src/Physics/Box.h index f1c3286ff..9c5aa6e5d 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::Box + * @brief Class Magnum::Physics::Box, typedef Magnum::Physics::Box2D, Magnum::Physics::Box3D */ #include "Math/Matrix4.h" @@ -24,34 +24,58 @@ namespace Magnum { namespace Physics { -/** @brief Unit size box with assigned transformation matrix */ -class PHYSICS_EXPORT Box: public AbstractShape { +/** +@brief Unit-size box with assigned transformation matrix + +@see Box2D, Box3D +*/ +template class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ - inline Box(const Matrix4& transformation): _transformation(transformation), _transformedTransformation(transformation) {} + inline Box(const typename AbstractShape::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif /** @brief Transformation */ - inline Matrix4 transformation() const { return _transformation; } + inline typename AbstractShape::MatrixType transformation() const { + return _transformation; + } /** @brief Set transformation */ - inline void setTransformation(const Matrix4& transformation) { + inline void setTransformation(const typename AbstractShape::MatrixType& transformation) { _transformation = transformation; } /** @brief Transformed transformation */ - inline Matrix4 transformedTransformation() const { + inline typename AbstractShape::MatrixType transformedTransformation() const { return _transformedTransformation; } protected: - inline Type type() const { return Type::Box; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Box; + } private: - Matrix4 _transformation, _transformedTransformation; + typename AbstractShape::MatrixType _transformation, + _transformedTransformation; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT Box<2>; +extern template class PHYSICS_EXPORT Box<3>; +#endif + +/** @brief Two-dimensional box */ +typedef Box<2> Box2D; + +/** @brief Three-dimensional box */ +typedef Box<3> Box3D; + }} #endif diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index b6d175f7d..a8109e1a8 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,30 +27,33 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -void Capsule::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Point3D(_a)).xyz(); - _transformedB = (transformation*Point3D(_b)).xyz(); - float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); +template void Capsule::applyTransformation(const typename AbstractShape::MatrixType& transformation) { + _transformedA = (transformation*typename AbstractShape::PointType(_a)).vector(); + _transformedB = (transformation*typename AbstractShape::PointType(_b)).vector(); + float scaling = (transformation.rotationScaling()*typename AbstractShape::VectorType(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } -bool Capsule::collides(const AbstractShape* other) const { - if(other->type() == Type::Point) - return *this % *static_cast(other); - if(other->type() == Type::Sphere) - return *this % *static_cast(other); +template bool Capsule::collides(const AbstractShape* other) const { + if(other->type() == AbstractShape::Type::Point) + return *this % *static_cast*>(other); + if(other->type() == AbstractShape::Type::Sphere) + return *this % *static_cast*>(other); - return AbstractShape::collides(other); + return AbstractShape::collides(other); } -bool Capsule::operator%(const Point& other) const { +template bool Capsule::operator%(const Point& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()); } -bool Capsule::operator%(const Sphere& other) const { +template bool Capsule::operator%(const Sphere& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()+other.transformedRadius()); } +template class Capsule<2>; +template class Capsule<3>; + }} diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index d85cef641..76bfc828f 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::Capsule + * @brief Class Magnum::Physics::Capsule, typedef Magnum::Physics::Capsule2D, Magnum::Physics::Capsule3D */ #include "Math/Vector3.h" @@ -24,29 +24,48 @@ namespace Magnum { namespace Physics { -class Point; -class Sphere; +template class Point; +template class Sphere; /** @brief %Capsule defined by cylinder start and end point and radius Unlike other elements the capsule doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. +@see Capsule2D, Capsule3D */ -class PHYSICS_EXPORT Capsule: public AbstractShape { +template class PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline Capsule(const Vector3& a, const Vector3& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline Capsule(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const; - inline Vector3 a() const { return _a; } /**< @brief Start point */ - inline Vector3 b() const { return _a; } /**< @brief End point */ + /** @brief Start point */ + inline typename AbstractShape::VectorType a() const { + return _a; + } + + /** @brief End point */ + inline typename AbstractShape::VectorType b() const { + return _a; + } - inline void setA(const Vector3& a) { _a = a; } /**< @brief Set start point */ - inline void setB(const Vector3& b) { _b = b; } /**< @brief Set end point */ + /** @brief Set start point */ + inline void setA(const typename AbstractShape::VectorType& a) { + _a = a; + } + + /** @brief Set end point */ + inline void setB(const typename AbstractShape::VectorType& b) { + _b = b; + } /** @brief Radius */ inline float radius() const { return _radius; } @@ -55,10 +74,14 @@ class PHYSICS_EXPORT Capsule: public AbstractShape { inline void setRadius(float radius) { _radius = radius; } /** @brief Transformed first point */ - inline Vector3 transformedA() const { return _transformedA; } + inline typename AbstractShape::VectorType transformedA() const { + return _transformedA; + } /** @brief Transformed second point */ - inline Vector3 transformedB() const { return _transformedB; } + inline typename AbstractShape::VectorType transformedB() const { + return _transformedB; + } /** @brief Transformed radius */ inline float transformedRadius() const { @@ -66,25 +89,38 @@ class PHYSICS_EXPORT Capsule: public AbstractShape { } /** @brief Collision with point */ - bool operator%(const Point& other) const; + bool operator%(const Point& other) const; /** @brief Collision with sphere */ - bool operator%(const Sphere& other) const; + bool operator%(const Sphere& other) const; protected: - inline Type type() const { return Type::Capsule; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Capsule; + } private: - Vector3 _a, _transformedA, + typename AbstractShape::VectorType _a, _transformedA, _b, _transformedB; float _radius, _transformedRadius; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT Capsule<2>; +extern template class PHYSICS_EXPORT Capsule<3>; +#endif + +/** @brief Two-dimensional capsule */ +typedef Capsule<2> Capsule2D; + +/** @brief Three-dimensional capsule */ +typedef Capsule<3> Capsule3D; + /** @collisionoperator{Point,Capsule} */ -inline bool operator%(const Point& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } /** @collisionoperator{Sphere,Capsule} */ -inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } }} diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 3dec9a602..882c516b7 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,9 +20,13 @@ namespace Magnum { namespace Physics { -void Line::applyTransformation(const Matrix4& transformation) { - _transformedA = (transformation*Point3D(_a)).xyz(); - _transformedB = (transformation*Point3D(_b)).xyz(); +template void Line::applyTransformation(const typename AbstractShape::MatrixType& transformation) { + _transformedA = (transformation*typename AbstractShape::PointType(_a)).vector(); + _transformedB = (transformation*typename AbstractShape::PointType(_b)).vector(); } +/* Explicitly instantiate the templates */ +template class Line<2>; +template class Line<3>; + }} diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 22897adf5..4e43b98a9 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::Line + * @brief Class Magnum::Physics::Line, typedef Magnum::Physics::Line2D, Magnum::Physics::Line3D */ #include "Math/Vector3.h" @@ -24,34 +24,74 @@ namespace Magnum { namespace Physics { -/** @brief Infinite line, defined by two points */ -class PHYSICS_EXPORT Line: public AbstractShape { +/** +@brief Infinite line, defined by two points + +@see Line2D, Line3D +@todo collision detection of two Line2D +*/ +template class PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ - inline Line(const Vector3& a, const Vector3& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} - - void applyTransformation(const Matrix4& transformation); - - inline Vector3 a() const { return _a; } /**< @brief First point */ - inline Vector3 b() const { return _a; } /**< @brief Second point */ - - inline void setA(const Vector3& a) { _a = a; } /**< @brief Set first point */ - inline void setB(const Vector3& b) { _b = b; } /**< @brief Set second point */ + inline Line(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} + + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif + + /** @brief First point */ + inline typename AbstractShape::VectorType a() const { + return _a; + } + + /** @brief Second point */ + inline typename AbstractShape::VectorType b() const { + return _a; + } + + /** @brief Set first point */ + inline void setA(const typename AbstractShape::VectorType& a) { + _a = a; + } + + /** @brief Set second point */ + inline void setB(const typename AbstractShape::VectorType& b) { + _b = b; + } /** @brief Transformed first point */ - inline Vector3 transformedA() const { return _transformedA; } + inline typename AbstractShape::VectorType transformedA() const { + return _transformedA; + } /** @brief Transformed second point */ - inline Vector3 transformedB() const { return _transformedB; } + inline typename AbstractShape::VectorType transformedB() const { + return _transformedB; + } protected: - inline Type type() const { return Type::Line; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Line; + } private: - Vector3 _a, _transformedA, + typename AbstractShape::VectorType _a, _transformedA, _b, _transformedB; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT Line<2>; +extern template class PHYSICS_EXPORT Line<3>; +#endif + +/** @brief Infinite two-dimensional line */ +typedef Line<2> Line2D; + +/** @brief Infinite three-dimensional line */ +typedef Line<3> Line3D; + }} #endif diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index c10a6d8f0..c7d59863d 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -16,23 +16,33 @@ */ /** @file - * @brief Class Magnum::Physics::LineSegment + * @brief Class Magnum::Physics::LineSegment, typedef Magnum::Physics::LineSegment2D, Magnum::Physics::LineSegment3D */ #include "Line.h" namespace Magnum { namespace Physics { -/** @brief %Line segment, defined by starting and ending point */ -class LineSegment: public Line { +/** +@brief %Line segment, defined by starting and ending point + +@see LineSegment2D, LineSegment3D +*/ +template class LineSegment: public Line { public: /** @brief Constructor */ - inline LineSegment(const Vector3& a, const Vector3& b): Line(a, b) {} + inline LineSegment(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b): Line(a, b) {} protected: - inline Type type() const { return Type::LineSegment; } + inline typename AbstractShape::Type type() const { return AbstractShape::Type::LineSegment; } }; +/** @brief Two-dimensional line segment */ +typedef LineSegment<2> LineSegment2D; + +/** @brief Three-dimensional line segment */ +typedef LineSegment<3> LineSegment3D; + }} #endif diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 124b28ccf..79ead18c7 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -32,21 +32,21 @@ void Plane::applyTransformation(const Matrix4& transformation) { _transformedNormal = transformation.rotation()*_normal; } -bool Plane::collides(const AbstractShape* other) const { +bool Plane::collides(const AbstractShape<3>* other) const { if(other->type() == Type::Line) - return *this % *static_cast(other); + return *this % *static_cast(other); if(other->type() == Type::LineSegment) - return *this % *static_cast(other); + return *this % *static_cast(other); return AbstractShape::collides(other); } -bool Plane::operator%(const Line& other) const { +bool Plane::operator%(const Line3D& other) const { float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); return t != t || (t != numeric_limits::infinity() && t != -numeric_limits::infinity()); } -bool Plane::operator%(const LineSegment& other) const { +bool Plane::operator%(const LineSegment3D& other) const { float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); return t > 0.0f && t < 1.0f; } diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index dd363b1c7..64e7c116e 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -24,18 +24,24 @@ namespace Magnum { namespace Physics { -class Line; -class LineSegment; +template class Line; +typedef Line<3> Line3D; +template class LineSegment; +typedef LineSegment<3> LineSegment3D; -/** @brief Infinite plane, defined by position and normal */ -class PHYSICS_EXPORT Plane: public AbstractShape { +/** @brief Infinite plane, defined by position and normal (3D only) */ +class PHYSICS_EXPORT Plane: public AbstractShape<3> { public: /** @brief Constructor */ inline Plane(const Vector3& position, const Vector3& normal): _position(position), _transformedPosition(position), _normal(normal), _transformedNormal(normal) {} + #ifndef DOXYGEN_GENERATING_OUTPUT void applyTransformation(const Matrix4& transformation); - + bool collides(const AbstractShape<3>* other) const; + #else + void applyTransformation(const MatrixType& transformation); bool collides(const AbstractShape* other) const; + #endif /** @brief Position */ inline Vector3 position() const { return _position; } @@ -64,10 +70,10 @@ class PHYSICS_EXPORT Plane: public AbstractShape { } /** @brief Collision with line */ - bool operator%(const Line& other) const; + bool operator%(const Line3D& other) const; /** @brief Collision with line segment */ - bool operator%(const LineSegment& other) const; + bool operator%(const LineSegment3D& other) const; protected: inline Type type() const { return Type::Plane; } @@ -78,10 +84,10 @@ class PHYSICS_EXPORT Plane: public AbstractShape { }; /** @collisionoperator{Line,Plane} */ -inline bool operator%(const Line& a, const Plane& b) { return b % a; } +inline bool operator%(const Line3D& a, const Plane& b) { return b % a; } /** @collisionoperator{LineSegment,Plane} */ -inline bool operator%(const LineSegment& a, const Plane& b) { return b % a; } +inline bool operator%(const LineSegment3D& a, const Plane& b) { return b % a; } }} diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 6ec43579b..048e66207 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,8 +20,11 @@ namespace Magnum { namespace Physics { -void Point::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Point3D(_position)).xyz(); +template void Point::applyTransformation(const typename AbstractShape::MatrixType& transformation) { + _transformedPosition = (transformation*typename AbstractShape::PointType(_position)).vector(); } +template class Point<2>; +template class Point<3>; + }} diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 787236b6b..05483d9b3 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::Point + * @brief Class Magnum::Physics::Point, typedef Magnum::Physics::Point2D, Magnum::Physics::Point3D */ #include "Math/Vector3.h" @@ -24,34 +24,55 @@ namespace Magnum { namespace Physics { -/** @brief %Point */ -class PHYSICS_EXPORT Point: public AbstractShape { +/** +@brief %Point + +@see Point2D, Point3D +*/ +template class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ - inline Point(const Vector3& position): _position(position), _transformedPosition(position) {} + inline Point(const typename AbstractShape::VectorType& position): _position(position), _transformedPosition(position) {} - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif /** @brief Position */ - inline Vector3 position() const { return _position; } + inline typename AbstractShape::VectorType position() const { + return _position; + } /** @brief Set position */ - inline void setPosition(const Vector3& position) { + inline void setPosition(const typename AbstractShape::VectorType& position) { _position = position; } /** @brief Transformed position */ - inline Vector3 transformedPosition() const { + inline typename AbstractShape::VectorType transformedPosition() const { return _transformedPosition; } protected: - inline Type type() const { return Type::Point; } + inline typename AbstractShape::Type type() const { return AbstractShape::Type::Point; } private: - Vector3 _position, _transformedPosition; + typename AbstractShape::VectorType _position, _transformedPosition; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT Point<2>; +extern template class PHYSICS_EXPORT Point<3>; +#endif + +/** @brief Two-dimensional point */ +typedef Point<2> Point2D; + +/** @brief Three-dimensional point */ +typedef Point<3> Point3D; + }} #endif diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 4f70f0b9e..813baf7bd 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -17,47 +17,50 @@ namespace Magnum { namespace Physics { -ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { - other.operation = AlwaysFalse; +template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { + other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; } -ShapeGroup::~ShapeGroup() { - if(!(operation & RefA)) delete a; - if(!(operation & RefB)) delete b; +template ShapeGroup::~ShapeGroup() { + if(!(operation & Implementation::GroupOperation::RefA)) delete a; + if(!(operation & Implementation::GroupOperation::RefB)) delete b; } -ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { - if(!(operation & RefA)) delete a; - if(!(operation & RefB)) delete b; +template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { + if(!(operation & Implementation::GroupOperation::RefA)) delete a; + if(!(operation & Implementation::GroupOperation::RefB)) delete b; operation = other.operation; a = other.a; b = other.b; - other.operation = AlwaysFalse; + other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; return *this; } -void ShapeGroup::applyTransformation(const Matrix4& transformation) { +template void ShapeGroup::applyTransformation(const typename AbstractShape::MatrixType& transformation) { if(a) a->applyTransformation(transformation); if(b) b->applyTransformation(transformation); } -bool ShapeGroup::collides(const AbstractShape* other) const { - switch(operation & ~RefAB) { - case And: return a->collides(other) && b->collides(other); - case Or: return a->collides(other) || b->collides(other); - case Not: return !a->collides(other); - case FirstObjectOnly: return a->collides(other); +template bool ShapeGroup::collides(const AbstractShape* other) const { + switch(operation & ~Implementation::GroupOperation::RefAB) { + case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); + case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); + case Implementation::GroupOperation::Not: return !a->collides(other); + case Implementation::GroupOperation::FirstObjectOnly: return a->collides(other); default: return false; } } +template class ShapeGroup<2>; +template class ShapeGroup<3>; + }} diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 4b56a8cb8..200898761 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::ShapeGroup + * @brief Class Magnum::Physics::ShapeGroup, typedef Magnum::Physics::ShapeGroup2D, Magnum::Physics::ShapeGroup3D */ #include "AbstractShape.h" @@ -27,8 +27,25 @@ namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT -#define enableIfIsBaseType typename std::enable_if::value, ShapeGroup>::type -#define enableIfAreBaseType typename std::enable_if::value && std::is_base_of::value, ShapeGroup>::type +namespace Implementation { + enum GroupOperation { + RefA = 0x01, + RefB = 0x02, + RefAB = 0x03, +// Complement = 1 << 2, +// Union = 2 << 2, +// Intersection = 3 << 2, +// Difference = 4 << 2, +// Xor = 5 << 2, + And = 6 << 2, + Or = 7 << 2, + Not = 8 << 2, + FirstObjectOnly = 9 << 2, + AlwaysFalse = 10 << 2 + }; +} +#define enableIfIsBaseType typename std::enable_if, T>::value, ShapeGroup>::type +#define enableIfAreBaseType typename std::enable_if, T>::value && std::is_base_of, U>::value, ShapeGroup>::type #endif /** @@ -36,26 +53,27 @@ namespace Magnum { namespace Physics { Result of logical operations on shapes. See @ref collision-detection for brief introduction. +@see ShapeGroup2D, ShapeGroup3D */ -class PHYSICS_EXPORT ShapeGroup: public AbstractShape { +template class PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT -// template friend constexpr enableIfIsBaseType operator~(const T& a); -// template friend constexpr enableIfIsBaseType operator~(T&& a); -// template friend constexpr enableIfIsBaseType operator~(T& a); - template friend constexpr enableIfIsBaseType operator!(const T& a); - template friend constexpr enableIfIsBaseType operator!(T&& a); - template friend constexpr enableIfIsBaseType operator!(T& a); +// template friend constexpr operator~(const T& a) -> enableIfIsBaseType; +// template friend constexpr operator~(T&& a) -> enableIfIsBaseType; +// template friend constexpr operator~(T& a) -> enableIfIsBaseType; + template friend constexpr auto operator!(const T& a) -> enableIfIsBaseType; + template friend constexpr auto operator!(T&& a) -> enableIfIsBaseType; + template friend constexpr auto operator!(T& a) -> enableIfIsBaseType; #define friendOp(char) \ - template friend constexpr enableIfAreBaseType operator char(const T& a, const U& b); \ - template friend constexpr enableIfAreBaseType operator char(const T& a, U&& b); \ - template friend constexpr enableIfAreBaseType operator char(T&& a, const U& b); \ - template friend constexpr enableIfAreBaseType operator char(T&& a, U&& b); \ - template friend constexpr enableIfAreBaseType operator char(const T& a, std::reference_wrapper b); \ - template friend constexpr enableIfAreBaseType operator char(T&& a, std::reference_wrapper b); \ - template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, const U& b); \ - template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, U&& b); \ - template friend constexpr enableIfAreBaseType operator char(std::reference_wrapper a, std::reference_wrapper b); + template friend constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(const T& a, U&& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(T&& a, const U& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(T&& a, U&& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(const T& a, std::reference_wrapper b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(T&& a, std::reference_wrapper b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(std::reference_wrapper a, const U& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(std::reference_wrapper a, U&& b) -> enableIfAreBaseType; \ + template friend constexpr auto operator char(std::reference_wrapper a, std::reference_wrapper b) -> enableIfAreBaseType; // friendOp(|) // friendOp(&) // friendOp(-) @@ -68,26 +86,9 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { ShapeGroup(const ShapeGroup& other) = delete; ShapeGroup& operator=(const ShapeGroup& other) = delete; - private: - enum Operation { - RefA = 0x01, - RefB = 0x02, - RefAB = 0x03, -// Complement = 1 << 2, -// Union = 2 << 2, -// Intersection = 3 << 2, -// Difference = 4 << 2, -// Xor = 5 << 2, - And = 6 << 2, - Or = 7 << 2, - Not = 8 << 2, - FirstObjectOnly = 9 << 2, - AlwaysFalse = 10 << 2 - }; - public: /** @brief Default constructor */ - inline ShapeGroup(): operation(AlwaysFalse), a(nullptr), b(nullptr) {} + inline ShapeGroup(): operation(Implementation::GroupOperation::AlwaysFalse), a(nullptr), b(nullptr) {} /** @brief Move constructor */ ShapeGroup(ShapeGroup&& other); @@ -98,21 +99,36 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { /** @brief Move assignment */ ShapeGroup& operator=(ShapeGroup&& other); - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const; protected: - virtual Type type() const { return Type::ShapeGroup; } + virtual typename AbstractShape::Type type() const { return AbstractShape::Type::ShapeGroup; } private: - inline ShapeGroup(int operation, AbstractShape* a, AbstractShape* b): operation(operation), a(a), b(b) {} + inline ShapeGroup(int operation, AbstractShape* a, AbstractShape* b): operation(operation), a(a), b(b) {} int operation; - AbstractShape* a; - AbstractShape* b; + AbstractShape* a; + AbstractShape* b; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT ShapeGroup<2>; +extern template class PHYSICS_EXPORT ShapeGroup<3>; +#endif + +/** @brief Two-dimensional shape group */ +typedef ShapeGroup<2> ShapeGroup2D; + +/** @brief Three-dimensional shape group */ +typedef ShapeGroup<3> ShapeGroup3D; + // /* @brief Complement of shape */ // template inline constexpr enableIfIsBaseType operator~(const T& a) { // return ShapeGroup(ShapeGroup::Complement, new T(a), nullptr); @@ -129,15 +145,15 @@ class PHYSICS_EXPORT ShapeGroup: public AbstractShape { /** @relates ShapeGroup @brief Logical NOT of shape */ -template inline constexpr enableIfIsBaseType operator!(const T& a) { - return ShapeGroup(ShapeGroup::Not, new T(a), nullptr); +template inline constexpr auto operator!(const T& a) -> enableIfIsBaseType { + return ShapeGroup(Implementation::GroupOperation::Not, new T(a), nullptr); } #ifndef DOXYGEN_GENERATING_OUTPUT -template inline constexpr enableIfIsBaseType operator!(T&& a) { - return ShapeGroup(ShapeGroup::Not, new T(std::forward(a)), nullptr); +template inline constexpr auto operator!(T&& a) -> enableIfIsBaseType { + return ShapeGroup(Implementation::GroupOperation::Not, new T(std::forward(a)), nullptr); } -template inline constexpr enableIfIsBaseType operator!(T& a) { - return ShapeGroup(ShapeGroup::Not|ShapeGroup::RefA, &a.get(), nullptr); +template inline constexpr auto operator!(T& a) -> enableIfIsBaseType { + return ShapeGroup(Implementation::GroupOperation::Not|Implementation::GroupOperation::RefA, &a.get(), nullptr); } #endif @@ -161,7 +177,7 @@ is used here, so this operation can be used for providing simplified shape version, because collision with @p b is computed only if @p a collides. See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); /** @relates ShapeGroup @brief Logical OR of two shapes @@ -170,35 +186,35 @@ template inline constexpr ShapeGroup operator&&(T a, U b); is used, so if collision with @p a is detected, collision with @p b is not computed. */ -template inline constexpr ShapeGroup operator||(T a, U b); +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ -template inline constexpr enableIfAreBaseType operator char(const T& a, const U& b) { \ - return ShapeGroup(ShapeGroup::type, new T(a), new U(b)); \ +template inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type, new T(a), new U(b)); \ } \ -template inline constexpr enableIfAreBaseType operator char(const T& a, U&& b) { \ - return ShapeGroup(ShapeGroup::type, new T(a), new U(std::forward(b))); \ +template inline constexpr auto operator char(const T& a, U&& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type, new T(a), new U(std::forward(b))); \ } \ -template inline constexpr enableIfAreBaseType operator char(T&& a, const U& b) { \ - return ShapeGroup(ShapeGroup::type, new T(std::forward(a)), new U(b)); \ +template inline constexpr auto operator char(T&& a, const U& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type, new T(std::forward(a)), new U(b)); \ } \ -template inline constexpr enableIfAreBaseType operator char(T&& a, U&& b) { \ - return ShapeGroup(ShapeGroup::type, new T(std::forward(a)), new U(std::forward(b))); \ +template inline constexpr auto operator char(T&& a, U&& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type, new T(std::forward(a)), new U(std::forward(b))); \ } \ -template inline constexpr enableIfAreBaseType operator char(const T& a, std::reference_wrapper b) { \ - return ShapeGroup(ShapeGroup::type|ShapeGroup::RefB, new T(a), &b.get()); \ +template inline constexpr auto operator char(const T& a, std::reference_wrapper b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type|Implementation::GroupOperation::RefB, new T(a), &b.get()); \ } \ -template inline constexpr enableIfAreBaseType operator char(T&& a, std::reference_wrapper b) { \ - return ShapeGroup(ShapeGroup::type|ShapeGroup::RefB, new T(std::forward(a)), &b.get()); \ +template inline constexpr auto operator char(T&& a, std::reference_wrapper b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type|Implementation::GroupOperation::RefB, new T(std::forward(a)), &b.get()); \ } \ -template inline constexpr enableIfAreBaseType operator char(std::reference_wrapper a, const U& b) { \ - return ShapeGroup(ShapeGroup::type|ShapeGroup::RefA, &a.get(), new U(b)); \ +template inline constexpr auto operator char(std::reference_wrapper a, const U& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type|Implementation::GroupOperation::RefA, &a.get(), new U(b)); \ } \ -template inline constexpr enableIfAreBaseType operator char(std::reference_wrapper a, U&& b) { \ - return ShapeGroup(ShapeGroup::type|ShapeGroup::RefA, &a.get(), new U(std::forward(b))); \ +template inline constexpr auto operator char(std::reference_wrapper a, U&& b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type|Implementation::GroupOperation::RefA, &a.get(), new U(std::forward(b))); \ } \ -template inline constexpr enableIfAreBaseType operator char(std::reference_wrapper a, std::reference_wrapper b) { \ - return ShapeGroup(ShapeGroup::type|ShapeGroup::RefAB, &a.get(), &b.get()); \ +template inline constexpr auto operator char(std::reference_wrapper a, std::reference_wrapper b) -> enableIfAreBaseType { \ + return ShapeGroup(Implementation::GroupOperation::type|Implementation::GroupOperation::RefAB, &a.get(), &b.get()); \ } // op(Union, |) // op(Intersection, &) diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index f3b0579b1..b2f6d00fb 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -27,43 +27,58 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -void Sphere::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Point3D(_position)).xyz(); - float scaling = (transformation.rotationScaling()*Vector3(1/Math::Constants::sqrt3())).length(); +namespace { + template static typename AbstractShape::VectorType unitVector(); + + template<> inline Vector2 unitVector<2>() { + return Vector2(1/Math::Constants::sqrt2()); + } + + template<> inline Vector3 unitVector<3>() { + return Vector3(1/Math::Constants::sqrt3()); + } +} + +template void Sphere::applyTransformation(const typename AbstractShape::MatrixType& transformation) { + _transformedPosition = (transformation*typename AbstractShape::PointType(_position)).vector(); + float scaling = (transformation.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } -bool Sphere::collides(const AbstractShape* other) const { - if(other->type() == Type::Point) - return *this % *static_cast(other); - if(other->type() == Type::Line) - return *this % *static_cast(other); - if(other->type() == Type::LineSegment) - return *this % *static_cast(other); - if(other->type() == Type::Sphere) - return *this % *static_cast(other); - - return AbstractShape::collides(other); +template bool Sphere::collides(const AbstractShape* other) const { + if(other->type() == AbstractShape::Type::Point) + return *this % *static_cast*>(other); + if(other->type() == AbstractShape::Type::Line) + return *this % *static_cast*>(other); + if(other->type() == AbstractShape::Type::LineSegment) + return *this % *static_cast*>(other); + if(other->type() == AbstractShape::Type::Sphere) + return *this % *static_cast*>(other); + + return AbstractShape::collides(other); } -bool Sphere::operator%(const Point& other) const { +template bool Sphere::operator%(const Point& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()); } -bool Sphere::operator%(const Line& other) const { +template bool Sphere::operator%(const Line& other) const { return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -bool Sphere::operator%(const LineSegment& other) const { +template bool Sphere::operator%(const LineSegment& other) const { return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -bool Sphere::operator%(const Sphere& other) const { +template bool Sphere::operator%(const Sphere& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()+other.transformedRadius()); } +template class Sphere<2>; +template class Sphere<3>; + }} diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index ddc317603..60639a37d 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::Sphere + * @brief Class Magnum::Physics::Sphere, typedef Magnum::Physics::Sphere2D, Magnum::Physics::Sphere3D */ #include "Math/Vector3.h" @@ -24,30 +24,39 @@ namespace Magnum { namespace Physics { -class Line; -class LineSegment; -class Point; +template class Line; +template class LineSegment; +template class Point; /** @brief %Sphere defined by position and radius Unlike other elements the sphere doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. +@see Sphere2D, Sphere3D */ -class PHYSICS_EXPORT Sphere: public AbstractShape { +template class PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline Sphere(const Vector3& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline Sphere(const typename AbstractShape::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} - void applyTransformation(const Matrix4& transformation); + #ifndef DOXYGEN_GENERATING_OUTPUT + void applyTransformation(const typename AbstractShape::MatrixType& transformation); + #else + void applyTransformation(const MatrixType& transformation); + #endif - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const; /** @brief Position */ - inline Vector3 position() const { return _position; } + inline typename AbstractShape::VectorType position() const { + return _position; + } /** @brief Set position */ - inline void setPosition(const Vector3& position) { _position = position; } + inline void setPosition(const typename AbstractShape::VectorType& position) { + _position = position; + } /** @brief Radius */ inline float radius() const { return _radius; } @@ -56,7 +65,7 @@ class PHYSICS_EXPORT Sphere: public AbstractShape { inline void setRadius(float radius) { _radius = radius; } /** @brief Transformed position */ - inline Vector3 transformedPosition() const { + inline typename AbstractShape::VectorType transformedPosition() const { return _transformedPosition; } @@ -66,33 +75,47 @@ class PHYSICS_EXPORT Sphere: public AbstractShape { } /** @brief Collision with point */ - bool operator%(const Point& other) const; + bool operator%(const Point& other) const; /** @brief Collision with line */ - bool operator%(const Line& other) const; + bool operator%(const Line& other) const; /** @brief Collision with line segment */ - bool operator%(const LineSegment& other) const; + bool operator%(const LineSegment& other) const; /** @brief Collision with sphere */ - bool operator%(const Sphere& other) const; + bool operator%(const Sphere& other) const; protected: - inline Type type() const { return Type::Sphere; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Sphere; + } private: - Vector3 _position, _transformedPosition; + typename AbstractShape::VectorType _position, + _transformedPosition; float _radius, _transformedRadius; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT Sphere<2>; +extern template class PHYSICS_EXPORT Sphere<3>; +#endif + +/** @brief Two-dimensional sphere */ +typedef Sphere<2> Sphere2D; + +/** @brief Three-dimensional sphere */ +typedef Sphere<3> Sphere3D; + /** @collisionoperator{Point,Sphere} */ -inline bool operator%(const Point& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } /** @collisionoperator{Line,Sphere} */ -inline bool operator%(const Line& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } /** @collisionoperator{LineSegment,Sphere} */ -inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } +template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } }} diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index 81d6eba57..da5cd0894 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -28,7 +28,7 @@ AxisAlignedBoxTest::AxisAlignedBoxTest() { } void AxisAlignedBoxTest::applyTransformation() { - Physics::AxisAlignedBox box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); + Physics::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); CORRADE_COMPARE(box.transformedPosition(), Vector3(-2.0f, 2.0f, -4.5f)); diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp index e844e4d2e..32c04ff48 100644 --- a/src/Physics/Test/BoxTest.cpp +++ b/src/Physics/Test/BoxTest.cpp @@ -27,7 +27,7 @@ BoxTest::BoxTest() { } void BoxTest::applyTransformation() { - Physics::Box box(Matrix4::translation({1.0f, 2.0f, -3.0f})); + Physics::Box3D box(Matrix4::translation({1.0f, 2.0f, -3.0f})); box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); CORRADE_COMPARE(box.transformedTransformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f})); diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 17feb9204..1d11fabc4 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -30,7 +30,7 @@ CapsuleTest::CapsuleTest() { } void CapsuleTest::applyTransformation() { - Physics::Capsule capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); + Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); capsule.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); CORRADE_COMPARE(capsule.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); @@ -43,10 +43,10 @@ void CapsuleTest::applyTransformation() { } void CapsuleTest::collisionPoint() { - Physics::Capsule capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); - Physics::Point point({2.0f, 0.0f, 0.0f}); - Physics::Point point1({2.9f, 1.0f, 0.0f}); - Physics::Point point2({1.0f, 3.1f, 0.0f}); + Physics::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); + Physics::Point3D point({2.0f, 0.0f, 0.0f}); + Physics::Point3D point1({2.9f, 1.0f, 0.0f}); + Physics::Point3D point2({1.0f, 3.1f, 0.0f}); randomTransformation(capsule); randomTransformation(point); @@ -59,10 +59,10 @@ void CapsuleTest::collisionPoint() { } void CapsuleTest::collisionSphere() { - Physics::Capsule capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); - Physics::Sphere sphere({3.0f, 0.0f, 0.0f}, 0.9f); - Physics::Sphere sphere1({3.5f, 1.0f, 0.0f}, 0.6f); - Physics::Sphere sphere2({1.0f, 4.1f, 0.0f}, 1.0f); + Physics::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); + Physics::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f); + Physics::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f); + Physics::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f); randomTransformation(capsule); randomTransformation(sphere); diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 1e06ccb4b..2a673d33c 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -28,7 +28,7 @@ LineTest::LineTest() { } void LineTest::applyTransformation() { - Physics::Line line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); + Physics::Line3D line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); line.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); CORRADE_COMPARE(line.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(line.transformedB(), Vector3(2.0f, -1.0f, -3.0f)); diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index f2f799189..75170f84c 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -45,9 +45,9 @@ void PlaneTest::applyTransformation() { void PlaneTest::collisionLine() { Physics::Plane plane(Vector3(), Vector3::yAxis()); - Physics::Line line({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}); - Physics::Line line2({0.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); - Physics::Line line3({0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); + Physics::Line3D line({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}); + Physics::Line3D line2({0.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); + Physics::Line3D line3({0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); randomTransformation(plane); randomTransformation(line); @@ -61,9 +61,9 @@ void PlaneTest::collisionLine() { void PlaneTest::collisionLineSegment() { Physics::Plane plane(Vector3(), Vector3::yAxis()); - Physics::LineSegment line({0.0f, -0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); - Physics::LineSegment line2({0.0f, 0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); - Physics::LineSegment line3({0.0f, -7.0f, 0.0f}, {0.0f, -0.1f, 0.0f}); + Physics::LineSegment3D line({0.0f, -0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); + Physics::LineSegment3D line2({0.0f, 0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); + Physics::LineSegment3D line3({0.0f, -7.0f, 0.0f}, {0.0f, -0.1f, 0.0f}); randomTransformation(plane); randomTransformation(line); diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index ed191dfc5..f6e47e785 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -27,7 +27,7 @@ PointTest::PointTest() { } void PointTest::applyTransformation() { - Physics::Point point({1.0f, 2.0f, 3.0f}); + Physics::Point3D point({1.0f, 2.0f, 3.0f}); point.applyTransformation(Matrix4::translation({5.0f, 6.0f, 7.0f})); CORRADE_COMPARE(point.transformedPosition(), Vector3(6.0f, 8.0f, 10.0f)); } diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index 69eaffa13..4270fd4be 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -32,10 +32,10 @@ ShapeGroupTest::ShapeGroupTest() { } void ShapeGroupTest::copy() { - ShapeGroup group; + ShapeGroup3D group; { - Physics::Point point({1.0f, 2.0f, 3.0f}); - Physics::LineSegment segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); + Physics::Point3D point({1.0f, 2.0f, 3.0f}); + Physics::LineSegment3D segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); group = !(point || segment); } @@ -47,10 +47,10 @@ void ShapeGroupTest::copy() { } void ShapeGroupTest::reference() { - Physics::Point point({1.0f, 2.0f, 3.0f}); - Physics::LineSegment segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); + Physics::Point3D point({1.0f, 2.0f, 3.0f}); + Physics::LineSegment3D segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); - ShapeGroup group = !(ref(point) || ref(segment)); + ShapeGroup3D group = !(ref(point) || ref(segment)); group.applyTransformation(Matrix4::translation(Vector3(1.0f))); diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index d78291a2c..473be576c 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -33,7 +33,7 @@ SphereTest::SphereTest() { } void SphereTest::applyTransformation() { - Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 7.0f); + Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); sphere.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::yAxis())); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f)); @@ -50,9 +50,9 @@ void SphereTest::applyTransformation() { } void SphereTest::collisionPoint() { - Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 2.0f); - Physics::Point point({1.0f, 3.0f, 3.0f}); - Physics::Point point2({1.0f, 3.0f, 1.0f}); + Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); + Physics::Point3D point({1.0f, 3.0f, 3.0f}); + Physics::Point3D point2({1.0f, 3.0f, 1.0f}); randomTransformation(sphere); randomTransformation(point); @@ -63,9 +63,9 @@ void SphereTest::collisionPoint() { } void SphereTest::collisionLine() { - Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 2.0f); - Physics::Line line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f}); - Physics::Line line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f}); + Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); + Physics::Line3D line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f}); + Physics::Line3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f}); randomTransformation(sphere); randomTransformation(line); @@ -76,9 +76,9 @@ void SphereTest::collisionLine() { } void SphereTest::collisionLineSegment() { - Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 2.0f); - Physics::LineSegment line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f}); - Physics::LineSegment line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f}); + Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); + Physics::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f}); + Physics::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f}); randomTransformation(sphere); randomTransformation(line); @@ -89,9 +89,9 @@ void SphereTest::collisionLineSegment() { } void SphereTest::collisionSphere() { - Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 2.0f); - Physics::Sphere sphere1({1.0f, 3.0f, 5.0f}, 1.0f); - Physics::Sphere sphere2({1.0f, 3.0f, 0.0f}, 1.0f); + Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); + Physics::Sphere3D sphere1({1.0f, 3.0f, 5.0f}, 1.0f); + Physics::Sphere3D sphere2({1.0f, 3.0f, 0.0f}, 1.0f); randomTransformation(sphere); randomTransformation(sphere1); From 949b092a60d68af15b67e3e58858f42408f99ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 27 Sep 2012 18:49:35 +0200 Subject: [PATCH 103/256] Support for '0' and '1' constants in swizzle() functions. Also deconfused related documentation a bit. --- doc/matrix-vector.dox | 6 +-- src/Swizzle.h | 84 ++++++++++++++++++++++------------------ src/Test/SwizzleTest.cpp | 8 ++++ src/Test/SwizzleTest.h | 1 + 4 files changed, 59 insertions(+), 40 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 795f5619c..6b05b00c3 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -138,9 +138,9 @@ For more involved operations with components there are two swizzle() functions, they have the same features, but one is guaranteed to do most of the work at compile-time, while the second has more convenient syntax: @code -Vector4 original(1, 2, 3, 4); -Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, 1, 4 } -Vector<6, int> a10rgb = swizzle(original, "a10rgb"); // { 4, 1, 0, 1, 2, 3 } +Vector4 original(-1, 2, 3, 4); +Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } +Vector<6, int> a10rgb = swizzle(original, "a10rgb"); // { 4, 1, 0, -1, 2, 3 } @endcode @section matrix-vector-column-major Matrices are column-major and vectors are columns diff --git a/src/Swizzle.h b/src/Swizzle.h index d61ae1cdb..cc57ca072 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -28,21 +28,27 @@ namespace Implementation { using Math::Implementation::Sequence; using Math::Implementation::GenerateSequence; - template struct GetPosition { + template struct ComponentAtPosition { static_assert(size > position, "Swizzle parameter out of range of base vector"); - inline constexpr static size_t value() { return position; } + template inline constexpr static T value(const Math::Vector& vector) { return vector[position]; } }; - template struct GetComponent {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; - template struct GetComponent: public GetPosition {}; + template struct Component {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component { + template inline constexpr static T value(const Math::Vector&) { return T(0); } + }; + template struct Component { + template inline constexpr static T value(const Math::Vector&) { return T(1); } + }; template struct TypeForSize { typedef Math::Vector Type; @@ -55,24 +61,26 @@ namespace Implementation { template struct TypeForSize<4, Color3> { typedef Color4 Type; }; template struct TypeForSize<4, Color4> { typedef Color4 Type; }; - inline constexpr size_t getPosition(size_t size, size_t position) { - return size > position ? position : throw; + template inline constexpr T componentAtPosition(const Math::Vector& vector, size_t position) { + return size > position ? vector[position] : throw; } - template inline constexpr size_t getComponent(char component) { - return component == 'x' ? getPosition(size, 0) : - component == 'y' ? getPosition(size, 1) : - component == 'z' ? getPosition(size, 2) : - component == 'w' ? getPosition(size, 3) : - component == 'r' ? getPosition(size, 0) : - component == 'g' ? getPosition(size, 1) : - component == 'b' ? getPosition(size, 2) : - component == 'a' ? getPosition(size, 3) : + template inline constexpr T component(const Math::Vector& vector, char component) { + return component == 'x' ? componentAtPosition(vector, 0) : + component == 'y' ? componentAtPosition(vector, 1) : + component == 'z' ? componentAtPosition(vector, 2) : + component == 'w' ? componentAtPosition(vector, 3) : + component == 'r' ? componentAtPosition(vector, 0) : + component == 'g' ? componentAtPosition(vector, 1) : + component == 'b' ? componentAtPosition(vector, 2) : + component == 'a' ? componentAtPosition(vector, 3) : + component == '0' ? T(0) : + component == '1' ? T(1) : throw; } template inline constexpr Math::Vector swizzleFrom(Sequence, const Math::Vector& vector, const char(&components)[sizeof...(sequence)+1]) { - return {vector[getComponent(components[sequence])]...}; + return {component(vector, components[sequence])...}; } } #endif @@ -82,14 +90,15 @@ namespace Implementation { Creates new vector from given components. Example: @code -Vector4 original(1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); -auto vec = swizzle<'a', 'b', 'b', 'g', 'r', 'r'>(original); -// vec == { 4, 3, 3, 2, 1, 1 } +auto vec = swizzle<'a', '1', '0', 'r', 'g', 'b'>(original); +// vec == { 4, 1, 0, -1, 2, 3 } @endcode -You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a`. Count of -elements is unlimited, but must be at least one. If the resulting vector is -two, three or four-component, corresponding Vector2, Vector3 or Vector4 +You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a` for addressing +components or letters `0` and `1` for zero and one. Count of elements is +unlimited, but must be at least one. If the resulting vector is two, three or +four-component, corresponding Vector2, Vector3, Vector4, Color3 or Color4 specialization is returned. @attention This function is less convenient to write than @@ -101,7 +110,7 @@ instead of at runtime. Vector4::xy(), Vector3::xy() */ template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector) { - return {vector[Implementation::GetComponent::value()]...}; + return {Implementation::Component::value(vector)...}; } /** @@ -109,15 +118,16 @@ template inline constexpr typename Implementation:: Creates new vector from given components. Example: @code -Vector4 original(1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); -auto vec = swizzle(original, "abbgrr"); -// vec == { 4, 3, 3, 2, 1, 1 } +auto vec = swizzle(original, "a10rgb"); +// vec == { 4, 1, 0, -1, 2, 3 } @endcode -You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a`. Count of -elements is unlimited, but must be at least one. If the resulting vector is -two, three or four-component, corresponding Vector2, Vector3 or Vector4 -specialization is returned. +You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a` for addressing +components or letters `0` and `1` for zero and one. Count of elements is +unlimited, but must be at least one. If the resulting vector is two, three or +four-component, corresponding Vector2, Vector3 or Vector4 specialization is +returned. @attention This function is more convenient to write than swizzle(const T&), but unless the result is marked with diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 561b53fcf..4f57462a8 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -30,6 +30,7 @@ typedef Math::Vector4 Vector4; SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::xyzw, &SwizzleTest::rgba, + &SwizzleTest::constants, &SwizzleTest::fromSmall, &SwizzleTest::type, &SwizzleTest::defaultType); @@ -49,6 +50,13 @@ void SwizzleTest::rgba() { CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(orig)), swizzled); } +void SwizzleTest::constants() { + Vector4 orig(2, 4, 5, 7); + Vector4 swizzled(1, 7, 0, 4); + CORRADE_COMPARE(swizzle(orig, "1w0g"), swizzled); + CORRADE_COMPARE((swizzle<'1', 'w', '0', 'g'>(orig)), swizzled); +} + void SwizzleTest::fromSmall() { /* Force compile-time evaluation for both */ constexpr Vector2 orig(1, 2); diff --git a/src/Test/SwizzleTest.h b/src/Test/SwizzleTest.h index b43180be0..56a705f5d 100644 --- a/src/Test/SwizzleTest.h +++ b/src/Test/SwizzleTest.h @@ -25,6 +25,7 @@ class SwizzleTest: public Corrade::TestSuite::Tester { void xyzw(); void rgba(); + void constants(); void fromSmall(); void type(); void defaultType(); From 6895611f9b107bd88b72297464b90b4b7e54a7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 16:54:40 +0200 Subject: [PATCH 104/256] Fixed ResourceManager example. --- src/ResourceManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 06ac7a99c..f58b59280 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -400,8 +400,8 @@ Resource texture(manager->get("texture")); Resource shader(manager->get("shader")); Resource cube(manager->get("cube")); -// The manager doesn't have data for the mesh yet, add them -if(!mesh) { +// The manager doesn't have data for the cube yet, add them +if(!cube) { Mesh* mesh = new Mesh; // ... manager->set("cube", mesh, ResourceDataState::Final, ResourcePolicy::Resident); From 9e24a7bca098751135539ecf3e80d71814ab75fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 20:14:59 +0200 Subject: [PATCH 105/256] Don't return Matrix3 from Matrix4 member functions. Matrix3 is for 2D affine transformations, while Matrix4 is for 3D. Returning Matrix3 would allow doing this, which isn't meaningful operation at all: Matrix4 transformation; Vector2 wtf = transformation.rotationScaling().translation(); --- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index f9a1f75de..8078198bc 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { /** -@brief 3x3 matrix +@brief 3x3 matrix for affine transformations in 2D @tparam T Data type Provides functions for transformations in 2D. See Matrix4 for 3D diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 1d72ee70a..2563646b9 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { /** -@brief 4x4 matrix +@brief 4x4 matrix for affine transformations in 3D @tparam T Data type Provides functions for transformations in 3D. See Matrix3 for 2D @@ -138,8 +138,9 @@ template class Matrix4: public Matrix<4, T> { * @see rotation() const, rotation(T, const Vector3&), * Matrix3::rotationScaling() const */ - inline Matrix3 rotationScaling() const { - return Matrix3::from( + inline Matrix<3, T> rotationScaling() const { + /* Not Matrix3, because it is for affine 2D transformations */ + return Matrix<3, T>::from( (*this)[0].xyz(), (*this)[1].xyz(), (*this)[2].xyz()); @@ -152,8 +153,9 @@ template class Matrix4: public Matrix<4, T> { * @see rotationScaling() const, rotation(T, const Vector3&), * Matrix3::rotation() const */ - inline Matrix3 rotation() const { - return Matrix3::from( + inline Matrix<3, T> rotation() const { + /* Not Matrix3, because it is for affine 2D transformations */ + return Matrix<3, T>::from( (*this)[0].xyz().normalized(), (*this)[1].xyz().normalized(), (*this)[2].xyz().normalized()); @@ -175,8 +177,6 @@ template class Matrix4: public Matrix<4, T> { } #ifndef DOXYGEN_GENERATING_OUTPUT - inline Matrix3 ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); } - inline Point3D operator*(const Point3D& other) const { return Matrix<4, T>::operator*(other); } From bfbaa79e7bd4f047a7e80da27bbaaa7669986732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 20:26:25 +0200 Subject: [PATCH 106/256] Better documentation for primitives. --- src/Primitives/Capsule.h | 5 +++-- src/Primitives/Cube.h | 7 ++++++- src/Primitives/Cylinder.h | 7 ++++++- src/Primitives/Icosphere.h | 11 +++++++---- src/Primitives/Plane.h | 4 ++-- src/Primitives/Square.h | 4 ++-- src/Primitives/UVSphere.h | 6 +++++- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 570a1ede0..243e426c9 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -24,9 +24,10 @@ namespace Magnum { namespace Primitives { /** -@brief %Capsule primitive +@brief 3D capsule primitive -Cylinder along Y axis with hemispheres instead of caps. +Cylinder along Y axis with hemispheres instead of caps. Indexed with normals +and optional 2D texture coordinates. */ class Capsule: public Trade::MeshData3D { friend class UVSphere; diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index e44368f58..95f98c0f5 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -23,7 +23,12 @@ namespace Magnum { namespace Primitives { -/** @brief %Cube primitive */ +/** +@brief 3D cube primitive + +Indexed with smooth normals. +@todo Does anyone EVER want smooth normals on a cube?! +*/ class Cube: public Trade::MeshData3D { public: /** @brief Constructor */ diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index f68993b70..f8c5a5a3b 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -25,7 +25,12 @@ namespace Magnum { namespace Primitives { -/** @brief Cylinder primitive */ +/** +@brief 3D cylinder primitive + +Indexed with normals, optional 2D texture coordinates and optional capped +ends. +*/ class Cylinder: public Capsule { public: /** diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index a31c887d2..5bc2afacc 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -29,8 +29,9 @@ namespace Magnum { namespace Primitives { template class Icosphere; /** -@brief %Icosphere primitive with zero subdivisions +@brief 3D icosphere primitive with zero subdivisions +Indexed with normals. @todo Use own computed (and more precise) icosahedron data, not these stolen from Blender. */ @@ -41,9 +42,11 @@ template<> class Icosphere<0>: public Trade::MeshData3D { }; /** - * @brief %Icosphere primitive - * @tparam subdivisions Number of subdivisions - */ +@brief 3D icosphere primitive +@tparam subdivisions Number of subdivisions + +Indexed with normals. +*/ #ifndef DOXYGEN_GENERATING_OUTPUT template class Icosphere: public Icosphere<0> { #else diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 7f1693284..e1d0045ce 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Primitives { /** -@brief %Plane primitive +@brief 3D plane primitive -2x2 plane with normals in positive Z direction. +2x2 plane, non-indexed with normals in positive Z direction. */ class Plane: public Trade::MeshData3D { public: diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index 67ad3ad5e..eff7f6595 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Primitives { /** -@brief %Square primitive +@brief 2D square primitive -2x2 square. +2x2 square, non-indexed. */ class Square: public Trade::MeshData2D { public: diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index 4e6be3b63..2e81ae6f4 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -23,7 +23,11 @@ namespace Magnum { namespace Primitives { -/** @brief UV Sphere primitive */ +/** +@brief 3D UV sphere primitive + +Indexed with normals and optional 2D texture coordinates. +*/ class UVSphere: public Capsule { public: /** From 93961aca65d42af3634940aa2caea747b8bc1628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 20:54:42 +0200 Subject: [PATCH 107/256] Don't include Matrix3 in Matrix4, as it isn't used. Also updated includes in dependent headers. --- src/AbstractShaderProgram.h | 1 + src/Math/Matrix4.h | 2 +- src/Math/Test/Matrix4Test.cpp | 2 +- src/Physics/AxisAlignedBox.cpp | 2 +- src/Physics/Box.h | 1 + src/Physics/Capsule.cpp | 2 +- src/Physics/Line.cpp | 2 +- src/Physics/Point.cpp | 2 +- src/Physics/Sphere.cpp | 2 +- src/SceneGraph/Object.h | 1 + 10 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index b52513f3a..355330a44 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -21,6 +21,7 @@ #include +#include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Math/Vector4.h" #include "Magnum.h" diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 2563646b9..7bf1dc1b1 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Math::Matrix4 */ -#include "Matrix3.h" +#include "Matrix.h" #include "Point3D.h" namespace Magnum { namespace Math { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index fdb051277..496cb5627 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -28,7 +28,7 @@ using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { typedef Math::Matrix4 Matrix4; -typedef Math::Matrix3 Matrix3; +typedef Math::Matrix<3, float> Matrix3; typedef Math::Vector3 Vector3; Matrix4Test::Matrix4Test() { diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index e9e9c254e..49a7c919f 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -15,8 +15,8 @@ #include "AxisAlignedBox.h" +#include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 9c5aa6e5d..02515d976 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Physics::Box, typedef Magnum::Physics::Box2D, Magnum::Physics::Box3D */ +#include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "AbstractShape.h" diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index a8109e1a8..9dd3715a4 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -17,8 +17,8 @@ #include "Math/Constants.h" #include "Math/Math.h" +#include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "Point.h" #include "Sphere.h" diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 882c516b7..5adf4f61a 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -15,8 +15,8 @@ #include "Line.h" +#include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 048e66207..67657450c 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -15,8 +15,8 @@ #include "Point.h" +#include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index b2f6d00fb..6015f5950 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -17,8 +17,8 @@ #include "Math/Constants.h" #include "Math/Math.h" +#include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" #include "Math/Geometry/Distance.h" #include "LineSegment.h" #include "Point.h" diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index cdeaf5a69..ddb8f6191 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -21,6 +21,7 @@ #include +#include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Magnum.h" From 23cbc121d676687c19c41c1fd83a99205c83fcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 21:39:01 +0200 Subject: [PATCH 108/256] Using only RectangularMatrix in setUniform(), added remaining setters. Shader implementations now have to include Vector, Matrix and Color classes on their own. --- src/AbstractShaderProgram.h | 79 ++++++++++++++++++++++++++++++------- src/Shaders/PhongShader.h | 10 +++-- 2 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 355330a44..d2f23c358 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -21,9 +21,7 @@ #include -#include "Math/Matrix3.h" -#include "Math/Matrix4.h" -#include "Math/Vector4.h" +#include "Math/RectangularMatrix.h" #include "Magnum.h" #include "magnumVisibility.h" @@ -379,17 +377,17 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Vector2& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLfloat>& value) { glUniform2fv(location, 1, value.data()); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Vector3& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLfloat>& value) { glUniform3fv(location, 1, value.data()); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Vector4& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLfloat>& value) { glUniform4fv(location, 1, value.data()); } @@ -399,17 +397,17 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** @copydoc setUniform(GLint, GLint) */ - inline void setUniform(GLint location, const Math::Vector2& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLint>& value) { glUniform2iv(location, 1, value.data()); } /** @copydoc setUniform(GLint, GLint) */ - inline void setUniform(GLint location, const Math::Vector3& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLint>& value) { glUniform3iv(location, 1, value.data()); } /** @copydoc setUniform(GLint, GLint) */ - inline void setUniform(GLint location, const Math::Vector4& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLint>& value) { glUniform4iv(location, 1, value.data()); } @@ -427,7 +425,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::Vector2& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLuint>& value) { glUniform2uiv(location, 1, value.data()); } @@ -436,7 +434,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::Vector3& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLuint>& value) { glUniform3uiv(location, 1, value.data()); } @@ -445,20 +443,73 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::Vector4& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLuint>& value) { glUniform4uiv(location, 1, value.data()); } /** @copydoc setUniform(GLint, GLint) */ - inline void setUniform(GLint location, const Matrix3& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLfloat>& value) { + glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); + } + + /** @copydoc setUniform(GLint, GLint) */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 3, GLfloat>& value) { glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); } /** @copydoc setUniform(GLint, GLint) */ - inline void setUniform(GLint location, const Matrix4& value) { + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 4, GLfloat>& value) { glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); } + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { + glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { + glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { + glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { + glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { + glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLint) + * @requires_gles30 (no extension providing this functionality) + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { + glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); + } + private: enum State { Initialized, diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index a6dd5c6dc..547f1d016 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -19,7 +19,9 @@ * @brief Class Magnum::Shaders::PhongShader */ +#include "Math/Matrix4.h" #include "AbstractShaderProgram.h" +#include "Color.h" #include "magnumShadersVisibility.h" @@ -44,12 +46,12 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. */ - inline void setAmbientColorUniform(const Vector3& color) { + inline void setAmbientColorUniform(const Color3& color) { setUniform(ambientColorUniform, color); } /** @brief Diffuse color */ - inline void setDiffuseColorUniform(const Vector3& color) { + inline void setDiffuseColorUniform(const Color3& color) { setUniform(diffuseColorUniform, color); } @@ -58,7 +60,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline void setSpecularColorUniform(const Vector3& color) { + inline void setSpecularColorUniform(const Color3& color) { setUniform(specularColorUniform, color); } @@ -92,7 +94,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline void setLightColorUniform(const Vector3& color) { + inline void setLightColorUniform(const Color3& color) { setUniform(lightColorUniform, color); } From 6a2ebf5c3d625442ccb49a5277226788adcb538a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 21:40:29 +0200 Subject: [PATCH 109/256] Fixed Vector, Point and Color constructors from smaller types. Currently, when accidentaly creating specialized Vector from smaller number of components than required, the error message isn't really helpful, as it stops on static assert on wrong number of arguments passed to RectangularMatrix: Vector3(0, 1); // static assert: wrong number of arguments passed to // RectangularMatrix<1, 2> -- wtf?! Now the first argument is Vector2/Vector3 instead of Vector<2>/Vector<3> and the error message now properly states that no matching constructor was found. --- src/Color.h | 2 +- src/Math/Point2D.h | 2 +- src/Math/Point3D.h | 2 +- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Color.h b/src/Color.h index 30b5af324..4245f4ece 100644 --- a/src/Color.h +++ b/src/Color.h @@ -359,7 +359,7 @@ template class Color4: public Math::Vector4 { */ /* Not marked as explicit, because conversion from Color3 to Color4 is fairly common, nearly always with A set to 1 */ - inline constexpr Color4(const Math::Vector<3, T>& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} + inline constexpr Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} inline T& r() { return Math::Vector4::x(); } /**< @brief R component */ inline constexpr T r() const { return Math::Vector4::x(); } /**< @overload */ diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index a882e68ab..896332e65 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -57,7 +57,7 @@ template class Point2D: public Vector3 { * @param xy Two-component vector * @param z Z component */ - inline constexpr Point2D(const Vector<2, T>& xy, T z = T(1)): Vector3(xy, z) {} + inline constexpr Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} /** * @brief Vector part of the point diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 19c89aa75..511946b9b 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -58,7 +58,7 @@ template class Point3D: public Vector4 { * @param xyz Three-component vector * @param w W component */ - inline constexpr Point3D(const Vector<3, T>& xyz, T w = T(1)): Vector4(xyz, w) {} + inline constexpr Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} /** * @brief Vector part of the point diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 79a3a9075..373801918 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -124,7 +124,7 @@ template class Vector3: public Vector<3, T> { * @param xy Two-component vector * @param z Z component */ - inline constexpr Vector3(const Vector<2, T>& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} + inline constexpr Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index e7b21e320..ef4eb762c 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -56,7 +56,7 @@ template class Vector4: public Vector<4, T> { * @param xyz Three-component vector * @param w W component */ - inline constexpr Vector4(const Vector<3, T>& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} + inline constexpr Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ From 1013d16b68867f8512d3d15855cf4a23391e3d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 22:02:15 +0200 Subject: [PATCH 110/256] More documentation updates for primitives. --- src/Primitives/Capsule.h | 4 ++-- src/Primitives/Cube.h | 2 +- src/Primitives/Cylinder.h | 4 ++-- src/Primitives/Icosphere.h | 4 ++-- src/Primitives/Plane.h | 2 +- src/Primitives/Square.h | 2 +- src/Primitives/UVSphere.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 243e426c9..b0b2b291f 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -26,8 +26,8 @@ namespace Magnum { namespace Primitives { /** @brief 3D capsule primitive -Cylinder along Y axis with hemispheres instead of caps. Indexed with normals -and optional 2D texture coordinates. +Cylinder along Y axis with hemispheres instead of caps. Indexed triangle mesh +with normals and optional 2D texture coordinates. */ class Capsule: public Trade::MeshData3D { friend class UVSphere; diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index 95f98c0f5..e3ed55951 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D cube primitive -Indexed with smooth normals. +Indexed triangle mesh with smooth normals. @todo Does anyone EVER want smooth normals on a cube?! */ class Cube: public Trade::MeshData3D { diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index f8c5a5a3b..c2dcf5877 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -28,8 +28,8 @@ namespace Magnum { namespace Primitives { /** @brief 3D cylinder primitive -Indexed with normals, optional 2D texture coordinates and optional capped -ends. +Indexed triangle mesh with normals, optional 2D texture coordinates and +optional capped ends. */ class Cylinder: public Capsule { public: diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 5bc2afacc..c01589d65 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -31,7 +31,7 @@ template class Icosphere; /** @brief 3D icosphere primitive with zero subdivisions -Indexed with normals. +Indexed triangle mesh with normals. @todo Use own computed (and more precise) icosahedron data, not these stolen from Blender. */ @@ -45,7 +45,7 @@ template<> class Icosphere<0>: public Trade::MeshData3D { @brief 3D icosphere primitive @tparam subdivisions Number of subdivisions -Indexed with normals. +Indexed triangle mesh with normals. */ #ifndef DOXYGEN_GENERATING_OUTPUT template class Icosphere: public Icosphere<0> { diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index e1d0045ce..1cdb6f104 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D plane primitive -2x2 plane, non-indexed with normals in positive Z direction. +2x2 plane as triangle strip, non-indexed with normals in positive Z direction. */ class Plane: public Trade::MeshData3D { public: diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index eff7f6595..d83520580 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 2D square primitive -2x2 square, non-indexed. +2x2 square as triangle strip, non-indexed. */ class Square: public Trade::MeshData2D { public: diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index 2e81ae6f4..d61c60a3c 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D UV sphere primitive -Indexed with normals and optional 2D texture coordinates. +Indexed triangle mesh with normals and optional 2D texture coordinates. */ class UVSphere: public Capsule { public: From b3517eda01a9c863b188301333a3549eda3d2cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 22:02:45 +0200 Subject: [PATCH 111/256] Doc: crosslinking MeshTools and relevant Mesh functions. --- src/IndexedMesh.h | 1 + src/Mesh.h | 1 + src/MeshTools/CompressIndices.h | 5 ++++- src/MeshTools/Interleave.h | 9 +++++++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index aba64e2d8..25f56e9b6 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -55,6 +55,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @brief Set index count * @return Pointer to self (for method chaining) * + * @see MeshTools::compressIndices() * @todo definalize after that? */ inline IndexedMesh* setIndexCount(GLsizei count) { diff --git a/src/Mesh.h b/src/Mesh.h index a9cf40985..284346110 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -365,6 +365,7 @@ class MAGNUM_EXPORT Mesh { * @return Pointer to self (for method chaining) * * This forces recalculation of attribute positions upon next drawing. + * @see MeshTools::interleave() */ inline Mesh* setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 709041000..1890d3af8 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -90,7 +90,10 @@ inline std::tuple compressIndices(const std::vector&), but this function writes the output to mesh's index buffer and updates index count and -type in the mesh accordingly. +type in the mesh accordingly, so you don't have to call Mesh::setIndexCount() +and Mesh::setIndexType() on your own. + +@see MeshTools::interleave() */ inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { return Implementation::CompressIndices{indices}(mesh, usage); diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 4f66df056..f345e0cb2 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -149,8 +149,11 @@ template inline typename std::enable_ifsetVertexCount(attribute.size()); @attention If there is more than one attribute array, the buffer must be set as interleaved (see Mesh::addBuffer()), otherwise this function does nothing. + +@see MeshTools::compressIndices() */ template inline void interleave(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { return Implementation::Interleave()(mesh, buffer, usage, attributes...); From 64e363f495eb1d27860ee5c483a8f55491269f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Sep 2012 00:42:41 +0200 Subject: [PATCH 112/256] Minor documentation fixes. --- src/AbstractShaderProgram.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index d2f23c358..56aff7675 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -396,23 +396,23 @@ class MAGNUM_EXPORT AbstractShaderProgram { glUniform1i(location, value); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLint>& value) { glUniform2iv(location, 1, value.data()); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLint>& value) { glUniform3iv(location, 1, value.data()); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLint>& value) { glUniform4iv(location, 1, value.data()); } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ @@ -421,7 +421,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ @@ -430,7 +430,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ @@ -439,7 +439,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLuint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ @@ -447,23 +447,23 @@ class MAGNUM_EXPORT AbstractShaderProgram { glUniform4uiv(location, 1, value.data()); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLfloat>& value) { glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 3, GLfloat>& value) { glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); } - /** @copydoc setUniform(GLint, GLint) */ + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 4, GLfloat>& value) { glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { @@ -471,7 +471,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { @@ -479,7 +479,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { @@ -487,7 +487,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { @@ -495,7 +495,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { @@ -503,7 +503,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { } /** - * @copydoc setUniform(GLint, GLint) + * @copydoc setUniform(GLint, GLfloat) * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { From 779808e2f7e0c34cbc0c9ecf41fce506fa9bddb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Sep 2012 00:42:58 +0200 Subject: [PATCH 113/256] Added setUniform() for doubles. I knew it did exist, but the manuals said otherwise. --- src/AbstractShaderProgram.h | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 56aff7675..c695f1d66 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -447,6 +447,44 @@ class MAGNUM_EXPORT AbstractShaderProgram { glUniform4uiv(location, 1, value.data()); } + #ifndef MAGNUM_TARGET_GLES + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, GLdouble value) { + glUniform1d(location, value); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLdouble>& value) { + glUniform2dv(location, 1, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLdouble>& value) { + glUniform3dv(location, 1, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLdouble>& value) { + glUniform4dv(location, 1, value.data()); + } + #endif + /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLfloat>& value) { glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); @@ -510,6 +548,89 @@ class MAGNUM_EXPORT AbstractShaderProgram { glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); } + #ifndef MAGNUM_TARGET_GLES + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLdouble>& value) { + glUniformMatrix2dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 3, GLdouble>& value) { + glUniformMatrix3dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 4, GLdouble>& value) { + glUniformMatrix4dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { + glUniformMatrix2x3dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { + glUniformMatrix3x2dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { + glUniformMatrix2x4dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { + glUniformMatrix4x2dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { + glUniformMatrix3x4dv(location, 1, GL_FALSE, value.data()); + } + + /** + * @copydoc setUniform(GLint, GLfloat) + * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl Only floats are available in OpenGL ES. + */ + inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { + glUniformMatrix4x3dv(location, 1, GL_FALSE, value.data()); + } + #endif + private: enum State { Initialized, From ce2ac51d08b6578a234463d295e2918ed4d46736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Sep 2012 00:55:41 +0200 Subject: [PATCH 114/256] Extension lists can be const as well. --- src/Context.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index f6bdfd1ad..2410bcfef 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -28,10 +28,10 @@ namespace Magnum { const std::vector& Extension::extensions(Version version) { #define _extension(prefix, vendor, extension) \ {Extensions::prefix::vendor::extension::Index, Extensions::prefix::vendor::extension::requiredVersion(), Extensions::prefix::vendor::extension::coreVersion(), Extensions::prefix::vendor::extension::string()} - static std::vector empty; - static std::vector extensions{ + static const std::vector empty; + static const std::vector extensions{ _extension(GL,EXT,texture_filter_anisotropic)}; - static std::vector extensions300{ + static const std::vector extensions300{ _extension(GL,APPLE,flush_buffer_range), _extension(GL,APPLE,vertex_array_object), _extension(GL,ARB,color_buffer_float), @@ -55,7 +55,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,NV,half_float), _extension(GL,NV,depth_buffer_float), _extension(GL,NV,conditional_render)}; - static std::vector extensions310{ + static const std::vector extensions310{ _extension(GL,ARB,texture_rectangle), _extension(GL,ARB,draw_instanced), _extension(GL,ARB,texture_buffer_object), @@ -63,7 +63,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,copy_buffer), _extension(GL,EXT,texture_snorm), _extension(GL,NV,primitive_restart)}; - static std::vector extensions320{ + static const std::vector extensions320{ _extension(GL,ARB,geometry_shader4), _extension(GL,ARB,depth_clamp), _extension(GL,ARB,draw_elements_base_vertex), @@ -73,7 +73,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,sync), _extension(GL,ARB,texture_multisample), _extension(GL,ARB,vertex_array_bgra)}; - static std::vector extensions330{ + static const std::vector extensions330{ _extension(GL,ARB,instanced_arrays), _extension(GL,ARB,blend_func_extended), _extension(GL,ARB,explicit_attrib_location), @@ -84,7 +84,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,texture_swizzle), _extension(GL,ARB,timer_query), _extension(GL,ARB,vertex_type_2_10_10_10_rev)}; - static std::vector extensions400{ + static const std::vector extensions400{ _extension(GL,ARB,draw_buffers_blend), _extension(GL,ARB,sample_shading), _extension(GL,ARB,texture_cube_map_array), @@ -98,14 +98,14 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,texture_buffer_object_rgb32), _extension(GL,ARB,transform_feedback2), _extension(GL,ARB,transform_feedback3)}; - static std::vector extensions410{ + static const std::vector extensions410{ _extension(GL,ARB,ES2_compatibility), _extension(GL,ARB,get_program_binary), _extension(GL,ARB,separate_shader_objects), _extension(GL,ARB,shader_precision), _extension(GL,ARB,vertex_attrib_64bit), _extension(GL,ARB,viewport_array)}; - static std::vector extensions420{ + static const std::vector extensions420{ _extension(GL,ARB,texture_compression_bptc), _extension(GL,ARB,base_instance), _extension(GL,ARB,shading_language_420pack), @@ -117,7 +117,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,shader_atomic_counters), _extension(GL,ARB,shader_image_load_store), _extension(GL,ARB,texture_storage)}; - static std::vector extensions430; + static const std::vector extensions430; #undef _extension switch(version) { From 5d9c4038f5644fd42712e7c4330c61ab77c8d53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Sep 2012 19:53:49 +0200 Subject: [PATCH 115/256] Doc++ --- src/Math/Matrix4.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 7bf1dc1b1..e539b5fc7 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -37,7 +37,7 @@ transformations. See also @ref matrix-vector for brief introduction. template class Matrix4: public Matrix<4, T> { public: /** - * @brief 3D translation matrix + * @brief 3D translation * @param vec Translation vector * * @see translation(), Matrix3::translation(const Vector2&), @@ -53,7 +53,7 @@ template class Matrix4: public Matrix<4, T> { } /** - * @brief 3D scaling matrix + * @brief 3D scaling * @param vec Scaling vector * * @see rotationScaling() const, Matrix3::scaling(const Vector2&), @@ -69,9 +69,9 @@ template class Matrix4: public Matrix<4, T> { } /** - * @brief 3D rotation matrix + * @brief 3D rotation around arbitrary axis * @param angle Rotation angle (counterclockwise, in radians) - * @param vec Normalized rotation vector + * @param vec Normalized rotation axis * * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() From ecad221a8b6ac5805069b922159b65f9838b40f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 29 Sep 2012 20:07:15 +0200 Subject: [PATCH 116/256] Faster alternatives for rotation around main axes. --- src/Math/Matrix4.h | 62 +++++++++++++++++++++++++++++++++++ src/Math/Test/Matrix4Test.cpp | 30 +++++++++++++++++ src/Math/Test/Matrix4Test.h | 3 ++ 3 files changed, 95 insertions(+) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index e539b5fc7..0ade48c5a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -73,6 +73,8 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * @param vec Normalized rotation axis * + * If possible, use faster alternatives like xRotation(), yRotation() + * or zRotation(). * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() * @attention Assertion fails on non-normalized rotation vector and @@ -110,6 +112,66 @@ template class Matrix4: public Matrix<4, T> { ); } + /** + * @brief 3D rotation around X axis + * @param angle Rotation angle (counterclockwise, in radians) + * + * Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`. + * @see rotation(T, const Vector3&), yRotation(), zRotation(), + * rotation() const, Matrix3::rotation(T), deg(), rad() + */ + static Matrix4 xRotation(T angle) { + T sine = std::sin(angle); + T cosine = std::cos(angle); + + return Matrix4( /* Column-major! */ + T(1), T(0), T(0), T(0), + T(0), cosine, sine, T(0), + T(0), -sine, cosine, T(0), + T(0), T(0), T(0), T(1) + ); + } + + /** + * @brief 3D rotation around Y axis + * @param angle Rotation angle (counterclockwise, in radians) + * + * Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`. + * @see rotation(T, const Vector3&), xRotation(), zRotation(), + * rotation() const, Matrix3::rotation(T), deg(), rad() + */ + static Matrix4 yRotation(T angle) { + T sine = std::sin(angle); + T cosine = std::cos(angle); + + return Matrix4( /* Column-major! */ + cosine, T(0), -sine, T(0), + T(0), T(1), T(0), T(0), + sine, T(0), cosine, T(0), + T(0), T(0), T(0), T(1) + ); + } + + /** + * @brief 3D rotation matrix around Z axis + * @param angle Rotation angle (counterclockwise, in radians) + * + * Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`. + * @see rotation(T, const Vector3&), xRotation(), yRotation(), + * rotation() const, Matrix3::rotation(T), deg(), rad() + */ + static Matrix4 zRotation(T angle) { + T sine = std::sin(angle); + T cosine = std::cos(angle); + + return Matrix4( /* Column-major! */ + cosine, sine, T(0), T(0), + -sine, cosine, T(0), T(0), + T(0), T(0), T(1), T(0), + T(0), T(0), T(0), T(1) + ); + } + /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 496cb5627..fbcc08e4d 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -36,6 +36,9 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::translation, &Matrix4Test::scaling, &Matrix4Test::rotation, + &Matrix4Test::xRotation, + &Matrix4Test::yRotation, + &Matrix4Test::zRotation, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, &Matrix4Test::translationPart, @@ -105,6 +108,33 @@ void Matrix4Test::rotation() { CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); } +void Matrix4Test::xRotation() { + Matrix4 matrix(1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.90096887f, 0.43388374f, 0.0f, + 0.0f, -0.43388374f, 0.90096887f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); + CORRADE_COMPARE(Matrix4::xRotation(rad(Math::Constants::pi()/7)), matrix); +} + +void Matrix4Test::yRotation() { + Matrix4 matrix(0.90096887f, 0.0f, -0.43388374f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.43388374f, 0.0f, 0.90096887f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); + CORRADE_COMPARE(Matrix4::yRotation(rad(Math::Constants::pi()/7)), matrix); +} + +void Matrix4Test::zRotation() { + Matrix4 matrix( 0.90096887f, 0.43388374f, 0.0f, 0.0f, + -0.43388374f, 0.90096887f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); + CORRADE_COMPARE(Matrix4::zRotation(rad(Math::Constants::pi()/7)), matrix); +} + void Matrix4Test::rotationScalingPart() { Matrix4 m( 3.0f, 5.0f, 8.0f, 4.0f, diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 9bc8dbe2b..7e22e979a 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -28,6 +28,9 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void translation(); void scaling(); void rotation(); + void xRotation(); + void yRotation(); + void zRotation(); void rotationScalingPart(); void rotationPart(); void translationPart(); From a22263c60b336a3c5028cb1be27ccea7fb6491c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:01:53 +0200 Subject: [PATCH 117/256] Added missing includes to Image classes. --- src/BufferedImage.h | 1 + src/Image.h | 1 + src/ImageWrapper.h | 1 + 3 files changed, 3 insertions(+) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 8b04bd615..76a244008 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -19,6 +19,7 @@ * @brief Class Magnum::BufferedImage, typedef Magnum::BufferedImage1D, Magnum::BufferedImage2D, Magnum::BufferedImage3D */ +#include "Math/Vector.h" #include "AbstractImage.h" #include "Buffer.h" #include "TypeTraits.h" diff --git a/src/Image.h b/src/Image.h index 472af324a..467bd24a8 100644 --- a/src/Image.h +++ b/src/Image.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Image, typedef Magnum::Image1D, Magnum::Image2D, Magnum::Image3D */ +#include "Math/Vector.h" #include "AbstractImage.h" #include "TypeTraits.h" diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 3a4ca8ce3..d625f7a6f 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -19,6 +19,7 @@ * @brief Class Magnum::ImageWrapper */ +#include "Math/Vector.h" #include "AbstractImage.h" #include "TypeTraits.h" From 624f4f85311f37e6c67b40de5e5e14acee063f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:03:36 +0200 Subject: [PATCH 118/256] Inlined inline functions. --- src/BufferedImage.h | 4 ++-- src/Color.h | 4 ++-- src/ImageWrapper.h | 2 +- src/Math/Matrix.h | 2 +- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- src/Math/Point2D.h | 2 +- src/Math/Point3D.h | 2 +- src/Math/Vector.h | 4 ++-- src/Math/Vector2.h | 2 +- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 76a244008..0de313b24 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -47,7 +47,7 @@ template class BufferedImage: public AbstractImage { * Dimensions and buffer are empty, call setData() to fill the image * with data. */ - BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} + inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} /** @brief %Image dimensions */ inline constexpr Math::Vector dimensions() const { return _dimensions; } @@ -61,7 +61,7 @@ template class BufferedImage: public AbstractImage { * * @see Buffer::bind(Target) */ - void* data() { + inline void* data() { _buffer.bind(Buffer::Target::PixelUnpack); return nullptr; } diff --git a/src/Color.h b/src/Color.h index 4245f4ece..bafd9c58f 100644 --- a/src/Color.h +++ b/src/Color.h @@ -406,12 +406,12 @@ template class Color4: public Math::Vector4 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) /** @debugoperator{Magnum::Color3} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color3& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color3& value) { return debug << static_cast&>(value); } /** @debugoperator{Magnum::Color4} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color4& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color4& value) { return debug << static_cast&>(value); } diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index d625f7a6f..d8c0370a7 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -93,7 +93,7 @@ template class ImageWrapper: public AbstractImage { * passed in constructor. The data are not copied nor deleted on * destruction. */ - void setData(GLvoid* data) { + inline void setData(GLvoid* data) { _data = reinterpret_cast(data); } diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 4f9d71907..e812971d7 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -168,7 +168,7 @@ template inline typename std::enable_if Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 8078198bc..4c7e4fd05 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -149,7 +149,7 @@ template class Matrix3: public Matrix<3, T> { }; /** @debugoperator{Magnum::Math::Matrix3} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix3& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix3& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 0ade48c5a..f067d6a59 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -249,7 +249,7 @@ template class Matrix4: public Matrix<4, T> { }; /** @debugoperator{Magnum::Math::Matrix4} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix4& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix4& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 896332e65..afd05e2d8 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -75,7 +75,7 @@ template class Point2D: public Vector3 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) /** @debugoperator{Magnum::Math::Point2D} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 511946b9b..68f2ef7b7 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -76,7 +76,7 @@ template class Point3D: public Vector4 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) /** @debugoperator{Magnum::Math::Point3D} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index e427c6098..42f19ad0b 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -106,7 +106,7 @@ template class Vector: public RectangularMatrix<1, s, T> { * * @see operator*=(const Vector&) */ - Vector operator*(const Vector& other) const { + inline Vector operator*(const Vector& other) const { return Vector(*this)*=other; } @@ -128,7 +128,7 @@ template class Vector: public RectangularMatrix<1, s, T> { * * @see operator/=(const Vector&) */ - Vector operator/(const Vector& other) const { + inline Vector operator/(const Vector& other) const { return Vector(*this)/=other; } diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 2b477a1f6..89279c042 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -95,7 +95,7 @@ template class Vector2: public Vector<2, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector2, 2) /** @debugoperator{Magnum::Math::Vector2} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 373801918..b289d7453 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -149,7 +149,7 @@ template class Vector3: public Vector<3, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector3, 3) /** @debugoperator{Magnum::Math::Vector3} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector3& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector3& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index ef4eb762c..4ef0e3267 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -92,7 +92,7 @@ template class Vector4: public Vector<4, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector4, 4) /** @debugoperator{Magnum::Math::Vector4} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector4& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector4& value) { return debug << static_cast&>(value); } From 6cb257670ac4d9ef373b417ce38af06454428cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:04:12 +0200 Subject: [PATCH 119/256] Fixed compilation for Color4::rgb(). --- src/Color.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Color.h b/src/Color.h index bafd9c58f..69ad21b6c 100644 --- a/src/Color.h +++ b/src/Color.h @@ -376,8 +376,8 @@ template class Color4: public Math::Vector4 { * * @see swizzle() */ - inline Color3& rgb() { return Math::Vector4::xyz(); } - inline constexpr Color3 rgb() const { return Math::Vector4::xyz(); } /**< @overload */ + inline Color3& rgb() { return Color3::from(Math::Vector4::data()); } + inline constexpr Color3 rgb() const { return Color3::from(Math::Vector4::data()); } /**< @overload */ /** @copydoc Color3::toHSV() */ inline constexpr HSV toHSV() const { From 14f53bf6a357322a6d49cdfde95d2866ff82f56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:05:19 +0200 Subject: [PATCH 120/256] Doc++ --- src/Math/Matrix3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 4c7e4fd05..284425446 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -65,7 +65,7 @@ template class Matrix3: public Matrix<3, T> { } /** - * @brief 3D rotation matrix + * @brief 2D rotation matrix * @param angle Rotation angle (counterclockwise, in radians) * * @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), From ca2993cadcd864aa4949cfb445b1f38954a861e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:05:40 +0200 Subject: [PATCH 121/256] Don't compute sine and cosine more times than necessary. --- src/Math/Matrix3.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 284425446..7be868204 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -72,9 +72,12 @@ template class Matrix3: public Matrix<3, T> { * rad() */ static Matrix3 rotation(T angle) { + T sine = std::sin(angle); + T cosine = std::cos(angle); + return Matrix3( /* Column-major! */ - T(cos(angle)), T(sin(angle)), T(0), - -T(sin(angle)), T(cos(angle)), T(0), + cosine, sine, T(0), + -sine, cosine, T(0), T(0), T(0), T(1) ); } From 5f822d0c9bdc3e9f6fce8bfa7bbf4206f1ebfc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:06:06 +0200 Subject: [PATCH 122/256] Fixed copypaste error in Matrix3::translation(). --- src/Math/Matrix3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 7be868204..a6a0b913f 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -137,7 +137,7 @@ template class Matrix3: public Matrix<3, T> { } /** @overload */ - inline constexpr Vector3 translation() const { + inline constexpr Vector2 translation() const { return (*this)[2].xy(); } From 16382c9ba92c9518c3a1ebc5a960fd668e6cb0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:06:51 +0200 Subject: [PATCH 123/256] No need to have separate ConfigurationValue implementation for Vector. --- src/Math/Vector.h | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 42f19ad0b..85cab8a2f 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -303,33 +303,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::Vector} */ -template struct ConfigurationValue> { - /** @brief Writes elements separated with spaces */ - static std::string toString(const Magnum::Math::Vector& value, int flags = 0) { - std::string output; - - for(size_t pos = 0; pos != size; ++pos) { - if(!output.empty()) output += ' '; - output += ConfigurationValue::toString(value[pos], flags); - } - - return output; - } - - /** @brief Reads elements separated with whitespace */ - static Magnum::Math::Vector fromString(const std::string& stringValue, int flags = 0) { - Magnum::Math::Vector result; - std::istringstream in(stringValue); - - std::string num; - for(size_t pos = 0; pos != size; ++pos) { - in >> num; - result[pos] = ConfigurationValue::fromString(num, flags); - } - - return result; - } -}; +template struct ConfigurationValue>: public ConfigurationValue> {}; }} From d65b2386b25a64cd147be2a67487c0b1b63fdf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:13:39 +0200 Subject: [PATCH 124/256] Code cleanup. --- src/Color.h | 8 ++++---- src/Math/Matrix.h | 4 ++-- src/Math/Matrix3.h | 4 ++-- src/Math/Matrix4.h | 4 ++-- src/Math/Point2D.h | 4 ++-- src/Math/Point3D.h | 4 ++-- src/Math/Vector.h | 2 +- src/Math/Vector2.h | 4 ++-- src/Math/Vector3.h | 4 ++-- src/Math/Vector4.h | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Color.h b/src/Color.h index 69ad21b6c..0dcecdb09 100644 --- a/src/Color.h +++ b/src/Color.h @@ -406,13 +406,13 @@ template class Color4: public Math::Vector4 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) /** @debugoperator{Magnum::Color3} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color3& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Color3& value) { + return debug << static_cast&>(value); } /** @debugoperator{Magnum::Color4} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color4& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Color4& value) { + return debug << static_cast&>(value); } } diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index e812971d7..065617261 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -168,8 +168,8 @@ template inline typename std::enable_if inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix& value) { + return debug << static_cast&>(value); } #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index a6a0b913f..5d80e6b6f 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -152,8 +152,8 @@ template class Matrix3: public Matrix<3, T> { }; /** @debugoperator{Magnum::Math::Matrix3} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix3& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix3& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index f067d6a59..b741eb27a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -249,8 +249,8 @@ template class Matrix4: public Matrix<4, T> { }; /** @debugoperator{Magnum::Math::Matrix4} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix4& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix4& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index afd05e2d8..76a775b89 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -75,8 +75,8 @@ template class Point2D: public Vector3 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) /** @debugoperator{Magnum::Math::Point2D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point2D& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point2D& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 68f2ef7b7..432ea5c0d 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -76,8 +76,8 @@ template class Point3D: public Vector4 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) /** @debugoperator{Magnum::Math::Point3D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Point3D& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point3D& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 85cab8a2f..621b1f778 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -240,7 +240,7 @@ template inline typename std::enable_if Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector& value) { +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector& value) { debug << "Vector("; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); for(size_t i = 0; i != size; ++i) { diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 89279c042..72c98d3b6 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -95,8 +95,8 @@ template class Vector2: public Vector<2, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector2, 2) /** @debugoperator{Magnum::Math::Vector2} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector2& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index b289d7453..51ce88517 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -149,8 +149,8 @@ template class Vector3: public Vector<3, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector3, 3) /** @debugoperator{Magnum::Math::Vector3} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector3& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector3& value) { + return debug << static_cast&>(value); } }} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 4ef0e3267..be28aa83f 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -92,8 +92,8 @@ template class Vector4: public Vector<4, T> { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector4, 4) /** @debugoperator{Magnum::Math::Vector4} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector4& value) { - return debug << static_cast&>(value); +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector4& value) { + return debug << static_cast&>(value); } }} From 871c2a4f901925f767bf8da29cd05a5af5c29de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 12:47:25 +0200 Subject: [PATCH 125/256] Forgot to initialize some variables in private Resource constructor. Thankfully catched in tests using gcc 4.6 (passed with 4.7). --- src/ResourceManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index f58b59280..2ff23433e 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -324,7 +324,7 @@ template class Resource { } private: - inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), key(key), lastCheck(0) { + inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { manager->incrementReferenceCount(key); } From 0f0b7a8d17e9b7df589e7dfc278ee46978d188f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 12:48:55 +0200 Subject: [PATCH 126/256] Move constructor and move assignment for Resource. Saves unnecessary manager access. --- src/ResourceManager.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 2ff23433e..c355aeb86 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -270,6 +270,11 @@ template class Resource { if(manager) manager->incrementReferenceCount(key); } + /** @brief Move constructor */ + inline Resource(Resource&& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + other.manager = nullptr; + } + /** @brief Destructor */ inline ~Resource() { if(manager) manager->decrementReferenceCount(key); @@ -289,6 +294,20 @@ template class Resource { return *this; } + /** @brief Assignment move operator */ + Resource& operator=(Resource&& other) { + if(manager) manager->decrementReferenceCount(key); + + manager = other.manager; + key = other.key; + lastCheck = other.lastCheck; + _state = other._state; + data = other.data; + + other.manager = nullptr; + return *this; + } + /** * @brief %Resource state * From caadb242b32b44b13702e0dfd317b8c06a825803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 30 Sep 2012 02:19:26 +0200 Subject: [PATCH 127/256] Explicit instantiation of Image types. De-inlined setData() functions, as they were too heavy for inlining. --- src/BufferedImage.cpp | 31 +++++++++++++++++++++++++++++++ src/BufferedImage.h | 13 +++++++------ src/CMakeLists.txt | 2 ++ src/Image.cpp | 32 ++++++++++++++++++++++++++++++++ src/Image.h | 14 +++++++------- 5 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 src/BufferedImage.cpp create mode 100644 src/Image.cpp diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp new file mode 100644 index 000000000..94907a60c --- /dev/null +++ b/src/BufferedImage.cpp @@ -0,0 +1,31 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "BufferedImage.h" + +namespace Magnum { + +template void BufferedImage::setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { + _components = components; + _type = type; + _dimensions = dimensions; + _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*dimensions.product(), data, usage); +} + +template class BufferedImage<1>; +template class BufferedImage<2>; +template class BufferedImage<3>; + +} diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 0de313b24..528284f8b 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -99,18 +99,19 @@ template class BufferedImage: public AbstractImage { * * @see Buffer::setData() */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { - _components = components; - _type = type; - _dimensions = dimensions; - _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*dimensions.product(), data, usage); - } + void setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); protected: Math::Vector _dimensions; /**< @brief %Image dimensions */ Buffer _buffer; /**< @brief %Image buffer */ }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class BufferedImage<1>; +extern template class BufferedImage<2>; +extern template class BufferedImage<3>; +#endif + /** @brief One-dimensional buffered image */ typedef BufferedImage<1> BufferedImage1D; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index debd4c69e..061399b1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,9 +21,11 @@ set(Magnum_SRCS AbstractImage.cpp AbstractTexture.cpp AbstractShaderProgram.cpp + BufferedImage.cpp BufferedTexture.cpp Context.cpp Framebuffer.cpp + Image.cpp IndexedMesh.cpp Mesh.cpp Profiler.cpp diff --git a/src/Image.cpp b/src/Image.cpp new file mode 100644 index 000000000..2172837cd --- /dev/null +++ b/src/Image.cpp @@ -0,0 +1,32 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Image.h" + +namespace Magnum { + +template void Image::setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data) { + delete[] _data; + _components = components; + _type = type; + _dimensions = dimensions; + _data = reinterpret_cast(data); +} + +template class Image<1>; +template class Image<2>; +template class Image<3>; + +} diff --git a/src/Image.h b/src/Image.h index 467bd24a8..a9268db34 100644 --- a/src/Image.h +++ b/src/Image.h @@ -105,19 +105,19 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data) { - delete[] _data; - _components = components; - _type = type; - _dimensions = dimensions; - _data = reinterpret_cast(data); - } + void setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data); protected: Math::Vector _dimensions; /**< @brief %Image dimensions */ char* _data; /**< @brief %Image data */ }; +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class Image<1>; +extern template class Image<2>; +extern template class Image<3>; +#endif + /** @brief One-dimensional image */ typedef Image<1> Image1D; From b5edb73f380461f921f07a318b2bbce0a13aa803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 15:38:26 +0200 Subject: [PATCH 128/256] GlutWindowContext: don't save unused argc and argv variables. --- src/Contexts/GlutWindowContext.cpp | 2 +- src/Contexts/GlutWindowContext.h | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Contexts/GlutWindowContext.cpp b/src/Contexts/GlutWindowContext.cpp index c94db351e..f06f4b38f 100644 --- a/src/Contexts/GlutWindowContext.cpp +++ b/src/Contexts/GlutWindowContext.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Contexts { GlutWindowContext* GlutWindowContext::instance = nullptr; -GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string& title, const Math::Vector2& size): argc(argc), argv(argv) { +GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string& title, const Math::Vector2& size) { /* Save global instance */ instance = this; diff --git a/src/Contexts/GlutWindowContext.h b/src/Contexts/GlutWindowContext.h index f4dff7120..0f33c71fd 100644 --- a/src/Contexts/GlutWindowContext.h +++ b/src/Contexts/GlutWindowContext.h @@ -250,9 +250,6 @@ class GlutWindowContext: public AbstractWindowContext { static GlutWindowContext* instance; - int& argc; - char** argv; - Context* c; }; From 2c52f7b85a90171fe7f1e8e62ce508d5939de32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 17:49:42 +0200 Subject: [PATCH 129/256] Non-explicit default constructor for Vector2 and Matrix*. So you can now write mat = {}; vec = {}; instead of mat = Matrix3(); vec = Vector2(); --- src/Math/Matrix.h | 2 +- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- src/Math/Vector2.h | 5 ++++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 065617261..58ac344ae 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -62,7 +62,7 @@ template class Matrix: public RectangularMatrix { * `Matrix m(Matrix::Identity);`. Optional parameter @p value allows * you to specify value on diagonal. */ - inline explicit Matrix(IdentityType = Identity, T value = T(1)) { + inline Matrix(IdentityType = Identity, T value = T(1)) { for(size_t i = 0; i != size; ++i) (*this)(i, i) = value; } diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 5d80e6b6f..e904975e0 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -86,7 +86,7 @@ template class Matrix3: public Matrix<3, T> { inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ - inline constexpr explicit Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( + inline constexpr Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( value, T(0), T(0), T(0), value, T(0), T(0), T(0), value diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index b741eb27a..e9a6a4231 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -176,7 +176,7 @@ template class Matrix4: public Matrix<4, T> { inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ - inline constexpr explicit Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( + inline constexpr Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( value, T(0), T(0), T(0), T(0), value, T(0), T(0), T(0), T(0), value, T(0), diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 72c98d3b6..c4d26eb11 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -70,8 +70,11 @@ template class Vector2: public Vector<2, T> { */ inline constexpr static Vector2 yScale(T scale) { return Vector2(T(1), scale); } + /** @copydoc Vector::Vector() */ + inline constexpr Vector2() {} + /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {} + inline constexpr explicit Vector2(T value): Vector<2, T>(value, value) {} /** @brief Copy constructor */ inline constexpr Vector2(const RectangularMatrix<1, 2, T>& other): Vector<2, T>(other) {} From 30a584741e22ccb9536499ccad711d4096e59542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 18:35:22 +0200 Subject: [PATCH 130/256] Fixed compilation with Clang. --- src/ResourceManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index c355aeb86..27898efe0 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -55,14 +55,14 @@ enum class ResourceDataState { * the data are accessed, but allows changing the data for e.g. debugging * purposes. */ - Mutable = ResourceState::Mutable, + Mutable = int(ResourceState::Mutable), /** * The resource cannot be changed by the manager in the future. This is * faster, as Resource instances will ask for the data only one time, thus * suitable for production code. */ - Final = ResourceState::Final + Final = int(ResourceState::Final) }; /** From c9d375f7a332232b3205b642c6351cf1bc74dbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 19:20:14 +0200 Subject: [PATCH 131/256] Making _data member of RectangularMatrix protected. Better than friending subclasses. --- src/Math/RectangularMatrix.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 044574fa5..329cccabd 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -63,8 +63,6 @@ Vector. template class RectangularMatrix { static_assert(c != 0 && r != 0, "Matrix cannot have zero elements"); - friend class Vector; - public: typedef T Type; /**< @brief Data type */ const static size_t cols = c; /**< @brief %Matrix column count */ @@ -332,6 +330,11 @@ template class RectangularMatrix { return out; } + #ifndef DOXYGEN_GENERATING_OUTPUT + protected: + T _data[rows*cols]; + #endif + private: template inline constexpr static RectangularMatrix from(Implementation::Sequence s, const Vector& first, U... next) { return from(s, next..., first[sequence]...); @@ -339,8 +342,6 @@ template class RectangularMatrix { template inline constexpr static RectangularMatrix from(Implementation::Sequence, T first, U... next) { return RectangularMatrix(first, next...); } - - T _data[rows*cols]; }; /** @relates RectangularMatrix From 4aec678539750d18fa63f402e900ec9c452e318f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 19:21:36 +0200 Subject: [PATCH 132/256] Have first letter of static constants uppercase, like previously. Lowecase didn't prove to be better, because Doxygen cannot implicitly link to it and it collides with non-type template parameters and private variables. --- src/Math/Matrix.h | 8 ++++---- src/Math/RectangularMatrix.h | 20 ++++++++++---------- src/Math/Vector.h | 12 ++++++------ src/MeshTools/Clean.h | 8 ++++---- src/MeshTools/Test/CleanTest.h | 2 +- src/MeshTools/Test/SubdivideTest.h | 2 +- src/SceneGraph/Camera.cpp | 2 +- src/Swizzle.h | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 58ac344ae..07d21527b 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -31,16 +31,16 @@ namespace Implementation { /** @brief Square matrix -@tparam s %Matrix size -@tparam T Data type +@tparam size %Matrix size +@tparam T Data type See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} */ -template class Matrix: public RectangularMatrix { +template class Matrix: public RectangularMatrix { public: - const static size_t size = s; /**< @brief %Matrix size */ + const static size_t Size = size; /**< @brief %Matrix size */ /** @brief Pass to constructor to create zero-filled matrix */ enum ZeroType { Zero }; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 329cccabd..7c023931f 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -53,20 +53,20 @@ template class Vector; /** @brief Rectangular matrix -@tparam c Column count -@tparam r Row count -@tparam T Data type +@tparam cols Column count +@tparam rows Row count +@tparam T Data type See @ref matrix-vector for brief introduction. See also Matrix (square) and Vector. */ -template class RectangularMatrix { - static_assert(c != 0 && r != 0, "Matrix cannot have zero elements"); +template class RectangularMatrix { + static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements"); public: - typedef T Type; /**< @brief Data type */ - const static size_t cols = c; /**< @brief %Matrix column count */ - const static size_t rows = r; /**< @brief %Matrix row count */ + typedef T Type; /**< @brief Data type */ + const static size_t Cols = cols; /**< @brief %Matrix column count */ + const static size_t Rows = rows; /**< @brief %Matrix row count */ /** * @brief %Matrix from array @@ -129,10 +129,10 @@ template class RectangularMatrix { #endif /** @brief Copy constructor */ - inline constexpr RectangularMatrix(const RectangularMatrix&) = default; + inline constexpr RectangularMatrix(const RectangularMatrix&) = default; /** @brief Assignment operator */ - inline RectangularMatrix& operator=(const RectangularMatrix&) = default; + inline RectangularMatrix& operator=(const RectangularMatrix&) = default; /** * @brief Raw data diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 621b1f778..e0d5ab5e0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -25,15 +25,15 @@ namespace Magnum { namespace Math { /** @brief %Vector -@tparam s %Vector size -@tparam T Data type +@tparam size %Vector size +@tparam T Data type See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} */ -template class Vector: public RectangularMatrix<1, s, T> { +template class Vector: public RectangularMatrix<1, size, T> { public: - const static size_t size = s; /**< @brief %Vector size */ + const static size_t Size = size; /**< @brief %Vector size */ /** * @brief Dot product @@ -224,8 +224,8 @@ template class Vector: public RectangularMatrix<1, s, T> { private: /* Hiding unused things from RectangularMatrix */ - using RectangularMatrix<1, size, T>::cols; - using RectangularMatrix<1, size, T>::rows; + using RectangularMatrix<1, size, T>::Cols; + using RectangularMatrix<1, size, T>::Rows; using RectangularMatrix<1, size, T>::operator[]; using RectangularMatrix<1, size, T>::operator(); }; diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 9a4a0d6b8..8c4389062 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -40,7 +40,7 @@ template class Clean { /* Get mesh bounds */ Vertex min, max; - for(size_t i = 0; i != Vertex::size; ++i) { + for(size_t i = 0; i != Vertex::Size; ++i) { min[i] = std::numeric_limits::max(); max[i] = std::numeric_limits::min(); } @@ -54,7 +54,7 @@ template class Clean { /* Make epsilon so large that size_t can index all vertices inside mesh bounds. */ Vertex size = max-min; - for(size_t i = 0; i != Vertex::size; ++i) + for(size_t i = 0; i != Vertex::Size; ++i) if(static_cast(size[i]/std::numeric_limits::max()) > epsilon) epsilon = static_cast(size[i]/std::numeric_limits::max()); @@ -92,7 +92,7 @@ template class Clean { std::swap(newVertices, vertices); /* Move vertex coordinates by epsilon/2 in next direction */ - if(moving != Vertex::size) { + if(moving != Vertex::Size) { moved = Vertex(); moved[moving] = epsilon/2; } @@ -137,7 +137,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h index 5663733d6..f24e4730e 100644 --- a/src/MeshTools/Test/CleanTest.h +++ b/src/MeshTools/Test/CleanTest.h @@ -28,7 +28,7 @@ class CleanTest: public Corrade::TestSuite::Tester { private: class Vector1 { public: - static const size_t size = 1; + static const size_t Size = 1; typedef int Type; Vector1(): data(0) {} diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h index af7c43484..bc7569cb5 100644 --- a/src/MeshTools/Test/SubdivideTest.h +++ b/src/MeshTools/Test/SubdivideTest.h @@ -29,7 +29,7 @@ class SubdivideTest: public Corrade::TestSuite::Tester { private: class Vector1 { public: - static const size_t size = 1; + static const size_t Size = 1; typedef int Type; Vector1(): data(0) {} diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 4b9cba14b..892a0a419 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -32,7 +32,7 @@ template MatrixType aspectRatioFix(AspectRatioPolicy aspectRat /* Extend on larger side = scale larger side down Clip on smaller side = scale smaller side up */ - return Camera::aspectRatioScale( + return Camera::aspectRatioScale( (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ? Vector2(relativeAspectRatio.y()/relativeAspectRatio.x(), 1.0f) : Vector2(1.0f, relativeAspectRatio.x()/relativeAspectRatio.y())); diff --git a/src/Swizzle.h b/src/Swizzle.h index cc57ca072..308eee93a 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -110,7 +110,7 @@ instead of at runtime. Vector4::xy(), Vector3::xy() */ template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector) { - return {Implementation::Component::value(vector)...}; + return {Implementation::Component::value(vector)...}; } /** From aceb93c313ce0abb7351fb4d20e1e5c920fb400b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Oct 2012 22:33:48 +0200 Subject: [PATCH 133/256] Distinguish dimensions (1D, 2D, 3D) from image size. --- src/BufferedImage.cpp | 6 +++--- src/BufferedImage.h | 22 +++++++++++----------- src/Framebuffer.cpp | 16 ++++++++-------- src/Framebuffer.h | 8 ++++---- src/Image.cpp | 4 ++-- src/Image.h | 30 +++++++++++++++--------------- src/ImageWrapper.h | 24 ++++++++++++------------ src/Texture.h | 4 ++-- src/Trade/ImageData.h | 18 +++++++++--------- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index 94907a60c..e40a9ab3f 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -17,11 +17,11 @@ namespace Magnum { -template void BufferedImage::setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { +template void BufferedImage::setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; _type = type; - _dimensions = dimensions; - _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*dimensions.product(), data, usage); + _size = size; + _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*size.product(), data, usage); } template class BufferedImage<1>; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 528284f8b..38f4ece69 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -35,9 +35,9 @@ Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ -template class BufferedImage: public AbstractImage { +template class BufferedImage: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor @@ -49,8 +49,8 @@ template class BufferedImage: public AbstractImage { */ inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} - /** @brief %Image dimensions */ - inline constexpr Math::Vector dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr Math::Vector size() const { return _size; } /** * @brief Data @@ -71,7 +71,7 @@ template class BufferedImage: public AbstractImage { /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -82,13 +82,13 @@ template class BufferedImage: public AbstractImage { * * @see setData(const Math::Vector&, Components, ComponentType, const GLvoid*, Buffer::Usage) */ - template inline void setData(const Math::Vector& dimensions, Components components, const T* data, Buffer::Usage usage) { - setData(dimensions, components, TypeTraits::imageType(), data, usage); + template inline void setData(const Math::Vector& size, Components components, const T* data, Buffer::Usage usage) { + setData(size, components, TypeTraits::imageType(), data, usage); } /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -99,11 +99,11 @@ template class BufferedImage: public AbstractImage { * * @see Buffer::setData() */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); + void setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - Buffer _buffer; /**< @brief %Image buffer */ + Math::Vector _size; /**< @brief %Image size */ + Buffer _buffer; /**< @brief %Image buffer */ }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index d0e158e08..e0cfa6303 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -42,21 +42,21 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { } #endif -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { - char* data = new char[AbstractImage::pixelSize(components, type)*dimensions.product()]; - glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast(components), static_cast(type), data); - image->setData(dimensions, components, type, data); +void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { + char* data = new char[AbstractImage::pixelSize(components, type)*size.product()]; + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); + image->setData(size, components, type, data); } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { +void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ - if(image->dimensions() != dimensions || image->components() != components || image->type() != type) - image->setData(dimensions, components, type, nullptr, usage); + if(image->size() != size || image->components() != components || image->type() != type) + image->setData(size, components, type, nullptr, usage); image->buffer()->bind(Buffer::Target::PixelPack); - glReadPixels(offset.x(), offset.y(), dimensions.x(), dimensions.y(), static_cast(components), static_cast(type), nullptr); + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), nullptr); } #endif diff --git a/src/Framebuffer.h b/src/Framebuffer.h index d1278ff86..1c69674d9 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -1134,7 +1134,7 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Read block of pixels from framebuffer to image * @param offset Offset in the framebuffer - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param image %Image where to put the data @@ -1142,13 +1142,13 @@ class MAGNUM_EXPORT Framebuffer { * @see @fn_gl{ReadPixels} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); + static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); #ifndef MAGNUM_TARGET_GLES /** * @brief Read block of pixels from framebuffer to buffered image * @param offset Offset in the framebuffer - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param image Buffered image where to put the data @@ -1158,7 +1158,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Math::Vector2& offset, const Math::Vector2& dimensions, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); + static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); #endif /*@}*/ diff --git a/src/Image.cpp b/src/Image.cpp index 2172837cd..f12b2caa7 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,11 +17,11 @@ namespace Magnum { -template void Image::setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data) { delete[] _data; _components = components; _type = type; - _dimensions = dimensions; + _size = size; _data = reinterpret_cast(data); } diff --git a/src/Image.h b/src/Image.h index a9268db34..37d4c820d 100644 --- a/src/Image.h +++ b/src/Image.h @@ -33,13 +33,13 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for example with Trade::ImageData. @see Image1D, Image2D, Image3D */ -template class Image: public AbstractImage { +template class Image: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data with proper size @@ -47,11 +47,11 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline Image(const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _dimensions(dimensions), _data(data) {} + template inline Image(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -59,7 +59,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline Image(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline Image(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -74,8 +74,8 @@ template class Image: public AbstractImage { /** @brief Destructor */ inline ~Image() { delete[] _data; } - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -83,7 +83,7 @@ template class Image: public AbstractImage { /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -91,13 +91,13 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - template inline void setData(const Math::Vector& dimensions, Components components, T* data) { - setData(dimensions, components, TypeTraits::imageType(), data); + template inline void setData(const Math::Vector& size, Components components, T* data) { + setData(size, components, TypeTraits::imageType(), data); } /** * @brief Set image data - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -105,11 +105,11 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data); + void setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data); protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - char* _data; /**< @brief %Image data */ + Math::Vector _size; /**< @brief %Image size */ + char* _data; /**< @brief %Image data */ }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index d8c0370a7..e1237e329 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -39,13 +39,13 @@ to change image properties, only data pointer. See also Image, BufferedImage and Trade::ImageData. */ -template class ImageWrapper: public AbstractImage { +template class ImageWrapper: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data with proper size @@ -53,11 +53,11 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageWrapper(const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _dimensions(dimensions), _data(data) {} + template inline ImageWrapper(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -65,21 +65,21 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageWrapper(const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline ImageWrapper(const Math::Vector& dimensions, Components components, ComponentType type): AbstractImage(components, type), _dimensions(dimensions), _data(nullptr) {} + inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -98,8 +98,8 @@ template class ImageWrapper: public AbstractImage { } protected: - Math::Vector _dimensions; /**< @brief %Image dimensions */ - char* _data; /**< @brief %Image data */ + Math::Vector _size; /**< @brief %Image size */ + char* _data; /**< @brief %Image data */ }; /** @brief One-dimensional image wrapper */ diff --git a/src/Texture.h b/src/Texture.h index ca8d54a4b..015f18cdb 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -48,9 +48,9 @@ for more information. @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray */ -template class Texture: public AbstractTexture { +template class Texture: public AbstractTexture { public: - static const size_t Dimensions = textureDimensions; /**< @brief %Texture dimension count */ + static const size_t Dimensions = dimensions; /**< @brief %Texture dimension count */ #ifdef DOXYGEN_GENERATING_OUTPUT /** diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 98a4345a4..260fa8d8a 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -31,14 +31,14 @@ namespace Magnum { namespace Trade { Provides access to image data and additional information about data type and dimensions. Can be used in the same situations as Image and BufferedImage. */ -template class ImageData: public AbstractImage { +template class ImageData: public AbstractImage { public: - const static size_t Dimensions = imageDimensions; /**< @brief %Image dimension count */ + const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor * @param name %Image name - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components. Data type is detected * from passed data array. * @param data %Image data @@ -46,12 +46,12 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageData(const std::string& name, const Math::Vector& dimensions, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + template inline ImageData(const std::string& name, const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor * @param name %Image name - * @param dimensions %Image dimensions + * @param size %Image size * @param components Color components * @param type Data type * @param data %Image data @@ -59,7 +59,7 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const std::string& name, const Math::Vector& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _dimensions(dimensions), _data(reinterpret_cast(data)) {} + inline ImageData(const std::string& name, const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } @@ -67,8 +67,8 @@ template class ImageData: public AbstractImage { /** @brief %Image name */ inline std::string name() const { return _name; } - /** @brief %Image dimensions */ - inline constexpr const Math::Vector& dimensions() const { return _dimensions; } + /** @brief %Image size */ + inline constexpr const Math::Vector& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -76,7 +76,7 @@ template class ImageData: public AbstractImage { private: std::string _name; - Math::Vector _dimensions; + Math::Vector _size; char* _data; }; From 64fae952dd26320c529c37d5882f4dd417d7f733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 4 Oct 2012 00:20:46 +0200 Subject: [PATCH 134/256] Follow-up fix for previous commit. --- src/AbstractTexture.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 32b0900fd..a4c10e9a4 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -712,11 +712,11 @@ template<> struct AbstractTexture::DataHelper<1> { } template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - glTexImage1D(target, mipLevel, internalFormat, image->dimensions()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + glTexImage1D(target, mipLevel, internalFormat, image->size()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { - glTexSubImage1D(target, mipLevel, offset[0], image->dimensions()[0], static_cast(image->components()), static_cast(image->type()), image->data()); + glTexSubImage1D(target, mipLevel, offset[0], image->size()[0], static_cast(image->components()), static_cast(image->type()), image->data()); } }; #endif @@ -735,15 +735,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { static void setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping); template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - glTexImage2D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + glTexImage2D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { - glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], image->dimensions()[1], static_cast(image->components()), static_cast(image->type()), image->data()); + glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], image->size()[1], static_cast(image->components()), static_cast(image->type()), image->data()); } template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { - glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { @@ -757,15 +757,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping); template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + glTexImage3D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], image->size()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { - glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], static_cast(image->components()), static_cast(image->type()), image->data()); + glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], image->size()[2], static_cast(image->components()), static_cast(image->type()), image->data()); } template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { - glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; #endif From 805a51fd175783c410c0ee7e63643dfaa3fb2bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 4 Oct 2012 00:21:09 +0200 Subject: [PATCH 135/256] Export BufferedImage and Image explicit instantiations. --- src/BufferedImage.h | 6 +++--- src/Image.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 38f4ece69..7cd0eedab 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -107,9 +107,9 @@ template class BufferedImage: public AbstractImage { }; #ifndef DOXYGEN_GENERATING_OUTPUT -extern template class BufferedImage<1>; -extern template class BufferedImage<2>; -extern template class BufferedImage<3>; +extern template class MAGNUM_EXPORT BufferedImage<1>; +extern template class MAGNUM_EXPORT BufferedImage<2>; +extern template class MAGNUM_EXPORT BufferedImage<3>; #endif /** @brief One-dimensional buffered image */ diff --git a/src/Image.h b/src/Image.h index 37d4c820d..aa2b6fcf8 100644 --- a/src/Image.h +++ b/src/Image.h @@ -113,9 +113,9 @@ template class Image: public AbstractImage { }; #ifndef DOXYGEN_GENERATING_OUTPUT -extern template class Image<1>; -extern template class Image<2>; -extern template class Image<3>; +extern template class MAGNUM_EXPORT Image<1>; +extern template class MAGNUM_EXPORT Image<2>; +extern template class MAGNUM_EXPORT Image<3>; #endif /** @brief One-dimensional image */ From 8a7c86d70088b1d3515570a70c7f8830b2e1681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 28 Sep 2012 16:01:36 +0200 Subject: [PATCH 136/256] Initial implementation of ShapedObject. Physics library now depends on SceneGraph, which must be explicitly linked too. --- CMakeLists.txt | 2 +- modules/FindMagnum.cmake | 2 +- src/Physics/CMakeLists.txt | 6 +- src/Physics/ShapedObject.cpp | 54 +++++++++++ src/Physics/ShapedObject.h | 95 ++++++++++++++++++ src/Physics/ShapedObjectGroup.cpp | 32 ++++++ src/Physics/ShapedObjectGroup.h | 134 ++++++++++++++++++++++++++ src/Physics/Test/CMakeLists.txt | 2 + src/Physics/Test/ShapedObjectTest.cpp | 59 ++++++++++++ src/Physics/Test/ShapedObjectTest.h | 31 ++++++ 10 files changed, 414 insertions(+), 3 deletions(-) create mode 100644 src/Physics/ShapedObject.cpp create mode 100644 src/Physics/ShapedObject.h create mode 100644 src/Physics/ShapedObjectGroup.cpp create mode 100644 src/Physics/ShapedObjectGroup.h create mode 100644 src/Physics/Test/ShapedObjectTest.cpp create mode 100644 src/Physics/Test/ShapedObjectTest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 76eed8cbe..c33a6f7ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING" ON) option(WITH_GLXWINDOWCONTEXT "Build GlxWindowContext library" OFF) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 70b874ff9..a4544ed74 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -16,7 +16,7 @@ # libraries. Additional dependencies are specified by the components. The # optional components are: # MeshTools - MeshTools library -# Physics - Physics library +# Physics - Physics library (depends on SceneGraph component) # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 430587b7d..799da9a00 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -6,6 +6,8 @@ set(MagnumPhysics_SRCS Line.cpp Plane.cpp Point.cpp + ShapedObject.cpp + ShapedObjectGroup.cpp ShapeGroup.cpp Sphere.cpp) set(MagnumPhysics_HEADERS @@ -17,6 +19,8 @@ set(MagnumPhysics_HEADERS LineSegment.h Plane.h Point.h + ShapedObject.h + ShapedObjectGroup.h ShapeGroup.h Sphere.h @@ -24,7 +28,7 @@ set(MagnumPhysics_HEADERS add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) -target_link_libraries(MagnumPhysics Magnum) +target_link_libraries(MagnumPhysics Magnum MagnumSceneGraph) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp new file mode 100644 index 000000000..f7f31deb9 --- /dev/null +++ b/src/Physics/ShapedObject.cpp @@ -0,0 +1,54 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ShapedObject.h" + +#include + +#include "AbstractShaderProgram.h" +#include "Mesh.h" +#include "ResourceManager.h" +#include "AbstractShape.h" +#include "ShapedObjectGroup.h" + +using namespace std; + +namespace Magnum { namespace Physics { + +template ShapedObject::ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), group(group), _shape(nullptr) { + group->objects.push_back(this); +} + +template ShapedObject::~ShapedObject() { + group->objects.erase(find(group->objects.begin(), group->objects.end(), this)); + delete _shape; +} + +template void ShapedObject::setDirty() { + SceneGraph::AbstractObject::ObjectType::setDirty(); + + group->setDirty(); +} + +template void ShapedObject::clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation) { + SceneGraph::AbstractObject::ObjectType::clean(absoluteTransformation); + + if(_shape) _shape->applyTransformation(absoluteTransformation); +} + +template class ShapedObject<2>; +template class ShapedObject<3>; + +}} diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h new file mode 100644 index 000000000..4ceeb238e --- /dev/null +++ b/src/Physics/ShapedObject.h @@ -0,0 +1,95 @@ +#ifndef Magnum_Physics_ShapedObject_h +#define Magnum_Physics_ShapedObject_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Physics::ShapedObject + */ + +#include "SceneGraph/Object.h" + +#include "magnumPhysicsVisibility.h" + +namespace Magnum { namespace Physics { + +template class ShapedObjectGroup; +template class AbstractShape; + +/** +@brief Object with assigned shape + +@see ShapedObject2D, ShapedObject3D +*/ +template class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject::ObjectType { + public: + /** + * @brief Constructor + * @param group Group this shaped object belongs to + * @param parent Parent object + * + * Creates object with no shape. + * @see setShape() + */ + ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent = nullptr); + + /** + * @brief Destructor + * + * Deletes associated shape. + */ + ~ShapedObject(); + + /** @brief Object shape */ + inline AbstractShape* shape() { return _shape; } + inline const AbstractShape* shape() const { return _shape; } /**< @overload */ + + /** @brief Set object shape */ + void setShape(AbstractShape* shape) { _shape = shape; } + + /** + * @copybrief SceneGraph::AbstractObject::setDirty() + * + * Marks shaped object group as dirty. + */ + void setDirty(); + + protected: + /** + * @copybrief SceneGraph::AbstractObject::clean() + * + * Applies transformation to associated shape. + */ + void clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation); + + private: + ShapedObjectGroup* group; + AbstractShape* _shape; +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT ShapedObject<2>; +extern template class PHYSICS_EXPORT ShapedObject<3>; +#endif + +/** @brief Two-dimensional shaped object */ +typedef ShapedObject<2> ShapedObject2D; + +/** @brief Three-dimensional shaped object */ +typedef ShapedObject<3> ShapedObject3D; + +}} + +#endif diff --git a/src/Physics/ShapedObjectGroup.cpp b/src/Physics/ShapedObjectGroup.cpp new file mode 100644 index 000000000..89a901449 --- /dev/null +++ b/src/Physics/ShapedObjectGroup.cpp @@ -0,0 +1,32 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ShapedObjectGroup.h" + +#include "ShapedObject.h" + +namespace Magnum { namespace Physics { + +template void ShapedObjectGroup::setClean() { + for(ShapedObject* object: objects) + if(object->isDirty()) object->setClean(); + + dirty = false; +} + +template class ShapedObjectGroup<2>; +template class ShapedObjectGroup<3>; + +}} diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h new file mode 100644 index 000000000..74d38c816 --- /dev/null +++ b/src/Physics/ShapedObjectGroup.h @@ -0,0 +1,134 @@ +#ifndef Magnum_Physics_ShapedObjectGroup_h +#define Magnum_Physics_ShapedObjectGroup_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Physics::ShapedObjectGroup + */ + +#include +#include + +#include "magnumPhysicsVisibility.h" + +namespace Magnum { + +class AbstractShaderProgram; +template class Resource; + +namespace Physics { + +template class ShapedObject; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + enum class DebugMode { + None, + Wireframe, + SolidWireframe + }; +} +#endif + +/** +@brief Group of shaped objects + +@ref ShapedObject "ShapedObject*D" instances are added to the group by +specifying it in the constructor. When the group is deleted, all objects +belogning to it are deleted too. +@see ShapedObjectGroup2D, ShapedObjectGroup3D +*/ +template class PHYSICS_EXPORT ShapedObjectGroup { + friend class ShapedObject; + + public: + #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Debug mode + * + * @see setDebugMode() + */ + enum class DebugMode { + None, /**< @brief Nothing is rendered */ + Wireframe, /**< @brief Wireframe of the shape is rendered */ + SolidWireframe /**< @brief Solid with wireframe is rendered */ + }; + #else + typedef Implementation::DebugMode DebugMode; + #endif + + /** + * @brief Destructor + * + * Deletes all objects belogning to the group. + */ + inline virtual ~ShapedObjectGroup() { + for(auto i: objects) delete i; + } + + /** @brief Debug mode */ + inline DebugMode debugMode() const { return _debugMode; } + + /** @brief Set debug mode */ + inline void setDebugMode(DebugMode mode) { _debugMode = mode; } + + /** + * @brief Whether the group is dirty + * @return True if any object in the group is dirty, false otherwise. + */ + inline bool isDirty() const { return dirty; } + + /** + * @brief Set the group as dirty + * + * If some body in the group changes its transformation, it sets dirty + * status also on the group to indicate that the body and maybe also + * group state needs to be cleaned before computing collisions. + * + * @see setClean() + */ + inline void setDirty() { dirty = true; } + + /** + * @brief Set the group and all bodies as clean + * + * This function is called before computing any collisions to ensure + * all objects are cleaned. + */ + void setClean(); + + private: + Resource& shader(); + + DebugMode _debugMode; + std::vector*> objects; + bool dirty; +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template class PHYSICS_EXPORT ShapedObjectGroup<2>; +extern template class PHYSICS_EXPORT ShapedObjectGroup<3>; +#endif + +/** @brief Group of two-dimensional shaped objects */ +typedef ShapedObjectGroup<2> ShapedObjectGroup2D; + +/** @brief Group of three-dimensional shaped objects */ +typedef ShapedObjectGroup<3> ShapedObjectGroup3D; + +}} + +#endif diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index 4f8130a83..dd56a0631 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -6,3 +6,5 @@ corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsPointTest PointTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsShapeGroupTest ShapeGroupTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsSphereTest SphereTest.cpp LIBRARIES MagnumPhysics) + +corrade_add_test2(PhysicsShapedObjectTest ShapedObjectTest.cpp LIBRARIES MagnumPhysics) diff --git a/src/Physics/Test/ShapedObjectTest.cpp b/src/Physics/Test/ShapedObjectTest.cpp new file mode 100644 index 000000000..fec1e3c5a --- /dev/null +++ b/src/Physics/Test/ShapedObjectTest.cpp @@ -0,0 +1,59 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ShapedObjectTest.h" + +#include "Physics/ShapedObjectGroup.h" +#include "Physics/ShapedObject.h" + +CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapedObjectTest) + +namespace Magnum { namespace Physics { namespace Test { + +ShapedObjectTest::ShapedObjectTest() { + addTests(&ShapedObjectTest::clean); +} + +void ShapedObjectTest::clean() { + ShapedObjectGroup3D group; + + ShapedObject3D a(&group), b(&group); + + /* Everything is dirty at the beginning */ + CORRADE_VERIFY(group.isDirty()); + CORRADE_VERIFY(a.isDirty()); + CORRADE_VERIFY(b.isDirty()); + + /* Cleaning object will not clean anything other */ + a.setClean(); + CORRADE_VERIFY(group.isDirty()); + CORRADE_VERIFY(!a.isDirty()); + CORRADE_VERIFY(b.isDirty()); + + /* Setting group clean will clean whole group */ + a.setDirty(); + group.setClean(); + CORRADE_VERIFY(!group.isDirty()); + CORRADE_VERIFY(!a.isDirty()); + CORRADE_VERIFY(!b.isDirty()); + + /* Setting object dirty will set also the group, but not other objects */ + b.setDirty(); + CORRADE_VERIFY(group.isDirty()); + CORRADE_VERIFY(!a.isDirty()); + CORRADE_VERIFY(b.isDirty()); +} + +}}} diff --git a/src/Physics/Test/ShapedObjectTest.h b/src/Physics/Test/ShapedObjectTest.h new file mode 100644 index 000000000..81f49e406 --- /dev/null +++ b/src/Physics/Test/ShapedObjectTest.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Physics_Test_ShapedObjectTest_h +#define Magnum_Physics_Test_ShapedObjectTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Physics { namespace Test { + +class ShapedObjectTest: public Corrade::TestSuite::Tester { + public: + ShapedObjectTest(); + + void clean(); +}; + +}}} + +#endif From 58d9d351c0d40d3840c845e67ae8e6a935140dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 13:49:24 +0200 Subject: [PATCH 137/256] Compile Primitives library with -fPIC. Allows to link it into dynamic libraries in the future (such as Physics library). --- src/Primitives/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index d154d79c6..10d36351e 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -16,6 +16,7 @@ set(MagnumPrimitives_HEADERS UVSphere.h) add_library(MagnumPrimitives STATIC ${MagnumPrimitives_SRCS}) +set_target_properties(MagnumPrimitives PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") target_link_libraries(MagnumPrimitives Magnum) install(TARGETS MagnumPrimitives DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) From 934d04a76bc2fd17d62f1edd1f99d410b10df0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 14:50:16 +0200 Subject: [PATCH 138/256] Added method for getting key of given Resource. --- src/ResourceManager.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 27898efe0..919bc810c 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -266,40 +266,40 @@ template class Resource { inline Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {} /** @brief Copy constructor */ - inline Resource(const Resource& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { - if(manager) manager->incrementReferenceCount(key); + inline Resource(const Resource& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + if(manager) manager->incrementReferenceCount(_key); } /** @brief Move constructor */ - inline Resource(Resource&& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + inline Resource(Resource&& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { other.manager = nullptr; } /** @brief Destructor */ inline ~Resource() { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); } /** @brief Assignment operator */ Resource& operator=(const Resource& other) { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); manager = other.manager; - key = other.key; + _key = other._key; lastCheck = other.lastCheck; _state = other._state; data = other.data; - if(manager) manager->incrementReferenceCount(key); + if(manager) manager->incrementReferenceCount(_key); return *this; } /** @brief Assignment move operator */ Resource& operator=(Resource&& other) { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); manager = other.manager; - key = other.key; + _key = other._key; lastCheck = other.lastCheck; _state = other._state; data = other.data; @@ -308,6 +308,9 @@ template class Resource { return *this; } + /** @brief Resource key */ + inline ResourceKey key() const { return _key; } + /** * @brief %Resource state * @@ -343,7 +346,7 @@ template class Resource { } private: - inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { + inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { manager->incrementReferenceCount(key); } @@ -355,7 +358,7 @@ template class Resource { if(manager->lastChange() < lastCheck) return; /* Acquire new data and save last check time */ - const typename Implementation::ResourceManagerData::Data& d = manager->data(key); + const typename Implementation::ResourceManagerData::Data& d = manager->data(_key); lastCheck = manager->lastChange(); /* Try to get the data */ @@ -368,7 +371,7 @@ template class Resource { } Implementation::ResourceManagerData* manager; - ResourceKey key; + ResourceKey _key; size_t lastCheck; ResourceState _state; T* data; @@ -423,7 +426,7 @@ Resource cube(manager->get("cube")); if(!cube) { Mesh* mesh = new Mesh; // ... - manager->set("cube", mesh, ResourceDataState::Final, ResourcePolicy::Resident); + manager->set(cube.key(), mesh, ResourceDataState::Final, ResourcePolicy::Resident); } @endcode - Using the resource data. From 2b3a2951cceab5bdb4f23731876d3bbb55dac376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:16:38 +0200 Subject: [PATCH 139/256] New struct DimensionTraits for matrix, vector and point specializations. --- src/DimensionTraits.h | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/DimensionTraits.h diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h new file mode 100644 index 000000000..d5c3a15aa --- /dev/null +++ b/src/DimensionTraits.h @@ -0,0 +1,109 @@ +#ifndef Magnum_DimensionTraits_h +#define Magnum_DimensionTraits_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +/** @file + * @brief Class Magnum::DimensionTraits + */ + +namespace Magnum { + +namespace Math { + template class Vector; + template class Vector2; + template class Vector3; + + template class Point2D; + template class Point3D; + + template class Matrix3; + template class Matrix4; +} + +/** @brief Matrix, point and vector specializations for given dimension count */ +template struct DimensionTraits { + #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Vector type + * + * Math::Vector, Math::Vector2 or Math::Vector3 based on dimension count. + */ + typedef U VectorType; + + /** + * @brief Point type + * + * Floating-point Math::Point2D or Math::Point3D for 2D or 3D. No point + * type defined for one dimension and integral types. + */ + typedef U PointType; + + /** + * @brief Matrix type + * + * Floating-point Math::Matrix3 or Math::Matrix4 for 2D or 3D. No matrix + * type defined for one dimension and integral types. + */ + typedef U MatrixType; + #endif +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +/* One dimension */ +template struct DimensionTraits<1, T> { + typedef Math::Vector<1, T> VectorType; +}; + +/* Two dimensions - integral */ +template struct DimensionTraits<2, T> { + typedef Math::Vector2 VectorType; +}; + +/* Two dimensions - floating-point */ +template<> struct DimensionTraits<2, float> { + typedef Math::Vector2 VectorType; + typedef Math::Point2D PointType; + typedef Math::Matrix3 MatrixType; +}; +template<> struct DimensionTraits<2, double> { + typedef Math::Vector2 VectorType; + typedef Math::Point2D PointType; + typedef Math::Matrix3 MatrixType; +}; + +/* Three dimensions - integral */ +template struct DimensionTraits<3, T> { + typedef Math::Vector3 VectorType; +}; + +/* Three dimensions - floating-point */ +template<> struct DimensionTraits<3, float> { + typedef Math::Vector3 VectorType; + typedef Math::Point3D PointType; + typedef Math::Matrix4 MatrixType; +}; +template<> struct DimensionTraits<3, double> { + typedef Math::Vector3 VectorType; + typedef Math::Point3D PointType; + typedef Math::Matrix4 MatrixType; +}; +#endif + +} + +#endif From d49ee5c76ef784c9af30e98b4ecec32895f4c119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:20:01 +0200 Subject: [PATCH 140/256] Using specialized Vector type in images and textures. Thanks to DimensionTraits it is now possible to e.g. conveniently access components by name or pass size as combination of vector and scalar: GLsizei width = image.size().x(); image.setData({xy, 1}, ...); Instead of previous inconvenient ways: GLsizei width = image.size()[0]; Math::Vector2 size(xy, 1); image.setData(size, ...); Not using the specialized type for internal functions and storage, as it wouldn't cause any other improvements. This way it is virtually possible to forward-declare the specialized types without including them in the headers. --- src/BufferedImage.cpp | 2 +- src/BufferedImage.h | 9 +++++---- src/CubeMapTexture.h | 2 +- src/Image.cpp | 2 +- src/Image.h | 13 +++++++------ src/ImageWrapper.h | 11 ++++++----- src/Texture.h | 3 ++- src/Trade/ImageData.h | 9 +++++---- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index e40a9ab3f..43c43227b 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void BufferedImage::setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { +template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; _type = type; _size = size; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 7cd0eedab..99062b105 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -19,9 +19,10 @@ * @brief Class Magnum::BufferedImage, typedef Magnum::BufferedImage1D, Magnum::BufferedImage2D, Magnum::BufferedImage3D */ -#include "Math/Vector.h" +#include "Math/Vector3.h" #include "AbstractImage.h" #include "Buffer.h" +#include "DimensionTraits.h" #include "TypeTraits.h" namespace Magnum { @@ -50,7 +51,7 @@ template class BufferedImage: public AbstractImage { inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} /** @brief %Image size */ - inline constexpr Math::Vector size() const { return _size; } + inline constexpr typename DimensionTraits::VectorType size() const { return _size; } /** * @brief Data @@ -82,7 +83,7 @@ template class BufferedImage: public AbstractImage { * * @see setData(const Math::Vector&, Components, ComponentType, const GLvoid*, Buffer::Usage) */ - template inline void setData(const Math::Vector& size, Components components, const T* data, Buffer::Usage usage) { + template inline void setData(const typename DimensionTraits::VectorType& size, Components components, const T* data, Buffer::Usage usage) { setData(size, components, TypeTraits::imageType(), data, usage); } @@ -99,7 +100,7 @@ template class BufferedImage: public AbstractImage { * * @see Buffer::setData() */ - void setData(const Math::Vector& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); + void setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); protected: Math::Vector _size; /**< @brief %Image size */ diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index edf64830a..a537eaec8 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -103,7 +103,7 @@ class CubeMapTexture: public AbstractTexture { } /** - * @copydoc Texture::setSubData(GLint, const Math::Vector&, Image*) + * @copydoc Texture::setSubData(GLint, const typename DimensionTraits::VectorType&, Image*) * @param coordinate Coordinate * @return Pointer to self (for method chaining) */ diff --git a/src/Image.cpp b/src/Image.cpp index f12b2caa7..a5fa6c4d1 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void Image::setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { delete[] _data; _components = components; _type = type; diff --git a/src/Image.h b/src/Image.h index aa2b6fcf8..83a1187a2 100644 --- a/src/Image.h +++ b/src/Image.h @@ -19,8 +19,9 @@ * @brief Class Magnum::Image, typedef Magnum::Image1D, Magnum::Image2D, Magnum::Image3D */ -#include "Math/Vector.h" +#include "Math/Vector3.h" #include "AbstractImage.h" +#include "DimensionTraits.h" #include "TypeTraits.h" namespace Magnum { @@ -47,7 +48,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline Image(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} + template inline Image(const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor @@ -59,7 +60,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline Image(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} + inline Image(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -75,7 +76,7 @@ template class Image: public AbstractImage { inline ~Image() { delete[] _data; } /** @brief %Image size */ - inline constexpr const Math::Vector& size() const { return _size; } + inline constexpr typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -91,7 +92,7 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - template inline void setData(const Math::Vector& size, Components components, T* data) { + template inline void setData(const typename DimensionTraits::VectorType& size, Components components, T* data) { setData(size, components, TypeTraits::imageType(), data); } @@ -105,7 +106,7 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const Math::Vector& size, Components components, ComponentType type, GLvoid* data); + void setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data); protected: Math::Vector _size; /**< @brief %Image size */ diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index e1237e329..6699d680e 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -19,8 +19,9 @@ * @brief Class Magnum::ImageWrapper */ -#include "Math/Vector.h" +#include "Math/Vector3.h" #include "AbstractImage.h" +#include "DimensionTraits.h" #include "TypeTraits.h" namespace Magnum { @@ -53,7 +54,7 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageWrapper(const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} + template inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor @@ -65,7 +66,7 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} + inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -76,10 +77,10 @@ template class ImageWrapper: public AbstractImage { * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline ImageWrapper(const Math::Vector& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} + inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} /** @brief %Image size */ - inline constexpr const Math::Vector& size() const { return _size; } + inline constexpr typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } diff --git a/src/Texture.h b/src/Texture.h index 015f18cdb..01560b586 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -20,6 +20,7 @@ */ #include "AbstractTexture.h" +#include "DimensionTraits.h" namespace Magnum { @@ -167,7 +168,7 @@ template class Texture: public AbstractTexture { * 1D texture array (which is two-dimensional) with 1D images. * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} */ - template inline Texture* setSubData(GLint mipLevel, const Math::Vector& offset, Image* image) { + template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { bind(); DataHelper::setSub(_target, mipLevel, offset, image); return this; diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index 260fa8d8a..bde311640 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -19,8 +19,9 @@ * @brief Class Magnum::Trade::ImageData */ -#include "Math/Vector.h" +#include "Math/Vector3.h" #include "AbstractImage.h" +#include "DimensionTraits.h" #include "TypeTraits.h" namespace Magnum { namespace Trade { @@ -46,7 +47,7 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageData(const std::string& name, const Math::Vector& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} + template inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -59,7 +60,7 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const std::string& name, const Math::Vector& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} + inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } @@ -68,7 +69,7 @@ template class ImageData: public AbstractImage { inline std::string name() const { return _name; } /** @brief %Image size */ - inline constexpr const Math::Vector& size() const { return _size; } + inline constexpr typename DimensionTraits::VectorType& size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } From cac85252ac201778fb71b832be8c73ae0bfd427b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:36:42 +0200 Subject: [PATCH 141/256] Using DimensionTraits in SceneGraph implementation. Removed equivalent typedefs from AbstractObject and replaced them with DimensionTraits. --- src/Physics/ShapedObject.cpp | 2 +- src/Physics/ShapedObject.h | 2 +- src/SceneGraph/Camera.cpp | 6 +++--- src/SceneGraph/Camera.h | 16 ++++++++-------- src/SceneGraph/Object.cpp | 10 +++++----- src/SceneGraph/Object.h | 31 ++++++++++--------------------- src/SceneGraph/Scene.h | 12 ++++++------ 7 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp index f7f31deb9..dd34a52a9 100644 --- a/src/Physics/ShapedObject.cpp +++ b/src/Physics/ShapedObject.cpp @@ -42,7 +42,7 @@ template void ShapedObject::setDirty() { group->setDirty(); } -template void ShapedObject::clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation) { +template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { SceneGraph::AbstractObject::ObjectType::clean(absoluteTransformation); if(_shape) _shape->applyTransformation(absoluteTransformation); diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index 4ceeb238e..2c04c962a 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -72,7 +72,7 @@ template class PHYSICS_EXPORT ShapedObject: public SceneGraph * * Applies transformation to associated shape. */ - void clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation); + void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); private: ShapedObjectGroup* group; diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 892a0a419..81c39d354 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -58,7 +58,7 @@ template void AbstractCamera::setViewport(const M fixAspectRatio(); } -template void AbstractCamera::clean(const typename AbstractObject::MatrixType& absoluteTransformation) { +template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { AbstractObject::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); @@ -72,10 +72,10 @@ template void AbstractCamera::draw() { drawChildren(s, cameraMatrix()); } -template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix) { +template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { for(typename AbstractObject::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ - typename AbstractObject::MatrixType matrix = transformationMatrix*i->transformation(); + typename DimensionTraits::MatrixType matrix = transformationMatrix*i->transformation(); /* Draw the object and its children */ i->draw(matrix, static_cast::CameraType*>(this)); diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 18f5c016c..3e473c4a7 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -86,7 +86,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr * Camera matrix describes world position relative to the camera and is * applied as first. */ - inline typename AbstractObject::MatrixType cameraMatrix() { + inline typename DimensionTraits::MatrixType cameraMatrix() { this->setClean(); return _cameraMatrix; } @@ -98,7 +98,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr * as last. * @see projectionSize() */ - inline typename AbstractObject::MatrixType projectionMatrix() const { return _projectionMatrix; } + inline typename DimensionTraits::MatrixType projectionMatrix() const { return _projectionMatrix; } /** * @brief Size of (near) XY plane in current projection @@ -135,27 +135,27 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr /** * Recalculates camera matrix. */ - void clean(const typename AbstractObject::MatrixType& absoluteTransformation); + void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); /** * @brief Draw object children * * Recursively draws all children of the object. */ - void drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix); + void drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix); #ifndef DOXYGEN_GENERATING_OUTPUT inline void fixAspectRatio() { - _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; + _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; } - typename AbstractObject::MatrixType rawProjectionMatrix; + typename DimensionTraits::MatrixType rawProjectionMatrix; AspectRatioPolicy _aspectRatioPolicy; #endif private: - typename AbstractObject::MatrixType _projectionMatrix; - typename AbstractObject::MatrixType _cameraMatrix; + typename DimensionTraits::MatrixType _projectionMatrix; + typename DimensionTraits::MatrixType _cameraMatrix; Math::Vector2 _viewport; }; diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index a0a02922a..b723a55a5 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -49,11 +49,11 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template typename AbstractObject::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { +template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ - if(camera == this) return MatrixType(); + if(camera == this) return typename DimensionTraits::MatrixType(); - MatrixType t = _transformation; + typename DimensionTraits::MatrixType t = _transformation; ObjectType* p = parent(); while(p != nullptr) { @@ -89,7 +89,7 @@ template typename AbstractObject::SceneType* Abst return nullptr; } -template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const MatrixType& transformation) { +template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -130,7 +130,7 @@ template void AbstractObject::setClean() { /* Call setClean(const Matrix4&) for every parent and also this object */ ObjectType* o = objects.top(); objects.pop(); - MatrixType absoluteTransformation = o->absoluteTransformation(); + typename DimensionTraits::MatrixType absoluteTransformation = o->absoluteTransformation(); o->clean(absoluteTransformation); while(!objects.empty()) { o = objects.top(); diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index ddb8f6191..3b2e5dca0 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -24,6 +24,7 @@ #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Magnum.h" +#include "DimensionTraits.h" #include "magnumSceneGraphVisibility.h" @@ -42,18 +43,12 @@ namespace Implementation { template struct ObjectDimensionTraits {}; template<> struct ObjectDimensionTraits<2> { - static const size_t Dimensions = 2; - typedef Vector2 VectorType; - typedef Matrix3 MatrixType; typedef Object2D ObjectType; typedef Camera2D CameraType; typedef Scene2D SceneType; }; template<> struct ObjectDimensionTraits<3> { - static const size_t Dimensions = 3; - typedef Vector3 VectorType; - typedef Matrix4 MatrixType; typedef Object3D ObjectType; typedef Camera3D CameraType; typedef Scene3D SceneType; @@ -88,12 +83,6 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra public: static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ - /** @brief %Vector type for given dimension count */ - typedef typename Implementation::ObjectDimensionTraits::VectorType VectorType; - - /** @brief %Matrix type for given dimension count */ - typedef typename Implementation::ObjectDimensionTraits::MatrixType MatrixType; - /** @brief %Object type for given dimension count */ typedef typename Implementation::ObjectDimensionTraits::ObjectType ObjectType; @@ -174,7 +163,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra }; /** @brief Transformation */ - inline MatrixType transformation() const { + inline typename DimensionTraits::MatrixType transformation() const { return _transformation; } @@ -189,13 +178,13 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * objects every time it is asked, unless this function is * reimplemented in a different way. */ - virtual MatrixType absoluteTransformation(CameraType* camera = nullptr); + virtual typename DimensionTraits::MatrixType absoluteTransformation(CameraType* camera = nullptr); /** * @brief Set transformation * @return Pointer to self (for method chaining) */ - ObjectType* setTransformation(const MatrixType& transformation); + ObjectType* setTransformation(const typename DimensionTraits::MatrixType& transformation); /** * @brief Multiply transformation @@ -203,7 +192,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * @param type Transformation type * @return Pointer to self (for method chaining) */ - inline ObjectType* multiplyTransformation(const MatrixType& transformation, Transformation type = Transformation::Global) { + inline ObjectType* multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, Transformation type = Transformation::Global) { setTransformation(type == Transformation::Global ? transformation*_transformation : _transformation*transformation); return static_cast(this); @@ -220,7 +209,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * * Default implementation does nothing. */ - virtual void draw(const MatrixType& transformationMatrix, CameraType* camera); + virtual void draw(const typename DimensionTraits::MatrixType& transformationMatrix, CameraType* camera); /** @{ @name Caching helpers * @@ -295,7 +284,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * } * @endcode */ - virtual void clean(const MatrixType& absoluteTransformation); + virtual void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); /*@}*/ @@ -313,15 +302,15 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra using Corrade::Containers::LinkedListItem::previous; using Corrade::Containers::LinkedListItem::next; - MatrixType _transformation; + typename DimensionTraits::MatrixType _transformation; bool dirty; }; template inline AbstractObject::~AbstractObject() {} /* Implementations for inline functions with unused parameters */ -template inline void AbstractObject::draw(const MatrixType&, CameraType*) {} -template inline void AbstractObject::clean(const MatrixType&) { dirty = false; } +template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} +template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 092f85e73..90d0e2ca7 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -36,15 +36,15 @@ template class SCENEGRAPH_EXPORT Scene: public AbstractObject /** @todo Some deleted functions belong only to Scene2D, some only to Scene3D - what to do? */ #ifndef DOXYGEN_GENERATING_OUTPUT void setParent(typename AbstractObject::ObjectType* parent) = delete; - void setTransformation(const typename AbstractObject::MatrixType& transformation) = delete; - void multiplyTransformation(const typename AbstractObject::MatrixType& transformation, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void translate(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void scale(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void rotate(GLfloat angle, const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void setTransformation(const typename DimensionTraits::MatrixType& transformation) = delete; + void multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, typename AbstractObject::Transformation type = DimensionTraits::Transformation::Global) = delete; + void translate(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void scale(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void rotate(GLfloat angle, const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; #endif private: - inline void draw(const typename AbstractObject::MatrixType&, typename AbstractObject::CameraType*) {} + inline void draw(const typename DimensionTraits::MatrixType&, typename AbstractObject::CameraType*) {} }; /** @brief Two-dimensional scene */ From 972846677d9efd082c73b4deb70ce91545dc6bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:37:41 +0200 Subject: [PATCH 142/256] Using DimensionTraits for Shape implementation. Removed equivalent typedefs from AbstractShape, using DimensionTraits everywhere except for internal storage. It would possibly allow to remove #include for specialized types from Shape headers. Also removed Doxygen workarounds for applyTransformation(), as both the pure virtual function and implementations have now the same signature. --- src/Physics/AbstractShape.h | 20 ++------------------ src/Physics/AxisAlignedBox.cpp | 4 ++-- src/Physics/AxisAlignedBox.h | 22 +++++++++------------- src/Physics/Box.cpp | 2 +- src/Physics/Box.h | 16 ++++++---------- src/Physics/Capsule.cpp | 8 ++++---- src/Physics/Capsule.h | 22 +++++++++------------- src/Physics/Line.cpp | 6 +++--- src/Physics/Line.h | 22 +++++++++------------- src/Physics/LineSegment.h | 2 +- src/Physics/Plane.h | 2 +- src/Physics/Point.cpp | 4 ++-- src/Physics/Point.h | 16 ++++++---------- src/Physics/ShapeGroup.cpp | 2 +- src/Physics/ShapeGroup.h | 6 +----- src/Physics/Sphere.cpp | 6 +++--- src/Physics/Sphere.h | 16 ++++++---------- 17 files changed, 66 insertions(+), 110 deletions(-) diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index f4b8ea370..62b60acfc 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -20,6 +20,7 @@ */ #include "Magnum.h" +#include "DimensionTraits.h" #include "magnumPhysicsVisibility.h" @@ -30,10 +31,6 @@ namespace Implementation { template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { - typedef Vector2 VectorType; - typedef Point2D PointType; - typedef Matrix3 MatrixType; - enum class Type { Point, Line, @@ -47,10 +44,6 @@ namespace Implementation { }; template<> struct ShapeDimensionTraits<3> { - typedef Vector3 VectorType; - typedef Point3D PointType; - typedef Matrix4 MatrixType; - enum class Type { Point, Line, @@ -74,15 +67,6 @@ See @ref collision-detection for brief introduction. */ template class PHYSICS_EXPORT AbstractShape { public: - /** @brief %Vector type for given dimension count */ - typedef typename Implementation::ShapeDimensionTraits::VectorType VectorType; - - /** @brief %Point type for given dimension count */ - typedef typename Implementation::ShapeDimensionTraits::PointType PointType; - - /** @brief %Matrix type for given dimension count */ - typedef typename Implementation::ShapeDimensionTraits::MatrixType MatrixType; - /** @brief Dimension count */ static const size_t Dimensions = dimensions; @@ -121,7 +105,7 @@ template class PHYSICS_EXPORT AbstractShape { * Applies transformation to user-defined shape properties and caches * them for later usage in collision detection. */ - virtual void applyTransformation(const MatrixType& transformation) = 0; + virtual void applyTransformation(const typename DimensionTraits::MatrixType& transformation) = 0; /** * @brief Detect collision with other shape diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 49a7c919f..64b832394 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformation(const typename AbstractShape::MatrixType& transformation) { - _transformedPosition = (transformation*typename AxisAlignedBox::PointType(_position)).vector(); +template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 45dab8f70..f6b9e87c7 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -32,39 +32,35 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ - inline AxisAlignedBox(const typename AbstractShape::VectorType& position, const typename AbstractShape::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Position */ - inline typename AbstractShape::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename AbstractShape::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } /** @brief Size */ - inline typename AbstractShape::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Set size */ - inline void setSize(const typename AbstractShape::VectorType& size) { + inline void setSize(const typename DimensionTraits::VectorType& size) { _size = size; } /** @brief Transformed position */ - inline typename AbstractShape::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } /** @brief Transformed size */ - inline typename AbstractShape::VectorType transformedSize() const { + inline typename DimensionTraits::VectorType transformedSize() const { return _transformedSize; } @@ -74,7 +70,7 @@ template class PHYSICS_EXPORT AxisAlignedBox: public Abstract } private: - typename AbstractShape::VectorType _position, _transformedPosition, + Math::Vector _position, _transformedPosition, _size, _transformedSize; }; diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index cc5d292bd..8b63ad5dd 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformation(const typename AbstractShape::MatrixType& transformation) { +template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedTransformation = (transformation*_transformation); } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 02515d976..f52b265d1 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -33,26 +33,22 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ - inline Box(const typename AbstractShape::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} + inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Transformation */ - inline typename AbstractShape::MatrixType transformation() const { + inline typename DimensionTraits::MatrixType transformation() const { return _transformation; } /** @brief Set transformation */ - inline void setTransformation(const typename AbstractShape::MatrixType& transformation) { + inline void setTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformation = transformation; } /** @brief Transformed transformation */ - inline typename AbstractShape::MatrixType transformedTransformation() const { + inline typename DimensionTraits::MatrixType transformedTransformation() const { return _transformedTransformation; } @@ -62,7 +58,7 @@ template class PHYSICS_EXPORT Box: public AbstractShape::MatrixType _transformation, + Math::Matrix _transformation, _transformedTransformation; }; diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 9dd3715a4..f05b19858 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,10 +27,10 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformation(const typename AbstractShape::MatrixType& transformation) { - _transformedA = (transformation*typename AbstractShape::PointType(_a)).vector(); - _transformedB = (transformation*typename AbstractShape::PointType(_b)).vector(); - float scaling = (transformation.rotationScaling()*typename AbstractShape::VectorType(1/Math::Constants::sqrt3())).length(); +template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); + float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 76bfc828f..93b950527 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -37,33 +37,29 @@ applying transformation, the scale factor is averaged from all axes. template class PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline Capsule(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; /** @brief Start point */ - inline typename AbstractShape::VectorType a() const { + inline typename DimensionTraits::VectorType a() const { return _a; } /** @brief End point */ - inline typename AbstractShape::VectorType b() const { + inline typename DimensionTraits::VectorType b() const { return _a; } /** @brief Set start point */ - inline void setA(const typename AbstractShape::VectorType& a) { + inline void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief Set end point */ - inline void setB(const typename AbstractShape::VectorType& b) { + inline void setB(const typename DimensionTraits::VectorType& b) { _b = b; } @@ -74,12 +70,12 @@ template class PHYSICS_EXPORT Capsule: public AbstractShape::VectorType transformedA() const { + inline typename DimensionTraits::VectorType transformedA() const { return _transformedA; } /** @brief Transformed second point */ - inline typename AbstractShape::VectorType transformedB() const { + inline typename DimensionTraits::VectorType transformedB() const { return _transformedB; } @@ -100,7 +96,7 @@ template class PHYSICS_EXPORT Capsule: public AbstractShape::VectorType _a, _transformedA, + Math::Vector _a, _transformedA, _b, _transformedB; float _radius, _transformedRadius; }; diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 5adf4f61a..bfe5362ed 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,9 +20,9 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformation(const typename AbstractShape::MatrixType& transformation) { - _transformedA = (transformation*typename AbstractShape::PointType(_a)).vector(); - _transformedB = (transformation*typename AbstractShape::PointType(_b)).vector(); +template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); } /* Explicitly instantiate the templates */ diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 4e43b98a9..90332cf9a 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -33,41 +33,37 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ - inline Line(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} + inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief First point */ - inline typename AbstractShape::VectorType a() const { + inline typename DimensionTraits::VectorType a() const { return _a; } /** @brief Second point */ - inline typename AbstractShape::VectorType b() const { + inline typename DimensionTraits::VectorType b() const { return _a; } /** @brief Set first point */ - inline void setA(const typename AbstractShape::VectorType& a) { + inline void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief Set second point */ - inline void setB(const typename AbstractShape::VectorType& b) { + inline void setB(const typename DimensionTraits::VectorType& b) { _b = b; } /** @brief Transformed first point */ - inline typename AbstractShape::VectorType transformedA() const { + inline typename DimensionTraits::VectorType transformedA() const { return _transformedA; } /** @brief Transformed second point */ - inline typename AbstractShape::VectorType transformedB() const { + inline typename DimensionTraits::VectorType transformedB() const { return _transformedB; } @@ -77,7 +73,7 @@ template class PHYSICS_EXPORT Line: public AbstractShape::VectorType _a, _transformedA, + Math::Vector _a, _transformedA, _b, _transformedB; }; diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index c7d59863d..407fdc382 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { template class LineSegment: public Line { public: /** @brief Constructor */ - inline LineSegment(const typename AbstractShape::VectorType& a, const typename AbstractShape::VectorType& b): Line(a, b) {} + inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} protected: inline typename AbstractShape::Type type() const { return AbstractShape::Type::LineSegment; } diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 64e7c116e..8c547dc8e 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -39,7 +39,7 @@ class PHYSICS_EXPORT Plane: public AbstractShape<3> { void applyTransformation(const Matrix4& transformation); bool collides(const AbstractShape<3>* other) const; #else - void applyTransformation(const MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; #endif diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 67657450c..f2a15267f 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformation(const typename AbstractShape::MatrixType& transformation) { - _transformedPosition = (transformation*typename AbstractShape::PointType(_position)).vector(); +template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); } template class Point<2>; diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 05483d9b3..f390c4f02 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -32,26 +32,22 @@ namespace Magnum { namespace Physics { template class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ - inline Point(const typename AbstractShape::VectorType& position): _position(position), _transformedPosition(position) {} + inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Position */ - inline typename AbstractShape::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename AbstractShape::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } /** @brief Transformed position */ - inline typename AbstractShape::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } @@ -59,7 +55,7 @@ template class PHYSICS_EXPORT Point: public AbstractShape::Type type() const { return AbstractShape::Type::Point; } private: - typename AbstractShape::VectorType _position, _transformedPosition; + Math::Vector _position, _transformedPosition; }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 813baf7bd..be94a88f2 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -43,7 +43,7 @@ template ShapeGroup& ShapeGroup::oper return *this; } -template void ShapeGroup::applyTransformation(const typename AbstractShape::MatrixType& transformation) { +template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { if(a) a->applyTransformation(transformation); if(b) b->applyTransformation(transformation); } diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 200898761..83d19b920 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -99,11 +99,7 @@ template class PHYSICS_EXPORT ShapeGroup: public AbstractShap /** @brief Move assignment */ ShapeGroup& operator=(ShapeGroup&& other); - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 6015f5950..af9a668a2 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -28,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename AbstractShape::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Math::Constants::sqrt2()); @@ -39,8 +39,8 @@ namespace { } } -template void Sphere::applyTransformation(const typename AbstractShape::MatrixType& transformation) { - _transformedPosition = (transformation*typename AbstractShape::PointType(_position)).vector(); +template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { + _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); float scaling = (transformation.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 60639a37d..dda4e5161 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -38,23 +38,19 @@ applying transformation, the scale factor is averaged from all axes. template class PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline Sphere(const typename AbstractShape::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} - #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const typename AbstractShape::MatrixType& transformation); - #else - void applyTransformation(const MatrixType& transformation); - #endif + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; /** @brief Position */ - inline typename AbstractShape::VectorType position() const { + inline typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - inline void setPosition(const typename AbstractShape::VectorType& position) { + inline void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } @@ -65,7 +61,7 @@ template class PHYSICS_EXPORT Sphere: public AbstractShape::VectorType transformedPosition() const { + inline typename DimensionTraits::VectorType transformedPosition() const { return _transformedPosition; } @@ -92,7 +88,7 @@ template class PHYSICS_EXPORT Sphere: public AbstractShape::VectorType _position, + Math::Vector _position, _transformedPosition; float _radius, _transformedRadius; }; From 131e75ef912e489bb14276a42625795a9498e8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 17:30:42 +0200 Subject: [PATCH 143/256] Added @todos. --- src/Texture.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Texture.h b/src/Texture.h index 01560b586..49bcf536c 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -48,6 +48,7 @@ for more information. @requires_gl31 Extension @extension{ARB,texture_rectangle} (rectangle textures) @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray +@todo @extension{AMD,sparse_texture} */ template class Texture: public AbstractTexture { public: @@ -125,6 +126,8 @@ template class Texture: public AbstractTexture { * more information. * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_WRAP_S}, * @def_gl{TEXTURE_WRAP_T}, @def_gl{TEXTURE_WRAP_R} + * @todo Use something better for this than Vector (mainly something + * that can easily create all values the same) */ inline Texture* setWrapping(const Math::Vector& wrapping) { bind(); From a0f79fcf78c96d8b8c9eb85008a7d00597a6343b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:28:33 +0200 Subject: [PATCH 144/256] Don't parse Implementation/ directories with Doxygen. These are even more "private" versions of Implementation namespace in public headers, so we don't need to generate public documentation for them. --- Doxyfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Doxyfile b/Doxyfile index d534db6af..0322c1da3 100644 --- a/Doxyfile +++ b/Doxyfile @@ -731,6 +731,7 @@ EXCLUDE_SYMLINKS = NO # for example use the pattern */test/* EXCLUDE_PATTERNS = */Test/* \ + */Implementation/* \ *Visibility.h # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names From 815f2d74918051fbddf56e805463e50d8c28620c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 18:11:29 +0200 Subject: [PATCH 145/256] Use the right type for attribute binding location. --- src/AbstractShaderProgram.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index c695f1d66..1892d5f16 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -203,13 +203,13 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @brief Base struct for attribute location and type * - * See AbstractShaderProgram documentation or Mesh::bindAttribute() + * See @ref AbstractShaderProgram-subclassing or Mesh::bindAttribute() * for an example. * * @todo Support for BGRA attribute type (OpenGL 3.2, @extension{ARB,vertex_array_bgra}) */ - template struct Attribute { - static const size_t Location = i; /**< Location to which the attribute is bound */ + template struct Attribute { + static const GLuint Location = i; /**< Location to which the attribute is bound */ typedef T Type; /**< %Attribute type */ }; From 0145343d59d576dd349c2b59e3c38884f49f8093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 23:56:57 +0200 Subject: [PATCH 146/256] Pedantic: using std::size_t instead of size_t from C compat headers. --- src/AbstractImage.cpp | 2 + src/AbstractImage.h | 2 +- src/Buffer.h | 8 +-- src/Context.h | 4 +- src/DimensionTraits.h | 2 +- src/Extensions.h | 2 +- src/Math/Algorithms/GaussJordan.h | 18 +++--- src/Math/MathTypeTraits.h | 2 +- src/Math/Matrix.h | 40 +++++++------- src/Math/RectangularMatrix.h | 82 ++++++++++++++-------------- src/Math/Vector.h | 38 ++++++------- src/MeshTools/Clean.h | 32 +++++------ src/MeshTools/CombineIndexedArrays.h | 18 +++--- src/MeshTools/CompressIndices.cpp | 2 + src/MeshTools/CompressIndices.h | 10 ++-- src/MeshTools/Interleave.h | 24 ++++---- src/MeshTools/Subdivide.h | 6 +- src/MeshTools/Test/CleanTest.h | 6 +- src/MeshTools/Test/SubdivideTest.h | 6 +- src/MeshTools/Test/TipsifyTest.h | 2 +- src/MeshTools/Tipsify.h | 4 +- src/MeshTools/Transform.h | 2 +- src/Primitives/Icosphere.h | 8 +-- src/Profiler.h | 4 +- src/ResourceManager.h | 24 ++++---- src/SizeTraits.h | 10 ++-- src/Swizzle.h | 34 ++++++------ src/Test/ResourceManagerTest.h | 2 +- src/TypeTraits.h | 58 ++++++++++---------- 29 files changed, 228 insertions(+), 224 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 4194431c2..de0e9929c 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -16,6 +16,8 @@ #include "AbstractImage.h" #include "TypeTraits.h" +using namespace std; + namespace Magnum { size_t AbstractImage::pixelSize(Components format, ComponentType type) { diff --git a/src/AbstractImage.h b/src/AbstractImage.h index f32b17e03..e310ff00a 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -268,7 +268,7 @@ class MAGNUM_EXPORT AbstractImage { * @param components Color components * @param type Data type */ - static size_t pixelSize(Components components, ComponentType type); + static std::size_t pixelSize(Components components, ComponentType type); /** * @brief Constructor diff --git a/src/Buffer.h b/src/Buffer.h index 5a35d152b..a7ff8df08 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -250,7 +250,7 @@ class Buffer { * setData(GLsizeiptr, const GLvoid*, Usage). * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ - template inline void setData(const T(&data)[size], Usage usage) { + template inline void setData(const T(&data)[size], Usage usage) { setData(_defaultTarget, data, usage); } @@ -291,7 +291,7 @@ class Buffer { * * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) */ - template inline void setData(Target target, const T(&data)[size], Usage usage) { + template inline void setData(Target target, const T(&data)[size], Usage usage) { setData(target, size*sizeof(T), data, usage); } @@ -330,7 +330,7 @@ class Buffer { * setSubData(GLintptr, GLsizeiptr, const GLvoid*). * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ - template inline void setSubData(GLintptr offset, const T(&data)[size]) { + template inline void setSubData(GLintptr offset, const T(&data)[size]) { setSubData(_defaultTarget, offset, data); } @@ -370,7 +370,7 @@ class Buffer { * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*). * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) */ - template inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) { + template inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) { setSubData(target, offset, size*sizeof(T), data); } diff --git a/src/Context.h b/src/Context.h index f603889b1..820b998e5 100644 --- a/src/Context.h +++ b/src/Context.h @@ -76,12 +76,12 @@ class MAGNUM_EXPORT Extension { private: /* GCC 4.6 doesn't like const members, as std::vector doesn't have proper move semantic yet */ - size_t _index; + std::size_t _index; Version _requiredVersion; Version _coreVersion; const char* _string; - inline constexpr Extension(size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} + inline constexpr Extension(std::size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} }; /** diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index d5c3a15aa..fe188f2b3 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -24,7 +24,7 @@ namespace Magnum { namespace Math { - template class Vector; + template class Vector; template class Vector2; template class Vector3; diff --git a/src/Extensions.h b/src/Extensions.h index 44385b8be..8fd0cadf5 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -38,7 +38,7 @@ namespace Extensions { #ifndef DOXYGEN_GENERATING_OUTPUT #define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ struct extension { \ - enum: size_t { Index = __LINE__-1 }; \ + enum: std::size_t { Index = __LINE__-1 }; \ constexpr static Version requiredVersion() { return Version::_requiredVersion; } \ constexpr static Version coreVersion() { return Version::_coreVersion; } \ constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \ diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index a3e9fafb4..2778fa5c2 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -48,7 +48,7 @@ class GaussJordan { * and the final backsubstitution is done only on @p t, as @p a would * always end with identity matrix anyway. */ - template static bool inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t); + template static bool inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t); /** * @brief Eliminate in place @@ -56,7 +56,7 @@ class GaussJordan { * Transposes the matrices, calls inPlaceTransposed() on them and then * transposes them back. */ - template static bool inPlace(RectangularMatrix& a, RectangularMatrix& t) { + template static bool inPlace(RectangularMatrix& a, RectangularMatrix& t) { a = a.transposed(); RectangularMatrix tTransposed = t.transposed(); @@ -69,11 +69,11 @@ class GaussJordan { } }; -template bool GaussJordan::inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t) { - for(size_t row = 0; row != size; ++row) { +template bool GaussJordan::inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t) { + for(std::size_t row = 0; row != size; ++row) { /* Find max pivot */ - size_t rowMax = row; - for(size_t row2 = row+1; row2 != size; ++row2) + std::size_t rowMax = row; + for(std::size_t row2 = row+1; row2 != size; ++row2) if(std::abs(a(row2, row)) > std::abs(a(rowMax, row))) rowMax = row2; @@ -86,7 +86,7 @@ template bool GaussJordan::inPlaceTransposed( return false; /* Eliminate column */ - for(size_t row2 = row+1; row2 != size; ++row2) { + for(std::size_t row2 = row+1; row2 != size; ++row2) { T c = a(row2, row)/a(row, row); a[row2] -= a[row]*c; @@ -95,10 +95,10 @@ template bool GaussJordan::inPlaceTransposed( } /* Backsubstitute */ - for(size_t row = size; row != 0; --row) { + for(std::size_t row = size; row != 0; --row) { T c = T(1)/a(row-1, row-1); - for(size_t row2 = 0; row2 != row-1; ++row2) + for(std::size_t row2 = 0; row2 != row-1; ++row2) t[row2] -= t[row-1]*a(row2, row-1)*c; /* Normalize the row */ diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index efe47f3a6..adf408955 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -112,7 +112,7 @@ template struct MathTypeTraitsFloatingPoint { } }; -template struct MathTypeTraitsLong {}; +template struct MathTypeTraitsLong {}; template<> struct MathTypeTraitsLong { typedef unsigned int UnsignedType; diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 07d21527b..2f882cc2f 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template class MatrixDeterminant; + template class MatrixDeterminant; } #endif @@ -38,9 +38,9 @@ See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} */ -template class Matrix: public RectangularMatrix { +template class Matrix: public RectangularMatrix { public: - const static size_t Size = size; /**< @brief %Matrix size */ + const static std::size_t Size = size; /**< @brief %Matrix size */ /** @brief Pass to constructor to create zero-filled matrix */ enum ZeroType { Zero }; @@ -63,7 +63,7 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix ij(size_t skipCol, size_t skipRow) const { + Matrix ij(std::size_t skipCol, std::size_t skipRow) const { Matrix out(Matrix::Zero); - for(size_t col = 0; col != size-1; ++col) - for(size_t row = 0; row != size-1; ++row) + for(std::size_t col = 0; col != size-1; ++col) + for(std::size_t row = 0; row != size-1; ++row) out(col, row) = (*this)(col + (col >= skipCol), row + (row >= skipRow)); @@ -135,8 +135,8 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix operator*(const Matrix& other) const { return RectangularMatrix::operator*(other); } - template inline RectangularMatrix operator*(const RectangularMatrix& other) const { + template inline RectangularMatrix operator*(const RectangularMatrix& other) const { return RectangularMatrix::operator*(other); } inline Vector operator*(const Vector& other) const { @@ -159,16 +159,16 @@ template class Matrix: public RectangularMatrix inline typename std::enable_if::value, Matrix>::type operator*(U number, const Matrix& matrix) { +template inline typename std::enable_if::value, Matrix>::type operator*(U number, const Matrix& matrix) { return number*RectangularMatrix(matrix); } -template inline typename std::enable_if::value, Matrix>::type operator/(U number, const Matrix& matrix) { +template inline typename std::enable_if::value, Matrix>::type operator/(U number, const Matrix& matrix) { return number/RectangularMatrix(matrix); } #endif /** @debugoperator{Magnum::Math::Matrix} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix& value) { +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix& value) { return debug << static_cast&>(value); } @@ -189,10 +189,10 @@ template inline Corrade::Utility::Debug operator<<(Corrade return *this; \ } \ \ - inline VectorType& operator[](size_t col) { \ + inline VectorType& operator[](std::size_t col) { \ return VectorType::from(Matrix::data()+col*size); \ } \ - inline constexpr const VectorType& operator[](size_t col) const { \ + inline constexpr const VectorType& operator[](std::size_t col) const { \ return VectorType::from(Matrix::data()+col*size); \ } \ \ @@ -203,7 +203,7 @@ template inline Corrade::Utility::Debug operator<<(Corrade Matrix::operator*=(other); \ return *this; \ } \ - template inline RectangularMatrix operator*(const RectangularMatrix& other) const { \ + template inline RectangularMatrix operator*(const RectangularMatrix& other) const { \ return Matrix::operator*(other); \ } \ inline VectorType operator*(const Vector& other) const { \ @@ -223,12 +223,12 @@ template inline Corrade::Utility::Debug operator<<(Corrade namespace Implementation { -template class MatrixDeterminant { +template class MatrixDeterminant { public: T operator()(const Matrix& m) { T out(0); - for(size_t col = 0; col != size; ++col) + for(std::size_t col = 0; col != size; ++col) out += ((col & 1) ? -1 : 1)*m(col, 0)*m.ij(col, 0).determinant(); return out; @@ -256,7 +256,7 @@ template class MatrixDeterminant<1, T> { namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::Matrix} */ - template struct ConfigurationValue>: public ConfigurationValue> {}; + template struct ConfigurationValue>: public ConfigurationValue> {}; }} #endif diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 7c023931f..d0bea5345 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -28,28 +28,28 @@ namespace Magnum { namespace Math { -template class RectangularMatrix; +template class RectangularMatrix; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct Sequence {}; + template struct Sequence {}; /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ - template struct GenerateSequence: + template struct GenerateSequence: GenerateSequence {}; - template struct GenerateSequence<0, sequence...> { + template struct GenerateSequence<0, sequence...> { typedef Sequence Type; }; /* Implementation for RectangularMatrix::from(const RectangularMatrix&) */ - template inline constexpr Math::RectangularMatrix rectangularMatrixFrom(Sequence, const Math::RectangularMatrix& matrix) { + template inline constexpr Math::RectangularMatrix rectangularMatrixFrom(Sequence, const Math::RectangularMatrix& matrix) { return {T(matrix.data()[sequence])...}; } } #endif -template class Vector; +template class Vector; /** @brief Rectangular matrix @@ -60,13 +60,13 @@ template class Vector; See @ref matrix-vector for brief introduction. See also Matrix (square) and Vector. */ -template class RectangularMatrix { +template class RectangularMatrix { static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements"); public: - typedef T Type; /**< @brief Data type */ - const static size_t Cols = cols; /**< @brief %Matrix column count */ - const static size_t Rows = rows; /**< @brief %Matrix row count */ + typedef T Type; /**< @brief Data type */ + const static std::size_t Cols = cols; /**< @brief %Matrix column count */ + const static std::size_t Rows = rows; /**< @brief %Matrix row count */ /** * @brief %Matrix from array @@ -148,11 +148,11 @@ template class RectangularMatrix { * For accessing individual elements prefer to use operator(), as it * is guaranteed to not involve unnecessary conversions. */ - inline Vector& operator[](size_t col) { + inline Vector& operator[](std::size_t col) { return Vector::from(_data+col*rows); } /** @overload */ - inline constexpr const Vector& operator[](size_t col) const { + inline constexpr const Vector& operator[](std::size_t col) const { return Vector::from(_data+col*rows); } @@ -162,17 +162,17 @@ template class RectangularMatrix { * Prefer this instead of using `[][]`. * @see operator[] */ - inline T& operator()(size_t col, size_t row) { + inline T& operator()(std::size_t col, std::size_t row) { return _data[col*rows+row]; } /** @overload */ - inline constexpr const T& operator()(size_t col, size_t row) const { + inline constexpr const T& operator()(std::size_t col, std::size_t row) const { return _data[col*rows+row]; } /** @brief Equality operator */ inline bool operator==(const RectangularMatrix& other) const { - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) if(!MathTypeTraits::equals(_data[i], other._data[i])) return false; return true; @@ -199,7 +199,7 @@ template class RectangularMatrix { * in-place. */ RectangularMatrix& operator+=(const RectangularMatrix& other) { - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) _data[i] += other._data[i]; return *this; @@ -209,7 +209,7 @@ template class RectangularMatrix { RectangularMatrix operator-() const { RectangularMatrix out; - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) out._data[i] = -_data[i]; return out; @@ -231,7 +231,7 @@ template class RectangularMatrix { * in-place. */ RectangularMatrix& operator-=(const RectangularMatrix& other) { - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) _data[i] -= other._data[i]; return *this; @@ -261,7 +261,7 @@ template class RectangularMatrix { #else template RectangularMatrix& operator*=(U number) { #endif - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) _data[i] *= number; return *this; @@ -291,19 +291,19 @@ template class RectangularMatrix { #else template RectangularMatrix& operator/=(U number) { #endif - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) _data[i] /= number; return *this; } /** @brief Multiply matrix */ - template RectangularMatrix operator*(const RectangularMatrix& other) const { + template RectangularMatrix operator*(const RectangularMatrix& other) const { RectangularMatrix out; - for(size_t col = 0; col != size; ++col) - for(size_t row = 0; row != rows; ++row) - for(size_t pos = 0; pos != cols; ++pos) + for(std::size_t col = 0; col != size; ++col) + for(std::size_t row = 0; row != rows; ++row) + for(std::size_t pos = 0; pos != cols; ++pos) out(col, row) += (*this)(pos, row)*other(col, pos); return out; @@ -323,8 +323,8 @@ template class RectangularMatrix { RectangularMatrix transposed() const { RectangularMatrix out; - for(size_t col = 0; col != cols; ++col) - for(size_t row = 0; row != rows; ++row) + for(std::size_t col = 0; col != cols; ++col) + for(std::size_t row = 0; row != rows; ++row) out(row, col) = (*this)(col, row); return out; @@ -336,10 +336,10 @@ template class RectangularMatrix { #endif private: - template inline constexpr static RectangularMatrix from(Implementation::Sequence s, const Vector& first, U... next) { + template inline constexpr static RectangularMatrix from(Implementation::Sequence s, const Vector& first, U... next) { return from(s, next..., first[sequence]...); } - template inline constexpr static RectangularMatrix from(Implementation::Sequence, T first, U... next) { + template inline constexpr static RectangularMatrix from(Implementation::Sequence, T first, U... next) { return RectangularMatrix(first, next...); } }; @@ -350,9 +350,9 @@ template class RectangularMatrix { @see RectangularMatrix::operator*(U) const */ #ifndef DOXYGEN_GENERATING_OUTPUT -template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number, const RectangularMatrix& matrix) { +template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number, const RectangularMatrix& matrix) { #else -template inline RectangularMatrix operator*(U number, const RectangularMatrix& matrix) { +template inline RectangularMatrix operator*(U number, const RectangularMatrix& matrix) { #endif return matrix*number; } @@ -368,25 +368,25 @@ RectangularMatrix<2, 3, float> another = 1.0f/mat; // {1.0f, 0.5f, -0.25f, 0.128 @see RectangularMatrix::operator/() */ #ifndef DOXYGEN_GENERATING_OUTPUT -template typename std::enable_if::value, RectangularMatrix>::type operator/(U number, const RectangularMatrix& matrix) { +template typename std::enable_if::value, RectangularMatrix>::type operator/(U number, const RectangularMatrix& matrix) { #else -template RectangularMatrix operator/(U number, const RectangularMatrix& matrix) { +template RectangularMatrix operator/(U number, const RectangularMatrix& matrix) { #endif RectangularMatrix out; - for(size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols*rows; ++i) out.data()[i] = number/matrix.data()[i]; return out; } /** @debugoperator{Magnum::Math::RectangularMatrix} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::RectangularMatrix& value) { +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::RectangularMatrix& value) { debug << "Matrix("; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); - for(size_t row = 0; row != rows; ++row) { + for(std::size_t row = 0; row != rows; ++row) { if(row != 0) debug << ",\n "; - for(size_t col = 0; col != cols; ++col) { + for(std::size_t col = 0; col != cols; ++col) { if(col != 0) debug << ", "; debug << typename MathTypeTraits::NumericType(value[col][row]); } @@ -455,13 +455,13 @@ template Corrade::Utility::Debug operator<<(C namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::RectangularMatrix} */ -template struct ConfigurationValue> { +template struct ConfigurationValue> { /** @brief Writes elements separated with spaces */ static std::string toString(const Magnum::Math::RectangularMatrix& value, int flags = 0) { std::string output; - for(size_t row = 0; row != rows; ++row) { - for(size_t col = 0; col != cols; ++col) { + for(std::size_t row = 0; row != rows; ++row) { + for(std::size_t col = 0; col != cols; ++col) { if(!output.empty()) output += ' '; output += ConfigurationValue::toString(value(col, row), flags); } @@ -475,8 +475,8 @@ template struct ConfigurationValue result; std::istringstream in(stringValue); - for(size_t row = 0; row != rows; ++row) { - for(size_t col = 0; col != cols; ++col) { + for(std::size_t row = 0; row != rows; ++row) { + for(std::size_t col = 0; col != cols; ++col) { std::string num; in >> num; result(col, row) = ConfigurationValue::fromString(num, flags); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index e0d5ab5e0..ba9651ba0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -31,9 +31,9 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} */ -template class Vector: public RectangularMatrix<1, size, T> { +template class Vector: public RectangularMatrix<1, size, T> { public: - const static size_t Size = size; /**< @brief %Vector size */ + const static std::size_t Size = size; /**< @brief %Vector size */ /** * @brief Dot product @@ -46,7 +46,7 @@ template class Vector: public RectangularMatrix<1, size, T static T dot(const Vector& a, const Vector& b) { T out(0); - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) out += a[i]*b[i]; return out; @@ -90,7 +90,7 @@ template class Vector: public RectangularMatrix<1, size, T #else inline explicit Vector(T value) { #endif - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) (*this)[i] = value; } @@ -98,8 +98,8 @@ template class Vector: public RectangularMatrix<1, size, T inline constexpr Vector(const RectangularMatrix<1, size, T>& other): RectangularMatrix<1, size, T>(other) {} /** @brief Value at given position */ - inline T& operator[](size_t pos) { return RectangularMatrix<1, size, T>::_data[pos]; } - inline constexpr T operator[](size_t pos) const { return RectangularMatrix<1, size, T>::_data[pos]; } /**< @overload */ + inline T& operator[](std::size_t pos) { return RectangularMatrix<1, size, T>::_data[pos]; } + inline constexpr T operator[](std::size_t pos) const { return RectangularMatrix<1, size, T>::_data[pos]; } /**< @overload */ /** * @brief Multiply vector component-wise @@ -117,7 +117,7 @@ template class Vector: public RectangularMatrix<1, size, T * because it does the computation in-place. */ Vector& operator*=(const Vector& other) { - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) (*this)[i] *= other[i]; return *this; @@ -139,7 +139,7 @@ template class Vector: public RectangularMatrix<1, size, T * because it does the computation in-place. */ Vector& operator/=(const Vector& other) { - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) (*this)[i] /= other[i]; return *this; @@ -177,7 +177,7 @@ template class Vector: public RectangularMatrix<1, size, T T sum() const { T out(0); - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) out += (*this)[i]; return out; @@ -187,7 +187,7 @@ template class Vector: public RectangularMatrix<1, size, T T product() const { T out(1); - for(size_t i = 0; i != size; ++i) + for(std::size_t i = 0; i != size; ++i) out *= (*this)[i]; return out; @@ -197,7 +197,7 @@ template class Vector: public RectangularMatrix<1, size, T T min() const { T out((*this)[0]); - for(size_t i = 1; i != size; ++i) + for(std::size_t i = 1; i != size; ++i) out = std::min(out, (*this)[i]); return out; @@ -207,7 +207,7 @@ template class Vector: public RectangularMatrix<1, size, T T max() const { T out((*this)[0]); - for(size_t i = 1; i != size; ++i) + for(std::size_t i = 1; i != size; ++i) out = std::max(out, (*this)[i]); return out; @@ -215,7 +215,7 @@ template class Vector: public RectangularMatrix<1, size, T #ifndef DOXYGEN_GENERATING_OUTPUT /* Reimplementation of functions to return correct type */ - template inline RectangularMatrix operator*(const RectangularMatrix& other) const { + template inline RectangularMatrix operator*(const RectangularMatrix& other) const { return RectangularMatrix<1, size, T>::operator*(other); } MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(1, size, Vector) @@ -231,19 +231,19 @@ template class Vector: public RectangularMatrix<1, size, T }; #ifndef DOXYGEN_GENERATING_OUTPUT -template inline typename std::enable_if::value, Vector>::type operator*(U number, const Vector& vector) { +template inline typename std::enable_if::value, Vector>::type operator*(U number, const Vector& vector) { return number*RectangularMatrix<1, size, T>(vector); } -template inline typename std::enable_if::value, Vector>::type operator/(U number, const Vector& vector) { +template inline typename std::enable_if::value, Vector>::type operator/(U number, const Vector& vector) { return number/RectangularMatrix<1, size, T>(vector); } #endif /** @debugoperator{Magnum::Math::Vector} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector& value) { +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector& value) { debug << "Vector("; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); - for(size_t i = 0; i != size; ++i) { + for(std::size_t i = 0; i != size; ++i) { if(i != 0) debug << ", "; debug << typename MathTypeTraits::NumericType(value[i]); } @@ -269,7 +269,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili return *this; \ } \ \ - template inline Math::RectangularMatrix operator*(const Math::RectangularMatrix& other) const { \ + template inline Math::RectangularMatrix operator*(const Math::RectangularMatrix& other) const { \ return Math::Vector::operator*(other); \ } \ inline Type operator*(const Math::Vector& other) const { \ @@ -303,7 +303,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::Vector} */ -template struct ConfigurationValue>: public ConfigurationValue> {}; +template struct ConfigurationValue>: public ConfigurationValue> {}; }} diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 8c4389062..fdd5c552f 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -31,7 +31,7 @@ namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -template class Clean { +template class Clean { public: inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} @@ -40,32 +40,32 @@ template class Clean { /* Get mesh bounds */ Vertex min, max; - for(size_t i = 0; i != Vertex::Size; ++i) { + for(std::size_t i = 0; i != Vertex::Size; ++i) { min[i] = std::numeric_limits::max(); max[i] = std::numeric_limits::min(); } for(auto it = vertices.cbegin(); it != vertices.cend(); ++it) - for(size_t i = 0; i != vertexSize; ++i) + for(std::size_t i = 0; i != vertexSize; ++i) if((*it)[i] < min[i]) min[i] = (*it)[i]; else if((*it)[i] > max[i]) max[i] = (*it)[i]; - /* Make epsilon so large that size_t can index all vertices inside - mesh bounds. */ + /* Make epsilon so large that std::size_t can index all vertices + inside mesh bounds. */ Vertex size = max-min; - for(size_t i = 0; i != Vertex::Size; ++i) - if(static_cast(size[i]/std::numeric_limits::max()) > epsilon) - epsilon = static_cast(size[i]/std::numeric_limits::max()); + for(std::size_t i = 0; i != Vertex::Size; ++i) + if(static_cast(size[i]/std::numeric_limits::max()) > epsilon) + epsilon = static_cast(size[i]/std::numeric_limits::max()); /* First go with original vertex coordinates, then move them by epsilon/2 in each direction. */ Vertex moved; - for(size_t moving = 0; moving <= vertexSize; ++moving) { + for(std::size_t moving = 0; moving <= vertexSize; ++moving) { /* Under each index is pointer to face which contains given vertex and index of vertex in the face. */ - std::unordered_map, HashedVertex, IndexHash> table; + std::unordered_map, HashedVertex, IndexHash> table; /* Reserve space for all vertices */ table.reserve(vertices.size()); @@ -73,15 +73,15 @@ template class Clean { /* Go through all faces' vertices */ for(auto it = indices.begin(); it != indices.end(); ++it) { /* Index of a vertex in vertexSize-dimensional table */ - size_t index[vertexSize]; - for(size_t ii = 0; ii != vertexSize; ++ii) + std::size_t index[vertexSize]; + for(std::size_t ii = 0; ii != vertexSize; ++ii) index[ii] = (vertices[*it][ii]+moved[ii]-min[ii])/epsilon; /* Try inserting the vertex into table, if it already exists, change vertex pointer of the face to already existing vertex */ HashedVertex v(*it, table.size()); - auto result = table.insert(std::pair, HashedVertex>(Math::Vector::from(index), v)); + auto result = table.insert(std::pair, HashedVertex>(Math::Vector::from(index), v)); *it = result.first->second.newIndex; } @@ -102,8 +102,8 @@ template class Clean { private: class IndexHash { public: - inline size_t operator()(const Math::Vector& data) const { - return *reinterpret_cast(Corrade::Utility::MurmurHash2()(reinterpret_cast(&data), sizeof(data)).byteArray()); + inline std::size_t operator()(const Math::Vector& data) const { + return *reinterpret_cast(Corrade::Utility::MurmurHash2()(reinterpret_cast(&data), sizeof(data)).byteArray()); } }; @@ -137,7 +137,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 25a8cca4e..39110a722 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -35,7 +35,7 @@ class CombineIndexedArrays { public: template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { /* Compute index count */ - size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); + std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); /* Resulting index array */ std::vector result; @@ -56,24 +56,24 @@ class CombineIndexedArrays { } private: - template inline static size_t indexCount(const std::vector& first, const std::vector&... next) { + template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0); return first.size(); } - template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { + template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { /* Copy the data to output */ - for(size_t i = 0; i != output.size(); ++i) + for(std::size_t i = 0; i != output.size(); ++i) output[i][size-sizeof...(next)-1] = first[i]; writeCombinedIndices(output, next...); } - template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { + template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { /* Rewrite output array */ std::vector output; - for(size_t i = 0; i != combinedIndices.size(); ++i) + for(std::size_t i = 0; i != combinedIndices.size(); ++i) output.push_back(first[combinedIndices[i][size-sizeof...(next)-1]]); std::swap(output, first); @@ -81,9 +81,9 @@ class CombineIndexedArrays { } /* Terminator functions for recursive calls */ - inline static size_t indexCount() { return 0; } - template inline static void writeCombinedIndices(std::vector>&) {} - template inline static void writeCombinedArrays(const std::vector>&) {} + inline static std::size_t indexCount() { return 0; } + template inline static void writeCombinedIndices(std::vector>&) {} + template inline static void writeCombinedArrays(const std::vector>&) {} }; } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 445f5378f..213760226 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -22,6 +22,8 @@ #include "IndexedMesh.h" #include "SizeTraits.h" +using namespace std; + namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 1890d3af8..c4ea6c0c0 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -39,13 +39,13 @@ class MESHTOOLS_EXPORT CompressIndices { public: CompressIndices(const std::vector& indices): indices(indices) {} - std::tuple operator()() const; + std::tuple operator()() const; void operator()(IndexedMesh* mesh, Buffer::Usage usage) const; private: struct Compressor { - template static std::tuple run(const std::vector& indices); + template static std::tuple run(const std::vector& indices); }; const std::vector& indices; @@ -66,11 +66,11 @@ wasteful to store them in array of `unsigned int`s, array of `unsigned short`s is sufficient. Size of the buffer can be computed from index count and type, as shown below. Example usage: @code -size_t indexCount; +std::size_t indexCount; Type indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices); -size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); +std::size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); // ... delete[] data; @endcode @@ -78,7 +78,7 @@ delete[] data; See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -inline std::tuple compressIndices(const std::vector& indices) { +inline std::tuple compressIndices(const std::vector& indices) { return Implementation::CompressIndices{indices}(); } diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index f345e0cb2..44451174f 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -36,7 +36,7 @@ class Interleave { public: inline Interleave(): _attributeCount(0), _stride(0), _data(nullptr) {} - template std::tuple operator()(const T&... attributes) { + template std::tuple operator()(const T&... attributes) { /* Compute buffer size and stride */ _attributeCount = attributeCount(attributes...); if(_attributeCount) { @@ -69,13 +69,13 @@ class Interleave { buffer->setData(attribute, usage); } - template inline static size_t attributeCount(const T& first, const U&... next) { + template inline static std::size_t attributeCount(const T& first, const U&... next) { CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0); return first.size(); } - template inline static size_t stride(const T&, const U&... next) { + template inline static std::size_t stride(const T&, const U&... next) { return sizeof(typename T::value_type) + stride(next...); } @@ -83,19 +83,19 @@ class Interleave { template void write(char* startingOffset, const T& first, const U&... next) { /* Copy the data to the buffer */ auto it = first.begin(); - for(size_t i = 0; i != _attributeCount; ++i, ++it) + for(std::size_t i = 0; i != _attributeCount; ++i, ++it) memcpy(startingOffset+i*_stride, reinterpret_cast(&*it), sizeof(typename T::value_type)); write(startingOffset+sizeof(typename T::value_type), next...); } /* Terminator functions for recursive calls */ - inline static size_t attributeCount() { return 0; } - inline static size_t stride() { return 0; } + inline static std::size_t attributeCount() { return 0; } + inline static std::size_t stride() { return 0; } inline void write(char*) {} - size_t _attributeCount; - size_t _stride; + std::size_t _attributeCount; + std::size_t _stride; char* _data; }; @@ -116,11 +116,11 @@ usage: @code std::vector positions; std::vector textureCoordinates; -size_t attributeCount; -size_t stride; +std::size_t attributeCount; +std::size_t stride; char* data; std::tie(attributeCount, stride, data) = MeshTools::interleave(positions, textureCoordinates); -size_t dataSize = attributeCount*stride; +std::size_t dataSize = attributeCount*stride; // ... delete[] data; @endcode @@ -137,7 +137,7 @@ which writes the interleaved array directly into buffer of given mesh. array has zero length. */ /* enable_if to avoid clash with overloaded function below */ -template inline typename std::enable_if::value, std::tuple>::type interleave(const T& attribute, const U&... attributes) { +template inline typename std::enable_if::value, std::tuple>::type interleave(const T& attribute, const U&... attributes) { return Implementation::Interleave()(attribute, attributes...); } diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index ab2c27dc8..690362362 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -34,11 +34,11 @@ template class Subdivide { void operator()(Interpolator interpolator) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); - size_t indexCount = indices.size(); + std::size_t indexCount = indices.size(); indices.reserve(indices.size()*4); /* Subdivide each face to four new */ - for(size_t i = 0; i != indexCount; i += 3) { + for(std::size_t i = 0; i != indexCount; i += 3) { /* Interpolate each side */ unsigned int newVertices[3]; for(int j = 0; j != 3; ++j) @@ -60,7 +60,7 @@ template class Subdivide { addFace(indices[i], newVertices[0], newVertices[2]); addFace(newVertices[0], indices[i+1], newVertices[1]); addFace(newVertices[2], newVertices[1], indices[i+2]); - for(size_t j = 0; j != 3; ++j) + for(std::size_t j = 0; j != 3; ++j) indices[i+j] = newVertices[j]; } } diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h index f24e4730e..1500ad601 100644 --- a/src/MeshTools/Test/CleanTest.h +++ b/src/MeshTools/Test/CleanTest.h @@ -28,13 +28,13 @@ class CleanTest: public Corrade::TestSuite::Tester { private: class Vector1 { public: - static const size_t Size = 1; + static const std::size_t Size = 1; typedef int Type; Vector1(): data(0) {} Vector1(int i): data(i) {} - int operator[](size_t) const { return data; } - int& operator[](size_t) { return data; } + int operator[](std::size_t) const { return data; } + int& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h index bc7569cb5..1ed5cc4f0 100644 --- a/src/MeshTools/Test/SubdivideTest.h +++ b/src/MeshTools/Test/SubdivideTest.h @@ -29,13 +29,13 @@ class SubdivideTest: public Corrade::TestSuite::Tester { private: class Vector1 { public: - static const size_t Size = 1; + static const std::size_t Size = 1; typedef int Type; Vector1(): data(0) {} Vector1(int i): data(i) {} - int operator[](size_t) const { return data; } - int& operator[](size_t) { return data; } + int operator[](std::size_t) const { return data; } + int& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } diff --git a/src/MeshTools/Test/TipsifyTest.h b/src/MeshTools/Test/TipsifyTest.h index 939f6ae5a..12928f852 100644 --- a/src/MeshTools/Test/TipsifyTest.h +++ b/src/MeshTools/Test/TipsifyTest.h @@ -28,7 +28,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester { private: std::vector indices; - size_t vertexCount; + std::size_t vertexCount; }; }}} diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index d43f4e926..39b3ed092 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -33,7 +33,7 @@ class MESHTOOLS_EXPORT Tipsify { public: inline Tipsify(std::vector& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {} - void operator()(size_t cacheSize); + void operator()(std::size_t cacheSize); /** * @brief Build vertex-triangle adjacency @@ -63,7 +63,7 @@ array for beter usage of post-transform vertex cache. Algorithm used: for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007, http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. */ -inline void tipsify(std::vector& indices, unsigned int vertexCount, size_t cacheSize) { +inline void tipsify(std::vector& indices, unsigned int vertexCount, std::size_t cacheSize) { Implementation::Tipsify(indices, vertexCount)(cacheSize); } diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h index 7e09e59ae..9ad5b3ceb 100644 --- a/src/MeshTools/Transform.h +++ b/src/MeshTools/Transform.h @@ -34,7 +34,7 @@ std::vector vertices; MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices); @endcode */ -template inline void transform(const Math::Matrix& matrix, U& vertices) { +template inline void transform(const Math::Matrix& matrix, U& vertices) { for(Math::Vector& vertex: vertices) vertex = matrix*vertex; } diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index c01589d65..3f938ba84 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { -template class Icosphere; +template class Icosphere; /** @brief 3D icosphere primitive with zero subdivisions @@ -48,14 +48,14 @@ template<> class Icosphere<0>: public Trade::MeshData3D { Indexed triangle mesh with normals. */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class Icosphere: public Icosphere<0> { +template class Icosphere: public Icosphere<0> { #else -template class Icosphere { +template class Icosphere { #endif public: /** @brief Constructor */ Icosphere() { - for(size_t i = 0; i != subdivisions; ++i) + for(std::size_t i = 0; i != subdivisions; ++i) MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) { return (a+b).normalized(); }); diff --git a/src/Profiler.h b/src/Profiler.h index b4f7f6306..1d52f14ed 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -115,7 +115,7 @@ class MAGNUM_EXPORT Profiler { * is 60. * @attention This function cannot be called if profiling is enabled. */ - void setMeasureDuration(size_t frames); + void setMeasureDuration(std::size_t frames); /** * @brief Add named section @@ -193,7 +193,7 @@ class MAGNUM_EXPORT Profiler { void save(); bool enabled; - size_t measureDuration, currentFrame, frameCount; + std::size_t measureDuration, currentFrame, frameCount; std::vector sections; std::vector frameData; std::vector totalData; diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 919bc810c..d4b1db993 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -106,7 +106,7 @@ class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { * @brief Constructor * @todo constexpr */ - template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} + template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} }; template class Resource; @@ -114,8 +114,8 @@ template class Resource; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { struct ResourceKeyHash { - inline size_t operator()(ResourceKey key) const { - return *reinterpret_cast(key.byteArray()); + inline std::size_t operator()(ResourceKey key) const { + return *reinterpret_cast(key.byteArray()); } }; @@ -146,18 +146,18 @@ namespace Implementation { T* data; ResourceDataState state; ResourcePolicy policy; - size_t referenceCount; + std::size_t referenceCount; }; inline virtual ~ResourceManagerData() { delete _fallback; } - inline size_t lastChange() const { return _lastChange; } + inline std::size_t lastChange() const { return _lastChange; } - inline size_t count() const { return _data.size(); } + inline std::size_t count() const { return _data.size(); } - size_t referenceCount(ResourceKey key) const { + std::size_t referenceCount(ResourceKey key) const { auto it = _data.find(key); if(it == _data.end()) return 0; return it->second.referenceCount; @@ -243,7 +243,7 @@ namespace Implementation { private: std::unordered_map _data; T* _fallback; - size_t _lastChange; + std::size_t _lastChange; }; } #endif @@ -372,7 +372,7 @@ template class Resource { Implementation::ResourceManagerData* manager; ResourceKey _key; - size_t lastCheck; + std::size_t lastCheck; ResourceState _state; T* data; }; @@ -465,7 +465,7 @@ template class ResourceManager: protected Implementation::Resour inline ~ResourceManager() { _instance = nullptr; } /** @brief Count of resources of given type */ - template inline size_t count() { + template inline std::size_t count() { return this->Implementation::ResourceManagerData::count(); } @@ -490,7 +490,7 @@ template class ResourceManager: protected Implementation::Resour * * @see set() */ - template inline size_t referenceCount(ResourceKey key) const { + template inline std::size_t referenceCount(ResourceKey key) const { return this->Implementation::ResourceManagerData::referenceCount(key); } @@ -552,7 +552,7 @@ template class ResourceManager: protected Implementation::Resour /** @debugoperator{Magnum::ResourceKey} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { - return debug << static_cast&>(value); + return debug << static_cast&>(value); } template ResourceManager* ResourceManager::_instance(nullptr); diff --git a/src/SizeTraits.h b/src/SizeTraits.h index 62f984d39..4d4b28c09 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -39,7 +39,7 @@ to compute logarithms at compile time, e.g. `SizeTraits::%value>::%SizeType`. */ #ifdef DOXYGEN_GENERATING_OUTPUT -template struct SizeTraits { +template struct SizeTraits { /** * @brief (Unsigned) type able to index the data * @@ -49,7 +49,7 @@ template struct SizeTraits { typedef T SizeType; }; #else -template struct SizeTraits: public SizeTraits {}; +template struct SizeTraits: public SizeTraits {}; #endif #ifndef DOXYGEN_GENERATING_OUTPUT @@ -75,7 +75,7 @@ template<> struct SizeTraits<4> { If you have templated function which you want to call with type suitable for indexing data of some size, you will probably use cascade of IFs, like this: @code -size_t dataSize; +std::size_t dataSize; template Bar foo(Arg1 arg1, Arg2 arg2, ...); Bar bar; @@ -105,7 +105,7 @@ template struct SizeBasedCall: public Base { * @brief Constructor * @param size Data size */ - SizeBasedCall(size_t size): size(size) {} + SizeBasedCall(std::size_t size): size(size) {} /** * @brief Functor @@ -132,7 +132,7 @@ template struct SizeBasedCall: public Base { } private: - size_t size; + std::size_t size; }; /** diff --git a/src/Swizzle.h b/src/Swizzle.h index 308eee93a..49b0870b8 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -28,29 +28,29 @@ namespace Implementation { using Math::Implementation::Sequence; using Math::Implementation::GenerateSequence; - template struct ComponentAtPosition { + template struct ComponentAtPosition { static_assert(size > position, "Swizzle parameter out of range of base vector"); template inline constexpr static T value(const Math::Vector& vector) { return vector[position]; } }; - template struct Component {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component { + template struct Component {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component { template inline constexpr static T value(const Math::Vector&) { return T(0); } }; - template struct Component { + template struct Component { template inline constexpr static T value(const Math::Vector&) { return T(1); } }; - template struct TypeForSize { + template struct TypeForSize { typedef Math::Vector Type; }; template struct TypeForSize<2, T> { typedef Math::Vector2 Type; }; @@ -61,11 +61,11 @@ namespace Implementation { template struct TypeForSize<4, Color3> { typedef Color4 Type; }; template struct TypeForSize<4, Color4> { typedef Color4 Type; }; - template inline constexpr T componentAtPosition(const Math::Vector& vector, size_t position) { + template inline constexpr T componentAtPosition(const Math::Vector& vector, std::size_t position) { return size > position ? vector[position] : throw; } - template inline constexpr T component(const Math::Vector& vector, char component) { + template inline constexpr T component(const Math::Vector& vector, char component) { return component == 'x' ? componentAtPosition(vector, 0) : component == 'y' ? componentAtPosition(vector, 1) : component == 'z' ? componentAtPosition(vector, 2) : @@ -79,7 +79,7 @@ namespace Implementation { throw; } - template inline constexpr Math::Vector swizzleFrom(Sequence, const Math::Vector& vector, const char(&components)[sizeof...(sequence)+1]) { + template inline constexpr Math::Vector swizzleFrom(Sequence, const Math::Vector& vector, const char(&components)[sizeof...(sequence)+1]) { return {component(vector, components[sequence])...}; } } @@ -137,7 +137,7 @@ evaluated at compile time, but at runtime. @see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), Vector4::xy(), Vector3::xy() */ -template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector, const char(&components)[newSize]) { +template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector, const char(&components)[newSize]) { return Implementation::swizzleFrom(typename Implementation::GenerateSequence::Type(), vector, components); } diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index 2f5ba5243..5d3364eb9 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -25,7 +25,7 @@ namespace Test { class Data { public: - static size_t count; + static std::size_t count; inline Data() { ++count; } inline ~Data() { --count; } diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 5b15c9832..2f01b0167 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -25,8 +25,8 @@ namespace Magnum { namespace Math { - template class Vector; - template class Matrix; + template class Vector; + template class Matrix; } template class Color3; @@ -73,14 +73,14 @@ template struct TypeTraits: public Math::MathTypeTraits { * Returns sizeof(GLfloat) for GLfloat, but also sizeof(GLfloat) for * Vector3. See count(). */ - inline constexpr static size_t size(); + inline constexpr static std::size_t size(); /** * @brief Count of plain elements in this type * * Returns 1 for plain OpenGL types like GLint, but e.g. 3 for Vector3. */ - inline constexpr static size_t count(); + inline constexpr static std::size_t count(); }; #else template struct TypeTraits {}; @@ -137,11 +137,11 @@ struct MAGNUM_EXPORT TypeInfo { * These two lines provide the same information, one at compile time, * one at runtime: * @code - * size_t size = TypeTraits::size(); - * size_t size = TypeInfo::sizeOf(Type::UnsignedByte); + * std::size_t size = TypeTraits::size(); + * std::size_t size = TypeInfo::sizeOf(Type::UnsignedByte); * @endcode */ - static size_t sizeOf(Type type); + static std::size_t sizeOf(Type type); /** * @brief Whether the type is integral @@ -169,56 +169,56 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } - inline constexpr static size_t size() { return sizeof(GLbyte); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLbyte); } + inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; } - inline constexpr static size_t size() { return sizeof(GLushort); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLushort); } + inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } - inline constexpr static size_t size() { return sizeof(GLshort); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLshort); } + inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } - inline constexpr static size_t size() { return sizeof(GLuint); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLuint); } + inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } - inline constexpr static size_t size() { return sizeof(GLint); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLint); } + inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; } - inline constexpr static size_t size() { return sizeof(GLfloat); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLfloat); } + inline constexpr static std::size_t count() { return 1; } }; #ifndef MAGNUM_TARGET_GLES @@ -226,17 +226,17 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Double; } /* Can not be used for indices */ /* Can not be used for images */ - inline constexpr static size_t size() { return sizeof(GLdouble); } - inline constexpr static size_t count() { return 1; } + inline constexpr static std::size_t size() { return sizeof(GLdouble); } + inline constexpr static std::size_t count() { return 1; } }; #endif -template struct TypeTraits> { +template struct TypeTraits> { inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ /* Can not be used for images */ - inline constexpr static size_t size() { return sizeof(T); } - inline constexpr static size_t count() { return vectorSize; } + inline constexpr static std::size_t size() { return sizeof(T); } + inline constexpr static std::size_t count() { return vectorSize; } }; template struct TypeTraits>: public TypeTraits> {}; @@ -247,12 +247,12 @@ template struct TypeTraits>: public TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits> { +template struct TypeTraits> { inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ /* Can not be used for images */ - inline constexpr static size_t size() { return sizeof(T); } - inline constexpr static size_t count() { return matrixSize*matrixSize; } + inline constexpr static std::size_t size() { return sizeof(T); } + inline constexpr static std::size_t count() { return matrixSize*matrixSize; } }; template struct TypeTraits>: public TypeTraits> {}; From 1077370937f159007cf997ff64ddb0e6c13e9bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:27:09 +0200 Subject: [PATCH 147/256] Using fixed-size 8bit integer for dimension count. There can be only one, two or three dimensions, so why to use eight times larger type than needed? --- src/AbstractTexture.h | 4 +++- src/BufferedImage.cpp | 2 +- src/BufferedImage.h | 4 ++-- src/Framebuffer.h | 4 ++-- src/Image.cpp | 2 +- src/Image.h | 4 ++-- src/ImageWrapper.h | 4 ++-- src/Physics/AbstractShape.cpp | 2 +- src/Physics/AbstractShape.h | 6 +++--- src/Physics/AxisAlignedBox.cpp | 2 +- src/Physics/AxisAlignedBox.h | 2 +- src/Physics/Box.cpp | 2 +- src/Physics/Box.h | 2 +- src/Physics/Capsule.cpp | 8 ++++---- src/Physics/Capsule.h | 10 +++++----- src/Physics/Line.cpp | 2 +- src/Physics/Line.h | 2 +- src/Physics/LineSegment.h | 2 +- src/Physics/Plane.h | 4 ++-- src/Physics/Point.cpp | 2 +- src/Physics/Point.h | 2 +- src/Physics/ShapeGroup.cpp | 10 +++++----- src/Physics/ShapeGroup.h | 6 +++--- src/Physics/ShapedObject.cpp | 8 ++++---- src/Physics/ShapedObject.h | 6 +++--- src/Physics/ShapedObjectGroup.cpp | 2 +- src/Physics/ShapedObjectGroup.h | 5 +++-- src/Physics/Sphere.cpp | 14 +++++++------- src/Physics/Sphere.h | 14 +++++++------- src/SceneGraph/Camera.cpp | 12 ++++++------ src/SceneGraph/Camera.h | 8 ++++---- src/SceneGraph/Object.cpp | 12 ++++++------ src/SceneGraph/Object.h | 14 +++++++------- src/SceneGraph/Scene.h | 2 +- src/Texture.h | 4 ++-- src/Trade/ImageData.h | 4 ++-- 36 files changed, 98 insertions(+), 95 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index a4c10e9a4..549588ea3 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -19,6 +19,8 @@ * @brief Class Magnum::AbstractTexture */ +#include + #include "Magnum.h" #include "Color.h" @@ -660,7 +662,7 @@ class MAGNUM_EXPORT AbstractTexture { protected: #ifndef DOXYGEN_GENERATING_OUTPUT - template struct DataHelper {}; + template struct DataHelper {}; #endif const GLenum _target; /**< @brief Target */ diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index 43c43227b..7a8b80936 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { +template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; _type = type; _size = size; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 99062b105..4ec955e47 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -36,9 +36,9 @@ Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ -template class BufferedImage: public AbstractImage { +template class BufferedImage: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 1c69674d9..873562572 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -29,8 +29,8 @@ namespace Magnum { -template class BufferedImage; -template class Image; +template class BufferedImage; +template class Image; typedef BufferedImage<1> BufferedImage1D; typedef BufferedImage<2> BufferedImage2D; diff --git a/src/Image.cpp b/src/Image.cpp index a5fa6c4d1..637001733 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { delete[] _data; _components = components; _type = type; diff --git a/src/Image.h b/src/Image.h index 83a1187a2..ec7ad719b 100644 --- a/src/Image.h +++ b/src/Image.h @@ -34,9 +34,9 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for example with Trade::ImageData. @see Image1D, Image2D, Image3D */ -template class Image: public AbstractImage { +template class Image: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 6699d680e..8b45d9c43 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -40,9 +40,9 @@ to change image properties, only data pointer. See also Image, BufferedImage and Trade::ImageData. */ -template class ImageWrapper: public AbstractImage { +template class ImageWrapper: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index cb920047e..23a15ec0d 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -17,7 +17,7 @@ namespace Magnum { namespace Physics { -template bool AbstractShape::collides(const AbstractShape* other) const { +template bool AbstractShape::collides(const AbstractShape* other) const { /* Operate only with simpler types than this */ if(static_cast(other->type()) > static_cast(type())) return other->collides(this); diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 62b60acfc..479482ad4 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ShapeDimensionTraits {}; + template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { enum class Type { @@ -65,10 +65,10 @@ namespace Implementation { See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ -template class PHYSICS_EXPORT AbstractShape { +template class PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ - static const size_t Dimensions = dimensions; + static const std::uint8_t Dimensions = dimensions; /** * @brief Shape type diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 64b832394..63b288fcc 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index f6b9e87c7..2f67eb456 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Physics { @see AxisAlignedBox2D, AxisAlignedBox3D */ -template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 8b63ad5dd..2b0eb5725 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedTransformation = (transformation*_transformation); } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index f52b265d1..25eed9345 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Physics { @see Box2D, Box3D */ -template class PHYSICS_EXPORT Box: public AbstractShape { +template class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index f05b19858..0c9c1b288 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,14 +27,14 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } -template bool Capsule::collides(const AbstractShape* other) const { +template bool Capsule::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Sphere) @@ -43,12 +43,12 @@ template bool Capsule::collides(const AbstractSha return AbstractShape::collides(other); } -template bool Capsule::operator%(const Point& other) const { +template bool Capsule::operator%(const Point& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Capsule::operator%(const Sphere& other) const { +template bool Capsule::operator%(const Sphere& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 93b950527..9ee660ef0 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -24,8 +24,8 @@ namespace Magnum { namespace Physics { -template class Point; -template class Sphere; +template class Point; +template class Sphere; /** @brief %Capsule defined by cylinder start and end point and radius @@ -34,7 +34,7 @@ Unlike other elements the capsule doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D */ -template class PHYSICS_EXPORT Capsule: public AbstractShape { +template class PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} @@ -113,10 +113,10 @@ typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; /** @collisionoperator{Point,Capsule} */ -template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } /** @collisionoperator{Sphere,Capsule} */ -template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } }} diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index bfe5362ed..c067306c0 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); } diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 90332cf9a..880bc2ea6 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Physics { @see Line2D, Line3D @todo collision detection of two Line2D */ -template class PHYSICS_EXPORT Line: public AbstractShape { +template class PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 407fdc382..2a5f1739c 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { @see LineSegment2D, LineSegment3D */ -template class LineSegment: public Line { +template class LineSegment: public Line { public: /** @brief Constructor */ inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 8c547dc8e..6afea764b 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Physics { -template class Line; +template class Line; typedef Line<3> Line3D; -template class LineSegment; +template class LineSegment; typedef LineSegment<3> LineSegment3D; /** @brief Infinite plane, defined by position and normal (3D only) */ diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index f2a15267f..6ca6df6f4 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); } diff --git a/src/Physics/Point.h b/src/Physics/Point.h index f390c4f02..60557b6b8 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Physics { @see Point2D, Point3D */ -template class PHYSICS_EXPORT Point: public AbstractShape { +template class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index be94a88f2..83a5f7178 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -17,18 +17,18 @@ namespace Magnum { namespace Physics { -template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { +template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; } -template ShapeGroup::~ShapeGroup() { +template ShapeGroup::~ShapeGroup() { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; } -template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { +template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; @@ -43,12 +43,12 @@ template ShapeGroup& ShapeGroup::oper return *this; } -template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { if(a) a->applyTransformation(transformation); if(b) b->applyTransformation(transformation); } -template bool ShapeGroup::collides(const AbstractShape* other) const { +template bool ShapeGroup::collides(const AbstractShape* other) const { switch(operation & ~Implementation::GroupOperation::RefAB) { case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 83d19b920..1f5900148 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -55,7 +55,7 @@ Result of logical operations on shapes. See @ref collision-detection for brief introduction. @see ShapeGroup2D, ShapeGroup3D */ -template class PHYSICS_EXPORT ShapeGroup: public AbstractShape { +template class PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT // template friend constexpr operator~(const T& a) -> enableIfIsBaseType; // template friend constexpr operator~(T&& a) -> enableIfIsBaseType; @@ -173,7 +173,7 @@ is used here, so this operation can be used for providing simplified shape version, because collision with @p b is computed only if @p a collides. See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); /** @relates ShapeGroup @brief Logical OR of two shapes @@ -182,7 +182,7 @@ template inline constexpr ShapeGroup inline constexpr ShapeGroup operator||(T a, U b); +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ template inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp index dd34a52a9..aee0750a2 100644 --- a/src/Physics/ShapedObject.cpp +++ b/src/Physics/ShapedObject.cpp @@ -27,22 +27,22 @@ using namespace std; namespace Magnum { namespace Physics { -template ShapedObject::ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), group(group), _shape(nullptr) { +template ShapedObject::ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), group(group), _shape(nullptr) { group->objects.push_back(this); } -template ShapedObject::~ShapedObject() { +template ShapedObject::~ShapedObject() { group->objects.erase(find(group->objects.begin(), group->objects.end(), this)); delete _shape; } -template void ShapedObject::setDirty() { +template void ShapedObject::setDirty() { SceneGraph::AbstractObject::ObjectType::setDirty(); group->setDirty(); } -template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { +template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { SceneGraph::AbstractObject::ObjectType::clean(absoluteTransformation); if(_shape) _shape->applyTransformation(absoluteTransformation); diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index 2c04c962a..fceee5c3b 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -25,15 +25,15 @@ namespace Magnum { namespace Physics { -template class ShapedObjectGroup; -template class AbstractShape; +template class ShapedObjectGroup; +template class AbstractShape; /** @brief Object with assigned shape @see ShapedObject2D, ShapedObject3D */ -template class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject::ObjectType { +template class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject::ObjectType { public: /** * @brief Constructor diff --git a/src/Physics/ShapedObjectGroup.cpp b/src/Physics/ShapedObjectGroup.cpp index 89a901449..ae02018f5 100644 --- a/src/Physics/ShapedObjectGroup.cpp +++ b/src/Physics/ShapedObjectGroup.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template void ShapedObjectGroup::setClean() { +template void ShapedObjectGroup::setClean() { for(ShapedObject* object: objects) if(object->isDirty()) object->setClean(); diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index 74d38c816..874cb53e5 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -20,6 +20,7 @@ */ #include +#include #include #include "magnumPhysicsVisibility.h" @@ -31,7 +32,7 @@ template class Resource; namespace Physics { -template class ShapedObject; +template class ShapedObject; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { @@ -51,7 +52,7 @@ specifying it in the constructor. When the group is deleted, all objects belogning to it are deleted too. @see ShapedObjectGroup2D, ShapedObjectGroup3D */ -template class PHYSICS_EXPORT ShapedObjectGroup { +template class PHYSICS_EXPORT ShapedObjectGroup { friend class ShapedObject; public: diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index af9a668a2..b0f578871 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -28,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Math::Constants::sqrt2()); @@ -39,13 +39,13 @@ namespace { } } -template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); float scaling = (transformation.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } -template bool Sphere::collides(const AbstractShape* other) const { +template bool Sphere::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Line) @@ -58,22 +58,22 @@ template bool Sphere::collides(const AbstractShap return AbstractShape::collides(other); } -template bool Sphere::operator%(const Point& other) const { +template bool Sphere::operator%(const Point& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Line& other) const { +template bool Sphere::operator%(const Line& other) const { return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const LineSegment& other) const { +template bool Sphere::operator%(const LineSegment& other) const { return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Sphere& other) const { +template bool Sphere::operator%(const Sphere& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index dda4e5161..9c92db521 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Physics { -template class Line; -template class LineSegment; -template class Point; +template class Line; +template class LineSegment; +template class Point; /** @brief %Sphere defined by position and radius @@ -35,7 +35,7 @@ Unlike other elements the sphere doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D */ -template class PHYSICS_EXPORT Sphere: public AbstractShape { +template class PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} @@ -105,13 +105,13 @@ typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; /** @collisionoperator{Point,Sphere} */ -template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } /** @collisionoperator{Line,Sphere} */ -template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } /** @collisionoperator{LineSegment,Sphere} */ -template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } +template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } }} diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 81c39d354..d51a9ff7b 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -45,26 +45,26 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons } #endif -template AbstractCamera::AbstractCamera(typename AbstractObject::ObjectType* parent): AbstractObject::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} +template AbstractCamera::AbstractCamera(typename AbstractObject::ObjectType* parent): AbstractObject::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template typename AbstractObject::CameraType* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template typename AbstractObject::CameraType* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); return static_cast::CameraType*>(this); } -template void AbstractCamera::setViewport(const Math::Vector2& size) { +template void AbstractCamera::setViewport(const Math::Vector2& size) { _viewport = size; fixAspectRatio(); } -template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { +template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { AbstractObject::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); } -template void AbstractCamera::draw() { +template void AbstractCamera::draw() { typename AbstractObject::SceneType* s = this->scene(); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); @@ -72,7 +72,7 @@ template void AbstractCamera::draw() { drawChildren(s, cameraMatrix()); } -template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { +template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { for(typename AbstractObject::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ typename DimensionTraits::MatrixType matrix = transformationMatrix*i->transformation(); diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 3e473c4a7..6f8c68bbb 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -36,8 +36,6 @@ namespace Implementation { NotPreserved, Extend, Clip }; - template class Camera {}; - template MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Vector2& projectionScale, const Math::Vector2& viewport); /* These templates are instantiated in source file */ @@ -49,7 +47,7 @@ namespace Implementation { /** @brief %Camera object */ -template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject::ObjectType { +template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject::ObjectType { public: /** * @brief Aspect ratio policy @@ -160,7 +158,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr Math::Vector2 _viewport; }; -template inline AbstractCamera::~AbstractCamera() {} +template inline AbstractCamera::~AbstractCamera() {} #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ @@ -168,6 +166,8 @@ extern template class SCENEGRAPH_EXPORT AbstractCamera<2>; extern template class SCENEGRAPH_EXPORT AbstractCamera<3>; namespace Implementation { + template class Camera {}; + template<> class Camera<2> { public: inline constexpr static Matrix3 aspectRatioScale(const Vector2& scale) { diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index b723a55a5..3cf9b2316 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -25,7 +25,7 @@ using namespace Magnum::Math; namespace Magnum { namespace SceneGraph { -template typename AbstractObject::ObjectType* AbstractObject::setParent(ObjectType* parent) { +template typename AbstractObject::ObjectType* AbstractObject::setParent(ObjectType* parent) { /* Skip if nothing to do or this is scene */ if(this->parent() == parent || isScene()) return static_cast(this); @@ -49,7 +49,7 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { +template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ if(camera == this) return typename DimensionTraits::MatrixType(); @@ -77,7 +77,7 @@ template typename DimensionTraits::Matri return t; } -template typename AbstractObject::SceneType* AbstractObject::scene() { +template typename AbstractObject::SceneType* AbstractObject::scene() { /* Goes up the family tree until it finds object which is parent of itself (that's the scene) */ ObjectType* p = parent(); @@ -89,7 +89,7 @@ template typename AbstractObject::SceneType* Abst return nullptr; } -template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { +template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -99,7 +99,7 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template void AbstractObject::setDirty() { +template void AbstractObject::setDirty() { /* The object (and all its children) are already dirty, nothing to do */ if(dirty) return; @@ -110,7 +110,7 @@ template void AbstractObject::setDirty() { i->setDirty(); } -template void AbstractObject::setClean() { +template void AbstractObject::setClean() { /* The object (and all its parents) are already clean, nothing to do */ if(!dirty) return; diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 3b2e5dca0..cd1d929fe 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -34,13 +34,13 @@ class Camera2D; class Camera3D; class Object2D; class Object3D; -template class Scene; +template class Scene; typedef Scene<2> Scene2D; typedef Scene<3> Scene3D; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ObjectDimensionTraits {}; + template struct ObjectDimensionTraits {}; template<> struct ObjectDimensionTraits<2> { typedef Object2D ObjectType; @@ -72,7 +72,7 @@ namespace Implementation { @todo Transform transformation when changing parent, so the object stays in place. */ -template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { +template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { #ifndef DOXYGEN_GENERATING_OUTPUT AbstractObject(const AbstractObject& other) = delete; AbstractObject(AbstractObject&& other) = delete; @@ -81,7 +81,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra #endif public: - static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ + static const std::uint8_t Dimensions = dimensions; /**< @brief %Object dimension count */ /** @brief %Object type for given dimension count */ typedef typename Implementation::ObjectDimensionTraits::ObjectType ObjectType; @@ -306,11 +306,11 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra bool dirty; }; -template inline AbstractObject::~AbstractObject() {} +template inline AbstractObject::~AbstractObject() {} /* Implementations for inline functions with unused parameters */ -template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} -template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } +template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} +template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 90d0e2ca7..42417426c 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -28,7 +28,7 @@ namespace Magnum { namespace SceneGraph { @see Scene2D, Scene3D */ -template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { +template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { public: /** @copydoc AbstractObject::isScene() */ inline bool isScene() const { return true; } diff --git a/src/Texture.h b/src/Texture.h index 49bcf536c..ba57c8d23 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -50,9 +50,9 @@ for more information. @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @todo @extension{AMD,sparse_texture} */ -template class Texture: public AbstractTexture { +template class Texture: public AbstractTexture { public: - static const size_t Dimensions = dimensions; /**< @brief %Texture dimension count */ + static const std::uint8_t Dimensions = dimensions; /**< @brief %Texture dimension count */ #ifdef DOXYGEN_GENERATING_OUTPUT /** diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index bde311640..a0383d806 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -32,9 +32,9 @@ namespace Magnum { namespace Trade { Provides access to image data and additional information about data type and dimensions. Can be used in the same situations as Image and BufferedImage. */ -template class ImageData: public AbstractImage { +template class ImageData: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor From 246f08c4f105ae498bdc79c0b311e274ab55c710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 19:52:26 +0200 Subject: [PATCH 148/256] Using fixed-size 8bit integer for color attachment IDs. --- src/Framebuffer.cpp | 2 +- src/Framebuffer.h | 14 +++++++------- src/Physics/ShapedObjectGroup.h | 1 - src/Trade/AbstractImporter.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index e0cfa6303..7a07ce3f2 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -31,7 +31,7 @@ void Framebuffer::mapDefaultForDraw(std::initializer_list delete[] _attachments; } -void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { +void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { GLenum* attachments = new GLenum[colorAttachments.size()]; for(auto it = colorAttachments.begin(); it != colorAttachments.end(); ++it) attachments[it-colorAttachments.begin()] = *it + GL_COLOR_ATTACHMENT0; diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 873562572..d9c43fe90 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -819,7 +819,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - void mapForDraw(std::initializer_list colorAttachments); + void mapForDraw(std::initializer_list colorAttachments); /** * @brief Map given attachment of default framebuffer for reading @@ -846,7 +846,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void mapForRead(unsigned int colorAttachment) { + inline void mapForRead(std::uint8_t colorAttachment) { bind(Target::Read); glReadBuffer(GL_COLOR_ATTACHMENT0 + colorAttachment); } @@ -904,7 +904,7 @@ class MAGNUM_EXPORT Framebuffer { * @see bind(), @fn_gl{FramebufferRenderbuffer} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void attachRenderbuffer(Target target, unsigned int colorAttachment, Renderbuffer* renderbuffer) { + inline void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { /** @todo Check for internal format compatibility */ bind(target); glFramebufferRenderbuffer(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, GL_RENDERBUFFER, renderbuffer->id()); @@ -940,7 +940,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void attachTexture1D(Target target, unsigned int colorAttachment, Texture1D* texture, GLint mipLevel) { + inline void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); @@ -977,7 +977,7 @@ class MAGNUM_EXPORT Framebuffer { * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void attachTexture2D(Target target, unsigned int colorAttachment, Texture2D* texture, GLint mipLevel) { + inline void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); @@ -1012,7 +1012,7 @@ class MAGNUM_EXPORT Framebuffer { * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void attachCubeMapTexture(Target target, unsigned int colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { + inline void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { /** @todo Check for internal format compatibility */ bind(target); glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(coordinate), texture->id(), mipLevel); @@ -1050,7 +1050,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline void attachTexture3D(Target target, unsigned int colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + inline void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index 874cb53e5..978e54e00 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -19,7 +19,6 @@ * @brief Class Magnum::Physics::ShapedObjectGroup */ -#include #include #include diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 43877f14d..259eee9b3 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Trade { class AbstractMaterialData; class CameraData; -template class ImageData; +template class ImageData; class LightData; class MeshData2D; class MeshData3D; From cdc2e5302cbca34d0e90df0022727856ae91b4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 23:15:36 +0200 Subject: [PATCH 149/256] Using fixed-size 32bit integer instead of size_t for log/pow. I want something like "use 32bit on x86, but 64bit on x86_64 and x86_32", but header has nothing like that. --- src/Math/Math.cpp | 6 ++++-- src/Math/Math.h | 6 +++--- src/SizeTraits.h | 18 +++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Math/Math.cpp b/src/Math/Math.cpp index 5c2560a21..56a7636eb 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Math.cpp @@ -15,10 +15,12 @@ #include "Math.h" +using namespace std; + namespace Magnum { namespace Math { -size_t log(size_t base, size_t number) { - size_t log = 0; +uint32_t log(uint32_t base, uint32_t number) { + uint32_t log = 0; while(number /= base) ++log; return log; diff --git a/src/Math/Math.h b/src/Math/Math.h index 47f345327..07ebea111 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -37,7 +37,7 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct Pow { + template struct Pow { template inline constexpr T operator()(T base) const { return base*Pow()(base); } @@ -53,7 +53,7 @@ namespace Implementation { * * Returns integral power of base to the exponent. */ -template inline constexpr T pow(T base) { +template inline constexpr T pow(T base) { return Implementation::Pow()(base); } @@ -62,7 +62,7 @@ template inline constexpr T pow(T base) { * * Returns integral logarithm of given number with given base. */ -size_t MAGNUM_EXPORT log(size_t base, size_t number); +std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); /** @brief Normalize floating-point value diff --git a/src/SizeTraits.h b/src/SizeTraits.h index 4d4b28c09..fe5c3c8d9 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -143,14 +143,14 @@ template struct SizeBasedCall: public Base { Useful mainly for computing template parameter value, e.g. in conjunction with SizeTraits class. */ -template struct Pow { +template struct Pow { /** @brief Value of the power */ - enum { value = base*Pow::value }; + enum: std::uint32_t { value = base*Pow::value }; }; #ifndef DOXYGEN_GENERATING_OUTPUT -template struct Pow { - enum { value = 1 }; +template struct Pow { + enum: std::uint32_t { value = 1 }; }; #endif @@ -162,15 +162,15 @@ template struct Pow { Useful mainly for computing template parameter value, e.g. in conjunction with SizeTraits class. */ -template struct Log { +template struct Log { /** @brief Value of the logarithm */ - enum { value = 1+Log::value }; + enum: std::uint32_t { value = 1+Log::value }; }; #ifndef DOXYGEN_GENERATING_OUTPUT -template struct Log: public Log {}; -template struct Log { - enum { value = 0 }; +template struct Log: public Log {}; +template struct Log { + enum: std::uint32_t { value = 0 }; }; #endif From 8f5940dd56d3d5609aac74dd60df0d1607cd385f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Oct 2012 00:14:58 +0200 Subject: [PATCH 150/256] Using fixed-size 32bit integer type for indices. --- src/MeshTools/Clean.h | 10 ++--- src/MeshTools/CombineIndexedArrays.h | 24 ++++++------ src/MeshTools/CompressIndices.cpp | 2 +- src/MeshTools/CompressIndices.h | 20 +++++----- src/MeshTools/FlipNormals.cpp | 2 +- src/MeshTools/FlipNormals.h | 9 +++-- src/MeshTools/GenerateFlatNormals.cpp | 6 +-- src/MeshTools/GenerateFlatNormals.h | 7 ++-- src/MeshTools/Subdivide.h | 12 +++--- src/MeshTools/Test/CleanTest.cpp | 4 +- .../Test/CombineIndexedArraysTest.cpp | 34 ++++++++--------- src/MeshTools/Test/CompressIndicesTest.cpp | 6 +-- src/MeshTools/Test/FlipNormalsTest.cpp | 8 ++-- .../Test/GenerateFlatNormalsTest.cpp | 6 +-- src/MeshTools/Test/SubdivideTest.cpp | 6 +-- src/MeshTools/Test/TipsifyTest.cpp | 2 +- src/MeshTools/Test/TipsifyTest.h | 2 +- src/MeshTools/Tipsify.cpp | 38 ++++++++++--------- src/MeshTools/Tipsify.h | 12 +++--- src/Primitives/Capsule.cpp | 12 +++--- src/Primitives/Cube.cpp | 2 +- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Test/CapsuleTest.cpp | 4 +- src/Primitives/Test/CylinderTest.cpp | 4 +- src/Primitives/Test/UVSphereTest.cpp | 4 +- src/Trade/MeshData2D.h | 8 ++-- src/Trade/MeshData3D.h | 8 ++-- 27 files changed, 129 insertions(+), 125 deletions(-) diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index fdd5c552f..26583743c 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -33,7 +33,7 @@ namespace Implementation { template class Clean { public: - inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(typename Vertex::Type epsilon = TypeTraits::epsilon()) { if(indices.empty()) return; @@ -108,12 +108,12 @@ template class Clean { }; struct HashedVertex { - unsigned int oldIndex, newIndex; + std::uint32_t oldIndex, newIndex; - HashedVertex(unsigned int oldIndex, unsigned int newIndex): oldIndex(oldIndex), newIndex(newIndex) {} + HashedVertex(std::uint32_t oldIndex, std::uint32_t newIndex): oldIndex(oldIndex), newIndex(newIndex) {} }; - std::vector& indices; + std::vector& indices; std::vector& vertices; }; @@ -137,7 +137,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 39110a722..a5d229614 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -33,17 +33,17 @@ namespace Implementation { class CombineIndexedArrays { public: - template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { + template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { /* Compute index count */ std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); /* Resulting index array */ - std::vector result; + std::vector result; result.resize(_indexCount); std::iota(result.begin(), result.end(), 0); /* All index combinations */ - std::vector > indexCombinations(_indexCount); + std::vector > indexCombinations(_indexCount); writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...); /* Make the combinations unique */ @@ -56,13 +56,13 @@ class CombineIndexedArrays { } private: - template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { + template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0); return first.size(); } - template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { + template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { /* Copy the data to output */ for(std::size_t i = 0; i != output.size(); ++i) output[i][size-sizeof...(next)-1] = first[i]; @@ -70,7 +70,7 @@ class CombineIndexedArrays { writeCombinedIndices(output, next...); } - template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { + template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { /* Rewrite output array */ std::vector output; for(std::size_t i = 0; i != combinedIndices.size(); ++i) @@ -82,8 +82,8 @@ class CombineIndexedArrays { /* Terminator functions for recursive calls */ inline static std::size_t indexCount() { return 0; } - template inline static void writeCombinedIndices(std::vector>&) {} - template inline static void writeCombinedArrays(const std::vector>&) {} + template inline static void writeCombinedIndices(std::vector>&) {} + template inline static void writeCombinedArrays(const std::vector>&) {} }; } @@ -105,13 +105,13 @@ avoid explicit verbose specification of tuple type, you can write it with help of some STL functions like shown below. Also if one index array is shader by more than one attribute array, just pass the index array more times. Example: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalTextureIndices; +std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; -std::vector indices = MeshTools::combineIndexedArrays( +std::vector indices = MeshTools::combineIndexedArrays( std::make_tuple(std::cref(vertexIndices), std::ref(positions)), std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)), std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates)) @@ -127,7 +127,7 @@ attributes indexed with `indices`. which parameter is index array and which is attribute array, mainly when both are of the same type. */ -template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { +template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { return Implementation::CombineIndexedArrays()(indexedArrays...); } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 213760226..fc028355b 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -46,7 +46,7 @@ void CompressIndices::operator()(IndexedMesh* mesh, Buffer::Usage usage) const { delete[] data; } -template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { +template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { /* Create smallest possible version of index buffer */ char* buffer = new char[indices.size()*sizeof(IndexType)]; for(size_t i = 0; i != indices.size(); ++i) { diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index c4ea6c0c0..d86dc154c 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -37,7 +37,7 @@ namespace Implementation { class MESHTOOLS_EXPORT CompressIndices { public: - CompressIndices(const std::vector& indices): indices(indices) {} + CompressIndices(const std::vector& indices): indices(indices) {} std::tuple operator()() const; @@ -45,10 +45,10 @@ class MESHTOOLS_EXPORT CompressIndices { private: struct Compressor { - template static std::tuple run(const std::vector& indices); + template static std::tuple run(const std::vector& indices); }; - const std::vector& indices; + const std::vector& indices; }; } @@ -62,9 +62,9 @@ class MESHTOOLS_EXPORT CompressIndices { This function takes index array and outputs them compressed to smallest possible size. For example when your indices have maximum number 463, it's -wasteful to store them in array of `unsigned int`s, array of `unsigned short`s -is sufficient. Size of the buffer can be computed from index count and type, -as shown below. Example usage: +wasteful to store them in array of 32bit integers, array of 16bit integers is +sufficient. Size of the buffer can be computed from index count and type, as +shown below. Example usage: @code std::size_t indexCount; Type indexType; @@ -75,10 +75,10 @@ std::size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); delete[] data; @endcode -See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), +See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -inline std::tuple compressIndices(const std::vector& indices) { +inline std::tuple compressIndices(const std::vector& indices) { return Implementation::CompressIndices{indices}(); } @@ -88,14 +88,14 @@ inline std::tuple compressIndices(const std::vector&), but this +The same as compressIndices(const std::vector&), but this function writes the output to mesh's index buffer and updates index count and type in the mesh accordingly, so you don't have to call Mesh::setIndexCount() and Mesh::setIndexType() on your own. @see MeshTools::interleave() */ -inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { +inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { return Implementation::CompressIndices{indices}(mesh, usage); } diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index ddfe16dd0..859f90306 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace MeshTools { -void flipFaceWinding(vector& indices) { +void flipFaceWinding(vector& indices) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); for(size_t i = 0; i != indices.size(); i += 3) diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 673b43a32..c113e908d 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -19,6 +19,7 @@ * @brief Function Magnum::MeshTools::flipNormals() */ +#include #include #include "Magnum.h" @@ -30,15 +31,15 @@ namespace Magnum { namespace MeshTools { /** @brief Flip face winding -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only face winding. */ -void MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); +void MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); /** @brief Flip mesh normals -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only normals, not face winding. */ void MESHTOOLS_EXPORT flipNormals(std::vector& normals); @@ -55,7 +56,7 @@ flipFaceWinding(), which flip normals or face winding only. @attention The function requires the mesh to have triangle faces, thus index count must be divisible by 3. */ -inline void flipNormals(std::vector& indices, std::vector& normals) { +inline void flipNormals(std::vector& indices, std::vector& normals) { flipFaceWinding(indices); flipNormals(normals); } diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 5d4868a3b..b223eefb1 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -22,11 +22,11 @@ using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { - CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { + CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ - vector normalIndices; + vector normalIndices; normalIndices.reserve(indices.size()); vector normals; normals.reserve(indices.size()/3); diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index bdbcca05a..2e23dfa5e 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -19,6 +19,7 @@ * @brief Function Magnum::MeshTools::generateFlatNormals() */ +#include #include #include @@ -37,10 +38,10 @@ namespace Magnum { namespace MeshTools { For each face generates one normal vector, removes duplicates before returning. Example usage: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalIndices; +std::vector normalIndices; std::vector normals; std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions); @endcode @@ -50,7 +51,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index 690362362..8993bb4da 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -29,7 +29,7 @@ namespace Implementation { template class Subdivide { public: - inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(Interpolator interpolator) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); @@ -40,7 +40,7 @@ template class Subdivide { /* Subdivide each face to four new */ for(std::size_t i = 0; i != indexCount; i += 3) { /* Interpolate each side */ - unsigned int newVertices[3]; + std::uint32_t newVertices[3]; for(int j = 0; j != 3; ++j) newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]])); @@ -66,15 +66,15 @@ template class Subdivide { } private: - std::vector& indices; + std::vector& indices; std::vector& vertices; - unsigned int addVertex(const Vertex& v) { + std::uint32_t addVertex(const Vertex& v) { vertices.push_back(v); return vertices.size()-1; } - void addFace(unsigned int first, unsigned int second, unsigned int third) { + void addFace(std::uint32_t first, std::uint32_t second, std::uint32_t third) { indices.push_back(first); indices.push_back(second); indices.push_back(third); @@ -96,7 +96,7 @@ template class Subdivide { Goes through all triangle faces and subdivides them into four new. Cleaning duplicate vertices in the mesh is up to user. */ -template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { +template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { Implementation::Subdivide(indices, vertices)(interpolator); } diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index 55f8b1bfc..a180be5f3 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -29,12 +29,12 @@ CleanTest::CleanTest() { void CleanTest::cleanMesh() { vector positions{1, 2, 1, 4}; - vector indices{0, 1, 2, 1, 2, 3}; + vector indices{0, 1, 2, 1, 2, 3}; MeshTools::clean(indices, positions); /* Verify cleanup */ CORRADE_VERIFY(positions == (vector{1, 2, 4})); - CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); + CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); } }}} diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index 9cbdcc542..57211078b 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -33,29 +33,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() { void CombineIndexedArraysTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector array; - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array), - tuple&, vector&>(vector{3, 4}, array)); + vector array; + vector result = MeshTools::combineIndexedArrays( + tuple&, vector&>(vector{0, 1, 0}, array), + tuple&, vector&>(vector{3, 4}, array)); CORRADE_COMPARE(result.size(), 0); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); } void CombineIndexedArraysTest::combine() { - vector array1{ 0, 1 }; - vector array2{ 0, 1, 2, 3, 4 }; - vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; - - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array1), - tuple&, vector&>(vector{3, 4, 3}, array2), - tuple&, vector&>(vector{6, 7, 6}, array3)); - - CORRADE_COMPARE(result, (vector{0, 1, 0})); - CORRADE_COMPARE(array1, (vector{0, 1})); - CORRADE_COMPARE(array2, (vector{3, 4})); - CORRADE_COMPARE(array3, (vector{6, 7})); + vector array1{ 0, 1 }; + vector array2{ 0, 1, 2, 3, 4 }; + vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; + + vector result = MeshTools::combineIndexedArrays( + tuple&, vector&>(vector{0, 1, 0}, array1), + tuple&, vector&>(vector{3, 4, 3}, array2), + tuple&, vector&>(vector{6, 7, 6}, array3)); + + CORRADE_COMPARE(result, (vector{0, 1, 0})); + CORRADE_COMPARE(array1, (vector{0, 1})); + CORRADE_COMPARE(array2, (vector{3, 4})); + CORRADE_COMPARE(array3, (vector{6, 7})); } }}} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 905918f1c..f50b7ce49 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -37,7 +37,7 @@ void CompressIndicesTest::compressChar() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 2, 3, 0, 4}); + vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); CORRADE_VERIFY(indexType == Type::UnsignedByte); @@ -52,7 +52,7 @@ void CompressIndicesTest::compressShort() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 256, 0, 5}); + vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); CORRADE_VERIFY(indexType == Type::UnsignedShort); @@ -78,7 +78,7 @@ void CompressIndicesTest::compressInt() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{65536, 3, 2}); + vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); CORRADE_VERIFY(indexType == Type::UnsignedInt); diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 59f3a757d..b900f39d5 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -36,19 +36,19 @@ void FlipNormalsTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector indices{0, 1}; + vector indices{0, 1}; MeshTools::flipFaceWinding(indices); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); } void FlipNormalsTest::flipFaceWinding() { - vector indices{0, 1, 2, + vector indices{0, 1, 2, 3, 4, 5}; MeshTools::flipFaceWinding(indices); - CORRADE_COMPARE(indices, (vector{0, 2, 1, - 3, 5, 4})); + CORRADE_COMPARE(indices, (vector{0, 2, 1, + 3, 5, 4})); } void FlipNormalsTest::flipNormals() { diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 1de255976..8cd88d313 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -34,7 +34,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() { void GenerateFlatNormalsTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector indices; + vector indices; vector normals; tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1 @@ -47,7 +47,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::generate() { /* Two vertices connected by one edge, each winded in another direction */ - vector indices; + vector indices; vector normals; tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1, 2, @@ -59,7 +59,7 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (vector{ 0, 0, 0, 1, 1, 1 })); diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 2e7153ef9..965c3ad36 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -36,20 +36,20 @@ void SubdivideTest::wrongIndexCount() { Error::setOutput(&ss); vector positions; - vector indices{0, 1}; + vector indices{0, 1}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); } void SubdivideTest::subdivide() { vector positions{0, 2, 6, 8}; - vector indices{0, 1, 2, 1, 2, 3}; + vector indices{0, 1, 2, 1, 2, 3}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); CORRADE_VERIFY(positions == (vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); - CORRADE_COMPARE(indices, (vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); + CORRADE_COMPARE(indices, (vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); MeshTools::clean(indices, positions); diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index a44a26507..67bcd4212 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -114,7 +114,7 @@ void TipsifyTest::buildAdjacency() { void TipsifyTest::tipsify() { MeshTools::tipsify(indices, vertexCount, 3); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (vector{ 4, 1, 0, 9, 5, 4, 1, 4, 5, diff --git a/src/MeshTools/Test/TipsifyTest.h b/src/MeshTools/Test/TipsifyTest.h index 12928f852..37ca6d4fb 100644 --- a/src/MeshTools/Test/TipsifyTest.h +++ b/src/MeshTools/Test/TipsifyTest.h @@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester { void tipsify(); private: - std::vector indices; + std::vector indices; std::size_t vertexCount; }; diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 5f19c1f92..7b5b6c00b 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -17,42 +17,44 @@ #include +using namespace std; + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Magnum { namespace MeshTools { namespace Implementation { void Tipsify::operator()(size_t cacheSize) { /* Neighboring triangles for each vertex, per-vertex live triangle count */ - std::vector liveTriangleCount, neighborPosition, neighbors; + std::vector liveTriangleCount, neighborPosition, neighbors; buildAdjacency(liveTriangleCount, neighborPosition, neighbors); /* Global time, per-vertex caching timestamps, per-triangle emmited flag */ - unsigned int time = cacheSize+1; - std::vector timestamp(vertexCount); + uint32_t time = cacheSize+1; + std::vector timestamp(vertexCount); std::vector emitted(indices.size()/3); /* Dead-end vertex stack */ - std::stack deadEndStack; + std::stack deadEndStack; /* Output index buffer */ - std::vector outputIndices; + std::vector outputIndices; outputIndices.reserve(indices.size()); /* Starting vertex for fanning, cursor */ - unsigned int fanningVertex = 0; - unsigned int i = 0; + uint32_t fanningVertex = 0; + uint32_t i = 0; while(fanningVertex != 0xFFFFFFFFu) { /* Array with candidates for next fanning vertex (in 1-ring around fanning vertex) */ - std::vector candidates; + std::vector candidates; /* For all neighbors of fanning vertex */ - for(unsigned int ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { + for(uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { /* Continue if already emitted */ if(emitted[t]) continue; emitted[t] = true; /* Write all vertices of the triangle to output buffer */ - for(unsigned int vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { + for(uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { outputIndices.push_back(v); /* Add to dead end stack and candidates array */ @@ -73,15 +75,15 @@ void Tipsify::operator()(size_t cacheSize) { fanningVertex = 0xFFFFFFFFu; /* Go through candidates in 1-ring around fanning vertex */ - int candidatePriority = -1; - for(unsigned int v: candidates) { + int32_t candidatePriority = -1; + for(uint32_t v: candidates) { /* Skip if it doesn't have any live triangles */ if(!liveTriangleCount[v]) continue; /* Get most fresh candidate which will still be in cache even after fanning. Every fanned triangle will generate at most two cache misses, thus 2*liveTriangleCount */ - int priority = 0; + int32_t priority = 0; if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) priority = time-timestamp[v]; if(priority > candidatePriority) { @@ -117,12 +119,12 @@ void Tipsify::operator()(size_t cacheSize) { std::swap(indices, outputIndices); } -void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { +void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { /* How many times is each vertex referenced == count of neighboring triangles for each vertex */ liveTriangleCount.clear(); liveTriangleCount.resize(vertexCount); - for(unsigned int i = 0; i != indices.size(); ++i) + for(size_t i = 0; i != indices.size(); ++i) ++liveTriangleCount[indices[i]]; /* Building offset array from counts. Neighbors for i-th vertex will at @@ -132,8 +134,8 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std:: neighborOffset.clear(); neighborOffset.reserve(vertexCount+1); neighborOffset.push_back(0); - unsigned int sum = 0; - for(unsigned int i = 0; i != vertexCount; ++i) { + uint32_t sum = 0; + for(size_t i = 0; i != vertexCount; ++i) { neighborOffset.push_back(sum); sum += liveTriangleCount[i]; } @@ -142,7 +144,7 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std:: positioning */ neighbors.clear(); neighbors.resize(sum); - for(unsigned int i = 0; i != indices.size(); ++i) + for(size_t i = 0; i != indices.size(); ++i) neighbors[neighborOffset[indices[i]+1]++] = i/3; } diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 39b3ed092..0d0a28ff8 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -19,7 +19,7 @@ * @brief Function Magnum::MeshTools::tipsify() */ -#include +#include #include #include "magnumMeshToolsVisibility.h" @@ -31,7 +31,7 @@ namespace Implementation { class MESHTOOLS_EXPORT Tipsify { public: - inline Tipsify(std::vector& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {} + inline Tipsify(std::vector& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} void operator()(std::size_t cacheSize); @@ -41,11 +41,11 @@ class MESHTOOLS_EXPORT Tipsify { * Computes count and indices of adjacent triangles for each vertex * (used internally). */ - void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; + void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; private: - std::vector& indices; - const unsigned int vertexCount; + std::vector& indices; + const std::uint32_t vertexCount; }; } @@ -63,7 +63,7 @@ array for beter usage of post-transform vertex cache. Algorithm used: for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007, http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. */ -inline void tipsify(std::vector& indices, unsigned int vertexCount, std::size_t cacheSize) { +inline void tipsify(std::vector& indices, std::uint32_t vertexCount, std::size_t cacheSize) { Implementation::Tipsify(indices, vertexCount)(cacheSize); } diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index d339f04f5..fb89c75f1 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); @@ -128,11 +128,11 @@ void Capsule::faceRings(unsigned int count, unsigned int offset) { for(unsigned int i = 0; i != count; ++i) { for(unsigned int j = 0; j != segments; ++j) { - unsigned int bottomLeft = i*vertexSegments+j+offset; - unsigned int bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? + uint32_t bottomLeft = i*vertexSegments+j+offset; + uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); - unsigned int topLeft = bottomLeft+vertexSegments; - unsigned int topRight = bottomRight+vertexSegments; + uint32_t topLeft = bottomLeft+vertexSegments; + uint32_t topRight = bottomRight+vertexSegments; indices()->push_back(bottomLeft); indices()->push_back(bottomRight); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 48b99c491..ed6d47217 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index f2ee23068..379365e18 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 7d95515c3..1f6fb6183 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -90,7 +90,7 @@ void CapsuleTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, @@ -165,7 +165,7 @@ void CapsuleTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index cb94fa6d7..f7f919cae 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -63,7 +63,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 0.0f, -0.5f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 }), Container); @@ -165,7 +165,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index cff3f77b9..1599eeb0d 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -63,7 +63,7 @@ void UVSphereTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 @@ -105,7 +105,7 @@ void UVSphereTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index cc650a213..6a594fd7c 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -51,7 +51,7 @@ class MAGNUM_EXPORT MeshData2D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData2D(); @@ -66,8 +66,8 @@ class MAGNUM_EXPORT MeshData2D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ inline unsigned int positionArrayCount() const { return _positions.size(); } @@ -96,7 +96,7 @@ class MAGNUM_EXPORT MeshData2D { private: std::string _name; Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _textureCoords2D; }; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 159a6ebcf..fcfb08107 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -52,7 +52,7 @@ class MAGNUM_EXPORT MeshData3D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData3D(); @@ -67,8 +67,8 @@ class MAGNUM_EXPORT MeshData3D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ inline unsigned int positionArrayCount() const { return _positions.size(); } @@ -109,7 +109,7 @@ class MAGNUM_EXPORT MeshData3D { private: std::string _name; Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; From 1de2154823d3fe07ce785cdc48e6d5703aac3ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Oct 2012 00:18:30 +0200 Subject: [PATCH 151/256] Using fixed-size integer types for Trade data IDs. --- src/Trade/AbstractImporter.h | 122 +++++++++++++++++------------------ src/Trade/MeshData2D.h | 12 ++-- src/Trade/MeshData3D.h | 18 +++--- src/Trade/MeshObjectData2D.h | 6 +- src/Trade/MeshObjectData3D.h | 6 +- src/Trade/ObjectData2D.h | 12 ++-- src/Trade/ObjectData3D.h | 12 ++-- src/Trade/SceneData.h | 8 +-- 8 files changed, 98 insertions(+), 98 deletions(-) diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 259eee9b3..e8181915a 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -118,10 +118,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @note The function is not const, because the value will probably * be lazy-populated. */ - virtual inline int defaultScene() { return -1; } + virtual inline std::int32_t defaultScene() { return -1; } /** @brief %Scene count */ - virtual inline unsigned int sceneCount() const { return 0; } + virtual inline std::uint32_t sceneCount() const { return 0; } /** * @brief %Scene ID for given name @@ -129,7 +129,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see SceneData::name() */ - virtual int sceneForName(const std::string& name); + virtual std::int32_t sceneForName(const std::string& name); /** * @brief %Scene @@ -137,10 +137,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given scene or nullptr, if no such scene exists. */ - virtual SceneData* scene(unsigned int id); + virtual SceneData* scene(std::uint32_t id); /** @brief %Light count */ - virtual inline unsigned int lightCount() const { return 0; } + virtual inline std::uint32_t lightCount() const { return 0; } /** * @brief %Light ID for given name @@ -148,7 +148,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no light for given name exists, returns -1. * @see LightData::name() */ - virtual int lightForName(const std::string& name); + virtual std::int32_t lightForName(const std::string& name); /** * @brief %Light @@ -156,10 +156,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given light or nullptr, if no such light exists. */ - virtual LightData* light(unsigned int id); + virtual LightData* light(std::uint32_t id); /** @brief %Camera count */ - virtual inline unsigned int cameraCount() const { return 0; } + virtual inline std::uint32_t cameraCount() const { return 0; } /** * @brief %Camera ID for given name @@ -167,7 +167,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no camera for given name exists, returns -1. * @see CameraData::name() */ - virtual int cameraForName(const std::string& name); + virtual std::int32_t cameraForName(const std::string& name); /** * @brief %Camera @@ -176,10 +176,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given camera or nullptr, if no such camera * exists. */ - virtual CameraData* camera(unsigned int id); + virtual CameraData* camera(std::uint32_t id); /** @brief Two-dimensional object count */ - virtual inline unsigned int object2DCount() const { return 0; } + virtual inline std::uint32_t object2DCount() const { return 0; } /** * @brief Two-dimensional object ID for given name @@ -187,7 +187,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see ObjectData2D::name() */ - virtual int object2DForName(const std::string& name); + virtual std::int32_t object2DForName(const std::string& name); /** * @brief Two-dimensional object @@ -196,10 +196,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given object or nullptr, if no such object * exists. */ - virtual ObjectData2D* object2D(unsigned int id); + virtual ObjectData2D* object2D(std::uint32_t id); /** @brief Three-dimensional object count */ - virtual inline unsigned int object3DCount() const { return 0; } + virtual inline std::uint32_t object3DCount() const { return 0; } /** * @brief Three-dimensional object ID for given name @@ -207,7 +207,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see ObjectData3D::name() */ - virtual int object3DForName(const std::string& name); + virtual std::int32_t object3DForName(const std::string& name); /** * @brief Three-dimensional object @@ -216,10 +216,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given object or nullptr, if no such object * exists. */ - virtual ObjectData3D* object3D(unsigned int id); + virtual ObjectData3D* object3D(std::uint32_t id); /** @brief Two-dimensional mesh count */ - virtual inline unsigned int mesh2DCount() const { return 0; } + virtual inline std::uint32_t mesh2DCount() const { return 0; } /** * @brief Two-dimensional mesh ID for given name @@ -227,7 +227,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no mesh for given name exists, returns -1. * @see MeshData2D::name() */ - virtual int mesh2DForName(const std::string& name); + virtual std::int32_t mesh2DForName(const std::string& name); /** * @brief Two-dimensional mesh @@ -235,10 +235,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ - virtual MeshData2D* mesh2D(unsigned int id); + virtual MeshData2D* mesh2D(std::uint32_t id); /** @brief Three-dimensional mesh count */ - virtual inline unsigned int mesh3DCount() const { return 0; } + virtual inline std::uint32_t mesh3DCount() const { return 0; } /** * @brief Three-dimensional mesh ID for given name @@ -246,7 +246,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no mesh for given name exists, returns -1. * @see MeshData3D::name() */ - virtual int mesh3DForName(const std::string& name); + virtual std::int32_t mesh3DForName(const std::string& name); /** * @brief Three-dimensional mesh @@ -254,10 +254,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ - virtual MeshData3D* mesh3D(unsigned int id); + virtual MeshData3D* mesh3D(std::uint32_t id); /** @brief Material count */ - virtual inline unsigned int materialCount() const { return 0; } + virtual inline std::uint32_t materialCount() const { return 0; } /** * @brief Material ID for given name @@ -265,7 +265,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no material for given name exists, returns -1. * @see AbstractMaterialData::name() */ - virtual int materialForName(const std::string& name); + virtual std::int32_t materialForName(const std::string& name); /** * @brief Material @@ -274,10 +274,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given material or nullptr, if no such material * exists. */ - virtual AbstractMaterialData* material(unsigned int id); + virtual AbstractMaterialData* material(std::uint32_t id); /** @brief %Texture count */ - virtual inline unsigned int textureCount() const { return 0; } + virtual inline std::uint32_t textureCount() const { return 0; } /** * @brief %Texture ID for given name @@ -285,7 +285,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no texture for given name exists, returns -1. * @see TextureData::name() */ - virtual int textureForName(const std::string& name); + virtual std::int32_t textureForName(const std::string& name); /** * @brief %Texture @@ -294,10 +294,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given texture or nullptr, if no such texture * exists. */ - virtual TextureData* texture(unsigned int id); + virtual TextureData* texture(std::uint32_t id); /** @brief One-dimensional image count */ - virtual inline unsigned int image1DCount() const { return 0; } + virtual inline std::uint32_t image1DCount() const { return 0; } /** * @brief One-dimensional image ID for given name @@ -305,7 +305,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see ImageData1D::name() */ - virtual int image1DForName(const std::string& name); + virtual std::int32_t image1DForName(const std::string& name); /** * @brief One-dimensional image @@ -313,10 +313,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData1D* image1D(unsigned int id); + virtual ImageData1D* image1D(std::uint32_t id); /** @brief Two-dimensional image count */ - virtual inline unsigned int image2DCount() const { return 0; } + virtual inline std::uint32_t image2DCount() const { return 0; } /** * @brief Two-dimensional image ID for given name @@ -324,7 +324,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see ImageData2D::name() */ - virtual int image2DForName(const std::string& name); + virtual std::int32_t image2DForName(const std::string& name); /** * @brief Two-dimensional image @@ -332,10 +332,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData2D* image2D(unsigned int id); + virtual ImageData2D* image2D(std::uint32_t id); /** @brief Three-dimensional image count */ - virtual inline unsigned int image3DCount() const { return 0; } + virtual inline std::uint32_t image3DCount() const { return 0; } /** * @brief Three-dimensional image ID for given name @@ -343,7 +343,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see ImageData3D::name() */ - virtual int image3DForName(const std::string& name); + virtual std::int32_t image3DForName(const std::string& name); /** * @brief Three-dimensional image @@ -351,7 +351,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData3D* image3D(unsigned int id); + virtual ImageData3D* image3D(std::uint32_t id); /*@}*/ }; @@ -359,30 +359,30 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features) /* Implementations for inline functions with unused parameters */ -inline int AbstractImporter::sceneForName(const std::string&) { return -1; } -inline SceneData* AbstractImporter::scene(unsigned int) { return nullptr; } -inline int AbstractImporter::lightForName(const std::string&) { return -1; } -inline LightData* AbstractImporter::light(unsigned int) { return nullptr; } -inline int AbstractImporter::cameraForName(const std::string&) { return -1; } -inline CameraData* AbstractImporter::camera(unsigned int) { return nullptr; } -inline int AbstractImporter::object2DForName(const std::string&) { return -1; } -inline ObjectData2D* AbstractImporter::object2D(unsigned int) { return nullptr; } -inline int AbstractImporter::object3DForName(const std::string&) { return -1; } -inline ObjectData3D* AbstractImporter::object3D(unsigned int) { return nullptr; } -inline int AbstractImporter::mesh2DForName(const std::string&) { return -1; } -inline MeshData2D* AbstractImporter::mesh2D(unsigned int) { return nullptr; } -inline int AbstractImporter::mesh3DForName(const std::string&) { return -1; } -inline MeshData3D* AbstractImporter::mesh3D(unsigned int) { return nullptr; } -inline int AbstractImporter::materialForName(const std::string&) { return -1; } -inline AbstractMaterialData* AbstractImporter::material(unsigned int) { return nullptr; } -inline int AbstractImporter::textureForName(const std::string&) { return -1; } -inline TextureData* AbstractImporter::texture(unsigned int) { return nullptr; } -inline int AbstractImporter::image1DForName(const std::string&) { return -1; } -inline ImageData1D* AbstractImporter::image1D(unsigned int) { return nullptr; } -inline int AbstractImporter::image2DForName(const std::string&) { return -1; } -inline ImageData2D* AbstractImporter::image2D(unsigned int) { return nullptr; } -inline int AbstractImporter::image3DForName(const std::string&) { return -1; } -inline ImageData3D* AbstractImporter::image3D(unsigned int) { return nullptr; } +inline std::int32_t AbstractImporter::sceneForName(const std::string&) { return -1; } +inline SceneData* AbstractImporter::scene(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::lightForName(const std::string&) { return -1; } +inline LightData* AbstractImporter::light(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::cameraForName(const std::string&) { return -1; } +inline CameraData* AbstractImporter::camera(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::object2DForName(const std::string&) { return -1; } +inline ObjectData2D* AbstractImporter::object2D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::object3DForName(const std::string&) { return -1; } +inline ObjectData3D* AbstractImporter::object3D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::mesh2DForName(const std::string&) { return -1; } +inline MeshData2D* AbstractImporter::mesh2D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::mesh3DForName(const std::string&) { return -1; } +inline MeshData3D* AbstractImporter::mesh3D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::materialForName(const std::string&) { return -1; } +inline AbstractMaterialData* AbstractImporter::material(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::textureForName(const std::string&) { return -1; } +inline TextureData* AbstractImporter::texture(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::image1DForName(const std::string&) { return -1; } +inline ImageData1D* AbstractImporter::image1D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::image2DForName(const std::string&) { return -1; } +inline ImageData2D* AbstractImporter::image2D(std::uint32_t) { return nullptr; } +inline std::int32_t AbstractImporter::image3DForName(const std::string&) { return -1; } +inline ImageData3D* AbstractImporter::image3D(std::uint32_t) { return nullptr; } }} diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 6a594fd7c..4e812f136 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -70,7 +70,7 @@ class MAGNUM_EXPORT MeshData2D { inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ - inline unsigned int positionArrayCount() const { return _positions.size(); } + inline std::uint32_t positionArrayCount() const { return _positions.size(); } /** * @brief Positions @@ -78,11 +78,11 @@ class MAGNUM_EXPORT MeshData2D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(unsigned int id) { return _positions[id]; } - inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(std::uint32_t id) { return _positions[id]; } + inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ /** @brief Count of 2D texture coordinate arrays */ - inline unsigned int textureCoords2DArrayCount() const { return _textureCoords2D.size(); } + inline std::uint32_t textureCoords2DArrayCount() const { return _textureCoords2D.size(); } /** * @brief 2D texture coordinates @@ -90,8 +90,8 @@ class MAGNUM_EXPORT MeshData2D { * @return %Texture coordinates or nullptr if there is no texture * coordinates array with given ID. */ - inline std::vector* textureCoords2D(unsigned int id) { return _textureCoords2D[id]; } - inline const std::vector* textureCoords2D(unsigned int id) const { return _textureCoords2D[id]; } /**< @overload */ + inline std::vector* textureCoords2D(std::uint32_t id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ private: std::string _name; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index fcfb08107..1de247976 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -71,7 +71,7 @@ class MAGNUM_EXPORT MeshData3D { inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ - inline unsigned int positionArrayCount() const { return _positions.size(); } + inline std::uint32_t positionArrayCount() const { return _positions.size(); } /** * @brief Positions @@ -79,11 +79,11 @@ class MAGNUM_EXPORT MeshData3D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(unsigned int id) { return _positions[id]; } - inline const std::vector* positions(unsigned int id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(std::uint32_t id) { return _positions[id]; } + inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ - inline unsigned int normalArrayCount() const { return _normals.size(); } + inline std::uint32_t normalArrayCount() const { return _normals.size(); } /** * @brief Normals @@ -91,11 +91,11 @@ class MAGNUM_EXPORT MeshData3D { * @return Normals or nullptr if there is no normal array with given * ID. */ - inline std::vector* normals(unsigned int id) { return _normals[id]; } - inline const std::vector* normals(unsigned int id) const { return _normals[id]; } /**< @overload */ + inline std::vector* normals(std::uint32_t id) { return _normals[id]; } + inline const std::vector* normals(std::uint32_t id) const { return _normals[id]; } /**< @overload */ /** @brief Count of 2D texture coordinate arrays */ - inline unsigned int textureCoords2DArrayCount() const { return _textureCoords2D.size(); } + inline std::uint32_t textureCoords2DArrayCount() const { return _textureCoords2D.size(); } /** * @brief 2D texture coordinates @@ -103,8 +103,8 @@ class MAGNUM_EXPORT MeshData3D { * @return %Texture coordinates or nullptr if there is no texture * coordinates array with given ID. */ - inline std::vector* textureCoords2D(unsigned int id) { return _textureCoords2D[id]; } - inline const std::vector* textureCoords2D(unsigned int id) const { return _textureCoords2D[id]; } /**< @overload */ + inline std::vector* textureCoords2D(std::uint32_t id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ private: std::string _name; diff --git a/src/Trade/MeshObjectData2D.h b/src/Trade/MeshObjectData2D.h index 8eda1d68f..dff0770b0 100644 --- a/src/Trade/MeshObjectData2D.h +++ b/src/Trade/MeshObjectData2D.h @@ -46,13 +46,13 @@ class MeshObjectData2D: public ObjectData2D { * * Creates object with mesh instance type. */ - inline MeshObjectData2D(const std::string& name, const std::vector& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData2D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData2D(const std::string& name, const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData2D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ - inline unsigned int material() const { return _material; } + inline std::uint32_t material() const { return _material; } private: - unsigned int _material; + std::uint32_t _material; }; }} diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h index c133f2ed7..acec3ed31 100644 --- a/src/Trade/MeshObjectData3D.h +++ b/src/Trade/MeshObjectData3D.h @@ -46,13 +46,13 @@ class MeshObjectData3D: public ObjectData3D { * * Creates object with mesh instance type. */ - inline MeshObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, unsigned int instance, unsigned int material): ObjectData3D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData3D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ - inline unsigned int material() const { return _material; } + inline std::uint32_t material() const { return _material; } private: - unsigned int _material; + std::uint32_t _material; }; }} diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index 2db556f08..8cc1b9226 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -53,7 +53,7 @@ class ObjectData2D { * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation, InstanceType instanceType, std::uint32_t instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance @@ -61,7 +61,7 @@ class ObjectData2D { * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData2D() {} @@ -70,7 +70,7 @@ class ObjectData2D { inline std::string name() const { return _name; } /** @brief Child objects */ - inline std::vector& children() { return _children; } + inline std::vector& children() { return _children; } /** @brief Transformation (relative to parent) */ inline Matrix3 transformation() const { return _transformation; } @@ -89,14 +89,14 @@ class ObjectData2D { * @return ID of given camera / light / mesh etc., specified by * instanceType() */ - inline int instanceId() const { return _instanceId; } + inline std::int32_t instanceId() const { return _instanceId; } private: std::string _name; - std::vector _children; + std::vector _children; Matrix3 _transformation; InstanceType _instanceType; - int _instanceId; + std::int32_t _instanceId; }; }} diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index ec048e194..0f125b672 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -54,7 +54,7 @@ class ObjectData3D { * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, InstanceType instanceType, unsigned int instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, InstanceType instanceType, std::uint32_t instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance @@ -62,7 +62,7 @@ class ObjectData3D { * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData3D() {} @@ -71,7 +71,7 @@ class ObjectData3D { inline std::string name() const { return _name; } /** @brief Child objects */ - inline std::vector& children() { return _children; } + inline std::vector& children() { return _children; } /** @brief Transformation (relative to parent) */ inline Matrix4 transformation() const { return _transformation; } @@ -90,14 +90,14 @@ class ObjectData3D { * @return ID of given camera / light / mesh etc., specified by * instanceType() */ - inline int instanceId() const { return _instanceId; } + inline std::int32_t instanceId() const { return _instanceId; } private: std::string _name; - std::vector _children; + std::vector _children; Matrix4 _transformation; InstanceType _instanceType; - int _instanceId; + std::int32_t _instanceId; }; }} diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index 84a5aa348..226fa327a 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -40,20 +40,20 @@ class MAGNUM_EXPORT SceneData { * @param children2D Two-dimensional child objects * @param children3D Three-dimensional child objects */ - inline SceneData(const std::string& name, const std::vector& children2D, const std::vector& children3D): _name(name), _children2D(children2D), _children3D(children3D) {} + inline SceneData(const std::string& name, const std::vector& children2D, const std::vector& children3D): _name(name), _children2D(children2D), _children3D(children3D) {} /** @brief Scene name */ inline std::string name() const { return _name; } /** @brief Two-dimensional child objects */ - inline const std::vector& children2D() const { return _children2D; } + inline const std::vector& children2D() const { return _children2D; } /** @brief Three-dimensional child objects */ - inline const std::vector& children3D() const { return _children3D; } + inline const std::vector& children3D() const { return _children3D; } private: std::string _name; - std::vector _children2D, + std::vector _children2D, _children3D; }; From c1cf94fb46e3716c5e9131273c0f650cad2b566e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Oct 2012 00:38:49 +0200 Subject: [PATCH 152/256] Using fixed-size integer types also everywhere else. It solves issues with int/long int/long long int ambiguity, which is good. --- src/Color.h | 4 +- src/Math/Math.h | 7 ++-- src/Math/MathTypeTraits.h | 52 +++++++++++------------- src/Math/RectangularMatrix.h | 2 +- src/Math/Test/ConstantsTest.cpp | 2 - src/Math/Test/MathTest.cpp | 54 ++++++++++++------------- src/Math/Test/MathTypeTraitsTest.cpp | 20 ++++----- src/Math/Test/MatrixTest.cpp | 4 +- src/Math/Test/RectangularMatrixTest.cpp | 14 +++---- src/MeshTools/Test/CleanTest.h | 10 ++--- src/MeshTools/Test/InterleaveTest.cpp | 20 ++++----- src/MeshTools/Test/SubdivideTest.h | 10 ++--- src/MeshTools/Test/TipsifyTest.cpp | 8 ++-- src/Primitives/Capsule.cpp | 30 +++++++------- src/Primitives/Capsule.h | 12 +++--- src/Primitives/Cube.cpp | 2 +- src/Primitives/Cylinder.cpp | 4 +- src/Primitives/Cylinder.h | 2 +- src/Primitives/UVSphere.cpp | 2 +- src/Primitives/UVSphere.h | 2 +- src/Profiler.h | 2 +- src/Swizzle.h | 4 +- src/Test/ColorTest.cpp | 4 +- src/Test/ResourceManagerTest.cpp | 14 +++---- src/Test/ResourceManagerTest.h | 2 +- src/Test/SwizzleTest.cpp | 14 +++---- src/Timeline.cpp | 2 +- src/TypeTraits.cpp | 20 +++++---- src/TypeTraits.h | 12 +++--- 29 files changed, 167 insertions(+), 168 deletions(-) diff --git a/src/Color.h b/src/Color.h index 0dcecdb09..c24866b9d 100644 --- a/src/Color.h +++ b/src/Color.h @@ -160,7 +160,7 @@ template class Color3: public Math::Vector3 { * @brief Create integral color from floating-point color * * E.g. `{0.294118, 0.45098, 0.878431}` is converted to - * `{75, 115, 224}`, if resulting type is `unsigned char`. + * `{75, 115, 224}`, if resulting type is `uint8_t`. * * @note This function is enabled only if source type is floating-point * and destination type is integral. @@ -175,7 +175,7 @@ template class Color3: public Math::Vector3 { * @brief Create floating-point color from integral color * * E.g. `{75, 115, 224}` is converted to - * `{0.294118, 0.45098, 0.878431}`, if source type is `unsigned char`. + * `{0.294118, 0.45098, 0.878431}`, if source type is `uint8_t`. * * @note This function is enabled only if source type is integral * and destination type is floating-point. diff --git a/src/Math/Math.h b/src/Math/Math.h index 07ebea111..a11f3c142 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -74,11 +74,11 @@ type to value in range @f$ [0, 1] @f$. literals, this function should be called with both template parameters explicit, e.g.: @code -// Even if this is char literal, integral type is `int`, thus a = 0.1f +// Even if this is character literal, integral type is 32bit, thus a != 1.0f float a = normalize('\127'); // b = 1.0f -float b = normalize('\127'); +float b = normalize('\127'); @endcode @todo Signed normalization to [-1.0, 1.0] like in OpenGL? @@ -95,7 +95,8 @@ Converts floating-point value in range @f$ [0, 1] @f$ to full range of given integral type. @note For best precision, `FloatingPoint` type should be always larger that -resulting `Integral` type (e.g. `double` to `int`, `long double` to `long long`). +resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` to +`std::int64_t`). @todo Signed normalization to [-1.0, 1.0] like in OpenGL? @todo Stable behavior (working/broken) for long double and long long diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index adf408955..4bf013937 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Math::MathTypeTraits */ -#include +#include #include /** @brief Precision when testing floats for equality */ @@ -53,7 +53,7 @@ support given feature, thus forcing the compilation stop with an error. template struct MathTypeTraits { #ifdef DOXYGEN_GENERATING_OUTPUT /** - * @brief Corresponding numeric type large at least as `int` + * @brief Corresponding numeric type large at least as 32bit integer * * Usable e.g. to prevent conversion of `char` to characters when printing * numeric types to output. @@ -114,58 +114,54 @@ template struct MathTypeTraitsFloatingPoint { template struct MathTypeTraitsLong {}; -template<> struct MathTypeTraitsLong { - typedef unsigned int UnsignedType; - typedef int Type; +template<> struct MathTypeTraitsLong<4> { + typedef std::uint32_t UnsignedType; + typedef std::int32_t Type; }; -template<> struct MathTypeTraitsLong { - typedef unsigned long long UnsignedType; - typedef long long Type; +template<> struct MathTypeTraitsLong<8> { + typedef std::uint64_t UnsignedType; + typedef std::int64_t Type; }; } -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned long long NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint64_t NumericType; typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef long long NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int64_t NumericType; typedef long double FloatingPointType; }; -/* long is 32 bits somewhere and 64 bits elsewhere */ -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; - template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { typedef float NumericType; typedef float FloatingPointType; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index d0bea5345..0ca329847 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -101,7 +101,7 @@ template class RectangularMatrix { * anything else. Example usage: * @code * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * RectangularMatrix<4, 1, int> integral(RectangularMatrix<4, 1, int>::from(floatingPoint)); + * RectangularMatrix<4, 1, std::int8_t> integral(RectangularMatrix<4, 1, std::int8_t>::from(floatingPoint)); * // integral == {1, 2, -15, 7} * @endcode */ diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index fb24fd8be..4a780de5c 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -18,8 +18,6 @@ #include "Constants.h" #include "Math.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 027f09c35..3aa7348ed 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -33,46 +33,46 @@ MathTest::MathTest() { void MathTest::normalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE((Math::normalize(-128)), 0.0f); - CORRADE_COMPARE((Math::normalize(127)), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(255)), 1.0f); + CORRADE_COMPARE((Math::normalize(-128)), 0.0f); + CORRADE_COMPARE((Math::normalize(127)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(255)), 1.0f); /* Between */ - CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); - CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); + CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); + CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); /* Test overflow for large types */ - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0f); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); + + CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); + CORRADE_COMPARE((Math::normalize(0)), 0.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); } void MathTest::denormalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE(Math::denormalize(0.0f), -128); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 255); + CORRADE_COMPARE(Math::denormalize(0.0f), -128); + CORRADE_COMPARE(Math::denormalize(1.0f), 127); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 255); /* Between */ - CORRADE_COMPARE(Math::denormalize(0.33f), -11141); - CORRADE_COMPARE(Math::denormalize(0.66f), 10485); + CORRADE_COMPARE(Math::denormalize(0.33f), -11141); + CORRADE_COMPARE(Math::denormalize(0.66f), 10485); /* Test overflow for large types */ - CORRADE_COMPARE(Math::denormalize(0.0f), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(0.0), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0), 0); + CORRADE_COMPARE(Math::denormalize(0.0f), numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(0.0), numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); // { // CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index 523b32017..cae312032 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -21,6 +21,8 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) +using namespace std; + namespace Magnum { namespace Math { namespace Test { MathTypeTraitsTest::MathTypeTraitsTest() { @@ -29,16 +31,14 @@ MathTypeTraitsTest::MathTypeTraitsTest() { } void MathTypeTraitsTest::equalsIntegral() { - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); } void MathTypeTraitsTest::equalsFloatingPoint() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 2d803ec16..6a015b328 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -98,7 +98,7 @@ void MatrixTest::constructZero() { } void MatrixTest::trace() { - Matrix<5, int> m( + Matrix<5, int32_t> m( 1, 2, 3, 0, 0, 2, 3, 2, 1, -2, 1, 1, -20, 1, 0, @@ -127,7 +127,7 @@ void MatrixTest::ij() { } void MatrixTest::determinant() { - Matrix<5, int> m( + Matrix<5, int32_t> m( 1, 2, 2, 1, 0, 2, 3, 2, 1, -2, 1, 1, 1, 1, 0, diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index b575941c7..e43c6e5e2 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { namespace Test { typedef RectangularMatrix<4, 3, float> Matrix4x3; typedef RectangularMatrix<3, 4, float> Matrix3x4; typedef RectangularMatrix<2, 2, float> Matrix2; -typedef RectangularMatrix<2, 2, int> Matrix2i; +typedef RectangularMatrix<2, 2, int32_t> Matrix2i; typedef Vector<4, float> Vector4; RectangularMatrixTest::RectangularMatrixTest() { @@ -154,8 +154,8 @@ void RectangularMatrixTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*vec, multiplied); CORRADE_COMPARE(multiplied/-1.5f, vec); - Math::RectangularMatrix<1, 1, char> vecChar(32); - Math::RectangularMatrix<1, 1, char> multipliedChar(-48); + Math::RectangularMatrix<1, 1, int8_t> vecChar(32); + Math::RectangularMatrix<1, 1, int8_t> multipliedChar(-48); CORRADE_COMPARE(vecChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, vecChar); CORRADE_COMPARE(-1.5f*vecChar, multipliedChar); @@ -168,14 +168,14 @@ void RectangularMatrixTest::multiplyDivide() { } void RectangularMatrixTest::multiply() { - RectangularMatrix<4, 6, int> left( + RectangularMatrix<4, 6, int32_t> left( -5, 27, 10, 33, 0, -15, 7, 56, 66, 1, 0, -24, 4, 41, 4, 0, 1, -4, 9, -100, 19, -49, 1, 9 ); - RectangularMatrix<5, 4, int> right( + RectangularMatrix<5, 4, int32_t> right( 1, -7, 0, 158, 2, 24, -3, 40, 3, -15, -2, -50, @@ -183,7 +183,7 @@ void RectangularMatrixTest::multiply() { 5, 30, 4, 18 ); - RectangularMatrix<5, 6, int> expected( + RectangularMatrix<5, 6, int32_t> expected( 1368, -16165, 2550, -7716, 158, 1575, 506, -2725, 2352, -1870, 37, -234, -578, 4159, -1918, 2534, -52, -127, @@ -226,7 +226,7 @@ void RectangularMatrixTest::debug() { " 4, 3, 0)\n"); o.str(""); - Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, char>(); + Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, int8_t>(); CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n" " 0, 0, 0,\n" " 0, 0, 0,\n" diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h index 1500ad601..57169d736 100644 --- a/src/MeshTools/Test/CleanTest.h +++ b/src/MeshTools/Test/CleanTest.h @@ -29,17 +29,17 @@ class CleanTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef int Type; + typedef std::int32_t Type; Vector1(): data(0) {} - Vector1(int i): data(i) {} - int operator[](std::size_t) const { return data; } - int& operator[](std::size_t) { return data; } + Vector1(Type i): data(i) {} + Type operator[](std::size_t) const { return data; } + Type& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } private: - int data; + Type data; }; }; diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 9218a995f..b734ea39a 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -37,18 +37,18 @@ InterleaveTest::InterleaveTest() { void InterleaveTest::attributeCount() { stringstream ss; Error::setOutput(&ss); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, - vector{0, 1, 2, 3, 4, 5})), size_t(0)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, + vector{0, 1, 2, 3, 4, 5})), size_t(0)); CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n"); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, - vector{3, 4, 5})), size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, + vector{3, 4, 5})), size_t(3)); } void InterleaveTest::stride() { - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(1)); - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(4)); - CORRADE_COMPARE((Implementation::Interleave::stride(vector(), vector())), size_t(5)); + CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(1)); + CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(4)); + CORRADE_COMPARE((Implementation::Interleave::stride(vector(), vector())), size_t(5)); } void InterleaveTest::write() { @@ -56,9 +56,9 @@ void InterleaveTest::write() { size_t stride; char* data; tie(attributeCount, stride, data) = MeshTools::interleave( - vector{0, 1, 2}, - vector{3, 4, 5}, - vector{6, 7, 8}); + vector{0, 1, 2}, + vector{3, 4, 5}, + vector{6, 7, 8}); CORRADE_COMPARE(attributeCount, size_t(3)); CORRADE_COMPARE(stride, size_t(7)); diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h index 1ed5cc4f0..b5ff7f0ef 100644 --- a/src/MeshTools/Test/SubdivideTest.h +++ b/src/MeshTools/Test/SubdivideTest.h @@ -30,17 +30,17 @@ class SubdivideTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef int Type; + typedef std::int32_t Type; Vector1(): data(0) {} - Vector1(int i): data(i) {} - int operator[](std::size_t) const { return data; } - int& operator[](std::size_t) { return data; } + Vector1(Type i): data(i) {} + Type operator[](std::size_t) const { return data; } + Type& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } private: - int data; + Type data; }; inline static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 67bcd4212..fc0a7c243 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -67,10 +67,10 @@ TipsifyTest::TipsifyTest(): indices{ } void TipsifyTest::buildAdjacency() { - vector liveTriangleCount, neighborOffset, neighbors; + vector liveTriangleCount, neighborOffset, neighbors; Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); - CORRADE_COMPARE(liveTriangleCount, (vector{ + CORRADE_COMPARE(liveTriangleCount, (vector{ 1, 3, 3, 2, 4, 6, 6, 2, 2, 6, 6, 4, @@ -78,7 +78,7 @@ void TipsifyTest::buildAdjacency() { 1, 1, 1 })); - CORRADE_COMPARE(neighborOffset, (vector{ + CORRADE_COMPARE(neighborOffset, (vector{ 0, 1, 4, 7, 9, 13, 19, 25, 27, 29, 35, 41, @@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() { 54, 55, 56, 57 })); - CORRADE_COMPARE(neighbors, (vector{ + CORRADE_COMPARE(neighbors, (vector{ 0, 0, 7, 11, 2, 7, 13, diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index fb89c75f1..ff0a545e2 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(uint32_t hemisphereRings, uint32_t cylinderRings, uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); @@ -60,15 +60,15 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; GLfloat x, y, z; - for(unsigned int i = 0; i != count; ++i) { + for(uint32_t i = 0; i != count; ++i) { GLfloat ringAngle = startRingAngle + i*ringAngleIncrement; x = z = cos(ringAngle); y = sin(ringAngle); - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({x*sin(segmentAngle), centerY+y, z*cos(segmentAngle)}); normals(0)->push_back({x*sin(segmentAngle), y, z*cos(segmentAngle)}); @@ -86,10 +86,10 @@ void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat } } -void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; - for(unsigned int i = 0; i != count; ++i) { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t i = 0; i != count; ++i) { + for(uint32_t j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({sin(segmentAngle), startY, cos(segmentAngle)}); normals(0)->push_back({sin(segmentAngle), 0.0f, cos(segmentAngle)}); @@ -110,7 +110,7 @@ void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yI } void Capsule::bottomFaceRing() { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { /* Bottom vertex */ indices()->push_back(0); @@ -123,11 +123,11 @@ void Capsule::bottomFaceRing() { } } -void Capsule::faceRings(unsigned int count, unsigned int offset) { - unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); +void Capsule::faceRings(uint32_t count, uint32_t offset) { + uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(unsigned int i = 0; i != count; ++i) { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t i = 0; i != count; ++i) { + for(uint32_t j = 0; j != segments; ++j) { uint32_t bottomLeft = i*vertexSegments+j+offset; uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); @@ -145,9 +145,9 @@ void Capsule::faceRings(unsigned int count, unsigned int offset) { } void Capsule::topFaceRing() { - unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); + uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { /* Bottom left vertex */ indices()->push_back(normals(0)->size()-vertexSegments+j-1); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index b0b2b291f..76dd89984 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -53,19 +53,19 @@ class Capsule: public Trade::MeshData3D { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: - Capsule(unsigned int segments, TextureCoords textureCoords); + Capsule(std::uint32_t segments, TextureCoords textureCoords); void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); - void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); - void cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void bottomFaceRing(); - void faceRings(unsigned int count, unsigned int offset = 1); + void faceRings(std::uint32_t count, std::uint32_t offset = 1); void topFaceRing(); - unsigned int segments; + std::uint32_t segments; TextureCoords textureCoords; }; diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index ed6d47217..739f2e6dd 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 709c7dfb9..ebe23b35c 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { +Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { CORRADE_ASSERT(rings >= 1 && segments >= 3, "Cylinder must have at least one ring and three segments", ); GLfloat y = length*0.5f; @@ -51,7 +51,7 @@ Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Fl void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; - for(unsigned int i = 0; i != segments; ++i) { + for(uint32_t i = 0; i != segments; ++i) { GLfloat segmentAngle = i*segmentAngleIncrement; positions(0)->push_back({sin(segmentAngle), y, cos(segmentAngle)}); normals(0)->push_back(normal); diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index c2dcf5877..29da7a73b 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -58,7 +58,7 @@ class Cylinder: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags = Flags()); + Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); private: void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 7a881cd43..e82814264 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -23,7 +23,7 @@ using namespace std; namespace Magnum { namespace Primitives { -UVSphere::UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { +UVSphere::UVSphere(uint32_t rings, uint32_t segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", ); GLfloat textureCoordsVIncrement = 1.0f/rings; diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index d61c60a3c..8d2f01054 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -39,7 +39,7 @@ class UVSphere: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords = TextureCoords::DontGenerate); + UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); }; }} diff --git a/src/Profiler.h b/src/Profiler.h index 1d52f14ed..3be943bd6 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -95,7 +95,7 @@ class MAGNUM_EXPORT Profiler { * * @see otherSection, addSection(), start(Section) */ - typedef unsigned int Section; + typedef std::uint32_t Section; /** * @brief Default section diff --git a/src/Swizzle.h b/src/Swizzle.h index 49b0870b8..529d538ec 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -90,7 +90,7 @@ namespace Implementation { Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); auto vec = swizzle<'a', '1', '0', 'r', 'g', 'b'>(original); // vec == { 4, 1, 0, -1, 2, 3 } @@ -118,7 +118,7 @@ template inline constexpr typename Implementation:: Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); auto vec = swizzle(original, "a10rgb"); // vec == { 4, 1, 0, -1, 2, 3 } diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 7813b5f06..7625131af 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -25,8 +25,8 @@ using namespace Corrade::Utility; namespace Magnum { namespace Test { -typedef Magnum::Color3 Color3; -typedef Magnum::Color4 Color4; +typedef Magnum::Color3 Color3; +typedef Magnum::Color4 Color4; typedef Magnum::Color3 Color3f; typedef Magnum::Color4 Color4f; diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 872dfefa1..bf99d364f 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -39,29 +39,29 @@ ResourceManagerTest::ResourceManagerTest() { void ResourceManagerTest::state() { ResourceKey questionKey("the-question"); - rm->set(questionKey, new int(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - Resource theQuestion = rm->get(questionKey); + rm->set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + Resource theQuestion = rm->get(questionKey); CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); CORRADE_COMPARE(*theQuestion, 10); /* Check that hash function is working properly */ ResourceKey answerKey("the-answer"); - rm->set(answerKey, new int(42), ResourceDataState::Final, ResourcePolicy::Resident); - Resource theAnswer = rm->get(answerKey); + rm->set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theAnswer = rm->get(answerKey); CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(rm->count(), 2); + CORRADE_COMPARE(rm->count(), 2); /* Cannot change already final resource */ stringstream out; Error::setOutput(&out); - rm->set(answerKey, new int(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm->set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n"); /* Check non-final resource changes */ - rm->set(questionKey, new int(20), ResourceDataState::Final, ResourcePolicy::Resident); + rm->set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index 5d3364eb9..ef7c1826a 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -31,7 +31,7 @@ class Data { inline ~Data() { --count; } }; -typedef Magnum::ResourceManager ResourceManager; +typedef Magnum::ResourceManager ResourceManager; class ResourceManagerTest: public Corrade::TestSuite::Tester { public: diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 4f57462a8..fa36a4576 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -23,9 +23,9 @@ CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) namespace Magnum { namespace Test { -typedef Math::Vector2 Vector2; -typedef Math::Vector3 Vector3; -typedef Math::Vector4 Vector4; +typedef Math::Vector2 Vector2; +typedef Math::Vector3 Vector3; +typedef Math::Vector4 Vector4; SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::xyzw, @@ -88,10 +88,10 @@ void SwizzleTest::type() { void SwizzleTest::defaultType() { Vector4 orig(1, 2, 3, 4); - CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int>(3))); - CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int>(3))); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); - CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int32_t>(3))); + CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int32_t>(3))); + CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1))); } }} diff --git a/src/Timeline.cpp b/src/Timeline.cpp index ccc8fbebe..7183c899d 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -37,7 +37,7 @@ void Timeline::nextFrame() { if(!running) return; auto now = high_resolution_clock::now(); - unsigned int duration = duration_cast(now-previousFrameTime).count(); + std::uint32_t duration = duration_cast(now-previousFrameTime).count(); _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index f9936e742..4dad71afe 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -15,18 +15,22 @@ #include "TypeTraits.h" +#include + +using namespace std; + namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(sizeof(GLubyte) == sizeof(unsigned char), "GLubyte is not the same as unsigned char"); -static_assert(sizeof(GLbyte) == sizeof(char), "GLbyte is not the same as char"); -static_assert(sizeof(GLushort) == sizeof(unsigned short), "GLushort is not the same as unsigned short"); -static_assert(sizeof(GLshort) == sizeof(short), "GLshort is not the same as short"); -static_assert(sizeof(GLuint) == sizeof(unsigned int), "GLuint is not the same as unsigned int"); -static_assert(sizeof(GLint) == sizeof(int), "GLint is not the same as int"); -static_assert(sizeof(GLfloat) == sizeof(float), "GLfloat is not the same as float"); +static_assert(is_same::value, "GLubyte is not the same as uint8_t"); +static_assert(is_same::value, "GLbyte is not the same as int8_t"); +static_assert(is_same::value, "GLushort is not the same as uint16_t"); +static_assert(is_same::value, "GLshort is not the same as int16_t"); +static_assert(is_same::value, "GLuint is not the same as uint32_t"); +static_assert(is_same::value, "GLint is not the same as int32_t"); +static_assert(is_same::value, "GLfloat is not the same as float"); #ifndef MAGNUM_TARGET_GLES -static_assert(sizeof(GLdouble) == sizeof(double), "GLdouble is not the same as double"); +static_assert(is_same::value, "GLdouble is not the same as double"); #endif #endif diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 2f01b0167..37dae7f43 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -165,7 +165,7 @@ template<> struct TypeOf { typedef GLfloat Type; }; template<> struct TypeOf { typedef GLdouble Type; }; #endif -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; } @@ -173,7 +173,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } @@ -181,7 +181,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; } @@ -189,7 +189,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } @@ -197,7 +197,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } @@ -205,7 +205,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } From 18c23cbd3709d69add4397fb2234e168fa80d472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 16:46:55 +0200 Subject: [PATCH 153/256] Ooops, forgot to install DimensionTraits.h. --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 061399b1f..1cf6c5361 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(Magnum_HEADERS Context.h CubeMapTextureArray.h CubeMapTexture.h + DimensionTraits.h Extensions.h Framebuffer.h Image.h From c97d2c9049cdd89c0d725de47c2119d6bcbfac27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 14:28:00 +0200 Subject: [PATCH 154/256] Support for filling Buffer from std::array. --- src/Buffer.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Buffer.h b/src/Buffer.h index a7ff8df08..c2403ec75 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -20,6 +20,7 @@ */ #include +#include #include #include "Magnum.h" @@ -266,6 +267,11 @@ class Buffer { setData(_defaultTarget, data, usage); } + /** @overload */ + template inline void setData(const std::array& data, Usage usage) { + setData(_defaultTarget, data, usage); + } + /** * @brief Set buffer data * @param target %Target @@ -307,6 +313,11 @@ class Buffer { setData(target, data.size()*sizeof(T), data.data(), usage); } + /** @overload */ + template inline void setData(Target target, const std::array& data, Usage usage) { + setData(target, data.size()*sizeof(T), data.data(), usage); + } + /** * @brief Set buffer subdata * @param offset Offset @@ -346,6 +357,11 @@ class Buffer { setSubData(_defaultTarget, offset, data); } + /** @overload */ + template inline void setSubData(GLintptr offset, const std::array& data) { + setSubData(_defaultTarget, offset, data); + } + /** * @brief Set buffer subdata * @param target %Target @@ -386,6 +402,11 @@ class Buffer { setSubData(target, offset, data.size()*sizeof(T), data.data()); } + /** @overload */ + template inline void setSubData(Target target, GLintptr offset, const std::array& data) { + setSubData(target, offset, data.size()*sizeof(T), data.data()); + } + private: GLuint buffer; Target _defaultTarget; From 3868dba6ae372ed13f88915c9168488a0fbe1373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 14:28:28 +0200 Subject: [PATCH 155/256] Buffer documentation update. * Documented setData()/setSubData() overloads. * Alphabetically reordered Target * Linking related functions from enums --- src/Buffer.h | 90 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 29 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index c2403ec75..38ef73d5c 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -28,7 +28,33 @@ namespace Magnum { /** -@brief Class for managing buffers +@brief %Buffer + +Encapsulates one OpenGL buffer object and provides functions for convenient +data updates. + +@section Buffer-data Data updating +Default way to set or update buffer data with setData() or setSubData() is to +explicitly specify data size and pass the pointer to it: +@code +Vector3* data = new Vector3[200]; +buffer.setData(200*sizeof(Vector3), data, Buffer::Usage::StaticDraw); +@endcode +Howewer, in some cases, you have the data in fixed-size array with size known +at compile time. There is an convenient overload which detects the size of +passed array, so you don't have to repeat it: +@code +Vector3 data[] = { + // ... +}; +buffer.setData(data, Buffer::Usage::StaticDraw); +@endcode +There is also overload for array-like containers from STL, such as `std::vector` or +`std::array`: +@code +std::vector data; +buffer.setData(data, Buffer::Usage::StaticDraw); +@endcode @todo Support for buffer copying (OpenGL 3.1, @extension{ARB,copy_buffer}) @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) @@ -40,7 +66,13 @@ class Buffer { Buffer& operator=(Buffer&& other) = delete; public: - /** @brief %Buffer target */ + /** + * @brief %Buffer target + * + * @see bind(Target), unbind(Target), + * setData(Target, GLsizeiptr, const GLvoid*, Usage), + * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) + */ enum class Target: GLenum { /** Used for storing vertex attributes. */ Array = GL_ARRAY_BUFFER, @@ -59,26 +91,33 @@ class Buffer { */ CopyWrite = GL_COPY_WRITE_BUFFER, + #ifndef MAGNUM_TARGET_GLES + /** + * Used for supplying arguments for instanced drawing. + * @requires_gl + * @requires_gl40 Extension @extension{ARB,draw_indirect} + */ + DrawIndirect = GL_DRAW_INDIRECT_BUFFER, + #endif + /** Used for storing vertex indices. */ ElementArray = GL_ELEMENT_ARRAY_BUFFER, /** - * Source for texture update operations. + * Target for pixel pack operations. * @requires_gles30 (no extension providing this functionality) */ - PixelUnpack = GL_PIXEL_UNPACK_BUFFER, + PixelPack = GL_PIXEL_PACK_BUFFER, /** - * Target for pixel pack operations. + * Source for texture update operations. * @requires_gles30 (no extension providing this functionality) */ - PixelPack = GL_PIXEL_PACK_BUFFER, + PixelUnpack = GL_PIXEL_UNPACK_BUFFER, #ifndef MAGNUM_TARGET_GLES /** - * Source for texel fetches. - * - * @see BufferedTexture + * Source for texel fetches. See BufferedTexture. * @requires_gl * @requires_gl31 Extension @extension{ARB,texture_buffer_object} */ @@ -98,20 +137,13 @@ class Buffer { * @requires_gles30 (no extension providing this functionality) */ Uniform = GL_UNIFORM_BUFFER - - #ifndef MAGNUM_TARGET_GLES - , - - /** - * Used for supplying arguments for instanced drawing. - * @requires_gl - * @requires_gl40 Extension @extension{ARB,draw_indirect} - */ - DrawIndirect = GL_DRAW_INDIRECT_BUFFER - #endif }; - /** @brief %Buffer usage */ + /** + * @brief %Buffer usage + * + * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) + */ enum class Usage: GLenum { /** * Set once by the application and used infrequently for drawing. @@ -174,7 +206,7 @@ class Buffer { /** * @brief Unbind any buffer from given target - * @param target %Target + * @param target %Target * * @see @fn_gl{BindBuffer} */ @@ -220,7 +252,7 @@ class Buffer { /** * @brief Bind buffer - * @param target %Target + * @param target %Target * * @see @fn_gl{BindBuffer} */ @@ -320,7 +352,7 @@ class Buffer { /** * @brief Set buffer subdata - * @param offset Offset + * @param offset Offset in the buffer * @param size Data size * @param data Pointer to data * @@ -333,7 +365,7 @@ class Buffer { /** * @brief Set buffer subdata - * @param offset Offset + * @param offset Offset in the buffer * @param data Fixed-size array with data * * Sets buffer subdata with default target. More convenient for @@ -347,7 +379,7 @@ class Buffer { /** * @brief Set buffer subdata - * @param offset Offset + * @param offset Offset in the buffer * @param data Vector with data * * Sets buffer subdata with default target. @@ -365,7 +397,7 @@ class Buffer { /** * @brief Set buffer subdata * @param target %Target - * @param offset Offset + * @param offset Offset in the buffer * @param size Data size * @param data Pointer to data * @@ -379,7 +411,7 @@ class Buffer { /** * @brief Set buffer subdata * @param target %Target - * @param offset Offset + * @param offset Offset in the buffer * @param data Fixed-size array with data * * More convenient for setting data from fixed-size arrays than @@ -393,7 +425,7 @@ class Buffer { /** * @brief Set buffer subdata * @param target %Target - * @param offset Offset + * @param offset Offset in the buffer * @param data Vector with data * * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) From f2a569de0e76a679dc177e34274a17d85f3cbf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 14:37:16 +0200 Subject: [PATCH 156/256] Workarounds to make Doxygen happy. --- src/Math/Math.cpp | 2 +- src/MeshTools/FlipNormals.cpp | 2 +- src/MeshTools/GenerateFlatNormals.cpp | 2 +- src/Primitives/Capsule.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Math/Math.cpp b/src/Math/Math.cpp index 56a7636eb..ec39d403d 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Math.cpp @@ -19,7 +19,7 @@ using namespace std; namespace Magnum { namespace Math { -uint32_t log(uint32_t base, uint32_t number) { +std::uint32_t log(std::uint32_t base, std::uint32_t number) { uint32_t log = 0; while(number /= base) ++log; diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index 859f90306..f34304fa1 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace MeshTools { -void flipFaceWinding(vector& indices) { +void flipFaceWinding(vector& indices) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); for(size_t i = 0; i != indices.size(); i += 3) diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index b223eefb1..918d19d68 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index ff0a545e2..266be7617 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(uint32_t hemisphereRings, uint32_t cylinderRings, uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; From ae5b88d448aa7399fe3f5ecb57688181adec29f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 14:52:00 +0200 Subject: [PATCH 157/256] Buffer: added last remaining targets from OpenGL 4.2 and 4.3. --- src/Buffer.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Buffer.h b/src/Buffer.h index 38ef73d5c..caca1706d 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -77,6 +77,15 @@ class Buffer { /** Used for storing vertex attributes. */ Array = GL_ARRAY_BUFFER, + #ifndef MAGNUM_TARGET_GLES + /** + * Used for storing atomic counters. + * @requires_gl42 Extension @extension{ARB,shader_atomic_counters} + * @requires_gl + */ + AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, + #endif + /** * Source for copies. * @requires_gl31 Extension @extension{ARB,copy_buffer} @@ -92,6 +101,13 @@ class Buffer { CopyWrite = GL_COPY_WRITE_BUFFER, #ifndef MAGNUM_TARGET_GLES + /** + * Indirect compute dispatch commands. + * @requires_gl43 Extension @extension{ARB,compute_shader} + * @requires_gl + */ + DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, + /** * Used for supplying arguments for instanced drawing. * @requires_gl @@ -116,6 +132,13 @@ class Buffer { PixelUnpack = GL_PIXEL_UNPACK_BUFFER, #ifndef MAGNUM_TARGET_GLES + /** + * Used for shader storage. + * @requires_gl43 Extension @extension{ARB,shader_storage_buffer_object} + * @requires_gl + */ + ShaderStorage = GL_SHADER_STORAGE_BUFFER, + /** * Source for texel fetches. See BufferedTexture. * @requires_gl From 5283b3b9cd03f5b49f01fcac4afca12ab0dd94f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 15:27:51 +0200 Subject: [PATCH 158/256] Buffer: support for copying. --- src/Buffer.cpp | 26 ++++++++++++++++++++++++++ src/Buffer.h | 25 +++++++++++++++++++++---- src/CMakeLists.txt | 1 + 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/Buffer.cpp diff --git a/src/Buffer.cpp b/src/Buffer.cpp new file mode 100644 index 000000000..5c238c729 --- /dev/null +++ b/src/Buffer.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Buffer.h" + +namespace Magnum { + +void Buffer::copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { + read->bind(Target::CopyRead); + write->bind(Target::CopyWrite); + glCopyBufferSubData(static_cast(Target::CopyRead), static_cast(Target::CopyWrite), readOffset, writeOffset, size); +} + +} diff --git a/src/Buffer.h b/src/Buffer.h index caca1706d..ca2c46a4c 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -25,6 +25,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** @@ -56,10 +58,9 @@ std::vector data; buffer.setData(data, Buffer::Usage::StaticDraw); @endcode -@todo Support for buffer copying (OpenGL 3.1, @extension{ARB,copy_buffer}) @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) */ -class Buffer { +class MAGNUM_EXPORT Buffer { Buffer(const Buffer& other) = delete; Buffer(Buffer&& other) = delete; Buffer& operator=(const Buffer& other) = delete; @@ -87,14 +88,14 @@ class Buffer { #endif /** - * Source for copies. + * Source for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) */ CopyRead = GL_COPY_READ_BUFFER, /** - * Target for copies. + * Target for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) */ @@ -237,6 +238,22 @@ class Buffer { glBindBuffer(static_cast(target), 0); } + /** + * @brief Copy one buffer to another + * @param read %Buffer from which to read + * @param write %Buffer to which to copy + * @param readOffset Offset in the read buffer + * @param writeOffset Offset in the write buffer + * @param size Data size + * + * Read buffer is bound to `Target::CopyRead`, write buffer to + * `Target::CopyWrite` and the copy is performed. + * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gles30 (no extension providing this functionality) + * @see @fn_gl{CopyBufferSubData} + */ + static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + /** * @brief Constructor * @param defaultTarget Default target (used when calling bind() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cf6c5361..e2e867e56 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(Magnum_SRCS AbstractImage.cpp AbstractTexture.cpp AbstractShaderProgram.cpp + Buffer.cpp BufferedImage.cpp BufferedTexture.cpp Context.cpp From 2595974fae07d2660fe2da2ddabccd9f44712604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 16:43:28 +0200 Subject: [PATCH 159/256] Refactoring of internal OpenGL object names. --- src/AbstractShaderProgram.cpp | 18 +++++++++--------- src/AbstractShaderProgram.h | 10 +++++----- src/AbstractTexture.h | 12 ++++++------ src/Buffer.h | 12 ++++++------ src/BufferedTexture.h | 8 ++++---- src/Framebuffer.h | 8 ++++---- src/Query.cpp | 16 ++++++++-------- src/Query.h | 15 +++++++++------ 8 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index eb7541f9d..0dccdc4a3 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -28,7 +28,7 @@ namespace Magnum { bool AbstractShaderProgram::use() { if(state != Linked) return false; - glUseProgram(program); + glUseProgram(_id); return true; } @@ -36,26 +36,26 @@ bool AbstractShaderProgram::attachShader(Shader& shader) { GLuint _shader = shader.compile(); if(!_shader) return false; - glAttachShader(program, _shader); + glAttachShader(_id, _shader); return true; } void AbstractShaderProgram::bindAttributeLocation(GLuint location, const string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: attribute cannot be bound after linking.", ); - glBindAttribLocation(program, location, name.c_str()); + glBindAttribLocation(_id, location, name.c_str()); } #ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::bindFragmentDataLocation(GLuint location, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", ); - glBindFragDataLocation(program, location, name.c_str()); + glBindFragDataLocation(_id, location, name.c_str()); } void AbstractShaderProgram::bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", ); - glBindFragDataLocationIndexed(program, location, index, name.c_str()); + glBindFragDataLocationIndexed(_id, location, index, name.c_str()); } #endif @@ -64,15 +64,15 @@ void AbstractShaderProgram::link() { if(state != Initialized) return; /* Link shader program */ - glLinkProgram(program); + glLinkProgram(_id); /* Check link status */ GLint status; - glGetProgramiv(program, GL_LINK_STATUS, &status); + glGetProgramiv(_id, GL_LINK_STATUS, &status); /* Display errors or warnings */ char message[LINKER_MESSAGE_MAX_LENGTH]; - glGetProgramInfoLog(program, LINKER_MESSAGE_MAX_LENGTH, nullptr, message); + glGetProgramInfoLog(_id, LINKER_MESSAGE_MAX_LENGTH, nullptr, message); /* Show error log and delete shader */ if(status == GL_FALSE) { @@ -92,7 +92,7 @@ GLint AbstractShaderProgram::uniformLocation(const std::string& name) { /** @todo What if linking just failed (not programmer error?) */ CORRADE_ASSERT(state == Linked, "AbstractShaderProgram: uniform location cannot be retrieved before linking.", -1); - GLint location = glGetUniformLocation(program, name.c_str()); + GLint location = glGetUniformLocation(_id, name.c_str()); if(location == -1) Warning() << "AbstractShaderProgram: location of uniform \'" + name + "\' cannot be retrieved!"; return location; diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 1892d5f16..d9140fdf9 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -220,7 +220,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @see @fn_gl{CreateProgram} */ inline AbstractShaderProgram(): state(Initialized) { - program = glCreateProgram(); + _id = glCreateProgram(); } /** @@ -253,7 +253,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setRetrievableBinary(bool enabled) { - glProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, enabled ? GL_TRUE : GL_FALSE); + glProgramParameteri(_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, enabled ? GL_TRUE : GL_FALSE); } #ifndef MAGNUM_TARGET_GLES @@ -268,7 +268,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl41 Extension @extension{ARB,separate_shader_objects} */ inline void setSeparable(bool enabled) { - glProgramParameteri(program, GL_PROGRAM_SEPARABLE, enabled ? GL_TRUE : GL_FALSE); + glProgramParameteri(_id, GL_PROGRAM_SEPARABLE, enabled ? GL_TRUE : GL_FALSE); } #endif @@ -638,11 +638,11 @@ class MAGNUM_EXPORT AbstractShaderProgram { Failed }; - GLuint program; + GLuint _id; State state; }; -inline AbstractShaderProgram::~AbstractShaderProgram() { glDeleteProgram(program); } +inline AbstractShaderProgram::~AbstractShaderProgram() { glDeleteProgram(_id); } } diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 549588ea3..fc0b0f818 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -557,7 +557,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see @fn_gl{GenTextures} */ inline AbstractTexture(GLenum target): _target(target) { - glGenTextures(1, &texture); + glGenTextures(1, &_id); } /** @@ -568,8 +568,8 @@ class MAGNUM_EXPORT AbstractTexture { */ virtual ~AbstractTexture() = 0; - /** @brief OpenGL internal texture ID */ - inline GLuint id() const { return texture; } + /** @brief OpenGL texture ID */ + inline GLuint id() const { return _id; } /** * @brief Bind texture for rendering @@ -675,14 +675,14 @@ class MAGNUM_EXPORT AbstractTexture { * @see @fn_gl{BindTexture} */ inline void bind() { - glBindTexture(_target, texture); + glBindTexture(_target, _id); } private: - GLuint texture; + GLuint _id; }; -inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &texture); } +inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &_id); } /** @relates AbstractTexture @brief Convertor of component count and data type to InternalFormat diff --git a/src/Buffer.h b/src/Buffer.h index ca2c46a4c..fb2f75da9 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -263,7 +263,7 @@ class MAGNUM_EXPORT Buffer { * @see @fn_gl{GenBuffers} */ inline Buffer(Target defaultTarget): _defaultTarget(defaultTarget) { - glGenBuffers(1, &buffer); + glGenBuffers(1, &_id); } /** @@ -273,14 +273,14 @@ class MAGNUM_EXPORT Buffer { * @see @fn_gl{DeleteBuffers} */ inline virtual ~Buffer() { - glDeleteBuffers(1, &buffer); + glDeleteBuffers(1, &_id); } /** @brief Default bind type */ inline Target defaultTarget() const { return _defaultTarget; } - /** @brief OpenGL internal buffer ID */ - inline GLuint id() const { return buffer; } + /** @brief OpenGL buffer ID */ + inline GLuint id() const { return _id; } /** * @brief Bind buffer @@ -297,7 +297,7 @@ class MAGNUM_EXPORT Buffer { * @see @fn_gl{BindBuffer} */ inline void bind(Target target) { - glBindBuffer(static_cast(target), buffer); + glBindBuffer(static_cast(target), _id); } /** @@ -480,7 +480,7 @@ class MAGNUM_EXPORT Buffer { } private: - GLuint buffer; + GLuint _id; Target _defaultTarget; }; diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index 8ae1a5b7a..be4e3bbf3 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -124,7 +124,7 @@ class BufferedTexture { * @see @fn_gl{GenTextures} */ inline BufferedTexture() { - glGenTextures(1, &texture); + glGenTextures(1, &_id); } /** @@ -134,7 +134,7 @@ class BufferedTexture { * @see @fn_gl{DeleteTextures} */ inline virtual ~BufferedTexture() { - glDeleteTextures(1, &texture); + glDeleteTextures(1, &_id); } /** @@ -166,10 +166,10 @@ class BufferedTexture { } private: - GLuint texture; + GLuint _id; inline void bind() { - glBindTexture(GL_TEXTURE_BUFFER, texture); + glBindTexture(GL_TEXTURE_BUFFER, _id); } }; diff --git a/src/Framebuffer.h b/src/Framebuffer.h index d9c43fe90..e70b7bc1b 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -756,7 +756,7 @@ class MAGNUM_EXPORT Framebuffer { * @see @fn_gl{GenFramebuffers} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline Framebuffer() { glGenFramebuffers(1, &framebuffer); } + inline Framebuffer() { glGenFramebuffers(1, &_id); } /** * @brief Destructor @@ -765,7 +765,7 @@ class MAGNUM_EXPORT Framebuffer { * @see @fn_gl{DeleteFramebuffers} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - inline ~Framebuffer() { glDeleteFramebuffers(1, &framebuffer); } + inline ~Framebuffer() { glDeleteFramebuffers(1, &_id); } /** * @brief Bind default framebuffer to given target @@ -785,7 +785,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void bind(Target target) { - glBindFramebuffer(static_cast(target), framebuffer); + glBindFramebuffer(static_cast(target), _id); } #ifndef MAGNUM_TARGET_GLES @@ -1164,7 +1164,7 @@ class MAGNUM_EXPORT Framebuffer { /*@}*/ private: - GLuint framebuffer; + GLuint _id; }; CORRADE_ENUMSET_OPERATORS(Framebuffer::ClearMask) diff --git a/src/Query.cpp b/src/Query.cpp index 928e2a701..36f8fc2a7 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -20,44 +20,44 @@ namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 bool AbstractQuery::resultAvailable() { GLuint result; - glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result); + glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result); return result == GL_TRUE; } template<> bool AbstractQuery::result() { GLuint result; - glGetQueryObjectuiv(query, GL_QUERY_RESULT, &result); + glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); return result == GL_TRUE; } template<> GLuint AbstractQuery::result() { GLuint result; - glGetQueryObjectuiv(query, GL_QUERY_RESULT, &result); + glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); return result; } #ifndef MAGNUM_TARGET_GLES template<> GLint AbstractQuery::result() { GLint result; - glGetQueryObjectiv(query, GL_QUERY_RESULT, &result); + glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result); return result; } template<> GLuint64 AbstractQuery::result() { GLuint64 result; - glGetQueryObjectui64v(query, GL_QUERY_RESULT, &result); + glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result); return result; } template<> GLint64 AbstractQuery::result() { GLint64 result; - glGetQueryObjecti64v(query, GL_QUERY_RESULT, &result); + glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result); return result; } #endif void Query::begin(Query::Target target) { - glBeginQuery(static_cast(target), query); + glBeginQuery(static_cast(target), id()); this->target = new Target(target); } @@ -70,7 +70,7 @@ void Query::end() { } void SampleQuery::begin(SampleQuery::Target target) { - glBeginQuery(static_cast(target), query); + glBeginQuery(static_cast(target), id()); this->target = new Target(target); } diff --git a/src/Query.h b/src/Query.h index e88f2af0a..90aff476d 100644 --- a/src/Query.h +++ b/src/Query.h @@ -41,7 +41,7 @@ class MAGNUM_EXPORT AbstractQuery { * Generates one OpenGL query. * @see @fn_gl{GenQueries} */ - inline AbstractQuery() { glGenQueries(1, &query); } + inline AbstractQuery() { glGenQueries(1, &_id); } /** * @brief Destructor @@ -49,7 +49,10 @@ class MAGNUM_EXPORT AbstractQuery { * Deletes assigned OpenGL query. * @see @fn_gl{DeleteQueries} */ - virtual inline ~AbstractQuery() { glDeleteQueries(1, &query); } + virtual inline ~AbstractQuery() { glDeleteQueries(1, &_id); } + + /** @brief OpenGL query ID */ + inline GLuint id() const { return _id; } /** * @brief Whether the result is available @@ -71,8 +74,8 @@ class MAGNUM_EXPORT AbstractQuery { */ template T result(); - protected: - GLuint query; /**< @brief OpenGL internal query ID */ + private: + GLuint _id; }; @@ -276,7 +279,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * @requires_gl30 Extension @extension{NV,conditional_render} */ inline void beginConditionalRender(ConditionalRenderMode mode) { - glBeginConditionalRender(query, static_cast(mode)); + glBeginConditionalRender(id(), static_cast(mode)); } /** @@ -336,7 +339,7 @@ class TimeQuery: public AbstractQuery { * @see @fn_gl{QueryCounter} with @def_gl{TIMESTAMP} */ inline void timestamp() { - glQueryCounter(query, GL_TIMESTAMP); + glQueryCounter(id(), GL_TIMESTAMP); } }; #endif From df836f126dab31c7115aa6ba6638950f29b69a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 16:57:04 +0200 Subject: [PATCH 160/256] Ability to link to extension functions in Doxygen documentation. --- Doxyfile | 1 + doc/coding-style.dox | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Doxyfile b/Doxyfile index 0322c1da3..b208057d0 100644 --- a/Doxyfile +++ b/Doxyfile @@ -201,6 +201,7 @@ ALIASES = \ "collisionoperator{2}=@relates \1\n@brief Collision of %\1 and %\2\n@see \2::operator%(const \1&) const" \ "todoc=@xrefitem todoc \"Documentation todo\" \"Documentation-related todo list\"" \ "fn_gl{1}=gl\1()" \ + "fn_gl_extension{3}=gl\1\2()" \ "def_gl{1}=`GL_\1`" \ "requires_gl=@xrefitem requires-gl \"Requires desktop OpenGL\" \"Functionality requiring desktop OpenGL (not available on OpenGL ES)\" Not available on OpenGL ES." \ "requires_gl30=@xrefitem requires-gl30 \"Requires OpenGL 3.0\" \"Functionality requiring OpenGL 3.0\"" \ diff --git a/doc/coding-style.dox b/doc/coding-style.dox index ad4b75de4..802f2e6e2 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -49,6 +49,16 @@ the operator is implemented (not of class in which the operator is implemented), thus efficiently connecting the two classes together in the documentation. +@subsubsection documentation-commands-extension Links to OpenGL extensions + +If an OpenGL extension is referenced in the documentation, it should be done +with @c \@extension command: +@code +@extension{ARB,timer_query} +@endcode +It produces link to the specification of the extension in OpenGL registry, +e.g. @extension{ARB,timer_query}. + @subsubsection documentation-commands-ref_gl Links to related OpenGL functions and definitions If an function touches OpenGL, related OpenGL functions should be documented @@ -64,15 +74,15 @@ inline static void setSeamless(bool enabled) { It produces link to the online manual, in this case @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS}. -@subsubsection documentation-commands-extension Links to OpenGL extensions - -If an OpenGL extension is referenced in the documentation, it should be done -with @c \@extension command: +For functions which are not part of OpenGL core specification, but only as +extensions, use @c \@fn_gl_extension command, e.g. @code -@extension{ARB,timer_query} +@fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} @endcode -It produces link to the specification of the extension in OpenGL registry, -e.g. @extension{ARB,timer_query}. +First parameter is function name without the suffix, the second two parameters +are the same as in @c \@extension command. It produced link to extension +specification, with function name as link text, in this case +@fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access}. @subsubsection documentation-commands-requires Classes and functions requiring specific OpenGL version or extensions From 04a0f9511fef706b480e4c30504612692df79bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 17:02:20 +0200 Subject: [PATCH 161/256] Fixed compilation error. I should really test before commit & push, wtf. --- src/Trade/ImageData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index a0383d806..d225db8bf 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -69,7 +69,7 @@ template class ImageData: public AbstractImage { inline std::string name() const { return _name; } /** @brief %Image size */ - inline constexpr typename DimensionTraits::VectorType& size() const { return _size; } + inline constexpr typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } From c47b416bcf43dcd801b9228030d5e2aa526a0445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 17:03:16 +0200 Subject: [PATCH 162/256] Added EXT_direct_state_access to Extensions list. --- src/Extensions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Extensions.h b/src/Extensions.h index 8fd0cadf5..78508441b 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -123,6 +123,7 @@ namespace GL { _extension(GL,EXT,draw_buffers2, GL210, GL300) // #340 _extension(GL,EXT,texture_integer, GL210, GL300) // #343 _extension(GL,EXT,transform_feedback, GL210, GL300) // #352 + _extension(GL,EXT,direct_state_access, GL210, None) // #353 _extension(GL,EXT,texture_snorm, GL300, GL310) // #365 } namespace NV { _extension(GL,NV,half_float, GL210, GL300) // #283 From 806828f17326754bf6f7261e9effbacf3073b592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 17:03:55 +0200 Subject: [PATCH 163/256] First extension-aware functionality - Buffer::copy(). If EXT_direct_state_access is supported, it uses faster alternative to explicit binding. --- src/Buffer.cpp | 21 ++++++++++++++++++++- src/Buffer.h | 22 ++++++++++++++++++---- src/Context.cpp | 4 ++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5c238c729..7c7a60e83 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -15,12 +15,31 @@ #include "Buffer.h" +#include + +#include "Context.h" +#include "Extensions.h" + namespace Magnum { -void Buffer::copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { +Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault; + +void Buffer::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported()) { + Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + copyImplementation = &Buffer::copyImplementationDSA; + } +} + +void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { read->bind(Target::CopyRead); write->bind(Target::CopyWrite); glCopyBufferSubData(static_cast(Target::CopyRead), static_cast(Target::CopyWrite), readOffset, writeOffset, size); } +void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { + glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size); +} + } diff --git a/src/Buffer.h b/src/Buffer.h index fb2f75da9..6d9b89ff9 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -29,6 +29,8 @@ namespace Magnum { +class Context; + /** @brief %Buffer @@ -61,6 +63,8 @@ buffer.setData(data, Buffer::Usage::StaticDraw); @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) */ class MAGNUM_EXPORT Buffer { + friend class Context; + Buffer(const Buffer& other) = delete; Buffer(Buffer&& other) = delete; Buffer& operator=(const Buffer& other) = delete; @@ -246,13 +250,16 @@ class MAGNUM_EXPORT Buffer { * @param writeOffset Offset in the write buffer * @param size Data size * - * Read buffer is bound to `Target::CopyRead`, write buffer to - * `Target::CopyWrite` and the copy is performed. + * If @extension{EXT,direct_state_access} is not available, read + * buffer is bound to `Target::CopyRead` and write buffer to + * `Target::CopyWrite` before the copy is performed. * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) - * @see @fn_gl{CopyBufferSubData} + * @see @fn_gl{CopyBufferSubData} or @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} */ - static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { + copyImplementation(read, write, readOffset, writeOffset, size); + } /** * @brief Constructor @@ -480,6 +487,13 @@ class MAGNUM_EXPORT Buffer { } private: + static void initializeContextBasedFunctionality(Context* context); + + typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr); + static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + static CopyImplementation copyImplementation; + GLuint _id; Target _defaultTarget; }; diff --git a/src/Context.cpp b/src/Context.cpp index 2410bcfef..3a46b7638 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -19,6 +19,7 @@ #include #include +#include "Buffer.h" #include "Extensions.h" using namespace std; @@ -191,6 +192,9 @@ Context::Context() { /* Set this context as current */ CORRADE_ASSERT(!_current, "Context: Another context currently active", ); _current = this; + + /* Initialize functionality based on current OpenGL version and extensions */ + Buffer::initializeContextBasedFunctionality(this); } Context::~Context() { From 684a1ee71288a77f9e36028c11234b4e83b40dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 17:14:38 +0200 Subject: [PATCH 164/256] Removed set*Data(Target, ...) functions from Buffer. They didn't make sense at all (and even less with DSA, where target doesn't need to be specified anywhere), the only usage in BufferedImage was misunderstood from the beginning. --- src/Buffer.h | 137 ++++++------------------------------------ src/BufferedImage.cpp | 2 +- 2 files changed, 19 insertions(+), 120 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 6d9b89ff9..57b4eebe4 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -74,9 +74,7 @@ class MAGNUM_EXPORT Buffer { /** * @brief %Buffer target * - * @see bind(Target), unbind(Target), - * setData(Target, GLsizeiptr, const GLvoid*, Usage), - * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) + * @see bind(Target), unbind(Target) */ enum class Target: GLenum { /** Used for storing vertex attributes. */ @@ -170,7 +168,7 @@ class MAGNUM_EXPORT Buffer { /** * @brief %Buffer usage * - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) + * @see setData(GLsizeiptr, const GLvoid*, Usage) */ enum class Usage: GLenum { /** @@ -313,11 +311,11 @@ class MAGNUM_EXPORT Buffer { * @param data Pointer to data * @param usage %Buffer usage * - * Sets buffer data with default target. - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) + * @see bind(), @fn_gl{BufferData} */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { - setData(_defaultTarget, size, data, usage); + bind(); + glBufferData(static_cast(_defaultTarget), size, data, static_cast(usage)); } /** @@ -325,13 +323,10 @@ class MAGNUM_EXPORT Buffer { * @param data Fixed-size array with data * @param usage %Buffer usage * - * Sets buffer data with default target. More convenient for setting - * data from fixed-size arrays than - * setData(GLsizeiptr, const GLvoid*, Usage). - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) + * @see setData(GLsizeiptr, const GLvoid*, Usage). */ template inline void setData(const T(&data)[size], Usage usage) { - setData(_defaultTarget, data, usage); + setData(size*sizeof(T), data, usage); } /** @@ -339,62 +334,15 @@ class MAGNUM_EXPORT Buffer { * @param data Vector with data * @param usage %Buffer usage * - * Sets buffer data with default target. - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) + * @see setData(GLsizeiptr, const GLvoid*, Usage) */ template inline void setData(const std::vector& data, Usage usage) { - setData(_defaultTarget, data, usage); + setData(data.size()*sizeof(T), data.data(), usage); } /** @overload */ template inline void setData(const std::array& data, Usage usage) { - setData(_defaultTarget, data, usage); - } - - /** - * @brief Set buffer data - * @param target %Target - * @param size Data size - * @param data Pointer to data - * @param usage %Buffer usage - * - * @see bind(Target), @fn_gl{BufferData} - */ - inline void setData(Target target, GLsizeiptr size, const GLvoid* data, Usage usage) { - bind(target); - glBufferData(static_cast(target), size, data, static_cast(usage)); - } - - /** - * @brief Set buffer data - * @param target %Target - * @param data Fixed-size array with data - * @param usage %Buffer usage - * - * More convenient for setting data from fixed-size arrays than - * setData(Target, GLsizeiptr, const GLvoid*, Usage). - * - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) - */ - template inline void setData(Target target, const T(&data)[size], Usage usage) { - setData(target, size*sizeof(T), data, usage); - } - - /** - * @brief Set buffer data - * @param target %Target - * @param data Vector with data - * @param usage %Buffer usage - * - * @see setData(Target, GLsizeiptr, const GLvoid*, Usage) - */ - template inline void setData(Target target, const std::vector& data, Usage usage) { - setData(target, data.size()*sizeof(T), data.data(), usage); - } - - /** @overload */ - template inline void setData(Target target, const std::array& data, Usage usage) { - setData(target, data.size()*sizeof(T), data.data(), usage); + setData(data.size()*sizeof(T), data.data(), usage); } /** @@ -403,11 +351,11 @@ class MAGNUM_EXPORT Buffer { * @param size Data size * @param data Pointer to data * - * Sets buffer subdata with default target. - * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) + * @see bind(), @fn_gl{BufferSubData} */ inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { - setSubData(_defaultTarget, offset, size, data); + bind(); + glBufferSubData(static_cast(_defaultTarget), offset, size, data); } /** @@ -415,13 +363,10 @@ class MAGNUM_EXPORT Buffer { * @param offset Offset in the buffer * @param data Fixed-size array with data * - * Sets buffer subdata with default target. More convenient for - * setting data from fixed-size arrays than - * setSubData(GLintptr, GLsizeiptr, const GLvoid*). - * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) + * @see setSubData(GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(GLintptr offset, const T(&data)[size]) { - setSubData(_defaultTarget, offset, data); + setSubData(offset, size*sizeof(T), data); } /** @@ -429,61 +374,15 @@ class MAGNUM_EXPORT Buffer { * @param offset Offset in the buffer * @param data Vector with data * - * Sets buffer subdata with default target. - * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) + * @see setSubData(GLintptr, GLsizeiptr, const GLvoid*) */ template inline void setSubData(GLintptr offset, const std::vector& data) { - setSubData(_defaultTarget, offset, data); + setSubData(offset, data.size()*sizeof(T), data.data()); } /** @overload */ template inline void setSubData(GLintptr offset, const std::array& data) { - setSubData(_defaultTarget, offset, data); - } - - /** - * @brief Set buffer subdata - * @param target %Target - * @param offset Offset in the buffer - * @param size Data size - * @param data Pointer to data - * - * @see bind(Target), @fn_gl{BufferSubData} - */ - inline void setSubData(Target target, GLintptr offset, GLsizeiptr size, const GLvoid* data) { - bind(target); - glBufferSubData(static_cast(target), offset, size, data); - } - - /** - * @brief Set buffer subdata - * @param target %Target - * @param offset Offset in the buffer - * @param data Fixed-size array with data - * - * More convenient for setting data from fixed-size arrays than - * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*). - * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) - */ - template inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) { - setSubData(target, offset, size*sizeof(T), data); - } - - /** - * @brief Set buffer subdata - * @param target %Target - * @param offset Offset in the buffer - * @param data Vector with data - * - * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) - */ - template inline void setSubData(Target target, GLintptr offset, const std::vector& data) { - setSubData(target, offset, data.size()*sizeof(T), data.data()); - } - - /** @overload */ - template inline void setSubData(Target target, GLintptr offset, const std::array& data) { - setSubData(target, offset, data.size()*sizeof(T), data.data()); + setSubData(offset, data.size()*sizeof(T), data.data()); } private: diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index 7a8b80936..54fdeb03a 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -21,7 +21,7 @@ template void BufferedImage::setData(const _components = components; _type = type; _size = size; - _buffer.setData(Buffer::Target::PixelPack, pixelSize(_components, _type)*size.product(), data, usage); + _buffer.setData(pixelSize(_components, _type)*size.product(), data, usage); } template class BufferedImage<1>; From 7004ebdd50f18ec239a3ec3dc2bb58cc6b24e473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 19:55:26 +0200 Subject: [PATCH 165/256] Using EXT_direct_state_access also for Buffer::set*Data(). --- src/Buffer.cpp | 22 ++++++++++++++++++++++ src/Buffer.h | 24 ++++++++++++++++++------ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 7c7a60e83..e5486e0db 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -23,12 +23,16 @@ namespace Magnum { Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault; +Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; +Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; void Buffer::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; copyImplementation = &Buffer::copyImplementationDSA; + setDataImplementation = &Buffer::setDataImplementationDSA; + setSubDataImplementation = &Buffer::setSubDataImplementationDSA; } } @@ -42,4 +46,22 @@ void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOff glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size); } +void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { + bind(); + glBufferData(static_cast(_defaultTarget), size, data, static_cast(usage)); +} + +void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { + glNamedBufferDataEXT(_id, size, data, static_cast(usage)); +} + +void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { + bind(); + glBufferSubData(static_cast(_defaultTarget), offset, size, data); +} + +void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { + glNamedBufferSubDataEXT(_id, offset, size, data); +} + } diff --git a/src/Buffer.h b/src/Buffer.h index 57b4eebe4..f14583c0c 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -311,11 +311,12 @@ class MAGNUM_EXPORT Buffer { * @param data Pointer to data * @param usage %Buffer usage * - * @see bind(), @fn_gl{BufferData} + * If @extension{EXT,direct_state_access} is not available, the buffer + * is bound to default target before the operation. + * @see bind(), @fn_gl{BufferData} or @fn_gl_extension{NamedBufferData,EXT,direct_state_access} */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { - bind(); - glBufferData(static_cast(_defaultTarget), size, data, static_cast(usage)); + (this->*Magnum::Buffer::setDataImplementation)(size, data, usage); } /** @@ -351,11 +352,12 @@ class MAGNUM_EXPORT Buffer { * @param size Data size * @param data Pointer to data * - * @see bind(), @fn_gl{BufferSubData} + * If @extension{EXT,direct_state_access} is not available, the buffer + * is bound to default target before the operation. + * @see bind(), @fn_gl{BufferSubData} or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} */ inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { - bind(); - glBufferSubData(static_cast(_defaultTarget), offset, size, data); + (this->*setSubDataImplementation)(offset, size, data); } /** @@ -393,6 +395,16 @@ class MAGNUM_EXPORT Buffer { static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); static CopyImplementation copyImplementation; + typedef void(Buffer::*SetDataImplementation)(GLsizeiptr, const GLvoid*, Usage); + void MAGNUM_LOCAL setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Usage usage); + void MAGNUM_LOCAL setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Usage usage); + static SetDataImplementation setDataImplementation; + + typedef void(Buffer::*SetSubDataImplementation)(GLintptr, GLsizeiptr, const GLvoid*); + void MAGNUM_LOCAL setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data); + void MAGNUM_LOCAL setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data); + static SetSubDataImplementation setSubDataImplementation; + GLuint _id; Target _defaultTarget; }; From 4d8825bee0b3ff8d97ab4b73fddbb68def4be616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 23:03:09 +0200 Subject: [PATCH 166/256] Removed WTF todo. It was the case only for ES. --- src/IndexedMesh.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 25f56e9b6..5b9deec23 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -88,7 +88,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * * Expects an active shader with all uniforms set. * @see Buffer::bind(), bind(), unbind(), finalize(), @fn_gl{DrawElements} - * @todo Index buffer bound every time?! */ void draw(); From 193246e5339d83499657120d924a280f90171e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 23:55:00 +0200 Subject: [PATCH 167/256] Private (implementation-only) OpenGL state tracker. --- src/CMakeLists.txt | 2 ++ src/Context.cpp | 5 +++++ src/Context.h | 12 ++++++++++++ src/Implementation/State.cpp | 25 +++++++++++++++++++++++++ src/Implementation/State.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 src/Implementation/State.cpp create mode 100644 src/Implementation/State.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2e867e56..6f1d45eaa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,8 @@ set(Magnum_SRCS Timeline.cpp TypeTraits.cpp + Implementation/State.cpp + Trade/AbstractImporter.cpp Trade/MeshData2D.cpp Trade/MeshData3D.cpp) diff --git a/src/Context.cpp b/src/Context.cpp index 3a46b7638..92247c051 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -21,6 +21,7 @@ #include "Buffer.h" #include "Extensions.h" +#include "Implementation/State.h" using namespace std; @@ -193,12 +194,16 @@ Context::Context() { CORRADE_ASSERT(!_current, "Context: Another context currently active", ); _current = this; + /* Initialize state tracker */ + _state = new Implementation::State; + /* Initialize functionality based on current OpenGL version and extensions */ Buffer::initializeContextBasedFunctionality(this); } Context::~Context() { CORRADE_ASSERT(_current == this, "Context: Cannot destroy context which is not currently active", ); + delete _state; _current = nullptr; } diff --git a/src/Context.h b/src/Context.h index 820b998e5..3ac3de27e 100644 --- a/src/Context.h +++ b/src/Context.h @@ -28,6 +28,12 @@ namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + class State; +} +#endif + /** @brief OpenGL version */ enum class Version: GLint { None = 0, /**< @brief Unspecified */ @@ -202,6 +208,10 @@ class MAGNUM_EXPORT Context { return _version >= extension._coreVersion || (_version >= extension._requiredVersion && extensionStatus[extension._index]); } + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Implementation::State* state() { return _state; } + #endif + private: static Context* _current; @@ -211,6 +221,8 @@ class MAGNUM_EXPORT Context { std::bitset<128> extensionStatus; std::vector _supportedExtensions; + + Implementation::State* _state; }; } diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp new file mode 100644 index 000000000..2fb89de2d --- /dev/null +++ b/src/Implementation/State.cpp @@ -0,0 +1,25 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "State.h" + +namespace Magnum { namespace Implementation { + +State::State() {} + +State::~State() { +} + +}} diff --git a/src/Implementation/State.h b/src/Implementation/State.h new file mode 100644 index 000000000..8a070d47d --- /dev/null +++ b/src/Implementation/State.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Implementation_State_h +#define Magnum_Implementation_State_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +namespace Magnum { namespace Implementation { + +class BufferState; + +struct State { + State(); + ~State(); +}; + +}} + +#endif From 6b3781b97fc2f62e0c168b43c42664ee558dd3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 23:56:32 +0200 Subject: [PATCH 168/256] Tracking Buffer state. Reduces OpenGL call count if subsequently binding the same Buffer into the same Target. --- src/Buffer.cpp | 50 ++++++++++++++++++++---- src/Buffer.h | 15 +++---- src/CMakeLists.txt | 1 + src/Implementation/BufferState.cpp | 63 ++++++++++++++++++++++++++++++ src/Implementation/BufferState.h | 43 ++++++++++++++++++++ src/Implementation/State.cpp | 5 ++- src/Implementation/State.h | 4 +- 7 files changed, 163 insertions(+), 18 deletions(-) create mode 100644 src/Implementation/BufferState.cpp create mode 100644 src/Implementation/BufferState.h diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e5486e0db..5ecefd2e8 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -19,6 +19,8 @@ #include "Context.h" #include "Extensions.h" +#include "Implementation/State.h" +#include "Implementation/BufferState.h" namespace Magnum { @@ -36,10 +38,46 @@ void Buffer::initializeContextBasedFunctionality(Context* context) { } } +Buffer::~Buffer() { + GLuint* bindings = Context::current()->state()->buffer->bindings; + + /* Remove all current bindings from the state */ + for(std::size_t i = 1; i != Implementation::BufferState::TargetCount; ++i) + if(bindings[i] == _id) bindings[i] = 0; + + glDeleteBuffers(1, &_id); +} + +void Buffer::bind(Target target, GLuint id) { + GLuint& bound = Context::current()->state()->buffer->bindings[Implementation::BufferState::indexForTarget(target)]; + + /* Already bound, nothing to do */ + if(bound == id) return; + + /* Bind the buffer otherwise */ + bound = id; + glBindBuffer(static_cast(target), id); +} + +Buffer::Target Buffer::bindInternal(Target hint) { + GLuint* bindings = Context::current()->state()->buffer->bindings; + GLuint& hintBinding = bindings[Implementation::BufferState::indexForTarget(hint)]; + + /* Shortcut - if already bound to hint, return */ + if(hintBinding == _id) return hint; + + /* Return first target in which the buffer is bound */ + for(std::size_t i = 1; i != Implementation::BufferState::TargetCount; ++i) + if(bindings[i] == _id) return Implementation::BufferState::targetForIndex[i]; + + /* Bind the buffer to hint target otherwise */ + hintBinding = _id; + glBindBuffer(static_cast(hint), _id); + return hint; +} + void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { - read->bind(Target::CopyRead); - write->bind(Target::CopyWrite); - glCopyBufferSubData(static_cast(Target::CopyRead), static_cast(Target::CopyWrite), readOffset, writeOffset, size); + glCopyBufferSubData(static_cast(read->bindInternal(Target::CopyRead)), static_cast(write->bindInternal(Target::CopyWrite)), readOffset, writeOffset, size); } void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { @@ -47,8 +85,7 @@ void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOff } void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { - bind(); - glBufferData(static_cast(_defaultTarget), size, data, static_cast(usage)); + glBufferData(static_cast(bindInternal(_defaultTarget)), size, data, static_cast(usage)); } void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { @@ -56,8 +93,7 @@ void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffe } void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { - bind(); - glBufferSubData(static_cast(_defaultTarget), offset, size, data); + glBufferSubData(static_cast(bindInternal(_defaultTarget)), offset, size, data); } void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { diff --git a/src/Buffer.h b/src/Buffer.h index f14583c0c..e4747aa69 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -236,9 +236,7 @@ class MAGNUM_EXPORT Buffer { * * @see @fn_gl{BindBuffer} */ - inline static void unbind(Target target) { - glBindBuffer(static_cast(target), 0); - } + inline static void unbind(Target target) { bind(target, 0); } /** * @brief Copy one buffer to another @@ -277,9 +275,7 @@ class MAGNUM_EXPORT Buffer { * Deletes associated OpenGL buffer. * @see @fn_gl{DeleteBuffers} */ - inline virtual ~Buffer() { - glDeleteBuffers(1, &_id); - } + virtual ~Buffer(); /** @brief Default bind type */ inline Target defaultTarget() const { return _defaultTarget; } @@ -301,9 +297,7 @@ class MAGNUM_EXPORT Buffer { * * @see @fn_gl{BindBuffer} */ - inline void bind(Target target) { - glBindBuffer(static_cast(target), _id); - } + inline void bind(Target target) { bind(target, _id); } /** * @brief Set buffer data @@ -390,6 +384,9 @@ class MAGNUM_EXPORT Buffer { private: static void initializeContextBasedFunctionality(Context* context); + static void bind(Target hint, GLuint id); + Target bindInternal(Target hint); + typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr); static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f1d45eaa..b3a5f3c80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,7 @@ set(Magnum_SRCS Timeline.cpp TypeTraits.cpp + Implementation/BufferState.cpp Implementation/State.cpp Trade/AbstractImporter.cpp diff --git a/src/Implementation/BufferState.cpp b/src/Implementation/BufferState.cpp new file mode 100644 index 000000000..b8ef09cd4 --- /dev/null +++ b/src/Implementation/BufferState.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "BufferState.h" + +#include + +namespace Magnum { namespace Implementation { + +const Buffer::Target BufferState::targetForIndex[] = { + Buffer::Target::Array, + Buffer::Target::CopyRead, + Buffer::Target::CopyWrite, + Buffer::Target::ElementArray, + Buffer::Target::PixelPack, + Buffer::Target::PixelUnpack, + Buffer::Target::TransformFeedback, + Buffer::Target::Uniform, + #ifndef MAGNUM_TARGET_GLES + Buffer::Target::AtomicCounter, + Buffer::Target::DispatchIndirect, + Buffer::Target::DrawIndirect, + Buffer::Target::ShaderStorage, + Buffer::Target::Texture + #endif +}; + +std::size_t BufferState::indexForTarget(Buffer::Target target) { + switch(target) { + case Buffer::Target::Array: return 1; + case Buffer::Target::CopyRead: return 2; + case Buffer::Target::CopyWrite: return 3; + case Buffer::Target::ElementArray: return 4; + case Buffer::Target::PixelPack: return 5; + case Buffer::Target::PixelUnpack: return 6; + case Buffer::Target::TransformFeedback: return 7; + case Buffer::Target::Uniform: return 8; + #ifndef MAGNUM_TARGET_GLES + case Buffer::Target::AtomicCounter: return 9; + case Buffer::Target::DispatchIndirect: return 10; + case Buffer::Target::DrawIndirect: return 11; + case Buffer::Target::ShaderStorage: return 12; + case Buffer::Target::Texture: return 13; + #endif + } + + CORRADE_ASSERT(false, "Unknown Buffer target", 0); + return 0; +} + +}} diff --git a/src/Implementation/BufferState.h b/src/Implementation/BufferState.h new file mode 100644 index 000000000..3ea1e551b --- /dev/null +++ b/src/Implementation/BufferState.h @@ -0,0 +1,43 @@ +#ifndef Magnum_Implementation_BufferState_h +#define Magnum_Implementation_BufferState_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +#include "Buffer.h" + +namespace Magnum { namespace Implementation { + +struct BufferState { + #ifndef MAGNUM_TARGET_GLES + static const std::size_t TargetCount = 13+1; + #else + static const std::size_t TargetCount = 8+1; + #endif + + /* Target <-> index mapping */ + static std::size_t indexForTarget(Buffer::Target target); + static const Buffer::Target targetForIndex[TargetCount-1]; + + inline constexpr BufferState(): bindings() {} + + /* Currently bound buffer for all targets */ + GLuint bindings[TargetCount]; +}; + +}} + +#endif diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index 2fb89de2d..daf8b4cab 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -15,11 +15,14 @@ #include "State.h" +#include "BufferState.h" + namespace Magnum { namespace Implementation { -State::State() {} +State::State(): buffer(new BufferState) {} State::~State() { + delete buffer; } }} diff --git a/src/Implementation/State.h b/src/Implementation/State.h index 8a070d47d..a3438b028 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -19,11 +19,13 @@ namespace Magnum { namespace Implementation { -class BufferState; +struct BufferState; struct State { State(); ~State(); + + BufferState* const buffer; }; }} From 2dde4b9bf8bd7f479e60fbd4a6251c4e5997575c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 00:17:27 +0200 Subject: [PATCH 169/256] Tracking AbstractShaderProgram state. Reduces OpenGL call count when subsequently using the same shader for rendering. --- src/AbstractShaderProgram.cpp | 18 +++++++++++++- src/AbstractShaderProgram.h | 2 -- src/Implementation/ShaderProgramState.h | 31 +++++++++++++++++++++++++ src/Implementation/State.cpp | 4 +++- src/Implementation/State.h | 2 ++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/Implementation/ShaderProgramState.h diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 0dccdc4a3..feddb2c8a 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -18,6 +18,8 @@ #include #include "Shader.h" +#include "Implementation/State.h" +#include "Implementation/ShaderProgramState.h" #define LINKER_MESSAGE_MAX_LENGTH 1024 @@ -25,10 +27,24 @@ using namespace std; namespace Magnum { +AbstractShaderProgram::~AbstractShaderProgram() { + /* Remove current usage from the state */ + GLuint& current = Context::current()->state()->shaderProgram->current; + if(current == _id) + current = 0; + + glDeleteProgram(_id); +} + bool AbstractShaderProgram::use() { if(state != Linked) return false; - glUseProgram(_id); + /* Use only if the program isn't already in use */ + GLuint& current = Context::current()->state()->shaderProgram->current; + if(current != _id) { + current = _id; + glUseProgram(_id); + } return true; } diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index d9140fdf9..fbe4dcb9b 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -642,8 +642,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { State state; }; -inline AbstractShaderProgram::~AbstractShaderProgram() { glDeleteProgram(_id); } - } #endif diff --git a/src/Implementation/ShaderProgramState.h b/src/Implementation/ShaderProgramState.h new file mode 100644 index 000000000..d81af0aca --- /dev/null +++ b/src/Implementation/ShaderProgramState.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Implementation_ShaderProgramState_h +#define Magnum_Implementation_ShaderProgramState_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +namespace Magnum { namespace Implementation { + +struct ShaderProgramState { + inline constexpr ShaderProgramState(): current(0) {} + + /* Currently used program */ + GLuint current; +}; + +}} + +#endif diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index daf8b4cab..5c3ead774 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -16,12 +16,14 @@ #include "State.h" #include "BufferState.h" +#include "ShaderProgramState.h" namespace Magnum { namespace Implementation { -State::State(): buffer(new BufferState) {} +State::State(): buffer(new BufferState), shaderProgram(new ShaderProgramState) {} State::~State() { + delete shaderProgram; delete buffer; } diff --git a/src/Implementation/State.h b/src/Implementation/State.h index a3438b028..8330fb7bd 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -20,12 +20,14 @@ namespace Magnum { namespace Implementation { struct BufferState; +struct ShaderProgramState; struct State { State(); ~State(); BufferState* const buffer; + ShaderProgramState* const shaderProgram; }; }} From beea8235b1590446153ca1eb51874d9a35e03ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 16:55:03 +0200 Subject: [PATCH 170/256] Using EXT_direct_state_access/ARB_separate_shader_objects for uniforms. Also explicitly calling use() on default (non-DSA) setUniform() implementation. Because of that, it is now possible to conveniently call use() at the end, instead of at the beginning of uniform setting chain, for example: // before shader->use(); shader->setTransformation(transformation) ->setProjection(projection) ->setColor(color); // now shader->setTransformation(transformation) ->setProjection(projection) ->setColor(color) ->use(); Note that you still have to explicitly call use(), because if DSA is available, no use() is called explicitly on any setUniform(). If DSA is not available, use() is called on first setUniform() and subsequent calls have no negative performance impacts. --- src/AbstractShaderProgram.cpp | 399 ++++++++++++++++++++++++++++++++++ src/AbstractShaderProgram.h | 283 +++++++++++++++++++----- src/Context.cpp | 2 + 3 files changed, 626 insertions(+), 58 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index feddb2c8a..f6c42240d 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -17,9 +17,11 @@ #include +#include "Math/Matrix.h" #include "Shader.h" #include "Implementation/State.h" #include "Implementation/ShaderProgramState.h" +#include "Extensions.h" #define LINKER_MESSAGE_MAX_LENGTH 1024 @@ -27,6 +29,46 @@ using namespace std; namespace Magnum { +AbstractShaderProgram::Uniform1fImplementation AbstractShaderProgram::uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform2fvImplementation AbstractShaderProgram::uniform2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform3fvImplementation AbstractShaderProgram::uniform3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform4fvImplementation AbstractShaderProgram::uniform4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform1iImplementation AbstractShaderProgram::uniform1iImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform2ivImplementation AbstractShaderProgram::uniform2ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform3ivImplementation AbstractShaderProgram::uniform3ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform4ivImplementation AbstractShaderProgram::uniform4ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform1uiImplementation AbstractShaderProgram::uniform1uiImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform2uivImplementation AbstractShaderProgram::uniform2uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform3uivImplementation AbstractShaderProgram::uniform3uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform4uivImplementation AbstractShaderProgram::uniform4uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#ifndef MAGNUM_TARGET_GLES +AbstractShaderProgram::Uniform1dImplementation AbstractShaderProgram::uniform1dImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform2dvImplementation AbstractShaderProgram::uniform2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform3dvImplementation AbstractShaderProgram::uniform3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::Uniform4dvImplementation AbstractShaderProgram::uniform4dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#endif + +AbstractShaderProgram::UniformMatrix2fvImplementation AbstractShaderProgram::uniformMatrix2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3fvImplementation AbstractShaderProgram::uniformMatrix3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4fvImplementation AbstractShaderProgram::uniformMatrix4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix2x3fvImplementation AbstractShaderProgram::uniformMatrix2x3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3x2fvImplementation AbstractShaderProgram::uniformMatrix3x2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix2x4fvImplementation AbstractShaderProgram::uniformMatrix2x4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4x2fvImplementation AbstractShaderProgram::uniformMatrix4x2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3x4fvImplementation AbstractShaderProgram::uniformMatrix3x4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4x3fvImplementation AbstractShaderProgram::uniformMatrix4x3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#ifndef MAGNUM_TARGET_GLES +AbstractShaderProgram::UniformMatrix2dvImplementation AbstractShaderProgram::uniformMatrix2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3dvImplementation AbstractShaderProgram::uniformMatrix3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4dvImplementation AbstractShaderProgram::uniformMatrix4dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix2x3dvImplementation AbstractShaderProgram::uniformMatrix2x3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3x2dvImplementation AbstractShaderProgram::uniformMatrix3x2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix2x4dvImplementation AbstractShaderProgram::uniformMatrix2x4dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4x2dvImplementation AbstractShaderProgram::uniformMatrix4x2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix3x4dvImplementation AbstractShaderProgram::uniformMatrix3x4dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +AbstractShaderProgram::UniformMatrix4x3dvImplementation AbstractShaderProgram::uniformMatrix4x3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#endif + AbstractShaderProgram::~AbstractShaderProgram() { /* Remove current usage from the state */ GLuint& current = Context::current()->state()->shaderProgram->current; @@ -114,4 +156,361 @@ GLint AbstractShaderProgram::uniformLocation(const std::string& name) { return location; } +void AbstractShaderProgram::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported() || + context->isExtensionSupported()) { + Debug() << "AbstractShaderProgram: using" << (context->isExtensionSupported() ? + Extensions::GL::ARB::separate_shader_objects::string() : Extensions::GL::EXT::direct_state_access::string()) << "features"; + uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform4fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform1iImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform2ivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform3ivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform4ivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform1uiImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform2uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform3uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform4uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; + #ifndef MAGNUM_TARGET_GLES + uniform1dImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniform4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + #endif + + uniformMatrix2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix2x3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3x2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix2x4fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4x2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3x4fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4x3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + #ifndef MAGNUM_TARGET_GLES + uniformMatrix2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix2x3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3x2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix2x4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4x2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix3x4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + uniformMatrix4x3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; + #endif + } +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLfloat value) { + use(); + glUniform1f(location, value); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLfloat value) { + glProgramUniform1f(_id, location, value); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLfloat>& value) { + use(); + glUniform2fv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLfloat>& value) { + glProgramUniform2fv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLfloat>& value) { + use(); + glUniform3fv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLfloat>& value) { + glProgramUniform3fv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLfloat>& value) { + use(); + glUniform4fv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLfloat>& value) { + glProgramUniform4fv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLint value) { + use(); + glUniform1i(location, value); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLint value) { + glProgramUniform1i(_id, location, value); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLint>& value) { + use(); + glUniform2iv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLint>& value) { + glProgramUniform2iv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLint>& value) { + use(); + glUniform3iv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLint>& value) { + glProgramUniform3iv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLint>& value) { + use(); + glUniform4iv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLint>& value) { + glProgramUniform4iv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLuint value) { + use(); + glUniform1ui(location, value); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLuint value) { + glProgramUniform1ui(_id, location, value); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLuint>& value) { + use(); + glUniform2uiv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLuint>& value) { + glProgramUniform2uiv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLuint>& value) { + use(); + glUniform3uiv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLuint>& value) { + glProgramUniform3uiv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLuint>& value) { + use(); + glUniform4uiv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLuint>& value) { + glProgramUniform4uiv(_id, location, 1, value.data()); +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLdouble value) { + use(); + glUniform1d(location, value); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLdouble value) { + glProgramUniform1d(_id, location, value); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLdouble>& value) { + use(); + glUniform2dv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLdouble>& value) { + glProgramUniform2dv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLdouble>& value) { + use(); + glUniform3dv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLdouble>& value) { + glProgramUniform3dv(_id, location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLdouble>& value) { + use(); + glUniform4dv(location, 1, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLdouble>& value) { + glProgramUniform4dv(_id, location, 1, value.data()); +} +#endif + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<2, GLfloat>& value) { + use(); + glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<2, GLfloat>& value) { + glProgramUniformMatrix2fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<3, GLfloat>& value) { + use(); + glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<3, GLfloat>& value) { + glProgramUniformMatrix3fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<4, GLfloat>& value) { + use(); + glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<4, GLfloat>& value) { + glProgramUniformMatrix4fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { + use(); + glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { + glProgramUniformMatrix2x3fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { + use(); + glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { + glProgramUniformMatrix3x2fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { + use(); + glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { + glProgramUniformMatrix2x4fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { + use(); + glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { + glProgramUniformMatrix4x2fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { + use(); + glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { + glProgramUniformMatrix3x4fv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { + use(); + glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { + glProgramUniformMatrix4x3fv(_id, location, 1, GL_FALSE, value.data()); +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<2, GLdouble>& value) { + use(); + glUniformMatrix2dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<2, GLdouble>& value) { + glProgramUniformMatrix2dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<3, GLdouble>& value) { + use(); + glUniformMatrix3dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<3, GLdouble>& value) { + glProgramUniformMatrix3dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<4, GLdouble>& value) { + use(); + glUniformMatrix4dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<4, GLdouble>& value) { + glProgramUniformMatrix4dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { + use(); + glUniformMatrix2x3dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { + glProgramUniformMatrix2x3dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { + use(); + glUniformMatrix3x2dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { + glProgramUniformMatrix3x2dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { + use(); + glUniformMatrix2x4dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { + glProgramUniformMatrix2x4dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { + use(); + glUniformMatrix4x2dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { + glProgramUniformMatrix4x2dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { + use(); + glUniformMatrix3x4dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { + glProgramUniformMatrix3x4dv(_id, location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { + use(); + glUniformMatrix4x3dv(location, 1, GL_FALSE, value.data()); +} + +void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { + glProgramUniformMatrix4x3dv(_id, location, 1, GL_FALSE, value.data()); +} +#endif + } diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index fbe4dcb9b..57d36c8e5 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -19,15 +19,22 @@ * @brief Class Magnum::AbstractShaderProgram */ -#include +#include +#include -#include "Math/RectangularMatrix.h" #include "Magnum.h" #include "magnumVisibility.h" namespace Magnum { +namespace Math { + template class RectangularMatrix; + template class Matrix; + template class Vector; +} + +class Context; class Shader; /** @@ -191,9 +198,10 @@ void draw(const Magnum::Matrix4& transformationMatrix, Magnum::Camera* camera) { @endcode @todo Uniform arrays support -@todo DSA for uniforms - glProgramUniform*() (OpenGL 4.1, @extension{ARB,separate_shader_objects}) */ class MAGNUM_EXPORT AbstractShaderProgram { + friend class Context; + AbstractShaderProgram(const AbstractShaderProgram& other) = delete; AbstractShaderProgram(AbstractShaderProgram&& other) = delete; AbstractShaderProgram& operator=(const AbstractShaderProgram& other) = delete; @@ -232,7 +240,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { virtual ~AbstractShaderProgram() = 0; /** - * @brief Use shader + * @brief Use shader for rendering * @return False if the program wasn't successfully linked, true * otherwise. * @@ -369,46 +377,49 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @param location Uniform location (see uniformLocation()) * @param value Value * - * @attention This function doesn't check whether this shader is in use! - * @see @fn_gl{Uniform} + * If neither @extension{ARB,separate_shader_objects} nor + * @extension{EXT,direct_state_access} is available, use() is called + * before the operation. + * @see use(), @fn_gl{Uniform} or `glProgramUniform()` from + * @extension{ARB,separate_shader_objects}/@extension{EXT,direct_state_access}. */ inline void setUniform(GLint location, GLfloat value) { - glUniform1f(location, value); + (this->*uniform1fImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLfloat>& value) { - glUniform2fv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<2, GLfloat>& value) { + (this->*uniform2fvImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLfloat>& value) { - glUniform3fv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<3, GLfloat>& value) { + (this->*uniform3fvImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLfloat>& value) { - glUniform4fv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<4, GLfloat>& value) { + (this->*uniform4fvImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ inline void setUniform(GLint location, GLint value) { - glUniform1i(location, value); + (this->*uniform1iImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLint>& value) { - glUniform2iv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<2, GLint>& value) { + (this->*uniform2ivImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLint>& value) { - glUniform3iv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<3, GLint>& value) { + (this->*uniform3ivImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLint>& value) { - glUniform4iv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<4, GLint>& value) { + (this->*uniform4ivImplementation)(location, value); } /** @@ -417,7 +428,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, GLuint value) { - glUniform1ui(location, value); + (this->*uniform1uiImplementation)(location, value); } /** @@ -425,8 +436,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLuint>& value) { - glUniform2uiv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<2, GLuint>& value) { + (this->*uniform2uivImplementation)(location, value); } /** @@ -434,8 +445,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLuint>& value) { - glUniform3uiv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<3, GLuint>& value) { + (this->*uniform3uivImplementation)(location, value); } /** @@ -443,8 +454,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 Extension @extension{EXT,gpu_shader4} * @requires_gles30 (no extension providing this functionality) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLuint>& value) { - glUniform4uiv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<4, GLuint>& value) { + (this->*uniform4uivImplementation)(location, value); } #ifndef MAGNUM_TARGET_GLES @@ -454,7 +465,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, GLdouble value) { - glUniform1d(location, value); + (this->*uniform1dImplementation)(location, value); } /** @@ -462,8 +473,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 2, GLdouble>& value) { - glUniform2dv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<2, GLdouble>& value) { + (this->*uniform2dvImplementation)(location, value); } /** @@ -471,8 +482,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 3, GLdouble>& value) { - glUniform3dv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<3, GLdouble>& value) { + (this->*uniform3dvImplementation)(location, value); } /** @@ -480,24 +491,24 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<1, 4, GLdouble>& value) { - glUniform4dv(location, 1, value.data()); + inline void setUniform(GLint location, const Math::Vector<4, GLdouble>& value) { + (this->*uniform4dvImplementation)(location, value); } #endif /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLfloat>& value) { - glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<2, GLfloat>& value) { + (this->*uniformMatrix2fvImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 3, GLfloat>& value) { - glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<3, GLfloat>& value) { + (this->*uniformMatrix3fvImplementation)(location, value); } /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 4, GLfloat>& value) { - glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<4, GLfloat>& value) { + (this->*uniformMatrix4fvImplementation)(location, value); } /** @@ -505,7 +516,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { - glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix2x3fvImplementation)(location, value); } /** @@ -513,7 +524,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { - glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix3x2fvImplementation)(location, value); } /** @@ -521,7 +532,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { - glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix2x4fvImplementation)(location, value); } /** @@ -529,7 +540,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { - glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix4x2fvImplementation)(location, value); } /** @@ -537,7 +548,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { - glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix3x4fvImplementation)(location, value); } /** @@ -545,7 +556,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gles30 (no extension providing this functionality) */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { - glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix4x3fvImplementation)(location, value); } #ifndef MAGNUM_TARGET_GLES @@ -554,8 +565,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 2, GLdouble>& value) { - glUniformMatrix2dv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<2, GLdouble>& value) { + (this->*uniformMatrix2dvImplementation)(location, value); } /** @@ -563,8 +574,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 3, GLdouble>& value) { - glUniformMatrix3dv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<3, GLdouble>& value) { + (this->*uniformMatrix3dvImplementation)(location, value); } /** @@ -572,8 +583,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 4, GLdouble>& value) { - glUniformMatrix4dv(location, 1, GL_FALSE, value.data()); + inline void setUniform(GLint location, const Math::Matrix<4, GLdouble>& value) { + (this->*uniformMatrix4dvImplementation)(location, value); } /** @@ -582,7 +593,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { - glUniformMatrix2x3dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix2x3dvImplementation)(location, value); } /** @@ -591,7 +602,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { - glUniformMatrix3x2dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix3x2dvImplementation)(location, value); } /** @@ -600,7 +611,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { - glUniformMatrix2x4dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix2x4dvImplementation)(location, value); } /** @@ -609,7 +620,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { - glUniformMatrix4x2dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix4x2dvImplementation)(location, value); } /** @@ -618,7 +629,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { - glUniformMatrix3x4dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix3x4dvImplementation)(location, value); } /** @@ -627,7 +638,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { - glUniformMatrix4x3dv(location, 1, GL_FALSE, value.data()); + (this->*uniformMatrix4x3dvImplementation)(location, value); } #endif @@ -638,6 +649,162 @@ class MAGNUM_EXPORT AbstractShaderProgram { Failed }; + static void initializeContextBasedFunctionality(Context* context); + + typedef void(AbstractShaderProgram::*Uniform1fImplementation)(GLint, GLfloat); + typedef void(AbstractShaderProgram::*Uniform2fvImplementation)(GLint, const Math::Vector<2, GLfloat>&); + typedef void(AbstractShaderProgram::*Uniform3fvImplementation)(GLint, const Math::Vector<3, GLfloat>&); + typedef void(AbstractShaderProgram::*Uniform4fvImplementation)(GLint, const Math::Vector<4, GLfloat>&); + typedef void(AbstractShaderProgram::*Uniform1iImplementation)(GLint, GLint); + typedef void(AbstractShaderProgram::*Uniform2ivImplementation)(GLint, const Math::Vector<2, GLint>&); + typedef void(AbstractShaderProgram::*Uniform3ivImplementation)(GLint, const Math::Vector<3, GLint>&); + typedef void(AbstractShaderProgram::*Uniform4ivImplementation)(GLint, const Math::Vector<4, GLint>&); + typedef void(AbstractShaderProgram::*Uniform1uiImplementation)(GLint, GLuint); + typedef void(AbstractShaderProgram::*Uniform2uivImplementation)(GLint, const Math::Vector<2, GLuint>&); + typedef void(AbstractShaderProgram::*Uniform3uivImplementation)(GLint, const Math::Vector<3, GLuint>&); + typedef void(AbstractShaderProgram::*Uniform4uivImplementation)(GLint, const Math::Vector<4, GLuint>&); + #ifndef MAGNUM_TARGET_GLES + typedef void(AbstractShaderProgram::*Uniform1dImplementation)(GLint, GLdouble); + typedef void(AbstractShaderProgram::*Uniform2dvImplementation)(GLint, const Math::Vector<2, GLdouble>&); + typedef void(AbstractShaderProgram::*Uniform3dvImplementation)(GLint, const Math::Vector<3, GLdouble>&); + typedef void(AbstractShaderProgram::*Uniform4dvImplementation)(GLint, const Math::Vector<4, GLdouble>&); + #endif + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLfloat value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLint value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLuint value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLuint>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLuint>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLuint>& value); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLdouble value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLdouble>& value); + #endif + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLfloat value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLint value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<4, GLint>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLuint value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLuint>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLuint>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<4, GLuint>& value); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLdouble value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<4, GLdouble>& value); + #endif + static Uniform1fImplementation uniform1fImplementation; + static Uniform2fvImplementation uniform2fvImplementation; + static Uniform3fvImplementation uniform3fvImplementation; + static Uniform4fvImplementation uniform4fvImplementation; + static Uniform1iImplementation uniform1iImplementation; + static Uniform2ivImplementation uniform2ivImplementation; + static Uniform3ivImplementation uniform3ivImplementation; + static Uniform4ivImplementation uniform4ivImplementation; + static Uniform1uiImplementation uniform1uiImplementation; + static Uniform2uivImplementation uniform2uivImplementation; + static Uniform3uivImplementation uniform3uivImplementation; + static Uniform4uivImplementation uniform4uivImplementation; + #ifndef MAGNUM_TARGET_GLES + static Uniform1dImplementation uniform1dImplementation; + static Uniform2dvImplementation uniform2dvImplementation; + static Uniform3dvImplementation uniform3dvImplementation; + static Uniform4dvImplementation uniform4dvImplementation; + #endif + + typedef void(AbstractShaderProgram::*UniformMatrix2fvImplementation)(GLint, const Math::Matrix<2, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix3fvImplementation)(GLint, const Math::Matrix<3, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix4fvImplementation)(GLint, const Math::Matrix<4, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix2x3fvImplementation)(GLint, const Math::RectangularMatrix<2, 3, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix3x2fvImplementation)(GLint, const Math::RectangularMatrix<3, 2, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix2x4fvImplementation)(GLint, const Math::RectangularMatrix<2, 4, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix4x2fvImplementation)(GLint, const Math::RectangularMatrix<4, 2, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix3x4fvImplementation)(GLint, const Math::RectangularMatrix<3, 4, GLfloat>&); + typedef void(AbstractShaderProgram::*UniformMatrix4x3fvImplementation)(GLint, const Math::RectangularMatrix<4, 3, GLfloat>&); + #ifndef MAGNUM_TARGET_GLES + typedef void(AbstractShaderProgram::*UniformMatrix2dvImplementation)(GLint, const Math::Matrix<2, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix3dvImplementation)(GLint, const Math::Matrix<3, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix4dvImplementation)(GLint, const Math::Matrix<4, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix2x3dvImplementation)(GLint, const Math::RectangularMatrix<2, 3, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix3x2dvImplementation)(GLint, const Math::RectangularMatrix<3, 2, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix2x4dvImplementation)(GLint, const Math::RectangularMatrix<2, 4, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix4x2dvImplementation)(GLint, const Math::RectangularMatrix<4, 2, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix3x4dvImplementation)(GLint, const Math::RectangularMatrix<3, 4, GLdouble>&); + typedef void(AbstractShaderProgram::*UniformMatrix4x3dvImplementation)(GLint, const Math::RectangularMatrix<4, 3, GLdouble>&); + #endif + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value); + #endif + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value); + void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value); + #endif + static UniformMatrix2fvImplementation uniformMatrix2fvImplementation; + static UniformMatrix3fvImplementation uniformMatrix3fvImplementation; + static UniformMatrix4fvImplementation uniformMatrix4fvImplementation; + static UniformMatrix2x3fvImplementation uniformMatrix2x3fvImplementation; + static UniformMatrix3x2fvImplementation uniformMatrix3x2fvImplementation; + static UniformMatrix2x4fvImplementation uniformMatrix2x4fvImplementation; + static UniformMatrix4x2fvImplementation uniformMatrix4x2fvImplementation; + static UniformMatrix3x4fvImplementation uniformMatrix3x4fvImplementation; + static UniformMatrix4x3fvImplementation uniformMatrix4x3fvImplementation; + #ifndef MAGNUM_TARGET_GLES + static UniformMatrix2dvImplementation uniformMatrix2dvImplementation; + static UniformMatrix3dvImplementation uniformMatrix3dvImplementation; + static UniformMatrix4dvImplementation uniformMatrix4dvImplementation; + static UniformMatrix2x3dvImplementation uniformMatrix2x3dvImplementation; + static UniformMatrix3x2dvImplementation uniformMatrix3x2dvImplementation; + static UniformMatrix2x4dvImplementation uniformMatrix2x4dvImplementation; + static UniformMatrix4x2dvImplementation uniformMatrix4x2dvImplementation; + static UniformMatrix3x4dvImplementation uniformMatrix3x4dvImplementation; + static UniformMatrix4x3dvImplementation uniformMatrix4x3dvImplementation; + #endif + GLuint _id; State state; }; diff --git a/src/Context.cpp b/src/Context.cpp index 92247c051..d3361f8a5 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -19,6 +19,7 @@ #include #include +#include "AbstractShaderProgram.h" #include "Buffer.h" #include "Extensions.h" #include "Implementation/State.h" @@ -198,6 +199,7 @@ Context::Context() { _state = new Implementation::State; /* Initialize functionality based on current OpenGL version and extensions */ + AbstractShaderProgram::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); } From b97e6f8bcea9590021eb44f3cc71a229e658741f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 17:20:54 +0200 Subject: [PATCH 171/256] Updated and simplified AbstractShaderProgram documentation. --- src/AbstractShaderProgram.h | 47 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 57d36c8e5..c41c4baea 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -63,8 +63,8 @@ static const GLint SpecularTextureLayer = 1; - **Uniform locations** for setting uniform data (see below) (private constants), for example: @code -static const GLint TransformationMatrixUniform = 0; -static const GLint ProjectionMatrixUniform = 1; +static const GLint TransformationUniform = 0; +static const GLint ProjectionUniform = 1; static const GLint DiffuseTextureUniform = 2; static const GLint SpecularTextureUniform = 3; @endcode @@ -81,13 +81,16 @@ MyShader() { } @endcode - **Uniform setting functions**, which will provide public interface for - protected setUniform() functions. Example: + protected setUniform() functions. For usability purposes you can implement + also method chaining. Example: @code -void setTransformationMatrixUniform(const Matrix4& matrix) { - setUniform(TransformationMatrixUniform, matrix); +MyShader* setTransformation(const Matrix4& matrix) { + setUniform(TransformationUniform, matrix); + return this; } -void setProjectionMatrixUniform(const Matrix4& matrix) { - setUniform(ProjectionMatrixUniform, matrix); +MyShader* setProjection(const Matrix4& matrix) { + setUniform(ProjectionUniform, matrix); + return this; } @endcode @@ -144,8 +147,8 @@ code, e.g.: @code #version 430 // or #extension GL_ARB_explicit_uniform_location: enable -layout(location = 0) uniform mat4 transformationMatrix; -layout(location = 1) uniform mat4 projectionMatrix; +layout(location = 0) uniform mat4 transformation; +layout(location = 1) uniform mat4 projection; @endcode @requires_gl (for explicit uniform location instead of using uniformLocation()) @requires_gl43 Extension @extension{ARB,explicit_uniform_location} (for @@ -154,8 +157,8 @@ layout(location = 1) uniform mat4 projectionMatrix; If you don't have the required extension, you can get uniform location using uniformLocation() after linking stage: @code -GLint transformationMatrixUniform = uniformLocation("transformationMatrix"); -GLint projectionMatrixUniform = uniformLocation("projectionMatrix"); +GLint transformationUniform = uniformLocation("transformation"); +GLint projectionUniform = uniformLocation("projection"); @endcode @subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms @@ -183,18 +186,18 @@ setUniform(SpecularTextureUniform, SpecularTextureLayer); @section AbstractShaderProgram-rendering-workflow Rendering workflow Basic workflow with %AbstractShaderProgram subclasses is: instancing the class -(once at the beginning), then in Object::draw() reimplementation calling -use(), setting uniforms, binding required textures to their respective layers -using AbstractTexture::bind(GLint) and calling Mesh::draw(). For example: +(once at the beginning), then in draw event setting uniforms and marking the +shader for use, binding required textures to their respective layers using +AbstractTexture::bind(GLint) and calling Mesh::draw(). For example: @code -void draw(const Magnum::Matrix4& transformationMatrix, Magnum::Camera* camera) { - shader.use(); - shader.setTransformationMatrixUniform(transformationMatrix); - shader.setProjectionMatrixUniform(camera->projectionMatrix()); - diffuseTexture.bind(MyShader::DiffuseTextureLayer); - specularTexture.bind(MyShader::SpecularTextureLayer); - mesh.draw(); -} +shader->setTransformation(transformation) + ->setProjection(projection) + ->use(); + +diffuseTexture->bind(MyShader::DiffuseTextureLayer); +specularTexture->bind(MyShader::SpecularTextureLayer); + +mesh.draw(); @endcode @todo Uniform arrays support From 602a9be75e8a1ec9b78b08dad1dc3434851fc0f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 17:40:18 +0200 Subject: [PATCH 172/256] Don't duplicate CubeMapTexture functionality in CubeMapTextureArray. --- src/CubeMapTextureArray.h | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 4569c1ad1..ea6851aa2 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -33,6 +33,7 @@ classic textures, coordinates for cube map textures is signed three-part vector from the center of the cube, which intersects one of the six sides of the cube map. +@see CubeMapTexture::setSeamless() @requires_gl40 Extension @extension{ARB,texture_cube_map_array} */ class CubeMapTextureArray: public AbstractTexture { @@ -47,16 +48,6 @@ class CubeMapTextureArray: public AbstractTexture { NegativeZ = 5 /**< -Z cube side */ }; - /** - * @brief Enable/disable seamless cube map textures - * - * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} - * @requires_gl32 Extension @extension{ARB,seamless_cube_map} - */ - inline static void setSeamless(bool enabled) { - enabled ? glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) : glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); - } - /** * @brief Constructor * From f28f5398d35dfbe3666bb816d454474cf8c2deba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 17:41:10 +0200 Subject: [PATCH 173/256] Added some @todos. --- src/Buffer.h | 1 + src/Math/Matrix3.h | 2 ++ src/Math/Matrix4.h | 2 ++ src/Math/RectangularMatrix.h | 4 ++++ src/Math/Vector.h | 2 ++ src/MeshTools/Tipsify.h | 1 + src/SizeTraits.h | 2 ++ 7 files changed, 14 insertions(+) diff --git a/src/Buffer.h b/src/Buffer.h index e4747aa69..c95ae4d15 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -61,6 +61,7 @@ buffer.setData(data, Buffer::Usage::StaticDraw); @endcode @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) +@todo BindBufferRange/BindBufferOffset/BindBufferBase for transform feedback (3.0, @extension{EXT,transform_feedback}) */ class MAGNUM_EXPORT Buffer { friend class Context; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index e904975e0..0fdf309bc 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -141,6 +141,8 @@ template class Matrix3: public Matrix<3, T> { return (*this)[2].xy(); } + /** @todo up(), right() */ + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point2D operator*(const Point2D& other) const { return Matrix<3, T>::operator*(other); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index e9a6a4231..0354eb991 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -238,6 +238,8 @@ template class Matrix4: public Matrix<4, T> { return (*this)[3].xyz(); } + /** @todo up(), forward(), right() */ + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point3D operator*(const Point3D& other) const { return Matrix<4, T>::operator*(other); diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 0ca329847..8d917e19b 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -28,6 +28,8 @@ namespace Magnum { namespace Math { +/** @todo Properly test all constexpr */ + template class RectangularMatrix; #ifndef DOXYGEN_GENERATING_OUTPUT @@ -88,6 +90,8 @@ template class RectangularMatrix { * @brief %Matrix from column vectors * @param first First column vector * @param next Next column vectors + * + * @todo Creating matrix from arbitrary combination of matrices with n rows */ template inline constexpr static RectangularMatrix from(const Vector& first, const U&... next) { static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to Matrix from Vector constructor"); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index ba9651ba0..b698f88df 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -70,6 +70,8 @@ template class Vector: public RectangularMatrix<1, si /** @brief Default constructor */ inline constexpr Vector() {} + /** @todo Creating Vector from combination of vector and scalar types */ + /** * @brief Initializer-list constructor * @param first First value diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 0d0a28ff8..ca93c1297 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -40,6 +40,7 @@ class MESHTOOLS_EXPORT Tipsify { * * Computes count and indices of adjacent triangles for each vertex * (used internally). + * @todo Export only for unit test, hide otherwise */ void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; diff --git a/src/SizeTraits.h b/src/SizeTraits.h index fe5c3c8d9..66f8c3959 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -26,6 +26,8 @@ namespace Magnum { +/** @todo Remove/internalize things used only in one place (Math::log, Pow, Log)? Simplify SizeTraits? */ + /** @brief Traits class providing suitable types for given data sizes @tparam byte Highest byte needed (counting from zero) From ef6858aeca007ca240a221762eba8360bee44090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 8 Oct 2012 17:41:22 +0200 Subject: [PATCH 174/256] Warn about self-initialization. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3a5f3c80..23b57f72c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -pedantic -std=c++0x -fvisibility=hidden") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Winit-self -pedantic -std=c++0x -fvisibility=hidden") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") From 71d90580b0a25990c8bbcde4fad8b96c50f6d00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 11 Oct 2012 21:34:59 +0200 Subject: [PATCH 175/256] Physics: Shape type is public function. --- src/Physics/AxisAlignedBox.h | 9 ++++----- src/Physics/Box.h | 9 ++++----- src/Physics/Capsule.h | 9 ++++----- src/Physics/Line.h | 9 ++++----- src/Physics/LineSegment.h | 5 +++-- src/Physics/Plane.h | 5 ++--- src/Physics/Point.h | 7 ++++--- src/Physics/ShapeGroup.h | 7 ++++--- src/Physics/Sphere.h | 9 ++++----- 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 2f67eb456..c007c8ea6 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -34,6 +34,10 @@ template class PHYSICS_EXPORT AxisAlignedBox: public Ab /** @brief Constructor */ inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::AxisAlignedBox; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Position */ @@ -64,11 +68,6 @@ template class PHYSICS_EXPORT AxisAlignedBox: public Ab return _transformedSize; } - protected: - inline typename AbstractShape::Type type() const { - return AbstractShape::Type::AxisAlignedBox; - } - private: Math::Vector _position, _transformedPosition, _size, _transformedSize; diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 25eed9345..896adaa67 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -35,6 +35,10 @@ template class PHYSICS_EXPORT Box: public AbstractShape /** @brief Constructor */ inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Box; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Transformation */ @@ -52,11 +56,6 @@ template class PHYSICS_EXPORT Box: public AbstractShape return _transformedTransformation; } - protected: - inline typename AbstractShape::Type type() const { - return AbstractShape::Type::Box; - } - private: Math::Matrix _transformation, _transformedTransformation; diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 9ee660ef0..eb059b13e 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -39,6 +39,10 @@ template class PHYSICS_EXPORT Capsule: public AbstractS /** @brief Constructor */ inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Capsule; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; @@ -90,11 +94,6 @@ template class PHYSICS_EXPORT Capsule: public AbstractS /** @brief Collision with sphere */ bool operator%(const Sphere& other) const; - protected: - inline typename AbstractShape::Type type() const { - return AbstractShape::Type::Capsule; - } - private: Math::Vector _a, _transformedA, _b, _transformedB; diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 880bc2ea6..21c0c31ae 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -35,6 +35,10 @@ template class PHYSICS_EXPORT Line: public AbstractShap /** @brief Constructor */ inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Line; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief First point */ @@ -67,11 +71,6 @@ template class PHYSICS_EXPORT Line: public AbstractShap return _transformedB; } - protected: - inline typename AbstractShape::Type type() const { - return AbstractShape::Type::Line; - } - private: Math::Vector _a, _transformedA, _b, _transformedB; diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 2a5f1739c..82fe11861 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -33,8 +33,9 @@ template class LineSegment: public Line { /** @brief Constructor */ inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} - protected: - inline typename AbstractShape::Type type() const { return AbstractShape::Type::LineSegment; } + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::LineSegment; + } }; /** @brief Two-dimensional line segment */ diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 6afea764b..3895b6f6d 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -35,6 +35,8 @@ class PHYSICS_EXPORT Plane: public AbstractShape<3> { /** @brief Constructor */ inline Plane(const Vector3& position, const Vector3& normal): _position(position), _transformedPosition(position), _normal(normal), _transformedNormal(normal) {} + inline Type type() const { return Type::Plane; } + #ifndef DOXYGEN_GENERATING_OUTPUT void applyTransformation(const Matrix4& transformation); bool collides(const AbstractShape<3>* other) const; @@ -75,9 +77,6 @@ class PHYSICS_EXPORT Plane: public AbstractShape<3> { /** @brief Collision with line segment */ bool operator%(const LineSegment3D& other) const; - protected: - inline Type type() const { return Type::Plane; } - private: Vector3 _position, _transformedPosition, _normal, _transformedNormal; diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 60557b6b8..0644c85d9 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -34,6 +34,10 @@ template class PHYSICS_EXPORT Point: public AbstractSha /** @brief Constructor */ inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Point; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); /** @brief Position */ @@ -51,9 +55,6 @@ template class PHYSICS_EXPORT Point: public AbstractSha return _transformedPosition; } - protected: - inline typename AbstractShape::Type type() const { return AbstractShape::Type::Point; } - private: Math::Vector _position, _transformedPosition; }; diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 1f5900148..768731bd6 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -99,13 +99,14 @@ template class PHYSICS_EXPORT ShapeGroup: public Abstra /** @brief Move assignment */ ShapeGroup& operator=(ShapeGroup&& other); + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::ShapeGroup; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; - protected: - virtual typename AbstractShape::Type type() const { return AbstractShape::Type::ShapeGroup; } - private: inline ShapeGroup(int operation, AbstractShape* a, AbstractShape* b): operation(operation), a(a), b(b) {} diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 9c92db521..36992346e 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -40,6 +40,10 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh /** @brief Constructor */ inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline typename AbstractShape::Type type() const { + return AbstractShape::Type::Sphere; + } + void applyTransformation(const typename DimensionTraits::MatrixType& transformation); bool collides(const AbstractShape* other) const; @@ -82,11 +86,6 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh /** @brief Collision with sphere */ bool operator%(const Sphere& other) const; - protected: - inline typename AbstractShape::Type type() const { - return AbstractShape::Type::Sphere; - } - private: Math::Vector _position, _transformedPosition; From 706db2b5600246d597ad59e7632926e2c3aefcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 11 Oct 2012 22:06:36 +0200 Subject: [PATCH 176/256] Physics: Accessors to ShapeGroup members. --- src/Physics/ShapeGroup.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 768731bd6..505cb3309 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -107,6 +107,20 @@ template class PHYSICS_EXPORT ShapeGroup: public Abstra bool collides(const AbstractShape* other) const; + /** + * @brief First object in the group + * + * If there is no such object, returns `nullptr`. + */ + inline AbstractShape* first() { return a; } + + /** + * @brief Second object in the group + * + * If there is no such object, returns `nullptr`. + */ + inline AbstractShape* second() { return b; } + private: inline ShapeGroup(int operation, AbstractShape* a, AbstractShape* b): operation(operation), a(a), b(b) {} From 6ae88e22c5d38c4cf8ced14e0bf54282f0c1aa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 11 Oct 2012 18:54:08 +0200 Subject: [PATCH 177/256] Removed forgotten traces of debug draw from ShapedObject. --- src/Physics/ShapedObject.cpp | 3 --- src/Physics/ShapedObjectGroup.h | 41 +-------------------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp index aee0750a2..fb92ede11 100644 --- a/src/Physics/ShapedObject.cpp +++ b/src/Physics/ShapedObject.cpp @@ -17,9 +17,6 @@ #include -#include "AbstractShaderProgram.h" -#include "Mesh.h" -#include "ResourceManager.h" #include "AbstractShape.h" #include "ShapedObjectGroup.h" diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index 978e54e00..bf1f00f0c 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -24,25 +24,10 @@ #include "magnumPhysicsVisibility.h" -namespace Magnum { - -class AbstractShaderProgram; -template class Resource; - -namespace Physics { +namespace Magnum { namespace Physics { template class ShapedObject; -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - enum class DebugMode { - None, - Wireframe, - SolidWireframe - }; -} -#endif - /** @brief Group of shaped objects @@ -55,21 +40,6 @@ template class PHYSICS_EXPORT ShapedObjectGroup { friend class ShapedObject; public: - #ifdef DOXYGEN_GENERATING_OUTPUT - /** - * @brief Debug mode - * - * @see setDebugMode() - */ - enum class DebugMode { - None, /**< @brief Nothing is rendered */ - Wireframe, /**< @brief Wireframe of the shape is rendered */ - SolidWireframe /**< @brief Solid with wireframe is rendered */ - }; - #else - typedef Implementation::DebugMode DebugMode; - #endif - /** * @brief Destructor * @@ -79,12 +49,6 @@ template class PHYSICS_EXPORT ShapedObjectGroup { for(auto i: objects) delete i; } - /** @brief Debug mode */ - inline DebugMode debugMode() const { return _debugMode; } - - /** @brief Set debug mode */ - inline void setDebugMode(DebugMode mode) { _debugMode = mode; } - /** * @brief Whether the group is dirty * @return True if any object in the group is dirty, false otherwise. @@ -111,9 +75,6 @@ template class PHYSICS_EXPORT ShapedObjectGroup { void setClean(); private: - Resource& shader(); - - DebugMode _debugMode; std::vector*> objects; bool dirty; }; From c0aa6a3ba5020b6684b9552f4067b6c144168625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 11 Oct 2012 20:19:05 +0200 Subject: [PATCH 178/256] Don't forget to set ShapedObject as dirty after setting shape. Also inlined the function and allowed method chaining. --- src/Physics/ShapedObject.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index fceee5c3b..e7e2aac9e 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -56,8 +56,15 @@ template class PHYSICS_EXPORT ShapedObject: public Scen inline AbstractShape* shape() { return _shape; } inline const AbstractShape* shape() const { return _shape; } /**< @overload */ - /** @brief Set object shape */ - void setShape(AbstractShape* shape) { _shape = shape; } + /** + * @brief Set object shape + * @return Pointer to self (for method chaining) + */ + inline ShapedObject* setShape(AbstractShape* shape) { + _shape = shape; + setDirty(); + return this; + } /** * @copybrief SceneGraph::AbstractObject::setDirty() From 803ebfd2ab3cf3d1beef36bd96bbf1315619eeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Oct 2012 20:59:17 +0200 Subject: [PATCH 179/256] Removed unneeded #include. --- src/BufferedTexture.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index be4e3bbf3..125508470 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -19,7 +19,6 @@ * @brief Class Magnum::BufferedTexture */ -#include "Renderbuffer.h" #include "Buffer.h" namespace Magnum { From 676f89127fe8889f7c25630b9ac2fcf42b7fa0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Oct 2012 21:08:55 +0200 Subject: [PATCH 180/256] BufferedTexture is now privately based on AbstractTexture. Don't duplicate the functionality when it is not necessarily needed. --- src/BufferedTexture.h | 46 ++++++------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index 125508470..dabe50c67 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -19,6 +19,7 @@ * @brief Class Magnum::BufferedTexture */ +#include "AbstractTexture.h" #include "Buffer.h" namespace Magnum { @@ -39,7 +40,7 @@ data using integer coordinates in `texelFetch()`. @requires_gl @requires_gl31 Extension @extension{ARB,texture_buffer_object} */ -class BufferedTexture { +class BufferedTexture: private AbstractTexture { BufferedTexture(const BufferedTexture& other) = delete; BufferedTexture(BufferedTexture&& other) = delete; BufferedTexture& operator=(const BufferedTexture& other) = delete; @@ -116,38 +117,10 @@ class BufferedTexture { /*@}*/ - /** - * @brief Constructor - * - * Creates one OpenGL texture. - * @see @fn_gl{GenTextures} - */ - inline BufferedTexture() { - glGenTextures(1, &_id); - } - - /** - * @brief Destructor - * - * Deletes assigned OpenGL texture. - * @see @fn_gl{DeleteTextures} - */ - inline virtual ~BufferedTexture() { - glDeleteTextures(1, &_id); - } + inline BufferedTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} - /** - * @brief Bind texture for rendering - * - * Sets current texture as active in given layer. The layer must be - * between 0 and maxSupportedLayerCount(). Note that only one texture - * can be bound to given layer. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} - */ - inline void bind(GLint layer) { - glActiveTexture(GL_TEXTURE0 + layer); - bind(); - } + /** @copydoc AbstractTexture::bind() */ + inline void bind(GLint layer) { AbstractTexture::bind(layer); } /** * @brief Set texture buffer @@ -160,16 +133,9 @@ class BufferedTexture { * @see @fn_gl{BindTexture}, @fn_gl{TexBuffer} */ void setBuffer(InternalFormat internalFormat, Buffer* buffer) { - bind(); + AbstractTexture::bind(); glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); } - - private: - GLuint _id; - - inline void bind() { - glBindTexture(GL_TEXTURE_BUFFER, _id); - } }; /** @relates BufferedTexture From f9099a86bf68c10e5364ad3ff5b63c8b1ee3455d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Oct 2012 21:11:23 +0200 Subject: [PATCH 181/256] Tracking texture state - bindings and limits. --- src/AbstractTexture.cpp | 70 +++++++++++++++++++++++++++---- src/AbstractTexture.h | 53 ++++++++++++----------- src/BufferedTexture.h | 2 +- src/Context.cpp | 2 + src/CubeMapTexture.h | 6 +-- src/CubeMapTextureArray.h | 8 ++-- src/Implementation/State.cpp | 4 +- src/Implementation/State.h | 2 + src/Implementation/TextureState.h | 36 ++++++++++++++++ src/Texture.h | 6 +-- 10 files changed, 146 insertions(+), 43 deletions(-) create mode 100644 src/Implementation/TextureState.h diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 87af0d7b0..a2b5f3e1f 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -15,6 +15,10 @@ #include "AbstractTexture.h" +#include "Context.h" +#include "Implementation/State.h" +#include "Implementation/TextureState.h" + namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -35,25 +39,49 @@ static_assert((filter_or(NearestNeighbor, BaseLevel) == GL_NEAREST) && #endif GLint AbstractTexture::maxSupportedLayerCount() { - GLint value; - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value); - return value; + return Context::current()->state()->texture->maxSupportedLayerCount; } #ifndef MAGNUM_TARGET_GLES GLfloat AbstractTexture::maxSupportedAnisotropy() { - GLfloat value; - glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value); + GLfloat& value = Context::current()->state()->texture->maxSupportedAnisotropy; + + /* Get the value, if not already cached */ + if(value == 0.0f) + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value); + return value; } #endif +AbstractTexture::~AbstractTexture() { + /* Remove all bindings */ + for(GLuint& binding: Context::current()->state()->texture->bindings) + if(binding == _id) binding = 0; + + glDeleteTextures(1, &_id); +} + +void AbstractTexture::bind(GLint layer) { + Implementation::TextureState* const textureState = Context::current()->state()->texture; + + /* If already bound in given layer, nothing to do */ + if(textureState->bindings[layer] == _id) return; + + /* Change to given layer, if not already there */ + if(textureState->currentLayer != layer) + glActiveTexture(GL_TEXTURE0 + (textureState->currentLayer = layer)); + + /* Bind the texture to the layer */ + glBindTexture(_target, (textureState->bindings[layer] = _id)); +} + AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif - bind(); + bindInternal(); glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, static_cast(filter)|static_cast(mipmap)); return this; @@ -64,11 +92,39 @@ AbstractTexture* AbstractTexture::generateMipmap() { CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif - bind(); + bindInternal(); glGenerateMipmap(_target); return this; } +#ifndef DOXYGEN_GENERATING_OUTPUT +void AbstractTexture::bindInternal() { + Implementation::TextureState* const textureState = Context::current()->state()->texture; + + /* If the texture is already bound in current layer, nothing to do */ + if(textureState->bindings[textureState->currentLayer] == _id) + return; + + /* Set internal layer as active if not already */ + const GLint internalLayer = textureState->maxSupportedLayerCount-1; + if(textureState->currentLayer != internalLayer) + glActiveTexture(GL_TEXTURE0 + (textureState->currentLayer = internalLayer)); + + /* Bind the texture to internal layer, if not already */ + if(textureState->bindings[internalLayer] != _id) + glBindTexture(_target, (textureState->bindings[internalLayer] = _id)); +} +#endif + +void AbstractTexture::initializeContextBasedFunctionality(Context* context) { + Implementation::TextureState* const textureState = context->state()->texture; + GLint& value = textureState->maxSupportedLayerCount; + + /* Get the value and resize bindings array */ + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value); + textureState->bindings.resize(value); +} + AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) { #ifndef MAGNUM_TARGET_GLES #define internalFormatSwitch(c) switch(type) { \ diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index fc0b0f818..905618642 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -26,6 +26,8 @@ namespace Magnum { +class Context; + /** @brief Base for textures @@ -42,10 +44,24 @@ AbstractShaderProgram::setUniform(GLint, GLint). See Texture, CubeMapTexture and CubeMapTextureArray documentation for more information. +@section AbstractTexture-performance-optimization Performance optimizations +The engine tracks currently bound textures in all available layers to avoid +unnecessary calls to @fn_gl{ActiveTexture} and @fn_gl{BindTexture}. %Texture +configuration functions use dedicated highest available texture layer to not +affect active bindings in user layers. %Texture limits (such as +maxSupportedLayerCount()) are cached, so repeated queries don't result in +repeated @fn_gl{Get} calls. + +To achieve least state changes, fully configure each texture in one run -- +method chaining comes in handy -- and try to have often used textures in +dedicated layers, not occupied by other textures. + @todo Add glPixelStore encapsulation @todo Texture copying */ class MAGNUM_EXPORT AbstractTexture { + friend class Context; + AbstractTexture(const AbstractTexture& other) = delete; AbstractTexture(AbstractTexture&& other) = delete; AbstractTexture& operator=(const AbstractTexture& other) = delete; @@ -533,8 +549,8 @@ class MAGNUM_EXPORT AbstractTexture { /** * @brief Max supported layer count * - * At least 48. - * @see bind(GLint), @fn_gl{Get} with @def_gl{MAX_COMBINED_TEXTURE_IMAGE_UNITS} + * @see bind(GLint), @fn_gl{Get} with @def_gl{MAX_COMBINED_TEXTURE_IMAGE_UNITS}, + * @fn_gl{ActiveTexture} */ static GLint maxSupportedLayerCount(); @@ -577,12 +593,9 @@ class MAGNUM_EXPORT AbstractTexture { * Sets current texture as active in given layer. The layer must be * between 0 and maxSupportedLayerCount(). Note that only one texture * can be bound to given layer. - * @see bind(), @fn_gl{ActiveTexture} + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} */ - inline void bind(GLint layer) { - glActiveTexture(GL_TEXTURE0 + layer); - bind(); - } + void bind(GLint layer); /** * @brief Set minification filter @@ -612,7 +625,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAG_FILTER} */ inline AbstractTexture* setMagnificationFilter(Filter filter) { - bind(); + bindInternal(); glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast(filter)); return this; } @@ -628,7 +641,7 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_gl */ inline AbstractTexture* setBorderColor(const Color4& color) { - bind(); + bindInternal(); glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); return this; } @@ -644,7 +657,7 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_extension @extension{EXT,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { - bind(); + bindInternal(); glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); return this; } @@ -663,27 +676,19 @@ class MAGNUM_EXPORT AbstractTexture { protected: #ifndef DOXYGEN_GENERATING_OUTPUT template struct DataHelper {}; - #endif - const GLenum _target; /**< @brief Target */ + /* Unlike bind() this also sets the binding layer as active */ + void bindInternal(); - /** - * @brief Bind texture for parameter modification - * - * Unlike bind(GLint) doesn't bind the texture to any particular - * layer, thus unusable for binding for rendering. - * @see @fn_gl{BindTexture} - */ - inline void bind() { - glBindTexture(_target, _id); - } + const GLenum _target; + #endif private: + static void initializeContextBasedFunctionality(Context* context); + GLuint _id; }; -inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &_id); } - /** @relates AbstractTexture @brief Convertor of component count and data type to InternalFormat diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index dabe50c67..be3e6f8b8 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -133,7 +133,7 @@ class BufferedTexture: private AbstractTexture { * @see @fn_gl{BindTexture}, @fn_gl{TexBuffer} */ void setBuffer(InternalFormat internalFormat, Buffer* buffer) { - AbstractTexture::bind(); + bindInternal(); glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); } }; diff --git a/src/Context.cpp b/src/Context.cpp index d3361f8a5..70c9e391b 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -20,6 +20,7 @@ #include #include "AbstractShaderProgram.h" +#include "AbstractTexture.h" #include "Buffer.h" #include "Extensions.h" #include "Implementation/State.h" @@ -201,6 +202,7 @@ Context::Context() { /* Initialize functionality based on current OpenGL version and extensions */ AbstractShaderProgram::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); + AbstractTexture::initializeContextBasedFunctionality(this); } Context::~Context() { diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index a537eaec8..a6d1c170f 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -86,7 +86,7 @@ class CubeMapTexture: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bind(); + bindInternal(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); return this; } @@ -97,7 +97,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { - bind(); + bindInternal(); DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); return this; } @@ -108,7 +108,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bind(); + bindInternal(); DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index ea6851aa2..50689e746 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -60,7 +60,7 @@ class CubeMapTextureArray: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bind(); + bindInternal(); DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); return this; } @@ -73,7 +73,7 @@ class CubeMapTextureArray: public AbstractTexture { * The images are ordered the same way as Coordinate enum. */ template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { - bind(); + bindInternal(); DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); return this; } @@ -97,7 +97,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { - bind(); + bindInternal(); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); return this; } @@ -118,7 +118,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bind(); + bindInternal(); DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index 5c3ead774..b1cb03dd8 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -17,12 +17,14 @@ #include "BufferState.h" #include "ShaderProgramState.h" +#include "TextureState.h" namespace Magnum { namespace Implementation { -State::State(): buffer(new BufferState), shaderProgram(new ShaderProgramState) {} +State::State(): buffer(new BufferState), shaderProgram(new ShaderProgramState), texture(new TextureState) {} State::~State() { + delete texture; delete shaderProgram; delete buffer; } diff --git a/src/Implementation/State.h b/src/Implementation/State.h index 8330fb7bd..d655b3172 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -21,6 +21,7 @@ namespace Magnum { namespace Implementation { struct BufferState; struct ShaderProgramState; +struct TextureState; struct State { State(); @@ -28,6 +29,7 @@ struct State { BufferState* const buffer; ShaderProgramState* const shaderProgram; + TextureState* const texture; }; }} diff --git a/src/Implementation/TextureState.h b/src/Implementation/TextureState.h new file mode 100644 index 000000000..74388443e --- /dev/null +++ b/src/Implementation/TextureState.h @@ -0,0 +1,36 @@ +#ifndef Magnum_Implementation_TextureState_h +#define Magnum_Implementation_TextureState_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +#include "Buffer.h" + +namespace Magnum { namespace Implementation { + +struct TextureState { + inline TextureState(): maxSupportedLayerCount(0), maxSupportedAnisotropy(0.0f), currentLayer(0) {} + + GLint maxSupportedLayerCount; + GLfloat maxSupportedAnisotropy; + GLint currentLayer; + + std::vector bindings; +}; + +}} + +#endif diff --git a/src/Texture.h b/src/Texture.h index ba57c8d23..ff3454151 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -130,7 +130,7 @@ template class Texture: public AbstractTexture { * that can easily create all values the same) */ inline Texture* setWrapping(const Math::Vector& wrapping) { - bind(); + bindInternal(); DataHelper::setWrapping(_target, wrapping); return this; } @@ -148,7 +148,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexImage1D}, @fn_gl{TexImage2D}, @fn_gl{TexImage3D} */ template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { - bind(); + bindInternal(); DataHelper::set(_target, mipLevel, internalFormat, image); return this; } @@ -172,7 +172,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} */ template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { - bind(); + bindInternal(); DataHelper::setSub(_target, mipLevel, offset, image); return this; } From b9e96d3b086a47b4557318b084bcfdc2cf0d84a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 13 Oct 2012 23:54:03 +0200 Subject: [PATCH 182/256] Documented internal buffer state tracking. --- src/Buffer.h | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index c95ae4d15..8ff232aa4 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -60,6 +60,18 @@ std::vector data; buffer.setData(data, Buffer::Usage::StaticDraw); @endcode +@section Buffer-performance-optimization Performance optimizations +The engine tracks currently bound buffers to avoid unnecessary calls to +@fn_gl{BindBuffer}. If the buffer is already bound to some target, +functions copy(), setData() and setSubData() use that target in +@fn_gl{CopyBufferSubData}, @fn_gl{BufferData} and @fn_gl{BufferSubData} +functions instead of binding the buffer to some specific target. + +If extension @extension{EXT,direct_state_access} is available, functions +copy(), setData() and setSubData() use DSA functions to avoid unnecessary +calls to @fn_gl{BindBuffer}. See their respective documentation for more +information. + @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) @todo BindBufferRange/BindBufferOffset/BindBufferBase for transform feedback (3.0, @extension{EXT,transform_feedback}) */ @@ -247,12 +259,12 @@ class MAGNUM_EXPORT Buffer { * @param writeOffset Offset in the write buffer * @param size Data size * - * If @extension{EXT,direct_state_access} is not available, read - * buffer is bound to `Target::CopyRead` and write buffer to - * `Target::CopyWrite` before the copy is performed. + * If @extension{EXT,direct_state_access} is not available, both + * buffers are bound to some target before the copy is performed. * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) - * @see @fn_gl{CopyBufferSubData} or @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} + * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or + * @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} */ inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { copyImplementation(read, write, readOffset, writeOffset, size); @@ -287,7 +299,7 @@ class MAGNUM_EXPORT Buffer { /** * @brief Bind buffer * - * Binds buffer with default target. + * Binds buffer to default target. * @see bind(Target) */ inline void bind() { bind(_defaultTarget); } @@ -307,11 +319,12 @@ class MAGNUM_EXPORT Buffer { * @param usage %Buffer usage * * If @extension{EXT,direct_state_access} is not available, the buffer - * is bound to default target before the operation. - * @see bind(), @fn_gl{BufferData} or @fn_gl_extension{NamedBufferData,EXT,direct_state_access} + * is bound to some target before the operation. + * @see @fn_gl{BindBuffer} and @fn_gl{BufferData} or + * @fn_gl_extension{NamedBufferData,EXT,direct_state_access} */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { - (this->*Magnum::Buffer::setDataImplementation)(size, data, usage); + (this->*setDataImplementation)(size, data, usage); } /** @@ -348,8 +361,9 @@ class MAGNUM_EXPORT Buffer { * @param data Pointer to data * * If @extension{EXT,direct_state_access} is not available, the buffer - * is bound to default target before the operation. - * @see bind(), @fn_gl{BufferSubData} or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} + * is bound to some target before the operation. + * @see @fn_gl{BindBuffer} and @fn_gl{BufferSubData} or + * @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} */ inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { (this->*setSubDataImplementation)(offset, size, data); From 733e02b07b4704f7486593731af799402a05b65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 00:10:25 +0200 Subject: [PATCH 183/256] Documented internal shader program state tracking. --- src/AbstractShaderProgram.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index c41c4baea..be236dbb5 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -200,6 +200,18 @@ specularTexture->bind(MyShader::SpecularTextureLayer); mesh.draw(); @endcode +@section AbstractShaderProgram-performance-optimization Performance optimizations +The engine tracks currently used shader program to avoid unnecessary calls to +@fn_gl{UseProgram}. + +If extension @extension{ARB,separate_shader_objects} or +@extension{EXT,direct_state_access} is available, uniform setting +functions use DSA functions to avoid unnecessary calls to @fn_gl{UseProgram}. +See setUniform(GLint, GLfloat) documentation for more information. + +To achieve least state changes, set all uniforms in one run -- method chaining +comes in handy. + @todo Uniform arrays support */ class MAGNUM_EXPORT AbstractShaderProgram { @@ -381,10 +393,10 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @param value Value * * If neither @extension{ARB,separate_shader_objects} nor - * @extension{EXT,direct_state_access} is available, use() is called - * before the operation. - * @see use(), @fn_gl{Uniform} or `glProgramUniform()` from - * @extension{ARB,separate_shader_objects}/@extension{EXT,direct_state_access}. + * @extension{EXT,direct_state_access} is available, the shader is + * marked for use before the operation. + * @see @fn_gl{UseProgram}, @fn_gl{Uniform} or `glProgramUniform()` + * from @extension{ARB,separate_shader_objects}/@extension{EXT,direct_state_access}. */ inline void setUniform(GLint location, GLfloat value) { (this->*uniform1fImplementation)(location, value); From ddbfca2f95aa5852b2718926c2e33885fad83cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 01:05:45 +0200 Subject: [PATCH 184/256] Don't export private symbols. --- src/AbstractShaderProgram.h | 2 +- src/AbstractTexture.h | 2 +- src/Buffer.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index be236dbb5..5c2306051 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -664,7 +664,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { Failed }; - static void initializeContextBasedFunctionality(Context* context); + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); typedef void(AbstractShaderProgram::*Uniform1fImplementation)(GLint, GLfloat); typedef void(AbstractShaderProgram::*Uniform2fvImplementation)(GLint, const Math::Vector<2, GLfloat>&); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 905618642..075372add 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -684,7 +684,7 @@ class MAGNUM_EXPORT AbstractTexture { #endif private: - static void initializeContextBasedFunctionality(Context* context); + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); GLuint _id; }; diff --git a/src/Buffer.h b/src/Buffer.h index 8ff232aa4..04a127405 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -397,10 +397,10 @@ class MAGNUM_EXPORT Buffer { } private: - static void initializeContextBasedFunctionality(Context* context); + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); static void bind(Target hint, GLuint id); - Target bindInternal(Target hint); + Target MAGNUM_LOCAL bindInternal(Target hint); typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr); static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); From 1f3c360cb288836dc24dd4cb6d8ab5f9562d8f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 01:15:16 +0200 Subject: [PATCH 185/256] Using bindInternal() directly in AbstractTexture::DataHelper. --- src/AbstractTexture.cpp | 18 ++++++++++-------- src/AbstractTexture.h | 33 +++++++++++++++++++++------------ src/CubeMapTexture.h | 9 +++------ src/CubeMapTextureArray.h | 12 ++++-------- src/Texture.h | 9 +++------ 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index a2b5f3e1f..0822455e0 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -189,20 +189,22 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp } #ifndef DOXYGEN_GENERATING_OUTPUT -void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) { +void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); + CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); #endif - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); } -void AbstractTexture::DataHelper<3>::setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping) { - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); +void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping) { + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); #ifndef MAGNUM_TARGET_GLES - glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast(wrapping[2])); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_R, static_cast(wrapping[2])); #endif } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 075372add..a0ad2e615 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -714,15 +714,18 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } - inline static void setWrapping(GLenum target, const Math::Vector<1, Wrapping>& wrapping) { - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + inline static void setWrapping(AbstractTexture* texture, const Math::Vector<1, Wrapping>& wrapping) { + texture->bindInternal(); + glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); } - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage1D(target, mipLevel, internalFormat, image->size()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage1D(target, mipLevel, offset[0], image->size()[0], static_cast(image->components()), static_cast(image->type()), image->data()); } }; @@ -739,17 +742,20 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } - static void setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping); - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage2D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], image->size()[1], static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; @@ -761,17 +767,20 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } - static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping); - template inline static typename std::enable_if::type set(GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { + texture->bindInternal(); glTexImage3D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], image->size()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], image->size()[2], static_cast(image->components()), static_cast(image->type()), image->data()); } - template inline static typename std::enable_if::type setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { + texture->bindInternal(); glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); } }; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index a6d1c170f..e94df7529 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -86,8 +86,7 @@ class CubeMapTexture: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bindInternal(); - DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping); + DataHelper<3>::setWrapping(this, wrapping); return this; } @@ -97,8 +96,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { - bindInternal(); - DataHelper<2>::set(static_cast(coordinate), mipLevel, internalFormat, image); + DataHelper<2>::set(this, static_cast(coordinate), mipLevel, internalFormat, image); return this; } @@ -108,8 +106,7 @@ class CubeMapTexture: public AbstractTexture { * @return Pointer to self (for method chaining) */ template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<2>::setSub(static_cast(coordinate), mipLevel, offset, image); + DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } }; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 50689e746..00fb98a04 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -60,8 +60,7 @@ class CubeMapTextureArray: public AbstractTexture { * @copydoc Texture::setWrapping() */ inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { - bindInternal(); - DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP_ARRAY, wrapping); + DataHelper<3>::setWrapping(this, wrapping); return this; } @@ -73,8 +72,7 @@ class CubeMapTextureArray: public AbstractTexture { * The images are ordered the same way as Coordinate enum. */ template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { - bindInternal(); - DataHelper<3>::set(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); return this; } @@ -97,8 +95,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); return this; } @@ -118,8 +115,7 @@ class CubeMapTextureArray: public AbstractTexture { * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - bindInternal(); - DataHelper<3>::setSub(GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } }; diff --git a/src/Texture.h b/src/Texture.h index ff3454151..417b85ec9 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -130,8 +130,7 @@ template class Texture: public AbstractTexture { * that can easily create all values the same) */ inline Texture* setWrapping(const Math::Vector& wrapping) { - bindInternal(); - DataHelper::setWrapping(_target, wrapping); + DataHelper::setWrapping(this, wrapping); return this; } @@ -148,8 +147,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexImage1D}, @fn_gl{TexImage2D}, @fn_gl{TexImage3D} */ template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { - bindInternal(); - DataHelper::set(_target, mipLevel, internalFormat, image); + DataHelper::set(this, _target, mipLevel, internalFormat, image); return this; } @@ -172,8 +170,7 @@ template class Texture: public AbstractTexture { * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} */ template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { - bindInternal(); - DataHelper::setSub(_target, mipLevel, offset, image); + DataHelper::setSub(this, _target, mipLevel, offset, image); return this; } }; From 1f43839e04c4552745d4d8bb36fb7ca89a670133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 11:54:33 +0200 Subject: [PATCH 186/256] Using EXT_direct_state_access in textures. Saves unnecessary calls to glActiveTexture() and glBindTexture(). --- src/AbstractTexture.cpp | 160 +++++++++++++++++++++++++++++++++--- src/AbstractTexture.h | 165 +++++++++++++++++++++++++++----------- src/BufferedTexture.cpp | 23 ++++++ src/BufferedTexture.h | 31 +++++-- src/Context.cpp | 4 +- src/CubeMapTexture.h | 8 +- src/CubeMapTextureArray.h | 12 +-- src/Texture.h | 33 +++++--- 8 files changed, 351 insertions(+), 85 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 0822455e0..6cb0ca856 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -16,11 +16,35 @@ #include "AbstractTexture.h" #include "Context.h" +#include "Extensions.h" #include "Implementation/State.h" #include "Implementation/TextureState.h" namespace Magnum { +AbstractTexture::BindImplementation AbstractTexture::bindImplementation = + &AbstractTexture::bindImplementationDefault; +AbstractTexture::ParameteriImplementation AbstractTexture::parameteriImplementation = + &AbstractTexture::parameterImplementationDefault; +AbstractTexture::ParameterfImplementation AbstractTexture::parameterfImplementation = + &AbstractTexture::parameterImplementationDefault; +AbstractTexture::ParameterfvImplementation AbstractTexture::parameterfvImplementation = + &AbstractTexture::parameterImplementationDefault; +AbstractTexture::MipmapImplementation AbstractTexture::mipmapImplementation = + &AbstractTexture::mipmapImplementationDefault; +AbstractTexture::Image1DImplementation AbstractTexture::image1DImplementation = + &AbstractTexture::imageImplementationDefault; +AbstractTexture::Image2DImplementation AbstractTexture::image2DImplementation = + &AbstractTexture::imageImplementationDefault; +AbstractTexture::Image3DImplementation AbstractTexture::image3DImplementation = + &AbstractTexture::imageImplementationDefault; +AbstractTexture::SubImage1DImplementation AbstractTexture::subImage1DImplementation = + &AbstractTexture::subImageImplementationDefault; +AbstractTexture::SubImage2DImplementation AbstractTexture::subImage2DImplementation = + &AbstractTexture::subImageImplementationDefault; +AbstractTexture::SubImage3DImplementation AbstractTexture::subImage3DImplementation = + &AbstractTexture::subImageImplementationDefault; + #ifndef DOXYGEN_GENERATING_OUTPUT /* Check correctness of binary OR in setMinificationFilter(). If nobody fucks @@ -68,6 +92,12 @@ void AbstractTexture::bind(GLint layer) { /* If already bound in given layer, nothing to do */ if(textureState->bindings[layer] == _id) return; + (this->*bindImplementation)(layer); +} + +void AbstractTexture::bindImplementationDefault(GLint layer) { + Implementation::TextureState* const textureState = Context::current()->state()->texture; + /* Change to given layer, if not already there */ if(textureState->currentLayer != layer) glActiveTexture(GL_TEXTURE0 + (textureState->currentLayer = layer)); @@ -76,13 +106,16 @@ void AbstractTexture::bind(GLint layer) { glBindTexture(_target, (textureState->bindings[layer] = _id)); } +void AbstractTexture::bindImplementationDSA(GLint layer) { + glBindMultiTextureEXT(GL_TEXTURE0 + layer, _target, (Context::current()->state()->texture->bindings[layer] = _id)); +} + AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif - bindInternal(); - glTexParameteri(_target, GL_TEXTURE_MIN_FILTER, + (this->*parameteriImplementation)(GL_TEXTURE_MIN_FILTER, static_cast(filter)|static_cast(mipmap)); return this; } @@ -92,9 +125,17 @@ AbstractTexture* AbstractTexture::generateMipmap() { CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif + (this->*mipmapImplementation)(); + return this; +} + +void AbstractTexture::mipmapImplementationDefault() { bindInternal(); glGenerateMipmap(_target); - return this; +} + +void AbstractTexture::mipmapImplementationDSA() { + glGenerateTextureMipmapEXT(_id, _target); } #ifndef DOXYGEN_GENERATING_OUTPUT @@ -123,6 +164,103 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { /* Get the value and resize bindings array */ glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value); textureState->bindings.resize(value); + + if(context->isExtensionSupported()) { + Debug() << "AbstractTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + bindImplementation = &AbstractTexture::bindImplementationDSA; + parameteriImplementation = &AbstractTexture::parameterImplementationDSA; + parameterfImplementation = &AbstractTexture::parameterImplementationDSA; + parameterfvImplementation = &AbstractTexture::parameterImplementationDSA; + mipmapImplementation = &AbstractTexture::mipmapImplementationDSA; + image1DImplementation = &AbstractTexture::imageImplementationDSA; + image2DImplementation = &AbstractTexture::imageImplementationDSA; + image3DImplementation = &AbstractTexture::imageImplementationDSA; + subImage1DImplementation = &AbstractTexture::subImageImplementationDSA; + subImage2DImplementation = &AbstractTexture::subImageImplementationDSA; + subImage3DImplementation = &AbstractTexture::subImageImplementationDSA; + } +} + +void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLint value) { + bindInternal(); + glTexParameteri(_target, parameter, value); +} + +void AbstractTexture::parameterImplementationDSA(GLenum parameter, GLint value) { + glTextureParameteriEXT(_id, _target, parameter, value); +} + +void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLfloat value) { + bindInternal(); + glTexParameterf(_target, parameter, value); +} + +void AbstractTexture::parameterImplementationDSA(GLenum parameter, GLfloat value) { + glTextureParameterfEXT(_id, _target, parameter, value); +} + +void AbstractTexture::parameterImplementationDefault(GLenum parameter, const GLfloat* values) { + bindInternal(); + glTexParameterfv(_target, parameter, values); +} + +void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat* values) { + glTextureParameterfvEXT(_id, _target, parameter, values); +} + +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexImage1D(target, mipLevel, internalFormat, size[0], 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureImage1DEXT(_id, target, mipLevel, internalFormat, size[0], 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexImage2D(target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureImage2DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexImage3D(target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureImage3DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + bindInternal(); + glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); +} + +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { + glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); } AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) { @@ -189,22 +327,20 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp } #ifndef DOXYGEN_GENERATING_OUTPUT -void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping) { +void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Math::Vector2& wrapping) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); #endif - texture->bindInternal(); - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast(wrapping.y())); } -void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping) { - texture->bindInternal(); - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_T, static_cast(wrapping[1])); +void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Math::Vector3& wrapping) { + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast(wrapping.y())); #ifndef MAGNUM_TARGET_GLES - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_R, static_cast(wrapping[2])); + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_R, static_cast(wrapping.z())); #endif } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index a0ad2e615..c9e4b16ec 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -23,6 +23,7 @@ #include "Magnum.h" #include "Color.h" +#include "AbstractImage.h" namespace Magnum { @@ -52,6 +53,12 @@ affect active bindings in user layers. %Texture limits (such as maxSupportedLayerCount()) are cached, so repeated queries don't result in repeated @fn_gl{Get} calls. +If extension @extension{EXT,direct_state_access} is available, bind() uses DSA +function to avoid unnecessary calls to @fn_gl{ActiveTexture}. Also all texture +configuration functions use DSA functions to avoid unnecessary calls to +@fn_gl{ActiveTexture} and @fn_gl{BindTexture}. See respective function +documentation for more information. + To achieve least state changes, fully configure each texture in one run -- method chaining comes in handy -- and try to have often used textures in dedicated layers, not occupied by other textures. @@ -592,8 +599,11 @@ class MAGNUM_EXPORT AbstractTexture { * * Sets current texture as active in given layer. The layer must be * between 0 and maxSupportedLayerCount(). Note that only one texture - * can be bound to given layer. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} + * can be bound to given layer. If @extension{EXT,direct_state_access} + * is not available, the layer is made active before binding the + * texture. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} or + * @fn_gl_extension{BindMultiTexture,EXT,direct_state_access} */ void bind(GLint layer); @@ -606,12 +616,15 @@ class MAGNUM_EXPORT AbstractTexture { * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is smaller than the - * texture size. + * texture size. If @extension{EXT,direct_state_access} is not + * available, the texture is bound to some layer before the operation. * @attention For rectangle textures only some modes are supported, - * see @ref AbstractTexture::Filter "Filter" and - * @ref AbstractTexture::Mipmap "Mipmap" documentation for more - * information. - * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MIN_FILTER} + * see @ref AbstractTexture::Filter "Filter" and + * @ref AbstractTexture::Mipmap "Mipmap" documentation for more + * information. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} + * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_MIN_FILTER} */ AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); @@ -621,12 +634,14 @@ class MAGNUM_EXPORT AbstractTexture { * @return Pointer to self (for method chaining) * * Sets filter used when the object pixel size is larger than largest - * texture size. - * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAG_FILTER} + * texture size. If @extension{EXT,direct_state_access} is not + * available, the texture is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} + * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_MAG_FILTER} */ inline AbstractTexture* setMagnificationFilter(Filter filter) { - bindInternal(); - glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, static_cast(filter)); + (this->*parameteriImplementation)(GL_TEXTURE_MAG_FILTER, static_cast(filter)); return this; } @@ -636,13 +651,15 @@ class MAGNUM_EXPORT AbstractTexture { * @return Pointer to self (for method chaining) * * Border color when @ref AbstractTexture::Wrapping "wrapping" is set - * to `ClampToBorder`. - * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_BORDER_COLOR} + * to `ClampToBorder`. If @extension{EXT,direct_state_access} is not + * available, the texture is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} + * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_BORDER_COLOR} * @requires_gl */ inline AbstractTexture* setBorderColor(const Color4& color) { - bindInternal(); - glTexParameterfv(_target, GL_TEXTURE_BORDER_COLOR, color.data()); + (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); return this; } @@ -650,15 +667,19 @@ class MAGNUM_EXPORT AbstractTexture { * @brief Set max anisotropy * @return Pointer to self (for method chaining) * - * Default value is `1.0`, which means no anisotropy. Set to value - * greater than `1.0` for anisotropic filtering. - * @see maxSupportedAnisotropy(), bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} + * Default value is `1.0f`, which means no anisotropy. Set to value + * greater than `1.0f` for anisotropic filtering. If + * @extension{EXT,direct_state_access} is not available, the texture + * is bound to some layer before the operation. + * @see maxSupportedAnisotropy(), @fn_gl{ActiveTexture}, + * @fn_gl{BindTexture} and @fn_gl{TexParameter} or + * @fn_gl_extension{TextureParameter,EXT,direct_state_access} with + * @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} * @requires_gl * @requires_extension @extension{EXT,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { - bindInternal(); - glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); + (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); return this; } #endif @@ -667,8 +688,12 @@ class MAGNUM_EXPORT AbstractTexture { * @brief Generate mipmap * @return Pointer to self (for method chaining) * - * Can not be used for rectangle textures. - * @see setMinificationFilter(), @fn_gl{GenerateMipmap} + * Can not be used for rectangle textures. If + * @extension{EXT,direct_state_access} is not available, the texture + * is bound to some layer before the operation. + * @see setMinificationFilter(), @fn_gl{ActiveTexture}, + * @fn_gl{BindTexture} and @fn_gl{GenerateMipmap} or + * @fn_gl_extension{GenerateTextureMipmap,EXT,direct_state_access} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ AbstractTexture* generateMipmap(); @@ -678,7 +703,7 @@ class MAGNUM_EXPORT AbstractTexture { template struct DataHelper {}; /* Unlike bind() this also sets the binding layer as active */ - void bindInternal(); + void MAGNUM_LOCAL bindInternal(); const GLenum _target; #endif @@ -686,6 +711,61 @@ class MAGNUM_EXPORT AbstractTexture { private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + typedef void(AbstractTexture::*BindImplementation)(GLint); + void MAGNUM_LOCAL bindImplementationDefault(GLint layer); + void MAGNUM_LOCAL bindImplementationDSA(GLint layer); + static MAGNUM_LOCAL BindImplementation bindImplementation; + + typedef void(AbstractTexture::*ParameteriImplementation)(GLenum, GLint); + void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, GLint value); + void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, GLint value); + static ParameteriImplementation parameteriImplementation; + + typedef void(AbstractTexture::*ParameterfImplementation)(GLenum, GLfloat); + void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, GLfloat value); + void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, GLfloat value); + static ParameterfImplementation parameterfImplementation; + + typedef void(AbstractTexture::*ParameterfvImplementation)(GLenum, const GLfloat*); + void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, const GLfloat* values); + void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, const GLfloat* values); + static ParameterfvImplementation parameterfvImplementation; + + typedef void(AbstractTexture::*MipmapImplementation)(); + void MAGNUM_LOCAL mipmapImplementationDefault(); + void MAGNUM_LOCAL mipmapImplementationDSA(); + static MAGNUM_LOCAL MipmapImplementation mipmapImplementation; + + typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static Image1DImplementation image1DImplementation; + + typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static Image2DImplementation image2DImplementation; + + typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector3&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static Image3DImplementation image3DImplementation; + + typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static SubImage1DImplementation subImage1DImplementation; + + typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Math::Vector2&, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static SubImage2DImplementation subImage2DImplementation; + + typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Math::Vector3&, const Math::Vector3&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + static SubImage3DImplementation subImage3DImplementation; + GLuint _id; }; @@ -715,18 +795,15 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } inline static void setWrapping(AbstractTexture* texture, const Math::Vector<1, Wrapping>& wrapping) { - texture->bindInternal(); - glTexParameteri(texture->_target, GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - texture->bindInternal(); - glTexImage1D(target, mipLevel, internalFormat, image->size()[0], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + (texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { - texture->bindInternal(); - glTexSubImage1D(target, mipLevel, offset[0], image->size()[0], static_cast(image->components()), static_cast(image->type()), image->data()); + (texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); } }; #endif @@ -742,21 +819,18 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } - static void setWrapping(AbstractTexture* texture, const Math::Vector<2, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector2& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - texture->bindInternal(); - glTexImage2D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { - texture->bindInternal(); - glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], image->size()[1], static_cast(image->components()), static_cast(image->type()), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector2& offset, Image* image) { + (texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, Image* image) { - texture->bindInternal(); - glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->size()[0], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector2& offset, Image* image) { + (texture->*subImage2DImplementation)(target, mipLevel, offset, Math::Vector2(image->size(), 1), image->components(), image->type(), image->data()); } }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { @@ -767,21 +841,18 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } - static void setWrapping(AbstractTexture* texture, const Math::Vector<3, Wrapping>& wrapping); + static void setWrapping(AbstractTexture* texture, const Math::Vector3& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - texture->bindInternal(); - glTexImage3D(target, mipLevel, internalFormat, image->size()[0], image->size()[1], image->size()[2], 0, static_cast(image->components()), static_cast(image->type()), image->data()); + (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { - texture->bindInternal(); - glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], image->size()[2], static_cast(image->components()), static_cast(image->type()), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector3& offset, Image* image) { + (texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, Image* image) { - texture->bindInternal(); - glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->size()[0], image->size()[1], 1, static_cast(image->components()), static_cast(image->type()), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector3& offset, Image* image) { + (texture->*subImage3DImplementation)(target, mipLevel, offset, Math::Vector3(image->size(), 1), image->components(), image->type(), image->data()); } }; #endif diff --git a/src/BufferedTexture.cpp b/src/BufferedTexture.cpp index ffd5a6d20..aefb40905 100644 --- a/src/BufferedTexture.cpp +++ b/src/BufferedTexture.cpp @@ -15,8 +15,31 @@ #include "BufferedTexture.h" +#include "Buffer.h" +#include "Context.h" +#include "Extensions.h" + namespace Magnum { +BufferedTexture::SetBufferImplementation BufferedTexture::setBufferImplementation = &BufferedTexture::setBufferImplementationDefault; + +void BufferedTexture::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported()) { + Debug() << "BufferedTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + setBufferImplementation = &BufferedTexture::setBufferImplementationDSA; + } +} + +void BufferedTexture::setBufferImplementationDefault(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { + bindInternal(); + glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); +} + +void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { + glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id()); +} + #ifndef MAGNUM_TARGET_GLES BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) { #define internalFormatSwitch(c) switch(type) { \ diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index be3e6f8b8..ae483585e 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -20,10 +20,12 @@ */ #include "AbstractTexture.h" -#include "Buffer.h" namespace Magnum { +class Buffer; +class Context; + #ifndef MAGNUM_TARGET_GLES /** @brief Buffered texture @@ -37,10 +39,19 @@ using data setting functions in Buffer itself. When using buffered texture in the shader, use `samplerBuffer` and fetch the data using integer coordinates in `texelFetch()`. +@section BufferedTexture-performance-optimization Performance optimizations +If extension @extension{EXT,direct_state_access} is available, setBuffer() +uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and +@fn_gl{BindTexture}. See @ref AbstractTexture-performance-optimization +"relevant section in AbstractTexture documentation" and respective function +documentation for more information. + @requires_gl @requires_gl31 Extension @extension{ARB,texture_buffer_object} */ -class BufferedTexture: private AbstractTexture { +class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { + friend class Context; + BufferedTexture(const BufferedTexture& other) = delete; BufferedTexture(BufferedTexture&& other) = delete; BufferedTexture& operator=(const BufferedTexture& other) = delete; @@ -130,12 +141,20 @@ class BufferedTexture: private AbstractTexture { * Binds given buffer to this texture. The buffer itself can be then * filled with data of proper format at any time using Buffer own data * setting functions. - * @see @fn_gl{BindTexture}, @fn_gl{TexBuffer} + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} + * or @fn_gl_extension{TextureBuffer,EXT,direct_state_access} */ - void setBuffer(InternalFormat internalFormat, Buffer* buffer) { - bindInternal(); - glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); + inline void setBuffer(InternalFormat internalFormat, Buffer* buffer) { + (this->*setBufferImplementation)(internalFormat, buffer); } + + private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + typedef void(BufferedTexture::*SetBufferImplementation)(InternalFormat, Buffer*); + void MAGNUM_LOCAL setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer); + void MAGNUM_LOCAL setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer); + static SetBufferImplementation setBufferImplementation; }; /** @relates BufferedTexture diff --git a/src/Context.cpp b/src/Context.cpp index 70c9e391b..eed515804 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -24,6 +24,7 @@ #include "Buffer.h" #include "Extensions.h" #include "Implementation/State.h" +#include "BufferedTexture.h" using namespace std; @@ -201,8 +202,9 @@ Context::Context() { /* Initialize functionality based on current OpenGL version and extensions */ AbstractShaderProgram::initializeContextBasedFunctionality(this); - Buffer::initializeContextBasedFunctionality(this); AbstractTexture::initializeContextBasedFunctionality(this); + Buffer::initializeContextBasedFunctionality(this); + BufferedTexture::initializeContextBasedFunctionality(this); } Context::~Context() { diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index e94df7529..ef5de7806 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -27,9 +27,9 @@ namespace Magnum { @brief Cube map texture %Texture used mainly for environemnt maps. See AbstractTexture documentation -for more information about usage. It consists of 6 square textures generating -6 faces of the cube as following. Note that all images must be turned upside -down (+Y is top): +for more information. It consists of 6 square textures generating 6 faces of +the cube as following. Note that all images must be turned upside down (+Y is +top): +----+ | -Y | @@ -105,7 +105,7 @@ class CubeMapTexture: public AbstractTexture { * @param coordinate Coordinate * @return Pointer to self (for method chaining) */ - template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { + template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector2& offset, const Image* image) { DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 00fb98a04..0af738bef 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -26,7 +26,7 @@ namespace Magnum { /** @brief Cube map texture array -For information about usage, see CubeMapTexture documentation. +For information, see CubeMapTexture and AbstractTexture documentation. When using cube map texture in the shader, use `samplerCubeArray`. Unlike classic textures, coordinates for cube map textures is signed three-part @@ -59,7 +59,7 @@ class CubeMapTextureArray: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline CubeMapTextureArray* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTextureArray* setWrapping(const Math::Vector3& wrapping) { DataHelper<3>::setWrapping(this, wrapping); return this; } @@ -94,8 +94,8 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector<3, GLint>& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector<3, GLsizei>(Math::Vector())); + template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector3& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector3(Math::Vector())); return this; } @@ -114,8 +114,8 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector<3, GLint>(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector2& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector3(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } }; diff --git a/src/Texture.h b/src/Texture.h index 417b85ec9..dcbc3a190 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -28,7 +28,7 @@ namespace Magnum { @brief %Texture Template class for one- to three-dimensional textures. See AbstractTexture -documentation for more information about usage. +documentation for more information. In shader, the texture is used via `sampler1D`, `sampler2D` or `sampler3D` depending on dimension count. Note that you can have more than one texture bound @@ -120,12 +120,15 @@ template class Texture: public AbstractTexture { * * Sets wrapping type for coordinates out of range (0, 1) for normal * textures and (0, textureSizeInGivenDirection-1) for rectangle - * textures. + * textures. If @extension{EXT,direct_state_access} is not available, + * the texture is bound to some layer before the operation. * @attention For rectangle textures only some modes are supported, - * see @ref AbstractTexture::Wrapping "Wrapping" documentation for - * more information. - * @see bind(), @fn_gl{TexParameter} with @def_gl{TEXTURE_WRAP_S}, - * @def_gl{TEXTURE_WRAP_T}, @def_gl{TEXTURE_WRAP_R} + * see @ref AbstractTexture::Wrapping "Wrapping" documentation + * for more information. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} + * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_WRAP_S}, @def_gl{TEXTURE_WRAP_T}, + * @def_gl{TEXTURE_WRAP_R} * @todo Use something better for this than Vector (mainly something * that can easily create all values the same) */ @@ -143,8 +146,13 @@ template class Texture: public AbstractTexture { * @return Pointer to self (for method chaining) * * Sets texture data from given image. The image is not deleted - * afterwards. - * @see bind(), @fn_gl{TexImage1D}, @fn_gl{TexImage2D}, @fn_gl{TexImage3D} + * afterwards. If @extension{EXT,direct_state_access} is not available, + * the texture is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexImage1D}/ + * @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or + * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} */ template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { DataHelper::set(this, _target, mipLevel, internalFormat, image); @@ -167,7 +175,14 @@ template class Texture: public AbstractTexture { * taken as if it had the last dimension equal to 1. It can be used * for e.g. updating 3D texture with multiple 2D images or for filling * 1D texture array (which is two-dimensional) with 1D images. - * @see bind(), @fn_gl{TexSubImage1D}, @fn_gl{TexSubImage2D}, @fn_gl{TexSubImage3D} + * + * If @extension{EXT,direct_state_access} is not available, the + * texture is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexSubImage1D}/ + * @fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} or + * @fn_gl_extension{TextureSubImage1D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} */ template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { DataHelper::setSub(this, _target, mipLevel, offset, image); From 9f7ae0b34ff5cddc0118dafd548850f3691599fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 14 Oct 2012 14:52:45 +0200 Subject: [PATCH 187/256] Overloaded AbstractTexture methods in subclasses for better chaining. Allows to conveniently set the data after fully configuring the texture, so OpenGL can optimize the data to match the settings. Advice taken from http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesForWorkingWithTextureData/TechniquesForWorkingWithTextureData.html#//apple_ref/doc/uid/TP40008793-CH104-SW1 --- src/AbstractTexture.h | 3 +++ src/CubeMapTexture.h | 26 ++++++++++++++++++++++++++ src/CubeMapTextureArray.h | 26 ++++++++++++++++++++++++++ src/Texture.h | 26 ++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index c9e4b16ec..f53d7c690 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -63,6 +63,9 @@ To achieve least state changes, fully configure each texture in one run -- method chaining comes in handy -- and try to have often used textures in dedicated layers, not occupied by other textures. +Always fully configure the texture before setting the texture data, so OpenGL +can optimize the data to match your settings. + @todo Add glPixelStore encapsulation @todo Texture copying */ diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index ef5de7806..110214c42 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -109,6 +109,32 @@ class CubeMapTexture: public AbstractTexture { DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline CubeMapTexture* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline CubeMapTexture* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline CubeMapTexture* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline CubeMapTexture* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0af738bef..165e38e54 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -118,6 +118,32 @@ class CubeMapTextureArray: public AbstractTexture { DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector3(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline CubeMapTextureArray* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline CubeMapTextureArray* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline CubeMapTextureArray* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline CubeMapTextureArray* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; } diff --git a/src/Texture.h b/src/Texture.h index dcbc3a190..0dd5bcf2d 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -188,6 +188,32 @@ template class Texture: public AbstractTexture { DataHelper::setSub(this, _target, mipLevel, offset, image); return this; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Texture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + AbstractTexture::setMinificationFilter(filter, mipmap); + return this; + } + inline Texture* setMagnificationFilter(Filter filter) { + AbstractTexture::setMagnificationFilter(filter); + return this; + } + #ifndef MAGNUM_TARGET_GLES + inline Texture* setBorderColor(const Color4& color) { + AbstractTexture::setBorderColor(color); + return this; + } + inline Texture* setMaxAnisotropy(GLfloat anisotropy) { + AbstractTexture::setMaxAnisotropy(anisotropy); + return this; + } + #endif + inline Texture* generateMipmap() { + AbstractTexture::generateMipmap(); + return this; + } + #endif }; #ifndef MAGNUM_TARGET_GLES From f85a7fc568aaf9b8936832e0c094cfb7c997fbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 17 Oct 2012 12:28:25 +0200 Subject: [PATCH 188/256] Physics: Minimal initial implementation of debug draw. --- modules/FindMagnum.cmake | 3 +- src/Physics/CMakeLists.txt | 14 ++- src/Physics/DebugDrawResourceManager.cpp | 56 +++++++++ src/Physics/DebugDrawResourceManager.h | 119 ++++++++++++++++++ .../Implementation/AbstractDebugRenderer.cpp | 30 +++++ .../Implementation/AbstractDebugRenderer.h | 48 +++++++ src/Physics/Implementation/ShapeShader.cpp | 52 ++++++++ src/Physics/Implementation/ShapeShader.h | 52 ++++++++ src/Physics/Implementation/ShapeShader2D.frag | 7 ++ src/Physics/Implementation/ShapeShader2D.vert | 7 ++ 10 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 src/Physics/DebugDrawResourceManager.cpp create mode 100644 src/Physics/DebugDrawResourceManager.h create mode 100644 src/Physics/Implementation/AbstractDebugRenderer.cpp create mode 100644 src/Physics/Implementation/AbstractDebugRenderer.h create mode 100644 src/Physics/Implementation/ShapeShader.cpp create mode 100644 src/Physics/Implementation/ShapeShader.h create mode 100644 src/Physics/Implementation/ShapeShader2D.frag create mode 100644 src/Physics/Implementation/ShapeShader2D.vert diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index a4544ed74..a242f3310 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -16,7 +16,8 @@ # libraries. Additional dependencies are specified by the components. The # optional components are: # MeshTools - MeshTools library -# Physics - Physics library (depends on SceneGraph component) +# Physics - Physics library (depends on Primitives and SceneGraph +# components) # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 799da9a00..a9709f340 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,20 +1,30 @@ +corrade_add_resource(MagnumPhysics_RCS MagnumPhysics + Implementation/ShapeShader2D.vert ALIAS ShapeShader2D.vert + Implementation/ShapeShader2D.frag ALIAS ShapeShader2D.frag) + set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp Box.cpp Capsule.cpp + DebugDrawResourceManager.cpp Line.cpp Plane.cpp Point.cpp ShapedObject.cpp ShapedObjectGroup.cpp ShapeGroup.cpp - Sphere.cpp) + Sphere.cpp + + Implementation/AbstractDebugRenderer.cpp + Implementation/ShapeShader.cpp + ${MagnumPhysics_RCS}) set(MagnumPhysics_HEADERS AbstractShape.h AxisAlignedBox.h Box.h Capsule.h + DebugDrawResourceManager.h Line.h LineSegment.h Plane.h @@ -28,7 +38,7 @@ set(MagnumPhysics_HEADERS add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) -target_link_libraries(MagnumPhysics Magnum MagnumSceneGraph) +target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp new file mode 100644 index 000000000..a19cb3152 --- /dev/null +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -0,0 +1,56 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DebugDrawResourceManager.h" + +#include "AbstractShaderProgram.h" +#include "Mesh.h" +#include "AbstractShape.h" +#include "Box.h" +#include "ShapedObject.h" +#include "ShapeGroup.h" +#include "Implementation/AbstractDebugRenderer.h" +#include "Implementation/ShapeShader.h" + +namespace Magnum { + +template class ResourceManager; + +namespace Physics { + +SceneGraph::Object2D* DebugDrawResourceManager::createDebugRenderer(AbstractShape2D* shape, ResourceKey options) { + return createDebugMesh(nullptr, shape, options); +} + +SceneGraph::Object2D* DebugDrawResourceManager::createDebugMesh(SceneGraph::Object2D* parent, AbstractShape2D* shape, ResourceKey options) { + switch(shape->type()) { + case AbstractShape2D::Type::ShapeGroup: { + if(!parent) parent = new SceneGraph::Object2D; + ShapeGroup2D* group = static_cast(shape); + if(group->first()) createDebugMesh(parent, group->first(), options); + if(group->second()) createDebugMesh(parent, group->second(), options); + return parent; + } default: return nullptr; + } +} + +DebugDrawResourceManager::DebugDrawResourceManager() { + setFallback(new Options); + set("shader2d", new Implementation::ShapeShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); +} + +DebugDrawResourceManager::~DebugDrawResourceManager() {} + +}} diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h new file mode 100644 index 000000000..92f292b70 --- /dev/null +++ b/src/Physics/DebugDrawResourceManager.h @@ -0,0 +1,119 @@ +#ifndef Magnum_Physics_DebugDrawResourceManager_h +#define Magnum_Physics_DebugDrawResourceManager_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Physics::DebugDrawResourceManager + */ + +#include "Magnum.h" +#include "Color.h" +#include "ResourceManager.h" + +#include "magnumPhysicsVisibility.h" + +namespace Magnum { + +class AbstractShaderProgram; +class Mesh; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Physics { namespace Implementation { + struct Options { + Color3 color; + }; + template class AbstractDebugRenderer; +}} + +extern template class PHYSICS_EXPORT ResourceManager; +#endif + +namespace SceneGraph { + class Object2D; + class Object3D; +} + +namespace Physics { + +template class AbstractShape; +typedef AbstractShape<2> AbstractShape2D; +typedef AbstractShape<3> AbstractShape3D; + +/** +@brief %Resource manager for physics debug draw + +Can create objects which draw object collision shape for debugging purposes. + +@section DebugDrawResourceManager-usage Basic usage +The manager must be instanced for the whole lifetime of debug draw objects. +To create debug draw objects, call createDebugRenderer() and add the resulting +object to the scene. You can specify options via Options struct - add it to +the manager and then create debug renderer with the same options key. This way +you can easily share the same options with more objects. If no options for +given key exist, default is used. + +Example code: +@code +// Instance the manager at first +DebugDrawResourceManager manager; + +// Create some options +auto o = new DebugDrawResourceManager::Options { + {1.0f, 0.0f, 0.0f} // Red color +}; +manager->set("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); + +// Add debug draw object for given shape, use "red" options for it, don't +// forget to add it to the scene +ShapedObject2D* object; +DebugDrawResourceManager::createDebugRenderer(object->shape(), "red") + ->setParent(object); +@endcode +*/ +class PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { + public: + #ifdef DOXYGEN_GENERATING_OUTPUT + /** @brief %Options */ + struct Options { + Color3 color; /**< @brief Color */ + }; + #else + typedef Implementation::Options Options; + #endif + + /** + * @brief Create debug renderer for given shape + * @param shape Shape for which to create debug renderer + * @param options Options resource key. See + * @ref DebugDrawResourceManager-usage "class documentation" for + * more information. + * + * Returned object is not parented to anything, you have to add it to + * desired scene yourself. + */ + static SceneGraph::Object2D* createDebugRenderer(AbstractShape2D* shape, ResourceKey options = ResourceKey()); + + DebugDrawResourceManager(); + + ~DebugDrawResourceManager(); + + private: + static SceneGraph::Object2D* createDebugMesh(SceneGraph::Object2D* parent, AbstractShape2D* shape, ResourceKey options); +}; + +}} + +#endif diff --git a/src/Physics/Implementation/AbstractDebugRenderer.cpp b/src/Physics/Implementation/AbstractDebugRenderer.cpp new file mode 100644 index 000000000..76bcfcf22 --- /dev/null +++ b/src/Physics/Implementation/AbstractDebugRenderer.cpp @@ -0,0 +1,30 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractDebugRenderer.h" + +#include "AbstractShaderProgram.h" +#include "Mesh.h" +#include "Physics/DebugDrawResourceManager.h" +#include "ShapeShader.h" + +namespace Magnum { namespace Physics { namespace Implementation { + +template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)), options(DebugDrawResourceManager::instance()->get(options)) {} + +template class AbstractDebugRenderer<2>; +template class AbstractDebugRenderer<3>; + +}}} diff --git a/src/Physics/Implementation/AbstractDebugRenderer.h b/src/Physics/Implementation/AbstractDebugRenderer.h new file mode 100644 index 000000000..63400b22b --- /dev/null +++ b/src/Physics/Implementation/AbstractDebugRenderer.h @@ -0,0 +1,48 @@ +#ifndef Magnum_Physics_Implementation_AbstractDebugRenderer_h +#define Magnum_Physics_Implementation_AbstractDebugRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Color.h" +#include "ResourceManager.h" +#include "SceneGraph/Camera.h" + +namespace Magnum { + +class AbstractShaderProgram; +class Mesh; + +namespace Physics { namespace Implementation { + +struct Options; + +template class ShapeShader; + +template class AbstractDebugRenderer: public SceneGraph::AbstractObject::ObjectType { + public: + AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent); + + protected: + Resource> shader; + Resource mesh; + Resource options; +}; + +extern template class AbstractDebugRenderer<2>; +extern template class AbstractDebugRenderer<3>; + +}}} + +#endif diff --git a/src/Physics/Implementation/ShapeShader.cpp b/src/Physics/Implementation/ShapeShader.cpp new file mode 100644 index 000000000..c7cf1096f --- /dev/null +++ b/src/Physics/Implementation/ShapeShader.cpp @@ -0,0 +1,52 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ShapeShader.h" + +#include + +#include "Shader.h" + +namespace Magnum { namespace Physics { namespace Implementation { + +namespace { + template struct ShaderName {}; + + template<> struct ShaderName<2> { + constexpr static const char* Vertex = "ShapeShader2D.vert"; + constexpr static const char* Fragment = "ShapeShader2D.frag"; + }; + + template<> struct ShaderName<3> { + constexpr static const char* Vertex = "ShapeShader3D.vert"; + constexpr static const char* Fragment = "ShapeShader3D.frag"; + }; +} + +template ShapeShader::ShapeShader() { + Corrade::Utility::Resource resource("MagnumPhysics"); + attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, resource.get(ShaderName::Vertex))); + attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, resource.get(ShaderName::Fragment))); + + link(); + + transformationProjectionUniform = uniformLocation("transformationProjection"); + colorUniform = uniformLocation("color"); +} + +template class ShapeShader<2>; +template class ShapeShader<3>; + +}}} diff --git a/src/Physics/Implementation/ShapeShader.h b/src/Physics/Implementation/ShapeShader.h new file mode 100644 index 000000000..b1d1eac98 --- /dev/null +++ b/src/Physics/Implementation/ShapeShader.h @@ -0,0 +1,52 @@ +#ifndef Magnum_Physics_Implementation_ShapeShader_h +#define Magnum_Physics_Implementation_ShapeShader_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Math/Matrix3.h" +#include "Math/Matrix4.h" +#include "AbstractShaderProgram.h" +#include "Color.h" +#include "DimensionTraits.h" + +namespace Magnum { namespace Physics { namespace Implementation { + +template class ShapeShader: public AbstractShaderProgram { + public: + typedef Attribute<0, typename DimensionTraits::PointType> Position; + + ShapeShader(); + + ShapeShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { + setUniform(transformationProjectionUniform, matrix); + return this; + } + + ShapeShader* setColor(const Color3& color) { + setUniform(colorUniform, color); + return this; + } + + private: + GLint transformationProjectionUniform, + colorUniform; +}; + +extern template class ShapeShader<2>; +extern template class ShapeShader<3>; + +}}} + +#endif diff --git a/src/Physics/Implementation/ShapeShader2D.frag b/src/Physics/Implementation/ShapeShader2D.frag new file mode 100644 index 000000000..200b2f88c --- /dev/null +++ b/src/Physics/Implementation/ShapeShader2D.frag @@ -0,0 +1,7 @@ +uniform vec3 color; + +out vec4 fragmentColor; + +void main() { + fragmentColor = vec4(color, 1.0); +} diff --git a/src/Physics/Implementation/ShapeShader2D.vert b/src/Physics/Implementation/ShapeShader2D.vert new file mode 100644 index 000000000..0ab2076cf --- /dev/null +++ b/src/Physics/Implementation/ShapeShader2D.vert @@ -0,0 +1,7 @@ +uniform mat3 transformationProjection; + +layout(location = 0) in vec3 position; + +void main() { + gl_Position.xywz = vec4(transformationProjection*position, 0.0); +} From dfa92c2998931cb04de2fa7a708c6e8d9376acc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 17 Oct 2012 13:38:22 +0200 Subject: [PATCH 189/256] Physics: Box2D debug renderer. --- src/Physics/CMakeLists.txt | 1 + src/Physics/DebugDrawResourceManager.cpp | 3 + src/Physics/Implementation/BoxRenderer.cpp | 81 ++++++++++++++++++++++ src/Physics/Implementation/BoxRenderer.h | 41 +++++++++++ 4 files changed, 126 insertions(+) create mode 100644 src/Physics/Implementation/BoxRenderer.cpp create mode 100644 src/Physics/Implementation/BoxRenderer.h diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index a9709f340..837b068a4 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -17,6 +17,7 @@ set(MagnumPhysics_SRCS Sphere.cpp Implementation/AbstractDebugRenderer.cpp + Implementation/BoxRenderer.cpp Implementation/ShapeShader.cpp ${MagnumPhysics_RCS}) set(MagnumPhysics_HEADERS diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp index a19cb3152..92f27730f 100644 --- a/src/Physics/DebugDrawResourceManager.cpp +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -22,6 +22,7 @@ #include "ShapedObject.h" #include "ShapeGroup.h" #include "Implementation/AbstractDebugRenderer.h" +#include "Implementation/BoxRenderer.h" #include "Implementation/ShapeShader.h" namespace Magnum { @@ -36,6 +37,8 @@ SceneGraph::Object2D* DebugDrawResourceManager::createDebugRenderer(AbstractShap SceneGraph::Object2D* DebugDrawResourceManager::createDebugMesh(SceneGraph::Object2D* parent, AbstractShape2D* shape, ResourceKey options) { switch(shape->type()) { + case AbstractShape2D::Type::Box: + return new Implementation::BoxRenderer<2>(*static_cast(shape), options, parent); case AbstractShape2D::Type::ShapeGroup: { if(!parent) parent = new SceneGraph::Object2D; ShapeGroup2D* group = static_cast(shape); diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp new file mode 100644 index 000000000..e93e2e6ae --- /dev/null +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -0,0 +1,81 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "BoxRenderer.h" + +#include "Buffer.h" +#include "Physics/Box.h" +#include "Physics/DebugDrawResourceManager.h" +#include "Primitives/Cube.h" +#include "Primitives/Square.h" +#include "ShapeShader.h" + +namespace Magnum { namespace Physics { namespace Implementation { + +namespace { + template struct BoxMesh {}; + + template<> struct BoxMesh<2> { + constexpr static char shader[] = "shader2d"; + constexpr static char key[] = "box2d"; + + static Mesh* mesh() { + Primitives::Square square; + Mesh* mesh = new Mesh; + Buffer* buffer = mesh->addBuffer(Mesh::BufferType::NonInterleaved); + buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); + return mesh->setPrimitive(square.primitive()) + ->bindAttribute::Position>(buffer) + ->setVertexCount(square.positions(0)->size()); + } + }; + + template<> struct BoxMesh<3> { + constexpr static char shader[] = "shader3d"; + constexpr static char key[] = "box3d"; + + static Mesh* mesh() { + Primitives::Cube cube; + Mesh* mesh = new Mesh; + Buffer* buffer = mesh->addBuffer(Mesh::BufferType::NonInterleaved); + buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); + return mesh->setPrimitive(cube.primitive()) + ->bindAttribute::Position>(buffer) + ->setVertexCount(cube.positions(0)->size()); + } + }; +} + +constexpr char BoxMesh<2>::shader[]; +constexpr char BoxMesh<2>::key[]; +constexpr char BoxMesh<3>::shader[]; +constexpr char BoxMesh<3>::key[]; + +template BoxRenderer::BoxRenderer(Box& box, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): AbstractDebugRenderer(BoxMesh::shader, BoxMesh::key, options, parent), box(box) { + if(!this->mesh) + DebugDrawResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(), ResourceDataState::Final, ResourcePolicy::Manual); +} + +template void BoxRenderer::draw(const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractObject::CameraType* camera) { + this->shader->setTransformationProjection(camera->projectionMatrix()*box.transformedTransformation()) + ->setColor(this->options->color) + ->use(); + this->mesh->draw(); +} + +template class BoxRenderer<2>; +template class BoxRenderer<3>; + +}}} diff --git a/src/Physics/Implementation/BoxRenderer.h b/src/Physics/Implementation/BoxRenderer.h new file mode 100644 index 000000000..1540c8347 --- /dev/null +++ b/src/Physics/Implementation/BoxRenderer.h @@ -0,0 +1,41 @@ +#ifndef Magnum_Physics_Implementation_BoxRenderer_h +#define Magnum_Physics_Implementation_BoxRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractDebugRenderer.h" + +namespace Magnum { namespace Physics { + +template class Box; + +namespace Implementation { + +template class BoxRenderer: public AbstractDebugRenderer { + public: + BoxRenderer(Box& box, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent); + + void draw(const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractObject::CameraType* camera); + + private: + Box& box; +}; + +extern template class BoxRenderer<2>; +extern template class BoxRenderer<3>; + +}}} + +#endif From f5a63d7fc1ecd737ccf381d8d143a4abb69422ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 20 Oct 2012 20:21:46 +0200 Subject: [PATCH 190/256] Updated PhongShader to recent coding standards. Namely removed *Uniform from setter names and enabled method chaining. --- src/Shaders/PhongShader.h | 53 ++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 547f1d016..dfd4ab045 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -38,64 +38,87 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ - /** @brief Constructor */ PhongShader(); /** - * @brief %Ambient color + * @brief Ambient color + * @return Pointer to self (for method chaining) * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. */ - inline void setAmbientColorUniform(const Color3& color) { + inline PhongShader* setAmbientColor(const Color3& color) { setUniform(ambientColorUniform, color); + return this; } - /** @brief Diffuse color */ - inline void setDiffuseColorUniform(const Color3& color) { + /** + * @brief Diffuse color + * @return Pointer to self (for method chaining) + */ + inline PhongShader* setDiffuseColor(const Color3& color) { setUniform(diffuseColorUniform, color); + return this; } /** * @brief Specular color + * @return Pointer to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline void setSpecularColorUniform(const Color3& color) { + inline PhongShader* setSpecularColor(const Color3& color) { setUniform(specularColorUniform, color); + return this; } /** * @brief Shininess + * @return Pointer to self (for method chaining) * * The larger value, the harder surface (smaller specular highlight). * If not set, default value is `80.0f`. */ - inline void setShininessUniform(GLfloat shininess) { + inline PhongShader* setShininess(GLfloat shininess) { setUniform(shininessUniform, shininess); + return this; } - /** @brief Transformation matrix */ - inline void setTransformationMatrixUniform(const Matrix4& matrix) { + /** + * @brief Transformation matrix + * @return Pointer to self (for method chaining) + */ + inline PhongShader* setTransformation(const Matrix4& matrix) { setUniform(transformationMatrixUniform, matrix); + return this; } - /** @brief Projection matrix */ - inline void setProjectionMatrixUniform(const Matrix4& matrix) { + /** + * @brief Projection matrix + * @return Pointer to self (for method chaining) + */ + inline PhongShader* setProjection(const Matrix4& matrix) { setUniform(projectionMatrixUniform, matrix); + return this; } - /** @brief %Light position */ - inline void setLightUniform(const Vector3& light) { + /** + * @brief Light position + * @return Pointer to self (for method chaining) + */ + inline PhongShader* setLightPosition(const Vector3& light) { setUniform(lightUniform, light); + return this; } /** - * @brief %Light color + * @brief Light color + * @return Pointer to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - inline void setLightColorUniform(const Color3& color) { + inline PhongShader* setLightColor(const Color3& color) { setUniform(lightColorUniform, color); + return this; } private: From 40523e530cc0a7ff6fba875bd649399503cc0614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 20 Oct 2012 21:34:04 +0200 Subject: [PATCH 191/256] PhongShader: using `position` for vertex position. --- src/Shaders/PhongShader.vert | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 228cbad97..8fb57f05a 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -2,7 +2,7 @@ uniform mat4 transformationMatrix; uniform mat4 projectionMatrix; uniform vec3 light; -layout(location = 0) in vec4 vertex; +layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; out vec3 transformedNormal; @@ -11,18 +11,18 @@ out vec3 cameraDirection; void main() { /* Transformed vertex position */ - vec4 transformedVertex4 = transformationMatrix*vertex; - vec3 transformedVertex = transformedVertex4.xyz/transformedVertex4.w; + vec4 transformedPosition4 = transformationMatrix*position; + vec3 transformedPosition = transformedPosition4.xyz/transformedPosition4.w; /* Transformed normal vector */ transformedNormal = normalize(mat3x3(transformationMatrix)*normal); /* Direction to the light */ - lightDirection = normalize(light - transformedVertex); + lightDirection = normalize(light - transformedPosition); /* Direction to the camera */ - cameraDirection = -transformedVertex; + cameraDirection = -transformedPosition; - /* Transform the vertex */ - gl_Position = projectionMatrix*transformedVertex4; + /* Transform the position */ + gl_Position = projectionMatrix*transformedPosition4; } From 5ad384462669f5d90c055651ef060252fc13d25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 20 Oct 2012 21:59:47 +0200 Subject: [PATCH 192/256] PhongShader: fall back to GLSL 1.20 if 3.30/3.20 is not supported. --- src/Shaders/PhongShader.cpp | 11 +++++++++-- src/Shaders/PhongShader.frag | 7 +++++++ src/Shaders/PhongShader.h | 4 ++-- src/Shaders/PhongShader.vert | 11 +++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 382648f2c..8d79c69ba 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -17,14 +17,21 @@ #include +#include "Extensions.h" #include "Shader.h" namespace Magnum { namespace Shaders { PhongShader::PhongShader() { Corrade::Utility::Resource rs("MagnumShaders"); - attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, rs.get("PhongShader.vert"))); - attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, rs.get("PhongShader.frag"))); + Version v = Context::current()->isVersionSupported(Version::GL320) ? Version::GL320 : Version::GL210; + attachShader(Shader::fromData(v, Shader::Type::Vertex, rs.get("PhongShader.vert"))); + attachShader(Shader::fromData(v, Shader::Type::Fragment, rs.get("PhongShader.frag"))); + + if(!Context::current()->isExtensionSupported()) { + bindAttributeLocation(Position::Location, "position"); + bindAttributeLocation(Normal::Location, "normal"); + } link(); diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index 16a100336..c6d9c9be5 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -1,3 +1,8 @@ +#if __VERSION__ == 120 +#define in varying +#define color gl_FragColor +#endif + uniform vec3 ambientColor = vec3(0.0, 0.0, 0.0); uniform vec3 diffuseColor; uniform vec3 specularColor = vec3(1.0, 1.0, 1.0); @@ -8,7 +13,9 @@ in vec3 transformedNormal; in vec3 lightDirection; in vec3 cameraDirection; +#if __VERSION__ != 120 out vec4 color; +#endif void main() { /* Ambient color */ diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index dfd4ab045..d334133a9 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -30,8 +30,8 @@ namespace Magnum { namespace Shaders { /** @brief Phong shader -@requires_gl33 The shader is written in GLSL 3.3, although it should be trivial - to port it to older versions. +If supported, uses GLSL 3.20 and @extension{ARB,explicit_attrib_location}, +otherwise falls back to GLSL 1.20. */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 8fb57f05a..3872fcc74 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -1,9 +1,20 @@ +#if __VERSION__ == 120 +#define in attribute +#define out varying +#endif + uniform mat4 transformationMatrix; uniform mat4 projectionMatrix; uniform vec3 light; +#if __VERSION__ != 120 && defined(GL_ARB_explicit_attrib_location) +#extension GL_ARB_explicit_attrib_location: enable layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; +#else +in vec4 position; +in vec3 normal; +#endif out vec3 transformedNormal; out vec3 lightDirection; From 45f349644fb3b7b1c9c08bf83bffe2c827fb4498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 16:58:54 +0200 Subject: [PATCH 193/256] Ability to easily get pointer to data from Resource. Neither operator*() nor operator->() can be used to pass plain pointer to function or store it in variable. Now it should be converted automatically. --- src/ResourceManager.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index d4b1db993..62a717913 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -345,6 +345,12 @@ template class Resource { return static_cast(data); } + /** @brief %Resource data */ + inline operator U*() { + acquire(); + return static_cast(data); + } + private: inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { manager->incrementReferenceCount(key); From 53d82bda19d7e0d8eec5b53886da05d096533d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 16:34:02 +0200 Subject: [PATCH 194/256] Got rid of default Buffer target. For non-DSA access user can now specify target hint, which will be used when binding the buffer internally. --- src/Buffer.cpp | 4 ++-- src/Buffer.h | 50 ++++++++++++++++++++++++++------------------- src/BufferedImage.h | 4 +++- src/IndexedMesh.cpp | 4 ++-- src/IndexedMesh.h | 8 ++++++-- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5ecefd2e8..45647eeed 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -85,7 +85,7 @@ void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOff } void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { - glBufferData(static_cast(bindInternal(_defaultTarget)), size, data, static_cast(usage)); + glBufferData(static_cast(bindInternal(_targetHint)), size, data, static_cast(usage)); } void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { @@ -93,7 +93,7 @@ void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffe } void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { - glBufferSubData(static_cast(bindInternal(_defaultTarget)), offset, size, data); + glBufferSubData(static_cast(bindInternal(_targetHint)), offset, size, data); } void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { diff --git a/src/Buffer.h b/src/Buffer.h index 04a127405..17f69a52d 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -65,7 +65,8 @@ The engine tracks currently bound buffers to avoid unnecessary calls to @fn_gl{BindBuffer}. If the buffer is already bound to some target, functions copy(), setData() and setSubData() use that target in @fn_gl{CopyBufferSubData}, @fn_gl{BufferData} and @fn_gl{BufferSubData} -functions instead of binding the buffer to some specific target. +functions instead of binding the buffer to some specific target. You can also +use setTargetHint() to possibly reduce unnecessary rebinding. If extension @extension{EXT,direct_state_access} is available, functions copy(), setData() and setSubData() use DSA functions to avoid unnecessary @@ -259,8 +260,10 @@ class MAGNUM_EXPORT Buffer { * @param writeOffset Offset in the write buffer * @param size Data size * - * If @extension{EXT,direct_state_access} is not available, both - * buffers are bound to some target before the copy is performed. + * If @extension{EXT,direct_state_access} is not available and the + * buffers aren't already bound somewhere, they are bound to + * `Target::CopyRead` and `Target::CopyWrite` before the copy is + * performed. * @requires_gl31 Extension @extension{ARB,copy_buffer} * @requires_gles30 (no extension providing this functionality) * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or @@ -272,13 +275,11 @@ class MAGNUM_EXPORT Buffer { /** * @brief Constructor - * @param defaultTarget Default target (used when calling bind() - * without parameter) * * Generates new OpenGL buffer. * @see @fn_gl{GenBuffers} */ - inline Buffer(Target defaultTarget): _defaultTarget(defaultTarget) { + inline Buffer(): _targetHint(Target::Array) { glGenBuffers(1, &_id); } @@ -290,19 +291,24 @@ class MAGNUM_EXPORT Buffer { */ virtual ~Buffer(); - /** @brief Default bind type */ - inline Target defaultTarget() const { return _defaultTarget; } - /** @brief OpenGL buffer ID */ inline GLuint id() const { return _id; } + /** @brief Target hint */ + inline Target targetHint() const { return _targetHint; } + /** - * @brief Bind buffer + * @brief Set target hint * - * Binds buffer to default target. - * @see bind(Target) + * If @extension{EXT,direct_state_access} is not available, the buffer + * must be internally bound to some target before any operation. You + * can specify target which will always be used when binding the + * buffer internally, possibly saving some calls to @fn_gl{BindBuffer}. + * + * Default target hint is `Target::Array`. + * @see setData(), setSubData() */ - inline void bind() { bind(_defaultTarget); } + inline void setTargetHint(Target hint) { _targetHint = hint; } /** * @brief Bind buffer @@ -318,9 +324,10 @@ class MAGNUM_EXPORT Buffer { * @param data Pointer to data * @param usage %Buffer usage * - * If @extension{EXT,direct_state_access} is not available, the buffer - * is bound to some target before the operation. - * @see @fn_gl{BindBuffer} and @fn_gl{BufferData} or + * If @extension{EXT,direct_state_access} is not available and the + * buffer is not already bound somewhere, it is bound to hinted target + * before the operation. + * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferData} or * @fn_gl_extension{NamedBufferData,EXT,direct_state_access} */ inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) { @@ -360,10 +367,11 @@ class MAGNUM_EXPORT Buffer { * @param size Data size * @param data Pointer to data * - * If @extension{EXT,direct_state_access} is not available, the buffer - * is bound to some target before the operation. - * @see @fn_gl{BindBuffer} and @fn_gl{BufferSubData} or - * @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} + * If @extension{EXT,direct_state_access} is not available and the + * buffer is not already bound somewhere, it is bound to hinted target + * before the operation. + * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferSubData} + * or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} */ inline void setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { (this->*setSubDataImplementation)(offset, size, data); @@ -418,7 +426,7 @@ class MAGNUM_EXPORT Buffer { static SetSubDataImplementation setSubDataImplementation; GLuint _id; - Target _defaultTarget; + Target _targetHint; }; } diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 4ec955e47..a09f01964 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -48,7 +48,9 @@ template class BufferedImage: public AbstractImage { * Dimensions and buffer are empty, call setData() to fill the image * with data. */ - inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {} + inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type) { + _buffer.setTargetHint(Buffer::Target::PixelPack); + } /** @brief %Image size */ inline constexpr typename DimensionTraits::VectorType size() const { return _size; } diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 6e9e96549..b6473c677 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -30,7 +30,7 @@ void IndexedMesh::draw() { /* Buffers must be bound after initialization */ #ifdef MAGNUM_TARGET_GLES bind(); - _indexBuffer.bind(); + _indexBuffer.bind(Buffer::Target::ElementArray); #endif /** @todo Start at given index */ @@ -50,7 +50,7 @@ void IndexedMesh::finalize() { /* Bind index buffer to VAO too */ #ifndef MAGNUM_TARGET_GLES - _indexBuffer.bind(); + _indexBuffer.bind(Buffer::Target::ElementArray); #endif } #endif diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 5b9deec23..541c81a7b 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -37,7 +37,9 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * Note that you have to call setVertexCount(), setIndexCount() and * setIndexType() manually for mesh to draw properly. */ - inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(Buffer::Target::ElementArray), _indexCount(0), _indexType(Type::UnsignedShort) {} + inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexCount(0), _indexType(Type::UnsignedShort) { + _indexBuffer.setTargetHint(Buffer::Target::ElementArray); + } /** * @brief Constructor @@ -46,7 +48,9 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @param indexCount Count of indices * @param indexType Type of indices (indexable, see TypeTraits) */ - inline IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort): Mesh(primitive, vertexCount), _indexBuffer(Buffer::Target::ElementArray), _indexCount(indexCount), _indexType(indexType) {} + inline IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort): Mesh(primitive, vertexCount), _indexCount(indexCount), _indexType(indexType) { + _indexBuffer.setTargetHint(Buffer::Target::ElementArray); + } /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } From 21acb3edc6fc6e71c61f60f2a4ae612c9460b528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 16:01:40 +0200 Subject: [PATCH 195/256] Mesh rework, part 1: better vertex attribute management. * Instead of "binding attributes" the user now "adds vertex buffer". It corresponds better with what OpenGL itself does. * Vertex buffers now must be managed by the user. * Shader attributes are now static const members instead of typedefs to allow more convenient add*VertexBuffer*() calls. --- src/AbstractShaderProgram.h | 33 +-- src/Mesh.cpp | 117 +++------ src/Mesh.h | 261 +++++++++++++++------ src/MeshTools/Interleave.h | 8 +- src/Physics/DebugDrawResourceManager.cpp | 3 +- src/Physics/DebugDrawResourceManager.h | 5 +- src/Physics/Implementation/BoxRenderer.cpp | 22 +- src/Physics/Implementation/BoxRenderer.h | 7 +- src/Shaders/PhongShader.cpp | 7 +- src/Shaders/PhongShader.h | 4 +- 10 files changed, 268 insertions(+), 199 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 5c2306051..bd0cdfaf9 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -44,12 +44,12 @@ class Shader; This class is designed to be used via subclassing. Subclasses define these functions and properties: - - %Attribute location typedefs defining locations and types - for attribute binding with Mesh::bindAttribute(), for example: + - %Attribute definitions with location and type for + configuring meshes, for example: @code -typedef Attribute<0, Point3D> Position; -typedef Attribute<1, Vector3> Normal; -typedef Attribute<2, Vector2> TextureCoords; +static const Attribute<0, Point3D> Position; +static const Attribute<1, Vector3> Normal; +static const Attribute<2, Vector2> TextureCoordinates; @endcode @todoc Output attribute location (for bindFragmentDataLocationIndexed(), referenced also from Framebuffer::mapDefaultForDraw() / Framebuffer::mapForDraw()) @@ -103,7 +103,7 @@ shader code, e.g.: // or #extension GL_ARB_explicit_attrib_location: enable layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; -layout(location = 2) in vec2 textureCoords; +layout(location = 2) in vec2 textureCoordinates; @endcode Similarly for ouput attributes, you can also specify blend equation color index for them (see Framebuffer::BlendFunction for more information about @@ -131,9 +131,9 @@ attaching the shaders and linking the program: @code // Shaders attached... -bindAttributeLocation(Position::Location, "position"); -bindAttributeLocation(Normal::Location, "normal"); -bindAttributeLocation(TextureCoords::Location, "textureCoords"); +bindAttributeLocation(Position.Location, "position"); +bindAttributeLocation(Normal.Location, "normal"); +bindAttributeLocation(TextureCoords.Location, "textureCoordinates"); bindFragmentDataLocationIndexed(0, 0, "color"); bindFragmentDataLocationIndexed(1, 1, "ambient"); @@ -185,10 +185,11 @@ setUniform(SpecularTextureUniform, SpecularTextureLayer); @section AbstractShaderProgram-rendering-workflow Rendering workflow -Basic workflow with %AbstractShaderProgram subclasses is: instancing the class -(once at the beginning), then in draw event setting uniforms and marking the -shader for use, binding required textures to their respective layers using -AbstractTexture::bind(GLint) and calling Mesh::draw(). For example: +Basic workflow with %AbstractShaderProgram subclasses is to instance the class +and configuring attribute binding in meshes (see @ref Mesh-configuration "Mesh documentation" +for more information) at the beginning, then in draw event setting uniforms +and marking the shader for use, binding required textures to their respective +layers using AbstractTexture::bind(GLint) and calling Mesh::draw(). Example: @code shader->setTransformation(transformation) ->setProjection(projection) @@ -205,9 +206,9 @@ The engine tracks currently used shader program to avoid unnecessary calls to @fn_gl{UseProgram}. If extension @extension{ARB,separate_shader_objects} or -@extension{EXT,direct_state_access} is available, uniform setting -functions use DSA functions to avoid unnecessary calls to @fn_gl{UseProgram}. -See setUniform(GLint, GLfloat) documentation for more information. +@extension{EXT,direct_state_access} is available, uniform setting functions +use DSA functions to avoid unnecessary calls to @fn_gl{UseProgram}. See +setUniform(GLint, GLfloat) documentation for more information. To achieve least state changes, set all uniforms in one run -- method chaining comes in handy. diff --git a/src/Mesh.cpp b/src/Mesh.cpp index bd763af43..9c91ff31b 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -27,7 +27,7 @@ Mesh::Mesh(Mesh&& other): #ifndef MAGNUM_TARGET_GLES vao(other.vao), #endif - _primitive(other._primitive), _vertexCount(other._vertexCount), finalized(other.finalized), _buffers(other._buffers), _attributes(other._attributes) + _primitive(other._primitive), _vertexCount(other._vertexCount), finalized(other.finalized), attributes(other.attributes) { #ifndef MAGNUM_TARGET_GLES other.vao = 0; @@ -35,9 +35,6 @@ Mesh::Mesh(Mesh&& other): } void Mesh::destroy() { - for(auto& it: _buffers) - delete it.first; - #ifndef MAGNUM_TARGET_GLES glDeleteVertexArrays(1, &vao); #endif @@ -52,8 +49,7 @@ Mesh& Mesh::operator=(Mesh&& other) { _primitive = other._primitive; _vertexCount = other._vertexCount; finalized = other.finalized; - _buffers = other._buffers; - _attributes = other._attributes; + attributes = other.attributes; #ifndef MAGNUM_TARGET_GLES other.vao = 0; @@ -62,13 +58,6 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } -Buffer* Mesh::addBuffer(BufferType interleaved) { - Buffer* buffer = new Buffer(Buffer::Target::Array); - _buffers.insert(make_pair(buffer, make_pair(interleaved, vector()))); - - return buffer; -} - void Mesh::draw() { /* Vertex array must be bound before finalization */ #ifndef MAGNUM_TARGET_GLES @@ -102,8 +91,8 @@ void Mesh::unbind() { #ifndef MAGNUM_TARGET_GLES glBindVertexArray(0); #else - for(set::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it) - glDisableVertexAttribArray(*it); + for(const Attribute& attribute: attributes) + glDisableVertexAttribArray(attribute.location); #endif } @@ -111,45 +100,8 @@ void Mesh::finalize() { /* Already finalized */ if(finalized) return; - CORRADE_ASSERT(_vertexCount, "Mesh: the mesh has zero vertex count!", ); - - /* Finalize attribute positions for every buffer */ - for(auto& it: _buffers) { - /* Avoid confustion */ - bool interleaved = it.second.first == BufferType::Interleaved; - vector& attributes = it.second.second; - - /* Interleaved buffer, set stride and position of first attribute */ - if(interleaved) { - /* Set attribute position and compute stride */ - GLsizei stride = 0; - for(vector::iterator ait = attributes.begin(); ait != attributes.end(); ++ait) { - /* The attribute is positioned at the end of previous */ - ait->pointer = reinterpret_cast(stride); - - /* Add attribute size (per vertex) to stride */ - stride += ait->size*TypeInfo::sizeOf(ait->type); - } - - /* Set computed stride for all attributes */ - for(vector::iterator ait = attributes.begin(); ait != attributes.end(); ++ait) - ait->stride = stride; - - /* Non-interleaved buffer, set position of every attribute */ - } else { - /* Set attribute position */ - GLsizei position = 0; - for(vector::iterator ait = attributes.begin(); ait != attributes.end(); ++ait) { - /* The attribute is positioned at the end of previous attribute array */ - ait->pointer = reinterpret_cast(position); - - /* Add attribute size (for all vertices) to position */ - position += ait->size*TypeInfo::sizeOf(ait->type)*_vertexCount; - } - } - } + CORRADE_ASSERT((_vertexCount == 0) == attributes.empty(), "Mesh: vertex count is non-zero, but no attributes are bound", ); - /* Mesh is now finalized, attribute binding is not allowed */ finalized = true; #ifndef MAGNUM_TARGET_GLES @@ -158,46 +110,33 @@ void Mesh::finalize() { } void Mesh::bindBuffers() { - /* Enable vertex arrays for all attributes */ - for(set::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it) - glEnableVertexAttribArray(*it); - - for(auto& it: _buffers) { - /* Avoid confusion */ - vector& attributes = it.second.second; - - /* Bind buffer */ - it.first->bind(); - - /* Bind all attributes to this buffer */ - for(vector::const_iterator ait = attributes.begin(); ait != attributes.end(); ++ait) - #ifndef MAGNUM_TARGET_GLES - if(TypeInfo::isIntegral(ait->type)) - glVertexAttribIPointer(ait->attribute, ait->size, static_cast(ait->type), ait->stride, ait->pointer); - else - #endif - glVertexAttribPointer(ait->attribute, ait->size, static_cast(ait->type), GL_FALSE, ait->stride, ait->pointer); + /* Bind all attributes to this buffer */ + for(const Attribute& attribute: attributes) { + glEnableVertexAttribArray(attribute.location); + + attribute.buffer->bind(Buffer::Target::Array); + + #ifndef MAGNUM_TARGET_GLES + if(TypeInfo::isIntegral(attribute.type)) + glVertexAttribIPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); + else + #endif + glVertexAttribPointer(attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, reinterpret_cast(attribute.offset)); } } #endif -void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type) { - /* The mesh is finalized or attribute is already bound, nothing to do */ - if(finalized || _attributes.find(attribute) != _attributes.end()) return; - - /* If buffer is not managed by this mesh, nothing to do */ - auto found = _buffers.find(buffer); - if(found == _buffers.end()) return; - - Attribute a; - a.attribute = attribute; - a.size = size; - a.type = type; - a.stride = 0; - a.pointer = nullptr; - - found->second.second.push_back(a); - _attributes.insert(attribute); +void Mesh::addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride) { + CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", ); + + attributes.push_back({ + buffer, + location, + count, + type, + offset, + stride + }); } } diff --git a/src/Mesh.h b/src/Mesh.h index 284346110..2e8aee8d0 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -19,11 +19,9 @@ * @brief Class Magnum::Mesh */ -#include #include -#include -#include "Magnum.h" +#include "AbstractShaderProgram.h" #include "TypeTraits.h" namespace Magnum { @@ -33,6 +31,52 @@ class Buffer; /** @brief Base class for managing non-indexed meshes +@section Mesh-configuration Mesh configuration + +To properly configure mesh, you have to set primitive and vertex count, either +in constructor or using setPrimitive() and setVertexCount(). Then create +vertex buffers, fill them with vertex data and assign them to mesh and given +shader locations using addVertexBuffer() or addInterleavedVertexBuffer(). You +can also use MeshTools::interleave() to conveniently set vertex count and +buffer data. + +Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, +so you have to manage it on your own. On the other hand it allows you to use +one buffer for more meshes (each mesh for example configured for different +shader) or store more than only vertex data in one buffer. + +Example usage -- filling buffer with position data, configuring the mesh and +assigning the buffer to mesh to use with custom shader: +@code +Buffer* buffer; +Mesh* mesh; + +static constexpr Point3D positions[30] = { + // ... +}; +buffer->setData(positions, Buffer::Usage::StaticDraw); + +mesh->setPrimitve(Mesh::Primitive::Triangles) + ->setVertexCount(30) + ->addVertexBuffer(buffer, MyShader::Position); +@endcode + +Example usage -- creating a plane mesh and assigning buffer with interleaved +vertex attributes for use with phong shader: +@code +Buffer* buffer; +Mesh* mesh; + +Primitives::Plane plane; +MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, *plane.positions(0), *plane.normals(0)); +mesh->setPrimitive(plane.primitive()) + ->addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position, Shaders::PhongShader::Normal); +@endcode + +@section Mesh-drawing Rendering meshes + +Basic workflow is to set up respective shader (see @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" for more infromation) and call Mesh::draw(). + VAOs are used for desktop OpenGL (not in OpenGL ES). @requires_gl30 Extension @extension{APPLE,vertex_array_object} @requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) @@ -282,20 +326,6 @@ class MAGNUM_EXPORT Mesh { TriangleFan = GL_TRIANGLE_FAN }; - /** - * @brief %Buffer type - * - * If storing more than one attribute data in the buffer, the data of - * one attribute can be either kept together or interleaved with data - * for another attributes, so data for every vertex will be in one - * continuous place. - * @see addBuffer() - */ - enum class BufferType: bool { - Interleaved, /**< Interleaved buffer */ - NonInterleaved /**< Non-interleaved buffer */ - }; - /** * @brief Implicit constructor * @param primitive Primitive type @@ -330,7 +360,6 @@ class MAGNUM_EXPORT Mesh { /** * @brief Destructor * - * Deletes all associated buffers. * @see @fn_gl{DeleteVertexArrays} */ inline virtual ~Mesh() { destroy(); } @@ -364,52 +393,127 @@ class MAGNUM_EXPORT Mesh { * @brief Set vertex count * @return Pointer to self (for method chaining) * - * This forces recalculation of attribute positions upon next drawing. + * @attention All bound attributes are reset after calling this + * function, so you must call + * addVertexBuffer()/addInterleavedVertexBuffer() afterwards. * @see MeshTools::interleave() */ inline Mesh* setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; finalized = false; + attributes.clear(); return this; } /** - * @brief Add buffer - * @param interleaved Whether the buffer is interleaved + * @brief Add buffer with non-interleaved vertex attributes for use with given shader + * + * Attribute list is combination of attribute definitions (specified + * in implementation of given shader) and offsets between attribute + * arrays. * - * Adds new buffer to the mesh. The buffer can be then filled with - * Buffer::setData(). See also isInterleaved(). + * See @ref Mesh-configuration "class documentation" for simple usage + * example. For more involved example imagine that you have buffer + * with 35 bytes of some other data at the beginning (possibly material + * configuration), then position array, then texture coordinate array + * and then normal array. You want to draw it with Shaders::PhongShader, + * but it accepts only position and normal, so you have to skip the + * texture coordinate array: + * @code + * Mesh* mesh; + * Buffer* buffer; + * mesh->addVertexBuffer(buffer, + * 35, // skip other data + * Shaders::PhongShader::Position, // position array + * sizeof(Vector2)*mesh->vertexCount(), // skip texture coordinate array + * Shaders::PhongShader::Normal); // normal array + * @endcode * - * @todo Move interleaveability to Buffer itself? + * Vou can also achieve the same effect by calling this function more + * times with absolute offsets: + * @code + * mesh->addVertexBuffer(buffer, 35, Shaders::PhongShader::Position); + * ->addVertexBuffer(buffer, 35 + (sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2))* + * mesh->vertexCount(), Shaders::PhongShader::Normal); + * @endcode + * + * @attention Non-zero vertex count must be set before calling this + * function. + * @attention The buffer passed as parameter is not managed by the + * mesh, you must ensure it will exist for whole lifetime of the + * mesh and delete it afterwards. + * + * @see addInterleavedVertexBuffer() */ - Buffer* addBuffer(BufferType interleaved); + template inline Mesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { + addVertexBufferInternal(buffer, 0, attributes...); + return this; + } /** - * @brief Whether given buffer is interleaved - * @return True if the buffer belongs to the mesh and the buffer is - * interleaved, false otherwise. + * @brief Add buffer with interleaved vertex attributes for use with given shader + * + * Parameter @p offset is offset of the interleaved array from the + * beginning, attribute list is combination of attribute definitions + * (specified in implementation of given shader) and offsets between + * attributes. + * + * See @ref Mesh-configuration "class documentation" for simple usage + * example. For more involved example imagine that you have buffer + * with 35 bytes of some other data at the beginning (possibly material + * configuration) and then the interleaved vertex array. Each vertex + * consists of weight, position, texture coordinate and normal. You + * want to draw it with Shaders::PhongShader, but it accepts only + * position and normal, so you have to skip weight and texture + * coordinate in each vertex: + * @code + * Mesh* mesh; + * Buffer* buffer; + * mesh->addInterleavedVertexBuffer(buffer, + * 35, // skip other data + * sizeof(GLfloat), // skip vertex weight + * Shaders::PhongShader::Position, // vertex position + * sizeof(Vector2), // skip texture coordinates + * Shaders::PhongShader::Normal); // vertex normal + * @endcode + * + * You can also achieve the same effect by calling addVertexBufferStride() + * more times with absolute offset from the beginning and stride + * between vertex attributes: + * @code + * GLsizei stride = // size of one vertex + * sizeof(GLfloat) + + * sizeof(Shaders::PhongShader::Position::Type) + + * sizeof(Vector2) + + * sizeof(Shaders::PhongShader::Normal::Type); + * + * mesh->addVertexBufferStride(buffer, 35 + sizeof(GLfloat), + * stride, Shaders::PhongShader::Position); + * ->addVertexBufferStride(buffer, 35 + sizeof(GLfloat) + + * sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2), + * stride, Shaders::PhongShader::Normal); + * @endcode + * + * @attention Non-zero vertex count must be set before calling this + * function. + * @attention The buffer passed as parameter is not managed by the + * mesh, you must ensure it will exist for whole lifetime of the + * mesh and delete it afterwards. * - * See also addBuffer(). + * @see addVertexBufferStride(), addVertexBuffer() */ - inline bool isInterleaved(Buffer* buffer) const { - auto found = _buffers.find(buffer); - return found != _buffers.end() && found->second.first == BufferType::Interleaved; + template inline Mesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { + addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); + return this; } /** - * @brief Bind attribute - * @tparam attribute Attribute, defined in the shader - * @param buffer Buffer where bind the attribute to (pointer - * returned by addBuffer()) - * @return Pointer to self (for method chaining) + * @brief Add buffer with interleaved vertex attributes for use with given shader * - * Binds attribute of given type with given buffer. If the attribute is - * already bound, given buffer isn't managed with this mesh (wasn't - * initialized with addBuffer) or the mesh was already drawn, the - * function does nothing. + * See addInterleavedVertexBuffer() for more information. */ - template inline Mesh* bindAttribute(Buffer* buffer) { - bindAttribute(buffer, Attribute::Location, TypeTraits::count(), TypeTraits::type()); + template inline Mesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { + addInterleavedVertexBufferInternal(buffer, offset, stride, attribute); return this; } @@ -453,15 +557,54 @@ class MAGNUM_EXPORT Mesh { MAGNUM_LOCAL void finalize(); private: - /** @brief Vertex attribute */ struct MAGNUM_LOCAL Attribute { - GLuint attribute; /**< @brief %Attribute ID */ - GLint size; /**< @brief How many items of `type` are in the attribute */ - Type type; /**< @brief %Attribute item type */ - GLsizei stride; /**< @brief Distance of two adjacent attributes of this type in interleaved buffer */ - const GLvoid* pointer; /**< @brief Pointer to first attribute of this type in the buffer */ + Buffer* buffer; + GLuint location; + GLint count; + Type type; + GLintptr offset; + GLsizei stride; }; + /* Adding non-interleaved vertex attributes */ + template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute&, const U&... attributes) { + addVertexAttribute(buffer, location, TypeTraits::count(), TypeTraits::type(), offset, 0); + + /* Add size of this attribute array to offset for next attribute */ + addVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size()*_vertexCount, attributes...); + } + template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, GLintptr gap, const T&... attributes) { + /* Add the gap to offset for next attribute */ + addVertexBufferInternal(buffer, offset+gap, attributes...); + } + inline void addVertexBufferInternal(Buffer*, GLintptr) {} + + /* Computing stride of interleaved vertex attributes */ + template inline static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute&, const U&... attributes) { + return TypeTraits::count()*TypeTraits::size() + strideOfInterleaved(attributes...); + } + template inline static GLsizei strideOfInterleaved(GLintptr gap, const T&... attributes) { + return gap + strideOfInterleaved(attributes...); + } + inline static GLsizei strideOfInterleaved() { return 0; } + + /* Adding interleaved vertex attributes */ + template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute&, const U&... attributes) { + addVertexAttribute(buffer, location, TypeTraits::count(), TypeTraits::type(), offset, stride); + + /* Add size of this attribute to offset for next attribute */ + addInterleavedVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size(), stride, attributes...); + } + template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, GLintptr gap, const T&... attributes) { + /* Add the gap to offset for next attribute */ + addInterleavedVertexBufferInternal(buffer, offset+gap, stride, attributes...); + } + inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} + + void MAGNUM_EXPORT addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride); + + void destroy(); + #ifndef MAGNUM_TARGET_GLES GLuint vao; #endif @@ -469,25 +612,7 @@ class MAGNUM_EXPORT Mesh { GLsizei _vertexCount; bool finalized; - /** - * @brief Buffers with their attributes - * - * Map of associated buffers, evey buffer has: - * - boolean value which signalizes whether the buffer is interleaved - * - list of bound attributes - */ - std::map > > _buffers; - - /** - * @brief List of all bound attributes - * - * List of all bound attributes bound with bindAttribute(). - */ - std::set _attributes; - - MAGNUM_EXPORT void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type); - - void destroy(); + std::vector attributes; }; } diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 44451174f..6f85ef2b2 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -53,8 +53,6 @@ class Interleave { } template void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { - CORRADE_ASSERT(mesh->isInterleaved(buffer), "MeshTools::interleave(): the buffer is not interleaved, nothing done", ); - operator()(attributes...); mesh->setVertexCount(_attributeCount); @@ -153,7 +151,7 @@ output to given array buffer and updates vertex count in the mesh accordingly, so you don't have to call Mesh::setVertexCount() on your own. @attention Setting primitive type and binding the attributes to shader is left - to user - see Mesh::setPrimitive() and Mesh::bindAttribute(). + to user - see @ref Mesh-configuration "Mesh documentation". For only one attribute array this function is convenient equivalent to the following, without any performance loss: @@ -162,10 +160,6 @@ buffer->setData(attribute, usage); mesh->setVertexCount(attribute.size()); @endcode -@attention If there is more than one attribute array, the buffer must be set - as interleaved (see Mesh::addBuffer()), otherwise this function does - nothing. - @see MeshTools::compressIndices() */ template inline void interleave(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp index 92f27730f..539e677f8 100644 --- a/src/Physics/DebugDrawResourceManager.cpp +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -16,6 +16,7 @@ #include "DebugDrawResourceManager.h" #include "AbstractShaderProgram.h" +#include "Buffer.h" #include "Mesh.h" #include "AbstractShape.h" #include "Box.h" @@ -27,7 +28,7 @@ namespace Magnum { -template class ResourceManager; +template class ResourceManager; namespace Physics { diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h index 92f292b70..8108e5af9 100644 --- a/src/Physics/DebugDrawResourceManager.h +++ b/src/Physics/DebugDrawResourceManager.h @@ -28,6 +28,7 @@ namespace Magnum { class AbstractShaderProgram; +class Buffer; class Mesh; #ifndef DOXYGEN_GENERATING_OUTPUT @@ -38,7 +39,7 @@ namespace Physics { namespace Implementation { template class AbstractDebugRenderer; }} -extern template class PHYSICS_EXPORT ResourceManager; +extern template class PHYSICS_EXPORT ResourceManager; #endif namespace SceneGraph { @@ -83,7 +84,7 @@ DebugDrawResourceManager::createDebugRenderer(object->shape(), "red") ->setParent(object); @endcode */ -class PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { +class PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { public: #ifdef DOXYGEN_GENERATING_OUTPUT /** @brief %Options */ diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp index e93e2e6ae..c428335d2 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -31,14 +31,13 @@ namespace { constexpr static char shader[] = "shader2d"; constexpr static char key[] = "box2d"; - static Mesh* mesh() { + static Mesh* mesh(Buffer* buffer) { Primitives::Square square; Mesh* mesh = new Mesh; - Buffer* buffer = mesh->addBuffer(Mesh::BufferType::NonInterleaved); buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(square.primitive()) - ->bindAttribute::Position>(buffer) - ->setVertexCount(square.positions(0)->size()); + ->setVertexCount(square.positions(0)->size()) + ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); } }; @@ -46,14 +45,13 @@ namespace { constexpr static char shader[] = "shader3d"; constexpr static char key[] = "box3d"; - static Mesh* mesh() { + static Mesh* mesh(Buffer* buffer) { Primitives::Cube cube; Mesh* mesh = new Mesh; - Buffer* buffer = mesh->addBuffer(Mesh::BufferType::NonInterleaved); buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(cube.primitive()) - ->bindAttribute::Position>(buffer) - ->setVertexCount(cube.positions(0)->size()); + ->setVertexCount(cube.positions(0)->size()) + ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); } }; } @@ -63,9 +61,11 @@ constexpr char BoxMesh<2>::key[]; constexpr char BoxMesh<3>::shader[]; constexpr char BoxMesh<3>::key[]; -template BoxRenderer::BoxRenderer(Box& box, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): AbstractDebugRenderer(BoxMesh::shader, BoxMesh::key, options, parent), box(box) { - if(!this->mesh) - DebugDrawResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(), ResourceDataState::Final, ResourcePolicy::Manual); +template BoxRenderer::BoxRenderer(Box& box, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): AbstractDebugRenderer(BoxMesh::shader, BoxMesh::key, options, parent), buffer(DebugDrawResourceManager::instance()->get(BoxMesh::key)), box(box) { + if(!this->mesh) { + DebugDrawResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual); + DebugDrawResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual); + } } template void BoxRenderer::draw(const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractObject::CameraType* camera) { diff --git a/src/Physics/Implementation/BoxRenderer.h b/src/Physics/Implementation/BoxRenderer.h index 1540c8347..a04683ee4 100644 --- a/src/Physics/Implementation/BoxRenderer.h +++ b/src/Physics/Implementation/BoxRenderer.h @@ -17,7 +17,11 @@ #include "AbstractDebugRenderer.h" -namespace Magnum { namespace Physics { +namespace Magnum { + +class Buffer; + +namespace Physics { template class Box; @@ -30,6 +34,7 @@ template class BoxRenderer: public AbstractDebugRendere void draw(const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractObject::CameraType* camera); private: + Resource buffer; Box& box; }; diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 8d79c69ba..260d291cd 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -22,6 +22,9 @@ namespace Magnum { namespace Shaders { +const PhongShader::Attribute<0, Point3D> PhongShader::Position; +const PhongShader::Attribute<1, Vector3> PhongShader::Normal; + PhongShader::PhongShader() { Corrade::Utility::Resource rs("MagnumShaders"); Version v = Context::current()->isVersionSupported(Version::GL320) ? Version::GL320 : Version::GL210; @@ -29,8 +32,8 @@ PhongShader::PhongShader() { attachShader(Shader::fromData(v, Shader::Type::Fragment, rs.get("PhongShader.frag"))); if(!Context::current()->isExtensionSupported()) { - bindAttributeLocation(Position::Location, "position"); - bindAttributeLocation(Normal::Location, "normal"); + bindAttributeLocation(Position.Location, "position"); + bindAttributeLocation(Normal.Location, "normal"); } link(); diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index d334133a9..478b7b45d 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -35,8 +35,8 @@ otherwise falls back to GLSL 1.20. */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ - typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ + static const Attribute<0, Point3D> Position; /**< @brief Vertex position */ + static const Attribute<1, Vector3> Normal; /**< @brief Normal direction */ PhongShader(); From 5cf24280827ddace5b014cde4b4809753b01e48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 18:23:24 +0200 Subject: [PATCH 196/256] Merged two mesh constructors into one. --- src/Mesh.h | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index 2e8aee8d0..87f69c521 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -326,29 +326,14 @@ class MAGNUM_EXPORT Mesh { TriangleFan = GL_TRIANGLE_FAN }; - /** - * @brief Implicit constructor - * @param primitive Primitive type - * - * Allows creating the object without knowing anything about mesh - * data. Note that you have to call setVertexCount() manually for mesh - * to draw properly. - * @see @fn_gl{GenVertexArrays} - */ - inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0), finalized(false) { - #ifndef MAGNUM_TARGET_GLES - glGenVertexArrays(1, &vao); - #endif - } - /** * @brief Constructor * @param primitive Primitive type * @param vertexCount Vertex count * - * @see @fn_gl{GenVertexArrays} + * @see @fn_gl{GenVertexArrays}, setPrimitive(), setVertexCount() */ - inline Mesh(Primitive primitive, GLsizei vertexCount): _primitive(primitive), _vertexCount(vertexCount), finalized(false) { + inline Mesh(Primitive primitive = Primitive::Triangles, GLsizei vertexCount = 0): _primitive(primitive), _vertexCount(vertexCount), finalized(false) { #ifndef MAGNUM_TARGET_GLES glGenVertexArrays(1, &vao); #endif From 10e64d2d27d3f4f1c6eb1b199dbda10eb7e1754f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 23:32:05 +0200 Subject: [PATCH 197/256] Mesh rework, part 2: reworked internals. * VAOs are used only if the extension is supported. * Removed finalize() and other already useless stuff. * Preparation for DSA and state tracking. --- src/Context.cpp | 4 ++ src/IndexedMesh.cpp | 65 ++++++++++++------ src/IndexedMesh.h | 80 +++++++++++++++------- src/Mesh.cpp | 157 ++++++++++++++++++++++++-------------------- src/Mesh.h | 132 +++++++++++++++++++++---------------- 5 files changed, 270 insertions(+), 168 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index eed515804..a4473c665 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -23,6 +23,8 @@ #include "AbstractTexture.h" #include "Buffer.h" #include "Extensions.h" +#include "IndexedMesh.h" +#include "Mesh.h" #include "Implementation/State.h" #include "BufferedTexture.h" @@ -205,6 +207,8 @@ Context::Context() { AbstractTexture::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); BufferedTexture::initializeContextBasedFunctionality(this); + IndexedMesh::initializeContextBasedFunctionality(this); + Mesh::initializeContextBasedFunctionality(this); } Context::~Context() { diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index b6473c677..061e892df 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -17,21 +17,28 @@ #include +#include "Context.h" +#include "Extensions.h" + namespace Magnum { -void IndexedMesh::draw() { - /* Vertex array must be bound before finalization */ - #ifndef MAGNUM_TARGET_GLES - bind(); - #endif +IndexedMesh::CreateIndexedImplementation IndexedMesh::createIndexedImplementation = &IndexedMesh::createIndexedImplementationDefault; +IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; + +IndexedMesh::IndexedMesh(Mesh::Primitive primitive): Mesh(primitive), _indexCount(0), _indexType(Type::UnsignedShort) { + _indexBuffer.setTargetHint(Buffer::Target::ElementArray); + + (this->*createIndexedImplementation)(); +} - finalize(); +IndexedMesh::IndexedMesh(Mesh::Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType): Mesh(primitive, vertexCount), _indexCount(indexCount), _indexType(indexType) { + _indexBuffer.setTargetHint(Buffer::Target::ElementArray); - /* Buffers must be bound after initialization */ - #ifdef MAGNUM_TARGET_GLES + (this->*createIndexedImplementation)(); +} + +void IndexedMesh::draw() { bind(); - _indexBuffer.bind(Buffer::Target::ElementArray); - #endif /** @todo Start at given index */ glDrawElements(static_cast(primitive()), _indexCount, static_cast(_indexType), nullptr); @@ -39,20 +46,40 @@ void IndexedMesh::draw() { unbind(); } -#ifndef DOXYGEN_GENERATING_OUTPUT -void IndexedMesh::finalize() { - if(isFinalized()) return; - +void IndexedMesh::bind() { CORRADE_ASSERT(_indexCount, "IndexedMesh: the mesh has zero index count!", ); - /* Finalize attribute positions */ - Mesh::finalize(); + Mesh::bind(); + (this->*bindIndexedImplementation)(); +} + +void IndexedMesh::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported()) { + #ifndef MAGNUM_TARGET_GLES + Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; + + createIndexedImplementation = &IndexedMesh::createIndexedImplementationVAO; + bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; + #endif + } +} + +void IndexedMesh::createIndexedImplementationDefault() {} + +#ifndef MAGNUM_TARGET_GLES +void IndexedMesh::createIndexedImplementationVAO() { + glBindVertexArray(vao); - /* Bind index buffer to VAO too */ - #ifndef MAGNUM_TARGET_GLES _indexBuffer.bind(Buffer::Target::ElementArray); - #endif } #endif +void IndexedMesh::bindIndexedImplementationDefault() { + _indexBuffer.bind(Buffer::Target::ElementArray); +} + +#ifndef MAGNUM_TARGET_GLES +void IndexedMesh::bindIndexedImplementationVAO() {} +#endif + } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 541c81a7b..873a6d066 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -25,21 +25,39 @@ namespace Magnum { /** - * @brief Indexed mesh - */ +@brief Indexed mesh + +@section IndexedMesh-configuration Indexed mesh configuration + +Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you +have to specify also index count and type (either in constructor or using +setIndexCount() and setIndexType()). Then fill index buffer or use +MeshTools::compressIndices() to conveniently fill the index buffer and set +index count and type. + +@section IndexedMesh-drawing Rendering meshes + +From user point-of-view the operation is the same as for +@ref Mesh-drawing "non-indexed meshes". + +@section IndexedMesh-performance-optimization Performance optimizations + +If @extension{APPLE,vertex_array_object} is supported, next to +@ref Mesh-performance-optimization "optimizations in Mesh itself" the index +buffer is bound on object construction instead of in every draw() call. +*/ class MAGNUM_EXPORT IndexedMesh: public Mesh { + friend class Context; + public: /** * @brief Implicit constructor * @param primitive Primitive type * - * Allows creating the object without knowing anything about mesh data. - * Note that you have to call setVertexCount(), setIndexCount() and - * setIndexType() manually for mesh to draw properly. + * @see @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} + * is available) */ - inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexCount(0), _indexType(Type::UnsignedShort) { - _indexBuffer.setTargetHint(Buffer::Target::ElementArray); - } + IndexedMesh(Primitive primitive = Primitive::Triangles); /** * @brief Constructor @@ -47,10 +65,12 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @param vertexCount Count of unique vertices * @param indexCount Count of indices * @param indexType Type of indices (indexable, see TypeTraits) + * + * @see setPrimitive(), setVertexCount(), setIndexCount(), + * setIndexType(), @fn_gl{BindVertexArray} (if + * @extension{APPLE,vertex_array_object} is available) */ - inline IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort): Mesh(primitive, vertexCount), _indexCount(indexCount), _indexType(indexType) { - _indexBuffer.setTargetHint(Buffer::Target::ElementArray); - } + IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort); /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } @@ -60,7 +80,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @return Pointer to self (for method chaining) * * @see MeshTools::compressIndices() - * @todo definalize after that? */ inline IndexedMesh* setIndexCount(GLsizei count) { _indexCount = count; @@ -73,6 +92,8 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** * @brief Set index type * @return Pointer to self (for method chaining) + * + * @see MeshTools::compressIndices() */ inline IndexedMesh* setIndexType(Type type) { _indexType = type; @@ -90,20 +111,35 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** * @brief Draw the mesh * - * Expects an active shader with all uniforms set. - * @see Buffer::bind(), bind(), unbind(), finalize(), @fn_gl{DrawElements} + * Expects an active shader with all uniforms set. See + * @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" + * for more information. + * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, + * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} + * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} + * is available), @fn_gl{DrawElements} */ void draw(); - protected: - /** - * @brief Finalize the mesh - * - * @see Mesh::finalize(), Buffer::bind() - */ - MAGNUM_LOCAL void finalize(); - private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + void MAGNUM_LOCAL bind(); + + typedef void(IndexedMesh::*CreateIndexedImplementation)(); + void MAGNUM_LOCAL createIndexedImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL createIndexedImplementationVAO(); + #endif + static MAGNUM_LOCAL CreateIndexedImplementation createIndexedImplementation; + + typedef void(IndexedMesh::*BindIndexedImplementation)(); + void MAGNUM_LOCAL bindIndexedImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL bindIndexedImplementationVAO(); + #endif + static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; + Buffer _indexBuffer; GLsizei _indexCount; Type _indexType; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 9c91ff31b..d5931139d 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -18,59 +18,38 @@ #include #include "Buffer.h" +#include "Context.h" +#include "Extensions.h" using namespace std; namespace Magnum { -Mesh::Mesh(Mesh&& other): - #ifndef MAGNUM_TARGET_GLES - vao(other.vao), - #endif - _primitive(other._primitive), _vertexCount(other._vertexCount), finalized(other.finalized), attributes(other.attributes) -{ - #ifndef MAGNUM_TARGET_GLES - other.vao = 0; - #endif -} +Mesh::CreateImplementation Mesh::createImplementation = &Mesh::createImplementationDefault; +Mesh::DestroyImplementation Mesh::destroyImplementation = &Mesh::destroyImplementationDefault; +Mesh::BindAttributeImplementation Mesh::bindAttributeImplementation = &Mesh::bindAttributeImplementationDefault; +Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; +Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; -void Mesh::destroy() { - #ifndef MAGNUM_TARGET_GLES - glDeleteVertexArrays(1, &vao); - #endif +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(other.attributes) { + other.vao = 0; } Mesh& Mesh::operator=(Mesh&& other) { - destroy(); + (this->*destroyImplementation)(); - #ifndef MAGNUM_TARGET_GLES vao = other.vao; - #endif _primitive = other._primitive; _vertexCount = other._vertexCount; - finalized = other.finalized; attributes = other.attributes; - #ifndef MAGNUM_TARGET_GLES other.vao = 0; - #endif return *this; } void Mesh::draw() { - /* Vertex array must be bound before finalization */ - #ifndef MAGNUM_TARGET_GLES - bind(); - #endif - - /* Finalize, if not already */ - finalize(); - - /* Buffers must be bound after initialization */ - #ifdef MAGNUM_TARGET_GLES bind(); - #endif /** @todo Start at given index */ glDrawArrays(static_cast(_primitive), 0, _vertexCount); @@ -78,65 +57,99 @@ void Mesh::draw() { unbind(); } -#ifndef DOXYGEN_GENERATING_OUTPUT void Mesh::bind() { - #ifndef MAGNUM_TARGET_GLES - glBindVertexArray(vao); - #else - bindBuffers(); - #endif -} + CORRADE_ASSERT((_vertexCount == 0) == attributes.empty(), "Mesh: vertex count is non-zero, but no attributes are bound", ); -void Mesh::unbind() { - #ifndef MAGNUM_TARGET_GLES - glBindVertexArray(0); - #else - for(const Attribute& attribute: attributes) - glDisableVertexAttribArray(attribute.location); - #endif + (this->*bindImplementation)(); } -void Mesh::finalize() { - /* Already finalized */ - if(finalized) return; +void Mesh::addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride) { + CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", ); - CORRADE_ASSERT((_vertexCount == 0) == attributes.empty(), "Mesh: vertex count is non-zero, but no attributes are bound", ); + attributes.push_back({ + buffer, + location, + count, + type, + offset, + stride + }); - finalized = true; + (this->*bindAttributeImplementation)(attributes.back()); +} + +void Mesh::vertexAttribPointer(const Mesh::Attribute& attribute) { + glEnableVertexAttribArray(attribute.location); + + attribute.buffer->bind(Buffer::Target::Array); #ifndef MAGNUM_TARGET_GLES - bindBuffers(); + if(TypeInfo::isIntegral(attribute.type)) + glVertexAttribIPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); + else #endif + glVertexAttribPointer(attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, reinterpret_cast(attribute.offset)); } -void Mesh::bindBuffers() { - /* Bind all attributes to this buffer */ - for(const Attribute& attribute: attributes) { - glEnableVertexAttribArray(attribute.location); - - attribute.buffer->bind(Buffer::Target::Array); - +void Mesh::initializeContextBasedFunctionality(Context* context) { + if(context->isExtensionSupported()) { #ifndef MAGNUM_TARGET_GLES - if(TypeInfo::isIntegral(attribute.type)) - glVertexAttribIPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); - else + Debug() << "Mesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; + + createImplementation = &Mesh::createImplementationVAO; + destroyImplementation = &Mesh::destroyImplementationVAO; + bindAttributeImplementation = &Mesh::bindAttributeImplementationVAO; + bindImplementation = &Mesh::bindImplementationVAO; + unbindImplementation = &Mesh::unbindImplementationVAO; #endif - glVertexAttribPointer(attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, reinterpret_cast(attribute.offset)); } } + +void Mesh::createImplementationDefault() {} + +#ifndef MAGNUM_TARGET_GLES +void Mesh::createImplementationVAO() { + glGenVertexArrays(1, &vao); +} #endif -void Mesh::addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride) { - CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", ); +void Mesh::destroyImplementationDefault() {} - attributes.push_back({ - buffer, - location, - count, - type, - offset, - stride - }); +#ifndef MAGNUM_TARGET_GLES +void Mesh::destroyImplementationVAO() { + glDeleteVertexArrays(1, &vao); } +#endif + +void Mesh::bindAttributeImplementationDefault(const Attribute&) {} + +#ifndef MAGNUM_TARGET_GLES +void Mesh::bindAttributeImplementationVAO(const Attribute& attribute) { + glBindVertexArray(vao); + vertexAttribPointer(attribute); +} +#endif + +void Mesh::bindImplementationDefault() { + for(const Attribute& attribute: attributes) + vertexAttribPointer(attribute); +} + +#ifndef MAGNUM_TARGET_GLES +void Mesh::bindImplementationVAO() { + glBindVertexArray(vao); +} +#endif + +void Mesh::unbindImplementationDefault() { + for(const Attribute& attribute: attributes) + glDisableVertexAttribArray(attribute.location); +} + +#ifndef MAGNUM_TARGET_GLES +void Mesh::unbindImplementationVAO() { + glBindVertexArray(0); +} +#endif } diff --git a/src/Mesh.h b/src/Mesh.h index 87f69c521..b229cc835 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -27,6 +27,7 @@ namespace Magnum { class Buffer; +class Context; /** @brief Base class for managing non-indexed meshes @@ -77,8 +78,12 @@ mesh->setPrimitive(plane.primitive()) Basic workflow is to set up respective shader (see @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" for more infromation) and call Mesh::draw(). -VAOs are used for desktop OpenGL (not in OpenGL ES). -@requires_gl30 Extension @extension{APPLE,vertex_array_object} +@section Mesh-performance-optimization Performance optimizations + +If @extension{APPLE,vertex_array_object} is supported, VAOs are used instead +of binding the buffers and specifying vertex attribute pointers in each +draw() call. + @requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) @todo Support for normalized values (e.g. for color as char[4] passed to @@ -90,6 +95,9 @@ VAOs are used for desktop OpenGL (not in OpenGL ES). @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ class MAGNUM_EXPORT Mesh { + friend class IndexedMesh; + friend class Context; + Mesh(const Mesh& other) = delete; Mesh& operator=(const Mesh& other) = delete; @@ -331,12 +339,11 @@ class MAGNUM_EXPORT Mesh { * @param primitive Primitive type * @param vertexCount Vertex count * - * @see @fn_gl{GenVertexArrays}, setPrimitive(), setVertexCount() + * @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if + * @extension{APPLE,vertex_array_object} is available) */ - inline Mesh(Primitive primitive = Primitive::Triangles, GLsizei vertexCount = 0): _primitive(primitive), _vertexCount(vertexCount), finalized(false) { - #ifndef MAGNUM_TARGET_GLES - glGenVertexArrays(1, &vao); - #endif + inline Mesh(Primitive primitive = Primitive::Triangles, GLsizei vertexCount = 0): _primitive(primitive), _vertexCount(vertexCount) { + (this->*createImplementation)(); } /** @brief Move constructor */ @@ -345,20 +352,16 @@ class MAGNUM_EXPORT Mesh { /** * @brief Destructor * - * @see @fn_gl{DeleteVertexArrays} + * @see @fn_gl{DeleteVertexArrays} (if + * @extension{APPLE,vertex_array_object} is available) */ - inline virtual ~Mesh() { destroy(); } + inline virtual ~Mesh() { + (this->*destroyImplementation)(); + } /** @brief Move assignment */ Mesh& operator=(Mesh&& other); - /** - * @brief Whether the mesh is finalized - * - * When the mesh is finalized, no new attributes can be bound. - */ - inline bool isFinalized() const { return finalized; } - /** @brief Primitive type */ inline Primitive primitive() const { return _primitive; } @@ -385,7 +388,6 @@ class MAGNUM_EXPORT Mesh { */ inline Mesh* setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; - finalized = false; attributes.clear(); return this; } @@ -428,7 +430,10 @@ class MAGNUM_EXPORT Mesh { * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. * - * @see addInterleavedVertexBuffer() + * @see addInterleavedVertexBuffer(), @fn_gl{BindVertexArray}, + * @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, + * @fn_gl{VertexAttribPointer} (if + * @extension{APPLE,vertex_array_object} is available) */ template inline Mesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { addVertexBufferInternal(buffer, 0, attributes...); @@ -485,7 +490,10 @@ class MAGNUM_EXPORT Mesh { * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. * - * @see addVertexBufferStride(), addVertexBuffer() + * @see addVertexBufferStride(), addVertexBuffer(), + * @fn_gl{BindVertexArray}, @fn_gl{EnableVertexAttribArray}, + * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} (if + * @extension{APPLE,vertex_array_object} is available) */ template inline Mesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); @@ -505,42 +513,16 @@ class MAGNUM_EXPORT Mesh { /** * @brief Draw the mesh * - * Expects an active shader with all uniforms set. - * @see bind(), unbind(), finalize(), @fn_gl{DrawArrays} + * Expects an active shader with all uniforms set. See + * @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" + * for more information. + * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, + * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} + * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} + * is available), @fn_gl{DrawArrays} */ virtual void draw(); - protected: - /** - * @brief Bind all buffers - * - * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{VertexAttribPointer} - */ - void bindBuffers(); - - /** - * @brief Bind vertex array or all buffers - * - * @see @fn_gl{BindVertexArray} or bindBuffers() - */ - void bind(); - - /** - * @brief Unbind vertex array or all buffers - * - * @see @fn_gl{BindVertexArray} or @fn_gl{DisableVertexAttribArray} - */ - void unbind(); - - /** - * @brief Finalize the mesh - * - * Computes location and stride of each attribute in its buffer. After - * this function is called, no new attribute can be bound. - * @see bindBuffers() - */ - MAGNUM_LOCAL void finalize(); - private: struct MAGNUM_LOCAL Attribute { Buffer* buffer; @@ -551,6 +533,8 @@ class MAGNUM_EXPORT Mesh { GLsizei stride; }; + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + /* Adding non-interleaved vertex attributes */ template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute&, const U&... attributes) { addVertexAttribute(buffer, location, TypeTraits::count(), TypeTraits::type(), offset, 0); @@ -588,14 +572,52 @@ class MAGNUM_EXPORT Mesh { void MAGNUM_EXPORT addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride); - void destroy(); + void MAGNUM_LOCAL bind(); + + inline void unbind() { + (this->*unbindImplementation)(); + } + void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute); + + typedef void(Mesh::*CreateImplementation)(); + void MAGNUM_LOCAL createImplementationDefault(); #ifndef MAGNUM_TARGET_GLES - GLuint vao; + void MAGNUM_LOCAL createImplementationVAO(); + #endif + static CreateImplementation createImplementation; + + typedef void(Mesh::*DestroyImplementation)(); + void MAGNUM_LOCAL destroyImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL destroyImplementationVAO(); #endif + static DestroyImplementation destroyImplementation; + + typedef void(Mesh::*BindAttributeImplementation)(const Attribute&); + void MAGNUM_LOCAL bindAttributeImplementationDefault(const Attribute& attribute); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL bindAttributeImplementationVAO(const Attribute& attribute); + #endif + static MAGNUM_LOCAL BindAttributeImplementation bindAttributeImplementation; + + typedef void(Mesh::*BindImplementation)(); + void MAGNUM_LOCAL bindImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL bindImplementationVAO(); + #endif + static MAGNUM_LOCAL BindImplementation bindImplementation; + + typedef void(Mesh::*UnbindImplementation)(); + void MAGNUM_LOCAL unbindImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL unbindImplementationVAO(); + #endif + static MAGNUM_LOCAL UnbindImplementation unbindImplementation; + + GLuint vao; Primitive _primitive; GLsizei _vertexCount; - bool finalized; std::vector attributes; }; From 4aa01e073edee5dcaa172e35a8ce882889b119e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 23:08:19 +0200 Subject: [PATCH 198/256] Code cleanup, doc++ --- src/AbstractShaderProgram.h | 4 ++++ src/Buffer.h | 7 +++++++ src/Context.cpp | 2 +- src/Implementation/TextureState.h | 2 -- src/MeshTools/CompressIndices.h | 4 ++-- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index bd0cdfaf9..5ec2aad47 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -95,6 +95,7 @@ MyShader* setProjection(const Matrix4& matrix) { @endcode @subsection AbstractShaderProgram-attribute-location Binding attribute location + The preferred workflow is to specify attribute location for vertex shader input attributes and fragment shader output attributes explicitly in the shader code, e.g.: @@ -142,6 +143,7 @@ bindFragmentDataLocationIndexed(1, 1, "ambient"); @endcode @subsection AbstractShaderProgram-uniform-location Uniform locations + The preferred workflow is to specify uniform locations directly in the shader code, e.g.: @code @@ -162,6 +164,7 @@ GLint projectionUniform = uniformLocation("projection"); @endcode @subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms + The preferred workflow is to specify texture layers directly in the shader code, e.g.: @code @@ -202,6 +205,7 @@ mesh.draw(); @endcode @section AbstractShaderProgram-performance-optimization Performance optimizations + The engine tracks currently used shader program to avoid unnecessary calls to @fn_gl{UseProgram}. diff --git a/src/Buffer.h b/src/Buffer.h index 17f69a52d..93ff82dd9 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -38,6 +38,7 @@ Encapsulates one OpenGL buffer object and provides functions for convenient data updates. @section Buffer-data Data updating + Default way to set or update buffer data with setData() or setSubData() is to explicitly specify data size and pass the pointer to it: @code @@ -61,6 +62,7 @@ buffer.setData(data, Buffer::Usage::StaticDraw); @endcode @section Buffer-performance-optimization Performance optimizations + The engine tracks currently bound buffers to avoid unnecessary calls to @fn_gl{BindBuffer}. If the buffer is already bound to some target, functions copy(), setData() and setSubData() use that target in @@ -307,6 +309,9 @@ class MAGNUM_EXPORT Buffer { * * Default target hint is `Target::Array`. * @see setData(), setSubData() + * @todo Target::ElementArray cannot be used when no VAO is bound - + * http://www.opengl.org/wiki/Vertex_Specification#Index_buffers + * ... damned GL state */ inline void setTargetHint(Target hint) { _targetHint = hint; } @@ -314,6 +319,8 @@ class MAGNUM_EXPORT Buffer { * @brief Bind buffer * @param target %Target * + * @todo Allow binding to Target::ElementArray only if VAO is bound + * to avoid potential issues? * @see @fn_gl{BindBuffer} */ inline void bind(Target target) { bind(target, _id); } diff --git a/src/Context.cpp b/src/Context.cpp index a4473c665..06cfe594f 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -22,11 +22,11 @@ #include "AbstractShaderProgram.h" #include "AbstractTexture.h" #include "Buffer.h" +#include "BufferedTexture.h" #include "Extensions.h" #include "IndexedMesh.h" #include "Mesh.h" #include "Implementation/State.h" -#include "BufferedTexture.h" using namespace std; diff --git a/src/Implementation/TextureState.h b/src/Implementation/TextureState.h index 74388443e..73eca32af 100644 --- a/src/Implementation/TextureState.h +++ b/src/Implementation/TextureState.h @@ -17,8 +17,6 @@ #include "Magnum.h" -#include "Buffer.h" - namespace Magnum { namespace Implementation { struct TextureState { diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index d86dc154c..ec6c88fb5 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -90,8 +90,8 @@ inline std::tuple compressIndices(const std::vector&), but this function writes the output to mesh's index buffer and updates index count and -type in the mesh accordingly, so you don't have to call Mesh::setIndexCount() -and Mesh::setIndexType() on your own. +type in the mesh accordingly, so you don't have to call +IndexedMesh::setIndexCount() and IndexedMesh::setIndexType() on your own. @see MeshTools::interleave() */ From 2871222b86d1bf1d9287678980193c63f04f7165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 23:36:48 +0200 Subject: [PATCH 199/256] Mesh rework, part 3: don't specify vertex/index count in constructor. In most cases the constructor is called at a very different place than where the mesh is configured, leading to mistakes and/or confusion. --- src/IndexedMesh.cpp | 6 ------ src/IndexedMesh.h | 22 +++++----------------- src/Mesh.h | 15 +++++++-------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 061e892df..3bc9c8008 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -31,12 +31,6 @@ IndexedMesh::IndexedMesh(Mesh::Primitive primitive): Mesh(primitive), _indexCoun (this->*createIndexedImplementation)(); } -IndexedMesh::IndexedMesh(Mesh::Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType): Mesh(primitive, vertexCount), _indexCount(indexCount), _indexType(indexType) { - _indexBuffer.setTargetHint(Buffer::Target::ElementArray); - - (this->*createIndexedImplementation)(); -} - void IndexedMesh::draw() { bind(); diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 873a6d066..ccb0ae104 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -30,10 +30,9 @@ namespace Magnum { @section IndexedMesh-configuration Indexed mesh configuration Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you -have to specify also index count and type (either in constructor or using -setIndexCount() and setIndexType()). Then fill index buffer or use -MeshTools::compressIndices() to conveniently fill the index buffer and set -index count and type. +have to call also setIndexCount() and setIndexType(). Then fill index buffer +or use MeshTools::compressIndices() to conveniently fill the index buffer and +set index count and type. @section IndexedMesh-drawing Rendering meshes @@ -50,27 +49,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; public: - /** - * @brief Implicit constructor - * @param primitive Primitive type - * - * @see @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available) - */ - IndexedMesh(Primitive primitive = Primitive::Triangles); - /** * @brief Constructor * @param primitive Primitive type - * @param vertexCount Count of unique vertices - * @param indexCount Count of indices - * @param indexType Type of indices (indexable, see TypeTraits) * + * Creates indexed mesh with zero vertex count and zero index count. * @see setPrimitive(), setVertexCount(), setIndexCount(), * setIndexType(), @fn_gl{BindVertexArray} (if * @extension{APPLE,vertex_array_object} is available) */ - IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort); + IndexedMesh(Primitive primitive = Primitive::Triangles); /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } diff --git a/src/Mesh.h b/src/Mesh.h index b229cc835..1c8c0467d 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -34,12 +34,11 @@ class Context; @section Mesh-configuration Mesh configuration -To properly configure mesh, you have to set primitive and vertex count, either -in constructor or using setPrimitive() and setVertexCount(). Then create -vertex buffers, fill them with vertex data and assign them to mesh and given -shader locations using addVertexBuffer() or addInterleavedVertexBuffer(). You -can also use MeshTools::interleave() to conveniently set vertex count and -buffer data. +To properly configure mesh, you have to set primitive either in constructor or +using setPrimitive() and call setVertexCount(). Then create vertex buffers, +fill them with vertex data and assign them to mesh and given shader locations +using addVertexBuffer() or addInterleavedVertexBuffer(). You can also use +MeshTools::interleave() to conveniently set vertex count and buffer data. Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, so you have to manage it on your own. On the other hand it allows you to use @@ -337,12 +336,12 @@ class MAGNUM_EXPORT Mesh { /** * @brief Constructor * @param primitive Primitive type - * @param vertexCount Vertex count * + * Creates mesh with no vertex buffers and zero vertex count. * @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - inline Mesh(Primitive primitive = Primitive::Triangles, GLsizei vertexCount = 0): _primitive(primitive), _vertexCount(vertexCount) { + inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) { (this->*createImplementation)(); } From 365c664ef9076b026436de29ea3edf724ea725fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 00:38:24 +0200 Subject: [PATCH 200/256] Mesh rework, part 4: don't manage index buffer in IndexedMesh. The user now has to manage the buffer, similarly to vertex buffers in Mesh itself. --- src/IndexedMesh.cpp | 21 ++++++------- src/IndexedMesh.h | 50 +++++++++++++++++-------------- src/MeshTools/CompressIndices.cpp | 9 +++--- src/MeshTools/CompressIndices.h | 12 ++++---- 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 3bc9c8008..5b8b3433d 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -17,18 +17,19 @@ #include +#include "Buffer.h" #include "Context.h" #include "Extensions.h" namespace Magnum { -IndexedMesh::CreateIndexedImplementation IndexedMesh::createIndexedImplementation = &IndexedMesh::createIndexedImplementationDefault; +IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; -IndexedMesh::IndexedMesh(Mesh::Primitive primitive): Mesh(primitive), _indexCount(0), _indexType(Type::UnsignedShort) { - _indexBuffer.setTargetHint(Buffer::Target::ElementArray); - - (this->*createIndexedImplementation)(); +IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { + _indexBuffer = buffer; + (this->*bindIndexBufferImplementation)(); + return this; } void IndexedMesh::draw() { @@ -52,24 +53,24 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { #ifndef MAGNUM_TARGET_GLES Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; - createIndexedImplementation = &IndexedMesh::createIndexedImplementationVAO; + bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationVAO; bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; #endif } } -void IndexedMesh::createIndexedImplementationDefault() {} +void IndexedMesh::bindIndexBufferImplementationDefault() {} #ifndef MAGNUM_TARGET_GLES -void IndexedMesh::createIndexedImplementationVAO() { +void IndexedMesh::bindIndexBufferImplementationVAO() { glBindVertexArray(vao); - _indexBuffer.bind(Buffer::Target::ElementArray); + _indexBuffer->bind(Buffer::Target::ElementArray); } #endif void IndexedMesh::bindIndexedImplementationDefault() { - _indexBuffer.bind(Buffer::Target::ElementArray); + _indexBuffer->bind(Buffer::Target::ElementArray); } #ifndef MAGNUM_TARGET_GLES diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index ccb0ae104..1ee7d5d9e 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -20,7 +20,6 @@ */ #include "Mesh.h" -#include "Buffer.h" namespace Magnum { @@ -30,9 +29,15 @@ namespace Magnum { @section IndexedMesh-configuration Indexed mesh configuration Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you -have to call also setIndexCount() and setIndexType(). Then fill index buffer -or use MeshTools::compressIndices() to conveniently fill the index buffer and -set index count and type. +have to call also setIndexCount() and setIndexType(). Then create index buffer +and assign it to the mesh using setIndexBuffer() or use +MeshTools::compressIndices() to conveniently fill the index buffer and set +index count and type. + +Similarly as in Mesh itself the index buffer is not managed by the mesh, so +you have to manage it on your own. On the other hand it allows you to use +one index buffer for more meshes (with different vertex data in each mesh, for +example) or store more than only index data in one buffer. @section IndexedMesh-drawing Rendering meshes @@ -53,12 +58,21 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @brief Constructor * @param primitive Primitive type * - * Creates indexed mesh with zero vertex count and zero index count. - * @see setPrimitive(), setVertexCount(), setIndexCount(), - * setIndexType(), @fn_gl{BindVertexArray} (if - * @extension{APPLE,vertex_array_object} is available) + * Creates indexed mesh with no index buffer, zero vertex count and + * zero index count. + * @see setPrimitive(), setVertexCount(), setIndexBuffer(), + * setIndexCount(), setIndexType() + */ + inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(Type::UnsignedShort) {} + + /** + * @brief Set index buffer + * + * @see MeshTools::compressIndices(), @fn_gl{BindVertexArray}, + * @fn_gl{BindBuffer} (if @extension{APPLE,vertex_array_object} + * is available) */ - IndexedMesh(Primitive primitive = Primitive::Triangles); + IndexedMesh* setIndexBuffer(Buffer* buffer); /** @brief Index count */ inline GLsizei indexCount() const { return _indexCount; } @@ -88,14 +102,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { return this; } - /** - * @brief Index buffer - * - * Returns pointer to index buffer, which should be then filled with - * indices (of type specified in constructor). - */ - inline Buffer* indexBuffer() { return &_indexBuffer; } - /** * @brief Draw the mesh * @@ -114,12 +120,12 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { void MAGNUM_LOCAL bind(); - typedef void(IndexedMesh::*CreateIndexedImplementation)(); - void MAGNUM_LOCAL createIndexedImplementationDefault(); + typedef void(IndexedMesh::*BindIndexBufferImplementation)(); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(); #ifndef MAGNUM_TARGET_GLES - void MAGNUM_LOCAL createIndexedImplementationVAO(); + void MAGNUM_LOCAL bindIndexBufferImplementationVAO(); #endif - static MAGNUM_LOCAL CreateIndexedImplementation createIndexedImplementation; + static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation; typedef void(IndexedMesh::*BindIndexedImplementation)(); void MAGNUM_LOCAL bindIndexedImplementationDefault(); @@ -128,7 +134,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { #endif static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; - Buffer _indexBuffer; + Buffer* _indexBuffer; GLsizei _indexCount; Type _indexType; }; diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index fc028355b..e3e53b674 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -33,15 +33,16 @@ std::tuple CompressIndices::operator()() const { return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); } -void CompressIndices::operator()(IndexedMesh* mesh, Buffer::Usage usage) const { +void CompressIndices::operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage) const { size_t indexCount; Type indexType; char* data; std::tie(indexCount, indexType, data) = operator()(); - mesh->setIndexType(indexType); - mesh->setIndexCount(indices.size()); - mesh->indexBuffer()->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + mesh->setIndexBuffer(buffer) + ->setIndexType(indexType) + ->setIndexCount(indices.size()); + buffer->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); delete[] data; } diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index ec6c88fb5..1ca638eba 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -41,7 +41,7 @@ class MESHTOOLS_EXPORT CompressIndices { std::tuple operator()() const; - void operator()(IndexedMesh* mesh, Buffer::Usage usage) const; + void operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage) const; private: struct Compressor { @@ -85,18 +85,20 @@ inline std::tuple compressIndices(const std::vector&), but this -function writes the output to mesh's index buffer and updates index count and +function writes the output to given index buffer and updates index count and type in the mesh accordingly, so you don't have to call -IndexedMesh::setIndexCount() and IndexedMesh::setIndexType() on your own. +IndexedMesh::setIndexBuffer(), IndexedMesh::setIndexCount() and +IndexedMesh::setIndexType() on your own. @see MeshTools::interleave() */ -inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { - return Implementation::CompressIndices{indices}(mesh, usage); +inline void compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { + return Implementation::CompressIndices{indices}(mesh, buffer, usage); } }} From 69421f9187fe8de7fa23f6f15bb664befb8b0c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 15:34:01 +0200 Subject: [PATCH 201/256] Provide default constructor for AbstractShaderProgram::Attribute. Fixes compilation with clang. --- src/AbstractShaderProgram.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 5ec2aad47..fdce72366 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -237,6 +237,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @todo Support for BGRA attribute type (OpenGL 3.2, @extension{ARB,vertex_array_bgra}) */ template struct Attribute { + inline constexpr Attribute() = default; + static const GLuint Location = i; /**< Location to which the attribute is bound */ typedef T Type; /**< %Attribute type */ }; From 373b279278e312d254bf72791383c3b2a2f6b30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 15:34:50 +0200 Subject: [PATCH 202/256] Another fix for Clang compilation. --- src/SceneGraph/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 42417426c..9966bca21 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -37,7 +37,7 @@ template class SCENEGRAPH_EXPORT Scene: public Abstract #ifndef DOXYGEN_GENERATING_OUTPUT void setParent(typename AbstractObject::ObjectType* parent) = delete; void setTransformation(const typename DimensionTraits::MatrixType& transformation) = delete; - void multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, typename AbstractObject::Transformation type = DimensionTraits::Transformation::Global) = delete; + void multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, typename AbstractObject::Transformation type = (DimensionTraits::Transformation::Global)) = delete; void translate(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; void scale(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; void rotate(GLfloat angle, const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; From dbe4c22645c477f0ab6e77e0541a09f1a8d9e924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 15:35:35 +0200 Subject: [PATCH 203/256] Don't use constexpr in AbstractImage subclasses. AbstractImage has virtual destructor, thus it is not possible to instantiate it in constant expression. --- src/BufferedImage.h | 2 +- src/Image.h | 4 ++-- src/ImageWrapper.h | 4 ++-- src/Trade/ImageData.h | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index a09f01964..f950b9636 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -53,7 +53,7 @@ template class BufferedImage: public AbstractImage { } /** @brief %Image size */ - inline constexpr typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** * @brief Data diff --git a/src/Image.h b/src/Image.h index ec7ad719b..8613ebc5c 100644 --- a/src/Image.h +++ b/src/Image.h @@ -76,11 +76,11 @@ template class Image: public AbstractImage { inline ~Image() { delete[] _data; } /** @brief %Image size */ - inline constexpr typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } - inline constexpr const void* data() const { return _data; } /**< @overload */ + inline const void* data() const { return _data; } /**< @overload */ /** * @brief Set image data diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 8b45d9c43..68aabd58f 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -80,11 +80,11 @@ template class ImageWrapper: public AbstractImage { inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} /** @brief %Image size */ - inline constexpr typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } - inline constexpr const void* data() const { return _data; } /**< @overload */ + inline const void* data() const { return _data; } /**< @overload */ /** * @brief Set image data diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index d225db8bf..cb6ca2690 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -69,11 +69,11 @@ template class ImageData: public AbstractImage { inline std::string name() const { return _name; } /** @brief %Image size */ - inline constexpr typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } - inline constexpr const void* data() const { return _data; } /**< @overload */ + inline const void* data() const { return _data; } /**< @overload */ private: std::string _name; From 1cf017937726028b2bad4ead3367d5e0ad89ee17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 17:44:38 +0200 Subject: [PATCH 204/256] Avoid linker errors with *WindowContext on mingw. --- modules/FindMagnum.cmake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index a242f3310..1e6e4e97f 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -78,6 +78,13 @@ else() find_package(OpenGLES2 REQUIRED) endif() +# On Windows, *WindowContext libraries need to have ${MAGNUM_LIBRARY} listed +# in dependencies also after *WindowContext.lib static library name to avoid +# linker errors +if(WIN32) + set(_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY ${MAGNUM_LIBRARY}) +endif() + # Additional components foreach(component ${Magnum_FIND_COMPONENTS}) string(TOUPPER ${component} _COMPONENT) @@ -96,7 +103,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL GlutWindowContext) find_package(GLUT) if(GLUT_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() @@ -106,7 +113,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL Sdl2WindowContext) find_package(SDL2) if(SDL2_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) set(_MAGNUM_${_COMPONENT}_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) @@ -117,7 +124,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) if(${component} STREQUAL GlxWindowContext) find_package(X11) if(X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() @@ -128,7 +135,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) find_package(EGL) find_package(X11) if(EGL_FOUND AND X11_FOUND) - set(_MAGNUM_${_COMPONENT}_LIBRARIES ${EGL_LIBRARY} ${X11_LIBRARIES}) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${EGL_LIBRARY} ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) else() unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() From c4f321d91120a9cbd9269a0cf6e542447f4dd3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 17:46:06 +0200 Subject: [PATCH 205/256] Don't use extern template where it is not necessary. Extern template probably causes even inline functions to be instantiated, because MinGW's GCC 4.7.0 then complains about conflicting symbols, removing them fixes the issue. Extern template is not necessary here, as the needed functions are explicitly instantiated in source file only anyway and we don't care about instantiation count of inline functions. --- src/BufferedImage.h | 8 +------- src/Physics/AbstractShape.h | 5 ----- src/Physics/AxisAlignedBox.h | 5 ----- src/Physics/Box.h | 5 ----- src/Physics/Capsule.h | 5 ----- src/Physics/Line.h | 5 ----- src/Physics/Point.h | 5 ----- src/Physics/ShapeGroup.h | 5 ----- src/Physics/ShapedObject.h | 5 ----- src/Physics/ShapedObjectGroup.h | 5 ----- src/Physics/Sphere.h | 5 ----- src/SceneGraph/Camera.h | 4 ---- src/SceneGraph/Object.h | 6 ------ 13 files changed, 1 insertion(+), 67 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index f950b9636..b3c60244a 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -36,7 +36,7 @@ Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ -template class BufferedImage: public AbstractImage { +template class MAGNUM_EXPORT BufferedImage: public AbstractImage { public: const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ @@ -109,12 +109,6 @@ template class BufferedImage: public AbstractImage { Buffer _buffer; /**< @brief %Image buffer */ }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class MAGNUM_EXPORT BufferedImage<1>; -extern template class MAGNUM_EXPORT BufferedImage<2>; -extern template class MAGNUM_EXPORT BufferedImage<3>; -#endif - /** @brief One-dimensional buffered image */ typedef BufferedImage<1> BufferedImage1D; diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 479482ad4..6ac3bdf25 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -118,11 +118,6 @@ template class PHYSICS_EXPORT AbstractShape { virtual bool collides(const AbstractShape* other) const; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT AbstractShape<2>; -extern template class PHYSICS_EXPORT AbstractShape<3>; -#endif - /** @brief Abstract two-dimensional shape */ typedef AbstractShape<2> AbstractShape2D; diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index c007c8ea6..bff023255 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -73,11 +73,6 @@ template class PHYSICS_EXPORT AxisAlignedBox: public Ab _size, _transformedSize; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT AxisAlignedBox<2>; -extern template class PHYSICS_EXPORT AxisAlignedBox<3>; -#endif - /** @brief Two-dimensional axis-aligned box */ typedef AxisAlignedBox<2> AxisAlignedBox2D; diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 896adaa67..d70aac3ab 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -61,11 +61,6 @@ template class PHYSICS_EXPORT Box: public AbstractShape _transformedTransformation; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT Box<2>; -extern template class PHYSICS_EXPORT Box<3>; -#endif - /** @brief Two-dimensional box */ typedef Box<2> Box2D; diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index eb059b13e..7e20a9814 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -100,11 +100,6 @@ template class PHYSICS_EXPORT Capsule: public AbstractS float _radius, _transformedRadius; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT Capsule<2>; -extern template class PHYSICS_EXPORT Capsule<3>; -#endif - /** @brief Two-dimensional capsule */ typedef Capsule<2> Capsule2D; diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 21c0c31ae..9f16e3d2b 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -76,11 +76,6 @@ template class PHYSICS_EXPORT Line: public AbstractShap _b, _transformedB; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT Line<2>; -extern template class PHYSICS_EXPORT Line<3>; -#endif - /** @brief Infinite two-dimensional line */ typedef Line<2> Line2D; diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 0644c85d9..9f867762c 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -59,11 +59,6 @@ template class PHYSICS_EXPORT Point: public AbstractSha Math::Vector _position, _transformedPosition; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT Point<2>; -extern template class PHYSICS_EXPORT Point<3>; -#endif - /** @brief Two-dimensional point */ typedef Point<2> Point2D; diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 505cb3309..de8ab7fd8 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -129,11 +129,6 @@ template class PHYSICS_EXPORT ShapeGroup: public Abstra AbstractShape* b; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT ShapeGroup<2>; -extern template class PHYSICS_EXPORT ShapeGroup<3>; -#endif - /** @brief Two-dimensional shape group */ typedef ShapeGroup<2> ShapeGroup2D; diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index e7e2aac9e..b9763270f 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -86,11 +86,6 @@ template class PHYSICS_EXPORT ShapedObject: public Scen AbstractShape* _shape; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT ShapedObject<2>; -extern template class PHYSICS_EXPORT ShapedObject<3>; -#endif - /** @brief Two-dimensional shaped object */ typedef ShapedObject<2> ShapedObject2D; diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index bf1f00f0c..7654a1286 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -79,11 +79,6 @@ template class PHYSICS_EXPORT ShapedObjectGroup { bool dirty; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT ShapedObjectGroup<2>; -extern template class PHYSICS_EXPORT ShapedObjectGroup<3>; -#endif - /** @brief Group of two-dimensional shaped objects */ typedef ShapedObjectGroup<2> ShapedObjectGroup2D; diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 36992346e..245ed9a4c 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -92,11 +92,6 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh float _radius, _transformedRadius; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -extern template class PHYSICS_EXPORT Sphere<2>; -extern template class PHYSICS_EXPORT Sphere<3>; -#endif - /** @brief Two-dimensional sphere */ typedef Sphere<2> Sphere2D; diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 6f8c68bbb..69427db5c 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -161,10 +161,6 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public template inline AbstractCamera::~AbstractCamera() {} #ifndef DOXYGEN_GENERATING_OUTPUT -/* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT AbstractCamera<2>; -extern template class SCENEGRAPH_EXPORT AbstractCamera<3>; - namespace Implementation { template class Camera {}; diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index cd1d929fe..86d10a5a0 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -312,12 +312,6 @@ template inline AbstractObject::~AbstractOb template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } -#ifndef DOXYGEN_GENERATING_OUTPUT -/* These templates are instantiated in source file */ -extern template class SCENEGRAPH_EXPORT AbstractObject<2>; -extern template class SCENEGRAPH_EXPORT AbstractObject<3>; -#endif - /** @brief Two-dimensional object From 3367b3636c0f8c3b3e69d3accc7dec0abda8c1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 17:50:14 +0200 Subject: [PATCH 206/256] Disable "extern template" for ResourceManager in MinGW GCC. MinGW GCC probably has a bug which causes linker errors - complains about conflicting symbols (inline functions instantiated more than once). --- src/Physics/DebugDrawResourceManager.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h index 8108e5af9..db22e4221 100644 --- a/src/Physics/DebugDrawResourceManager.h +++ b/src/Physics/DebugDrawResourceManager.h @@ -39,8 +39,12 @@ namespace Physics { namespace Implementation { template class AbstractDebugRenderer; }} +#ifndef WIN32 extern template class PHYSICS_EXPORT ResourceManager; #endif +#endif + +/** @todo fix extern template multiple definition linker errors in mingw32-gcc */ namespace SceneGraph { class Object2D; From eb0565b5d9ab8c507f32d1b6f4f16257eebc713a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 18:32:27 +0200 Subject: [PATCH 207/256] Minor code cleanup. --- src/AbstractShaderProgram.cpp | 8 ++------ src/Contexts/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index f6c42240d..61e773700 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -72,8 +72,7 @@ AbstractShaderProgram::UniformMatrix4x3dvImplementation AbstractShaderProgram::u AbstractShaderProgram::~AbstractShaderProgram() { /* Remove current usage from the state */ GLuint& current = Context::current()->state()->shaderProgram->current; - if(current == _id) - current = 0; + if(current == _id) current = 0; glDeleteProgram(_id); } @@ -83,10 +82,7 @@ bool AbstractShaderProgram::use() { /* Use only if the program isn't already in use */ GLuint& current = Context::current()->state()->shaderProgram->current; - if(current != _id) { - current = _id; - glUseProgram(_id); - } + if(current != _id) glUseProgram(current = _id); return true; } diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index 7a3fd095f..f11098375 100644 --- a/src/Contexts/CMakeLists.txt +++ b/src/Contexts/CMakeLists.txt @@ -72,7 +72,7 @@ if(NEED_ABSTRACTXWINDOWCONTEXT) install(FILES AbstractXWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) endif() -# GLX window context +# GLX context if(NEED_GLXCONTEXT) add_library(MagnumGlxContextHandler OBJECT GlxContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts From 56bc8825cc1e7a6b69854297fd0620fe18647cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 18:24:41 +0200 Subject: [PATCH 208/256] Mesh rework, part 5: tracking currently bound VAO. If the VAO is already bound, not calling glBindVertexArray() again. --- src/Implementation/MeshState.h | 30 ++++++++++++++++++++++++++++++ src/Implementation/State.cpp | 4 +++- src/Implementation/State.h | 2 ++ src/IndexedMesh.cpp | 3 +-- src/Mesh.cpp | 21 ++++++++++++++++++--- src/Mesh.h | 11 ++++++----- 6 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 src/Implementation/MeshState.h diff --git a/src/Implementation/MeshState.h b/src/Implementation/MeshState.h new file mode 100644 index 000000000..1e0b24328 --- /dev/null +++ b/src/Implementation/MeshState.h @@ -0,0 +1,30 @@ +#ifndef Magnum_Implementation_MeshState_h +#define Magnum_Implementation_MeshState_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +namespace Magnum { namespace Implementation { + +struct MeshState { + inline MeshState(): currentVAO(0) {} + + GLuint currentVAO; +}; + +}} + +#endif diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index b1cb03dd8..062a98a8c 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -16,16 +16,18 @@ #include "State.h" #include "BufferState.h" +#include "MeshState.h" #include "ShaderProgramState.h" #include "TextureState.h" namespace Magnum { namespace Implementation { -State::State(): buffer(new BufferState), shaderProgram(new ShaderProgramState), texture(new TextureState) {} +State::State(): buffer(new BufferState), mesh(new MeshState), shaderProgram(new ShaderProgramState), texture(new TextureState) {} State::~State() { delete texture; delete shaderProgram; + delete mesh; delete buffer; } diff --git a/src/Implementation/State.h b/src/Implementation/State.h index d655b3172..a264247d7 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -20,6 +20,7 @@ namespace Magnum { namespace Implementation { struct BufferState; +struct MeshState; struct ShaderProgramState; struct TextureState; @@ -28,6 +29,7 @@ struct State { ~State(); BufferState* const buffer; + MeshState* const mesh; ShaderProgramState* const shaderProgram; TextureState* const texture; }; diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 5b8b3433d..9a8d0daa0 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -63,8 +63,7 @@ void IndexedMesh::bindIndexBufferImplementationDefault() {} #ifndef MAGNUM_TARGET_GLES void IndexedMesh::bindIndexBufferImplementationVAO() { - glBindVertexArray(vao); - + bindVAO(vao); _indexBuffer->bind(Buffer::Target::ElementArray); } #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d5931139d..719fc4b79 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -20,6 +20,8 @@ #include "Buffer.h" #include "Context.h" #include "Extensions.h" +#include "Implementation/MeshState.h" +#include "Implementation/State.h" using namespace std; @@ -31,6 +33,14 @@ Mesh::BindAttributeImplementation Mesh::bindAttributeImplementation = &Mesh::bin Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; +Mesh::~Mesh() { + /* Remove current vao from the state */ + GLuint& current = Context::current()->state()->mesh->currentVAO; + if(current == vao) current = 0; + + (this->*destroyImplementation)(); +} + Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(other.attributes) { other.vao = 0; } @@ -57,6 +67,11 @@ void Mesh::draw() { unbind(); } +void Mesh::bindVAO(GLuint vao) { + GLuint& current = Context::current()->state()->mesh->currentVAO; + if(current != vao) glBindVertexArray(current = vao); +} + void Mesh::bind() { CORRADE_ASSERT((_vertexCount == 0) == attributes.empty(), "Mesh: vertex count is non-zero, but no attributes are bound", ); @@ -125,7 +140,7 @@ void Mesh::bindAttributeImplementationDefault(const Attribute&) {} #ifndef MAGNUM_TARGET_GLES void Mesh::bindAttributeImplementationVAO(const Attribute& attribute) { - glBindVertexArray(vao); + bindVAO(vao); vertexAttribPointer(attribute); } #endif @@ -137,7 +152,7 @@ void Mesh::bindImplementationDefault() { #ifndef MAGNUM_TARGET_GLES void Mesh::bindImplementationVAO() { - glBindVertexArray(vao); + bindVAO(vao); } #endif @@ -148,7 +163,7 @@ void Mesh::unbindImplementationDefault() { #ifndef MAGNUM_TARGET_GLES void Mesh::unbindImplementationVAO() { - glBindVertexArray(0); + bindVAO(0); } #endif diff --git a/src/Mesh.h b/src/Mesh.h index 1c8c0467d..d4f6c32ed 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -81,7 +81,8 @@ Basic workflow is to set up respective shader (see @ref AbstractShaderProgram-re If @extension{APPLE,vertex_array_object} is supported, VAOs are used instead of binding the buffers and specifying vertex attribute pointers in each -draw() call. +draw() call. The engine tracks currently bound VAO to avoid unnecessary calls +to @fn_gl{BindVertexArray}. @requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) @@ -354,9 +355,7 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{DeleteVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - inline virtual ~Mesh() { - (this->*destroyImplementation)(); - } + virtual ~Mesh(); /** @brief Move assignment */ Mesh& operator=(Mesh&& other); @@ -571,6 +570,8 @@ class MAGNUM_EXPORT Mesh { void MAGNUM_EXPORT addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride); + static void MAGNUM_LOCAL bindVAO(GLuint vao); + void MAGNUM_LOCAL bind(); inline void unbind() { @@ -591,7 +592,7 @@ class MAGNUM_EXPORT Mesh { #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL destroyImplementationVAO(); #endif - static DestroyImplementation destroyImplementation; + static MAGNUM_LOCAL DestroyImplementation destroyImplementation; typedef void(Mesh::*BindAttributeImplementation)(const Attribute&); void MAGNUM_LOCAL bindAttributeImplementationDefault(const Attribute& attribute); From 14192fa40fd2bc9e69ddec7518525b918d9ecaa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 22 Oct 2012 19:42:12 +0200 Subject: [PATCH 209/256] Mesh rework, part 6: don't rebind default VAO after draw call. There are a few corner cases namely with binding element buffer, which should be resolved as soon as possible. --- src/Buffer.h | 2 ++ src/Mesh.cpp | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 93ff82dd9..6df02acad 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -321,6 +321,8 @@ class MAGNUM_EXPORT Buffer { * * @todo Allow binding to Target::ElementArray only if VAO is bound * to avoid potential issues? + * @bug Binding to ElementArray if any VAO is active will corrupt the mesh + * @todo Don't allow user to bind buffers? * @see @fn_gl{BindBuffer} */ inline void bind(Target target) { bind(target, _id); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 719fc4b79..1fad6de36 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -162,9 +162,7 @@ void Mesh::unbindImplementationDefault() { } #ifndef MAGNUM_TARGET_GLES -void Mesh::unbindImplementationVAO() { - bindVAO(0); -} +void Mesh::unbindImplementationVAO() {} #endif } From 77716dacdd5f9f7465b1e385155ecfa47002ab9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Oct 2012 18:29:34 +0200 Subject: [PATCH 210/256] Mesh rework, part 7: using EXT_direct_state_access for vertex pointers. --- src/Mesh.cpp | 17 ++++++++++++++++- src/Mesh.h | 30 +++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 1fad6de36..48781627b 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -113,7 +113,12 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { createImplementation = &Mesh::createImplementationVAO; destroyImplementation = &Mesh::destroyImplementationVAO; - bindAttributeImplementation = &Mesh::bindAttributeImplementationVAO; + + if(context->isExtensionSupported()) { + Debug() << "Mesg: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + bindAttributeImplementation = &Mesh::bindAttributeImplementationDSA; + } else bindAttributeImplementation = &Mesh::bindAttributeImplementationVAO; + bindImplementation = &Mesh::bindImplementationVAO; unbindImplementation = &Mesh::unbindImplementationVAO; #endif @@ -143,6 +148,16 @@ void Mesh::bindAttributeImplementationVAO(const Attribute& attribute) { bindVAO(vao); vertexAttribPointer(attribute); } +void Mesh::bindAttributeImplementationDSA(const Attribute& attribute) { + glEnableVertexArrayAttribEXT(vao, attribute.location); + + #ifndef MAGNUM_TARGET_GLES + if(TypeInfo::isIntegral(attribute.type)) + glVertexArrayVertexAttribIOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, attribute.offset); + else + #endif + glVertexArrayVertexAttribOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, attribute.offset); +} #endif void Mesh::bindImplementationDefault() { diff --git a/src/Mesh.h b/src/Mesh.h index d4f6c32ed..60cab2348 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -36,9 +36,10 @@ class Context; To properly configure mesh, you have to set primitive either in constructor or using setPrimitive() and call setVertexCount(). Then create vertex buffers, -fill them with vertex data and assign them to mesh and given shader locations -using addVertexBuffer() or addInterleavedVertexBuffer(). You can also use -MeshTools::interleave() to conveniently set vertex count and buffer data. +and them with vertex data. You can also use MeshTools::interleave() to +conveniently set vertex count and buffer data. At last assign them to mesh and +given shader locations using addVertexBuffer(), addInterleavedVertexBuffer() +or addVertexBufferStride(). Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, so you have to manage it on your own. On the other hand it allows you to use @@ -84,6 +85,12 @@ of binding the buffers and specifying vertex attribute pointers in each draw() call. The engine tracks currently bound VAO to avoid unnecessary calls to @fn_gl{BindVertexArray}. +If extension @extension{EXT,direct_state_access} and VAOs are available, +DSA functions are used for specifying attribute locations to avoid unnecessary +calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of +addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for +more information. + @requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) @todo Support for normalized values (e.g. for color as char[4] passed to @@ -428,10 +435,12 @@ class MAGNUM_EXPORT Mesh { * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. * - * @see addInterleavedVertexBuffer(), @fn_gl{BindVertexArray}, - * @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, - * @fn_gl{VertexAttribPointer} (if - * @extension{APPLE,vertex_array_object} is available) + * @see addInterleavedVertexBuffer(), addVertexBufferStride(), + * @fn_gl{BindVertexArray}, @fn_gl{EnableVertexAttribArray}, + * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} or + * @fn_gl_extension{EnableVertexArrayAttrib,EXT,direct_state_access}, + * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} + * if @extension{APPLE,vertex_array_object} is available */ template inline Mesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { addVertexBufferInternal(buffer, 0, attributes...); @@ -490,8 +499,10 @@ class MAGNUM_EXPORT Mesh { * * @see addVertexBufferStride(), addVertexBuffer(), * @fn_gl{BindVertexArray}, @fn_gl{EnableVertexAttribArray}, - * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} (if - * @extension{APPLE,vertex_array_object} is available) + * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} or + * @fn_gl_extension{EnableVertexArrayAttrib,EXT,direct_state_access}, + * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} + * if @extension{APPLE,vertex_array_object} is available */ template inline Mesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); @@ -598,6 +609,7 @@ class MAGNUM_EXPORT Mesh { void MAGNUM_LOCAL bindAttributeImplementationDefault(const Attribute& attribute); #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL bindAttributeImplementationVAO(const Attribute& attribute); + void MAGNUM_LOCAL bindAttributeImplementationDSA(const Attribute& attribute); #endif static MAGNUM_LOCAL BindAttributeImplementation bindAttributeImplementation; From 6278db11e258e156ce33dfdc895d9c4f6ebe49c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Oct 2012 18:38:50 +0200 Subject: [PATCH 211/256] Don't show links to extension functions in non-proportional font. --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index b208057d0..e11bd5171 100644 --- a/Doxyfile +++ b/Doxyfile @@ -201,7 +201,7 @@ ALIASES = \ "collisionoperator{2}=@relates \1\n@brief Collision of %\1 and %\2\n@see \2::operator%(const \1&) const" \ "todoc=@xrefitem todoc \"Documentation todo\" \"Documentation-related todo list\"" \ "fn_gl{1}=gl\1()" \ - "fn_gl_extension{3}=gl\1\2()" \ + "fn_gl_extension{3}=gl\1\2()" \ "def_gl{1}=`GL_\1`" \ "requires_gl=@xrefitem requires-gl \"Requires desktop OpenGL\" \"Functionality requiring desktop OpenGL (not available on OpenGL ES)\" Not available on OpenGL ES." \ "requires_gl30=@xrefitem requires-gl30 \"Requires OpenGL 3.0\" \"Functionality requiring OpenGL 3.0\"" \ From 84850b5bf980eaa9575a1159a3cee57f9feb99a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 24 Oct 2012 15:51:56 +0200 Subject: [PATCH 212/256] Updated AbstractShaderProgram documentation. * #version directive doesn't belong to shader sources, since it is specified in Shader constructor. * It's not needed to call use() before setUniform() anymore. --- src/AbstractShaderProgram.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index fdce72366..41f05ac57 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -100,8 +100,8 @@ The preferred workflow is to specify attribute location for vertex shader input attributes and fragment shader output attributes explicitly in the shader code, e.g.: @code -#version 330 -// or #extension GL_ARB_explicit_attrib_location: enable +// GLSL 3.30, or +#extension GL_ARB_explicit_attrib_location: enable layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 textureCoordinates; @@ -147,8 +147,8 @@ bindFragmentDataLocationIndexed(1, 1, "ambient"); The preferred workflow is to specify uniform locations directly in the shader code, e.g.: @code -#version 430 -// or #extension GL_ARB_explicit_uniform_location: enable +// GLSL 4.30, or +#extension GL_ARB_explicit_uniform_location: enable layout(location = 0) uniform mat4 transformation; layout(location = 1) uniform mat4 projection; @endcode @@ -168,8 +168,8 @@ GLint projectionUniform = uniformLocation("projection"); The preferred workflow is to specify texture layers directly in the shader code, e.g.: @code -#version 420 -// or #extension GL_ARB_shading_language_420pack: enable +// GLSL 4.20, or +#extension GL_ARB_shading_language_420pack: enable layout(binding = 0) uniform sampler2D diffuseTexture; layout(binding = 1) uniform sampler2D specularTexture; @endcode @@ -181,7 +181,6 @@ layout(binding = 1) uniform sampler2D specularTexture; If you don't have the required extension (or if you want to change the layer later), you can set the texture layer uniform using setUniform(GLint, GLint): @code -use(); setUniform(DiffuseTextureUniform, DiffuseTextureLayer); setUniform(SpecularTextureUniform, SpecularTextureLayer); @endcode From 9f48ba1d53dea3bce5f5f148f1bded9045dc772e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 24 Oct 2012 15:54:27 +0200 Subject: [PATCH 213/256] Added @todo and new extension. --- src/Extensions.h | 4 +++- src/Mesh.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Extensions.h b/src/Extensions.h index 78508441b..16491af8d 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -45,7 +45,9 @@ namespace Extensions { }; namespace GL { #line 1 - namespace APPLE { + namespace AMD { + _extension(GL,AMD,shader_trinary_minmax, GL210, None) // #428 + } namespace APPLE { _extension(GL,APPLE,flush_buffer_range, GL210, GL300) // #321 _extension(GL,APPLE,vertex_array_object, GL210, GL300) // #273 } namespace ARB { diff --git a/src/Mesh.h b/src/Mesh.h index 60cab2348..96d624877 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -93,6 +93,7 @@ more information. @requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) +@todo The attributes can be specified with different type than in shader - how? @todo Support for normalized values (e.g. for color as char[4] passed to shader as floating-point vec4) @todo Support for packed unsigned integer types for attributes (OpenGL 3.3, @extension{ARB,vertex_type_2_10_10_10_rev}) From 5efa8402e5f3157f1562e78de919564a699a0b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 24 Oct 2012 15:55:31 +0200 Subject: [PATCH 214/256] Marking some non-implemented features as "won't be supported". --- doc/required-extensions.dox | 1 + doc/unsupported.dox | 22 ++++++++++++++++++++++ src/Extensions.h | 3 +++ src/Mesh.h | 1 - 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 doc/unsupported.dox diff --git a/doc/required-extensions.dox b/doc/required-extensions.dox index 443109d1a..5598d000c 100644 --- a/doc/required-extensions.dox +++ b/doc/required-extensions.dox @@ -24,6 +24,7 @@ supported on Intel GPUs even if they are capable of OpenGL 2.1 only). - @subpage requires-extension - @subpage requires-gles30 - @subpage requires-es-extension +- @subpage unsupported @page requires-gl Functionality requiring desktop OpenGL (not available on OpenGL ES) @page requires-gl30 Functionality requiring OpenGL 3.0 diff --git a/doc/unsupported.dox b/doc/unsupported.dox new file mode 100644 index 000000000..4d6ae1232 --- /dev/null +++ b/doc/unsupported.dox @@ -0,0 +1,22 @@ +/** @page unsupported Unsupported OpenGL features + +Some functionality, which is either soon-to-be deprecated or isn't proven to +add any performance gains, is not supported in %Magnum. + +@section unsupported-features Unsupported features + +- Luminance texture formats (OpenGL ES) are not supported, as they are + deprecated in OpenGL ES 3.0 and not present in core desktop OpenGL. +- Fixed precision data types (OpenGL ES) are not supported, as they occupy the + same memory as floats and they aren't faster than floats on current hardware + anymore. + +@section unsupported-extensions Unsupported extensions + +- @extension{INTEL,map_texture} negatively affects texture access performance. + Combination of buffer mapping and pixel buffers might be of the same or + better performance, without affecting texture access speed. +- @extension{NV,draw_texture} can be done with framebuffer blitting and + doesn't make any full-screen postprocessing easier, as shaders are excluded. + +*/ diff --git a/src/Extensions.h b/src/Extensions.h index 16491af8d..e656bc447 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -127,11 +127,14 @@ namespace GL { _extension(GL,EXT,transform_feedback, GL210, GL300) // #352 _extension(GL,EXT,direct_state_access, GL210, None) // #353 _extension(GL,EXT,texture_snorm, GL300, GL310) // #365 + } namespace INTEL { + /* INTEL_map_texture not supported */ // #429 } namespace NV { _extension(GL,NV,half_float, GL210, GL300) // #283 _extension(GL,NV,primitive_restart, GL210, GL310) // #285 _extension(GL,NV,depth_buffer_float, GL210, GL300) // #334 _extension(GL,NV,conditional_render, GL210, GL300) // #346 + /* NV_draw_texture not supported */ // #430 } } #undef _extension diff --git a/src/Mesh.h b/src/Mesh.h index 96d624877..da12210db 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -97,7 +97,6 @@ more information. @todo Support for normalized values (e.g. for color as char[4] passed to shader as floating-point vec4) @todo Support for packed unsigned integer types for attributes (OpenGL 3.3, @extension{ARB,vertex_type_2_10_10_10_rev}) -@todo Support for fixed precision type for attributes (OpenGL 4.1, @extension{ARB,ES2_compatibility}) @todo Support for double type for attributes (OpenGL 4.1, @extension{ARB,vertex_attrib_64bit}) @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. From eec4e7d0993c970c0cc8ed4a9497de86405135fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 25 Oct 2012 18:21:35 +0200 Subject: [PATCH 215/256] Implementation of double vertex attributes in Mesh. --- src/Mesh.cpp | 6 ++++-- src/Mesh.h | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 48781627b..f62ec3563 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -101,7 +101,8 @@ void Mesh::vertexAttribPointer(const Mesh::Attribute& attribute) { #ifndef MAGNUM_TARGET_GLES if(TypeInfo::isIntegral(attribute.type)) glVertexAttribIPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); - else + else if(attribute.type == Type::Double) + glVertexAttribLPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); #endif glVertexAttribPointer(attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, reinterpret_cast(attribute.offset)); } @@ -154,7 +155,8 @@ void Mesh::bindAttributeImplementationDSA(const Attribute& attribute) { #ifndef MAGNUM_TARGET_GLES if(TypeInfo::isIntegral(attribute.type)) glVertexArrayVertexAttribIOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, attribute.offset); - else + else if(attribute.type == Type::Double) + glVertexArrayVertexAttribLOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, attribute.offset); #endif glVertexArrayVertexAttribOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, attribute.offset); } diff --git a/src/Mesh.h b/src/Mesh.h index da12210db..090574932 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -91,13 +91,16 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for more information. -@requires_gl30 Extension @extension{EXT,gpu_shader4} (for unsigned integer attributes) +@requires_gles30 Integer attributes are not supported in OpenGL ES 2.0. +@requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes) + +@requires_gl Double attributes are supported only on Desktop OpenGL. +@requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double attributes) @todo The attributes can be specified with different type than in shader - how? @todo Support for normalized values (e.g. for color as char[4] passed to shader as floating-point vec4) @todo Support for packed unsigned integer types for attributes (OpenGL 3.3, @extension{ARB,vertex_type_2_10_10_10_rev}) -@todo Support for double type for attributes (OpenGL 4.1, @extension{ARB,vertex_attrib_64bit}) @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ From adb4d06b952c2340d7926b9a44433194f0c79a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 25 Oct 2012 18:22:13 +0200 Subject: [PATCH 216/256] Have consistent template order (first size, then type). --- src/TypeTraits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 37dae7f43..5a1310502 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -231,7 +231,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { }; #endif -template struct TypeTraits> { +template struct TypeTraits> { inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ /* Can not be used for images */ @@ -247,7 +247,7 @@ template struct TypeTraits>: public TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits> { +template struct TypeTraits> { inline constexpr static Type type() { return TypeTraits::type(); } /* Can not be used for indices */ /* Can not be used for images */ From 42af2c1a498e6b876fce7ac934daaa62b4876427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 26 Oct 2012 12:35:18 +0200 Subject: [PATCH 217/256] Fixed serious copy/paste error. Unnoticed since c1cf94fb46e3716c5e9131273c0f650cad2b566e. --- src/TypeTraits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 5a1310502..08da1bf09 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -197,7 +197,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } @@ -205,7 +205,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } From cb1c3f0b2b9ebc25f9924ab4a05952bdd2bcafe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 26 Oct 2012 15:10:32 +0200 Subject: [PATCH 218/256] Preparation for type checked vertex attributes. Currently it was possible to pass e.g. five-component vector or 2x1 matrix to shader, we don't want that. --- src/AbstractShaderProgram.h | 47 +++++++++++++++ src/TypeTraits.h | 112 +++++++++++++++++++++++++++++++----- 2 files changed, 144 insertions(+), 15 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 41f05ac57..449afea09 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -203,6 +203,53 @@ specularTexture->bind(MyShader::SpecularTextureLayer); mesh.draw(); @endcode +@section AbstractShaderProgram-types Mapping between GLSL and Magnum types + +- `vec2`, `vec3` and `vec4` is @ref Math::Vector "Math::Vector<2, GLfloat>", + @ref Math::Vector "Math::Vector<3, GLfloat>" and + @ref Math::Vector "Math::Vector<4, GLfloat>". + +- `mat2`, `mat3` and `mat4` is @ref Math::Matrix "Math::Matrix<2, GLfloat>", + @ref Math::Matrix "Math::Matrix<3, GLfloat>" and + @ref Math::Matrix "Math::Matrix<4, GLfloat>". + +- `mat2x3`, `mat3x2`, `mat2x4`, `mat4x2`, `mat3x4`, `mat4x3` is + @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 3, GLfloat>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 2, GLfloat>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 4, GLfloat>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 2, GLfloat>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 4, GLfloat>" and + @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 3, GLfloat>". + +- `ivec2`, `ivec3` and `ivec4` is @ref Math::Vector "Math::Vector<2, GLint>", + @ref Math::Vector "Math::Vector<3, GLint>" and + @ref Math::Vector "Math::Vector<4, GLint>", `uvec2`, `uvec3` and `uvec4` is + @ref Math::Vector "Math::Vector<2, GLuint>", + @ref Math::Vector "Math::Vector<3, GLuint>" and + @ref Math::Vector "Math::Vector<4, GLuint>". + @requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes) + @requires_gles30 Integer attributes are not supported in OpenGL ES 2.0. + +- `dvec2`, `dvec3` and `dvec4` is @ref Math::Vector "Math::Vector<2, GLdouble>", + @ref Math::Vector "Math::Vector<3, GLdouble>" and + @ref Math::Vector "Math::Vector<4, GLdouble>", `dmat2`, `dmat3` and `dmat4` + is @ref Math::Matrix "Math::Matrix<2, GLdouble>", + @ref Math::Matrix "Math::Matrix<3, GLdouble>" and + @ref Math::Matrix "Math::Matrix<4, GLdouble>", `dmat2x3`, `dmat3x2`, + `dmat2x4`, `dmat4x2`, `dmat3x4`, `dmat4x3` is + @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 3, GLdouble>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 2, GLdouble>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 4, GLdouble>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 2, GLdouble>", + @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 4, GLdouble>" and + @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 3, GLdouble>". + @requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double attributes) + @requires_gl Double attributes are supported only on desktop OpenGL. + +Only types listed here (and their subclasses and specializations, such as +@ref Matrix3 or Color4) can be used for setting uniforms and specifying +vertex attributes. See also TypeTraits::AttributeType. + @section AbstractShaderProgram-performance-optimization Performance optimizations The engine tracks currently used shader program to avoid unnecessary calls to diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 08da1bf09..ba53cb79b 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -25,8 +25,9 @@ namespace Magnum { namespace Math { - template class Vector; + template class RectangularMatrix; template class Matrix; + template class Vector; } template class Color3; @@ -42,6 +43,16 @@ OpenGL-specific traits. */ #ifdef DOXYGEN_GENERATING_OUTPUT template struct TypeTraits: public Math::MathTypeTraits { + /** + * @brief Corresponding type for vertex attributes + * + * Implemented only in types which can be used for vertex attributes. This + * function is not present for types unusable for vertex attributes, like + * five-component vectors or GLdouble in OpenGL ES. See also + * @ref AbstractShaderProgram-types. + */ + typedef U AttributeType; + /** * @brief OpenGL plain type ID * @@ -166,6 +177,7 @@ template<> struct TypeOf { typedef GLdouble Type; }; #endif template<> struct TypeTraits: public Math::MathTypeTraits { + /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; } @@ -174,6 +186,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits }; template<> struct TypeTraits: public Math::MathTypeTraits { + /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } @@ -182,6 +195,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { }; template<> struct TypeTraits: public Math::MathTypeTraits { + /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; } @@ -190,6 +204,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { + /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } @@ -198,6 +213,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits }; template<> struct TypeTraits: public Math::MathTypeTraits { + typedef GLuint AttributeType; inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } @@ -206,6 +222,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits }; template<> struct TypeTraits: public Math::MathTypeTraits { + typedef GLint AttributeType; inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } @@ -214,6 +231,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { }; template<> struct TypeTraits: public Math::MathTypeTraits { + typedef GLfloat AttributeType; inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; } @@ -223,6 +241,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { #ifndef MAGNUM_TARGET_GLES template<> struct TypeTraits: public Math::MathTypeTraits { + typedef GLdouble AttributeType; inline constexpr static Type type() { return Type::Double; } /* Can not be used for indices */ /* Can not be used for images */ @@ -231,13 +250,45 @@ template<> struct TypeTraits: public Math::MathTypeTraits { }; #endif -template struct TypeTraits> { - inline constexpr static Type type() { return TypeTraits::type(); } - /* Can not be used for indices */ - /* Can not be used for images */ - inline constexpr static std::size_t size() { return sizeof(T); } - inline constexpr static std::size_t count() { return vectorSize; } -}; +namespace Implementation { + template struct VectorTypeTraits { + /* Might be used for attributes, see below */ + inline constexpr static Type type() { return TypeTraits::type(); } + /* Might be used for attributes, see below */ + /* Can not be used for indices */ + /* Can not be used for images */ + inline constexpr static std::size_t size() { return sizeof(T); } + inline constexpr static std::size_t count() { return vectorSize; } + }; + + template struct VectorAttributeType {}; + + template<> struct VectorAttributeType { + typedef GLuint AttributeType; + }; + + template<> struct VectorAttributeType { + typedef GLint AttributeType; + }; + + template<> struct VectorAttributeType { + typedef GLfloat AttributeType; + }; + + #ifndef MAGNUM_TARGET_GLES + template<> struct VectorAttributeType { + typedef GLdouble AttributeType; + }; + #endif +} + +template struct TypeTraits>: public Implementation::VectorTypeTraits {}; + +/* Only some vectors can be used as attributes */ +template struct TypeTraits>: Implementation::VectorTypeTraits<1, T>, Implementation::VectorAttributeType {}; +template struct TypeTraits>: Implementation::VectorTypeTraits<2, T>, Implementation::VectorAttributeType {}; +template struct TypeTraits>: Implementation::VectorTypeTraits<3, T>, Implementation::VectorAttributeType {}; +template struct TypeTraits>: Implementation::VectorTypeTraits<4, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; @@ -247,13 +298,44 @@ template struct TypeTraits>: public TypeTraits struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits> { - inline constexpr static Type type() { return TypeTraits::type(); } - /* Can not be used for indices */ - /* Can not be used for images */ - inline constexpr static std::size_t size() { return sizeof(T); } - inline constexpr static std::size_t count() { return matrixSize*matrixSize; } -}; +namespace Implementation { + template struct MatrixTypeTraits { + inline constexpr static Type type() { return TypeTraits::type(); } + /* Might be used for attributes, see below */ + /* Can not be used for indices */ + /* Can not be used for images */ + inline constexpr static std::size_t size() { return sizeof(T); } + inline constexpr static std::size_t count() { return rows; } + inline constexpr static std::size_t vectors() { return cols; } + }; + + template struct MatrixAttributeType {}; + + template<> struct MatrixAttributeType { + typedef GLfloat AttributeType; + }; + + #ifndef MAGNUM_TARGET_GLES + template<> struct MatrixAttributeType { + typedef GLdouble AttributeType; + }; + #endif +} + +template struct TypeTraits>: public Implementation::MatrixTypeTraits {}; + +/* Only some floating-point matrices can be used as attributes */ +template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 2, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 3, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 4, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 3, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 2, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 4, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 2, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 4, T>, Implementation::MatrixAttributeType {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 3, T>, Implementation::MatrixAttributeType {}; + +template struct TypeTraits>: TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; template struct TypeTraits>: public TypeTraits> {}; From 259a9f6666ac73d83ebf41d082aca524df695061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 26 Oct 2012 15:13:19 +0200 Subject: [PATCH 219/256] Type-checked vertex attributes with type conversion possibility. * Normalization of e.g. color components passed as unsigned byte to float values is possible. * BGRA vector component ordering is possible. * Proper type checking, allowing only GLSL-equivalent types to be used as attributes. * Reverted back to typedef'ing shader attributes, as type conversion can now be specified in constructor. --- src/AbstractShaderProgram.h | 322 +++++++++++++++++++++++++++++++++++- src/Mesh.cpp | 114 +++++++++---- src/Mesh.h | 197 ++++++++++++++++------ src/Shaders/PhongShader.cpp | 7 +- src/Shaders/PhongShader.h | 4 +- 5 files changed, 542 insertions(+), 102 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 449afea09..2c9ddbe50 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -21,8 +21,10 @@ #include #include +#include #include "Magnum.h" +#include "TypeTraits.h" #include "magnumVisibility.h" @@ -37,8 +39,14 @@ namespace Math { class Context; class Shader; +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct Attribute; +} +#endif + /** -@brief Base class for shaders +@brief Base class for shader program implementations @section AbstractShaderProgram-subclassing Subclassing workflow @@ -277,16 +285,146 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @brief Base struct for attribute location and type * - * See @ref AbstractShaderProgram-subclassing or Mesh::bindAttribute() - * for an example. + * Template parameter @p T is the type which is used for shader + * attribute, e.g. @ref Math::Vector4 "Vector4" for `ivec4`. + * DataType is type of passed data when adding vertex buffers to mesh. + * By default it is the same as type used in shader (e.g. + * @ref DataType "DataType::Int" for @ref Math::Vector4 "Vector4"). + * It's also possible to pass integer data to floating-point shader + * inputs. In this case you may want to normalize the values (e.g. + * color components from 0-255 to 0.0f-1.0f) - see + * @ref DataOption "DataOption::Normalize". + * + * Only some types are allowed as attribute types, see + * @ref AbstractShaderProgram-types or TypeTraits::AttributeType for + * more information. * - * @todo Support for BGRA attribute type (OpenGL 3.2, @extension{ARB,vertex_array_bgra}) + * See @ref AbstractShaderProgram-subclassing for example usage in + * shaders and @ref Mesh-configuration for example usage when adding + * vertex buffers to mesh. */ - template struct Attribute { - inline constexpr Attribute() = default; - - static const GLuint Location = i; /**< Location to which the attribute is bound */ - typedef T Type; /**< %Attribute type */ + template class Attribute { + public: + /** @brief Location to which the attribute is bound */ + static const GLuint Location = i; + + /** + * @brief Type + * + * Type used in shader code. + * @see DataType + */ + typedef typename TypeTraits::AttributeType Type; + + /** + * @brief Data type + * + * Type of data passed to shader. + * @see Type, DataOptions, Attribute() + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + enum class DataType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ + Byte = GL_BYTE, /**< Byte */ + UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ + Short = GL_SHORT, /**< Short */ + UnsignedInt = GL_UNSIGNED_INT, /**< Unsigned int */ + Int = GL_INT, /**< Int */ + + /** + * Half float. Only for float attribute types. + * @requires_gl30 %Extension @extension{NV,half_float} + * @requires_gles30 %Extension @es_extension{OES,vertex_half_float} + */ + Half = GL_HALF_FLOAT, + + /** Float. Only for float attribute types. */ + Float = GL_FLOAT, + + #ifndef MAGNUM_TARGET_GLES + /** + * Double. Only for float and double attribute types. + * @requires_gl Only floats are available in OpenGL ES. + */ + Double = GL_DOUBLE, + #endif + + /* GL_FIXED not supported */ + + /** + * Unsigned 2.10.10.10 packed integer. Only for + * four-component float vector attribute type. + * @todo How about (incompatible) @es_extension{OES,vertex_type_10_10_10_2}? + * @requires_gl33 %Extension @extension{ARB,vertex_type_2_10_10_10_rev} + * @requires_gles30 (no extension providing this functionality) + */ + UnsignedInt2101010REV = GL_UNSIGNED_INT_2_10_10_10_REV, + + /** + * Signed 2.10.10.10 packed integer. Only for + * four-component float vector attribute type. + * @requires_gl33 %Extension @extension{ARB,vertex_type_2_10_10_10_rev} + * @requires_gles30 (no extension providing this functionality) + */ + Int2101010REV = GL_INT_2_10_10_10_REV + }; + #else + typedef typename Implementation::Attribute::DataType DataType; + #endif + + /** + * @brief Data option + * @see DataOptions, Attribute() + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + enum class DataOption: std::uint8_t { + /** + * Normalize integer components. Only for float attribute + * types. Default is to not normalize. + */ + Normalize = 1 << 0, + + /** + * BGRA component ordering. Default is RGBA. Only for + * four-component float vector attribute type. + * @requires_gl32 %Extension @extension{ARB,vertex_array_bgra} + * @requires_gl Only RGBA component ordering is available + * on OpenGL ES. + */ + BGRA = 1 << 1 + }; + #else + typedef typename Implementation::Attribute::DataOption DataOption; + #endif + + /** + * @brief Data options + * @see Attribute() + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + typedef typename Corrade::Containers::EnumSet DataOptions; + #else + typedef typename Implementation::Attribute::DataOptions DataOptions; + #endif + + /** + * @brief Constructor + * @param dataType Type of passed data. Default is the + * same as type used in shader (e.g. DataType::Integer + * for Vector4). + * @param dataOptions Data options. Default is no options. + */ + inline constexpr Attribute(DataType dataType = Implementation::Attribute::DefaultDataType, DataOptions dataOptions = DataOptions()): _dataType(dataType), _dataOptions(dataOptions) {} + + /** @brief Type of passed data */ + inline constexpr DataType dataType() const { return _dataType; } + + /** @brief Data options */ + inline constexpr DataOptions dataOptions() const { return _dataOptions; } + + private: + const DataType _dataType; + const DataOptions _dataOptions; }; /** @@ -877,6 +1015,172 @@ class MAGNUM_EXPORT AbstractShaderProgram { State state; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +template struct Attribute {}; + +template<> struct Attribute { + enum class DataType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, + Byte = GL_BYTE, + UnsignedShort = GL_UNSIGNED_SHORT, + Short = GL_SHORT, + UnsignedInt = GL_UNSIGNED_INT, + Int = GL_INT, + HalfFloat = GL_HALF_FLOAT, + Float = GL_FLOAT, + Double = GL_DOUBLE + }; + + enum class DataOption: std::uint8_t { + Normalized = 1 << 0 + }; + + typedef Corrade::Containers::EnumSet DataOptions; + + static const DataType DefaultDataType = DataType::Float; + + inline constexpr static GLint size(DataOptions) { return 1; } + inline constexpr static std::size_t vectorCount() { return 1; } +}; + +CORRADE_ENUMSET_OPERATORS(Attribute::DataOptions) + +template struct Attribute>: public Attribute { + inline constexpr static GLint size(DataOptions) { return vectorSize; } + inline constexpr static std::size_t vectorCount() { return 1; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size(DataOptions) { return rows; } + inline constexpr static std::size_t vectorCount() { return cols; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size(DataOptions) { return matrixSize; } + inline constexpr static std::size_t vectorCount() { return matrixSize; } +}; + +template<> struct Attribute> { + enum class DataType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, + Byte = GL_BYTE, + UnsignedShort = GL_UNSIGNED_SHORT, + Short = GL_SHORT, + UnsignedInt = GL_UNSIGNED_INT, + Int = GL_INT, + Half = GL_HALF_FLOAT, + Float = GL_FLOAT, + Double = GL_DOUBLE, + UnsignedAlpha2RGB10 = GL_UNSIGNED_INT_2_10_10_10_REV, + Alpha2RGB10 = GL_INT_2_10_10_10_REV + }; + + enum class DataOption: std::uint8_t { + Normalized = 1 << 0, + BGRA = 2 << 0 + }; + + typedef Corrade::Containers::EnumSet DataOptions; + + static const DataType DefaultDataType = DataType::Float; + + inline constexpr static GLint size(DataOptions options) { + return options & DataOption::BGRA ? GL_BGRA : 4; + } + inline constexpr static std::size_t vectorCount() { return 1; } +}; + +typedef Math::Vector<4, GLfloat> _Vector4; +CORRADE_ENUMSET_OPERATORS(Attribute<_Vector4>::DataOptions) + +template<> struct Attribute { + enum class DataType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, + Byte = GL_BYTE, + UnsignedShort = GL_UNSIGNED_SHORT, + Short = GL_SHORT, + UnsignedInt = GL_UNSIGNED_INT, + Int = GL_INT + }; + + enum class DataOption: std::uint8_t {}; + + typedef Corrade::Containers::EnumSet DataOptions; + + static const DataType DefaultDataType = DataType::Int; + + inline constexpr static GLint size() { return 1; } +}; + +template<> struct Attribute { + typedef Attribute::DataType DataType; + typedef Attribute::DataOption DataOption; + + typedef Corrade::Containers::EnumSet DataOptions; + + static const DataType DefaultDataType = DataType::UnsignedInt; + + inline constexpr static GLint size() { return 1; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size() { return size; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size() { return size; } +}; + +template<> struct Attribute { + enum class DataType: GLenum { + Double = GL_DOUBLE + }; + + enum class DataOption: std::uint8_t {}; + + typedef Corrade::Containers::EnumSet DataOptions; + + static const DataType DefaultDataType = DataType::Double; + + inline constexpr static GLint size() { return 1; } + inline constexpr static std::size_t vectorCount() { return 1; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size() { return rows; } + inline constexpr static std::size_t vectorCount() { return cols; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size() { return size; } + inline constexpr static std::size_t vectorCount() { return size; } +}; + +template struct Attribute>: public Attribute { + inline constexpr static GLint size() { return size; } + inline constexpr static std::size_t vectorCount() { return size; } +}; + +template struct Attribute>: public Attribute> {}; +template struct Attribute>: public Attribute> {}; +template struct Attribute>: public Attribute> {}; + +template struct Attribute>: public Attribute> {}; +template struct Attribute>: public Attribute> {}; + +template class Color3; +template class Color4; +template struct Attribute>: public Attribute> {}; +template struct Attribute>: public Attribute> {}; + +template struct Attribute>: public Attribute> {}; +template struct Attribute>: public Attribute> {}; + +} +#endif + } #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index f62ec3563..1fe2c3919 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -29,7 +29,9 @@ namespace Magnum { Mesh::CreateImplementation Mesh::createImplementation = &Mesh::createImplementationDefault; Mesh::DestroyImplementation Mesh::destroyImplementation = &Mesh::destroyImplementationDefault; -Mesh::BindAttributeImplementation Mesh::bindAttributeImplementation = &Mesh::bindAttributeImplementationDefault; +Mesh::AttributePointerImplementation Mesh::attributePointerImplementation = &Mesh::attributePointerImplementationDefault; +Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &Mesh::attributePointerImplementationDefault; +Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault; Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; @@ -58,6 +60,16 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } +Mesh* Mesh::setVertexCount(GLsizei vertexCount) { + _vertexCount = vertexCount; + attributes.clear(); + #ifndef MAGNUM_TARGET_GLES + integerAttributes.clear(); + longAttributes.clear(); + #endif + return this; +} + void Mesh::draw() { bind(); @@ -78,34 +90,25 @@ void Mesh::bind() { (this->*bindImplementation)(); } -void Mesh::addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride) { - CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", ); - - attributes.push_back({ - buffer, - location, - count, - type, - offset, - stride - }); - - (this->*bindAttributeImplementation)(attributes.back()); +void Mesh::vertexAttribPointer(const Attribute& attribute) { + glEnableVertexAttribArray(attribute.location); + attribute.buffer->bind(Buffer::Target::Array); + glVertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, reinterpret_cast(attribute.offset)); } -void Mesh::vertexAttribPointer(const Mesh::Attribute& attribute) { +#ifndef MAGNUM_TARGET_GLES +void Mesh::vertexAttribPointer(const IntegerAttribute& attribute) { glEnableVertexAttribArray(attribute.location); - attribute.buffer->bind(Buffer::Target::Array); + glVertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); +} - #ifndef MAGNUM_TARGET_GLES - if(TypeInfo::isIntegral(attribute.type)) - glVertexAttribIPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); - else if(attribute.type == Type::Double) - glVertexAttribLPointer(attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, reinterpret_cast(attribute.offset)); - #endif - glVertexAttribPointer(attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, reinterpret_cast(attribute.offset)); +void Mesh::vertexAttribPointer(const LongAttribute& attribute) { + glEnableVertexAttribArray(attribute.location); + attribute.buffer->bind(Buffer::Target::Array); + glVertexAttribLPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); } +#endif void Mesh::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { @@ -117,8 +120,15 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { Debug() << "Mesg: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; - bindAttributeImplementation = &Mesh::bindAttributeImplementationDSA; - } else bindAttributeImplementation = &Mesh::bindAttributeImplementationVAO; + + attributePointerImplementation = &Mesh::attributePointerImplementationDSA; + attributeIPointerImplementation = &Mesh::attributePointerImplementationDSA; + attributeLPointerImplementation = &Mesh::attributePointerImplementationDSA; + } else { + attributePointerImplementation = &Mesh::attributePointerImplementationVAO; + attributeIPointerImplementation = &Mesh::attributePointerImplementationVAO; + attributeLPointerImplementation = &Mesh::attributePointerImplementationVAO; + } bindImplementation = &Mesh::bindImplementationVAO; unbindImplementation = &Mesh::unbindImplementationVAO; @@ -142,29 +152,55 @@ void Mesh::destroyImplementationVAO() { } #endif -void Mesh::bindAttributeImplementationDefault(const Attribute&) {} +void Mesh::attributePointerImplementationDefault(const Attribute&) {} #ifndef MAGNUM_TARGET_GLES -void Mesh::bindAttributeImplementationVAO(const Attribute& attribute) { +void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { bindVAO(vao); vertexAttribPointer(attribute); } -void Mesh::bindAttributeImplementationDSA(const Attribute& attribute) { + +void Mesh::attributePointerImplementationDSA(const Attribute& attribute) { glEnableVertexArrayAttribEXT(vao, attribute.location); + glVertexArrayVertexAttribOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.offset); +} - #ifndef MAGNUM_TARGET_GLES - if(TypeInfo::isIntegral(attribute.type)) - glVertexArrayVertexAttribIOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, attribute.offset); - else if(attribute.type == Type::Double) - glVertexArrayVertexAttribLOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), attribute.stride, attribute.offset); - #endif - glVertexArrayVertexAttribOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.count, static_cast(attribute.type), GL_FALSE, attribute.stride, attribute.offset); +void Mesh::attributePointerImplementationDefault(const IntegerAttribute&) {} + +void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) { + bindVAO(vao); + vertexAttribPointer(attribute); +} + +void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute) { + glEnableVertexArrayAttribEXT(vao, attribute.location); + glVertexArrayVertexAttribIOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset); +} + +void Mesh::attributePointerImplementationDefault(const LongAttribute&) {} + +void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) { + bindVAO(vao); + vertexAttribPointer(attribute); +} + +void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { + glEnableVertexArrayAttribEXT(vao, attribute.location); + glVertexArrayVertexAttribLOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset); } #endif void Mesh::bindImplementationDefault() { for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); + + #ifndef MAGNUM_TARGET_GLES + for(const IntegerAttribute& attribute: integerAttributes) + vertexAttribPointer(attribute); + + for(const LongAttribute& attribute: longAttributes) + vertexAttribPointer(attribute); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -176,6 +212,14 @@ void Mesh::bindImplementationVAO() { void Mesh::unbindImplementationDefault() { for(const Attribute& attribute: attributes) glDisableVertexAttribArray(attribute.location); + + #ifndef MAGNUM_TARGET_GLES + for(const IntegerAttribute& attribute: integerAttributes) + glDisableVertexAttribArray(attribute.location); + + for(const LongAttribute& attribute: longAttributes) + glDisableVertexAttribArray(attribute.location); + #endif } #ifndef MAGNUM_TARGET_GLES diff --git a/src/Mesh.h b/src/Mesh.h index 090574932..bdd430d70 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -20,6 +20,7 @@ */ #include +#include #include "AbstractShaderProgram.h" #include "TypeTraits.h" @@ -30,7 +31,7 @@ class Buffer; class Context; /** -@brief Base class for managing non-indexed meshes +@brief Non-indexed mesh @section Mesh-configuration Mesh configuration @@ -38,8 +39,8 @@ To properly configure mesh, you have to set primitive either in constructor or using setPrimitive() and call setVertexCount(). Then create vertex buffers, and them with vertex data. You can also use MeshTools::interleave() to conveniently set vertex count and buffer data. At last assign them to mesh and -given shader locations using addVertexBuffer(), addInterleavedVertexBuffer() -or addVertexBufferStride(). +@ref AbstractShaderProgram::Attribute "shader attributes" using +addVertexBuffer(), addInterleavedVertexBuffer() or addVertexBufferStride(). Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, so you have to manage it on your own. On the other hand it allows you to use @@ -49,6 +50,12 @@ shader) or store more than only vertex data in one buffer. Example usage -- filling buffer with position data, configuring the mesh and assigning the buffer to mesh to use with custom shader: @code +class MyShader: public AbstractShaderProgram { + public: + typedef Attribute<0, Point3D> Position; + + // ... +}; Buffer* buffer; Mesh* mesh; @@ -59,11 +66,11 @@ buffer->setData(positions, Buffer::Usage::StaticDraw); mesh->setPrimitve(Mesh::Primitive::Triangles) ->setVertexCount(30) - ->addVertexBuffer(buffer, MyShader::Position); + ->addVertexBuffer(buffer, MyShader::Position()); @endcode Example usage -- creating a plane mesh and assigning buffer with interleaved -vertex attributes for use with phong shader: +vertex attributes for use with Shaders::PhongShader: @code Buffer* buffer; Mesh* mesh; @@ -71,7 +78,22 @@ Mesh* mesh; Primitives::Plane plane; MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, *plane.positions(0), *plane.normals(0)); mesh->setPrimitive(plane.primitive()) - ->addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position, Shaders::PhongShader::Normal); + ->addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); +@endcode + +Example usage -- passing color attribute as normalized unsigned byte with BGRA +component ordering (e.g. directly from @ref Trade::TgaImporter "TGA file"): +@code +class MyShader: public AbstractShaderProgram { + public: + typedef Attribute<1, Color4> Color; + + // ... +}; +Buffer* buffer; +Mesh* mesh; + +mesh->addVertexBuffer(buffer, MyShader::Color(Type::UsignedByte, MyShader::Color::Normalized|MyShader::Color::BGRA)); @endcode @section Mesh-drawing Rendering meshes @@ -91,16 +113,6 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for more information. -@requires_gles30 Integer attributes are not supported in OpenGL ES 2.0. -@requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes) - -@requires_gl Double attributes are supported only on Desktop OpenGL. -@requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double attributes) - -@todo The attributes can be specified with different type than in shader - how? -@todo Support for normalized values (e.g. for color as char[4] passed to - shader as floating-point vec4) -@todo Support for packed unsigned integer types for attributes (OpenGL 3.3, @extension{ARB,vertex_type_2_10_10_10_rev}) @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ @@ -394,18 +406,15 @@ class MAGNUM_EXPORT Mesh { * addVertexBuffer()/addInterleavedVertexBuffer() afterwards. * @see MeshTools::interleave() */ - inline Mesh* setVertexCount(GLsizei vertexCount) { - _vertexCount = vertexCount; - attributes.clear(); - return this; - } + Mesh* setVertexCount(GLsizei vertexCount); /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader * - * Attribute list is combination of attribute definitions (specified - * in implementation of given shader) and offsets between attribute - * arrays. + * Attribute list is combination of + * @ref AbstractShaderProgram::Attribute "attribute definitions" + * (specified in implementation of given shader) and offsets between + * attribute arrays. * * See @ref Mesh-configuration "class documentation" for simple usage * example. For more involved example imagine that you have buffer @@ -419,17 +428,17 @@ class MAGNUM_EXPORT Mesh { * Buffer* buffer; * mesh->addVertexBuffer(buffer, * 35, // skip other data - * Shaders::PhongShader::Position, // position array + * Shaders::PhongShader::Position(), // position array * sizeof(Vector2)*mesh->vertexCount(), // skip texture coordinate array - * Shaders::PhongShader::Normal); // normal array + * Shaders::PhongShader::Normal()); // normal array * @endcode * * Vou can also achieve the same effect by calling this function more * times with absolute offsets: * @code - * mesh->addVertexBuffer(buffer, 35, Shaders::PhongShader::Position); + * mesh->addVertexBuffer(buffer, 35, Shaders::PhongShader::Position()); * ->addVertexBuffer(buffer, 35 + (sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2))* - * mesh->vertexCount(), Shaders::PhongShader::Normal); + * mesh->vertexCount(), Shaders::PhongShader::Normal()); * @endcode * * @attention Non-zero vertex count must be set before calling this @@ -446,6 +455,8 @@ class MAGNUM_EXPORT Mesh { * if @extension{APPLE,vertex_array_object} is available */ template inline Mesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { + CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", this); + addVertexBufferInternal(buffer, 0, attributes...); return this; } @@ -454,7 +465,8 @@ class MAGNUM_EXPORT Mesh { * @brief Add buffer with interleaved vertex attributes for use with given shader * * Parameter @p offset is offset of the interleaved array from the - * beginning, attribute list is combination of attribute definitions + * beginning, attribute list is combination of + * @ref AbstractShaderProgram::Attribute "attribute definitions" * (specified in implementation of given shader) and offsets between * attributes. * @@ -470,32 +482,30 @@ class MAGNUM_EXPORT Mesh { * Mesh* mesh; * Buffer* buffer; * mesh->addInterleavedVertexBuffer(buffer, - * 35, // skip other data - * sizeof(GLfloat), // skip vertex weight - * Shaders::PhongShader::Position, // vertex position - * sizeof(Vector2), // skip texture coordinates - * Shaders::PhongShader::Normal); // vertex normal + * 35, // skip other data + * sizeof(GLfloat), // skip vertex weight + * Shaders::PhongShader::Position(), // vertex position + * sizeof(Vector2), // skip texture coordinates + * Shaders::PhongShader::Normal()); // vertex normal * @endcode * * You can also achieve the same effect by calling addVertexBufferStride() * more times with absolute offset from the beginning and stride * between vertex attributes: * @code - * GLsizei stride = // size of one vertex + * GLsizei stride = // size of one vertex * sizeof(GLfloat) + * sizeof(Shaders::PhongShader::Position::Type) + * sizeof(Vector2) + * sizeof(Shaders::PhongShader::Normal::Type); * * mesh->addVertexBufferStride(buffer, 35 + sizeof(GLfloat), - * stride, Shaders::PhongShader::Position); + * stride, Shaders::PhongShader::Position()); * ->addVertexBufferStride(buffer, 35 + sizeof(GLfloat) + * sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2), - * stride, Shaders::PhongShader::Normal); + * stride, Shaders::PhongShader::Normal()); * @endcode * - * @attention Non-zero vertex count must be set before calling this - * function. * @attention The buffer passed as parameter is not managed by the * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. @@ -536,20 +546,41 @@ class MAGNUM_EXPORT Mesh { virtual void draw(); private: + #ifndef DOXYGEN_GENERATING_OUTPUT struct MAGNUM_LOCAL Attribute { Buffer* buffer; GLuint location; - GLint count; - Type type; + GLint size; + GLenum type; + bool normalized; + GLintptr offset; + GLsizei stride; + }; + + struct MAGNUM_LOCAL IntegerAttribute { + Buffer* buffer; + GLuint location; + GLint size; + GLenum type; + GLintptr offset; + GLsizei stride; + }; + + struct MAGNUM_LOCAL LongAttribute { + Buffer* buffer; + GLuint location; + GLint size; + GLenum type; GLintptr offset; GLsizei stride; }; + #endif static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); /* Adding non-interleaved vertex attributes */ - template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute&, const U&... attributes) { - addVertexAttribute(buffer, location, TypeTraits::count(), TypeTraits::type(), offset, 0); + template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + addVertexAttribute(buffer, attribute, offset, 0); /* Add size of this attribute array to offset for next attribute */ addVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size()*_vertexCount, attributes...); @@ -570,8 +601,8 @@ class MAGNUM_EXPORT Mesh { inline static GLsizei strideOfInterleaved() { return 0; } /* Adding interleaved vertex attributes */ - template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute&, const U&... attributes) { - addVertexAttribute(buffer, location, TypeTraits::count(), TypeTraits::type(), offset, stride); + template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + addVertexAttribute(buffer, attribute, offset, stride); /* Add size of this attribute to offset for next attribute */ addInterleavedVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size(), stride, attributes...); @@ -582,7 +613,51 @@ class MAGNUM_EXPORT Mesh { } inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} - void MAGNUM_EXPORT addVertexAttribute(Buffer* buffer, GLuint location, GLint count, Type type, GLintptr offset, GLsizei stride); + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { + attributes.push_back({ + buffer, + location+i, + Implementation::Attribute::size(attribute.dataOptions()), + static_cast(attribute.dataType()), + !!(attribute.dataOptions() & AbstractShaderProgram::Attribute::DataOption::Normalized), + offset, + stride + }); + } + + (this->*attributePointerImplementation)(attributes.back()); + } + + #ifndef MAGNUM_TARGET_GLES + template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + integerAttributes.push_back({ + buffer, + location, + Implementation::Attribute::size(), + static_cast(attribute.dataType()), + offset, + stride + }); + + (this->*attributeIPointerImplementation)(integerAttributes.back()); + } + + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { + longAttributes.push_back({ + buffer, + location+i, + Implementation::Attribute::size(), + static_cast(attribute.dataType()), + offset, + stride + }); + + (this->*attributeLPointerImplementation)(longAttributes.back()); + } + } + #endif static void MAGNUM_LOCAL bindVAO(GLuint vao); @@ -593,6 +668,10 @@ class MAGNUM_EXPORT Mesh { } void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL vertexAttribPointer(const IntegerAttribute& attribute); + void MAGNUM_LOCAL vertexAttribPointer(const LongAttribute& attribute); + #endif typedef void(Mesh::*CreateImplementation)(); void MAGNUM_LOCAL createImplementationDefault(); @@ -608,13 +687,27 @@ class MAGNUM_EXPORT Mesh { #endif static MAGNUM_LOCAL DestroyImplementation destroyImplementation; - typedef void(Mesh::*BindAttributeImplementation)(const Attribute&); - void MAGNUM_LOCAL bindAttributeImplementationDefault(const Attribute& attribute); + typedef void(Mesh::*AttributePointerImplementation)(const Attribute&); + void MAGNUM_LOCAL attributePointerImplementationDefault(const Attribute& attribute); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL attributePointerImplementationVAO(const Attribute& attribute); + void MAGNUM_LOCAL attributePointerImplementationDSA(const Attribute& attribute); + #endif + static AttributePointerImplementation attributePointerImplementation; + #ifndef MAGNUM_TARGET_GLES - void MAGNUM_LOCAL bindAttributeImplementationVAO(const Attribute& attribute); - void MAGNUM_LOCAL bindAttributeImplementationDSA(const Attribute& attribute); + typedef void(Mesh::*AttributeIPointerImplementation)(const IntegerAttribute&); + void MAGNUM_LOCAL attributePointerImplementationDefault(const IntegerAttribute& attribute); + void MAGNUM_LOCAL attributePointerImplementationVAO(const IntegerAttribute& attribute); + void MAGNUM_LOCAL attributePointerImplementationDSA(const IntegerAttribute& attribute); + static AttributeIPointerImplementation attributeIPointerImplementation; + + typedef void(Mesh::*AttributeLPointerImplementation)(const LongAttribute&); + void MAGNUM_LOCAL attributePointerImplementationDefault(const LongAttribute& attribute); + void MAGNUM_LOCAL attributePointerImplementationVAO(const LongAttribute& attribute); + void MAGNUM_LOCAL attributePointerImplementationDSA(const LongAttribute& attribute); + static AttributeLPointerImplementation attributeLPointerImplementation; #endif - static MAGNUM_LOCAL BindAttributeImplementation bindAttributeImplementation; typedef void(Mesh::*BindImplementation)(); void MAGNUM_LOCAL bindImplementationDefault(); @@ -635,6 +728,8 @@ class MAGNUM_EXPORT Mesh { GLsizei _vertexCount; std::vector attributes; + std::vector integerAttributes; + std::vector longAttributes; }; } diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 260d291cd..8d79c69ba 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -22,9 +22,6 @@ namespace Magnum { namespace Shaders { -const PhongShader::Attribute<0, Point3D> PhongShader::Position; -const PhongShader::Attribute<1, Vector3> PhongShader::Normal; - PhongShader::PhongShader() { Corrade::Utility::Resource rs("MagnumShaders"); Version v = Context::current()->isVersionSupported(Version::GL320) ? Version::GL320 : Version::GL210; @@ -32,8 +29,8 @@ PhongShader::PhongShader() { attachShader(Shader::fromData(v, Shader::Type::Fragment, rs.get("PhongShader.frag"))); if(!Context::current()->isExtensionSupported()) { - bindAttributeLocation(Position.Location, "position"); - bindAttributeLocation(Normal.Location, "normal"); + bindAttributeLocation(Position::Location, "position"); + bindAttributeLocation(Normal::Location, "normal"); } link(); diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 478b7b45d..d334133a9 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -35,8 +35,8 @@ otherwise falls back to GLSL 1.20. */ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - static const Attribute<0, Point3D> Position; /**< @brief Vertex position */ - static const Attribute<1, Vector3> Normal; /**< @brief Normal direction */ + typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ + typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ PhongShader(); From bf55b5854b1161ca805c8883bc9f438ad645e1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 26 Oct 2012 15:18:23 +0200 Subject: [PATCH 220/256] TypeTraits: Default inheritance type for structs is public. Simplified already too long lines. --- src/Math/MathTypeTraits.h | 20 ++++++++++---------- src/TypeTraits.h | 40 +++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 4bf013937..53413f4ae 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -126,49 +126,49 @@ template<> struct MathTypeTraitsLong<8> { } -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::uint32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::int32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::uint64_t NumericType; typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef std::int64_t NumericType; typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { typedef float NumericType; typedef float FloatingPointType; inline constexpr static float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { typedef float NumericType; typedef double FloatingPointType; diff --git a/src/TypeTraits.h b/src/TypeTraits.h index ba53cb79b..e134e7b9d 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -42,7 +42,7 @@ Where it makes sense, this class extends Math::MathTypeTraits with OpenGL-specific traits. */ #ifdef DOXYGEN_GENERATING_OUTPUT -template struct TypeTraits: public Math::MathTypeTraits { +template struct TypeTraits: Math::MathTypeTraits { /** * @brief Corresponding type for vertex attributes * @@ -176,7 +176,7 @@ template<> struct TypeOf { typedef GLfloat Type; }; template<> struct TypeOf { typedef GLdouble Type; }; #endif -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; } @@ -185,7 +185,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ @@ -194,7 +194,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } @@ -203,7 +203,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ @@ -212,7 +212,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } @@ -221,7 +221,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ @@ -230,7 +230,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ @@ -240,7 +240,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { }; #ifndef MAGNUM_TARGET_GLES -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; inline constexpr static Type type() { return Type::Double; } /* Can not be used for indices */ @@ -282,7 +282,7 @@ namespace Implementation { #endif } -template struct TypeTraits>: public Implementation::VectorTypeTraits {}; +template struct TypeTraits>: Implementation::VectorTypeTraits {}; /* Only some vectors can be used as attributes */ template struct TypeTraits>: Implementation::VectorTypeTraits<1, T>, Implementation::VectorAttributeType {}; @@ -290,13 +290,13 @@ template struct TypeTraits>: Implementation::VectorT template struct TypeTraits>: Implementation::VectorTypeTraits<3, T>, Implementation::VectorAttributeType {}; template struct TypeTraits>: Implementation::VectorTypeTraits<4, T>, Implementation::VectorAttributeType {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; namespace Implementation { template struct MatrixTypeTraits { @@ -322,7 +322,7 @@ namespace Implementation { #endif } -template struct TypeTraits>: public Implementation::MatrixTypeTraits {}; +template struct TypeTraits>: Implementation::MatrixTypeTraits {}; /* Only some floating-point matrices can be used as attributes */ template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 2, T>, Implementation::MatrixAttributeType {}; @@ -337,8 +337,8 @@ template struct TypeTraits>: Implement template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; -template struct TypeTraits>: public TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; +template struct TypeTraits>: TypeTraits> {}; #endif } From c460fdc059af9046c2a50c6d6535506be943b1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 00:21:30 +0100 Subject: [PATCH 221/256] Doc++ --- src/AbstractShaderProgram.h | 2 +- src/Trade/AbstractImporter.h | 4 ++-- src/Trade/AbstractMaterialData.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 2c9ddbe50..e1efd315e 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -46,7 +46,7 @@ namespace Implementation { #endif /** -@brief Base class for shader program implementations +@brief Base for shader program implementations @section AbstractShaderProgram-subclassing Subclassing workflow diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index e8181915a..23cef208c 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -42,12 +42,12 @@ typedef ImageData<2> ImageData2D; typedef ImageData<3> ImageData3D; /** -@brief Base class for importer plugins +@brief Base for importer plugins Importer is used for importing data like scenes, lights, objects, images, textures etc. -@section AbstractImporterSubclassing Subclassing +@section AbstractImporter-subclassing Subclassing Plugin implements function features(), one or more open() functions, function close() and one or more pairs of data access functions, based on which features are supported in given format. diff --git a/src/Trade/AbstractMaterialData.h b/src/Trade/AbstractMaterialData.h index 477146bea..0e0b17c69 100644 --- a/src/Trade/AbstractMaterialData.h +++ b/src/Trade/AbstractMaterialData.h @@ -24,7 +24,7 @@ namespace Magnum { namespace Trade { /** -@brief Base class for material data +@brief Base for material data Subclasses provide access to parameters for given material type. */ From f707e91599efa8f77cdb0769f72827756145da26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 00:22:52 +0100 Subject: [PATCH 222/256] Better parameter names in Matrix transformation methods. Mainly it is now explicitly stated in parameter name that rotation axis must be normalized. --- src/Math/Matrix3.h | 16 +++++------ src/Math/Matrix4.h | 50 +++++++++++++++++------------------ src/Math/Test/Matrix4Test.cpp | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 0fdf309bc..9d0ec0223 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -36,37 +36,37 @@ template class Matrix3: public Matrix<3, T> { public: /** * @brief 2D translation matrix - * @param vec Translation vector + * @param vector Translation vector * * @see translation(), Matrix4::translation(const Vector3&), * Vector2::xAxis(), Vector2::yAxis() */ - inline constexpr static Matrix3 translation(const Vector2& vec) { + inline constexpr static Matrix3 translation(const Vector2& vector) { return Matrix3( /* Column-major! */ T(1), T(0), T(0), T(0), T(1), T(0), - vec.x(), vec.y(), T(1) + vector.x(), vector.y(), T(1) ); } /** * @brief 2D scaling matrix - * @param vec Scaling vector + * @param vector Scaling vector * * @see rotationScaling() const, Matrix4::scaling(const Vector3&), * Vector2::xScale(), Vector2::yScale() */ - inline constexpr static Matrix3 scaling(const Vector2& vec) { + inline constexpr static Matrix3 scaling(const Vector2& vector) { return Matrix3( /* Column-major! */ - vec.x(), T(0), T(0), - T(0), vec.y(), T(0), + vector.x(), T(0), T(0), + T(0), vector.y(), T(0), T(0), T(0), T(1) ); } /** * @brief 2D rotation matrix - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise, in radians) * * @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), * rad() diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 0354eb991..0e4a94cee 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -38,40 +38,40 @@ template class Matrix4: public Matrix<4, T> { public: /** * @brief 3D translation - * @param vec Translation vector + * @param vector Translation vector * * @see translation(), Matrix3::translation(const Vector2&), * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() */ - inline constexpr static Matrix4 translation(const Vector3& vec) { + inline constexpr static Matrix4 translation(const Vector3& vector) { return Matrix4( /* Column-major! */ T(1), T(0), T(0), T(0), T(0), T(1), T(0), T(0), T(0), T(0), T(1), T(0), - vec.x(), vec.y(), vec.z(), T(1) + vector.x(), vector.y(), vector.z(), T(1) ); } /** * @brief 3D scaling - * @param vec Scaling vector + * @param vector Scaling vector * * @see rotationScaling() const, Matrix3::scaling(const Vector2&), * Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ - inline constexpr static Matrix4 scaling(const Vector3& vec) { + inline constexpr static Matrix4 scaling(const Vector3& vector) { return Matrix4( /* Column-major! */ - vec.x(), T(0), T(0), T(0), - T(0), vec.y(), T(0), T(0), - T(0), T(0), vec.z(), T(0), + vector.x(), T(0), T(0), T(0), + T(0), vector.y(), T(0), T(0), + T(0), T(0), vector.z(), T(0), T(0), T(0), T(0), T(1) ); } /** * @brief 3D rotation around arbitrary axis - * @param angle Rotation angle (counterclockwise, in radians) - * @param vec Normalized rotation axis + * @param angle Rotation angle (counterclockwise, in radians) + * @param normalizedAxis Normalized rotation axis * * If possible, use faster alternatives like xRotation(), yRotation() * or zRotation(). @@ -80,32 +80,32 @@ template class Matrix4: public Matrix<4, T> { * @attention Assertion fails on non-normalized rotation vector and * identity matrix is returned. */ - static Matrix4 rotation(T angle, const Vector3& vec) { - CORRADE_ASSERT(MathTypeTraits::equals(vec.dot(), T(1)), - "Math::Matrix4::rotation(): vector must be normalized", {}); + static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + "Math::Matrix4::rotation(): axis must be normalized", {}); T sine = std::sin(angle); T cosine = std::cos(angle); T oneMinusCosine = T(1) - cosine; - T xx = vec.x()*vec.x(); - T xy = vec.x()*vec.y(); - T xz = vec.x()*vec.z(); - T yy = vec.y()*vec.y(); - T yz = vec.y()*vec.z(); - T zz = vec.z()*vec.z(); + T xx = normalizedAxis.x()*normalizedAxis.x(); + T xy = normalizedAxis.x()*normalizedAxis.y(); + T xz = normalizedAxis.x()*normalizedAxis.z(); + T yy = normalizedAxis.y()*normalizedAxis.y(); + T yz = normalizedAxis.y()*normalizedAxis.z(); + T zz = normalizedAxis.z()*normalizedAxis.z(); return Matrix4( /* Column-major! */ cosine + xx*oneMinusCosine, - xy*oneMinusCosine + vec.z()*sine, - xz*oneMinusCosine - vec.y()*sine, + xy*oneMinusCosine + normalizedAxis.z()*sine, + xz*oneMinusCosine - normalizedAxis.y()*sine, T(0), - xy*oneMinusCosine - vec.z()*sine, + xy*oneMinusCosine - normalizedAxis.z()*sine, cosine + yy*oneMinusCosine, - yz*oneMinusCosine + vec.x()*sine, + yz*oneMinusCosine + normalizedAxis.x()*sine, T(0), - xz*oneMinusCosine + vec.y()*sine, - yz*oneMinusCosine - vec.x()*sine, + xz*oneMinusCosine + normalizedAxis.y()*sine, + yz*oneMinusCosine - normalizedAxis.x()*sine, cosine + zz*oneMinusCosine, T(0), T(0), T(0), T(0), T(1) diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index fbcc08e4d..b65142c53 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -97,7 +97,7 @@ void Matrix4Test::rotation() { Error::setOutput(&o); CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); - CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): vector must be normalized\n"); + CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n"); Matrix4 matrix( 0.35612214f, -0.80181062f, 0.47987163f, 0.0f, From b5fc7864784483e5f156c399a11d935bd0198873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 00:34:36 +0100 Subject: [PATCH 223/256] Renamed Matrix4::[xyz]Rotation() to Matrix4::rotation[XYZ](). * "Rotation around [XYZ]" makes more sense than "[XYZ] axis rotation". * This naming will appear in autocompletion. * SceneGraph transformation methods will be named similarly rotate[XYZ]() (because [xyz]Rotate() is weird even more). --- src/Math/Matrix4.h | 16 ++++++++-------- src/Math/Test/Matrix4Test.cpp | 18 +++++++++--------- src/Math/Test/Matrix4Test.h | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 0e4a94cee..7fda233b9 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -73,8 +73,8 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * @param normalizedAxis Normalized rotation axis * - * If possible, use faster alternatives like xRotation(), yRotation() - * or zRotation(). + * If possible, use faster alternatives like rotationX(), rotationY() + * and rotationZ(). * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() * @attention Assertion fails on non-normalized rotation vector and @@ -117,10 +117,10 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * * Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`. - * @see rotation(T, const Vector3&), yRotation(), zRotation(), + * @see rotation(T, const Vector3&), rotationY(), rotationZ(), * rotation() const, Matrix3::rotation(T), deg(), rad() */ - static Matrix4 xRotation(T angle) { + static Matrix4 rotationX(T angle) { T sine = std::sin(angle); T cosine = std::cos(angle); @@ -137,10 +137,10 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * * Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`. - * @see rotation(T, const Vector3&), xRotation(), zRotation(), + * @see rotation(T, const Vector3&), rotationX(), rotationZ(), * rotation() const, Matrix3::rotation(T), deg(), rad() */ - static Matrix4 yRotation(T angle) { + static Matrix4 rotationY(T angle) { T sine = std::sin(angle); T cosine = std::cos(angle); @@ -157,10 +157,10 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * * Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`. - * @see rotation(T, const Vector3&), xRotation(), yRotation(), + * @see rotation(T, const Vector3&), rotationX(), rotationY(), * rotation() const, Matrix3::rotation(T), deg(), rad() */ - static Matrix4 zRotation(T angle) { + static Matrix4 rotationZ(T angle) { T sine = std::sin(angle); T cosine = std::cos(angle); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index b65142c53..a124d2b4c 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -36,9 +36,9 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::translation, &Matrix4Test::scaling, &Matrix4Test::rotation, - &Matrix4Test::xRotation, - &Matrix4Test::yRotation, - &Matrix4Test::zRotation, + &Matrix4Test::rotationX, + &Matrix4Test::rotationY, + &Matrix4Test::rotationZ, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, &Matrix4Test::translationPart, @@ -108,31 +108,31 @@ void Matrix4Test::rotation() { CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); } -void Matrix4Test::xRotation() { +void Matrix4Test::rotationX() { Matrix4 matrix(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.90096887f, 0.43388374f, 0.0f, 0.0f, -0.43388374f, 0.90096887f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); - CORRADE_COMPARE(Matrix4::xRotation(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotationX(rad(Math::Constants::pi()/7)), matrix); } -void Matrix4Test::yRotation() { +void Matrix4Test::rotationY() { Matrix4 matrix(0.90096887f, 0.0f, -0.43388374f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.43388374f, 0.0f, 0.90096887f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); - CORRADE_COMPARE(Matrix4::yRotation(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotationY(rad(Math::Constants::pi()/7)), matrix); } -void Matrix4Test::zRotation() { +void Matrix4Test::rotationZ() { Matrix4 matrix( 0.90096887f, 0.43388374f, 0.0f, 0.0f, -0.43388374f, 0.90096887f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); - CORRADE_COMPARE(Matrix4::zRotation(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationScalingPart() { diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 7e22e979a..783c6adb2 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -28,9 +28,9 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void translation(); void scaling(); void rotation(); - void xRotation(); - void yRotation(); - void zRotation(); + void rotationX(); + void rotationY(); + void rotationZ(); void rotationScalingPart(); void rotationPart(); void translationPart(); From 6ebe42c3a9195966eda4305844e4fbd3a646c67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 14:09:24 +0100 Subject: [PATCH 224/256] Compatibility mode for GCC 4.6. 4.6 doesn't support `override` keyword, using preprocessor macro to simply hide it. The compatibility mode must be explicitly enabled, though, using GCC46_COMPATIBILITY CMake option. --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 6 ++++++ src/magnumCompatibility.h | 24 ++++++++++++++++++++++++ src/magnumConfigure.h.cmake | 1 + 4 files changed, 33 insertions(+) create mode 100644 src/magnumCompatibility.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c33a6f7ee..9ab022437 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(Magnum) include(CMakeDependentOption) +option(GCC46_COMPATIBILITY "Enable compatibility mode for GCC 4.6 (might disable some features)" OFF) + option(TARGET_GLES "Build for OpenGL ES instead of desktop OpenGL" OFF) cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23b57f72c..b6361857c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,11 @@ endif() if(TARGET_GLES2) set(MAGNUM_TARGET_GLES2 1) endif() + +if(GCC46_COMPATIBILITY) + set(MAGNUM_GCC46_COMPATIBILITY 1) +endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumConfigure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h) @@ -73,6 +78,7 @@ set(Magnum_HEADERS Timeline.h TypeTraits.h + magnumCompatibility.h magnumVisibility.h) add_library(MagnumObjects OBJECT ${Magnum_SRCS}) diff --git a/src/magnumCompatibility.h b/src/magnumCompatibility.h new file mode 100644 index 000000000..c69691732 --- /dev/null +++ b/src/magnumCompatibility.h @@ -0,0 +1,24 @@ +#ifndef magnumCompatibility_h +#define magnumCompatibility_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "magnumConfigure.h" + +#ifdef MAGNUM_GCC46_COMPATIBILITY +#define override +#endif + +#endif diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index 7b42510db..a2d1d818f 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -1,2 +1,3 @@ #cmakedefine MAGNUM_TARGET_GLES #cmakedefine MAGNUM_TARGET_GLES2 +#cmakedefine MAGNUM_GCC46_COMPATIBILITY From e9329745e89913c387f020e7db4b523bbf223cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 14:12:23 +0100 Subject: [PATCH 225/256] Using `override` keyword in all places I can think of at this time. --- src/Contexts/AbstractXWindowContext.h | 4 +++- src/Contexts/EglContextHandler.h | 10 ++++++---- src/Contexts/GlutWindowContext.h | 4 +++- src/Contexts/GlxContextHandler.h | 12 +++++++----- src/Contexts/Sdl2WindowContext.h | 4 +++- src/Physics/AxisAlignedBox.h | 6 ++++-- src/Physics/Box.h | 6 ++++-- src/Physics/Capsule.h | 8 +++++--- src/Physics/Line.h | 6 ++++-- src/Physics/LineSegment.h | 2 +- src/Physics/Plane.h | 12 +++++++----- src/Physics/Point.h | 6 ++++-- src/Physics/ShapeGroup.h | 8 +++++--- src/Physics/Sphere.h | 8 +++++--- 14 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/Contexts/AbstractXWindowContext.h b/src/Contexts/AbstractXWindowContext.h index 75e8eccd2..dc84d51f5 100644 --- a/src/Contexts/AbstractXWindowContext.h +++ b/src/Contexts/AbstractXWindowContext.h @@ -33,6 +33,8 @@ #include "AbstractWindowContext.h" #include "AbstractContextHandler.h" +#include "magnumCompatibility.h" + namespace Magnum { class Context; @@ -67,7 +69,7 @@ class AbstractXWindowContext: public AbstractWindowContext { */ virtual ~AbstractXWindowContext() = 0; - int exec(); + int exec() override; /** @brief Exit application main loop */ inline void exit() { flags |= Flag::Exit; } diff --git a/src/Contexts/EglContextHandler.h b/src/Contexts/EglContextHandler.h index 824aa0177..7c9eab9c6 100644 --- a/src/Contexts/EglContextHandler.h +++ b/src/Contexts/EglContextHandler.h @@ -28,6 +28,8 @@ #include "AbstractContextHandler.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Contexts { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -48,14 +50,14 @@ class EglContextHandler: public AbstractContextHandler class PHYSICS_EXPORT AxisAlignedBox: public Ab /** @brief Constructor */ inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::AxisAlignedBox; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Position */ inline typename DimensionTraits::VectorType position() const { diff --git a/src/Physics/Box.h b/src/Physics/Box.h index d70aac3ab..d92ab64ab 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -23,6 +23,8 @@ #include "Math/Matrix4.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { /** @@ -35,11 +37,11 @@ template class PHYSICS_EXPORT Box: public AbstractShape /** @brief Constructor */ inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Box; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Transformation */ inline typename DimensionTraits::MatrixType transformation() const { diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 7e20a9814..c493f1db9 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -22,6 +22,8 @@ #include "Math/Vector3.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { template class Point; @@ -39,13 +41,13 @@ template class PHYSICS_EXPORT Capsule: public AbstractS /** @brief Constructor */ inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Capsule; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const override; /** @brief Start point */ inline typename DimensionTraits::VectorType a() const { diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 9f16e3d2b..39cb70363 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -22,6 +22,8 @@ #include "Math/Vector3.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { /** @@ -35,11 +37,11 @@ template class PHYSICS_EXPORT Line: public AbstractShap /** @brief Constructor */ inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Line; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief First point */ inline typename DimensionTraits::VectorType a() const { diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 82fe11861..8c0d00242 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -33,7 +33,7 @@ template class LineSegment: public Line { /** @brief Constructor */ inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::LineSegment; } }; diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 3895b6f6d..c17114b16 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -22,6 +22,8 @@ #include "Math/Vector3.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { template class Line; @@ -35,14 +37,14 @@ class PHYSICS_EXPORT Plane: public AbstractShape<3> { /** @brief Constructor */ inline Plane(const Vector3& position, const Vector3& normal): _position(position), _transformedPosition(position), _normal(normal), _transformedNormal(normal) {} - inline Type type() const { return Type::Plane; } + inline Type type() const override { return Type::Plane; } #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const Matrix4& transformation); - bool collides(const AbstractShape<3>* other) const; + void applyTransformation(const Matrix4& transformation) override; + bool collides(const AbstractShape<3>* other) const override; #else - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); - bool collides(const AbstractShape* other) const; + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + bool collides(const AbstractShape* other) const override; #endif /** @brief Position */ diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 9f867762c..142b315e0 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -22,6 +22,8 @@ #include "Math/Vector3.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { /** @@ -34,11 +36,11 @@ template class PHYSICS_EXPORT Point: public AbstractSha /** @brief Constructor */ inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Point; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; /** @brief Position */ inline typename DimensionTraits::VectorType position() const { diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index de8ab7fd8..8a3533e84 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -24,6 +24,8 @@ #include #include +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -99,13 +101,13 @@ template class PHYSICS_EXPORT ShapeGroup: public Abstra /** @brief Move assignment */ ShapeGroup& operator=(ShapeGroup&& other); - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::ShapeGroup; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const override; /** * @brief First object in the group diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 245ed9a4c..9a91966ca 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -22,6 +22,8 @@ #include "Math/Vector3.h" #include "AbstractShape.h" +#include "magnumCompatibility.h" + namespace Magnum { namespace Physics { template class Line; @@ -40,13 +42,13 @@ template class PHYSICS_EXPORT Sphere: public AbstractSh /** @brief Constructor */ inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} - inline typename AbstractShape::Type type() const { + inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Sphere; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation); + void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; - bool collides(const AbstractShape* other) const; + bool collides(const AbstractShape* other) const override; /** @brief Position */ inline typename DimensionTraits::VectorType position() const { From fe8d36db56c565ef0f3d15c4cc2cdbfbbf17bd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 15:03:37 +0100 Subject: [PATCH 226/256] Doc++ --- src/Shaders/PhongShader.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index d334133a9..5662c8f34 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -41,7 +41,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { PhongShader(); /** - * @brief Ambient color + * @brief Set ambient color * @return Pointer to self (for method chaining) * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. @@ -52,7 +52,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Diffuse color + * @brief Set diffuse color * @return Pointer to self (for method chaining) */ inline PhongShader* setDiffuseColor(const Color3& color) { @@ -61,7 +61,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Specular color + * @brief Set specular color * @return Pointer to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. @@ -72,7 +72,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Shininess + * @brief Set shininess * @return Pointer to self (for method chaining) * * The larger value, the harder surface (smaller specular highlight). @@ -84,7 +84,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Transformation matrix + * @brief Set transformation matrix * @return Pointer to self (for method chaining) */ inline PhongShader* setTransformation(const Matrix4& matrix) { @@ -93,7 +93,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Projection matrix + * @brief Set projection matrix * @return Pointer to self (for method chaining) */ inline PhongShader* setProjection(const Matrix4& matrix) { @@ -102,7 +102,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Light position + * @brief Set light position * @return Pointer to self (for method chaining) */ inline PhongShader* setLightPosition(const Vector3& light) { @@ -111,7 +111,7 @@ class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Light color + * @brief Set light color * @return Pointer to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. From d46bc34390a8b913057c1cb9618b273dcc5c62fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 15:06:23 +0100 Subject: [PATCH 227/256] Moved flat shader from internal physics implementation to Shaders. It is so general that it can be reused elsewhere. --- CMakeLists.txt | 2 +- modules/FindMagnum.cmake | 4 +- src/Physics/CMakeLists.txt | 10 +---- src/Physics/DebugDrawResourceManager.cpp | 4 +- .../Implementation/AbstractDebugRenderer.cpp | 4 +- .../Implementation/AbstractDebugRenderer.h | 8 ++-- src/Physics/Implementation/BoxRenderer.cpp | 6 +-- src/Shaders/CMakeLists.txt | 6 ++- .../FlatShader.cpp} | 22 +++++------ .../ShapeShader.h => Shaders/FlatShader.h} | 39 +++++++++++++------ .../FlatShader2D.frag} | 0 .../FlatShader2D.vert} | 0 12 files changed, 61 insertions(+), 44 deletions(-) rename src/{Physics/Implementation/ShapeShader.cpp => Shaders/FlatShader.cpp} (67%) rename src/{Physics/Implementation/ShapeShader.h => Shaders/FlatShader.h} (55%) rename src/{Physics/Implementation/ShapeShader2D.frag => Shaders/FlatShader2D.frag} (100%) rename src/{Physics/Implementation/ShapeShader2D.vert => Shaders/FlatShader2D.vert} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ab022437..f307a54d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EV cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) -cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) option(WITH_GLXWINDOWCONTEXT "Build GlxWindowContext library" OFF) cmake_dependent_option(WITH_XEGLWINDOWCONTEXT "Build XEglWindowContext library" OFF "TARGET_GLES" OFF) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 1e6e4e97f..76175adcc 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -16,8 +16,8 @@ # libraries. Additional dependencies are specified by the components. The # optional components are: # MeshTools - MeshTools library -# Physics - Physics library (depends on Primitives and SceneGraph -# components) +# Physics - Physics library (depends on Primitives, SceneGraph and +# Shaders components) # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 837b068a4..1dc1bf4cf 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,7 +1,3 @@ -corrade_add_resource(MagnumPhysics_RCS MagnumPhysics - Implementation/ShapeShader2D.vert ALIAS ShapeShader2D.vert - Implementation/ShapeShader2D.frag ALIAS ShapeShader2D.frag) - set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp @@ -17,9 +13,7 @@ set(MagnumPhysics_SRCS Sphere.cpp Implementation/AbstractDebugRenderer.cpp - Implementation/BoxRenderer.cpp - Implementation/ShapeShader.cpp - ${MagnumPhysics_RCS}) + Implementation/BoxRenderer.cpp) set(MagnumPhysics_HEADERS AbstractShape.h AxisAlignedBox.h @@ -39,7 +33,7 @@ set(MagnumPhysics_HEADERS add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) -target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph) +target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph MagnumShaders) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp index 539e677f8..f048a5816 100644 --- a/src/Physics/DebugDrawResourceManager.cpp +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -18,13 +18,13 @@ #include "AbstractShaderProgram.h" #include "Buffer.h" #include "Mesh.h" +#include "Shaders/FlatShader.h" #include "AbstractShape.h" #include "Box.h" #include "ShapedObject.h" #include "ShapeGroup.h" #include "Implementation/AbstractDebugRenderer.h" #include "Implementation/BoxRenderer.h" -#include "Implementation/ShapeShader.h" namespace Magnum { @@ -52,7 +52,7 @@ SceneGraph::Object2D* DebugDrawResourceManager::createDebugMesh(SceneGraph::Obje DebugDrawResourceManager::DebugDrawResourceManager() { setFallback(new Options); - set("shader2d", new Implementation::ShapeShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); + set("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); } DebugDrawResourceManager::~DebugDrawResourceManager() {} diff --git a/src/Physics/Implementation/AbstractDebugRenderer.cpp b/src/Physics/Implementation/AbstractDebugRenderer.cpp index 76bcfcf22..63235f8bb 100644 --- a/src/Physics/Implementation/AbstractDebugRenderer.cpp +++ b/src/Physics/Implementation/AbstractDebugRenderer.cpp @@ -18,11 +18,11 @@ #include "AbstractShaderProgram.h" #include "Mesh.h" #include "Physics/DebugDrawResourceManager.h" -#include "ShapeShader.h" +#include "Shaders/FlatShader.h" namespace Magnum { namespace Physics { namespace Implementation { -template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)), options(DebugDrawResourceManager::instance()->get(options)) {} +template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)), options(DebugDrawResourceManager::instance()->get(options)) {} template class AbstractDebugRenderer<2>; template class AbstractDebugRenderer<3>; diff --git a/src/Physics/Implementation/AbstractDebugRenderer.h b/src/Physics/Implementation/AbstractDebugRenderer.h index 63400b22b..ed236b60d 100644 --- a/src/Physics/Implementation/AbstractDebugRenderer.h +++ b/src/Physics/Implementation/AbstractDebugRenderer.h @@ -24,18 +24,20 @@ namespace Magnum { class AbstractShaderProgram; class Mesh; +namespace Shaders { + template class FlatShader; +} + namespace Physics { namespace Implementation { struct Options; -template class ShapeShader; - template class AbstractDebugRenderer: public SceneGraph::AbstractObject::ObjectType { public: AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh, ResourceKey options, typename SceneGraph::AbstractObject::ObjectType* parent); protected: - Resource> shader; + Resource> shader; Resource mesh; Resource options; }; diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp index c428335d2..472af6781 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -20,7 +20,7 @@ #include "Physics/DebugDrawResourceManager.h" #include "Primitives/Cube.h" #include "Primitives/Square.h" -#include "ShapeShader.h" +#include "Shaders/FlatShader.h" namespace Magnum { namespace Physics { namespace Implementation { @@ -37,7 +37,7 @@ namespace { buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(square.primitive()) ->setVertexCount(square.positions(0)->size()) - ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); + ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); } }; @@ -51,7 +51,7 @@ namespace { buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); return mesh->setPrimitive(cube.primitive()) ->setVertexCount(cube.positions(0)->size()) - ->addVertexBuffer(buffer, Implementation::ShapeShader<2>::Position()); + ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); } }; } diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 020acb2b7..53b99a0f2 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,8 +1,12 @@ -corrade_add_resource(MagnumShaders_RCS MagnumShaders PhongShader.frag PhongShader.vert) +corrade_add_resource(MagnumShaders_RCS MagnumShaders + FlatShader2D.vert FlatShader2D.frag + PhongShader.frag PhongShader.vert) set(MagnumShaders_SRCS + FlatShader.cpp PhongShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS + FlatShader.h PhongShader.h magnumShadersVisibility.h) diff --git a/src/Physics/Implementation/ShapeShader.cpp b/src/Shaders/FlatShader.cpp similarity index 67% rename from src/Physics/Implementation/ShapeShader.cpp rename to src/Shaders/FlatShader.cpp index c7cf1096f..4d6df9a03 100644 --- a/src/Physics/Implementation/ShapeShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -13,30 +13,30 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ShapeShader.h" +#include "FlatShader.h" #include #include "Shader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace Shaders { namespace { template struct ShaderName {}; template<> struct ShaderName<2> { - constexpr static const char* Vertex = "ShapeShader2D.vert"; - constexpr static const char* Fragment = "ShapeShader2D.frag"; + constexpr static const char* Vertex = "FlatShader2D.vert"; + constexpr static const char* Fragment = "FlatShader2D.frag"; }; template<> struct ShaderName<3> { - constexpr static const char* Vertex = "ShapeShader3D.vert"; - constexpr static const char* Fragment = "ShapeShader3D.frag"; + constexpr static const char* Vertex = "FlatShader3D.vert"; + constexpr static const char* Fragment = "FlatShader3D.frag"; }; } -template ShapeShader::ShapeShader() { - Corrade::Utility::Resource resource("MagnumPhysics"); +template FlatShader::FlatShader() { + Corrade::Utility::Resource resource("MagnumShaders"); attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, resource.get(ShaderName::Vertex))); attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, resource.get(ShaderName::Fragment))); @@ -46,7 +46,7 @@ template ShapeShader::ShapeShader() { colorUniform = uniformLocation("color"); } -template class ShapeShader<2>; -template class ShapeShader<3>; +template class FlatShader<2>; +template class FlatShader<3>; -}}} +}} diff --git a/src/Physics/Implementation/ShapeShader.h b/src/Shaders/FlatShader.h similarity index 55% rename from src/Physics/Implementation/ShapeShader.h rename to src/Shaders/FlatShader.h index b1d1eac98..f2e247a2d 100644 --- a/src/Physics/Implementation/ShapeShader.h +++ b/src/Shaders/FlatShader.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_ShapeShader_h -#define Magnum_Physics_Implementation_ShapeShader_h +#ifndef Magnum_Shaders_FlatShader_h +#define Magnum_Shaders_FlatShader_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -15,26 +15,46 @@ GNU Lesser General Public License version 3 for more details. */ +/** @file + * @brief Class Magnum::Shaders::FlatShader + */ + #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "AbstractShaderProgram.h" #include "Color.h" #include "DimensionTraits.h" -namespace Magnum { namespace Physics { namespace Implementation { +#include "magnumShadersVisibility.h" + +namespace Magnum { namespace Shaders { + +/** +@brief Flat shader -template class ShapeShader: public AbstractShaderProgram { +Draws whole mesh with one color. +*/ +template class SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: + /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::PointType> Position; - ShapeShader(); + FlatShader(); - ShapeShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { + /** + * @brief Set transformation and projection matrix + * @return Pointer to self (for method chaining) + */ + FlatShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionUniform, matrix); return this; } - ShapeShader* setColor(const Color3& color) { + /** + * @brief Set color + * @return Pointer to self (for method chaining) + */ + FlatShader* setColor(const Color3& color) { setUniform(colorUniform, color); return this; } @@ -44,9 +64,6 @@ template class ShapeShader: public AbstractShaderProgra colorUniform; }; -extern template class ShapeShader<2>; -extern template class ShapeShader<3>; - -}}} +}} #endif diff --git a/src/Physics/Implementation/ShapeShader2D.frag b/src/Shaders/FlatShader2D.frag similarity index 100% rename from src/Physics/Implementation/ShapeShader2D.frag rename to src/Shaders/FlatShader2D.frag diff --git a/src/Physics/Implementation/ShapeShader2D.vert b/src/Shaders/FlatShader2D.vert similarity index 100% rename from src/Physics/Implementation/ShapeShader2D.vert rename to src/Shaders/FlatShader2D.vert From 3191b477dfa0085057a6bcdf1b7adc716b2bd594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:04:38 +0100 Subject: [PATCH 228/256] Typedef 2D and 3D alternatives of FlatShader. More intuitive than e.g. FlatShader<2>. --- src/Shaders/FlatShader.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index f2e247a2d..bbdca99e5 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -33,6 +33,7 @@ namespace Magnum { namespace Shaders { @brief Flat shader Draws whole mesh with one color. +@see FlatShader2D, FlatShader3D */ template class SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: @@ -64,6 +65,12 @@ template class SHADERS_EXPORT FlatShader: public Abstra colorUniform; }; +/** @brief 2D flat shader */ +typedef FlatShader<2> FlatShader2D; + +/** @brief 3D flat shader */ +typedef FlatShader<3> FlatShader3D; + }} #endif From 68f0bac60a397caa521f570134d14337a5ba86a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:23:23 +0100 Subject: [PATCH 229/256] Fixed compilation of Contexts::EglContextHandler. --- src/Contexts/EglContextHandler.cpp | 2 ++ src/Contexts/EglContextHandler.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/Contexts/EglContextHandler.cpp b/src/Contexts/EglContextHandler.cpp index c21b1ecf7..fe89eb477 100644 --- a/src/Contexts/EglContextHandler.cpp +++ b/src/Contexts/EglContextHandler.cpp @@ -15,6 +15,8 @@ #include "EglContextHandler.h" +#include + #include "Context.h" namespace Magnum { namespace Contexts { diff --git a/src/Contexts/EglContextHandler.h b/src/Contexts/EglContextHandler.h index 7c9eab9c6..ae5f3daf0 100644 --- a/src/Contexts/EglContextHandler.h +++ b/src/Contexts/EglContextHandler.h @@ -26,6 +26,9 @@ #endif #include +/* undef Xlib nonsense to avoid conflicts */ +#undef None + #include "AbstractContextHandler.h" #include "magnumCompatibility.h" From efa7cbc079a29b0a7b5912900b504ee828da8b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:38:52 +0100 Subject: [PATCH 230/256] Fixed Mesh move constructor and move assignment operator. Forgot to move integer and long attributes. Also using move instead of copy for vectors. --- src/Mesh.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 1fe2c3919..927d2c38e 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -43,7 +43,7 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(other.attributes) { +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(std::move(other.attributes)), integerAttributes(std::move(other.integerAttributes)), longAttributes(std::move(other.longAttributes)) { other.vao = 0; } @@ -53,7 +53,9 @@ Mesh& Mesh::operator=(Mesh&& other) { vao = other.vao; _primitive = other._primitive; _vertexCount = other._vertexCount; - attributes = other.attributes; + attributes = std::move(other.attributes); + integerAttributes = std::move(other.integerAttributes); + longAttributes = std::move(other.longAttributes); other.vao = 0; From 930c9f2a5df54afd7a24d4bd1a3b05112382a01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:25:27 +0100 Subject: [PATCH 231/256] Don't have `default:` in switches where all cases need to be handled. Also added assert for cases which shouldn't be reached. --- src/AbstractImage.cpp | 16 ++++++++++++++-- src/Context.cpp | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index de0e9929c..075ff69b3 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -14,6 +14,9 @@ */ #include "AbstractImage.h" + +#include + #include "TypeTraits.h" using namespace std; @@ -71,6 +74,8 @@ size_t AbstractImage::pixelSize(Components format, ComponentType type) { switch(format) { #ifndef MAGNUM_TARGET_GLES case Components::Red: + case Components::Green: + case Components::Blue: return 1*size; case Components::RedGreen: return 2*size; @@ -85,9 +90,16 @@ size_t AbstractImage::pixelSize(Components format, ComponentType type) { case Components::BGRA: #endif return 4*size; - default: - return 0; + + #ifndef MAGNUM_TARGET_GLES + case Components::Depth: + case Components::StencilIndex: + case Components::DepthStencil: + CORRADE_ASSERT(false, "AbstractImage::pixelSize(): unhandled depth/stencil type", 0); + #endif } + + return 0; } } diff --git a/src/Context.cpp b/src/Context.cpp index 06cfe594f..23d506d0c 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -129,6 +129,7 @@ const std::vector& Extension::extensions(Version version) { switch(version) { case Version::None: return extensions; + case Version::GL210: return empty; case Version::GL300: return extensions300; case Version::GL310: return extensions310; case Version::GL320: return extensions320; @@ -137,8 +138,9 @@ const std::vector& Extension::extensions(Version version) { case Version::GL410: return extensions410; case Version::GL420: return extensions420; case Version::GL430: return extensions430; - default: return empty; } + + return empty; } Context* Context::_current = nullptr; From a755a0a8aab9f1800608e72143a0d7f72100506c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:27:21 +0100 Subject: [PATCH 232/256] Doc++ I had no idea what that code was doing. Better to be documented. --- src/Context.cpp | 6 ++++-- src/TypeTraits.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 23d506d0c..a9afef9f9 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -151,7 +151,7 @@ Context::Context() { glGetIntegerv(GL_MINOR_VERSION, &_minorVersion); _version = static_cast(_majorVersion*100+_minorVersion*10); - /* Future versions */ + /* Get first future (not supported) version */ vector versions{ Version::GL300, Version::GL310, @@ -167,7 +167,9 @@ Context::Context() { while(versions[future] != Version::None && versions[future] < _version) ++future; - /* Extensions */ + /* List of extensions from future versions (extensions from current and + previous versions should be supported automatically, so we don't need + to check for them) */ unordered_map futureExtensions; for(size_t i = future; i != versions.size(); ++i) for(const Extension& extension: Extension::extensions(versions[i])) diff --git a/src/TypeTraits.h b/src/TypeTraits.h index e134e7b9d..23f882df5 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -111,7 +111,7 @@ enum class Type: GLenum { , /** * Double - * @requires_gl + * @requires_gl Only floats are available in OpenGL ES. */ Double = GL_DOUBLE #endif From 1db86e7388f04e4c2f392188b05d337d70e585c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:10:55 +0100 Subject: [PATCH 233/256] Updated Doxygen commands for OpenGL ES, mentioned them in coding style. --- Doxyfile | 5 +++-- doc/coding-style.dox | 17 ++++++++++++++++- doc/required-extensions.dox | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Doxyfile b/Doxyfile index e11bd5171..4ca3d9dc2 100644 --- a/Doxyfile +++ b/Doxyfile @@ -203,7 +203,6 @@ ALIASES = \ "fn_gl{1}=gl\1()" \ "fn_gl_extension{3}=gl\1\2()" \ "def_gl{1}=`GL_\1`" \ - "requires_gl=@xrefitem requires-gl \"Requires desktop OpenGL\" \"Functionality requiring desktop OpenGL (not available on OpenGL ES)\" Not available on OpenGL ES." \ "requires_gl30=@xrefitem requires-gl30 \"Requires OpenGL 3.0\" \"Functionality requiring OpenGL 3.0\"" \ "requires_gl31=@xrefitem requires-gl31 \"Requires OpenGL 3.1\" \"Functionality requiring OpenGL 3.1\"" \ "requires_gl32=@xrefitem requires-gl32 \"Requires OpenGL 3.2\" \"Functionality requiring OpenGL 3.2\"" \ @@ -215,8 +214,10 @@ ALIASES = \ "requires_extension=@xrefitem requires-extension \"Requires OpenGL extension\" \"Functionality requiring specific OpenGL extension\"" \ "extension{2}=\1_\2" \ "requires_gles30=@xrefitem requires-gles30 \"Requires OpenGL ES 3.0\" \"Functionality requiring OpenGL ES 3.0\"" \ + "requires_gl=@xrefitem requires-gl \"Requires desktop OpenGL\" \"Functionality requiring desktop OpenGL (not available in OpenGL ES)\"" \ "requires_es_extension=@xrefitem requires-es-extension \"Requires OpenGL ES extension\" \"Functionality requiring specific OpenGL ES extension\"" \ - "es_extension{2}=\1_\2" + "es_extension{2}=\1_\2" \ + "es_extension2{3}=\1_\2" # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding diff --git a/doc/coding-style.dox b/doc/coding-style.dox index 802f2e6e2..74ea08d2b 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -57,7 +57,14 @@ with @c \@extension command: @extension{ARB,timer_query} @endcode It produces link to the specification of the extension in OpenGL registry, -e.g. @extension{ARB,timer_query}. +e.g. @extension{ARB,timer_query}. Similarly for OpenGL ES extensions there is +@c \@es_extension command. Some extensions have slightly different URL, +with command @c \@es_extension2 you can specify extension filename, if the +previous command gives 404 error. The following produces link to +@es_extension2{NV,read_buffer_front,GL_NV_read_buffer} extension: +@code +@es_extension2{NV,read_buffer_front,GL_NV_read_buffer} +@endcode @subsubsection documentation-commands-ref_gl Links to related OpenGL functions and definitions @@ -102,6 +109,14 @@ function, only the function should be marked. If the extension is needed only for some functionality (not related to any member function), it should be noted in the description. +Similarly for OpenGL ES there is command @c \@requires_gl for functionality +not available in OpenGL ES at all, @c \@requires_gles30 for functionality +requiring OpenGL ES 3.0 (i.e. not part of OpenGL 2.0) and +@c \@requires_es_extension for specific extensions not part of OpenGL ES +specification. When there is both required desktop OpenGL version/extension +and OpenGL ES version/extension, first come desktop requirements, then ES +requirements. + All classes and functions using those commands are cross-referenced in page @ref required-extensions. diff --git a/doc/required-extensions.dox b/doc/required-extensions.dox index 5598d000c..58a47ebfc 100644 --- a/doc/required-extensions.dox +++ b/doc/required-extensions.dox @@ -12,7 +12,6 @@ functionality, so if given hardware supports required extension, it doesn't need to have required OpenGL version too (e.g. `APPLE_vertex_array_object` is supported on Intel GPUs even if they are capable of OpenGL 2.1 only). -- @subpage requires-gl - @subpage requires-gl30 - @subpage requires-gl31 - @subpage requires-gl32 @@ -22,6 +21,7 @@ supported on Intel GPUs even if they are capable of OpenGL 2.1 only). - @subpage requires-gl42 - @subpage requires-gl43 - @subpage requires-extension +- @subpage requires-gl - @subpage requires-gles30 - @subpage requires-es-extension - @subpage unsupported From 29893ebe82b247b9e780ccdae40434e14dd38a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:13:19 +0100 Subject: [PATCH 234/256] Updated OpenGL ES support in shaders. --- src/AbstractShaderProgram.cpp | 59 +++++++++++++- src/AbstractShaderProgram.h | 145 ++++++++++++++++++++++------------ src/Shader.h | 8 +- 3 files changed, 152 insertions(+), 60 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 61e773700..e02831f1a 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -37,10 +37,12 @@ AbstractShaderProgram::Uniform1iImplementation AbstractShaderProgram::uniform1iI AbstractShaderProgram::Uniform2ivImplementation AbstractShaderProgram::uniform2ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform3ivImplementation AbstractShaderProgram::uniform3ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform4ivImplementation AbstractShaderProgram::uniform4ivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#ifndef MAGNUM_TARGET_GLES2 AbstractShaderProgram::Uniform1uiImplementation AbstractShaderProgram::uniform1uiImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform2uivImplementation AbstractShaderProgram::uniform2uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform3uivImplementation AbstractShaderProgram::uniform3uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform4uivImplementation AbstractShaderProgram::uniform4uivImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#endif #ifndef MAGNUM_TARGET_GLES AbstractShaderProgram::Uniform1dImplementation AbstractShaderProgram::uniform1dImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform2dvImplementation AbstractShaderProgram::uniform2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; @@ -51,12 +53,14 @@ AbstractShaderProgram::Uniform4dvImplementation AbstractShaderProgram::uniform4d AbstractShaderProgram::UniformMatrix2fvImplementation AbstractShaderProgram::uniformMatrix2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix3fvImplementation AbstractShaderProgram::uniformMatrix3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix4fvImplementation AbstractShaderProgram::uniformMatrix4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#ifndef MAGNUM_TARGET_GLES2 AbstractShaderProgram::UniformMatrix2x3fvImplementation AbstractShaderProgram::uniformMatrix2x3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix3x2fvImplementation AbstractShaderProgram::uniformMatrix3x2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix2x4fvImplementation AbstractShaderProgram::uniformMatrix2x4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix4x2fvImplementation AbstractShaderProgram::uniformMatrix4x2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix3x4fvImplementation AbstractShaderProgram::uniformMatrix3x4fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix4x3fvImplementation AbstractShaderProgram::uniformMatrix4x3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; +#endif #ifndef MAGNUM_TARGET_GLES AbstractShaderProgram::UniformMatrix2dvImplementation AbstractShaderProgram::uniformMatrix2dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::UniformMatrix3dvImplementation AbstractShaderProgram::uniformMatrix3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; @@ -153,6 +157,8 @@ GLint AbstractShaderProgram::uniformLocation(const std::string& name) { } void AbstractShaderProgram::initializeContextBasedFunctionality(Context* context) { + /** @todo OpenGL ES 2 has extension @es_extension{EXT,separate_shader_objects} for this */ + #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported() || context->isExtensionSupported()) { Debug() << "AbstractShaderProgram: using" << (context->isExtensionSupported() ? @@ -169,12 +175,10 @@ void AbstractShaderProgram::initializeContextBasedFunctionality(Context* context uniform2uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniform3uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniform4uivImplementation = &AbstractShaderProgram::uniformImplementationDSA; - #ifndef MAGNUM_TARGET_GLES uniform1dImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniform2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniform3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniform4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; - #endif uniformMatrix2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; @@ -185,7 +189,6 @@ void AbstractShaderProgram::initializeContextBasedFunctionality(Context* context uniformMatrix4x2fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix3x4fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix4x3fvImplementation = &AbstractShaderProgram::uniformImplementationDSA; - #ifndef MAGNUM_TARGET_GLES uniformMatrix2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; @@ -195,8 +198,10 @@ void AbstractShaderProgram::initializeContextBasedFunctionality(Context* context uniformMatrix4x2dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix3x4dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; uniformMatrix4x3dvImplementation = &AbstractShaderProgram::uniformImplementationDSA; - #endif } + #else + static_cast(context); + #endif } void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLfloat value) { @@ -204,108 +209,134 @@ void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLfloat glUniform1f(location, value); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLfloat value) { glProgramUniform1f(_id, location, value); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLfloat>& value) { use(); glUniform2fv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLfloat>& value) { glProgramUniform2fv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLfloat>& value) { use(); glUniform3fv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLfloat>& value) { glProgramUniform3fv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLfloat>& value) { use(); glUniform4fv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLfloat>& value) { glProgramUniform4fv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLint value) { use(); glUniform1i(location, value); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLint value) { glProgramUniform1i(_id, location, value); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLint>& value) { use(); glUniform2iv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLint>& value) { glProgramUniform2iv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLint>& value) { use(); glUniform3iv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLint>& value) { glProgramUniform3iv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLint>& value) { use(); glUniform4iv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLint>& value) { glProgramUniform4iv(_id, location, 1, value.data()); } +#endif +#ifndef MAGNUM_TARGET_GLES2 void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLuint value) { use(); glUniform1ui(location, value); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, GLuint value) { glProgramUniform1ui(_id, location, value); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<2, GLuint>& value) { use(); glUniform2uiv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<2, GLuint>& value) { glProgramUniform2uiv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<3, GLuint>& value) { use(); glUniform3uiv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<3, GLuint>& value) { glProgramUniform3uiv(_id, location, 1, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Vector<4, GLuint>& value) { use(); glUniform4uiv(location, 1, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Vector<4, GLuint>& value) { glProgramUniform4uiv(_id, location, 1, value.data()); } +#endif +#endif #ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDefault(GLint location, GLdouble value) { @@ -350,81 +381,101 @@ void AbstractShaderProgram::uniformImplementationDefault(GLint location, const M glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<2, GLfloat>& value) { glProgramUniformMatrix2fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<3, GLfloat>& value) { use(); glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<3, GLfloat>& value) { glProgramUniformMatrix3fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<4, GLfloat>& value) { use(); glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::Matrix<4, GLfloat>& value) { glProgramUniformMatrix4fv(_id, location, 1, GL_FALSE, value.data()); } +#endif +#ifndef MAGNUM_TARGET_GLES2 void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { use(); glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { glProgramUniformMatrix2x3fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { use(); glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { glProgramUniformMatrix3x2fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { use(); glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { glProgramUniformMatrix2x4fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { use(); glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { glProgramUniformMatrix4x2fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { use(); glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { glProgramUniformMatrix3x4fv(_id, location, 1, GL_FALSE, value.data()); } +#endif void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { use(); glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); } +#ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { glProgramUniformMatrix4x3fv(_id, location, 1, GL_FALSE, value.data()); } +#endif +#endif #ifndef MAGNUM_TARGET_GLES void AbstractShaderProgram::uniformImplementationDefault(GLint location, const Math::Matrix<2, GLdouble>& value) { diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index e1efd315e..1ed8222bc 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -121,22 +121,11 @@ using color input index): layout(location = 0, index = 0) out vec4 color; layout(location = 1, index = 1) out vec4 ambient; @endcode -@requires_gl (for explicit input attribute location instead of using - bindAttributeLocation()) -@requires_gl (for using bindFragmentDataLocation() / - bindFragmentDataLocationIndexed()) -@requires_gl30 Extension @extension{EXT,gpu_shader4} (for using - bindFragmentDataLocation()) -@requires_gl33 Extension @extension{ARB,blend_func_extended} (for using - bindFragmentDataLocationIndexed()) -@requires_gl33 Extension @extension{ARB,explicit_attrib_location} (for - explicit attribute location instead of using bindAttributeLocation()) -@requires_gles30 (no extension providing this functionality) (for explicit - input and output attribute location) - -If you don't have the required extension, you can use functions bindAttributeLocation() -and bindFragmentDataLocation() / bindFragmentDataLocationIndexed() between -attaching the shaders and linking the program: + +If you don't have the required extension, you can use functions +bindAttributeLocation() and bindFragmentDataLocation() / +bindFragmentDataLocationIndexed() between attaching the shaders and linking +the program: @code // Shaders attached... @@ -150,6 +139,19 @@ bindFragmentDataLocationIndexed(1, 1, "ambient"); // Link... @endcode +@requires_gl30 %Extension @extension{EXT,gpu_shader4} for using + bindFragmentDataLocation(). +@requires_gl33 %Extension @extension{ARB,blend_func_extended} for using + bindFragmentDataLocationIndexed(). +@requires_gl33 %Extension @extension{ARB,explicit_attrib_location} for + explicit attribute location instead of using bindAttributeLocation(), + bindFragmentDataLocation() or bindFragmentDataLocationIndexed(). +@requires_gles30 Explicit location specification of input attributes is not + supported in OpenGL ES 2.0, use bindAttributeLocation() instead. +@requires_gles30 Multiple fragment shader outputs are not available in OpenGL + ES 2.0, similar functionality is available in extension + @extension{NV,draw_buffers}. + @subsection AbstractShaderProgram-uniform-location Uniform locations The preferred workflow is to specify uniform locations directly in the shader @@ -160,9 +162,6 @@ code, e.g.: layout(location = 0) uniform mat4 transformation; layout(location = 1) uniform mat4 projection; @endcode -@requires_gl (for explicit uniform location instead of using uniformLocation()) -@requires_gl43 Extension @extension{ARB,explicit_uniform_location} (for - explicit uniform location instead of using uniformLocation()) If you don't have the required extension, you can get uniform location using uniformLocation() after linking stage: @@ -171,6 +170,11 @@ GLint transformationUniform = uniformLocation("transformation"); GLint projectionUniform = uniformLocation("projection"); @endcode +@requires_gl43 Extension @extension{ARB,explicit_uniform_location} for + explicit uniform location instead of using uniformLocation(). +@requires_gl Explicit uniform location is not supported in OpenGL ES. Use + uniformLocation() instead. + @subsection AbstractShaderProgram-texture-layer Binding texture layer uniforms The preferred workflow is to specify texture layers directly in the shader @@ -181,10 +185,6 @@ code, e.g.: layout(binding = 0) uniform sampler2D diffuseTexture; layout(binding = 1) uniform sampler2D specularTexture; @endcode -@requires_gl (for explicit texture layer binding instead of using - setUniform(GLint, GLint)) -@requires_gl42 Extension @extension{ARB,shading_language_420pack} (for explicit - texture layer binding instead of using setUniform(GLint, GLint)) If you don't have the required extension (or if you want to change the layer later), you can set the texture layer uniform using setUniform(GLint, GLint): @@ -193,6 +193,11 @@ setUniform(DiffuseTextureUniform, DiffuseTextureLayer); setUniform(SpecularTextureUniform, SpecularTextureLayer); @endcode +@requires_gl42 Extension @extension{ARB,shading_language_420pack} for explicit + texture layer binding instead of using setUniform(GLint, GLint). +@requires_gl Explicit texture layer binding is not supported in OpenGL ES. Use + setUniform(GLint, GLint) instead. + @section AbstractShaderProgram-rendering-workflow Rendering workflow Basic workflow with %AbstractShaderProgram subclasses is to instance the class @@ -235,8 +240,10 @@ mesh.draw(); @ref Math::Vector "Math::Vector<2, GLuint>", @ref Math::Vector "Math::Vector<3, GLuint>" and @ref Math::Vector "Math::Vector<4, GLuint>". - @requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes) - @requires_gles30 Integer attributes are not supported in OpenGL ES 2.0. + @requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes + and unsigned integer uniforms) + @requires_gles30 Integer attributes and unsigned integer uniforms are not + available in OpenGL ES 2.0. - `dvec2`, `dvec3` and `dvec4` is @ref Math::Vector "Math::Vector<2, GLdouble>", @ref Math::Vector "Math::Vector<3, GLdouble>" and @@ -251,8 +258,9 @@ mesh.draw(); @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 2, GLdouble>", @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 4, GLdouble>" and @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 3, GLdouble>". - @requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double attributes) - @requires_gl Double attributes are supported only on desktop OpenGL. + @requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double + attributes) + @requires_gl Double attributes are not available in OpenGL ES. Only types listed here (and their subclasses and specializations, such as @ref Matrix3 or Color4) can be used for setting uniforms and specifying @@ -388,8 +396,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { * BGRA component ordering. Default is RGBA. Only for * four-component float vector attribute type. * @requires_gl32 %Extension @extension{ARB,vertex_array_bgra} - * @requires_gl Only RGBA component ordering is available - * on OpenGL ES. + * @requires_gl Only RGBA component ordering is supported + * in OpenGL ES. */ BGRA = 1 << 1 }; @@ -462,15 +470,13 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @note This function should be called after attachShader() calls and * before link(). * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_BINARY_RETRIEVABLE_HINT} - * @requires_gl * @requires_gl41 Extension @extension{ARB,get_program_binary} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Always allowed in OpenGL ES 2.0. */ inline void setRetrievableBinary(bool enabled) { glProgramParameteri(_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, enabled ? GL_TRUE : GL_FALSE); } - #ifndef MAGNUM_TARGET_GLES /** * @brief Allow the program to be bound to individual pipeline stages * @@ -478,13 +484,17 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @note This function should be called after attachShader() calls and * before link(). * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_SEPARABLE} - * @requires_gl * @requires_gl41 Extension @extension{ARB,separate_shader_objects} + * @requires_es_extension %Extension @es_extension{EXT,separate_shader_objects} */ inline void setSeparable(bool enabled) { + /** @todo Remove when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES glProgramParameteri(_id, GL_PROGRAM_SEPARABLE, enabled ? GL_TRUE : GL_FALSE); + #else + static_cast(enabled); + #endif } - #endif /** * @brief Load shader @@ -536,8 +546,9 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @ref AbstractShaderProgram-attribute-location "class documentation" * for more information. * @see @fn_gl{BindFragDataLocationIndexed} - * @requires_gl * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blend function inputs are not available in + * OpenGL ES. */ void bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name); @@ -549,8 +560,9 @@ class MAGNUM_EXPORT AbstractShaderProgram { * The same as bindFragmentDataLocationIndexed(), but with `index` set * to `0`. * @see @fn_gl{BindFragDataLocation} - * @requires_gl * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl Use explicit location specification in OpenGL ES 3.0 + * instead. */ void bindFragmentDataLocation(GLuint location, const std::string& name); #endif @@ -628,10 +640,11 @@ class MAGNUM_EXPORT AbstractShaderProgram { (this->*uniform4ivImplementation)(location, value); } + #ifndef MAGNUM_TARGET_GLES2 /** * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, GLuint value) { (this->*uniform1uiImplementation)(location, value); @@ -640,7 +653,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<2, GLuint>& value) { (this->*uniform2uivImplementation)(location, value); @@ -649,7 +662,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<3, GLuint>& value) { (this->*uniform3uivImplementation)(location, value); @@ -658,11 +671,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) * @requires_gl30 Extension @extension{EXT,gpu_shader4} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<4, GLuint>& value) { (this->*uniform4uivImplementation)(location, value); } + #endif #ifndef MAGNUM_TARGET_GLES /** @@ -717,9 +731,10 @@ class MAGNUM_EXPORT AbstractShaderProgram { (this->*uniformMatrix4fvImplementation)(location, value); } + #ifndef MAGNUM_TARGET_GLES2 /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { (this->*uniformMatrix2x3fvImplementation)(location, value); @@ -727,7 +742,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { (this->*uniformMatrix3x2fvImplementation)(location, value); @@ -735,7 +750,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { (this->*uniformMatrix2x4fvImplementation)(location, value); @@ -743,7 +758,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { (this->*uniformMatrix4x2fvImplementation)(location, value); @@ -751,7 +766,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { (this->*uniformMatrix3x4fvImplementation)(location, value); @@ -759,11 +774,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { (this->*uniformMatrix4x3fvImplementation)(location, value); } + #endif #ifndef MAGNUM_TARGET_GLES /** @@ -865,10 +881,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { typedef void(AbstractShaderProgram::*Uniform2ivImplementation)(GLint, const Math::Vector<2, GLint>&); typedef void(AbstractShaderProgram::*Uniform3ivImplementation)(GLint, const Math::Vector<3, GLint>&); typedef void(AbstractShaderProgram::*Uniform4ivImplementation)(GLint, const Math::Vector<4, GLint>&); + #ifndef MAGNUM_TARGET_GLES2 typedef void(AbstractShaderProgram::*Uniform1uiImplementation)(GLint, GLuint); typedef void(AbstractShaderProgram::*Uniform2uivImplementation)(GLint, const Math::Vector<2, GLuint>&); typedef void(AbstractShaderProgram::*Uniform3uivImplementation)(GLint, const Math::Vector<3, GLuint>&); typedef void(AbstractShaderProgram::*Uniform4uivImplementation)(GLint, const Math::Vector<4, GLuint>&); + #endif #ifndef MAGNUM_TARGET_GLES typedef void(AbstractShaderProgram::*Uniform1dImplementation)(GLint, GLdouble); typedef void(AbstractShaderProgram::*Uniform2dvImplementation)(GLint, const Math::Vector<2, GLdouble>&); @@ -883,16 +901,17 @@ class MAGNUM_EXPORT AbstractShaderProgram { void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLint>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLint>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLint>& value); + #ifndef MAGNUM_TARGET_GLES2 void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLuint value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLuint>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLuint>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLuint>& value); + #endif #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL uniformImplementationDefault(GLint location, GLdouble value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<2, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<3, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Vector<4, GLdouble>& value); - #endif void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLfloat value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLfloat>& value); @@ -905,7 +924,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLuint>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLuint>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<4, GLuint>& value); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL uniformImplementationDSA(GLint location, GLdouble value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<2, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Vector<3, GLdouble>& value); @@ -919,10 +937,12 @@ class MAGNUM_EXPORT AbstractShaderProgram { static Uniform2ivImplementation uniform2ivImplementation; static Uniform3ivImplementation uniform3ivImplementation; static Uniform4ivImplementation uniform4ivImplementation; + #ifndef MAGNUM_TARGET_GLES2 static Uniform1uiImplementation uniform1uiImplementation; static Uniform2uivImplementation uniform2uivImplementation; static Uniform3uivImplementation uniform3uivImplementation; static Uniform4uivImplementation uniform4uivImplementation; + #endif #ifndef MAGNUM_TARGET_GLES static Uniform1dImplementation uniform1dImplementation; static Uniform2dvImplementation uniform2dvImplementation; @@ -933,12 +953,14 @@ class MAGNUM_EXPORT AbstractShaderProgram { typedef void(AbstractShaderProgram::*UniformMatrix2fvImplementation)(GLint, const Math::Matrix<2, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix3fvImplementation)(GLint, const Math::Matrix<3, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix4fvImplementation)(GLint, const Math::Matrix<4, GLfloat>&); + #ifndef MAGNUM_TARGET_GLES2 typedef void(AbstractShaderProgram::*UniformMatrix2x3fvImplementation)(GLint, const Math::RectangularMatrix<2, 3, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix3x2fvImplementation)(GLint, const Math::RectangularMatrix<3, 2, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix2x4fvImplementation)(GLint, const Math::RectangularMatrix<2, 4, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix4x2fvImplementation)(GLint, const Math::RectangularMatrix<4, 2, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix3x4fvImplementation)(GLint, const Math::RectangularMatrix<3, 4, GLfloat>&); typedef void(AbstractShaderProgram::*UniformMatrix4x3fvImplementation)(GLint, const Math::RectangularMatrix<4, 3, GLfloat>&); + #endif #ifndef MAGNUM_TARGET_GLES typedef void(AbstractShaderProgram::*UniformMatrix2dvImplementation)(GLint, const Math::Matrix<2, GLdouble>&); typedef void(AbstractShaderProgram::*UniformMatrix3dvImplementation)(GLint, const Math::Matrix<3, GLdouble>&); @@ -953,12 +975,14 @@ class MAGNUM_EXPORT AbstractShaderProgram { void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<3, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<4, GLfloat>& value); + #ifndef MAGNUM_TARGET_GLES2 void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value); + #endif #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<2, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::Matrix<3, GLdouble>& value); @@ -969,7 +993,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDefault(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value); - #endif void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<3, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<4, GLfloat>& value); @@ -979,7 +1002,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<2, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<3, GLdouble>& value); void MAGNUM_LOCAL uniformImplementationDSA(GLint location, const Math::Matrix<4, GLdouble>& value); @@ -993,12 +1015,14 @@ class MAGNUM_EXPORT AbstractShaderProgram { static UniformMatrix2fvImplementation uniformMatrix2fvImplementation; static UniformMatrix3fvImplementation uniformMatrix3fvImplementation; static UniformMatrix4fvImplementation uniformMatrix4fvImplementation; + #ifndef MAGNUM_TARGET_GLES2 static UniformMatrix2x3fvImplementation uniformMatrix2x3fvImplementation; static UniformMatrix3x2fvImplementation uniformMatrix3x2fvImplementation; static UniformMatrix2x4fvImplementation uniformMatrix2x4fvImplementation; static UniformMatrix4x2fvImplementation uniformMatrix4x2fvImplementation; static UniformMatrix3x4fvImplementation uniformMatrix3x4fvImplementation; static UniformMatrix4x3fvImplementation uniformMatrix4x3fvImplementation; + #endif #ifndef MAGNUM_TARGET_GLES static UniformMatrix2dvImplementation uniformMatrix2dvImplementation; static UniformMatrix3dvImplementation uniformMatrix3dvImplementation; @@ -1029,8 +1053,12 @@ template<> struct Attribute { UnsignedInt = GL_UNSIGNED_INT, Int = GL_INT, HalfFloat = GL_HALF_FLOAT, - Float = GL_FLOAT, + Float = GL_FLOAT + + #ifndef MAGNUM_TARGET_GLES + , Double = GL_DOUBLE + #endif }; enum class DataOption: std::uint8_t { @@ -1072,23 +1100,34 @@ template<> struct Attribute> { Int = GL_INT, Half = GL_HALF_FLOAT, Float = GL_FLOAT, + #ifndef MAGNUM_TARGET_GLES Double = GL_DOUBLE, + #endif UnsignedAlpha2RGB10 = GL_UNSIGNED_INT_2_10_10_10_REV, Alpha2RGB10 = GL_INT_2_10_10_10_REV }; enum class DataOption: std::uint8_t { - Normalized = 1 << 0, + Normalized = 1 << 0 + + #ifndef MAGNUM_TARGET_GLES + , BGRA = 2 << 0 + #endif }; typedef Corrade::Containers::EnumSet DataOptions; static const DataType DefaultDataType = DataType::Float; + #ifndef MAGNUM_TARGET_GLES inline constexpr static GLint size(DataOptions options) { return options & DataOption::BGRA ? GL_BGRA : 4; } + #else + inline constexpr static GLint size(DataOptions) { return 4; } + #endif + inline constexpr static std::size_t vectorCount() { return 1; } }; @@ -1133,6 +1172,7 @@ template struct Attribute>: public Attri inline constexpr static GLint size() { return size; } }; +#ifndef MAGNUM_TARGET_GLES template<> struct Attribute { enum class DataType: GLenum { Double = GL_DOUBLE @@ -1162,6 +1202,7 @@ template struct Attribute>: public Att inline constexpr static GLint size() { return size; } inline constexpr static std::size_t vectorCount() { return size; } }; +#endif template struct Attribute>: public Attribute> {}; template struct Attribute>: public Attribute> {}; diff --git a/src/Shader.h b/src/Shader.h index 7da337718..643674b77 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -48,29 +48,29 @@ class MAGNUM_EXPORT Shader { #ifndef MAGNUM_TARGET_GLES /** * Tessellation control shader - * @requires_gl * @requires_gl40 Extension @extension{ARB,tessellation_shader} + * @requires_gl Tessellation shaders are not available in OpenGL ES. */ TessellationControl = GL_TESS_CONTROL_SHADER, /** * Tessellation evaluation shader - * @requires_gl * @requires_gl40 Extension @extension{ARB,tessellation_shader} + * @requires_gl Tessellation shaders are not available in OpenGL ES. */ TessellationEvaluation = GL_TESS_EVALUATION_SHADER, /** * Geometry shader - * @requires_gl * @requires_gl32 Extension @extension{ARB,geometry_shader4} + * @requires_gl Geometry shaders are not available in OpenGL ES. */ Geometry = GL_GEOMETRY_SHADER, /** * Compute shader - * @requires_gl * @requires_gl43 Extension @extension{ARB,compute_shader} + * @requires_gl Compute shaders are not available in OpenGL ES. */ Compute = GL_COMPUTE_SHADER, #endif From bb2fe188dbecceaa91281cfb0bf2db1fa397a925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:22:43 +0100 Subject: [PATCH 235/256] Updated OpenGL ES support in Buffer and related classes. --- src/Buffer.cpp | 14 ++++++++++ src/Buffer.h | 60 ++++++++++++++++++++++++++++------------- src/BufferedImage.h | 2 +- src/BufferedTexture.cpp | 4 +-- src/BufferedTexture.h | 8 +++--- 5 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 45647eeed..777d0b06b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -24,11 +24,14 @@ namespace Magnum { +#ifndef MAGNUM_TARGET_GLES2 Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault; +#endif Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; void Buffer::initializeContextBasedFunctionality(Context* context) { + #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported()) { Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; @@ -36,6 +39,9 @@ void Buffer::initializeContextBasedFunctionality(Context* context) { setDataImplementation = &Buffer::setDataImplementationDSA; setSubDataImplementation = &Buffer::setSubDataImplementationDSA; } + #else + static_cast(context); + #endif } Buffer::~Buffer() { @@ -76,28 +82,36 @@ Buffer::Target Buffer::bindInternal(Target hint) { return hint; } +#ifndef MAGNUM_TARGET_GLES2 void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { glCopyBufferSubData(static_cast(read->bindInternal(Target::CopyRead)), static_cast(write->bindInternal(Target::CopyWrite)), readOffset, writeOffset, size); } +#ifndef MAGNUM_TARGET_GLES void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size); } +#endif +#endif void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { glBufferData(static_cast(bindInternal(_targetHint)), size, data, static_cast(usage)); } +#ifndef MAGNUM_TARGET_GLES void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { glNamedBufferDataEXT(_id, size, data, static_cast(usage)); } +#endif void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { glBufferSubData(static_cast(bindInternal(_targetHint)), offset, size, data); } +#ifndef MAGNUM_TARGET_GLES void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { glNamedBufferSubDataEXT(_id, offset, size, data); } +#endif } diff --git a/src/Buffer.h b/src/Buffer.h index 6df02acad..5efa508a2 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -100,7 +100,7 @@ class MAGNUM_EXPORT Buffer { /** * Used for storing atomic counters. * @requires_gl42 Extension @extension{ARB,shader_atomic_counters} - * @requires_gl + * @requires_gl Atomic counters are not available in OpenGL ES. */ AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, #endif @@ -108,14 +108,16 @@ class MAGNUM_EXPORT Buffer { /** * Source for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Buffer copying is not available in OpenGL ES + * 2.0. */ CopyRead = GL_COPY_READ_BUFFER, /** * Target for copies. See copy(). * @requires_gl31 Extension @extension{ARB,copy_buffer} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Buffer copying is not available in OpenGL ES + * 2.0. */ CopyWrite = GL_COPY_WRITE_BUFFER, @@ -123,14 +125,14 @@ class MAGNUM_EXPORT Buffer { /** * Indirect compute dispatch commands. * @requires_gl43 Extension @extension{ARB,compute_shader} - * @requires_gl + * @requires_gl Compute shaders are not available in OpenGL ES. */ DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, /** - * Used for supplying arguments for instanced drawing. - * @requires_gl + * Used for supplying arguments for indirect drawing. * @requires_gl40 Extension @extension{ARB,draw_indirect} + * @requires_gl Indirect drawing not available in OpenGL ES. */ DrawIndirect = GL_DRAW_INDIRECT_BUFFER, #endif @@ -140,13 +142,15 @@ class MAGNUM_EXPORT Buffer { /** * Target for pixel pack operations. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Pixel buffer objects are not available in + * OpenGL ES 2.0. */ PixelPack = GL_PIXEL_PACK_BUFFER, /** * Source for texture update operations. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Pixel buffer objects are not available in + * OpenGL ES 2.0. */ PixelUnpack = GL_PIXEL_UNPACK_BUFFER, @@ -154,14 +158,14 @@ class MAGNUM_EXPORT Buffer { /** * Used for shader storage. * @requires_gl43 Extension @extension{ARB,shader_storage_buffer_object} - * @requires_gl + * @requires_gl Shader storage is not available in OpenGL ES. */ ShaderStorage = GL_SHADER_STORAGE_BUFFER, /** * Source for texel fetches. See BufferedTexture. - * @requires_gl * @requires_gl31 Extension @extension{ARB,texture_buffer_object} + * @requires_gl Texture buffers are not available in OpenGL ES. */ Texture = GL_TEXTURE_BUFFER, #endif @@ -169,14 +173,16 @@ class MAGNUM_EXPORT Buffer { /** * Target for transform feedback. * @requires_gl30 Extension @extension{EXT,transform_feedback} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Transform feedback is not available in OpenGL + * ES 2.0. */ TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, /** * Used for storing uniforms. * @requires_gl31 Extension @extension{ARB,uniform_buffer_object} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Uniform buffers are not available in OpenGL ES + * 2.0. */ Uniform = GL_UNIFORM_BUFFER }; @@ -195,14 +201,16 @@ class MAGNUM_EXPORT Buffer { /** * Set once as output from an OpenGL command and used infequently * for drawing. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StreamDraw" + * is available in OpenGL ES 2.0. */ StreamRead = GL_STREAM_READ, /** * Set once as output from an OpenGL command and used infrequently * for drawing or copying to other buffers. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StreamDraw" + * is available in OpenGL ES 2.0. */ StreamCopy = GL_STREAM_COPY, @@ -214,14 +222,16 @@ class MAGNUM_EXPORT Buffer { /** * Set once as output from an OpenGL command and queried many * times by the application. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StaticDraw" + * is available in OpenGL ES 2.0. */ StaticRead = GL_STATIC_READ, /** * Set once as output from an OpenGL command and used frequently * for drawing or copying to other buffers. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::StaticDraw" + * is available in OpenGL ES 2.0. */ StaticCopy = GL_STATIC_COPY, @@ -234,14 +244,16 @@ class MAGNUM_EXPORT Buffer { /** * Updated frequently as output from OpenGL command and queried * many times from the application. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicDraw" + * is available in OpenGL ES 2.0. */ DynamicRead = GL_DYNAMIC_READ, /** * Updated frequently as output from OpenGL command and used * frequently for drawing or copying to other images. - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicCopy" + * is available in OpenGL ES 2.0. */ DynamicCopy = GL_DYNAMIC_COPY }; @@ -254,6 +266,7 @@ class MAGNUM_EXPORT Buffer { */ inline static void unbind(Target target) { bind(target, 0); } + #ifndef MAGNUM_TARGET_GLES2 /** * @brief Copy one buffer to another * @param read %Buffer from which to read @@ -267,13 +280,14 @@ class MAGNUM_EXPORT Buffer { * `Target::CopyRead` and `Target::CopyWrite` before the copy is * performed. * @requires_gl31 Extension @extension{ARB,copy_buffer} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Buffer copying is not available in OpenGL ES 2.0. * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or * @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} */ inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { copyImplementation(read, write, readOffset, writeOffset, size); } + #endif /** * @brief Constructor @@ -419,19 +433,27 @@ class MAGNUM_EXPORT Buffer { static void bind(Target hint, GLuint id); Target MAGNUM_LOCAL bindInternal(Target hint); + #ifndef MAGNUM_TARGET_GLES2 typedef void(*CopyImplementation)(Buffer*, Buffer*, GLintptr, GLintptr, GLsizeiptr); static void MAGNUM_LOCAL copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + #ifndef MAGNUM_TARGET_GLES static void MAGNUM_LOCAL copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); + #endif static CopyImplementation copyImplementation; + #endif typedef void(Buffer::*SetDataImplementation)(GLsizeiptr, const GLvoid*, Usage); void MAGNUM_LOCAL setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Usage usage); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Usage usage); + #endif static SetDataImplementation setDataImplementation; typedef void(Buffer::*SetSubDataImplementation)(GLintptr, GLsizeiptr, const GLvoid*); void MAGNUM_LOCAL setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data); + #endif static SetSubDataImplementation setSubDataImplementation; GLuint _id; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index b3c60244a..0831f653b 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -34,7 +34,7 @@ Class for storing image data in GPU memory. Can be replaced with Image, which stores image data in client memory, ImageWrapper, or for example with Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer -@requires_gles30 (no extension providing this functionality) +@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ template class MAGNUM_EXPORT BufferedImage: public AbstractImage { public: diff --git a/src/BufferedTexture.cpp b/src/BufferedTexture.cpp index aefb40905..862f1f97a 100644 --- a/src/BufferedTexture.cpp +++ b/src/BufferedTexture.cpp @@ -15,6 +15,7 @@ #include "BufferedTexture.h" +#ifndef MAGNUM_TARGET_GLES #include "Buffer.h" #include "Context.h" #include "Extensions.h" @@ -40,7 +41,6 @@ void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id()); } -#ifndef MAGNUM_TARGET_GLES BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) { #define internalFormatSwitch(c) switch(type) { \ case ComponentType::UnsignedByte: \ @@ -72,6 +72,6 @@ BufferedTexture::InternalFormat::InternalFormat(Components components, Component internalFormatSwitch(RGBA) #undef internalFormatSwitch } -#endif } +#endif diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index ae483585e..170f606b9 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -15,18 +15,20 @@ GNU Lesser General Public License version 3 for more details. */ +#ifndef MAGNUM_TARGET_GLES /** @file * @brief Class Magnum::BufferedTexture */ +#endif #include "AbstractTexture.h" +#ifndef MAGNUM_TARGET_GLES namespace Magnum { class Buffer; class Context; -#ifndef MAGNUM_TARGET_GLES /** @brief Buffered texture @@ -46,8 +48,8 @@ uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and "relevant section in AbstractTexture documentation" and respective function documentation for more information. -@requires_gl @requires_gl31 Extension @extension{ARB,texture_buffer_object} +@requires_gl Texture buffers are not available in OpenGL ES. */ class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { friend class Context; @@ -169,8 +171,8 @@ inline BufferedTexture::InternalFormat operator|(BufferedTexture::Components com inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) { return BufferedTexture::InternalFormat(components, type); } -#endif } +#endif #endif From e2023ab2785f165d9f0794cf5ec05df734d61e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:32:52 +0100 Subject: [PATCH 236/256] Updated OpenGL ES support in Context and related files. --- src/Context.cpp | 28 +++++++++++++++++++++++++++- src/Context.h | 29 ++++++++++++++++++++++++++--- src/Extensions.h | 2 ++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index a9afef9f9..eab210cba 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -36,6 +36,7 @@ const std::vector& Extension::extensions(Version version) { #define _extension(prefix, vendor, extension) \ {Extensions::prefix::vendor::extension::Index, Extensions::prefix::vendor::extension::requiredVersion(), Extensions::prefix::vendor::extension::coreVersion(), Extensions::prefix::vendor::extension::string()} static const std::vector empty; + #ifndef MAGNUM_TARGET_GLES static const std::vector extensions{ _extension(GL,EXT,texture_filter_anisotropic)}; static const std::vector extensions300{ @@ -126,18 +127,30 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,texture_storage)}; static const std::vector extensions430; #undef _extension + #else + static const std::vector extensions; + static const std::vector extensionsES200; + static const std::vector extensionsES300; + #endif switch(version) { case Version::None: return extensions; + #ifndef MAGNUM_TARGET_GLES case Version::GL210: return empty; case Version::GL300: return extensions300; case Version::GL310: return extensions310; case Version::GL320: return extensions320; case Version::GL330: return extensions330; case Version::GL400: return extensions400; + /* case Version::GLES200: */ case Version::GL410: return extensions410; case Version::GL420: return extensions420; + /* case Version::GLES300: */ case Version::GL430: return extensions430; + #else + case Version::GLES200: return extensionsES200; + case Version::GLES300: return extensionsES300; + #endif } return empty; @@ -153,6 +166,7 @@ Context::Context() { /* Get first future (not supported) version */ vector versions{ + #ifndef MAGNUM_TARGET_GLES Version::GL300, Version::GL310, Version::GL320, @@ -161,6 +175,10 @@ Context::Context() { Version::GL410, Version::GL420, Version::GL430, + #else + Version::GLES200, + Version::GLES300, + #endif Version::None }; size_t future = 0; @@ -176,7 +194,12 @@ Context::Context() { futureExtensions.insert(make_pair(extension._string, extension)); /* Check for presence of extensions in future versions */ + #ifndef MAGNUM_TARGET_GLES if(isVersionSupported(Version::GL300)) { + #else + if(isVersionSupported(Version::GLES300)) { + #endif + #ifndef MAGNUM_TARGET_GLES2 GLuint index = 0; const char* extension; while((extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, index++)))) { @@ -186,8 +209,9 @@ Context::Context() { extensionStatus.set(found->second._index); } } + #endif - /* OpenGL 2.1 doesn't have glGetStringi() */ + /* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ } else { vector extensions = Corrade::Utility::split(reinterpret_cast(glGetString(GL_EXTENSIONS)), ' '); for(const string& extension: extensions) { @@ -210,7 +234,9 @@ Context::Context() { AbstractShaderProgram::initializeContextBasedFunctionality(this); AbstractTexture::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); + #ifndef MAGNUM_TARGET_GLES BufferedTexture::initializeContextBasedFunctionality(this); + #endif IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); } diff --git a/src/Context.h b/src/Context.h index 3ac3de27e..3443cf0dc 100644 --- a/src/Context.h +++ b/src/Context.h @@ -46,10 +46,33 @@ enum class Version: GLint { GL400 = 400, /**< @brief OpenGL 4.0, GLSL 4.00 */ GL410 = 410, /**< @brief OpenGL 4.1, GLSL 4.10 */ GL420 = 420, /**< @brief OpenGL 4.2, GLSL 4.20 */ - GL430 = 430 /**< @brief OpenGL 4.3, GLSL 4.30 */ + GL430 = 430, /**< @brief OpenGL 4.3, GLSL 4.30 */ + #endif + + /** + * @brief OpenGL ES 2.0, GLSL ES 1.00 + * + * All the functionality is present in OpenGL 4.2 (extension + * @extension{ARB,ES2_compatibility}), so on desktop OpenGL this is + * equivalent to @ref Version "Version::GL410". + */ + #ifndef MAGNUM_TARGET_GLES + GLES200 = 410, + #else + GLES200 = 200, + #endif + + /** + * @brief OpenGL ES 3.0, GLSL ES 3.00 + * + * All the functionality is present in OpenGL 4.3 (extension + * @extension{ARB,ES3_compatibility}), so on desktop OpenGL this is the + * equivalent to @ref Version "Version::GL430". + */ + #ifndef MAGNUM_TARGET_GLES + GLES300 = 430, #else - GLES200 = 200, /**< @brief OpenGL ES 2.0, GLSL ES 1.00 */ - GLES300 = 300 /**< @brief OpenGL ES 3.0, GLSL ES 3.00 */ + GLES300 = 300 #endif }; diff --git a/src/Extensions.h b/src/Extensions.h index e656bc447..8f7438cf2 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -35,6 +35,7 @@ example usage. */ namespace Extensions { +#ifndef MAGNUM_TARGET_GLES #ifndef DOXYGEN_GENERATING_OUTPUT #define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ struct extension { \ @@ -139,6 +140,7 @@ namespace GL { } #undef _extension #endif +#endif } From 50a0e5558e5d5f9050dc5e194cbae10a401ab871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 12:47:50 +0100 Subject: [PATCH 237/256] Updated OpenGL ES support in Mesh and IndexedMesh. VAOs could be supported with extensions, thus not disabling them for ES2. --- src/IndexedMesh.cpp | 11 ++++---- src/IndexedMesh.h | 4 --- src/Mesh.cpp | 67 ++++++++++++++++++++++++++++++++++----------- src/Mesh.h | 32 ++++++++++++++-------- 4 files changed, 76 insertions(+), 38 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 9a8d0daa0..e91453f74 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -49,31 +49,30 @@ void IndexedMesh::bind() { } void IndexedMesh::initializeContextBasedFunctionality(Context* context) { + /** @todo VAOs are in ES 3.0 and as extension in ES 2.0, enable them when some extension wrangler is available */ + #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported()) { - #ifndef MAGNUM_TARGET_GLES Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationVAO; bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; - #endif } + #else + static_cast(context); + #endif } void IndexedMesh::bindIndexBufferImplementationDefault() {} -#ifndef MAGNUM_TARGET_GLES void IndexedMesh::bindIndexBufferImplementationVAO() { bindVAO(vao); _indexBuffer->bind(Buffer::Target::ElementArray); } -#endif void IndexedMesh::bindIndexedImplementationDefault() { _indexBuffer->bind(Buffer::Target::ElementArray); } -#ifndef MAGNUM_TARGET_GLES void IndexedMesh::bindIndexedImplementationVAO() {} -#endif } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 1ee7d5d9e..1a0b25e9f 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -122,16 +122,12 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { typedef void(IndexedMesh::*BindIndexBufferImplementation)(); void MAGNUM_LOCAL bindIndexBufferImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL bindIndexBufferImplementationVAO(); - #endif static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation; typedef void(IndexedMesh::*BindIndexedImplementation)(); void MAGNUM_LOCAL bindIndexedImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL bindIndexedImplementationVAO(); - #endif static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; Buffer* _indexBuffer; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 927d2c38e..f868c38be 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -30,8 +30,12 @@ namespace Magnum { Mesh::CreateImplementation Mesh::createImplementation = &Mesh::createImplementationDefault; Mesh::DestroyImplementation Mesh::destroyImplementation = &Mesh::destroyImplementationDefault; Mesh::AttributePointerImplementation Mesh::attributePointerImplementation = &Mesh::attributePointerImplementationDefault; +#ifndef MAGNUM_TARGET_GLES2 Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &Mesh::attributePointerImplementationDefault; +#ifndef MAGNUM_TARGET_GLES Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault; +#endif +#endif Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; @@ -43,7 +47,14 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(std::move(other.attributes)), integerAttributes(std::move(other.integerAttributes)), longAttributes(std::move(other.longAttributes)) { +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(std::move(other.attributes)) + #ifndef MAGNUM_TARGET_GLES2 + , integerAttributes(std::move(other.integerAttributes)) + #ifndef MAGNUM_TARGET_GLES + , longAttributes(std::move(other.longAttributes)) + #endif + #endif +{ other.vao = 0; } @@ -54,8 +65,12 @@ Mesh& Mesh::operator=(Mesh&& other) { _primitive = other._primitive; _vertexCount = other._vertexCount; attributes = std::move(other.attributes); + #ifndef MAGNUM_TARGET_GLES2 integerAttributes = std::move(other.integerAttributes); + #ifndef MAGNUM_TARGET_GLES longAttributes = std::move(other.longAttributes); + #endif + #endif other.vao = 0; @@ -65,10 +80,12 @@ Mesh& Mesh::operator=(Mesh&& other) { Mesh* Mesh::setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; attributes.clear(); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 integerAttributes.clear(); + #ifndef MAGNUM_TARGET_GLES longAttributes.clear(); #endif + #endif return this; } @@ -82,8 +99,13 @@ void Mesh::draw() { } void Mesh::bindVAO(GLuint vao) { + /** @todo Get some extension wrangler instead to avoid linker errors to glBindVertexArray() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 GLuint& current = Context::current()->state()->mesh->currentVAO; if(current != vao) glBindVertexArray(current = vao); + #else + static_cast(vao); + #endif } void Mesh::bind() { @@ -98,23 +120,26 @@ void Mesh::vertexAttribPointer(const Attribute& attribute) { glVertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, reinterpret_cast(attribute.offset)); } -#ifndef MAGNUM_TARGET_GLES +#ifndef MAGNUM_TARGET_GLES2 void Mesh::vertexAttribPointer(const IntegerAttribute& attribute) { glEnableVertexAttribArray(attribute.location); attribute.buffer->bind(Buffer::Target::Array); glVertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); } +#ifndef MAGNUM_TARGET_GLES void Mesh::vertexAttribPointer(const LongAttribute& attribute) { glEnableVertexAttribArray(attribute.location); attribute.buffer->bind(Buffer::Target::Array); glVertexAttribLPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast(attribute.offset)); } #endif +#endif void Mesh::initializeContextBasedFunctionality(Context* context) { + /** @todo VAOs are in ES 3.0 and as extension in ES 2.0, enable them when some extension wrangler is available */ + #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported()) { - #ifndef MAGNUM_TARGET_GLES Debug() << "Mesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; createImplementation = &Mesh::createImplementationVAO; @@ -134,39 +159,45 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { bindImplementation = &Mesh::bindImplementationVAO; unbindImplementation = &Mesh::unbindImplementationVAO; - #endif } + #else + static_cast(context); + #endif } void Mesh::createImplementationDefault() {} -#ifndef MAGNUM_TARGET_GLES void Mesh::createImplementationVAO() { + /** @todo Get some extension wrangler instead to avoid linker errors to glGenVertexArrays() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 glGenVertexArrays(1, &vao); + #endif } -#endif void Mesh::destroyImplementationDefault() {} -#ifndef MAGNUM_TARGET_GLES void Mesh::destroyImplementationVAO() { + /** @todo Get some extension wrangler instead to avoid linker errors to glDeleteVertexArrays() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 glDeleteVertexArrays(1, &vao); + #endif } -#endif void Mesh::attributePointerImplementationDefault(const Attribute&) {} -#ifndef MAGNUM_TARGET_GLES void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { bindVAO(vao); vertexAttribPointer(attribute); } +#ifndef MAGNUM_TARGET_GLES void Mesh::attributePointerImplementationDSA(const Attribute& attribute) { glEnableVertexArrayAttribEXT(vao, attribute.location); glVertexArrayVertexAttribOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.offset); } +#endif +#ifndef MAGNUM_TARGET_GLES2 void Mesh::attributePointerImplementationDefault(const IntegerAttribute&) {} void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) { @@ -174,11 +205,14 @@ void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) vertexAttribPointer(attribute); } +#ifndef MAGNUM_TARGET_GLES void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute) { glEnableVertexArrayAttribEXT(vao, attribute.location); glVertexArrayVertexAttribIOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset); } +#endif +#ifndef MAGNUM_TARGET_GLES void Mesh::attributePointerImplementationDefault(const LongAttribute&) {} void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) { @@ -191,41 +225,42 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { glVertexArrayVertexAttribLOffsetEXT(vao, attribute.buffer->id(), attribute.location, attribute.size, attribute.type, attribute.stride, attribute.offset); } #endif +#endif void Mesh::bindImplementationDefault() { for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 for(const IntegerAttribute& attribute: integerAttributes) vertexAttribPointer(attribute); + #ifndef MAGNUM_TARGET_GLES for(const LongAttribute& attribute: longAttributes) vertexAttribPointer(attribute); #endif + #endif } -#ifndef MAGNUM_TARGET_GLES void Mesh::bindImplementationVAO() { bindVAO(vao); } -#endif void Mesh::unbindImplementationDefault() { for(const Attribute& attribute: attributes) glDisableVertexAttribArray(attribute.location); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 for(const IntegerAttribute& attribute: integerAttributes) glDisableVertexAttribArray(attribute.location); + #ifndef MAGNUM_TARGET_GLES for(const LongAttribute& attribute: longAttributes) glDisableVertexAttribArray(attribute.location); #endif + #endif } -#ifndef MAGNUM_TARGET_GLES void Mesh::unbindImplementationVAO() {} -#endif } diff --git a/src/Mesh.h b/src/Mesh.h index bdd430d70..78a1ee686 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -557,6 +557,7 @@ class MAGNUM_EXPORT Mesh { GLsizei stride; }; + #ifndef MAGNUM_TARGET_GLES2 struct MAGNUM_LOCAL IntegerAttribute { Buffer* buffer; GLuint location; @@ -566,6 +567,7 @@ class MAGNUM_EXPORT Mesh { GLsizei stride; }; + #ifndef MAGNUM_TARGET_GLES struct MAGNUM_LOCAL LongAttribute { Buffer* buffer; GLuint location; @@ -575,6 +577,8 @@ class MAGNUM_EXPORT Mesh { GLsizei stride; }; #endif + #endif + #endif static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); @@ -629,7 +633,7 @@ class MAGNUM_EXPORT Mesh { (this->*attributePointerImplementation)(attributes.back()); } - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { integerAttributes.push_back({ buffer, @@ -643,6 +647,7 @@ class MAGNUM_EXPORT Mesh { (this->*attributeIPointerImplementation)(integerAttributes.back()); } + #ifndef MAGNUM_TARGET_GLES template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { longAttributes.push_back({ @@ -658,6 +663,7 @@ class MAGNUM_EXPORT Mesh { } } #endif + #endif static void MAGNUM_LOCAL bindVAO(GLuint vao); @@ -668,59 +674,57 @@ class MAGNUM_EXPORT Mesh { } void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 void MAGNUM_LOCAL vertexAttribPointer(const IntegerAttribute& attribute); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL vertexAttribPointer(const LongAttribute& attribute); #endif + #endif typedef void(Mesh::*CreateImplementation)(); void MAGNUM_LOCAL createImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL createImplementationVAO(); - #endif static CreateImplementation createImplementation; typedef void(Mesh::*DestroyImplementation)(); void MAGNUM_LOCAL destroyImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL destroyImplementationVAO(); - #endif static MAGNUM_LOCAL DestroyImplementation destroyImplementation; typedef void(Mesh::*AttributePointerImplementation)(const Attribute&); void MAGNUM_LOCAL attributePointerImplementationDefault(const Attribute& attribute); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL attributePointerImplementationVAO(const Attribute& attribute); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL attributePointerImplementationDSA(const Attribute& attribute); #endif static AttributePointerImplementation attributePointerImplementation; - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 typedef void(Mesh::*AttributeIPointerImplementation)(const IntegerAttribute&); void MAGNUM_LOCAL attributePointerImplementationDefault(const IntegerAttribute& attribute); void MAGNUM_LOCAL attributePointerImplementationVAO(const IntegerAttribute& attribute); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL attributePointerImplementationDSA(const IntegerAttribute& attribute); + #endif static AttributeIPointerImplementation attributeIPointerImplementation; + #ifndef MAGNUM_TARGET_GLES typedef void(Mesh::*AttributeLPointerImplementation)(const LongAttribute&); void MAGNUM_LOCAL attributePointerImplementationDefault(const LongAttribute& attribute); void MAGNUM_LOCAL attributePointerImplementationVAO(const LongAttribute& attribute); void MAGNUM_LOCAL attributePointerImplementationDSA(const LongAttribute& attribute); static AttributeLPointerImplementation attributeLPointerImplementation; #endif + #endif typedef void(Mesh::*BindImplementation)(); void MAGNUM_LOCAL bindImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL bindImplementationVAO(); - #endif static MAGNUM_LOCAL BindImplementation bindImplementation; typedef void(Mesh::*UnbindImplementation)(); void MAGNUM_LOCAL unbindImplementationDefault(); - #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL unbindImplementationVAO(); - #endif static MAGNUM_LOCAL UnbindImplementation unbindImplementation; GLuint vao; @@ -728,8 +732,12 @@ class MAGNUM_EXPORT Mesh { GLsizei _vertexCount; std::vector attributes; + #ifndef MAGNUM_TARGET_GLES2 std::vector integerAttributes; + #ifndef MAGNUM_TARGET_GLES std::vector longAttributes; + #endif + #endif }; } From fc0b405ccb6221768f80b3ada186a329b0ea724c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 16:12:52 +0100 Subject: [PATCH 238/256] Updated OpenGL ES support in Framebuffer. --- src/Framebuffer.cpp | 9 +- src/Framebuffer.h | 236 ++++++++++++++++++++++++++++++++------------ 2 files changed, 179 insertions(+), 66 deletions(-) diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 7a07ce3f2..c545c0dc6 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -20,7 +20,7 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES +#ifndef MAGNUM_TARGET_GLES2 void Framebuffer::mapDefaultForDraw(std::initializer_list attachments) { GLenum* _attachments = new GLenum[attachments.size()]; for(auto it = attachments.begin(); it != attachments.end(); ++it) @@ -30,6 +30,7 @@ void Framebuffer::mapDefaultForDraw(std::initializer_list glDrawBuffers(attachments.size(), _attachments); delete[] _attachments; } +#endif void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { GLenum* attachments = new GLenum[colorAttachments.size()]; @@ -37,10 +38,12 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments attachments[it-colorAttachments.begin()] = *it + GL_COLOR_ATTACHMENT0; bind(Target::Draw); + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 glDrawBuffers(colorAttachments.size(), attachments); + #endif delete[] attachments; } -#endif void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { char* data = new char[AbstractImage::pixelSize(components, type)*size.product()]; @@ -48,7 +51,6 @@ void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2setData(size, components, type, data); } -#ifndef MAGNUM_TARGET_GLES void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ @@ -58,6 +60,5 @@ void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2buffer()->bind(Buffer::Target::PixelPack); glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), nullptr); } -#endif } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index e70b7bc1b..0482b567c 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -86,14 +86,15 @@ class MAGNUM_EXPORT Framebuffer { /** * Logical operation * @see setLogicOperation() - * @requires_gl Logic operations on framebuffer are in desktop OpenGL only. + * @requires_gl Logical operations on framebuffer are not + * available in OpenGL ES. */ LogicOperation = GL_COLOR_LOGIC_OP, /** * Depth clamping. If enabled, ignores near and far clipping plane. - * @requires_gl * @requires_gl32 Extension @extension{ARB,depth_clamp} + * @requires_gl Depth clamping is not available in OpenGL ES. */ DepthClamp = GL_DEPTH_CLAMP, #endif @@ -184,7 +185,7 @@ class MAGNUM_EXPORT Framebuffer { * * Initial value is `1.0`. * @see @fn_gl{ClearDepth} - * @requires_gl See setClearDepth(GLfloat), which is supported in OpenGL ES. + * @requires_gl See setClearDepth(GLfloat), which is available in OpenGL ES. */ inline static void setClearDepth(GLdouble depth) { glClearDepth(depth); } #endif @@ -431,24 +432,19 @@ class MAGNUM_EXPORT Framebuffer { enum class BlendEquation: GLenum { Add = GL_FUNC_ADD, /**< `source + destination` */ Subtract = GL_FUNC_SUBTRACT, /**< `source - destination` */ - ReverseSubtract = GL_FUNC_REVERSE_SUBTRACT /**< `destination - source` */ - - #ifndef MAGNUM_TARGET_GLES - /** @todo Enable for ES3 when the headers are available */ - , + ReverseSubtract = GL_FUNC_REVERSE_SUBTRACT, /**< `destination - source` */ /** * `min(source, destination)` - * @requires_gles30 Extension @es_extension{EXT,blend_minmax} + * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} */ Min = GL_MIN, /** * `max(source, destination)` - * @requires_gles30 Extension @es_extension{EXT,blend_minmax} + * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} */ Max = GL_MAX - #endif }; /** @@ -499,8 +495,9 @@ class MAGNUM_EXPORT Framebuffer { * Second source color (@f$ RGB = (R_{s1}, G_{s1}, B_{s1}); A = A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. */ SecondSourceColor = GL_SRC1_COLOR, #endif @@ -515,8 +512,9 @@ class MAGNUM_EXPORT Framebuffer { * One minus second source color (@f$ RGB = (1.0 - R_{s1}, 1.0 - G_{s1}, 1.0 - B_{s1}); A = 1.0 - A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. */ OneMinusSecondSourceColor = GL_ONE_MINUS_SRC1_COLOR, #endif @@ -536,8 +534,9 @@ class MAGNUM_EXPORT Framebuffer { * Second source alpha (@f$ RGB = (A_{s1}, A_{s1}, A_{s1}); A = A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. */ SecondSourceAlpha = GL_SRC1_ALPHA, #endif @@ -552,8 +551,9 @@ class MAGNUM_EXPORT Framebuffer { * One minus second source alpha (@f$ RGB = (1.0 - A_{s1}, 1.0 - A_{s1}, 1.0 - A_{s1}); A = 1.0 - A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. */ OneMinusSecondSourceAlpha = GL_ONE_MINUS_SRC1_ALPHA, #endif @@ -650,7 +650,8 @@ class MAGNUM_EXPORT Framebuffer { * @brief Logical operation * * @see setLogicOperation() - * @requires_gl + * @requires_gl Logical operations on framebuffer are not available in + * OpenGL ES. */ enum class LogicOperation: GLenum { Clear = GL_CLEAR, /**< `0` */ @@ -676,7 +677,8 @@ class MAGNUM_EXPORT Framebuffer { * * @attention You have to enable logical operation with setFeature() first. * @see @fn_gl{LogicOp} - * @requires_gl Logic operations on framebuffer are in desktop OpenGL only. + * @requires_gl Logical operations on framebuffer are not available in + * OpenGL ES. */ inline static void setLogicOperation(LogicOperation operation) { glLogicOp(static_cast(operation)); @@ -694,60 +696,157 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ enum class Target: GLenum { - #ifndef MAGNUM_TARGET_GLES /** * For reading only. - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} + * or @es_extension{ANGLE,framebuffer_blit} */ Read = GL_READ_FRAMEBUFFER, /** * For drawing only. - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} + * or @es_extension{ANGLE,framebuffer_blit} */ Draw = GL_DRAW_FRAMEBUFFER, - #endif ReadDraw = GL_FRAMEBUFFER /**< For both reading and drawing. */ }; - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 /** * @brief Draw attachment for default framebuffer * * @see mapDefaultForDraw() - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 Draw attachments for default framebuffer are + * available only in OpenGL ES 3.0. */ enum class DefaultDrawAttachment: GLenum { - None = GL_NONE, /**< Don't use the output. */ - BackLeft = GL_BACK_LEFT, /**< Write output to back left framebuffer. */ - BackRight = GL_BACK_RIGHT, /**< Write output to back right framebuffer. */ - FrontLeft = GL_FRONT_LEFT, /**< Write output to front left framebuffer. */ - FrontRight = GL_FRONT_RIGHT /**< Write output to front right framebuffer. */ + /** Don't use the output. */ + None = GL_NONE, + + #ifndef MAGNUM_TARGET_GLES + /** + * Write output to back left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackLeft = GL_BACK_LEFT, + + /** + * Write output to back right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackRight = GL_BACK_RIGHT, + + /** + * Write output to front left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontLeft = GL_FRONT_LEFT, + + /** + * Write output to front right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontRight = GL_FRONT_RIGHT, + #endif + + /** + * Write output to back framebuffer. + * + * On desktop OpenGL, this is equal to + * @ref Magnum::Framebuffer::DefaultDrawAttachment "DefaultDrawAttachment::BackLeft". + */ + #ifdef MAGNUM_TARGET_GLES + Back = GL_BACK, + #else + Back = GL_BACK_LEFT, + #endif + + /** + * Write output to front framebuffer. + * + * On desktop OpenGL, this is equal to + * @ref Magnum::Framebuffer::DefaultDrawAttachment "DefaultDrawAttachment::FrontLeft". + */ + #ifdef MAGNUM_TARGET_GLES + Front = GL_FRONT + #else + Front = GL_FRONT_LEFT + #endif }; + #endif /** * @brief Read attachment for default framebuffer * * @see mapDefaultForRead() - * @requires_gl - * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gl30 %Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ enum class DefaultReadAttachment: GLenum { - FrontLeft = GL_FRONT_LEFT, /**< Read from front left framebuffer. */ - FrontRight = GL_FRONT_RIGHT, /**< Read from front right framebuffer. */ - BackLeft = GL_BACK_LEFT, /**< Read from back left framebuffer. */ - BackRight = GL_BACK_RIGHT, /**< Read from back right framebuffer. */ - Left = GL_LEFT, /**< Read from left framebuffers. */ - Right = GL_RIGHT, /**< Read from right framebuffers. */ - Front = GL_FRONT, /**< Read from front framebuffers. */ - Back = GL_BACK, /**< Read from back framebuffers. */ - FrontAndBack = GL_FRONT_AND_BACK /**< Read from front and back framebuffers. */ + #ifndef MAGNUM_TARGET_GLES + /** + * Read from back left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackLeft = GL_BACK_LEFT, + + /** + * Read from back right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackRight = GL_BACK_RIGHT, + + /** + * Read from front left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontLeft = GL_FRONT_LEFT, + + /** + * Read from front right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontRight = GL_FRONT_RIGHT, + + /** + * Read from left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + Left = GL_LEFT, + + /** + * Read from right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + Right = GL_RIGHT, + #endif + + /** Read from back framebuffer. */ + Back = GL_BACK, + + /** + * Read from front framebuffer. + * @requires_es_extension %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} + */ + Front = GL_FRONT + + #ifndef MAGNUM_TARGET_GLES + , + + /** + * Read from front and back framebuffer. + * @requires_gl In OpenGL ES you must specify either + * @ref Magnum::Framebuffer::DefaultReadAttachment "DefaultReadAttachment::Front" + * or @ref Magnum::Framebuffer::DefaultReadAttachment "DefaultReadAttachment::Back". + */ + FrontAndBack = GL_FRONT_AND_BACK + #endif }; - #endif /** * @brief Constructor @@ -788,7 +887,7 @@ class MAGNUM_EXPORT Framebuffer { glBindFramebuffer(static_cast(target), _id); } - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 /** * @brief Map given attachments of default framebuffer for drawing * @param attachments Default attachments. If any value is @@ -800,10 +899,12 @@ class MAGNUM_EXPORT Framebuffer { * should have either renderbuffer or texture attached for writing to * work properly. * @see mapForDraw(), mapDefaultForRead(), bindDefault(), @fn_gl{DrawBuffers} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 Draw attachments for default framebuffer are + * available only in OpenGL ES 3.0. */ static void mapDefaultForDraw(std::initializer_list attachments); + #endif /** * @brief Map given color attachments of current framebuffer for drawing @@ -816,8 +917,8 @@ class MAGNUM_EXPORT Framebuffer { * should have either renderbuffer or texture attached for writing to * work properly. * @see mapDefaultForDraw(), mapForRead(), bind(), @fn_gl{DrawBuffers} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ void mapForDraw(std::initializer_list colorAttachments); @@ -828,8 +929,8 @@ class MAGNUM_EXPORT Framebuffer { * Each used attachment should have either renderbuffer or texture * attached to work properly. * @see mapForRead(), mapDefaultForDraw(), bindDefault(), @fn_gl{ReadBuffer} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline static void mapDefaultForRead(DefaultReadAttachment attachment) { bindDefault(Target::Read); @@ -843,14 +944,13 @@ class MAGNUM_EXPORT Framebuffer { * The color attachment should have either renderbuffer or texture * attached for reading to work properly. * @see mapDefaultForRead(), mapForDraw(), bind(), @fn_gl{ReadBuffer} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline void mapForRead(std::uint8_t colorAttachment) { bind(Target::Read); glReadBuffer(GL_COLOR_ATTACHMENT0 + colorAttachment); } - #endif /*@}*/ @@ -871,10 +971,12 @@ class MAGNUM_EXPORT Framebuffer { Stencil = GL_STENCIL_ATTACHMENT /**< Stencil output only. */ - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 , /** * Both depth and stencil output. + * @requires_gles30 Combined depth and stencil attachment is not + * available in OpenGL ES 2.0. */ DepthStencil = GL_DEPTH_STENCIL_ATTACHMENT #endif @@ -919,8 +1021,8 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -937,8 +1039,8 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -1018,7 +1120,6 @@ class MAGNUM_EXPORT Framebuffer { glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(coordinate), texture->id(), mipLevel); } - #ifndef MAGNUM_TARGET_GLES /** * @brief Attach 3D texture to given framebuffer depth/stencil attachment * @param target %Target @@ -1028,14 +1129,22 @@ class MAGNUM_EXPORT Framebuffer { * @param layer Layer of 2D image within a 3D texture * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); + /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ + #ifndef MAGNUM_TARGET_GLES glFramebufferTexture3D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel, layer); + #else + static_cast(depthStencilAttachment); + static_cast(texture); + static_cast(mipLevel); + static_cast(layer); + #endif } /** @@ -1047,30 +1156,36 @@ class MAGNUM_EXPORT Framebuffer { * @param layer Layer of 2D image within a 3D texture. * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); + /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ + #ifndef MAGNUM_TARGET_GLES glFramebufferTexture3D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel, layer); + #else + static_cast(colorAttachment); + static_cast(texture); + static_cast(mipLevel); + static_cast(layer); + #endif } - #endif /*@}*/ /** @{ @name Framebuffer blitting and reading */ - #ifndef MAGNUM_TARGET_GLES /** * @brief Output mask for blitting * * Specifies which data are copied when performing blit operation * using blit(). * @see BlitMask - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ enum class Blit: GLbitfield { Color = GL_COLOR_BUFFER_BIT, /**< Color */ @@ -1080,8 +1195,8 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Output mask for blitting - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ typedef Corrade::Containers::EnumSet BlitMask; @@ -1102,8 +1217,8 @@ class MAGNUM_EXPORT Framebuffer { * and drawing. If multiple attachments are specified in mapForDraw() * / mapDefaultForDraw(), the data are written to each of them. * @see @fn_gl{BlitFramebuffer} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ inline static void blit(const Math::Vector2& bottomLeft, const Math::Vector2& topRight, const Math::Vector2& destinationBottomLeft, const Math::Vector2& destinationTopRight, BlitMask blitMask, AbstractTexture::Filter filter) { glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(blitMask), static_cast(filter)); @@ -1123,13 +1238,12 @@ class MAGNUM_EXPORT Framebuffer { * AbstractTexture::Filter::NearestNeighbor filtering is used by * default. * @see @fn_gl{BlitFramebuffer} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ inline static void blit(const Math::Vector2& bottomLeft, const Math::Vector2& topRight, BlitMask blitMask) { glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), static_cast(blitMask), static_cast(AbstractTexture::Filter::NearestNeighbor)); } - #endif /** * @brief Read block of pixels from framebuffer to image @@ -1144,7 +1258,6 @@ class MAGNUM_EXPORT Framebuffer { */ static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); - #ifndef MAGNUM_TARGET_GLES /** * @brief Read block of pixels from framebuffer to buffered image * @param offset Offset in the framebuffer @@ -1155,11 +1268,10 @@ class MAGNUM_EXPORT Framebuffer { * @param usage %Buffer usage * * @see Buffer::bind(Target), @fn_gl{ReadPixels} - * @requires_gl * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); - #endif /*@}*/ From 4bfc7459708d64d7ae6911bcce17078aa1945c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 16:16:41 +0100 Subject: [PATCH 239/256] Updated OpenGL ES support in queries. --- src/Query.cpp | 25 +++++++++++++++++++++++-- src/Query.h | 25 ++++++++++++++----------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/Query.cpp b/src/Query.cpp index 36f8fc2a7..1b9fc86bc 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -17,23 +17,37 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES2 bool AbstractQuery::resultAvailable() { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 GLuint result; glGetQueryObjectuiv(_id, GL_QUERY_RESULT_AVAILABLE, &result); return result == GL_TRUE; + #else + return false; + #endif } template<> bool AbstractQuery::result() { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 GLuint result; glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); return result == GL_TRUE; + #else + return false; + #endif } template<> GLuint AbstractQuery::result() { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 GLuint result; glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); return result; + #else + return 0; + #endif } #ifndef MAGNUM_TARGET_GLES @@ -56,6 +70,7 @@ template<> GLint64 AbstractQuery::result() { } #endif +#ifndef MAGNUM_TARGET_GLES2 void Query::begin(Query::Target target) { glBeginQuery(static_cast(target), id()); this->target = new Target(target); @@ -68,19 +83,25 @@ void Query::end() { delete target; target = nullptr; } +#endif void SampleQuery::begin(SampleQuery::Target target) { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 glBeginQuery(static_cast(target), id()); + #endif this->target = new Target(target); } void SampleQuery::end() { if(!target) return; + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 glEndQuery(static_cast(*target)); + #endif delete target; target = nullptr; } -#endif } diff --git a/src/Query.h b/src/Query.h index 90aff476d..ef07d4cd3 100644 --- a/src/Query.h +++ b/src/Query.h @@ -25,13 +25,12 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES2 /** @brief Base class for queries See Query, SampleQuery, TimeQuery documentation for more information. @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) -@requires_gles30 (no extension providing this functionality) +@requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean} */ class MAGNUM_EXPORT AbstractQuery { public: @@ -69,8 +68,9 @@ class MAGNUM_EXPORT AbstractQuery { * Note that this function is blocking until the result is available. * See resultAvailable(). * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} - * @requires_gl Result type `GLint`, `GLuint64`, `GLint64` * @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`) + * @requires_gl Result types @c GLint, @c GLuint64 and @c GLint64 are + * not available in OpenGL ES. */ template T result(); @@ -87,7 +87,6 @@ template<> GLint MAGNUM_EXPORT AbstractQuery::result(); template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result(); template<> GLint64 MAGNUM_EXPORT AbstractQuery::result(); #endif -#endif /** @brief %Query for primitives and elapsed time @@ -109,7 +108,7 @@ if(!q.resultAvailable()) { GLuint primitiveCount = q.result(); @endcode @requires_gl30 Extension @extension{EXT,transform_feedback} -@requires_gles30 (no extension providing this functionality) +@requires_gles30 Only sample queries are available on OpenGL ES 2.0. */ class MAGNUM_EXPORT Query: public AbstractQuery { public: @@ -119,7 +118,8 @@ class MAGNUM_EXPORT Query: public AbstractQuery { /** * Count of primitives generated from vertex shader or geometry * shader. - * @requires_gl + * @requires_gl Only transform feedback query is available in + * OpenGL ES. */ PrimitivesGenerated = GL_PRIMITIVES_GENERATED, #endif @@ -132,8 +132,9 @@ class MAGNUM_EXPORT Query: public AbstractQuery { /** * Elapsed time - * @requires_gl * @requires_gl33 Extension @extension{ARB,timer_query} + * @requires_gl Only transform feedback query is available in + * OpenGL ES. */ TimeElapsed = GL_TIME_ELAPSED #endif @@ -197,7 +198,7 @@ q.beginConditionalRender(SampleQuery::ConditionalRenderMode::Wait); // render full version of the object only if the query returns nonzero result q.endConditionalRender(); @endcode -@requires_gles30 (no extension providing this functionality) +@requires_gles30 %Extension @es_extension{EXT,occlusion_query_boolean} */ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { public: @@ -206,7 +207,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { #ifndef MAGNUM_TARGET_GLES /** * Count of samples passed from fragment shader - * @requires_gl + * @requires_gl Only boolean query is available in OpenGL ES. */ SamplesPassed = GL_SAMPLES_PASSED, #endif @@ -231,8 +232,8 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** * @brief Conditional render mode * - * @requires_gl * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl Conditional rendering is not available in OpenGL ES. */ enum class ConditionalRenderMode: GLenum { /** @@ -277,6 +278,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * * @see @fn_gl{BeginConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl Conditional rendering is not available in OpenGL ES. */ inline void beginConditionalRender(ConditionalRenderMode mode) { glBeginConditionalRender(id(), static_cast(mode)); @@ -287,6 +289,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * * @see @fn_gl{EndConditionalRender} * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl Conditional rendering is not available in OpenGL ES. */ inline void endConditionalRender() { glEndConditionalRender(); @@ -328,8 +331,8 @@ GLuint timeElapsed1 = tmp-q1.result(); GLuint timeElapsed2 = q3.result()-tmp; @endcode Using this query results in fewer OpenGL calls when doing more measures. -@requires_gl @requires_gl33 Extension @extension{ARB,timer_query} +@requires_gl Timer query is not available in OpenGL ES. */ class TimeQuery: public AbstractQuery { public: From b12792d15a186635e2eea250b4e3ddf1ad7ce708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 16:32:58 +0100 Subject: [PATCH 240/256] Updated OpenGL ES support in textures. --- src/AbstractTexture.cpp | 53 +++++++++++++++++++++++++++++++++++++-- src/AbstractTexture.h | 35 +++++++++++++++++++------- src/CubeMapTexture.h | 4 +-- src/CubeMapTextureArray.h | 7 ++++-- src/Texture.h | 19 ++++++++------ 5 files changed, 95 insertions(+), 23 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 6cb0ca856..8012626b7 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -32,14 +32,18 @@ AbstractTexture::ParameterfvImplementation AbstractTexture::parameterfvImplement &AbstractTexture::parameterImplementationDefault; AbstractTexture::MipmapImplementation AbstractTexture::mipmapImplementation = &AbstractTexture::mipmapImplementationDefault; +#ifndef MAGNUM_TARGET_GLES AbstractTexture::Image1DImplementation AbstractTexture::image1DImplementation = &AbstractTexture::imageImplementationDefault; +#endif AbstractTexture::Image2DImplementation AbstractTexture::image2DImplementation = &AbstractTexture::imageImplementationDefault; AbstractTexture::Image3DImplementation AbstractTexture::image3DImplementation = &AbstractTexture::imageImplementationDefault; +#ifndef MAGNUM_TARGET_GLES AbstractTexture::SubImage1DImplementation AbstractTexture::subImage1DImplementation = &AbstractTexture::subImageImplementationDefault; +#endif AbstractTexture::SubImage2DImplementation AbstractTexture::subImage2DImplementation = &AbstractTexture::subImageImplementationDefault; AbstractTexture::SubImage3DImplementation AbstractTexture::subImage3DImplementation = @@ -66,17 +70,18 @@ GLint AbstractTexture::maxSupportedLayerCount() { return Context::current()->state()->texture->maxSupportedLayerCount; } -#ifndef MAGNUM_TARGET_GLES GLfloat AbstractTexture::maxSupportedAnisotropy() { GLfloat& value = Context::current()->state()->texture->maxSupportedAnisotropy; + /** @todo Re-enable when extension header is available */ + #ifndef MAGNUM_TARGET_GLES /* Get the value, if not already cached */ if(value == 0.0f) glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value); + #endif return value; } -#endif AbstractTexture::~AbstractTexture() { /* Remove all bindings */ @@ -106,9 +111,11 @@ void AbstractTexture::bindImplementationDefault(GLint layer) { glBindTexture(_target, (textureState->bindings[layer] = _id)); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::bindImplementationDSA(GLint layer) { glBindMultiTextureEXT(GL_TEXTURE0 + layer, _target, (Context::current()->state()->texture->bindings[layer] = _id)); } +#endif AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES @@ -134,9 +141,11 @@ void AbstractTexture::mipmapImplementationDefault() { glGenerateMipmap(_target); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::mipmapImplementationDSA() { glGenerateTextureMipmapEXT(_id, _target); } +#endif #ifndef DOXYGEN_GENERATING_OUTPUT void AbstractTexture::bindInternal() { @@ -165,6 +174,7 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &value); textureState->bindings.resize(value); + #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported()) { Debug() << "AbstractTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; @@ -180,6 +190,7 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { subImage2DImplementation = &AbstractTexture::subImageImplementationDSA; subImage3DImplementation = &AbstractTexture::subImageImplementationDSA; } + #endif } void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLint value) { @@ -187,24 +198,29 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLint val glTexParameteri(_target, parameter, value); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::parameterImplementationDSA(GLenum parameter, GLint value) { glTextureParameteriEXT(_id, _target, parameter, value); } +#endif void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLfloat value) { bindInternal(); glTexParameterf(_target, parameter, value); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::parameterImplementationDSA(GLenum parameter, GLfloat value) { glTextureParameterfEXT(_id, _target, parameter, value); } +#endif void AbstractTexture::parameterImplementationDefault(GLenum parameter, const GLfloat* values) { bindInternal(); glTexParameterfv(_target, parameter, values); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat* values) { glTextureParameterfvEXT(_id, _target, parameter, values); } @@ -217,25 +233,42 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureImage1DEXT(_id, target, mipLevel, internalFormat, size[0], 0, static_cast(components), static_cast(type), data); } +#endif void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); glTexImage2D(target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureImage2DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } +#endif void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); + /** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 glTexImage3D(target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); + #else + static_cast(target); + static_cast(mipLevel); + static_cast(internalFormat); + static_cast(size); + static_cast(components); + static_cast(type); + static_cast(data); + #endif } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureImage3DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); } +#endif +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); @@ -244,24 +277,40 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLeve void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); } +#endif void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); } +#endif void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); + /** @todo Get some extension wrangler instead to avoid linker errors to glTexSubImage3D() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); + #else + static_cast(target); + static_cast(mipLevel); + static_cast(offset); + static_cast(size); + static_cast(components); + static_cast(type); + static_cast(data); + #endif } +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); } +#endif AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) { #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index f53d7c690..27b1895eb 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -133,7 +133,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * Clamp to border color. Coordinates out of range will be clamped * to border color (set with setBorderColor()). - * @requires_gl + * @requires_gl Texture border is not available in OpenGL ES. */ ClampToBorder = GL_CLAMP_TO_BORDER #endif @@ -564,16 +564,14 @@ class MAGNUM_EXPORT AbstractTexture { */ static GLint maxSupportedLayerCount(); - #ifndef MAGNUM_TARGET_GLES /** * @brief Max supported anisotropy * * @see setMaxAnisotropy(), @fn_gl{Get} with @def_gl{MAX_TEXTURE_MAX_ANISOTROPY_EXT} - * @requires_gl - * @requires_extension @extension{EXT,texture_filter_anisotropic} + * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} + * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ static GLfloat maxSupportedAnisotropy(); - #endif /** * @brief Constructor @@ -659,12 +657,13 @@ class MAGNUM_EXPORT AbstractTexture { * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_BORDER_COLOR} - * @requires_gl + * @requires_gl Texture border is not available in OpenGL ES. */ inline AbstractTexture* setBorderColor(const Color4& color) { (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); return this; } + #endif /** * @brief Set max anisotropy @@ -678,14 +677,18 @@ class MAGNUM_EXPORT AbstractTexture { * @fn_gl{BindTexture} and @fn_gl{TexParameter} or * @fn_gl_extension{TextureParameter,EXT,direct_state_access} with * @def_gl{TEXTURE_MAX_ANISOTROPY_EXT} - * @requires_gl - * @requires_extension @extension{EXT,texture_filter_anisotropic} + * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} + * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { + /** @todo Remove `ifndef` when extension header is available */ + #ifndef MAGNUM_TARGET_GLES (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); + #else + static_cast(anisotropy); + #endif return this; } - #endif /** * @brief Generate mipmap @@ -716,33 +719,45 @@ class MAGNUM_EXPORT AbstractTexture { typedef void(AbstractTexture::*BindImplementation)(GLint); void MAGNUM_LOCAL bindImplementationDefault(GLint layer); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL bindImplementationDSA(GLint layer); + #endif static MAGNUM_LOCAL BindImplementation bindImplementation; typedef void(AbstractTexture::*ParameteriImplementation)(GLenum, GLint); void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, GLint value); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, GLint value); + #endif static ParameteriImplementation parameteriImplementation; typedef void(AbstractTexture::*ParameterfImplementation)(GLenum, GLfloat); void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, GLfloat value); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, GLfloat value); + #endif static ParameterfImplementation parameterfImplementation; typedef void(AbstractTexture::*ParameterfvImplementation)(GLenum, const GLfloat*); void MAGNUM_LOCAL parameterImplementationDefault(GLenum parameter, const GLfloat* values); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL parameterImplementationDSA(GLenum parameter, const GLfloat* values); + #endif static ParameterfvImplementation parameterfvImplementation; typedef void(AbstractTexture::*MipmapImplementation)(); void MAGNUM_LOCAL mipmapImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL mipmapImplementationDSA(); + #endif static MAGNUM_LOCAL MipmapImplementation mipmapImplementation; + #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static Image1DImplementation image1DImplementation; + #endif typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); @@ -754,10 +769,12 @@ class MAGNUM_EXPORT AbstractTexture { void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static Image3DImplementation image3DImplementation; + #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static SubImage1DImplementation subImage1DImplementation; + #endif typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Math::Vector2&, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 110214c42..df1d3b77f 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -65,9 +65,9 @@ class CubeMapTexture: public AbstractTexture { * * Initially disabled on desktop OpenGL. * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} + * @requires_gl32 Extension @extension{ARB,seamless_cube_map} * @requires_gl Not available in OpenGL ES 2.0, always enabled in * OpenGL ES 3.0. - * @requires_gl32 Extension @extension{ARB,seamless_cube_map} */ inline static void setSeamless(bool enabled) { enabled ? glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) : glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); @@ -125,11 +125,11 @@ class CubeMapTexture: public AbstractTexture { AbstractTexture::setBorderColor(color); return this; } + #endif inline CubeMapTexture* setMaxAnisotropy(GLfloat anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); return this; } - #endif inline CubeMapTexture* generateMipmap() { AbstractTexture::generateMipmap(); return this; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 165e38e54..0aa441935 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -15,12 +15,15 @@ GNU Lesser General Public License version 3 for more details. */ +#ifndef MAGNUM_TARGET_GLES /** @file * @brief Class Magnum::CubeMapTextureArray */ +#endif #include "Texture.h" +#ifndef MAGNUM_TARGET_GLES namespace Magnum { /** @@ -35,6 +38,7 @@ the cube map. @see CubeMapTexture::setSeamless() @requires_gl40 Extension @extension{ARB,texture_cube_map_array} +@requires_gl Cube map texture arrays are not available in OpenGL ES. */ class CubeMapTextureArray: public AbstractTexture { public: @@ -129,7 +133,6 @@ class CubeMapTextureArray: public AbstractTexture { AbstractTexture::setMagnificationFilter(filter); return this; } - #ifndef MAGNUM_TARGET_GLES inline CubeMapTextureArray* setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); return this; @@ -138,7 +141,6 @@ class CubeMapTextureArray: public AbstractTexture { AbstractTexture::setMaxAnisotropy(anisotropy); return this; } - #endif inline CubeMapTextureArray* generateMipmap() { AbstractTexture::generateMipmap(); return this; @@ -147,5 +149,6 @@ class CubeMapTextureArray: public AbstractTexture { }; } +#endif #endif diff --git a/src/Texture.h b/src/Texture.h index 0dd5bcf2d..c73550993 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -44,7 +44,7 @@ don't support mipmapping and repeating wrapping modes, see @ref Texture::Filter "Filter", @ref Texture::Mipmap "Mipmap" and generateMipmap() documentation for more information. -@requires_gl (rectangle textures) +@requires_gl Rectangle textures are not available in OpenGL ES. @requires_gl31 Extension @extension{ARB,texture_rectangle} (rectangle textures) @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @@ -63,7 +63,8 @@ template class Texture: public AbstractTexture { enum class Target: GLenum { /** * One-dimensional texture - * @requires_gl + * @requires_gl Only 2D and 3D textures are available in OpenGL + * ES. */ Texture1D = GL_TEXTURE_1D, @@ -71,28 +72,30 @@ template class Texture: public AbstractTexture { /** * Three-dimensional texture - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 %Extension @es_extension{OES,texture_3D} */ Texture3D = GL_TEXTURE_3D, /** * One-dimensional texture array (i.e. two dimensions in total) - * @requires_gl * @requires_gl30 Extension @extension{EXT,texture_array} + * @requires_gl Only 2D and 3D textures are available in OpenGL + * ES. */ Texture1DArray = GL_TEXTURE_1D_ARRAY, /** * Two-dimensional texture array (i.e. three dimensions in total) * @requires_gl30 Extension @extension{EXT,texture_array} - * @requires_gles30 (no extension providing this functionality) + * @requires_gles30 Array textures are not available in OpenGL ES + * 2.0. */ Texture2DArray = GL_TEXTURE_2D_ARRAY, /** * Rectangle texture (i.e. two dimensions) - * @requires_gl * @requires_gl31 Extension @extension{ARB,texture_rectangle} + * @requires_gl Rectangle textures are not available in OpenGL ES. */ Rectangle = GL_TEXTURE_RECTANGLE }; @@ -220,7 +223,7 @@ template class Texture: public AbstractTexture { /** @brief One-dimensional texture -@requires_gl +@requires_gl Only 2D and 3D textures are available in OpenGL ES. */ typedef Texture<1> Texture1D; #endif @@ -231,7 +234,7 @@ typedef Texture<2> Texture2D; /** @brief Three-dimensional texture -@requires_gles30 (no extension providing this functionality) +@requires_gles30 %Extension @es_extension{OES,texture_3D} */ typedef Texture<3> Texture3D; From 264a2e768fdc94b99ed7d8766b341fef45b32f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 17:30:13 +0100 Subject: [PATCH 241/256] Don't compile/install desktop-only features if targeting OpenGL ES. --- src/CMakeLists.txt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6361857c..c9fd8c6de 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,6 @@ set(Magnum_SRCS AbstractShaderProgram.cpp Buffer.cpp BufferedImage.cpp - BufferedTexture.cpp Context.cpp Framebuffer.cpp Image.cpp @@ -48,16 +47,21 @@ set(Magnum_SRCS Trade/AbstractImporter.cpp Trade/MeshData2D.cpp Trade/MeshData3D.cpp) + +# Desktop-only code +if(NOT TARGET_GLES) + set(Magnum_SRCS ${Magnum_SRCS} + BufferedTexture.cpp) +endif() + set(Magnum_HEADERS AbstractImage.h AbstractShaderProgram.h AbstractTexture.h BufferedImage.h - BufferedTexture.h Buffer.h Color.h Context.h - CubeMapTextureArray.h CubeMapTexture.h DimensionTraits.h Extensions.h @@ -80,6 +84,14 @@ set(Magnum_HEADERS magnumCompatibility.h magnumVisibility.h) + +# Desktop-only headers +if(NOT TARGET_GLES) + set(Magnum_HEADERS ${Magnum_HEADERS} + BufferedTexture.h + CubeMapTextureArray.h) +endif() + add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library From ef3a28e5d4e7b2109f763928c29dd5cc9d44e8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 17:41:08 +0100 Subject: [PATCH 242/256] Added missing value to Framebuffer::DefaultReadAttachment. --- src/Framebuffer.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 0482b567c..8cf84490d 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -788,6 +788,9 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ enum class DefaultReadAttachment: GLenum { + /** Don't read from any framebuffer */ + None = GL_NONE, + #ifndef MAGNUM_TARGET_GLES /** * Read from back left framebuffer. From 818fdefbd60866d8e1148fbc777760911b749819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 3 Nov 2012 23:34:40 +0100 Subject: [PATCH 243/256] Added convenience function Context::supportedVersion(). --- src/Context.cpp | 11 +++++++++++ src/Context.h | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index eab210cba..e86df90df 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -247,4 +247,15 @@ Context::~Context() { _current = nullptr; } +Version Context::supportedVersion(initializer_list versions) const { + for(auto version: versions) + if(isVersionSupported(version)) return version; + + #ifndef MAGNUM_TARGET_GLES + return Version::GL210; + #else + return Version::GLES200; + #endif +} + } diff --git a/src/Context.h b/src/Context.h index 3443cf0dc..f896975f0 100644 --- a/src/Context.h +++ b/src/Context.h @@ -194,11 +194,31 @@ class MAGNUM_EXPORT Context { return _supportedExtensions; } - /** @brief Whether given OpenGL version is supported */ + /** + * @brief Whether given OpenGL version is supported + * + * @see supportedVersion() + */ inline bool isVersionSupported(Version version) const { return _version >= version; } + /** + * @brief Get supported OpenGL version + * + * Returns first supported OpenGL version from passed list. Convenient + * equivalent to subsequent isVersionSupported() calls, e.g.: + * @code + * Version v = isVersionSupported(Version::GL330) ? Version::GL330 : Version::GL210; + * Version v = supportedVersion({Version::GL330, Version::GL210}); + * @endcode + * + * If no version from the list is supported, returns lowest available + * OpenGL version (@ref Version "Version::GL210" for desktop OpenGL, + * @ref Version "Version::GLES200" for OpenGL ES). + */ + Version supportedVersion(std::initializer_list versions) const; + /** * @brief Whether given extension is supported * From 0cb857b66f1d6f1f649423abf7978de55cd4602a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 3 Nov 2012 23:39:20 +0100 Subject: [PATCH 244/256] @todo++ --- src/Extensions.h | 4 ++++ src/Framebuffer.h | 1 + src/Magnum.h | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/src/Extensions.h b/src/Extensions.h index 8f7438cf2..a99f9d569 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -32,6 +32,10 @@ the same public methods as Extension class (requiredVersion(), coreVersion() and string(), but these structs are better suited for compile-time decisions rather than Extension instances. See Context::isExtensionSupported() for example usage. + +@todo Manual indices for extensions, this has gaps +@todo Unhide ES2_compatibility, ES3_compatibility on ES +@todo Add ES and GL 4.3 extensions */ namespace Extensions { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 8cf84490d..3edfac3fa 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -195,6 +195,7 @@ class MAGNUM_EXPORT Framebuffer { * * @see @fn_gl{ClearDepth} * @requires_gl41 Extension @extension{ARB,ES2_compatibility} + * @todo Call double version if the extension is not available */ inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } diff --git a/src/Magnum.h b/src/Magnum.h index 63bcc00c7..9300082ee 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -28,6 +28,15 @@ #include #endif +/** + * @todo Link to libGL / libGLES based on which windowcontext is used in app + * and whether GLES is enabled or not -- this allows us to use glx with + * ES on nvidia/intel. Using libGL and EGL on nvidia is whole another + * problem, though. How about windows? It won't allow unlinked DLLs, so + * probably always link Magnum itself to GL library there. How about unit + * tests not needing any of GL? -- different testing library? + */ + namespace Corrade { namespace Utility { class Debug; From 81ae500fd8162347b401d004193f552fc17ee2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 13:50:06 +0100 Subject: [PATCH 245/256] Fixed typo. --- src/Mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index f868c38be..4cb19a549 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -146,7 +146,7 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { destroyImplementation = &Mesh::destroyImplementationVAO; if(context->isExtensionSupported()) { - Debug() << "Mesg: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + Debug() << "Mesh: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; attributePointerImplementation = &Mesh::attributePointerImplementationDSA; attributeIPointerImplementation = &Mesh::attributePointerImplementationDSA; From 1c67fc3c667e9958c2c9429de48a4d91a6891f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 15:34:01 +0100 Subject: [PATCH 246/256] Fixed unintialized variable. Accidentaly found when running unit tests on GLES build. --- src/Physics/ShapedObjectGroup.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index 7654a1286..acd5fb96a 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -40,6 +40,13 @@ template class PHYSICS_EXPORT ShapedObjectGroup { friend class ShapedObject; public: + /** + * @brief Constructor + * + * Marks the group as dirty. + */ + inline constexpr ShapedObjectGroup(): dirty(true) {} + /** * @brief Destructor * From a3c908f5fab0ccef2e0bbc4b4498203771fa4e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 15:35:09 +0100 Subject: [PATCH 247/256] Don't show Query for ES 2.0 target. It isn't (and won't be) supported there, so why not hide it. --- src/Query.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Query.h b/src/Query.h index ef07d4cd3..35aae172f 100644 --- a/src/Query.h +++ b/src/Query.h @@ -88,6 +88,7 @@ template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result(); template<> GLint64 MAGNUM_EXPORT AbstractQuery::result(); #endif +#ifndef MAGNUM_TARGET_GLES2 /** @brief %Query for primitives and elapsed time @@ -163,6 +164,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery { private: Target* target; }; +#endif /** @brief %Query for samples From ca061091f9a796d3681bfcbadd36973bb4920ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 15:43:03 +0100 Subject: [PATCH 248/256] Using nullptr instead of 0. --- src/Contexts/EglContextHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contexts/EglContextHandler.cpp b/src/Contexts/EglContextHandler.cpp index fe89eb477..da7224eda 100644 --- a/src/Contexts/EglContextHandler.cpp +++ b/src/Contexts/EglContextHandler.cpp @@ -30,7 +30,7 @@ EglContextHandler::~EglContextHandler() { VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Initialize */ display = eglGetDisplay(nativeDisplay); - eglInitialize(display, 0, 0); + eglInitialize(display, nullptr, nullptr); #ifndef MAGNUM_TARGET_GLES eglBindAPI(EGL_OPENGL_API); #else From c72390d139de34cf2348cc5fbdd9d10e6325b11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 15:44:07 +0100 Subject: [PATCH 249/256] EglContextHandler: better error handling. --- src/Contexts/EglContextHandler.cpp | 57 ++++++++++++++++++++++++------ src/Contexts/EglContextHandler.h | 2 ++ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/Contexts/EglContextHandler.cpp b/src/Contexts/EglContextHandler.cpp index da7224eda..e237b1714 100644 --- a/src/Contexts/EglContextHandler.cpp +++ b/src/Contexts/EglContextHandler.cpp @@ -30,12 +30,20 @@ EglContextHandler::~EglContextHandler() { VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { /* Initialize */ display = eglGetDisplay(nativeDisplay); - eglInitialize(display, nullptr, nullptr); + if(!eglInitialize(display, nullptr, nullptr)) { + Error() << "Cannot initialize EGL:" << errorString(eglGetError()); + exit(1); + } + #ifndef MAGNUM_TARGET_GLES - eglBindAPI(EGL_OPENGL_API); + EGLenum api = EGL_OPENGL_API; #else - eglBindAPI(EGL_OPENGL_ES_API); + EGLenum api = EGL_OPENGL_ES_API; #endif + if(!eglBindAPI(api)) { + Error() << "Cannot bind EGL API:" << errorString(eglGetError()); + exit(1); + } /* Choose EGL config */ static const EGLint attribs[] = { @@ -52,14 +60,19 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { }; EGLint configCount; if(!eglChooseConfig(display, attribs, &config, 1, &configCount)) { - Error() << "Cannot get EGL visual config"; + Error() << "Cannot get EGL visual config:" << errorString(eglGetError()); + exit(1); + } + + if(!configCount) { + Error() << "No matching EGL visual config available"; exit(1); } /* Get visual ID */ EGLint visualId; if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { - Error() << "Cannot get native visual ID"; + Error() << "Cannot get native visual ID:" << errorString(eglGetError()); exit(1); } @@ -73,18 +86,40 @@ void EglContextHandler::createContext(EGLNativeWindowType window) { #endif EGL_NONE }; - context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes); - if(!context) { - Error() << "Cannot create EGL context"; + if(!eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes)) { + Error() << "Cannot create EGL context:" << errorString(eglGetError()); exit(1); } - surface = eglCreateWindowSurface(display, config, window, NULL); - if(!surface) { - Error() << "Cannot create window surface"; + if(!(surface = eglCreateWindowSurface(display, config, window, NULL))) { + Error() << "Cannot create window surface:" << errorString(eglGetError()); exit(1); } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ } +const char* EglContextHandler::errorString(EGLint error) { + switch(error) { + #define _error(name) case name: return #name; + _error(EGL_SUCCESS) + _error(EGL_NOT_INITIALIZED) + _error(EGL_BAD_ACCESS) + _error(EGL_BAD_ALLOC) + _error(EGL_BAD_ATTRIBUTE) + _error(EGL_BAD_CONTEXT) + _error(EGL_BAD_CONFIG) + _error(EGL_BAD_CURRENT_SURFACE) + _error(EGL_BAD_DISPLAY) + _error(EGL_BAD_SURFACE) + _error(EGL_BAD_MATCH) + _error(EGL_BAD_PARAMETER) + _error(EGL_BAD_NATIVE_PIXMAP) + _error(EGL_BAD_NATIVE_WINDOW) + _error(EGL_CONTEXT_LOST) + #undef _error + } + + return ""; +} + }} diff --git a/src/Contexts/EglContextHandler.h b/src/Contexts/EglContextHandler.h index ae5f3daf0..b05c68f69 100644 --- a/src/Contexts/EglContextHandler.h +++ b/src/Contexts/EglContextHandler.h @@ -65,6 +65,8 @@ class EglContextHandler: public AbstractContextHandler Date: Sun, 4 Nov 2012 16:09:09 +0100 Subject: [PATCH 250/256] Blind port of PhongShader to OpenGL ES 2.0. --- src/Shaders/CMakeLists.txt | 3 ++- src/Shaders/PhongShader.cpp | 23 ++++++++++++++++++++--- src/Shaders/PhongShader.frag | 4 ++-- src/Shaders/PhongShader.vert | 5 ++--- src/Shaders/compatibility.glsl | 14 ++++++++++++++ 5 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/Shaders/compatibility.glsl diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 53b99a0f2..926bc6238 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,6 +1,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader2D.frag - PhongShader.frag PhongShader.vert) + PhongShader.frag PhongShader.vert + compatibility.glsl) set(MagnumShaders_SRCS FlatShader.cpp PhongShader.cpp diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 8d79c69ba..394243dcb 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -24,11 +24,28 @@ namespace Magnum { namespace Shaders { PhongShader::PhongShader() { Corrade::Utility::Resource rs("MagnumShaders"); - Version v = Context::current()->isVersionSupported(Version::GL320) ? Version::GL320 : Version::GL210; - attachShader(Shader::fromData(v, Shader::Type::Vertex, rs.get("PhongShader.vert"))); - attachShader(Shader::fromData(v, Shader::Type::Fragment, rs.get("PhongShader.frag"))); + #ifndef MAGNUM_TARGET_GLES + Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + #else + Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + #endif + + Shader vertexShader(v, Shader::Type::Vertex); + vertexShader.addSource(rs.get("compatibility.glsl")); + vertexShader.addSource(rs.get("PhongShader.vert")); + attachShader(vertexShader); + + Shader fragmentShader(v, Shader::Type::Fragment); + fragmentShader.addSource(rs.get("compatibility.glsl")); + fragmentShader.addSource(rs.get("PhongShader.frag")); + attachShader(fragmentShader); + + #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) { + #else + if(!Context::current()->isVersionSupported(Version::GLES300)) { + #endif bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Normal::Location, "normal"); } diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index c6d9c9be5..638a1e3fa 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -1,4 +1,4 @@ -#if __VERSION__ == 120 +#ifndef NEW_GLSL #define in varying #define color gl_FragColor #endif @@ -13,7 +13,7 @@ in vec3 transformedNormal; in vec3 lightDirection; in vec3 cameraDirection; -#if __VERSION__ != 120 +#ifdef NEW_GLSL out vec4 color; #endif diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 3872fcc74..1c794cbce 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -1,4 +1,4 @@ -#if __VERSION__ == 120 +#ifndef NEW_GLSL #define in attribute #define out varying #endif @@ -7,8 +7,7 @@ uniform mat4 transformationMatrix; uniform mat4 projectionMatrix; uniform vec3 light; -#if __VERSION__ != 120 && defined(GL_ARB_explicit_attrib_location) -#extension GL_ARB_explicit_attrib_location: enable +#ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; #else diff --git a/src/Shaders/compatibility.glsl b/src/Shaders/compatibility.glsl new file mode 100644 index 000000000..2ccbfae6b --- /dev/null +++ b/src/Shaders/compatibility.glsl @@ -0,0 +1,14 @@ +#if (!defined(GL_ES) && __VERSION__ >= 130) || (defined(GL_ES) && __VERSION__ >= 300) +#define NEW_GLSL +#endif + +/* On NVidia and GLSL 1.20 layout qualifiers result in parsing error, even if + the extension is defined as supported */ +#if !defined(GL_ES) && __VERSION__ >= 120 && defined(GL_ARB_explicit_attrib_location) +#extension GL_ARB_explicit_attrib_location: enable +#define EXPLICIT_ATTRIB_LOCATION +#endif + +#if defined(GL_ES) && __VERSION__ >= 300 +#define EXPLICIT_ATTRIB_LOCATION +#endif From 6f6d3d09b23acdf284e6757d2bfdb49d22808cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 16:09:45 +0100 Subject: [PATCH 251/256] Blind port of FlatShader to OpenGL 2.1 and OpenGL ES 2.0. --- src/Shaders/FlatShader.cpp | 29 ++++++++++++++++++++++++++--- src/Shaders/FlatShader2D.frag | 6 ++++++ src/Shaders/FlatShader2D.vert | 8 ++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index 4d6df9a03..69d15c3a0 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -17,6 +17,7 @@ #include +#include "Extensions.h" #include "Shader.h" namespace Magnum { namespace Shaders { @@ -36,9 +37,31 @@ namespace { } template FlatShader::FlatShader() { - Corrade::Utility::Resource resource("MagnumShaders"); - attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, resource.get(ShaderName::Vertex))); - attachShader(Shader::fromData(Version::GL330, Shader::Type::Fragment, resource.get(ShaderName::Fragment))); + Corrade::Utility::Resource rs("MagnumShaders"); + + #ifndef MAGNUM_TARGET_GLES + Version v = Context::current()->supportedVersion({/*Version::GL320, */Version::GL210}); + #else + Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + #endif + + Shader vertexShader(v, Shader::Type::Vertex); + vertexShader.addSource(rs.get("compatibility.glsl")); + vertexShader.addSource(rs.get(ShaderName::Vertex)); + attachShader(vertexShader); + + Shader fragmentShader(v, Shader::Type::Fragment); + fragmentShader.addSource(rs.get("compatibility.glsl")); + fragmentShader.addSource(rs.get(ShaderName::Fragment)); + attachShader(fragmentShader); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + if(!Context::current()->isVersionSupported(Version::GLES300)) { + #endif + bindAttributeLocation(Position::Location, "position"); + } link(); diff --git a/src/Shaders/FlatShader2D.frag b/src/Shaders/FlatShader2D.frag index 200b2f88c..bdc52dd38 100644 --- a/src/Shaders/FlatShader2D.frag +++ b/src/Shaders/FlatShader2D.frag @@ -1,6 +1,12 @@ +#ifndef NEW_GLSL +#define fragmentColor gl_FragColor +#endif + uniform vec3 color; +#ifndef NEW_GLSL out vec4 fragmentColor; +#endif void main() { fragmentColor = vec4(color, 1.0); diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index 0ab2076cf..60355d131 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -1,6 +1,14 @@ +#ifndef NEW_GLSL +#define in attribute +#endif + uniform mat3 transformationProjection; +#ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in vec3 position; +#else +in vec3 position; +#endif void main() { gl_Position.xywz = vec4(transformationProjection*position, 0.0); From ba86c3d2f81914d10086504e0deb80780afe755d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Nov 2012 17:46:04 +0100 Subject: [PATCH 252/256] Avoid crash when glGetString(GL_EXTENSIONS) returns nullptr. --- src/Context.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index e86df90df..3f6f11916 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -213,12 +213,16 @@ Context::Context() { /* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ } else { - vector extensions = Corrade::Utility::split(reinterpret_cast(glGetString(GL_EXTENSIONS)), ' '); - for(const string& extension: extensions) { - auto found = futureExtensions.find(extension); - if(found != futureExtensions.end()) { - _supportedExtensions.push_back(found->second); - extensionStatus.set(found->second._index); + /* Don't crash when glGetString() returns nullptr */ + const char* e = reinterpret_cast(glGetString(GL_EXTENSIONS)); + if(e) { + vector extensions = Corrade::Utility::split(e, ' '); + for(const string& extension: extensions) { + auto found = futureExtensions.find(extension); + if(found != futureExtensions.end()) { + _supportedExtensions.push_back(found->second); + extensionStatus.set(found->second._index); + } } } } From b2f42f234eecab34edf5b56fe9ba0b7db5efaa99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 6 Nov 2012 11:44:41 +0100 Subject: [PATCH 253/256] Documentation fixes and updates. --- src/Query.h | 2 +- src/ResourceManager.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Query.h b/src/Query.h index 35aae172f..4657775c4 100644 --- a/src/Query.h +++ b/src/Query.h @@ -87,6 +87,7 @@ template<> GLint MAGNUM_EXPORT AbstractQuery::result(); template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result(); template<> GLint64 MAGNUM_EXPORT AbstractQuery::result(); #endif +#endif #ifndef MAGNUM_TARGET_GLES2 /** @@ -348,7 +349,6 @@ class TimeQuery: public AbstractQuery { } }; #endif -#endif } diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 62a717913..d5f9b4e34 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -24,7 +24,7 @@ namespace Magnum { -/** +/** @relates ResourceManager * @brief %Resource state * * @see Resource::state(), ResourceManager::state() @@ -43,7 +43,7 @@ enum class ResourceState { Final }; -/** +/** @relates ResourceManager * @brief %Resource data state * * @see ResourceManager::set() @@ -65,7 +65,7 @@ enum class ResourceDataState { Final = int(ResourceState::Final) }; -/** +/** @relates ResourceManager @brief %Resource policy @see ResourceManager::set(), ResourceManager::free() @@ -88,7 +88,7 @@ enum class ResourcePolicy { @brief Key for accessing resource @see ResourceManager::referenceCount(), ResourceManager::state(), - ResourceManager::get(), ResourceManager::set() + ResourceManager::get(), ResourceManager::set(), Resource::key() */ class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { public: @@ -438,7 +438,7 @@ if(!cube) { - Using the resource data. @code shader->use(); -texture->bind(); +texture->bind(layer); cube->draw(); @endcode - Destroying resource references and deleting manager instance when nothing From a021e4e20927de9af42d7bccd91278726c314329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 6 Nov 2012 17:56:29 +0100 Subject: [PATCH 254/256] Using CORRADE_INTERNAL_ASSERT() for, ahem, internal issues. --- src/AbstractImage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 075ff69b3..04f14f2b6 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -95,7 +95,7 @@ size_t AbstractImage::pixelSize(Components format, ComponentType type) { case Components::Depth: case Components::StencilIndex: case Components::DepthStencil: - CORRADE_ASSERT(false, "AbstractImage::pixelSize(): unhandled depth/stencil type", 0); + CORRADE_INTERNAL_ASSERT(false); #endif } From 1437043c624abae06ba1a17704800c044958f8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 7 Nov 2012 21:25:30 +0100 Subject: [PATCH 255/256] Fixed compiler warning. --- src/Context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context.h b/src/Context.h index f896975f0..d9f6decd2 100644 --- a/src/Context.h +++ b/src/Context.h @@ -70,7 +70,7 @@ enum class Version: GLint { * equivalent to @ref Version "Version::GL430". */ #ifndef MAGNUM_TARGET_GLES - GLES300 = 430, + GLES300 = 430 #else GLES300 = 300 #endif From 02267d1439e83c7b458a6e585ab70c95eadc3b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Oct 2012 20:13:55 +0100 Subject: [PATCH 256/256] Doxygen configuration. * Don't extract local classes. * Don't include header code in documentation (the only purpose would be to scare users off). * Include template implementation files in documentation. --- Doxyfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doxyfile b/Doxyfile index 4ca3d9dc2..2553d0c84 100644 --- a/Doxyfile +++ b/Doxyfile @@ -400,7 +400,7 @@ EXTRACT_STATIC = NO # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. -EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_CLASSES = NO # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in @@ -704,6 +704,7 @@ INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.cpp \ *.h \ + *.hpp \ *.dox # The RECURSIVE tag can be used to turn specify whether or not subdirectories @@ -860,7 +861,7 @@ USE_HTAGS = NO # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. -VERBATIM_HEADERS = YES +VERBATIM_HEADERS = NO #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index