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

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

Issue 14402003: Add OES_texture_half_float extension support in Chromium for desktop GL implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove support for glReadPixels and update test cases Created 7 years, 8 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
Index: gpu/command_buffer/tests/gl_oes_texture_half_float_unittest.cc
diff --git a/gpu/command_buffer/tests/gl_oes_texture_half_float_unittest.cc b/gpu/command_buffer/tests/gl_oes_texture_half_float_unittest.cc
new file mode 100755
index 0000000000000000000000000000000000000000..a5203a45dd559f3dcb5b2eadd30c413da2aca40b
--- /dev/null
+++ b/gpu/command_buffer/tests/gl_oes_texture_half_float_unittest.cc
@@ -0,0 +1,130 @@
+// 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 a_position;
+ void main() {
+ gl_Position = a_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 GLOesTextureHalfFloatTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ gl_.Initialize(GLManager::Options());
+
+ glGenTextures(2, textures);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textures[1]);
+
+ // Some drivers (NVidia/SGX) require texture settings to be a certain way or
+ // they won't report FRAMEBUFFER_COMPLETE.
+ 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);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
+ textures[1], 0);
+ }
+
+ virtual void TearDown() {
+ glDeleteTextures(2, textures);
+ glDeleteFramebuffers(1, &fbo);
+ gl_.Destroy();
+ }
+
+ GLManager gl_;
+ GLuint textures[2];
+ GLuint fbo;
+};
+
+TEST_F(GLOesTextureHalfFloatTest, TexImage2DAndTexSubImage2D) {
+ if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) {
+ return;
+ }
+
+ // (0.25, 0.5, 2.0, 4.0)
+ static int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 };
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+
+ GLenum formats[5] = { GL_RGBA, GL_RGB, GL_LUMINANCE_ALPHA,
+ GL_LUMINANCE, GL_ALPHA };
+ for (unsigned int i = 0; i < 5; i++) {
+ glTexImage2D(GL_TEXTURE_2D, 0, formats[i], 1, 1, 0, formats[i],
+ GL_HALF_FLOAT_OES, pixels);
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, formats[i],
+ GL_HALF_FLOAT_OES, pixels);
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+ }
+}
+
+TEST_F(GLOesTextureHalfFloatTest, OesTextureHalfFloatTest) {
+ if (!GLTestHelper::HasExtension("GL_OES_texture_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, "a_position");
+ GLTestHelper::SetupUnitQuad(position_loc);
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+
+ glBindTexture(GL_TEXTURE_2D, textures[1]);
+ glTexImage2D(
+ GL_TEXTURE_2D, 0, GL_RGBA, 4, 4,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
+ glCheckFramebufferStatus(GL_FRAMEBUFFER));
+
+ // (0.25, 0.5, 2.0, 4.0)
+ static 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);
+ // check pixels
+ uint8 expect_pixels[1 * 4] = { 255, 255, 255, 255 };
+ GLTestHelper::CheckPixels(0, 0, 4, 4, 0, expect_pixels);
+
+ glTexSubImage2D(
+ GL_TEXTURE_2D, 0, 0, 0, 1, 1,
+ GL_RGBA, GL_HALF_FLOAT_OES, pixels);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+ // check pixels
+ GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expect_pixels);
+ EXPECT_TRUE(glGetError() == GL_NO_ERROR);
+}
+
+} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698