void FileSystemLayer::getConfigPaths() { #if U2_PLATFORM == U2_PLATFORM_WIN32 // try to determine the application's path DWORD bufsize = 256; char* resolved = 0; do { char* buf = U2_ALLOC_T(char, bufsize, MEMCATEGORY_GENERAL); DWORD retval = GetModuleFileNameA(NULL, buf, bufsize); if (retval == 0) { // failed U2_FREE(buf, MEMCATEGORY_GENERAL); break; } if (retval < bufsize) { // operation was successful. resolved = buf; } else { // buffer was too small, grow buffer and try again U2_FREE(buf, MEMCATEGORY_GENERAL); bufsize <<= 1; } } while (!resolved); String appPath = resolved; if (resolved) U2_FREE(resolved, MEMCATEGORY_GENERAL); if (!appPath.empty()) { // need to strip the application filename from the path String::size_type pos = appPath.rfind('\\'); if (pos != String::npos) appPath.erase(pos); } else { // fall back to current working dir appPath = "."; } #elif U2_PLATFORM == U2_PLATFORM_WINRT String appPath; if(!widePathToOgreString(appPath, Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data())) { // fallback to current working dir appPath = "."; } #endif // use application path as config search path mConfigPaths.push_back(appPath + '\\'); }
void U2MultiTextureEffect::SetTextureCnt(uint32 uTextureCnt) { U2ASSERT(uTextureCnt > 0); m_uTextureCnt = uTextureCnt; U2_FREE(m_ppTextureNameArray); m_ppTextureNameArray = NULL; m_ppTextureNameArray = U2_ALLOC(U2DynString*, m_uTextureCnt); memset(m_ppTextureNameArray, 0, sizeof(U2DynString*) * m_uTextureCnt); m_alphaStateArray.Resize(m_uTextureCnt); SetDefaultAlphaState(); }
bool U2D3DXEffectShader::LoadResource() { U2ASSERT(0 == m_pD3DEffect); HRESULT hr; IDirect3DDevice9* pD3DDev = m_pRenderer->GetD3DDevice(); U2ASSERT(pD3DDev); U2FilePath fPath; TCHAR fullPath[MAX_PATH]; // StackString Memory Leak... U2DynString includePath(FX_SHADER_PATH); includePath += _T("\\2.0"); fPath.ConvertToAbs(fullPath, MAX_PATH * sizeof(TCHAR) , m_szFilename.Str(), includePath); U2File* pFile = U2File::GetFile(fullPath, U2File::READ_ONLY); if(!pFile) { U2_DELETE pFile; return false; } uint32 uBuffLen = pFile->GetfileSize(); if(uBuffLen == 0) { U2_DELETE pFile; return false; } unsigned char* pBuffer = U2_ALLOC(unsigned char, uBuffLen); pFile->Read(pBuffer, uBuffLen); U2_DELETE pFile; ID3DXBuffer* pErrorBuffer = NULL; #ifdef DEBUG_SHADER DWORD compileFlags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL | D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT | D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT ; #else DWORD compileFlags = D3DXSHADER_USE_LEGACY_D3DX9_31_DLL; #endif //U2DynString includePath(FX_SHADER_PATH); //includePath += _T("\\2.0"); U2D3DXEffectShaderInclude includeHandler(includePath); ID3DXEffectPool* pEffectPool = m_pRenderer->GetD3DEffectPool(); U2ASSERT(pEffectPool); // get the highest supported shader profiles // LPCSTR vsProfile, psProfile; //#ifdef UNICODE // vsProfile = ToUnicode( D3DXGetVertexShaderProfile(pD3DDev) ); // psProfile = ToUnicode( D3DXGetPixelShaderProfile(pD3DDev) ); //#else // vsProfile = D3DXGetVertexShaderProfile(pD3DDev); // psProfile = D3DXGetPixelShaderProfile(pD3DDev); //#endif LPCSTR vsProfile = D3DXGetVertexShaderProfile(pD3DDev); LPCSTR psProfile = D3DXGetPixelShaderProfile(pD3DDev); if (0 == vsProfile) { FDebug("Invalid Vertex Shader profile! Fallback to vs_2_0!\n"); vsProfile = "vs_2_0"; } if (0 == psProfile) { FDebug("Invalid Pixel Shader profile! Fallback to ps_2_0!\n"); psProfile = "ps_2_0"; } // create macro definitions for shader compiler D3DXMACRO defines[] = { { "VS_PROFILE", vsProfile }, { "PS_PROFILE", psProfile }, { 0, 0 }, }; // create effect if (compileFlags) { hr = D3DXCreateEffectFromFile( pD3DDev, // pDevice fullPath, // File name defines, // pDefines &includeHandler, // pInclude compileFlags, // Flags pEffectPool, // pPool &m_pD3DEffect, // ppEffect &pErrorBuffer); // ppCompilationErrors } else { hr = D3DXCreateEffect( pD3DDev, // pDevice pBuffer, // pFileData uBuffLen, // DataSize defines, // pDefines &includeHandler, // pInclude compileFlags, // Flags pEffectPool, // pPool &(m_pD3DEffect), // ppEffect &pErrorBuffer); // ppCompilationErrors } U2_FREE(pBuffer); pBuffer = NULL; if (FAILED(hr)) { FDebug("nD3D9Shader: failed to load fx file '%s' with:\n\n%s\n", fullPath, pErrorBuffer ? pErrorBuffer->GetBufferPointer() : "No D3DX error message."); if (pErrorBuffer) { pErrorBuffer->Release(); } return false; } U2ASSERT(m_pD3DEffect); m_bValidated = false; m_bNotValidate = false; this->ValidateEffect(); return true; }
U2MultiTextureEffect::~U2MultiTextureEffect() { U2_FREE(m_ppTextureNameArray); m_ppTextureNameArray = NULL; }