Skip to content

Commit 1af518a

Browse files
committed
fix buffer conflict between CPU and GPU on iOS/macOS
1 parent 9015578 commit 1af518a

23 files changed

+158
-42
lines changed

build/cocos2d_libs.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@
800800
46C02E0818E91123004B7456 /* xxhash.c in Sources */ = {isa = PBXBuildFile; fileRef = 46C02E0518E91123004B7456 /* xxhash.c */; };
801801
46C02E0918E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; };
802802
46C02E0A18E91123004B7456 /* xxhash.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C02E0618E91123004B7456 /* xxhash.h */; };
803+
46D3D45B21DE014500EF5E75 /* BufferManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46D3D45921DE014500EF5E75 /* BufferManager.mm */; };
804+
46D3D45C21DE014500EF5E75 /* BufferManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46D3D45921DE014500EF5E75 /* BufferManager.mm */; };
805+
46D3D45D21DE014500EF5E75 /* BufferManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46D3D45A21DE014500EF5E75 /* BufferManager.h */; };
806+
46D3D45E21DE014500EF5E75 /* BufferManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 46D3D45A21DE014500EF5E75 /* BufferManager.h */; };
803807
46E21B4721B900C900430A43 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E21B4521B900C900430A43 /* StringUtils.cpp */; };
804808
46E21B4821B900C900430A43 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46E21B4521B900C900430A43 /* StringUtils.cpp */; };
805809
46E21B4921B900C900430A43 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 46E21B4621B900C900430A43 /* StringUtils.h */; };
@@ -2890,6 +2894,8 @@
28902894
46BDE4A91FA3316A00104C05 /* libbox2d.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbox2d.a; path = ../external/Box2D/prebuilt/ios/libbox2d.a; sourceTree = "<group>"; };
28912895
46C02E0518E91123004B7456 /* xxhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xxhash.c; sourceTree = "<group>"; };
28922896
46C02E0618E91123004B7456 /* xxhash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xxhash.h; sourceTree = "<group>"; };
2897+
46D3D45921DE014500EF5E75 /* BufferManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BufferManager.mm; sourceTree = "<group>"; };
2898+
46D3D45A21DE014500EF5E75 /* BufferManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BufferManager.h; sourceTree = "<group>"; };
28932899
46E21B4521B900C900430A43 /* StringUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringUtils.cpp; sourceTree = "<group>"; };
28942900
46E21B4621B900C900430A43 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
28952901
46E7207B1ECAC75C0034BEC7 /* ccShader_ETC1AS_PositionTextureColor.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_ETC1AS_PositionTextureColor.frag; sourceTree = "<group>"; };
@@ -4576,6 +4582,8 @@
45764582
460D4D0121ABD0C60075726E /* TextureMTL.mm */,
45774583
460D4CF421ABD0C60075726E /* Utils.h */,
45784584
460D4CF621ABD0C60075726E /* Utils.mm */,
4585+
46D3D45921DE014500EF5E75 /* BufferManager.mm */,
4586+
46D3D45A21DE014500EF5E75 /* BufferManager.h */,
45794587
);
45804588
path = metal;
45814589
sourceTree = "<group>";
@@ -6294,6 +6302,7 @@
62946302
50ABBE5B1925AB6F00A911A9 /* CCEventKeyboard.h in Headers */,
62956303
EDC78D1221CA19FC00E1863C /* CCArmatureDataManager.h in Headers */,
62966304
4631CBED21AFD9FA0000D408 /* UIPageView.h in Headers */,
6305+
46D3D45D21DE014500EF5E75 /* BufferManager.h in Headers */,
62976306
1A40D1391E8E56C7002E363A /* pow10.h in Headers */,
62986307
50ABC00F1926664800A911A9 /* CCFileUtils.h in Headers */,
62996308
50ABBE3B1925AB6F00A911A9 /* CCData.h in Headers */,
@@ -6808,6 +6817,7 @@
68086817
50ABBEC41925AB6F00A911A9 /* CCVector.h in Headers */,
68096818
EDC78BED21CA19FB00E1863C /* CCComAttribute.h in Headers */,
68106819
EDC78C9921CA19FC00E1863C /* TextAtlasReader.h in Headers */,
6820+
46D3D45E21DE014500EF5E75 /* BufferManager.h in Headers */,
68116821
50ABBE501925AB6F00A911A9 /* CCEventCustom.h in Headers */,
68126822
A0534A661B872FFD006B03E5 /* CCDownloader-apple.h in Headers */,
68136823
B240C5EC1B09DFB000137F50 /* CCFrameBuffer.h in Headers */,
@@ -7700,6 +7710,7 @@
77007710
B6DD2FF51B04825B00E47F5F /* fastlz.c in Sources */,
77017711
15AE1BB519AADFEF00C27E9E /* SocketIO.cpp in Sources */,
77027712
EDC78C4221CA19FB00E1863C /* FlatBuffersSerialize.cpp in Sources */,
7713+
46D3D45B21DE014500EF5E75 /* BufferManager.mm in Sources */,
77037714
50ABBE5D1925AB6F00A911A9 /* CCEventListener.cpp in Sources */,
77047715
50ABBD601925AB0000A911A9 /* Vec4.cpp in Sources */,
77057716
EDC78C7A21CA19FC00E1863C /* ArmatureNodeReader.cpp in Sources */,
@@ -8334,6 +8345,7 @@
83348345
1A1645B1191B726C008C7C7F /* ConvertUTF.c in Sources */,
83358346
50ABBE3A1925AB6F00A911A9 /* CCData.cpp in Sources */,
83368347
1A1645B3191B726C008C7C7F /* ConvertUTFWrapper.cpp in Sources */,
8348+
46D3D45C21DE014500EF5E75 /* BufferManager.mm in Sources */,
83378349
B6DD2FEA1B04825B00E47F5F /* DetourProximityGrid.cpp in Sources */,
83388350
1ABA68AF1888D700007D1BB4 /* CCFontCharMap.cpp in Sources */,
83398351
46F9B74A21B0CB44009DF858 /* UIWebViewImpl-ios.mm in Sources */,

cocos/2d/CCDrawNode.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void DrawNode::ensureCapacity(int count)
155155
_bufferCapacity += MAX(_bufferCapacity, count);
156156
_buffer = (V2F_C4B_T2F*)realloc(_buffer, _bufferCapacity*sizeof(V2F_C4B_T2F));
157157

158-
_customCommand.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacity);
158+
_customCommand.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacity, CustomCommand::BufferUsage::STATIC);
159159
_customCommand.updateVertexBuffer(_buffer, _bufferCapacity*sizeof(V2F_C4B_T2F));
160160
}
161161
}
@@ -169,7 +169,7 @@ void DrawNode::ensureCapacityGLPoint(int count)
169169
_bufferCapacityGLPoint += MAX(_bufferCapacityGLPoint, count);
170170
_bufferGLPoint = (V2F_C4B_T2F*)realloc(_bufferGLPoint, _bufferCapacityGLPoint*sizeof(V2F_C4B_T2F));
171171

172-
_customCommandGLPoint.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityGLPoint);
172+
_customCommandGLPoint.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityGLPoint, CustomCommand::BufferUsage::STATIC);
173173
_customCommandGLPoint.updateVertexBuffer(_bufferGLPoint, _bufferCapacityGLPoint*sizeof(V2F_C4B_T2F));
174174
}
175175
}
@@ -183,7 +183,7 @@ void DrawNode::ensureCapacityGLLine(int count)
183183
_bufferCapacityGLLine += MAX(_bufferCapacityGLLine, count);
184184
_bufferGLLine = (V2F_C4B_T2F*)realloc(_bufferGLLine, _bufferCapacityGLLine*sizeof(V2F_C4B_T2F));
185185

186-
_customCommandGLLine.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityGLLine);
186+
_customCommandGLLine.createVertexBuffer(sizeof(V2F_C4B_T2F), _bufferCapacityGLLine, CustomCommand::BufferUsage::STATIC);
187187
_customCommandGLLine.updateVertexBuffer(_bufferGLLine, _bufferCapacityGLLine*sizeof(V2F_C4B_T2F));
188188
}
189189
}

