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 TRACE("%s = %08lx\n", _get_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) {
90 glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
92 case D3DFILL_WIREFRAME:
93 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
96 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
100 ERR("Unhandled fill mode !\n");
104 case D3DRENDERSTATE_SHADEMODE: /* 9 */
105 switch ((D3DSHADEMODE) dwRenderState) {
107 glShadeModel(GL_FLAT);
110 case D3DSHADE_GOURAUD:
111 glShadeModel(GL_SMOOTH);
115 ERR("Unhandled shade mode !\n");
119 case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
121 glDepthMask(GL_TRUE);
123 glDepthMask(GL_FALSE);
126 case D3DRENDERSTATE_TEXTUREMAG: /* 17 */
127 switch ((D3DTEXTUREFILTER) dwRenderState) {
128 case D3DFILTER_NEAREST:
129 rs->mag = GL_NEAREST;
132 case D3DFILTER_LINEAR:
137 ERR("Unhandled texture mag !\n");
141 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
142 switch ((D3DTEXTUREFILTER) dwRenderState) {
143 case D3DFILTER_NEAREST:
144 rs->min = GL_NEAREST;
147 case D3DFILTER_LINEAR:
152 ERR("Unhandled texture min !\n");
156 case D3DRENDERSTATE_SRCBLEND: /* 19 */
157 switch ((D3DBLEND) dwRenderState) {
158 case D3DBLEND_SRCALPHA:
159 rs->src = GL_SRC_ALPHA;
163 ERR("Unhandled blend mode !\n");
166 glBlendFunc(rs->src, rs->dst);
169 case D3DRENDERSTATE_DESTBLEND: /* 20 */
170 switch ((D3DBLEND) dwRenderState) {
171 case D3DBLEND_INVSRCALPHA:
172 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
176 ERR("Unhandled blend mode !\n");
179 glBlendFunc(rs->src, rs->dst);
182 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
183 switch ((D3DTEXTUREBLEND) dwRenderState) {
184 case D3DTBLEND_MODULATE:
185 case D3DTBLEND_MODULATEALPHA:
186 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
190 ERR("Unhandled texture environment !\n");
194 case D3DRENDERSTATE_CULLMODE: /* 22 */
195 switch ((D3DCULL) dwRenderState) {
197 glDisable(GL_CULL_FACE);
201 glEnable(GL_CULL_FACE);
206 glEnable(GL_CULL_FACE);
211 ERR("Unhandled cull mode !\n");
215 case D3DRENDERSTATE_ZFUNC: /* 23 */
216 switch ((D3DCMPFUNC) dwRenderState) {
218 glDepthFunc(GL_NEVER);
221 glDepthFunc(GL_LESS);
224 glDepthFunc(GL_EQUAL);
226 case D3DCMP_LESSEQUAL:
227 glDepthFunc(GL_LEQUAL);
230 glDepthFunc(GL_GREATER);
232 case D3DCMP_NOTEQUAL:
233 glDepthFunc(GL_NOTEQUAL);
235 case D3DCMP_GREATEREQUAL:
236 glDepthFunc(GL_GEQUAL);
239 glDepthFunc(GL_ALWAYS);
243 ERR("Unexpected value\n");
247 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
251 glDisable(GL_DITHER);
254 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
261 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
268 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
272 ERR("Unhandled dwRenderStateType %s !\n", _get_renderstate(dwRenderStateType));