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 uint8 source_pixels
[16] = {
55 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
57 glTexSubImage2D(GL_TEXTURE_2D
,
61 GL_RGBA
, GL_UNSIGNED_BYTE
,
63 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels
));
66 TEST_F(TextureStorageTest
, IsImmutable
) {
67 if (!extension_available_
)
70 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
73 glGetTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_IMMUTABLE_FORMAT_EXT
, ¶m
);
77 TEST_F(TextureStorageTest
, OneLevel
) {
78 if (!extension_available_
)
81 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
83 uint8 source_pixels
[64] = { 0 };
85 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
86 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 4, 4,
87 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
88 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
89 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 2, 2,
90 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
91 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
94 TEST_F(TextureStorageTest
, MultipleLevels
) {
95 if (!extension_available_
)
98 glTexStorage2DEXT(GL_TEXTURE_2D
, 2, GL_RGBA8_OES
, 2, 2);
100 uint8 source_pixels
[16] = { 0 };
102 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
103 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 2, 2,
104 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
105 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
106 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 1, 1,
107 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
108 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
109 glTexSubImage2D(GL_TEXTURE_2D
, 2, 0, 0, 1, 1,
110 GL_RGBA
, GL_UNSIGNED_BYTE
, source_pixels
);
111 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
114 TEST_F(TextureStorageTest
, BadTarget
) {
115 if (!extension_available_
)
118 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
119 glTexStorage2DEXT(GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 1, GL_RGBA8_OES
, 4, 4);
120 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_ENUM
), glGetError());
123 TEST_F(TextureStorageTest
, InvalidId
) {
124 if (!extension_available_
)
127 glDeleteTextures(1, &tex_
);
128 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
129 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
130 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
133 TEST_F(TextureStorageTest
, CannotRedefine
) {
134 if (!extension_available_
)
137 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
139 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
140 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
141 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());
143 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
144 glTexImage2D(GL_TEXTURE_2D
,
152 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());