diff --git a/doc/changelog.dox b/doc/changelog.dox index 041ee7a07..384727118 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -107,6 +107,8 @@ See also: - New @ref GL::Buffer::Buffer(Containers::ArrayView, BufferUsage) constructor for directly creating buffers filled with data. - New @ref GL::Mesh::maxVertexAttributeStride() limit query +- Added a @ref GL::Shader::Shader(NoCreateT) constructor for consistency with + other OpenGL wrapper objects @subsubsection changelog-latest-new-math Math library diff --git a/src/Magnum/GL/Shader.h b/src/Magnum/GL/Shader.h index b8428e0c4..68ed604a3 100644 --- a/src/Magnum/GL/Shader.h +++ b/src/Magnum/GL/Shader.h @@ -33,6 +33,7 @@ #include #include +#include "Magnum/Tags.h" #include "Magnum/GL/AbstractObject.h" #include "Magnum/GL/GL.h" @@ -512,6 +513,21 @@ class MAGNUM_GL_EXPORT Shader: public AbstractObject { */ explicit Shader(Version version, Type type); + /** + * @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. + * + * This function can be safely used for constructing (and later + * destructing) objects even without any OpenGL context being active. + * However note that this is a low-level and a potentially dangerous + * API, see the documentation of @ref NoCreate for alternatives. + * @see @ref Shader() + */ + explicit Shader(NoCreateT) noexcept: _type{}, _id{0} {} + /** @brief Copying is not allowed */ Shader(const Shader&) = delete; diff --git a/src/Magnum/GL/Test/ShaderTest.cpp b/src/Magnum/GL/Test/ShaderTest.cpp index 6b1f9fd91..b37fa1b3c 100644 --- a/src/Magnum/GL/Test/ShaderTest.cpp +++ b/src/Magnum/GL/Test/ShaderTest.cpp @@ -34,15 +34,26 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct ShaderTest: TestSuite::Tester { explicit ShaderTest(); + void constructNoCreate(); void constructCopy(); void debugType(); }; ShaderTest::ShaderTest() { - addTests({&ShaderTest::constructCopy, + addTests({&ShaderTest::constructNoCreate, + &ShaderTest::constructCopy, &ShaderTest::debugType}); } +void ShaderTest::constructNoCreate() { + { + Shader shader{NoCreate}; + CORRADE_COMPARE(shader.id(), 0); + } + + CORRADE_VERIFY(true); +} + void ShaderTest::constructCopy() { CORRADE_VERIFY(!(std::is_constructible{})); CORRADE_VERIFY(!(std::is_assignable{}));