Improve traces + small fix.
[wine/hacks.git] / dlls / ddraw / mesa.c
blobb205c152ef9aef176c152aace20846ed4d3b8b8c
1 /* Direct3D Common functions
2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains all MESA common code
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include "windef.h"
24 #include "objbase.h"
25 #include "ddraw.h"
26 #include "d3d.h"
27 #include "wine/debug.h"
29 #include "mesa_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
33 GLenum convert_D3D_compare_to_GL(D3DCMPFUNC dwRenderState)
35 switch (dwRenderState) {
36 case D3DCMP_NEVER: return GL_NEVER;
37 case D3DCMP_LESS: return GL_LESS;
38 case D3DCMP_EQUAL: return GL_EQUAL;
39 case D3DCMP_LESSEQUAL: return GL_LEQUAL;
40 case D3DCMP_GREATER: return GL_GREATER;
41 case D3DCMP_NOTEQUAL: return GL_NOTEQUAL;
42 case D3DCMP_GREATEREQUAL: return GL_GEQUAL;
43 case D3DCMP_ALWAYS: return GL_ALWAYS;
44 default: ERR("Unexpected compare type %d !\n", dwRenderState);
46 return GL_ALWAYS;
50 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
51 DWORD dwRenderState, RenderState *rs)
53 if (TRACE_ON(ddraw))
54 TRACE("%s = %08lx\n", _get_renderstate(dwRenderStateType), dwRenderState);
56 /* First, all the stipple patterns */
57 if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
58 (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
59 ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType);
60 } else {
61 ENTER_GL();
63 /* All others state variables */
64 switch (dwRenderStateType) {
65 case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
66 IDirectDrawSurfaceImpl *tex = (IDirectDrawSurfaceImpl*) dwRenderState;
68 if (tex == NULL) {
69 glBindTexture(GL_TEXTURE_2D, 0);
70 glDisable(GL_TEXTURE_2D);
71 TRACE("disabling texturing\n");
72 } else {
73 IDirect3DTextureGLImpl *gl_tex = (IDirect3DTextureGLImpl *) tex->tex_private;
75 glEnable(GL_TEXTURE_2D);
76 /* Default parameters */
77 glBindTexture(GL_TEXTURE_2D, gl_tex->tex_name);
78 /* To prevent state change, we could test here what are the parameters
79 stored in the texture */
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
82 TRACE("setting OpenGL texture handle : %d\n", gl_tex->tex_name);
84 } break;
86 case D3DRENDERSTATE_TEXTUREADDRESSU: /* 44 */
87 case D3DRENDERSTATE_TEXTUREADDRESSV: /* 45 */
88 case D3DRENDERSTATE_TEXTUREADDRESS: { /* 3 */
89 GLenum arg = GL_REPEAT; /* Default value */
90 switch ((D3DTEXTUREADDRESS) dwRenderState) {
91 case D3DTADDRESS_WRAP: arg = GL_REPEAT; break;
92 case D3DTADDRESS_CLAMP: arg = GL_CLAMP; break;
93 case D3DTADDRESS_BORDER: arg = GL_CLAMP_TO_EDGE; break;
94 default: ERR("Unhandled TEXTUREADDRESS mode %ld !\n", dwRenderState);
96 if ((dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESSU) ||
97 (dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESS))
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, arg);
99 if ((dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESSV) ||
100 (dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESS))
101 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, arg);
102 } break;
104 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
105 if (dwRenderState)
106 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
107 else
108 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
109 break;
111 case D3DRENDERSTATE_ZENABLE: /* 7 */
112 if (dwRenderState)
113 glEnable(GL_DEPTH_TEST);
114 else
115 glDisable(GL_DEPTH_TEST);
116 break;
118 case D3DRENDERSTATE_FILLMODE: /* 8 */
119 switch ((D3DFILLMODE) dwRenderState) {
120 case D3DFILL_POINT:
121 glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
122 break;
123 case D3DFILL_WIREFRAME:
124 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
125 break;
126 case D3DFILL_SOLID:
127 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
128 break;
129 default:
130 ERR("Unhandled fill mode %ld !\n",dwRenderState);
132 break;
134 case D3DRENDERSTATE_SHADEMODE: /* 9 */
135 switch ((D3DSHADEMODE) dwRenderState) {
136 case D3DSHADE_FLAT:
137 glShadeModel(GL_FLAT);
138 break;
139 case D3DSHADE_GOURAUD:
140 glShadeModel(GL_SMOOTH);
141 break;
142 default:
143 ERR("Unhandled shade mode %ld !\n",dwRenderState);
145 break;
147 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
148 if (dwRenderState)
149 glDepthMask(GL_TRUE);
150 else
151 glDepthMask(GL_FALSE);
152 break;
154 case D3DRENDERSTATE_ALPHATESTENABLE: /* 15 */
155 if (dwRenderState)
156 glEnable(GL_ALPHA_TEST);
157 else
158 glDisable(GL_ALPHA_TEST);
159 break;
161 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
162 switch ((D3DTEXTUREFILTER) dwRenderState) {
163 case D3DFILTER_NEAREST:
164 rs->mag = GL_NEAREST;
165 break;
166 case D3DFILTER_LINEAR:
167 rs->mag = GL_LINEAR;
168 break;
169 default:
170 ERR("Unhandled texture mag %ld !\n",dwRenderState);
172 break;
174 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
175 switch ((D3DTEXTUREFILTER) dwRenderState) {
176 case D3DFILTER_NEAREST:
177 rs->min = GL_NEAREST;
178 break;
179 case D3DFILTER_LINEAR:
180 rs->mag = GL_LINEAR;
181 break;
182 default:
183 ERR("Unhandled texture min %ld !\n",dwRenderState);
185 break;
187 case D3DRENDERSTATE_SRCBLEND: /* 19 */
188 switch ((D3DBLEND) dwRenderState) {
189 case D3DBLEND_ONE:
190 rs->src = GL_ONE;
191 break;
192 case D3DBLEND_SRCALPHA:
193 rs->src = GL_SRC_ALPHA;
194 break;
195 default:
196 ERR("Unhandled blend mode %ld !\n",dwRenderState);
198 glBlendFunc(rs->src, rs->dst);
199 break;
201 case D3DRENDERSTATE_DESTBLEND: /* 20 */
202 switch ((D3DBLEND) dwRenderState) {
203 case D3DBLEND_ONE:
204 rs->dst = GL_ONE;
205 break;
206 case D3DBLEND_INVSRCALPHA:
207 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
208 break;
209 default:
210 ERR("Unhandled blend mode %ld !\n",dwRenderState);
212 glBlendFunc(rs->src, rs->dst);
213 break;
215 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
216 switch ((D3DTEXTUREBLEND) dwRenderState) {
217 case D3DTBLEND_MODULATE:
218 case D3DTBLEND_MODULATEALPHA:
219 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
220 break;
221 default:
222 ERR("Unhandled texture environment %ld !\n",dwRenderState);
224 break;
226 case D3DRENDERSTATE_CULLMODE: /* 22 */
227 switch ((D3DCULL) dwRenderState) {
228 case D3DCULL_NONE:
229 glDisable(GL_CULL_FACE);
230 break;
231 case D3DCULL_CW:
232 glEnable(GL_CULL_FACE);
233 glFrontFace(GL_CW);
234 break;
235 case D3DCULL_CCW:
236 glEnable(GL_CULL_FACE);
237 glFrontFace(GL_CCW);
238 break;
239 default:
240 ERR("Unhandled cull mode %ld !\n",dwRenderState);
242 break;
244 case D3DRENDERSTATE_ZFUNC: /* 23 */
245 glDepthFunc(convert_D3D_compare_to_GL(dwRenderState));
246 break;
248 case D3DRENDERSTATE_ALPHAREF: /* 24 */
249 rs->alpha_ref = dwRenderState / 255.0;
250 glAlphaFunc(rs->alpha_func, rs->alpha_ref);
251 break;
253 case D3DRENDERSTATE_ALPHAFUNC: /* 25 */
254 rs->alpha_func = convert_D3D_compare_to_GL(dwRenderState);
255 glAlphaFunc(rs->alpha_func, rs->alpha_ref);
256 break;
258 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
259 if (dwRenderState)
260 glEnable(GL_DITHER);
261 else
262 glDisable(GL_DITHER);
263 break;
265 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
266 if (dwRenderState)
267 glEnable(GL_BLEND);
268 else
269 glDisable(GL_BLEND);
270 break;
272 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
273 if (dwRenderState)
274 glEnable(GL_BLEND);
275 else
276 glDisable(GL_BLEND);
277 break;
279 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
280 break;
282 default:
283 ERR("Unhandled dwRenderStateType %s !\n", _get_renderstate(dwRenderStateType));
285 LEAVE_GL();