Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / tests / gl_texture_storage_unittest.cc
blobb28baf0c054a0569327b51f2fe184e697e36aaa8
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.
5 #include <GLES2/gl2.h>
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"
13 namespace gpu {
15 class TextureStorageTest : public testing::Test {
16 protected:
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);
22 gl_.MakeCurrent();
24 glGenTextures(1, &tex_);
25 glBindTexture(GL_TEXTURE_2D, tex_);
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);
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() {
41 gl_.Destroy();
44 GLManager gl_;
45 GLuint tex_;
46 GLuint fbo_;
47 bool extension_available_;
50 TEST_F(TextureStorageTest, CorrectPixels) {
51 if (!extension_available_)
52 return;
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,
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));
68 TEST_F(TextureStorageTest, IsImmutable) {
69 if (!extension_available_)
70 return;
72 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
74 GLint param = 0;
75 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT_EXT, &param);
76 EXPECT_TRUE(param);
79 TEST_F(TextureStorageTest, OneLevel) {
80 if (!extension_available_)
81 return;
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_)
98 return;
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_)
118 return;
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_)
127 return;
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_)
137 return;
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,
148 GL_RGBA,
149 4, 4,
151 GL_RGBA,
152 GL_UNSIGNED_BYTE,
153 NULL);
154 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
157 } // namespace gpu