Chromium Code Reviews| 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..65cf3820c7b5aa5fbb5db4331853c3998296da35 |
| --- /dev/null |
| +++ b/gpu/command_buffer/tests/gl_oes_texture_half_float_unittest.cc |
| @@ -0,0 +1,205 @@ |
| +// 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; |
|
greggman
2013/05/02 16:37:26
nit: a_ for attribute, v_ for varying?
|
| + 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 GLOesTextureHalfFloatTest : 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); |
| + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| + textures[1], 0); |
|
greggman
2013/05/02 16:37:26
nit: indenting
|
| + } |
| + |
| + virtual void TearDown() { |
| + glDeleteTextures(2, textures); |
| + glDeleteFramebuffers(1, &fbo); |
| + gl_.Destroy(); |
| + } |
| + |
| + GLuint SetupUnitQuad(GLint position_location); |
| + |
| + GLManager gl_; |
| + GLuint textures[2]; |
| + GLuint fbo; |
| +}; |
| + |
| +GLuint GLOesTextureHalfFloatTest::SetupUnitQuad(GLint position_location) { |
|
greggman
2013/05/02 16:37:26
Can you just use GLTestHelper::SetupUnitQuad?
|
| + 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(GLOesTextureHalfFloatTest, TexImage2DAndTexSubImage2D) { |
| + if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { |
| + return; |
| + } |
| + |
| + // (0.25, 0.5, 2.0, 4.0) |
| + int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; |
|
greggman
2013/05/02 16:37:26
static?
|
| + 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, ReadPixels) { |
| + 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, "v_position"); |
| + 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_HALF_FLOAT_OES, NULL); |
| + // Direct return if GL_HALF_FLOAT_OES if not a renderable type. |
| + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) |
| + != static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE)) |
| + return; |
| + |
| + // (0.25, 0.5, 0.5, 4.0) / (0x3400, 0x3800, 0x3800, 0x4400) |
| + int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x3800, 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); |
| + |
| + uint16 actual_pixels[1 * 4] = { 0 }; |
| + glReadPixels( |
| + 0, 0, 1, 1, GL_RGBA, GL_HALF_FLOAT_OES, |
|
greggman
2013/05/02 16:37:26
AFAIK in GL ES 2.0 ReadPixels does not have to sup
|
| + actual_pixels); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + // (1.0, 1.0, 0.25, 1.0) / (15360, 15360, 13312, 15360) |
| + EXPECT_EQ(15360, actual_pixels[0]); |
| + EXPECT_EQ(15360, actual_pixels[1]); |
| + EXPECT_EQ(13312, actual_pixels[2]); |
| + EXPECT_EQ(15360, actual_pixels[3]); |
| +} |
| + |
| + |
| +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, "v_position"); |
| + 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) / (0x3400, 0x3800, 0x4000, 0x4400) |
| + int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; |
|
greggman
2013/05/02 16:37:26
static?
|
| + 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 actual_pixels[1 * 4] = { 0 }; |
|
greggman
2013/05/02 16:37:26
use GLTestHelper::CheckRect?
|
| + glReadPixels( |
| + 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| + actual_pixels); |
| + for (unsigned int i = 0; i < 4; i++) { |
| + EXPECT_EQ(255, actual_pixels[i]); |
| + } |
| + |
| + glTexSubImage2D( |
| + GL_TEXTURE_2D, 0, 0, 0, 1, 1, |
| + GL_RGBA, GL_HALF_FLOAT_OES, pixels); |
| + glDrawArrays(GL_TRIANGLES, 0, 6); |
| + // check pixels |
| + uint8 actual_pixels_sub[1 * 4] = { 0 }; |
| + glReadPixels( |
| + 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| + actual_pixels_sub); |
| + EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| + |
| + for (unsigned int i = 0; i < 4; i++) { |
|
greggman
2013/05/02 16:37:26
use GLTestHelper::CheckRect?
|
| + EXPECT_EQ(255, actual_pixels_sub[i]); |
| + } |
| +} |
| + |
| +} // namespace gpu |