const char *S9xGetDirectory (enum s9x_getdirtype dirtype) { static char path[PATH_MAX]={0}; strncpy(path,_tToChar(S9xGetDirectoryT(dirtype)),PATH_MAX-1); return path; }
bool CDirect3D::SetShaderHLSL(const TCHAR *file) { //MUDLORD: the guts //Compiles a shader from files on disc //Sets LUT textures to texture files in PNG format. TCHAR folder[MAX_PATH]; TCHAR rubyLUTfileName[MAX_PATH]; TCHAR *slash; char *shaderText = NULL; TCHAR errorMsg[MAX_PATH + 50]; IXMLDOMDocument * pXMLDoc = NULL; IXMLDOMElement * pXDE = NULL; IXMLDOMNode * pXDN = NULL; BSTR queryString, nodeContent; HRESULT hr; shaderTimer = 1.0f; shaderTimeStart = 0; shaderTimeElapsed = 0; if(effect) { effect->Release(); effect = NULL; } for(int i = 0; i < MAX_SHADER_TEXTURES; i++) { if (rubyLUT[i] != NULL) { rubyLUT[i]->Release(); rubyLUT[i] = NULL; } } if (file == NULL || *file==TEXT('\0')) return true; hr = CoCreateInstance(CLSID_DOMDocument,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pXMLDoc)); if(FAILED(hr)) { MessageBox(NULL, TEXT("Error creating XML Parser"), TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); return false; } VARIANT fileName; VARIANT_BOOL ret; fileName.vt = VT_BSTR; #ifdef UNICODE fileName.bstrVal = SysAllocString(file); #else wchar_t tempfilename[MAX_PATH]; MultiByteToWideChar(CP_UTF8,0,file,-1,tempfilename,MAX_PATH); fileName.bstrVal = SysAllocString(tempfilename); #endif hr = pXMLDoc->load(fileName,&ret); SysFreeString(fileName.bstrVal); if(FAILED(hr) || hr==S_FALSE) { _stprintf(errorMsg,TEXT("Error loading HLSL shader file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); pXMLDoc->Release(); return false; } VARIANT attributeValue; BSTR attributeName; hr = pXMLDoc->get_documentElement(&pXDE); if(FAILED(hr) || hr==S_FALSE) { _stprintf(errorMsg,TEXT("Error loading root element from file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); pXMLDoc->Release(); return false; } attributeName=SysAllocString(L"language"); pXDE->getAttribute(attributeName,&attributeValue); SysFreeString(attributeName); pXDE->Release(); if(attributeValue.vt!=VT_BSTR || lstrcmpiW(attributeValue.bstrVal,L"hlsl")) { _stprintf(errorMsg,TEXT("Shader language is <%s>, expected <HLSL> in file:\n%s"),attributeValue.bstrVal,file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal); pXMLDoc->Release(); return false; } if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal); queryString=SysAllocString(L"/shader/source"); hr = pXMLDoc->selectSingleNode(queryString,&pXDN); SysFreeString(queryString); if(hr == S_OK) { hr = pXDN->get_text(&nodeContent); if(hr == S_OK) { int requiredChars = WideCharToMultiByte(CP_ACP,0,nodeContent,-1,shaderText,0,NULL,NULL); shaderText = new char[requiredChars]; WideCharToMultiByte(CP_UTF8,0,nodeContent,-1,shaderText,requiredChars,NULL,NULL); } SysFreeString(nodeContent); pXDN->Release(); pXDN = NULL; } pXMLDoc->Release(); if(!shaderText) { _stprintf(errorMsg,TEXT("No HLSL shader program in file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); return false; } LPD3DXBUFFER pBufferErrors = NULL; hr = D3DXCreateEffect( pDevice,shaderText,strlen(shaderText),NULL, NULL, D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, NULL, &effect, &pBufferErrors ); delete[] shaderText; if( FAILED(hr) ) { _stprintf(errorMsg,TEXT("Error parsing HLSL shader file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); if(pBufferErrors) { LPVOID pCompilErrors = pBufferErrors->GetBufferPointer(); MessageBox(NULL, (const TCHAR*)pCompilErrors, TEXT("FX Compile Error"), MB_OK|MB_ICONEXCLAMATION); } return false; } lstrcpy(folder,file); slash = _tcsrchr(folder,TEXT('\\')); if(slash) *(slash+1)=TEXT('\0'); else *folder=TEXT('\0'); SetCurrentDirectory(S9xGetDirectoryT(DEFAULT_DIR)); for(int i = 0; i < MAX_SHADER_TEXTURES; i++) { _stprintf(rubyLUTfileName, TEXT("%srubyLUT%d.png"), folder, i); hr = D3DXCreateTextureFromFile(pDevice,rubyLUTfileName,&rubyLUT[i]); if FAILED(hr){ rubyLUT[i] = NULL; } } D3DXHANDLE hTech; effect->FindNextValidTechnique(NULL,&hTech); effect->SetTechnique( hTech ); shader_type = D3D_SHADER_HLSL; return true; }
bool CDirect3D::SetShaderHLSL(const TCHAR *file) { //MUDLORD: the guts //Compiles a shader from files on disc //Sets LUT textures to texture files in PNG format. TCHAR folder[MAX_PATH]; TCHAR rubyLUTfileName[MAX_PATH]; TCHAR *slash; TCHAR errorMsg[MAX_PATH + 50]; shaderTimer = 1.0f; shaderTimeStart = 0; shaderTimeElapsed = 0; if(effect) { effect->Release(); effect = NULL; } for(int i = 0; i < MAX_SHADER_TEXTURES; i++) { if (rubyLUT[i] != NULL) { rubyLUT[i]->Release(); rubyLUT[i] = NULL; } } if (file == NULL || *file==TEXT('\0')) return true; CXML xml; if(!xml.loadXmlFile(file)) return false; TCHAR *lang = xml.getAttribute(TEXT("/shader"),TEXT("language")); if(lstrcmpi(lang,TEXT("hlsl"))) { _stprintf(errorMsg,TEXT("Shader language is <%s>, expected <HLSL> in file:\n%s"),lang,file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); return false; } TCHAR *shaderText = xml.getNodeContent(TEXT("/shader/source")); if(!shaderText) { _stprintf(errorMsg,TEXT("No HLSL shader program in file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); return false; } LPD3DXBUFFER pBufferErrors = NULL; #ifdef UNICODE HRESULT hr = D3DXCreateEffect( pDevice,WideToCP(shaderText,CP_ACP),strlen(WideToCP(shaderText,CP_ACP)),NULL, NULL, D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, NULL, &effect, &pBufferErrors ); #else HRESULT hr = D3DXCreateEffect( pDevice,shaderText,strlen(shaderText),NULL, NULL, D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, NULL, &effect, &pBufferErrors ); #endif if( FAILED(hr) ) { _stprintf(errorMsg,TEXT("Error parsing HLSL shader file:\n%s"),file); MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION); if(pBufferErrors) { LPVOID pCompilErrors = pBufferErrors->GetBufferPointer(); MessageBox(NULL, (const TCHAR*)pCompilErrors, TEXT("FX Compile Error"), MB_OK|MB_ICONEXCLAMATION); } return false; } lstrcpy(folder,file); slash = _tcsrchr(folder,TEXT('\\')); if(slash) *(slash+1)=TEXT('\0'); else *folder=TEXT('\0'); SetCurrentDirectory(S9xGetDirectoryT(DEFAULT_DIR)); for(int i = 0; i < MAX_SHADER_TEXTURES; i++) { _stprintf(rubyLUTfileName, TEXT("%srubyLUT%d.png"), folder, i); hr = D3DXCreateTextureFromFile(pDevice,rubyLUTfileName,&rubyLUT[i]); if FAILED(hr){ rubyLUT[i] = NULL; } } D3DXHANDLE hTech; effect->FindNextValidTechnique(NULL,&hTech); effect->SetTechnique( hTech ); shader_type = D3D_SHADER_HLSL; return true; }