⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primindexed.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	pbIBData	+= ui32IBByteStride;
	pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;

	/* Validate index value to prevent access violations */
	if(!VALIDATE_INDEX(psContext, (*pui32IBData & ui32IndexMask)))
	{
		psContext->hrLastError = D3DMERR_INVALIDCALL;
		goto ErrorExit;
	}	
	SetupNativeVertex(psContext, (IMG_UINT32*)(pbVBData + ((*pui32IBData & ui32IndexMask) * ui32VBByteStride)),
						ui32FVFcode,
						apsVertex[1]);

	/* Advance pointer */
	pbIBData	+= ui32IBByteStride;
	pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;
	
	/************************
		first time clip test
	************************/
	DoClipTestandVPTransform(psContext, &apsVertex[0], 2);

	for(i=0; i<ui32PrimCount; i++)
	{
		/* Validate index value to prevent access violations */
		if(!VALIDATE_INDEX(psContext, (*pui32IBData & ui32IndexMask)))
		{
			psContext->hrLastError = D3DMERR_INVALIDCALL;
			goto ErrorExit;
		}	
		SetupNativeVertex(psContext, (IMG_UINT32*)(pbVBData + ((*pui32IBData & ui32IndexMask) * ui32VBByteStride)),
							ui32FVFcode,
							apsVertex[2]);

		/* Advance pointer */
		pbIBData	+= ui32IBByteStride;
		pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;

		/* Store pointers to colours for flat shading */
		psContext->sTState.sSWTNLState.psCurrentFlatShadeDiffuse  = &apsVertex[0]->sDiffuseOut;
		psContext->sTState.sSWTNLState.psCurrentFlatShadeSpecular = &apsVertex[0]->sSpecularOut;

		/**********************
			clip test
		**********************/
		DoClipTestandVPTransform(psContext, &apsVertex[2], 1);

		/**********************
			Depth bias
		**********************/
		if(psContext->sTState.dwRSFlags & TSTATE_RSFLAGS_DEPTHBIAS)
		{
			/* Calculate value of m */
			NTV_TYPE ntvNewDepthM = TriangleMaxDepthSlope(apsVertex[0]);

			/* if m is different from previous m then calculate depth bias offset */
			if(ntvNewDepthM != ntvDepthM)
			{
				CalculateDepthBias(psContext,ntvNewDepthM);

				ntvDepthM = ntvNewDepthM;
			}
		}

		/* any vertices clipped? */
		ui32ClipCode =	 (apsVertex[0]->ui32Flags 
						| apsVertex[1]->ui32Flags 
						| apsVertex[2]->ui32Flags) & D3DM_CLIPFLAG_MASK;
		
		if (ui32ClipCode == 0)	/* no clipping: */
		{
			if(bNewStrip)
			{
				if(ui32NumStrips)
				{
					TACSWriteEndPrim(psContext);
				}
				else
				{
					TACSWritePrimHdr(psContext, psContext->dwTAPrimCtl, MBX1_TAOBJTYPE_VERTEXLINESTRIP);
					TACSWriteLinePointSize(psContext, 0x3F000000/*0.5*/);
				}
				ui32NumStrips++;

				ValidateVertex(psContext, &apsVertex[0], 3);

				OutputVertices(psContext, &apsVertex[0], 4);

				bNewStrip = IMG_FALSE;
			}
			else
			{
				/* draw segments 1->2, 2->0 */
				ValidateVertex(psContext, &apsVertex[2], 1);
				OutputVertices(psContext, &apsVertex[1], 3);
			}
		}
		else if (!(	apsVertex[0]->ui32Flags 
				&	apsVertex[1]->ui32Flags 
				&	apsVertex[2]->ui32Flags & D3DM_CLIPFLAG_MASK))
		{
			ValidateVertex(psContext, &apsVertex[0], 3);

			/* go through segments */
			for (j=0; j<3; j++)
			{
				ui32NumVerts = DoLineClip(psContext, apsVertex[j], apsVertex[j+1], ui32ClipCode);
				if(ui32NumVerts)
				{
					if(ui32NumStrips)
					{
						TACSWriteEndPrim(psContext);
					}
					else
					{
						/* Start a new primitive block */
						TACSWritePrimHdr(psContext, psContext->dwTAPrimCtl, MBX1_TAOBJTYPE_VERTEXLINESTRIP);
						TACSWriteLinePointSize(psContext, 0x3F000000/*0.5*/);
					}
					ui32NumStrips++;

					ppsVertex = psContext->sTState.sSWTNLState.ppsOutputArray;		
					OutputVertices(psContext, ppsVertex, ui32NumVerts);					
				}
			}

			bNewStrip = IMG_TRUE;
		}
		else
		{
			bNewStrip = IMG_TRUE;
		}

		/* advance vertices */
		psVTmp = apsVertex[0];
		apsVertex[0] = apsVertex[1];
		apsVertex[1] = apsVertex[2];
		apsVertex[2] = psVTmp;
		apsVertex[3] = apsVertex[0];
	}

