]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/ShivaVG/src/shExtensions.c
Update for OpenSceneGraph 3.3.2 API changes.
[simgear.git] / simgear / canvas / ShivaVG / src / shExtensions.c
1 /*
2  * Copyright (c) 2007 Ivan Leben
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library in the file COPYING;
16  * if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  */
20
21 #include <vg/openvg.h>
22 #include "shDefs.h"
23 #include "shExtensions.h"
24 #include "shContext.h"
25 #include <stdio.h>
26 #include <string.h>
27
28 /*-----------------------------------------------------
29  * Extensions check
30  *-----------------------------------------------------*/
31
32 void fallbackActiveTexture(GLenum texture) {
33 }
34
35 void fallbackMultiTexCoord1f(GLenum target, GLfloat x) {
36   glTexCoord1f(x);
37 }
38
39 void fallbackMultiTexCoord2f(GLenum target, GLfloat x, GLfloat y) {
40   glTexCoord2f(x, y);
41 }
42
43 static int checkExtension(const char *extensions, const char *name)
44 {
45         int nlen = (int)strlen(name);
46         int elen = (int)strlen(extensions);
47         const char *e = extensions;
48         SH_ASSERT(nlen > 0);
49
50         while (1) {
51
52                 /* Try to find sub-string */
53                 e = strstr(e, name);
54     if (e == NULL) return 0;
55                 /* Check if last */
56                 if (e == extensions + elen - nlen)
57                         return 1;
58                 /* Check if space follows (avoid same names with a suffix) */
59     if (*(e + nlen) == ' ')
60       return 1;
61     
62     e += nlen;
63         }
64
65   return 0;
66 }
67
68 typedef void (*PFVOID)();
69
70 PFVOID shGetProcAddress(const char *name)
71 {
72   #if defined(_WIN32)
73   return (PFVOID)wglGetProcAddress(name);
74   #elif defined(__APPLE__)
75   /* TODO: Mac OS glGetProcAddress implementation */
76   return (PFVOID)NULL;
77   #else
78   return (PFVOID)glXGetProcAddress((const unsigned char *)name);
79   #endif
80 }
81
82 void shLoadExtensions(VGContext *c)
83 {
84   const char *ext = (const char*)glGetString(GL_EXTENSIONS);
85   
86   /* GL_TEXTURE_CLAMP_TO_EDGE */
87   if (checkExtension(ext, "GL_EXT_texture_edge_clamp"))
88     c->isGLAvailable_ClampToEdge = 1;
89   else if (checkExtension(ext, "GL_SGIS_texture_edge_clamp"))
90     c->isGLAvailable_ClampToEdge = 1;
91   else /* Unavailable */
92     c->isGLAvailable_ClampToEdge = 0;
93   
94   
95   /* GL_TEXTURE_MIRRORED_REPEAT */
96   if (checkExtension(ext, "GL_ARB_texture_mirrored_repeat"))
97     c->isGLAvailable_MirroredRepeat = 1;
98   else if(checkExtension(ext, "GL_IBM_texture_mirrored_repeat"))
99     c->isGLAvailable_MirroredRepeat = 1;
100   else /* Unavailable */
101     c->isGLAvailable_MirroredRepeat = 0;
102   
103   
104   /* glActiveTexture, glMultiTexCoord1f */  
105   if (checkExtension(ext, "GL_ARB_multitexture")) {    
106     c->isGLAvailable_Multitexture = 1;
107     
108     c->pglActiveTexture = (SH_PGLACTIVETEXTURE)
109       shGetProcAddress("glActiveTextureARB");
110     c->pglMultiTexCoord1f = (SH_PGLMULTITEXCOORD1F)
111       shGetProcAddress("glMultiTexCoord1fARB");
112     c->pglMultiTexCoord2f = (SH_PGLMULTITEXCOORD2F)
113       shGetProcAddress("glMultiTexCoord2fARB");
114     
115     if (c->pglActiveTexture == NULL || c->pglMultiTexCoord1f == NULL ||
116         c->pglMultiTexCoord2f == NULL)
117       c->isGLAvailable_Multitexture = 0;
118     
119   }else{ /* Unavailable */
120     c->isGLAvailable_Multitexture = 0;
121     c->pglActiveTexture = (SH_PGLACTIVETEXTURE)fallbackActiveTexture;
122     c->pglMultiTexCoord1f = (SH_PGLMULTITEXCOORD1F)fallbackMultiTexCoord1f;
123     c->pglMultiTexCoord2f = (SH_PGLMULTITEXCOORD2F)fallbackMultiTexCoord2f;
124   }
125   
126   /* Non-power-of-two textures */
127   if (checkExtension(ext, "GL_ARB_texture_non_power_of_two"))
128     c->isGLAvailable_TextureNonPowerOfTwo = 1;
129   else /* Unavailable */
130     c->isGLAvailable_TextureNonPowerOfTwo = 0;
131 }