• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h>
7 
8 #include "gpu/command_buffer/tests/gl_manager.h"
9 #include "gpu/command_buffer/tests/gl_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace gpu {
14 
15 class TextureStorageTest : public testing::Test {
16  protected:
17   static const GLsizei kResolution = 64;
SetUp()18   virtual void SetUp() {
19     GLManager::Options options;
20     options.size = gfx::Size(kResolution, kResolution);
21     gl_.Initialize(options);
22     gl_.MakeCurrent();
23 
24     glGenTextures(1, &tex_);
25     glBindTexture(GL_TEXTURE_2D, tex_);
26 
27     glGenFramebuffers(1, &fbo_);
28     glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
29     glFramebufferTexture2D(GL_FRAMEBUFFER,
30                            GL_COLOR_ATTACHMENT0,
31                            GL_TEXTURE_2D,
32                            tex_,
33                            0);
34 
35     const GLubyte* extensions = glGetString(GL_EXTENSIONS);
36     extension_available_ = strstr(reinterpret_cast<const char*>(
37         extensions), "GL_EXT_texture_storage");
38   }
39 
TearDown()40   virtual void TearDown() {
41     gl_.Destroy();
42   }
43 
44   GLManager gl_;
45   GLuint tex_;
46   GLuint fbo_;
47   bool extension_available_;
48 };
49 
TEST_F(TextureStorageTest,CorrectPixels)50 TEST_F(TextureStorageTest, CorrectPixels) {
51   if (!extension_available_)
52     return;
53 
54   glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA8_OES, 2, 2);
55 
56   uint8 source_pixels[16] = {
57       1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
58   };
59   glTexSubImage2D(GL_TEXTURE_2D,
60                   0,
61                   0, 0,
62                   2, 2,
63                   GL_RGBA, GL_UNSIGNED_BYTE,
64                   source_pixels);
65   EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels));
66 }
67 
TEST_F(TextureStorageTest,IsImmutable)68 TEST_F(TextureStorageTest, IsImmutable) {
69   if (!extension_available_)
70     return;
71 
72   glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
73 
74   GLint param = 0;
75   glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT_EXT, &param);
76   EXPECT_TRUE(param);
77 }
78 
TEST_F(TextureStorageTest,OneLevel)79 TEST_F(TextureStorageTest, OneLevel) {
80   if (!extension_available_)
81     return;
82 
83   glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
84 
85   uint8 source_pixels[64] = { 0 };
86 
87   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
88   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4,
89                   GL_RGBA, GL_UNSIGNED_BYTE, source_pixels);
90   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
91   glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2,
92                   GL_RGBA, GL_UNSIGNED_BYTE, source_pixels);
93   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
94 }
95 
TEST_F(TextureStorageTest,MultipleLevels)96 TEST_F(TextureStorageTest, MultipleLevels) {
97   if (!extension_available_)
98     return;
99 
100   glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA8_OES, 2, 2);
101 
102   uint8 source_pixels[16] = { 0 };
103 
104   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
105   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2,
106                   GL_RGBA, GL_UNSIGNED_BYTE, source_pixels);
107   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
108   glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 1, 1,
109                   GL_RGBA, GL_UNSIGNED_BYTE, source_pixels);
110   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
111   glTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1,
112                   GL_RGBA, GL_UNSIGNED_BYTE, source_pixels);
113   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
114 }
115 
TEST_F(TextureStorageTest,BadTarget)116 TEST_F(TextureStorageTest, BadTarget) {
117   if (!extension_available_)
118     return;
119 
120   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
121   glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8_OES, 4, 4);
122   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
123 }
124 
TEST_F(TextureStorageTest,InvalidId)125 TEST_F(TextureStorageTest, InvalidId) {
126   if (!extension_available_)
127     return;
128 
129   glDeleteTextures(1, &tex_);
130   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
131   glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
132   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
133 }
134 
TEST_F(TextureStorageTest,CannotRedefine)135 TEST_F(TextureStorageTest, CannotRedefine) {
136   if (!extension_available_)
137     return;
138 
139   glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
140 
141   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
142   glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
143   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
144 
145   EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
146   glTexImage2D(GL_TEXTURE_2D,
147                0,
148                GL_RGBA,
149                4, 4,
150                0,
151                GL_RGBA,
152                GL_UNSIGNED_BYTE,
153                NULL);
154   EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
155 }
156 
157 }  // namespace gpu
158 
159 
160 
161