PuzzleSDK
DrawNode3D类 参考

#include <DrawNode3D.h>

+ 类 DrawNode3D 继承关系图:
+ DrawNode3D 的协作图:

struct  V3F_C4B
 

Public 成员函数

void drawLine (const cocos2d::Vec3 &from, const cocos2d::Vec3 &to, const Color4F &color)
 
void drawCube (cocos2d::Vec3 *vertices, const Color4F &color)
 
void clear ()
 
const BlendFunc & getBlendFunc () const
 
void setBlendFunc (const BlendFunc &blendFunc)
 
void updateCommand (cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
 
virtual void draw (cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override
 
virtual ~DrawNode3D ()
 
virtual bool init () override
 

静态 Public 成员函数

static cocos2d::DrawNode3D * create ()
 

Public 属性

CC_CONSTRUCTOR_ACCESS __pad0__: DrawNode3D()
 

Protected 成员函数

void onBeforeDraw ()
 
void onAfterDraw ()
 
void ensureCapacity (int count)
 

Protected 属性

BlendFunc _blendFunc
 
cocos2d::CustomCommand _customCommand
 
backend::ProgramState * _programStateLine = nullptr
 
backend::DepthStencilDescriptor * _depthstencilDescriptor = nullptr
 
backend::UniformLocation _locMVPMatrix
 
std::vector< V3F_C4B_bufferLines
 

Private 成员函数

 CC_DISALLOW_COPY_AND_ASSIGN (DrawNode3D)
 

Private 属性

bool _isDirty = true
 
bool _rendererDepthTestEnabled = true
 

详细描述

Copy DrawNode for 3D geometry drawing.

在文件 DrawNode3D.h36 行定义.

构造及析构函数说明

◆ ~DrawNode3D()

DrawNode3D::~DrawNode3D ( )
virtual

在文件 DrawNode3D.cpp36 行定义.

37{
38 CC_SAFE_RELEASE_NULL(_programStateLine);
39 CC_SAFE_DELETE(_depthstencilDescriptor);
40}
backend::ProgramState * _programStateLine
Definition: DrawNode3D.h:105
backend::DepthStencilDescriptor * _depthstencilDescriptor
Definition: DrawNode3D.h:106

引用了 _depthstencilDescriptor , 以及 _programStateLine.

成员函数说明

◆ CC_DISALLOW_COPY_AND_ASSIGN()

DrawNode3D::CC_DISALLOW_COPY_AND_ASSIGN ( DrawNode3D  )
private

◆ clear()

void DrawNode3D::clear ( )

Clear the geometry in the node's buffer.

在文件 DrawNode3D.cpp193 行定义.

194{
195 _bufferLines.clear();
196 _isDirty = true;
197}
std::vector< V3F_C4B > _bufferLines
Definition: DrawNode3D.h:108
bool _isDirty
Definition: DrawNode3D.h:114

引用了 _bufferLines , 以及 _isDirty.

◆ create()

DrawNode3D * DrawNode3D::create ( )
static

creates and initialize a DrawNode3D node

在文件 DrawNode3D.cpp42 行定义.

43{
44 DrawNode3D* ret = new (std::nothrow) DrawNode3D();
45 if (ret && ret->init())
46 {
47 ret->autorelease();
48 }
49 else
50 {
51 CC_SAFE_DELETE(ret);
52 }
53
54 return ret;
55}
virtual bool init() override
Definition: DrawNode3D.cpp:72

引用了 init().

被这些函数引用 Sprite3DWithOBBPerformanceTest::addNewSpriteWithCoords(), Sprite3DWithOBBPerformanceTest::initDrawBox(), Camera3DTestDemo::onEnter(), CameraCullingDemo::onEnter() , 以及 CameraArcBallDemo::onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ draw()

void DrawNode3D::draw ( cocos2d::Renderer *  renderer,
const cocos2d::Mat4 &  transform,
uint32_t  flags 
)
overridevirtual

在文件 DrawNode3D.cpp122 行定义.

123{
124 _customCommand.init(_globalZOrder, transform, flags);
125
126 updateCommand(renderer, transform, flags);
127
128 if (_isDirty && !_bufferLines.empty())
129 {
130 _customCommand.updateVertexBuffer(_bufferLines.data(), (unsigned int)(_bufferLines.size() * sizeof(_bufferLines[0])));
131 _customCommand.setVertexDrawInfo(0, _bufferLines.size());
132 _isDirty = false;
133 }
134
135 if (!_bufferLines.empty())
136 {
137 renderer->addCommand(&_customCommand);
138 }
139}
cocos2d::CustomCommand _customCommand
Definition: DrawNode3D.h:104
void updateCommand(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
Definition: DrawNode3D.cpp:141

引用了 _bufferLines, _customCommand, _isDirty , 以及 updateCommand().

+ 函数调用图:

◆ drawCube()

void DrawNode3D::drawCube ( cocos2d::Vec3 *  vertices,
const Color4F &  color 
)

Draw 3D cube

参数
pointto a vertex array who has 8 element. vertices[0]:Left-top-front, vertices[1]:Left-bottom-front, vertices[2]:Right-bottom-front, vertices[3]:Right-top-front, vertices[4]:Right-top-back, vertices[5]:Right-bottom-back, vertices[6]:Left-bottom-back, vertices[7]:Left-top-back.
color

在文件 DrawNode3D.cpp172 行定义.

173{
174 // front face
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);
179
180 // back face
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);
185
186 // edge
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);
191}
void drawLine(const cocos2d::Vec3 &from, const cocos2d::Vec3 &to, const Color4F &color)
Definition: DrawNode3D.cpp:157

