2013-12-18 10:12:15 +08:00
|
|
|
/****************************************************************************
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-18 10:12:15 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __CCRENDERCOMMAND_H_
|
|
|
|
#define __CCRENDERCOMMAND_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-05-17 05:36:00 +08:00
|
|
|
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccTypes.h"
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
2015-06-01 13:43:56 +08:00
|
|
|
* @addtogroup renderer
|
2015-03-27 11:54:40 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-11-05 01:14:22 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-03-07 08:14:06 +08:00
|
|
|
/** Base class of the `RenderCommand` hierarchy.
|
|
|
|
*
|
|
|
|
The `Renderer` knows how to render `RenderCommands` objects.
|
2014-01-18 08:08:29 +08:00
|
|
|
*/
|
2014-07-14 17:02:06 +08:00
|
|
|
class CC_DLL RenderCommand
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
2013-12-03 14:08:47 +08:00
|
|
|
public:
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Enum the type of render command. */
|
2013-12-18 10:02:11 +08:00
|
|
|
enum class Type
|
|
|
|
{
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Reserved type.*/
|
2014-01-17 14:29:25 +08:00
|
|
|
UNKNOWN_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Quad command, used for draw quad.*/
|
2013-12-18 10:02:11 +08:00
|
|
|
QUAD_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Custom command, used for calling callback for rendering.*/
|
2013-12-18 10:02:11 +08:00
|
|
|
CUSTOM_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Batch command, used for draw batches in texture atlas.*/
|
2014-01-16 08:07:38 +08:00
|
|
|
BATCH_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Group command, which can group command in a tree hierarchy.*/
|
2013-12-18 10:02:11 +08:00
|
|
|
GROUP_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Mesh command, used to draw 3D meshes.*/
|
2014-05-19 05:49:16 +08:00
|
|
|
MESH_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Primitive command, used to draw primitives such as lines, points and triangles.*/
|
2014-08-01 14:46:35 +08:00
|
|
|
PRIMITIVE_COMMAND,
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Triangles command, used to draw triangles.*/
|
2014-08-27 18:39:49 +08:00
|
|
|
TRIANGLES_COMMAND
|
2013-12-18 10:02:11 +08:00
|
|
|
};
|
|
|
|
|
2015-01-16 06:00:49 +08:00
|
|
|
/**
|
2015-03-18 20:30:52 +08:00
|
|
|
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.
|
2015-01-16 06:00:49 +08:00
|
|
|
*/
|
|
|
|
void init(float globalZOrder, const Mat4& modelViewTransform, uint32_t flags);
|
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Get global Z order. */
|
2014-01-19 03:35:27 +08:00
|
|
|
inline float getGlobalOrder() const { return _globalOrder; }
|
2014-01-16 11:10:40 +08:00
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Returns the Command type. */
|
2014-01-18 15:10:04 +08:00
|
|
|
inline Type getType() const { return _type; }
|
2014-09-18 12:00:44 +08:00
|
|
|
|
2015-10-23 15:37:33 +08:00
|
|
|
/** Returns whether is transparent. */
|
2014-09-18 12:00:44 +08:00
|
|
|
inline bool isTransparent() const { return _isTransparent; }
|
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Set transparent flag. */
|
2014-09-18 12:00:44 +08:00
|
|
|
inline void setTransparent(bool isTransparent) { _isTransparent = isTransparent; }
|
2015-03-18 20:30:52 +08:00
|
|
|
/**
|
2015-04-25 05:02:39 +08:00
|
|
|
Get skip batching status, if a rendering is skip batching, it will be forced to be rendering separately.
|
2015-03-18 20:30:52 +08:00
|
|
|
*/
|
2015-01-10 06:06:21 +08:00
|
|
|
inline bool isSkipBatching() const { return _skipBatching; }
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Set skip batching.*/
|
2015-01-10 06:06:21 +08:00
|
|
|
inline void setSkipBatching(bool value) { _skipBatching = value; }
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Whether the command should be rendered at 3D mode.*/
|
2015-01-13 14:52:20 +08:00
|
|
|
inline bool is3D() const { return _is3D; }
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Set the command rendered in 3D mode or not.*/
|
2015-01-12 14:20:41 +08:00
|
|
|
inline void set3D(bool value) { _is3D = value; }
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Get the depth by current model view matrix.*/
|
2015-01-27 14:29:09 +08:00
|
|
|
inline float getDepth() const { return _depth; }
|
|
|
|
|
2013-11-05 01:14:22 +08:00
|
|
|
protected:
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Constructor.*/
|
2013-12-18 10:02:11 +08:00
|
|
|
RenderCommand();
|
2015-09-22 16:08:23 +08:00
|
|
|
/**Destructor.*/
|
2013-12-18 10:02:11 +08:00
|
|
|
virtual ~RenderCommand();
|
2015-03-18 20:30:52 +08:00
|
|
|
//used for debug but it is not implemented.
|
2013-11-05 01:14:22 +08:00
|
|
|
void printID();
|
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/**Type used in order to avoid dynamic cast, faster. */
|
2013-12-18 10:02:11 +08:00
|
|
|
Type _type;
|
2014-01-18 08:08:29 +08:00
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Commands are sort by global Z order. */
|
2014-01-19 03:35:27 +08:00
|
|
|
float _globalOrder;
|
2014-09-18 12:00:44 +08:00
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Transparent flag. */
|
2014-09-18 12:00:44 +08:00
|
|
|
bool _isTransparent;
|
2015-03-18 20:30:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
QuadCommand and TrianglesCommand could be auto batched if there material ID is the same, however, if
|
2015-04-25 05:02:39 +08:00
|
|
|
a command is skip batching, it would be forced to draw in a separate function call, and break the batch.
|
2015-03-18 20:30:52 +08:00
|
|
|
*/
|
2015-01-10 06:06:21 +08:00
|
|
|
bool _skipBatching;
|
2015-01-12 14:20:41 +08:00
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Is the command been rendered on 3D pass. */
|
2015-01-12 14:20:41 +08:00
|
|
|
bool _is3D;
|
2015-01-27 14:29:09 +08:00
|
|
|
|
2015-03-18 20:30:52 +08:00
|
|
|
/** Depth from the model view matrix.*/
|
2015-01-27 14:29:09 +08:00
|
|
|
float _depth;
|
2013-11-05 01:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
|
|
|
end of support group
|
|
|
|
@}
|
|
|
|
*/
|
2013-11-05 01:14:22 +08:00
|
|
|
#endif //__CCRENDERCOMMAND_H_
|