Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
GraphicsHandle.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_GRAPHICS_HANDLE_H
22#define GF_GRAPHICS_HANDLE_H
23
24#include <utility>
25
26#include "Types.h"
27
28namespace gf {
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30inline namespace v1 {
31#endif
32
37 enum class GraphicsTag {
38 Buffer,
40 Texture,
41 };
42
47 template<GraphicsTag Tag>
49
56 template<GraphicsTag Tag>
58 public:
65 : m_name()
66 {
67 GraphicsTrait<Tag>::gen(1, &m_name);
68 }
69
75 constexpr GraphicsHandle(NoneType) noexcept
76 : m_name(0)
77 {
78 }
79
83 ~GraphicsHandle() noexcept {
84 if (m_name != 0) {
85 GraphicsTrait<Tag>::del(1, &m_name);
86 }
87 }
88
93
98
105 : m_name(std::exchange(other.m_name, 0))
106 {
107 }
108
116 std::swap(m_name, other.m_name);
117 return *this;
118 }
119
125 bool isValid() const noexcept {
126 return m_name != 0;
127 }
128
134 unsigned getName() const noexcept {
135 return m_name;
136 }
137
143 operator unsigned () const noexcept {
144 return m_name;
145 }
146
147 private:
148 unsigned m_name;
149 };
150
151#ifndef DOXYGEN_SHOULD_SKIP_THIS
152}
153#endif
154}
155
156#endif // GF_GRAPHICS_HANDLE_H
A GL handle.
Definition: GraphicsHandle.h:57
GraphicsHandle()
Constructor.
Definition: GraphicsHandle.h:64
bool isValid() const noexcept
Check if the handle is valid.
Definition: GraphicsHandle.h:125
unsigned getName() const noexcept
Get the underlying name of the handle.
Definition: GraphicsHandle.h:134
GraphicsHandle & operator=(GraphicsHandle &&other) noexcept
Move assignment.
Definition: GraphicsHandle.h:115
~GraphicsHandle() noexcept
Destructor.
Definition: GraphicsHandle.h:83
constexpr GraphicsHandle(NoneType) noexcept
Constructor.
Definition: GraphicsHandle.h:75
GraphicsHandle & operator=(const GraphicsHandle &)=delete
Deleted copy assignment.
GraphicsHandle(GraphicsHandle &&other) noexcept
Move constructor.
Definition: GraphicsHandle.h:104
GraphicsHandle(const GraphicsHandle &)=delete
Deleted copy constructor.
A texture for colored images.
Definition: Texture.h:313
GraphicsTag
A tag to represent various GPU resources.
Definition: GraphicsHandle.h:37
@ Framebuffer
A GPU framebuffer.
@ Buffer
A GPU buffer.
The namespace for gf classes.
A trait to handle creation and deletion of GPU resources.
Definition: GraphicsHandle.h:48
Semantic type to represent "none".
Definition: Types.h:37