引用了 drawLine().

+ 函数调用图:

◆ drawLine()

void DrawNode3D::drawLine ( const cocos2d::Vec3 &  from,
const cocos2d::Vec3 &  to,
const Color4F &  color 
)

Draw 3D Line

在文件 DrawNode3D.cpp157 行定义.

158{
159 unsigned int vertex_count = 2;
160 ensureCapacity(vertex_count);
161
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, };
165
166 _bufferLines.push_back(a);
167 _bufferLines.push_back(b);
168
169 _isDirty = true;
170}
void ensureCapacity(int count)
Definition: DrawNode3D.cpp:57

引用了 _bufferLines, _isDirty , 以及 ensureCapacity().

被这些函数引用 drawCube() , 以及 Camera3DTestDemo::onEnter().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ ensureCapacity()

void DrawNode3D::ensureCapacity ( int  count)
protected

在文件 DrawNode3D.cpp57 行定义.

58{
59 CCASSERT(count>=0, "capacity must be >= 0");
60
61 auto EXTENDED_SIZE = _bufferLines.size() + count;
62
63 _bufferLines.reserve(EXTENDED_SIZE);
64
65 if (!_customCommand.getVertexBuffer() || _customCommand.getVertexBuffer()->getSize() < (EXTENDED_SIZE * sizeof(_bufferLines[0])))
66 {
67 _customCommand.createVertexBuffer(sizeof(V3F_C4B), EXTENDED_SIZE + (EXTENDED_SIZE >> 1), CustomCommand::BufferUsage::DYNAMIC);
68 }
69
70}

引用了 _bufferLines , 以及 _customCommand.

被这些函数引用 drawLine() , 以及 init().

+ 这是这个函数的调用关系图:

◆ getBlendFunc()

const BlendFunc & DrawNode3D::getBlendFunc ( ) const

@js NA @lua NA

在文件 DrawNode3D.cpp199 行定义.

200{
201 return _blendFunc;
202}
BlendFunc _blendFunc
Definition: DrawNode3D.h:103

引用了 _blendFunc.

◆ init()

bool DrawNode3D::init ( )
overridevirtual

在文件 DrawNode3D.cpp72 行定义.

73{
74 _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
75 auto &pd = _customCommand.getPipelineDescriptor();
76 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::LINE_COLOR_3D);
77 _programStateLine = new backend::ProgramState(program);
78 pd.programState = _programStateLine;
79
80 _locMVPMatrix = _programStateLine->getUniformLocation("u_MVPMatrix");
81
82 _customCommand.setBeforeCallback(CC_CALLBACK_0(DrawNode3D::onBeforeDraw, this));
83 _customCommand.setAfterCallback(CC_CALLBACK_0(DrawNode3D::onAfterDraw, this));
84
85 auto layout = _programStateLine->getVertexLayout();
86#define INITIAL_VERTEX_BUFFER_LENGTH 512
87
89
90 _customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
91 _customCommand.setPrimitiveType(CustomCommand::PrimitiveType::LINE);
92
93 const auto& attributeInfo = _programStateLine->getProgram()->getActiveAttributes();
94 auto iter = attributeInfo.find("a_position");
95 if(iter != attributeInfo.end())
96 {
97 layout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
98 }
99 iter = attributeInfo.find("a_color");
100 if(iter != attributeInfo.end())
101 {
102 layout->setAttribute("a_color", iter->second.location, backend::VertexFormat::UBYTE4, sizeof(Vec3), true);
103 }
104 layout->setLayout(sizeof(V3F_C4B));
105
106 _customCommand.createVertexBuffer(sizeof(V3F_C4B), INITIAL_VERTEX_BUFFER_LENGTH, CustomCommand::BufferUsage::DYNAMIC);
107 _isDirty = true;
108
109#if CC_ENABLE_CACHE_TEXTURE_DATA
110 // Need to listen the event only when not use batchnode, because it will use VBO
111 auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
113 this->init();
114 });
115
116 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
117#endif
118
119 return true;
120}
#define INITIAL_VERTEX_BUFFER_LENGTH
void onAfterDraw()
Definition: DrawNode3D.cpp:217
void onBeforeDraw()
Definition: DrawNode3D.cpp:210
backend::UniformLocation _locMVPMatrix
Definition: DrawNode3D.h:107

