From adf88d55354bcb03e0bd277533392dd7486cf652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 5 Jul 2015 17:43:17 +0200 Subject: [PATCH] Ability to instantiate OpenGL objects without creating them. Similarly to what's now done with NoInit tags for Containers::Array and all math types such as Vector, there's now NoCreate tag for creating wrappers without actually creating the underlying OpenGL object. The instance is then equivalent to moved-from state. Useful to avoid needless creation/deletion of OpenGL object in case you would overwrite the instance later anyway: Mesh mesh{NoCreate}; std::unique_ptr indices, vertices; std::tie(mesh, indices, vertices) = MeshTools:compile(...); --- src/Magnum/AbstractQuery.h | 2 + src/Magnum/AbstractTexture.h | 2 + src/Magnum/Buffer.h | 21 +++++++- src/Magnum/BufferTexture.h | 14 ++++- src/Magnum/CMakeLists.txt | 1 + src/Magnum/CubeMapTexture.h | 14 ++++- src/Magnum/CubeMapTextureArray.h | 15 +++++- src/Magnum/Framebuffer.h | 14 ++++- src/Magnum/Mesh.cpp | 9 ++++ src/Magnum/Mesh.h | 16 +++++- src/Magnum/MultisampleTexture.h | 14 ++++- src/Magnum/PrimitiveQuery.h | 13 ++++- src/Magnum/RectangleTexture.h | 15 +++++- src/Magnum/Renderbuffer.h | 15 +++++- src/Magnum/SampleQuery.h | 13 ++++- src/Magnum/Tags.h | 51 +++++++++++++++++++ src/Magnum/Test/BufferGLTest.cpp | 13 +++++ src/Magnum/Test/BufferTextureGLTest.cpp | 13 +++++ src/Magnum/Test/CubeMapTextureArrayGLTest.cpp | 13 +++++ src/Magnum/Test/CubeMapTextureGLTest.cpp | 13 +++++ src/Magnum/Test/FramebufferGLTest.cpp | 13 +++++ src/Magnum/Test/MeshGLTest.cpp | 13 +++++ src/Magnum/Test/MultisampleTextureGLTest.cpp | 26 ++++++++++ src/Magnum/Test/PrimitiveQueryGLTest.cpp | 15 +++++- src/Magnum/Test/RectangleTextureGLTest.cpp | 13 +++++ src/Magnum/Test/RenderbufferGLTest.cpp | 13 +++++ src/Magnum/Test/SampleQueryGLTest.cpp | 15 +++++- src/Magnum/Test/TextureArrayGLTest.cpp | 26 ++++++++++ src/Magnum/Test/TextureGLTest.cpp | 39 ++++++++++++++ src/Magnum/Test/TransformFeedbackGLTest.cpp | 13 +++++ src/Magnum/Text/Test/RendererGLTest.cpp | 4 +- src/Magnum/Texture.h | 16 ++++-- src/Magnum/TextureArray.h | 14 ++++- src/Magnum/TimeQuery.h | 13 ++++- src/Magnum/TransformFeedback.h | 14 ++++- 35 files changed, 497 insertions(+), 31 deletions(-) create mode 100644 src/Magnum/Tags.h diff --git a/src/Magnum/AbstractQuery.h b/src/Magnum/AbstractQuery.h index 963c7a133..8b2899205 100644 --- a/src/Magnum/AbstractQuery.h +++ b/src/Magnum/AbstractQuery.h @@ -35,6 +35,7 @@ #include #include "Magnum/AbstractObject.h" +#include "Magnum/Tags.h" #include "Magnum/configure.h" #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) @@ -173,6 +174,7 @@ class MAGNUM_EXPORT AbstractQuery: public AbstractObject { private: #endif explicit AbstractQuery(GLenum target); + explicit AbstractQuery(NoCreateT, GLenum target) noexcept: _id{0}, _target{target}, _flags{ObjectFlag::DeleteOnDestruction} {} explicit AbstractQuery(GLuint id, GLenum target, ObjectFlags flags) noexcept: _id{id}, _target{target}, _flags{flags} {} #ifdef MAGNUM_BUILD_DEPRECATED diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index c91e4404b..074e09f2d 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -34,6 +34,7 @@ #include "Magnum/AbstractObject.h" #include "Magnum/DimensionTraits.h" #include "Magnum/Sampler.h" +#include "Magnum/Tags.h" namespace Magnum { @@ -340,6 +341,7 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { template struct DataHelper {}; explicit AbstractTexture(GLenum target); + explicit AbstractTexture(NoCreateT, GLenum target) noexcept: _target{target}, _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {} explicit AbstractTexture(GLuint id, GLenum target, ObjectFlags flags) noexcept: _target{target}, _id{id}, _flags{flags} {} #ifndef MAGNUM_TARGET_WEBGL diff --git a/src/Magnum/Buffer.h b/src/Magnum/Buffer.h index ed5b72100..f3a963d8d 100644 --- a/src/Magnum/Buffer.h +++ b/src/Magnum/Buffer.h @@ -38,6 +38,7 @@ #include "Magnum/AbstractObject.h" #include "Magnum/Magnum.h" +#include "Magnum/Tags.h" #ifdef MAGNUM_BUILD_DEPRECATED #include @@ -850,11 +851,21 @@ class MAGNUM_EXPORT Buffer: public AbstractObject { * Creates new OpenGL buffer object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the buffer is created on * first use. - * @see @ref wrap(), @fn_gl{CreateBuffers}, eventually - * @fn_gl{GenBuffers} + * @see @ref Buffer(NoCreateT), @ref wrap(), @fn_gl{CreateBuffers}, + * eventually @fn_gl{GenBuffers} */ explicit Buffer(TargetHint targetHint = TargetHint::Array); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref Buffer(TargetHint), @ref wrap() + */ + explicit Buffer(NoCreateT) noexcept; + #ifdef MAGNUM_BUILD_DEPRECATED /** * @copybrief Buffer(TargetHint) @@ -1424,6 +1435,12 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, Buffer::TargetHint value); Debug MAGNUM_EXPORT operator<<(Debug debug, Buffer::Target value); #endif +inline Buffer::Buffer(NoCreateT) noexcept: _id{0}, _targetHint{TargetHint::Array}, _flags{ObjectFlag::DeleteOnDestruction} + #ifdef CORRADE_TARGET_NACL + , _mappedBuffer{nullptr} + #endif +{} + inline Buffer::Buffer(Buffer&& other) noexcept: _id{other._id}, _targetHint{other._targetHint}, #ifdef CORRADE_TARGET_NACL _mappedBuffer{other._mappedBuffer}, diff --git a/src/Magnum/BufferTexture.h b/src/Magnum/BufferTexture.h index 5a56ca6a5..2d05f87f0 100644 --- a/src/Magnum/BufferTexture.h +++ b/src/Magnum/BufferTexture.h @@ -244,11 +244,21 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with @def_gl{TEXTURE_BUFFER}, - * eventually @fn_gl{GenTextures} + * @see @ref BufferTexture(NoCreateT), @ref wrap(), @fn_gl{CreateTextures} + * with @def_gl{TEXTURE_BUFFER}, eventually @fn_gl{GenTextures} */ explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref BufferTexture(), @ref wrap() + */ + explicit BufferTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_BUFFER} {} + /** * @brief Set texture buffer * @param internalFormat Internal format diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index fe0754b69..7769904f2 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -108,6 +108,7 @@ set(Magnum_HEADERS ResourceManager.hpp Sampler.h Shader.h + Tags.h Texture.h TextureFormat.h Timeline.h diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 26c62cb20..20da14b89 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -123,11 +123,21 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with - * @def_gl{TEXTURE_CUBE_MAP}, eventually @fn_gl{GenTextures} + * @see @ref CubeMapTexture(NoCreateT), @ref wrap(), @fn_gl{CreateTextures} + * with @def_gl{TEXTURE_CUBE_MAP}, eventually @fn_gl{GenTextures} */ explicit CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref CubeMapTexture(), @ref wrap() + */ + explicit CubeMapTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_CUBE_MAP} {} + #ifndef MAGNUM_TARGET_GLES2 /** * @copybrief Texture::setBaseLevel() diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index ab590ec7a..27116298e 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/src/Magnum/CubeMapTextureArray.h @@ -116,11 +116,22 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with - * @def_gl{TEXTURE_CUBE_MAP_ARRAY}, eventually @fn_gl{GenTextures} + * @see @ref CubeMapTextureArray(NoCreateT), @ref wrap(), + * @fn_gl{CreateTextures} with @def_gl{TEXTURE_CUBE_MAP_ARRAY}, + * eventually @fn_gl{GenTextures} */ explicit CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref CubeMapTextureArray(), @ref wrap() + */ + explicit CubeMapTextureArray(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_CUBE_MAP_ARRAY} {} + /** * @copybrief Texture::setBaseLevel() * @return Reference to self (for method chaining) diff --git a/src/Magnum/Framebuffer.h b/src/Magnum/Framebuffer.h index 6c7205b75..8a7d961c7 100644 --- a/src/Magnum/Framebuffer.h +++ b/src/Magnum/Framebuffer.h @@ -340,11 +340,21 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractObje * Generates new OpenGL framebuffer object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the framebuffer is created on * first use. - * @see @ref setViewport(), @ref wrap(), @fn_gl{CreateFramebuffers}, - * eventually @fn_gl{GenFramebuffers} + * @see @ref Framebuffer(NoCreateT), @ref wrap(), @ref setViewport(), + * @fn_gl{CreateFramebuffers}, eventually @fn_gl{GenFramebuffers} */ explicit Framebuffer(const Range2Di& viewport); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref Framebuffer(const Range2Di&), @ref wrap() + */ + explicit Framebuffer(NoCreateT) noexcept { _id = 0; } + /** @brief Copying is not allowed */ Framebuffer(const Framebuffer&) = delete; diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index d70a751cf..e1583e727 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -119,6 +119,15 @@ Mesh::Mesh(const MeshPrimitive primitive): _primitive{primitive}, _flags{ObjectF (this->*Context::current()->state().mesh->createImplementation)(); } +Mesh::Mesh(NoCreateT) noexcept: _id{0}, _primitive{MeshPrimitive::Triangles}, _flags{ObjectFlag::DeleteOnDestruction}, _count{0}, _baseVertex{0}, _instanceCount{1}, + #ifndef MAGNUM_TARGET_GLES + _baseInstance{0}, + #endif + #ifndef MAGNUM_TARGET_GLES2 + _indexStart(0), _indexEnd(0), + #endif + _indexOffset(0), _indexType(IndexType::UnsignedInt), _indexBuffer(nullptr) {} + Mesh::~Mesh() { /* Moved out or not deleting on destruction, nothing to do */ if(!_id || !(_flags & ObjectFlag::DeleteOnDestruction)) return; diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index ac3ca38e8..14965c1b9 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -35,6 +35,7 @@ #include "Magnum/AbstractObject.h" #include "Magnum/Attribute.h" +#include "Magnum/Tags.h" #ifdef MAGNUM_BUILD_DEPRECATED #include @@ -461,11 +462,22 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * available, vertex array object is created. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the vertex array object is * created on first use. - * @see @ref setPrimitive(), @ref setCount(), @ref wrap(), - * @fn_gl{CreateVertexArrays}, eventually @fn_gl{GenVertexArrays} + * @see @ref Mesh(NoCreateT), @ref wrap(), @ref setPrimitive(), + * @ref setCount(), @fn_gl{CreateVertexArrays}, eventually + * @fn_gl{GenVertexArrays} */ explicit Mesh(MeshPrimitive primitive = MeshPrimitive::Triangles); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref Mesh(MeshPrimitive), @ref wrap() + */ + explicit Mesh(NoCreateT) noexcept; + /** @brief Copying is not allowed */ Mesh(const Mesh&) = delete; diff --git a/src/Magnum/MultisampleTexture.h b/src/Magnum/MultisampleTexture.h index b57cdf0bc..df5c36414 100644 --- a/src/Magnum/MultisampleTexture.h +++ b/src/Magnum/MultisampleTexture.h @@ -136,13 +136,23 @@ template class MultisampleTexture: public AbstractTextur * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with - * @def_gl{TEXTURE_2D_MULTISAMPLE} or + * @see @ref MultisampleTexture(NoCreateT), @ref wrap(), + * @fn_gl{CreateTextures} with @def_gl{TEXTURE_2D_MULTISAMPLE} or * @def_gl{TEXTURE_2D_MULTISAMPLE_ARRAY}, eventually * @fn_gl{GenTextures} */ explicit MultisampleTexture(): AbstractTexture(Implementation::multisampleTextureTarget()) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref MultisampleTexture(), @ref wrap() + */ + explicit MultisampleTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::multisampleTextureTarget()} {} + /** * @brief Set storage * @param samples Sample count diff --git a/src/Magnum/PrimitiveQuery.h b/src/Magnum/PrimitiveQuery.h index 615e62378..f06724eea 100644 --- a/src/Magnum/PrimitiveQuery.h +++ b/src/Magnum/PrimitiveQuery.h @@ -114,10 +114,21 @@ class PrimitiveQuery: public AbstractQuery { * Creates new OpenGL query object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the query is created on first * use. - * @see @ref wrap(), @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} + * @see @ref PrimitiveQuery(NoCreateT), @ref wrap(), + * @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} */ explicit PrimitiveQuery(Target target): AbstractQuery(GLenum(target)) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref PrimitiveQuery(Target), @ref wrap() + */ + explicit PrimitiveQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::TransformFeedbackPrimitivesWritten)} {} + #ifdef MAGNUM_BUILD_DEPRECATED /** * @copybrief AbstractQuery::begin() diff --git a/src/Magnum/RectangleTexture.h b/src/Magnum/RectangleTexture.h index 19340002a..fceba142d 100644 --- a/src/Magnum/RectangleTexture.h +++ b/src/Magnum/RectangleTexture.h @@ -101,11 +101,22 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with - * @def_gl{TEXTURE_RECTANGLE}, eventually @fn_gl{GenTextures} + * @see @ref RectangleTexture(NoCreateT), @ref wrap(), + * @fn_gl{CreateTextures} with @def_gl{TEXTURE_RECTANGLE}, + * eventually @fn_gl{GenTextures} */ explicit RectangleTexture(): AbstractTexture(GL_TEXTURE_RECTANGLE) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref RectangleTexture(), @ref wrap() + */ + explicit RectangleTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_RECTANGLE} {} + /** * @copybrief Texture::setMinificationFilter() * @return Reference to self (for method chaining) diff --git a/src/Magnum/Renderbuffer.h b/src/Magnum/Renderbuffer.h index d387f36be..f19b3a73a 100644 --- a/src/Magnum/Renderbuffer.h +++ b/src/Magnum/Renderbuffer.h @@ -33,6 +33,7 @@ #include "Magnum/AbstractObject.h" #include "Magnum/Magnum.h" +#include "Magnum/Tags.h" namespace Magnum { @@ -109,11 +110,21 @@ class MAGNUM_EXPORT Renderbuffer: public AbstractObject { * Generates new OpenGL renderbuffer object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the renderbuffer is created * on first use. - * @see @ref wrap(), @fn_gl{CreateRenderbuffers}, eventually - * @fn_gl{GenRenderbuffers} + * @see @ref Renderbuffer(NoCreateT), @ref wrap(), + * @fn_gl{CreateRenderbuffers}, eventually @fn_gl{GenRenderbuffers} */ explicit Renderbuffer(); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref Renderbuffer(), @ref wrap() + */ + explicit Renderbuffer(NoCreateT) noexcept: _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {} + /** @brief Copying is not allowed */ Renderbuffer(const Renderbuffer&) = delete; diff --git a/src/Magnum/SampleQuery.h b/src/Magnum/SampleQuery.h index 7fe518d5f..adb80dc55 100644 --- a/src/Magnum/SampleQuery.h +++ b/src/Magnum/SampleQuery.h @@ -212,10 +212,21 @@ class SampleQuery: public AbstractQuery { * Creates new OpenGL query object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the query is created on first * use. - * @see @ref wrap(), @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} + * @see @ref SampleQuery(NoCreateT), @ref wrap(), @fn_gl{CreateQueries}, + * eventually @fn_gl{GenQueries} */ explicit SampleQuery(Target target): AbstractQuery(GLenum(target)) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref SampleQuery(Target), @ref wrap() + */ + explicit SampleQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::AnySamplesPassed)} {} + #ifdef MAGNUM_BUILD_DEPRECATED /** * @copybrief AbstractQuery::begin() diff --git a/src/Magnum/Tags.h b/src/Magnum/Tags.h new file mode 100644 index 000000000..1cab60360 --- /dev/null +++ b/src/Magnum/Tags.h @@ -0,0 +1,51 @@ +#ifndef Magnum_Tags_h +#define Magnum_Tags_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is 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 Software. + + THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Tag type @ref Magnum::NoCreateT, tag @ref Magnum::NoCreate + */ + +namespace Magnum { + +/** +@brief No creation tag type + +Used to distinguish construction without creating the underlying OpenGL object. +@see @ref NoCreate +*/ +struct NoCreateT {}; + +/** +@brief No creation tag + +Use for construction without creating the underlying OpenGL object. +*/ +constexpr NoCreateT NoCreate{}; + +} + +#endif diff --git a/src/Magnum/Test/BufferGLTest.cpp b/src/Magnum/Test/BufferGLTest.cpp index 9559e4c19..c64b702cc 100644 --- a/src/Magnum/Test/BufferGLTest.cpp +++ b/src/Magnum/Test/BufferGLTest.cpp @@ -38,6 +38,7 @@ struct BufferGLTest: AbstractOpenGLTester { explicit BufferGLTest(); void construct(); + void constructNoCreate(); void constructCopy(); void constructMove(); void wrap(); @@ -64,6 +65,7 @@ struct BufferGLTest: AbstractOpenGLTester { BufferGLTest::BufferGLTest() { addTests({&BufferGLTest::construct, + &BufferGLTest::constructNoCreate, &BufferGLTest::constructCopy, &BufferGLTest::constructMove, &BufferGLTest::wrap, @@ -101,6 +103,17 @@ void BufferGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void BufferGLTest::constructNoCreate() { + { + Buffer buffer{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(buffer.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void BufferGLTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{})); diff --git a/src/Magnum/Test/BufferTextureGLTest.cpp b/src/Magnum/Test/BufferTextureGLTest.cpp index f3f83b6f4..1f0cc66ef 100644 --- a/src/Magnum/Test/BufferTextureGLTest.cpp +++ b/src/Magnum/Test/BufferTextureGLTest.cpp @@ -35,6 +35,7 @@ struct BufferTextureGLTest: AbstractOpenGLTester { explicit BufferTextureGLTest(); void construct(); + void constructNoCreate(); void wrap(); void bind(); @@ -44,6 +45,7 @@ struct BufferTextureGLTest: AbstractOpenGLTester { BufferTextureGLTest::BufferTextureGLTest() { addTests({&BufferTextureGLTest::construct, + &BufferTextureGLTest::constructNoCreate, &BufferTextureGLTest::wrap, &BufferTextureGLTest::bind, @@ -65,6 +67,17 @@ void BufferTextureGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void BufferTextureGLTest::constructNoCreate() { + { + BufferTexture texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void BufferTextureGLTest::wrap() { if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_buffer_object::string() + std::string(" is not supported.")); diff --git a/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp b/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp index c8a42fbab..3282f056c 100644 --- a/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp +++ b/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp @@ -40,6 +40,7 @@ struct CubeMapTextureArrayGLTest: AbstractOpenGLTester { explicit CubeMapTextureArrayGLTest(); void construct(); + void constructNoCreate(); void wrap(); void bind(); @@ -67,6 +68,7 @@ struct CubeMapTextureArrayGLTest: AbstractOpenGLTester { CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() { addTests({&CubeMapTextureArrayGLTest::construct, + &CubeMapTextureArrayGLTest::constructNoCreate, &CubeMapTextureArrayGLTest::wrap, &CubeMapTextureArrayGLTest::bind, @@ -106,6 +108,17 @@ void CubeMapTextureArrayGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void CubeMapTextureArrayGLTest::constructNoCreate() { + { + CubeMapTextureArray texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void CubeMapTextureArrayGLTest::wrap() { if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); diff --git a/src/Magnum/Test/CubeMapTextureGLTest.cpp b/src/Magnum/Test/CubeMapTextureGLTest.cpp index 05d58c547..b1b92b1ac 100644 --- a/src/Magnum/Test/CubeMapTextureGLTest.cpp +++ b/src/Magnum/Test/CubeMapTextureGLTest.cpp @@ -43,6 +43,7 @@ struct CubeMapTextureGLTest: AbstractOpenGLTester { explicit CubeMapTextureGLTest(); void construct(); + void constructNoCreate(); void wrap(); void bind(); @@ -90,6 +91,7 @@ struct CubeMapTextureGLTest: AbstractOpenGLTester { CubeMapTextureGLTest::CubeMapTextureGLTest() { addTests({&CubeMapTextureGLTest::construct, + &CubeMapTextureGLTest::constructNoCreate, &CubeMapTextureGLTest::wrap, &CubeMapTextureGLTest::bind, @@ -146,6 +148,17 @@ void CubeMapTextureGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void CubeMapTextureGLTest::constructNoCreate() { + { + CubeMapTexture texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void CubeMapTextureGLTest::wrap() { GLuint id; glGenTextures(1, &id); diff --git a/src/Magnum/Test/FramebufferGLTest.cpp b/src/Magnum/Test/FramebufferGLTest.cpp index bff01c6dc..99751b770 100644 --- a/src/Magnum/Test/FramebufferGLTest.cpp +++ b/src/Magnum/Test/FramebufferGLTest.cpp @@ -53,6 +53,7 @@ struct FramebufferGLTest: AbstractOpenGLTester { explicit FramebufferGLTest(); void construct(); + void constructNoCreate(); void constructCopy(); void constructMove(); void wrap(); @@ -105,6 +106,7 @@ struct FramebufferGLTest: AbstractOpenGLTester { FramebufferGLTest::FramebufferGLTest() { addTests({&FramebufferGLTest::construct, + &FramebufferGLTest::constructNoCreate, &FramebufferGLTest::constructCopy, &FramebufferGLTest::constructMove, &FramebufferGLTest::wrap, @@ -177,6 +179,17 @@ void FramebufferGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void FramebufferGLTest::constructNoCreate() { + { + Framebuffer framebuffer{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(framebuffer.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void FramebufferGLTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{})); diff --git a/src/Magnum/Test/MeshGLTest.cpp b/src/Magnum/Test/MeshGLTest.cpp index 72dc4bb53..7cb2932fc 100644 --- a/src/Magnum/Test/MeshGLTest.cpp +++ b/src/Magnum/Test/MeshGLTest.cpp @@ -46,6 +46,7 @@ struct MeshGLTest: AbstractOpenGLTester { explicit MeshGLTest(); void construct(); + void constructNoCreate(); void constructCopy(); void constructMove(); void wrap(); @@ -138,6 +139,7 @@ struct MeshGLTest: AbstractOpenGLTester { MeshGLTest::MeshGLTest() { addTests({&MeshGLTest::construct, + &MeshGLTest::constructNoCreate, &MeshGLTest::constructCopy, &MeshGLTest::constructMove, &MeshGLTest::wrap, @@ -247,6 +249,17 @@ void MeshGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void MeshGLTest::constructNoCreate() { + { + Mesh mesh{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(mesh.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void MeshGLTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{})); diff --git a/src/Magnum/Test/MultisampleTextureGLTest.cpp b/src/Magnum/Test/MultisampleTextureGLTest.cpp index e22fe4c3b..3bb390fe5 100644 --- a/src/Magnum/Test/MultisampleTextureGLTest.cpp +++ b/src/Magnum/Test/MultisampleTextureGLTest.cpp @@ -36,8 +36,10 @@ struct MultisampleTextureGLTest: AbstractOpenGLTester { explicit MultisampleTextureGLTest(); void construct2D(); + void construct2DNoCreate(); #ifndef MAGNUM_TARGET_GLES void construct2DArray(); + void construct2DArrayNoCreate(); #endif void wrap2D(); @@ -68,8 +70,10 @@ struct MultisampleTextureGLTest: AbstractOpenGLTester { MultisampleTextureGLTest::MultisampleTextureGLTest() { addTests({&MultisampleTextureGLTest::construct2D, + &MultisampleTextureGLTest::construct2DNoCreate, #ifndef MAGNUM_TARGET_GLES &MultisampleTextureGLTest::construct2DArray, + &MultisampleTextureGLTest::construct2DArrayNoCreate, #endif &MultisampleTextureGLTest::wrap2D, @@ -118,6 +122,17 @@ void MultisampleTextureGLTest::construct2D() { MAGNUM_VERIFY_NO_ERROR(); } +void MultisampleTextureGLTest::construct2DNoCreate() { + { + MultisampleTexture2D texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + #ifndef MAGNUM_TARGET_GLES void MultisampleTextureGLTest::construct2DArray() { if(!Context::current()->isExtensionSupported()) @@ -132,6 +147,17 @@ void MultisampleTextureGLTest::construct2DArray() { MAGNUM_VERIFY_NO_ERROR(); } + +void MultisampleTextureGLTest::construct2DArrayNoCreate() { + { + MultisampleTexture2DArray texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} #endif void MultisampleTextureGLTest::wrap2D() { diff --git a/src/Magnum/Test/PrimitiveQueryGLTest.cpp b/src/Magnum/Test/PrimitiveQueryGLTest.cpp index 73d0f9cf5..e6d105a7c 100644 --- a/src/Magnum/Test/PrimitiveQueryGLTest.cpp +++ b/src/Magnum/Test/PrimitiveQueryGLTest.cpp @@ -40,6 +40,7 @@ namespace Magnum { namespace Test { struct PrimitiveQueryGLTest: AbstractOpenGLTester { explicit PrimitiveQueryGLTest(); + void constructNoCreate(); void wrap(); #ifndef MAGNUM_TARGET_GLES @@ -49,7 +50,8 @@ struct PrimitiveQueryGLTest: AbstractOpenGLTester { }; PrimitiveQueryGLTest::PrimitiveQueryGLTest() { - addTests({&PrimitiveQueryGLTest::wrap, + addTests({&PrimitiveQueryGLTest::constructNoCreate, + &PrimitiveQueryGLTest::wrap, #ifndef MAGNUM_TARGET_GLES &PrimitiveQueryGLTest::primitivesGenerated, @@ -57,6 +59,17 @@ PrimitiveQueryGLTest::PrimitiveQueryGLTest() { &PrimitiveQueryGLTest::transformFeedbackPrimitivesWritten}); } +void PrimitiveQueryGLTest::constructNoCreate() { + { + PrimitiveQuery query{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(query.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void PrimitiveQueryGLTest::wrap() { #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) diff --git a/src/Magnum/Test/RectangleTextureGLTest.cpp b/src/Magnum/Test/RectangleTextureGLTest.cpp index 164f1a4e0..e215a012d 100644 --- a/src/Magnum/Test/RectangleTextureGLTest.cpp +++ b/src/Magnum/Test/RectangleTextureGLTest.cpp @@ -42,6 +42,7 @@ struct RectangleTextureGLTest: AbstractOpenGLTester { explicit RectangleTextureGLTest(); void construct(); + void constructNoCreate(); void wrap(); void bind(); @@ -67,6 +68,7 @@ struct RectangleTextureGLTest: AbstractOpenGLTester { RectangleTextureGLTest::RectangleTextureGLTest() { addTests({&RectangleTextureGLTest::construct, + &RectangleTextureGLTest::constructNoCreate, &RectangleTextureGLTest::wrap, &RectangleTextureGLTest::bind, @@ -105,6 +107,17 @@ void RectangleTextureGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void RectangleTextureGLTest::constructNoCreate() { + { + RectangleTexture texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void RectangleTextureGLTest::wrap() { if(!Context::current()->isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); diff --git a/src/Magnum/Test/RenderbufferGLTest.cpp b/src/Magnum/Test/RenderbufferGLTest.cpp index 6eb2e015e..b591879c7 100644 --- a/src/Magnum/Test/RenderbufferGLTest.cpp +++ b/src/Magnum/Test/RenderbufferGLTest.cpp @@ -36,6 +36,7 @@ struct RenderbufferGLTest: AbstractOpenGLTester { explicit RenderbufferGLTest(); void construct(); + void constructNoCreate(); void constructCopy(); void constructMove(); void wrap(); @@ -48,6 +49,7 @@ struct RenderbufferGLTest: AbstractOpenGLTester { RenderbufferGLTest::RenderbufferGLTest() { addTests({&RenderbufferGLTest::construct, + &RenderbufferGLTest::constructNoCreate, &RenderbufferGLTest::constructCopy, &RenderbufferGLTest::constructMove, &RenderbufferGLTest::wrap, @@ -74,6 +76,17 @@ void RenderbufferGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void RenderbufferGLTest::constructNoCreate() { + { + Renderbuffer renderbuffer{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(renderbuffer.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void RenderbufferGLTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{})); diff --git a/src/Magnum/Test/SampleQueryGLTest.cpp b/src/Magnum/Test/SampleQueryGLTest.cpp index d218c2fd3..fbb7e91db 100644 --- a/src/Magnum/Test/SampleQueryGLTest.cpp +++ b/src/Magnum/Test/SampleQueryGLTest.cpp @@ -41,6 +41,7 @@ namespace Magnum { namespace Test { struct SampleQueryGLTest: AbstractOpenGLTester { explicit SampleQueryGLTest(); + void constructNoCreate(); void wrap(); void querySamplesPassed(); @@ -50,7 +51,8 @@ struct SampleQueryGLTest: AbstractOpenGLTester { }; SampleQueryGLTest::SampleQueryGLTest() { - addTests({&SampleQueryGLTest::wrap, + addTests({&SampleQueryGLTest::constructNoCreate, + &SampleQueryGLTest::wrap, &SampleQueryGLTest::querySamplesPassed, #ifndef MAGNUM_TARGET_GLES @@ -59,6 +61,17 @@ SampleQueryGLTest::SampleQueryGLTest() { }); } +void SampleQueryGLTest::constructNoCreate() { + { + SampleQuery query{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(query.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void SampleQueryGLTest::wrap() { #ifdef MAGNUM_TARGET_GLES2 if(!Context::current()->isExtensionSupported()) diff --git a/src/Magnum/Test/TextureArrayGLTest.cpp b/src/Magnum/Test/TextureArrayGLTest.cpp index 57d0a957a..ebeeeda31 100644 --- a/src/Magnum/Test/TextureArrayGLTest.cpp +++ b/src/Magnum/Test/TextureArrayGLTest.cpp @@ -42,8 +42,10 @@ struct TextureArrayGLTest: AbstractOpenGLTester { #ifndef MAGNUM_TARGET_GLES void construct1D(); + void construct1DNoCreate(); #endif void construct2D(); + void construct2DNoCreate(); #ifndef MAGNUM_TARGET_GLES void wrap1D(); @@ -134,8 +136,10 @@ TextureArrayGLTest::TextureArrayGLTest() { addTests({ #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::construct1D, + &TextureArrayGLTest::construct1DNoCreate, #endif &TextureArrayGLTest::construct2D, + &TextureArrayGLTest::construct2DNoCreate, #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::wrap1D, @@ -231,6 +235,17 @@ void TextureArrayGLTest::construct1D() { MAGNUM_VERIFY_NO_ERROR(); } + +void TextureArrayGLTest::construct1DNoCreate() { + { + Texture1DArray texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} #endif void TextureArrayGLTest::construct2D() { @@ -249,6 +264,17 @@ void TextureArrayGLTest::construct2D() { MAGNUM_VERIFY_NO_ERROR(); } +void TextureArrayGLTest::construct2DNoCreate() { + { + Texture2DArray texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + #ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::wrap1D() { GLuint id; diff --git a/src/Magnum/Test/TextureGLTest.cpp b/src/Magnum/Test/TextureGLTest.cpp index b2dcd6ba0..0161ff516 100644 --- a/src/Magnum/Test/TextureGLTest.cpp +++ b/src/Magnum/Test/TextureGLTest.cpp @@ -44,9 +44,12 @@ struct TextureGLTest: AbstractOpenGLTester { #ifndef MAGNUM_TARGET_GLES void construct1D(); + void construct1DNoCreate(); #endif void construct2D(); + void construct2DNoCreate(); void construct3D(); + void construct3DNoCreate(); #ifndef MAGNUM_TARGET_GLES void wrap1D(); @@ -165,9 +168,12 @@ TextureGLTest::TextureGLTest() { addTests({ #ifndef MAGNUM_TARGET_GLES &TextureGLTest::construct1D, + &TextureGLTest::construct1DNoCreate, #endif &TextureGLTest::construct2D, + &TextureGLTest::construct2DNoCreate, &TextureGLTest::construct3D, + &TextureGLTest::construct3DNoCreate, #ifndef MAGNUM_TARGET_GLES &TextureGLTest::wrap1D, @@ -292,6 +298,17 @@ void TextureGLTest::construct1D() { MAGNUM_VERIFY_NO_ERROR(); } + +void TextureGLTest::construct1DNoCreate() { + { + Texture1D texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} #endif void TextureGLTest::construct2D() { @@ -305,6 +322,17 @@ void TextureGLTest::construct2D() { MAGNUM_VERIFY_NO_ERROR(); } +void TextureGLTest::construct2DNoCreate() { + { + Texture2D texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void TextureGLTest::construct3D() { #ifdef MAGNUM_TARGET_GLES2 if(!Context::current()->isExtensionSupported()) @@ -321,6 +349,17 @@ void TextureGLTest::construct3D() { MAGNUM_VERIFY_NO_ERROR(); } +void TextureGLTest::construct3DNoCreate() { + { + Texture3D texture{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(texture.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + #ifndef MAGNUM_TARGET_GLES void TextureGLTest::wrap1D() { GLuint id; diff --git a/src/Magnum/Test/TransformFeedbackGLTest.cpp b/src/Magnum/Test/TransformFeedbackGLTest.cpp index 04e151330..8cdcf7870 100644 --- a/src/Magnum/Test/TransformFeedbackGLTest.cpp +++ b/src/Magnum/Test/TransformFeedbackGLTest.cpp @@ -37,6 +37,7 @@ struct TransformFeedbackGLTest: AbstractOpenGLTester { explicit TransformFeedbackGLTest(); void construct(); + void constructNoCreate(); void constructCopy(); void constructMove(); void wrap(); @@ -55,6 +56,7 @@ struct TransformFeedbackGLTest: AbstractOpenGLTester { TransformFeedbackGLTest::TransformFeedbackGLTest() { addTests({&TransformFeedbackGLTest::construct, + &TransformFeedbackGLTest::constructNoCreate, &TransformFeedbackGLTest::constructCopy, &TransformFeedbackGLTest::constructMove, &TransformFeedbackGLTest::wrap, @@ -88,6 +90,17 @@ void TransformFeedbackGLTest::construct() { MAGNUM_VERIFY_NO_ERROR(); } +void TransformFeedbackGLTest::constructNoCreate() { + { + TransformFeedback feedback{NoCreate}; + + MAGNUM_VERIFY_NO_ERROR(); + CORRADE_COMPARE(feedback.id(), 0); + } + + MAGNUM_VERIFY_NO_ERROR(); +} + void TransformFeedbackGLTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{})); diff --git a/src/Magnum/Text/Test/RendererGLTest.cpp b/src/Magnum/Text/Test/RendererGLTest.cpp index 03b4cd39a..012930460 100644 --- a/src/Magnum/Text/Test/RendererGLTest.cpp +++ b/src/Magnum/Text/Test/RendererGLTest.cpp @@ -172,7 +172,7 @@ void RendererGLTest::renderData() { void RendererGLTest::renderMesh() { TestFont font; - Mesh mesh; + Mesh mesh{NoCreate}; Buffer vertexBuffer, indexBuffer; Range2D bounds; std::tie(mesh, bounds) = Text::Renderer3D::render(font, nullGlyphCache, @@ -220,7 +220,7 @@ void RendererGLTest::renderMesh() { void RendererGLTest::renderMeshIndexType() { #ifndef MAGNUM_TARGET_GLES TestFont font; - Mesh mesh; + Mesh mesh{NoCreate}; Buffer vertexBuffer, indexBuffer; /* Sizes: four vertices per glyph, each vertex has 2D position and 2D diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index 45cf1b60f..3c26ba806 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -145,12 +145,22 @@ template class Texture: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with @def_gl{TEXTURE_1D}, - * @def_gl{TEXTURE_2D} or @def_gl{TEXTURE_3D}, eventually - * @fn_gl{GenTextures} + * @see @ref Texture(NoCreateT), @ref wrap(), @fn_gl{CreateTextures} + * with @def_gl{TEXTURE_1D}, @def_gl{TEXTURE_2D} or + * @def_gl{TEXTURE_3D}, eventually @fn_gl{GenTextures} */ explicit Texture(): AbstractTexture(Implementation::textureTarget()) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref Texture(), @ref wrap() + */ + explicit Texture(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::textureTarget()} {} + #ifndef MAGNUM_TARGET_GLES2 /** * @brief Set base mip level diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index 9673b7737..85894bb56 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -133,12 +133,22 @@ template class TextureArray: public AbstractTexture { * Creates new OpenGL texture object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the texture is created on * first use. - * @see @ref wrap(), @fn_gl{CreateTextures} with - * @def_gl{TEXTURE_1D_ARRAY} or @def_gl{TEXTURE_2D_ARRAY}, + * @see @ref TextureArray(NoCreateT), @ref wrap(), @fn_gl{CreateTextures} + * with @def_gl{TEXTURE_1D_ARRAY} or @def_gl{TEXTURE_2D_ARRAY}, * eventually @fn_gl{GenTextures} */ explicit TextureArray(): AbstractTexture(Implementation::textureArrayTarget()) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref TextureArray(), @ref wrap() + */ + explicit TextureArray(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::textureArrayTarget()} {} + /** * @copybrief Texture::setBaseLevel() * @return Reference to self (for method chaining) diff --git a/src/Magnum/TimeQuery.h b/src/Magnum/TimeQuery.h index 25ab2cd3f..309e33aee 100644 --- a/src/Magnum/TimeQuery.h +++ b/src/Magnum/TimeQuery.h @@ -126,10 +126,21 @@ class TimeQuery: public AbstractQuery { * Creates new OpenGL query object. If @extension{ARB,direct_state_access} * (part of OpenGL 4.5) is not available, the query is created on first * use. - * @see @ref wrap(), @fn_gl{CreateQueries}, eventually @fn_gl{GenQueries} + * @see @ref TimeQuery(NoCreateT), @ref wrap(), @fn_gl{CreateQueries}, + * eventually @fn_gl{GenQueries} */ explicit TimeQuery(Target target): AbstractQuery(GLenum(target)) {} + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref TimeQuery(Target), @ref wrap() + */ + explicit TimeQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::TimeElapsed)} {} + /** * @brief Query timestamp * diff --git a/src/Magnum/TransformFeedback.h b/src/Magnum/TransformFeedback.h index 1c8f803ea..87a259c0d 100644 --- a/src/Magnum/TransformFeedback.h +++ b/src/Magnum/TransformFeedback.h @@ -28,6 +28,7 @@ #include #include "Magnum/AbstractObject.h" +#include "Magnum/Tags.h" #ifndef MAGNUM_TARGET_GLES2 /** @file @@ -168,11 +169,22 @@ class MAGNUM_EXPORT TransformFeedback: public AbstractObject { * Creates new OpenGL transform feedback object. If * @extension{ARB,direct_state_access} (part of OpenGL 4.5) is not * available, the transform feedback object is created on first use. - * @see @ref wrap(), @fn_gl{CreateTransformFeedbacks}, eventually + * @see @ref TransformFeedback(NoCreateT), @ref wrap(), + * @fn_gl{CreateTransformFeedbacks}, eventually * @fn_gl{GenTransformFeedbacks} */ explicit TransformFeedback(); + /** + * @brief Construct without creating the underlying OpenGL object + * + * The constructed instance is equivalent to moved-from state. Useful + * in cases where you will overwrite the instance later anyway. Move + * another object over it to make it useful. + * @see @ref TransformFeedback(), @ref wrap() + */ + explicit TransformFeedback(NoCreateT) noexcept: _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {} + /** @brief Copying is not allowed */ TransformFeedback(const TransformFeedback&) = delete;