📄 vgplite.c
字号:
dwSectionsToEnable |= 1 << VGPTNL_SECTIONORD_COLOURPASSTHRU;
/*
Setup the section execution range to only output the
colour components that are present
*/
if (dwColoursPresent & PVRD3DTNL_FLAGS_DIFFUSE_PRESENT)
{
dwSectionStart = 0;
}
else
{
dwSectionStart = 1;
}
if (dwColoursPresent & PVRD3DTNL_FLAGS_SPECULAR_PRESENT)
{
dwSectionEnd = 1;
}
else
{
dwSectionEnd = 0;
}
SetSectionExeRange(VGPTNL_SECTIONORD_COLOURPASSTHRU,
dwSectionStart,
dwSectionEnd,
psContext);
}
}
/*
Texture coordinate transform/generation active?
*/
if(dwTNLFlags2 & PVRD3DTNL_FLAGS2_TEXGEN_ACTIVE)
{
DWORD dwSectionSize;
/* Reconfigure the texture-coordinate generation section if required */
if(dwTNLFlags2 & PVRD3DTNL_FLAGS2_TEXGEN_CHANGED)
{
DWORD dwTexGenBaseInstruction;
HWVGPINST *pInstBuffer;
DWORD i;
pInstBuffer = (HWVGPINST*) &psContext->sHWState.sVGPCode;
/* Generate new section */
VGPTNLGenerateTextureCoordSection(psContext,
&dwSectionSize,
psTextureCoordinateGenerationSection);
/* Get first instruction address */
dwTexGenBaseInstruction = psContext->ppsFFTNLSections[VGPTNL_SECTIONORD_TEXCOORDGENERATION]->sConfig.sLoadRange.dwFirst;
/* Write new instructions to state buffer */
for(i=0; i < dwSectionSize; i++)
{
pInstBuffer[dwTexGenBaseInstruction + i] = psTextureCoordinateGenerationSection[i];
}
/* Flag modified instructions */
FlagArraySetFlagRange((PFLAGARRAY)&psContext->sHWStateCtl.sVGPInstsChanged, dwTexGenBaseInstruction, dwTexGenBaseInstruction + dwSectionSize - 1);
/* Set the executable range */
SetSectionExeRange(VGPTNL_SECTIONORD_TEXCOORDGENERATION,
0,
dwSectionSize - 1,
psContext);
/* Clear Flag */
dwTNLFlags2 &= ~PVRD3DTNL_FLAGS2_TEXGEN_CHANGED;
}
/* Enable the texture-coordinate generation section */
dwSectionsToEnable |= 1 << VGPTNL_SECTIONORD_TEXCOORDGENERATION;
}
else
{
/*
Texture coordinate generatioon inactive. Enable and configure
the texture coordinate passthrough section as appropriate.
*/
dwTcCount = (dwTNLFlags & PVRD3DTNL_FLAGS_TC_COUNT_MASK) >>
PVRD3DTNL_FLAGS_TC_COUNT_SHIFT;
if(dwTcCount > 0)
{
dwSectionsToEnable |= 1 << VGPTNL_SECTIONORD_TEXCOORDPASSTHRU;
SetSectionExeRange(VGPTNL_SECTIONORD_TEXCOORDPASSTHRU,
0,
dwTcCount - 1,
psContext);
}
}
/* Fog enabled? */
if(dwRSFlags & TSTATE_RSFLAGS_FOG)
{
DWORD dwSectionSize;
if(dwTNLFlags & PVRD3DTNL_FLAGS_FOG_CHANGED)
{
DWORD dwFogBaseInstruction;
HWVGPINST *pInstBuffer;
DWORD i;
pInstBuffer = (HWVGPINST*) &psContext->sHWState.sVGPCode;
VGPTNLGenerateFogSection(psContext, &dwSectionSize, psFogSection);
/* Get first instruction address */
dwFogBaseInstruction = psContext->ppsFFTNLSections[VGPTNL_SECTIONORD_FOG]->sConfig.sLoadRange.dwFirst;
/* Write new instructions to state buffer */
for(i=0; i < dwSectionSize; i++)
{
pInstBuffer[dwFogBaseInstruction + i] = psFogSection[i];
}
/* Flag modified instructions */
FlagArraySetFlagRange((PFLAGARRAY)&psContext->sHWStateCtl.sVGPInstsChanged, dwFogBaseInstruction, dwFogBaseInstruction + dwSectionSize - 1);
/* Set the executable range */
SetSectionExeRange(VGPTNL_SECTIONORD_FOG,
0,
dwSectionSize - 1,
psContext);
/* Clear Flag */
dwTNLFlags &= ~PVRD3DTNL_FLAGS_FOG_CHANGED;
}
/* Enable the fog section */
dwSectionsToEnable |= 1 << VGPTNL_SECTIONORD_FOG;
}
/* Set the required sections */
EnableSections(dwSectionsToEnable, psContext);
/* Clear passthrough flag */
dwSectionModFlags &= ~PVRD3DTNL_FLAGS_PASSTHROUGH_LOADED;
psSWTNLState->dwSectionModFlags = dwSectionModFlags;
psSWTNLState->dwTNLFlags = dwTNLFlags;
psSWTNLState->dwTNLFlags2 = dwTNLFlags2;
psTState->dwRSFlags = dwRSFlags;
}
/*****************************************************************************
FUNCTION : VGPTNLUpdateConstants
PURPOSE : Updates the VGP constants to reflect any state or TNL changes
PARAMETERS : psContext - The current SW context
RETURNS : void
****************************************************************************/
void VGPTNLUpdateConstants(LPD3DM_CONTEXT psContext)
{
PTRANSIENT_STATE psTState;
PSWTNLSTATE psSWTNLState;
DWORD dwTNLFlags;
DWORD dwTNLFlags2;
DWORD dwRSFlags;
DWORD dwConstantFlags;
DWORD i;
psTState = &psContext->sTState;
psSWTNLState = &psTState->sSWTNLState;
dwTNLFlags = psSWTNLState->dwTNLFlags;
dwTNLFlags2 = psSWTNLState->dwTNLFlags2;
dwRSFlags = psTState->dwRSFlags;
dwConstantFlags = psSWTNLState->dwConstantFlags;
if (dwConstantFlags & VGPTNL_CONST_WVT_CHANGED)
{
VGPTNLSetConstants(psContext,
CONST_MODELTOVIEW_ROW0,
4,
psSWTNLState->sWorldViewT.m[0]);
}
if (dwConstantFlags & VGPTNL_CONST_WVPT_CHANGED)
{
VGPTNLSetConstants(psContext,
CONST_MODELTOPROJ_ROW0,
4,
psSWTNLState->sWorldViewProjT.m[0]);
}
if (dwConstantFlags & VGPTNL_CONST_WVIT_CHANGED)
{
VGPTNLSetConstants(psContext,
CONST_MODELTOVIEWINV_ROW0,
4,
psSWTNLState->sWorldViewInvT.m[0]);
}
if (dwTNLFlags & PVRD3DTNL_FLAGS_MATERIAL_CHANGED)
{
PVR_MATERIAL* psMaterial;
psMaterial = &psSWTNLState->sMaterial;
VGPTNLOutputColour(psContext,
CONST_MATERIAL_AMBIENT_COLOUR,
&psMaterial->Ambient);
VGPTNLOutputColour(psContext,
CONST_MATERIAL_DIFFUSE_COLOUR,
&psMaterial->Diffuse);
VGPTNLOutputColour(psContext,
CONST_MATERIAL_SPECULAR_COLOUR,
&psMaterial->Specular);
VGPTNLSetConstant1(psContext,
CONST_MATERIAL_POWER,
psMaterial->Power);
VGPTNLSetConstant1(psContext,
CONST_SPECULAR_THRESHOLD,
psSWTNLState->SpecularThreshold);
}
if(dwTNLFlags & PVRD3DTNL_FLAGS_COLOURVTX_CHANGED)
{
VGPTNLOutputColour(psContext,
CONST_GLOBAL_AMBIENT_COLOUR,
&psSWTNLState->sAmbientColour);
}
if(dwTNLFlags2 & PVRD3DTNL_FLAGS2_TEXGEN_MATRIX_CHANGED)
{
for (i = 0; i < MBX1_MAXTEXTURE_LAYERS; i++)
{
if(dwTNLFlags2 & (PVRD3DTNL_FLAGS2_TEXGEN_MATRIX0_CHANGED << i))
{
PVR_44_MATRIX sTemp;
TransposeMatrix(&psSWTNLState->sTexMatrix[i], &sTemp);
VGPTNLSetConstants(psContext,
VGPTNL_CONSTANTS_TEXMAT_BASE + (i * 4),
4,
sTemp.m[0]);
dwTNLFlags2 &= ~(PVRD3DTNL_FLAGS2_TEXGEN_MATRIX0_CHANGED << i);
}
}
}
if(dwConstantFlags & VGPTNL_CONST_LIGHTS_CHANGED)
{
for(i = 0; i < VGPTNL_MAXIMUM_LIGHTS; i++)
{
PLIGHTDATA psLightData;
psLightData = psSWTNLState->ppsEnabledLights[i];
if(psLightData)
{
if(psLightData->dwFlags & LIGHTDATA_FLAGS_DATA_CHANGED)
{
PVR_LIGHT* psLightInfo;
DWORD dwConstBase;
psLightInfo = &psLightData->sLightInfo;
dwConstBase = VGPTNL_CONSTANTS_LIGHT_BASE +
(i * VGPTNL_CONSTANTS_PER_LIGHT);
psLightData->dwFlags &= ~LIGHTDATA_FLAGS_DATA_CHANGED;
/* Generic Light processing setup */
VGPTNLSetConstant(psContext,
dwConstBase + CONST_PSLIGHT_POS,
(NTV_TYPE*) &psLightInfo->EyePosition);
if(psLightInfo->Type == D3DMLIGHT_POINT)
{
VGPTNLSetConstant2(psContext,
dwConstBase + CONST_PSLIGHT_PARAMS,
psLightData->RangeSquared,
psLightInfo->Attenuation0,
psLightInfo->Attenuation1,
psLightInfo->Attenuation2);
VGPTNLSetConstant2(psContext,
dwConstBase + CONST_PSLIGHT_TYPESPECIFIC,
D3DM_One,
D3DM_Zero,
D3DM_Zero,
D3DM_Zero);
}
else
{
VGPTNLSetConstant2(psContext,
dwConstBase + CONST_PSLIGHT_PARAMS,
FL2NTV(10000.0f),
D3DM_One,
D3DM_One,
D3DM_One);
VGPTNLSetConstant2(psContext,
dwConstBase + CONST_PSLIGHT_TYPESPECIFIC,
D3DM_Zero,
D3DM_One,
D3DM_Zero,
D3DM_Zero);
}
VGPTNLOutputColour(psContext,
dwConstBase + CONST_PSLIGHT_AMBIENT,
&psLightInfo->Ambient);
VGPTNLOutputColour(psContext,
dwConstBase + CONST_PSLIGHT_DIFFUSE,
&psLightInfo->Diffuse);
VGPTNLOutputColour(psContext,
dwConstBase + CONST_PSLIGHT_SPECULAR,
&psLightInfo->Specular);
VGPTNLSetConstant(psContext,
dwConstBase + CONST_PSLIGHT_DIRECTION,
(NTV_TYPE*) &psLightInfo->EyeDirection);
}
}
}
}
if(dwTNLFlags & PVRD3DTNL_FLAGS_FOG_PARAMS_CHANGED)
{
if(dwRSFlags & TSTATE_RSFLAGS_FOG)
{
VGPTNLSetConstant2(psContext,
CONST_FOG_PARAMS,
psContext->sTState.D3DFogDensity,
D3DM_E,
psContext->sTState.D3DFogEnd,
psContext->sTState.OneOverEndMinusStart);
dwTNLFlags &= ~PVRD3DTNL_FLAGS_FOG_PARAMS_CHANGED;
}
}
if(dwTNLFlags & PVRD3DTNL_FLAGS_ZBIAS_PARAMS_CHANGED)
{
if(dwRSFlags & TSTATE_RSFLAGS_DEPTHBIAS)
{
VGPTNLSetConstant2(psContext,
CONST_ZBIAS_PARAMS,
psContext->sHWState.sTACtl3DState.sVPTrans.ZScale,
psContext->sHWState.sTACtl3DState.sVPTrans.ZOffset,
psContext->sTState.D3DZBias,
D3DM_Zero);
dwTNLFlags &= ~PVRD3DTNL_FLAGS_ZBIAS_PARAMS_CHANGED;
}
}
#if (COREVERSION >= 120)
/* Process vertices mode, so we need to send the viewport */
if(psContext->dwFlags & D3DM_CONTEXT_SWFLAGS_PROCVERT_MODE)
{
VGPTNLSetConstant2(psContext,
CONST_VPORT_SCALE,
psContext->sHWState.sTACtl3DState.sVPTrans.XScale,
psContext->sHWState.sTACtl3DState.sVPTrans.YScale,
psContext->sHWState.sTACtl3DState.sVPTrans.ZScale,
D3DM_Zero);
VGPTNLSetConstant2(psContext,
CONST_VPORT_OFFSET,
psContext->sHWState.sTACtl3DState.sVPTrans.XOffset,
psContext->sHWState.sTACtl3DState.sVPTrans.YOffset,
psContext->sHWState.sTACtl3DState.sVPTrans.ZOffset,
D3DM_Zero);
}
#endif
if(dwConstantFlags & VGPTNL_CONST_STATIC_CONSTANTS)
{
VGPTNLSetConstant1(psContext, CONST_ZERO, D3DM_Zero);
VGPTNLSetConstant1(psContext, CONST_ONE, D3DM_One);
VGPTNLSetConstant1(psContext, CONST_HALF, D3DM_Half);
VGPTNLSetConstant1(psContext,
CONST_LIGHT_SIZE,
VGPTNL_CONSTANTS_PER_LIGHT);
VGPTNLSetConstant2(psContext,
CONST_LOCAL_VIEWER_DEFAULT,
0.0f, 0.0f, -1.0f, 0.0f);
VGPTNLSetConstant1(psContext,
CONST_LIGHTING_ADDRESS_BASE,
VGPTNL_CONSTANTS_LIGHT_BASE);
VGPTNLSetConstant1(psContext,
CONST_TEXMAT_BASE,
VGPTNL_CONSTANTS_TEXMAT_BASE);
VGPTNLSetConstant2(psContext,
CONST_DEFAULT_DIFFUSE,
1.0f, 1.0f, 1.0f, 1.0f);
VGPTNLSetConstant2(psContext,
CONST_DEFAULT_SPECULAR,
0.0f, 0.0f, 0.0f, 1.0f);
VGPTNLSetConstant2(psContext,
CONST_CLIPPLANEFRONT,
0.0f, 0.0f, 1.0f, /*0.0f*/-1.0e-2f);
VGPTNLSetConstant2(psContext,
CONST_CLIPPLANEREAR,
0.0f, 0.0f, -1.0f, 1.0f);
}
/*
Reset all the constant-flags, indicating that all constants are
up-to-date
*/
psSWTNLState->dwConstantFlags = 0;
psSWTNLState->dwTNLFlags = dwTNLFlags;
psSWTNLState->dwTNLFlags2 = dwTNLFlags2;
psTState->dwRSFlags = dwRSFlags;
}
#endif /* #if defined(SUPPORT_VGP) */
/*****************************************************************************
End of file (VGP.C)
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -