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.
6 #include <GLES2/gl2ext.h>
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"
15 class TextureStorageTest
: public testing::Test
{
17 static const GLsizei kResolution
= 64;
18 void SetUp() override
{
19 GLManager::Options options
;
20 options
.size
= gfx::Size(kResolution
, kResolution
);
21 gl_
.Initialize(options
);
24 glGenTextures(1, &tex_
);
25 glBindTexture(GL_TEXTURE_2D
, tex_
);
27 glGenFramebuffers(1, &fbo_
);
28 glBindFramebuffer(GL_FRAMEBUFFER
, fbo_
);
29 glFramebufferTexture2D(GL_FRAMEBUFFER
,
35 const GLubyte
* extensions
= glGetString(GL_EXTENSIONS
);
36 extension_available_
= strstr(reinterpret_cast<const char*>(
37 extensions
), "GL_EXT_texture_storage");
40 void TearDown() override
{ gl_
.Destroy(); }
45 bool extension_available_
;
48 TEST_F(TextureStorageTest
, CorrectPixels
) {
49 if (!extension_available_
)
52 glTexStorage2DEXT(GL_TEXTURE_2D
, 2, GL_RGBA8_OES
, 2, 2);
54 // Mesa dirvers crash without rebinding to FBO. It's why
55 // DISABLE_TEXTURE_STORAGE workaround is introduced. crbug.com/521904
56 glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
,
59 uint8 source_pixels
[16] = {
60 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
62 glTexSubImage2D(GL_TEXTURE_2D
,
66 GL_RGBA
, GL_UNSIGNED_BYTE
,
68 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels
));
71 TEST_F(TextureStorageTest
, IsImmutable
) {
72 if (!extension_available_
)
75 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
78 glGetTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_IMMUTABLE_FORMAT_EXT
, ¶m
);
82 TEST_F(TextureStorageTest
, OneLevel
) {
83 if (!extension_available_
)
86 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
88 uint8 source_pixels
[64] = { 0 };
90 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
91 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 4, 4,
92 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
93 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
94 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 2, 2,
95 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
96 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
99 TEST_F(TextureStorageTest
, MultipleLevels
) {
100 if (!extension_available_
)
103 glTexStorage2DEXT(GL_TEXTURE_2D
, 2, GL_RGBA8_OES
, 2, 2);
105 uint8 source_pixels
[16] = { 0 };
107 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
108 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 2, 2,
109 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
110 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
111 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 1, 1,
112 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
113 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
114 glTexSubImage2D(GL_TEXTURE_2D
, 2, 0, 0, 1, 1,
115 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
116 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
119 TEST_F(TextureStorageTest
, BadTarget
) {
120 if (!extension_available_
)
123 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
124 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 1, GL_RGBA8_OES
, 4, 4);
125 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_ENUM
), glGetError());
128 TEST_F(TextureStorageTest
, InvalidId
) {
129 if (!extension_available_
)
132 glDeleteTextures(1, &tex_
);
133 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
134 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
135 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
138 TEST_F(TextureStorageTest
, CannotRedefine
) {
139 if (!extension_available_
)
142 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
144 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
145 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
146 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
148 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
149 glTexImage2D(GL_TEXTURE_2D
,
157 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());