blob: a9e4ed4fc23166e55ee8946ed8bddfefaa3c18ef [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Corentin Wallezac3ab882015-05-12 13:31:28 -04007#include "end2end_tests/ANGLETest.h"
Geoff Lang0ddab0c2013-10-23 13:24:41 -04008
9#include <vector>
10
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Geoff Lang0ddab0c2013-10-23 13:24:41 -040013class IncompleteTextureTest : public ANGLETest
14{
Jamie Madillfa05f602015-05-07 13:47:11 -040015 protected:
16 IncompleteTextureTest()
Geoff Lang0ddab0c2013-10-23 13:24:41 -040017 {
18 setWindowWidth(128);
19 setWindowHeight(128);
20 setConfigRedBits(8);
21 setConfigGreenBits(8);
22 setConfigBlueBits(8);
23 setConfigAlphaBits(8);
24 }
25
26 virtual void SetUp()
27 {
28 ANGLETest::SetUp();
29
30 const std::string vertexShaderSource = SHADER_SOURCE
31 (
32 precision highp float;
33 attribute vec4 position;
34 varying vec2 texcoord;
35
36 void main()
37 {
38 gl_Position = position;
39 texcoord = (position.xy * 0.5) + 0.5;
40 }
41 );
42
43 const std::string fragmentShaderSource = SHADER_SOURCE
44 (
45 precision highp float;
46 uniform sampler2D tex;
47 varying vec2 texcoord;
48
49 void main()
50 {
51 gl_FragColor = texture2D(tex, texcoord);
52 }
53 );
54
Jamie Madill5599c8f2014-08-26 13:16:39 -040055 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Lang0ddab0c2013-10-23 13:24:41 -040056 if (mProgram == 0)
57 {
58 FAIL() << "shader compilation failed.";
59 }
60
61 mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
62 }
63
64 virtual void TearDown()
65 {
66 glDeleteProgram(mProgram);
67
68 ANGLETest::TearDown();
69 }
70
71 void fillTextureData(std::vector<GLubyte> &buffer, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
72 {
73 size_t count = buffer.size() / 4;
74 for (size_t i = 0; i < count; i++)
75 {
76 buffer[i * 4 + 0] = r;
77 buffer[i * 4 + 1] = g;
78 buffer[i * 4 + 2] = b;
79 buffer[i * 4 + 3] = a;
80 }
81 }
82
83 GLuint mProgram;
84 GLint mTextureUniformLocation;
85};
86
Jamie Madillfa05f602015-05-07 13:47:11 -040087TEST_P(IncompleteTextureTest, IncompleteTexture2D)
Geoff Lang0ddab0c2013-10-23 13:24:41 -040088{
89 GLuint tex;
90 glGenTextures(1, &tex);
91 glActiveTexture(GL_TEXTURE0);
92 glBindTexture(GL_TEXTURE_2D, tex);
93
94 glUseProgram(mProgram);
95 glUniform1i(mTextureUniformLocation, 0);
96
97 const GLsizei textureWidth = 2;
98 const GLsizei textureHeight = 2;
99 std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
100 fillTextureData(textureData, 255, 0, 0, 255);
101
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400102 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
104
105 drawQuad(mProgram, "position", 0.5f);
106 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
107
108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
109
110 drawQuad(mProgram, "position", 0.5f);
111 EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
112
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400113 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 -0400114
115 drawQuad(mProgram, "position", 0.5f);
116 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
117
118 glDeleteTextures(1, &tex);
119}
120
Jamie Madillfa05f602015-05-07 13:47:11 -0400121TEST_P(IncompleteTextureTest, UpdateTexture)
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400122{
123 GLuint tex;
124 glGenTextures(1, &tex);
125 glActiveTexture(GL_TEXTURE0);
126 glBindTexture(GL_TEXTURE_2D, tex);
127
128 glUseProgram(mProgram);
129 glUniform1i(mTextureUniformLocation, 0);
130
131 const GLsizei redTextureWidth = 64;
132 const GLsizei redTextureHeight = 64;
133 std::vector<GLubyte> redTextureData(redTextureWidth * redTextureHeight * 4);
134 fillTextureData(redTextureData, 255, 0, 0, 255);
135 for (size_t i = 0; i < 7; i++)
136 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400137 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400138 &redTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400139 }
140
141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
143
144 drawQuad(mProgram, "position", 0.5f);
145 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
146
147 const GLsizei greenTextureWidth = 32;
148 const GLsizei greenTextureHeight = 32;
149 std::vector<GLubyte> greenTextureData(greenTextureWidth * greenTextureHeight * 4);
150 fillTextureData(greenTextureData, 0, 255, 0, 255);
151
152 for (size_t i = 0; i < 6; i++)
153 {
Jamie Madillf67115c2014-04-22 13:14:05 -0400154 glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400155 greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400156 &greenTextureData[0]);
Geoff Lang0ddab0c2013-10-23 13:24:41 -0400157 }
158
159 drawQuad(mProgram, "position", 0.5f);
160 EXPECT_PIXEL_EQ(getWindowWidth() - greenTextureWidth, getWindowHeight() - greenTextureWidth, 0, 255, 0, 255);
161
162 glDeleteTextures(1, &tex);
163}
Jamie Madillfa05f602015-05-07 13:47:11 -0400164
165// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
166ANGLE_INSTANTIATE_TEST(IncompleteTextureTest, ES2_D3D9(), ES2_D3D11());