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

Method initProgram

core/renderer/Texture2D.cpp:745–781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745void Texture2D::initProgram()
746{
747 if (_programState != nullptr)
748 return;
749
750 auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
751 // create program state
752 auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE);
753 _programState = new ax::backend::ProgramState(program);
754 _mvpMatrixLocation = _programState->getUniformLocation("u_MVPMatrix");
755 _textureLocation = _programState->getUniformLocation("u_tex0");
756
757 pipelineDescriptor.programState = _programState;
758
759 // create vertex buffer
760 _customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
761 _customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE_STRIP);
762 _customCommand.createVertexBuffer(4 * sizeof(float), 4, CustomCommand::BufferUsage::DYNAMIC);
763
764 // setup blend state
765 BlendFunc blendFunc;
766 if (hasPremultipliedAlpha())
767 {
768 blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
769 }
770 else
771 {
772 blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
773 }
774
775 auto& blendDescriptor = pipelineDescriptor.blendDescriptor;
776 blendDescriptor.blendEnabled = true;
777 blendDescriptor.sourceRGBBlendFactor = blendDescriptor.sourceAlphaBlendFactor = blendFunc.src;
778 blendDescriptor.destinationRGBBlendFactor = blendDescriptor.destinationAlphaBlendFactor = blendFunc.dst;
779
780 _programState->setTexture(_textureLocation, 0, _texture);
781}
782
783void Texture2D::drawAtPoint(const Vec2& point, float globalZOrder)
784{

Callers

nothing calls this directly

Calls 4

hasPremultipliedAlphaFunction · 0.85
createVertexBufferMethod · 0.80
getUniformLocationMethod · 0.45
setTextureMethod · 0.45

Tested by

no test coverage detected