Skip to content

Commit 8f7a19a

Browse files
committed
adjust code style
1 parent 553acfb commit 8f7a19a

File tree

3 files changed

+583
-608
lines changed

3 files changed

+583
-608
lines changed

cocos/3d/CCMesh.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ NS_CC_BEGIN
1717

1818
bool RenderMeshData::hasVertexAttrib(int attrib)
1919
{
20-
for (auto itr = _vertexAttribs.begin(); itr != _vertexAttribs.end(); itr++) {
20+
for (auto itr = _vertexAttribs.begin(); itr != _vertexAttribs.end(); itr++)
21+
{
2122
if ((*itr).vertexAttrib == attrib)
2223
return true; //already has
2324
}
@@ -93,7 +94,6 @@ bool RenderMeshData::initFrom(std::vector<float>& posions, std::vector<float>& n
9394
return true;
9495
}
9596

96-
9797
Mesh::Mesh()
9898
:_vertexBuffer(0)
9999
, _indexBuffer(0)
@@ -102,23 +102,13 @@ Mesh::Mesh()
102102
, _indexCount(0)
103103
{
104104

105-
106105
}
107106

108107
Mesh::~Mesh()
109108
{
110109
cleanAndFreeBuffers();
111110
}
112111

113-
//void Mesh::releaseMeshPart()
114-
//{
115-
// glDeleteBuffers(1, &_indexBuffer);
116-
// _primitiveType = PrimitiveType_TRIANGLES;
117-
// _indexFormat = IndexFormat_INDEX16;
118-
// _indexCount = 0;
119-
// _indexBuffer = 0;
120-
//}
121-
122112
Mesh* Mesh::create(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices)
123113
{
124114
auto mesh = new Mesh();
@@ -133,13 +123,11 @@ Mesh* Mesh::create(std::vector<float>& posions, std::vector<float>& normals, std
133123

134124
bool Mesh::init(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices)
135125
{
136-
137126
bool bRet = _renderdata.initFrom(posions, normals, texs, indices);
138127
if (!bRet)
139128
return false;
140129

141130
restore();
142-
143131
return true;
144132
}
145133

@@ -193,9 +181,7 @@ void Mesh::buildBuffer()
193181
void Mesh::restore()
194182
{
195183
cleanAndFreeBuffers();
196-
197184
buildBuffer();
198-
199185
}
200186

201187
NS_CC_END

cocos/3d/CCMesh.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "math/CCMath.h"
1111
#include "renderer/CCGLProgram.h"
1212

13-
1413
NS_CC_BEGIN
1514

1615
/**
@@ -41,10 +40,8 @@ struct MeshVertexAttrib
4140
GLint size;
4241
//GL_FLOAT
4342
GLenum type;
44-
4543
//VERTEX_ATTRIB_POSITION,VERTEX_ATTRIB_COLOR,VERTEX_ATTRIB_TEX_COORD,VERTEX_ATTRIB_NORMAL, GLProgram for detail
4644
int vertexAttrib;
47-
4845
//size in bytes
4946
int attribSizeBytes;
5047
};
@@ -56,9 +53,7 @@ class RenderMeshData
5653
RenderMeshData(): _vertexsizeBytes(0)
5754
{
5855
}
59-
6056
bool hasVertexAttrib(int attrib);
61-
6257
bool initFrom(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices);
6358

6459
protected:
@@ -69,68 +64,49 @@ class RenderMeshData
6964
std::vector<MeshVertexAttrib> _vertexAttribs;
7065
};
7166

72-
7367
class Mesh : public Ref
7468
{
7569
public:
76-
77-
virtual ~Mesh();
78-
7970
//create
8071
static Mesh* create(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices);
81-
82-
bool init(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices);
8372

8473
//get vertex buffer
8574
inline GLuint getVertexBuffer() const { return _vertexBuffer; }
8675

8776
//get mesh vertex attribute count
8877
int getMeshVertexAttribCount() const { return _renderdata._vertexAttribs.size(); }
89-
9078
//get MeshVertexAttribute by index
9179
const MeshVertexAttrib& getMeshVertexAttribute(int idx) const { return _renderdata._vertexAttribs[idx]; }
92-
9380
//has vertex attribute?
9481
bool hasVertexAttrib(int attrib) { return _renderdata.hasVertexAttrib(attrib); }
95-
9682
//get per vertex size in bytes
9783
int getVertexSizeInBytes() const { return _renderdata._vertexsizeBytes; }
9884

9985
PrimitiveType getPrimitiveType() const { return _primitiveType; }
100-
10186
unsigned int getIndexCount() const { return _indexCount; }
102-
10387
IndexFormat getIndexFormat() const { return _indexFormat; }
104-
10588
GLuint getIndexBuffer() const {return _indexBuffer; }
10689

10790
//build vertex buffer from renderdata
10891
void restore();
10992
protected:
11093
Mesh();
94+
virtual ~Mesh();
95+
bool init(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices);
11196

11297
//build buffer
11398
void buildBuffer();
114-
11599
void cleanAndFreeBuffers();
116100

117-
//void releaseMeshPart();
118-
119-
//void addMeshPart(PrimitiveType primitiveType, IndexFormat indexformat, void* indexData, unsigned int indexCount);
120-
121101
protected:
122-
void countVertexData() const;
123102
std::string _name;
124-
125103
GLuint _vertexBuffer;
126-
127104
PrimitiveType _primitiveType;
128105
IndexFormat _indexFormat;
129106
unsigned int _indexCount;
130107
GLuint _indexBuffer;
131108

132109
private:
133-
134110
RenderMeshData _renderdata;
135111
};
136112

0 commit comments

Comments
 (0)