cocos/2d/CCGrid.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,10 @@ void Grid3D::updateVertexAndTexCoordinate()
521521
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
522522
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &tempTexPointer[i], sizeof(Vec2));
523523
}
524-
_drawCommand.createVertexBuffer((unsigned int)(sizeof(Vec3) + sizeof(Vec2)), numOfPoints);
524+
_drawCommand.createVertexBuffer((unsigned int)(sizeof(Vec3) + sizeof(Vec2)), numOfPoints, CustomCommand::BufferUsage::DYNAMIC);
525525
_drawCommand.updateVertexBuffer(_vertexBuffer, numOfPoints * sizeof(Vec3) + numOfPoints * sizeof(Vec2));
526526

527-
_drawCommand.createIndexBuffer(sizeof(unsigned short), _gridSize.width * _gridSize.height * 6);
527+
_drawCommand.createIndexBuffer(sizeof(unsigned short), _gridSize.width * _gridSize.height * 6, CustomCommand::BufferUsage::DYNAMIC);
528528
_drawCommand.updateIndexBuffer(_indices, _gridSize.width * _gridSize.height * 6 * sizeof(unsigned short));
529529
}
530530

@@ -777,10 +777,10 @@ void TiledGrid3D::updateVertexAndTexCoordinate()
777777
memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3));
778778
memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &tempTexPointer[i], sizeof(Vec2));
779779
}
780-
_drawCommand.createVertexBuffer((unsigned int)(sizeof(Vec3) + sizeof(Vec2) ), numOfPoints);
780+
_drawCommand.createVertexBuffer((unsigned int)(sizeof(Vec3) + sizeof(Vec2) ), numOfPoints, CustomCommand::BufferUsage::DYNAMIC);
781781
_drawCommand.updateVertexBuffer(_vertexBuffer, numOfPoints * sizeof(Vec3) + numOfPoints * sizeof(Vec2));
782782

783-
_drawCommand.createIndexBuffer(sizeof(unsigned short), _gridSize.width * _gridSize.height * 6);
783+
_drawCommand.createIndexBuffer(sizeof(unsigned short), _gridSize.width * _gridSize.height * 6, CustomCommand::BufferUsage::DYNAMIC);
784784
_drawCommand.updateIndexBuffer(_indices, _gridSize.width * _gridSize.height * 6 * sizeof(unsigned short));
785785
}
786786

