Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: gpu/command_buffer/tests/gl_ext_color_buffer_half_float_unittest.cc

Issue 18246005: Add EXT_color_buffer_half_float extension support in GPU commandbuffer service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase the patch Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc ('k') | gpu/gpu.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/tests/gl_ext_color_buffer_half_float_unittest.cc
diff --git a/gpu/command_buffer/tests/gl_ext_color_buffer_half_float_unittest.cc b/gpu/command_buffer/tests/gl_ext_color_buffer_half_float_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea577e7fd050ee57d229e64b127a33f577723190
--- /dev/null
+++ b/gpu/command_buffer/tests/gl_ext_color_buffer_half_float_unittest.cc
@@ -0,0 +1,277 @@
+// 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 GLExtColorBufferHalfFloatTest : 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 GLExtColorBufferHalfFloatTest::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(GLExtColorBufferHalfFloatTest, RenderBuffers) {
+ if (!GLTestHelper::HasExtension("EXT_color_buffer_half_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_RGBA16F_EXT, GL_RGB16F_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, &params);
+ EXPECT_EQ(GL_RENDERBUFFER, params);
+ params = 0;
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &params);
+ EXPECT_EQ(renderbuffer_id, static_cast<GLuint>(params));
+ params = 0;
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT,
+ &params);
+ EXPECT_EQ(componentType[i], params);
+
+ // (0.25, 0.5, 2.0, 4.0) / (0x3400, 0x3800, 0x4000, 0x4400)
+ int16 pixels[1 * 4] = {0x3400, 0x3800, 0x4000, 0x4400};
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
+ 0, GL_RGBA, GL_HALF_FLOAT_OES, pixels);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+
+ // Check glReadPixels
+ if (internalFormats[i] != GL_RGBA16F_EXT
+ && internalFormats[i] != GL_RGB16F_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(GLExtColorBufferHalfFloatTest, Textures) {
+ if (!GLTestHelper::HasExtension("EXT_color_buffer_half_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_HALF_FLOAT_OES, 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, &params);
+ EXPECT_EQ(GL_TEXTURE, params);
+ params = 0;
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &params);
+ EXPECT_EQ(textures[1], static_cast<GLuint>(params));
+ params = 0;
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT,
+ &params);
+ EXPECT_EQ(GL_FLOAT, params);
+
+ // (0.25, 0.5, 0.5, 4.0) / (0x3400, 0x3800, 0x3800, 0x4400)
+ int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 };
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
+ GL_HALF_FLOAT_OES, 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
« no previous file with comments | « gpu/command_buffer/tests/gl_ANGLE_color_buffer_float_unittest.cc ('k') | gpu/gpu.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698