YourGameLib
Loading...
Searching...
No Matches
geometry.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2025 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_GLGEOMETRY_H
21#define YOURGAME_GLGEOMETRY_H
22
23#include <string>
24#include <map>
25#include <vector>
26#include "yourgame/gl_include.h"
27
28namespace yourgame
29{
30 namespace gl
31 {
33 {
34 public:
36 {
37 GLuint index;
38 GLint size;
39 GLenum type;
40 GLboolean normalized;
41 GLsizei stride;
42 const GLvoid *pointer;
44 };
45
47 {
48 GLenum type;
49 GLenum drawMode;
50 GLsizei numElements;
51 };
52
53 static Geometry *make();
54 ~Geometry();
55
56 bool addArrayBuffer(std::string name,
57 GLsizeiptr size,
58 const GLvoid *data,
59 GLenum usage,
60 ArrayBufferDescriptor descriptor);
61
62 bool bufferArrayData(std::string name, GLsizeiptr size, const GLvoid *data);
63
64 bool setElementArrayBuffer(GLsizeiptr size,
65 const GLvoid *data,
66 GLenum usage,
68
69 bool init();
70
71 void draw() const;
72 void drawInstanced(GLsizei instancecount) const;
73
74 /* deleting the copy constructor and the copy assignment operator
75 prevents copying (and moving) of the object. */
76 Geometry(Geometry const &) = delete;
77 Geometry &operator=(Geometry const &) = delete;
78
79 private:
80 class Buffer
81 {
82 public:
83 static Buffer *make(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
84 ~Buffer();
85 void bind();
86 void unbindTarget();
87 bool bufferData(GLsizeiptr size, const GLvoid *data);
88
89 /* deleting the copy constructor and the copy assignment operator
90 prevents copying (and moving) of the object. */
91 Buffer(Buffer const &) = delete;
92 Buffer &operator=(Buffer const &) = delete;
93
94 private:
95 Buffer() {}
96 GLenum m_target;
97 GLuint m_handle;
98 GLenum m_usage;
99 };
100
101 struct ArrayBuffer
102 {
103 Buffer *buffer = nullptr;
104 ArrayBufferDescriptor descriptor;
105 };
106
107 struct ElementArrayBuffer
108 {
109 Buffer *buffer = nullptr;
110 ElementArrayBufferDescriptor descriptor;
111 };
112
113 Geometry() {}
114 std::map<std::string, ArrayBuffer> m_arrayBuffers;
115 ElementArrayBuffer m_elementArrayBuffer;
116 GLuint m_vaoHandle = 0;
117 };
118 } // namespace gl
119} // namespace yourgame
120
121#endif
Definition geometry.h:33
Geometry(Geometry const &)=delete
bool addArrayBuffer(std::string name, GLsizeiptr size, const GLvoid *data, GLenum usage, ArrayBufferDescriptor descriptor)
Definition geometry.cpp:50
void draw() const
Definition geometry.cpp:139
bool setElementArrayBuffer(GLsizeiptr size, const GLvoid *data, GLenum usage, ElementArrayBufferDescriptor descriptor)
Definition geometry.cpp:69
bool init()
Definition geometry.cpp:101
bool bufferArrayData(std::string name, GLsizeiptr size, const GLvoid *data)
Definition geometry.cpp:91
~Geometry()
Definition geometry.cpp:31
Geometry & operator=(Geometry const &)=delete
static Geometry * make()
Definition geometry.cpp:26
void drawInstanced(GLsizei instancecount) const
Definition geometry.cpp:149
Definition audio.h:27
const GLvoid * pointer
Definition geometry.h:42
GLuint attribDivisor
Definition geometry.h:43
GLboolean normalized
Definition geometry.h:40
GLenum type
Definition geometry.h:39
GLint size
Definition geometry.h:38
GLsizei stride
Definition geometry.h:41
GLuint index
Definition geometry.h:37