cocos/2d/CCLabel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,8 @@ void Label::updateBuffer(TextureAtlas* textureAtlas, CustomCommand& customComman
15071507
{
15081508
if(textureAtlas->getTotalQuads() > customCommand.getVertexCapacity())
15091509
{
1510-
customCommand.createVertexBuffer((unsigned int)sizeof(V3F_C4B_T2F_Quad), (unsigned int)textureAtlas->getTotalQuads());
1511-
customCommand.createIndexBuffer((unsigned int)sizeof(unsigned short), (unsigned int)textureAtlas->getTotalQuads()*6);
1510+
customCommand.createVertexBuffer((unsigned int)sizeof(V3F_C4B_T2F_Quad), (unsigned int)textureAtlas->getTotalQuads(), CustomCommand::BufferUsage::DYNAMIC);
1511+
customCommand.createIndexBuffer((unsigned int)sizeof(unsigned short), (unsigned int)textureAtlas->getTotalQuads()*6, CustomCommand::BufferUsage::DYNAMIC);
15121512
}
15131513
customCommand.updateVertexBuffer(textureAtlas->getQuads(), (unsigned int)(textureAtlas->getTotalQuads() * sizeof(V3F_C4B_T2F_Quad)) );
15141514
customCommand.updateIndexBuffer(textureAtlas->getIndices(), (unsigned int)(textureAtlas->getTotalQuads()*6*sizeof(unsigned short)) );

cocos/2d/CCLayer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@ LayerColor::LayerColor()
309309
pipelineDescriptor.vertexShader = ShaderCache::newVertexShaderModule(positionColor_vert);
310310
pipelineDescriptor.fragmentShader = ShaderCache::newFragmentShaderModule(positionColor_frag);
311311

312-
_customCommand.createIndexBuffer(sizeof(unsigned short), 6);
312+
_customCommand.createIndexBuffer(sizeof(unsigned short), 6, CustomCommand::BufferUsage::STATIC);
313313
unsigned short indices[] = {0, 1, 2, 2, 1, 3};
314314
_customCommand.updateIndexBuffer(indices, sizeof(indices));
315315

316-
_customCommand.createVertexBuffer(sizeof(_noMVPVertices[0]) + sizeof(_squareColors[0]), 4);
316+
_customCommand.createVertexBuffer(sizeof(_noMVPVertices[0]) + sizeof(_squareColors[0]), 4, CustomCommand::BufferUsage::DYNAMIC);
317317

318318
_customCommand.setDrawType(CustomCommand::DrawType::ELEMENT);
319319
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE);
@@ -726,7 +726,7 @@ LayerRadialGradient::LayerRadialGradient()
726726
vertexLayout.setAtrribute("a_position", 0, backend::VertexFormat::FLOAT_R32G32, 0, false);
727727
vertexLayout.setLayout(sizeof(_vertices[0]), backend::VertexStepMode::VERTEX);
728728

729-
_customCommand.createVertexBuffer(sizeof(_vertices[0]), sizeof(_vertices) / sizeof(_vertices[0]));
729+
_customCommand.createVertexBuffer(sizeof(_vertices[0]), sizeof(_vertices) / sizeof(_vertices[0]), CustomCommand::BufferUsage::DYNAMIC);
730730
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
731731
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE_STRIP);
732732
}

cocos/2d/CCMotionStreak.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co
121121
_vertices = (Vec2*)malloc(sizeof(Vec2) * _vertexCount);
122122
_texCoords = (Tex2F*)malloc(sizeof(Tex2F) * _vertexCount);
123123
_colorPointer = (uint8_t*)malloc(sizeof(uint8_t) * 4 * _vertexCount);
124-
_customCommand.createVertexBuffer(sizeof(Vec2) + sizeof(Tex2F) + sizeof(uint8_t) * 4, _vertexCount);
124+
_customCommand.createVertexBuffer(sizeof(Vec2) + sizeof(Tex2F) + sizeof(uint8_t) * 4, _vertexCount, CustomCommand::BufferUsage::DYNAMIC);
125125

126126
setTexture(texture);
127127
setColor(color);

cocos/2d/CCParticleBatchNode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,10 @@ void ParticleBatchNode::draw(Renderer* renderer, const Mat4 & transform, uint32_
446446
unsigned int capacity = (unsigned int)_textureAtlas->getCapacity();
447447
const auto& indices = _textureAtlas->getIndices();
448448

449-
_customCommand.createVertexBuffer((unsigned int)(sizeof(quads[0]) ), capacity);
449+
_customCommand.createVertexBuffer((unsigned int)(sizeof(quads[0]) ), capacity, CustomCommand::BufferUsage::STATIC);
450450
_customCommand.updateVertexBuffer(quads, sizeof(quads[0]) * capacity);
451451

452-
_customCommand.createIndexBuffer(sizeof(indices[0]) , capacity * 6);
452+
_customCommand.createIndexBuffer(sizeof(indices[0]) , capacity * 6, CustomCommand::BufferUsage::STATIC);
453453
_customCommand.updateIndexBuffer(indices, sizeof(indices[0]) * capacity * 6);
454454
}
455455

cocos/2d/CCProgressTimer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ void ProgressTimer::updateRadial(void)
376376
{
377377
sameIndexCount = false;
378378
_vertexData.resize(index + 3);
379-
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), (unsigned int)_vertexData.size());
379+
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), (unsigned int)_vertexData.size(), CustomCommand::BufferUsage::DYNAMIC);
380380
}
381381

