mf/tests: Test input type for WMA decoder DMO.
[wine.git] / dlls / wined3d / gl_compat.c
blob261b06fe77861845719e366223dc050f0bea039d
1 /*
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
21 #include <stdio.h>
23 #include "wined3d_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(gl_compat);
26 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
28 /* Start GL_ARB_multitexture emulation */
29 static void WINE_GLAPI wine_glMultiTexCoord1fARB(GLenum target, GLfloat s)
31 if (target != GL_TEXTURE0)
33 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
34 return;
36 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord1f(s);
39 static void WINE_GLAPI wine_glMultiTexCoord1fvARB(GLenum target, const GLfloat *v)
41 if (target != GL_TEXTURE0)
43 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
44 return;
46 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord1fv(v);
49 static void WINE_GLAPI wine_glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t)
51 if (target != GL_TEXTURE0)
53 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
54 return;
56 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord2f(s, t);
59 static void WINE_GLAPI wine_glMultiTexCoord2fvARB(GLenum target, const GLfloat *v)
61 if (target != GL_TEXTURE0)
63 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
64 return;
66 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord2fv(v);
69 static void WINE_GLAPI wine_glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r)
71 if (target != GL_TEXTURE0)
73 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
74 return;
76 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord3f(s, t, r);
79 static void WINE_GLAPI wine_glMultiTexCoord3fvARB(GLenum target, const GLfloat *v)
81 if (target != GL_TEXTURE0)
83 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
84 return;
86 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord3fv(v);
89 static void WINE_GLAPI wine_glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
91 if (target != GL_TEXTURE0)
93 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
94 return;
96 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord4f(s, t, r, q);
99 static void WINE_GLAPI wine_glMultiTexCoord4fvARB(GLenum target, const GLfloat *v)
101 if (target != GL_TEXTURE0)
103 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
104 return;
106 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord4fv(v);
109 static void WINE_GLAPI wine_glMultiTexCoord2svARB(GLenum target, const GLshort *v)
111 if (target != GL_TEXTURE0)
113 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
114 return;
116 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord2sv(v);
119 static void WINE_GLAPI wine_glMultiTexCoord4svARB(GLenum target, const GLshort *v)
121 if (target != GL_TEXTURE0)
123 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported.\n");
124 return;
126 wined3d_context_gl_get_current()->gl_info->gl_ops.gl.p_glTexCoord4sv(v);
129 static void WINE_GLAPI wine_glActiveTexture(GLenum texture)
131 if(texture != GL_TEXTURE0) {
132 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
133 return;
137 static void WINE_GLAPI wine_glClientActiveTextureARB(GLenum texture) {
138 if(texture != GL_TEXTURE0) {
139 ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
140 return;
144 static void (WINE_GLAPI *old_multitex_glGetIntegerv) (GLenum pname, GLint* params) = NULL;
145 static void WINE_GLAPI wine_glGetIntegerv(GLenum pname, GLint* params) {
146 switch(pname) {
147 case GL_ACTIVE_TEXTURE: *params = 0; break;
148 case GL_MAX_TEXTURE_UNITS_ARB: *params = 1; break;
149 default: old_multitex_glGetIntegerv(pname, params);
153 static void (WINE_GLAPI *old_multitex_glGetFloatv) (GLenum pname, GLfloat* params) = NULL;
154 static void WINE_GLAPI wine_glGetFloatv(GLenum pname, GLfloat* params) {
155 if (pname == GL_ACTIVE_TEXTURE) *params = 0.0f;
156 else old_multitex_glGetFloatv(pname, params);
159 static void (WINE_GLAPI *old_multitex_glGetDoublev) (GLenum pname, GLdouble* params) = NULL;
160 static void WINE_GLAPI wine_glGetDoublev(GLenum pname, GLdouble* params) {
161 if(pname == GL_ACTIVE_TEXTURE) *params = 0.0;
162 else old_multitex_glGetDoublev(pname, params);
165 /* Start GL_EXT_fogcoord emulation */
166 static void (WINE_GLAPI *old_fogcoord_glEnable)(GLenum cap);
167 static void WINE_GLAPI wine_glEnable(GLenum cap)
169 if (cap == GL_FOG)
171 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
173 ctx->fog_enabled = 1;
174 if (ctx->gl_fog_source != GL_FRAGMENT_DEPTH_EXT)
175 return;
177 old_fogcoord_glEnable(cap);
180 static void (WINE_GLAPI *old_fogcoord_glDisable)(GLenum cap);
181 static void WINE_GLAPI wine_glDisable(GLenum cap)
183 if (cap == GL_FOG)
185 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
187 ctx->fog_enabled = 0;
188 if (ctx->gl_fog_source != GL_FRAGMENT_DEPTH_EXT)
189 return;
191 old_fogcoord_glDisable(cap);
194 static void (WINE_GLAPI *old_fogcoord_glFogi)(GLenum pname, GLint param);
195 static void WINE_GLAPI wine_glFogi(GLenum pname, GLint param)
197 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
199 if (pname == GL_FOG_COORDINATE_SOURCE_EXT)
201 ctx->gl_fog_source = param;
202 if (param == GL_FRAGMENT_DEPTH_EXT)
204 if (ctx->fog_enabled)
205 old_fogcoord_glEnable(GL_FOG);
207 else
209 WARN_(d3d_perf)("Fog coordinates activated, but not supported. Using slow emulation.\n");
210 old_fogcoord_glDisable(GL_FOG);
213 else
215 if (pname == GL_FOG_START)
216 ctx->fog_start = (float)param;
217 else if (pname == GL_FOG_END)
218 ctx->fog_end = (float)param;
219 old_fogcoord_glFogi(pname, param);
223 static void (WINE_GLAPI *old_fogcoord_glFogiv)(GLenum pname, const GLint *param);
224 static void WINE_GLAPI wine_glFogiv(GLenum pname, const GLint *param)
226 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
228 if (pname == GL_FOG_COORDINATE_SOURCE_EXT)
230 ctx->gl_fog_source = *param;
231 if (*param == GL_FRAGMENT_DEPTH_EXT)
233 if (ctx->fog_enabled)
234 old_fogcoord_glEnable(GL_FOG);
236 else
238 WARN_(d3d_perf)("Fog coordinates activated, but not supported. Using slow emulation.\n");
239 old_fogcoord_glDisable(GL_FOG);
242 else
244 if (pname == GL_FOG_START)
245 ctx->fog_start = (float)*param;
246 else if (pname == GL_FOG_END)
247 ctx->fog_end = (float)*param;
248 old_fogcoord_glFogiv(pname, param);
252 static void (WINE_GLAPI *old_fogcoord_glFogf)(GLenum pname, GLfloat param);
253 static void WINE_GLAPI wine_glFogf(GLenum pname, GLfloat param)
255 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
257 if (pname == GL_FOG_COORDINATE_SOURCE_EXT)
259 ctx->gl_fog_source = (GLint)param;
260 if (param == GL_FRAGMENT_DEPTH_EXT)
262 if (ctx->fog_enabled)
263 old_fogcoord_glEnable(GL_FOG);
265 else
267 WARN_(d3d_perf)("Fog coordinates activated, but not supported. Using slow emulation.\n");
268 old_fogcoord_glDisable(GL_FOG);
271 else
273 if (pname == GL_FOG_START)
274 ctx->fog_start = param;
275 else if (pname == GL_FOG_END)
276 ctx->fog_end = param;
277 old_fogcoord_glFogf(pname, param);
281 static void (WINE_GLAPI *old_fogcoord_glFogfv)(GLenum pname, const GLfloat *param);
282 static void WINE_GLAPI wine_glFogfv(GLenum pname, const GLfloat *param)
284 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
286 if (pname == GL_FOG_COORDINATE_SOURCE_EXT)
288 ctx->gl_fog_source = (GLint)*param;
289 if (*param == GL_FRAGMENT_DEPTH_EXT)
291 if (ctx->fog_enabled)
292 old_fogcoord_glEnable(GL_FOG);
294 else
296 WARN_(d3d_perf)("Fog coordinates activated, but not supported. Using slow emulation.\n");
297 old_fogcoord_glDisable(GL_FOG);
300 else
302 if (pname == GL_FOG_COLOR)
304 ctx->fog_colour[0] = param[0];
305 ctx->fog_colour[1] = param[1];
306 ctx->fog_colour[2] = param[2];
307 ctx->fog_colour[3] = param[3];
309 else if (pname == GL_FOG_START)
311 ctx->fog_start = *param;
313 else if (pname == GL_FOG_END)
315 ctx->fog_end = *param;
317 old_fogcoord_glFogfv(pname, param);
321 static void (WINE_GLAPI *old_fogcoord_glVertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
322 static void (WINE_GLAPI *old_fogcoord_glColor4f)(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
324 static void WINE_GLAPI wine_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
326 const struct wined3d_context_gl *ctx_gl = wined3d_context_gl_get_current();
328 /* This can be called from draw_test_quad() and at that point there is no
329 * wined3d_context current. */
330 if (!ctx_gl)
332 old_fogcoord_glVertex4f(x, y, z, w);
333 return;
336 if (ctx_gl->gl_fog_source == GL_FOG_COORDINATE_EXT && ctx_gl->fog_enabled)
338 GLfloat c[4] = {ctx_gl->colour[0], ctx_gl->colour[1], ctx_gl->colour[2], ctx_gl->colour[3]};
339 GLfloat i;
341 i = (ctx_gl->fog_end - ctx_gl->fog_coord_value) / (ctx_gl->fog_end - ctx_gl->fog_start);
342 c[0] = i * c[0] + (1.0f - i) * ctx_gl->fog_colour[0];
343 c[1] = i * c[1] + (1.0f - i) * ctx_gl->fog_colour[1];
344 c[2] = i * c[2] + (1.0f - i) * ctx_gl->fog_colour[2];
346 old_fogcoord_glColor4f(c[0], c[1], c[2], c[3]);
347 old_fogcoord_glVertex4f(x, y, z, w);
349 else
351 old_fogcoord_glVertex4f(x, y, z, w);
355 static void WINE_GLAPI wine_glVertex4fv(const GLfloat *pos) {
356 wine_glVertex4f(pos[0], pos[1], pos[2], pos[3]);
359 static void WINE_GLAPI wine_glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
360 wine_glVertex4f(x, y, z, 1.0f);
363 static void WINE_GLAPI wine_glVertex3fv(const GLfloat *pos) {
364 wine_glVertex4f(pos[0], pos[1], pos[2], 1.0f);
367 static void WINE_GLAPI wine_glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
369 struct wined3d_context_gl *ctx_gl = wined3d_context_gl_get_current();
371 /* This can be called from draw_test_quad() and at that point there is no
372 * wined3d_context current. */
373 if (!ctx_gl)
375 old_fogcoord_glColor4f(r, g, b, a);
376 return;
379 ctx_gl->colour[0] = r;
380 ctx_gl->colour[1] = g;
381 ctx_gl->colour[2] = b;
382 ctx_gl->colour[3] = a;
383 old_fogcoord_glColor4f(r, g, b, a);
386 static void WINE_GLAPI wine_glColor4fv(const GLfloat *c) {
387 wine_glColor4f(c[0], c[1], c[2], c[3]);
390 static void WINE_GLAPI wine_glColor3f(GLfloat r, GLfloat g, GLfloat b) {
391 wine_glColor4f(r, g, b, 1.0f);
394 static void WINE_GLAPI wine_glColor3fv(const GLfloat *c) {
395 wine_glColor4f(c[0], c[1], c[2], 1.0f);
398 static void WINE_GLAPI wine_glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
399 wine_glColor4f(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
402 /* In D3D the fog coord is a UBYTE, so there's no problem with using the
403 * single precision function. */
404 static void WINE_GLAPI wine_glFogCoordfEXT(GLfloat f)
406 struct wined3d_context_gl *ctx = wined3d_context_gl_get_current();
408 ctx->fog_coord_value = f;
410 static void WINE_GLAPI wine_glFogCoorddEXT(GLdouble f) {
411 wine_glFogCoordfEXT((GLfloat) f);
413 static void WINE_GLAPI wine_glFogCoordfvEXT(const GLfloat *f) {
414 wine_glFogCoordfEXT(*f);
416 static void WINE_GLAPI wine_glFogCoorddvEXT(const GLdouble *f) {
417 wine_glFogCoordfEXT((GLfloat) *f);
420 /* End GL_EXT_fog_coord emulation */
422 void install_gl_compat_wrapper(struct wined3d_gl_info *gl_info, enum wined3d_gl_extension ext)
424 switch (ext)
426 case ARB_MULTITEXTURE:
427 if (gl_info->supported[ARB_MULTITEXTURE])
428 return;
429 if (gl_info->gl_ops.ext.p_glActiveTexture == wine_glActiveTexture)
431 FIXME("ARB_multitexture emulation hooks already applied.\n");
432 return;
434 TRACE("Applying GL_ARB_multitexture emulation hooks.\n");
435 gl_info->gl_ops.ext.p_glActiveTexture = wine_glActiveTexture;
436 gl_info->gl_ops.ext.p_glClientActiveTextureARB = wine_glClientActiveTextureARB;
437 gl_info->gl_ops.ext.p_glMultiTexCoord1fARB = wine_glMultiTexCoord1fARB;
438 gl_info->gl_ops.ext.p_glMultiTexCoord1fvARB = wine_glMultiTexCoord1fvARB;
439 gl_info->gl_ops.ext.p_glMultiTexCoord2fARB = wine_glMultiTexCoord2fARB;
440 gl_info->gl_ops.ext.p_glMultiTexCoord2fvARB = wine_glMultiTexCoord2fvARB;
441 gl_info->gl_ops.ext.p_glMultiTexCoord3fARB = wine_glMultiTexCoord3fARB;
442 gl_info->gl_ops.ext.p_glMultiTexCoord3fvARB = wine_glMultiTexCoord3fvARB;
443 gl_info->gl_ops.ext.p_glMultiTexCoord4fARB = wine_glMultiTexCoord4fARB;
444 gl_info->gl_ops.ext.p_glMultiTexCoord4fvARB = wine_glMultiTexCoord4fvARB;
445 gl_info->gl_ops.ext.p_glMultiTexCoord2svARB = wine_glMultiTexCoord2svARB;
446 gl_info->gl_ops.ext.p_glMultiTexCoord4svARB = wine_glMultiTexCoord4svARB;
447 old_multitex_glGetIntegerv = gl_info->gl_ops.gl.p_glGetIntegerv;
448 gl_info->gl_ops.gl.p_glGetIntegerv = wine_glGetIntegerv;
449 old_multitex_glGetFloatv = gl_info->gl_ops.gl.p_glGetFloatv;
450 gl_info->gl_ops.gl.p_glGetFloatv = wine_glGetFloatv;
451 old_multitex_glGetDoublev = gl_info->gl_ops.gl.p_glGetDoublev;
452 gl_info->gl_ops.gl.p_glGetDoublev = wine_glGetDoublev;
453 gl_info->supported[ARB_MULTITEXTURE] = TRUE;
454 return;
456 case EXT_FOG_COORD:
457 /* This emulation isn't perfect. There are a number of potential problems, but they should
458 * not matter in practise:
460 * Fog vs fragment shader: If we are using GL_ARB_fragment_program with the fog option, the
461 * glDisable(GL_FOG) here won't matter. However, if we have GL_ARB_fragment_program, it is pretty
462 * unlikely that we don't have GL_EXT_fog_coord. Besides, we probably have GL_ARB_vertex_program
463 * too, which would allow fog coord emulation in a fixed function vertex pipeline replacement.
465 * Fog vs texture: We apply the fog in the vertex color. An app could set up texturing settings which
466 * ignore the vertex color, thus effectively disabling our fog. However, in D3D this type of fog is
467 * a per-vertex fog too, so the apps shouldn't do that.
469 * Fog vs lighting: The app could in theory use D3DFOG_NONE table and D3DFOG_NONE vertex fog with
470 * untransformed vertices. That enables lighting and fog coords at the same time, and the lighting
471 * calculations could affect the already blended in fog color. There's nothing we can do against that,
472 * but most apps using fog color do their own lighting too and often even use RHW vertices. So live
473 * with it.
475 if (gl_info->supported[EXT_FOG_COORD])
476 return;
477 if (gl_info->gl_ops.gl.p_glFogi == wine_glFogi)
479 FIXME("EXT_fog_coord emulation hooks already applied.\n");
480 return;
482 TRACE("Applying GL_ARB_fog_coord emulation hooks\n");
484 /* This probably means that the implementation doesn't advertise the extension, but implicitly supports
485 * it via the GL core version, or someone messed around in the extension table in directx.c. Add version-
486 * dependent loading for this extension if we ever hit this situation
488 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
490 FIXME("GL implementation supports GL_ARB_fragment_program but not GL_EXT_fog_coord\n");
491 FIXME("The fog coord emulation will most likely fail\n");
493 else if (gl_info->supported[ARB_FRAGMENT_SHADER])
495 FIXME("GL implementation supports GL_ARB_fragment_shader but not GL_EXT_fog_coord\n");
496 FIXME("The fog coord emulation will most likely fail\n");
499 old_fogcoord_glFogi = gl_info->gl_ops.gl.p_glFogi;
500 gl_info->gl_ops.gl.p_glFogi = wine_glFogi;
501 old_fogcoord_glFogiv = gl_info->gl_ops.gl.p_glFogiv;
502 gl_info->gl_ops.gl.p_glFogiv = wine_glFogiv;
503 old_fogcoord_glFogf = gl_info->gl_ops.gl.p_glFogf;
504 gl_info->gl_ops.gl.p_glFogf = wine_glFogf;
505 old_fogcoord_glFogfv = gl_info->gl_ops.gl.p_glFogfv;
506 gl_info->gl_ops.gl.p_glFogfv = wine_glFogfv;
507 old_fogcoord_glEnable = gl_info->p_glEnableWINE;
508 gl_info->p_glEnableWINE = wine_glEnable;
509 old_fogcoord_glDisable = gl_info->p_glDisableWINE;
510 gl_info->p_glDisableWINE = wine_glDisable;
512 old_fogcoord_glVertex4f = gl_info->gl_ops.gl.p_glVertex4f;
513 gl_info->gl_ops.gl.p_glVertex4f = wine_glVertex4f;
514 gl_info->gl_ops.gl.p_glVertex4fv = wine_glVertex4fv;
515 gl_info->gl_ops.gl.p_glVertex3f = wine_glVertex3f;
516 gl_info->gl_ops.gl.p_glVertex3fv = wine_glVertex3fv;
518 old_fogcoord_glColor4f = gl_info->gl_ops.gl.p_glColor4f;
519 gl_info->gl_ops.gl.p_glColor4f = wine_glColor4f;
520 gl_info->gl_ops.gl.p_glColor4fv = wine_glColor4fv;
521 gl_info->gl_ops.gl.p_glColor3f = wine_glColor3f;
522 gl_info->gl_ops.gl.p_glColor3fv = wine_glColor3fv;
523 gl_info->gl_ops.gl.p_glColor4ub = wine_glColor4ub;
525 gl_info->gl_ops.ext.p_glFogCoordfEXT = wine_glFogCoordfEXT;
526 gl_info->gl_ops.ext.p_glFogCoordfvEXT = wine_glFogCoordfvEXT;
527 gl_info->gl_ops.ext.p_glFogCoorddEXT = wine_glFogCoorddEXT;
528 gl_info->gl_ops.ext.p_glFogCoorddvEXT = wine_glFogCoorddvEXT;
529 gl_info->supported[EXT_FOG_COORD] = TRUE;
530 return;
532 default:
533 FIXME("Extension %u emulation not supported.\n", ext);