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

Method init

tests/lua-tests/Source/lua_test_bindings.cpp:144–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144bool DrawNode3D::init()
145{
146
147 _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
148 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::LINE_COLOR_3D);
149 _programState = new backend::ProgramState(program);
150
151 _locMVPMatrix = _programState->getUniformLocation("u_MVPMatrix");
152
153#define INITIAL_VERTEX_BUFFER_LENGTH 512
154 ensureCapacity(INITIAL_VERTEX_BUFFER_LENGTH);
155
156 _customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
157 _customCommand.setPrimitiveType(CustomCommand::PrimitiveType::LINE);
158
159 const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
160 auto iter = attributeInfo.find("a_position");
161 auto vertexLayout = _programState->getMutableVertexLayout();
162 if (iter != attributeInfo.end())
163 {
164 vertexLayout->setAttrib(iter->first, iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
165 }
166 iter = attributeInfo.find("a_color");
167 if (iter != attributeInfo.end())
168 {
169 vertexLayout->setAttrib(iter->first, iter->second.location, backend::VertexFormat::UBYTE4, sizeof(Vec3),
170 true);
171 }
172 vertexLayout->setStride(sizeof(V3F_C4B));
173
174 _customCommand.createVertexBuffer(sizeof(V3F_C4B), INITIAL_VERTEX_BUFFER_LENGTH,
175 CustomCommand::BufferUsage::DYNAMIC);
176
177 _customCommand.getPipelineDescriptor().programState = _programState;
178
179 _dirty = true;
180
181 _customCommand.setBeforeCallback(AX_CALLBACK_0(DrawNode3D::onBeforeDraw, this));
182 _customCommand.setAfterCallback(AX_CALLBACK_0(DrawNode3D::onAfterDraw, this));
183
184#if AX_ENABLE_CACHE_TEXTURE_DATA
185 // Need to listen the event only when not use batchnode, because it will use VBO
186 auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event) {
187 /** listen the event that coming to foreground on Android */
188 this->init();
189 });
190
191 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
192#endif
193
194 return true;
195}
196
197void DrawNode3D::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
198{

Callers 2

createMethod · 0.45
drawMethod · 0.45

Calls 11

ensureCapacityFunction · 0.85
createFunction · 0.85
getProgramMethod · 0.80
setAttribMethod · 0.80
setStrideMethod · 0.80
createVertexBufferMethod · 0.80
getUniformLocationMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected