1 /* Direct3D Common functions
2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains all MESA common code
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/obj_base.h"
27 #include "wine/debug.h"
29 #include "mesa_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 #define D3DTPRIVATE(x) mesa_d3dt_private *dtpriv = (mesa_d3dt_private*)(x)->private
35 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType
,
36 DWORD dwRenderState
, RenderState
*rs
)
40 _dump_renderstate(dwRenderStateType
, dwRenderState
);
42 /* First, all the stipple patterns */
43 if ((dwRenderStateType
>= D3DRENDERSTATE_STIPPLEPATTERN00
) &&
44 (dwRenderStateType
<= D3DRENDERSTATE_STIPPLEPATTERN31
)) {
45 ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType
);
49 /* All others state variables */
50 switch (dwRenderStateType
) {
52 case D3DRENDERSTATE_TEXTUREHANDLE
: { /* 1 */
53 IDirect3DTexture2Impl
* tex
= (IDirect3DTexture2Impl
*) dwRenderState
;
56 glBindTexture(GL_TEXTURE_2D
, 0);
57 glDisable(GL_TEXTURE_2D
);
58 TRACE("disabling texturing\n");
62 glEnable(GL_TEXTURE_2D
);
63 /* Default parameters */
64 glBindTexture(GL_TEXTURE_2D
, dtpriv
->tex_name
);
65 /* To prevent state change, we could test here what are the parameters
66 stored in the texture */
67 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, rs
->mag
);
68 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, rs
->min
);
69 TRACE("setting OpenGL texture handle : %d\n", dtpriv
->tex_name
);
73 case D3DRENDERSTATE_TEXTUREPERSPECTIVE
: /* 4 */
75 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
);
77 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_FASTEST
);
80 case D3DRENDERSTATE_ZENABLE
: /* 7 */
82 glEnable(GL_DEPTH_TEST
);
84 glDisable(GL_DEPTH_TEST
);
87 case D3DRENDERSTATE_FILLMODE
: /* 8 */
88 switch ((D3DFILLMODE
) dwRenderState
) {
93 ERR("Unhandled fill mode !\n");
97 case D3DRENDERSTATE_SHADEMODE
: /* 9 */
98 switch ((D3DSHADEMODE
) dwRenderState
) {
100 glShadeModel(GL_FLAT
);
103 case D3DSHADE_GOURAUD
:
104 glShadeModel(GL_SMOOTH
);
108 ERR("Unhandled shade mode !\n");
112 case D3DRENDERSTATE_ZWRITEENABLE
: /* 14 */
114 glDepthMask(GL_TRUE
);
116 glDepthMask(GL_FALSE
);
119 case D3DRENDERSTATE_TEXTUREMAG
: /* 17 */
120 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
121 case D3DFILTER_NEAREST
:
122 rs
->mag
= GL_NEAREST
;
125 case D3DFILTER_LINEAR
:
130 ERR("Unhandled texture mag !\n");
134 case D3DRENDERSTATE_TEXTUREMIN
: /* 18 */
135 switch ((D3DTEXTUREFILTER
) dwRenderState
) {
136 case D3DFILTER_NEAREST
:
137 rs
->min
= GL_NEAREST
;
140 case D3DFILTER_LINEAR
:
145 ERR("Unhandled texture min !\n");
149 case D3DRENDERSTATE_SRCBLEND
: /* 19 */
150 switch ((D3DBLEND
) dwRenderState
) {
151 case D3DBLEND_SRCALPHA
:
152 rs
->src
= GL_SRC_ALPHA
;
156 ERR("Unhandled blend mode !\n");
159 glBlendFunc(rs
->src
, rs
->dst
);
162 case D3DRENDERSTATE_DESTBLEND
: /* 20 */
163 switch ((D3DBLEND
) dwRenderState
) {
164 case D3DBLEND_INVSRCALPHA
:
165 rs
->dst
= GL_ONE_MINUS_SRC_ALPHA
;
169 ERR("Unhandled blend mode !\n");
172 glBlendFunc(rs
->src
, rs
->dst
);
175 case D3DRENDERSTATE_TEXTUREMAPBLEND
: /* 21 */
176 switch ((D3DTEXTUREBLEND
) dwRenderState
) {
177 case D3DTBLEND_MODULATE
:
178 case D3DTBLEND_MODULATEALPHA
:
179 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
183 ERR("Unhandled texture environment !\n");
187 case D3DRENDERSTATE_CULLMODE
: /* 22 */
188 switch ((D3DCULL
) dwRenderState
) {
190 glDisable(GL_CULL_FACE
);
194 glEnable(GL_CULL_FACE
);
199 glEnable(GL_CULL_FACE
);
204 ERR("Unhandled cull mode !\n");
208 case D3DRENDERSTATE_ZFUNC
: /* 23 */
209 switch ((D3DCMPFUNC
) dwRenderState
) {
211 glDepthFunc(GL_NEVER
);
214 glDepthFunc(GL_LESS
);
217 glDepthFunc(GL_EQUAL
);
219 case D3DCMP_LESSEQUAL
:
220 glDepthFunc(GL_LEQUAL
);
223 glDepthFunc(GL_GREATER
);
225 case D3DCMP_NOTEQUAL
:
226 glDepthFunc(GL_NOTEQUAL
);
228 case D3DCMP_GREATEREQUAL
:
229 glDepthFunc(GL_GEQUAL
);
232 glDepthFunc(GL_ALWAYS
);
236 ERR("Unexpected value\n");
240 case D3DRENDERSTATE_DITHERENABLE
: /* 26 */
244 glDisable(GL_DITHER
);
247 case D3DRENDERSTATE_ALPHABLENDENABLE
: /* 27 */
254 case D3DRENDERSTATE_COLORKEYENABLE
: /* 41 */
261 case D3DRENDERSTATE_FLUSHBATCH
: /* 50 */
265 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType
);