/// <summary> /// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { bool bRet = false; do { w *= (int)CCDirector.sharedDirector().ContentScaleFactor; h *= (int)CCDirector.sharedDirector().ContentScaleFactor; //glGetIntegerv(0x8CA6, m_nOldFBO); // textures must be power of two squared uint powW = (uint)ccUtils.ccNextPOT(w); uint powH = (uint)ccUtils.ccNextPOT(h); m_pTexture = new CCTexture2D(); CCApplication app = CCApplication.sharedApplication(); m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h); app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D); app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0)); m_pTexture.initWithTexture(m_RenderTarget2D); // generate FBO //ccglGenFramebuffers(1, &m_uFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO); // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCAssert(0, "Render Texture : Could not attach texture to framebuffer"); // CC_SAFE_DELETE(m_pTexture); // break; //} //m_pTexture.setAliasTexParameters(); m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //m_pTexture->release(); //m_pSprite.scaleY = -1; this.addChild(m_pSprite); ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; m_pSprite.BlendFunc = tBlendFunc; //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); bRet = true; } while (false); return(bRet); }
public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0) { return(false); } w = w * (int)CCDirector.sharedDirector().ContentScaleFactor; h = h * (int)CCDirector.sharedDirector().ContentScaleFactor; ccUtils.ccNextPOT((long)w); ccUtils.ccNextPOT((long)h); this.m_pTexture = new CCTexture2D(); CCApplication cCApplication = CCApplication.sharedApplication(); this.m_RenderTarget2D = new RenderTarget2D(cCApplication.GraphicsDevice, w, h); cCApplication.GraphicsDevice.SetRenderTarget(this.m_RenderTarget2D); cCApplication.GraphicsDevice.Clear(new Color(0, 0, 0, 0)); this.m_pTexture.initWithTexture(this.m_RenderTarget2D); this.m_pSprite = CCSprite.spriteWithTexture(this.m_pTexture); this.addChild(this.m_pSprite); ccBlendFunc _ccBlendFunc = new ccBlendFunc() { src = 1, dst = 771 }; this.m_pSprite.BlendFunc = _ccBlendFunc; return(true); }
public bool initWithSize(ccGridSize gridSize) { CCDirector pDirector = CCDirector.sharedDirector(); CCSize s = pDirector.winSizeInPixels; ulong POTWide = ccNextPOT((uint)s.width); ulong POTHigh = ccNextPOT((uint)s.height); // we only use rgba8888 CCTexture2DPixelFormat format = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888; CCTexture2D pTexture = new CCTexture2D(); pTexture.initWithData(null, format, (uint)POTWide, (uint)POTHigh, s); if (pTexture == null) { CCLog.Log("cocos2d: CCGrid: error creating texture"); return(false); } initWithSize(gridSize, pTexture, false); return(true); }
public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture cCRenderTexture = new CCRenderTexture(); if (cCRenderTexture.initWithWidthAndHeight(w, h, eFormat)) { return(cCRenderTexture); } return(null); }
/// <summary> /// creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture pRet = new CCRenderTexture(); if (pRet.initWithWidthAndHeight(w, h, eFormat)) { return pRet; } return null; }
/// <summary> /// creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> /// <param name="w"></param> /// <param name="h"></param> /// <param name="eFormat"></param> /// <returns></returns> public static CCRenderTexture renderTextureWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { CCRenderTexture pRet = new CCRenderTexture(); if (pRet != null && pRet.initWithWidthAndHeight(w, h, eFormat)) { //pRet->autorelease(); return pRet; } //CC_SAFE_DELETE(pRet); return null; }
public bool initWithSize(ccGridSize gridSize) { CCSize cCSize = CCDirector.sharedDirector().winSizeInPixels; ulong num = this.ccNextPOT((ulong)((uint)cCSize.width)); ulong num1 = this.ccNextPOT((ulong)((uint)cCSize.height)); CCTexture2DPixelFormat cCTexture2DPixelFormat = CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888; CCTexture2D cCTexture2D = new CCTexture2D(); cCTexture2D.initWithData(null, cCTexture2DPixelFormat, (uint)num, (uint)num1, cCSize); if (cCTexture2D == null) { CCLog.Log("cocos2d: CCGrid: error creating texture"); return(false); } this.initWithSize(gridSize, cCTexture2D, false); return(true); }
/// <summary> /// Intializes with a texture2d with data /// </summary> public bool InitWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { CCApplication app = CCApplication.SharedApplication; Texture = new Texture2D(app.GraphicsDevice, (int)contentSize.Width, (int)contentSize.Height); m_tContentSize = contentSize; m_uPixelsWide = (int)pixelsWide; m_uPixelsHigh = (int)pixelsHigh; m_ePixelFormat = pixelFormat; m_fMaxS = contentSize.Width / (pixelsWide); m_fMaxT = contentSize.Height / (pixelsHigh); m_bHasPremultipliedAlpha = false; //m_bHasMipmaps = false; return(true); }
/*public object keepData(object data, uint length) * { * throw new NotImplementedException(); * } */ /// <summary> /// Intializes with a texture2d with data /// </summary> public bool initWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { SurfaceFormat format = SurfaceFormat.Color; switch (pixelFormat) { case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_A8: format = SurfaceFormat.Alpha8; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_AI88: break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Automatic: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Default: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_I8: format = SurfaceFormat.Single; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC2: format = SurfaceFormat.Vector2; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC4: format = SurfaceFormat.Vector4; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB565: format = SurfaceFormat.Bgr565; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB5A1: format = SurfaceFormat.Bgra5551; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB888: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444: format = SurfaceFormat.Bgra4444; break; } Texture2D t = new Texture2D(CCApplication.sharedApplication().GraphicsDevice, (int)pixelsWide, (int)pixelsHigh, false, format); // This was the old version that is not compatible with non-WP7 devices. // Texture2D t = new Texture2D(CCApplication.sharedApplication().GraphicsDevice, (int)contentSize.width, (int)contentSize.height, false, format); if (data is byte[]) { t.SetData((byte[])data); } m_tContentSize = new CCSize(contentSize); m_uPixelsWide = (int)pixelsWide; m_uPixelsHigh = (int)pixelsHigh; m_ePixelFormat = pixelFormat; m_fMaxS = contentSize.width / (float)(pixelsWide); m_fMaxT = contentSize.height / (float)(pixelsHigh); m_bHasPremultipliedAlpha = false; /* * long POTWide, POTHigh; * POTWide = ccUtils.ccNextPOT(texture.Width); * POTHigh = ccUtils.ccNextPOT(texture.Height); * * int maxTextureSize = CCConfiguration.sharedConfiguration().MaxTextureSize; * if (POTHigh > maxTextureSize || POTWide > maxTextureSize) * { * CCLog.Log(string.Format("cocos2d: WARNING: Image ({0} x {1}) is bigger than the supported {2} x {3}", POTWide, POTHigh, maxTextureSize, maxTextureSize)); * return false; * }*/ texture2D = t; // return initWithTexture(t); return(true); }
/** sets the default pixel format for UIImages that contains alpha channel. If the UIImage contains alpha channel, then the options are: - generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one) - generate 24-bit textures: kCCTexture2DPixelFormat_RGB888 - generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444 - generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1 - generate 16-bit textures: kCCTexture2DPixelFormat_RGB565 - generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color) How does it work ? - If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture) - If the image is an RGB (without Alpha) then an RGB565 or RGB888 texture will be used (16-bit texture) @since v0.8 */ static public void setDefaultAlphaPixelFormat(CCTexture2DPixelFormat format) { throw new NotImplementedException(); }
/** Extensions to make it easy to create a CCTexture2D object from a PVRTC file Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). */ /** Initializes a texture from a PVRTC buffer */ public bool initWithPVRTCData(object data, int level, int bpp, bool hasAlpha, int length, CCTexture2DPixelFormat pixelFormat) { throw new NotImplementedException(); }
/*public object keepData(object data, uint length) { throw new NotImplementedException(); } */ /// <summary> /// Intializes with a texture2d with data /// </summary> public bool initWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { SurfaceFormat format = SurfaceFormat.Color; switch(pixelFormat) { case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_A8: format = SurfaceFormat.Alpha8; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_AI88: break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Automatic: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Default: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_I8: format = SurfaceFormat.Single; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC2: format = SurfaceFormat.Vector2; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC4: format = SurfaceFormat.Vector4; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB565: format = SurfaceFormat.Bgr565; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB5A1: format = SurfaceFormat.Bgra5551; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB888: format = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444: format = SurfaceFormat.Bgra4444; break; } Texture2D t = new Texture2D(CCApplication.sharedApplication().GraphicsDevice, (int)pixelsWide, (int)pixelsHigh, false, format); // This was the old version that is not compatible with non-WP7 devices. // Texture2D t = new Texture2D(CCApplication.sharedApplication().GraphicsDevice, (int)contentSize.width, (int)contentSize.height, false, format); if (data is byte[]) { t.SetData((byte[])data); } m_tContentSize = new CCSize(contentSize); m_uPixelsWide = (int)pixelsWide; m_uPixelsHigh = (int)pixelsHigh; m_ePixelFormat = pixelFormat; m_fMaxS = contentSize.width / (float)(pixelsWide); m_fMaxT = contentSize.height / (float)(pixelsHigh); m_bHasPremultipliedAlpha = false; /* long POTWide, POTHigh; POTWide = ccUtils.ccNextPOT(texture.Width); POTHigh = ccUtils.ccNextPOT(texture.Height); int maxTextureSize = CCConfiguration.sharedConfiguration().MaxTextureSize; if (POTHigh > maxTextureSize || POTWide > maxTextureSize) { CCLog.Log(string.Format("cocos2d: WARNING: Image ({0} x {1}) is bigger than the supported {2} x {3}", POTWide, POTHigh, maxTextureSize, maxTextureSize)); return false; }*/ texture2D = t; // return initWithTexture(t); return (true); }
public bool initWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { SurfaceFormat color = SurfaceFormat.Color; switch (pixelFormat) { case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Automatic: color = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888: color = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB888: color = SurfaceFormat.Color; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB565: color = SurfaceFormat.Bgr565; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_A8: color = SurfaceFormat.Alpha8; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_I8: color = SurfaceFormat.Single; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444: color = SurfaceFormat.Bgra4444; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGB5A1: color = SurfaceFormat.Bgra5551; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC4: color = SurfaceFormat.Vector4; break; case CCTexture2DPixelFormat.kCCTexture2DPixelFormat_PVRTC2: color = SurfaceFormat.Vector2; break; } Texture2D textured = new Texture2D(CCApplication.sharedApplication().GraphicsDevice, (int)pixelsWide, (int)pixelsHigh, false, color); if (data is byte[]) { textured.SetData <byte>((byte[])data); } this.m_tContentSize = new CCSize(contentSize); this.m_uPixelsWide = (int)pixelsWide; this.m_uPixelsHigh = (int)pixelsHigh; this.m_ePixelFormat = pixelFormat; this.m_fMaxS = contentSize.width / ((float)pixelsWide); this.m_fMaxT = contentSize.height / ((float)pixelsHigh); this.m_bHasPremultipliedAlpha = false; this.texture2D = textured; return(true); }
public static void setDefaultAlphaPixelFormat(CCTexture2DPixelFormat format) { throw new NotImplementedException(); }
/** * Extensions to make it easy to create a CCTexture2D object from a PVRTC file * Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). */ /** Initializes a texture from a PVRTC buffer */ public bool initWithPVRTCData(object data, int level, int bpp, bool hasAlpha, int length, CCTexture2DPixelFormat pixelFormat) { throw new NotImplementedException(); }
/// <summary> /// Intializes with a texture2d with data /// </summary> public bool initWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { CCApplication app = CCApplication.sharedApplication(); texture2D = new Texture2D(app.GraphicsDevice, (int)contentSize.width, (int)contentSize.height); m_tContentSize.width = contentSize.width; m_tContentSize.height = contentSize.height; return true; }
/// <summary> /// Intializes with a texture2d with data /// </summary> public bool initWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { throw new NotImplementedException(); }
/// <summary> /// Intializes with a texture2d with data /// </summary> public bool InitWithData(object data, CCTexture2DPixelFormat pixelFormat, uint pixelsWide, uint pixelsHigh, CCSize contentSize) { CCApplication app = CCApplication.SharedApplication; Texture = new Texture2D(app.GraphicsDevice, (int) contentSize.Width, (int) contentSize.Height); m_tContentSize = contentSize; m_uPixelsWide = (int) pixelsWide; m_uPixelsHigh = (int) pixelsHigh; m_ePixelFormat = pixelFormat; m_fMaxS = contentSize.Width / (pixelsWide); m_fMaxT = contentSize.Height / (pixelsHigh); m_bHasPremultipliedAlpha = false; //m_bHasMipmaps = false; return true; }
/// <summary> /// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { // If the gles version is lower than GLES_VER_1_0, // some extended gles functions can't be implemented, so return false directly. if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0) { return false; } bool bRet = false; do { w *= (int)CCDirector.sharedDirector().ContentScaleFactor; h *= (int)CCDirector.sharedDirector().ContentScaleFactor; //glGetIntegerv(0x8CA6, m_nOldFBO); // textures must be power of two squared uint powW = (uint)ccUtils.ccNextPOT(w); uint powH = (uint)ccUtils.ccNextPOT(h); m_pTexture = new CCTexture2D(); CCApplication app = CCApplication.sharedApplication(); m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h); app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D); app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0)); m_pTexture.initWithTexture(m_RenderTarget2D); // generate FBO //ccglGenFramebuffers(1, &m_uFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO); // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCAssert(0, "Render Texture : Could not attach texture to framebuffer"); // CC_SAFE_DELETE(m_pTexture); // break; //} //m_pTexture.setAliasTexParameters(); m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //m_pTexture->release(); //m_pSprite.scaleY = -1; this.addChild(m_pSprite); ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; m_pSprite.BlendFunc = tBlendFunc; //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); bRet = true; } while (false); return bRet; }
/// <summary> /// initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid /// </summary> /// <param name="w"></param> /// <param name="h"></param> /// <param name="eFormat"></param> /// <returns></returns> public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat) { // If the gles version is lower than GLES_VER_1_0, // some extended gles functions can't be implemented, so return false directly. if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0) { return false; } bool bRet = false; do { w = (int)CCDirector.sharedDirector().ContentScaleFactor; h = (int)CCDirector.sharedDirector().ContentScaleFactor; //glGetIntegerv(0x8CA6, m_nOldFBO); // textures must be power of two squared uint powW = (uint)ccUtils.ccNextPOT(w); uint powH = (uint)ccUtils.ccNextPOT(h); var data = (int)(powW * powH * 4); //CC_BREAK_IF(! data); //memset(data, 0, (int)(powW * powH * 4)); //m_ePixelFormat = eFormat; m_pTexture = new CCTexture2D(); //CC_BREAK_IF(! m_pTexture); m_pTexture.initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, new CCSize((float)w, (float)h)); //free( data ); // generate FBO //ccglGenFramebuffers(1, &m_uFBO); //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO); // associate texture with FBO //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0); // check if it worked (probably worth doing :) ) //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); //if (status != CC_GL_FRAMEBUFFER_COMPLETE) //{ // CCAssert(0, "Render Texture : Could not attach texture to framebuffer"); // CC_SAFE_DELETE(m_pTexture); // break; //} m_pTexture.setAliasTexParameters(); m_pSprite = CCSprite.spriteWithTexture(m_pTexture); //m_pTexture->release(); m_pSprite.scaleY = -1; this.addChild(m_pSprite); ccBlendFunc tBlendFunc = new ccBlendFunc { src = 1, dst = 0x0303 }; m_pSprite.BlendFunc = tBlendFunc; //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); bRet = true; } while (true); return bRet; }