blob: ae58ba0b500a9b68f0dc6503cda54aeed824c9a0 [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.
6typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
7TYPED_TEST_CASE(IncompleteTextureTest, TestFixtureTypes);
8
9template<typename T>
Geoff Lang0ddab0c2013-10-23 13:24:41 -040010class IncompleteTextureTest : public ANGLETest
11{
12protected:
Austin Kinross18b931d2014-09-29 12:58:31 -070013 IncompleteTextureTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
Geoff Lang0ddab0c2013-10-23 13:24:41 -040014 {
15 setWindowWidth(128);
16 setWindowHeight(128);
17 setConfigRedBits(8);
18 setConfigGreenBits(8);
19 setConfigBlueBits(8);
20 setConfigAlphaBits(8);
21 }
22
23 virtual void SetUp()
24 {
25 ANGLETest::SetUp();
26
27 const std::string vertexShaderSource = SHADER_SOURCE
28 (
29 precision highp float;
30 attribute vec4 position;
31 varying vec2 texcoord;
32
33 void main()
34 {
35 gl_Position = position;
36 texcoord = (position.xy * 0.5) + 0.5;
37 }
38 );
39
40 const std::string fragmentShaderSource = SHADER_SOURCE
41 (
42 precision highp float;
43 uniform sampler2D tex;
44 varying vec2 texcoord;
45
46 void main()
47 {
48 gl_FragColor = texture2D(tex, texcoord);
49 }
50 );
51
Jamie Madill5599c8f2014-08-26 13:16:39 -040052 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Lang0ddab0c2013-10-23 13:24:41 -040053 if (mProgram == 0)
54 {
55 FAIL() << "shader compilation failed.";
56 }
57
58 mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
59 }
60
61 virtual void TearDown()
62 {
63 glDeleteProgram(mProgram);
64
65 ANGLETest::TearDown();
66 }
67
68 void fillTextureData(std::vector<GLubyte> &buffer, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
69 {
70 size_t count = buffer.size() / 4;
71 for (size_t i = 0; i < count; i++)
72 {
73 buffer[i * 4 + 0] = r;
74 buffer[i * 4 + 1] = g;
75 buffer[i * 4 + 2] = b;
76 buffer[i * 4 + 3] = a;
77 }
78 }
79
80 GLuint mProgram;
81 GLint mTextureUniformLocation;
82};
83
Austin Kinross18b931d2014-09-29 12:58:31 -070084TYPED_TEST(IncompleteTextureTest, IncompleteTexture2D)
Geoff Lang0ddab0c2013-10-23 13:24:41 -040085{
86 GLuint tex;
87 glGenTextures(1, &tex);
88 glActiveTexture(GL_TEXTURE0);
89 glBindTexture(GL_TEXTURE_2D, tex);
90
91 glUseProgram(mProgram);
92 glUniform1i(mTextureUniformLocation, 0);
93
94 const GLsizei textureWidth = 2;
95 const GLsizei textureHeight = 2;
96 std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
97 fillTextureData(textureData, 255, 0, 0, 255);
98
Jamie Madillb4fd0c92014-10-01 17:40:24 -040099 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
101
102 drawQuad(mProgram, "position", 0.5f);
103 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
104
105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
106
107 drawQuad(mProgram, "position", 0.5f);
108 EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
109
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400110 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 -0400111
112 drawQuad(mProgram, "position", 0.5f);
113 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
114
115 glDeleteTextures(1, &tex);
116}
117
Austin Kinross18b931d2014-09-29 12:58:31 -0700118TYPED_TEST(IncompleteTextureTest, UpdateTexture)
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400119{
120 GLuint tex;
121 glGenTextures(1, &tex);
122 glActiveTexture(GL_TEXTURE0);
123 glBindTexture(GL_TEXTURE_2D, tex);
124
125 glUseProgram(mProgram);
126 glUniform1i(mTextureUniformLocation, 0);
127
128 const GLsizei redTextureWidth = 64;
129 const GLsizei redTextureHeight = 64;
130 std::vector<GLubyte> redTextureData(redTextureWidth * redTextureHeight * 4);
131 fillTextureData(redTextureData, 255, 0, 0, 255);
132 for (size_t i = 0; i < 7; i++)
133 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400134 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400135 &redTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400136 }
137
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
140
141 drawQuad(mProgram, "position", 0.5f);
142 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
143
144 const GLsizei greenTextureWidth = 32;
145 const GLsizei greenTextureHeight = 32;
146 std::vector<GLubyte> greenTextureData(greenTextureWidth * greenTextureHeight * 4);
147 fillTextureData(greenTextureData, 0, 255, 0, 255);
148
149 for (size_t i = 0; i < 6; i++)
150 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400151 glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400152 greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400153 &greenTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400154 }
155
156 drawQuad(mProgram, "position", 0.5f);
157 EXPECT_PIXEL_EQ(getWindowWidth() - greenTextureWidth, getWindowHeight() - greenTextureWidth, 0, 255, 0, 255);
158
159 glDeleteTextures(1, &tex);
160}