Skip to content

Commit a7c9a65

Browse files
committed
remove MeshPart
1 parent 3b7b406 commit a7c9a65

File tree

5 files changed

+59
-219
lines changed

5 files changed

+59
-219
lines changed

cocos/3d/CCMesh.cpp

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "base/ccMacros.h"
1010
#include "renderer/ccGLStateCache.h"
11-
#include "CCMeshPart.h"
1211
#include "CCObjLoader.h"
1312
#include "CCSprite3DDataCache.h"
1413

@@ -97,28 +96,28 @@ bool RenderMeshData::initFrom(std::vector<float>& posions, std::vector<float>& n
9796

9897
Mesh::Mesh()
9998
:_vertexBuffer(0)
100-
, _parts(nullptr)
101-
, _partCount(0)
99+
, _indexBuffer(0)
100+
, _primitiveType(PrimitiveType_TRIANGLES)
101+
, _indexFormat(IndexFormat_INDEX16)
102+
, _indexCount(0)
102103
{
103104

104105

105106
}
106107

107108
Mesh::~Mesh()
108109
{
109-
releaseMeshPart();
110-
111-
freeBuffers();
110+
cleanAndFreeBuffers();
112111
}
113112

114-
void Mesh::releaseMeshPart()
115-
{
116-
// for (unsigned int i = 0; i < _partCount; ++i)
117-
// {
118-
// delete _parts[i];
119-
// }
120-
// delete _parts;
121-
}
113+
//void Mesh::releaseMeshPart()
114+
//{
115+
// glDeleteBuffers(1, &_indexBuffer);
116+
// _primitiveType = PrimitiveType_TRIANGLES;
117+
// _indexFormat = IndexFormat_INDEX16;
118+
// _indexCount = 0;
119+
// _indexBuffer = 0;
120+
//}
122121

123122
Mesh* Mesh::create(std::vector<float>& posions, std::vector<float>& normals, std::vector<float>& texs, const std::vector<unsigned short>& indices)
124123
{
@@ -144,18 +143,27 @@ bool Mesh::init(std::vector<float>& posions, std::vector<float>& normals, std::v
144143
return true;
145144
}
146145

147-
void Mesh::freeBuffers()
146+
void Mesh::cleanAndFreeBuffers()
148147
{
149148
if(glIsBuffer(_vertexBuffer))
150149
{
151150
glDeleteBuffers(1, &_vertexBuffer);
152151
_vertexBuffer = 0;
153152
}
153+
154+
if(glIsBuffer(_indexBuffer))
155+
{
156+
glDeleteBuffers(1, &_indexBuffer);
157+
_indexBuffer = 0;
158+
}
159+
_primitiveType = PrimitiveType_TRIANGLES;
160+
_indexFormat = IndexFormat_INDEX16;
161+
_indexCount = 0;
154162
}
155163

156164
void Mesh::buildBuffer()
157165
{
158-
freeBuffers();
166+
cleanAndFreeBuffers();
159167

160168
glGenBuffers(1, &_vertexBuffer);
161169
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
@@ -165,39 +173,10 @@ void Mesh::buildBuffer()
165173
&_renderdata._vertexs[0],
166174
GL_STATIC_DRAW);
167175
glBindBuffer(GL_ARRAY_BUFFER, 0);
168-
}
169-
170-
//void Mesh::addMeshPart(PrimitiveType primitiveType, IndexFormat indexformat, void* indexData, unsigned int indexCount)
171-
//{
172-
// MeshPart* part = MeshPart::create(this, _partCount, primitiveType, indexformat, indexData, indexCount);
173-
// if (part)
174-
// {
175-
// // Increase size of part array and copy old subets into it.
176-
// MeshPart** oldParts = _parts;
177-
// _parts = new MeshPart*[_partCount + 1];
178-
// for (unsigned int i = 0; i < _partCount; ++i)
179-
// {
180-
// _parts[i] = oldParts[i];
181-
// }
182-
//
183-
// // Add new part to array.
184-
// _parts[_partCount++] = part;
185-
//
186-
// // Delete old part array.
187-
// delete[] (oldParts);
188-
// }
189-
//}
190-
191-
void Mesh::restore()
192-
{
193-
releaseMeshPart();
194-
195-
buildBuffer();
196176

197-
GLuint vbo;
198-
glGenBuffers(1, &vbo);
177+
glGenBuffers(1, &_indexBuffer);
199178

200-
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo);
179+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
201180

202181
unsigned int indexSize = 2;
203182
IndexFormat indexformat = IndexFormat_INDEX16;
@@ -209,7 +188,13 @@ void Mesh::restore()
209188
_primitiveType = PrimitiveType_TRIANGLES;
210189
_indexFormat = indexformat;
211190
_indexCount = _renderdata._indices.size();
212-
_indexBuffer = vbo;
191+
}
192+
193+
void Mesh::restore()
194+
{
195+
cleanAndFreeBuffers();
196+
197+
buildBuffer();
213198

214199
}
215200

