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