//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- HRESULT CDXUTMesh::Create( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData ) { LPD3DXBUFFER pMtrlBuffer = NULL; LPD3DXBUFFER pAdjacencyBuffer = NULL; HRESULT hr; // Load the mesh from the DXFILEDATA object if( FAILED( hr = D3DXLoadMeshFromXof( pFileData, D3DXMESH_SYSTEMMEM, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pSysMemMesh ) ) ) { return hr; } // Optimize the mesh for performance if( FAILED( hr = m_pSysMemMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL ) ) ) { SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; } hr = CreateMaterials( L"", pd3dDevice, pAdjacencyBuffer, pMtrlBuffer ); SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; }
//----------------------------------------------------------------------------- HRESULT CDXUTMesh::Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename ) { WCHAR strPath[MAX_PATH]; LPD3DXBUFFER pAdjacencyBuffer = NULL; LPD3DXBUFFER pMtrlBuffer = NULL; HRESULT hr; // Cleanup previous mesh if any Destroy(); // Find the path for the file, and convert it to ANSI (for the D3DX API) DXUTFindDXSDKMediaFileCch( strPath, sizeof(strPath) / sizeof(WCHAR), strFilename ); // Load the mesh if( FAILED( hr = D3DXLoadMeshFromX( strPath, D3DXMESH_MANAGED, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh ) ) ) { return hr; } // Optimize the mesh for performance if( FAILED( hr = m_pMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL ) ) ) { SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; } // Set strPath to the path of the mesh file WCHAR *pLastBSlash = wcsrchr( strPath, L'\\' ); if( pLastBSlash ) *(pLastBSlash + 1) = L'\0'; else *strPath = L'\0'; D3DXMATERIAL* d3dxMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); hr = CreateMaterials( strPath, pd3dDevice, d3dxMtrls, m_dwNumMaterials ); SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); // Extract data from m_pMesh for easy access D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE]; m_dwNumVertices = m_pMesh->GetNumVertices(); m_dwNumFaces = m_pMesh->GetNumFaces(); m_dwBytesPerVertex = m_pMesh->GetNumBytesPerVertex(); m_pMesh->GetIndexBuffer( &m_pIB ); m_pMesh->GetVertexBuffer( &m_pVB ); m_pMesh->GetDeclaration( decl ); pd3dDevice->CreateVertexDeclaration( decl, &m_pDecl ); return hr; }
//----------------------------------------------------------------------------- HRESULT CDXUTMesh::Create( LPDIRECT3DDEVICE9 pd3dDevice, ID3DXMesh* pInMesh, D3DXMATERIAL* pd3dxMaterials, DWORD dwMaterials ) { // Cleanup previous mesh if any Destroy(); // Optimize the mesh for performance DWORD *rgdwAdjacency = NULL; rgdwAdjacency = new DWORD[pInMesh->GetNumFaces() * 3]; if( rgdwAdjacency == NULL ) return E_OUTOFMEMORY; pInMesh->GenerateAdjacency(1e-6f,rgdwAdjacency); D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE]; pInMesh->GetDeclaration( decl ); DWORD dwOptions = pInMesh->GetOptions(); dwOptions &= ~(D3DXMESH_32BIT | D3DXMESH_SYSTEMMEM | D3DXMESH_WRITEONLY); dwOptions |= D3DXMESH_MANAGED; dwOptions |= D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE; ID3DXMesh* pTempMesh = NULL; if( FAILED( pInMesh->Optimize( dwOptions, rgdwAdjacency, NULL, NULL, NULL, &pTempMesh ) ) ) { SAFE_DELETE_ARRAY( rgdwAdjacency ); return E_FAIL; } SAFE_DELETE_ARRAY( rgdwAdjacency ); SAFE_RELEASE( m_pMesh ); m_pMesh = pTempMesh; HRESULT hr; hr = CreateMaterials( L"", pd3dDevice, pd3dxMaterials, dwMaterials ); // Extract data from m_pMesh for easy access m_dwNumVertices = m_pMesh->GetNumVertices(); m_dwNumFaces = m_pMesh->GetNumFaces(); m_dwBytesPerVertex = m_pMesh->GetNumBytesPerVertex(); m_pMesh->GetIndexBuffer( &m_pIB ); m_pMesh->GetVertexBuffer( &m_pVB ); m_pMesh->GetDeclaration( decl ); pd3dDevice->CreateVertexDeclaration( decl, &m_pDecl ); return hr; }
//----------------------------------------------------------------------------- HRESULT CDXUTMesh::Create( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData ) { LPD3DXBUFFER pMtrlBuffer = NULL; LPD3DXBUFFER pAdjacencyBuffer = NULL; HRESULT hr; // Cleanup previous mesh if any Destroy(); // Load the mesh from the DXFILEDATA object if( FAILED( hr = D3DXLoadMeshFromXof( pFileData, D3DXMESH_MANAGED, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh ) ) ) { return hr; } // Optimize the mesh for performance if( FAILED( hr = m_pMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL ) ) ) { SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; } D3DXMATERIAL* d3dxMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); hr = CreateMaterials( L"", pd3dDevice, d3dxMtrls, m_dwNumMaterials ); SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); // Extract data from m_pMesh for easy access D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE]; m_dwNumVertices = m_pMesh->GetNumVertices(); m_dwNumFaces = m_pMesh->GetNumFaces(); m_dwBytesPerVertex = m_pMesh->GetNumBytesPerVertex(); m_pMesh->GetIndexBuffer( &m_pIB ); m_pMesh->GetVertexBuffer( &m_pVB ); m_pMesh->GetDeclaration( decl ); pd3dDevice->CreateVertexDeclaration( decl, &m_pDecl ); return hr; }
bool Init() { // Only truly initialize on the first volumetric light ++m_nRefCount; if (m_nRefCount > 1) return true; // Setup any console variables if (!g_cvarEnableVolumetricLight.IsInitted()) { g_cvarEnableVolumetricLight.Init(g_pLTClient, "EnableVolumetricLight", NULL, 1.0f); g_cvarVolumetricLightSlices.Init(g_pLTClient, "VolumetricLightSlices", NULL, DEFAULT_SLICES); g_cvarVolumetricLightSliceRes.Init(g_pLTClient, "VolumetricLightSliceRes", NULL, 320.0f); g_cvarVolumetricLightShadow.Init(g_pLTClient, "VolumetricLightShadow", NULL, 1.0f); g_cvarVolumetricLightShadowRes.Init(g_pLTClient, "VolumetricLightShadowSize", NULL, 128.0f); g_cvarVolumetricLightNoise.Init(g_pLTClient, "VolumetricLightNoise", NULL, 1.0f); g_cvarVolumetricLightFloat.Init(g_pLTClient, "VolumetricLightFloat", NULL, 1.0f); } if (!DATABASE_CATEGORY(VolumetricLight).Init()) { Term(); return false; } if (!CreateVertexDecl()) { Term(); return false; } if (!CreateMaterials()) { Term(); return false; } if (!CreateShellIB()) { Term(); return false; } return true; }
void WorldStage::Start() { CreateMaterials(); if(!actorList.LoadActorsFromFile()) { int mapWidth = 80; int mapHeight = 80; actorList.CreateSomeActorsRandomly(currentMap, mapWidth, mapHeight); } LoadMapFromFileOrCreateNewMap(); }
//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- HRESULT CDXUTMesh::Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename ) { WCHAR strPath[MAX_PATH]; LPD3DXBUFFER pAdjacencyBuffer = NULL; LPD3DXBUFFER pMtrlBuffer = NULL; HRESULT hr; // Find the path for the file, and convert it to ANSI (for the D3DX API) DXUTFindDXSDKMediaFileCch( strPath, sizeof(strPath) / sizeof(WCHAR), strFilename ); // Load the mesh if( FAILED( hr = D3DXLoadMeshFromX( strPath, D3DXMESH_SYSTEMMEM, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pSysMemMesh ) ) ) { return hr; } // Optimize the mesh for performance if( FAILED( hr = m_pSysMemMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL ) ) ) { SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; } // Set strPath to the path of the mesh file WCHAR *pLastBSlash = wcsrchr( strPath, L'\\' ); if( pLastBSlash ) *(pLastBSlash + 1) = L'\0'; else *strPath = L'\0'; hr = CreateMaterials( strPath, pd3dDevice, pAdjacencyBuffer, pMtrlBuffer ); SAFE_RELEASE( pAdjacencyBuffer ); SAFE_RELEASE( pMtrlBuffer ); return hr; }
void CComponentGraphic_GL::DrawDependencyLine( float /*cellSize*/, const CDependencyDescription* pDependency ) { CreateMaterials(); CQuadBatchRenderGroup *renderGroup = dynamic_cast<CQuadBatchRenderGroup *>( CRenderGroupManager::GetInstance()->GetRenderGroup(CRenderGroupManager::LAYER_GUI)); BEATS_ASSERT(renderGroup); BEATS_ASSERT(pDependency != NULL); if (pDependency->IsVisible()) { size_t uDependencyLineCount = pDependency->GetDependencyLineCount(); for (size_t i = 0; i < uDependencyLineCount; ++i) { CDependencyDescriptionLine* pDependencyLine = pDependency->GetDependencyLine(i); const SVertex* pData = pDependencyLine->GetRectArray(); static const size_t SVERTEX_SIZE = 24; CSerializer serializer(SVERTEX_SIZE * 4, (void*)pData); DWORD tmpColor = 0; CQuadPTC dependencyLine; serializer >> dependencyLine.br.position.x; serializer >> dependencyLine.br.position.y; serializer >> dependencyLine.br.position.z; serializer >> tmpColor; serializer >> dependencyLine.br.tex.u; serializer >> dependencyLine.br.tex.v; serializer >> dependencyLine.bl.position.x; serializer >> dependencyLine.bl.position.y; serializer >> dependencyLine.bl.position.z; serializer >> tmpColor; serializer >> dependencyLine.bl.tex.u; serializer >> dependencyLine.bl.tex.v; serializer >> dependencyLine.tr.position.x; serializer >> dependencyLine.tr.position.y; serializer >> dependencyLine.tr.position.z; serializer >> tmpColor; serializer >> dependencyLine.tr.tex.u; serializer >> dependencyLine.tr.tex.v; serializer >> dependencyLine.tl.position.x; serializer >> dependencyLine.tl.position.y; serializer >> dependencyLine.tl.position.z; serializer >> tmpColor; serializer >> dependencyLine.tl.tex.u; serializer >> dependencyLine.tl.tex.v; renderGroup->AddQuad(dependencyLine, m_pMaterials[pDependencyLine->IsSelected() ? eCT_SelectedLine : eCT_NormalLine]); const SVertex* pArrowData = pDependencyLine->GetArrowRectArray(); CSerializer serializerArrow(SVERTEX_SIZE * 4, (void*)pArrowData); CQuadPTC arrow; serializerArrow >> arrow.br.position.x; serializerArrow >> arrow.br.position.y; serializerArrow >> arrow.br.position.z; serializerArrow >> tmpColor; serializerArrow >> arrow.br.tex.u; serializerArrow >> arrow.br.tex.v; serializerArrow >> arrow.bl.position.x; serializerArrow >> arrow.bl.position.y; serializerArrow >> arrow.bl.position.z; serializerArrow >> tmpColor; serializerArrow >> arrow.bl.tex.u; serializerArrow >> arrow.bl.tex.v; serializerArrow >> arrow.tr.position.x; serializerArrow >> arrow.tr.position.y; serializerArrow >> arrow.tr.position.z; serializerArrow >> tmpColor; serializerArrow >> arrow.tr.tex.u; serializerArrow >> arrow.tr.tex.v; serializerArrow >> arrow.tl.position.x; serializerArrow >> arrow.tl.position.y; serializerArrow >> arrow.tl.position.z; serializerArrow >> tmpColor; serializerArrow >> arrow.tl.tex.u; serializerArrow >> arrow.tl.tex.v; renderGroup->AddQuad(arrow, m_pMaterials[pDependencyLine->IsSelected() ? eCT_SelectedArrow : eCT_NormalArrow]); //Render index number for dependency list. if (pDependency->IsListType()) { kmVec3 deltaDirection; kmVec3Subtract(&deltaDirection, &dependencyLine.tr.position, &dependencyLine.tl.position); float fXPos = (dependencyLine.tl.position.x + deltaDirection.x * 0.15f); static const float fHardCodeOffset = 8; float fYPos = (dependencyLine.tl.position.y + deltaDirection.y * 0.15f - fHardCodeOffset); TCHAR szIndex[8]; _stprintf(szIndex, _T("%d"), pDependencyLine->GetIndex()); m_pFont->RenderText(szIndex, fXPos, fYPos, 0xffff00ff); } } }
void CComponentGraphic_GL::DrawDependencies( float cellSize ) { CreateMaterials(); CQuadBatchRenderGroup *renderGroup = dynamic_cast<CQuadBatchRenderGroup *>( CRenderGroupManager::GetInstance()->GetRenderGroup(CRenderGroupManager::LAYER_GUI)); BEATS_ASSERT(renderGroup); size_t uDependencyCount = m_pOwner->GetDependencies().size(); for (int i = 0; i < (int)uDependencyCount; ++i) { // 1. Draw background. CQuadPTC dependencyPoint; dependencyPoint.tl.position.x = m_gridPosX * cellSize; // Left top dependencyPoint.tl.position.y = (m_gridPosY + HEADER_HEIGHT + i * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.tl.position.z = (float)m_gridPosZ; dependencyPoint.tl.tex.u = 0; dependencyPoint.tl.tex.v = 0; dependencyPoint.bl.position.x = m_gridPosX * cellSize; // Left down dependencyPoint.bl.position.y = (m_gridPosY + HEADER_HEIGHT + (i + 1) * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.bl.position.z = (float)m_gridPosZ; dependencyPoint.bl.tex.u = 0; dependencyPoint.bl.tex.v = 1; dependencyPoint.tr.position.x = (m_gridPosX + MIN_WIDTH) * cellSize; // Right top dependencyPoint.tr.position.y = (m_gridPosY + HEADER_HEIGHT + i * DEPENDENCY_HEIGHT) * cellSize ; dependencyPoint.tr.position.z = (float)m_gridPosZ; dependencyPoint.tr.tex.u = 1; dependencyPoint.tr.tex.v = 0; dependencyPoint.br.position.x = (m_gridPosX + MIN_WIDTH) * cellSize; // Right down dependencyPoint.br.position.y = (m_gridPosY + HEADER_HEIGHT + (i + 1) * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.br.position.z = (float)m_gridPosZ; dependencyPoint.br.tex.u = 1; dependencyPoint.br.tex.v = 1; renderGroup->AddQuad(dependencyPoint, m_pMaterials[eCT_RectBG]); // 2. Draw dependency name. m_pFont->RenderText(m_pOwner->GetDependency(i)->GetDisplayName(), dependencyPoint.tl.position.x + Font_Render_X_Offset, dependencyPoint.tl.position.y, 0xFFFFFFFF); // 3. Draw Connect rect. CDependencyDescription* pDescription = m_pOwner->GetDependency(i); BEATS_ASSERT(pDescription != NULL); bool bConnected = pDescription->GetDependencyLineCount() > 0; EComponentTexture textureType = eCT_Count; EDependencyType descriptionType = pDescription->GetType(); bool bIsList = pDescription->IsListType(); if (bConnected) { textureType = bIsList ? eCT_ConnectedDependencyList : eCT_ConnectedDependency; } else { if (bIsList) { textureType = descriptionType == eDT_Strong ? eCT_StrongDependencyList : eCT_WeakDependencyList; } else { textureType = descriptionType == eDT_Strong ? eCT_StrongDependency : eCT_WeakDependency; } } BEATS_ASSERT(textureType != eCT_Count); dependencyPoint.tl.position.x = (m_gridPosX + MIN_WIDTH) * cellSize; // Left top dependencyPoint.tl.position.y = (m_gridPosY + HEADER_HEIGHT + i * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.tl.position.z = (float)m_gridPosZ; dependencyPoint.tl.tex.u = 0; dependencyPoint.tl.tex.v = 0; dependencyPoint.bl.position.x = (m_gridPosX + MIN_WIDTH) * cellSize; // Left down dependencyPoint.bl.position.y = (m_gridPosY + HEADER_HEIGHT + (i + 1) * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.bl.position.z = (float)m_gridPosZ; dependencyPoint.bl.tex.u = 0; dependencyPoint.bl.tex.v = 1; dependencyPoint.tr.position.x = (m_gridPosX + MIN_WIDTH + CONNECTION_WIDTH) * cellSize; // Right top dependencyPoint.tr.position.y = (m_gridPosY + HEADER_HEIGHT + i * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.tr.position.z = (float)m_gridPosZ; dependencyPoint.tr.tex.u = 1; dependencyPoint.tr.tex.v = 0; dependencyPoint.br.position.x = (m_gridPosX + MIN_WIDTH + CONNECTION_WIDTH) * cellSize; // Right down dependencyPoint.br.position.y = (m_gridPosY + HEADER_HEIGHT + (i + 1) * DEPENDENCY_HEIGHT) * cellSize; dependencyPoint.br.position.z = (float)m_gridPosZ; dependencyPoint.br.tex.u = 1; dependencyPoint.br.tex.v = 1; renderGroup->AddQuad(dependencyPoint, m_pMaterials[textureType]); // 4. Draw the line. DrawDependencyLine(cellSize, m_pOwner->GetDependency(i)); } }
void CComponentGraphic_GL::DrawHead(float cellSize) { CreateMaterials(); CQuadBatchRenderGroup *renderGroup = dynamic_cast<CQuadBatchRenderGroup *>( CRenderGroupManager::GetInstance()->GetRenderGroup(CRenderGroupManager::LAYER_GUI)); BEATS_ASSERT(renderGroup); CQuadPTC head; head.tl.position.x = (m_gridPosX + CONNECTION_WIDTH) * cellSize;// Left top head.tl.position.y = m_gridPosY * cellSize; head.tl.position.z = (float)m_gridPosZ; head.tl.tex.u = 0; head.tl.tex.v = 0; head.bl.position.x = (m_gridPosX + CONNECTION_WIDTH) * cellSize;// Left down head.bl.position.y = (m_gridPosY + HEADER_HEIGHT) * cellSize; head.bl.position.z = (float)m_gridPosZ; head.bl.tex.u = 0; head.bl.tex.v = 1; head.tr.position.x = (m_gridPosX + CONNECTION_WIDTH + MIN_WIDTH) * cellSize; // Right top head.tr.position.y = m_gridPosY * cellSize; head.tr.position.z = (float)m_gridPosZ; head.tr.tex.u = 1; head.tr.tex.v = 0; head.br.position.x = (m_gridPosX + CONNECTION_WIDTH + MIN_WIDTH) * cellSize; // Right down head.br.position.y = (m_gridPosY + HEADER_HEIGHT) * cellSize; head.br.position.z = (float)m_gridPosZ; head.br.tex.u = 1; head.br.tex.v = 1; renderGroup->AddQuad(head, m_pMaterials[eCT_RectBG]); // 2. Draw title text. m_pFont->RenderText(m_pOwner->GetDisplayName(), head.tl.position.x + Font_Render_X_Offset, head.tl.position.y, 0xFFFFFFFF); // 3. Draw Connect rect. CQuadPTC connectRect; connectRect.tl.position.x = m_gridPosX * cellSize; // Left top connectRect.tl.position.y = m_gridPosY * cellSize; connectRect.tl.position.z = (float)m_gridPosZ; connectRect.tl.tex.u = 0; connectRect.tl.tex.v = 0; connectRect.bl.position.x = m_gridPosX * cellSize; // Left down connectRect.bl.position.y = (m_gridPosY + HEADER_HEIGHT) * cellSize; connectRect.bl.position.z = (float)m_gridPosZ; connectRect.bl.tex.u = 0; connectRect.bl.tex.v = 1; connectRect.tr.position.x = (m_gridPosX + CONNECTION_WIDTH) * cellSize; // Right top connectRect.tr.position.y = m_gridPosY * cellSize; connectRect.tr.position.z = (float)m_gridPosZ; connectRect.tr.tex.u = 1; connectRect.tr.tex.v = 0; connectRect.br.position.x = (m_gridPosX + CONNECTION_WIDTH) * cellSize; // Right down connectRect.br.position.y = (m_gridPosY + HEADER_HEIGHT) * cellSize; connectRect.br.position.z = (float)m_gridPosZ; connectRect.br.tex.u = 1; connectRect.br.tex.v = 1; renderGroup->AddQuad(connectRect, m_pMaterials[eCT_ConnectRect]); }