2 * Compatibility functions for older GL implementations
4 * Copyright 2008 Stefan Dösinger for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(gl_compat);
30 /* Start GL_ARB_multitexture emulation */
31 static void WINE_GLAPI wine_glMultiTexCoord1fARB(GLenum target, GLfloat s) {
32 if(target != GL_TEXTURE0) {
33 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
39 static void WINE_GLAPI wine_glMultiTexCoord1fvARB(GLenum target, const GLfloat *v) {
40 if(target != GL_TEXTURE0) {
41 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
47 static void WINE_GLAPI wine_glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t) {
48 if(target != GL_TEXTURE0) {
49 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
55 static void WINE_GLAPI wine_glMultiTexCoord2fvARB(GLenum target, const GLfloat *v) {
56 if(target != GL_TEXTURE0) {
57 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
63 static void WINE_GLAPI wine_glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r) {
64 if(target != GL_TEXTURE0) {
65 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
68 glTexCoord3f(s, t, r);
71 static void WINE_GLAPI wine_glMultiTexCoord3fvARB(GLenum target, const GLfloat *v) {
72 if(target != GL_TEXTURE0) {
73 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
79 static void WINE_GLAPI wine_glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
80 if(target != GL_TEXTURE0) {
81 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
84 glTexCoord4f(s, t, r, q);
87 static void WINE_GLAPI wine_glMultiTexCoord4fvARB(GLenum target, const GLfloat *v) {
88 if(target != GL_TEXTURE0) {
89 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
95 static void WINE_GLAPI wine_glMultiTexCoord2svARB(GLenum target, const GLshort *v) {
96 if(target != GL_TEXTURE0) {
97 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
103 static void WINE_GLAPI wine_glMultiTexCoord4svARB(GLenum target, const GLshort *v) {
104 if(target != GL_TEXTURE0) {
105 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
111 static void WINE_GLAPI wine_glActiveTextureARB(GLenum texture) {
112 if(texture != GL_TEXTURE0) {
113 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
118 static void WINE_GLAPI wine_glClientActiveTextureARB(GLenum texture) {
119 if(texture != GL_TEXTURE0) {
120 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
125 static void (WINE_GLAPI *old_multitex_glGetIntegerv) (GLenum pname, GLint* params) = NULL;
126 static void WINE_GLAPI wine_glGetIntegerv(GLenum pname, GLint* params) {
128 case GL_ACTIVE_TEXTURE: *params = 0; break;
129 case GL_MAX_TEXTURE_UNITS_ARB: *params = 1; break;
130 default: old_multitex_glGetIntegerv(pname, params);
134 static void (WINE_GLAPI *old_multitex_glGetFloatv) (GLenum pname, GLfloat* params) = NULL;
135 static void WINE_GLAPI wine_glGetFloatv(GLenum pname, GLfloat* params) {
136 if (pname == GL_ACTIVE_TEXTURE) *params = 0.0f;
137 else old_multitex_glGetFloatv(pname, params);
140 static void (WINE_GLAPI *old_multitex_glGetDoublev) (GLenum pname, GLdouble* params) = NULL;
141 static void WINE_GLAPI wine_glGetDoublev(GLenum pname, GLdouble* params) {
142 if(pname == GL_ACTIVE_TEXTURE) *params = 0.0;
143 else old_multitex_glGetDoublev(pname, params);
146 /* Start GL_EXT_fogcoord emulation */
147 static void (WINE_GLAPI *old_fogcoord_glEnable) (GLenum cap) = NULL;
148 static void WINE_GLAPI wine_glEnable(GLenum cap) {
150 struct wined3d_context *ctx = context_get_current();
151 ctx->fog_enabled = 1;
152 if(ctx->gl_fog_source != GL_FRAGMENT_DEPTH_EXT) return;
154 old_fogcoord_glEnable(cap);
157 static void (WINE_GLAPI *old_fogcoord_glDisable) (GLenum cap) = NULL;
158 static void WINE_GLAPI wine_glDisable(GLenum cap) {
160 struct wined3d_context *ctx = context_get_current();
161 ctx->fog_enabled = 0;
162 if(ctx->gl_fog_source != GL_FRAGMENT_DEPTH_EXT) return;
164 old_fogcoord_glDisable(cap);
167 static void (WINE_GLAPI *old_fogcoord_glFogi) (GLenum pname, GLint param) = NULL;
168 static void WINE_GLAPI wine_glFogi(GLenum pname, GLint param) {
169 struct wined3d_context *ctx = context_get_current();
171 if(pname == GL_FOG_COORDINATE_SOURCE_EXT) {
172 ctx->gl_fog_source = param;
173 if(param == GL_FRAGMENT_DEPTH_EXT) {
174 if(ctx->fog_enabled) old_fogcoord_glEnable(GL_FOG);
176 WARN("Fog coords activated, but not supported. Using slow emulation\n");
177 old_fogcoord_glDisable(GL_FOG);
180 if(pname == GL_FOG_START) {
181 ctx->fogstart = (float) param;
182 } else if(pname == GL_FOG_END) {
183 ctx->fogend = (float) param;
185 old_fogcoord_glFogi(pname, param);
189 static void (WINE_GLAPI *old_fogcoord_glFogiv) (GLenum pname, const GLint *param) = NULL;
190 static void WINE_GLAPI wine_glFogiv(GLenum pname, const GLint *param) {
191 struct wined3d_context *ctx = context_get_current();
192 if(pname == GL_FOG_COORDINATE_SOURCE_EXT) {
193 ctx->gl_fog_source = *param;
194 if(*param == GL_FRAGMENT_DEPTH_EXT) {
195 if(ctx->fog_enabled) old_fogcoord_glEnable(GL_FOG);
197 WARN("Fog coords activated, but not supported. Using slow emulation\n");
198 old_fogcoord_glDisable(GL_FOG);
201 if(pname == GL_FOG_START) {
202 ctx->fogstart = (float) *param;
203 } else if(pname == GL_FOG_END) {
204 ctx->fogend = (float) *param;
206 old_fogcoord_glFogiv(pname, param);
210 static void (WINE_GLAPI *old_fogcoord_glFogf) (GLenum pname, GLfloat param) = NULL;
211 static void WINE_GLAPI wine_glFogf(GLenum pname, GLfloat param) {
212 struct wined3d_context *ctx = context_get_current();
213 if(pname == GL_FOG_COORDINATE_SOURCE_EXT) {
214 ctx->gl_fog_source = (GLint) param;
215 if(param == GL_FRAGMENT_DEPTH_EXT) {
216 if(ctx->fog_enabled) old_fogcoord_glEnable(GL_FOG);
218 WARN("Fog coords activated, but not supported. Using slow emulation\n");
219 old_fogcoord_glDisable(GL_FOG);
222 if(pname == GL_FOG_START) {
223 ctx->fogstart = param;
224 } else if(pname == GL_FOG_END) {
227 old_fogcoord_glFogf(pname, param);
231 static void (WINE_GLAPI *old_fogcoord_glFogfv) (GLenum pname, const GLfloat *param) = NULL;
232 static void WINE_GLAPI wine_glFogfv(GLenum pname, const GLfloat *param) {
233 struct wined3d_context *ctx = context_get_current();
234 if(pname == GL_FOG_COORDINATE_SOURCE_EXT) {
235 ctx->gl_fog_source = (GLint) *param;
236 if(*param == GL_FRAGMENT_DEPTH_EXT) {
237 if(ctx->fog_enabled) old_fogcoord_glEnable(GL_FOG);
239 WARN("Fog coords activated, but not supported. Using slow emulation\n");
240 old_fogcoord_glDisable(GL_FOG);
243 if(pname == GL_FOG_COLOR) {
244 ctx->fogcolor[0] = param[0];
245 ctx->fogcolor[1] = param[1];
246 ctx->fogcolor[2] = param[2];
247 ctx->fogcolor[3] = param[3];
248 } else if(pname == GL_FOG_START) {
249 ctx->fogstart = *param;
250 } else if(pname == GL_FOG_END) {
251 ctx->fogend = *param;
253 old_fogcoord_glFogfv(pname, param);
257 static void (WINE_GLAPI *old_fogcoord_glVertex4f) (GLfloat x, GLfloat y, GLfloat z, GLfloat w) = NULL;
258 static void (WINE_GLAPI *old_fogcoord_glVertex4fv) (const GLfloat *pos) = NULL;
259 static void (WINE_GLAPI *old_fogcoord_glVertex3f) (GLfloat x, GLfloat y, GLfloat z) = NULL;
260 static void (WINE_GLAPI *old_fogcoord_glVertex3fv) (const GLfloat *pos) = NULL;
261 static void (WINE_GLAPI *old_fogcoord_glColor4f) (GLfloat r, GLfloat g, GLfloat b, GLfloat a) = NULL;
262 static void (WINE_GLAPI *old_fogcoord_glColor4fv) (const GLfloat *color) = NULL;
263 static void (WINE_GLAPI *old_fogcoord_glColor3f) (GLfloat r, GLfloat g, GLfloat b) = NULL;
264 static void (WINE_GLAPI *old_fogcoord_glColor3fv) (const GLfloat *color) = NULL;
265 static void (WINE_GLAPI *old_fogcoord_glColor4ub) (GLubyte r, GLubyte g, GLubyte b, GLubyte a) = NULL;
266 static void (WINE_GLAPI *old_fogcoord_glFogCoordfEXT) (GLfloat f) = NULL;
267 static void (WINE_GLAPI *old_fogcoord_glFogCoorddEXT) (GLdouble f) = NULL;
268 static void (WINE_GLAPI *old_fogcoord_glFogCoordfvEXT) (const GLfloat *f) = NULL;
269 static void (WINE_GLAPI *old_fogcoord_glFogCoorddvEXT) (const GLdouble *f) = NULL;
271 static void WINE_GLAPI wine_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
272 struct wined3d_context *ctx = context_get_current();
273 if(ctx->gl_fog_source == GL_FOG_COORDINATE_EXT && ctx->fog_enabled) {
274 GLfloat c[4] = {ctx->color[0], ctx->color[1], ctx->color[2], ctx->color[3]};
277 i = (ctx->fogend - ctx->fog_coord_value) / (ctx->fogend - ctx->fogstart);
278 c[0] = i * c[0] + (1.0f - i) * ctx->fogcolor[0];
279 c[1] = i * c[1] + (1.0f - i) * ctx->fogcolor[1];
280 c[2] = i * c[2] + (1.0f - i) * ctx->fogcolor[2];
282 old_fogcoord_glColor4f(c[0], c[1], c[2], c[3]);
283 old_fogcoord_glVertex4f(x, y, z, w);
285 old_fogcoord_glVertex4f(x, y, z, w);
289 static void WINE_GLAPI wine_glVertex4fv(const GLfloat *pos) {
290 wine_glVertex4f(pos[0], pos[1], pos[2], pos[3]);
293 static void WINE_GLAPI wine_glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
294 wine_glVertex4f(x, y, z, 1.0f);
297 static void WINE_GLAPI wine_glVertex3fv(const GLfloat *pos) {
298 wine_glVertex4f(pos[0], pos[1], pos[2], 1.0f);
301 static void WINE_GLAPI wine_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
302 struct wined3d_context *ctx = context_get_current();
307 old_fogcoord_glColor4f(r, g, b, a);
310 static void WINE_GLAPI wine_glColor4fv(const GLfloat *c) {
311 wine_glColor4f(c[0], c[1], c[2], c[3]);
314 static void WINE_GLAPI wine_glColor3f(GLfloat r, GLfloat g, GLfloat b) {
315 wine_glColor4f(r, g, b, 1.0f);
318 static void WINE_GLAPI wine_glColor3fv(const GLfloat *c) {
319 wine_glColor4f(c[0], c[1], c[2], 1.0f);
322 static void WINE_GLAPI wine_glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
323 wine_glColor4f(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
326 /* In D3D the fog coord is a UBYTE, so there's no problem with using the single
329 static void WINE_GLAPI wine_glFogCoordfEXT(GLfloat f) {
330 struct wined3d_context *ctx = context_get_current();
331 ctx->fog_coord_value = f;
333 static void WINE_GLAPI wine_glFogCoorddEXT(GLdouble f) {
334 wine_glFogCoordfEXT((GLfloat) f);
336 static void WINE_GLAPI wine_glFogCoordfvEXT(const GLfloat *f) {
337 wine_glFogCoordfEXT(*f);
339 static void WINE_GLAPI wine_glFogCoorddvEXT(const GLdouble *f) {
340 wine_glFogCoordfEXT((GLfloat) *f);
343 /* End GL_EXT_fog_coord emulation */
345 void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info)
347 if (!gl_info->supported[ARB_MULTITEXTURE])
349 TRACE("Applying GL_ARB_multitexture emulation hooks\n");
350 gl_info->glActiveTextureARB = wine_glActiveTextureARB;
351 gl_info->glClientActiveTextureARB = wine_glClientActiveTextureARB;
352 gl_info->glMultiTexCoord1fARB = wine_glMultiTexCoord1fARB;
353 gl_info->glMultiTexCoord1fvARB = wine_glMultiTexCoord1fvARB;
354 gl_info->glMultiTexCoord2fARB = wine_glMultiTexCoord2fARB;
355 gl_info->glMultiTexCoord2fvARB = wine_glMultiTexCoord2fvARB;
356 gl_info->glMultiTexCoord3fARB = wine_glMultiTexCoord3fARB;
357 gl_info->glMultiTexCoord3fvARB = wine_glMultiTexCoord3fvARB;
358 gl_info->glMultiTexCoord4fARB = wine_glMultiTexCoord4fARB;
359 gl_info->glMultiTexCoord4fvARB = wine_glMultiTexCoord4fvARB;
360 gl_info->glMultiTexCoord2svARB = wine_glMultiTexCoord2svARB;
361 gl_info->glMultiTexCoord4svARB = wine_glMultiTexCoord4svARB;
362 if(old_multitex_glGetIntegerv) {
363 FIXME("GL_ARB_multitexture glGetIntegerv hook already applied\n");
365 old_multitex_glGetIntegerv = glGetIntegerv;
366 glGetIntegerv = wine_glGetIntegerv;
368 if(old_multitex_glGetFloatv) {
369 FIXME("GL_ARB_multitexture glGetGloatv hook already applied\n");
371 old_multitex_glGetFloatv = glGetFloatv;
372 glGetFloatv = wine_glGetFloatv;
374 if(old_multitex_glGetDoublev) {
375 FIXME("GL_ARB_multitexture glGetDoublev hook already applied\n");
377 old_multitex_glGetDoublev = glGetDoublev;
378 glGetDoublev = wine_glGetDoublev;
380 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
383 if (!gl_info->supported[EXT_FOG_COORD])
385 /* This emulation isn't perfect. There are a number of potential problems, but they should
386 * not matter in practise:
388 * Fog vs fragment shader: If we are using GL_ARB_fragment_program with the fog option, the
389 * glDisable(GL_FOG) here won't matter. However, if we have GL_ARB_fragment_program, it is pretty
390 * unlikely that we don't have GL_EXT_fog_coord. Besides, we probably have GL_ARB_vertex_program
391 * too, which would allow fog coord emulation in a fixed function vertex pipeline replacement.
393 * Fog vs texture: We apply the fog in the vertex color. An app could set up texturing settings which
394 * ignore the vertex color, thus effectively disabing our fog. However, in D3D this type of fog is
395 * a per-vertex fog too, so the apps shouldn't do that.
397 * Fog vs lighting: The app could in theory use D3DFOG_NONE table and D3DFOG_NONE vertex fog with
398 * untransformed vertices. That enables lighting and fog coords at the same time, and the lighting
399 * calculations could affect the already blended in fog color. There's nothing we can do against that,
400 * but most apps using fog color do their own lighting too and often even use RHW vertices. So live
403 TRACE("Applying GL_ARB_fog_coord emulation hooks\n");
405 /* This probably means that the implementation doesn't advertise the extension, but implicitly supports
406 * it via the GL core version, or someone messed around in the extension table in directx.c. Add version-
407 * dependent loading for this extension if we ever hit this situation
409 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
411 FIXME("GL implementation supports GL_ARB_fragment_program but not GL_EXT_fog_coord\n");
412 FIXME("The fog coord emulation will most likely fail\n");
414 else if (gl_info->supported[ARB_FRAGMENT_SHADER])
416 FIXME("GL implementation supports GL_ARB_fragment_shader but not GL_EXT_fog_coord\n");
417 FIXME("The fog coord emulation will most likely fail\n");
420 if(old_fogcoord_glFogi) {
421 FIXME("GL_EXT_fogcoord glFogi hook already applied\n");
423 old_fogcoord_glFogi = glFogi;
424 glFogi = wine_glFogi;
426 if(old_fogcoord_glFogiv) {
427 FIXME("GL_EXT_fogcoord glFogiv hook already applied\n");
429 old_fogcoord_glFogiv = glFogiv;
430 glFogiv = wine_glFogiv;
432 if(old_fogcoord_glFogf) {
433 FIXME("GL_EXT_fogcoord glFogf hook already applied\n");
435 old_fogcoord_glFogf = glFogf;
436 glFogf = wine_glFogf;
438 if(old_fogcoord_glFogfv) {
439 FIXME("GL_EXT_fogcoord glFogfv hook already applied\n");
441 old_fogcoord_glFogfv = glFogfv;
442 glFogfv = wine_glFogfv;
444 if(old_fogcoord_glEnable) {
445 FIXME("GL_EXT_fogcoord glEnable hook already applied\n");
447 old_fogcoord_glEnable = glEnableWINE;
448 glEnableWINE = wine_glEnable;
450 if(old_fogcoord_glDisable) {
451 FIXME("GL_EXT_fogcoord glDisable hook already applied\n");
453 old_fogcoord_glDisable = glDisableWINE;
454 glDisableWINE = wine_glDisable;
457 if(old_fogcoord_glVertex4f) {
458 FIXME("GL_EXT_fogcoord glVertex4f hook already applied\n");
460 old_fogcoord_glVertex4f = glVertex4f;
461 glVertex4f = wine_glVertex4f;
463 if(old_fogcoord_glVertex4fv) {
464 FIXME("GL_EXT_fogcoord glVertex4fv hook already applied\n");
466 old_fogcoord_glVertex4fv = glVertex4fv;
467 glVertex4fv = wine_glVertex4fv;
469 if(old_fogcoord_glVertex3f) {
470 FIXME("GL_EXT_fogcoord glVertex3f hook already applied\n");
472 old_fogcoord_glVertex3f = glVertex3f;
473 glVertex3f = wine_glVertex3f;
475 if(old_fogcoord_glVertex3fv) {
476 FIXME("GL_EXT_fogcoord glVertex3fv hook already applied\n");
478 old_fogcoord_glVertex3fv = glVertex3fv;
479 glVertex3fv = wine_glVertex3fv;
482 if(old_fogcoord_glColor4f) {
483 FIXME("GL_EXT_fogcoord glColor4f hook already applied\n");
485 old_fogcoord_glColor4f = glColor4f;
486 glColor4f = wine_glColor4f;
488 if(old_fogcoord_glColor4fv) {
489 FIXME("GL_EXT_fogcoord glColor4fv hook already applied\n");
491 old_fogcoord_glColor4fv = glColor4fv;
492 glColor4fv = wine_glColor4fv;
494 if(old_fogcoord_glColor3f) {
495 FIXME("GL_EXT_fogcoord glColor3f hook already applied\n");
497 old_fogcoord_glColor3f = glColor3f;
498 glColor3f = wine_glColor3f;
500 if(old_fogcoord_glColor3fv) {
501 FIXME("GL_EXT_fogcoord glColor3fv hook already applied\n");
503 old_fogcoord_glColor3fv = glColor3fv;
504 glColor3fv = wine_glColor3fv;
506 if(old_fogcoord_glColor4ub) {
507 FIXME("GL_EXT_fogcoord glColor4ub hook already applied\n");
509 old_fogcoord_glColor4ub = glColor4ub;
510 glColor4ub = wine_glColor4ub;
513 if(old_fogcoord_glFogCoordfEXT) {
514 FIXME("GL_EXT_fogcoord glFogCoordfEXT hook already applied\n");
516 old_fogcoord_glFogCoordfEXT = gl_info->glFogCoordfEXT;
517 gl_info->glFogCoordfEXT = wine_glFogCoordfEXT;
519 if(old_fogcoord_glFogCoordfvEXT) {
520 FIXME("GL_EXT_fogcoord glFogCoordfvEXT hook already applied\n");
522 old_fogcoord_glFogCoordfvEXT = gl_info->glFogCoordfvEXT;
523 gl_info->glFogCoordfvEXT = wine_glFogCoordfvEXT;
525 if(old_fogcoord_glFogCoorddEXT) {
526 FIXME("GL_EXT_fogcoord glFogCoorddEXT hook already applied\n");
528 old_fogcoord_glFogCoorddEXT = gl_info->glFogCoorddEXT;
529 gl_info->glFogCoorddEXT = wine_glFogCoorddEXT;
531 if(old_fogcoord_glFogCoorddvEXT) {
532 FIXME("GL_EXT_fogcoord glFogCoorddvEXT hook already applied\n");
534 old_fogcoord_glFogCoorddvEXT = gl_info->glFogCoorddvEXT;
535 gl_info->glFogCoorddvEXT = wine_glFogCoorddvEXT;
537 gl_info->supported[EXT_FOG_COORD] = TRUE;