1 /* Direct3D Common functions
4 This file contains all MESA common code */
7 #include "wine/obj_base.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
)
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
);
32 /* All others state variables */
33 switch (dwRenderStateType
) {
35 case D3DRENDERSTATE_TEXTUREHANDLE
: { /* 1 */
36 IDirect3DTexture2Impl
* tex
= (IDirect3DTexture2Impl
*) dwRenderState
;
40 glBindTexture(GL_TEXTURE_2D
, 0);
41 glDisable(GL_TEXTURE_2D
);
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
);
54 case D3DRENDERSTATE_TEXTUREPERSPECTIVE
: /* 4 */
56 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
58 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
61 case D3DRENDERSTATE_ZENABLE
: /* 7 */
63 glEnable(GL_DEPTH_TEST
);
65 glDisable(GL_DEPTH_TEST
);
68 case D3DRENDERSTATE_FILLMODE
: /* 8 */
69 switch ((D3DFILLMODE
) dwRenderState
) {
74 ERR("Unhandled fill mode !\n");
78 case D3DRENDERSTATE_SHADEMODE
: /* 9 */
79 switch ((D3DSHADEMODE
) dwRenderState
) {
81 glShadeModel(GL_FLAT
);
84 case D3DSHADE_GOURAUD
:
85 glShadeModel(GL_SMOOTH
);
89 ERR("Unhandled shade mode !\n");
93 case D3DRENDERSTATE_ZWRITEENABLE
: /* 14 */
97 glDepthMask(GL_FALSE
);
100 case D3DRENDERSTATE_TEXTUREMAG
: /* 17 */
101 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
102 case D3DFILTER_NEAREST
:
103 rs
->mag
= GL_NEAREST
;
106 case D3DFILTER_LINEAR
:
111 ERR("Unhandled texture mag !\n");
115 case D3DRENDERSTATE_TEXTUREMIN
: /* 18 */
116 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
117 case D3DFILTER_NEAREST
:
118 rs
->min
= GL_NEAREST
;
121 case D3DFILTER_LINEAR
:
126 ERR("Unhandled texture min !\n");
130 case D3DRENDERSTATE_SRCBLEND
: /* 19 */
131 switch ((D3DBLEND
) dwRenderState
) {
132 case D3DBLEND_SRCALPHA
:
133 rs
->src
= GL_SRC_ALPHA
;
137 ERR("Unhandled blend mode !\n");
140 glBlendFunc(rs
->src
, rs
->dst
);
143 case D3DRENDERSTATE_DESTBLEND
: /* 20 */
144 switch ((D3DBLEND
) dwRenderState
) {
145 case D3DBLEND_INVSRCALPHA
:
146 rs
->dst
= GL_ONE_MINUS_SRC_ALPHA
;
150 ERR("Unhandled blend mode !\n");
153 glBlendFunc(rs
->src
, rs
->dst
);
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
);
164 ERR("Unhandled texture environment !\n");
168 case D3DRENDERSTATE_CULLMODE
: /* 22 */
169 switch ((D3DCULL
) dwRenderState
) {
171 glDisable(GL_CULL_FACE
);
175 glEnable(GL_CULL_FACE
);
180 glEnable(GL_CULL_FACE
);
185 ERR("Unhandled cull mode !\n");
189 case D3DRENDERSTATE_ZFUNC
: /* 23 */
190 switch ((D3DCMPFUNC
) dwRenderState
) {
192 glDepthFunc(GL_NEVER
);
195 glDepthFunc(GL_LESS
);
198 glDepthFunc(GL_EQUAL
);
200 case D3DCMP_LESSEQUAL
:
201 glDepthFunc(GL_LEQUAL
);
204 glDepthFunc(GL_GREATER
);
206 case D3DCMP_NOTEQUAL
:
207 glDepthFunc(GL_NOTEQUAL
);
209 case D3DCMP_GREATEREQUAL
:
210 glDepthFunc(GL_GEQUAL
);
213 glDepthFunc(GL_ALWAYS
);
217 ERR("Unexpected value\n");
221 case D3DRENDERSTATE_DITHERENABLE
: /* 26 */
225 glDisable(GL_DITHER
);
228 case D3DRENDERSTATE_ALPHABLENDENABLE
: /* 27 */
235 case D3DRENDERSTATE_COLORKEYENABLE
: /* 41 */
242 case D3DRENDERSTATE_FLUSHBATCH
: /* 50 */
246 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType
);