mirror of https://github.com/axmolengine/axmol.git
clean up primitive code
This commit is contained in:
parent
01b69c9e4f
commit
b1954ef516
|
@ -422,7 +422,7 @@ void TMXLayer::updatePrimitives()
|
|||
auto primitiveIter= _primitives.find(iter.first);
|
||||
if(primitiveIter == _primitives.end())
|
||||
{
|
||||
auto primitive = Primitive::create(_vData, _indexBuffer, PrimitiveType::TRIANGLES);
|
||||
auto primitive = Primitive::create(_vData, _indexBuffer, GL_TRIANGLES);
|
||||
primitive->setCount(iter.second * 6);
|
||||
primitive->setStart(start * 6);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Primitive* Primitive::create(VertexData* verts, IndexBuffer* indices, PrimitiveType type)
|
||||
Primitive* Primitive::create(VertexData* verts, IndexBuffer* indices, int type)
|
||||
{
|
||||
auto result = new (std::nothrow) Primitive();
|
||||
if( result && result->init(verts, indices, type))
|
||||
|
@ -55,7 +55,7 @@ IndexBuffer* Primitive::getIndexData()
|
|||
Primitive::Primitive()
|
||||
: _verts(nullptr)
|
||||
, _indices(nullptr)
|
||||
, _type(PrimitiveType::POINTS)
|
||||
, _type(GL_POINTS)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ Primitive::~Primitive()
|
|||
CC_SAFE_RELEASE_NULL(_indices);
|
||||
}
|
||||
|
||||
bool Primitive::init(VertexData* verts, IndexBuffer* indices, PrimitiveType type)
|
||||
bool Primitive::init(VertexData* verts, IndexBuffer* indices, int type)
|
||||
{
|
||||
if( nullptr == verts ) return false;
|
||||
if(verts != _verts)
|
||||
|
@ -92,46 +92,15 @@ void Primitive::draw()
|
|||
if(_verts && _indices)
|
||||
{
|
||||
_verts->use();
|
||||
switch (_type) {
|
||||
case PrimitiveType::POINTS:
|
||||
if(_indices!= nullptr)
|
||||
{
|
||||
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 * _indices->getSizePerIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_POINTS, _count, _start);
|
||||
}
|
||||
break;
|
||||
case PrimitiveType::LINES:
|
||||
if(_indices!= nullptr)
|
||||
{
|
||||
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 * _indices->getSizePerIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_LINES, _count, _start);
|
||||
}
|
||||
break;
|
||||
case PrimitiveType::TRIANGLES:
|
||||
if(_indices!= nullptr)
|
||||
{
|
||||
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 * _indices->getSizePerIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLES, _count, _start);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CC_ASSERT(0);
|
||||
break;
|
||||
if(_indices!= nullptr)
|
||||
{
|
||||
GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());
|
||||
glDrawElements((GLenum)_type, _count, type, (GLvoid*)(_start * _indices->getSizePerIndex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays((GLenum)_type, _count, _start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,23 +31,17 @@
|
|||
#include "renderer/CCVertexIndexData.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
enum class PrimitiveType
|
||||
{
|
||||
POINTS,
|
||||
LINES,
|
||||
TRIANGLES
|
||||
};
|
||||
|
||||
class Primitive : public Ref
|
||||
{
|
||||
public:
|
||||
static Primitive* create(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||
static Primitive* create(VertexData* verts, IndexBuffer* indices, int type);
|
||||
|
||||
VertexData* getVertexData();
|
||||
|
||||
IndexBuffer* getIndexData();
|
||||
|
||||
PrimitiveType getType() const { return _type; }
|
||||
int getType() const { return _type; }
|
||||
|
||||
//called by rendering framework
|
||||
void draw();
|
||||
|
@ -61,14 +55,14 @@ protected:
|
|||
Primitive();
|
||||
virtual ~Primitive();
|
||||
|
||||
bool init(VertexData* verts, IndexBuffer* indices, PrimitiveType type);
|
||||
bool init(VertexData* verts, IndexBuffer* indices, int type);
|
||||
|
||||
protected:
|
||||
VertexData* _verts;
|
||||
IndexBuffer* _indices;
|
||||
int _start;
|
||||
int _count;
|
||||
PrimitiveType _type;
|
||||
int _type;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -113,43 +113,6 @@ VertexData::~VertexData()
|
|||
_vertexStreams.clear();
|
||||
}
|
||||
|
||||
GLint VertexData::getGLSize(VertexType type)
|
||||
{
|
||||
if(VertexType::FLOAT1 == type)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(VertexType::FLOAT2 == type)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if(VertexType::FLOAT3 == type)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
GLenum VertexData::getGLType(VertexType type)
|
||||
{
|
||||
if(VertexType::BYTE4 == type)
|
||||
{
|
||||
return GL_UNSIGNED_BYTE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GL_FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
GLint VertexData::getGLSemanticBinding(VertexSemantic semantic)
|
||||
{
|
||||
return GLint(semantic);
|
||||
}
|
||||
|
||||
void VertexData::use()
|
||||
{
|
||||
uint32_t flags;
|
||||
|
|
|
@ -37,30 +37,6 @@ NS_CC_BEGIN
|
|||
|
||||
class VertexBuffer;
|
||||
|
||||
enum VertexSemantic
|
||||
{
|
||||
UNKNOWN = -1,
|
||||
POSITION,
|
||||
COLOR,
|
||||
NORMAL,
|
||||
BLEND_WEIGHT,
|
||||
BLEND_INDEX,
|
||||
TEXTURECOORD0,
|
||||
TEXTURECOORD1,
|
||||
TEXTURECOORD2,
|
||||
TEXTURECOORD3
|
||||
};
|
||||
|
||||
enum class VertexType
|
||||
{
|
||||
UNKNOWN,
|
||||
FLOAT1,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
BYTE4
|
||||
};
|
||||
|
||||
struct VertexStreamAttribute
|
||||
{
|
||||
VertexStreamAttribute()
|
||||
|
@ -110,10 +86,6 @@ protected:
|
|||
};
|
||||
|
||||
std::map<int, BufferAttribute> _vertexStreams;
|
||||
protected:
|
||||
static GLint getGLSize(VertexType type);
|
||||
static GLenum getGLType(VertexType type);
|
||||
static GLint getGLSemanticBinding(VertexSemantic semantic);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
Loading…
Reference in New Issue