Hash :
5599c8f6
Author :
Date :
2014-08-26T13:16:39
Use shared compile helpers in the ANGLE tests. BUG=angle:730 Change-Id: Ib3bd646c73355449105e6cf79bdcf0a14b391fd2 Reviewed-on: https://chromium-review.googlesource.com/213550 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#include "ANGLETest.h"
#include <vector>
class IncompleteTextureTest : public ANGLETest
{
protected:
IncompleteTextureTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
virtual void SetUp()
{
ANGLETest::SetUp();
const std::string vertexShaderSource = SHADER_SOURCE
(
precision highp float;
attribute vec4 position;
varying vec2 texcoord;
void main()
{
gl_Position = position;
texcoord = (position.xy * 0.5) + 0.5;
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
(
precision highp float;
uniform sampler2D tex;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(tex, texcoord);
}
);
mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
}
virtual void TearDown()
{
glDeleteProgram(mProgram);
ANGLETest::TearDown();
}
void fillTextureData(std::vector<GLubyte> &buffer, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
{
size_t count = buffer.size() / 4;
for (size_t i = 0; i < count; i++)
{
buffer[i * 4 + 0] = r;
buffer[i * 4 + 1] = g;
buffer[i * 4 + 2] = b;
buffer[i * 4 + 3] = a;
}
}
GLuint mProgram;
GLint mTextureUniformLocation;
};
TEST_F(IncompleteTextureTest, IncompleteTexture2D)
{
GLuint tex;
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUseProgram(mProgram);
glUniform1i(mTextureUniformLocation, 0);
const GLsizei textureWidth = 2;
const GLsizei textureHeight = 2;
std::vector<GLubyte> textureData(textureWidth * textureHeight * 4);
fillTextureData(textureData, 255, 0, 0, 255);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 255);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, textureWidth >> 1, textureHeight >> 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
glDeleteTextures(1, &tex);
}
TEST_F(IncompleteTextureTest, UpdateTexture)
{
GLuint tex;
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUseProgram(mProgram);
glUniform1i(mTextureUniformLocation, 0);
const GLsizei redTextureWidth = 64;
const GLsizei redTextureHeight = 64;
std::vector<GLubyte> redTextureData(redTextureWidth * redTextureHeight * 4);
fillTextureData(redTextureData, 255, 0, 0, 255);
for (size_t i = 0; i < 7; i++)
{
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, redTextureWidth >> i, redTextureHeight >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
redTextureData.data());
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
const GLsizei greenTextureWidth = 32;
const GLsizei greenTextureHeight = 32;
std::vector<GLubyte> greenTextureData(greenTextureWidth * greenTextureHeight * 4);
fillTextureData(greenTextureData, 0, 255, 0, 255);
for (size_t i = 0; i < 6; i++)
{
glTexSubImage2D(GL_TEXTURE_2D, i, greenTextureWidth >> i, greenTextureHeight >> i,
greenTextureWidth >> i, greenTextureHeight >> i, GL_RGBA, GL_UNSIGNED_BYTE,
greenTextureData.data());
}
drawQuad(mProgram, "position", 0.5f);
EXPECT_PIXEL_EQ(getWindowWidth() - greenTextureWidth, getWindowHeight() - greenTextureWidth, 0, 255, 0, 255);
glDeleteTextures(1, &tex);
}