27#include "renderer/backend/Buffer.h"
31DrawNode3D::DrawNode3D()
45 if (ret && ret->
init())
59 CCASSERT(count>=0,
"capacity must be >= 0");
67 _customCommand.createVertexBuffer(
sizeof(
V3F_C4B), EXTENDED_SIZE + (EXTENDED_SIZE >> 1), CustomCommand::BufferUsage::DYNAMIC);
76 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::LINE_COLOR_3D);
86#define INITIAL_VERTEX_BUFFER_LENGTH 512
91 _customCommand.setPrimitiveType(CustomCommand::PrimitiveType::LINE);
93 const auto& attributeInfo =
_programStateLine->getProgram()->getActiveAttributes();
94 auto iter = attributeInfo.find(
"a_position");
95 if(iter != attributeInfo.end())
97 layout->setAttribute(
"a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0,
false);
99 iter = attributeInfo.find(
"a_color");
100 if(iter != attributeInfo.end())
102 layout->setAttribute(
"a_color", iter->second.location, backend::VertexFormat::UBYTE4,
sizeof(Vec3),
true);
104 layout->setLayout(
sizeof(
V3F_C4B));
109#if CC_ENABLE_CACHE_TEXTURE_DATA
111 auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [
this](EventCustom* event){
116 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
143 auto &matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
144 auto mvp = matrixP * transform;
149 auto &blend =
_customCommand.getPipelineDescriptor().blendDescriptor;
150 blend.blendEnabled =
true;
151 blend.sourceRGBBlendFactor = blend.sourceAlphaBlendFactor =
_blendFunc.src;
152 blend.destinationRGBBlendFactor = blend.destinationAlphaBlendFactor =
_blendFunc.dst;
154 CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,
_bufferLines.size());
159 unsigned int vertex_count = 2;
162 Color4B col = Color4B(color);
163 V3F_C4B a = {Vec3(from.x, from.y, from.z), col};
164 V3F_C4B b = {Vec3(to.x, to.y, to.z), col, };
175 drawLine(vertices[0], vertices[1], color);
176 drawLine(vertices[1], vertices[2], color);
177 drawLine(vertices[2], vertices[3], color);
178 drawLine(vertices[3], vertices[0], color);
181 drawLine(vertices[4], vertices[5], color);
182 drawLine(vertices[5], vertices[6], color);
183 drawLine(vertices[6], vertices[7], color);
184 drawLine(vertices[7], vertices[4], color);
187 drawLine(vertices[0], vertices[7], color);
188 drawLine(vertices[1], vertices[6], color);
189 drawLine(vertices[2], vertices[5], color);
190 drawLine(vertices[3], vertices[4], color);
212 auto *renderer = Director::getInstance()->getRenderer();
214 renderer->setDepthTest(
true);
219 auto *renderer = Director::getInstance()->getRenderer();
#define INITIAL_VERTEX_BUFFER_LENGTH
std::vector< V3F_C4B > _bufferLines
cocos2d::CustomCommand _customCommand
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override
backend::ProgramState * _programStateLine
bool _rendererDepthTestEnabled
void ensureCapacity(int count)
const BlendFunc & getBlendFunc() const
backend::DepthStencilDescriptor * _depthstencilDescriptor
void setBlendFunc(const BlendFunc &blendFunc)
void drawCube(cocos2d::Vec3 *vertices, const Color4F &color)
void updateCommand(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
backend::UniformLocation _locMVPMatrix
static cocos2d::DrawNode3D * create()
void drawLine(const cocos2d::Vec3 &from, const cocos2d::Vec3 &to, const Color4F &color)
virtual bool init() override