mirror of https://github.com/axmolengine/axmol.git
remove IndexData class
This commit is contained in:
parent
414d67851f
commit
2dca0a4809
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
Primitive* Primitive::create(VertexData* verts, IndexData* indices, PrimitiveType type)
|
Primitive* Primitive::create(VertexData* verts, IndexBuffer* indices, PrimitiveType type)
|
||||||
{
|
{
|
||||||
auto result = new (std::nothrow) Primitive();
|
auto result = new (std::nothrow) Primitive();
|
||||||
if( result && result->init(verts, indices, type))
|
if( result && result->init(verts, indices, type))
|
||||||
|
@ -47,7 +47,7 @@ VertexData* Primitive::getVertexData()
|
||||||
return _verts;
|
return _verts;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexData* Primitive::getIndexData()
|
IndexBuffer* Primitive::getIndexData()
|
||||||
{
|
{
|
||||||
return _indices;
|
return _indices;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ Primitive::~Primitive()
|
||||||
CC_SAFE_RELEASE_NULL(_indices);
|
CC_SAFE_RELEASE_NULL(_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Primitive::init(VertexData* verts, IndexData* indices, PrimitiveType type)
|
bool Primitive::init(VertexData* verts, IndexBuffer* indices, PrimitiveType type)
|
||||||
{
|
{
|
||||||
if(nullptr == verts || nullptr == indices) return false;
|
if(nullptr == verts || nullptr == indices) return false;
|
||||||
if(verts != _verts)
|
if(verts != _verts)
|
||||||
|
@ -94,39 +94,39 @@ void Primitive::draw()
|
||||||
_verts->use();
|
_verts->use();
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case PrimitiveType::POINTS:
|
case PrimitiveType::POINTS:
|
||||||
if(_indices->getIndexBuffer() != nullptr)
|
if(_indices!= nullptr)
|
||||||
{
|
{
|
||||||
GLenum type = (_indices->getIndexBuffer()->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||||
glDrawElements(GL_POINTS, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
glDrawElements(GL_POINTS, _count, type, (GLvoid*)_start);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_POINTS, _indices->getStart(), _indices->getCount());
|
glDrawArrays(GL_POINTS, _count, _start);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PrimitiveType::LINES:
|
case PrimitiveType::LINES:
|
||||||
if(_indices->getIndexBuffer() != nullptr)
|
if(_indices!= nullptr)
|
||||||
{
|
{
|
||||||
GLenum type = (_indices->getIndexBuffer()->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||||
glDrawElements(GL_LINES, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
glDrawElements(GL_LINES, _count, type, (GLvoid*)_start);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_LINES, _indices->getStart(), _indices->getCount());
|
glDrawArrays(GL_LINES, _count, _start);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PrimitiveType::TRIANGLES:
|
case PrimitiveType::TRIANGLES:
|
||||||
if(_indices->getIndexBuffer() != nullptr)
|
if(_indices!= nullptr)
|
||||||
{
|
{
|
||||||
GLenum type = (_indices->getIndexBuffer()->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||||
glDrawElements(GL_TRIANGLES, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
glDrawElements(GL_TRIANGLES, _count, type, (GLvoid*)_start);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLES, _indices->getStart(), _indices->getCount());
|
glDrawArrays(GL_TRIANGLES, _count, _start);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -41,25 +41,33 @@ enum class PrimitiveType
|
||||||
class Primitive : public Ref
|
class Primitive : public Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Primitive* create(VertexData* verts, IndexData* indices, PrimitiveType type);
|
static Primitive* create(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||||
|
|
||||||
VertexData* getVertexData();
|
VertexData* getVertexData();
|
||||||
|
|
||||||
IndexData* getIndexData();
|
IndexBuffer* getIndexData();
|
||||||
|
|
||||||
PrimitiveType getType() const { return _type; }
|
PrimitiveType getType() const { return _type; }
|
||||||
|
|
||||||
//called by rendering framework
|
//called by rendering framework
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
|
int getStart() const { return _start; }
|
||||||
|
int getCount() const { return _count; }
|
||||||
|
void setStart(int start) { _start = start; }
|
||||||
|
void setCount(int count) { _count = count; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Primitive();
|
Primitive();
|
||||||
virtual ~Primitive();
|
virtual ~Primitive();
|
||||||
|
|
||||||
bool init(VertexData* verts, IndexData* indices, PrimitiveType type);
|
bool init(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
VertexData* _verts;
|
VertexData* _verts;
|
||||||
IndexData* _indices;
|
IndexBuffer* _indices;
|
||||||
|
int _start;
|
||||||
|
int _count;
|
||||||
PrimitiveType _type;
|
PrimitiveType _type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -161,47 +161,4 @@ void VertexData::use()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexData* IndexData::create(IndexBuffer* buffer, int start, int count)
|
|
||||||
{
|
|
||||||
IndexData* result = new (std::nothrow) IndexData();
|
|
||||||
if(result && result->init(buffer, start, count))
|
|
||||||
{
|
|
||||||
result->autorelease();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CC_SAFE_DELETE(result);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexData::IndexData()
|
|
||||||
: _buffer(nullptr)
|
|
||||||
, _start(0)
|
|
||||||
, _count(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexData::~IndexData()
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IndexData::init(IndexBuffer* buffer, int start, int count)
|
|
||||||
{
|
|
||||||
if(count == 0) return false;
|
|
||||||
if(_buffer != buffer)
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(_buffer);
|
|
||||||
CC_SAFE_RETAIN(buffer);
|
|
||||||
_buffer = buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
_start = start;
|
|
||||||
_count = count;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -116,26 +116,6 @@ protected:
|
||||||
static GLint getGLSemanticBinding(VertexSemantic semantic);
|
static GLint getGLSemanticBinding(VertexSemantic semantic);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IndexData : public Ref
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static IndexData* create(IndexBuffer* buffer, int start, int count);
|
|
||||||
|
|
||||||
IndexBuffer* getIndexBuffer() const { return _buffer; }
|
|
||||||
int getStart() const { return _start; }
|
|
||||||
int getCount() const { return _count; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
IndexData();
|
|
||||||
virtual ~IndexData();
|
|
||||||
|
|
||||||
bool init(IndexBuffer* buffer, int start, int count);
|
|
||||||
protected:
|
|
||||||
IndexBuffer* _buffer;
|
|
||||||
int _start;
|
|
||||||
int _count;
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__CC_VERTEX_INDEX_DATA_H__
|
#endif //__CC_VERTEX_INDEX_DATA_H__
|
||||||
|
|
Loading…
Reference in New Issue