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

Side by Side Diff: gpu/command_buffer/tests/gl_stream_draw_unittest.cc

Issue 2602563002: Refactor DrawTextureQuad and CheckPixels in gl_tests util (Closed)
Patch Set: git cl format Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h> 6 #include <GLES2/gl2ext.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "gpu/command_buffer/tests/gl_manager.h" 9 #include "gpu/command_buffer/tests/gl_manager.h"
10 #include "gpu/command_buffer/tests/gl_test_utils.h" 10 #include "gpu/command_buffer/tests/gl_test_utils.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 static uint8_t expected_green[4] = { 70 static uint8_t expected_green[4] = {
71 0, 255, 0, 255, 71 0, 255, 0, 255,
72 }; 72 };
73 73
74 GLuint program = SetupProgram(); 74 GLuint program = SetupProgram();
75 GLuint position_loc = glGetAttribLocation(program, "a_position"); 75 GLuint position_loc = glGetAttribLocation(program, "a_position");
76 GLuint color_loc = glGetAttribLocation(program, "a_color"); 76 GLuint color_loc = glGetAttribLocation(program, "a_color");
77 GLTestHelper::SetupUnitQuad(position_loc); 77 GLTestHelper::SetupUnitQuad(position_loc);
78 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_red, GL_STREAM_DRAW); 78 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_red, GL_STREAM_DRAW);
79 glDrawArrays(GL_TRIANGLES, 0, 6); 79 glDrawArrays(GL_TRIANGLES, 0, 6);
80 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red)); 80 EXPECT_TRUE(
81 GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red, nullptr));
81 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW); 82 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW);
82 glDrawArrays(GL_TRIANGLES, 0, 6); 83 glDrawArrays(GL_TRIANGLES, 0, 6);
83 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green)); 84 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green,
85 nullptr));
84 86
85 GLTestHelper::CheckGLError("no errors", __LINE__); 87 GLTestHelper::CheckGLError("no errors", __LINE__);
86 } 88 }
87 89
88 // http://crbug.com/281565 90 // http://crbug.com/281565
89 #if !defined(OS_ANDROID) 91 #if !defined(OS_ANDROID)
90 TEST_F(GLStreamDrawTest, DrawElements) { 92 TEST_F(GLStreamDrawTest, DrawElements) {
91 static GLfloat float_red[4] = { 1.0f, 0.0f, 0.0f, 1.0f, }; 93 static GLfloat float_red[4] = { 1.0f, 0.0f, 0.0f, 1.0f, };
92 static GLfloat float_green[4] = { 0.0f, 1.0f, 0.0f, 1.0f, }; 94 static GLfloat float_green[4] = { 0.0f, 1.0f, 0.0f, 1.0f, };
93 static uint8_t expected_red[4] = { 95 static uint8_t expected_red[4] = {
94 255, 0, 0, 255, 96 255, 0, 0, 255,
95 }; 97 };
96 static uint8_t expected_green[4] = { 98 static uint8_t expected_green[4] = {
97 0, 255, 0, 255, 99 0, 255, 0, 255,
98 }; 100 };
99 101
100 GLuint program = SetupProgram(); 102 GLuint program = SetupProgram();
101 GLuint position_loc = glGetAttribLocation(program, "a_position"); 103 GLuint position_loc = glGetAttribLocation(program, "a_position");
102 GLuint color_loc = glGetAttribLocation(program, "a_color"); 104 GLuint color_loc = glGetAttribLocation(program, "a_color");
103 GLTestHelper::SetupUnitQuad(position_loc); 105 GLTestHelper::SetupUnitQuad(position_loc);
104 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_red, GL_STREAM_DRAW); 106 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_red, GL_STREAM_DRAW);
105 107
106 GLuint index_buffer = 0; 108 GLuint index_buffer = 0;
107 glGenBuffers(1, &index_buffer); 109 glGenBuffers(1, &index_buffer);
108 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer); 110 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
109 static GLubyte indices[] = { 0, 1, 2, 3, 4, 5, }; 111 static GLubyte indices[] = { 0, 1, 2, 3, 4, 5, };
110 glBufferData( 112 glBufferData(
111 GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STREAM_DRAW); 113 GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STREAM_DRAW);
112 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, NULL); 114 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, nullptr);
113 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red)); 115 EXPECT_TRUE(
116 GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red, nullptr));
114 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW); 117 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW);
115 118
116 glBufferData( 119 glBufferData(
117 GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 120 GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
118 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, NULL); 121 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, nullptr);
119 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green)); 122 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green,
123 nullptr));
120 124
121 GLTestHelper::CheckGLError("no errors", __LINE__); 125 GLTestHelper::CheckGLError("no errors", __LINE__);
122 } 126 }
123 #endif 127 #endif
124 128
125 TEST_F(GLStreamDrawTest, VertexArrayObjects) { 129 TEST_F(GLStreamDrawTest, VertexArrayObjects) {
126 if (!GLTestHelper::HasExtension("GL_OES_vertex_array_object")) { 130 if (!GLTestHelper::HasExtension("GL_OES_vertex_array_object")) {
127 return; 131 return;
128 } 132 }
129 133
(...skipping 19 matching lines...) Expand all
149 153
150 glBindVertexArrayOES(vaos[1]); 154 glBindVertexArrayOES(vaos[1]);
151 glBindBuffer(GL_ARRAY_BUFFER, position_buffer); 155 glBindBuffer(GL_ARRAY_BUFFER, position_buffer);
152 glEnableVertexAttribArray(position_loc); 156 glEnableVertexAttribArray(position_loc);
153 glVertexAttribPointer(position_loc, 2, GL_FLOAT, GL_FALSE, 0, 0); 157 glVertexAttribPointer(position_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
154 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW); 158 GLTestHelper::SetupColorsForUnitQuad(color_loc, float_green, GL_STATIC_DRAW);
155 159
156 for (int ii = 0; ii < 2; ++ii) { 160 for (int ii = 0; ii < 2; ++ii) {
157 glBindVertexArrayOES(vaos[0]); 161 glBindVertexArrayOES(vaos[0]);
158 glDrawArrays(GL_TRIANGLES, 0, 6); 162 glDrawArrays(GL_TRIANGLES, 0, 6);
159 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red)); 163 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_red,
164 nullptr));
160 165
161 glBindVertexArrayOES(vaos[1]); 166 glBindVertexArrayOES(vaos[1]);
162 glDrawArrays(GL_TRIANGLES, 0, 6); 167 glDrawArrays(GL_TRIANGLES, 0, 6);
163 EXPECT_TRUE( 168 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green,
164 GLTestHelper::CheckPixels(0, 0, kSize, kSize, 0, expected_green)); 169 nullptr));
165 } 170 }
166 171
167 GLTestHelper::CheckGLError("no errors", __LINE__); 172 GLTestHelper::CheckGLError("no errors", __LINE__);
168 } 173 }
169 174
170 } // namespace gpu 175 } // namespace gpu
171 176
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698