Skip to content

Commit 23732ab

Browse files
Mee-guminggo
authored andcommitted
remove arrays of vertex buffer (#20022)
1 parent 3c693c7 commit 23732ab

File tree

6 files changed

+25
-44
lines changed

6 files changed

+25
-44
lines changed

cocos/renderer/CCRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ void Renderer::drawBatchedTriangles()
634634
for (int i = 0; i < batchesTotal; ++i)
635635
{
636636
beginRenderPass(_triBatchesToDraw[i].cmd);
637-
_commandBuffer->setVertexBuffer(0, _vertexBuffer);
637+
_commandBuffer->setVertexBuffer(_vertexBuffer);
638638
_commandBuffer->setIndexBuffer(_indexBuffer);
639639
auto& pipelineDescriptor = _triBatchesToDraw[i].cmd->getPipelineDescriptor();
640640
_commandBuffer->setProgramState(pipelineDescriptor.programState);
@@ -664,7 +664,7 @@ void Renderer::drawCustomCommand(RenderCommand *command)
664664
if (cmd->getBeforeCallback()) cmd->getBeforeCallback()();
665665

666666
beginRenderPass(command);
667-
_commandBuffer->setVertexBuffer(0, cmd->getVertexBuffer());
667+
_commandBuffer->setVertexBuffer(cmd->getVertexBuffer());
668668
_commandBuffer->setProgramState(cmd->getPipelineDescriptor().programState);
669669

670670
auto drawType = cmd->getDrawType();

cocos/renderer/backend/CommandBuffer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ class CommandBuffer : public cocos2d::Ref
9898

9999
/**
100100
* Set a global buffer for all vertex shaders at the given bind point index 0.
101-
* @param index An index in the buffer argument table.
102101
* @param buffer The vertex buffer to be setted in the buffer argument table.
103102
*/
104-
virtual void setVertexBuffer(unsigned int index, Buffer* buffer) = 0;
103+
virtual void setVertexBuffer(Buffer* buffer) = 0;
105104

106105
/**
107106
* Set unifroms and textures

cocos/renderer/backend/metal/CommandBufferMTL.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ class CommandBufferMTL final : public CommandBuffer
9797

9898
/**
9999
* Set a global buffer for all vertex shaders at the given bind point index 0.
100-
* @param index An index in the buffer argument table.
101100
* @param buffer The buffer to set in the buffer argument table.
102101
*/
103-
virtual void setVertexBuffer(unsigned int index, Buffer* buffer) override;
102+
virtual void setVertexBuffer(Buffer* buffer) override;
104103

105104
/**
106105
* Set the uniform data at a given vertex and fragment buffer binding point 1

cocos/renderer/backend/metal/CommandBufferMTL.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ MTLCullMode toMTLCullMode(CullMode mode)
292292
[_mtlRenderEncoder setFrontFacingWinding:toMTLWinding(winding)];
293293
}
294294

295-
void CommandBufferMTL::setVertexBuffer(unsigned int index, Buffer* buffer)
295+
void CommandBufferMTL::setVertexBuffer(Buffer* buffer)
296296
{
297297
// Vertex buffer is bound in index 0.
298298
[_mtlRenderEncoder setVertexBuffer:static_cast<BufferMTL*>(buffer)->getMTLBuffer()

cocos/renderer/backend/opengl/CommandBufferGL.cpp

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,15 @@ void CommandBufferGL::setIndexBuffer(Buffer* buffer)
319319
_indexBuffer = static_cast<BufferGL*>(buffer);
320320
}
321321

322-
void CommandBufferGL::setVertexBuffer(unsigned int index, Buffer* buffer)
322+
void CommandBufferGL::setVertexBuffer(Buffer* buffer)
323323
{
324324
assert(buffer != nullptr);
325325
if (buffer == nullptr)
326326
return;
327327

328328
buffer->retain();
329329

330-
if (index >= _vertexBuffers.size())
331-
_vertexBuffers.resize(index + 1);
332-
333-
CC_SAFE_RELEASE(_vertexBuffers[index]);
334-
_vertexBuffers[index] = static_cast<BufferGL*>(buffer);
330+
_vertexBuffer = static_cast<BufferGL*>(buffer);
335331
}
336332

337333
void CommandBufferGL::setProgramState(ProgramState* programState)
@@ -419,31 +415,23 @@ void CommandBufferGL::bindVertexBuffer(ProgramGL *program) const
419415
int i = 0;
420416
const auto& attributeInfos = program->getAttributeInfos();
421417
const auto& vertexLayouts = getVertexLayouts();
422-
for (const auto& vertexBuffer : _vertexBuffers)
423-
{
424-
if (! vertexBuffer)
425-
continue;
426-
if (i >= attributeInfos.size())
427-
break;
428-
429-
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->getHandler());
418+
419+
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer->getHandler());
430420

431-
const auto& attributeInfo = attributeInfos[i];
432-
const auto &layouts = vertexLayouts->at(i);
433-
for (const auto& attribute : attributeInfo)
434-
{
435-
const auto &layoutInfo = layouts.getAttributes().at(attribute.name);
436-
glEnableVertexAttribArray(attribute.location);
437-
glVertexAttribPointer(attribute.location,
438-
UtilsGL::getGLAttributeSize(layoutInfo.format),
439-
UtilsGL::toGLAttributeType(layoutInfo.format),
440-
layoutInfo.needToBeNormallized,
441-
layouts.getStride(),
442-
(GLvoid*)layoutInfo.offset);
443-
}
444-
445-
++i;
421+
const auto& attributeInfo = attributeInfos[i];
422+
const auto &layouts = vertexLayouts->at(i);
423+
for (const auto& attribute : attributeInfo)
424+
{
425+
const auto &layoutInfo = layouts.getAttributes().at(attribute.name);
426+
glEnableVertexAttribArray(attribute.location);
427+
glVertexAttribPointer(attribute.location,
428+
UtilsGL::getGLAttributeSize(layoutInfo.format),
429+
UtilsGL::toGLAttributeType(layoutInfo.format),
430+
layoutInfo.needToBeNormallized,
431+
layouts.getStride(),
432+
(GLvoid*)layoutInfo.offset);
446433
}
434+
447435
}
448436

449437
void CommandBufferGL::setUniforms(ProgramGL* program) const
@@ -598,11 +586,7 @@ void CommandBufferGL::cleanResources()
598586
CC_SAFE_RELEASE_NULL(_indexBuffer);
599587
CC_SAFE_RELEASE_NULL(_renderPipeline);
600588
CC_SAFE_RELEASE_NULL(_programState);
601-
602-
for (const auto& vertexBuffer : _vertexBuffers)
603-
CC_SAFE_RELEASE(vertexBuffer);
604-
605-
_vertexBuffers.clear();
589+
CC_SAFE_RELEASE(_vertexBuffer);
606590
}
607591

608592
void CommandBufferGL::setLineWidth(float lineWidth)

cocos/renderer/backend/opengl/CommandBufferGL.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ class CommandBufferGL final : public CommandBuffer
9696

9797
/**
9898
* Set a global buffer for all vertex shaders at the given bind point index 0.
99-
* @param index An index in the buffer argument table.
10099
* @param buffer The vertex buffer to be setted in the buffer argument table.
101100
*/
102-
virtual void setVertexBuffer(unsigned int index, Buffer* buffer) override;
101+
virtual void setVertexBuffer(Buffer* buffer) override;
103102

104103
/**
105104
* Set unifroms and textures
@@ -194,7 +193,7 @@ class CommandBufferGL final : public CommandBuffer
194193

195194
GLint _defaultFBO = 0; // The value gets from glGetIntegerv, so need to use GLint
196195
GLuint _currentFBO = 0;
197-
std::vector<BufferGL*> _vertexBuffers;
196+
BufferGL* _vertexBuffer;
198197
ProgramState* _programState = nullptr;
199198
BufferGL* _indexBuffer = nullptr;
200199
RenderPipelineGL* _renderPipeline = nullptr;

0 commit comments

Comments
 (0)