1 /* Direct3D Common functions
4 This file contains all common miscellaneous code that spans
10 #include "wine/obj_base.h"
15 #include "d3d_private.h"
19 static void _dump_renderstate(D3DRENDERSTATETYPE type,
23 "D3DRENDERSTATE_TEXTUREHANDLE",
24 "D3DRENDERSTATE_ANTIALIAS",
25 "D3DRENDERSTATE_TEXTUREADDRESS",
26 "D3DRENDERSTATE_TEXTUREPERSPECTIVE",
27 "D3DRENDERSTATE_WRAPU",
28 "D3DRENDERSTATE_WRAPV",
29 "D3DRENDERSTATE_ZENABLE",
30 "D3DRENDERSTATE_FILLMODE",
31 "D3DRENDERSTATE_SHADEMODE",
32 "D3DRENDERSTATE_LINEPATTERN",
33 "D3DRENDERSTATE_MONOENABLE",
34 "D3DRENDERSTATE_ROP2",
35 "D3DRENDERSTATE_PLANEMASK",
36 "D3DRENDERSTATE_ZWRITEENABLE",
37 "D3DRENDERSTATE_ALPHATESTENABLE",
38 "D3DRENDERSTATE_LASTPIXEL",
39 "D3DRENDERSTATE_TEXTUREMAG",
40 "D3DRENDERSTATE_TEXTUREMIN",
41 "D3DRENDERSTATE_SRCBLEND",
42 "D3DRENDERSTATE_DESTBLEND",
43 "D3DRENDERSTATE_TEXTUREMAPBLEND",
44 "D3DRENDERSTATE_CULLMODE",
45 "D3DRENDERSTATE_ZFUNC",
46 "D3DRENDERSTATE_ALPHAREF",
47 "D3DRENDERSTATE_ALPHAFUNC",
48 "D3DRENDERSTATE_DITHERENABLE",
49 "D3DRENDERSTATE_ALPHABLENDENABLE",
50 "D3DRENDERSTATE_FOGENABLE",
51 "D3DRENDERSTATE_SPECULARENABLE",
52 "D3DRENDERSTATE_ZVISIBLE",
53 "D3DRENDERSTATE_SUBPIXEL",
54 "D3DRENDERSTATE_SUBPIXELX",
55 "D3DRENDERSTATE_STIPPLEDALPHA",
56 "D3DRENDERSTATE_FOGCOLOR",
57 "D3DRENDERSTATE_FOGTABLEMODE",
58 "D3DRENDERSTATE_FOGTABLESTART",
59 "D3DRENDERSTATE_FOGTABLEEND",
60 "D3DRENDERSTATE_FOGTABLEDENSITY",
61 "D3DRENDERSTATE_STIPPLEENABLE",
62 "D3DRENDERSTATE_EDGEANTIALIAS",
63 "D3DRENDERSTATE_COLORKEYENABLE",
65 "D3DRENDERSTATE_BORDERCOLOR",
66 "D3DRENDERSTATE_TEXTUREADDRESSU",
67 "D3DRENDERSTATE_TEXTUREADDRESSV",
68 "D3DRENDERSTATE_MIPMAPLODBIAS",
69 "D3DRENDERSTATE_ZBIAS",
70 "D3DRENDERSTATE_RANGEFOGENABLE",
71 "D3DRENDERSTATE_ANISOTROPY",
72 "D3DRENDERSTATE_FLUSHBATCH",
73 "ERR", "ERR", "ERR", "ERR", "ERR", "ERR", "ERR",
74 "ERR", "ERR", "ERR", "ERR", "ERR", "ERR",
75 "D3DRENDERSTATE_STIPPLEPATTERN00",
76 "D3DRENDERSTATE_STIPPLEPATTERN01",
77 "D3DRENDERSTATE_STIPPLEPATTERN02",
78 "D3DRENDERSTATE_STIPPLEPATTERN03",
79 "D3DRENDERSTATE_STIPPLEPATTERN04",
80 "D3DRENDERSTATE_STIPPLEPATTERN05",
81 "D3DRENDERSTATE_STIPPLEPATTERN06",
82 "D3DRENDERSTATE_STIPPLEPATTERN07",
83 "D3DRENDERSTATE_STIPPLEPATTERN08",
84 "D3DRENDERSTATE_STIPPLEPATTERN09",
85 "D3DRENDERSTATE_STIPPLEPATTERN10",
86 "D3DRENDERSTATE_STIPPLEPATTERN11",
87 "D3DRENDERSTATE_STIPPLEPATTERN12",
88 "D3DRENDERSTATE_STIPPLEPATTERN13",
89 "D3DRENDERSTATE_STIPPLEPATTERN14",
90 "D3DRENDERSTATE_STIPPLEPATTERN15",
91 "D3DRENDERSTATE_STIPPLEPATTERN16",
92 "D3DRENDERSTATE_STIPPLEPATTERN17",
93 "D3DRENDERSTATE_STIPPLEPATTERN18",
94 "D3DRENDERSTATE_STIPPLEPATTERN19",
95 "D3DRENDERSTATE_STIPPLEPATTERN20",
96 "D3DRENDERSTATE_STIPPLEPATTERN21",
97 "D3DRENDERSTATE_STIPPLEPATTERN22",
98 "D3DRENDERSTATE_STIPPLEPATTERN23",
99 "D3DRENDERSTATE_STIPPLEPATTERN24",
100 "D3DRENDERSTATE_STIPPLEPATTERN25",
101 "D3DRENDERSTATE_STIPPLEPATTERN26",
102 "D3DRENDERSTATE_STIPPLEPATTERN27",
103 "D3DRENDERSTATE_STIPPLEPATTERN28",
104 "D3DRENDERSTATE_STIPPLEPATTERN29",
105 "D3DRENDERSTATE_STIPPLEPATTERN30",
106 "D3DRENDERSTATE_STIPPLEPATTERN31"
109 DUMP(" %s = 0x%08lx\n", states[type], value);
113 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
114 DWORD dwRenderState, RenderState *rs)
118 _dump_renderstate(dwRenderStateType, dwRenderState);
120 /* First, all the stipple patterns */
121 if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
122 (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
123 ERR(ddraw, "Unhandled stipple !\n");
125 /* All others state variables */
126 switch (dwRenderStateType) {
128 case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
129 LPDIRECT3DTEXTURE2 tex = (LPDIRECT3DTEXTURE2) dwRenderState;
132 glBindTexture(GL_TEXTURE_2D, 0);
133 glDisable(GL_TEXTURE_2D);
135 TRACE(ddraw, "setting OpenGL texture handle : %d\n", tex->tex_name);
136 glEnable(GL_TEXTURE_2D);
137 /* Default parameters */
138 glBindTexture(GL_TEXTURE_2D, tex->tex_name);
139 /* To prevent state change, we could test here what are the parameters
140 stored in the texture */
141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
146 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
148 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
150 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
153 case D3DRENDERSTATE_ZENABLE: /* 7 */
155 glEnable(GL_DEPTH_TEST);
157 glDisable(GL_DEPTH_TEST);
160 case D3DRENDERSTATE_FILLMODE: /* 8 */
161 switch ((D3DFILLMODE) dwRenderState) {
166 ERR(ddraw, "Unhandled fill mode !\n");
170 case D3DRENDERSTATE_SHADEMODE: /* 9 */
171 switch ((D3DSHADEMODE) dwRenderState) {
173 glShadeModel(GL_FLAT);
176 case D3DSHADE_GOURAUD:
177 glShadeModel(GL_SMOOTH);
181 ERR(ddraw, "Unhandled shade mode !\n");
185 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
187 glDepthMask(GL_TRUE);
189 glDepthMask(GL_FALSE);
192 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
193 switch ((D3DTEXTUREFILTER) dwRenderState) {
194 case D3DFILTER_NEAREST:
195 rs->mag = GL_NEAREST;
198 case D3DFILTER_LINEAR:
203 ERR(ddraw, "Unhandled texture mag !\n");
207 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
208 switch ((D3DTEXTUREFILTER) dwRenderState) {
209 case D3DFILTER_NEAREST:
210 rs->min = GL_NEAREST;
213 case D3DFILTER_LINEAR:
218 ERR(ddraw, "Unhandled texture min !\n");
222 case D3DRENDERSTATE_SRCBLEND: /* 19 */
223 switch ((D3DBLEND) dwRenderState) {
224 case D3DBLEND_SRCALPHA:
225 rs->src = GL_SRC_ALPHA;
229 ERR(ddraw, "Unhandled blend mode !\n");
232 glBlendFunc(rs->src, rs->dst);
235 case D3DRENDERSTATE_DESTBLEND: /* 20 */
236 switch ((D3DBLEND) dwRenderState) {
237 case D3DBLEND_INVSRCALPHA:
238 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
242 ERR(ddraw, "Unhandled blend mode !\n");
245 glBlendFunc(rs->src, rs->dst);
248 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
249 switch ((D3DTEXTUREBLEND) dwRenderState) {
250 case D3DTBLEND_MODULATE:
251 case D3DTBLEND_MODULATEALPHA:
252 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
256 ERR(ddraw, "Unhandled texture environment !\n");
260 case D3DRENDERSTATE_CULLMODE: /* 22 */
261 switch ((D3DCULL) dwRenderState) {
263 glDisable(GL_CULL_FACE);
267 glEnable(GL_CULL_FACE);
272 glEnable(GL_CULL_FACE);
277 ERR(ddraw, "Unhandled cull mode !\n");
281 case D3DRENDERSTATE_ZFUNC: /* 23 */
282 switch ((D3DCMPFUNC) dwRenderState) {
284 glDepthFunc(GL_NEVER);
287 glDepthFunc(GL_LESS);
290 glDepthFunc(GL_EQUAL);
292 case D3DCMP_LESSEQUAL:
293 glDepthFunc(GL_LEQUAL);
296 glDepthFunc(GL_GREATER);
298 case D3DCMP_NOTEQUAL:
299 glDepthFunc(GL_NOTEQUAL);
301 case D3DCMP_GREATEREQUAL:
302 glDepthFunc(GL_GEQUAL);
305 glDepthFunc(GL_ALWAYS);
309 ERR(ddraw, "Unexpected value\n");
313 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
317 glDisable(GL_DITHER);
320 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
327 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
334 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
338 ERR(ddraw, "Unhandled Render State\n");
345 #endif /* HAVE_MESAGL */