MCPcopy Create free account
hub / github.com/axmolengine/axmol / initWithVertex

Method initWithVertex

tests/cpp-tests/Source/ShaderTest/ShaderTest.cpp:89–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89bool ShaderNode::initWithVertex(std::string_view vert, std::string_view frag)
90{
91 if (vert.empty())
92 vert = position_vert;
93 _vertFileName = vert;
94 _fragFileName = frag;
95
96 loadShaderVertex(vert, frag);
97
98 _time = 0;
99 _resolution = Vec2(SIZE_X, SIZE_Y);
100
101 scheduleUpdate();
102
103 setContentSize(Size(SIZE_X, SIZE_Y));
104 setAnchorPoint(Vec2(0.5f, 0.5f));
105
106 // init custom command
107 auto attrPosLoc = _programState->getAttributeLocation("a_position");
108
109 auto vertexLayout = _programState->getMutableVertexLayout();
110 vertexLayout->setAttrib("a_position", attrPosLoc, backend::VertexFormat::FLOAT2, 0, false);
111
112 float w = SIZE_X, h = SIZE_Y;
113 Vec2 vertices[6] = {Vec2(0.0f, 0.0f), Vec2(w, 0.0f), Vec2(w, h), Vec2(0.0f, 0.0f), Vec2(0.0f, h), Vec2(w, h)};
114 vertexLayout->setStride(sizeof(Vec2));
115
116 /*
117 * TODO: the Y-coordinate of subclasses are flipped in metal
118 *
119 * keywords: AX_USE_METAL , AX_USE_GL
120 */
121
122 _customCommand.createVertexBuffer(sizeof(Vec2), 6, CustomCommand::BufferUsage::STATIC);
123 _customCommand.updateVertexBuffer(vertices, sizeof(vertices));
124
125 _customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
126
127 return true;
128}
129
130void ShaderNode::loadShaderVertex(std::string_view vert, std::string_view frag)
131{

Callers 1

shaderNodeWithVertexMethod · 0.80

Calls 11

scheduleUpdateFunction · 0.85
getAttributeLocationMethod · 0.80
setAttribMethod · 0.80
setStrideMethod · 0.80
createVertexBufferMethod · 0.80
Vec2Function · 0.50
SizeFunction · 0.50
setAnchorPointFunction · 0.50
emptyMethod · 0.45
updateVertexBufferMethod · 0.45

Tested by

no test coverage detected