Home | History | Annotate | Download | only in angle_tests
      1 #include "ANGLETest.h"
      2 
      3 class TextureTest : public ANGLETest
      4 {
      5 protected:
      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();
     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 
     52         mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
     53         if (mProgram == 0)
     54         {
     55             FAIL() << "shader compilation failed.";
     56         }
     57 
     58         mTextureUniformLocation = glGetUniformLocation(mProgram, "tex");
     59     }
     60 
     61     virtual void TearDown()
     62     {
     63         glDeleteTextures(1, &mTexture);
     64         glDeleteProgram(mProgram);
     65 
     66         ANGLETest::TearDown();
     67     }
     68 
     69     GLuint mTexture;
     70 
     71     GLuint mProgram;
     72     GLint mTextureUniformLocation;
     73 };
     74 
     75 TEST_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 }
     84 
     85 TEST_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 }
    106