2000-04-09 16:30:50 +02:00
|
|
|
/* Direct3D Common functions
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright (c) 1998 Lionel ULMER
|
|
|
|
*
|
|
|
|
* This file contains all MESA common code
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2001-11-06 21:57:11 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-04-09 16:30:50 +02:00
|
|
|
#include "windef.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
|
|
#include "mesa_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-12-16 23:39:09 +01:00
|
|
|
GLenum convert_D3D_compare_to_GL(D3DCMPFUNC dwRenderState)
|
|
|
|
{
|
|
|
|
switch (dwRenderState) {
|
|
|
|
case D3DCMP_NEVER: return GL_NEVER;
|
|
|
|
case D3DCMP_LESS: return GL_LESS;
|
|
|
|
case D3DCMP_EQUAL: return GL_EQUAL;
|
|
|
|
case D3DCMP_LESSEQUAL: return GL_LEQUAL;
|
|
|
|
case D3DCMP_GREATER: return GL_GREATER;
|
|
|
|
case D3DCMP_NOTEQUAL: return GL_NOTEQUAL;
|
|
|
|
case D3DCMP_GREATEREQUAL: return GL_GEQUAL;
|
|
|
|
case D3DCMP_ALWAYS: return GL_ALWAYS;
|
2002-12-16 23:48:20 +01:00
|
|
|
default: ERR("Unexpected compare type %d !\n", dwRenderState);
|
2002-12-16 23:39:09 +01:00
|
|
|
}
|
2002-12-16 23:48:20 +01:00
|
|
|
return GL_ALWAYS;
|
2002-12-16 23:39:09 +01:00
|
|
|
}
|
|
|
|
|
2003-01-02 21:01:54 +01:00
|
|
|
GLenum convert_D3D_stencilop_to_GL(D3DSTENCILOP dwRenderState)
|
|
|
|
{
|
|
|
|
switch (dwRenderState) {
|
|
|
|
case D3DSTENCILOP_KEEP: return GL_KEEP;
|
|
|
|
case D3DSTENCILOP_ZERO: return GL_ZERO;
|
|
|
|
case D3DSTENCILOP_REPLACE: return GL_REPLACE;
|
|
|
|
case D3DSTENCILOP_INCRSAT: return GL_INCR;
|
|
|
|
case D3DSTENCILOP_DECRSAT: return GL_DECR;
|
|
|
|
case D3DSTENCILOP_INVERT: return GL_INVERT;
|
|
|
|
case D3DSTENCILOP_INCR: WARN("D3DSTENCILOP_INCR not properly handled !\n"); return GL_INCR;
|
|
|
|
case D3DSTENCILOP_DECR: WARN("D3DSTENCILOP_DECR not properly handled !\n"); return GL_DECR;
|
|
|
|
default: ERR("Unexpected compare type %d !\n", dwRenderState);
|
|
|
|
}
|
|
|
|
return GL_KEEP;
|
|
|
|
}
|
2002-12-16 23:39:09 +01:00
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
GLenum convert_D3D_blendop_to_GL(D3DBLEND dwRenderState)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2003-01-08 00:08:31 +01:00
|
|
|
switch ((D3DBLEND) dwRenderState) {
|
|
|
|
case D3DBLEND_ZERO: return GL_ZERO;
|
|
|
|
case D3DBLEND_ONE: return GL_ONE;
|
|
|
|
case D3DBLEND_SRCALPHA: return GL_SRC_ALPHA;
|
|
|
|
case D3DBLEND_INVSRCALPHA: return GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
case D3DBLEND_DESTALPHA: return GL_DST_ALPHA;
|
|
|
|
case D3DBLEND_INVDESTALPHA: return GL_ONE_MINUS_DST_ALPHA;
|
|
|
|
case D3DBLEND_DESTCOLOR: return GL_DST_COLOR;
|
|
|
|
case D3DBLEND_INVDESTCOLOR: return GL_ONE_MINUS_DST_COLOR;
|
|
|
|
case D3DBLEND_SRCALPHASAT: return GL_SRC_ALPHA_SATURATE;
|
|
|
|
case D3DBLEND_SRCCOLOR: return GL_SRC_COLOR;
|
|
|
|
case D3DBLEND_INVSRCCOLOR: return GL_ONE_MINUS_SRC_COLOR;
|
|
|
|
default: ERR("Unhandled blend mode %d !\n", dwRenderState); return GL_ZERO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_render_state(IDirect3DDeviceImpl* This,
|
|
|
|
D3DRENDERSTATETYPE dwRenderStateType, STATEBLOCK *lpStateBlock)
|
|
|
|
{
|
|
|
|
DWORD dwRenderState = lpStateBlock->render_state[dwRenderStateType - 1];
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
TRACE("%s = %08lx\n", _get_renderstate(dwRenderStateType), dwRenderState);
|
|
|
|
|
|
|
|
/* First, all the stipple patterns */
|
|
|
|
if ((dwRenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00) &&
|
|
|
|
(dwRenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)) {
|
|
|
|
ERR("Unhandled dwRenderStateType stipple %d!\n",dwRenderStateType);
|
|
|
|
} else {
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
/* All others state variables */
|
|
|
|
switch (dwRenderStateType) {
|
|
|
|
case D3DRENDERSTATE_TEXTUREHANDLE: { /* 1 */
|
2002-12-15 02:17:59 +01:00
|
|
|
IDirectDrawSurfaceImpl *tex = (IDirectDrawSurfaceImpl*) dwRenderState;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-05 02:04:55 +01:00
|
|
|
LEAVE_GL();
|
2003-01-08 00:08:31 +01:00
|
|
|
IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
|
2003-01-05 02:04:55 +01:00
|
|
|
0,
|
|
|
|
ICOM_INTERFACE(tex, IDirectDrawSurface7));
|
|
|
|
ENTER_GL();
|
2002-11-21 22:04:16 +01:00
|
|
|
} break;
|
2002-12-17 00:09:23 +01:00
|
|
|
|
2002-12-16 23:39:09 +01:00
|
|
|
case D3DRENDERSTATE_TEXTUREADDRESSU: /* 44 */
|
|
|
|
case D3DRENDERSTATE_TEXTUREADDRESSV: /* 45 */
|
|
|
|
case D3DRENDERSTATE_TEXTUREADDRESS: { /* 3 */
|
2003-01-08 00:08:31 +01:00
|
|
|
D3DTEXTURESTAGESTATETYPE d3dTexStageStateType;
|
|
|
|
|
|
|
|
if (dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESS) d3dTexStageStateType = D3DTSS_ADDRESS;
|
|
|
|
else if (dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESSU) d3dTexStageStateType = D3DTSS_ADDRESSU;
|
|
|
|
else d3dTexStageStateType = D3DTSS_ADDRESSV;
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
|
|
|
|
0, d3dTexStageStateType,
|
|
|
|
dwRenderState);
|
|
|
|
ENTER_GL();
|
2002-12-16 23:08:24 +01:00
|
|
|
} break;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
case D3DRENDERSTATE_TEXTUREPERSPECTIVE: /* 4 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
|
|
else
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
|
|
|
break;
|
|
|
|
|
2002-12-23 03:09:20 +01:00
|
|
|
case D3DRENDERSTATE_WRAPU: /* 5 */
|
|
|
|
if (dwRenderState)
|
|
|
|
ERR("WRAPU mode unsupported by OpenGL.. Expect graphical glitches !\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_WRAPV: /* 6 */
|
|
|
|
if (dwRenderState)
|
|
|
|
ERR("WRAPV mode unsupported by OpenGL.. Expect graphical glitches !\n");
|
|
|
|
break;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
case D3DRENDERSTATE_ZENABLE: /* 7 */
|
2003-01-02 21:13:47 +01:00
|
|
|
/* To investigate : in OpenGL, if we disable the depth test, the Z buffer will NOT be
|
|
|
|
updated either.. No idea about what happens in D3D.
|
|
|
|
|
|
|
|
Maybe replacing the Z function by ALWAYS would be a better idea. */
|
|
|
|
if (dwRenderState == D3DZB_TRUE)
|
2002-11-21 22:04:16 +01:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2003-01-02 21:13:47 +01:00
|
|
|
else if (dwRenderState == D3DZB_FALSE)
|
2002-11-21 22:04:16 +01:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2003-01-02 21:13:47 +01:00
|
|
|
else {
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
WARN(" w-buffering not supported.\n");
|
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_FILLMODE: /* 8 */
|
|
|
|
switch ((D3DFILLMODE) dwRenderState) {
|
|
|
|
case D3DFILL_POINT:
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
|
|
|
|
break;
|
|
|
|
case D3DFILL_WIREFRAME:
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
|
|
|
break;
|
|
|
|
case D3DFILL_SOLID:
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
|
|
|
|
break;
|
|
|
|
default:
|
2002-12-16 23:50:30 +01:00
|
|
|
ERR("Unhandled fill mode %ld !\n",dwRenderState);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_SHADEMODE: /* 9 */
|
|
|
|
switch ((D3DSHADEMODE) dwRenderState) {
|
|
|
|
case D3DSHADE_FLAT:
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
break;
|
|
|
|
case D3DSHADE_GOURAUD:
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
break;
|
|
|
|
default:
|
2002-12-16 23:50:30 +01:00
|
|
|
ERR("Unhandled shade mode %ld !\n",dwRenderState);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_ZWRITEENABLE: /* 14 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
else
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
break;
|
2002-12-16 23:39:09 +01:00
|
|
|
|
|
|
|
case D3DRENDERSTATE_ALPHATESTENABLE: /* 15 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
else
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
break;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
case D3DRENDERSTATE_TEXTUREMAG: { /* 17 */
|
|
|
|
DWORD tex_mag = 0xFFFFFFFF;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
switch ((D3DTEXTUREFILTER) dwRenderState) {
|
|
|
|
case D3DFILTER_NEAREST:
|
2003-01-08 00:08:31 +01:00
|
|
|
tex_mag = D3DTFG_POINT;
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
case D3DFILTER_LINEAR:
|
2003-01-08 00:08:31 +01:00
|
|
|
tex_mag = D3DTFG_LINEAR;
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
2002-12-16 23:50:30 +01:00
|
|
|
ERR("Unhandled texture mag %ld !\n",dwRenderState);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
if (tex_mag != 0xFFFFFFFF) {
|
|
|
|
LEAVE_GL();
|
|
|
|
IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7), 0, D3DTSS_MAGFILTER, tex_mag);
|
|
|
|
ENTER_GL();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_TEXTUREMIN: { /* 18 */
|
|
|
|
DWORD tex_min = 0xFFFFFFFF;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
switch ((D3DTEXTUREFILTER) dwRenderState) {
|
|
|
|
case D3DFILTER_NEAREST:
|
2003-01-08 00:08:31 +01:00
|
|
|
tex_min = D3DTFN_POINT;
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
case D3DFILTER_LINEAR:
|
2003-01-08 00:08:31 +01:00
|
|
|
tex_min = D3DTFN_LINEAR;
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
2002-12-16 23:50:30 +01:00
|
|
|
ERR("Unhandled texture min %ld !\n",dwRenderState);
|
2003-01-08 00:08:31 +01:00
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
if (tex_min != 0xFFFFFFFF) {
|
|
|
|
LEAVE_GL();
|
|
|
|
IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7), 0, D3DTSS_MINFILTER, tex_min);
|
|
|
|
ENTER_GL();
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2003-01-08 00:08:31 +01:00
|
|
|
} break;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
case D3DRENDERSTATE_SRCBLEND: /* 19 */
|
2002-11-21 22:04:16 +01:00
|
|
|
case D3DRENDERSTATE_DESTBLEND: /* 20 */
|
2003-01-08 00:08:31 +01:00
|
|
|
glBlendFunc(convert_D3D_blendop_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_SRCBLEND - 1]),
|
|
|
|
convert_D3D_blendop_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_DESTBLEND - 1]));
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_TEXTUREMAPBLEND: /* 21 */
|
|
|
|
switch ((D3DTEXTUREBLEND) dwRenderState) {
|
|
|
|
case D3DTBLEND_MODULATE:
|
|
|
|
case D3DTBLEND_MODULATEALPHA:
|
2003-01-02 20:45:23 +01:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
break;
|
2002-11-21 22:04:16 +01:00
|
|
|
default:
|
2003-01-08 00:08:31 +01:00
|
|
|
ERR("Unhandled texture environment %ld !\n",dwRenderState);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_CULLMODE: /* 22 */
|
|
|
|
switch ((D3DCULL) dwRenderState) {
|
|
|
|
case D3DCULL_NONE:
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
break;
|
|
|
|
case D3DCULL_CW:
|
|
|
|
glEnable(GL_CULL_FACE);
|
2003-01-02 21:05:48 +01:00
|
|
|
glFrontFace(GL_CCW);
|
2003-01-02 20:45:23 +01:00
|
|
|
glCullFace(GL_BACK);
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
case D3DCULL_CCW:
|
|
|
|
glEnable(GL_CULL_FACE);
|
2003-01-02 21:05:48 +01:00
|
|
|
glFrontFace(GL_CW);
|
2003-01-02 20:45:23 +01:00
|
|
|
glCullFace(GL_BACK);
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
2002-12-16 23:50:30 +01:00
|
|
|
ERR("Unhandled cull mode %ld !\n",dwRenderState);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_ZFUNC: /* 23 */
|
2002-12-16 23:39:09 +01:00
|
|
|
glDepthFunc(convert_D3D_compare_to_GL(dwRenderState));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_ALPHAREF: /* 24 */
|
2003-01-08 00:08:31 +01:00
|
|
|
case D3DRENDERSTATE_ALPHAFUNC: /* 25 */
|
|
|
|
glAlphaFunc(convert_D3D_compare_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_ALPHAFUNC - 1]),
|
|
|
|
(lpStateBlock->render_state[D3DRENDERSTATE_ALPHAREF - 1] & 0x000000FF) / 255.0);
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_DITHERENABLE: /* 26 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glEnable(GL_DITHER);
|
|
|
|
else
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
|
2003-01-02 20:45:23 +01:00
|
|
|
if (dwRenderState) {
|
2002-11-21 22:04:16 +01:00
|
|
|
glEnable(GL_BLEND);
|
2003-01-02 20:45:23 +01:00
|
|
|
} else {
|
2002-11-21 22:04:16 +01:00
|
|
|
glDisable(GL_BLEND);
|
2003-01-02 20:45:23 +01:00
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
break;
|
2002-12-17 00:09:23 +01:00
|
|
|
|
|
|
|
case D3DRENDERSTATE_FOGENABLE: /* 28 */
|
2003-01-23 02:21:50 +01:00
|
|
|
/* Nothing to do here. Only the storage matters :-) */
|
2002-12-17 00:09:23 +01:00
|
|
|
break;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2002-12-17 00:09:23 +01:00
|
|
|
case D3DRENDERSTATE_SPECULARENABLE: /* 29 */
|
|
|
|
if (dwRenderState)
|
|
|
|
ERR(" Specular Lighting not supported yet.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_SUBPIXEL: /* 31 */
|
|
|
|
case D3DRENDERSTATE_SUBPIXELX: /* 32 */
|
|
|
|
/* We do not support this anyway, so why protest :-) */
|
2003-01-23 02:21:50 +01:00
|
|
|
break;
|
2002-12-17 00:09:23 +01:00
|
|
|
|
2002-12-24 02:03:04 +01:00
|
|
|
case D3DRENDERSTATE_STIPPLEDALPHA: /* 33 */
|
|
|
|
if (dwRenderState)
|
|
|
|
ERR(" Stippled Alpha not supported yet.\n");
|
|
|
|
break;
|
|
|
|
|
2002-12-17 00:09:23 +01:00
|
|
|
case D3DRENDERSTATE_FOGCOLOR: { /* 34 */
|
2003-01-23 02:21:50 +01:00
|
|
|
GLfloat color[4];
|
|
|
|
color[0] = ((dwRenderState >> 16) & 0xFF)/255.0f;
|
|
|
|
color[1] = ((dwRenderState >> 8) & 0xFF)/255.0f;
|
|
|
|
color[2] = ((dwRenderState >> 0) & 0xFF)/255.0f;
|
|
|
|
color[3] = ((dwRenderState >> 24) & 0xFF)/255.0f;
|
|
|
|
glFogfv(GL_FOG_COLOR,color);
|
|
|
|
/* Note: glFogiv does not seem to work */
|
2002-12-17 00:09:23 +01:00
|
|
|
} break;
|
|
|
|
|
2003-01-23 02:21:50 +01:00
|
|
|
case D3DRENDERSTATE_FOGTABLEMODE: /* 35 */
|
|
|
|
case D3DRENDERSTATE_FOGVERTEXMODE: /* 140 */
|
|
|
|
case D3DRENDERSTATE_FOGSTART: /* 36 */
|
|
|
|
case D3DRENDERSTATE_FOGEND: /* 37 */
|
|
|
|
/* Nothing to do here. Only the storage matters :-) */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_FOGDENSITY: /* 38 */
|
|
|
|
glFogi(GL_FOG_DENSITY,*(float*)&dwRenderState);
|
|
|
|
break;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */
|
2003-01-03 22:16:03 +01:00
|
|
|
/* This needs to be fixed. */
|
2002-11-21 22:04:16 +01:00
|
|
|
if (dwRenderState)
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
else
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
break;
|
|
|
|
|
2002-12-17 00:09:23 +01:00
|
|
|
case D3DRENDERSTATE_ZBIAS: /* 47 */
|
|
|
|
/* This is a tad bit hacky.. But well, no idea how to do it better in OpenGL :-/ */
|
|
|
|
if (dwRenderState == 0) {
|
|
|
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glDisable(GL_POLYGON_OFFSET_LINE);
|
|
|
|
glDisable(GL_POLYGON_OFFSET_POINT);
|
|
|
|
} else {
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_LINE);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_POINT);
|
|
|
|
glPolygonOffset(1.0, dwRenderState * 1.0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
case D3DRENDERSTATE_FLUSHBATCH: /* 50 */
|
|
|
|
break;
|
|
|
|
|
2003-01-02 21:01:54 +01:00
|
|
|
case D3DRENDERSTATE_STENCILENABLE: /* 52 */
|
|
|
|
if (dwRenderState)
|
2003-01-08 00:08:31 +01:00
|
|
|
glEnable(GL_STENCIL_TEST);
|
2003-01-02 21:01:54 +01:00
|
|
|
else
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_STENCILFAIL: /* 53 */
|
|
|
|
case D3DRENDERSTATE_STENCILZFAIL: /* 54 */
|
|
|
|
case D3DRENDERSTATE_STENCILPASS: /* 55 */
|
2003-01-08 00:08:31 +01:00
|
|
|
glStencilOp(convert_D3D_stencilop_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_STENCILFAIL - 1]),
|
|
|
|
convert_D3D_stencilop_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_STENCILZFAIL - 1]),
|
|
|
|
convert_D3D_stencilop_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_STENCILPASS - 1]));
|
2003-01-02 21:01:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_STENCILFUNC: /* 56 */
|
|
|
|
case D3DRENDERSTATE_STENCILREF: /* 57 */
|
|
|
|
case D3DRENDERSTATE_STENCILMASK: /* 58 */
|
2003-01-08 00:08:31 +01:00
|
|
|
glStencilFunc(convert_D3D_compare_to_GL(lpStateBlock->render_state[D3DRENDERSTATE_STENCILFUNC - 1]),
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_STENCILREF - 1],
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_STENCILMASK - 1]);
|
2003-01-02 21:01:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_STENCILWRITEMASK: /* 59 */
|
|
|
|
glStencilMask(dwRenderState);
|
|
|
|
break;
|
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
case D3DRENDERSTATE_CLIPPING: /* 136 */
|
|
|
|
case D3DRENDERSTATE_CLIPPLANEENABLE: { /* 152 */
|
2003-01-07 20:42:26 +01:00
|
|
|
GLint i;
|
|
|
|
DWORD mask, runner;
|
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
if (dwRenderStateType == D3DRENDERSTATE_CLIPPING) {
|
|
|
|
mask = ((dwRenderState) ?
|
|
|
|
(This->state_block.render_state[D3DRENDERSTATE_CLIPPLANEENABLE - 1]) : (0x0000));
|
2003-01-07 20:42:26 +01:00
|
|
|
} else {
|
|
|
|
mask = dwRenderState;
|
|
|
|
}
|
2003-01-08 00:08:31 +01:00
|
|
|
for (i = 0, runner = 0x00000001; i < This->max_clipping_planes; i++, runner = (runner << 1)) {
|
2003-01-07 20:42:26 +01:00
|
|
|
if (mask & runner) {
|
|
|
|
glEnable(GL_CLIP_PLANE0 + i);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_CLIP_PLANE0 + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-03 20:10:48 +01:00
|
|
|
break;
|
|
|
|
|
2002-12-24 02:03:04 +01:00
|
|
|
case D3DRENDERSTATE_LIGHTING: /* 137 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
else
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
break;
|
2003-01-02 21:01:54 +01:00
|
|
|
|
|
|
|
case D3DRENDERSTATE_AMBIENT: { /* 139 */
|
|
|
|
float light[4];
|
|
|
|
|
|
|
|
light[0] = ((dwRenderState >> 16) & 0xFF) / 255.0;
|
|
|
|
light[1] = ((dwRenderState >> 8) & 0xFF) / 255.0;
|
|
|
|
light[2] = ((dwRenderState >> 0) & 0xFF) / 255.0;
|
|
|
|
light[3] = ((dwRenderState >> 24) & 0xFF) / 255.0;
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (float *) light);
|
|
|
|
} break;
|
|
|
|
|
2003-02-12 22:35:06 +01:00
|
|
|
case D3DRENDERSTATE_COLORVERTEX: /* 141 */
|
|
|
|
/* Nothing to do here.. Only storage matters */
|
|
|
|
break;
|
|
|
|
|
2003-01-02 21:01:54 +01:00
|
|
|
case D3DRENDERSTATE_LOCALVIEWER: /* 142 */
|
|
|
|
if (dwRenderState)
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
|
|
|
else
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DRENDERSTATE_NORMALIZENORMALS: /* 143 */
|
|
|
|
if (dwRenderState) {
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
glEnable(GL_RESCALE_NORMAL);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
glDisable(GL_RESCALE_NORMAL);
|
|
|
|
}
|
|
|
|
break;
|
2002-12-24 02:03:04 +01:00
|
|
|
|
2003-01-03 22:08:50 +01:00
|
|
|
case D3DRENDERSTATE_DIFFUSEMATERIALSOURCE: /* 145 */
|
2003-01-03 22:03:15 +01:00
|
|
|
case D3DRENDERSTATE_SPECULARMATERIALSOURCE: /* 146 */
|
|
|
|
case D3DRENDERSTATE_AMBIENTMATERIALSOURCE: /* 147 */
|
|
|
|
case D3DRENDERSTATE_EMISSIVEMATERIALSOURCE: /* 148 */
|
2003-01-08 00:08:31 +01:00
|
|
|
/* Nothing to do here. Only the storage matters :-) */
|
2003-01-03 22:03:15 +01:00
|
|
|
break;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
default:
|
2002-12-24 02:00:45 +01:00
|
|
|
ERR("Unhandled dwRenderStateType %s (%08x) !\n", _get_renderstate(dwRenderStateType), dwRenderStateType);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
LEAVE_GL();
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
}
|
2003-01-03 22:08:50 +01:00
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
void store_render_state(IDirect3DDeviceImpl *This,
|
|
|
|
D3DRENDERSTATETYPE dwRenderStateType, DWORD dwRenderState, STATEBLOCK *lpStateBlock)
|
2003-01-03 22:08:50 +01:00
|
|
|
{
|
|
|
|
TRACE("%s = %08lx\n", _get_renderstate(dwRenderStateType), dwRenderState);
|
2003-01-08 00:08:31 +01:00
|
|
|
|
|
|
|
/* Some special cases first.. */
|
|
|
|
if (dwRenderStateType == D3DRENDERSTATE_SRCBLEND) {
|
|
|
|
if (dwRenderState == D3DBLEND_BOTHSRCALPHA) {
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_SRCBLEND - 1] = D3DBLEND_SRCALPHA;
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_DESTBLEND - 1] = D3DBLEND_SRCALPHA;
|
|
|
|
return;
|
|
|
|
} else if (dwRenderState == D3DBLEND_BOTHINVSRCALPHA) {
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_SRCBLEND - 1] = D3DBLEND_INVSRCALPHA;
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_DESTBLEND - 1] = D3DBLEND_INVSRCALPHA;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (dwRenderStateType == D3DRENDERSTATE_TEXTUREADDRESS) {
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_TEXTUREADDRESSU - 1] = dwRenderState;
|
|
|
|
lpStateBlock->render_state[D3DRENDERSTATE_TEXTUREADDRESSV - 1] = dwRenderState;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default case */
|
|
|
|
lpStateBlock->render_state[dwRenderStateType - 1] = dwRenderState;
|
2003-01-03 22:08:50 +01:00
|
|
|
}
|
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
void get_render_state(IDirect3DDeviceImpl *This,
|
|
|
|
D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState, STATEBLOCK *lpStateBlock)
|
2003-01-03 22:08:50 +01:00
|
|
|
{
|
2003-01-08 00:08:31 +01:00
|
|
|
*lpdwRenderState = lpStateBlock->render_state[dwRenderStateType - 1];
|
2003-01-03 22:08:50 +01:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
TRACE("%s = %08lx\n", _get_renderstate(dwRenderStateType), *lpdwRenderState);
|
|
|
|
}
|
|
|
|
|
2003-01-08 00:08:31 +01:00
|
|
|
void apply_render_state(IDirect3DDeviceImpl *This, STATEBLOCK *lpStateBlock)
|
2003-01-03 22:08:50 +01:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
TRACE("(%p,%p)\n", This, lpStateBlock);
|
2003-01-08 00:08:31 +01:00
|
|
|
for(i = 0; i < HIGHEST_RENDER_STATE; i++)
|
2003-01-03 22:08:50 +01:00
|
|
|
if (lpStateBlock->set_flags.render_state[i])
|
2003-01-08 00:08:31 +01:00
|
|
|
set_render_state(This, i + 1, lpStateBlock);
|
2003-01-03 22:08:50 +01:00
|
|
|
}
|