2013-07-26 13:43:28 +08:00
|
|
|
local scheduler = CCDirector:getInstance():getScheduler()
|
2013-04-05 16:13:04 +08:00
|
|
|
local kTagLabel = 1
|
|
|
|
local kTagSprite1 = 2
|
|
|
|
local kTagSprite2 = 3
|
|
|
|
|
|
|
|
local originCreateLayer = createTestLayer
|
|
|
|
local function createTestLayer(title, subtitle)
|
|
|
|
local ret = originCreateLayer(title, subtitle)
|
|
|
|
Helper.titleLabel:setTag(kTagLabel)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-07-05 16:49:22 +08:00
|
|
|
local col = CCLayerColor:create(Color4B(128,128,128,255))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(col, -10)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureTIFF
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
|
|
|
|
local function TextureTIFF()
|
|
|
|
local ret = createTestLayer("TIFF Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.tiff")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePNG
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePNG()
|
|
|
|
local ret = createTestLayer("PNG Test")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureJPEG
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureJPEG()
|
|
|
|
local ret = createTestLayer("JPEG Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.jpeg")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureWEBP
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureWEBP()
|
|
|
|
local ret = createTestLayer("WEBP Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.webp")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureMipMap
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureMipMap()
|
|
|
|
local ret = createTestLayer("Texture Mipmap",
|
|
|
|
"Left image uses mipmap. Right image doesn't")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local texture0 = CCTextureCache:getInstance():addImage(
|
2013-04-05 16:13:04 +08:00
|
|
|
"Images/grossini_dance_atlas.png")
|
|
|
|
texture0:generateMipmap()
|
2013-08-06 11:34:48 +08:00
|
|
|
local texParams = CCTexture:TexParams()
|
2013-04-05 16:13:04 +08:00
|
|
|
texParams.minFilter = GL_LINEAR_MIPMAP_LINEAR
|
|
|
|
texParams.magFilter = GL_LINEAR
|
|
|
|
texParams.wrapS = GL_CLAMP_TO_EDGE
|
|
|
|
texParams.wrapT = GL_CLAMP_TO_EDGE
|
|
|
|
texture0:setTexParameters(texParams)
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local texture1 = CCTextureCache:getInstance():addImage(
|
2013-04-05 16:13:04 +08:00
|
|
|
"Images/grossini_dance_atlas_nomipmap.png")
|
|
|
|
|
|
|
|
local img0 = CCSprite:createWithTexture(texture0)
|
2013-07-26 13:43:28 +08:00
|
|
|
img0:setTextureRect(CCRect(85, 121, 85, 121))
|
|
|
|
img0:setPosition(CCPoint( s.width/3.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img0)
|
|
|
|
|
|
|
|
local img1 = CCSprite:createWithTexture(texture1)
|
2013-07-26 13:43:28 +08:00
|
|
|
img1:setTextureRect(CCRect(85, 121, 85, 121))
|
|
|
|
img1:setPosition(CCPoint( 2*s.width/3.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img1)
|
|
|
|
|
|
|
|
local scale1 = CCEaseOut:create(CCScaleBy:create(4, 0.01), 3)
|
|
|
|
local sc_back = scale1:reverse()
|
|
|
|
|
2013-06-19 12:08:26 +08:00
|
|
|
local scale2 = tolua.cast(scale1:clone(), "CCEaseOut")
|
2013-04-05 16:13:04 +08:00
|
|
|
local sc_back2 = scale2:reverse()
|
|
|
|
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale1)
|
|
|
|
arr:addObject(sc_back)
|
|
|
|
img0:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
|
|
|
|
|
|
|
arr = CCArray:create()
|
|
|
|
arr:addObject(scale2)
|
|
|
|
arr:addObject(sc_back2)
|
|
|
|
img1:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRMipMap
|
|
|
|
-- To generate PVR images read this article:
|
|
|
|
-- http:--developer.apple.com/iphone/library/qa/qa2008/qa1611.html
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRMipMap()
|
|
|
|
local ret = createTestLayer("PVRTC MipMap Test", "Left image uses mipmap. Right image doesn't")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local imgMipMap = CCSprite:create("Images/logo-mipmap.pvr")
|
|
|
|
if imgMipMap ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
imgMipMap:setPosition(CCPoint( s.width/2.0-100, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(imgMipMap)
|
|
|
|
|
|
|
|
-- support mipmap filtering
|
2013-08-06 11:34:48 +08:00
|
|
|
local texParams = CCTexture:TexParams()
|
2013-04-05 16:13:04 +08:00
|
|
|
texParams.minFilter = GL_LINEAR_MIPMAP_LINEAR
|
|
|
|
texParams.magFilter = GL_LINEAR
|
|
|
|
texParams.wrapS = GL_CLAMP_TO_EDGE
|
|
|
|
texParams.wrapT = GL_CLAMP_TO_EDGE
|
|
|
|
|
|
|
|
imgMipMap:getTexture():setTexParameters(texParams)
|
|
|
|
end
|
|
|
|
|
|
|
|
local img = CCSprite:create("Images/logo-nomipmap.pvr")
|
|
|
|
if img ~= nil then
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0+100, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
|
|
|
|
local scale1 = CCEaseOut:create(CCScaleBy:create(4, 0.01), 3)
|
|
|
|
local sc_back = scale1:reverse()
|
|
|
|
|
2013-06-19 12:08:26 +08:00
|
|
|
local scale2 = tolua.cast(scale1:clone(), "CCEaseOut")
|
2013-04-05 16:13:04 +08:00
|
|
|
local sc_back2 = scale2:reverse()
|
|
|
|
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale1)
|
|
|
|
arr:addObject(sc_back)
|
|
|
|
imgMipMap:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
|
|
|
|
|
|
|
arr = CCArray:create()
|
|
|
|
arr:addObject(scale2)
|
|
|
|
arr:addObject(sc_back2)
|
|
|
|
|
|
|
|
img:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRMipMap2
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRMipMap2()
|
|
|
|
local ret = createTestLayer("PVR MipMap Test #2", "Left image uses mipmap. Right image doesn't")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local imgMipMap = CCSprite:create("Images/test_image_rgba4444_mipmap.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
imgMipMap:setPosition(CCPoint( s.width/2.0-100, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(imgMipMap)
|
|
|
|
|
|
|
|
-- support mipmap filtering
|
2013-08-06 11:34:48 +08:00
|
|
|
local texParams = CCTexture:TexParams()
|
2013-04-05 16:13:04 +08:00
|
|
|
texParams.minFilter = GL_LINEAR_MIPMAP_LINEAR
|
|
|
|
texParams.magFilter = GL_LINEAR
|
|
|
|
texParams.wrapS = GL_CLAMP_TO_EDGE
|
|
|
|
texParams.wrapT = GL_CLAMP_TO_EDGE
|
|
|
|
|
|
|
|
imgMipMap:getTexture():setTexParameters(texParams)
|
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0+100, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
|
|
|
|
local scale1 = CCEaseOut:create(CCScaleBy:create(4, 0.01), 3)
|
|
|
|
local sc_back = scale1:reverse()
|
|
|
|
|
2013-06-19 12:08:26 +08:00
|
|
|
local scale2 = tolua.cast(scale1:clone(), "CCEaseOut")
|
2013-04-05 16:13:04 +08:00
|
|
|
local sc_back2 = scale2:reverse()
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale1)
|
|
|
|
arr:addObject(sc_back)
|
|
|
|
|
|
|
|
imgMipMap:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
|
|
|
|
|
|
|
arr = CCArray:create()
|
|
|
|
arr:addObject(scale2)
|
|
|
|
arr:addObject(sc_back2)
|
|
|
|
|
|
|
|
img:runAction(CCRepeatForever:create(CCSequence:create(arr)))
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVR2BPP
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVR2BPP()
|
|
|
|
local ret = createTestLayer("PVR TC 2bpp Test")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtc2bpp.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVR
|
|
|
|
-- To generate PVR images read this article:
|
|
|
|
-- http:--developer.apple.com/iphone/library/qa/qa2008/qa1611.html
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVR()
|
|
|
|
local ret = createTestLayer("PVR TC 4bpp Test #2")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("This test is not supported.")
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVR4BPP
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVR4BPP()
|
|
|
|
local ret = createTestLayer("PVR TC 4bpp Test #3")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtc4bpp.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("This test is not supported in cocos2d-mac")
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGBA8888
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGBA8888()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 8888 Test")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba8888.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRBGRA8888
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRBGRA8888()
|
|
|
|
local ret = createTestLayer("PVR + BGRA 8888 Test")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_bgra8888.pvr")
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("BGRA8888 images are not supported")
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGBA5551
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGBA5551()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 5551 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba5551.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGBA4444
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGBA4444()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 4444 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba4444.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGBA4444GZ
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGBA4444GZ()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 4444 + GZ Test",
|
|
|
|
"This is a gzip PVR image")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba4444.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGBA4444CCZ
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGBA4444CCZ()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 4444 + CCZ Test",
|
|
|
|
"This is a ccz PVR image")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba4444.pvr.ccz")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRRGB565
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRRGB565()
|
|
|
|
local ret = createTestLayer("PVR + RGB 565 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgb565.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVR RGB888
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
local function TexturePVRRGB888()
|
|
|
|
local ret = createTestLayer("PVR + RGB 888 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgb888.pvr")
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRA8
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRA8()
|
|
|
|
local ret = createTestLayer("PVR + A8 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_a8.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRI8
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRI8()
|
|
|
|
local ret = createTestLayer("PVR + I8 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_i8.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRAI88
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRAI88()
|
|
|
|
local ret = createTestLayer("PVR + AI88 Test")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_ai88.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVR2BPPv3
|
|
|
|
local function TexturePVR2BPPv3()
|
|
|
|
local ret = createTestLayer("PVR TC 2bpp Test", "Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtc2bpp_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRII2BPPv3
|
|
|
|
local function TexturePVRII2BPPv3()
|
|
|
|
local ret = createTestLayer("PVR TC II 2bpp Test", "Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtcii2bpp_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVR4BPPv3
|
|
|
|
local function TexturePVR4BPPv3()
|
|
|
|
local ret = createTestLayer("PVR TC 4bpp Test", "Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtc4bpp_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("This test is not supported")
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRII4BPPv3
|
|
|
|
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
|
|
|
|
local function TexturePVRII4BPPv3()
|
|
|
|
local ret = createTestLayer("PVR TC II 4bpp Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_pvrtcii4bpp_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("This test is not supported")
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRRGBA8888v3
|
|
|
|
local function TexturePVRRGBA8888v3()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 8888 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba8888_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRBGRA8888v3
|
|
|
|
local function TexturePVRBGRA8888v3()
|
|
|
|
local ret = createTestLayer("PVR + BGRA 8888 Test",
|
|
|
|
"Testing PVR File Format v3")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_bgra8888_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
else
|
|
|
|
cclog("BGRA images are not supported")
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRRGBA5551v3
|
|
|
|
local function TexturePVRRGBA5551v3()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 5551 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
local img = CCSprite:create("Images/test_image_rgba5551_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRRGBA4444v3
|
|
|
|
local function TexturePVRRGBA4444v3()
|
|
|
|
local ret = createTestLayer("PVR + RGBA 4444 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgba4444_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRRGB565v3
|
|
|
|
local function TexturePVRRGB565v3()
|
|
|
|
local ret = createTestLayer("PVR + RGB 565 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgb565_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRRGB888v3
|
|
|
|
local function TexturePVRRGB888v3()
|
|
|
|
local ret = createTestLayer("PVR + RGB 888 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_rgb888_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRA8v3
|
|
|
|
local function TexturePVRA8v3()
|
|
|
|
local ret = createTestLayer("PVR + A8 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_a8_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRI8v3
|
|
|
|
local function TexturePVRI8v3()
|
|
|
|
local ret = createTestLayer("PVR + I8 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_i8_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRAI88v3
|
|
|
|
local function TexturePVRAI88v3()
|
|
|
|
local ret = createTestLayer("PVR + AI88 Test",
|
|
|
|
"Testing PVR File Format v3")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image_ai88_v3.pvr")
|
|
|
|
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint(s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRBadEncoding
|
|
|
|
-- Image generated using PVRTexTool:
|
|
|
|
-- http:--www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRBadEncoding()
|
|
|
|
local ret = createTestLayer("PVR Unsupported encoding",
|
|
|
|
"You should not see any image")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/test_image-bad_encoding.pvr")
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRNonSquare
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRNonSquare()
|
|
|
|
local ret = createTestLayer("PVR + Non square texture",
|
|
|
|
"Loading a 128x256 texture")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/grossini_128x256_mipmap.pvr")
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRNPOT4444
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRNPOT4444()
|
|
|
|
local ret = createTestLayer("PVR RGBA4 + NPOT texture",
|
|
|
|
"Loading a 81x121 RGBA4444 texture.")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/grossini_pvr_rgba4444.pvr")
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePVRNPOT8888
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePVRNPOT8888()
|
|
|
|
local ret = createTestLayer("PVR RGBA8 + NPOT texture",
|
|
|
|
"Loading a 81x121 RGBA8888 texture.")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local img = CCSprite:create("Images/grossini_pvr_rgba8888.pvr")
|
|
|
|
if img ~= nil then
|
2013-07-26 13:43:28 +08:00
|
|
|
img:setPosition(CCPoint( s.width/2.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(img)
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureAlias
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureAlias()
|
|
|
|
local ret = createTestLayer("AntiAlias / Alias textures",
|
|
|
|
"Left image is antialiased. Right image is aliases")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Sprite 1: GL_LINEAR
|
|
|
|
--
|
|
|
|
-- Default filter is GL_LINEAR
|
|
|
|
|
|
|
|
local sprite = CCSprite:create("Images/grossinis_sister1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint( s.width/3.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite)
|
|
|
|
|
|
|
|
-- this is the default filterting
|
|
|
|
sprite:getTexture():setAntiAliasTexParameters()
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Sprite 1: GL_NEAREST
|
|
|
|
--
|
|
|
|
|
|
|
|
local sprite2 = CCSprite:create("Images/grossinis_sister2.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite2:setPosition(CCPoint( 2*s.width/3.0, s.height/2.0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite2)
|
|
|
|
|
|
|
|
-- Use Nearest in this one
|
|
|
|
sprite2:getTexture():setAliasTexParameters()
|
|
|
|
|
|
|
|
-- scale them to show
|
|
|
|
local sc = CCScaleBy:create(3, 8.0)
|
|
|
|
local sc_back = tolua.cast(sc:reverse(), "CCScaleBy")
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(sc)
|
|
|
|
arr:addObject(sc_back)
|
|
|
|
local scaleforever = CCRepeatForever:create(CCSequence:create(arr))
|
2013-06-19 12:08:26 +08:00
|
|
|
local scaleToo = tolua.cast(scaleforever:clone(), "CCRepeatForever")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
sprite2:runAction(scaleforever)
|
|
|
|
sprite:runAction(scaleToo)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TexturePixelFormat
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TexturePixelFormat()
|
|
|
|
local ret = createTestLayer("Texture Pixel Formats",
|
|
|
|
"Textures: RGBA8888, RGBA4444, RGB5A1, RGB888, RGB565, A8")
|
|
|
|
--
|
|
|
|
-- This example displays 1 png images 4 times.
|
|
|
|
-- Each time the image is generated using:
|
|
|
|
-- 1- 32-bit RGBA8
|
|
|
|
-- 2- 16-bit RGBA4
|
|
|
|
-- 3- 16-bit RGB5A1
|
|
|
|
-- 4- 16-bit RGB565
|
|
|
|
|
|
|
|
local label = tolua.cast(ret:getChildByTag(kTagLabel), "CCLabelTTF")
|
2013-07-05 16:49:22 +08:00
|
|
|
label:setColor(Color3B(16,16,255))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
local background = CCLayerColor:create(Color4B(128,128,128,255), s.width, s.height)
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(background, -1)
|
|
|
|
|
|
|
|
-- RGBA 8888 image (32-bit)
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888)
|
|
|
|
local sprite1 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite1:setPosition(CCPoint(1*s.width/7, s.height/2+32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite1, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite1:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- RGBA 4444 image (16-bit)
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444)
|
|
|
|
local sprite2 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite2:setPosition(CCPoint(2*s.width/7, s.height/2-32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite2, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite2:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- RGB5A1 image (16-bit)
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1)
|
|
|
|
local sprite3 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite3:setPosition(CCPoint(3*s.width/7, s.height/2+32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite3, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite3:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- RGB888 image
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB888)
|
|
|
|
local sprite4 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite4:setPosition(CCPoint(4*s.width/7, s.height/2-32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite4, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite4:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- RGB565 image (16-bit)
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565)
|
|
|
|
local sprite5 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite5:setPosition(CCPoint(5*s.width/7, s.height/2+32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite5, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite5:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- A8 image (8-bit)
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_A8)
|
|
|
|
local sprite6 = CCSprite:create("Images/test-rgba1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite6:setPosition(CCPoint(6*s.width/7, s.height/2-32))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite6, 0)
|
|
|
|
|
|
|
|
-- remove texture from texture manager
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite6:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local fadeout = CCFadeOut:create(2)
|
|
|
|
local fadein = CCFadeIn:create(2)
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(CCDelayTime:create(2))
|
|
|
|
arr:addObject(fadeout)
|
|
|
|
arr:addObject(fadein)
|
|
|
|
local seq = CCSequence:create(arr)
|
|
|
|
local seq_4ever = CCRepeatForever:create(seq)
|
2013-06-19 12:08:26 +08:00
|
|
|
local seq_4ever2 = tolua.cast(seq_4ever:clone(), "CCRepeatForever")
|
|
|
|
local seq_4ever3 = tolua.cast(seq_4ever:clone(), "CCRepeatForever")
|
|
|
|
local seq_4ever4 = tolua.cast(seq_4ever:clone(), "CCRepeatForever")
|
|
|
|
local seq_4ever5 = tolua.cast(seq_4ever:clone(), "CCRepeatForever")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
sprite1:runAction(seq_4ever)
|
|
|
|
sprite2:runAction(seq_4ever2)
|
|
|
|
sprite3:runAction(seq_4ever3)
|
|
|
|
sprite4:runAction(seq_4ever4)
|
|
|
|
sprite5:runAction(seq_4ever5)
|
|
|
|
|
|
|
|
-- restore default
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():dumpCachedTextureInfo()
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureBlend
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureBlend()
|
|
|
|
local ret = createTestLayer("Texture Blending",
|
|
|
|
"Testing 3 different blending modes")
|
|
|
|
local i = 0
|
|
|
|
for i=0, 14 do
|
|
|
|
-- BOTTOM sprites have alpha pre-multiplied
|
|
|
|
-- they use by default GL_ONE, GL_ONE_MINUS_SRC_ALPHA
|
|
|
|
local cloud = CCSprite:create("Images/test_blend.png")
|
|
|
|
ret:addChild(cloud, i+1, 100+i)
|
2013-07-26 13:43:28 +08:00
|
|
|
cloud:setPosition(CCPoint(50+25*i, 80))
|
2013-07-05 16:49:22 +08:00
|
|
|
local blendFunc1 = BlendFunc()
|
2013-04-05 16:13:04 +08:00
|
|
|
blendFunc1.src = GL_ONE
|
|
|
|
blendFunc1.dst = GL_ONE_MINUS_SRC_ALPHA
|
|
|
|
cloud:setBlendFunc(blendFunc1)
|
|
|
|
|
|
|
|
-- CENTER sprites have also alpha pre-multiplied
|
|
|
|
-- they use by default GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
|
|
|
|
cloud = CCSprite:create("Images/test_blend.png")
|
|
|
|
ret:addChild(cloud, i+1, 200+i)
|
2013-07-26 13:43:28 +08:00
|
|
|
cloud:setPosition(CCPoint(50+25*i, 160))
|
2013-07-05 16:49:22 +08:00
|
|
|
local blendFunc2 = BlendFunc()
|
2013-04-05 16:13:04 +08:00
|
|
|
blendFunc2.src = GL_ONE_MINUS_DST_COLOR
|
|
|
|
blendFunc2.dst = GL_ZERO
|
|
|
|
cloud:setBlendFunc(blendFunc2)
|
|
|
|
|
|
|
|
-- UPPER sprites are using custom blending function
|
|
|
|
-- You can set any blend function to your sprites
|
|
|
|
cloud = CCSprite:create("Images/test_blend.png")
|
|
|
|
ret:addChild(cloud, i+1, 200+i)
|
2013-07-26 13:43:28 +08:00
|
|
|
cloud:setPosition(CCPoint(50+25*i, 320-80))
|
2013-07-05 16:49:22 +08:00
|
|
|
local blendFunc3 = BlendFunc()
|
2013-04-05 16:13:04 +08:00
|
|
|
blendFunc3.src = GL_SRC_ALPHA
|
|
|
|
blendFunc3.dst = GL_ONE
|
|
|
|
cloud:setBlendFunc(blendFunc3) -- additive blending
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureAsync
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
|
|
|
|
local function TextureAsync()
|
|
|
|
local ret = createTestLayer("Texture Async Load",
|
|
|
|
"Textures should load while an animation is being run")
|
|
|
|
local m_nImageOffset = 0
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local size =CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local label = CCLabelTTF:create("Loading...", "Marker Felt", 32)
|
2013-07-26 13:43:28 +08:00
|
|
|
label:setPosition(CCPoint( size.width/2, size.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(label, 10)
|
|
|
|
|
|
|
|
local scale = CCScaleBy:create(0.3, 2)
|
|
|
|
local scale_back = tolua.cast(scale:reverse(), "CCScaleBy")
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale)
|
|
|
|
arr:addObject(scale_back)
|
|
|
|
local seq = CCSequence:create(arr)
|
|
|
|
label:runAction(CCRepeatForever:create(seq))
|
|
|
|
|
|
|
|
local function imageLoaded(pObj)
|
|
|
|
local tex = tolua.cast(pObj, "CCTexture2D")
|
2013-07-26 13:43:28 +08:00
|
|
|
local director = CCDirector:getInstance()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
--CCASSERT( [NSThread currentThread] == [director runningThread], @"FAIL. Callback should be on cocos2d thread")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- IMPORTANT: The order on the callback is not guaranteed. Don't depend on the callback
|
|
|
|
|
|
|
|
-- This test just creates a sprite based on the Texture
|
|
|
|
|
|
|
|
local sprite = CCSprite:createWithTexture(tex)
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setAnchorPoint(CCPoint(0,0))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite, -1)
|
|
|
|
|
|
|
|
local size = director:getWinSize()
|
|
|
|
local i = m_nImageOffset * 32
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint( i % size.width, (i / size.width) * 32 ))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
m_nImageOffset = m_nImageOffset + 1
|
|
|
|
cclog("Image loaded:...")-- %p", tex)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function loadImages(dt)
|
|
|
|
local i = 0
|
|
|
|
local j = 0
|
|
|
|
for i=0, 7 do
|
|
|
|
for j=0, 7 do
|
|
|
|
local szSpriteName = string.format(
|
|
|
|
"Images/sprites_test/sprite-%d-%d.png", i, j)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():addImageAsync(
|
2013-04-05 16:13:04 +08:00
|
|
|
szSpriteName, imageLoaded)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():addImageAsync("Images/background1.jpg", imageLoaded)
|
|
|
|
CCTextureCache:getInstance():addImageAsync("Images/background2.jpg", imageLoaded)
|
|
|
|
CCTextureCache:getInstance():addImageAsync("Images/background.png", imageLoaded)
|
|
|
|
CCTextureCache:getInstance():addImageAsync("Images/atlastest.png", imageLoaded)
|
|
|
|
CCTextureCache:getInstance():addImageAsync("Images/grossini_dance_atlas.png",imageLoaded)
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local schedulerEntry = nil
|
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "enter" then
|
|
|
|
schedulerEntry = scheduler:scheduleScriptFunc(loadImages, 1.0, false)
|
|
|
|
elseif event == "exit" then
|
|
|
|
scheduler:unscheduleScriptEntry(schedulerEntry)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeAllTextures()
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureGlClamp
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureGlClamp()
|
|
|
|
local ret = createTestLayer("Texture GL_CLAMP")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local size = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- The .png image MUST be power of 2 in order to create a continue effect.
|
|
|
|
-- eg: 32x64, 512x128, 256x1024, 64x64, etc..
|
2013-07-26 13:43:28 +08:00
|
|
|
local sprite = CCSprite:create("Images/pattern1.png", CCRect(0,0,512,256))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite, -1, kTagSprite1)
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(size.width/2,size.height/2))
|
2013-08-06 11:34:48 +08:00
|
|
|
local texParams = CCTexture:TexParams()
|
2013-04-05 16:13:04 +08:00
|
|
|
texParams.minFilter = GL_LINEAR
|
|
|
|
texParams.magFilter = GL_LINEAR
|
|
|
|
texParams.wrapS = GL_CLAMP_TO_EDGE
|
|
|
|
texParams.wrapT = GL_CLAMP_TO_EDGE
|
|
|
|
|
|
|
|
sprite:getTexture():setTexParameters(texParams)
|
|
|
|
|
|
|
|
local rotate = CCRotateBy:create(4, 360)
|
|
|
|
sprite:runAction(rotate)
|
|
|
|
local scale = CCScaleBy:create(2, 0.04)
|
|
|
|
local scaleBack = tolua.cast(scale:reverse(), "CCScaleBy")
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale)
|
|
|
|
arr:addObject(scaleBack)
|
|
|
|
local seq = CCSequence:create(arr)
|
|
|
|
sprite:runAction(seq)
|
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeUnusedTextures()
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureGlRepeat
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureGlRepeat()
|
|
|
|
local ret = createTestLayer("Texture GL_REPEAT")
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local size = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
-- The .png image MUST be power of 2 in order to create a continue effect.
|
|
|
|
-- eg: 32x64, 512x128, 256x1024, 64x64, etc..
|
2013-07-26 13:43:28 +08:00
|
|
|
local sprite = CCSprite:create("Images/pattern1.png", CCRect(0, 0, 4096, 4096))
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(sprite, -1, kTagSprite1)
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(size.width/2,size.height/2))
|
2013-08-06 11:34:48 +08:00
|
|
|
local texParams = CCTexture:TexParams()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
texParams.minFilter = GL_LINEAR
|
|
|
|
texParams.magFilter = GL_LINEAR
|
|
|
|
texParams.wrapS = GL_REPEAT
|
|
|
|
texParams.wrapT = GL_REPEAT
|
|
|
|
|
|
|
|
sprite:getTexture():setTexParameters(texParams)
|
|
|
|
|
|
|
|
local rotate = CCRotateBy:create(4, 360)
|
|
|
|
sprite:runAction(rotate)
|
|
|
|
local scale = CCScaleBy:create(2, 0.04)
|
|
|
|
local scaleBack = tolua.cast(scale:reverse(), "CCScaleBy")
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(scale)
|
|
|
|
arr:addObject(scaleBack)
|
|
|
|
local seq = CCSequence:create(arr)
|
|
|
|
sprite:runAction(seq)
|
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeUnusedTextures()
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureSizeTest
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureSizeTest()
|
|
|
|
local ret = createTestLayer("Different Texture Sizes",
|
|
|
|
"512x512, 1024x1024. See the console.")
|
|
|
|
local sprite = nil
|
|
|
|
|
|
|
|
cclog("Loading 512x512 image...")
|
|
|
|
sprite = CCSprite:create("Images/texture512x512.png")
|
|
|
|
if sprite ~= nil then
|
|
|
|
cclog("OK\n")
|
|
|
|
else
|
|
|
|
cclog("Error\n")
|
|
|
|
|
|
|
|
cclog("Loading 1024x1024 image...")
|
|
|
|
sprite = CCSprite:create("Images/texture1024x1024.png")
|
|
|
|
if sprite ~= nil then
|
|
|
|
cclog("OK\n")
|
|
|
|
else
|
|
|
|
cclog("Error\n")
|
|
|
|
-- @todo
|
|
|
|
-- cclog("Loading 2048x2048 image...")
|
|
|
|
-- sprite = CCSprite:create("Images/texture2048x2048.png")
|
|
|
|
-- if( sprite )
|
|
|
|
-- cclog("OK\n")
|
|
|
|
-- else
|
|
|
|
-- cclog("Error\n")
|
|
|
|
--
|
|
|
|
-- cclog("Loading 4096x4096 image...")
|
|
|
|
-- sprite = CCSprite:create("Images/texture4096x4096.png")
|
|
|
|
-- if( sprite )
|
|
|
|
-- cclog("OK\n")
|
|
|
|
-- else
|
|
|
|
-- cclog("Error\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- TextureCache1
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureCache1()
|
|
|
|
local ret = createTestLayer("CCTextureCache: remove",
|
|
|
|
"4 images should appear: alias, antialias, alias, antilias")
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local sprite = nil
|
|
|
|
|
|
|
|
sprite = CCSprite:create("Images/grossinis_sister1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(s.width/5*1, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
sprite:getTexture():setAliasTexParameters()
|
|
|
|
sprite:setScale(2)
|
|
|
|
ret:addChild(sprite)
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTexture(sprite:getTexture())
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
sprite = CCSprite:create("Images/grossinis_sister1.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(s.width/5*2, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
sprite:getTexture():setAntiAliasTexParameters()
|
|
|
|
sprite:setScale(2)
|
|
|
|
ret:addChild(sprite)
|
|
|
|
|
|
|
|
-- 2nd set of sprites
|
|
|
|
|
|
|
|
sprite = CCSprite:create("Images/grossinis_sister2.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(s.width/5*3, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
sprite:getTexture():setAliasTexParameters()
|
|
|
|
sprite:setScale(2)
|
|
|
|
ret:addChild(sprite)
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTextureForKey("Images/grossinis_sister2.png")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
sprite = CCSprite:create("Images/grossinis_sister2.png")
|
2013-07-26 13:43:28 +08:00
|
|
|
sprite:setPosition(CCPoint(s.width/5*4, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
sprite:getTexture():setAntiAliasTexParameters()
|
|
|
|
sprite:setScale(2)
|
|
|
|
ret:addChild(sprite)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TextureDrawAtPoint
|
|
|
|
local function TextureDrawAtPoint()
|
|
|
|
local m_pTex1 = nil
|
2013-07-05 16:49:22 +08:00
|
|
|
local m_pTex2F = nil
|
2013-04-05 16:13:04 +08:00
|
|
|
local ret = createTestLayer("CCTexture2D: drawAtPoint",
|
|
|
|
"draws 2 textures using drawAtPoint")
|
|
|
|
|
|
|
|
local function draw()
|
|
|
|
-- TextureDemo:draw()
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
m_pTex1:drawAtPoint(CCPoint(s.width/2-50, s.height/2 - 50))
|
|
|
|
m_pTex2F:drawAtPoint(CCPoint(s.width/2+50, s.height/2 - 50))
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
m_pTex1 = CCTextureCache:getInstance():addImage("Images/grossinis_sister1.png")
|
|
|
|
m_pTex2F = CCTextureCache:getInstance():addImage("Images/grossinis_sister2.png")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
m_pTex1:retain()
|
2013-07-05 16:49:22 +08:00
|
|
|
m_pTex2F:retain()
|
2013-04-05 16:13:04 +08:00
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
|
|
|
m_pTex1:release()
|
2013-07-05 16:49:22 +08:00
|
|
|
m_pTex2F:release()
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TextureDrawInRect
|
|
|
|
|
|
|
|
local function TextureDrawInRect()
|
|
|
|
local ret = createTestLayer("CCTexture2D: drawInRect",
|
|
|
|
"draws 2 textures using drawInRect")
|
|
|
|
local function draw()
|
|
|
|
-- TextureDemo:draw()
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local rect1 = CCRect( s.width/2 - 80, 20, m_pTex1:getContentSize().width * 0.5, m_pTex1:getContentSize().height *2 )
|
|
|
|
local rect2 = CCRect( s.width/2 + 80, s.height/2, m_pTex1:getContentSize().width * 2, m_pTex1:getContentSize().height * 0.5 )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
m_pTex1:drawInRect(rect1)
|
2013-07-05 16:49:22 +08:00
|
|
|
m_pTex2F:drawInRect(rect2)
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local m_pTex1 = CCTextureCache:getInstance():addImage("Images/grossinis_sister1.png")
|
|
|
|
local m_pTex2F = CCTextureCache:getInstance():addImage("Images/grossinis_sister2.png")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
m_pTex1:retain()
|
2013-07-05 16:49:22 +08:00
|
|
|
m_pTex2F:retain()
|
2013-04-05 16:13:04 +08:00
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
|
|
|
m_pTex1:release()
|
2013-07-05 16:49:22 +08:00
|
|
|
m_pTex2F:release()
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------
|
|
|
|
-- --
|
|
|
|
-- TextureMemoryAlloc
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function TextureMemoryAlloc()
|
|
|
|
local ret = createTestLayer("Texture memory",
|
|
|
|
"Testing Texture Memory allocation. Use Instruments + VM Tracker")
|
|
|
|
local m_pBackground = nil
|
|
|
|
|
|
|
|
CCMenuItemFont:setFontSize(24)
|
|
|
|
|
|
|
|
local function updateImage(tag,sender)
|
|
|
|
if m_pBackground ~= nil then
|
|
|
|
cclog("updateImage"..tag)
|
|
|
|
m_pBackground:removeFromParentAndCleanup(true)
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeUnusedTextures()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
local file = ""
|
|
|
|
if tag == 0 then
|
|
|
|
file = "Images/test_1021x1024.png"
|
|
|
|
elseif tag == 1 then
|
|
|
|
file = "Images/test_1021x1024_rgba8888.pvr"
|
|
|
|
elseif tag == 2 then
|
|
|
|
file = "Images/test_1021x1024_rgb888.pvr"
|
|
|
|
elseif tag == 3 then
|
|
|
|
file = "Images/test_1021x1024_rgba4444.pvr"
|
|
|
|
elseif tag == 4 then
|
|
|
|
file = "Images/test_1021x1024_a8.pvr"
|
|
|
|
end
|
|
|
|
|
|
|
|
m_pBackground = CCSprite:create(file)
|
|
|
|
ret:addChild(m_pBackground, -10)
|
|
|
|
|
|
|
|
m_pBackground:setVisible(false)
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
|
|
|
m_pBackground:setPosition(CCPoint(s.width/2, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local item1 = CCMenuItemFont:create("PNG")
|
|
|
|
item1:registerScriptTapHandler(updateImage)
|
|
|
|
item1:setTag(0)
|
|
|
|
|
|
|
|
local item2 = CCMenuItemFont:create("RGBA8")
|
|
|
|
item2:registerScriptTapHandler(updateImage)
|
|
|
|
item2:setTag(1)
|
|
|
|
|
|
|
|
local item3 = CCMenuItemFont:create("RGB8")
|
|
|
|
item3:registerScriptTapHandler(updateImage)
|
|
|
|
item3:setTag(2)
|
|
|
|
|
|
|
|
local item4 = CCMenuItemFont:create("RGBA4")
|
|
|
|
item4:registerScriptTapHandler(updateImage)
|
|
|
|
item4:setTag(3)
|
|
|
|
|
|
|
|
local item5 = CCMenuItemFont:create("A8")
|
|
|
|
item5:registerScriptTapHandler(updateImage)
|
|
|
|
item5:setTag(4)
|
|
|
|
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(item1)
|
|
|
|
arr:addObject(item2)
|
|
|
|
arr:addObject(item3)
|
|
|
|
arr:addObject(item4)
|
|
|
|
arr:addObject(item5)
|
|
|
|
local menu = CCMenu:createWithArray(arr)
|
|
|
|
menu:alignItemsHorizontally()
|
|
|
|
|
|
|
|
ret:addChild(menu)
|
|
|
|
|
|
|
|
local warmup = CCMenuItemFont:create("warm up texture")
|
|
|
|
|
|
|
|
local function changeBackgroundVisible(tag, sender)
|
|
|
|
if m_pBackground ~= nil then
|
|
|
|
cclog("changeBackgroundVisible")
|
|
|
|
m_pBackground:setVisible(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
warmup:registerScriptTapHandler(changeBackgroundVisible)
|
|
|
|
local menu2 = CCMenu:createWithItem(warmup)
|
|
|
|
|
|
|
|
menu2:alignItemsHorizontally()
|
|
|
|
|
|
|
|
ret:addChild(menu2)
|
2013-07-26 13:43:28 +08:00
|
|
|
local s = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
menu2:setPosition(CCPoint(s.width/2, s.height/4))
|
2013-04-05 16:13:04 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TexturePVRv3Premult
|
|
|
|
local function TexturePVRv3Premult()
|
|
|
|
local ret = createTestLayer("PVRv3 Premult Flag",
|
|
|
|
"All images should look exactly the same")
|
|
|
|
|
|
|
|
local function transformSprite(sprite)
|
|
|
|
local fade = CCFadeOut:create(2)
|
|
|
|
local dl = CCDelayTime:create(2)
|
|
|
|
local fadein = tolua.cast(fade:reverse(), "CCFadeOut")
|
|
|
|
local arr = CCArray:create()
|
|
|
|
arr:addObject(fade)
|
|
|
|
arr:addObject(fadein)
|
|
|
|
arr:addObject(dl)
|
|
|
|
local seq = CCSequence:create(arr)
|
|
|
|
local repeatAction = CCRepeatForever:create(seq)
|
|
|
|
sprite:runAction(repeatAction)
|
|
|
|
end
|
|
|
|
|
2013-07-26 13:43:28 +08:00
|
|
|
local size = CCDirector:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
local background = CCLayerColor:create(Color4B(128,128,128,255), size.width, size.height)
|
2013-04-05 16:13:04 +08:00
|
|
|
ret:addChild(background, -1)
|
|
|
|
|
|
|
|
|
|
|
|
-- PVR premultiplied
|
|
|
|
local pvr1 = CCSprite:create("Images/grossinis_sister1-testalpha_premult.pvr")
|
|
|
|
ret:addChild(pvr1, 0)
|
2013-07-26 13:43:28 +08:00
|
|
|
pvr1:setPosition(CCPoint(size.width/4*1, size.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
transformSprite(pvr1)
|
|
|
|
|
|
|
|
-- PVR non-premultiplied
|
|
|
|
local pvr2 = CCSprite:create("Images/grossinis_sister1-testalpha_nopremult.pvr")
|
|
|
|
ret:addChild(pvr2, 0)
|
2013-07-26 13:43:28 +08:00
|
|
|
pvr2:setPosition(CCPoint(size.width/4*2, size.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
transformSprite(pvr2)
|
|
|
|
|
|
|
|
-- PNG
|
|
|
|
CCTexture2D:setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888)
|
2013-07-26 13:43:28 +08:00
|
|
|
CCTextureCache:getInstance():removeTextureForKey("Images/grossinis_sister1-testalpha.png")
|
2013-04-05 16:13:04 +08:00
|
|
|
local png = CCSprite:create("Images/grossinis_sister1-testalpha.png")
|
|
|
|
ret:addChild(png, 0)
|
2013-07-26 13:43:28 +08:00
|
|
|
png:setPosition(CCPoint(size.width/4*3, size.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
transformSprite(png)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Texture2dTestMain()
|
|
|
|
cclog("Texture2dTestMain")
|
|
|
|
Helper.index = 1
|
|
|
|
local scene = CCScene:create()
|
|
|
|
Helper.createFunctionTable = {
|
|
|
|
TextureMemoryAlloc,
|
|
|
|
TextureAlias,
|
|
|
|
TexturePVRMipMap,
|
|
|
|
TexturePVRMipMap2,
|
|
|
|
TexturePVRNonSquare,
|
|
|
|
TexturePVRNPOT4444,
|
|
|
|
TexturePVRNPOT8888,
|
|
|
|
TexturePVR,
|
|
|
|
TexturePVR2BPP,
|
|
|
|
TexturePVR2BPPv3,
|
|
|
|
TexturePVR4BPP,
|
|
|
|
TexturePVR4BPPv3,
|
|
|
|
TexturePVRII4BPPv3,
|
|
|
|
TexturePVRRGBA8888,
|
|
|
|
TexturePVRRGBA8888v3,
|
|
|
|
TexturePVRBGRA8888,
|
|
|
|
TexturePVRBGRA8888v3,
|
|
|
|
TexturePVRRGBA4444,
|
|
|
|
TexturePVRRGBA4444v3,
|
|
|
|
TexturePVRRGBA4444GZ,
|
|
|
|
TexturePVRRGBA4444CCZ,
|
|
|
|
TexturePVRRGBA5551,
|
|
|
|
TexturePVRRGBA5551v3,
|
|
|
|
TexturePVRRGB565,
|
|
|
|
TexturePVRRGB565v3,
|
|
|
|
TexturePVRRGB888,
|
|
|
|
TexturePVRRGB888v3,
|
|
|
|
TexturePVRA8,
|
|
|
|
TexturePVRA8v3,
|
|
|
|
TexturePVRI8,
|
|
|
|
TexturePVRI8v3,
|
|
|
|
TexturePVRAI88,
|
|
|
|
TexturePVRAI88v3,
|
|
|
|
TexturePVRv3Premult,
|
|
|
|
TexturePVRBadEncoding,
|
|
|
|
TexturePNG,
|
|
|
|
TextureJPEG,
|
|
|
|
TextureTIFF,
|
|
|
|
TextureWEBP,
|
|
|
|
TextureMipMap,
|
|
|
|
TexturePixelFormat,
|
|
|
|
TextureBlend,
|
|
|
|
TextureAsync,
|
|
|
|
TextureGlClamp,
|
|
|
|
TextureGlRepeat,
|
|
|
|
TextureSizeTest,
|
|
|
|
TextureCache1,
|
|
|
|
TextureDrawAtPoint,
|
|
|
|
TextureDrawInRect
|
|
|
|
}
|
|
|
|
scene:addChild(TextureMemoryAlloc())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
return scene
|
|
|
|
end
|