382382
if (_indexData.size() != 3 + 3 * index)
383383
{
384384
_indexData.resize(3 + 3 * index);
385-
_customCommand.createIndexBuffer(sizeof(_indexData[0]), (unsigned int)_indexData.size());
385+
_customCommand.createIndexBuffer(sizeof(_indexData[0]), (unsigned int)_indexData.size(), CustomCommand::BufferUsage::DYNAMIC);
386386
}
387387

388388
if (!sameIndexCount)
@@ -465,7 +465,7 @@ void ProgressTimer::updateBar(void)
465465
if (_vertexData.size() != 4)
466466
{
467467
_vertexData.resize(4);
468-
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size());
468+
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size(), CustomCommand::BufferUsage::DYNAMIC);
469469
}
470470

471471
// TOPLEFT
@@ -490,8 +490,8 @@ void ProgressTimer::updateBar(void)
490490
} else {
491491
if(_vertexData.size() != 8) {
492492
_vertexData.resize(8);
493-
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size() / 2);
494-
_customCommand2.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size() / 2);
493+
_customCommand.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size() / 2, CustomCommand::BufferUsage::DYNAMIC);
494+
_customCommand2.createVertexBuffer(sizeof(_vertexData[0]), _vertexData.size() / 2, CustomCommand::BufferUsage::DYNAMIC);
495495
// TOPLEFT 1
496496
_vertexData[0].texCoords = textureCoordFromAlphaPoint(Vec2(0,1));
497497
_vertexData[0].vertices = vertexFromAlphaPoint(Vec2(0,1));

cocos/base/CCDirector.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ void Director::setGLDefaultValues()
249249
// Draw the Scene
250250
void Director::drawScene()
251251
{
252+
_renderer->beginFrame();
253+
252254
// calculate "global" dt
253255
calculateDeltaTime();
254256

@@ -265,7 +267,6 @@ void Director::drawScene()
265267
_eventDispatcher->dispatchEvent(_eventAfterUpdate);
266268
}
267269

268-
_renderer->beginFrame();
269270
_renderer->clear(ClearFlag::ALL, _clearColor, 1, 0);
270271
experimental::FrameBuffer::clearAllFBOs();
271272

cocos/base/CCStencilStateManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ StencilStateManager::StencilStateManager()
4949
Vec2(1.0f, 1.0f),
5050
Vec2(-1.0f, 1.0f)
5151
};
52-
_customCommand.createVertexBuffer(sizeof(Vec2), 4);
52+
_customCommand.createVertexBuffer(sizeof(Vec2), 4, CustomCommand::BufferUsage::STATIC);
5353
_customCommand.updateVertexBuffer(vertices, sizeof(vertices));
5454

5555
unsigned short indices[6] = {0, 1, 2, 0, 2, 3};
56-
_customCommand.createIndexBuffer(sizeof(unsigned short), 6);
56+
_customCommand.createIndexBuffer(sizeof(unsigned short), 6, CustomCommand::BufferUsage::STATIC);
5757
_customCommand.updateIndexBuffer(indices, sizeof(indices));
5858

5959
Color4F color(1, 1, 1, 1);

cocos/renderer/CCCustomCommand.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void CustomCommand::init(float globalZOrder, const BlendFunc& blendFunc)
5555
blendDescriptor.destinationRGBBlendFactor = blendDescriptor.destinationAlphaBlendFactor = utils::toBackendBlendFactor(blendFunc.dst);
5656
}
5757

