4 * GL-based support functions
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #ifndef lxdream_glutil_H
20 #define lxdream_glutil_H
30 * Test if a specific extension is supported. From opengl.org
31 * @param extension extension name to check for
32 * @return TRUE if supported, otherwise FALSE.
34 gboolean isGLExtensionSupported( const char *extension );
36 gboolean isOpenGLES2();
39 * Dump GL information to the output stream, usually for debugging purposes
41 void glPrintInfo( FILE *out );
44 * Check for a GL error and print a message if there is one
45 * @param context If not null, a string to be printed along side an error message
46 * @return FALSE if there was an error, otherwise TRUE
48 gboolean gl_check_error( const char *context );
50 * Test if secondary color (GL_COLOR_SUM) is supported.
52 gboolean isGLSecondaryColorSupported();
54 gboolean isGLVertexBufferSupported();
55 gboolean isGLVertexRangeSupported();
56 gboolean isGLPixelBufferSupported();
57 gboolean isGLMultitextureSupported();
58 gboolean isGLMirroredTextureSupported();
59 gboolean isGLBGRATextureSupported();
60 gboolean isGLShaderSupported();
61 GLint glGetMaxColourAttachments();
64 * Wrapper function for glTexImage2D calls that may have BGRA data - on systems
65 * where this isn't directly supported, swizzle the data into an acceptable RGBA
66 * equivalent. If preserveData is true, data will not be modified - otherwise
67 * the method may swizzle data in-place.
69 void glTexImage2DBGRA( int level, GLint intFormat, int width, int height, GLint format, GLint type, unsigned char *data, int preserveData );
70 void glTexSubImage2DBGRA( int level, int xoff, int yoff, int width, int height, GLint format, GLint type, unsigned char *data, int preserveData );
72 /****** Extension variant wrangling *****/
74 #if defined(GL_MIRRORED_REPEAT_ARB) && !defined(GL_MIRRORED_REPEAT)
75 #define GL_MIRRORED_REPEAT GL_MIRRORED_REPEAT_ARB
78 #if defined(GL_MAX_TEXTURE_UNITS_ARB) && !defined(GL_MAX_TEXTURE_UNITS)
79 #define GL_MAX_TEXTURE_UNITS GL_MAX_TEXTURE_UNITS_ARB
82 #if defined(GL_FRAMEBUFFER_EXT) && !defined(GL_FRAMEBUFFER)
83 #define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
86 #if defined(GL_RENDERBUFFER_EXT) && !defined(GL_RENDERBUFFER)
87 #define GL_RENDERBUFFER GL_RENDERBUFFER_EXT
90 #if defined(GL_COLOR_ATTACHMENT0_EXT) && !defined(GL_COLOR_ATTACHMENT0)
91 #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
94 #if defined(GL_MAX_COLOR_ATTACHMENTS_EXT) && !defined(GL_MAX_COLOR_ATTACHMENTS)
95 #define GL_MAX_COLOR_ATTACHMENTS GL_MAX_COLOR_ATTACHMENTS_EXT
98 #if defined(GL_STENCIL_ATTACHMENT_EXT) && !defined(GL_STENCIL_ATTACHMENT)
99 #define GL_STENCIL_ATTACHMENT GL_STENCIL_ATTACHMENT_EXT
102 #if defined(GL_DEPTH_ATTACHMENT_EXT) && !defined(GL_DEPTH_ATTACHMENT)
103 #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT
106 #if defined(GL_DEPTH_COMPONENT24_OES) && !defined(GL_DEPTH_COMPONENT24)
107 #define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
110 #ifndef GL_DEPTH24_STENCIL8
111 #if defined(GL_DEPTH24_STENCIL8_EXT)
112 #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_EXT
113 #elif defined(GL_DEPTH24_STENCIL8_OES)
114 #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
118 #if defined(GL_FRAMEBUFFER_COMPLETE_EXT) && !defined(GL_FRAMEBUFFER_COMPLETE)
119 #define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
122 #if defined(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT) && !defined(GL_UNSIGNED_SHORT_1_5_5_5_REV)
123 #define GL_UNSIGNED_SHORT_1_5_5_5_REV GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT
126 #if defined(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT) && !defined(GL_UNSIGNED_SHORT_4_4_4_4_REV)
127 #define GL_UNSIGNED_SHORT_4_4_4_4_REV GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT
130 #if defined(GL_BGRA_EXT) && !defined(GL_BGRA)
131 #define GL_BGRA GL_BGRA_EXT
134 #if defined(GL_SHADING_LANGUAGE_VERSION_ARB) && !defined(GL_SHADING_LANGUAGE_VERSION)
135 #define GL_SHADING_LANGUAGE_VERSION GL_SHADING_LANGUAGE_VERSION_ARB
139 #if defined(HAVE_OPENGL_FBO_EXT) && !defined(HAVE_OPENGL_FBO)
140 #define glGenFramebuffers glGenFramebuffersEXT
141 #define glGenRenderbuffers glGenRenderbuffersEXT
142 #define glBindFramebuffer glBindFramebufferEXT
143 #define glDeleteFramebuffers glDeleteFramebuffersEXT
144 #define glDeleteRenderbuffers glDeleteRenderbuffersEXT
145 #define glBindFramebuffer glBindFramebufferEXT
146 #define glBindRenderbuffer glBindRenderbufferEXT
147 #define glRenderbufferStorage glRenderbufferStorageEXT
148 #define glFramebufferRenderbuffer glFramebufferRenderbufferEXT
149 #define glFramebufferTexture2D glFramebufferTexture2DEXT
150 #define glCheckFramebufferStatus glCheckFramebufferStatusEXT
153 /* Define an orthographic transform matrix, given the bounding box (assuming origin at 0) */
154 void defineOrthoMatrix( GLfloat *matrix, GLfloat width, GLfloat height, GLfloat znear, GLfloat zfar );
156 /* Convenience formatting function for driver use */
157 void fprint_extensions( FILE *out, const char *extensions );
159 /****** Texture formats (missing definitions) *****/
161 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
162 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
165 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
166 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
170 #define GL_BGRA 0x80E1
177 #endif /* !lxdream_glutil_H */
.