void CEffect::CreateEffect(CHAR * szFxFile) { char file[MAX_PATH]; InsertDirectoryEx(g_szFileDir, szFxFile, file); DWORD flags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined (DEBUG) | (_DEBUG) flags |= D3D10_CREATE_DEVICE_DEBUG; #endif ID3D10Blob * errors = NULL; D3DX10CreateEffectFromFileA(file, NULL, NULL, "fx_4_0", flags, 0, g_pD3DDevice, NULL, NULL, &m_pEffect, &errors, NULL); if (errors) { MessageBoxA(0, (char*)errors->GetBufferPointer(), 0, 0); _DestroyProcess(); } else if (!m_pEffect) { DxUtSendErrorEx("CreateEffect could not create ID3DX10Effect from file.", file); } ReleaseX(errors); }
bool DX10_Renderer::BuildFX(std::string _fxFileName, std::string _techniqueName, ID3D10Effect*& _prFX, ID3D10EffectTechnique*& _prTech) { ID3D10Effect* pFX = 0; ID3D10EffectTechnique* pTech = 0; // Checking if the Effects file is already loaded std::map<std::string, ID3D10Effect*>::iterator fxCheck; fxCheck = m_fxFiles.find(_fxFileName); // Check if the FX file has already been created if (fxCheck != m_fxFiles.end()) { // FX file already exists, save the Pointer pFX = fxCheck->second; } else { // Set the shader flags to enforce strictness DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) // Addition shader flags for information in DEBUG mode only shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors; // Add the directory path from the DX10Render file to the stored FX files std::string fxfilePath = "Resources/FX/" + _fxFileName; // Create the FX file from the input file string VALIDATEHR(D3DX10CreateEffectFromFileA(fxfilePath.c_str(), 0, 0, "fx_4_0", shaderFlags, 0, m_pDX10Device, 0, 0, &pFX, &compilationErrors, 0)); ReleaseCOM(compilationErrors); // Create the pairs to be inserted into the appropriate FX Maps std::pair<std::string, ID3D10Effect*> fxPair(_fxFileName, pFX); // Insert the pairs into their respective Maps VALIDATE(m_fxFiles.insert(fxPair).second); } // Adding the Technique to the Map // Retrieve the Technique IDs map using the FX ID to get a Map of all techniques for that particular FX file std::map<std::string, std::map<std::string, ID3D10EffectTechnique*>>::iterator fxNameCheck; fxNameCheck = m_techniques.find(_fxFileName); // Check if the FX file already has techniques stored for it if (fxNameCheck != m_techniques.end()) { // Search the Inner Map (of Techs by FX ID) to check if the Technique has already been created std::map<std::string, ID3D10EffectTechnique*>::iterator techNameCheck; techNameCheck = fxNameCheck->second.find(_techniqueName); if (techNameCheck != fxNameCheck->second.end()) { // Technique already exists, save the ID pTech = techNameCheck->second; } else { // Technique has not been created so Retrieve the Tech from the FX file pTech = pFX->GetTechniqueByName(_techniqueName.c_str()); if (pTech == NULL) { // technique was not found return false; } // Create pairs to store in the Technique Maps std::pair<std::string, ID3D10EffectTechnique*> techPair(_techniqueName, pTech); // Insert the pairs into their respective Maps VALIDATE((&fxNameCheck->second)->insert(techPair).second); } } else { // Technique has not been created so Retrieve the Tech from the FX file pTech = pFX->GetTechniqueByName(_techniqueName.c_str()); if (pTech == NULL) { // technique was not found return false; } // Create pairs to store in the Technique Maps std::map<std::string, ID3D10EffectTechnique*> innerTechMap; std::pair<std::string, ID3D10EffectTechnique*> innerTechPair(_techniqueName, pTech); VALIDATE(innerTechMap.insert(innerTechPair).second); std::pair<std::string, std::map<std::string, ID3D10EffectTechnique*>> outerTechMap(_fxFileName, innerTechMap); VALIDATE(m_techniques.insert(outerTechMap).second); } // Save the FX and Technique IDs in the memory passed by the Object. _prFX = pFX; _prTech = pTech; return true; }