Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOOpenGLExtensionManager.h
Go to the documentation of this file.
1/*
2
3OOOpenGLExtensionManager.h
4
5Handles checking for and using OpenGL extensions and related information.
6
7This is thread safe, except for initialization; that is, +sharedManager should
8be called from the main thread at an early point. The OpenGL context must be
9set up by then.
10
11
12Copyright (C) 2007-2013 Jens Ayton and contributors
13
14Permission is hereby granted, free of charge, to any person obtaining a copy
15of this software and associated documentation files (the "Software"), to deal
16in the Software without restriction, including without limitation the rights
17to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18copies of the Software, and to permit persons to whom the Software is
19furnished to do so, subject to the following conditions:
20
21The above copyright notice and this permission notice shall be included in all
22copies or substantial portions of the Software.
23
24THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30SOFTWARE.
31
32*/
33
34#import "OOCocoa.h"
35#import "OOOpenGL.h"
37#import "OOTypes.h"
38
39
40#ifndef OO_SHADERS
41#ifdef NO_SHADERS
42#define OO_SHADERS 0
43#else
44#define OO_SHADERS 1
45#endif
46#endif
47
48
49#if OO_SHADERS
50
51// Certain extensions are required for shader support.
52#ifndef GL_ARB_multitexture
53#warning NO_SHADERS not defined and GL_ARB_multitexture not defined; if possible, use a newer version of glext.h.
54#endif
55
56#ifndef GL_ARB_shader_objects
57#warning NO_SHADERS not defined and GL_ARB_shader_objects not defined; if possible, use a newer version of glext.h.
58#endif
59
60#ifndef GL_ARB_shading_language_100
61#warning NO_SHADERS not defined and GL_ARB_shading_language_100 not defined; if possible, use a newer version of glext.h.
62#endif
63
64#ifndef GL_ARB_fragment_shader
65#warning NO_SHADERS not defined and GL_ARB_fragment_shader not defined; if possible, use a newer version of glext.h.
66#endif
67
68#ifndef GL_ARB_vertex_shader
69#warning NO_SHADERS not defined and GL_ARB_vertex_shader not defined; if possible, use a newer version of glext.h.
70#endif
71
72#endif //OO_SHADERS
73
74
75#if GL_ARB_vertex_buffer_object
76#define OO_USE_VBO 0 // Disabled due to crashes on certain systems (and limited VBO use)
77#else
78#define OO_USE_VBO 0
79#warning Building without vertex buffer object support, are your OpenGL headers up to date?
80#endif
81
82
83#if GL_EXT_framebuffer_object
84#define OO_USE_FBO 1
85#else
86#define OO_USE_FBO 0
87#warning Building without frame buffer object support, are your OpenGL headers up to date?
88#endif
89
90
91/* Multitexturing requires GL_ARB_multitexture, but we only have use for it
92 if GL_ARB_texture_env_combine is available, and GL_ARB_texture_env_combine
93 requires GL_ARB_multitexture. Both GL_ARB_multitexture and
94 GL_ARB_texture_env_combine were promoted to core in OpenGL 1.3.
95*/
96#if GL_ARB_texture_env_combine
97#define OO_MULTITEXTURE 1
98#else
99#warning Building without texture combiner support, are your OpenGL headers up to date?
100#define OO_MULTITEXTURE 0
101#endif
102
103#if defined(GL_ARB_texture_cube_map) || defined(GL_VERSION_1_3)
104#define OO_TEXTURE_CUBE_MAP 1
105#else
106#warning Building without cube map support, are your OpenGL headers up to date?
107#define OO_TEXTURE_CUBE_MAP 0
108#endif
109
110
111
112#define OOOPENGLEXTMGR_LOCK_SET_ACCESS (!OOLITE_MAC_OS_X)
113
114
115@interface OOOpenGLExtensionManager: NSObject
116{
117@private
118#if OOOPENGLEXTMGR_LOCK_SET_ACCESS
119 NSLock *lock;
120#endif
122
123 NSString *vendor;
124 NSString *renderer;
125
126 unsigned major, minor, release;
127
131
132#if OO_SHADERS
138#endif
139#if OO_USE_VBO
140 BOOL vboSupported;
141#endif
142#if OO_USE_FBO
143 BOOL fboSupported;
144#endif
145#if OO_MULTITEXTURE
147 GLint textureUnitCount;
148#endif
149}
150
151+ (OOOpenGLExtensionManager *) sharedManager;
152
153- (void) reset;
154
155- (BOOL)haveExtension:(NSString *)extension;
156
157- (BOOL)shadersSupported;
158- (BOOL)shadersForceDisabled;
159- (OOGraphicsDetail)defaultDetailLevel;
160- (OOGraphicsDetail)maximumDetailLevel;
161- (GLint)textureImageUnitCount; // Fragment shader sampler count limit. Does not apply to fixed function multitexturing. (GL_MAX_TEXTURE_IMAGE_UNITS_ARB)
162
163- (BOOL)vboSupported; // Vertex buffer objects
164- (BOOL)fboSupported; // Frame buffer objects
165- (BOOL)textureCombinersSupported;
166- (GLint)textureUnitCount; // Fixed function multitexture limit, does not apply to shaders. (GL_MAX_TEXTURE_UNITS_ARB)
167
168- (NSUInteger)majorVersionNumber;
169- (NSUInteger)minorVersionNumber;
170- (NSUInteger)releaseVersionNumber;
171- (void)getVersionMajor:(unsigned *)outMajor minor:(unsigned *)outMinor release:(unsigned *)outRelease;
172- (BOOL) versionIsAtLeastMajor:(unsigned)maj minor:(unsigned)min;
173
174- (NSString *) vendorString;
175- (NSString *) rendererString;
176
177// GL_POINT_SMOOTH is slow or non-functional on some GPUs.
178- (BOOL) usePointSmoothing;
179- (BOOL) useLineSmoothing;
180
181// Using vertex shader for dust transformation is counterproductive on systems which run vertex shaders on the CPU.
182- (BOOL) useDustShader;
183
184@end
185
186
192
193
194#if OOLITE_WINDOWS
195/* Declare the function pointers for the OpenGL extensions used in the game
196 (required for Windows only).
197*/
198
199#if OO_SHADERS
200// Shader functions
201PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
202PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
203PFNGLUNIFORM1IARBPROC glUniform1iARB;
204PFNGLUNIFORM1FARBPROC glUniform1fARB;
205PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB;
206PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB;
207PFNGLUNIFORM4FVARBPROC glUniform4fvARB;
208PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
209PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
210PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
211PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
212PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
213PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
214PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
215PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
216PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
217PFNGLUNIFORM2FVARBPROC glUniform2fvARB;
218PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB;
219PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB;
220PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB;
221PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB;
222PFNGLVALIDATEPROGRAMARBPROC glValidateProgramARB;
223#endif // OO_SHADERS
224
225
226#if OO_SHADERS || OO_MULTITEXTURE
227PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
228#endif
229
230#if OO_MULTITEXTURE
231PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
232#endif
233
234#if OO_USE_VBO
235PFNGLGENBUFFERSARBPROC glGenBuffersARB;
236PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB;
237PFNGLBINDBUFFERARBPROC glBindBufferARB;
238PFNGLBUFFERDATAARBPROC glBufferDataARB;
239#endif
240
241#if OO_USE_FBO
242PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT;
243PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT;
244PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT;
245PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT;
246PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT;
247PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT;
248PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT;
249PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT;
250PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
251PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT;
252PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
253PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
254PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
255PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
256PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
257PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
258PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
259PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
260PFNGLGENBUFFERSPROC glGenBuffers;
261PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
262PFNGLBINDBUFFERPROC glBindBuffer;
263PFNGLBUFFERDATAPROC glBufferData;
264PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
265PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
266PFNGLUSEPROGRAMPROC glUseProgram;
267PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
268PFNGLUNIFORM1IPROC glUniform1i;
269PFNGLACTIVETEXTUREPROC glActiveTexture;
270PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
271PFNGLUNIFORM1FPROC glUniform1f;
272PFNGLUNIFORM2FVPROC glUniform2fv;
273PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
274PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
275PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
276PFNGLDELETEBUFFERSPROC glDeleteBuffers;
277PFNGLDRAWBUFFERSPROC glDrawBuffers;
278PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
279PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample;
280PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
281PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
282PFNGLCLAMPCOLORPROC glClampColor;
283#endif
284
285#endif // OOLITE_WINDOWS
#define INLINE_PURE_FUNC
#define OOINLINE
OOINLINE BOOL OOShadersSupported(void) INLINE_PURE_FUNC
OOShaderSetting
Definition OOOpenGL.h:35
OOGraphicsDetail
Definition OOTypes.h:243
OOOpenGLExtensionManager * sharedManager()