Skip to content

Commit c4e6ede

Browse files
Mee-guminggo
authored andcommitted
move VertexLayout to ProgramState (#20029)
* move VertexLayout to ProgramState * fix lua
1 parent e23f1f3 commit c4e6ede

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+246
-375
lines changed

cocos/2d/CCAtlasNode.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,27 @@ AtlasNode::AtlasNode()
4949
_mvpMatrixLocation = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
5050
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
5151

52-
auto& vertexLayout = pipelineDescriptor.vertexLayout;
53-
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
54-
auto iter = attributeInfo.find("a_position");
55-
if(iter != attributeInfo.end())
56-
{
57-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
58-
}
59-
iter = attributeInfo.find("a_texCoord");
60-
if(iter != attributeInfo.end())
61-
{
62-
vertexLayout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
63-
}
64-
iter = attributeInfo.find("a_color");
65-
if(iter != attributeInfo.end())
66-
{
67-
vertexLayout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
68-
}
69-
vertexLayout.setLayout(sizeof(V3F_C4B_T2F));
52+
auto vertexLayout = _programState->getVertexLayout();
53+
//a_position
54+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
55+
_programState->getAttributeLocation(backend::Attribute::POSITION),
56+
backend::VertexFormat::FLOAT3,
57+
0,
58+
false);
59+
60+
//a_texCoord
61+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
62+
_programState->getAttributeLocation(backend::Attribute::TEXCOORD),
63+
backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords),
64+
false);
65+
66+
//a_color
67+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_COLOR,
68+
_programState->getAttributeLocation(backend::Attribute::COLOR),
69+
backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors),
70+
true);
71+
72+
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
7073
}
7174

7275
AtlasNode::~AtlasNode()

cocos/2d/CCCameraBackgroundBrush.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,24 @@ bool CameraBackgroundDepthBrush::init()
129129
auto &pipelineDescriptor = _customCommand.getPipelineDescriptor();
130130
pipelineDescriptor.programState = _programState;
131131

132-
auto &layout = pipelineDescriptor.vertexLayout;
132+
auto layout = _programState->getVertexLayout();
133133
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
134134
auto iter = attributeInfo.find("a_position");
135135
if(iter != attributeInfo.end())
136136
{
137-
layout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, offsetof(V3F_C4B_T2F, vertices), false);
137+
layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, offsetof(V3F_C4B_T2F, vertices), false);
138138
}
139139
iter = attributeInfo.find("a_color");
140140
if(iter != attributeInfo.end())
141141
{
142-
layout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
142+
layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
143143
}
144144
iter = attributeInfo.find("a_texCoord");
145145
if(iter != attributeInfo.end())
146146
{
147-
layout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), true);
147+
layout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), true);
148148
}
149-
layout.setLayout(sizeof(_vertices[0]));
149+
layout->setLayout(sizeof(_vertices[0]));
150150

151151
_vertices.resize(4);
152152
_vertices[0].vertices = Vec3(-1, -1, 0);
@@ -416,13 +416,13 @@ bool CameraBackgroundSkyBoxBrush::init()
416416

417417

418418
auto &pipelineDescriptor = _customCommand.getPipelineDescriptor();
419-
auto &layout = pipelineDescriptor.vertexLayout;
419+
auto layout = _programState->getVertexLayout();
420420
pipelineDescriptor.programState = _programState;
421421
// disable blend
422422
pipelineDescriptor.blendDescriptor.blendEnabled = false;
423423

424-
layout.setAttribute(shaderinfos::attribute::ATTRIBUTE_NAME_POSITION, 0, backend::VertexFormat::FLOAT3, 0, false);
425-
layout.setLayout(sizeof(Vec3));
424+
layout->setAttribute(shaderinfos::attribute::ATTRIBUTE_NAME_POSITION, 0, backend::VertexFormat::FLOAT3, 0, false);
425+
layout->setLayout(sizeof(Vec3));
426426

427427
initBuffer();
428428

