| Index: gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc
|
| diff --git a/gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc b/gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..43f58215ccb68c151ac6aab376f33ce886ca2ef8
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc
|
| @@ -0,0 +1,275 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef GL_GLEXT_PROTOTYPES
|
| +#define GL_GLEXT_PROTOTYPES
|
| +#endif
|
| +
|
| +#include <GLES2/gl2.h>
|
| +#include <GLES2/gl2ext.h>
|
| +
|
| +#include "gpu/command_buffer/tests/gl_manager.h"
|
| +#include "gpu/command_buffer/tests/gl_test_utils.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +#define SHADER(Src) #Src
|
| +
|
| +namespace gpu {
|
| +
|
| +static const char* v_shader_str = SHADER(
|
| + attribute vec4 v_position;
|
| + void main() {
|
| + gl_Position = v_position;
|
| + }
|
| +);
|
| +
|
| +static const char* f_shader_str = SHADER(
|
| + uniform sampler2D u_texture;
|
| + void main() {
|
| + gl_FragColor = texture2D(u_texture, vec2(0.5, 0.5)) *
|
| + vec4(4.0, 2.0, 0.5, 0.25);
|
| + }
|
| +);
|
| +
|
| +class GLANGLEColorBufferFloatTest : public testing::Test {
|
| + protected:
|
| + virtual void SetUp() {
|
| + gl_.Initialize(GLManager::Options());
|
| +
|
| + glGenTextures(2, textures);
|
| + glActiveTexture(GL_TEXTURE0);
|
| + glBindTexture(GL_TEXTURE_2D, textures[1]);
|
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| +
|
| + glGenFramebuffers(1, &fbo);
|
| + glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
| + }
|
| +
|
| + virtual void TearDown() {
|
| + glDeleteTextures(2, textures);
|
| + glDeleteFramebuffers(1, &fbo);
|
| + gl_.Destroy();
|
| + }
|
| +
|
| + GLuint SetupUnitQuad(GLint position_location);
|
| +
|
| + GLManager gl_;
|
| + GLuint textures[2];
|
| + GLuint fbo;
|
| +};
|
| +
|
| +GLuint GLANGLEColorBufferFloatTest::SetupUnitQuad(GLint position_location) {
|
| + GLuint vbo = 0;
|
| + glGenBuffers(1, &vbo);
|
| + glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
| + static float vertices[] = {
|
| + 1.0f, 1.0f, 1.0f,
|
| + -1.0f, 1.0f, 0.0f,
|
| + -1.0f, -1.0f, -1.0f,
|
| + 1.0f, 1.0f, 1.0f,
|
| + -1.0f, -1.0f, -1.0f,
|
| + 1.0f, -1.0f, 0.0f,
|
| + };
|
| + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
| + glEnableVertexAttribArray(position_location);
|
| + glVertexAttribPointer(position_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
| +
|
| + return vbo;
|
| +}
|
| +
|
| +TEST_F(GLANGLEColorBufferFloatTest, RenderBuffers) {
|
| + if (!GLTestHelper::HasExtension("GL_ANGLE_color_buffer_float")) {
|
| + return;
|
| + }
|
| +
|
| + GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
|
| + glUseProgram(program);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + GLint position_loc = glGetAttribLocation(program, "v_position");
|
| + SetupUnitQuad(position_loc);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + GLenum internalFormats[5] = {GL_RGBA32F_EXT, GL_RGB32F_EXT, GL_RGBA4,
|
| + GL_RGB5_A1, GL_RGB565};
|
| + GLint componentType[5] = {GL_FLOAT, GL_FLOAT, GL_UNSIGNED_NORMALIZED_EXT,
|
| + GL_UNSIGNED_NORMALIZED_EXT,
|
| + GL_UNSIGNED_NORMALIZED_EXT};
|
| + for (int i = 0; i < 5; i++) {
|
| + GLuint renderbuffer_id;
|
| + glGenRenderbuffers(1, &renderbuffer_id);
|
| + glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer_id);
|
| + glRenderbufferStorage(GL_RENDERBUFFER, internalFormats[i], 4, 4);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
| + GL_RENDERBUFFER, renderbuffer_id);
|
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
|
| + glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
| +
|
| + // Query and check GL_FRAMEBUFFER_ATTACHMENT Parameters
|
| + GLint params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, ¶ms);
|
| + EXPECT_EQ(GL_RENDERBUFFER, params);
|
| + params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, ¶ms);
|
| + EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(params));
|
| + params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT,
|
| + ¶ms);
|
| + EXPECT_EQ(componentType[i], params);
|
| +
|
| + float pixels[1 * 4] = {0.25, 0.5, 2.0, 4.0};
|
| + glBindTexture(GL_TEXTURE_2D, textures[0]);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
|
| + 0, GL_RGBA, GL_FLOAT, pixels);
|
| + glDrawArrays(GL_TRIANGLES, 0, 6);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + // Check glReadPixels
|
| + if (internalFormats[i] != GL_RGBA32F_EXT
|
| + && internalFormats[i] != GL_RGB32F_EXT)
|
| + return;
|
| +
|
| + // Implementation-chosen format
|
| + GLint attachmentType = 0;
|
| + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &attachmentType);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + GLint attachmentFormat = 0;
|
| + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &attachmentFormat);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + if (attachmentType == GL_FLOAT) {
|
| + float actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_FLOAT, actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(1, actual_pixels[i]);
|
| + }
|
| + if (attachmentType == GL_HALF_FLOAT_OES) {
|
| + uint16 actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_HALF_FLOAT_OES,
|
| + actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(15360, actual_pixels[i]);
|
| + }
|
| + if (attachmentType == GL_UNSIGNED_BYTE) {
|
| + uint8 actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_UNSIGNED_BYTE,
|
| + actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(255, actual_pixels[i]);
|
| + }
|
| +
|
| + // RGBA/FLOAT
|
| + float actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(1, actual_pixels[i]);
|
| +
|
| + glDeleteRenderbuffers(1, &renderbuffer_id);
|
| + }
|
| +}
|
| +
|
| +TEST_F(GLANGLEColorBufferFloatTest, Textures) {
|
| + if (!GLTestHelper::HasExtension("GL_ANGLE_color_buffer_float")) {
|
| + return;
|
| + }
|
| +
|
| + GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
|
| + glUseProgram(program);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + GLint position_loc = glGetAttribLocation(program, "v_position");
|
| + SetupUnitQuad(position_loc);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + GLenum formats[2] = {GL_RGBA, GL_RGB};
|
| + for (int i = 0; i < 2; i++)
|
| + {
|
| + glBindTexture(GL_TEXTURE_2D, textures[1]);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, formats[i], 4, 4, 0, formats[i],
|
| + GL_FLOAT, NULL);
|
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
| + GL_TEXTURE_2D, textures[1], 0);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
|
| + glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
| +
|
| + //query GL_FRAMEBUFFER_ATTACHMENT Parameters
|
| + GLint params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, ¶ms);
|
| + EXPECT_EQ(GL_TEXTURE, params);
|
| + params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, ¶ms);
|
| + EXPECT_EQ(textures[1], static_cast<GLuint>(params));
|
| + params = 0;
|
| + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
|
| + GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT,
|
| + ¶ms);
|
| + EXPECT_EQ(GL_FLOAT, params);
|
| +
|
| + float pixels[1 * 4] = {0.25, 0.5, 2.0, 4.0};
|
| + glBindTexture(GL_TEXTURE_2D, textures[0]);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
|
| + GL_FLOAT, pixels);
|
| + glDrawArrays(GL_TRIANGLES, 0, 6);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| +
|
| + // Check glReadPixels
|
| + // Implementation-chosen format
|
| + GLint attachmentType = 0;
|
| + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &attachmentType);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + GLint attachmentFormat = 0;
|
| + glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &attachmentFormat);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + if (attachmentType == GL_FLOAT) {
|
| + float actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_FLOAT, actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(1, actual_pixels[i]);
|
| + }
|
| + if (attachmentType == GL_HALF_FLOAT_OES) {
|
| + uint16 actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_HALF_FLOAT_OES,
|
| + actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(15360, actual_pixels[i]);
|
| + }
|
| + if (attachmentType == GL_UNSIGNED_BYTE) {
|
| + uint8 actual_pixels[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, attachmentFormat, GL_UNSIGNED_BYTE,
|
| + actual_pixels);
|
| + EXPECT_TRUE(GL_NO_ERROR == glGetError());
|
| + for (unsigned int i = 0; i < 4; i++)
|
| + EXPECT_EQ(255, actual_pixels[i]);
|
| + }
|
| +
|
| + // RGBA/FLOAT
|
| + float actual_pixels_[1 * 4] = {0, 0, 0, 0};
|
| + glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, actual_pixels_);
|
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR);
|
| + for (int i = 0; i < 4; i++)
|
| + EXPECT_EQ(1, actual_pixels_[i]);
|
| +
|
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
| + GL_TEXTURE_2D, 0, 0);
|
| + }
|
| +}
|
| +
|
| +} // namespace gpu
|
|
|