![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUSpriteMesh.h>
Public Member Functions | |
SpriteMesh () | |
~SpriteMesh () | |
void | dispose () |
bool | init () |
bool | initWithMesh (const Mesh< SpriteVertex > &mesh, bool buffer=true) |
bool | initWithMesh (Mesh< SpriteVertex > &&mesh, bool buffer=true) |
bool | initWithData (const std::shared_ptr< JsonValue > &data, bool buffer=true) |
const Mesh< SpriteVertex > | getMesh () const |
void | setMesh (const Mesh< SpriteVertex > &mesh) |
void | setMesh (Mesh< SpriteVertex > &&mesh) |
std::shared_ptr< VertexBuffer > | getVertexBuffer () const |
void | draw (const std::shared_ptr< Shader > &shader) |
Static Public Member Functions | |
static std::shared_ptr< SpriteMesh > | alloc () |
static std::shared_ptr< SpriteMesh > | allocWithMesh (const Mesh< SpriteVertex > &mesh, bool buffer=true) |
static std::shared_ptr< SpriteMesh > | allocWithMesh (Mesh< SpriteVertex > &&mesh, bool buffer=true) |
static std::shared_ptr< SpriteMesh > | allocWithData (const std::shared_ptr< JsonValue > &data, bool buffer=true) |
Friends | |
class | SpriteMeshLoader |
This class is represents a sprite with a static mesh.
Sprites are typically drawn with a SpriteBatch
. Sprite batches work best when geometric complexity is low, as they are constantly updating their VertexBuffer
. However, if a sprite does not change much, it sometimes makes sense to assign it its own VertexBuffer
. That is the purpose of this class.
Because a sprite mesh has its own buffer, it is intended to be used directly with a Shader
. With that said, the vertices are all instances of SpriteVertex
, and thus this class can be used with the default SpriteBatch#getShader
.
|
inline |
Creates a degenerate sprite mesh
This sprite mesh has degenerate values for all attributes. Nothing will rendered to the screen until it is initialized.
|
inline |
Deletes this sprite mesh, disposing all of the resources.
|
inlinestatic |
Returns a newly allocated empty sprite mesh.
The sprite mesh will have an empty mesh and therefore not create an a graphics buffer. It will need a mesh provided to setMesh
.
|
inlinestatic |
Returns a newly allocated sprite mesh from the given JsonValue
This JSON object can either be an array or an object. If it is an array, it should contain JSON values compatible with the SpriteVertex
constructor. If it is a JSON object, then it supports the following attributes:
"vertices": An array {@link SpriteVertex} descriptions "indices": An intenger list of triangle indices (in multiples of 3) "triangulator": One of 'monotone', 'earclip', 'delaunay', 'fan', or 'strip'
All attributes are optional. If "vertices" are missing, the mesh will be empty. If both "indices" and "triangulator" are missing, the mesh will use a triangle fan. The "triangulator" choice will only be applied if the "indices" are missing.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
data | The JSON object specifying the sprite mesh |
buffer | Whether to create a graphics buffer |
|
inlinestatic |
Returns a newly allocated sprite mesh with the given vertex mesh.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
mesh | The sprite vertex mesh |
buffer | Whether to create a graphics buffer |
|
inlinestatic |
Returns a newly allocated sprite mesh with the given vertex mesh.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
mesh | The sprite vertex mesh |
buffer | Whether to create a graphics buffer |
void cugl::graphics::SpriteMesh::dispose | ( | ) |
Disposes the mesh and vertex buffer for this sprite mesh.
You must reinitialize the sprite mesh to use it.
void cugl::graphics::SpriteMesh::draw | ( | const std::shared_ptr< Shader > & | shader | ) |
Draws the sprite mesh with the given shader.
Note that sprite meshes to do not necessarily come with an texture or a gradient; they are just a mesh. Those values should be passed to the shader separately as uniforms.
shader | The shader to draw with |
|
inline |
Returns the mesh associated with sprite mesh.
This mesh can be safely changed at any time. However, changing the mesh affects the getVertexBuffer
. Therefore, the mesh should never be modified directly. Changes should go through setMesh
.
|
inline |
Returns the vertex buffer for this sprite mesh.
This buffer is used to render the mesh. It should be combined with a Shader
, preferably one compatible with SpriteBatch
.
|
inline |
Initializes an empty sprite mesh.
The sprite mesh will have an empty mesh and therefore not create an a graphics buffer. It will need a mesh provided to setMesh
.
bool cugl::graphics::SpriteMesh::initWithData | ( | const std::shared_ptr< JsonValue > & | data, |
bool | buffer = true |
||
) |
Initializes a sprite mesh from the given JsonValue
This JSON object can either be an array or an object. If it is an array, it should contain JSON values compatible with the SpriteVertex
constructor. If it is a JSON object, then it supports the following attributes:
"vertices": An array {@link SpriteVertex} descriptions "indices": An intenger list of triangle indices (in multiples of 3) "triangulator": One of 'monotone', 'earclip', 'delaunay', 'fan', or 'strip'
All attributes are optional. If "vertices" are missing, the mesh will be empty. If both "indices" and "triangulator" are missing, the mesh will use a triangle fan. The "triangulator" choice will only be applied if the "indices" are missing.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
data | The JSON object specifying the sprite mesh |
buffer | Whether to create a graphics buffer |
bool cugl::graphics::SpriteMesh::initWithMesh | ( | const Mesh< SpriteVertex > & | mesh, |
bool | buffer = true |
||
) |
Initializes a sprite mesh with the given vertex mesh.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
mesh | The sprite vertex mesh |
buffer | Whether to create a graphics buffer |
bool cugl::graphics::SpriteMesh::initWithMesh | ( | Mesh< SpriteVertex > && | mesh, |
bool | buffer = true |
||
) |
Initializes a sprite mesh with the given vertex mesh.
The sprite mesh will only create a graphics buffer if buffer is true. This is to handle cases where the sprite mesh is created in a separate thread (as OpenGL only allows graphics buffers to be made on the main thread).
mesh | The sprite vertex mesh |
buffer | Whether to create a graphics buffer |
|
inline |
Sets the mesh associated with sprite mesh.
This mesh can be safely changed at any time. However, changing the mesh affects the getVertexBuffer
. Therefore, the mesh should never be modified directly. Changes should go through setMesh
.
This method will always create a graphics buffer, even if one did not previously exist. It should not be called outside the main thread.
mesh | The mesh associated with sprite mesh. |
|
inline |
Sets the mesh associated with sprite mesh.
This mesh can be safely changed at any time. However, changing the mesh affects the getVertexBuffer
. Therefore, the mesh should never be modified directly. Changes should go through setMesh
.
This method will always create a graphics buffer, even if one did not previously exist. It should not be called outside the main thread.
mesh | The mesh associated with sprite mesh. |