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 v_position; | |
greggman
2013/05/02 16:37:26
nit: a_ for attribute, v_ for varying?
| |
23 void main() { | |
24 gl_Position = v_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 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
45 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
48 | |
49 glGenFramebuffers(1, &fbo); | |
50 glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
51 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | |
52 textures[1], 0); | |
greggman
2013/05/02 16:37:26
nit: indenting
| |
53 } | |
54 | |
55 virtual void TearDown() { | |
56 glDeleteTextures(2, textures); | |
57 glDeleteFramebuffers(1, &fbo); | |
58 gl_.Destroy(); | |
59 } | |
60 | |
61 GLuint SetupUnitQuad(GLint position_location); | |
62 | |
63 GLManager gl_; | |
64 GLuint textures[2]; | |
65 GLuint fbo; | |
66 }; | |
67 | |
68 GLuint GLOesTextureHalfFloatTest::SetupUnitQuad(GLint position_location) { | |
greggman
2013/05/02 16:37:26
Can you just use GLTestHelper::SetupUnitQuad?
| |
69 GLuint vbo = 0; | |
70 glGenBuffers(1, &vbo); | |
71 glBindBuffer(GL_ARRAY_BUFFER, vbo); | |
72 static float vertices[] = { | |
73 1.0f, 1.0f, 1.0f, | |
74 -1.0f, 1.0f, 0.0f, | |
75 -1.0f, -1.0f, -1.0f, | |
76 1.0f, 1.0f, 1.0f, | |
77 -1.0f, -1.0f, -1.0f, | |
78 1.0f, -1.0f, 0.0f, | |
79 }; | |
80 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); | |
81 glEnableVertexAttribArray(position_location); | |
82 glVertexAttribPointer(position_location, 3, GL_FLOAT, GL_FALSE, 0, 0); | |
83 | |
84 return vbo; | |
85 } | |
86 | |
87 TEST_F(GLOesTextureHalfFloatTest, TexImage2DAndTexSubImage2D) { | |
88 if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { | |
89 return; | |
90 } | |
91 | |
92 // (0.25, 0.5, 2.0, 4.0) | |
93 int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; | |
greggman
2013/05/02 16:37:26
static?
| |
94 glBindTexture(GL_TEXTURE_2D, textures[0]); | |
95 | |
96 GLenum formats[5] = { GL_RGBA, GL_RGB, GL_LUMINANCE_ALPHA, | |
97 GL_LUMINANCE, GL_ALPHA }; | |
98 for (unsigned int i = 0; i < 5; i++) { | |
99 glTexImage2D(GL_TEXTURE_2D, 0, formats[i], 1, 1, 0, formats[i], | |
100 GL_HALF_FLOAT_OES, pixels); | |
101 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
102 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, formats[i], | |
103 GL_HALF_FLOAT_OES, pixels); | |
104 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
105 } | |
106 } | |
107 | |
108 TEST_F(GLOesTextureHalfFloatTest, ReadPixels) { | |
109 if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { | |
110 return; | |
111 } | |
112 | |
113 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); | |
114 glUseProgram(program); | |
115 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
116 | |
117 GLint position_loc = glGetAttribLocation(program, "v_position"); | |
118 SetupUnitQuad(position_loc); | |
119 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
120 | |
121 glBindTexture(GL_TEXTURE_2D, textures[1]); | |
122 glTexImage2D( | |
123 GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, | |
124 0, GL_RGBA, GL_HALF_FLOAT_OES, NULL); | |
125 // Direct return if GL_HALF_FLOAT_OES if not a renderable type. | |
126 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) | |
127 != static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE)) | |
128 return; | |
129 | |
130 // (0.25, 0.5, 0.5, 4.0) / (0x3400, 0x3800, 0x3800, 0x4400) | |
131 int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x3800, 0x4400 }; | |
132 glBindTexture(GL_TEXTURE_2D, textures[0]); | |
133 glTexImage2D( | |
134 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, | |
135 0, GL_RGBA, GL_HALF_FLOAT_OES, pixels); | |
136 | |
137 glDrawArrays(GL_TRIANGLES, 0, 6); | |
138 | |
139 uint16 actual_pixels[1 * 4] = { 0 }; | |
140 glReadPixels( | |
141 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
| |
142 actual_pixels); | |
143 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
144 | |
145 // (1.0, 1.0, 0.25, 1.0) / (15360, 15360, 13312, 15360) | |
146 EXPECT_EQ(15360, actual_pixels[0]); | |
147 EXPECT_EQ(15360, actual_pixels[1]); | |
148 EXPECT_EQ(13312, actual_pixels[2]); | |
149 EXPECT_EQ(15360, actual_pixels[3]); | |
150 } | |
151 | |
152 | |
153 TEST_F(GLOesTextureHalfFloatTest, OesTextureHalfFloatTest) { | |
154 if (!GLTestHelper::HasExtension("GL_OES_texture_half_float")) { | |
155 return; | |
156 } | |
157 | |
158 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); | |
159 glUseProgram(program); | |
160 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
161 | |
162 GLint position_loc = glGetAttribLocation(program, "v_position"); | |
163 SetupUnitQuad(position_loc); | |
164 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
165 | |
166 glBindTexture(GL_TEXTURE_2D, textures[1]); | |
167 glTexImage2D( | |
168 GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, | |
169 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
170 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
171 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
172 | |
173 // (0.25, 0.5, 2.0, 4.0) / (0x3400, 0x3800, 0x4000, 0x4400) | |
174 int16 pixels[1 * 4] = { 0x3400, 0x3800, 0x4000, 0x4400 }; | |
greggman
2013/05/02 16:37:26
static?
| |
175 glBindTexture(GL_TEXTURE_2D, textures[0]); | |
176 glTexImage2D( | |
177 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, | |
178 0, GL_RGBA, GL_HALF_FLOAT_OES, pixels); | |
179 glDrawArrays(GL_TRIANGLES, 0, 6); | |
180 // check pixels | |
181 uint8 actual_pixels[1 * 4] = { 0 }; | |
greggman
2013/05/02 16:37:26
use GLTestHelper::CheckRect?
| |
182 glReadPixels( | |
183 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, | |
184 actual_pixels); | |
185 for (unsigned int i = 0; i < 4; i++) { | |
186 EXPECT_EQ(255, actual_pixels[i]); | |
187 } | |
188 | |
189 glTexSubImage2D( | |
190 GL_TEXTURE_2D, 0, 0, 0, 1, 1, | |
191 GL_RGBA, GL_HALF_FLOAT_OES, pixels); | |
192 glDrawArrays(GL_TRIANGLES, 0, 6); | |
193 // check pixels | |
194 uint8 actual_pixels_sub[1 * 4] = { 0 }; | |
195 glReadPixels( | |
196 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, | |
197 actual_pixels_sub); | |
198 EXPECT_TRUE(glGetError() == GL_NO_ERROR); | |
199 | |
200 for (unsigned int i = 0; i < 4; i++) { | |
greggman
2013/05/02 16:37:26
use GLTestHelper::CheckRect?
| |
201 EXPECT_EQ(255, actual_pixels_sub[i]); | |
202 } | |
203 } | |
204 | |
205 } // namespace gpu | |
OLD | NEW |