2 * Copyright (C) 2003-2011 Neverball authors
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
22 /*---------------------------------------------------------------------------*/
26 PFNGLCLIENTACTIVETEXTURE_PROC glClientActiveTexture_;
27 PFNGLACTIVETEXTURE_PROC glActiveTexture_;
29 PFNGLGENBUFFERS_PROC glGenBuffers_;
30 PFNGLBINDBUFFER_PROC glBindBuffer_;
31 PFNGLBUFFERDATA_PROC glBufferData_;
32 PFNGLBUFFERSUBDATA_PROC glBufferSubData_;
33 PFNGLDELETEBUFFERS_PROC glDeleteBuffers_;
34 PFNGLISBUFFER_PROC glIsBuffer_;
36 PFNGLPOINTPARAMETERFV_PROC glPointParameterfv_;
40 /*---------------------------------------------------------------------------*/
42 int glext_check(const char *needle)
44 const GLubyte *haystack, *c;
46 /* Search for the given string in the OpenGL extension strings. */
48 for (haystack = glGetString(GL_EXTENSIONS); *haystack; haystack++)
50 for (c = (const GLubyte *) needle; *c && *haystack; c++, haystack++)
54 if ((*c == 0) && (*haystack == ' ' || *haystack == '\0'))
61 int glext_assert(const char *ext)
63 if (!glext_check(ext))
65 fprintf(stderr, "Missing required OpenGL extension (%s)\n", ext);
71 /*---------------------------------------------------------------------------*/
73 #define SDL_GL_GFPA(fun, str) do { \
74 ptr = SDL_GL_GetProcAddress(str); \
75 memcpy(&fun, &ptr, sizeof (void *)); \
78 /*---------------------------------------------------------------------------*/
84 memset(&gli, 0, sizeof (struct gl_info));
88 gli.max_texture_units = 1;
89 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gli.max_texture_size);
94 if (glext_assert("ARB_multitexture"))
96 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gli.max_texture_units);
98 SDL_GL_GFPA(glClientActiveTexture_, "glClientActiveTextureARB");
99 SDL_GL_GFPA(glActiveTexture_, "glActiveTextureARB");
101 gli.multitexture = 1;
104 if (glext_assert("ARB_vertex_buffer_object"))
106 SDL_GL_GFPA(glGenBuffers_, "glGenBuffersARB");
107 SDL_GL_GFPA(glBindBuffer_, "glBindBufferARB");
108 SDL_GL_GFPA(glBufferData_, "glBufferDataARB");
109 SDL_GL_GFPA(glBufferSubData_, "glBufferSubDataARB");
110 SDL_GL_GFPA(glDeleteBuffers_, "glDeleteBuffersARB");
111 SDL_GL_GFPA(glIsBuffer_, "glIsBufferARB");
113 gli.vertex_buffer_object = 1;
116 if (glext_assert("ARB_point_parameters"))
118 SDL_GL_GFPA(glPointParameterfv_, "glPointParameterfvARB");
120 gli.point_parameters = 1;
123 return (gli.multitexture &&
124 gli.vertex_buffer_object &&
125 gli.point_parameters);
129 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gli.max_texture_units);
131 gli.multitexture = 1;
132 gli.vertex_buffer_object = 1;
133 gli.point_parameters = 1;
139 /*---------------------------------------------------------------------------*/
141 void glClipPlane4f_(GLenum p, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
168 /*---------------------------------------------------------------------------*/