• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 "arraysize.h"
8 #include "main.h"
9 #include "testbase.h"
10 #include "utils.h"
11 
12 namespace glbench {
13 
14 class DrawSizeTest : public DrawElementsTestFunc {
15  public:
DrawSizeTest()16   DrawSizeTest() {}
~DrawSizeTest()17   virtual ~DrawSizeTest() {}
18   virtual bool Run();
Name() const19   virtual const char* Name() const { return "draw_size"; }
20 
21  private:
22   DISALLOW_COPY_AND_ASSIGN(DrawSizeTest);
23 };
24 
25 const char* kDrawSizeVS =
26     "attribute vec4 pos;"
27     "void main() {"
28     "  gl_Position = pos;"
29     "}";
30 
31 const char* kDrawSizeFS =
32     "uniform vec4 color;"
33     "void main() {"
34     "  gl_FragColor = color;"
35     "}";
36 
Run()37 bool DrawSizeTest::Run() {
38   GLuint program = InitShaderProgram(kDrawSizeVS, kDrawSizeFS);
39   const int sizes[] = {4, 8, 16, 32, 64, 128};
40 
41   glViewport(0, 0, g_width, g_height);
42 
43   for (unsigned int j = 0; j < arraysize(sizes); j++) {
44     // This specifies a square mesh in the middle of the viewport.
45     // Larger meshes make this test too slow for devices that do 1 mtri/sec.
46     // Also note that GLES 2.0 uses 16 bit indices.
47     GLint width = sizes[j];
48     GLint height = sizes[j];
49 
50     GLfloat* vertices = NULL;
51     GLsizeiptr vertex_buffer_size = 0;
52     CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
53                   width, height);
54     GLuint vertex_buffer =
55         SetupVBO(GL_ARRAY_BUFFER, vertex_buffer_size, vertices);
56 
57     GLint attribute_index = glGetAttribLocation(program, "pos");
58     glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
59     glEnableVertexAttribArray(attribute_index);
60 
61     // Use orange for drawing.
62     const GLfloat orange[4] = {1.0f, 0.5f, 0.0f, 1.0f};
63     GLint color_uniform = glGetUniformLocation(program, "color");
64     glUniform4fv(color_uniform, 1, orange);
65 
66     GLushort* indices = NULL;
67     GLuint index_buffer = 0;
68     GLsizeiptr index_buffer_size = 0;
69 
70     count_ = CreateMesh(&indices, &index_buffer_size, width, height, 0);
71 
72     index_buffer =
73         SetupVBO(GL_ELEMENT_ARRAY_BUFFER, index_buffer_size, indices);
74 
75     std::string name = "draw_size_" + IntToString(width * height);
76 
77     RunTest(this, name.c_str(), count_ / 3, g_width, g_height, true);
78 
79     glDeleteBuffers(1, &index_buffer);
80     delete[] indices;
81     glDeleteBuffers(1, &vertex_buffer);
82     delete[] vertices;
83   }
84 
85   glDeleteProgram(program);
86   return true;
87 }
88 
GetDrawSizeTest()89 TestBase* GetDrawSizeTest() {
90   return new DrawSizeTest;
91 }
92 
93 }  // namespace glbench
94