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

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

Issue 2123013: Split tests into individual files. Got rid of globals by converting them to classes. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: addressed comments Created 10 years, 7 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/all_tests.h ('k') | client/deps/glbench/src/bench.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "main.h"
6 #include "utils.h"
7 #include "testbase.h"
8
9
10 namespace glbench {
11
12 class AttributeFetchShaderTest : public DrawElementsTestFunc {
13 public:
14 AttributeFetchShaderTest() {}
15 virtual ~AttributeFetchShaderTest() {}
16 virtual bool Run();
17
18 private:
19 DISALLOW_COPY_AND_ASSIGN(AttributeFetchShaderTest);
20 };
21
22
23 const char *simple_vertex_shader =
24 "attribute vec4 c1;"
25 "void main() {"
26 " gl_Position = c1;"
27 "}";
28
29 const char *simple_vertex_shader_2_attr =
30 "attribute vec4 c1;"
31 "attribute vec4 c2;"
32 "void main() {"
33 " gl_Position = c1+c2;"
34 "}";
35
36 const char *simple_vertex_shader_4_attr =
37 "attribute vec4 c1;"
38 "attribute vec4 c2;"
39 "attribute vec4 c3;"
40 "attribute vec4 c4;"
41 "void main() {"
42 " gl_Position = c1+c2+c3+c4;"
43 "}";
44
45 const char *simple_vertex_shader_8_attr =
46 "attribute vec4 c1;"
47 "attribute vec4 c2;"
48 "attribute vec4 c3;"
49 "attribute vec4 c4;"
50 "attribute vec4 c5;"
51 "attribute vec4 c6;"
52 "attribute vec4 c7;"
53 "attribute vec4 c8;"
54 "void main() {"
55 " gl_Position = c1+c2+c3+c4+c5+c6+c7+c8;"
56 "}";
57
58 const char *simple_fragment_shader =
59 "void main() {"
60 " gl_FragColor = vec4(0.5);"
61 "}";
62
63 GLuint AttributeFetchShaderProgram(int attribute_count,
64 GLuint vertex_buffers[]) {
65 const char *vertex_shader = NULL;
66 switch (attribute_count) {
67 case 1: vertex_shader = simple_vertex_shader; break;
68 case 2: vertex_shader = simple_vertex_shader_2_attr; break;
69 case 4: vertex_shader = simple_vertex_shader_4_attr; break;
70 case 8: vertex_shader = simple_vertex_shader_8_attr; break;
71 default: return 0;
72 }
73 GLuint program =
74 InitShaderProgram(vertex_shader, simple_fragment_shader);
75
76 for (int i = 0; i < attribute_count; i++) {
77 char attribute[] = "c_";
78 attribute[1] = '1' + i;
79 int attribute_index = glGetAttribLocation(program, attribute);
80 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffers[i]);
81 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
82 glEnableVertexAttribArray(attribute_index);
83 }
84
85 return program;
86 }
87
88 bool AttributeFetchShaderTest::Run() {
89 GLint width = 64;
90 GLint height = 64;
91
92 glViewport(-g_width, -g_height, g_width*2, g_height*2);
93
94 GLfloat *vertices = NULL;
95 GLsizeiptr vertex_buffer_size = 0;
96 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
97 width, height);
98 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
99 vertex_buffer_size, vertices);
100
101 GLuint *indices = NULL;
102 GLuint index_buffer = 0;
103 GLsizeiptr index_buffer_size = 0;
104
105 // Everything will be back-face culled.
106 count_ = CreateMesh(&indices, &index_buffer_size, width, height, 0);
107 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
108 index_buffer_size, indices);
109
110 glEnable(GL_CULL_FACE);
111
112 GLuint vertex_buffers[8];
113 for (GLuint i = 0; i < sizeof(vertex_buffers)/sizeof(vertex_buffers[0]); i++)
114 vertex_buffers[i] = vertex_buffer;
115
116 GLuint program = AttributeFetchShaderProgram(1, vertex_buffers);
117 RunTest(this,
118 "mvtx_sec_attribute_fetch_shader", count_, true);
119 glDeleteProgram(program);
120
121 program = AttributeFetchShaderProgram(2, vertex_buffers);
122 RunTest(this,
123 "mvtx_sec_attribute_fetch_shader_2_attr", count_, true);
124 glDeleteProgram(program);
125
126 program = AttributeFetchShaderProgram(4, vertex_buffers);
127 RunTest(this,
128 "mvtx_sec_attribute_fetch_shader_4_attr", count_, true);
129 glDeleteProgram(program);
130
131 program = AttributeFetchShaderProgram(8, vertex_buffers);
132 RunTest(this,
133 "mvtx_sec_attribute_fetch_shader_8_attr", count_, true);
134 glDeleteProgram(program);
135
136 glDeleteBuffers(1, &index_buffer);
137 delete[] indices;
138
139 glDeleteBuffers(1, &vertex_buffer);
140 delete[] vertices;
141 return true;
142 }
143
144 TestBase* GetAttributeFetchShaderTest() {
145 return new AttributeFetchShaderTest();
146 }
147
148 } // namespace glbench
OLDNEW
« no previous file with comments | « client/deps/glbench/src/all_tests.h ('k') | client/deps/glbench/src/bench.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698