summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/windows/gldirect/dx9/gld_ext_dx9.c
blob: 745c987602bc4206e4bea4a299b9702744fef582 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/****************************************************************************
*
*                        Mesa 3-D graphics library
*                        Direct3D Driver Interface
*
*  ========================================================================
*
*   Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
*
*   Permission is hereby granted, free of charge, to any person obtaining a
*   copy of this software and associated documentation files (the "Software"),
*   to deal in the Software without restriction, including without limitation
*   the rights to use, copy, modify, merge, publish, distribute, sublicense,
*   and/or sell copies of the Software, and to permit persons to whom the
*   Software is furnished to do so, subject to the following conditions:
*
*   The above copyright notice and this permission notice shall be included
*   in all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
*   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
*   SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
*   OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*   SOFTWARE.
*
*  ======================================================================
*
* Language:     ANSI C
* Environment:  Windows 9x/2000/XP/XBox (Win32)
*
* Description:  GL extensions
*
****************************************************************************/

//#include "../GLDirect.h"
//#include "../gld_log.h"
//#include "../gld_settings.h"

#include <windows.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

//#include "ddlog.h"
//#include "gld_dx8.h"

#include "glheader.h"
#include "context.h"
#include "colormac.h"
#include "depth.h"
#include "extensions.h"
#include "macros.h"
#include "matrix.h"
// #include "mem.h"
//#include "mmath.h"
#include "mtypes.h"
#include "texformat.h"
#include "texstore.h"
#include "array_cache/acache.h"
#include "swrast_setup/swrast_setup.h"
#include "swrast_setup/ss_context.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"
#include "tnl/t_pipeline.h"

#include "dglcontext.h"
#include "extensions.h"

// For some reason this is not defined in an above header...
extern void _mesa_enable_imaging_extensions(GLcontext *ctx);

//---------------------------------------------------------------------------
// Hack for the SGIS_multitexture extension that was removed from Mesa
// NOTE: SGIS_multitexture enums also clash with GL_SGIX_async_pixel

	// NOTE: Quake2 ran *slower* with this enabled, so I've
	// disabled it for now.
	// To enable, uncomment:
	//  _mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0);

//---------------------------------------------------------------------------

enum {
	/* Quake2 GL_SGIS_multitexture */
	GL_SELECTED_TEXTURE_SGIS			= 0x835B,
	GL_SELECTED_TEXTURE_COORD_SET_SGIS	= 0x835C,
	GL_MAX_TEXTURES_SGIS				= 0x835D,
	GL_TEXTURE0_SGIS					= 0x835E,
	GL_TEXTURE1_SGIS					= 0x835F,
	GL_TEXTURE2_SGIS					= 0x8360,
	GL_TEXTURE3_SGIS					= 0x8361,
	GL_TEXTURE_COORD_SET_SOURCE_SGIS	= 0x8363,
};

//---------------------------------------------------------------------------

void APIENTRY gldSelectTextureSGIS(
	GLenum target)
{
	GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS);
	glActiveTextureARB(ARB_target);
}

//---------------------------------------------------------------------------

void APIENTRY gldMTexCoord2fSGIS(
	GLenum target,
	GLfloat s,
	GLfloat t)
{
	GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS);
	glMultiTexCoord2fARB(ARB_target, s, t);
}

//---------------------------------------------------------------------------

void APIENTRY gldMTexCoord2fvSGIS(
	GLenum target,
	const GLfloat *v)
{
	GLenum ARB_target = GL_TEXTURE0_ARB + (target - GL_TEXTURE0_SGIS);
	glMultiTexCoord2fvARB(ARB_target, v);
}

//---------------------------------------------------------------------------
// Extensions
//---------------------------------------------------------------------------

typedef struct {
	PROC proc;
	char *name;
}  GLD_extension;

GLD_extension GLD_extList[] = {
#ifdef GL_EXT_polygon_offset
    {	(PROC)glPolygonOffsetEXT,		"glPolygonOffsetEXT"		},
#endif
    {	(PROC)glBlendEquationEXT,		"glBlendEquationEXT"		},
    {	(PROC)glBlendColorEXT,			"glBlendColorExt"			},
    {	(PROC)glVertexPointerEXT,		"glVertexPointerEXT"		},
    {	(PROC)glNormalPointerEXT,		"glNormalPointerEXT"		},
    {	(PROC)glColorPointerEXT,		"glColorPointerEXT"			},
    {	(PROC)glIndexPointerEXT,		"glIndexPointerEXT"			},
    {	(PROC)glTexCoordPointerEXT,		"glTexCoordPointer"			},
    {	(PROC)glEdgeFlagPointerEXT,		"glEdgeFlagPointerEXT"		},
    {	(PROC)glGetPointervEXT,			"glGetPointervEXT"			},
    {	(PROC)glArrayElementEXT,		"glArrayElementEXT"			},
    {	(PROC)glDrawArraysEXT,			"glDrawArrayEXT"			},
    {	(PROC)glAreTexturesResidentEXT,	"glAreTexturesResidentEXT"	},
    {	(PROC)glBindTextureEXT,			"glBindTextureEXT"			},
    {	(PROC)glDeleteTexturesEXT,		"glDeleteTexturesEXT"		},
    {	(PROC)glGenTexturesEXT,			"glGenTexturesEXT"			},
    {	(PROC)glIsTextureEXT,			"glIsTextureEXT"			},
    {	(PROC)glPrioritizeTexturesEXT,	"glPrioritizeTexturesEXT"	},
    {	(PROC)glCopyTexSubImage3DEXT,	"glCopyTexSubImage3DEXT"	},
    {	(PROC)glTexImage3DEXT,			"glTexImage3DEXT"			},
    {	(PROC)glTexSubImage3DEXT,		"glTexSubImage3DEXT"		},
    {	(PROC)glPointParameterfEXT,		"glPointParameterfEXT"		},
    {	(PROC)glPointParameterfvEXT,	"glPointParameterfvEXT"		},

    {	(PROC)glLockArraysEXT,			"glLockArraysEXT"			},
    {	(PROC)glUnlockArraysEXT,		"glUnlockArraysEXT"			},
	{	NULL,							"\0"						}
};

GLD_extension GLD_multitexList[] = {
/*
    {	(PROC)glMultiTexCoord1dSGIS,		"glMTexCoord1dSGIS"			},
    {	(PROC)glMultiTexCoord1dvSGIS,		"glMTexCoord1dvSGIS"		},
    {	(PROC)glMultiTexCoord1fSGIS,		"glMTexCoord1fSGIS"			},
    {	(PROC)glMultiTexCoord1fvSGIS,		"glMTexCoord1fvSGIS"		},
    {	(PROC)glMultiTexCoord1iSGIS,		"glMTexCoord1iSGIS"			},
    {	(PROC)glMultiTexCoord1ivSGIS,		"glMTexCoord1ivSGIS"		},
    {	(PROC)glMultiTexCoord1sSGIS,		"glMTexCoord1sSGIS"			},
    {	(PROC)glMultiTexCoord1svSGIS,		"glMTexCoord1svSGIS"		},
    {	(PROC)glMultiTexCoord2dSGIS,		"glMTexCoord2dSGIS"			},
    {	(PROC)glMultiTexCoord2dvSGIS,		"glMTexCoord2dvSGIS"		},
    {	(PROC)glMultiTexCoord2fSGIS,		"glMTexCoord2fSGIS"			},
    {	(PROC)glMultiTexCoord2fvSGIS,		"glMTexCoord2fvSGIS"		},
    {	(PROC)glMultiTexCoord2iSGIS,		"glMTexCoord2iSGIS"			},
    {	(PROC)glMultiTexCoord2ivSGIS,		"glMTexCoord2ivSGIS"		},
    {	(PROC)glMultiTexCoord2sSGIS,		"glMTexCoord2sSGIS"			},
    {	(PROC)glMultiTexCoord2svSGIS,		"glMTexCoord2svSGIS"		},
    {	(PROC)glMultiTexCoord3dSGIS,		"glMTexCoord3dSGIS"			},
    {	(PROC)glMultiTexCoord3dvSGIS,		"glMTexCoord3dvSGIS"		},
    {	(PROC)glMultiTexCoord3fSGIS,		"glMTexCoord3fSGIS"			},
    {	(PROC)glMultiTexCoord3fvSGIS,		"glMTexCoord3fvSGIS"		},
    {	(PROC)glMultiTexCoord3iSGIS,		"glMTexCoord3iSGIS"			},
    {	(PROC)glMultiTexCoord3ivSGIS,		"glMTexCoord3ivSGIS"		},
    {	(PROC)glMultiTexCoord3sSGIS,		"glMTexCoord3sSGIS"			},
    {	(PROC)glMultiTexCoord3svSGIS,		"glMTexCoord3svSGIS"		},
    {	(PROC)glMultiTexCoord4dSGIS,		"glMTexCoord4dSGIS"			},
    {	(PROC)glMultiTexCoord4dvSGIS,		"glMTexCoord4dvSGIS"		},
    {	(PROC)glMultiTexCoord4fSGIS,		"glMTexCoord4fSGIS"			},
    {	(PROC)glMultiTexCoord4fvSGIS,		"glMTexCoord4fvSGIS"		},
    {	(PROC)glMultiTexCoord4iSGIS,		"glMTexCoord4iSGIS"			},
    {	(PROC)glMultiTexCoord4ivSGIS,		"glMTexCoord4ivSGIS"		},
    {	(PROC)glMultiTexCoord4sSGIS,		"glMTexCoord4sSGIS"			},
    {	(PROC)glMultiTexCoord4svSGIS,		"glMTexCoord4svSGIS"		},
    {	(PROC)glMultiTexCoordPointerSGIS,	"glMTexCoordPointerSGIS"	},
    {	(PROC)glSelectTextureSGIS,			"glSelectTextureSGIS"			},
    {	(PROC)glSelectTextureCoordSetSGIS,	"glSelectTextureCoordSetSGIS"	},
*/
    {	(PROC)glActiveTextureARB,		"glActiveTextureARB"		},
    {	(PROC)glClientActiveTextureARB,	"glClientActiveTextureARB"	},
    {	(PROC)glMultiTexCoord1dARB,		"glMultiTexCoord1dARB"		},
    {	(PROC)glMultiTexCoord1dvARB,	"glMultiTexCoord1dvARB"		},
    {	(PROC)glMultiTexCoord1fARB,		"glMultiTexCoord1fARB"		},
    {	(PROC)glMultiTexCoord1fvARB,	"glMultiTexCoord1fvARB"		},
    {	(PROC)glMultiTexCoord1iARB,		"glMultiTexCoord1iARB"		},
    {	(PROC)glMultiTexCoord1ivARB,	"glMultiTexCoord1ivARB"		},
    {	(PROC)glMultiTexCoord1sARB,		"glMultiTexCoord1sARB"		},
    {	(PROC)glMultiTexCoord1svARB,	"glMultiTexCoord1svARB"		},
    {	(PROC)glMultiTexCoord2dARB,		"glMultiTexCoord2dARB"		},
    {	(PROC)glMultiTexCoord2dvARB,	"glMultiTexCoord2dvARB"		},
    {	(PROC)glMultiTexCoord2fARB,		"glMultiTexCoord2fARB"		},
    {	(PROC)glMultiTexCoord2fvARB,	"glMultiTexCoord2fvARB"		},
    {	(PROC)glMultiTexCoord2iARB,		"glMultiTexCoord2iARB"		},
    {	(PROC)glMultiTexCoord2ivARB,	"glMultiTexCoord2ivARB"		},
    {	(PROC)glMultiTexCoord2sARB,		"glMultiTexCoord2sARB"		},
    {	(PROC)glMultiTexCoord2svARB,	"glMultiTexCoord2svARB"		},
    {	(PROC)glMultiTexCoord3dARB,		"glMultiTexCoord3dARB"		},
    {	(PROC)glMultiTexCoord3dvARB,	"glMultiTexCoord3dvARB"		},
    {	(PROC)glMultiTexCoord3fARB,		"glMultiTexCoord3fARB"		},
    {	(PROC)glMultiTexCoord3fvARB,	"glMultiTexCoord3fvARB"		},
    {	(PROC)glMultiTexCoord3iARB,		"glMultiTexCoord3iARB"		},
    {	(PROC)glMultiTexCoord3ivARB,	"glMultiTexCoord3ivARB"		},
    {	(PROC)glMultiTexCoord3sARB,		"glMultiTexCoord3sARB"		},
    {	(PROC)glMultiTexCoord3svARB,	"glMultiTexCoord3svARB"		},
    {	(PROC)glMultiTexCoord4dARB,		"glMultiTexCoord4dARB"		},
    {	(PROC)glMultiTexCoord4dvARB,	"glMultiTexCoord4dvARB"		},
    {	(PROC)glMultiTexCoord4fARB,		"glMultiTexCoord4fARB"		},
    {	(PROC)glMultiTexCoord4fvARB,	"glMultiTexCoord4fvARB"		},
    {	(PROC)glMultiTexCoord4iARB,		"glMultiTexCoord4iARB"		},
    {	(PROC)glMultiTexCoord4ivARB,	"glMultiTexCoord4ivARB"		},
    {	(PROC)glMultiTexCoord4sARB,		"glMultiTexCoord4sARB"		},
    {	(PROC)glMultiTexCoord4svARB,	"glMultiTexCoord4svARB"		},

	// Descent3 doesn't use correct string, hence this hack
    {	(PROC)glMultiTexCoord4fARB,		"glMultiTexCoord4f"			},

	// Quake2 SGIS multitexture
    {	(PROC)gldSelectTextureSGIS,		"glSelectTextureSGIS"		},
    {	(PROC)gldMTexCoord2fSGIS,		"glMTexCoord2fSGIS"			},
    {	(PROC)gldMTexCoord2fvSGIS,		"glMTexCoord2fvSGIS"		},

	{	NULL,							"\0"						}
};

//---------------------------------------------------------------------------

PROC gldGetProcAddress_DX(
	LPCSTR a)
{
	int		i;
	PROC	proc = NULL;

	for (i=0; GLD_extList[i].proc; i++) {
		if (!strcmp(a, GLD_extList[i].name)) {
			proc = GLD_extList[i].proc;
			break;
		}
	}

	if (glb.bMultitexture) {
		for (i=0; GLD_multitexList[i].proc; i++) {
			if (!strcmp(a, GLD_multitexList[i].name)) {
				proc = GLD_multitexList[i].proc;
				break;
			}
		}
	}

	gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed");

	return proc;
}

//---------------------------------------------------------------------------

void gldEnableExtensions_DX9(
	GLcontext *ctx)
{
	GLuint i;

	// Mesa enables some extensions by default.
	// This table decides which ones we want to switch off again.

	// NOTE: GL_EXT_compiled_vertex_array appears broken.

	const char *gld_disable_extensions[] = {
//		"GL_ARB_transpose_matrix",
//		"GL_EXT_compiled_vertex_array",
//		"GL_EXT_polygon_offset",
//		"GL_EXT_rescale_normal",
		"GL_EXT_texture3D",
//		"GL_NV_texgen_reflection",
		NULL
	};

	const char *gld_multitex_extensions[] = {
		"GL_ARB_multitexture",		// Quake 3
		NULL
	};

	// Quake 2 engines
	const char *szGL_SGIS_multitexture = "GL_SGIS_multitexture";

	const char *gld_enable_extensions[] = {
		"GL_EXT_texture_env_add",	// Quake 3
		"GL_ARB_texture_env_add",	// Quake 3
		NULL
	};
	
	for (i=0; gld_disable_extensions[i]; i++) {
		_mesa_disable_extension(ctx, gld_disable_extensions[i]);
	}
	
	for (i=0; gld_enable_extensions[i]; i++) {
		_mesa_enable_extension(ctx, gld_enable_extensions[i]);
	}

	if (glb.bMultitexture) {	
		for (i=0; gld_multitex_extensions[i]; i++) {
			_mesa_enable_extension(ctx, gld_multitex_extensions[i]);
		}

		// GL_SGIS_multitexture
		// NOTE: Quake2 ran *slower* with this enabled, so I've
		// disabled it for now.
		// Fair bit slower on GeForce256,
		// Much slower on 3dfx Voodoo5 5500.
//		_mesa_add_extension(ctx, GL_TRUE, szGL_SGIS_multitexture, 0);

	}

	_mesa_enable_imaging_extensions(ctx);
	_mesa_enable_1_3_extensions(ctx);
	_mesa_enable_1_4_extensions(ctx);
}

//---------------------------------------------------------------------------