Browse Source

GL: add a NoCreate Shader constructor.

It wasn't there because I thought it was not needed. I need it now.
pull/430/head
Vladimír Vondruš 6 years ago
parent
commit
e455a6731a
  1. 2
      doc/changelog.dox
  2. 16
      src/Magnum/GL/Shader.h
  3. 13
      src/Magnum/GL/Test/ShaderTest.cpp

2
doc/changelog.dox

@ -107,6 +107,8 @@ See also:
- New @ref GL::Buffer::Buffer(Containers::ArrayView<const void>, BufferUsage) - New @ref GL::Buffer::Buffer(Containers::ArrayView<const void>, BufferUsage)
constructor for directly creating buffers filled with data. constructor for directly creating buffers filled with data.
- New @ref GL::Mesh::maxVertexAttributeStride() limit query - 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 @subsubsection changelog-latest-new-math Math library

16
src/Magnum/GL/Shader.h

@ -33,6 +33,7 @@
#include <vector> #include <vector>
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include "Magnum/Tags.h"
#include "Magnum/GL/AbstractObject.h" #include "Magnum/GL/AbstractObject.h"
#include "Magnum/GL/GL.h" #include "Magnum/GL/GL.h"
@ -512,6 +513,21 @@ class MAGNUM_GL_EXPORT Shader: public AbstractObject {
*/ */
explicit Shader(Version version, Type type); 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 */ /** @brief Copying is not allowed */
Shader(const Shader&) = delete; Shader(const Shader&) = delete;

13
src/Magnum/GL/Test/ShaderTest.cpp

@ -34,15 +34,26 @@ namespace Magnum { namespace GL { namespace Test { namespace {
struct ShaderTest: TestSuite::Tester { struct ShaderTest: TestSuite::Tester {
explicit ShaderTest(); explicit ShaderTest();
void constructNoCreate();
void constructCopy(); void constructCopy();
void debugType(); void debugType();
}; };
ShaderTest::ShaderTest() { ShaderTest::ShaderTest() {
addTests({&ShaderTest::constructCopy, addTests({&ShaderTest::constructNoCreate,
&ShaderTest::constructCopy,
&ShaderTest::debugType}); &ShaderTest::debugType});
} }
void ShaderTest::constructNoCreate() {
{
Shader shader{NoCreate};
CORRADE_COMPARE(shader.id(), 0);
}
CORRADE_VERIFY(true);
}
void ShaderTest::constructCopy() { void ShaderTest::constructCopy() {
CORRADE_VERIFY(!(std::is_constructible<Shader, const Shader&>{})); CORRADE_VERIFY(!(std::is_constructible<Shader, const Shader&>{}));
CORRADE_VERIFY(!(std::is_assignable<Shader, const Shader&>{})); CORRADE_VERIFY(!(std::is_assignable<Shader, const Shader&>{}));

Loading…
Cancel
Save