[ci skip]adjust comments CCVertexIndexBuffer.h and CCVertexIndexData.h

This commit is contained in:
Huabing.Xu 2015-03-18 17:40:10 +08:00
parent a71fb9f946
commit fb1d9899c7
2 changed files with 144 additions and 76 deletions

View File

@ -35,68 +35,93 @@ class EventListenerCustom;
/**
VertexBuffer is an abstraction of low level openGL Vertex Buffer Object.
It used to save an array of vertices
It is used to save an array of vertices.
*/
class CC_DLL VertexBuffer : public Ref
{
public:
/**
Create an instance of VertexBuffer
@param sizePerVertex Size in bytes of one vertex
@param vertexNumber The number of vertex
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it
Create an instance of VertexBuffer.
@param sizePerVertex Size in bytes of one vertex.
@param vertexNumber The number of vertex.
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it.
*/
static VertexBuffer* create(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
/*Get the size in bytes of one vertex*/
/**Get the size in bytes of one vertex.*/
int getSizePerVertex() const;
/*Get the number of vertices*/
/**Get the number of vertices.*/
int getVertexNumber() const;
/**
Update all or part of vertice data, if the range specified exceeds the vertex buffer, it will be clipped
@param verts The pointer of the vertex data
@param count The number of vertices to update
@param begin The first vertex to update
Update all or part of vertice data, if the range specified exceeds the vertex buffer, it will be clipped.
@param verts The pointer of the vertex data.
@param count The number of vertices to update.
@param begin The first vertex to update.
*/
bool updateVertices(const void* verts, int count, int begin);
/*Get the size of the vertex array in bytes, equals getSizePerVertex() * getVertexNumber()*/
/**
Get the size of the vertex array in bytes, equals getSizePerVertex() * getVertexNumber().
*/
int getSize() const;
/*Get the internal openGL handle*/
/**
Get the internal openGL handle.
*/
GLuint getVBO() const;
protected:
/*Constructor*/
/**
Constructor.
*/
VertexBuffer();
/*Destructor*/
/**
Destructor.
*/
virtual ~VertexBuffer();
/**
Init the storage of vertex buffer
@param sizePerVertex Size in bytes of one vertex
@param vertexNumber The number of vertex
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it
Init the storage of vertex buffer.
@param sizePerVertex Size in bytes of one vertex.
@param vertexNumber The number of vertex.
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it.
*/
bool init(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
protected:
//event listener for foreground
/**
Event handler for foreground.
*/
void recreateVBO() const;
/**
Event listener for foreground.
*/
EventListenerCustom* _recreateVBOEventListener;
protected:
/*internal handle for openGL*/
/**
Internal handle for openGL.
*/
mutable GLuint _vbo;
//size in bytes for one vertex
/**
Size in bytes for one vertex.
*/
int _sizePerVertex;
//number of vertices
/**
Number of vertices.
*/
int _vertexNumber;
//buffer used for shadow copy
/**
Buffer used for shadow copy.
*/
std::vector<unsigned char> _shadowCopy;
//Hint for optimisation in GL
/**
Hint for optimisation in GL.
*/
GLenum _usage;
protected:
//static member to indicate that use _shadowCopy or not
/**
Static member to indicate that use _shadowCopy or not.
*/
static bool _enableShadowCopy;
public:
/**
Static getter/setter for shadowCopy
Static getter/setter for shadowCopy.
*/
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }
@ -104,13 +129,13 @@ public:
/**
IndexBuffer is an abstraction of low level openGL Buffer Object.
It used to save an array of indices
It used to save an array of indices.
*/
class CC_DLL IndexBuffer : public Ref
{
public:
/**
Enum for the type of index, short indices and int indices could be used
Enum for the type of index, short indices and int indices could be used.
*/
enum class IndexType
{
@ -120,65 +145,96 @@ public:
public:
/**
Create an instance of IndexBuffer
@param type type of index
@param number The number of indices
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it
Create an instance of IndexBuffer.
@param type type of index.
@param number The number of indices.
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it.
*/
static IndexBuffer* create(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
//Getter for type of indices
/**
Getter for type of indices.
*/
IndexType getType() const;
//Get the size in bytes for one index, will be 2 for INDEX_TYPE_SHORT_16 and 4 for INDEX_TYPE_UINT_32
/**
Get the size in bytes for one index, will be 2 for INDEX_TYPE_SHORT_16 and 4 for INDEX_TYPE_UINT_32.
*/
int getSizePerIndex() const;
//Get the number of indices
/**
Get the number of indices.
*/
int getIndexNumber() const;
/**
Update all or part of indices data, if the range specified exceeds the vertex buffer, it will be clipped
@param indices The pointer of the index data
@param count The number of indices to update
@param begin The start index to update
Update all or part of indices data, if the range specified exceeds the vertex buffer, it will be clipped.
@param indices The pointer of the index data.
@param count The number of indices to update.
@param begin The start index to update.
*/
bool updateIndices(const void* indices, int count, int begin);
//Get the size in bytes of the array of indices
/**
Get the size in bytes of the array of indices.
*/
int getSize() const;
//Get the openGL handle for index buffer
/**
Get the openGL handle for index buffer.
*/
GLuint getVBO() const;
protected:
//Constructor
/**
Constructor.
*/
IndexBuffer();
//Destructor
/**
Destructor.
*/
virtual ~IndexBuffer();
/**
Init the storageof IndexBuffer
@param type type of index
@param number The number of indices
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it
Init the storageof IndexBuffer.
@param type type of index.
@param number The number of indices.
@param usage A hint to indicate whether the vertexBuffer are updated frequently or not to let GL optimise it.
*/
bool init(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
protected:
//handle for openGL
/**
Handle for openGL.
*/
mutable GLuint _vbo;
//type for index
/**
Type for index.
*/
IndexType _type;
//number of indices
/**
Number of indices.
*/
int _indexNumber;
protected:
//event listener for foreground
/**
Event handler for foreground.
*/
void recreateVBO() const;
/**
Event listener for foreground.
*/
EventListenerCustom* _recreateVBOEventListener;
//buffer used for shadow copy
/**
Buffer used for shadow copy.
*/
std::vector<unsigned char> _shadowCopy;
//Hint for optimisation in GL
/**
Hint for optimisation in GL.
*/
GLenum _usage;
protected:
//static member to indicate that use _shadowCopy or not
/**
Static member to indicate that use _shadowCopy or not.
*/
static bool _enableShadowCopy;
public:
/**
Static getter/setter for shadowCopy
Static getter/setter for shadowCopy.
*/
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }

View File

@ -33,7 +33,7 @@ NS_CC_BEGIN
class VertexBuffer;
/**
VertexStreamAttribute is used to specify the vertex attribute for drawing, which is correspondent to
glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr).
_semantic -> index
_size -> size
@ -41,7 +41,7 @@ glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized
_normalize -> normalized
_offset is used to compute the start offset in a interleaved array, take a V3F_C4B_T2F array,
offset of vertex will be 0, offset of color would be 0 + sizeof(float) * 3 = 12,
offset of texture coord would be 12 + sizeof(char) * 4 = 16
offset of texture coord would be 12 + sizeof(char) * 4 = 16.
*/
struct CC_DLL VertexStreamAttribute
{
@ -70,63 +70,75 @@ struct CC_DLL VertexStreamAttribute
/**
VertexData is a class used for specify input streams for GPU rendering pipeline,
a VertexData will be composed by several streams, every stream will contain a VertexStreamAttribute
and the binding VertexBuffer. streams will be identified by semantic
and the binding VertexBuffer. Streams will be identified by semantic.
*/
class CC_DLL VertexData : public Ref
{
public:
/**
Create function, used to create a instance of VertexData
Create function, used to create a instance of VertexData.
*/
static VertexData* create();
/*Get the number of streams in the VertexData*/
/**
Get the number of streams in the VertexData.
*/
size_t getVertexStreamCount() const;
/**
Set a stream to VertexData,given that stream is identified by semantic, so if the semantic is not
specified before, it will add a stream, or it will override the old one
@param buffer The binding buffer of the stream
specified before, it will add a stream, or it will override the old one.
@param buffer The binding buffer of the stream.
@param stream The binding vertex attribute, its member semantic will be used as the identifier.
*/
bool setStream(VertexBuffer* buffer, const VertexStreamAttribute& stream);
/**
Remove the given streams
@param semantic The semantic of the stream
Remove the given streams.
@param semantic The semantic of the stream.
*/
void removeStream(int semantic);
/**
Get the attribute of stream const version
@param semantic The semantic of the stream
Get the attribute of stream, const version.
@param semantic The semantic of the stream.
*/
const VertexStreamAttribute* getStreamAttribute(int semantic) const;
/**
Get the attribute of stream
@param semantic The semantic of the stream
Get the attribute of stream.
@param semantic The semantic of the stream.
*/
VertexStreamAttribute* getStreamAttribute(int semantic);
/**
Get the binded buffer of the stream
@param semantic The semantic of the stream
Get the binded buffer of the stream.
@param semantic The semantic of the stream.
*/
VertexBuffer* getStreamBuffer(int semantic) const;
/*Called for rendering, it will bind the state of vertex data to current rendering pipeline*/
/**
Called for rendering, it will bind the state of vertex data to current rendering pipeline.
*/
void use();
protected:
/*Constructor*/
/**
Constructor.
*/
VertexData();
/*Destructor*/
/**
Destructor.
*/
virtual ~VertexData();
protected:
/*Simple struct to bundle buffer and attribute*/
/**
Simple struct to bundle buffer and attribute.
*/
struct BufferAttribute
{
VertexBuffer* _buffer;
VertexStreamAttribute _stream;
};
/*Streams in the VertexData*/
/**
Streams in the VertexData.
*/
std::map<int, BufferAttribute> _vertexStreams;
};