123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- #ifndef __CCRENDER_TEXTURE_H__
- #define __CCRENDER_TEXTURE_H__
- #include "2d/CCNode.h"
- #include "2d/CCSprite.h"
- #include "platform/CCImage.h"
- #include "renderer/CCGroupCommand.h"
- #include "renderer/CCCustomCommand.h"
- NS_CC_BEGIN
- class EventCustom;
- class CC_DLL RenderTexture : public Node
- {
- public:
-
- static RenderTexture * create(int w ,int h, Texture2D::PixelFormat format, GLuint depthStencilFormat);
-
- static RenderTexture * create(int w, int h, Texture2D::PixelFormat format);
-
- static RenderTexture * create(int w, int h);
-
- virtual void begin();
-
- virtual void beginWithClear(float r, float g, float b, float a);
-
- virtual void beginWithClear(float r, float g, float b, float a, float depthValue);
-
- virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue);
-
- virtual void end();
-
- void clear(float r, float g, float b, float a);
-
- virtual void clearDepth(float depthValue);
-
- virtual void clearStencil(int stencilValue);
-
-
- Image* newImage(bool flipImage = true);
-
- CC_DEPRECATED_ATTRIBUTE Image* newCCImage(bool flipImage = true) { return newImage(flipImage); };
-
- bool saveToFile(const std::string& filename, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);
-
- bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, std::function<void (RenderTexture*, const std::string&)> callback = nullptr);
-
-
- void listenToBackground(EventCustom *event);
-
-
- void listenToForeground(EventCustom *event);
-
-
- unsigned int getClearFlags() const { return _clearFlags; }
-
-
- void setClearFlags(unsigned int clearFlags) { _clearFlags = clearFlags; }
-
-
- const Color4F& getClearColor() const { return _clearColor; }
-
-
- void setClearColor(const Color4F &clearColor) { _clearColor = clearColor; }
-
-
- float getClearDepth() const { return _clearDepth; }
-
-
- void setClearDepth(float clearDepth) { _clearDepth = clearDepth; }
-
-
- int getClearStencil() const { return _clearStencil; }
-
-
- void setClearStencil(int clearStencil) { _clearStencil = clearStencil; }
-
-
- bool isAutoDraw() const { return _autoDraw; }
-
-
- void setAutoDraw(bool isAutoDraw) { _autoDraw = isAutoDraw; }
-
- Sprite* getSprite() const { return _sprite; }
-
-
- void setSprite(Sprite* sprite);
-
-
- virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
- virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
-
- void setKeepMatrix(bool keepMatrix);
-
- void setVirtualViewport(const Vec2& rtBegin, const Rect& fullRect, const Rect& fullViewport);
- public:
-
- RenderTexture();
-
- virtual ~RenderTexture();
-
- bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format);
-
- bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, GLuint depthStencilFormat);
- protected:
- virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags);
-
-
- bool _keepMatrix;
- Rect _rtTextureRect;
- Rect _fullRect;
- Rect _fullviewPort;
-
- GLuint _FBO;
- GLuint _depthRenderBuffer;
- GLuint _stencilRenderBuffer;
- GLint _oldFBO;
- Texture2D* _texture;
- Texture2D* _textureCopy;
- Image* _UITextureImage;
- Texture2D::PixelFormat _pixelFormat;
-
-
- GLbitfield _clearFlags;
- Color4F _clearColor;
- GLclampf _clearDepth;
- GLint _clearStencil;
- bool _autoDraw;
-
- Sprite* _sprite;
-
- GroupCommand _groupCommand;
- CustomCommand _beginWithClearCommand;
- CustomCommand _clearDepthCommand;
- CustomCommand _clearCommand;
- CustomCommand _beginCommand;
- CustomCommand _endCommand;
-
- CustomCommand _saveToFileCommand;
- std::function<void (RenderTexture*, const std::string&)> _saveFileCallback;
- protected:
-
- void onBegin();
- void onEnd();
- void onClear();
- void onClearDepth();
- void onSaveToFile(const std::string& fileName, bool isRGBA = true);
-
- Mat4 _oldTransMatrix, _oldProjMatrix;
- Mat4 _transformMatrix, _projectionMatrix;
- private:
- CC_DISALLOW_COPY_AND_ASSIGN(RenderTexture);
- };
- NS_CC_END
- #endif
|