cocos/2d/CCDrawNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,26 @@ void DrawNode::updateShader()
173173
void DrawNode::setVertexLayout(CustomCommand& cmd)
174174
{
175175
auto* programState = cmd.getPipelineDescriptor().programState;
176-
auto& layout = cmd.getPipelineDescriptor().vertexLayout;
176+
auto layout = programState->getVertexLayout();
177177
const auto& attributeInfo = programState->getProgram()->getActiveAttributes();
178178
auto iter = attributeInfo.find("a_position");
179179
if(iter != attributeInfo.end())
180180
{
181-
layout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
181+
layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
182182
}
183183

184184
iter = attributeInfo.find("a_texCoord");
185185
if(iter != attributeInfo.end())
186186
{
187-
layout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V2F_C4B_T2F, texCoords), false);
187+
layout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V2F_C4B_T2F, texCoords), false);
188188
}
189189

190190
iter = attributeInfo.find("a_color");
191191
if(iter != attributeInfo.end())
192192
{
193-
layout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V2F_C4B_T2F, colors), true);
193+
layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V2F_C4B_T2F, colors), true);
194194
}
195-
layout.setLayout(sizeof(V2F_C4B_T2F));
195+
layout->setLayout(sizeof(V2F_C4B_T2F));
196196
}
197197

198198
void DrawNode::updateBlendState(CustomCommand& cmd)

