1 /* Direct3D Common functions
4 This file contains all common miscellaneous code that spans
8 #include "wine/obj_base.h"
11 #include "debugtools.h"
13 #include "d3d_private.h"
15 DEFAULT_DEBUG_CHANNEL(ddraw
)
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 DPRINTF(" %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("Unhandled stipple !\n");
127 /* All others state variables */
128 switch (dwRenderStateType
) {
130 case D3DRENDERSTATE_TEXTUREHANDLE
: { /* 1 */
131 IDirect3DTexture2Impl
* tex
= (IDirect3DTexture2Impl
*) dwRenderState
;
134 glBindTexture(GL_TEXTURE_2D
, 0);
135 glDisable(GL_TEXTURE_2D
);
137 TRACE("setting OpenGL texture handle : %d\n", tex
->tex_name
);
138 glEnable(GL_TEXTURE_2D
);
139 /* Default parameters */
140 glBindTexture(GL_TEXTURE_2D
, tex
->tex_name
);
141 /* To prevent state change, we could test here what are the parameters
142 stored in the texture */
143 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, rs
->mag
);
144 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, rs
->min
);
148 case D3DRENDERSTATE_TEXTUREPERSPECTIVE
: /* 4 */
150 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
152 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
155 case D3DRENDERSTATE_ZENABLE
: /* 7 */
157 glEnable(GL_DEPTH_TEST
);
159 glDisable(GL_DEPTH_TEST
);
162 case D3DRENDERSTATE_FILLMODE
: /* 8 */
163 switch ((D3DFILLMODE
) dwRenderState
) {
168 ERR("Unhandled fill mode !\n");
172 case D3DRENDERSTATE_SHADEMODE
: /* 9 */
173 switch ((D3DSHADEMODE
) dwRenderState
) {
175 glShadeModel(GL_FLAT
);
178 case D3DSHADE_GOURAUD
:
179 glShadeModel(GL_SMOOTH
);
183 ERR("Unhandled shade mode !\n");
187 case D3DRENDERSTATE_ZWRITEENABLE
: /* 14 */
189 glDepthMask(GL_TRUE
);
191 glDepthMask(GL_FALSE
);
194 case D3DRENDERSTATE_TEXTUREMAG
: /* 17 */
195 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
196 case D3DFILTER_NEAREST
:
197 rs
->mag
= GL_NEAREST
;
200 case D3DFILTER_LINEAR
:
205 ERR("Unhandled texture mag !\n");
209 case D3DRENDERSTATE_TEXTUREMIN
: /* 18 */
210 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
211 case D3DFILTER_NEAREST
:
212 rs
->min
= GL_NEAREST
;
215 case D3DFILTER_LINEAR
:
220 ERR("Unhandled texture min !\n");
224 case D3DRENDERSTATE_SRCBLEND
: /* 19 */
225 switch ((D3DBLEND
) dwRenderState
) {
226 case D3DBLEND_SRCALPHA
:
227 rs
->src
= GL_SRC_ALPHA
;
231 ERR("Unhandled blend mode !\n");
234 glBlendFunc(rs
->src
, rs
->dst
);
237 case D3DRENDERSTATE_DESTBLEND
: /* 20 */
238 switch ((D3DBLEND
) dwRenderState
) {
239 case D3DBLEND_INVSRCALPHA
:
240 rs
->dst
= GL_ONE_MINUS_SRC_ALPHA
;
244 ERR("Unhandled blend mode !\n");
247 glBlendFunc(rs
->src
, rs
->dst
);
250 case D3DRENDERSTATE_TEXTUREMAPBLEND
: /* 21 */
251 switch ((D3DTEXTUREBLEND
) dwRenderState
) {
252 case D3DTBLEND_MODULATE
:
253 case D3DTBLEND_MODULATEALPHA
:
254 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
258 ERR("Unhandled texture environment !\n");
262 case D3DRENDERSTATE_CULLMODE
: /* 22 */
263 switch ((D3DCULL
) dwRenderState
) {
265 glDisable(GL_CULL_FACE
);
269 glEnable(GL_CULL_FACE
);
274 glEnable(GL_CULL_FACE
);
279 ERR("Unhandled cull mode !\n");
283 case D3DRENDERSTATE_ZFUNC
: /* 23 */
284 switch ((D3DCMPFUNC
) dwRenderState
) {
286 glDepthFunc(GL_NEVER
);
289 glDepthFunc(GL_LESS
);
292 glDepthFunc(GL_EQUAL
);
294 case D3DCMP_LESSEQUAL
:
295 glDepthFunc(GL_LEQUAL
);
298 glDepthFunc(GL_GREATER
);
300 case D3DCMP_NOTEQUAL
:
301 glDepthFunc(GL_NOTEQUAL
);
303 case D3DCMP_GREATEREQUAL
:
304 glDepthFunc(GL_GEQUAL
);
307 glDepthFunc(GL_ALWAYS
);
311 ERR("Unexpected value\n");
315 case D3DRENDERSTATE_DITHERENABLE
: /* 26 */
319 glDisable(GL_DITHER
);
322 case D3DRENDERSTATE_ALPHABLENDENABLE
: /* 27 */
329 case D3DRENDERSTATE_COLORKEYENABLE
: /* 41 */
336 case D3DRENDERSTATE_FLUSHBATCH
: /* 50 */
340 ERR("Unhandled Render State\n");
349 #endif /* HAVE_MESAGL */