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