bool Shader::compileAndLinkFromFiles(const std::string& vertShaderFilename, const std::string& fragShaderFilename) { char* vertShaderSource; int vertShaderSize = _LoadFileToMemory(vertShaderFilename.c_str(), &vertShaderSource); if (vertShaderSize <= 0) { fprintf(stderr, "Shader::compileAndLinkFromFiles() Failed to load vertex shader \"%s\"\n", vertShaderFilename.c_str()); return false; } char* fragShaderSource; int fragShaderSize = _LoadFileToMemory(fragShaderFilename.c_str(), &fragShaderSource); if (fragShaderSize <= 0) { fprintf(stderr, "Shader::compileAndLinkFromFiles() Failed to load fragment shader \"%s\"\n", fragShaderFilename.c_str()); delete [] vertShaderSource; return false; } if (!_CompileShader(&m_vertShader, GL_VERTEX_SHADER, vertShaderSource, vertShaderSize)) { fprintf(stderr, "Shader::compileAndLinkFromFiles() Failed to compile vertex shader \"%s\"\n", vertShaderFilename.c_str()); _DumpShaderInfoLog(m_vertShader); glDeleteShader(m_vertShader); m_vertShader = 0; return false; } if (!_CompileShader(&m_fragShader, GL_FRAGMENT_SHADER, fragShaderSource, fragShaderSize)) { fprintf(stderr, "Shader::compileAndLinkFromFiles() Failed to compile fragment shader \"%s\"\n", fragShaderFilename.c_str()); _DumpShaderInfoLog(m_fragShader); glDeleteShader(m_fragShader); m_fragShader = 0; return false; } if (!_Link(&m_program, m_vertShader, m_fragShader)) { fprintf(stderr, "Shader::compileAndLinkFromFiles() Failed to link shaders \"%s\" and \"%s\"\n", vertShaderFilename.c_str(), fragShaderFilename.c_str()); _DumpProgramInfoLog(m_program); glDeleteProgram(m_program); m_program = 0; return false; } m_vertShaderFilename = vertShaderFilename; m_fragShaderFilename = fragShaderFilename; buildVarMaps(); return true; }
/** * 頂点プログラムをコンパイル */ BOOL CPostEffectConverter::CompileVertexProgram( BOOL bIsAsm, LPCSTR lpszCompileCommand, LPCSTR lpszShaderFile, LPCSTR lpszObjDir) { CCompileCmdCreator::GetInstance().SetIsVS(TRUE); IZ_UINT nPassCnt = 0; CGtechnique tech = ::cgGetFirstTechnique(m_pCgEffect); while (tech != NULL) { CGpass pass = ::cgGetFirstPass(tech); while (pass != NULL) { SVSInfo sVSInfo; // 出力ファイル名を作成 _MakeOutFile( sVSInfo.file, nPassCnt, lpszShaderFile, lpszObjDir); CGprogram progVS = CPassUtil::GetVSProgram(pass); IZ_PCSTR pszEntryPoint = ::cgGetProgramString(progVS, CG_PROGRAM_ENTRY); IZ_PCSTR pszProfile = ::cgGetProgramString(progVS, CG_PROGRAM_PROFILE); CGprofile profile = ::cgGetProfile(pszProfile); // コンパイル if (!_CompileShader( sVSInfo.file, bIsAsm, lpszCompileCommand, lpszShaderFile, pszEntryPoint, profile)) { IZ_ASSERT(FALSE); // TODO return FALSE; } sVSInfo.type = CPostEffectConvUtil::GetVtxShaderType(pszEntryPoint); m_CompiledVSList.push_back(sVSInfo); nPassCnt++; pass = ::cgGetNextPass(pass); } tech = ::cgGetNextTechnique(tech); } return TRUE; }
bool D3D11DrawConfig::CompileVertexShader(const std::string &target, const std::string &entry, const std::string &source, ID3D11InputLayout ** ppInputLayout, D3D11_INPUT_ELEMENT_DESC const * pInputElementDescs, int numInputElements, ID3D11Device * pd3dDevice) { ID3DBlob * pBlob = NULL; pBlob = _CompileShader(target, entry, source); HRESULT hr = pd3dDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &_vertexShader); if (FAILED(hr)) { return false; } if (ppInputLayout && !*ppInputLayout) { hr = pd3dDevice->CreateInputLayout( pInputElementDescs, numInputElements, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), ppInputLayout); if (FAILED(hr)) { return false; } } if (pBlob) pBlob->Release(); return true; }
/** * ピクセルプログラムをコンパイル */ BOOL CPostEffectConverter::CompilePixelProgram( BOOL bIsAsm, LPCSTR lpszCompileCommand, LPCSTR lpszShaderFile, LPCSTR lpszObjDir) { CCompileCmdCreator::GetInstance().SetIsVS(FALSE); IZ_UINT nPassCnt = 0; CGtechnique tech = ::cgGetFirstTechnique(m_pCgEffect); while (tech != NULL) { CGpass pass = ::cgGetFirstPass(tech); while (pass != NULL) { // 出力ファイル名を作成 izanagi::tool::CString strOut; _MakeOutFile( strOut, nPassCnt, lpszShaderFile, lpszObjDir); CGprogram progPS = CPassUtil::GetPSProgram(pass); IZ_PCSTR pszEntryPoint = ::cgGetProgramString(progPS, CG_PROGRAM_ENTRY); IZ_PCSTR pszProfile = ::cgGetProgramString(progPS, CG_PROGRAM_PROFILE); CGprofile profile = ::cgGetProfile(pszProfile); // コンパイル if (!_CompileShader( strOut, bIsAsm, lpszCompileCommand, lpszShaderFile, pszEntryPoint, profile)) { IZ_ASSERT(FALSE); // TODO return FALSE; } m_CompiledPSList.push_back(strOut); nPassCnt++; pass = ::cgGetNextPass(pass); } tech = ::cgGetNextTechnique(tech); } return TRUE; }
bool D3D11DrawConfig::CompilePixelShader(const std::string &target, const std::string &entry, const std::string &source, ID3D11Device * pd3dDevice) { ID3DBlob * pBlob = NULL; pBlob = _CompileShader(target, entry, source); HRESULT hr = pd3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &_pixelShader); if (FAILED(hr)) { return false; } if (pBlob) pBlob->Release(); return true; }
VertexShaderPtr CShaderManager::CompileVertexShader(xst_castring& strName, xst_castring& strEntryPoint, u32 uInputLayoutElementIds, xst_castring& strCode, xst_castring& strGroupName) { /*ShaderPtr pShader = _CreateShader( ShaderTypes::VERTEX, strName, strEntryPoint, strGroupName ); if( pShader == xst_null ) { return pShader; } VertexShaderPtr pVS( pShader ); pVS->SetInputLayout( m_pRenderSystem->GetInputLayout( uInputLayoutElementIds ) ); if( XST_FAILED( pVS->Compile( strEntryPoint, ShaderProfiles::VS_BEST, strCode ) ) ) { this->DestroyResource( pVS ); return VertexShaderPtr(); } pVS->m_iResourceState = Resources::ResourceStates::PREPARED; return pVS;*/ return _CompileShader( ShaderTypes::VERTEX, ShaderProfiles::VS_BEST, strName, strEntryPoint, m_pRenderSystem->GetInputLayout( uInputLayoutElementIds ), strCode, strGroupName ); }
BOOL CShaderConverter::CompileProgram( BOOL bIsVS, const SShaderConfig& config, LPCSTR lpszObjDir) { CCompileCmdCreator::GetInstance(config.type).SetIsVS(FALSE); IZ_UINT nPassCnt = 0; CGtechnique tech = ::cgGetFirstTechnique(m_pCgEffect); while (tech != NULL) { CGpass pass = ::cgGetFirstPass(tech); while (pass != NULL) { // 出力ファイル名を作成 izanagi::tool::CString strOut; _MakeOutFile( strOut, nPassCnt, config.shader, lpszObjDir); CCompileCmdCreator::GetInstance(config.type).SetIsVS(bIsVS); CGprogram program = (bIsVS ? CPassUtil::GetVSProgram(pass) : CPassUtil::GetPSProgram(pass)); IZ_PCSTR entry = ::cgGetProgramString(program, CG_PROGRAM_ENTRY); IZ_PCSTR pszProfile = ::cgGetProgramString(program, CG_PROGRAM_PROFILE); CGprofile profile = ::cgGetProfile(pszProfile); // コンパイル if (!_CompileShader( strOut, config, entry, profile)) { IZ_ASSERT(FALSE); // TODO return FALSE; } if (bIsVS) { m_CompiledVSList.push_back(strOut); } else { m_CompiledPSList.push_back(strOut); } nPassCnt++; pass = ::cgGetNextPass(pass); } tech = ::cgGetNextTechnique(tech); } return TRUE; }
OsdD3D11DrawConfig* OsdD3D11DrawRegistryBase::_CreateDrawConfig( DescType const & desc, SourceConfigType const * sconfig, ID3D11Device * pd3dDevice, ID3D11InputLayout ** ppInputLayout, D3D11_INPUT_ELEMENT_DESC const * pInputElementDescs, int numInputElements) { assert(sconfig); ID3DBlob * pBlob; ID3D11VertexShader *vertexShader = NULL; if (! sconfig->vertexShader.source.empty()) { pBlob = _CompileShader(sconfig->commonShader, sconfig->vertexShader); pd3dDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &vertexShader); assert(vertexShader); if (ppInputLayout and !*ppInputLayout) { pd3dDevice->CreateInputLayout(pInputElementDescs, numInputElements, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), ppInputLayout); assert(ppInputLayout); } SAFE_RELEASE(pBlob); } ID3D11HullShader *hullShader = NULL; if (! sconfig->hullShader.source.empty()) { pBlob = _CompileShader(sconfig->commonShader, sconfig->hullShader); pd3dDevice->CreateHullShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &hullShader); assert(hullShader); SAFE_RELEASE(pBlob); } ID3D11DomainShader *domainShader = NULL; if (! sconfig->domainShader.source.empty()) { pBlob = _CompileShader(sconfig->commonShader, sconfig->domainShader); pd3dDevice->CreateDomainShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &domainShader); assert(domainShader); SAFE_RELEASE(pBlob); } ID3D11GeometryShader *geometryShader = NULL; if (! sconfig->geometryShader.source.empty()) { pBlob = _CompileShader(sconfig->commonShader, sconfig->geometryShader); pd3dDevice->CreateGeometryShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &geometryShader); assert(geometryShader); SAFE_RELEASE(pBlob); } ID3D11PixelShader *pixelShader = NULL; if (! sconfig->pixelShader.source.empty()) { pBlob = _CompileShader(sconfig->commonShader, sconfig->pixelShader); pd3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &pixelShader); assert(pixelShader); SAFE_RELEASE(pBlob); } OsdD3D11DrawConfig * config = _NewDrawConfig(); config->vertexShader = vertexShader; config->hullShader = hullShader; config->domainShader = domainShader; config->geometryShader = geometryShader; config->pixelShader = pixelShader; return config; }