引用了 _blendFunc, _customCommand, _isDirty, _locMVPMatrix, _programStateLine, ensureCapacity(), init(), INITIAL_VERTEX_BUFFER_LENGTH, onAfterDraw() , 以及 onBeforeDraw().

被这些函数引用 create() , 以及 init().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onAfterDraw()

void DrawNode3D::onAfterDraw ( )
protected

在文件 DrawNode3D.cpp217 行定义.

218{
219 auto *renderer = Director::getInstance()->getRenderer();
220 renderer->setDepthTest(_rendererDepthTestEnabled);
221}
bool _rendererDepthTestEnabled
Definition: DrawNode3D.h:115

引用了 _rendererDepthTestEnabled.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ onBeforeDraw()

void DrawNode3D::onBeforeDraw ( )
protected

在文件 DrawNode3D.cpp210 行定义.

211{
212 auto *renderer = Director::getInstance()->getRenderer();
213 _rendererDepthTestEnabled = renderer->getDepthTest();
214 renderer->setDepthTest(true);
215}

引用了 _rendererDepthTestEnabled.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ setBlendFunc()

void DrawNode3D::setBlendFunc ( const BlendFunc &  blendFunc)
When this function bound into js or lua,the parameter will be changed
In js: var setBlendFunc(var src, var dst)
void setBlendFunc(const BlendFunc &blendFunc)
Definition: DrawNode3D.cpp:204

@lua NA

在文件 DrawNode3D.cpp204 行定义.

205{
206 _blendFunc = blendFunc;
207}

引用了 _blendFunc.

◆ updateCommand()

void DrawNode3D::updateCommand ( cocos2d::Renderer *  renderer,
const cocos2d::Mat4 &  transform,
uint32_t  flags 
)

在文件 DrawNode3D.cpp141 行定义.

142{
143 auto &matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
144 auto mvp = matrixP * transform;
145
146 _programStateLine->setUniform(_locMVPMatrix, mvp.m, sizeof(mvp.m));
147
148
149 auto &blend = _customCommand.getPipelineDescriptor().blendDescriptor;
150 blend.blendEnabled = true;
151 blend.sourceRGBBlendFactor = blend.sourceAlphaBlendFactor = _blendFunc.src;
152 blend.destinationRGBBlendFactor = blend.destinationAlphaBlendFactor = _blendFunc.dst;
153
154 CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferLines.size());
155}

引用了 _blendFunc, _bufferLines, _customCommand, _locMVPMatrix , 以及 _programStateLine.

被这些函数引用 draw().

+ 这是这个函数的调用关系图:

类成员变量说明

◆ __pad0__

CC_CONSTRUCTOR_ACCESS DrawNode3D::__pad0__

在文件 DrawNode3D.h85 行定义.

◆ _blendFunc

BlendFunc DrawNode3D::_blendFunc
protected

在文件 DrawNode3D.h103 行定义.

被这些函数引用 getBlendFunc(), init(), setBlendFunc() , 以及 updateCommand().

◆ _bufferLines

std::vector<V3F_C4B> DrawNode3D::_bufferLines
protected

在文件 DrawNode3D.h108 行定义.

被这些函数引用 clear(), draw(), drawLine(), ensureCapacity() , 以及 updateCommand().

◆ _customCommand

cocos2d::CustomCommand DrawNode3D::_customCommand
protected

在文件 DrawNode3D.h104 行定义.

被这些函数引用 draw(), ensureCapacity(), init() , 以及 updateCommand().

◆ _depthstencilDescriptor

backend::DepthStencilDescriptor* DrawNode3D::_depthstencilDescriptor = nullptr
protected

在文件 DrawNode3D.h106 行定义.

被这些函数引用 ~DrawNode3D().

◆ _isDirty

bool DrawNode3D::_isDirty = true
private

在文件 DrawNode3D.h114 行定义.

被这些函数引用 clear(), draw(), drawLine() , 以及 init().

◆ _locMVPMatrix

backend::UniformLocation DrawNode3D::_locMVPMatrix
protected

在文件 DrawNode3D.h107 行定义.

被这些函数引用 init() , 以及 updateCommand().

◆ _programStateLine

backend::ProgramState* DrawNode3D::_programStateLine = nullptr
protected

在文件 DrawNode3D.h105 行定义.

被这些函数引用 init(), updateCommand() , 以及 ~DrawNode3D().

◆ _rendererDepthTestEnabled

bool DrawNode3D::_rendererDepthTestEnabled = true
private

在文件 DrawNode3D.h115 行定义.

被这些函数引用 onAfterDraw() , 以及 onBeforeDraw().


该类的文档由以下文件生成: