Added the DFCS_{HOT,TRANSPARENT} definitions.
[wine/gsoc_dplay.git] / dlls / ddraw / mesa.c
blob62bf56008074e4f3a6c7ee7abd3a43a796e92bc8
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 "wine/obj_base.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 #define D3DTPRIVATE(x) mesa_d3dt_private *dtpriv = (mesa_d3dt_private*)(x)->private
35 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
36 DWORD dwRenderState, RenderState *rs)
39 if (TRACE_ON(ddraw))
40 _dump_renderstate(dwRenderStateType, dwRenderState);
42 /* First, all the stipple patterns */
43 if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
44 (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
45 ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType);
46 } else {
47 ENTER_GL();
49 /* All others state variables */
50 switch (dwRenderStateType) {
52 case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
53 IDirect3DTexture2Impl* tex = (IDirect3DTexture2Impl*) dwRenderState;
55 if (tex == NULL) {
56 glBindTexture(GL_TEXTURE_2D, 0);
57 glDisable(GL_TEXTURE_2D);
58 TRACE("disabling texturing\n");
59 } else {
60 D3DTPRIVATE(tex);
62 glEnable(GL_TEXTURE_2D);
63 /* Default parameters */
64 glBindTexture(GL_TEXTURE_2D, dtpriv->tex_name);
65 /* To prevent state change, we could test here what are the parameters
66 stored in the texture */
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
69 TRACE("setting OpenGL texture handle : %d\n", dtpriv->tex_name);
71 } break;
73 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
74 if (dwRenderState)
75 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
76 else
77 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
78 break;
80 case D3DRENDERSTATE_ZENABLE: /* 7 */
81 if (dwRenderState)
82 glEnable(GL_DEPTH_TEST);
83 else
84 glDisable(GL_DEPTH_TEST);
85 break;
87 case D3DRENDERSTATE_FILLMODE: /* 8 */
88 switch ((D3DFILLMODE) dwRenderState) {
89 case D3DFILL_SOLID:
90 break;
92 default:
93 ERR("Unhandled fill mode !\n");
95 break;
97 case D3DRENDERSTATE_SHADEMODE: /* 9 */
98 switch ((D3DSHADEMODE) dwRenderState) {
99 case D3DSHADE_FLAT:
100 glShadeModel(GL_FLAT);
101 break;
103 case D3DSHADE_GOURAUD:
104 glShadeModel(GL_SMOOTH);
105 break;
107 default:
108 ERR("Unhandled shade mode !\n");
110 break;
112 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
113 if (dwRenderState)
114 glDepthMask(GL_TRUE);
115 else
116 glDepthMask(GL_FALSE);
117 break;
119 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
120 switch ((D3DTEXTUREFILTER) dwRenderState) {
121 case D3DFILTER_NEAREST:
122 rs->mag = GL_NEAREST;
123 break;
125 case D3DFILTER_LINEAR:
126 rs->mag = GL_LINEAR;
127 break;
129 default:
130 ERR("Unhandled texture mag !\n");
132 break;
134 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
135 switch ((D3DTEXTUREFILTER) dwRenderState) {
136 case D3DFILTER_NEAREST:
137 rs->min = GL_NEAREST;
138 break;
140 case D3DFILTER_LINEAR:
141 rs->mag = GL_LINEAR;
142 break;
144 default:
145 ERR("Unhandled texture min !\n");
147 break;
149 case D3DRENDERSTATE_SRCBLEND: /* 19 */
150 switch ((D3DBLEND) dwRenderState) {
151 case D3DBLEND_SRCALPHA:
152 rs->src = GL_SRC_ALPHA;
153 break;
155 default:
156 ERR("Unhandled blend mode !\n");
159 glBlendFunc(rs->src, rs->dst);
160 break;
162 case D3DRENDERSTATE_DESTBLEND: /* 20 */
163 switch ((D3DBLEND) dwRenderState) {
164 case D3DBLEND_INVSRCALPHA:
165 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
166 break;
168 default:
169 ERR("Unhandled blend mode !\n");
172 glBlendFunc(rs->src, rs->dst);
173 break;
175 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
176 switch ((D3DTEXTUREBLEND) dwRenderState) {
177 case D3DTBLEND_MODULATE:
178 case D3DTBLEND_MODULATEALPHA:
179 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
180 break;
182 default:
183 ERR("Unhandled texture environment !\n");
185 break;
187 case D3DRENDERSTATE_CULLMODE: /* 22 */
188 switch ((D3DCULL) dwRenderState) {
189 case D3DCULL_NONE:
190 glDisable(GL_CULL_FACE);
191 break;
193 case D3DCULL_CW:
194 glEnable(GL_CULL_FACE);
195 glFrontFace(GL_CW);
196 break;
198 case D3DCULL_CCW:
199 glEnable(GL_CULL_FACE);
200 glFrontFace(GL_CCW);
201 break;
203 default:
204 ERR("Unhandled cull mode !\n");
206 break;
208 case D3DRENDERSTATE_ZFUNC: /* 23 */
209 switch ((D3DCMPFUNC) dwRenderState) {
210 case D3DCMP_NEVER:
211 glDepthFunc(GL_NEVER);
212 break;
213 case D3DCMP_LESS:
214 glDepthFunc(GL_LESS);
215 break;
216 case D3DCMP_EQUAL:
217 glDepthFunc(GL_EQUAL);
218 break;
219 case D3DCMP_LESSEQUAL:
220 glDepthFunc(GL_LEQUAL);
221 break;
222 case D3DCMP_GREATER:
223 glDepthFunc(GL_GREATER);
224 break;
225 case D3DCMP_NOTEQUAL:
226 glDepthFunc(GL_NOTEQUAL);
227 break;
228 case D3DCMP_GREATEREQUAL:
229 glDepthFunc(GL_GEQUAL);
230 break;
231 case D3DCMP_ALWAYS:
232 glDepthFunc(GL_ALWAYS);
233 break;
235 default:
236 ERR("Unexpected value\n");
238 break;
240 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
241 if (dwRenderState)
242 glEnable(GL_DITHER);
243 else
244 glDisable(GL_DITHER);
245 break;
247 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
248 if (dwRenderState)
249 glEnable(GL_BLEND);
250 else
251 glDisable(GL_BLEND);
252 break;
254 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
255 if (dwRenderState)
256 glEnable(GL_BLEND);
257 else
258 glDisable(GL_BLEND);
259 break;
261 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
262 break;
264 default:
265 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType);
266 break;
269 LEAVE_GL();