- add prototypes for serial API functions
[wine/wine-kai.git] / dlls / ddraw / mesa.c
blobaa8b78299b0f6c9536f7e4a4803ca5c5c31736e5
1 /* Direct3D Common functions
2 (c) 1998 Lionel ULMER
4 This file contains all MESA common code */
6 #include "windef.h"
7 #include "wine/obj_base.h"
8 #include "ddraw.h"
9 #include "d3d.h"
10 #include "debugtools.h"
12 #include "mesa_private.h"
14 DEFAULT_DEBUG_CHANNEL(ddraw)
16 #define D3DTPRIVATE(x) mesa_d3dt_private *dtpriv = (mesa_d3dt_private*)(x)->private
18 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
19 DWORD dwRenderState, RenderState *rs)
22 if (TRACE_ON(ddraw))
23 _dump_renderstate(dwRenderStateType, dwRenderState);
25 /* First, all the stipple patterns */
26 if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
27 (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
28 ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType);
29 } else {
30 ENTER_GL();
32 /* All others state variables */
33 switch (dwRenderStateType) {
35 case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
36 IDirect3DTexture2Impl* tex = (IDirect3DTexture2Impl*) dwRenderState;
37 D3DTPRIVATE(tex);
39 if (tex == NULL) {
40 glBindTexture(GL_TEXTURE_2D, 0);
41 glDisable(GL_TEXTURE_2D);
42 } else {
43 TRACE("setting OpenGL texture handle : %d\n", dtpriv->tex_name);
44 glEnable(GL_TEXTURE_2D);
45 /* Default parameters */
46 glBindTexture(GL_TEXTURE_2D, dtpriv->tex_name);
47 /* To prevent state change, we could test here what are the parameters
48 stored in the texture */
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
52 } break;
54 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
55 if (dwRenderState)
56 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
57 else
58 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
59 break;
61 case D3DRENDERSTATE_ZENABLE: /* 7 */
62 if (dwRenderState)
63 glEnable(GL_DEPTH_TEST);
64 else
65 glDisable(GL_DEPTH_TEST);
66 break;
68 case D3DRENDERSTATE_FILLMODE: /* 8 */
69 switch ((D3DFILLMODE) dwRenderState) {
70 case D3DFILL_SOLID:
71 break;
73 default:
74 ERR("Unhandled fill mode !\n");
76 break;
78 case D3DRENDERSTATE_SHADEMODE: /* 9 */
79 switch ((D3DSHADEMODE) dwRenderState) {
80 case D3DSHADE_FLAT:
81 glShadeModel(GL_FLAT);
82 break;
84 case D3DSHADE_GOURAUD:
85 glShadeModel(GL_SMOOTH);
86 break;
88 default:
89 ERR("Unhandled shade mode !\n");
91 break;
93 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
94 if (dwRenderState)
95 glDepthMask(GL_TRUE);
96 else
97 glDepthMask(GL_FALSE);
98 break;
100 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
101 switch ((D3DTEXTUREFILTER) dwRenderState) {
102 case D3DFILTER_NEAREST:
103 rs->mag = GL_NEAREST;
104 break;
106 case D3DFILTER_LINEAR:
107 rs->mag = GL_LINEAR;
108 break;
110 default:
111 ERR("Unhandled texture mag !\n");
113 break;
115 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
116 switch ((D3DTEXTUREFILTER) dwRenderState) {
117 case D3DFILTER_NEAREST:
118 rs->min = GL_NEAREST;
119 break;
121 case D3DFILTER_LINEAR:
122 rs->mag = GL_LINEAR;
123 break;
125 default:
126 ERR("Unhandled texture min !\n");
128 break;
130 case D3DRENDERSTATE_SRCBLEND: /* 19 */
131 switch ((D3DBLEND) dwRenderState) {
132 case D3DBLEND_SRCALPHA:
133 rs->src = GL_SRC_ALPHA;
134 break;
136 default:
137 ERR("Unhandled blend mode !\n");
140 glBlendFunc(rs->src, rs->dst);
141 break;
143 case D3DRENDERSTATE_DESTBLEND: /* 20 */
144 switch ((D3DBLEND) dwRenderState) {
145 case D3DBLEND_INVSRCALPHA:
146 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
147 break;
149 default:
150 ERR("Unhandled blend mode !\n");
153 glBlendFunc(rs->src, rs->dst);
154 break;
156 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
157 switch ((D3DTEXTUREBLEND) dwRenderState) {
158 case D3DTBLEND_MODULATE:
159 case D3DTBLEND_MODULATEALPHA:
160 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
161 break;
163 default:
164 ERR("Unhandled texture environment !\n");
166 break;
168 case D3DRENDERSTATE_CULLMODE: /* 22 */
169 switch ((D3DCULL) dwRenderState) {
170 case D3DCULL_NONE:
171 glDisable(GL_CULL_FACE);
172 break;
174 case D3DCULL_CW:
175 glEnable(GL_CULL_FACE);
176 glFrontFace(GL_CW);
177 break;
179 case D3DCULL_CCW:
180 glEnable(GL_CULL_FACE);
181 glFrontFace(GL_CCW);
182 break;
184 default:
185 ERR("Unhandled cull mode !\n");
187 break;
189 case D3DRENDERSTATE_ZFUNC: /* 23 */
190 switch ((D3DCMPFUNC) dwRenderState) {
191 case D3DCMP_NEVER:
192 glDepthFunc(GL_NEVER);
193 break;
194 case D3DCMP_LESS:
195 glDepthFunc(GL_LESS);
196 break;
197 case D3DCMP_EQUAL:
198 glDepthFunc(GL_EQUAL);
199 break;
200 case D3DCMP_LESSEQUAL:
201 glDepthFunc(GL_LEQUAL);
202 break;
203 case D3DCMP_GREATER:
204 glDepthFunc(GL_GREATER);
205 break;
206 case D3DCMP_NOTEQUAL:
207 glDepthFunc(GL_NOTEQUAL);
208 break;
209 case D3DCMP_GREATEREQUAL:
210 glDepthFunc(GL_GEQUAL);
211 break;
212 case D3DCMP_ALWAYS:
213 glDepthFunc(GL_ALWAYS);
214 break;
216 default:
217 ERR("Unexpected value\n");
219 break;
221 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
222 if (dwRenderState)
223 glEnable(GL_DITHER);
224 else
225 glDisable(GL_DITHER);
226 break;
228 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
229 if (dwRenderState)
230 glEnable(GL_BLEND);
231 else
232 glDisable(GL_BLEND);
233 break;
235 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
236 if (dwRenderState)
237 glEnable(GL_BLEND);
238 else
239 glDisable(GL_BLEND);
240 break;
242 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
243 break;
245 default:
246 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType);
247 break;
250 LEAVE_GL();