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
ToyMaker::StaticMesh Class Reference

A class whose current main purpose is to store geometry related info, and to upload it to GPU memory when requested. More...

#include <mesh.hpp>

Inheritance diagram for ToyMaker::StaticMesh:
ToyMaker::Resource< StaticMesh > ToyMaker::IResource

Public Member Functions

 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.
 
 StaticMesh (const StaticMesh &other)
 Copy constructor.
 
StaticMeshoperator= (const StaticMesh &other)
 Copy assignment operator.
 
 StaticMesh (StaticMesh &&other)
 Move constructor.
 
StaticMeshoperator= (StaticMesh &&other)
 Move assignment operator.
 
 ~StaticMesh ()
 Destructor.
 
GLuint getElementCount ()
 Returns number of elements in the elements array for this mesh.
 
void bind (const VertexLayout &shaderVertexLayout)
 Binds this object's vertex data according to the vertex layout specified by the shader program.
 
void unbind ()
 Unbinds this object's vertex data.
 
std::vector< BuiltinVertexData >::iterator getVertexListBegin ()
 Gets an iterator to the beginning of this object's vertex list.
 
std::vector< BuiltinVertexData >::iterator getVertexListEnd ()
 Gets an iterator to the end of this object's vertex list.
 
std::vector< BuiltinVertexData >::const_iterator getVertexListBegin () const
 Gets a const iterator to the beginning of this object's vertex list.
 
std::vector< BuiltinVertexData >::const_iterator getVertexListEnd () const
 Gets a const iterator to the end of this object's vertex list.
 
VertexLayout getVertexLayout () const
 Gets the vertex layout associated with this object, that of BuiltinVertexData.
 
- Public Member Functions inherited from ToyMaker::Resource< StaticMesh >
std::string getResourceTypeName_ () const override
 Get the resource type string for this resource.
 
- Public Member Functions inherited from ToyMaker::IResource
virtual ~IResource ()=default
 Destroy the IResource object.
 

Static Public Member Functions

static std::string getResourceTypeName ()
 Gets the resource type string for this object.
 

Private Member Functions

void setAttributePointers (const VertexLayout &shaderVertexLayout, std::size_t startingOffset=0)
 Specifies the offsets of vertex attributes per the vertex layout requested by a shader.
 
void upload ()
 Uploads the vertex and element data for this object to the GPU.
 
void unload ()
 Deallocates vertex and element data belonging to this object from the GPU.
 
void destroyResource ()
 Deallocates related GPU buffers and releases resources owned by this object.
 
void releaseResource ()
 Loses references to resources owned by this object, allowing another object to take ownership of them (including GPU buffers)
 

Private Attributes

std::vector< BuiltinVertexDatamVertices {}
 This object's vertex data.
 
std::vector< GLuint > mElements {}
 This object's element list.
 
VertexLayout mVertexLayout
 The vertex layout associated with this mesh, same as BuiltinVertexData's vertex layout.
 
bool mIsUploaded { false }
 Marker for whether the data in this object has been uploaded to the GPU.
 
GLuint mVertexBuffer { 0 }
 The OpenGL vertex buffer handle for this object, if it has been uploaded to GPU memory.
 
GLuint mElementBuffer { 0 }
 The OpenGL element buffer handle for this object, if it has been uploaded to GPU memory.
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::Resource< StaticMesh >
 Resource (int explicitlyInitializeMe)
 Construct a new resource object.
 
- Protected Member Functions inherited from ToyMaker::IResource
 IResource ()=default
 Construct a new IResource object.
 
- Static Protected Member Functions inherited from ToyMaker::IResource
template<typename TResource>
static void RegisterResource ()
 Registers this resource as a Resource type with the ResourceDatabase.
 

Detailed Description

A class whose current main purpose is to store geometry related info, and to upload it to GPU memory when requested.

Constructor & Destructor Documentation

◆ StaticMesh()

StaticMesh::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.

Parameters
mVerticesA list of vertex data.
mElementsA list where each item is an index into the vertices array, and where every 3 contiguous elements describe a triangle of a mesh.
vertexBufferThe OpenGL vertex buffer handle, if one exists, associated with this object in GPU memory.
elementBufferThe OpenGL element buffer handle, if one exists, associated with this object in GPU memory.
isUploadedWhether this mesh's data has already been uploaded to the GPU.

Member Function Documentation

◆ bind()

void StaticMesh::bind ( const VertexLayout & shaderVertexLayout)

Binds this object's vertex data according to the vertex layout specified by the shader program.

Parameters
shaderVertexLayoutThe requested vertex layout.

◆ getElementCount()

GLuint ToyMaker::StaticMesh::getElementCount ( )
inline

Returns number of elements in the elements array for this mesh.

Returns
GLuint The no. of elements.

◆ getResourceTypeName()

static std::string ToyMaker::StaticMesh::getResourceTypeName ( )
inlinestatic

Gets the resource type string for this object.

Returns
std::string This object's resource type string.

◆ getVertexLayout()

VertexLayout StaticMesh::getVertexLayout ( ) const

Gets the vertex layout associated with this object, that of BuiltinVertexData.

Returns
VertexLayout This mesh's vertex layout.

◆ getVertexListBegin() [1/2]

std::vector< BuiltinVertexData >::iterator StaticMesh::getVertexListBegin ( )

Gets an iterator to the beginning of this object's vertex list.

Returns
std::vector<BuiltinVertexData>::iterator This object's vertex list's beginning iterator.

◆ getVertexListBegin() [2/2]

std::vector< BuiltinVertexData >::const_iterator StaticMesh::getVertexListBegin ( ) const

Gets a const iterator to the beginning of this object's vertex list.

Returns
std::vector<BuiltinVertexData>::const_iterator This object's vertex list's beginning const iterator.

◆ getVertexListEnd() [1/2]

std::vector< BuiltinVertexData >::iterator StaticMesh::getVertexListEnd ( )

Gets an iterator to the end of this object's vertex list.

Returns
std::vector<BuiltinVertexData>::iterator This object's vertex list's ending iterator.

◆ getVertexListEnd() [2/2]

std::vector< BuiltinVertexData >::const_iterator StaticMesh::getVertexListEnd ( ) const

Gets a const iterator to the end of this object's vertex list.

Returns
std::vector<BuiltinVertexData>::const_iterator This object's vertex lists' ending const iterator.

◆ setAttributePointers()

void StaticMesh::setAttributePointers ( const VertexLayout & shaderVertexLayout,
std::size_t startingOffset = 0 )
private

Specifies the offsets of vertex attributes per the vertex layout requested by a shader.

Parameters
shaderVertexLayoutThe vertex layout required by a shader.
startingOffsetThe starting offset, in bytes, to the part of vertex and element arrays associated with this mesh.

Member Data Documentation

◆ mElements

std::vector<GLuint> ToyMaker::StaticMesh::mElements {}
private

This object's element list.

Each element corresponds to an index into mVertices. Every 3 elements defines one triangle of this mesh.


The documentation for this class was generated from the following files: