2 * Copyright (c) 2007 Ivan Leben
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.
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.
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
21 #include <vg/openvg.h>
23 #include "shExtensions.h"
24 #include "shContext.h"
28 /*-----------------------------------------------------
30 *-----------------------------------------------------*/
32 void fallbackActiveTexture(GLenum texture) {
35 void fallbackMultiTexCoord1f(GLenum target, GLfloat x) {
39 void fallbackMultiTexCoord2f(GLenum target, GLfloat x, GLfloat y) {
43 static int checkExtension(const char *extensions, const char *name)
45 int nlen = (int)strlen(name);
46 int elen = (int)strlen(extensions);
47 const char *e = extensions;
52 /* Try to find sub-string */
54 if (e == NULL) return 0;
56 if (e == extensions + elen - nlen)
58 /* Check if space follows (avoid same names with a suffix) */
59 if (*(e + nlen) == ' ')
68 typedef void (*PFVOID)();
70 PFVOID shGetProcAddress(const char *name)
73 return (PFVOID)wglGetProcAddress(name);
74 #elif defined(__APPLE__)
75 /* TODO: Mac OS glGetProcAddress implementation */
78 return (PFVOID)glXGetProcAddress((const unsigned char *)name);
82 void shLoadExtensions(VGContext *c)
84 const char *ext = (const char*)glGetString(GL_EXTENSIONS);
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;
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;
104 /* glActiveTexture, glMultiTexCoord1f */
105 if (checkExtension(ext, "GL_ARB_multitexture")) {
106 c->isGLAvailable_Multitexture = 1;
108 c->pglActiveTexture = (SH_PGLACTIVETEXTURE)
109 shGetProcAddress("glActiveTextureARB");
110 c->pglMultiTexCoord1f = (SH_PGLMULTITEXCOORD1F)
111 shGetProcAddress("glMultiTexCoord1fARB");
112 c->pglMultiTexCoord2f = (SH_PGLMULTITEXCOORD2F)
113 shGetProcAddress("glMultiTexCoord2fARB");
115 if (c->pglActiveTexture == NULL || c->pglMultiTexCoord1f == NULL ||
116 c->pglMultiTexCoord2f == NULL)
117 c->isGLAvailable_Multitexture = 0;
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;
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;