CResManager::~CResManager() { g_pResManager = NULL; m_bThreadWork = false; WaitForMultipleObjects( 1, &m_hLoadThread, TRUE, INFINITE ); CloseHandle( m_hLoadThread ); index_t nID = INVALID_INDEX; for ( uint n = 0; n < m_ResReady.GetCount(); ++n ) { TResource * pRes = m_ResReady[ n ]; DEL_ARRAY( pRes->pBuffer ); DEL( pRes ); } for ( uint n = 0; n < m_ResQueue.GetCount(); ++n ) { TResource * pRes = m_ResQueue[ n ]; g_pVfs->CloseFile( (IFile **)&pRes->pFile ); DEL_ARRAY( pRes->pBuffer ); DEL( pRes ); } /*for ( index_t nID = INVALID_INDEX; m_ResSlots.Iterate( nID ); ) { DEL( m_ResSlots[ nID ] ); }*/ m_ResReady.Delete(); m_ResQueue.Delete(); m_pCreators.Delete(); // mem leak? m_ResSlots.Delete(); }
void CVertices::CleanUp(void) { DEL_ARRAY(m_Vertices); DEL_ARRAY(m_Normals); DEL_ARRAY(m_PolygonRefs); m_nVertices = 0; }
CLandTile::~CLandTile() { RELEASE( m_pVB ); RELEASE( m_pIB ); DEL_ARRAY( m_pVertices ); DEL_ARRAY( m_pIndices ); DEL_ARRAY( m_pTraceBoxes ); }
CLandscape::~CLandscape() { DEL_ARRAY( m_pTiles ); //DEL( pMat ); DEL_ARRAY( m_pVertices ); DEL_ARRAY( m_pIndices ); }
CMayaMesh::~CMayaMesh() { while( m_nSurfCount-- ) { TMayaSurface & tSurf = m_pSurfaces[ m_nSurfCount ]; for ( uint n = 0; n < m_nUvSetCount; ++n ) tSurf.ppUvIndices[ n ].Delete(); tSurf.pIndices.Delete(); } DEL_ARRAY( m_pUvSets ); DEL_ARRAY( m_pSurfaces ); }
/* ================================================================================ // Name: // Desc: ================================================================================ */ CIndexBuffer::~CIndexBuffer() { g_pRenderer->RemoveIB( m_nIndex ); if ( g_pRenderer->IsExtSupported( EXT_GL_VBO ) ) { if ( m_nBufferID ) { glDeleteBuffersARB( 1, &m_nBufferID ); GL_VALIDATE; } } else { DEL_ARRAY( m_pMemBuffer ); } }
void CShaderCfgLoader::FinalizeRes( TResource * pRes ) { pRes->eState = TResource::FAILED; //-------------------------------------------------------------------------- // Tip: Check XMLWrapper //-------------------------------------------------------------------------- IXMLWrapper * pWrapper = (IXMLWrapper *)g_pSystem->GetInterface( IT_UTIL ); if ( !pWrapper ) return; CXMLElement * pRoot = NULL; pWrapper->LoadXMLFromMem( (char *)pRes->pBuffer, pRes->nSize, &pRoot ); DEL_ARRAY( pRes->pBuffer ); //pRes->pResource = pRoot; //-------------------------------------------------------------------------- // Tip: Check root element name //-------------------------------------------------------------------------- CStr sName( pRoot->GetName() ); if ( !sName.Compare( "Shaders" ) ) { DEL( pRoot ); return; } //-------------------------------------------------------------------------- // Tip: Parsing shaders //-------------------------------------------------------------------------- for ( size_t i = 0; i < pRoot->GetNumChilds(); ++i ) { //---------------------------------------------------------------------- // Tip: New shader //---------------------------------------------------------------------- CXMLElement * pShaderBranch = pRoot->GetChild( i ); CStr sPath( "Shaders/" ); sPath.Add( pShaderBranch->GetName() ); // const CStr sShader( pShaderBranch->GetName() ); // CBaseShader * pShader = NEW CBaseShader( sShader.GetString() ); // CXMLAttr * pProgPath = pShaderBranch->GetAttr( "ProgramPath" ); // CStr sProgPath( pProgPath->GetValue() ); SysWrite( Va( "\tshader %s", pShaderBranch->GetName() ) ); IVertexDecl * pDecl = NULL; TUniform * pUniforms = NULL; uint nUnfmCount = 0; //---------------------------------------------------------------------- // Tip: Parse shader data //---------------------------------------------------------------------- for ( size_t j = 0; j < pShaderBranch->GetNumChilds(); ++j ) { CXMLElement * pStruct = pShaderBranch->GetChild( j ); const CStr sStruct( pStruct->GetName() ); if ( sStruct.Compare( "VertexFormat" ) ) { pDecl = ParseVertexFormat( pStruct ); } else if ( sStruct.Compare( "Constants" ) ) { /* pShader->m_nUniformCount = 1; pShader->m_pUniforms = NEW CBaseShader::TUniform [ pShader->m_nUniformCount ]; pShader->m_pUniforms[ 0 ].sName = "vColorMod"; pShader->m_pUniforms[ 0 ].eType = TYPE_VEC4; pShader->m_pUniforms[ 0 ].nLoc = pShader->GetUniformLoc( pShader->m_pUniforms[ 0 ].sName ); pShader->m_pUniforms[ 0 ].nCount = 1; m_ppShaders[ UI_SHADER ] = pShader; */ nUnfmCount = ParseConstants( pStruct, &pUniforms ); //pShader->ParseMaps( pStruct ); } } g_pRenderer->CreateShader( sPath.GetString(), pDecl, pUniforms, nUnfmCount ); } DEL( pRoot ); pRes->eState = TResource::LOADED; }
void CLandscape::Load( const char * szFileName ) { if ( !szFileName ) return; IFile * pFile = NULL; g_pVfs->OpenFile( &pFile, szFileName, VFS_READ | VFS_BINARY ); if ( !pFile ) return; byte * pHeightMap = NEW byte [ pFile->GetSize() ]; if ( pHeightMap ) g_pVfs->Read( pFile, pHeightMap, pFile->GetSize() ); g_pVfs->CloseFile( &pFile ); //m_vSize.Set( 128, 128 ); m_nTileCount = 16; m_pTiles = NEW CLandTile [ m_nTileCount ]; for ( uint y = 0; y < 4; ++y ) { for ( uint x = 0; x < 4; ++x ) { uint nOffset = ( 129 * y * CLandTile::SIDE_CELL_COUNT ) + ( CLandTile::SIDE_CELL_COUNT * x ); uint nTile = y * 4 + x; m_pTiles[ nTile ].Create( pHeightMap + nOffset, 129 ); } } /* // nrml for ( uint nTri = 0; nTri < m_nTriangleCount; ++nTri ) { int nOffset = nTri * 3; TVertex & v1 = pVertices[ m_pIndices[ nOffset++ ] ]; TVertex & v2 = pVertices[ m_pIndices[ nOffset++ ] ]; TVertex & v3 = pVertices[ m_pIndices[ nOffset ] ]; vec3 vNormal = Cross( v1.vPos - v3.vPos, v1.vPos - v2.vPos ); vNormal.Normalize(); /*v1.vNormal = vNormal; v2.vNormal = vNormal; v3.vNormal = vNormal;* }*/ DEL_ARRAY( pHeightMap ); m_pVDecl = g_pRenderer->CreateVertexDecl(); if ( m_pVDecl ) { m_pVDecl->SetStride( sizeof( TLandVertex ) ); m_pVDecl->AddAttr( "vPos", NULL, TYPE_VEC3, 0 ); m_pVDecl->AddAttr( "vTex0", NULL, TYPE_VEC2, sizeof( vec3 ) ); } }
bool CMayaMesh::FillMeshData() { //-------------------------------------------------------------------------- // Tip: Prepare arrays //-------------------------------------------------------------------------- /*MMatrix mModelMatrix = m_FnMesh.transformationMatrix(); mat4 m; for ( int mi = 0; mi < 4; ++mi ) { for ( int mj = 0; mj < 4; ++mj ) { m.pArray[ mi * 4 + mj ] = (float)mModelMatrix.matrix[ mi ][ mj ]; } }*/ //////////////////////////////////////////////////////////////////////////// ZeroMemory( &m_MeshData, sizeof( TMeshData ) ); m_MeshData.tHeader.nHeaderSize = sizeof( TMeshData::THeader ); m_MeshData.tHeader.nVertexCount = GetVertexCount(); m_MeshData.tHeader.nSurfCount = m_nSurfCount; if ( ( 0 == m_nSurfCount ) || ( 0 == m_MeshData.tHeader.nVertexCount ) ) { return false; } m_MeshData.tHeader.nComponentCount = 2; m_MeshData.pSurfaces = NEW TSurface [ m_nSurfCount ]; TVertex * pVB = NEW TVertex[ m_MeshData.tHeader.nVertexCount ]; m_MeshData.pComponents = NEW TVertexComponent[ m_MeshData.tHeader.nComponentCount ]; if ( ( NULL == m_MeshData.pSurfaces ) || ( NULL == pVB ) || ( NULL == m_MeshData.pComponents ) ) { DEL_ARRAY( m_MeshData.pSurfaces ); DEL_ARRAY( pVB ); DEL_ARRAY( m_MeshData.pComponents ); return false; } m_MeshData.pVertices = pVB; m_MeshData.tHeader.nVertexSize = sizeof( TVertex ); m_MeshData.pComponents[ 0 ].eType = TYPE_VEC3; m_MeshData.pComponents[ 0 ].nSize = sizeof( vec3 ); strcpy( m_MeshData.pComponents[ 0 ].szName, "vPos" ); m_MeshData.pComponents[ 1 ].eType = TYPE_VEC2; m_MeshData.pComponents[ 1 ].nSize = sizeof( vec2 ); strcpy( m_MeshData.pComponents[ 1 ].szName, "vTex0" ); //-------------------------------------------------------------------------- // Tip: Prepare arrays //-------------------------------------------------------------------------- for ( uint nID = 0; nID < m_nSurfCount; ++nID ) { TMayaSurface & tSurf = m_pSurfaces[ nID ]; TUVSet & tUVset = m_pUvSets[ 0 ]; // may not exist CUintVector & tUVindices = tSurf.ppUvIndices[ 0 ]; // may not exist for ( dword n = 0; n < tSurf.pIndices.GetCount(); ++n ) { int t = tUVindices[ n ]; int p = tSurf.pIndices[ n ]; pVB[ t ].vPos.Set( m_pVertices[ p ].x, m_pVertices[ p ].y, m_pVertices[ p ].z ); //pVB[ t ].vPos.Multiply( m ); //pBiNormals[ t ].Set(BiNormals[ p ].x, //BiNormals[ p ].y, //BiNormals[ p ].z ); pVB[ t ].vUV.Set( tUVset.pU[ t ], tUVset.pV[ t ] ); } if ( m_MeshData.pSurfaces ) { TSurface & tSurface = m_MeshData.pSurfaces[ nID ]; tSurface.tHeader.nIndexSize = sizeof( uint ); tSurface.tHeader.nIndexCount = tSurf.pIndices.GetCount(); tSurface.pIndices = tUVindices.GetArray(); strcpy( tSurface.tHeader.szName, tSurf.sName.asChar() ); } } return true; }
void CShaderCreator::FinalizeRes( TResource * pRes ) { // Компилируем шейдер -------------------------------------------------- ID3D10Blob * pByteCode = NULL; CShader * pShader = (CShader *)pRes->pResource; uint nConstBufferSize; const char * szEntry = NULL; const char * szProfile = NULL; bool bIsVertexShader = true; if ( CStr::FinishWith( pRes->sFileName.GetString(), ".vsh" ) ) { szEntry = "Ripple"; szProfile = "vs_4_0"; } else if ( CStr::FinishWith( pRes->sFileName.GetString(), ".psh" ) ) { szEntry = "main"; szProfile = "ps_4_0"; bIsVertexShader = false; } EResult rStatus = CompileShader( pRes->sFileName.GetString(), (const char *)pRes->pBuffer, szEntry, szProfile, &pByteCode ); // После компиляции исходный код уже не нужен DEL_ARRAY( pRes->pBuffer ); if ( R_OK != rStatus ) { // Компиляция провалилась pRes->eState = TResource::FAILED; return; } ID3D10ShaderReflection * pRef = NULL; HRESULT hRes; if ( bIsVertexShader ) { pShader->m_pByteCodeVS = pByteCode; // Обрабатываем переменные --------------------------------------------- hRes = D3D10ReflectShader( pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), &pRef ); if ( ( S_OK == hRes ) && ( NULL != pRef ) ) { D3D10_SHADER_DESC desc; pRef->GetDesc( &desc ); DEBUG_ASSERT( 1 == desc.ConstantBuffers ) // Перебираем каждый буффер констант for ( uint i = 0; i < desc.ConstantBuffers; ++i ) { ID3D10ShaderReflectionConstantBuffer * pCBuf = pRef->GetConstantBufferByIndex( i ); D3D10_SHADER_BUFFER_DESC bufDesc; pCBuf->GetDesc( &bufDesc ); const char * szCBName = bufDesc.Name; nConstBufferSize = bufDesc.Size; pShader->m_nUniformCount = bufDesc.Variables; pShader->m_pUniforms = NEW CShader::TUniform [ pShader->m_nUniformCount ]; // Перебираем каждую переменную в буффере for ( uint nVar = 0; nVar < bufDesc.Variables; ++nVar ) { ID3D10ShaderReflectionVariable * pVar = pCBuf->GetVariableByIndex( nVar ); D3D10_SHADER_VARIABLE_DESC varDesc; pVar->GetDesc( &varDesc ); CShader::TUniform & tUniform = pShader->m_pUniforms[ nVar ]; tUniform.sName = varDesc.Name; tUniform.nCount = varDesc.Size / sizeof( vec4 ); tUniform.nLoc = varDesc.StartOffset / sizeof( vec4 ); } } } hRes = g_pDevice->CreateVertexShader( pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), &pShader->m_pVS ); }