removed support for GL_SGIS_multitexture (ancient)
[divverent/darkplaces.git] / vid_shared.c
1
2 #include "quakedef.h"
3
4 // LordHavoc: these are only set in wgl
5 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
6 qboolean isRagePro = false; // LordHavoc: the ATI Rage Pro has limitations with per pixel alpha (the color scaler does not apply to per pixel alpha images...), although not as bad as a G200.
7
8 // LordHavoc: GL_ARB_multitexture support
9 int gl_mtexable = false;
10 // LordHavoc: GL_ARB_texture_env_combine support
11 int gl_combine_extension = false;
12 // LordHavoc: GL_EXT_compiled_vertex_array support
13 int gl_supportslockarrays = false;
14
15 cvar_t vid_mode = {0, "vid_mode", "0"};
16 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
17 cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"};
18 cvar_t gl_combine = {0, "gl_combine", "0"};
19
20 // GL_ARB_multitexture
21 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
22 void (GLAPIENTRY *qglActiveTexture) (GLenum);
23 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
24
25 // GL_EXT_compiled_vertex_array
26 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
27 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
28
29 typedef struct
30 {
31         char *name;
32         void **funcvariable;
33 }
34 gl_extensionfunctionlist_t;
35
36 typedef struct
37 {
38         char *name;
39         gl_extensionfunctionlist_t *funcs;
40         int *enablevariable;
41         char *disableparm;
42 }
43 gl_extensioninfo_t;
44
45 static gl_extensionfunctionlist_t multitexturefuncs[] =
46 {
47         {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
48         {"glActiveTextureARB", (void **) &qglActiveTexture},
49         {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
50         {NULL, NULL}
51 };
52
53 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
54 {
55         {"glLockArraysEXT", (void **) &qglLockArraysEXT},
56         {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
57         {NULL, NULL}
58 };
59
60 static gl_extensioninfo_t gl_extensioninfo[] =
61 {
62         {"GL_ARB_multitexture", multitexturefuncs, &gl_mtexable, "-nomtex"},
63         {"GL_ARB_texture_env_combine", NULL, &gl_combine_extension, "-nocombine"},
64         {"GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, &gl_supportslockarrays, "-nocva"},
65         {NULL, NULL, NULL, NULL}
66 };
67
68 #ifndef WIN32
69 #include <dlfcn.h>
70 #endif
71
72 void VID_CheckExtensions(void)
73 {
74 #ifndef WIN32
75         void *prjobj;
76 #endif
77         gl_extensioninfo_t *info;
78         gl_extensionfunctionlist_t *func;
79 //      multitexturefuncs[0].funcvariable = (void **)&qglMultiTexCoord2f;
80         Con_Printf("Checking OpenGL extensions...\n");
81 #ifndef WIN32
82         if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL)
83         {
84                 Con_Printf("Unable to open symbol list for main program.\n");
85                 return;
86         }
87 #endif
88         for (info = gl_extensioninfo;info && info->name;info++)
89         {
90                 *info->enablevariable = false;
91                 for (func = info->funcs;func && func->name;func++)
92                         *func->funcvariable = NULL;
93                 Con_Printf("checking for %s...  ", info->name);
94                 if (info->disableparm && COM_CheckParm(info->disableparm))
95                 {
96                         Con_Printf("disabled by commandline\n");
97                         continue;
98                 }
99                 if (strstr(gl_extensions, info->name))
100                 {
101                         for (func = info->funcs;func && func->name != NULL;func++)
102                         {
103 #ifdef WIN32
104                                 if (!(*func->funcvariable = (void *) wglGetProcAddress(func->name)))
105 #else
106                                 if (!(*func->funcvariable = (void *) dlsym(prjobj, func->name)))
107 #endif
108                                 {
109                                         Con_Printf("missing function \"%s\"!\n", func->name);
110                                         goto missingfunc;
111                                 }
112                         }
113                         Con_Printf("enabled\n");
114                         *info->enablevariable = true;
115                         missingfunc:;
116                 }
117                 else
118                         Con_Printf("not detected\n");
119         }
120 #ifndef WIN32
121         dlclose(prjobj);
122 #endif
123 }
124
125 /*
126 void VID_CheckCombine(void)
127 {
128         // LordHavoc: although texture_env_combine doesn't require multiple TMUs
129         // (it does require the multitexture extension however), it is useless to
130         // darkplaces without multiple TMUs...
131         if (gl_mtexable && strstr(gl_extensions, "GL_ARB_texture_env_combine "))
132         {
133                 gl_combine_extension = true;
134                 Cvar_SetValue("gl_combine", true);
135                 Con_Printf("GL_ARB_texture_env_combine detected\n");
136         }
137         else
138         {
139                 gl_combine_extension = false;
140                 Cvar_SetValue("gl_combine", false);
141                 Con_Printf("GL_ARB_texture_env_combine not detected\n");
142         }
143 }
144 */
145
146 void Force_CenterView_f (void)
147 {
148         cl.viewangles[PITCH] = 0;
149 }
150
151 void VID_InitCvars(void)
152 {
153         Cvar_RegisterVariable(&vid_mode);
154         Cvar_RegisterVariable(&vid_mouse);
155         Cvar_RegisterVariable(&vid_fullscreen);
156         Cvar_RegisterVariable(&gl_combine);
157         Cmd_AddCommand("force_centerview", Force_CenterView_f);
158 }