mirror of https://github.com/axmolengine/axmol.git
add param for usage in class VertexBuffer and IndexBuffer
This commit is contained in:
parent
6984e7097f
commit
2b79ff1d87
|
@ -42,10 +42,10 @@ bool IndexBuffer::_enableShadowCopy = true;
|
|||
bool IndexBuffer::_enableShadowCopy = false;
|
||||
#endif
|
||||
|
||||
VertexBuffer* VertexBuffer::create(int sizePerVertex, int vertexNumber)
|
||||
VertexBuffer* VertexBuffer::create(int sizePerVertex, int vertexNumber, GLenum usage/* = GL_STATIC_DRAW*/)
|
||||
{
|
||||
auto result = new (std::nothrow) VertexBuffer();
|
||||
if(result && result->init(sizePerVertex, vertexNumber))
|
||||
if(result && result->init(sizePerVertex, vertexNumber, usage))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
|
@ -85,12 +85,13 @@ VertexBuffer::~VertexBuffer()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool VertexBuffer::init(int sizePerVertex, int vertexNumber)
|
||||
bool VertexBuffer::init(int sizePerVertex, int vertexNumber, GLenum usage/* = GL_STATIC_DRAW*/)
|
||||
{
|
||||
if(0 == sizePerVertex || 0 == vertexNumber)
|
||||
return false;
|
||||
_sizePerVertex = sizePerVertex;
|
||||
_vertexNumber = vertexNumber;
|
||||
_usage = usage;
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
{
|
||||
|
@ -99,7 +100,7 @@ bool VertexBuffer::init(int sizePerVertex, int vertexNumber)
|
|||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), nullptr, _usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
return true;
|
||||
}
|
||||
|
@ -158,7 +159,7 @@ void VertexBuffer::recreateVBO() const
|
|||
buffer = &_shadowCopy[0];
|
||||
}
|
||||
CCLOG("recreate IndexBuffer with size %d %d", getSizePerVertex(), _vertexNumber);
|
||||
glBufferData(GL_ARRAY_BUFFER, _sizePerVertex * _vertexNumber, buffer, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, _sizePerVertex * _vertexNumber, buffer, _usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
if(!glIsBuffer(_vbo))
|
||||
{
|
||||
|
@ -171,10 +172,10 @@ int VertexBuffer::getSize() const
|
|||
return _sizePerVertex * _vertexNumber;
|
||||
}
|
||||
|
||||
IndexBuffer* IndexBuffer::create(IndexType type, int number)
|
||||
IndexBuffer* IndexBuffer::create(IndexType type, int number, GLenum usage/* = GL_STATIC_DRAW*/)
|
||||
{
|
||||
auto result = new (std::nothrow) IndexBuffer();
|
||||
if(result && result->init(type, number))
|
||||
if(result && result->init(type, number, usage))
|
||||
{
|
||||
result->autorelease();
|
||||
return result;
|
||||
|
@ -211,16 +212,17 @@ IndexBuffer::~IndexBuffer()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool IndexBuffer::init(IndexBuffer::IndexType type, int number)
|
||||
bool IndexBuffer::init(IndexBuffer::IndexType type, int number, GLenum usage/* = GL_STATIC_DRAW*/)
|
||||
{
|
||||
if(number <=0 ) return false;
|
||||
|
||||
_type = type;
|
||||
_indexNumber = number;
|
||||
_usage = usage;
|
||||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, getSize(), nullptr, _usage);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
if(isShadowCopyEnabled())
|
||||
|
@ -295,7 +297,7 @@ void IndexBuffer::recreateVBO() const
|
|||
buffer = &_shadowCopy[0];
|
||||
}
|
||||
CCLOG("recreate IndexBuffer with size %d %d ", getSizePerIndex(), _indexNumber);
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), buffer, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, getSize(), buffer, _usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
if(!glIsBuffer(_vbo))
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ class EventListenerCustom;
|
|||
class CC_DLL VertexBuffer : public Ref
|
||||
{
|
||||
public:
|
||||
static VertexBuffer* create(int sizePerVertex, int vertexNumber);
|
||||
static VertexBuffer* create(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
|
||||
|
||||
int getSizePerVertex() const;
|
||||
int getVertexNumber() const;
|
||||
|
@ -50,7 +50,7 @@ protected:
|
|||
VertexBuffer();
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
bool init(int sizePerVertex, int vertexNumber);
|
||||
bool init(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
|
||||
protected:
|
||||
//event listener for foreground
|
||||
void recreateVBO() const;
|
||||
|
@ -61,6 +61,7 @@ protected:
|
|||
int _vertexNumber;
|
||||
//buffer used for shadow copy
|
||||
std::vector<unsigned char> _shadowCopy;
|
||||
GLenum _usage;
|
||||
protected:
|
||||
static bool _enableShadowCopy;
|
||||
public:
|
||||
|
@ -78,7 +79,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
static IndexBuffer* create(IndexType type, int number);
|
||||
static IndexBuffer* create(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
|
||||
|
||||
IndexType getType() const;
|
||||
int getSizePerIndex() const;
|
||||
|
@ -93,7 +94,7 @@ protected:
|
|||
IndexBuffer();
|
||||
virtual ~IndexBuffer();
|
||||
|
||||
bool init(IndexType type, int number);
|
||||
bool init(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
|
||||
|
||||
protected:
|
||||
mutable GLuint _vbo;
|
||||
|
@ -106,6 +107,7 @@ protected:
|
|||
EventListenerCustom* _recreateVBOEventListener;
|
||||
//buffer used for shadow copy
|
||||
std::vector<unsigned char> _shadowCopy;
|
||||
GLenum _usage;
|
||||
protected:
|
||||
static bool _enableShadowCopy;
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue