/////////////////////////////////////////////////////////////////////////////// // Copyright (C) Microsoft Corporation, 2000. // // refdevi.cpp // // Direct3D Reference Device - Main Internal Object Methods // /////////////////////////////////////////////////////////////////////////////// #include "pch.cpp" #pragma hdrstop ////////////////////////////////////////////////////////////////////////////////// // // // global controls // // // ////////////////////////////////////////////////////////////////////////////////// float g_GammaTable[256]; UINT g_iGamma = 150; ////////////////////////////////////////////////////////////////////////////////// // // // RefDev Methods // // // ////////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // // Constructor/Destructor for renderer core object. // //----------------------------------------------------------------------------- RefDev::RefDev( LPDDRAWI_DIRECTDRAW_LCL pDDLcl, DWORD dwInterfaceType, RDDDITYPE dwDDIType, D3DCAPS8* pCaps8 ) : m_RefVP(), m_RefVM(), m_Clipper(), m_FVFShader() { m_Caps8 = *pCaps8; m_pDDLcl = NULL; m_wSaveFP = 0; m_bInBegin = FALSE; m_bPointSprite = 0; m_pRenderTarget = NULL; memset( m_fWBufferNorm, 0, sizeof( float)*2 ); memset( m_dwRenderState, 0, sizeof( DWORD ) * D3DHAL_MAX_RSTATES ); memset( &m_renderstate_override, 0, sizeof(m_renderstate_override) ); m_cActiveTextureStages = 0; m_ReferencedTexCoordMask = 0; memset( m_pTexture, 0, sizeof(RDSurface2D*)*D3DHAL_TSS_MAXSTAGES ); memset( m_dwTextureStageState, 0, sizeof(m_dwTextureStageState) ); for (int i=0; iSetRefDev(this); // update num active stages UpdateActiveTexStageCount(); } //----------------------------------------------------------------------------- // // SetTextureHandle - On DX7, this is called when a texture handle is set. // This maps the texture handle embedded in the per-stage state to texture // object pointers. // //----------------------------------------------------------------------------- HRESULT RefDev::SetTextureHandle( int iStage, DWORD dwTexHandle ) { HRESULT hr = D3D_OK; // Special case, if texture handle == 0, then unmap the texture from the TSS if (dwTexHandle == 0) { m_pTexture[iStage] = NULL; // update num active stages UpdateActiveTexStageCount(); return D3D_OK; } // Ask DDraw to decipher what this particular handle meant wrt. to the // the DDraw_Local associated with this instance of the Refrast RDSurface2D* pTex = (RDSurface2D *)g_SurfMgr.GetSurfFromList(m_pDDLcl, dwTexHandle); if( pTex == NULL ) { DPFERR( "Unable to obtain Texture from the list" ); return DDERR_INVALIDOBJECT; } // map one m_pTexture[iStage] = pTex; m_pTexture[iStage]->SetRefDev(this); // update num active stages UpdateActiveTexStageCount(); return D3D_OK; } //----------------------------------------------------------------------------- // // UpdateActiveTexStageCount - Updates number of texture coordinate/lookup // stages that are active. // //----------------------------------------------------------------------------- void RefDev::UpdateActiveTexStageCount( void ) { m_dwRastFlags |= RDRF_TEXTURESTAGESTATE_CHANGED; // DX3/5 - always one active texture stage if ( NULL != m_dwRenderState[D3DRENDERSTATE_TEXTUREHANDLE] ) { m_cActiveTextureStages = 1; m_ReferencedTexCoordMask = 0x1; return; } // DX8+ pixel shading model - count derived from shader code if (m_CurrentPShaderHandle) { RDPShader* pShader = GetPShader(m_CurrentPShaderHandle); if( pShader ) { m_cActiveTextureStages = pShader->m_cActiveTextureStages; m_ReferencedTexCoordMask = pShader->m_ReferencedTexCoordMask; } else { m_cActiveTextureStages = 0; m_ReferencedTexCoordMask = 0; } return; } // DX6/7 pixel shading model m_cActiveTextureStages = 0; for ( int iStage=0; iStage