axmol/core/renderer/CCRenderCommand.h

146 lines
5.1 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-08-08 18:02:17 +08:00
https://axys1.github.io/
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "platform/CCPlatformMacros.h"
#include "base/ccTypes.h"
#include "renderer/CCPipelineDescriptor.h"
/**
* @addtogroup renderer
* @{
*/
NS_AX_BEGIN
2019-11-23 20:27:39 +08:00
/** Base class of the `RenderCommand` hierarchy.
*
The `Renderer` knows how to render `RenderCommands` objects.
*/
2022-07-16 10:43:05 +08:00
class AX_DLL RenderCommand
2019-11-23 20:27:39 +08:00
{
public:
/**Enum the type of render command. */
enum class Type
{
/** Reserved type.*/
UNKNOWN_COMMAND,
/** Quad command, used for draw quad.*/
QUAD_COMMAND,
/**Custom command, used to draw things other then TRIANGLES_COMMAND.*/
CUSTOM_COMMAND,
/**Group command, which can group command in a tree hierarchy.*/
GROUP_COMMAND,
/**Mesh command, used to draw 3D meshes.*/
MESH_COMMAND,
/**Triangles command, used to draw triangles.*/
TRIANGLES_COMMAND,
/**Callback command, used for calling callback for rendering.*/
CALLBACK_COMMAND,
};
/**
Init function, will be called by all the render commands.
@param globalZOrder The global order of command, used for rendercommand sorting.
@param modelViewTransform Modelview matrix when submitting the render command.
@param flags Flag used to indicate whether the command should be draw at 3D mode or not.
*/
void init(float globalZOrder, const Mat4& modelViewTransform, unsigned int flags);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Get global Z order. */
float getGlobalOrder() const { return _globalOrder; }
/** Returns the Command type. */
Type getType() const { return _type; }
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Returns whether is transparent. */
bool isTransparent() const { return _isTransparent; }
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Set transparent flag. */
void setTransparent(bool isTransparent) { _isTransparent = isTransparent; }
/**
Get skip batching status, if a rendering is skip batching, it will be forced to be rendering separately.
*/
bool isSkipBatching() const { return _skipBatching; }
/**Set skip batching.*/
void setSkipBatching(bool value) { _skipBatching = value; }
/**Whether the command should be rendered at 3D mode.*/
bool is3D() const { return _is3D; }
/**Set the command rendered in 3D mode or not.*/
void set3D(bool value) { _is3D = value; }
/**Get the depth by current model view matrix.*/
float getDepth() const { return _depth; }
/**Whether the command should be rendered in wireframe mode.*/
bool isWireframe() const { return _isWireframe; }
/**Set wireframe render mode for this command.*/
void setWireframe(bool value) { _isWireframe = value; }
2019-11-23 20:27:39 +08:00
/// Can use the result to change the descriptor content.
inline PipelineDescriptor& getPipelineDescriptor() { return _pipelineDescriptor; }
2021-12-25 10:04:45 +08:00
const Mat4& getMV() const { return _mv; }
2019-11-23 20:27:39 +08:00
protected:
/**Constructor.*/
RenderCommand();
/**Destructor.*/
virtual ~RenderCommand();
2021-12-25 10:04:45 +08:00
// used for debug but it is not implemented.
2019-11-23 20:27:39 +08:00
void printID();
/**Type used in order to avoid dynamic cast, faster. */
Type _type = RenderCommand::Type::UNKNOWN_COMMAND;
/** Commands are sort by global Z order. */
float _globalOrder = 0.f;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Transparent flag. */
2021-12-25 10:04:45 +08:00
bool _isTransparent = true;
2019-11-23 20:27:39 +08:00
/**
QuadCommand and TrianglesCommand could be auto batched if there material ID is the same, however, if
a command is skip batching, it would be forced to draw in a separate function call, and break the batch.
*/
bool _skipBatching = false;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Is the command been rendered on 3D pass. */
bool _is3D = false;
2021-12-25 10:04:45 +08:00
/** Depth from the model view matrix. */
2019-11-23 20:27:39 +08:00
float _depth = 0.f;
/** Polygon render mode set to LINE, which represents wireframe mode. */
bool _isWireframe = false;
2019-11-23 20:27:39 +08:00
Mat4 _mv;
PipelineDescriptor _pipelineDescriptor;
};
NS_AX_END
2019-11-23 20:27:39 +08:00
/**
end of support group
@}
*/