Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1
11
12#ifndef FOOLSENGINE_MESH_H
13#define FOOLSENGINE_MESH_H
14
15#include <vector>
16#include <map>
17#include <queue>
18#include <memory>
19
20#include <GL/glew.h>
21
22#include <assimp/scene.h>
23
25#include "vertex.hpp"
26
27namespace ToyMaker {
33 class StaticMesh: public Resource<StaticMesh> {
34 public:
44 StaticMesh(const std::vector<BuiltinVertexData>& mVertices, const std::vector<GLuint>& mElements, GLuint vertexBuffer=0, GLuint elementBuffer=0, bool isUploaded=false);
45
47 StaticMesh(const StaticMesh& other);
48
50 StaticMesh& operator=(const StaticMesh& other);
51
53 StaticMesh(StaticMesh&& other);
54
57
60
66 GLuint getElementCount() {
67 return mElements.size();
68 }
69
75 void bind(const VertexLayout& shaderVertexLayout);
76
81 void unbind();
82
88 std::vector<BuiltinVertexData>::iterator getVertexListBegin();
89
95 std::vector<BuiltinVertexData>::iterator getVertexListEnd();
96
102 std::vector<BuiltinVertexData>::const_iterator getVertexListBegin() const;
103
109 std::vector<BuiltinVertexData>::const_iterator getVertexListEnd() const;
110
117
123 inline static std::string getResourceTypeName() { return "StaticMesh"; }
124
125
126 private:
127
134 void setAttributePointers(const VertexLayout& shaderVertexLayout, std::size_t startingOffset=0);
135
140 std::vector<BuiltinVertexData> mVertices {};
147 std::vector<GLuint> mElements {};
148
154
159 bool mIsUploaded { false };
160
165 GLuint mVertexBuffer { 0 };
166
171 GLuint mElementBuffer { 0 };
172
177 void upload();
178
183 void unload();
184
189 void destroyResource();
190
195 void releaseResource();
196 };
197
247 class StaticMeshFromDescription: public ResourceConstructor<StaticMesh, StaticMeshFromDescription> {
248 public:
249
257
264 inline static std::string getResourceConstructorName(){ return "fromDescription"; }
265
266 private:
267
275 std::shared_ptr<IResource> createResource(const nlohmann::json& methodParameters) override;
276 };
277}
278
279#endif
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:491
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:389
StaticMeshFromDescription()
Creates this StaticMesh constructor.
Definition mesh.hpp:254
static std::string getResourceConstructorName()
Gets the constructor type string for this constructor.
Definition mesh.hpp:264
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParameters) override
The method responsible for actually creating a StaticMesh.
Definition mesh.cpp:220
A class whose current main purpose is to store geometry related info, and to upload it to GPU memory ...
Definition mesh.hpp:33
StaticMesh(const std::vector< BuiltinVertexData > &mVertices, const std::vector< GLuint > &mElements, GLuint vertexBuffer=0, GLuint elementBuffer=0, bool isUploaded=false)
Constructs a new static mesh object.
Definition mesh.cpp:15
std::vector< BuiltinVertexData >::iterator getVertexListEnd()
Gets an iterator to the end of this object's vertex list.
Definition mesh.cpp:238
void unload()
Deallocates vertex and element data belonging to this object from the GPU.
Definition mesh.cpp:192
void setAttributePointers(const VertexLayout &shaderVertexLayout, std::size_t startingOffset=0)
Specifies the offsets of vertex attributes per the vertex layout requested by a shader.
Definition mesh.cpp:133
void bind(const VertexLayout &shaderVertexLayout)
Binds this object's vertex data according to the vertex layout specified by the shader program.
Definition mesh.cpp:90
GLuint getElementCount()
Returns number of elements in the elements array for this mesh.
Definition mesh.hpp:66
GLuint mVertexBuffer
The OpenGL vertex buffer handle for this object, if it has been uploaded to GPU memory.
Definition mesh.hpp:165
void releaseResource()
Loses references to resources owned by this object, allowing another object to take ownership of them...
Definition mesh.cpp:207
void unbind()
Unbinds this object's vertex data.
Definition mesh.cpp:187
void destroyResource()
Deallocates related GPU buffers and releases resources owned by this object.
Definition mesh.cpp:203
std::vector< BuiltinVertexData >::iterator getVertexListBegin()
Gets an iterator to the beginning of this object's vertex list.
Definition mesh.cpp:232
VertexLayout getVertexLayout() const
Gets the vertex layout associated with this object, that of BuiltinVertexData.
Definition mesh.cpp:216
void upload()
Uploads the vertex and element data for this object to the GPU.
Definition mesh.cpp:107
std::vector< BuiltinVertexData > mVertices
This object's vertex data.
Definition mesh.hpp:140
bool mIsUploaded
Marker for whether the data in this object has been uploaded to the GPU.
Definition mesh.hpp:159
VertexLayout mVertexLayout
The vertex layout associated with this mesh, same as BuiltinVertexData's vertex layout.
Definition mesh.hpp:153
GLuint mElementBuffer
The OpenGL element buffer handle for this object, if it has been uploaded to GPU memory.
Definition mesh.hpp:171
static std::string getResourceTypeName()
Gets the resource type string for this object.
Definition mesh.hpp:123
StaticMesh & operator=(const StaticMesh &other)
Copy assignment operator.
Definition mesh.cpp:75
~StaticMesh()
Destructor.
Definition mesh.cpp:31
std::vector< GLuint > mElements
This object's element list.
Definition mesh.hpp:147
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Headers relating to resources and their management for a given project.
A list of attribute descriptors that together define the layout and size of the vertex they make up i...
Definition vertex.hpp:141
Contains engine's built-in vertex definitions, along with their associated attribute locations in the...