📄 drawprim.c
字号:
LPD3DM_RENDERTARGET psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_RENDERTARGET) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_RenderTarget"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
SetRenderTarget(psContext,
(LPD3DM_SURFACE)psCurrentOp->RenderTarget,
(LPD3DM_SURFACE)psCurrentOp->ZBuffer,
IMG_FALSE);
ulBytesProcessed += sizeof(D3DM_RENDERTARGET);
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_RenderTarget"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_RenderState
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_RenderState(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_RENDERSTATE psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_RENDERSTATE) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_RenderState"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
if(psCurrentOp->RenderState < D3DM_MAXRENDERSTATES)
{
PROFILE_START_RENDERSTATE(psCurrentOp->RenderState);
psContext->eLastRenderStateChange = psCurrentOp->RenderState;
psContext->ppfnsRStateFunctions[psCurrentOp->RenderState](psContext, psCurrentOp->Value);
PROFILE_STOP_RENDERSTATE(psCurrentOp->RenderState);
}
ulBytesProcessed += sizeof(D3DM_RENDERSTATE);
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_RenderState"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_Transform
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_Transform(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_TRANSFORM psCurrentOp;
PSWTNLSTATE psSWTNLState;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_TRANSFORM) pvCommandData;
psSWTNLState = &psContext->sTState.sSWTNLState;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_Transform"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current set transform */
switch(psCurrentOp->TransformType)
{
case D3DMTS_WORLD:
{
/* Save the new matrix, and flag that it has changed */
PVR44ConvertD3DMatrix(&psCurrentOp->Matrix, &psSWTNLState->sWorldMatrix, IS_FIXED(psCurrentOp->Format));
psSWTNLState->dwTNLFlags |= PVRD3DTNL_FLAGS_WORLD_CHANGED;
break;
}
case D3DMTS_VIEW:
{
/* Save the new matrix, and flag that it has changed */
PVR44ConvertD3DMatrix(&psCurrentOp->Matrix, &psSWTNLState->sViewMatrix, IS_FIXED(psCurrentOp->Format));
psSWTNLState->dwTNLFlags |= PVRD3DTNL_FLAGS_VIEW_CHANGED;
break;
}
case D3DMTS_PROJECTION:
{
NTV_TYPE ntv34, ntv43, ntv33, ntv44;
/* Save the new matrix, and flag that it has changed */
PVR44ConvertD3DMatrix(&psCurrentOp->Matrix, &psSWTNLState->sProjMatrix, IS_FIXED(psCurrentOp->Format));
psSWTNLState->dwTNLFlags |= PVRD3DTNL_FLAGS_PROJECTION_CHANGED;
ntv33 = psSWTNLState->sProjMatrix._33;
ntv34 = psSWTNLState->sProjMatrix._34;
ntv43 = psSWTNLState->sProjMatrix._43;
ntv44 = psSWTNLState->sProjMatrix._44;
if((ntv33 == ntv34) || (ntv33 == 0))
{
float fTmp = 1e-5f;
D3DM_DPF((DPF_WARN, "D3DM_DP_OP_Transform: Cannot compute WNear and WFar new projection matrix"));
psContext->sTState.WNear = FL2NTV(fTmp);
psContext->sTState.WFar = D3DM_One;
}
else
{
/*
Store Near & Far W depths -
used for depth clears in D3D W-Buffering mode
*/
psContext->sTState.WNear = Mul((Sub(ntv44,ntv34)), Div(ntv43, ntv33));
psContext->sTState.WFar = Mul((Add(ntv44,ntv34)), Div((Sub(ntv44,ntv43)),(Sub(ntv33,ntv34))));
/* Update the viewport transform */
SetupViewportTransform(psContext);
}
break;
}
case D3DMTS_TEXTURE0:
case D3DMTS_TEXTURE1:
{
DWORD dwMatrixNum;
/* Save the new matrix, and flag that it has changed */
dwMatrixNum = (DWORD)psCurrentOp->TransformType - (DWORD) D3DMTS_TEXTURE0;
PVR44ConvertD3DMatrix(&psCurrentOp->Matrix, &psSWTNLState->sTexMatrix[dwMatrixNum], IS_FIXED(psCurrentOp->Format));
psSWTNLState->dwTNLFlags2 |= PVRD3DTNL_FLAGS2_TEXGEN_MATRIX0_CHANGED << dwMatrixNum;
break;
}
case D3DMTS_TEXTURE2:
case D3DMTS_TEXTURE3:
{
/* Unsupported */
break;
}
default:
{
D3DM_DPF((DPF_ERROR, "D3DM_DP_OP_Transform:Invalid transform type"));
}
}
ulBytesProcessed += sizeof(D3DM_TRANSFORM);
}
/* Mark all enabled lights as requiring transformation if World or view matrices have changed */
if(psSWTNLState->dwTNLFlags & PVRD3DTNL_FLAGS_WORLD_CHANGED ||
psSWTNLState->dwTNLFlags & PVRD3DTNL_FLAGS_VIEW_CHANGED)
{
PLIGHTDATA *ppsEnabledLight;
ppsEnabledLight = psSWTNLState->ppsEnabledLights;
while(*ppsEnabledLight)
{
/* mark every enabled light as needing transformation */
(*ppsEnabledLight)->dwFlags |= LIGHTDATA_FLAGS_NEED_XFORM;
/* advance to next light */
ppsEnabledLight++;
}
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_Transform"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_ViewPort
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_ViewPort(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_VIEWPORT psCurrentOp;
PTRANSIENT_STATE psTState;
D3DMRECT sViewPortRect;
psTState = &psContext->sTState;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_VIEWPORT) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_ViewPort"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current Viewport */
ulBytesProcessed += sizeof(D3DM_VIEWPORT);
/* Create Rect */
VLSetRect(&sViewPortRect,
psCurrentOp->Viewport.X,
psCurrentOp->Viewport.Y,
psCurrentOp->Viewport.X + psCurrentOp->Viewport.Width,
psCurrentOp->Viewport.Y + psCurrentOp->Viewport.Height);
/*
Don't bother setting up a viewport if zero height or width,
or if there is no change in viewport size
*/
if((psCurrentOp->Viewport.Width && psCurrentOp->Viewport.Height) &&
((psTState->sViewPortRect.x1 ^ sViewPortRect.x1) ||
(psTState->sViewPortRect.y1 ^ sViewPortRect.y1) ||
(psTState->sViewPortRect.x2 ^ sViewPortRect.x2) ||
(psTState->sViewPortRect.y2 ^ sViewPortRect.y2)))
{
/* Copy new one over */
psTState->sViewPortRect = sViewPortRect;
/*
The FF-TNL point size calculation uses the viewport height, so
flag that it needs to be updated
*/
psTState->sSWTNLState.dwTNLFlags2 |= PVRD3DTNL_FLAGS2_POINTSIZECHANGED;
/*
If a scene has already been started, set the new viewport
now. Otherwise it will be setup at start-of-scene
(by DoBeginScene)
*/
if(psContext->psCurrentRenderTarget->dwFlags & D3DM_SURFACE_FLAGS_SCENE_STARTED)
{
/* Acquire TA and Slave port */
if(D3DMAcquireTAResources(psContext, TRUE) != PVRSRV_OK)
{
/* Scene is invalid so dont send anything */
goto Skip_Send;
}
SetViewPort(psContext, &psContext->sTState.sViewPortRect);
D3DMReleaseTAResources(psContext, FALSE);
}
Skip_Send:
/* Set Z distances */
psTState->ZMin = FL2NTV(psCurrentOp->Viewport.MinZ);
psTState->ZMax = FL2NTV(psCurrentOp->Viewport.MaxZ);
}
}
/* Update the viewport transform */
SetupViewportTransform(psContext);
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_ViewPort"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_Material
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_Material(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_MATERIAL psCurrentOp;
PSWTNLSTATE psSWTNLState;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_MATERIAL) pvCommandData;
psSWTNLState = &psContext->sTState.sSWTNLState;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_Material"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current operation */
ulBytesProcessed += sizeof(D3DM_MATERIAL);
/* Copy/Convert the new D3D material*/
PVRCopyConvertD3DMaterial(&psCurrentOp->Material,
&psSWTNLState->sMaterial,
(psCurrentOp->Format == D3DMFMT_D3DMVALUE_FIXED));
/* Flag that the material has changed */
psSWTNLState->dwTNLFlags |= PVRD3DTNL_FLAGS_MATERIAL_CHANGED;
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_Material"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_CreateLight
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_CreateLight(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_CREATELIGHT psCurrentOp;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_CREATELIGHT) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_CreateLight"));
for(i=0; i <nCount; i++, psCurrentOp++)
{
/* Process current CreateLight */
CreateLight(psContext, psCurrentOp->Index);
ulBytesProcessed += sizeof(D3DM_CREATELIGHT);
}
D3DM_DPF((DPF_EXIT, "<-D3DM_DP_OP_CreateLight"));
return ulBytesProcessed;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: D3DM_DP_OP_SetLight
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_SetLight(LPD3DM_CONTEXT psContext, LPVOID pvCommandData, WORD nCount)
{
WORD i;
ULONG ulBytesProcessed;
LPD3DM_SETLIGHT psCurrentOp;
PLIGHTDATA psLight;
ulBytesProcessed = 0;
psCurrentOp = (LPD3DM_SETLIGHT) pvCommandData;
D3DM_DPF((DPF_ENTRY, "->D3DM_DP_OP_SetLight"));
for(i=0; i <nCount; i++)
{
/* Process current setlight */
psCurrentOp = (LPD3DM_SETLIGHT)(((DWORD)pvCommandData) + ulBytesProcessed);
/* Get requested light */
psLight = GetLight(psContext, psCurrentOp->Index);
/* check set light type */
switch(psCurrentOp->DataType)
{
case D3DM_SETLIGHT_ENABLE:
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -