Cocos2d-x  v4
CustomCommand Class Reference

Custom command is used to draw all things except triangle commands. More...

Inherits RenderCommand.

Inherited by MeshCommand.

Public Types

using BufferUsage = backend::BufferUsage
 Buffer usage of vertex/index buffer. More...
 
using IndexFormat = backend::IndexFormat
 The index format determine the size for index data. More...
 
- Public Types inherited from RenderCommand
enum  Type {
  UNKNOWN_COMMAND, QUAD_COMMAND, CUSTOM_COMMAND, GROUP_COMMAND,
  MESH_COMMAND, TRIANGLES_COMMAND, CALLBACK_COMMAND
}
 Enum the type of render command. More...
 

Public Member Functions

 CustomCommand ()
 Constructor.
 
 ~CustomCommand ()
 Destructor.
 
void init (float globalZOrder, const Mat4 &modelViewTransform, unsigned int flags)
 TODO: should remove it. More...
 
void init (float globalZOrder)
 Init function. More...
 
void init (float globalZOrder, const BlendFunc &blendFunc)
 Init function. More...
 
void createVertexBuffer (std::size_t vertexSize, std::size_t capacity, BufferUsage usage)
 Create a vertex buffer of the custom command. More...
 
void createIndexBuffer (IndexFormat format, std::size_t capacity, BufferUsage usage)
 Create an index buffer of the custom command. More...
 
void updateVertexBuffer (void *data, std::size_t length)
 Update vertex buffer contents. More...
 
void updateIndexBuffer (void *data, std::size_t length)
 Update index buffer contents. More...
 
void updateVertexBuffer (void *data, std::size_t offset, std::size_t length)
 Update some or all contents of vertex buffer. More...
 
void updateIndexBuffer (void *data, std::size_t offset, std::size_t length)
 Update some or call contents of index buffer. More...
 
std::size_t getVertexCapacity () const
 Get vertex buffer capacity.
 
std::size_t getIndexCapacity () const
 Get index buffer capacity.
 
void setVertexBuffer (backend::Buffer *vertexBuffer)
 Set the vertex buffer. More...
 
void setIndexBuffer (backend::Buffer *indexBuffer, IndexFormat indexFormat)
 Set the index buffer. More...
 
void setVertexDrawInfo (std::size_t start, std::size_t count)
 Set the drawing information if the drawing type is ARRAY. More...
 
void setIndexDrawInfo (std::size_t start, std::size_t count)
 Set the drawing information if the drawing type is ELEMENT. More...
 
void setBeforeCallback (const CallBackFunc &before)
 set a callback which will be invoke before rendering
 
void setAfterCallback (const CallBackFunc &after)
 set a callback which will be invoke after rendering
 
- Public Member Functions inherited from RenderCommand
void init (float globalZOrder, const Mat4 &modelViewTransform, unsigned int flags)
 Init function, will be called by all the render commands. More...
 
float getGlobalOrder () const
 Get global Z order.
 
Type getType () const
 Returns the Command type.
 
bool isTransparent () const
 Returns whether is transparent.
 
void setTransparent (bool isTransparent)
 Set transparent flag.
 
bool isSkipBatching () const
 Get skip batching status, if a rendering is skip batching, it will be forced to be rendering separately.
 
void setSkipBatching (bool value)
 Set skip batching.
 
bool is3D () const
 Whether the command should be rendered at 3D mode.
 
void set3D (bool value)
 Set the command rendered in 3D mode or not.
 
float getDepth () const
 Get the depth by current model view matrix.
 
PipelineDescriptor & getPipelineDescriptor ()
 Can use the result to change the descriptor content.
 

Public Attributes

std::function< void()> func
 Callback function.
 

Detailed Description

Custom command is used to draw all things except triangle commands.

You can use this command to draw things, just provide vertex/index data and set corret flags.

Member Typedef Documentation

◆ BufferUsage

using BufferUsage = backend::BufferUsage

Buffer usage of vertex/index buffer.

If the contents is not updated every frame, then use STATIC, other use DYNAMIC.

◆ IndexFormat

using IndexFormat = backend::IndexFormat

The index format determine the size for index data.

U_SHORT is enough for most cases.

Member Function Documentation

◆ init() [1/3]

void init ( float  globalZOrder,
const Mat4 modelViewTransform,
unsigned int  flags 
)

TODO: should remove it.

Init function.

Parameters
globalZOrderGlobalZOrder of the render command.
modelViewTransformWhen in 3D mode, depth sorting needs modelViewTransform.
flagsUse to identify that the render command is 3D mode or not.

◆ init() [2/3]

void init ( float  globalZOrder)

Init function.

The render command will be in 2D mode.

Parameters
globalZOrderGlobalZOrder of the render command.

◆ init() [3/3]

void init ( float  globalZOrder,
const BlendFunc blendFunc 
)

Init function.

The render command will be in 2D mode.

Parameters
globalZOrderGlobalZOrder of the render command.
blendFuncblend function of the render command.

◆ createVertexBuffer()

void createVertexBuffer ( std::size_t  vertexSize,
std::size_t  capacity,
BufferUsage  usage 
)

Create a vertex buffer of the custom command.

The buffer size is (vertexSize * capacity). If the buffer already exists, then it will delete the old buffer and create a new one.

Parameters
vertexSizethe size of every vertex data.
capacityhow many vertices of the buffer
usagethe usage of the vertex buffer. Use Static of the vertex data are not updated every frame, otherwise use DYNAMIC.

◆ createIndexBuffer()

void createIndexBuffer ( IndexFormat  format,
std::size_t  capacity,
BufferUsage  usage 
)

Create an index buffer of the custom command.

The buffer size is (indexSize * capacity). Index size is determined by format. If the buffer already exists, then it will delete the old buffer and create a new one.

Parameters
formatindex fomrat, if format is U_SHORT, then the index data type should be unsigned short, otherwise should be unsigned int.
capacityhow many indices of the buffer
usagethe usage of the vertex buffer. Use Static of the index data are not updated every frame, otherwise use DYNAMIC.

◆ updateVertexBuffer() [1/2]

void updateVertexBuffer ( void *  data,
std::size_t  length 
)

Update vertex buffer contents.

Parameters
dataSpecifies a pointer to the new data that will be copied into the data store.
lengthSpecifies the length in bytes of the data store region being replaced.

◆ updateIndexBuffer() [1/2]

void updateIndexBuffer ( void *  data,
std::size_t  length 
)

Update index buffer contents.

Parameters
dataSpecifies a pointer to the new data that will be copied into the data store.
lengthSpecifies the size in bytes of the data store region being replaced.

◆ updateVertexBuffer() [2/2]

void updateVertexBuffer ( void *  data,
std::size_t  offset,
std::size_t  length 
)

Update some or all contents of vertex buffer.

Parameters
dataSpecifies a pointer to the new data that will be copied into the data store.
offsetSpecifies the offset into the buffer object's data store where data replacement will begin, measured in bytes.
lengthSpecifies the size in bytes of the data store region being replaced.

◆ updateIndexBuffer() [2/2]

void updateIndexBuffer ( void *  data,
std::size_t  offset,
std::size_t  length 
)

Update some or call contents of index buffer.

Parameters
dataSpecifies a pointer to the new data that will be copied into the data store.
offsetspecifies the offset into the buffer object's data store where data replacement will begin, measured in bytes.
lengthSpecifies the size in bytes of the data store region being replaced.

◆ setVertexBuffer()

void setVertexBuffer ( backend::Buffer vertexBuffer)

Set the vertex buffer.

The existing vertex buffer will be replaced if exist.

◆ setIndexBuffer()

void setIndexBuffer ( backend::Buffer indexBuffer,
IndexFormat  indexFormat 
)

Set the index buffer.

The existing index buffer will be replaced if exist.

◆ setVertexDrawInfo()

void setVertexDrawInfo ( std::size_t  start,
std::size_t  count 
)
inline

Set the drawing information if the drawing type is ARRAY.

@start specifices the starting index of vertex buffer @count specifices the number of vertices to be rendered

◆ setIndexDrawInfo()

void setIndexDrawInfo ( std::size_t  start,
std::size_t  count 
)
inline

Set the drawing information if the drawing type is ELEMENT.

@start specifices the starting index of index buffer @count specifices the number of indices to be rendered


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