📄 state.c
字号:
/*
* Direct3D state management
*
* Copyright 2002 Lionel Ulmer
* Copyright 2002-2005 Jason Edmeades
* Copyright 2003-2004 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2006 Henri Verbeet
* Copyright 2006-2007 Stefan D鰏inger for CodeWeavers
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
#include "wined3d_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
static void state_nogl(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
/* Used for states which are not mapped to a gl state as-is, but used somehow different,
* e.g as a parameter for drawing, or which are unimplemented in windows d3d
*/
if(STATE_IS_RENDER(state)) {
WINED3DRENDERSTATETYPE RenderState = state - STATE_RENDER(0);
TRACE("(%s,%d) no direct mapping to gl\n", debug_d3drenderstate(RenderState), stateblock->renderState[RenderState]);
} else {
/* Shouldn't have an unknown type here */
FIXME("%d no direct mapping to gl of state with unknown type\n", state);
}
}
static void state_undefined(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
/* Print a WARN, this allows the stateblock code to loop over all states to generate a display
* list without causing confusing terminal output. Deliberately no special debug name here
* because its undefined.
*/
WARN("undefined state %d\n", state);
}
static void state_fillmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
WINED3DFILLMODE Value = stateblock->renderState[WINED3DRS_FILLMODE];
switch(Value) {
case WINED3DFILL_POINT:
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
break;
case WINED3DFILL_WIREFRAME:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
break;
case WINED3DFILL_SOLID:
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
break;
default:
FIXME("Unrecognized WINED3DRS_FILLMODE value %d\n", Value);
}
}
static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
BOOL transformed;
/* Lighting is not enabled if transformed vertices are drawn
* but lighting does not affect the stream sources, so it is not grouped for performance reasons.
* This state reads the decoded vertex decl, so if it is dirty don't do anything. The
* vertex declaration appplying function calls this function for updating
*/
if(isStateDirty(context, STATE_VDECL)) {
return;
}
transformed = ((stateblock->wineD3DDevice->strided_streams.u.s.position.lpData != NULL ||
stateblock->wineD3DDevice->strided_streams.u.s.position.VBO != 0) &&
stateblock->wineD3DDevice->strided_streams.u.s.position_transformed) ? TRUE : FALSE;
if (stateblock->renderState[WINED3DRS_LIGHTING] && !transformed) {
glEnable(GL_LIGHTING);
checkGLcall("glEnable GL_LIGHTING");
} else {
glDisable(GL_LIGHTING);
checkGLcall("glDisable GL_LIGHTING");
}
}
static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
/* No z test without depth stencil buffers */
if(stateblock->wineD3DDevice->stencilBufferTarget == NULL) {
glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
checkGLcall("glDisable GL_DEPTH_TEST");
return;
}
switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) {
case WINED3DZB_FALSE:
glDisable(GL_DEPTH_TEST);
checkGLcall("glDisable GL_DEPTH_TEST");
break;
case WINED3DZB_TRUE:
glEnable(GL_DEPTH_TEST);
checkGLcall("glEnable GL_DEPTH_TEST");
break;
case WINED3DZB_USEW:
glEnable(GL_DEPTH_TEST);
checkGLcall("glEnable GL_DEPTH_TEST");
FIXME("W buffer is not well handled\n");
break;
default:
FIXME("Unrecognized D3DZBUFFERTYPE value %d\n", stateblock->renderState[WINED3DRS_ZENABLE]);
}
}
static void state_cullmode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
/* TODO: Put this into the offscreen / onscreen rendering block due to device->render_offscreen */
/* If we are culling "back faces with clockwise vertices" then
set front faces to be counter clockwise and enable culling
of back faces */
switch ((WINED3DCULL) stateblock->renderState[WINED3DRS_CULLMODE]) {
case WINED3DCULL_NONE:
glDisable(GL_CULL_FACE);
checkGLcall("glDisable GL_CULL_FACE");
break;
case WINED3DCULL_CW:
glEnable(GL_CULL_FACE);
checkGLcall("glEnable GL_CULL_FACE");
if (stateblock->wineD3DDevice->render_offscreen) {
glFrontFace(GL_CW);
checkGLcall("glFrontFace GL_CW");
} else {
glFrontFace(GL_CCW);
checkGLcall("glFrontFace GL_CCW");
}
glCullFace(GL_BACK);
break;
case WINED3DCULL_CCW:
glEnable(GL_CULL_FACE);
checkGLcall("glEnable GL_CULL_FACE");
if (stateblock->wineD3DDevice->render_offscreen) {
glFrontFace(GL_CCW);
checkGLcall("glFrontFace GL_CCW");
} else {
glFrontFace(GL_CW);
checkGLcall("glFrontFace GL_CW");
}
glCullFace(GL_BACK);
break;
default:
FIXME("Unrecognized/Unhandled WINED3DCULL value %d\n", stateblock->renderState[WINED3DRS_CULLMODE]);
}
}
static void state_shademode(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
switch ((WINED3DSHADEMODE) stateblock->renderState[WINED3DRS_SHADEMODE]) {
case WINED3DSHADE_FLAT:
glShadeModel(GL_FLAT);
checkGLcall("glShadeModel(GL_FLAT)");
break;
case WINED3DSHADE_GOURAUD:
glShadeModel(GL_SMOOTH);
checkGLcall("glShadeModel(GL_SMOOTH)");
break;
case WINED3DSHADE_PHONG:
FIXME("WINED3DSHADE_PHONG isn't supported\n");
break;
default:
FIXME("Unrecognized/Unhandled WINED3DSHADEMODE value %d\n", stateblock->renderState[WINED3DRS_SHADEMODE]);
}
}
static void state_ditherenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
if (stateblock->renderState[WINED3DRS_DITHERENABLE]) {
glEnable(GL_DITHER);
checkGLcall("glEnable GL_DITHER");
} else {
glDisable(GL_DITHER);
checkGLcall("glDisable GL_DITHER");
}
}
static void state_zwritenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
/* TODO: Test if in d3d z writing is enabled even if ZENABLE is off. If yes,
* this has to be merged with ZENABLE and ZFUNC
*/
if (stateblock->renderState[WINED3DRS_ZWRITEENABLE]) {
glDepthMask(1);
checkGLcall("glDepthMask(1)");
} else {
glDepthMask(0);
checkGLcall("glDepthMask(0)");
}
}
static void state_zfunc(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
int glParm = CompareFunc(stateblock->renderState[WINED3DRS_ZFUNC]);
if(glParm) {
glDepthFunc(glParm);
checkGLcall("glDepthFunc");
}
}
static void state_ambient(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
float col[4];
D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_AMBIENT], col);
TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
checkGLcall("glLightModel for MODEL_AMBIENT");
}
static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
int srcBlend = GL_ZERO;
int dstBlend = GL_ZERO;
/* GL_LINE_SMOOTH needs GL_BLEND to work, according to the red book, and special blending params */
if (stateblock->renderState[WINED3DRS_ALPHABLENDENABLE] ||
stateblock->renderState[WINED3DRS_EDGEANTIALIAS] ||
stateblock->renderState[WINED3DRS_ANTIALIASEDLINEENABLE]) {
glEnable(GL_BLEND);
checkGLcall("glEnable GL_BLEND");
} else {
glDisable(GL_BLEND);
checkGLcall("glDisable GL_BLEND");
/* Nothing more to do - get out */
return;
};
switch (stateblock->renderState[WINED3DRS_SRCBLEND]) {
case WINED3DBLEND_ZERO : srcBlend = GL_ZERO; break;
case WINED3DBLEND_ONE : srcBlend = GL_ONE; break;
case WINED3DBLEND_SRCCOLOR : srcBlend = GL_SRC_COLOR; break;
case WINED3DBLEND_INVSRCCOLOR : srcBlend = GL_ONE_MINUS_SRC_COLOR; break;
case WINED3DBLEND_SRCALPHA : srcBlend = GL_SRC_ALPHA; break;
case WINED3DBLEND_INVSRCALPHA : srcBlend = GL_ONE_MINUS_SRC_ALPHA; break;
case WINED3DBLEND_DESTALPHA : srcBlend = GL_DST_ALPHA; break;
case WINED3DBLEND_INVDESTALPHA : srcBlend = GL_ONE_MINUS_DST_ALPHA; break;
case WINED3DBLEND_DESTCOLOR : srcBlend = GL_DST_COLOR; break;
case WINED3DBLEND_INVDESTCOLOR : srcBlend = GL_ONE_MINUS_DST_COLOR; break;
case WINED3DBLEND_SRCALPHASAT : srcBlend = GL_SRC_ALPHA_SATURATE; break;
case WINED3DBLEND_BOTHSRCALPHA : srcBlend = GL_SRC_ALPHA;
dstBlend = GL_SRC_ALPHA;
break;
case WINED3DBLEND_BOTHINVSRCALPHA : srcBlend = GL_ONE_MINUS_SRC_ALPHA;
dstBlend = GL_ONE_MINUS_SRC_ALPHA;
break;
case WINED3DBLEND_BLENDFACTOR : srcBlend = GL_CONSTANT_COLOR; break;
case WINED3DBLEND_INVBLENDFACTOR : srcBlend = GL_ONE_MINUS_CONSTANT_COLOR; break;
default:
FIXME("Unrecognized src blend value %d\n", stateblock->renderState[WINED3DRS_SRCBLEND]);
}
switch (stateblock->renderState[WINED3DRS_DESTBLEND]) {
case WINED3DBLEND_ZERO : dstBlend = GL_ZERO; break;
case WINED3DBLEND_ONE : dstBlend = GL_ONE; break;
case WINED3DBLEND_SRCCOLOR : dstBlend = GL_SRC_COLOR; break;
case WINED3DBLEND_INVSRCCOLOR : dstBlend = GL_ONE_MINUS_SRC_COLOR; break;
case WINED3DBLEND_SRCALPHA : dstBlend = GL_SRC_ALPHA; break;
case WINED3DBLEND_INVSRCALPHA : dstBlend = GL_ONE_MINUS_SRC_ALPHA; break;
case WINED3DBLEND_DESTALPHA : dstBlend = GL_DST_ALPHA; break;
case WINED3DBLEND_INVDESTALPHA : dstBlend = GL_ONE_MINUS_DST_ALPHA; break;
case WINED3DBLEND_DESTCOLOR : dstBlend = GL_DST_COLOR; break;
case WINED3DBLEND_INVDESTCOLOR : dstBlend = GL_ONE_MINUS_DST_COLOR; break;
case WINED3DBLEND_SRCALPHASAT :
dstBlend = GL_SRC_ALPHA_SATURATE;
WARN("Application uses SRCALPHASAT as dest blend factor, expect problems\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -