Vertex shader output is lit and transformed, so stop GL doing it all

again.
This commit is contained in:
Jason Edmeades 2003-09-19 00:07:34 +00:00 committed by Alexandre Julliard
parent 74c3281bef
commit 40b09a23e5
2 changed files with 43 additions and 22 deletions

View File

@ -214,21 +214,21 @@ void init_materials(LPDIRECT3DDEVICE8 iface, BOOL isDiffuseSupplied) {
/* Setup views - Transformed & lit if RHW, else untransformed. /* Setup views - Transformed & lit if RHW, else untransformed.
Only unlit if Normals are supplied Only unlit if Normals are supplied
Returns: Whether to restore lighting afterwards */ Returns: Whether to restore lighting afterwards */
BOOL primitiveInitState(LPDIRECT3DDEVICE8 iface, BOOL vtx_transformed, BOOL vtx_lit) { BOOL primitiveInitState(LPDIRECT3DDEVICE8 iface, BOOL vtx_transformed, BOOL vtx_lit, BOOL useVS) {
BOOL isLightingOn = FALSE; BOOL isLightingOn = FALSE;
ICOM_THIS(IDirect3DDevice8Impl,iface); ICOM_THIS(IDirect3DDevice8Impl,iface);
/* If no normals, DISABLE lighting otherwise, dont touch lighing as it is /* If no normals, DISABLE lighting otherwise, dont touch lighing as it is
set by the appropriate render state */ set by the appropriate render state. Note Vertex Shader output is already lit */
if (vtx_lit) { if (vtx_lit || useVS) {
isLightingOn = glIsEnabled(GL_LIGHTING); isLightingOn = glIsEnabled(GL_LIGHTING);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
checkGLcall("glDisable(GL_LIGHTING);"); checkGLcall("glDisable(GL_LIGHTING);");
TRACE("Disabled lighting as no normals supplied, old state = %d\n", isLightingOn); TRACE("Disabled lighting as no normals supplied, old state = %d\n", isLightingOn);
} }
if (vtx_transformed) { if (!useVS && vtx_transformed) {
/* If the last draw was transformed as well, no need to reapply all the matrixes */ /* If the last draw was transformed as well, no need to reapply all the matrixes */
if (!This->last_was_rhw) { if (!This->last_was_rhw) {
@ -270,7 +270,7 @@ BOOL primitiveInitState(LPDIRECT3DDEVICE8 iface, BOOL vtx_transformed, BOOL vtx_
/* Untransformed, so relies on the view and projection matrices */ /* Untransformed, so relies on the view and projection matrices */
if (This->last_was_rhw || !This->modelview_valid) { if (!useVS && (This->last_was_rhw || !This->modelview_valid)) {
/* Only reapply when have to */ /* Only reapply when have to */
This->modelview_valid = TRUE; This->modelview_valid = TRUE;
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -288,7 +288,7 @@ BOOL primitiveInitState(LPDIRECT3DDEVICE8 iface, BOOL vtx_transformed, BOOL vtx_
} }
} }
if (This->last_was_rhw || !This->proj_valid) { if (!useVS && (This->last_was_rhw || !This->proj_valid)) {
/* Only reapply when have to */ /* Only reapply when have to */
This->proj_valid = TRUE; This->proj_valid = TRUE;
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -308,6 +308,24 @@ BOOL primitiveInitState(LPDIRECT3DDEVICE8 iface, BOOL vtx_transformed, BOOL vtx_
checkGLcall("glLoadMatrixf"); checkGLcall("glLoadMatrixf");
} }
/* Vertex Shader output is already transformed, so set up identity matrices */
/* FIXME: Actually, only true for software emulated ones, so when h/w ones
come along this needs to take into account whether s/w ones were
requested or not */
if (useVS) {
glMatrixMode(GL_MODELVIEW);
checkGLcall("glMatrixMode");
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
checkGLcall("glMatrixMode");
glLoadIdentity();
/* Window Coord 0 is the middle of the first pixel, so translate by half
a pixel (See comment above glTranslate above) */
glTranslatef(1.0/This->StateBlock->viewport.Width, -1.0/This->StateBlock->viewport.Height, 0);
checkGLcall("glTranslatef (1.0/width, -1.0/height, 0)");
This->modelview_valid = FALSE;
This->proj_valid = FALSE;
}
This->last_was_rhw = FALSE; This->last_was_rhw = FALSE;
} }
return isLightingOn; return isLightingOn;
@ -601,7 +619,7 @@ void draw_vertex(LPDIRECT3DDEVICE8 iface, /* interf
/* Position -------------------------------- */ /* Position -------------------------------- */
if (isXYZ == TRUE) { if (isXYZ == TRUE) {
if (1.0f == rhw || rhw < 0.01f) { if (1.0f == rhw || rhw < 0.00001f) {
VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z)); VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z));
glVertex3f(x, y, z); glVertex3f(x, y, z);
} else { } else {
@ -1166,7 +1184,7 @@ void drawStridedSlow(LPDIRECT3DDEVICE8 iface, Direct3DVertexStridedData *sd,
/* Position -------------------------------- */ /* Position -------------------------------- */
if (sd->u.s.position.lpData != NULL) { if (sd->u.s.position.lpData != NULL) {
if (1.0f == rhw || rhw < 0.01f) { if (1.0f == rhw || rhw < 0.0001f) {
VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z)); VTRACE(("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z));
glVertex3f(x, y, z); glVertex3f(x, y, z);
} else { } else {
@ -1302,7 +1320,7 @@ void drawStridedSoftwareVS(LPDIRECT3DDEVICE8 iface, Direct3DVertexStridedData *s
/* Draw using this information */ /* Draw using this information */
draw_vertex(iface, draw_vertex(iface,
TRUE, x, y, z, rhw, TRUE, x, y, z, rhw,
FALSE, 0.0f, 0.0f, 0.0f, TRUE, 0.0f, 0.0f, 1.0f,
TRUE, (float*) &vertex_shader->output.oD[0], TRUE, (float*) &vertex_shader->output.oD[0],
TRUE, (float*) &vertex_shader->output.oD[1], TRUE, (float*) &vertex_shader->output.oD[1],
FALSE, ptSize, /* FIXME: Change back when supported */ FALSE, ptSize, /* FIXME: Change back when supported */
@ -1350,7 +1368,7 @@ void drawPrimitive(LPDIRECT3DDEVICE8 iface,
/** init Constants */ /** init Constants */
if (TRUE == This->UpdateStateBlock->Changed.vertexShaderConstant) { if (TRUE == This->UpdateStateBlock->Changed.vertexShaderConstant) {
TRACE_(d3d_shader)("vertex shader init Constant\n"); TRACE_(d3d_shader)("vertex shader initializing constants\n");
IDirect3DVertexShaderImpl_SetConstantF(vertex_shader, 0, (CONST FLOAT*) &This->UpdateStateBlock->vertexShaderConstant[0], 96); IDirect3DVertexShaderImpl_SetConstantF(vertex_shader, 0, (CONST FLOAT*) &This->UpdateStateBlock->vertexShaderConstant[0], 96);
} }
} }
@ -1361,7 +1379,8 @@ void drawPrimitive(LPDIRECT3DDEVICE8 iface,
/* Setup transform matrices and sort out */ /* Setup transform matrices and sort out */
isLightingOn = primitiveInitState(iface, isLightingOn = primitiveInitState(iface,
fvf & D3DFVF_XYZRHW, fvf & D3DFVF_XYZRHW,
!(fvf & D3DFVF_NORMAL)); !(fvf & D3DFVF_NORMAL),
useVertexShaderFunction);
/* Initialize all values to null */ /* Initialize all values to null */
if (useVertexShaderFunction == FALSE) { if (useVertexShaderFunction == FALSE) {
@ -1422,8 +1441,8 @@ void drawPrimitive(LPDIRECT3DDEVICE8 iface,
idxData, idxSize, minIndex, StartIdx); idxData, idxSize, minIndex, StartIdx);
} }
/* If no normals, restore previous lighting state */ /* If vertex shaders or no normals, restore previous lighting state */
if (!(fvf & D3DFVF_NORMAL)) { if (useVertexShaderFunction || !(fvf & D3DFVF_NORMAL)) {
if (isLightingOn) glEnable(GL_LIGHTING); if (isLightingOn) glEnable(GL_LIGHTING);
else glDisable(GL_LIGHTING); else glDisable(GL_LIGHTING);
TRACE("Restored lighting to original state\n"); TRACE("Restored lighting to original state\n");

View File

@ -245,7 +245,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZ; break; case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZ; break;
case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZRHW; break; case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZRHW; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
if (type >= MAX_VSHADER_DECL_TYPES) { if (type >= MAX_VSHADER_DECL_TYPES) {
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported and unrecognized type %08lx\n", type); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported and unrecognized type %08lx\n", type);
@ -262,7 +262,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZB3; break; case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZB3; break;
case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZB4; break; case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZB4; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -272,7 +272,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
switch (type) { switch (type) {
case D3DVSDT_UBYTE4: fvf |= D3DFVF_LASTBETA_UBYTE4; break; case D3DVSDT_UBYTE4: fvf |= D3DFVF_LASTBETA_UBYTE4; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -282,7 +282,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
switch (type) { switch (type) {
case D3DVSDT_FLOAT3: fvf |= D3DFVF_NORMAL; break; case D3DVSDT_FLOAT3: fvf |= D3DFVF_NORMAL; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -292,7 +292,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
switch (type) { switch (type) {
case D3DVSDT_FLOAT1: fvf |= D3DFVF_PSIZE; break; case D3DVSDT_FLOAT1: fvf |= D3DFVF_PSIZE; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -302,7 +302,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
switch (type) { switch (type) {
case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_DIFFUSE; break; case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_DIFFUSE; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -312,7 +312,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
switch (type) { switch (type) {
case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_SPECULAR; break; case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_SPECULAR; break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -336,7 +336,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
case D3DVSDT_FLOAT3: fvf |= D3DFVF_TEXCOORDSIZE3(texNo); break; case D3DVSDT_FLOAT3: fvf |= D3DFVF_TEXCOORDSIZE3(texNo); break;
case D3DVSDT_FLOAT4: fvf |= D3DFVF_TEXCOORDSIZE4(texNo); break; case D3DVSDT_FLOAT4: fvf |= D3DFVF_TEXCOORDSIZE4(texNo); break;
default: default:
/** errooooorr mismatched use of a register, invalid fvf computing */ /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
invalid_fvf = TRUE; invalid_fvf = TRUE;
TRACE("Mismatched use in VertexShader declaration of D3DVSDE_TEXCOORD? register: unsupported type %s\n", VertexShaderDeclDataTypes[type]); TRACE("Mismatched use in VertexShader declaration of D3DVSDE_TEXCOORD? register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
} }
@ -345,7 +345,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevic
case D3DVSDE_POSITION2: /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */ case D3DVSDE_POSITION2: /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */
case D3DVSDE_NORMAL2: /* FIXME i don't know what to do here ;( */ case D3DVSDE_NORMAL2: /* FIXME i don't know what to do here ;( */
TRACE("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg, token); FIXME("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg, token);
break; break;
} }
TRACE("VertexShader declaration define %lx as current FVF\n", fvf); TRACE("VertexShader declaration define %lx as current FVF\n", fvf);
@ -442,6 +442,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_FillVertexShaderInput(IDirect3DDevice8Impl* T
} else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 != (0x10000000 & tokentype)) { } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 != (0x10000000 & tokentype)) {
/** skip datas */ /** skip datas */
DWORD skipCount = ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT); DWORD skipCount = ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
TRACE(" skipping %ld dwords\n", skipCount);
curPos = curPos + skipCount * sizeof(DWORD); curPos = curPos + skipCount * sizeof(DWORD);
++pToken; ++pToken;
@ -450,6 +451,7 @@ HRESULT WINAPI IDirect3DDeviceImpl_FillVertexShaderInput(IDirect3DDevice8Impl* T
DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT); DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
++pToken; ++pToken;
TRACE(" type : %ld, reg = %ld\n", type, reg);
switch (type) { switch (type) {
case D3DVSDT_FLOAT1: case D3DVSDT_FLOAT1:
x = *(float*) curPos; x = *(float*) curPos;