blob: 8d16b367b9b5fcf42c8f0d028b4064897dc66be5 [file] [log] [blame]
Jamie Madillf67115c2014-04-22 13:14:05 -04001#include "ANGLETest.h"
2
3class TextureTest : public ANGLETest
4{
5protected:
6 TextureTest()
7 {
8 setWindowWidth(128);
9 setWindowHeight(128);
10 setConfigRedBits(8);
11 setConfigGreenBits(8);
12 setConfigBlueBits(8);
13 setConfigAlphaBits(8);
14 }
15
16 virtual void SetUp()
17 {
18 ANGLETest::SetUp();
Jamie Madilld4cfa572014-07-08 10:00:32 -040019 glGenTextures(1, &mTexture2D);
20 glGenTextures(1, &mTextureCube);
Jamie Madillf67115c2014-04-22 13:14:05 -040021
Jamie Madilld4cfa572014-07-08 10:00:32 -040022 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -040023 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
24 EXPECT_GL_NO_ERROR();
25
Jamie Madilld4cfa572014-07-08 10:00:32 -040026 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
27 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
28 EXPECT_GL_NO_ERROR();
29
Jamie Madillf67115c2014-04-22 13:14:05 -040030 ASSERT_GL_NO_ERROR();
Geoff Langc41e42d2014-04-28 10:58:16 -040031
32 const std::string vertexShaderSource = SHADER_SOURCE
33 (
34 precision highp float;
35 attribute vec4 position;
36 varying vec2 texcoord;
37
38 void main()
39 {
40 gl_Position = position;
41 texcoord = (position.xy * 0.5) + 0.5;
42 }
43 );
44
Jamie Madilld4cfa572014-07-08 10:00:32 -040045 const std::string fragmentShaderSource2D = SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040046 (
47 precision highp float;
48 uniform sampler2D tex;
49 varying vec2 texcoord;
50
51 void main()
52 {
53 gl_FragColor = texture2D(tex, texcoord);
54 }
55 );
56
Jamie Madilld4cfa572014-07-08 10:00:32 -040057 const std::string fragmentShaderSourceCube = SHADER_SOURCE
58 (
59 precision highp float;
60 uniform sampler2D tex2D;
61 uniform samplerCube texCube;
62 varying vec2 texcoord;
63
64 void main()
65 {
66 gl_FragColor = texture2D(tex2D, texcoord);
67 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
68 }
69 );
70
71 m2DProgram = compileProgram(vertexShaderSource, fragmentShaderSource2D);
72 mCubeProgram = compileProgram(vertexShaderSource, fragmentShaderSourceCube);
73 if (m2DProgram == 0 || mCubeProgram == 0)
Geoff Langc41e42d2014-04-28 10:58:16 -040074 {
75 FAIL() << "shader compilation failed.";
76 }
77
Jamie Madilld4cfa572014-07-08 10:00:32 -040078 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
Jamie Madillf67115c2014-04-22 13:14:05 -040079 }
80
81 virtual void TearDown()
82 {
Jamie Madilld4cfa572014-07-08 10:00:32 -040083 glDeleteTextures(1, &mTexture2D);
84 glDeleteTextures(1, &mTextureCube);
85 glDeleteProgram(m2DProgram);
86 glDeleteProgram(mCubeProgram);
Jamie Madillf67115c2014-04-22 13:14:05 -040087
88 ANGLETest::TearDown();
89 }
90
Jamie Madilld4cfa572014-07-08 10:00:32 -040091 GLuint mTexture2D;
92 GLuint mTextureCube;
Geoff Langc41e42d2014-04-28 10:58:16 -040093
Jamie Madilld4cfa572014-07-08 10:00:32 -040094 GLuint m2DProgram;
95 GLuint mCubeProgram;
96 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -040097};
98
Jamie Madillb759a742014-07-17 10:40:49 -040099TEST_F(TextureTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -0400100{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400101 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -0400102 EXPECT_GL_ERROR(GL_NO_ERROR);
103
104 const GLubyte *pixels[20] = { 0 };
105 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
106 EXPECT_GL_ERROR(GL_INVALID_VALUE);
107}
Geoff Langc41e42d2014-04-28 10:58:16 -0400108
Jamie Madillb759a742014-07-17 10:40:49 -0400109TEST_F(TextureTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -0400110{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400111 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -0400112 EXPECT_GL_ERROR(GL_NO_ERROR);
113
114 // Use the texture first to make sure it's in video memory
Jamie Madilld4cfa572014-07-08 10:00:32 -0400115 glUseProgram(m2DProgram);
116 glUniform1i(mTexture2DUniformLocation, 0);
117 drawQuad(m2DProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -0400118
119 const GLubyte *pixel[4] = { 0 };
120
121 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
122 EXPECT_GL_NO_ERROR();
123
124 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
125 EXPECT_GL_NO_ERROR();
126
127 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
128 EXPECT_GL_NO_ERROR();
129}
Jamie Madilld4cfa572014-07-08 10:00:32 -0400130
131// Test drawing with two texture types, to trigger an ANGLE bug in validation
Jamie Madillb759a742014-07-17 10:40:49 -0400132TEST_F(TextureTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -0400133{
134 glActiveTexture(GL_TEXTURE0);
135 glBindTexture(GL_TEXTURE_2D, mTexture2D);
136 glActiveTexture(GL_TEXTURE1);
137 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
138 EXPECT_GL_ERROR(GL_NO_ERROR);
139
140 glUseProgram(mCubeProgram);
141 GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D");
142 GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube");
143 EXPECT_NE(-1, tex2DUniformLocation);
144 EXPECT_NE(-1, texCubeUniformLocation);
145 glUniform1i(tex2DUniformLocation, 0);
146 glUniform1i(texCubeUniformLocation, 1);
147 drawQuad(mCubeProgram, "position", 0.5f);
148 EXPECT_GL_NO_ERROR();
149}