2014-07-25 09:58:24 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
http://www.cocos2d-x.org
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_VERTEX_INDEX_DATA_H__
|
|
|
|
#define __CC_VERTEX_INDEX_DATA_H__
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include <map>
|
|
|
|
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup support
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class VertexBuffer;
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
|
|
|
VertexStreamAttribute is used to specify the vertex attribute for drawing, which is correspondent to
|
2015-03-18 17:40:10 +08:00
|
|
|
glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr).
|
2014-07-25 09:58:24 +08:00
|
|
|
|
2015-03-18 14:43:44 +08:00
|
|
|
_semantic -> index
|
|
|
|
_size -> size
|
|
|
|
_type -> type
|
|
|
|
_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,
|
2015-03-18 17:40:10 +08:00
|
|
|
offset of texture coord would be 12 + sizeof(char) * 4 = 16.
|
2015-03-19 20:20:16 +08:00
|
|
|
@js NA
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-08-12 11:56:21 +08:00
|
|
|
struct CC_DLL VertexStreamAttribute
|
2014-07-25 09:58:24 +08:00
|
|
|
{
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
VertexStreamAttribute()
|
2014-10-30 22:25:46 +08:00
|
|
|
: _normalize(false),_offset(0),_semantic(0),_type(0),_size(0)
|
2014-07-25 09:58:24 +08:00
|
|
|
{
|
|
|
|
}
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Constructor
|
|
|
|
@param offset The offset of the attribute.
|
|
|
|
@param semantic The semantic (Position, Texcoord, Color etc) of attribute.
|
|
|
|
@param type The type of attribute, could be GL_FLOAT, GL_UNSIGNED_BYTE etc.
|
|
|
|
@param size Describe how many elements of type in the attribute.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
VertexStreamAttribute(int offset, int semantic, int type, int size)
|
2014-10-30 22:25:46 +08:00
|
|
|
: _normalize(false),_offset(offset),_semantic(semantic),_type(type),_size(size)
|
2014-08-04 16:08:54 +08:00
|
|
|
{
|
|
|
|
}
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Constructor
|
|
|
|
@param offset The offset of the attribute.
|
|
|
|
@param semantic The semantic (Position, Texcoord, Color etc) of attribute.
|
|
|
|
@param type The type of attribute, could be GL_FLOAT, GL_UNSIGNED_BYTE etc.
|
|
|
|
@param size Describe how many elements of type in the attribute.
|
|
|
|
@param normalize If true, the data will be normalized by deviding 255.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
VertexStreamAttribute(int offset, int semantic, int type, int size, bool normalize)
|
2014-10-30 22:25:46 +08:00
|
|
|
: _normalize(normalize),_offset(offset),_semantic(semantic),_type(type),_size(size)
|
2014-08-04 16:08:54 +08:00
|
|
|
{
|
|
|
|
}
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Whether the attribute should be normalized or not.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
bool _normalize;
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
The offset of the attribute in the buffer.
|
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
int _offset;
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Describe that the attribute usage, could be Position, Color etc.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
int _semantic;
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Describe the type of attribute, could be GL_FLOAT, GL_UNSIGNED_BYTE etc.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
int _type;
|
2015-03-18 19:32:10 +08:00
|
|
|
/**
|
|
|
|
Describe how many elements of type in the attribute.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
int _size;
|
2014-07-25 09:58:24 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
|
|
|
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
|
2015-03-18 17:40:10 +08:00
|
|
|
and the binding VertexBuffer. Streams will be identified by semantic.
|
2015-03-19 20:20:16 +08:00
|
|
|
@js NA
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
|
|
|
|
2014-08-12 11:56:21 +08:00
|
|
|
class CC_DLL VertexData : public Ref
|
2014-07-25 09:58:24 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
2015-03-18 17:40:10 +08:00
|
|
|
Create function, used to create a instance of VertexData.
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
static VertexData* create();
|
|
|
|
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Get the number of streams in the VertexData.
|
|
|
|
*/
|
2014-07-25 11:58:54 +08:00
|
|
|
size_t getVertexStreamCount() const;
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
|
|
|
Set a stream to VertexData,given that stream is identified by semantic, so if the semantic is not
|
2015-03-18 17:40:10 +08:00
|
|
|
specified before, it will add a stream, or it will override the old one.
|
|
|
|
@param buffer The binding buffer of the stream.
|
2015-03-18 14:43:44 +08:00
|
|
|
@param stream The binding vertex attribute, its member semantic will be used as the identifier.
|
|
|
|
*/
|
2014-08-01 14:46:35 +08:00
|
|
|
bool setStream(VertexBuffer* buffer, const VertexStreamAttribute& stream);
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
2015-03-18 17:40:10 +08:00
|
|
|
Remove the given streams.
|
|
|
|
@param semantic The semantic of the stream.
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
void removeStream(int semantic);
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
2015-03-18 17:40:10 +08:00
|
|
|
Get the attribute of stream, const version.
|
|
|
|
@param semantic The semantic of the stream.
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
const VertexStreamAttribute* getStreamAttribute(int semantic) const;
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
2015-03-18 17:40:10 +08:00
|
|
|
Get the attribute of stream.
|
|
|
|
@param semantic The semantic of the stream.
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
VertexStreamAttribute* getStreamAttribute(int semantic);
|
2015-03-18 14:43:44 +08:00
|
|
|
/**
|
2015-03-18 17:40:10 +08:00
|
|
|
Get the binded buffer of the stream.
|
|
|
|
@param semantic The semantic of the stream.
|
2015-03-18 14:43:44 +08:00
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
VertexBuffer* getStreamBuffer(int semantic) const;
|
2014-07-25 09:58:24 +08:00
|
|
|
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Called for rendering, it will bind the state of vertex data to current rendering pipeline.
|
|
|
|
*/
|
2014-08-01 14:46:35 +08:00
|
|
|
void use();
|
2014-07-25 09:58:24 +08:00
|
|
|
protected:
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
VertexData();
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
virtual ~VertexData();
|
|
|
|
protected:
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Simple struct to bundle buffer and attribute.
|
|
|
|
*/
|
2014-07-25 11:58:54 +08:00
|
|
|
struct BufferAttribute
|
|
|
|
{
|
|
|
|
VertexBuffer* _buffer;
|
|
|
|
VertexStreamAttribute _stream;
|
|
|
|
};
|
|
|
|
|
2015-03-18 17:40:10 +08:00
|
|
|
/**
|
|
|
|
Streams in the VertexData.
|
|
|
|
*/
|
2014-08-04 16:08:54 +08:00
|
|
|
std::map<int, BufferAttribute> _vertexStreams;
|
2014-07-25 11:58:54 +08:00
|
|
|
};
|
|
|
|
|
2014-07-25 09:58:24 +08:00
|
|
|
NS_CC_END
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
|
|
|
end of support group
|
|
|
|
@}
|
|
|
|
*/
|
2014-07-25 09:58:24 +08:00
|
|
|
#endif //__CC_VERTEX_INDEX_DATA_H__
|