📄 vgp.c
字号:
/***********************************************************************************
Function Name : SetupVGPSectionEnables
Inputs : gc, bPassThrough, bTextured
Outputs : ui32VGPClipControlWord
Returns : -
Description : Sets up VGP section enables based on GL state.
************************************************************************************/
IMG_VOID SetupVGPSectionEnables(GLESContext *gc, IMG_BOOL bPassThrough, IMG_BOOL bTextured)
{
IMG_UINT32 ui32Loop;
IMG_UINT32 ui32Count = 0;
IMG_UINT32 ui32VGPSectionEnables, ui32VGPStartSection, ui32VGPClipControlWord;
IMG_UINT32 ui32MVChangeMask = 0;
ui32VGPClipControlWord = MBX1_VGPCLIPCTL_REARCLIPPLANE_ENABLE |
#if !defined(FIX_HW_PRN_306)
MBX1_VGPCLIPCTL_WCLAMP_ENABLE |
#endif
MBX1_VGPCLIPCTL_FRONTCLIPPLANE_ENABLE;
/* Zero, just in case... */
ui32VGPSectionEnables = 0;
ui32VGPStartSection = 0;
#if !defined(PASSTHROUGH_BUILD)
if(!bPassThrough)
{
/* TNL VGP Program */
ui32VGPClipControlWord |= MBX1_VGPCLIPCTL_VIEWPORTTRANS_ENABLE;
if(!gc->bLastProgramLoadedFF)
{
GLESVertexProgram *psProgram = gc->sVertexProgram.psCurrentProgram;
ui32VGPSectionEnables |= VGP_SECTION(psProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_USERCODE]);
/* Assume if foglin section is present, all fog sections are present */
if(psProgram->sInfo.ui32Flags & (VGPFLAGS_SECTIONTYPE_FOGLINEAR << VGPFLAGS_SECTIONTYPE_SHIFT))
{
if(gc->ui32RasterEnables & GLES_RS_FOG_ENABLE)
{
switch(gc->sState.sFog.eMode)
{
case GL_LINEAR:
ui32VGPSectionEnables |=
VGP_SECTION(psProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_FOGLINEAR]);
break;
case GL_EXP:
ui32VGPSectionEnables |=
VGP_SECTION(psProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_FOGEXP]);
break;
case GL_EXP2:
ui32VGPSectionEnables |=
VGP_SECTION(psProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_FOGEXP2]);
break;
}
}
}
/*
* If the redirect section is present we know there were writes to both texcoord layer 0 and layer 1 in the
* user program. If texture state means that layer 0 is not enabled, but layer 1 is enabled,
* then we must use the redirect code in this extra section.
*/
if(psProgram->sInfo.ui32Flags & (VGPFLAGS_SECTIONTYPE_TEXLAYER1REDIRECT << VGPFLAGS_SECTIONTYPE_SHIFT))
{
if((gc->ui32RasterEnables & (GLES_RS_TEXTURE0_ENABLE|GLES_RS_TEXTURE1_ENABLE)) == GLES_RS_TEXTURE1_ENABLE)
{
ui32VGPSectionEnables |=
VGP_SECTION(psProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_TEXLAYER1REDIRECT]);
}
}
}
else
{
/* If these sections have changed, may need to recalculate MV matrix */
ui32MVChangeMask = VGP_SECTION(VGP_SECTION_EYE_POS) | VGP_SECTION(VGP_SECTION_LIGHTING_INIT);
/* Transform position */
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_TRANSFORM);
/* If fog is enabled, be sure to calculate eye Z and copy to the fog coord output register */
if(gc->ui32RasterEnables & GLES_RS_FOG_ENABLE)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
if(gc->sState.sFog.eMode == GL_LINEAR)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_LINEAR_FOG);
}
else
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EXPEXP2_FOG);
}
}
if(gc->ui32TnLEnables & GLES_TL_LIGHTING_ENABLE)
{
if(gc->ui32TnLEnables & (GLES_TL_NORMALIZE_ENABLE | GLES_TL_RESCALE_ENABLE))
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_NORMALISE_NORMAL);
}
/* Do lighting and output the lighting colours */
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_LIGHTING_INIT);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_LIGHTING_OUTPUT);
#if defined(OPENGLES1_1)
if(gc->ui32TnLEnables & GLES_TL_LIGHTS_ENABLE)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_GENERIC_LIGHTING);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
}
#else
if(gc->sLight.aui32NumEnabled[GLES_LIGHT_TYPE_INFINITE])
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_INFINITE_LIGHTING);
}
if(gc->sLight.aui32NumEnabled[GLES_LIGHT_TYPE_POINT])
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_POINT_LIGHTING);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
}
if(gc->sLight.aui32NumEnabled[GLES_LIGHT_TYPE_SPOT])
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_SPOT_LIGHTING);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
}
#endif
}
for(ui32Loop=0; ui32Loop<GLES_MAX_TEXTURE_UNITS; ui32Loop++)
{
if(gc->sTexture.abTexUnitValid[ui32Loop])
{
if(gc->sTransform.apsTexture[ui32Loop]->sMatrix.eMatrixType == GLES_MT_IDENTITY)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_COPY_TEXTURE0 + ui32Count);
}
else
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_TEXMATRIX0 + ui32Count);
}
ui32Count++;
}
}
#if defined(SUPPORT_VGP)
if(gc->ui32TnLEnables & GLES_TL_CLIP_PLANES_ENABLE )
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_USER_CLIPPLANES);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
}
#endif
#if defined(OPENGLES1_1)
if(gc->bPointPrim && gc->sState.sPoint.bAttenuationEnabled)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_EYE_POS);
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_POINT_ATTEN);
}
#endif
}
#if defined(SUPPORT_VGP)
ui32VGPClipControlWord |=
((gc->ui32TnLEnables & GLES_TL_CLIP_PLANES_ENABLE) >> GLES_TL_CLIP_PLANE0_SHIFT) << MBX1_VGPCLIPCTL_CLIPPLANES_SHIFT;
#endif
}
else
#endif /* PASSTHROUGH_BUILD */
{
if(!gc->bLastProgramLoadedFF)
{
ui32VGPSectionEnables |=
VGP_SECTION(gc->sVertexProgram.psCurrentProgram->sInfo.aui32SectionDesc[VGP_SECTIONDESC_PASSTHROUGH]);
}
else
{
/* Position */
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_COPY_POSITION_COLOUR);
if(bTextured)
{
ui32VGPSectionEnables |= VGP_SECTION(VGP_SECTION_COPY_TEXTURE0);
}
}
}
for(ui32Loop=0; ui32Loop < 16; ui32Loop++)
{
if(ui32VGPSectionEnables & (MBX1_VGPCLIPCTL_SECTION0_ENABLE << ui32Loop))
{
ui32VGPClipControlWord |= VGP_START_SECTION(ui32Loop);
break;
}
}
/* Need to set dirty modelview/inv modelview if these sections change */
if((gc->sHWContext.ui32VGPClipControlWord & ui32MVChangeMask) !=
(ui32VGPSectionEnables & ui32MVChangeMask))
{
gc->ui32DirtyConstantMask |= GLES_DIRTY_CONSTANT_MODELVIEW;
}
gc->sHWContext.ui32VGPClipControlWord = ui32VGPClipControlWord | ui32VGPSectionEnables;
}
IMG_BOOL CheckVGPCodeRev()
{
#if !defined(PASSTHROUGH_BUILD)
IMG_CHAR *pszDriver = GetVGPCodeRev();
if(!strstr(pszDriver, VGPCODE_HEADER_REV))
{
DPF((DBG_ERROR,"VGP code mismatches with driver"));
DPF((DBG_ERROR,"Header = %s",VGPCODE_HEADER_REV));
DPF((DBG_ERROR,"Driver = %s",pszDriver));
return IMG_FALSE;
}
#endif
return IMG_TRUE;
}
/*
Basic Transformation and Lighting VGP Code for an INFINITE viewer
-----------------------------------------------------------------
VGP code to perform basic transformation and lighting for an infinite viewer
Sections
--------
0 -> Transform position to clip-space, do front/back clip
1 -> Transform position to eye-space
2 -> User clip planes
3 -> Lighting set-up, Colour Material setup & global lighting
4 -> Normalise normal
5 -> Infinite lights
6 -> Point lights
7 -> Spot lights
8 -> Lighting output
9 -> Pass through position and base colour
10 -> Pass through texture layers 0
11 -> Pass through texture layers 1
12 -> Texture matrices transform 0
13 -> Texture matrices transform 1
14 -> Fog linear
15 -> Fog exp/exp2
Constants
---------
See vgp.h
Register usage
--------------
r0 -> Transformed vertex
r1 -> Transformed normal (normalised, if required)
r2 -> Accumulating base colour
r3 -> Clip-space vertex position/Accumulating specular colour
r4 -> Eye->vertex vector
r5-r8 -> Various uses
r9 -> Eye Z
r10 -> Colour Material ambient
r11 -> Colour Material diffuse
r12 -> Constant relative addressing amount
*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -