1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ETCTextureTest:
7 //   Tests for ETC lossy decode formats.
8 //
9 
10 #include "test_utils/ANGLETest.h"
11 
12 using namespace angle;
13 
14 namespace
15 {
16 
17 class ETCTextureTest : public ANGLETest
18 {
19   protected:
ETCTextureTest()20     ETCTextureTest() : mTexture(0u)
21     {
22         setWindowWidth(128);
23         setWindowHeight(128);
24         setConfigRedBits(8);
25         setConfigGreenBits(8);
26         setConfigBlueBits(8);
27         setConfigAlphaBits(8);
28     }
29 
SetUp()30     void SetUp() override
31     {
32         ANGLETest::SetUp();
33 
34         glGenTextures(1, &mTexture);
35         ASSERT_GL_NO_ERROR();
36     }
37 
TearDown()38     void TearDown() override
39     {
40         glDeleteTextures(1, &mTexture);
41 
42         ANGLETest::TearDown();
43     }
44 
45     GLuint mTexture;
46 };
47 
48 // Tests a texture with ETC1 lossy decode format
TEST_P(ETCTextureTest,ETC1Validation)49 TEST_P(ETCTextureTest, ETC1Validation)
50 {
51     bool supported = extensionEnabled("GL_ANGLE_lossy_etc_decode");
52 
53     glBindTexture(GL_TEXTURE_2D, mTexture);
54 
55     GLubyte pixel[8] = { 0x0, 0x0, 0xf8, 0x2, 0x43, 0xff, 0x4, 0x12 };
56     glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 0,
57                            sizeof(pixel), pixel);
58     if (supported)
59     {
60         EXPECT_GL_NO_ERROR();
61 
62         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE,
63                                   sizeof(pixel), pixel);
64         EXPECT_GL_NO_ERROR();
65 
66 
67         glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 2, 2, 0,
68             sizeof(pixel), pixel);
69         glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 1, 1, 0,
70             sizeof(pixel), pixel);
71     }
72     else
73     {
74         EXPECT_GL_ERROR(GL_INVALID_ENUM);
75     }
76 }
77 
78 ANGLE_INSTANTIATE_TEST(ETCTextureTest,
79                        ES2_D3D9(),
80                        ES2_D3D11(),
81                        ES2_D3D11_FL9_3(),
82                        ES3_D3D11(),
83                        ES2_OPENGL(),
84                        ES3_OPENGL());
85 }  // anonymous namespace
86