blob: 346500f5d9fc0764d46cdcb28a761905839c554b [file] [log] [blame]
Geoff Lang0ddab0c2013-10-23 13:24:41 -04001#include "ANGLETest.h"
2
3#include <vector>
4
Austin Kinross18b931d2014-09-29 12:58:31 -07005// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lang0d3683c2014-10-23 11:08:16 -04006ANGLE_TYPED_TEST_CASE(IncompleteTextureTest, ES2_D3D9, ES2_D3D11);
Austin Kinross18b931d2014-09-29 12:58:31 -07007
8template<typename T>
Geoff Lang0ddab0c2013-10-23 13:24:41 -04009class IncompleteTextureTest : public ANGLETest
10{
11protected:
Geoff Lang0d3683c2014-10-23 11:08:16 -040012 IncompleteTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform())
Geoff Lang0ddab0c2013-10-23 13:24:41 -040013 {
14 setWindowWidth(128);
15 setWindowHeight(128);
16 setConfigRedBits(8);
17 setConfigGreenBits(8);
18 setConfigBlueBits(8);
19 setConfigAlphaBits(8);
20 }
21
22 virtual void SetUp()
23 {
24 ANGLETest::SetUp();
25
26 const std::string vertexShaderSource = SHADER_SOURCE
27 (
28 precision highp float;
29 attribute vec4 position;
30 varying vec2 texcoord;
31
32 void main()
33 {
34 gl_Position = position;
35 texcoord = (position.xy * 0.5) + 0.5;
36 }
37 );
38
39 const std::string fragmentShaderSource = SHADER_SOURCE
40 (
41 precision highp float;
42 uniform sampler2D tex;
43 varying vec2 texcoord;
44
45 void main()
46 {
47 gl_FragColor = texture2D(tex, texcoord);
48 }
49 );
50
Jamie Madill5599c8f2014-08-26 13:16:39 -040051 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Lang0ddab0c2013-10-23 13:24:41 -040052 if (mProgram == 0)
53 {
54 FAIL() << "shader compilation failed.";
55 }
56
57 mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
58 }
59
60 virtual void TearDown()
61 {
62 glDeleteProgram(mProgram);
63
64 ANGLETest::TearDown();
65 }
66
67 void fillTextureData(std::vector<GLubyte> &buffer, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
68 {
69 size_t count = buffer.size() / 4;
70 for (size_t i = 0; i < count; i++)
71 {
72 buffer[i * 4 + 0] = r;
73 buffer[i * 4 + 1] = g;
74 buffer[i * 4 + 2] = b;
75 buffer[i * 4 + 3] = a;
76 }
77 }
78
79 GLuint mProgram;
80 GLint mTextureUniformLocation;
81};
82
Austin Kinross18b931d2014-09-29 12:58:31 -070083TYPED_TEST(IncompleteTextureTest, IncompleteTexture2D)
Geoff Lang0ddab0c2013-10-23 13:24:41 -040084{
85 GLuint tex;
86 glGenTextures(1, &tex);
87 glActiveTexture(GL_TEXTURE0);
88 glBindTexture(GL_TEXTURE_2D, tex);
89
90 glUseProgram(mProgram);
91 glUniform1i(mTextureUniformLocation, 0);
92
93 const GLsizei textureWidth = 2;
94 const GLsizei textureHeight = 2;
95 std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
96 fillTextureData(textureData, 255, 0, 0, 255);
97
Jamie Madillb4fd0c92014-10-01 17:40:24 -040098 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -040099 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
100
101 drawQuad(mProgram, "position", 0.5f);
102 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
103
104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
105
106 drawQuad(mProgram, "position", 0.5f);
107 EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
108
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400109 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, textureWidth >> 1, textureHeight >> 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400110
111 drawQuad(mProgram, "position", 0.5f);
112 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
113
114 glDeleteTextures(1, &tex);
115}
116
Austin Kinross18b931d2014-09-29 12:58:31 -0700117TYPED_TEST(IncompleteTextureTest, UpdateTexture)
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400118{
119 GLuint tex;
120 glGenTextures(1, &tex);
121 glActiveTexture(GL_TEXTURE0);
122 glBindTexture(GL_TEXTURE_2D, tex);
123
124 glUseProgram(mProgram);
125 glUniform1i(mTextureUniformLocation, 0);
126
127 const GLsizei redTextureWidth = 64;
128 const GLsizei redTextureHeight = 64;
129 std::vector<GLubyte> redTextureData(redTextureWidth * redTextureHeight * 4);
130 fillTextureData(redTextureData, 255, 0, 0, 255);
131 for (size_t i = 0; i < 7; i++)
132 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400133 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400134 &redTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400135 }
136
137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
139
140 drawQuad(mProgram, "position", 0.5f);
141 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
142
143 const GLsizei greenTextureWidth = 32;
144 const GLsizei greenTextureHeight = 32;
145 std::vector<GLubyte> greenTextureData(greenTextureWidth * greenTextureHeight * 4);
146 fillTextureData(greenTextureData, 0, 255, 0, 255);
147
148 for (size_t i = 0; i < 6; i++)
149 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400150 glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400151 greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400152 &greenTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400153 }
154
155 drawQuad(mProgram, "position", 0.5f);
156 EXPECT_PIXEL_EQ(getWindowWidth() - greenTextureWidth, getWindowHeight() - greenTextureWidth, 0, 255, 0, 255);
157
158 glDeleteTextures(1, &tex);
159}