Path: blob/main_old/src/tests/gl_tests/ETCTextureTest.cpp
1693 views
//1// Copyright 2015 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ETCTextureTest:6// Tests for ETC lossy decode formats.7//89#include "test_utils/ANGLETest.h"1011using namespace angle;1213namespace14{1516class ETCTextureTest : public ANGLETest17{18protected:19ETCTextureTest() : mTexture(0u)20{21setWindowWidth(128);22setWindowHeight(128);23setConfigRedBits(8);24setConfigGreenBits(8);25setConfigBlueBits(8);26setConfigAlphaBits(8);27}2829void testSetUp() override30{31glGenTextures(1, &mTexture);32ASSERT_GL_NO_ERROR();33}3435void testTearDown() override { glDeleteTextures(1, &mTexture); }3637GLuint mTexture;38};3940// Tests a texture with ETC1 lossy decode format41TEST_P(ETCTextureTest, ETC1Validation)42{43bool supported = IsGLExtensionEnabled("GL_ANGLE_lossy_etc_decode");4445glBindTexture(GL_TEXTURE_2D, mTexture);4647GLubyte pixel[8] = {0x0, 0x0, 0xf8, 0x2, 0x43, 0xff, 0x4, 0x12};48glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 0,49sizeof(pixel), pixel);50if (supported)51{52EXPECT_GL_NO_ERROR();5354glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE,55sizeof(pixel), pixel);56EXPECT_GL_NO_ERROR();5758glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 2, 2, 0,59sizeof(pixel), pixel);60EXPECT_GL_NO_ERROR();6162glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 1, 1, 0,63sizeof(pixel), pixel);64EXPECT_GL_NO_ERROR();65}66else67{68EXPECT_GL_ERROR(GL_INVALID_ENUM);69}70}7172// Tests a texture with ETC2 RGB8 lossy decode format73TEST_P(ETCTextureTest, ETC2RGB8Validation)74{75bool supported = IsGLExtensionEnabled("GL_ANGLE_lossy_etc_decode");7677glBindTexture(GL_TEXTURE_2D, mTexture);7879GLubyte pixel[] = {800x00, 0x00, 0xf8, 0x02, 0x43, 0xff, 0x04, 0x12, // Individual/differential block810x1c, 0x65, 0xc6, 0x62, 0xff, 0xf0, 0xff, 0x00, // T block820x62, 0xf2, 0xe3, 0x32, 0xff, 0x0f, 0xff, 0x00, // H block830x71, 0x88, 0xfb, 0xee, 0x87, 0x07, 0x11, 0x1f // Planar block84};85glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 8, 8, 0,86sizeof(pixel), pixel);87if (supported)88{89EXPECT_GL_NO_ERROR();9091glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8,92GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, sizeof(pixel), pixel);93EXPECT_GL_NO_ERROR();9495const GLsizei imageSize = 8;9697glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4,980, imageSize, pixel);99EXPECT_GL_NO_ERROR();100101glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 2, 2,1020, imageSize, pixel);103EXPECT_GL_NO_ERROR();104105glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 1, 1,1060, imageSize, pixel);107EXPECT_GL_NO_ERROR();108}109else110{111EXPECT_GL_ERROR(GL_INVALID_ENUM);112}113}114115// Tests a texture with ETC2 SRGB8 lossy decode format116TEST_P(ETCTextureTest, ETC2SRGB8Validation)117{118bool supported = IsGLExtensionEnabled("GL_ANGLE_lossy_etc_decode");119120glBindTexture(GL_TEXTURE_2D, mTexture);121122GLubyte pixel[] = {1230x00, 0x00, 0xf8, 0x02, 0x43, 0xff, 0x04, 0x12, // Individual/differential block1240x1c, 0x65, 0xc6, 0x62, 0xff, 0xf0, 0xff, 0x00, // T block1250x62, 0xf2, 0xe3, 0x32, 0xff, 0x0f, 0xff, 0x00, // H block1260x71, 0x88, 0xfb, 0xee, 0x87, 0x07, 0x11, 0x1f // Planar block127};128glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 8, 8, 0,129sizeof(pixel), pixel);130if (supported)131{132EXPECT_GL_NO_ERROR();133134glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8,135GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, sizeof(pixel),136pixel);137EXPECT_GL_NO_ERROR();138139const GLsizei imageSize = 8;140141glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4,1420, imageSize, pixel);143EXPECT_GL_NO_ERROR();144145glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 2, 2,1460, imageSize, pixel);147EXPECT_GL_NO_ERROR();148149glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 1, 1,1500, imageSize, pixel);151EXPECT_GL_NO_ERROR();152}153else154{155EXPECT_GL_ERROR(GL_INVALID_ENUM);156}157}158159// Tests a texture with ETC2 RGB8 punchthrough A1 lossy decode format160TEST_P(ETCTextureTest, ETC2RGB8A1Validation)161{162bool supported = IsGLExtensionEnabled("GL_ANGLE_lossy_etc_decode");163164glBindTexture(GL_TEXTURE_2D, mTexture);165166GLubyte pixel[] = {1670x80, 0x98, 0x59, 0x02, 0x6e, 0xe7, 0x44, 0x47, // Individual/differential block1680xeb, 0x85, 0x68, 0x30, 0x77, 0x73, 0x44, 0x44, // T block1690xb4, 0x05, 0xab, 0x92, 0xf8, 0x8c, 0x07, 0x73, // H block1700xbb, 0x90, 0x15, 0xba, 0x8a, 0x8c, 0xd5, 0x5f // Planar block171};172glCompressedTexImage2D(GL_TEXTURE_2D, 0,173GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 8, 8, 0,174sizeof(pixel), pixel);175if (supported)176{177EXPECT_GL_NO_ERROR();178179glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8,180GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE,181sizeof(pixel), pixel);182EXPECT_GL_NO_ERROR();183184const GLsizei imageSize = 8;185186glCompressedTexImage2D(GL_TEXTURE_2D, 1,187GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4,1880, imageSize, pixel);189EXPECT_GL_NO_ERROR();190191glCompressedTexImage2D(GL_TEXTURE_2D, 2,192GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 2, 2,1930, imageSize, pixel);194EXPECT_GL_NO_ERROR();195196glCompressedTexImage2D(GL_TEXTURE_2D, 3,197GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 1, 1,1980, imageSize, pixel);199EXPECT_GL_NO_ERROR();200}201else202{203EXPECT_GL_ERROR(GL_INVALID_ENUM);204}205}206207// Tests a texture with ETC2 SRGB8 punchthrough A1 lossy decode format208TEST_P(ETCTextureTest, ETC2SRGB8A1Validation)209{210bool supported = IsGLExtensionEnabled("GL_ANGLE_lossy_etc_decode");211212glBindTexture(GL_TEXTURE_2D, mTexture);213214GLubyte pixel[] = {2150x80, 0x98, 0x59, 0x02, 0x6e, 0xe7, 0x44, 0x47, // Individual/differential block2160xeb, 0x85, 0x68, 0x30, 0x77, 0x73, 0x44, 0x44, // T block2170xb4, 0x05, 0xab, 0x92, 0xf8, 0x8c, 0x07, 0x73, // H block2180xbb, 0x90, 0x15, 0xba, 0x8a, 0x8c, 0xd5, 0x5f // Planar block219};220glCompressedTexImage2D(GL_TEXTURE_2D, 0,221GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 8, 8, 0,222sizeof(pixel), pixel);223if (supported)224{225EXPECT_GL_NO_ERROR();226227glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8,228GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE,229sizeof(pixel), pixel);230EXPECT_GL_NO_ERROR();231232const GLsizei imageSize = 8;233234glCompressedTexImage2D(GL_TEXTURE_2D, 1,235GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4,2364, 0, imageSize, pixel);237EXPECT_GL_NO_ERROR();238239glCompressedTexImage2D(GL_TEXTURE_2D, 2,240GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 2,2412, 0, imageSize, pixel);242EXPECT_GL_NO_ERROR();243244glCompressedTexImage2D(GL_TEXTURE_2D, 3,245GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 1,2461, 0, imageSize, pixel);247EXPECT_GL_NO_ERROR();248}249else250{251EXPECT_GL_ERROR(GL_INVALID_ENUM);252}253}254255ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ETCTextureTest);256} // anonymous namespace257258259