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 #ifndef BENCH_GL_MAIN_H_
6 #define BENCH_GL_MAIN_H_
7
8 #include <gflags/gflags.h>
9 #include <stdarg.h>
10 #include <sys/time.h>
11
12 #if defined(USE_OPENGLES)
13 #include <GLES2/gl2.h>
14 #include <EGL/egl.h>
15 #include <GLES2/gl2ext.h>
16 #elif defined(USE_OPENGL)
17 #include <GL/gl.h>
18 #include <GL/glx.h>
19
20 #ifdef WORKAROUND_CROSBUG14304
21 #define LIST_PROC_FUNCTIONS(F) \
22 F(glActiveTexture, PFNGLACTIVETEXTUREPROC) \
23 F(glAttachShader, PFNGLATTACHSHADERPROC) \
24 F(glBindBuffer, PFNGLBINDBUFFERPROC) \
25 F(glBufferData, PFNGLBUFFERDATAPROC) \
26 F(glCompileShader, PFNGLCOMPILESHADERPROC) \
27 F(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
28 F(glCreateShader, PFNGLCREATESHADERPROC) \
29 F(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \
30 F(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \
31 F(glDeleteShader, PFNGLDELETESHADERPROC) \
32 F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \
33 F(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
34 F(glGenBuffers, PFNGLGENBUFFERSPROC) \
35 F(glGetAttribLocation, PFNGLGETATTRIBLOCATIONPROC) \
36 F(glGetInfoLogARB, PFNGLGETPROGRAMINFOLOGPROC) \
37 F(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \
38 F(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \
39 F(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \
40 F(glLinkProgram, PFNGLLINKPROGRAMPROC) \
41 F(glShaderSource, PFNGLSHADERSOURCEPROC) \
42 F(glUniform1f, PFNGLUNIFORM1FPROC) \
43 F(glUniform1i, PFNGLUNIFORM1IPROC) \
44 F(glUniform4fv, PFNGLUNIFORM4FVPROC) \
45 F(glUniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC) \
46 F(glUseProgram, PFNGLUSEPROGRAMPROC) \
47 F(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \
48 F(glXSwapIntervalSGI, PFNGLXSWAPINTERVALSGIPROC) \
49 F(glXBindTexImageEXT, PFNGLXBINDTEXIMAGEEXTPROC) \
50 F(glXReleaseTexImageEXT, PFNGLXRELEASETEXIMAGEEXTPROC)
51 #else
52 #define LIST_PROC_FUNCTIONS(F) \
53 F(glAttachShader, PFNGLATTACHSHADERPROC) \
54 F(glBindBuffer, PFNGLBINDBUFFERPROC) \
55 F(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC) \
56 F(glBindRenderbuffer, PFNGLBINDRENDERBUFFERPROC) \
57 F(glBufferData, PFNGLBUFFERDATAPROC) \
58 F(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC) \
59 F(glCompileShader, PFNGLCOMPILESHADERPROC) \
60 F(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
61 F(glCreateShader, PFNGLCREATESHADERPROC) \
62 F(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \
63 F(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \
64 F(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \
65 F(glDeleteRenderbuffers, PFNGLDELETERENDERBUFFERSPROC) \
66 F(glDeleteShader, PFNGLDELETESHADERPROC) \
67 F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \
68 F(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
69 F(glFramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC) \
70 F(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC) \
71 F(glGenBuffers, PFNGLGENBUFFERSPROC) \
72 F(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC) \
73 F(glGenRenderbuffers, PFNGLGENRENDERBUFFERSPROC) \
74 F(glGetAttribLocation, PFNGLGETATTRIBLOCATIONPROC) \
75 F(glGetInfoLogARB, PFNGLGETPROGRAMINFOLOGPROC) \
76 F(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \
77 F(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \
78 F(glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \
79 F(glLinkProgram, PFNGLLINKPROGRAMPROC) \
80 F(glRenderbufferStorage, PFNGLRENDERBUFFERSTORAGEPROC) \
81 F(glShaderSource, PFNGLSHADERSOURCEPROC) \
82 F(glUniform1f, PFNGLUNIFORM1FPROC) \
83 F(glUniform1i, PFNGLUNIFORM1IPROC) \
84 F(glUniform4fv, PFNGLUNIFORM4FVPROC) \
85 F(glUniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC) \
86 F(glUseProgram, PFNGLUSEPROGRAMPROC) \
87 F(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \
88 F(glXBindTexImageEXT, PFNGLXBINDTEXIMAGEEXTPROC) \
89 F(glXReleaseTexImageEXT, PFNGLXRELEASETEXIMAGEEXTPROC) \
90 F(glXSwapIntervalSGI, PFNGLXSWAPINTERVALSGIPROC)
91 #endif
92
93 namespace gl {
94 #define F(fun, type) extern type fun;
95 LIST_PROC_FUNCTIONS(F)
96 #undef F
97 };
98
99 using namespace gl;
100 #else
101 #error bad graphics backend
102 #endif
103
GetUTime()104 inline uint64_t GetUTime() {
105 struct timeval tv;
106 gettimeofday(&tv, NULL);
107 return static_cast<uint64_t>(tv.tv_usec) +
108 1000000ULL*static_cast<uint64_t>(tv.tv_sec);
109 }
110
111 extern bool g_verbose;
112 extern bool g_hasty;
113 extern GLint g_width;
114 extern GLint g_height;
115 extern GLint g_max_texture_size;
116
117 DECLARE_bool(override_redirect);
118
119 // This size is for a window that is very large but will fit on all
120 // the displays we care about.
121 #define WINDOW_WIDTH 512
122 #define WINDOW_HEIGHT 512
123
dbg_printf(const char * format,...)124 inline void dbg_printf(const char* format, ...) {
125 if (!g_verbose)
126 return;
127 va_list args;
128 va_start(args, format);
129 vprintf(format, args);
130 va_end(args);
131 }
132
133 #endif // BENCH_GL_MAIN_H_
134