CPixelBufferView::EffectPtr CPixelBufferView::CreateEffectFromResource(const TCHAR* resourceName) { HRESULT result = S_OK; HRSRC shaderResourceInfo = FindResource(GetModuleHandle(nullptr), resourceName, _T("TEXTFILE")); assert(shaderResourceInfo != nullptr); HGLOBAL shaderResourceHandle = LoadResource(GetModuleHandle(nullptr), shaderResourceInfo); DWORD shaderResourceSize = SizeofResource(GetModuleHandle(nullptr), shaderResourceInfo); const char* shaderData = reinterpret_cast<const char*>(LockResource(shaderResourceHandle)); EffectPtr effect; Framework::Win32::CComPtr<ID3DXBuffer> errors; result = D3DXCreateEffect(m_device, shaderData, shaderResourceSize, nullptr, nullptr, 0, nullptr, &effect, &errors); if(!errors.IsEmpty()) { std::string errorText(reinterpret_cast<const char*>(errors->GetBufferPointer()), reinterpret_cast<const char*>(errors->GetBufferPointer()) + errors->GetBufferSize()); OutputDebugStringA("Failed to compile shader:\r\n"); OutputDebugStringA(errorText.c_str()); } assert(SUCCEEDED(result)); UnlockResource(shaderResourceHandle); return effect; }
void CDx11Effect::CompilePixelShader(const std::string& shaderText) { assert(m_pixelShader.IsEmpty()); Framework::Win32::CComPtr<ID3DBlob> pixelShaderCode; Framework::Win32::CComPtr<ID3DBlob> pixelShaderErrors; UINT compileFlags = 0; #ifdef _DEBUG compileFlags |= D3DCOMPILE_DEBUG; #endif HRESULT result = D3DCompile(shaderText.c_str(), shaderText.length() + 1, "ps", nullptr, nullptr, "PixelProgram", "ps_5_0", compileFlags, 0, &pixelShaderCode, &pixelShaderErrors); if(FAILED(result)) { if(!pixelShaderErrors.IsEmpty()) { OutputDebugStringA(shaderText.c_str()); OutputDebugStringA("\r\n"); OutputDebugStringA(reinterpret_cast<const char*>(pixelShaderErrors->GetBufferPointer())); } DebugBreak(); } result = m_device->CreatePixelShader(pixelShaderCode->GetBufferPointer(), pixelShaderCode->GetBufferSize(), nullptr, &m_pixelShader); assert(SUCCEEDED(result)); }