📄 drawprim.c
字号:
ulBytesProcessed += sizeof(D3DM_SETLIGHT);
if(psLight == NULL)
continue;
/* Enable Light */
EnableLight(psContext,psLight);
/* Flag Lights changed */
psContext->sTState.sSWTNLState.dwTNLFlags |= PVRD3DTNL_FLAGS_LIGHTS_CHANGED;
break;
}
case D3DM_SETLIGHT_DISABLE:
{
ulBytesProcessed += sizeof(D3DM_SETLIGHT);
if(psLight == NULL)
continue;
/* Disable Light */
DisableLight(psContext,psLight);
/* Flag Lights changed */
psContext->sTState.sSWTNLState.dwTNLFlags |= PVRD3DTNL_FLAGS_LIGHTS_CHANGED;
break;
}
case D3DM_SETLIGHT_DATA_ENABLE:
{
LPD3DM_SETLIGHT_WITHDATA psOpWithData;
ulBytesProcessed += sizeof(D3DM_SETLIGHT_WITHDATA);
if(psLight == NULL)
continue;
psOpWithData = (LPD3DM_SETLIGHT_WITHDATA) psCurrentOp;
/* Set Data */
SetLightData(psLight, &psOpWithData->Data, psOpWithData->Format);
/* Enable Light */
EnableLight(psContext,psLight);
/* Flag Lights changed */
psContext->sTState.sSWTNLState.dwTNLFlags |= PVRD3DTNL_FLAGS_LIGHTS_CHANGED;
break;
}
case D3DM_SETLIGHT_DATA_DISABLE:
{
LPD3DM_SETLIGHT_WITHDATA psOpWithData;
ulBytesProcessed += sizeof(D3DM_SETLIGHT_WITHDATA);
if(psLight == NULL)
continue;
psOpWithData = (LPD3DM_SETLIGHT_WITHDATA) psCurrentOp;
/* Set Data */
SetLightData(psLight, &psOpWithData->Data, psOpWithData->Format);
/* Disable Light */
DisableLight(psContext,psLight);
/* Flag Lights changed */
psContext->sTState.sSWTNLState.dwTNLFlags |= PVRD3DTNL_FLAGS_LIGHTS_CHANGED;
break;
}
default:
{
D3DM_DPF((DPF_ERROR, "D3DM_DP_OP_SetLight:Invalid set light type"));
return ulBytesProcessed;
}
}
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_SetLight"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_TextureStageState
PURPOSE:
PARAMETERS: In: psContext - Context to operate on
In: pvCommandData - Pointer to command ops to execute
In: nCount - number of ops of this type to process
RETURNS: number of bytes processed
</function>
------------------------------------------------------------------------------*/
ULONG D3DM_DP_OP_TextureStageState(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_TEXTURESTAGESTATE psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_TEXTURESTAGESTATE) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_TextureStageState"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
DWORD dwState;
dwState = psCurrentOp->State;
ulBytesProcessed += sizeof(D3DM_TEXTURESTAGESTATE);
if(psCurrentOp->Stage >= sPVRD3DMCaps.MaxSimultaneousTextures)
{
D3DM_DPF((DPF_WARN, "D3DM_DP_OP_TextureStageState:Unsupported texture layer % u requested: Ignoring"));
continue;
}
if(psCurrentOp->State < D3DMTSS_MAXTEXTURESTATES)
{
PROFILE_START_TEXTURESTATE(dwState);
psContext->ppfnsTSStateFunctions[dwState](psContext, psCurrentOp);
PROFILE_STOP_TEXTURESTATE(dwState);
}
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_TextureStageState"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_CreatePalette
PURPOSE:
PARAMETERS: In: psContext - Context to operate on
In: pvCommandData - Pointer to command ops to execute
In: nCount - number of ops of this type to process
RETURNS: number of bytes processed
</function>
------------------------------------------------------------------------------*/
ULONG D3DM_DP_OP_CreatePalette(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_CREATEPALETTE psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_CREATEPALETTE) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_CreatePalette"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
ulBytesProcessed += sizeof(D3DM_CREATEPALETTE);
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_CreatePalette"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_SetPalette
PURPOSE:
PARAMETERS: In: psContext - Context to operate on
In: pvCommandData - Pointer to command ops to execute
In: nCount - number of ops of this type to process
RETURNS: number of bytes processed
</function>
------------------------------------------------------------------------------*/
ULONG D3DM_DP_OP_SetPalette(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_SETPALETTE psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_SETPALETTE) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_SetPalette"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
ulBytesProcessed += sizeof(D3DM_SETPALETTE);
if(psCurrentOp->DataType == D3DM_SETPALETTE_SETENTRIES)
{
/* Add size of Pallete entries */
ulBytesProcessed += (sizeof(PALETTEENTRY) * 256);
}
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_SetPalette"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_ProcessVertices
PURPOSE:
PARAMETERS: In: psContext - Context to operate on
In: pvCommandData - Pointer to command ops to execute
In: nCount - number of ops of this type to process
RETURNS: number of bytes processed
</function>
------------------------------------------------------------------------------*/
ULONG D3DM_DP_OP_ProcessVertices(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_PROCESSVERTICES psCurrentOp;
LPD3DM_VBUFFER psDestBuffer;
DWORD dwCurrentRotation = psContext->dwRotationAngle;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_PROCESSVERTICES) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_ProcessVertices"));
/* Signal process vertices mode */
psContext->dwFlags |= D3DM_CONTEXT_SWFLAGS_PROCVERT_MODE;
/* Force zero degrees for Process vertices */
if(psContext->dwRotationAngle != 0)
{
psContext->dwRotationAngle = 0;
SetupViewportTransform(psContext);
}
for(i=0; i <nCount; i++, psCurrentOp++)
{
DWORD j;
/* Process current operation */
ulBytesProcessed += sizeof(D3DM_PROCESSVERTICES);
/* Validate Format of destination buffer */
psDestBuffer = (LPD3DM_VBUFFER) psCurrentOp->DestBufferId;
if(psDestBuffer == IMG_NULL)
{
goto SkipValidation;
}
/* Clear process vertices flags */
psContext->dwFlags &= ~(D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_DIFFUSE_COPY |
D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_SPECULAR_COPY |
D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_TEX_COPY_MASK);
/*
Validate dest buffer position flags: -
a) Must Have RHW value (float or fixed)
b) Must not have a normal component(neither float nor fixed)
*/
if(((psDestBuffer->dwFVFFlags & D3DMFVF_POSITION_MASK) != D3DMFVF_XYZRHW_FLOAT &&
(psDestBuffer->dwFVFFlags & D3DMFVF_POSITION_MASK) != D3DMFVF_XYZRHW_FIXED) ||
((psDestBuffer->dwFVFFlags & D3DMFVF_NORMAL_MASK) == D3DMFVF_NORMAL_FLOAT ||
(psDestBuffer->dwFVFFlags & D3DMFVF_NORMAL_MASK) == D3DMFVF_NORMAL_FIXED))
{
/* Invalid destination buffer FVF code */
psContext->hrLastError = D3DMERR_INVALIDCALL;
continue;
}
/*
Validate dest buffer diffuse FVF Lighting Flags.
Must contain a Diffuse component if any of the following is true: -
a) Lighting is enabled (D3DMRS_LIGHTING set to TRUE).
b) The current stream source vertex buffer FVF contains a diffuse color
field (D3DMFVF_DIFFUSE) and the dwFlags parameter of ProcessVertices
does not have the D3DMPV_DONOTCOPYDATA bit set.
*/
if(psContext->sTState.dwRSFlags & TSTATE_RSFLAGS_LIGHTING ||
((psContext->psVertexSource->dwFVFFlags & D3DMFVF_DIFFUSE) &&
!(psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA)))
{
if(!(psDestBuffer->dwFVFFlags & D3DMFVF_DIFFUSE))
{
/* Invalid destination buffer FVF code */
psContext->hrLastError = D3DMERR_INVALIDCALL;
continue;
}
}
else if((psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA) &&
!(psContext->sTState.dwRSFlags & TSTATE_RSFLAGS_LIGHTING))
{
/* Diffuse value will not change so don't copy it */
psContext->dwFlags |= D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_DIFFUSE_COPY;
}
/*
Validate specular FVF lighting Flags.
Must contain a Specular component if any of the following is true: -
a) Lighting is enabled and specular is also enabled (D3DMFVF_LIGHTING and
D3DMFVF_SPECULAR are both set to TRUE).
b) Vertex fog is enabled (D3DMRS_FOGVERTEXMODE is set to a render state
other than D3DMFOG_NONE).
c) The current stream source vertex buffer FVF contains a specular color
field (D3DMFVF_SPECULAR) and the dwFlags parameter of ProcessVertices
does not have the D3DMPV_DONOTCOPYDATA bit set.
*/
if((psContext->sTState.dwRSFlags & (TSTATE_RSFLAGS_LIGHTING | TSTATE_RSFLAGS_SPECULAR)) ||
(psContext->sTState.dwD3DVertexFogMode != D3DMFOG_NONE) ||
((psContext->psVertexSource->dwFVFFlags & D3DMFVF_SPECULAR) &&
!(psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA)))
{
if(!(psDestBuffer->dwFVFFlags & D3DMFVF_SPECULAR))
{
/* Invalid destination buffer FVF code */
psContext->hrLastError = D3DMERR_INVALIDCALL;
continue;
}
}
else if((psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA) &&
!(psContext->sTState.dwRSFlags & (TSTATE_RSFLAGS_LIGHTING | TSTATE_RSFLAGS_SPECULAR)))
{
/* Specular value will not change so don't copy it */
psContext->dwFlags |= D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_SPECULAR_COPY;
}
/*
Validate texture options per stage. Texture stages are inactive if:-
a) The COLOROP of the texture stage is set to D3DMTOP_DISABLE.
b) The color argument (D3DMTSS_COLORARG1) is set to D3DMTA_TEXTURE
and there is currently no texture bound to the texture stage.
When ProcessVertices writes texture coordinates to the destination
vertex buffer and none of the active texture stages specify texture
coordinate generation or texture transformation, the following rules apply:
a) If dwFlags is not set to D3DMPV_DONOTCOPYDATA, then the number of
texture coordinates and their dimensionality must match those of
the source vertex buffer.
b) If dwFlags is set to D3DMPV_DONOTCOPYDATA, then the number of texture
coordinates and their dimensionality in the destination vertex buffer
are ignored.
*/
for(j=0; j<sPVRD3DMCaps.MaxSimultaneousTextures; j++)
{
PLAYER_TSTATE psLState;
psLState = &psContext->sTState.sLState[j];
if(psLState->dwCOp != D3DMTOP_DISABLE ||
!(psLState->dwCArg1 == D3DMTA_TEXTURE && psLState->psSurfData == NULL))
{
/* Stage is active */
if(psLState->dwCoordAutoGenMode == D3DMTSS_TCI_PASSTHRU ||
(psLState->dwD3DTexTransFlags & ~D3DMTTFF_PROJECTED) == D3DMTTFF_DISABLE)
{
/* Texgen and tex transform are disabled for this stage */
if(!(psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA) &&
(GetTexCoordinateCount(psDestBuffer->dwFVFFlags, j) !=
GetTexCoordinateCount(psContext->psVertexSource->dwFVFFlags, j)))
{
/* Invalid destination buffer FVF code */
psContext->hrLastError = D3DMERR_INVALIDCALL;
continue;
}
else if(psCurrentOp->Flags & D3DMPV_DONOTCOPYDATA)
{
/* Texture co-oords wont be altered so dont copy this set */
psContext->dwFlags |= (0x00000001 << (D3DM_CONTEXT_SWFLAGS_PROCVERT_NO_TEX_COPY_SHIFT + i));
}
}
}
}
SkipValidation:
/* Ensure TextureState is correct */
PostProcessTSState(psContext);
/* Update Matrices */
UpdateMatrices(psContext);
/* Update Lights */
UpdateLights(psContext);
/* Process Vertices */
ProcessVertices( psContext,
psDestBuffer,
psCurrentOp->SrcStartIndex,
psCurrentOp->DestIndex,
psCurrentOp->VertexCount,
psCurrentOp->Flags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -