Update V8 to version 4.6.8.
[chromium-blink-merge.git] / gpu / command_buffer / tests / gl_texture_storage_unittest.cc
blob3006888aa6be6eb6ea13e02bd0c21cf9d061cca5
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 void SetUp() override {
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 void TearDown() override { gl_.Destroy(); }
42 GLManager gl_;
43 GLuint tex_;
44 GLuint fbo_;
45 bool extension_available_;
48 TEST_F(TextureStorageTest, CorrectPixels) {
49 if (!extension_available_)
50 return;
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,
59 0, 0,
60 2, 2,
61 GL_RGBA, GL_UNSIGNED_BYTE,
62 source_pixels);
63 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, 2, 2, 0, source_pixels));
66 TEST_F(TextureStorageTest, IsImmutable) {
67 if (!extension_available_)
68 return;
70 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 4, 4);
72 GLint param = 0;
73 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT_EXT, &param);
74 EXPECT_TRUE(param);
77 TEST_F(TextureStorageTest, OneLevel) {
78 if (!extension_available_)
79 return;
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_)
96 return;
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_)
116 return;
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_)
125 return;
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_)
135 return;
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,
146 GL_RGBA,
147 4, 4,
149 GL_RGBA,
150 GL_UNSIGNED_BYTE,
151 NULL);
152 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
155 } // namespace gpu