Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 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 <stdlib.h> |
| 6 | |
| 7 | #include "main.h" |
| 8 | #include "testbase.h" |
| 9 | #include "utils.h" |
| 10 | |
| 11 | |
| 12 | namespace glbench { |
| 13 | |
| 14 | |
| 15 | class TriangleSetupTest : public DrawElementsTestFunc { |
| 16 | public: |
| 17 | TriangleSetupTest() {} |
| 18 | virtual ~TriangleSetupTest() {} |
| 19 | virtual bool Run(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 20 | virtual const char* Name() const { return "triangle_setup"; } |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 21 | |
| 22 | private: |
| 23 | DISALLOW_COPY_AND_ASSIGN(TriangleSetupTest); |
| 24 | }; |
| 25 | |
Alexey Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame^] | 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 | "}"; |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 37 | |
| 38 | bool 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 Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame^] | 51 | |
| 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 Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 59 | |
| 60 | GLuint *indices = NULL; |
| 61 | GLuint index_buffer = 0; |
| 62 | GLsizeiptr index_buffer_size = 0; |
| 63 | |
| 64 | { |
Alexey Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame^] | 65 | const GLfloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 66 | glUniform4fv(color_uniform, 1, white); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 67 | 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 Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame^] | 81 | const GLfloat cyan[4] = {0.0f, 1.0f, 1.0f, 1.0f}; |
| 82 | glUniform4fv(color_uniform, 1, cyan); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 83 | 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 Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame^] | 95 | glDeleteProgram(program); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 96 | glDeleteBuffers(1, &vertex_buffer); |
| 97 | delete[] vertices; |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | TestBase* GetTriangleSetupTest() { |
| 103 | return new TriangleSetupTest; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | } // namespace glbench |