2012-04-19 14:35:52 +08:00
/****************************************************************************
2012-06-12 01:43:07 +08:00
Copyright ( c ) 2010 - 2012 cocos2d - x . org
2012-04-19 14:35:52 +08:00
Copyright ( c ) 2009 Jason Booth
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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef __CCRENDER_TEXTURE_H__
# define __CCRENDER_TEXTURE_H__
2012-06-19 13:50:11 +08:00
# include "base_nodes/CCNode.h"
# include "sprite_nodes/CCSprite.h"
2012-04-19 14:35:52 +08:00
# include "kazmath/mat4.h"
NS_CC_BEGIN
2012-06-20 18:09:11 +08:00
/**
* @ addtogroup textures
* @ {
*/
2012-04-19 14:35:52 +08:00
typedef enum eImageFormat
{
kCCImageFormatJPEG = 0 ,
kCCImageFormatPNG = 1 ,
} tCCImageFormat ;
/**
@ brief CCRenderTexture is a generic rendering target . To render things into it ,
simply construct a render target , call begin on it , call visit on any cocos
2012-09-17 15:02:24 +08:00
scenes or objects to render them , and call end . For convenience , render texture
2012-04-19 14:35:52 +08:00
adds a sprite as it ' s display child with the results , so you can simply add
the render texture to your scene and treat it like any other CocosNode .
There are also functions for saving the render texture to disk in PNG or JPG format .
@ since v0 .8 .1
*/
class CC_DLL CCRenderTexture : public CCNode
{
/** The CCSprite being used.
The sprite , by default , will use the following blending function : GL_ONE , GL_ONE_MINUS_SRC_ALPHA .
The blending function can be changed in runtime by calling :
- [ [ renderTexture sprite ] setBlendFunc : ( ccBlendFunc ) { GL_ONE , GL_ONE_MINUS_SRC_ALPHA } ] ;
*/
CC_PROPERTY ( CCSprite * , m_pSprite , Sprite )
public :
CCRenderTexture ( ) ;
virtual ~ CCRenderTexture ( ) ;
2012-06-12 01:43:07 +08:00
2012-06-19 13:50:11 +08:00
/** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-06-19 13:50:11 +08:00
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCRenderTexture * renderTextureWithWidthAndHeight ( int w , int h , CCTexture2DPixelFormat eFormat , GLuint uDepthStencilFormat ) ;
2012-06-12 01:43:07 +08:00
2012-06-14 15:13:16 +08:00
/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-06-14 15:13:16 +08:00
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCRenderTexture * renderTextureWithWidthAndHeight ( int w , int h , CCTexture2DPixelFormat eFormat ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-06-14 15:13:16 +08:00
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCRenderTexture * renderTextureWithWidthAndHeight ( int w , int h ) ;
2012-04-19 14:35:52 +08:00
2012-06-19 13:50:11 +08:00
/** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format*/
2012-06-14 15:13:16 +08:00
static CCRenderTexture * create ( int w , int h , CCTexture2DPixelFormat eFormat , GLuint uDepthStencilFormat ) ;
2012-06-08 14:30:55 +08:00
2012-04-19 14:35:52 +08:00
/** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
2012-06-14 15:13:16 +08:00
static CCRenderTexture * create ( int w , int h , CCTexture2DPixelFormat eFormat ) ;
2012-04-19 14:35:52 +08:00
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
2012-06-14 15:13:16 +08:00
static CCRenderTexture * create ( int w , int h ) ;
2012-04-19 14:35:52 +08:00
/** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */
bool initWithWidthAndHeight ( int w , int h , CCTexture2DPixelFormat eFormat ) ;
2012-06-19 13:50:11 +08:00
/** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format*/
2012-06-12 01:43:07 +08:00
bool initWithWidthAndHeight ( int w , int h , CCTexture2DPixelFormat eFormat , GLuint uDepthStencilFormat ) ;
2012-04-19 14:35:52 +08:00
/** starts grabbing */
void begin ( ) ;
/** starts rendering to the texture while clearing the texture first.
This is more efficient then calling - clear first and then - begin */
void beginWithClear ( float r , float g , float b , float a ) ;
2012-06-19 13:50:11 +08:00
/** starts rendering to the texture while clearing the texture first.
This is more efficient then calling - clear first and then - begin */
void beginWithClear ( float r , float g , float b , float a , float depthValue ) ;
/** starts rendering to the texture while clearing the texture first.
This is more efficient then calling - clear first and then - begin */
2012-06-12 01:43:07 +08:00
void beginWithClear ( float r , float g , float b , float a , float depthValue , int stencilValue ) ;
2012-04-19 14:35:52 +08:00
/** end is key word of lua, use other name to export to lua. */
inline void endToLua ( ) { end ( ) ; } ;
/** ends grabbing*/
2012-06-14 18:37:57 +08:00
void end ( ) ;
2012-04-19 14:35:52 +08:00
/** clears the texture with a color */
void clear ( float r , float g , float b , float a ) ;
2012-06-19 13:50:11 +08:00
/** clears the texture with a specified depth value */
void clearDepth ( float depthValue ) ;
/** clears the texture with a specified stencil value */
2012-06-12 01:43:07 +08:00
void clearStencil ( int stencilValue ) ;
2012-04-19 14:35:52 +08:00
/* creates a new CCImage from with the texture's data.
Caller is responsible for releasing it by calling delete .
*/
CCImage * newCCImage ( ) ;
/** saves the texture into a file using JPEG format. The file will be saved in the Documents folder.
Returns YES if the operation is successful .
*/
bool saveToFile ( const char * szFilePath ) ;
/** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder.
Returns YES if the operation is successful .
*/
bool saveToFile ( const char * name , tCCImageFormat format ) ;
2012-06-14 18:37:57 +08:00
/** Listen "come to background" message, and save render texture.
It only has effect on Android .
*/
void listenToBackground ( CCObject * obj ) ;
2012-04-19 14:35:52 +08:00
protected :
2012-06-12 01:43:07 +08:00
GLuint m_uFBO ;
GLuint m_uDepthRenderBufffer ;
GLint m_nOldFBO ;
CCTexture2D * m_pTexture ;
2012-10-10 11:36:02 +08:00
CCTexture2D * m_pTextureCopy ; // a copy of m_pTexture
2012-06-12 01:43:07 +08:00
CCImage * m_pUITextureImage ;
GLenum m_ePixelFormat ;
2012-04-19 14:35:52 +08:00
} ;
2012-06-20 18:09:11 +08:00
// end of textures group
/// @}
2012-04-19 14:35:52 +08:00
NS_CC_END
2012-06-14 05:26:28 +08:00
# endif //__CCRENDER_TEXTURE_H__