blob: f5fff414c86a650b59683936705d58bc3789cd05 [file] [log] [blame]
Jamie Madillf67115c2014-04-22 13:14:05 -04001#include "ANGLETest.h"
2
3class TextureTest : public ANGLETest
4{
5protected:
6 TextureTest()
7 {
8 setWindowWidth(128);
9 setWindowHeight(128);
10 setConfigRedBits(8);
11 setConfigGreenBits(8);
12 setConfigBlueBits(8);
13 setConfigAlphaBits(8);
14 }
15
16 virtual void SetUp()
17 {
18 ANGLETest::SetUp();
19 glGenTextures(1, &mTexture);
20
21 glBindTexture(GL_TEXTURE_2D, mTexture);
22 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
23 EXPECT_GL_NO_ERROR();
24
25 ASSERT_GL_NO_ERROR();
Geoff Langc41e42d2014-04-28 10:58:16 -040026
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
52 mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
53 if (mProgram == 0)
54 {
55 FAIL() << "shader compilation failed.";
56 }
57
58 mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
Jamie Madillf67115c2014-04-22 13:14:05 -040059 }
60
61 virtual void TearDown()
62 {
63 glDeleteTextures(1, &mTexture);
Geoff Langc41e42d2014-04-28 10:58:16 -040064 glDeleteProgram(mProgram);
Jamie Madillf67115c2014-04-22 13:14:05 -040065
66 ANGLETest::TearDown();
67 }
68
69 GLuint mTexture;
Geoff Langc41e42d2014-04-28 10:58:16 -040070
71 GLuint mProgram;
72 GLint mTextureUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -040073};
74
75TEST_F(TextureTest, negative_api_subimage)
76{
77 glBindTexture(GL_TEXTURE_2D, mTexture);
78 EXPECT_GL_ERROR(GL_NO_ERROR);
79
80 const GLubyte *pixels[20] = { 0 };
81 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
82 EXPECT_GL_ERROR(GL_INVALID_VALUE);
83}
Geoff Langc41e42d2014-04-28 10:58:16 -040084
85TEST_F(TextureTest, zero_sized_uploads)
86{
87 glBindTexture(GL_TEXTURE_2D, mTexture);
88 EXPECT_GL_ERROR(GL_NO_ERROR);
89
90 // Use the texture first to make sure it's in video memory
91 glUseProgram(mProgram);
92 glUniform1i(mTextureUniformLocation, 0);
93 drawQuad(mProgram, "position", 0.5f);
94
95 const GLubyte *pixel[4] = { 0 };
96
97 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
98 EXPECT_GL_NO_ERROR();
99
100 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
101 EXPECT_GL_NO_ERROR();
102
103 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
104 EXPECT_GL_NO_ERROR();
105}