58-
void CustomCommand::createVertexBuffer(unsigned int vertexSize, unsigned int capacity)
58+
void CustomCommand::createVertexBuffer(unsigned int vertexSize, unsigned int capacity, BufferUsage usage)
5959
{
6060
CC_SAFE_RELEASE(_vertexBuffer);
6161

@@ -64,10 +64,10 @@ void CustomCommand::createVertexBuffer(unsigned int vertexSize, unsigned int cap
6464
_vertexDrawCount = capacity;
6565

6666
auto device = backend::Device::getInstance();
67-
_vertexBuffer = device->newBuffer(vertexSize * capacity, backend::BufferType::VERTEX, backend::BufferUsage::READ);
67+
_vertexBuffer = device->newBuffer(vertexSize * capacity, backend::BufferType::VERTEX, usage);
6868
}
6969

70-
void CustomCommand::createIndexBuffer(unsigned int indexSize, unsigned int capacity)
70+
void CustomCommand::createIndexBuffer(unsigned int indexSize, unsigned int capacity, BufferUsage usage)
7171
{
7272
CC_SAFE_RELEASE(_indexBuffer);
7373

@@ -76,7 +76,7 @@ void CustomCommand::createIndexBuffer(unsigned int indexSize, unsigned int capac
7676
_indexDrawCount = capacity;
7777

7878
auto device = backend::Device::getInstance();
79-
_indexBuffer = device->newBuffer(indexSize * capacity, backend::BufferType::INDEX, backend::BufferUsage::READ);
79+
_indexBuffer = device->newBuffer(indexSize * capacity, backend::BufferType::INDEX, usage);
8080
}
8181

8282
void CustomCommand::updateVertexBuffer(void* data, unsigned int offset, unsigned int length)

cocos/renderer/CCCustomCommand.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class CC_DLL CustomCommand : public RenderCommand
5353
};
5454

5555
using PrimitiveType = backend::PrimitiveType;
56+
using BufferUsage = backend::BufferUsage;
5657

5758
/**Constructor.*/
5859
CustomCommand();
@@ -75,8 +76,8 @@ class CC_DLL CustomCommand : public RenderCommand
7576
void init(float globalZOrder);
7677
void init(float globalZOrder, const BlendFunc& blendFunc);
7778

78-
void createVertexBuffer(unsigned int vertexSize, unsigned int capacity);
79-
void createIndexBuffer(unsigned int indexSize, unsigned int capacity);
79+
void createVertexBuffer(unsigned int vertexSize, unsigned int capacity, BufferUsage usage);
80+
void createIndexBuffer(unsigned int indexSize, unsigned int capacity, BufferUsage usage);
8081

8182
void updateVertexBuffer(void* data, unsigned int length);
8283
void updateIndexBuffer(void* data, unsigned int length);

cocos/renderer/CCRenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,15 @@ void Renderer::TriangleCommandBufferManager::prepareNextBuffer()
10251025
if (!tmpData)
10261026
return;
10271027

1028-
auto vertexBuffer = device->newBuffer(Renderer::VBO_SIZE * sizeof(_verts[0]), backend::BufferType::VERTEX, backend::BufferUsage::READ);
1028+
auto vertexBuffer = device->newBuffer(Renderer::VBO_SIZE * sizeof(_verts[0]), backend::BufferType::VERTEX, backend::BufferUsage::DYNAMIC);
10291029
if (!vertexBuffer)
10301030
{
10311031
free(tmpData);
10321032
return;
10331033
}
10341034
vertexBuffer->updateData(tmpData, Renderer::VBO_SIZE * sizeof(_verts[0]));
10351035

1036-
auto indexBuffer = device->newBuffer(Renderer::INDEX_VBO_SIZE * sizeof(_indices[0]), backend::BufferType::INDEX, backend::BufferUsage::READ);
1036+
auto indexBuffer = device->newBuffer(Renderer::INDEX_VBO_SIZE * sizeof(_indices[0]), backend::BufferType::INDEX, backend::BufferUsage::DYNAMIC);
10371037
if (! indexBuffer)
10381038
{
10391039
free(tmpData);

cocos/renderer/backend/Buffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Buffer : public cocos2d::Ref
2121

2222
virtual ~Buffer() = default;
2323

24-
BufferUsage _usage = BufferUsage::READ;
24+
BufferUsage _usage = BufferUsage::DYNAMIC;
2525
BufferType _type = BufferType::VERTEX;
2626
unsigned int _size = 0;
2727
};

cocos/renderer/backend/Macros.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
#define CC_BACKEND_BEGIN namespace cocos2d{ namespace backend{
44
#define CC_BACKEND_END }}
55

6-
// FIXME: is 8 enough?
7-
#define MAX_COLOR_ATTCHMENT 8
6+
#define MAX_COLOR_ATTCHMENT 1
7+
8+
#define MAX_INFLIGHT_BUFFER 3

0 commit comments

Comments
 (0)