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

Side by Side Diff: client/deps/glbench/src/trianglesetuptest.cc

Issue 2965008: Converted triangle setup test to GLES2. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: renamed shader variables Created 10 years, 5 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
« no previous file with comments | « client/deps/glbench/src/main.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "main.h" 7 #include "main.h"
8 #include "testbase.h" 8 #include "testbase.h"
9 #include "utils.h" 9 #include "utils.h"
10 10
11 11
12 namespace glbench { 12 namespace glbench {
13 13
14 14
15 class TriangleSetupTest : public DrawElementsTestFunc { 15 class TriangleSetupTest : public DrawElementsTestFunc {
16 public: 16 public:
17 TriangleSetupTest() {} 17 TriangleSetupTest() {}
18 virtual ~TriangleSetupTest() {} 18 virtual ~TriangleSetupTest() {}
19 virtual bool Run(); 19 virtual bool Run();
20 virtual const char* Name() const { return "triangle_setup"; } 20 virtual const char* Name() const { return "triangle_setup"; }
21 21
22 private: 22 private:
23 DISALLOW_COPY_AND_ASSIGN(TriangleSetupTest); 23 DISALLOW_COPY_AND_ASSIGN(TriangleSetupTest);
24 }; 24 };
25 25
26 const char* kVertexShader =
27 "attribute vec4 c;"
28 "void main() {"
29 " gl_Position = c;"
30 "}";
31
32 const char* kFragmentShader =
33 "uniform vec4 color;"
34 "void main() {"
35 " gl_FragColor = color;"
36 "}";
26 37
27 bool TriangleSetupTest::Run() { 38 bool TriangleSetupTest::Run() {
28 glViewport(-g_width, -g_height, g_width*2, g_height*2); 39 glViewport(-g_width, -g_height, g_width*2, g_height*2);
29 40
30 // Larger meshes make this test too slow for devices that do 1 mtri/sec. 41 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
31 GLint width = 64; 42 GLint width = 64;
32 GLint height = 64; 43 GLint height = 64;
33 44
34 GLfloat *vertices = NULL; 45 GLfloat *vertices = NULL;
35 GLsizeiptr vertex_buffer_size = 0; 46 GLsizeiptr vertex_buffer_size = 0;
36 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height, 47 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
37 width, height); 48 width, height);
38 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, 49 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
39 vertex_buffer_size, vertices); 50 vertex_buffer_size, vertices);
40 glVertexPointer(2, GL_FLOAT, 0, 0); 51
41 glEnableClientState(GL_VERTEX_ARRAY); 52 GLuint program =
53 InitShaderProgram(kVertexShader, kFragmentShader);
54 GLint attribute_index = glGetAttribLocation(program, "c");
55 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
56 glEnableVertexAttribArray(attribute_index);
57
58 GLint color_uniform = glGetUniformLocation(program, "color");
42 59
43 GLuint *indices = NULL; 60 GLuint *indices = NULL;
44 GLuint index_buffer = 0; 61 GLuint index_buffer = 0;
45 GLsizeiptr index_buffer_size = 0; 62 GLsizeiptr index_buffer_size = 0;
46 63
47 { 64 {
65 const GLfloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
66 glUniform4fv(color_uniform, 1, white);
48 count_ = CreateMesh(&indices, &index_buffer_size, width, height, 0); 67 count_ = CreateMesh(&indices, &index_buffer_size, width, height, 0);
49 68
50 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, 69 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
51 index_buffer_size, indices); 70 index_buffer_size, indices);
52 RunTest(this, "mtri_sec_triangle_setup", count_ / 3, true); 71 RunTest(this, "mtri_sec_triangle_setup", count_ / 3, true);
53 glEnable(GL_CULL_FACE); 72 glEnable(GL_CULL_FACE);
54 RunTest(this, "mtri_sec_triangle_setup_all_culled", count_ / 3, true); 73 RunTest(this, "mtri_sec_triangle_setup_all_culled", count_ / 3, true);
55 glDisable(GL_CULL_FACE); 74 glDisable(GL_CULL_FACE);
56 75
57 glDeleteBuffers(1, &index_buffer); 76 glDeleteBuffers(1, &index_buffer);
58 delete[] indices; 77 delete[] indices;
59 } 78 }
60 79
61 { 80 {
62 glColor4f(0.f, 1.f, 1.f, 1.f); 81 const GLfloat cyan[4] = {0.0f, 1.0f, 1.0f, 1.0f};
82 glUniform4fv(color_uniform, 1, cyan);
63 count_ = CreateMesh(&indices, &index_buffer_size, width, height, 83 count_ = CreateMesh(&indices, &index_buffer_size, width, height,
64 RAND_MAX / 2); 84 RAND_MAX / 2);
65 85
66 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, 86 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
67 index_buffer_size, indices); 87 index_buffer_size, indices);
68 glEnable(GL_CULL_FACE); 88 glEnable(GL_CULL_FACE);
69 RunTest(this, "mtri_sec_triangle_setup_half_culled", count_ / 3, true); 89 RunTest(this, "mtri_sec_triangle_setup_half_culled", count_ / 3, true);
70 90
71 glDeleteBuffers(1, &index_buffer); 91 glDeleteBuffers(1, &index_buffer);
72 delete[] indices; 92 delete[] indices;
73 } 93 }
74 94
95 glDeleteProgram(program);
75 glDeleteBuffers(1, &vertex_buffer); 96 glDeleteBuffers(1, &vertex_buffer);
76 delete[] vertices; 97 delete[] vertices;
77 return true; 98 return true;
78 } 99 }
79 100
80 101
81 TestBase* GetTriangleSetupTest() { 102 TestBase* GetTriangleSetupTest() {
82 return new TriangleSetupTest; 103 return new TriangleSetupTest;
83 } 104 }
84 105
85 106
86 } // namespace glbench 107 } // namespace glbench
OLDNEW
« no previous file with comments | « client/deps/glbench/src/main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698