本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-x节点(CCRenderTexture.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
渲染纹理,把渲染 texture 存储为 PNG或JPG格式,捕获 android设备的 come to background/foreground消息 ,来 存储/恢复缓存对象
///cocos2d-x-3.0alpha0/cocos2dx/misc_nodes
//渲染纹理,把渲染 texture 存储为 PNG或JPG格式,捕获 android 设备的 come to background/foreground 消息 ,来 存储/恢复 缓存对象
#ifndef __CCRENDER_TEXTURE_H__
#define __CCRENDER_TEXTURE_H__
#include "base_nodes/CCNode.h"
#include "sprite_nodes/CCSprite.h"
#include "kazmath/mat4.h"
#include "platform/CCImage.h"
NS_CC_BEGIN
/**
* @addtogroup textures
* @{
*/
/**
@brief RenderTexture 是一个通用的渲染 target(目标). 要渲染的东西使用它,
简单的构建并渲染一个 target(目标), 调用它开始, 调用它访问 cocos
scenes or objects 来渲染它们, 结束时也要调用它. 为方便起见,渲染 texture
添加一个 sprite 来现实它的子结果,所以你可以简单的添加渲染 texture 到你的 scene,对待它就像对待其它CocosNode一样,另外它还可以把渲染 texture 以 PNG或JPG格式存储到磁盘
@since v0.8.1
*/
class CC_DLL RenderTexture : public Node
{
public:
/** 使用 点的高度和宽度,像素格式(只在 RGB ,RGBA 格式有效),depthStencil(深度模板)格式 初始化一个 RenderTexture 对象
*/
static RenderTexture * create(int w ,int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat);
/** 使用 点的高度和宽度,像素格式(只在 RGB ,RGBA 格式有效) 创建一个 RenderTexture 对象 */
static RenderTexture * create(int w, int h, Texture2D::PixelFormat eFormat);
/** 使用 点的高度和宽度,像素格式(RGBA8888) 初始化一个 RenderTexture 对象
*/
static RenderTexture * create(int w, int h);
/**
* @js ctor
*/
RenderTexture();
/**
* @js NA
* @lua NA
*/
virtual ~RenderTexture();
/** 使用 点的高度和宽度,像素格式(只在 RGB ,RGBA 格式有效) 初始化一个 RenderTexture 对象 */
bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat);
/** 使用 点的高度和宽度,像素格式(只在 RGB ,RGBA 格式有效),depthStencil(深度模板)格式 初始化一个 RenderTexture 对象
*/
bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat);
/** starts grabbing(抢占) */
void begin();
/** 首先 clearing the texture 的时候开始 rendering(渲染)到texture。
首先调用 -clear 然后调用 -begin 更有效*/
void beginWithClear(float r, float g, float b, float a);
/** 首先 clearing the texture 的时候开始 rendering(渲染)到texture。
首先调用 -clear 然后调用 -begin 更有效 */
void beginWithClear(float r, float g, float b, float a, float depthValue);
/** 首先 clearing the texture 的时候开始 rendering(渲染)到texture。
首先调用 -clear 然后调用 -begin 更有效 */
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue);
/** lua 的 end 关键字, 使用其他名称出口到Lua. */
inline void endToLua(){ end();};
/** ends grabbing(抢占)*/
void end();
/** 使用 color 来清除 texture */
void clear(float r, float g, float b, float a);
/** 使用指定的 depth(深度)值来清除 texture */
void clearDepth(float depthValue);
/** 使用指定的 模版值来清除 texture */
void clearStencil(int stencilValue);
/* 使用 texture's数据 创建一个 Image
Caller(来电)通过调用 delete 负责删除它.
*/
Image* newImage(bool flipImage = true);
CC_DEPRECATED_ATTRIBUTE Image* newCCImage(bool flipImage = true) { return newImage(flipImage); };
/** saves the texture into a file using JPEG format. 该文件将被保存在Documents文件夹中。
Returns true 如果操作成功
*/
bool saveToFile(const char *szFilePath);
/** saves the texture into a file. 该格式可以是JPG或PNG格式。该文件将被保存在Documents文件夹中。
Returns true 如果操作成功
*/
bool saveToFile(const char *name, Image::Format format);
/** 监听 "come to background(后台)" 的消息, 并存储 render(呈现的) texture.
It only has effect on Android.
*/
void listenToBackground(Object *obj);
/** 监听 "come to foreground(前台)"的消息,并恢复帧缓冲对象
它只有在Android上有效果
*/
void listenToForeground(Object *obj);
/** Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. 只用当 "autoDraw" 是 true 时,它才有效. */
inline unsigned int getClearFlags() const { return _clearFlags; };
inline void setClearFlags(unsigned int clearFlags) { _clearFlags = clearFlags; };
/** Clear color value. 只用当 "autoDraw" 是 true 时,它才有效. */
inline const Color4F& getClearColor() const { return _clearColor; };
inline void setClearColor(const Color4F &clearColor) { _clearColor = clearColor; };
/** clearDepth 的值. 只用当 "autoDraw" 是 true 时,它才有效 */
inline float getClearDepth() const { return _clearDepth; };
inline void setClearDepth(float clearDepth) { _clearDepth = clearDepth; };
/** clear 模板的值. 只用当 "autoDraw" 是 true 时,它才有效 */
inline int getClearStencil() const { return _clearStencil; };
inline void setClearStencil(int clearStencil) { _clearStencil = clearStencil; };
/** enabled 时, 它会自动 render(显示)他的 children 的 texture .兼容性的原因,默认情况下禁用.
将来会启用
*/
inline bool isAutoDraw() const { return _autoDraw; };
inline void setAutoDraw(bool isAutoDraw) { _autoDraw = isAutoDraw; };
/** Gets 正在使用的 Sprite . */
inline Sprite* getSprite() const { return _sprite; };
/** Sets 正在使用的 Sprite . */
inline void setSprite(Sprite* sprite) {
CC_SAFE_RETAIN(sprite);
CC_SAFE_RELEASE(_sprite);
_sprite = sprite;
};
// Overrides
virtual void visit() override;
virtual void draw() override;
private:
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags);
protected:
GLuint _FBO;
GLuint _depthRenderBufffer;
GLint _oldFBO;
Texture2D* _texture;
Texture2D* _textureCopy; // a copy of _texture
Image* _UITextureImage;
Texture2D::PixelFormat _pixelFormat;
// code for "auto" update
GLbitfield _clearFlags;
Color4F _clearColor;
GLclampf _clearDepth;
GLint _clearStencil;
bool _autoDraw;
/** The Sprite being used.
The sprite, 默认情况下会使用下列混合功能: GL_ONE, GL_ONE_MINUS_SRC_ALPHA.
混合功能可以在运行时调用下列方法改变:
- [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
*/
Sprite* _sprite;
};
// end of textures group
/// @}
NS_CC_END
#endif //__CCRENDER_TEXTURE_H__