2014-08-08 17:54:39 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DRAW_NODE_3D_H__
|
|
|
|
#define __DRAW_NODE_3D_H__
|
|
|
|
|
2022-10-12 00:15:09 +08:00
|
|
|
#include "axmol.h"
|
2014-08-08 17:54:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-08-08 17:54:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy DrawNode for 3D geometry drawing.
|
|
|
|
*/
|
2022-07-11 17:50:21 +08:00
|
|
|
class DrawNode3D : public axis::Node
|
2014-08-08 17:54:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** creates and initialize a DrawNode3D node */
|
2022-07-11 17:50:21 +08:00
|
|
|
static axis::DrawNode3D* create();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
/**
|
|
|
|
* Draw 3D Line
|
|
|
|
*/
|
2022-07-11 17:50:21 +08:00
|
|
|
void drawLine(const axis::Vec3& from, const axis::Vec3& to, const Color4F& color);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
/**
|
2021-12-28 16:06:23 +08:00
|
|
|
* Draw 3D cube
|
|
|
|
* @param point to 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.
|
|
|
|
* @param color
|
|
|
|
*/
|
2022-07-11 17:50:21 +08:00
|
|
|
void drawCube(axis::Vec3* vertices, const Color4F& color);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
/** Clear the geometry in the node's buffer. */
|
|
|
|
void clear();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
/**
|
2021-12-28 16:06:23 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-08-08 17:54:39 +08:00
|
|
|
const BlendFunc& getBlendFunc() const;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
/**
|
2021-12-28 16:06:23 +08:00
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var setBlendFunc(var src, var dst)
|
|
|
|
* @endcode
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setBlendFunc(const BlendFunc& blendFunc);
|
2014-08-08 17:54:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void updateCommand(axis::Renderer* renderer, const axis::Mat4& transform, uint32_t flags);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
// Overrides
|
2022-07-11 17:50:21 +08:00
|
|
|
virtual void draw(axis::Renderer* renderer, const axis::Mat4& transform, uint32_t flags) override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
DrawNode3D();
|
2014-08-08 17:54:39 +08:00
|
|
|
virtual ~DrawNode3D();
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2014-08-08 17:54:39 +08:00
|
|
|
|
|
|
|
protected:
|
2019-02-15 14:30:10 +08:00
|
|
|
void onBeforeDraw();
|
|
|
|
void onAfterDraw();
|
|
|
|
|
2014-08-08 17:54:39 +08:00
|
|
|
void ensureCapacity(int count);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
BlendFunc _blendFunc;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::CustomCommand _customCommand;
|
2021-12-28 16:06:23 +08:00
|
|
|
backend::ProgramState* _programStateLine = nullptr;
|
|
|
|
backend::DepthStencilDescriptor* _depthstencilDescriptor = nullptr;
|
2019-02-15 14:30:10 +08:00
|
|
|
backend::UniformLocation _locMVPMatrix;
|
|
|
|
std::vector<V3F_C4B> _bufferLines;
|
2014-08-08 17:54:39 +08:00
|
|
|
|
|
|
|
private:
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(DrawNode3D);
|
2019-02-15 14:30:10 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
bool _isDirty = true;
|
|
|
|
bool _rendererDepthTestEnabled = true;
|
2014-08-08 17:54:39 +08:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-08-08 17:54:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
#endif // __DRAW_NODE_3D_H__
|