bool CD3DVAMesh::Load(ILTStream& File, LTB_Header& LTBHeader) { if (LTBHeader.m_iFileType != LTB_D3D_MODEL_FILE) { OutputDebugString("Error: Wrong file type in CD3DSkelMesh::Load\n"); return false; } if (LTBHeader.m_iVersion != CD3D_LTB_LOAD_VERSION) { OutputDebugString("Error: Wrong file version in CD3DSkelMesh::Load\n"); return false; } // Read in the basics... uint32 iObjSize; File.Read(&iObjSize,sizeof(iObjSize)); File.Read(&m_iVertCount,sizeof(m_iVertCount)); File.Read(&m_iUnDupVertCount,sizeof(m_iUnDupVertCount)); File.Read(&m_iPolyCount,sizeof(m_iPolyCount)); File.Read(&m_iMaxBonesPerTri,sizeof(m_iMaxBonesPerTri)); File.Read(&m_iMaxBonesPerVert,sizeof(m_iMaxBonesPerVert)); File.Read(&m_VertStreamFlags[0],sizeof(uint32)*4); File.Read(&m_iAnimNodeIdx,sizeof(m_iAnimNodeIdx)); File.Read(&m_iBoneEffector,sizeof(m_iBoneEffector)); // Read in our Verts... for (uint32 i=0;i<4;++i) { if (!m_VertStreamFlags[i]) continue; uint32 iVertexSize = 0; // Figure out the vertex size... uint32 iVertFlags = 0; uint32 iUVSets = 0; GetVertexFlags_and_Size(eNO_WORLD_BLENDS,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData); uint32 iSize = iVertexSize * m_iVertCount; // Alloc the VertData... LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER); File.Read(m_pVertData[i],iSize); } // Read in pIndexList... LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER); File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3); // Read in m_pDupMapList... File.Read(&m_iDupMapListCount,sizeof(m_iDupMapListCount)); assert(m_iDupMapListCount < 1000000 && "Invalid VA VertData"); LT_MEM_TRACK_ALLOC(m_pDupMapList = new DupMap[m_iDupMapListCount],LT_MEM_TYPE_RENDERER); File.Read(m_pDupMapList,sizeof(DupMap) * m_iDupMapListCount); // Create the VBs and stuff... ReCreateObject(); return true; }
bool CD3DSkelMesh::Load_MP(ILTStream& File) { // Read in out Min/Max Bones (effecting this guy)... File.Read(&m_iMinBone,sizeof(m_iMinBone)); File.Read(&m_iMaxBone,sizeof(m_iMaxBone)); // What type of Vert do we need? switch (m_iMaxBonesPerVert) { case 2 : m_VertType = eINDEXED_B1; break; case 3 : m_VertType = eINDEXED_B2; break; case 4 : m_VertType = eINDEXED_B3; break; default : assert(0); return false; } // If we are using re-indexed bones, read them in... if (m_bReIndexedBones) { uint32 iBoneCount = 0; File.Read(&iBoneCount,sizeof(iBoneCount)); assert(iBoneCount < 10000 && "Crazy bone count, checked your packed model format."); LT_MEM_TRACK_ALLOC(m_pReIndexedBoneList = new uint32[iBoneCount],LT_MEM_TYPE_RENDERER); File.Read(m_pReIndexedBoneList,sizeof(uint32)*iBoneCount); } // Read in our Verts... for (uint32 i=0;i<4;++i) { if (!m_VertStreamFlags[i]) continue; uint32 iVertexSize = 0; // Figure out the vertex size... uint32 iVertFlags = 0; uint32 iUVSets = 0; GetVertexFlags_and_Size(m_VertType,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData); uint32 iSize = iVertexSize * m_iVertCount; // Alloc the VertData... LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER); File.Read(m_pVertData[i],iSize); } // Read in pIndexList... LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER); File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3); // Create the VBs and stuff... ReCreateObject(); return true; }
bool CD3DSkelMesh::Load_RD(ILTStream& File) { // What type of Vert do we need? switch (m_iMaxBonesPerTri) { case 1 : m_VertType = eNO_WORLD_BLENDS; break; case 2 : m_VertType = eNONINDEXED_B1; break; case 3 : m_VertType = eNONINDEXED_B2; break; case 4 : m_VertType = eNONINDEXED_B3; break; default : assert(0); return false; } // Read in our Verts... for (uint32 i=0;i<4;++i) { if (!m_VertStreamFlags[i]) continue; uint32 iVertexSize = 0; // Figure out the vertex size... uint32 iVertFlags = 0; uint32 iUVSets = 0; GetVertexFlags_and_Size(m_VertType,m_VertStreamFlags[i],iVertFlags,iVertexSize,iUVSets,m_bNonFixPipeData); uint32 iSize = iVertexSize * m_iVertCount; // Alloc the VertData... LT_MEM_TRACK_ALLOC(m_pVertData[i] = new uint8[iSize],LT_MEM_TYPE_RENDERER); File.Read(m_pVertData[i],iSize); } // Read in pIndexList... LT_MEM_TRACK_ALLOC(m_pIndexData = new uint8[sizeof(uint16) * m_iPolyCount * 3],LT_MEM_TYPE_RENDERER); File.Read(m_pIndexData,sizeof(uint16) * m_iPolyCount * 3); // Allocate and read in the BoneSets... File.Read(&m_iBoneSetCount,sizeof(m_iBoneSetCount)); LT_MEM_TRACK_ALLOC(m_pBoneSetArray = new BoneSetListItem[m_iBoneSetCount],LT_MEM_TYPE_RENDERER); if (!m_pBoneSetArray) return false; File.Read(m_pBoneSetArray,sizeof(BoneSetListItem)*m_iBoneSetCount); // Create the VBs and stuff... ReCreateObject(); return true; }
void CD3DSkelMesh::BeginRender(D3DMATRIX* pD3DTransforms, CD3DRenderStyle* pRenderStyle, uint32 iRenderPass) { // [dlj] remove this because DX9 doesn't have this bug // DX8 has bug with table fog with blended meshes... // PD3DDEVICE->GetRenderState(D3DRS_FOGTABLEMODE, &m_nPrevFogTableMode); // PD3DDEVICE->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE); // PD3DDEVICE->GetRenderState(D3DRS_FOGVERTEXMODE, &m_nPrevFogVertexMode); // PD3DDEVICE->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // Do we need to do software vert processing... bool bSoftwareProcessing = m_bSWVertProcessing; // Check if we need to do software processing... switch (m_eRenderMethod) { case eD3DRenderDirect : if (m_iMaxBonesPerTri > g_Device.GetDeviceCaps()->MaxVertexBlendMatrices) { bSoftwareProcessing = true; } break; case eD3DRenderMatrixPalettes : // Note: I am multiplying by two because the spec sais, if you're doing normals as well, it's half of the cap sais... if ((m_iMaxBone-m_iMinBone)*2+1 > g_Device.GetDeviceCaps()->MaxVertexBlendMatrixIndex) { bSoftwareProcessing = true; } break; } // If not already software vertex processing then set if (!m_bSWVertProcessing && bSoftwareProcessing) { m_bSWVertProcessing = true; FreeDeviceObjects(); ReCreateObject(); } // If this pass has a vertex shader, use it. RSD3DRenderPass *pPass = pRenderStyle->GetRenderPass_D3DOptions(iRenderPass); if (NULL != pPass && pPass->bUseVertexShader && pPass->VertexShaderID != LTVertexShader::VERTEXSHADER_INVALID) { if ( m_bSWVSBuffers && !m_bSWVertProcessing ) { m_bSWVertProcessing = true; FreeDeviceObjects(); ReCreateObject(); } // Store the pointer to the actual shader during rendering. m_pVertexShader = LTVertexShaderMgr::GetSingleton().GetVertexShader(pPass->VertexShaderID); if (m_pVertexShader != NULL) { // Install the shader. if (!LTVertexShaderMgr::GetSingleton().InstallVertexShader(m_pVertexShader)) { m_pVertexShader = NULL; return; } } } else if (!m_VBController.getVertexFormat(0) || m_bNonFixPipeData) { RSD3DOptions rsD3DOptions; pRenderStyle->GetDirect3D_Options(&rsD3DOptions); if(!rsD3DOptions.bUseEffectShader) { return; // This is a non fixed function pipe VB - bail out... } //return; // This is a non fixed function pipe VB - bail out... } else if (FAILED(g_RenderStateMgr.SetVertexShader(m_VBController.getVertexFormat(0)))) { return; } // If this pass has a pixel shader, use it. if (NULL != pPass && pPass->bUsePixelShader && pPass->PixelShaderID != LTPixelShader::PIXELSHADER_INVALID) { // Store the pointer to the actual shader during rendering. m_pPixelShader = LTPixelShaderMgr::GetSingleton().GetPixelShader(pPass->PixelShaderID); if (m_pPixelShader != NULL) { // Install the shader. if (!LTPixelShaderMgr::GetSingleton().InstallPixelShader(m_pPixelShader)) { m_pPixelShader = NULL; return; } } } // We need software processing if(m_bSWVertProcessing) { PD3DDEVICE->SetSoftwareVertexProcessing(TRUE); } m_VBController.SetStreamSources(); if(m_eRenderMethod == eD3DRenderMatrixPalettes) { PD3DDEVICE->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, TRUE); } }
void CD3DVAMesh::Render(ModelInstance *pInstance, D3DMATRIX& WorldTransform, CD3DRenderStyle* pRenderStyle, uint32 iRenderPass) { RSD3DOptions rsD3DOptions; pRenderStyle->GetDirect3D_Options(&rsD3DOptions); // If this pass has a vertex shader, use it. RSD3DRenderPass *pPass = pRenderStyle->GetRenderPass_D3DOptions(iRenderPass); if (NULL != pPass && pPass->bUseVertexShader && pPass->VertexShaderID != LTVertexShader::VERTEXSHADER_INVALID) { if ( m_bSWVSBuffers && !m_bSWVertProcessing ) { m_bSWVertProcessing = true; FreeDeviceObjects(); ReCreateObject(); } // Store the pointer to the actual shader during rendering. m_pVertexShader = LTVertexShaderMgr::GetSingleton().GetVertexShader(pPass->VertexShaderID); if (m_pVertexShader != NULL) { // Install the shader. if (!LTVertexShaderMgr::GetSingleton().InstallVertexShader(m_pVertexShader)) { m_pVertexShader = NULL; return; } } } else if (!rsD3DOptions.bUseEffectShader) { if (!m_VBController.getVertexFormat(0) || m_bNonFixPipeData) { // This is a non fixed function pipe VB - bail out... return; } else if(FAILED(g_RenderStateMgr.SetVertexShader(m_VBController.getVertexFormat(0)))) { return; } } // If this pass has a pixel shader, use it. if (NULL != pPass && pPass->bUsePixelShader && pPass->PixelShaderID != LTPixelShader::PIXELSHADER_INVALID) { // Store the pointer to the actual shader during rendering. m_pPixelShader = LTPixelShaderMgr::GetSingleton().GetPixelShader(pPass->PixelShaderID); if (m_pPixelShader != NULL) { // Install the shader. if (!LTPixelShaderMgr::GetSingleton().InstallPixelShader(m_pPixelShader)) { m_pPixelShader = NULL; return; } } } // We need software processing if(m_bSWVertProcessing) { PD3DDEVICE->SetSoftwareVertexProcessing(TRUE); } g_RenderStateMgr.SetTransform(D3DTS_WORLDMATRIX(0), &WorldTransform); m_VBController.SetStreamSources(); // Set the vertex shader constants. if (m_pVertexShader != NULL) { // Let the client set some constants. if (NULL != i_client_shell) { i_client_shell->OnVertexShaderSetConstants(m_pVertexShader, iRenderPass, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton()); } // Send the constants to the video card. LTVertexShaderMgr::GetSingleton().SetVertexShaderConstants(m_pVertexShader); } // Set the pixel shader constants. if (m_pPixelShader != NULL) { // Let the client set some constants. if (NULL != i_client_shell) { i_client_shell->OnPixelShaderSetConstants(m_pPixelShader, iRenderPass, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton()); } // Send the constants to the video card. LTPixelShaderMgr::GetSingleton().SetPixelShaderConstants(m_pPixelShader); } if(rsD3DOptions.bUseEffectShader) { LTEffectImpl* _pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(rsD3DOptions.EffectShaderID); ID3DXEffect* pEffect = _pEffect->GetEffect(); if(pEffect) { i_client_shell->OnEffectShaderSetParams((LTEffectShader*)_pEffect, pRenderStyle, pInstance, LTShaderDeviceStateImp::GetSingleton()); pEffect->CommitChanges(); } } m_VBController.Render(0,0,m_iVertCount,m_iPolyCount); if ( m_bSWVertProcessing ) { // If we are running with hardware then turn back on hardware processing if ( (g_Device.GetDeviceCaps()->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ) { PD3DDEVICE->SetSoftwareVertexProcessing(FALSE); } } PD3DDEVICE->SetStreamSource(0, 0, 0, 0); PD3DDEVICE->SetIndices(0); // Uninstall the vertex shader. if (NULL != m_pVertexShader) { LTVertexShaderMgr::GetSingleton().UninstallVertexShader(); m_pVertexShader = NULL; } // Uninstall the pixel shader. if (NULL != m_pPixelShader) { LTPixelShaderMgr::GetSingleton().UninstallPixelShader(); m_pPixelShader = NULL; } }