Skip to content

Commit a342866

Browse files
committed
Test for WebP with & without alpha
1 parent b30553e commit a342866

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Texture2DTests::Texture2DTests()
8181
ADD_TEST_CASE(TextureTGA);
8282
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
8383
ADD_TEST_CASE(TextureWEBP);
84+
ADD_TEST_CASE(TextureWEBPNoAlpha)
8485
#endif
8586
ADD_TEST_CASE(TexturePixelFormat);
8687
ADD_TEST_CASE(TextureBlend);
@@ -261,11 +262,36 @@ void TextureWEBP::onEnter()
261262
img->setPosition(Vec2( s.width/2.0f, s.height/2.0f));
262263
addChild(img);
263264
log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
265+
Texture2D* texture = Director::getInstance()->getTextureCache()->getTextureForKey("Images/test_image.webp");
266+
log("pixel format:%d, premultiplied alpha:%d\n", texture->getPixelFormat(), texture->hasPremultipliedAlpha());
264267
}
265268

266269
std::string TextureWEBP::title() const
267270
{
268-
return "WEBP Test";
271+
return "WEBP with alpha Test";
272+
}
273+
274+
//------------------------------------------------------------------
275+
//
276+
// TextureWEBPNoAlpha
277+
//
278+
//------------------------------------------------------------------
279+
void TextureWEBPNoAlpha::onEnter()
280+
{
281+
TextureDemo::onEnter();
282+
auto s = Director::getInstance()->getWinSize();
283+
284+
auto img = Sprite::create("Images/test_image_no_alpha.webp");
285+
img->setPosition(Vec2( s.width/2.0f, s.height/2.0f));
286+
addChild(img);
287+
log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
288+
Texture2D* texture = Director::getInstance()->getTextureCache()->getTextureForKey("Images/test_image_no_alpha.webp");
289+
log("pixel format:%d, premultiplied alpha:%d\n", texture->getPixelFormat(), texture->hasPremultipliedAlpha());
290+
}
291+
292+
std::string TextureWEBPNoAlpha::title() const
293+
{
294+
return "WEBP without alpha Test";
269295
}
270296

271297
//------------------------------------------------------------------

tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.h

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class TextureWEBP : public TextureDemo
7979
virtual void onEnter() override;
8080
};
8181

82+
class TextureWEBPNoAlpha : public TextureDemo
83+
{
84+
public:
85+
CREATE_FUNC(TextureWEBPNoAlpha);
86+
virtual std::string title() const override;
87+
virtual void onEnter() override;
88+
};
89+
8290
class TextureMipMap : public TextureDemo
8391
{
8492
public:
Binary file not shown.

0 commit comments

Comments
 (0)