Fixed some flickering that was occurring in the image list control
[wine/wine-kai.git] / dlls / ddraw / mesa.c
blob5aab71a124598d1460fa96045fbc533aeb32328d
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;
38 if (tex == NULL) {
39 glBindTexture(GL_TEXTURE_2D, 0);
40 glDisable(GL_TEXTURE_2D);
41 TRACE("disabling texturing\n");
42 } else {
43 D3DTPRIVATE(tex);
45 glEnable(GL_TEXTURE_2D);
46 /* Default parameters */
47 glBindTexture(GL_TEXTURE_2D, dtpriv->tex_name);
48 /* To prevent state change, we could test here what are the parameters
49 stored in the texture */
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
52 TRACE("setting OpenGL texture handle : %d\n", dtpriv->tex_name);
54 } break;
56 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
57 if (dwRenderState)
58 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
59 else
60 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
61 break;
63 case D3DRENDERSTATE_ZENABLE: /* 7 */
64 if (dwRenderState)
65 glEnable(GL_DEPTH_TEST);
66 else
67 glDisable(GL_DEPTH_TEST);
68 break;
70 case D3DRENDERSTATE_FILLMODE: /* 8 */
71 switch ((D3DFILLMODE) dwRenderState) {
72 case D3DFILL_SOLID:
73 break;
75 default:
76 ERR("Unhandled fill mode !\n");
78 break;
80 case D3DRENDERSTATE_SHADEMODE: /* 9 */
81 switch ((D3DSHADEMODE) dwRenderState) {
82 case D3DSHADE_FLAT:
83 glShadeModel(GL_FLAT);
84 break;
86 case D3DSHADE_GOURAUD:
87 glShadeModel(GL_SMOOTH);
88 break;
90 default:
91 ERR("Unhandled shade mode !\n");
93 break;
95 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
96 if (dwRenderState)
97 glDepthMask(GL_TRUE);
98 else
99 glDepthMask(GL_FALSE);
100 break;
102 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
103 switch ((D3DTEXTUREFILTER) dwRenderState) {
104 case D3DFILTER_NEAREST:
105 rs->mag = GL_NEAREST;
106 break;
108 case D3DFILTER_LINEAR:
109 rs->mag = GL_LINEAR;
110 break;
112 default:
113 ERR("Unhandled texture mag !\n");
115 break;
117 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
118 switch ((D3DTEXTUREFILTER) dwRenderState) {
119 case D3DFILTER_NEAREST:
120 rs->min = GL_NEAREST;
121 break;
123 case D3DFILTER_LINEAR:
124 rs->mag = GL_LINEAR;
125 break;
127 default:
128 ERR("Unhandled texture min !\n");
130 break;
132 case D3DRENDERSTATE_SRCBLEND: /* 19 */
133 switch ((D3DBLEND) dwRenderState) {
134 case D3DBLEND_SRCALPHA:
135 rs->src = GL_SRC_ALPHA;
136 break;
138 default:
139 ERR("Unhandled blend mode !\n");
142 glBlendFunc(rs->src, rs->dst);
143 break;
145 case D3DRENDERSTATE_DESTBLEND: /* 20 */
146 switch ((D3DBLEND) dwRenderState) {
147 case D3DBLEND_INVSRCALPHA:
148 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
149 break;
151 default:
152 ERR("Unhandled blend mode !\n");
155 glBlendFunc(rs->src, rs->dst);
156 break;
158 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
159 switch ((D3DTEXTUREBLEND) dwRenderState) {
160 case D3DTBLEND_MODULATE:
161 case D3DTBLEND_MODULATEALPHA:
162 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
163 break;
165 default:
166 ERR("Unhandled texture environment !\n");
168 break;
170 case D3DRENDERSTATE_CULLMODE: /* 22 */
171 switch ((D3DCULL) dwRenderState) {
172 case D3DCULL_NONE:
173 glDisable(GL_CULL_FACE);
174 break;
176 case D3DCULL_CW:
177 glEnable(GL_CULL_FACE);
178 glFrontFace(GL_CW);
179 break;
181 case D3DCULL_CCW:
182 glEnable(GL_CULL_FACE);
183 glFrontFace(GL_CCW);
184 break;
186 default:
187 ERR("Unhandled cull mode !\n");
189 break;
191 case D3DRENDERSTATE_ZFUNC: /* 23 */
192 switch ((D3DCMPFUNC) dwRenderState) {
193 case D3DCMP_NEVER:
194 glDepthFunc(GL_NEVER);
195 break;
196 case D3DCMP_LESS:
197 glDepthFunc(GL_LESS);
198 break;
199 case D3DCMP_EQUAL:
200 glDepthFunc(GL_EQUAL);
201 break;
202 case D3DCMP_LESSEQUAL:
203 glDepthFunc(GL_LEQUAL);
204 break;
205 case D3DCMP_GREATER:
206 glDepthFunc(GL_GREATER);
207 break;
208 case D3DCMP_NOTEQUAL:
209 glDepthFunc(GL_NOTEQUAL);
210 break;
211 case D3DCMP_GREATEREQUAL:
212 glDepthFunc(GL_GEQUAL);
213 break;
214 case D3DCMP_ALWAYS:
215 glDepthFunc(GL_ALWAYS);
216 break;
218 default:
219 ERR("Unexpected value\n");
221 break;
223 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
224 if (dwRenderState)
225 glEnable(GL_DITHER);
226 else
227 glDisable(GL_DITHER);
228 break;
230 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
231 if (dwRenderState)
232 glEnable(GL_BLEND);
233 else
234 glDisable(GL_BLEND);
235 break;
237 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
238 if (dwRenderState)
239 glEnable(GL_BLEND);
240 else
241 glDisable(GL_BLEND);
242 break;
244 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
245 break;
247 default:
248 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType);
249 break;
252 LEAVE_GL();