cocos/2d/CCFastTMXLayer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,24 +420,24 @@ void TMXLayer::updatePrimitives()
420420
auto programState = new (std::nothrow) backend::ProgramState(positionTextureColor_vert, positionTextureColor_frag);
421421
pipelineDescriptor.programState = programState;
422422
}
423-
auto& vertexLayout = pipelineDescriptor.vertexLayout;
423+
auto vertexLayout = pipelineDescriptor.programState->getVertexLayout();
424424
const auto& attributeInfo = pipelineDescriptor.programState->getProgram()->getActiveAttributes();
425425
auto iterAttribute = attributeInfo.find("a_position");
426426
if(iterAttribute != attributeInfo.end())
427427
{
428-
vertexLayout.setAttribute("a_position", iterAttribute->second.location, backend::VertexFormat::FLOAT3, 0, false);
428+
vertexLayout->setAttribute("a_position", iterAttribute->second.location, backend::VertexFormat::FLOAT3, 0, false);
429429
}
430430
iterAttribute = attributeInfo.find("a_texCoord");
431431
if(iterAttribute != attributeInfo.end())
432432
{
433-
vertexLayout.setAttribute("a_texCoord", iterAttribute->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
433+
vertexLayout->setAttribute("a_texCoord", iterAttribute->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
434434
}
435435
iterAttribute = attributeInfo.find("a_color");
436436
if(iterAttribute != attributeInfo.end())
437437
{
438-
vertexLayout.setAttribute("a_color", iterAttribute->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
438+
vertexLayout->setAttribute("a_color", iterAttribute->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
439439
}
440-
vertexLayout.setLayout(sizeof(V3F_C4B_T2F));
440+
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
441441
_mvpMatrixLocaiton = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
442442
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
443443
pipelineDescriptor.programState->setTexture(_textureLocation, 0, _texture->getBackendTexture());

cocos/2d/CCGrid.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ bool GridBase::initWithSize(const Size& gridSize, Texture2D *texture, bool flipp
117117
#define VERTEX_TEXCOORD_SIZE 2
118118
uint32_t texcoordOffset = (VERTEX_POSITION_SIZE)*sizeof(float);
119119
uint32_t totalSize = (VERTEX_POSITION_SIZE+VERTEX_TEXCOORD_SIZE)*sizeof(float);
120-
auto& vertexLayout = _drawCommand.getPipelineDescriptor().vertexLayout;
120+
auto vertexLayout = _programState->getVertexLayout();
121121
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
122122
auto iter = attributeInfo.find("a_position");
123123
if(iter != attributeInfo.end())
124124
{
125-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
125+
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
126126
}
127127
iter = attributeInfo.find("a_texCoord");
128128
if(iter != attributeInfo.end())
129129
{
130-
vertexLayout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, texcoordOffset, false);
130+
vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, texcoordOffset, false);
131131
}
132-
vertexLayout.setLayout(totalSize);
132+
vertexLayout->setLayout(totalSize);
133133

134134
calculateVertexPoints();
135135
updateBlendState();

cocos/2d/CCLabel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,28 +595,28 @@ static Texture2D* _getTexture(Label* label)
595595

596596
void Label::setVertexLayout(PipelineDescriptor& pipelineDescriptor)
597597
{
598-
auto& layout = pipelineDescriptor.vertexLayout;
598+
auto vertexLayout = _programState->getVertexLayout();
599599
///a_position
600-
layout.setAttribute(backend::ATTRIBUTE_NAME_POSITION,
600+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_POSITION,
601601
_programState->getAttributeLocation(backend::Attribute::POSITION),
602602
backend::VertexFormat::FLOAT3,
603603
0,
604604
false);
605605

606606
///a_texCoord
607-
layout.setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
607+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_TEXCOORD,
608608
_programState->getAttributeLocation(backend::Attribute::TEXCOORD),
609609
backend::VertexFormat::FLOAT2,
610610
offsetof(V3F_C4B_T2F, texCoords),
611611
false);
612612

613613
///a_color
614-
layout.setAttribute(backend::ATTRIBUTE_NAME_COLOR,
614+
vertexLayout->setAttribute(backend::ATTRIBUTE_NAME_COLOR,
615615
_programState->getAttributeLocation(backend::Attribute::COLOR),
616616
backend::VertexFormat::UBYTE4,
617617
offsetof(V3F_C4B_T2F, colors),
618618
true);
619-
layout.setLayout(sizeof(V3F_C4B_T2F));
619+
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
620620
}
621621

622622
void Label::setProgramState(backend::ProgramState *programState)

cocos/2d/CCLayer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,19 @@ LayerColor::LayerColor()
291291
_programState = new (std::nothrow) backend::ProgramState(positionColor_vert, positionColor_frag);
292292
pipelineDescriptor.programState = _programState;
293293

294-
auto& vertexLayout = _customCommand.getPipelineDescriptor().vertexLayout;
294+
auto vertexLayout = _programState->getVertexLayout();
295295
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
296296
auto iter = attributeInfo.find("a_position");
297297
if(iter != attributeInfo.end())
298298
{
299-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
299+
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
300300
}
301301
iter = attributeInfo.find("a_color");
302302
if(iter != attributeInfo.end())
303303
{
304-
vertexLayout.setAttribute("a_color", iter->second.location, backend::VertexFormat::FLOAT4, sizeof(_vertexData[0].vertices), false);
304+
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::FLOAT4, sizeof(_vertexData[0].vertices), false);
305305
}
306-
vertexLayout.setLayout(sizeof(_vertexData[0]));
306+
vertexLayout->setLayout(sizeof(_vertexData[0]));
307307

308308
_mvpMatrixLocation = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
309309

@@ -714,14 +714,14 @@ LayerRadialGradient::LayerRadialGradient()
714714
_radiusLocation = pipelineDescriptor.programState->getUniformLocation("u_radius");
715715
_expandLocation = pipelineDescriptor.programState->getUniformLocation("u_expand");
716716

717-
auto& vertexLayout = _customCommand.getPipelineDescriptor().vertexLayout;
717+
auto vertexLayout = _programState->getVertexLayout();
718718
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
719719
auto iter = attributeInfo.find("a_position");
720720
if(iter != attributeInfo.end())
721721
{
722-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
722+
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
723723
}
724-
vertexLayout.setLayout(sizeof(_vertices[0]));
724+
vertexLayout->setLayout(sizeof(_vertices[0]));
725725

726726
_customCommand.createVertexBuffer(sizeof(_vertices[0]), sizeof(_vertices) / sizeof(_vertices[0]), CustomCommand::BufferUsage::STATIC);
727727
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);

cocos/2d/CCMotionStreak.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ MotionStreak::MotionStreak()
4747
_mvpMatrixLocaiton = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
4848
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
4949

50-
auto& vertexLayout = pipelineDescriptor.vertexLayout;
50+
auto vertexLayout = _programState->getVertexLayout();
5151
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
5252
auto iter = attributeInfo.find("a_position");
5353
if(iter != attributeInfo.end())
5454
{
55-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
55+
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
5656
}
5757
iter = attributeInfo.find("a_texCoord");
5858
if(iter != attributeInfo.end())
5959
{
60-
vertexLayout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, 2 * sizeof(float), false);
60+
vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, 2 * sizeof(float), false);
6161
}
6262
iter = attributeInfo.find("a_color");
6363
if(iter != attributeInfo.end())
6464
{
65-
vertexLayout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, 4 * sizeof(float), true);
65+
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, 4 * sizeof(float), true);
6666
}
67-
vertexLayout.setLayout(4 * sizeof(float) + 4 * sizeof(uint8_t));
67+
vertexLayout->setLayout(4 * sizeof(float) + 4 * sizeof(uint8_t));
6868
}
6969

