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 void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
34 DWORD dwRenderState, RenderState *rs)
37 TRACE("%s = %08lx\n", _get_renderstate(dwRenderStateType), dwRenderState);
39 /* First, all the stipple patterns */
40 if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
41 (dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
42 ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType);
46 /* All others state variables */
47 switch (dwRenderStateType) {
48 case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
49 IDirect3DTextureImpl *tex = (IDirect3DTextureImpl*) dwRenderState;
52 glBindTexture(GL_TEXTURE_2D, 0);
53 glDisable(GL_TEXTURE_2D);
54 TRACE("disabling texturing\n");
56 IDirect3DTextureGLImpl *gl_tex = (IDirect3DTextureGLImpl *) tex;
58 glEnable(GL_TEXTURE_2D);
59 /* Default parameters */
60 glBindTexture(GL_TEXTURE_2D, gl_tex->tex_name);
61 /* To prevent state change, we could test here what are the parameters
62 stored in the texture */
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
65 TRACE("setting OpenGL texture handle : %d\n", gl_tex->tex_name);
69 case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
71 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
73 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
76 case D3DRENDERSTATE_ZENABLE: /* 7 */
78 glEnable(GL_DEPTH_TEST);
80 glDisable(GL_DEPTH_TEST);
83 case D3DRENDERSTATE_FILLMODE: /* 8 */
84 switch ((D3DFILLMODE) dwRenderState) {
86 glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
88 case D3DFILL_WIREFRAME:
89 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
92 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
95 ERR("Unhandled fill mode !\n");
99 case D3DRENDERSTATE_SHADEMODE: /* 9 */
100 switch ((D3DSHADEMODE) dwRenderState) {
102 glShadeModel(GL_FLAT);
104 case D3DSHADE_GOURAUD:
105 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;
124 case D3DFILTER_LINEAR:
128 ERR("Unhandled texture mag !\n");
132 case D3DRENDERSTATE_TEXTUREMIN: /* 18 */
133 switch ((D3DTEXTUREFILTER) dwRenderState) {
134 case D3DFILTER_NEAREST:
135 rs->min = GL_NEAREST;
137 case D3DFILTER_LINEAR:
141 ERR("Unhandled texture min !\n");
145 case D3DRENDERSTATE_SRCBLEND: /* 19 */
146 switch ((D3DBLEND) dwRenderState) {
147 case D3DBLEND_SRCALPHA:
148 rs->src = GL_SRC_ALPHA;
151 ERR("Unhandled blend mode !\n");
153 glBlendFunc(rs->src, rs->dst);
156 case D3DRENDERSTATE_DESTBLEND: /* 20 */
157 switch ((D3DBLEND) dwRenderState) {
158 case D3DBLEND_INVSRCALPHA:
159 rs->dst = GL_ONE_MINUS_SRC_ALPHA;
162 ERR("Unhandled blend mode !\n");
164 glBlendFunc(rs->src, rs->dst);
167 case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
168 switch ((D3DTEXTUREBLEND) dwRenderState) {
169 case D3DTBLEND_MODULATE:
170 case D3DTBLEND_MODULATEALPHA:
171 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
174 ERR("Unhandled texture environment !\n");
178 case D3DRENDERSTATE_CULLMODE: /* 22 */
179 switch ((D3DCULL) dwRenderState) {
181 glDisable(GL_CULL_FACE);
184 glEnable(GL_CULL_FACE);
188 glEnable(GL_CULL_FACE);
192 ERR("Unhandled cull mode !\n");
196 case D3DRENDERSTATE_ZFUNC: /* 23 */
197 switch ((D3DCMPFUNC) dwRenderState) {
199 glDepthFunc(GL_NEVER);
202 glDepthFunc(GL_LESS);
205 glDepthFunc(GL_EQUAL);
207 case D3DCMP_LESSEQUAL:
208 glDepthFunc(GL_LEQUAL);
211 glDepthFunc(GL_GREATER);
213 case D3DCMP_NOTEQUAL:
214 glDepthFunc(GL_NOTEQUAL);
216 case D3DCMP_GREATEREQUAL:
217 glDepthFunc(GL_GEQUAL);
220 glDepthFunc(GL_ALWAYS);
223 ERR("Unexpected value\n");
227 case D3DRENDERSTATE_DITHERENABLE: /* 26 */
231 glDisable(GL_DITHER);
234 case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
241 case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
248 case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
252 ERR("Unhandled dwRenderStateType %s !\n", _get_renderstate(dwRenderStateType));