/////////////////////////////////////////////////////////////////////////////// // Copyright (C) Microsoft Corporation, 2000. // // rastattr.cpp // // Direct3D Reference Device - // /////////////////////////////////////////////////////////////////////////////// #include "pch.cpp" #pragma hdrstop //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void RDAttribute::Init( RefRast* pRefRast, // RefRast with which this attrib is used UINT cDimensionality, BOOL bPerspective, BOOL bClamp ) { m_pRR = pRefRast; m_cDimensionality = cDimensionality; m_bPerspective = bPerspective; m_bClamp = bClamp; m_cProjection = 0; m_dwWrapFlags = 0x0; m_bFlatShade = FALSE; } /////////////////////////////////////////////////////////////////////////////// // // Sampling Routines // /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // // Sample - Sample attribute at given location. // //----------------------------------------------------------------------------- void RDAttribute::Sample( FLOAT* pSample, FLOAT fX, FLOAT fY, BOOL bNoProjectionOverride, // disables projection if TRUE BOOL bClampOverride) // enables (forces) clamp if TRUE { FLOAT fPScale = 1.0F; if (m_cProjection && !m_bFlatShade && !bNoProjectionOverride) { // note that perspective is already incorporated into projective coord fPScale = 1.0F/( fX*m_fA[m_cProjection] + fY*m_fB[m_cProjection] + m_fC[m_cProjection] ); } else if (m_bPerspective && !m_bFlatShade) { fPScale = m_pRR->m_fW[m_pRR->m_iPix]; } for ( UINT i=0; im_bIsLine) { LineSetup( pVtx0, pVtx1, pVtx2 ); return; } for ( UINT i=0; im_iFlatVtx ) { default: case 0: m_fC[i] = fVal0; break; case 1: m_fC[i] = fVal1; break; case 2: m_fC[i] = fVal2; break; } continue; } // extract wrap flag for this dimension BOOL bWrap = m_dwWrapFlags & (1<m_fRHW0) : (1.0F); FLOAT fRHW1 = (m_bPerspective) ? (m_pRR->m_fRHW1) : (1.0F); FLOAT fRHW2 = (m_bPerspective) ? (m_pRR->m_fRHW2) : (1.0F); FLOAT fDelAttrib10 = ( fVal1P * fRHW1 ) - ( fVal0 * fRHW0 ); FLOAT fDelAttrib20 = ( fVal2P * fRHW2 ) - ( fVal0 * fRHW0 ); // compute A & B terms (dVdX and dVdY) m_fA[i] = m_pRR->m_fTriOODet * ( fDelAttrib10 * m_pRR->m_fDelY20 + fDelAttrib20 * m_pRR->m_fDelY01 ); m_fB[i] = m_pRR->m_fTriOODet * ( fDelAttrib20 * m_pRR->m_fDelX10 + fDelAttrib10 * m_pRR->m_fDelX02 ); // compute C term (Fv = A*Xv + B*Yv + C => C = Fv - A*Xv - B*Yv) m_fC[i] = ( fVal0 * fRHW0 ) - ( m_fA[i] * m_pRR->m_fX0 ) - ( m_fB[i] * m_pRR->m_fY0 ); } } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void RDAttribute::LineSetup( const FLOAT* pVtx0, const FLOAT* pVtx1, const FLOAT* pVtxFlat) { for ( UINT i=0; im_fRHW0) : (1.0F); FLOAT fRHW1 = (m_bPerspective) ? (m_pRR->m_fRHW1) : (1.0F); FLOAT fDelta = ( fVal1P*fRHW1 - fVal0*fRHW0) / m_pRR->m_fLineMajorLength; m_fA[i] = ( m_pRR->m_bLineXMajor ) ? ( fDelta ) : ( 0. ); m_fB[i] = ( m_pRR->m_bLineXMajor ) ? ( 0. ) : ( fDelta ); // compute C term (Fv = A*Xv + B*Yv + C => C = Fv - A*Xv - B*Yv) m_fC[i] = ( fVal0* fRHW0) - ( m_fA[i] * m_pRR->m_fX0 ) - ( m_fB[i] * m_pRR->m_fY0 ); } } //----------------------------------------------------------------------------- // // Setup attribute given packed DWORD color. Color format is that of the // colors in the FVF vertex, which corresponds to D3DFMT_A8R8G8B8 (and is // the same as D3DCOLOR). // //----------------------------------------------------------------------------- void RDAttribute::Setup( DWORD dwVtx0, DWORD dwVtx1, DWORD dwVtx2) { FLOAT fVtx0[4]; FLOAT fVtx1[4]; FLOAT fVtx2[4]; fVtx0[0] = RGBA_GETRED( dwVtx0 ) * (1./255.); fVtx0[1] = RGBA_GETGREEN( dwVtx0 ) * (1./255.); fVtx0[2] = RGBA_GETBLUE( dwVtx0 ) * (1./255.); fVtx0[3] = RGBA_GETALPHA( dwVtx0 ) * (1./255.); fVtx1[0] = RGBA_GETRED( dwVtx1 ) * (1./255.); fVtx1[1] = RGBA_GETGREEN( dwVtx1 ) * (1./255.); fVtx1[2] = RGBA_GETBLUE( dwVtx1 ) * (1./255.); fVtx1[3] = RGBA_GETALPHA( dwVtx1 ) * (1./255.); fVtx2[0] = RGBA_GETRED( dwVtx2 ) * (1./255.); fVtx2[1] = RGBA_GETGREEN( dwVtx2 ) * (1./255.); fVtx2[2] = RGBA_GETBLUE( dwVtx2 ) * (1./255.); fVtx2[3] = RGBA_GETALPHA( dwVtx2 ) * (1./255.); Setup( fVtx0, fVtx1, fVtx2); } /////////////////////////////////////////////////////////////////////////////// // end