cocos/3d/CCMesh.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "base/CCRef.h"
99
#include "base/ccTypes.h"
10-
#include "CCMeshPart.h"
1110
#include "math/CCMath.h"
1211
#include "renderer/CCGLProgram.h"
1312

@@ -16,7 +15,26 @@ USING_NS_CC_MATH;
1615

1716
NS_CC_BEGIN
1817

19-
class MeshPart;
18+
/**
19+
* Defines supported index formats.
20+
*/
21+
enum IndexFormat
22+
{
23+
IndexFormat_INDEX8 = GL_UNSIGNED_BYTE,
24+
IndexFormat_INDEX16 = GL_UNSIGNED_SHORT,
25+
};
26+
27+
/**
28+
* Defines supported primitive types.
29+
*/
30+
enum PrimitiveType
31+
{
32+
PrimitiveType_TRIANGLES = GL_TRIANGLES,
33+
PrimitiveType_TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
34+
PrimitiveType_LINES = GL_LINES,
35+
PrimitiveType_LINE_STRIP = GL_LINE_STRIP,
36+
PrimitiveType_POINTS = GL_POINTS
37+
};
2038

2139
//mesh vertex attribute
2240
struct MeshVertexAttrib
@@ -67,10 +85,6 @@ class Mesh : public Ref
6785
//get vertex buffer
6886
inline GLuint getVertexBuffer() const { return _vertexBuffer; }
6987

70-
71-
//build vertex buffer from renderdata
72-
void restore();
73-
7488
//get mesh vertex attribute count
7589
int getMeshVertexAttribCount() const { return _renderdata._vertexAttribs.size(); }
7690

@@ -90,15 +104,18 @@ class Mesh : public Ref
90104
IndexFormat getIndexFormat() const { return _indexFormat; }
91105

92106
GLuint getIndexBuffer() const {return _indexBuffer; }
107+
108+
//build vertex buffer from renderdata
109+
void restore();
93110
protected:
94111
Mesh();
95-
112+
96113
//build buffer
97114
void buildBuffer();
98115

99-
void freeBuffers();
116+
void cleanAndFreeBuffers();
100117

101-
void releaseMeshPart();
118+
//void releaseMeshPart();
102119

103120
//void addMeshPart(PrimitiveType primitiveType, IndexFormat indexformat, void* indexData, unsigned int indexCount);
104121

@@ -108,9 +125,6 @@ class Mesh : public Ref
108125

109126
GLuint _vertexBuffer;
110127

111-
unsigned int _partCount;
112-
MeshPart** _parts;
113-
114128
PrimitiveType _primitiveType;
115129
IndexFormat _indexFormat;
116130
unsigned int _indexCount;

cocos/3d/CCMeshPart.cpp

Lines changed: 0 additions & 90 deletions
This file was deleted.

cocos/3d/CCMeshPart.h

Lines changed: 0 additions & 68 deletions
This file was deleted.

cocos/3d/CCSprite3DDataCache.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void Sprite3DDataCache::listenBackToForeground(EventCustom* event)
112112
for (auto iter = _sprite3DDatas.begin(); iter != _sprite3DDatas.end(); ++iter)
113113
{
114114
auto mesh = iter->second.mesh;
115-
mesh->restore();
116115
}
117116
}
118117
#endif

0 commit comments

Comments
 (0)