7070
MotionStreak::~MotionStreak()

cocos/2d/CCParticleBatchNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ ParticleBatchNode::ParticleBatchNode()
5151
_mvpMatrixLocaiton = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
5252
_textureLocation = pipelineDescriptor.programState->getUniformLocation("u_texture");
5353

54-
auto& layout = pipelineDescriptor.vertexLayout;
54+
auto layout = _programState->getVertexLayout();
5555
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
5656
auto iter = attributeInfo.find("a_position");
5757
if(iter != attributeInfo.end())
5858
{
59-
layout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
59+
layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
6060
}
6161
iter = attributeInfo.find("a_texCoord");
6262
if(iter != attributeInfo.end())
6363
{
64-
layout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
64+
layout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
6565
}
6666
iter = attributeInfo.find("a_color");
6767
if(iter != attributeInfo.end())
6868
{
69-
layout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
69+
layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
7070
}
71-
layout.setLayout(sizeof(V3F_C4B_T2F));
71+
layout->setLayout(sizeof(V3F_C4B_T2F));
7272

7373
_customCommand.setDrawType(CustomCommand::DrawType::ELEMENT);
7474
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE);

cocos/2d/CCParticleSystemQuad.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,24 @@ ParticleSystemQuad::ParticleSystemQuad()
5555
_mvpMatrixLocaiton = pipelieDescriptor.programState->getUniformLocation("u_MVPMatrix");
5656
_textureLocation = pipelieDescriptor.programState->getUniformLocation("u_texture");
5757

58-
auto& vertexLayout = pipelieDescriptor.vertexLayout;
58+
auto vertexLayout = _programState->getVertexLayout();
5959
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
6060
auto iter = attributeInfo.find("a_position");
6161
if(iter != attributeInfo.end())
6262
{
63-
vertexLayout.setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
63+
vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
6464
}
6565
iter = attributeInfo.find("a_texCoord");
6666
if(iter != attributeInfo.end())
6767
{
68-
vertexLayout.setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
68+
vertexLayout->setAttribute("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, offsetof(V3F_C4B_T2F, texCoords), false);
6969
}
7070
iter = attributeInfo.find("a_color");
7171
if(iter != attributeInfo.end())
7272
{
73-
vertexLayout.setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
73+
vertexLayout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, offsetof(V3F_C4B_T2F, colors), true);
7474
}
75-
vertexLayout.setLayout(sizeof(V3F_C4B_T2F));
75+
vertexLayout->setLayout(sizeof(V3F_C4B_T2F));
7676
}
7777

7878
ParticleSystemQuad::~ParticleSystemQuad()

0 commit comments

Comments
 (0)