Skip to content

Commit

Permalink
doc: hint that Optional is a safer NoCreate.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Oct 19, 2019
1 parent 82f5386 commit d06914a
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/opengl-wrapping.dox
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ you know you would overwrite it later with another object:

@snippet MagnumGL.cpp opengl-wrapping-nocreate

<b></b>

@m_class{m-note m-warning}

@par
Note that calling anything on objects created this way is not defined (and
not checked or guarded in any way) and may result in crashes. If you want delayed object creation with safety checks (however with some extra
memory overhead), wrap the objects in an @ref Corrade::Containers::Optional.

If you need to preserve the underlying OpenGL object after destruction, you can
call @cpp release() @ce. It returns ID of the underlying object, the instance
is then equivalent to moved-from state and you are responsible for proper
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/AbstractShaderProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ class MAGNUM_GL_EXPORT AbstractShaderProgram: public AbstractObject {
*
* 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 AbstractShaderProgram()
*/
explicit AbstractShaderProgram(NoCreateT) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
*
* 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 Buffer(TargetHint), @ref wrap()
*/
explicit Buffer(NoCreateT) noexcept;
Expand Down
7 changes: 7 additions & 0 deletions src/Magnum/GL/BufferImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ template<UnsignedInt dimensions> class BufferImage {
*
* 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 BufferImage(), @ref Buffer::wrap()
*/
explicit BufferImage(NoCreateT) noexcept;
Expand Down Expand Up @@ -561,6 +563,11 @@ template<UnsignedInt dimensions> class CompressedBufferImage {
* 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 CompressedBufferImage(), @ref Buffer::wrap()
*/
explicit CompressedBufferImage(NoCreateT) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/BufferTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class MAGNUM_GL_EXPORT BufferTexture: public AbstractTexture {
*
* 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 BufferTexture(), @ref wrap()
*/
explicit BufferTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_BUFFER} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/CubeMapTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class MAGNUM_GL_EXPORT CubeMapTexture: public AbstractTexture {
*
* 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 CubeMapTexture(), @ref wrap()
*/
explicit CubeMapTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_CUBE_MAP} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/CubeMapTextureArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class MAGNUM_GL_EXPORT CubeMapTextureArray: public AbstractTexture {
*
* 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 CubeMapTextureArray(), @ref wrap()
*/
explicit CubeMapTextureArray(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_CUBE_MAP_ARRAY} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ class MAGNUM_GL_EXPORT Framebuffer: public AbstractFramebuffer, public AbstractO
*
* 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 Framebuffer(const Range2Di&), @ref wrap()
*/
explicit Framebuffer(NoCreateT) noexcept: AbstractFramebuffer{{}, {}, {}} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
*
* 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 Mesh(MeshPrimitive), @ref wrap()
*/
explicit Mesh(NoCreateT) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/MultisampleTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTextur
*
* 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 MultisampleTexture(), @ref wrap()
*/
explicit MultisampleTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::multisampleTextureTarget<dimensions>()} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/PrimitiveQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class MAGNUM_GL_EXPORT PrimitiveQuery: public AbstractQuery {
*
* 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 PrimitiveQuery(Target), @ref wrap()
*/
explicit PrimitiveQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::TransformFeedbackPrimitivesWritten)} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/RectangleTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class MAGNUM_GL_EXPORT RectangleTexture: public AbstractTexture {
*
* 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 RectangleTexture(), @ref wrap()
*/
explicit RectangleTexture(NoCreateT) noexcept: AbstractTexture{NoCreate, GL_TEXTURE_RECTANGLE} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/Renderbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class MAGNUM_GL_EXPORT Renderbuffer: public AbstractObject {
*
* 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 Renderbuffer(), @ref wrap()
*/
explicit Renderbuffer(NoCreateT) noexcept: _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/SampleQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class SampleQuery: public AbstractQuery {
*
* 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 SampleQuery(Target), @ref wrap()
*/
explicit SampleQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::AnySamplesPassed)} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
*
* 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 Texture(), @ref wrap()
*/
explicit Texture(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::textureTarget<dimensions>()} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/TextureArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
*
* 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 TextureArray(), @ref wrap()
*/
explicit TextureArray(NoCreateT) noexcept: AbstractTexture{NoCreate, Implementation::textureArrayTarget<dimensions>()} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/TimeQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class TimeQuery: public AbstractQuery {
*
* 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 TimeQuery(Target), @ref wrap()
*/
explicit TimeQuery(NoCreateT) noexcept: AbstractQuery{NoCreate, GLenum(Target::TimeElapsed)} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/GL/TransformFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class MAGNUM_GL_EXPORT TransformFeedback: public AbstractObject {
*
* 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 TransformFeedback(), @ref wrap()
*/
explicit TransformFeedback(NoCreateT) noexcept: _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {}
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/DistanceFieldVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
*
* 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.
*/
explicit DistanceFieldVector(NoCreateT) noexcept
/** @todoc remove workaround when doxygen is sane */
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/Flat.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public GL::Ab
*
* 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.
*/
explicit Flat(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}

Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/MeshVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram {
*
* 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.
*/
explicit MeshVisualizer(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}

Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/Phong.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram {
*
* 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.
*/
explicit Phong(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}

Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
*
* 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.
*/
explicit Vector(NoCreateT) noexcept
/** @todoc remove workaround when doxygen is sane */
Expand Down
2 changes: 2 additions & 0 deletions src/Magnum/Shaders/VertexColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public
*
* 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.
*/
explicit VertexColor(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {}

Expand Down
6 changes: 5 additions & 1 deletion src/Magnum/Tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ struct NoCreateT {
/**
@brief No creation tag
Use for construction without creating the underlying OpenGL object.
Use for construction without creating the underlying OpenGL object. Note that
calling anything on objects created this way is not defined (and not checked or
guarded in any way) and may result in crashes. If you want delayed object
creation with safety checks (however with some extra memory overhead), wrap
the objects in an @ref Corrade::Containers::Optional.
*/
constexpr NoCreateT NoCreate{NoCreateT::Init{}};

Expand Down

0 comments on commit d06914a

Please sign in to comment.