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;
39 glBindTexture(GL_TEXTURE_2D, 0);
40 glDisable(GL_TEXTURE_2D);
41 TRACE("disabling texturing\n");
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);
56 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
58 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
60 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
63 case D3DRENDERSTATE_ZENABLE: /* 7 */
65 glEnable(GL_DEPTH_TEST);
67 glDisable(GL_DEPTH_TEST);
70 case D3DRENDERSTATE_FILLMODE: /* 8 */
71 switch ((D3DFILLMODE) dwRenderState) {
76 ERR("Unhandled fill mode !\n");
80 case D3DRENDERSTATE_SHADEMODE: /* 9 */
81 switch ((D3DSHADEMODE) dwRenderState) {
83 glShadeModel(GL_FLAT);
86 case D3DSHADE_GOURAUD:
87 glShadeModel(GL_SMOOTH);
91 ERR("Unhandled shade mode !\n");
95 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
99 glDepthMask(GL_FALSE);
102 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
103 switch ((D3DTEXTUREFILTER) dwRenderState) {
104 case D3DFILTER_NEAREST:
105 rs->mag = GL_NEAREST;
108 case D3DFILTER_LINEAR:
113 ERR("Unhandled texture mag !\n");
117 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
118 switch ((D3DTEXTUREFILTER) dwRenderState) {
119 case D3DFILTER_NEAREST:
120 rs->min = GL_NEAREST;
123 case D3DFILTER_LINEAR:
128 ERR("Unhandled texture min !\n");
132 case D3DRENDERSTATE_SRCBLEND: /* 19 */
133 switch ((D3DBLEND) dwRenderState) {
134 case D3DBLEND_SRCALPHA:
135 rs->src = GL_SRC_ALPHA;
139 ERR("Unhandled blend mode !\n");
142 glBlendFunc(rs->src, rs->dst);
145 case D3DRENDERSTATE_DESTBLEND: /* 20 */
146 switch ((D3DBLEND) dwRenderState) {
147 case D3DBLEND_INVSRCALPHA:
148 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
152 ERR("Unhandled blend mode !\n");
155 glBlendFunc(rs->src, rs->dst);
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);
166 ERR("Unhandled texture environment !\n");
170 case D3DRENDERSTATE_CULLMODE: /* 22 */
171 switch ((D3DCULL) dwRenderState) {
173 glDisable(GL_CULL_FACE);
177 glEnable(GL_CULL_FACE);
182 glEnable(GL_CULL_FACE);
187 ERR("Unhandled cull mode !\n");
191 case D3DRENDERSTATE_ZFUNC: /* 23 */
192 switch ((D3DCMPFUNC) dwRenderState) {
194 glDepthFunc(GL_NEVER);
197 glDepthFunc(GL_LESS);
200 glDepthFunc(GL_EQUAL);
202 case D3DCMP_LESSEQUAL:
203 glDepthFunc(GL_LEQUAL);
206 glDepthFunc(GL_GREATER);
208 case D3DCMP_NOTEQUAL:
209 glDepthFunc(GL_NOTEQUAL);
211 case D3DCMP_GREATEREQUAL:
212 glDepthFunc(GL_GEQUAL);
215 glDepthFunc(GL_ALWAYS);
219 ERR("Unexpected value\n");
223 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
227 glDisable(GL_DITHER);
230 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
237 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
244 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
248 ERR("Unhandled dwRenderStateType %d!\n",dwRenderStateType);