ErrorExit:
	
	/*
		Finish the primitive block
	*/
	if(ui32NumStrips)
	{
		TACSWriteLastPrim(psContext);
#ifdef FIX_HW_PRN_299
		TACSWriteTACtlAnd3DState ( 	psContext,
									MBX1_TASTATEPRES_ISPCTL,
								 	&psContext->sHWState.sTACtl3DState,
								 	TRUE);
#endif		
	}
}
/***********************************************************************************
 Function Name      : IndexedTriFanLine
************************************************************************************/
IMG_VOID IndexedTriFanLine(	LPD3DM_CONTEXT	psContext,
							IMG_UINT32		ui32FVFcode, 
							BYTE			*pbVBData,
							IMG_UINT32		ui32VBByteStride,
							BYTE			*pbIBData,
							IMG_UINT32		ui32IBByteStride,
							IMG_UINT32		ui32PrimCount)
{
	IMG_UINT32			i, j;
	PVR_NATIVE_VERTEX	asVertex[3], *apsVertex[4], *psVTmp, **ppsVertex;
	IMG_UINT32			ui32ClipCode;
	IMG_BOOL			bNewFan = IMG_TRUE;
	IMG_UINT32			ui32NumFans = 0;
	IMG_UINT32			ui32NumVerts;
	IMG_UINT32			ui32IndexMask;
	UNALIGNED IMG_UINT32	*pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;
	NTV_TYPE			ntvDepthM = D3DM_Zero;

	ui32IndexMask = psContext->ui32IndexMask;

	/* initialise the vertex ptr array */
	apsVertex[0] = &asVertex[0];
	apsVertex[1] = &asVertex[1];
	apsVertex[2] = &asVertex[2];
	apsVertex[3] = &asVertex[0];/* and wrap to first vertex */
	
	/* construct native vertices */
	/* Validate index value to prevent access violations */
	if(!VALIDATE_INDEX(psContext, (*pui32IBData & ui32IndexMask)))
	{
		psContext->hrLastError = D3DMERR_INVALIDCALL;
		goto ErrorExit;
	}	
	SetupNativeVertex(psContext, (IMG_UINT32*)(pbVBData + ((*pui32IBData & ui32IndexMask) * ui32VBByteStride)),
						ui32FVFcode,
						apsVertex[0]);

	/* Advance pointer */
	pbIBData	+= ui32IBByteStride;
	pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;

	/* Validate index value to prevent access violations */
	if(!VALIDATE_INDEX(psContext, (*pui32IBData & ui32IndexMask)))
	{
		psContext->hrLastError = D3DMERR_INVALIDCALL;
		goto ErrorExit;
	}	
	SetupNativeVertex(psContext, (IMG_UINT32*)(pbVBData + ((*pui32IBData & ui32IndexMask) * ui32VBByteStride)),
						ui32FVFcode,
						apsVertex[1]);

	/* Advance pointer */
	pbIBData	+= ui32IBByteStride;
	pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;
	
	/************************
		first time clip test
	************************/
	DoClipTestandVPTransform(psContext, &apsVertex[0], 2);

	for(i=0; i<ui32PrimCount; i++)
	{
		/* Validate index value to prevent access violations */
		if(!VALIDATE_INDEX(psContext, (*pui32IBData & ui32IndexMask)))
		{
			psContext->hrLastError = D3DMERR_INVALIDCALL;
			goto ErrorExit;
		}	
		SetupNativeVertex(psContext, (IMG_UINT32*)(pbVBData + ((*pui32IBData & ui32IndexMask) * ui32VBByteStride)),
							ui32FVFcode,
							apsVertex[2]);

		/* Advance pointer */
		pbIBData	+= ui32IBByteStride;
		pui32IBData = (UNALIGNED IMG_UINT32*)pbIBData;

		/* Store pointers to colours for flat shading */
		psContext->sTState.sSWTNLState.psCurrentFlatShadeDiffuse  = &apsVertex[0]->sDiffuseOut;
		psContext->sTState.sSWTNLState.psCurrentFlatShadeSpecular = &apsVertex[0]->sSpecularOut;

		/**********************
			clip test
		**********************/
		DoClipTestandVPTransform(psContext, &apsVertex[2], 1);

		/**********************
			Depth bias
		**********************/
		if(psContext->sTState.dwRSFlags & TSTATE_RSFLAGS_DEPTHBIAS)
		{
			/* Calculate value of m */
			NTV_TYPE ntvNewDepthM = TriangleMaxDepthSlope(apsVertex[0]);

			/* if m is different from previous m then calculate depth bias offset */
			if(ntvNewDepthM != ntvDepthM)
			{
				CalculateDepthBias(psContext,ntvNewDepthM);

				ntvDepthM = ntvNewDepthM;
			}
		}

		/* any vertices clipped? */
		ui32ClipCode =	 (apsVertex[0]->ui32Flags 
						| apsVertex[1]->ui32Flags 
						| apsVertex[2]->ui32Flags) & D3DM_CLIPFLAG_MASK;
		
		if (ui32ClipCode == 0)	/* no clipping: */
		{
			if(bNewFan)
			{
				if (ui32NumFans)
				{
					TACSWriteEndPrim(psContext);
				}
				else
				{
					TACSWritePrimHdr(psContext, psContext->dwTAPrimCtl, MBX1_TAOBJTYPE_VERTEXLINESTRIP);
					TACSWriteLinePointSize(psContext, 0x3F000000/*0.5*/);
				}
				ui32NumFans++;

				ValidateVertex(psContext, &apsVertex[0], 3);

				OutputVertices(psContext, &apsVertex[0], 4);

				bNewFan = IMG_FALSE;
			}
			else
			{
				/* draw segments 1->2, 2->0 */
				ValidateVertex(psContext, &apsVertex[2], 1);
				OutputVertices(psContext, &apsVertex[1], 3);
			}
		}
		else if (!(	apsVertex[0]->ui32Flags 
				&	apsVertex[1]->ui32Flags 
				&	apsVertex[2]->ui32Flags & D3DM_CLIPFLAG_MASK))
		{
			ValidateVertex(psContext, &apsVertex[0], 3);

			/* go through segments */
			for (j=0; j<3; j++)
			{
				ui32NumVerts = DoLineClip(psContext, apsVertex[j], apsVertex[j+1], ui32ClipCode);
				if(ui32NumVerts)
				{
					if (ui32NumFans)
					{
						TACSWriteEndPrim(psContext);
					}
					else
					{
						/* Start a new primitive block */
						TACSWritePrimHdr(psContext, psContext->dwTAPrimCtl, MBX1_TAOBJTYPE_VERTEXLINESTRIP);
						TACSWriteLinePointSize(psContext, 0x3F000000/*0.5*/);
					}
					ui32NumFans++;
					ppsVertex = psContext->sTState.sSWTNLState.ppsOutputArray;		
					OutputVertices(psContext, ppsVertex, ui32NumVerts);
				}
			}
					
			bNewFan = IMG_TRUE;
		}
		else
		{
			bNewFan = IMG_TRUE;
		}

		/* advance vertices */
		psVTmp = apsVertex[1];
		apsVertex[1] = apsVertex[2];
		apsVertex[2] = psVTmp;
	}

ErrorExit:
	
	/*
		Finish the primitive block
	*/
	if(ui32NumFans)
	{
		TACSWriteLastPrim(psContext);
#ifdef FIX_HW_PRN_299
		TACSWriteTACtlAnd3DState ( 	psContext,
									MBX1_TASTATEPRES_ISPCTL,
								 	&psContext->sHWState.sTACtl3DState,
								 	TRUE);
#endif		
	}
}
/***********************************************************************************
 Function Name      : DrawIndexedPrimitive
					: 
 Returns            : -
 Description        : Selects and calls correct primitive draw function
************************************************************************************/
IMG_VOID DrawIndexedPrimitive (	LPD3DM_CONTEXT		psContext, 
								D3DMPRIMITIVETYPE	PrimType,
								IMG_UINT32			ui32MinIndex,
								IMG_UINT32			ui32NumVertices,
								IMG_UINT32			ui32StartIndexOffset,
								IMG_UINT32			ui32PrimitiveCount,
								IMG_UINT32			ui32BaseVertexIndex)
{
	/* select current vertex buffer */
	LPD3DM_VBUFFER	psCurrentVB = psContext->psVertexSource;
	LPD3DM_IBUFFER	psCurrentIB = psContext->psIndexSource;
	IMG_UINT32		ui32VBByteStride = psCurrentVB->dwStrideDW<<2;
	IMG_UINT32		ui32IBByteStride = psCurrentIB->dwStrideByte;
	BYTE			*pbVBData = (BYTE*)psCurrentVB->pvVertexData;
	BYTE			*pbIBData = (BYTE*)psCurrentIB->pvIndexData;
	PRIM_FILLMODE	eFillMode = psContext->ePrimFillMode;

	/*
		MinIndex 
			Specifies the minimum index of a range of vertices that 
			are potentially accessed by the primitives to be drawn and, 
			therefore, which vertices should be processed. 
		NumVertices 
			Specifies the number of vertices in a range that are 
			potentially accessed by the primitives to be drawn and, 
			therefore, which vertices should be processed. 
		StartIndexOffset 
			Specifies the first index in the index buffer from 
			which indices are read to draw the primitives. 
		PrimitiveCount 
			Specifies the number of triangles, lines or 
			points to draw for the given primitive. 
		BaseVertexIndex 
			Specifies the amount that should be added to each index 
			referenced by the various primitives to determine the 
			actual index of the vertex elements in each vertex stream. 
	*/

#ifdef BLOCK_TRANS
	/*
		If we want to do block tranformation
		here's the range of vertices that are addressed
		for this primitive
	*/
	pbVBBlockData = pbVBData + ((ui32BaseVertexIndex + ui32MinIndex) * ui32VBByteStride);
	ui32VerticesInBlock = ui32NumVertices;
#else
	/*
		Base of VB for this primitive
	*/
	pbVBData += ui32BaseVertexIndex * ui32VBByteStride;
#endif

	/* 
		advance Index buffer to first index 
	*/
	pbIBData += ui32StartIndexOffset * ui32IBByteStride;

	/* store the current prim type to avoid passing extra args */
	psContext->eCurrentPrimType = PrimType;

#if defined (FIX_HW_PRN_725_MBXLITE)

	/* Initialise Flags */
	psContext->dwHWPRN725Flags  &= ~HW_PRN_725_FLAGS_INDEXED;
	psContext->dwHWPRN725Flags  |= HW_PRN_725_FLAGS_STOREVERTS;
	psContext->dwHWPRN725Flags  &= ~HW_PRN_725_FLAGS_FAN_MODE;

#endif

	PROFILE_START_PRIM_INDEXED(PrimType, eFillMode);
	/* FIXME - Validate buffer access - i.e. that we're not goint to exceed the buffer length /*
	
	/* copy vertex data (and transform if SW TnL) */
	switch(PrimType)
	{
	    case D3DMPT_TRIANGLELIST:
		{
#if defined (FIX_HW_PRN_725_MBXLITE)
			if(eFillMode != PRIM_FILLMODE_WIREFRAME)
			{
				psContext->dwHWPRN725Flags  &= ~HW_PRN_725_FLAGS_STOREVERTS;
			}
#endif
			apfnIndexedTriList[eFillMode](psContext,
										 psCurrentVB->dwFVFFlags, 
										 pbVBData,
										 ui32VBByteStride,
										 pbIBData,
										 ui32IBByteStride,
										 ui32PrimitiveCount);
			break;
		}
	    case D3DMPT_TRIANGLESTRIP:
		{
			apfnIndexedTriStrip[eFillMode](psContext,
										 psCurrentVB->dwFVFFlags, 
										 pbVBData,
										 ui32VBByteStride,
										 pbIBData,
										 ui32IBByteStride,
										 ui32PrimitiveCount);
			break;
		}
	    case D3DMPT_TRIANGLEFAN:
		{
#if defined (FIX_HW_PRN_725_MBXLITE)
			if(eFillMode != PRIM_FILLMODE_WIREFRAME)
			{
				psContext->dwHWPRN725Flags  &= ~HW_PRN_725_FLAGS_STOREVERTS;
			}
#endif
			apfnIndexedTriFan[eFillMode](psContext,
										 psCurrentVB->dwFVFFlags, 
										 pbVBData,
										 ui32VBByteStride,
										 pbIBData,
										 ui32IBByteStride,
										 ui32PrimitiveCount);
			break;
		}
		case D3DMPT_POINTLIST:
		{
#if defined (FIX_HW_PRN_725_MBXLITE)
			psContext->dwHWPRN725Flags  &= ~HW_PRN_725_FLAGS_STOREVERTS;
#endif
			apfnIndexedPointList[eFillMode]	(psContext,
											 psCurrentVB->dwFVFFlags, 
											 pbVBData,
											 ui32VBByteStride,
											 pbIBData,
											 ui32IBByteStride,
											 ui32PrimitiveCount);
			break;
		}
	    case D3DMPT_LINELIST:
		{
			apfnIndexedLineList[eFillMode]	(psContext,
											 psCurrentVB->dwFVFFlags, 
											 pbVBData,
											 ui32VBByteStride,
											 pbIBData,
											 ui32IBByteStride,
											 ui32PrimitiveCount);
			break;
		}
	    case D3DMPT_LINESTRIP:
		{
			apfnIndexedLineStrip[eFillMode]	(psContext,
											 psCurrentVB->dwFVFFlags, 
											 pbVBData,
											 ui32VBByteStride,
											 pbIBData,
											 ui32IBByteStride,
											 ui32PrimitiveCount);
			break;
		}
	    default:
			break;
	    	///error!!!!!!!!!!!!!!!!!!!!!!!!!!
    }


	PROFILE_STOP_PRIM_INDEXED(PrimType, eFillMode);
}
#endif /* SUPPORT_VGP */

/*****************************************************************************
 End of file (primindexed.c)
*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -