blob: 7fb193c851bbc532df6a2be3958000e849fcfdc9 [file] [log] [blame]
Geoff Lang066230a2013-10-30 12:59:30 -04001#include "ANGLETest.h"
2#include "media/stanfordbunny.inl"
3#include "media/stanforddragon.inl"
4
5class CompressedTextureTest : public ANGLETest
6{
7protected:
8 CompressedTextureTest()
9 {
10 setWindowWidth(512);
11 setWindowHeight(512);
12 setConfigRedBits(8);
13 setConfigGreenBits(8);
14 setConfigBlueBits(8);
15 setConfigAlphaBits(8);
16 }
17
18 virtual void SetUp()
19 {
20 ANGLETest::SetUp();
21
22 const std::string vsSource = SHADER_SOURCE
23 (
24 precision highp float;
25 attribute vec4 position;
26 varying vec2 texcoord;
27
28 void main()
29 {
30 gl_Position = position;
31 texcoord = (position.xy * 0.5) + 0.5;
32 texcoord.y = 1.0 - texcoord.y;
33 }
34 );
35
36 const std::string textureFSSource = SHADER_SOURCE
37 (
38 precision highp float;
39 uniform sampler2D tex;
40 varying vec2 texcoord;
41
42 void main()
43 {
44 gl_FragColor = texture2D(tex, texcoord);
45 }
46 );
47
48 mTextureProgram = compileProgram(vsSource, textureFSSource);
49 if (mTextureProgram == 0)
50 {
51 FAIL() << "shader compilation failed.";
52 }
53
54 mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex");
55
56 ASSERT_GL_NO_ERROR();
57 }
58
59 virtual void TearDown()
60 {
61 glDeleteProgram(mTextureProgram);
62
63 ANGLETest::TearDown();
64 }
65
66 GLuint mTextureProgram;
67 GLint mTextureUniformLocation;
68};
69
70TEST_F(CompressedTextureTest, compressed_tex_image)
71{
72 if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_texture_compression_dxt1"))
73 {
74 return;
75 }
76
77 GLuint texture;
78 glGenTextures(1, &texture);
79 glBindTexture(GL_TEXTURE_2D, texture);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
82 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
83 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
84
85 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 0, 1U), std::max(stanfordbunnyHeight >> 0, 1U), 0, sizeof(stanfordbunny_0), stanfordbunny_0);
86 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 1, 1U), std::max(stanfordbunnyHeight >> 1, 1U), 0, sizeof(stanfordbunny_1), stanfordbunny_1);
87 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 2, 1U), std::max(stanfordbunnyHeight >> 2, 1U), 0, sizeof(stanfordbunny_2), stanfordbunny_2);
88 glCompressedTexImage2D(GL_TEXTURE_2D, 3, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 3, 1U), std::max(stanfordbunnyHeight >> 3, 1U), 0, sizeof(stanfordbunny_3), stanfordbunny_3);
89 glCompressedTexImage2D(GL_TEXTURE_2D, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 4, 1U), std::max(stanfordbunnyHeight >> 4, 1U), 0, sizeof(stanfordbunny_4), stanfordbunny_4);
90 glCompressedTexImage2D(GL_TEXTURE_2D, 5, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 5, 1U), std::max(stanfordbunnyHeight >> 5, 1U), 0, sizeof(stanfordbunny_5), stanfordbunny_5);
91 glCompressedTexImage2D(GL_TEXTURE_2D, 6, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 6, 1U), std::max(stanfordbunnyHeight >> 6, 1U), 0, sizeof(stanfordbunny_6), stanfordbunny_6);
92 glCompressedTexImage2D(GL_TEXTURE_2D, 7, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 7, 1U), std::max(stanfordbunnyHeight >> 7, 1U), 0, sizeof(stanfordbunny_7), stanfordbunny_7);
93 glCompressedTexImage2D(GL_TEXTURE_2D, 8, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 8, 1U), std::max(stanfordbunnyHeight >> 8, 1U), 0, sizeof(stanfordbunny_8), stanfordbunny_8);
94 glCompressedTexImage2D(GL_TEXTURE_2D, 9, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, std::max(stanfordbunnyWidth >> 9, 1U), std::max(stanfordbunnyHeight >> 9, 1U), 0, sizeof(stanfordbunny_9), stanfordbunny_9);
95
96 EXPECT_GL_NO_ERROR();
97
98 glUseProgram(mTextureProgram);
99 glUniform1i(mTextureUniformLocation, 0);
100
101 drawQuad(mTextureProgram, "position", 0.5f);
102
103 EXPECT_GL_NO_ERROR();
104
105 glDeleteTextures(1, &texture);
106
107 EXPECT_GL_NO_ERROR();
108}
109
110TEST_F(CompressedTextureTest, compressed_tex_storage)
111{
112 if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_texture_compression_dxt1"))
113 {
114 return;
115 }
116
117 if (getClientVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8")))
118 {
119 return;
120 }
121
122 GLuint texture;
123 glGenTextures(1, &texture);
124 glBindTexture(GL_TEXTURE_2D, texture);
125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
129
130 if (getClientVersion() < 3)
131 {
132 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, stanforddragonWidth, stanforddragonHeight);
133 }
134 else
135 {
136 glTexStorage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, stanforddragonWidth, stanforddragonHeight);
137 }
138 EXPECT_GL_NO_ERROR();
139
140 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, stanforddragonWidth, stanforddragonHeight, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, sizeof(stanforddragon), stanforddragon);
141
142 EXPECT_GL_NO_ERROR();
143
144 glUseProgram(mTextureProgram);
145 glUniform1i(mTextureUniformLocation, 0);
146
147 drawQuad(mTextureProgram, "position", 0.5f);
148
149 EXPECT_GL_NO_ERROR();
150
151 glDeleteTextures(1, &texture);
152
153 EXPECT_GL_NO_ERROR();
154}