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
|
||||
|
||||
Primitive* Primitive::create(VertexData* verts, IndexData* indices, PrimitiveType type)
|
||||
Primitive* Primitive::create(VertexData* verts, IndexBuffer* indices, PrimitiveType type)
|
||||
{
|
||||
auto result = new (std::nothrow) Primitive();
|
||||
if( result && result->init(verts, indices, type))
|
||||
|
@ -47,7 +47,7 @@ VertexData* Primitive::getVertexData()
|
|||
return _verts;
|
||||
}
|
||||
|
||||
IndexData* Primitive::getIndexData()
|
||||
IndexBuffer* Primitive::getIndexData()
|
||||
{
|
||||
return _indices;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ Primitive::~Primitive()
|
|||
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(verts != _verts)
|
||||
|
@ -94,39 +94,39 @@ void Primitive::draw()
|
|||
_verts->use();
|
||||
switch (_type) {
|
||||
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;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
||||
glDrawElements(GL_POINTS, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
||||
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||
glDrawElements(GL_POINTS, _count, type, (GLvoid*)_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_POINTS, _indices->getStart(), _indices->getCount());
|
||||
glDrawArrays(GL_POINTS, _count, _start);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
||||
glDrawElements(GL_LINES, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
||||
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||
glDrawElements(GL_LINES, _count, type, (GLvoid*)_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_LINES, _indices->getStart(), _indices->getCount());
|
||||
glDrawArrays(GL_LINES, _count, _start);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getIndexBuffer()->getVBO());
|
||||
glDrawElements(GL_TRIANGLES, _indices->getCount(), type, (GLvoid*)_indices->getStart());
|
||||
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||
glDrawElements(GL_TRIANGLES, _count, type, (GLvoid*)_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLES, _indices->getStart(), _indices->getCount());
|
||||
glDrawArrays(GL_TRIANGLES, _count, _start);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -41,25 +41,33 @@ enum class PrimitiveType
|
|||
class Primitive : public Ref
|
||||
{
|
||||
public:
|
||||
static Primitive* create(VertexData* verts, IndexData* indices, PrimitiveType type);
|
||||
static Primitive* create(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||
|
||||
VertexData* getVertexData();
|
||||
|
||||
IndexData* getIndexData();
|
||||
IndexBuffer* getIndexData();
|
||||
|
||||
PrimitiveType getType() const { return _type; }
|
||||
|
||||
//called by rendering framework
|
||||
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:
|
||||
Primitive();
|
||||
virtual ~Primitive();
|
||||
|
||||
bool init(VertexData* verts, IndexData* indices, PrimitiveType type);
|
||||
bool init(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||
|
||||
protected:
|
||||
VertexData* _verts;
|
||||
IndexData* _indices;
|
||||
IndexBuffer* _indices;
|
||||
int _start;
|
||||
int _count;
|
||||
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
|
||||
|
|
|
@ -116,26 +116,6 @@ protected:
|
|||
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
|
||||
|
||||
#endif //__CC_VERTEX_INDEX_DATA_H__
|
||||
|
|
Loading…
Reference in New Issue