Added option to list all tests
[glmemperf] / util.h
1 /**
2  * OpenGL ES 2.0 memory performance estimator
3  * Copyright (C) 2009 Nokia
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * \author Sami Kyöstilä <sami.kyostila@nokia.com>
20  *
21  * EGL and OpenGL ES utility functions
22  */
23 #ifndef UTIL_H
24 #define UTIL_H
25
26 #include <string>
27 #include <GLES2/gl2.h>
28 #include <EGL/egl.h>
29 #include <assert.h>
30
31 /**
32  *  Verify that GL commands up to this point have not produced any errors.
33  */
34 #define ASSERT_GL() \
35     do \
36     { \
37         GLint err = glGetError(); \
38         if (err) \
39         { \
40             printf("GL error 0x%x (%d) at %s:%d\n", err, err, __FILE__, __LINE__); \
41             assert(!err); \
42         } \
43     } while (0)
44
45 /**
46  *  Verify that EGL commands up to this point have not produced any errors.
47  */
48 #define ASSERT_EGL() \
49     do \
50     { \
51         EGLint err = eglGetError(); \
52         if (err != EGL_SUCCESS) \
53         { \
54             printf("EGL error 0x%x (%d) at %s:%d\n", err, err, __FILE__, __LINE__); \
55             assert(!err); \
56         } \
57     } while (0)
58
59 /**
60  *  EGL context objects available to all tests
61  */
62 struct Context
63 {
64     EGLNativeDisplayType nativeDisplay;
65     EGLConfig config;
66     EGLNativeWindowType win;
67     EGLDisplay dpy;
68     EGLContext context;
69     EGLSurface surface;
70 };
71
72 extern struct Context ctx;
73
74 /**
75  *  Indicate that a frame is complete
76  */
77 void swapBuffers();
78
79 /**
80  *  Load a texture from a binary file
81  *
82  *  @param target               Texture target (usually GL_TEXTURE_2D)
83  *  @param level                Mipmap level
84  *  @param internalFormat       Internal texture format
85  *  @param width                Texture width in pixels
86  *  @param height               Texture height in pixels
87  *  @param type                 Data type
88  *  @param fileName             File containing the texture data
89  *
90  *  @returns true on success, false on failure
91  */
92 bool loadRawTexture(GLenum target, int level, GLenum internalFormat, int width,
93                     int height, GLenum format, GLenum type, const std::string& fileName);
94
95 /**
96  *  Load a compressed texture from a binary file
97  *
98  *  @param target               Texture target (usually GL_TEXTURE_2D)
99  *  @param internalFormat       Internal texture format
100  *  @param width                Texture width in pixels
101  *  @param height               Texture height in pixels
102  *  @param fileName             File containing the texture data
103  *
104  *  @returns true on success, false on failure
105  */
106 bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
107                            int height, const std::string& fileName);
108
109 /**
110  *  Check whether an EGL extension is supported
111  *
112  *  @param name                 Extension name
113  *
114  *  @returns true if extension is supported
115  */
116 bool isEGLExtensionSupported(const std::string& name);
117
118 /**
119  *  Check whether an OpenGL ES extension is supported
120  *
121  *  @param name                 Extension name
122  *
123  *  @returns true if extension is supported
124  */
125 bool isGLExtensionSupported(const std::string& name);
126
127 /**
128  *  Compile a vertex and fragment shader and create a new program from the
129  *  result
130  *
131  *  @param vertSrc              Vertex program source
132  *  @param fragSrc              Fragment program source
133  *
134  *  @returns new program handle
135  */
136 GLint createProgram(const std::string& vertSrc, const std::string& fragSrc);
137
138 /**
139  *  Describe a texture format and type combination
140  *
141  *  @param format               Texture format
142  *  @param type                 Texture type
143  */
144 std::string textureFormatName(GLenum format, GLenum type);
145
146 /**
147  *  Print EGL config attributes on the terminal
148  *
149  *  @param dpy                  EGL display
150  *  @param config               EGL config
151  */
152 void dumpConfig(EGLDisplay dpy, EGLConfig config);
153
154 #endif // UTIL_H