OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #ifndef GL_GLEXT_PROTOTYPES |
| 6 #define GL_GLEXT_PROTOTYPES |
| 7 #endif |
| 8 |
| 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> |
| 11 |
| 12 #include "gpu/command_buffer/tests/gl_manager.h" |
| 13 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 #define SHADER(Src) #Src |
| 18 |
| 19 namespace gpu { |
| 20 |
| 21 static const char* v_shader_str = SHADER( |
| 22 attribute vec4 a_position; |
| 23 void main() { |
| 24 gl_Position = a_position; |
| 25 } |
| 26 ); |
| 27 |
| 28 static const char* f_shader_str = SHADER( |
| 29 uniform sampler2D u_texture; |
| 30 void main() { |
| 31 gl_FragColor = texture2D(u_texture, vec2(0.5, 0.5)) * |
| 32 vec4(4.0, 2.0, 0.5, 0.25); |
| 33 } |
| 34 ); |
| 35 |
| 36 class GLOesTextureHalfFloatTest : public testing::Test { |
| 37 protected: |
| 38 virtual void SetUp() { |
| 39 gl_.Initialize(GLManager::Options()); |
| 40 |
| 41 glGenTextures(2, textures); |
| 42 glActiveTexture(GL_TEXTURE0); |
| 43 glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 44 |
| 45 // Some drivers (NVidia/SGX) require texture settings to be a certain way or |
| 46 // they won't report FRAMEBUFFER_COMPLETE. |
| 47 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 48 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 51 |
| 52 glGenFramebuffers(1, &fbo); |
| 53 glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 54 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 55 textures[1], 0); |
| 56 } |
| 57 |
| 58 virtual void TearDown() { |
| 59 glDeleteTextures(2, textures); |
| 60 glDeleteFramebuffers(1, &fbo); |
| 61 gl_.Destroy(); |
| 62 } |
| 63 |
| 64 GLManager gl_; |
| 65 GLuint textures[2]; |
| 66 GLuint fbo; |
| 67 }; |
| 68 |
| 69 TEST_F(GLOesTextureHalfFloatTest, TexImage2DAndTexSubImage2D) { |
| 70 if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { |
| 71 return; |
| 72 } |
| 73 |
| 74 // (0.25, 0.5, 2.0, 4.0) |
| 75 static int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; |
| 76 glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 77 |
| 78 GLenum formats[5] = { GL_RGBA, GL_RGB, GL_LUMINANCE_ALPHA, |
| 79 GL_LUMINANCE, GL_ALPHA }; |
| 80 for (unsigned int i = 0; i < 5; i++) { |
| 81 glTexImage2D(GL_TEXTURE_2D, 0, formats[i], 1, 1, 0, formats[i], |
| 82 GL_HALF_FLOAT_OES, pixels); |
| 83 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 84 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, formats[i], |
| 85 GL_HALF_FLOAT_OES, pixels); |
| 86 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 87 } |
| 88 } |
| 89 |
| 90 TEST_F(GLOesTextureHalfFloatTest, OesTextureHalfFloatTest) { |
| 91 if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { |
| 92 return; |
| 93 } |
| 94 |
| 95 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); |
| 96 glUseProgram(program); |
| 97 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 98 |
| 99 GLint position_loc = glGetAttribLocation(program, "a_position"); |
| 100 GLTestHelper::SetupUnitQuad(position_loc); |
| 101 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 102 |
| 103 glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 104 glTexImage2D( |
| 105 GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, |
| 106 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 107 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 108 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 109 |
| 110 // (0.25, 0.5, 2.0, 4.0) |
| 111 static int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; |
| 112 glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 113 glTexImage2D( |
| 114 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, |
| 115 0, GL_RGBA, GL_HALF_FLOAT_OES, pixels); |
| 116 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 117 // check pixels |
| 118 uint8 expect_pixels[1 * 4] = { 255, 255, 255, 255 }; |
| 119 GLTestHelper::CheckPixels(0, 0, 4, 4, 0, expect_pixels); |
| 120 |
| 121 glTexSubImage2D( |
| 122 GL_TEXTURE_2D, 0, 0, 0, 1, 1, |
| 123 GL_RGBA, GL_HALF_FLOAT_OES, pixels); |
| 124 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 125 // check pixels |
| 126 GLTestHelper::CheckPixels(0, 0, 1, 1, 0, expect_pixels); |
| 127 EXPECT_TRUE(glGetError() == GL_NO_ERROR); |
| 128 } |
| 129 |
| 130 } // namespace gpu |
OLD | NEW |