Added missing includes
[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 <stdio.h>
28 #include <GLES2/gl2.h>
29 #include <EGL/egl.h>
30 #include <assert.h>
31
32 /**
33  *  Verify that GL commands up to this point have not produced any errors.
34  */
35 #define ASSERT_GL() \
36     do \
37     { \
38         GLint err = glGetError(); \
39         if (err) \
40         { \
41             printf("GL error 0x%x (%d) at %s:%d\n", err, err, __FILE__, __LINE__); \
42             assert(!err); \
43         } \
44     } while (0)
45
46 /**
47  *  Verify that EGL commands up to this point have not produced any errors.
48  */
49 #define ASSERT_EGL() \
50     do \
51     { \
52         EGLint err = eglGetError(); \
53         if (err != EGL_SUCCESS) \
54         { \
55             printf("EGL error 0x%x (%d) at %s:%d\n", err, err, __FILE__, __LINE__); \
56             assert(!err); \
57         } \
58     } while (0)
59
60 /**
61  *  EGL context objects available to all tests
62  */
63 struct Context
64 {
65     EGLNativeDisplayType nativeDisplay;
66     EGLConfig config;
67     EGLNativeWindowType win;
68     EGLDisplay dpy;
69     EGLContext context;
70     EGLSurface surface;
71 };
72
73 extern struct Context ctx;
74
75 /**
76  *  Indicate that a frame is complete
77  */
78 void swapBuffers();
79
80 /**
81  *  Load a texture from a binary file
82  *
83  *  @param target               Texture target (usually GL_TEXTURE_2D)
84  *  @param level                Mipmap level
85  *  @param internalFormat       Internal texture format
86  *  @param width                Texture width in pixels
87  *  @param height               Texture height in pixels
88  *  @param type                 Data type
89  *  @param fileName             File containing the texture data
90  *
91  *  @returns true on success, false on failure
92  */
93 bool loadRawTexture(GLenum target, int level, GLenum internalFormat, int width,
94                     int height, GLenum format, GLenum type, const std::string& fileName);
95
96 /**
97  *  Load a compressed texture from a binary file
98  *
99  *  @param target               Texture target (usually GL_TEXTURE_2D)
100  *  @param internalFormat       Internal texture format
101  *  @param width                Texture width in pixels
102  *  @param height               Texture height in pixels
103  *  @param fileName             File containing the texture data
104  *
105  *  @returns true on success, false on failure
106  */
107 bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
108                            int height, const std::string& fileName);
109
110 /**
111  *  Check whether an EGL extension is supported
112  *
113  *  @param name                 Extension name
114  *
115  *  @returns true if extension is supported
116  */
117 bool isEGLExtensionSupported(const std::string& name);
118
119 /**
120  *  Check whether an OpenGL ES extension is supported
121  *
122  *  @param name                 Extension name
123  *
124  *  @returns true if extension is supported
125  */
126 bool isGLExtensionSupported(const std::string& name);
127
128 /**
129  *  Compile a vertex and fragment shader and create a new program from the
130  *  result
131  *
132  *  @param vertSrc              Vertex program source
133  *  @param fragSrc              Fragment program source
134  *
135  *  @returns new program handle
136  */
137 GLint createProgram(const std::string& vertSrc, const std::string& fragSrc);
138
139 /**
140  *  Describe a texture format and type combination
141  *
142  *  @param format               Texture format
143  *  @param type                 Texture type
144  */
145 std::string textureFormatName(GLenum format, GLenum type);
146
147 /**
148  *  Print EGL config attributes on the terminal
149  *
150  *  @param dpy                  EGL display
151  *  @param config               EGL config
152  */
153 void dumpConfig(EGLDisplay dpy, EGLConfig config);
154
155 #endif // UTIL_H