axmol/cocos/navmesh/CCNavMeshDebugDraw.h

126 lines
4.2 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
http://www.cocos2d-x.org
2021-12-25 10:04:45 +08:00
2019-11-23 20:27: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-25 10:04:45 +08:00
2019-11-23 20:27: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-25 10:04:45 +08:00
2019-11-23 20:27: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.
****************************************************************************/
#pragma once
#include "base/ccConfig.h"
#if CC_USE_NAVMESH
2021-12-25 10:04:45 +08:00
# include "renderer/CCRenderState.h"
# include "renderer/backend/ProgramState.h"
# include "renderer/backend/Types.h"
# include "renderer/backend/Buffer.h"
# include "math/Vec3.h"
# include "recast/DebugDraw.h"
# include "renderer/CCGroupCommand.h"
# include "renderer/CCCallbackCommand.h"
# include "renderer/CCCustomCommand.h"
# include <string>
# include <vector>
2019-11-23 20:27:39 +08:00
NS_CC_BEGIN
/**
* @addtogroup 3d
* @{
*/
class Renderer;
class NavMeshDebugDraw : public duDebugDraw
{
public:
NavMeshDebugDraw();
virtual ~NavMeshDebugDraw();
virtual void depthMask(bool state) override;
2021-12-25 10:04:45 +08:00
virtual void texture(bool /*state*/) override{};
2019-11-23 20:27:39 +08:00
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) override;
virtual void vertex(const float* pos, unsigned int color) override;
virtual void vertex(const float x, const float y, const float z, unsigned int color) override;
virtual void vertex(const float* pos, unsigned int color, const float* uv) override;
2021-12-25 10:04:45 +08:00
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v)
override;
2019-11-23 20:27:39 +08:00
virtual void end() override;
void draw(Renderer* renderer);
void clear();
private:
2021-12-25 10:04:45 +08:00
void initCustomCommand(CustomCommand& command);
2019-11-23 20:27:39 +08:00
backend::PrimitiveType getPrimitiveType(duDebugDrawPrimitives prim);
static Vec4 getColor(unsigned int col);
void onBeforeVisitCmd();
void onAfterVisitCmd();
void onBeforeEachCommand(bool enableDepthWrite);
private:
struct V3F_C4F
{
Vec3 position;
Vec4 color;
};
struct Primitive
{
2021-12-25 10:04:45 +08:00
backend::PrimitiveType type = backend::PrimitiveType::LINE;
bool depthMask = false;
unsigned short start = 0;
unsigned short end = 0;
float size = 1.0f;
2019-11-23 20:27:39 +08:00
};
2021-12-25 10:04:45 +08:00
Primitive* _currentPrimitive = nullptr;
backend::ProgramState* _programState = nullptr;
bool _currentDepthMask = true;
bool _dirtyBuffer = true;
backend::Buffer* _vertexBuffer = nullptr;
// RenderState::StateBlock _stateBlock;
std::vector<V3F_C4F> _vertices;
std::vector<Primitive*> _primitiveList;
backend::UniformLocation _locMVP;
std::vector<CustomCommand> _commands;
CallbackCommand _beforeCommand;
CallbackCommand _afterCommand;
// renderer state cache variables
bool _rendererDepthTestEnabled = true;
backend::CompareFunction _rendererDepthCmpFunc = backend::CompareFunction::LESS;
backend::CullMode _rendererCullMode = backend::CullMode::BACK;
backend::Winding _rendererWinding = backend::Winding::COUNTER_CLOCK_WISE;
bool _rendererDepthWrite = false;
2019-11-23 20:27:39 +08:00
};
/** @} */
NS_CC_END
2021-12-25 10:04:45 +08:00
#endif // CC_USE_NAVMESH