blob: e4a46d835d27cac5fdc439b66ab027d5f7a7a8a1 [file] [log] [blame]
Alexey Marinichev9f9b8732010-05-20 19:33:44 -07001// 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 <stdlib.h>
6
7#include "main.h"
8#include "testbase.h"
9#include "utils.h"
10
11
12namespace glbench {
13
14
15class TriangleSetupTest : public DrawElementsTestFunc {
16 public:
17 TriangleSetupTest() {}
18 virtual ~TriangleSetupTest() {}
19 virtual bool Run();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070020 virtual const char* Name() const { return "triangle_setup"; }
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070021
22 private:
23 DISALLOW_COPY_AND_ASSIGN(TriangleSetupTest);
24};
25
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070026const char* kVertexShader =
27 "attribute vec4 c;"
28 "void main() {"
29 " gl_Position = c;"
30 "}";
31
32const char* kFragmentShader =
33 "uniform vec4 color;"
34 "void main() {"
35 " gl_FragColor = color;"
36 "}";
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070037
38bool TriangleSetupTest::Run() {
39 glViewport(-g_width, -g_height, g_width*2, g_height*2);
40
41 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
42 GLint width = 64;
43 GLint height = 64;
44
45 GLfloat *vertices = NULL;
46 GLsizeiptr vertex_buffer_size = 0;
47 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
48 width, height);
49 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
50 vertex_buffer_size, vertices);
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070051
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");
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070059
60 GLuint *indices = NULL;
61 GLuint index_buffer = 0;
62 GLsizeiptr index_buffer_size = 0;
63
64 {
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070065 const GLfloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
66 glUniform4fv(color_uniform, 1, white);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070067 count_ = CreateMesh(&indices, &index_buffer_size, width, height, 0);
68
69 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
70 index_buffer_size, indices);
71 RunTest(this, "mtri_sec_triangle_setup", count_ / 3, true);
72 glEnable(GL_CULL_FACE);
73 RunTest(this, "mtri_sec_triangle_setup_all_culled", count_ / 3, true);
74 glDisable(GL_CULL_FACE);
75
76 glDeleteBuffers(1, &index_buffer);
77 delete[] indices;
78 }
79
80 {
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070081 const GLfloat cyan[4] = {0.0f, 1.0f, 1.0f, 1.0f};
82 glUniform4fv(color_uniform, 1, cyan);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070083 count_ = CreateMesh(&indices, &index_buffer_size, width, height,
84 RAND_MAX / 2);
85
86 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
87 index_buffer_size, indices);
88 glEnable(GL_CULL_FACE);
89 RunTest(this, "mtri_sec_triangle_setup_half_culled", count_ / 3, true);
90
91 glDeleteBuffers(1, &index_buffer);
92 delete[] indices;
93 }
94
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070095 glDeleteProgram(program);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070096 glDeleteBuffers(1, &vertex_buffer);
97 delete[] vertices;
98 return true;
99}
100
101
102TestBase* GetTriangleSetupTest() {
103 return new TriangleSetupTest;
104}
105
106
107} // namespace glbench