axmol/cocos/renderer/CCVertexIndexBuffer.h

118 lines
3.4 KiB
C
Raw Normal View History

2014-07-23 09:20:33 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
2014-08-07 15:53:20 +08:00
2014-07-23 09:20:33 +08:00
http://www.cocos2d-x.org
2014-08-07 15:53:20 +08:00
2014-07-23 09:20:33 +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-23 09:20:33 +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-23 09:20:33 +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_BUFFER_H__
#define __CC_VERTEX_INDEX_BUFFER_H__
#include "base/CCRef.h"
#include "base/CCDirector.h"
NS_CC_BEGIN
2014-08-12 11:56:21 +08:00
class CC_DLL VertexBuffer : public Ref
2014-07-23 09:20:33 +08:00
{
public:
static VertexBuffer* create(int sizePerVertex, int vertexNumber);
int getSizePerVertex() const;
int getVertexNumber() const;
bool updateVertices(const void* verts, int count, int begin);
int getSize() const;
GLuint getVBO() const;
2014-08-01 14:46:35 +08:00
2014-07-23 09:20:33 +08:00
protected:
VertexBuffer();
virtual ~VertexBuffer();
bool init(int sizePerVertex, int vertexNumber);
protected:
//event listener for foreground and background
void listenToBackground(EventCustom *event);
void recreateVBO() const;
protected:
mutable GLuint _vbo;
2014-07-23 09:20:33 +08:00
int _sizePerVertex;
int _vertexNumber;
//buffer used for shadow copy
std::vector<unsigned char> _shadowCopy;
protected:
static bool _enableShadowCopy;
public:
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }
2014-07-23 09:20:33 +08:00
};
2014-08-12 11:56:21 +08:00
class CC_DLL IndexBuffer : public Ref
2014-07-23 09:20:33 +08:00
{
public:
enum class IndexType
{
INDEX_TYPE_SHORT_16,
INDEX_TYPE_UINT_32
};
public:
static IndexBuffer* create(IndexType type, int number);
IndexType getType() const;
int getSizePerIndex() const;
int getIndexNumber() const;
bool updateIndices(const void* indices, int count, int begin);
int getSize() const;
2014-08-01 14:46:35 +08:00
GLuint getVBO() const;
2014-07-23 09:20:33 +08:00
protected:
IndexBuffer();
virtual ~IndexBuffer();
bool init(IndexType type, int number);
protected:
mutable GLuint _vbo;
2014-07-23 09:20:33 +08:00
IndexType _type;
int _indexNumber;
protected:
//event listener for foreground and background
void listenToBackground(EventCustom *event);
void recreateVBO() const;
//buffer used for shadow copy
std::vector<unsigned char> _shadowCopy;
protected:
static bool _enableShadowCopy;
public:
static bool isShadowCopyEnabled() { return _enableShadowCopy; }
static void enableShadowCopy(bool enabled) { _enableShadowCopy = enabled; }
2014-07-23 09:20:33 +08:00
};
NS_CC_END
#endif /* __CC_VERTEX_INDEX_BUFFER_H__*/