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 virtual void SetUp() {
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 virtual void TearDown() {
47 bool extension_available_
;
50 TEST_F(TextureStorageTest
, CorrectPixels
) {
51 if (!extension_available_
)
54 glTexStorage2DEXT(GL_TEXTURE_2D
, 2, GL_RGBA8_OES
, 2, 2);
56 uint8 source_pixels
[16] = {
57 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4
59 glTexSubImage2D(GL_TEXTURE_2D
,
63 GL_RGBA
, GL_UNSIGNED_BYTE
,
65 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels
));
68 TEST_F(TextureStorageTest
, IsImmutable
) {
69 if (!extension_available_
)
72 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
75 glGetTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_IMMUTABLE_FORMAT_EXT
, ¶m
);
79 TEST_F(TextureStorageTest
, OneLevel
) {
80 if (!extension_available_
)
83 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
85 uint8 source_pixels
[64] = { 0 };
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());
96 TEST_F(TextureStorageTest
, MultipleLevels
) {
97 if (!extension_available_
)
100 glTexStorage2DEXT(GL_TEXTURE_2D
, 2, GL_RGBA8_OES
, 2, 2);
102 uint8 source_pixels
[16] = { 0 };
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());
116 TEST_F(TextureStorageTest
, BadTarget
) {
117 if (!extension_available_
)
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());
125 TEST_F(TextureStorageTest
, InvalidId
) {
126 if (!extension_available_
)
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());
135 TEST_F(TextureStorageTest
, CannotRedefine
) {
136 if (!extension_available_
)
139 glTexStorage2DEXT(GL_TEXTURE_2D
, 1, GL_RGBA8_OES
, 4, 4);
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());
145 EXPECT_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
146 glTexImage2D(GL_TEXTURE_2D
,
154 EXPECT_EQ(static_cast<GLenum
>(GL_INVALID_OPERATION
), glGetError());