blob: 1213972423f929f562b272fd1515bda584f0b660 [file] [log] [blame]
Jamie Madillf67115c2014-04-22 13:14:05 -04001#include "ANGLETest.h"
2
Austin Kinross18b931d2014-09-29 12:58:31 -07003// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5TYPED_TEST_CASE(TextureTest, TestFixtureTypes);
6
7template<typename T>
Jamie Madillf67115c2014-04-22 13:14:05 -04008class TextureTest : public ANGLETest
9{
10protected:
Austin Kinross18b931d2014-09-29 12:58:31 -070011 TextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
Jamie Madillf67115c2014-04-22 13:14:05 -040012 {
13 setWindowWidth(128);
14 setWindowHeight(128);
15 setConfigRedBits(8);
16 setConfigGreenBits(8);
17 setConfigBlueBits(8);
18 setConfigAlphaBits(8);
19 }
20
21 virtual void SetUp()
22 {
23 ANGLETest::SetUp();
Jamie Madilld4cfa572014-07-08 10:00:32 -040024 glGenTextures(1, &mTexture2D);
25 glGenTextures(1, &mTextureCube);
Jamie Madillf67115c2014-04-22 13:14:05 -040026
Jamie Madilld4cfa572014-07-08 10:00:32 -040027 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -040028 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
29 EXPECT_GL_NO_ERROR();
30
Jamie Madilld4cfa572014-07-08 10:00:32 -040031 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
32 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
33 EXPECT_GL_NO_ERROR();
34
Jamie Madillf67115c2014-04-22 13:14:05 -040035 ASSERT_GL_NO_ERROR();
Geoff Langc41e42d2014-04-28 10:58:16 -040036
37 const std::string vertexShaderSource = SHADER_SOURCE
38 (
39 precision highp float;
40 attribute vec4 position;
41 varying vec2 texcoord;
42
43 void main()
44 {
Jamie Madilldcd8f132014-10-03 19:54:50 +000045 gl_Position = position;
Geoff Langc41e42d2014-04-28 10:58:16 -040046 texcoord = (position.xy * 0.5) + 0.5;
47 }
48 );
49
Jamie Madilld4cfa572014-07-08 10:00:32 -040050 const std::string fragmentShaderSource2D = SHADER_SOURCE
Geoff Langc41e42d2014-04-28 10:58:16 -040051 (
52 precision highp float;
53 uniform sampler2D tex;
54 varying vec2 texcoord;
55
56 void main()
57 {
58 gl_FragColor = texture2D(tex, texcoord);
59 }
60 );
61
Jamie Madilld4cfa572014-07-08 10:00:32 -040062 const std::string fragmentShaderSourceCube = SHADER_SOURCE
63 (
64 precision highp float;
65 uniform sampler2D tex2D;
66 uniform samplerCube texCube;
67 varying vec2 texcoord;
68
69 void main()
70 {
71 gl_FragColor = texture2D(tex2D, texcoord);
72 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
73 }
74 );
75
Jamie Madill5599c8f2014-08-26 13:16:39 -040076 m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D);
77 mCubeProgram = CompileProgram(vertexShaderSource, fragmentShaderSourceCube);
Jamie Madilld4cfa572014-07-08 10:00:32 -040078 if (m2DProgram == 0 || mCubeProgram == 0)
Geoff Langc41e42d2014-04-28 10:58:16 -040079 {
80 FAIL() << "shader compilation failed.";
81 }
82
Jamie Madilld4cfa572014-07-08 10:00:32 -040083 mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex");
Jamie Madillf67115c2014-04-22 13:14:05 -040084 }
85
86 virtual void TearDown()
87 {
Jamie Madilld4cfa572014-07-08 10:00:32 -040088 glDeleteTextures(1, &mTexture2D);
89 glDeleteTextures(1, &mTextureCube);
90 glDeleteProgram(m2DProgram);
91 glDeleteProgram(mCubeProgram);
Jamie Madillf67115c2014-04-22 13:14:05 -040092
93 ANGLETest::TearDown();
94 }
95
Jamie Madilld4cfa572014-07-08 10:00:32 -040096 GLuint mTexture2D;
97 GLuint mTextureCube;
Geoff Langc41e42d2014-04-28 10:58:16 -040098
Jamie Madilld4cfa572014-07-08 10:00:32 -040099 GLuint m2DProgram;
100 GLuint mCubeProgram;
101 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400102};
103
Austin Kinross18b931d2014-09-29 12:58:31 -0700104TYPED_TEST(TextureTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -0400105{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400106 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -0400107 EXPECT_GL_ERROR(GL_NO_ERROR);
108
109 const GLubyte *pixels[20] = { 0 };
110 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
111 EXPECT_GL_ERROR(GL_INVALID_VALUE);
112}
Geoff Langc41e42d2014-04-28 10:58:16 -0400113
Austin Kinross18b931d2014-09-29 12:58:31 -0700114TYPED_TEST(TextureTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -0400115{
Jamie Madilld4cfa572014-07-08 10:00:32 -0400116 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -0400117 EXPECT_GL_ERROR(GL_NO_ERROR);
118
119 // Use the texture first to make sure it's in video memory
Jamie Madilld4cfa572014-07-08 10:00:32 -0400120 glUseProgram(m2DProgram);
121 glUniform1i(mTexture2DUniformLocation, 0);
122 drawQuad(m2DProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -0400123
124 const GLubyte *pixel[4] = { 0 };
125
126 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
127 EXPECT_GL_NO_ERROR();
128
129 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
130 EXPECT_GL_NO_ERROR();
131
132 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
133 EXPECT_GL_NO_ERROR();
134}
Jamie Madilld4cfa572014-07-08 10:00:32 -0400135
136// Test drawing with two texture types, to trigger an ANGLE bug in validation
Austin Kinross18b931d2014-09-29 12:58:31 -0700137TYPED_TEST(TextureTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -0400138{
139 glActiveTexture(GL_TEXTURE0);
140 glBindTexture(GL_TEXTURE_2D, mTexture2D);
141 glActiveTexture(GL_TEXTURE1);
142 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
143 EXPECT_GL_ERROR(GL_NO_ERROR);
144
145 glUseProgram(mCubeProgram);
146 GLint tex2DUniformLocation = glGetUniformLocation(mCubeProgram, "tex2D");
147 GLint texCubeUniformLocation = glGetUniformLocation(mCubeProgram, "texCube");
148 EXPECT_NE(-1, tex2DUniformLocation);
149 EXPECT_NE(-1, texCubeUniformLocation);
150 glUniform1i(tex2DUniformLocation, 0);
151 glUniform1i(texCubeUniformLocation, 1);
152 drawQuad(mCubeProgram, "position", 0.5f);
153 EXPECT_GL_NO_ERROR();
154}