本文整理汇总了C++中D3DCompileFromFile函数的典型用法代码示例。如果您正苦于以下问题:C++ D3DCompileFromFile函数的具体用法?C++ D3DCompileFromFile怎么用?C++ D3DCompileFromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了D3DCompileFromFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: D3DCompileFromFile
bool ShaderClass::createGeometryShader(ID3D11Device* pDevice, WCHAR* fileName, CHAR* EntryPoint, ID3D11GeometryShader** ppGShader)
{
HRESULT hr;
// Initialie Geometry shader
ID3D10Blob* geometryShaderBuffer;
ID3D10Blob* errorMessages;
hr = D3DCompileFromFile(
fileName,
NULL,
NULL,
EntryPoint,
"gs_5_0",
0,
0,
&geometryShaderBuffer,
&errorMessages);
if (FAILED(hr))
{
// If the shader failed to compile it should have writen something to the error message.
if (errorMessages)
{
OutputShaderErrorMessage(errorMessages, fileName);
return false;
}
// If there was nothing in the error message then it simply could not find the shader file itself.
else
{
MessageBox(0, fileName, L"Missing Shader File", MB_OK);
return false;
}
}
// Create the geometry shader from the buffer.
hr = pDevice->CreateGeometryShader(geometryShaderBuffer->GetBufferPointer(), geometryShaderBuffer->GetBufferSize(), NULL, ppGShader);
if (FAILED(hr))
{
MessageBox(0, L"Failed to create geometry shader", 0, MB_OK);
return false;
}
geometryShaderBuffer->Release();
return true;
}
示例2: CompileComputeShader
//Helper for compiling compute shaders taken from DirectX documentation
HRESULT CompileComputeShader(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint,
_In_ ID3D11Device* device, _Outptr_ ID3DBlob** blob)
{
if (!srcFile || !entryPoint || !device || !blob)
return E_INVALIDARG;
*blob = nullptr;
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3DCOMPILE_DEBUG;
#endif
// We generally prefer to use the higher CS shader profile when possible as CS 5.0 is better performance on 11-class hardware
LPCSTR profile = (device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0) ? "cs_5_0" : "cs_4_0";
const D3D_SHADER_MACRO defines[] =
{
"EXAMPLE_DEFINE", "1",
NULL, NULL
};
ID3DBlob* shaderBlob = nullptr;
ID3DBlob* errorBlob = nullptr;
HRESULT hr = D3DCompileFromFile(srcFile, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE,
entryPoint, profile,
flags, 0, &shaderBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob)
{
OutputDebugStringA((char*)errorBlob->GetBufferPointer());
errorBlob->Release();
}
if (shaderBlob)
shaderBlob->Release();
return hr;
}
*blob = shaderBlob;
return hr;
}
示例3: D3DCompileFromFile
int ShaderClass::CreatePixelShader(ID3D11PixelShader** ppPS, WCHAR* fileName, char* EntryPoint)
{
HRESULT hr;
// Initialie Pixel shader
ID3D10Blob* pixelShaderBuffer;
ID3D10Blob* errorMessages;
hr = D3DCompileFromFile(
fileName,
NULL,
NULL,
EntryPoint,
"ps_5_0",
0,
0,
&pixelShaderBuffer,
&errorMessages);
if (FAILED(hr))
{
// If the shader failed to compile it should have writen something to the error message.
if (errorMessages)
{
OutputShaderErrorMessage(errorMessages, fileName);
return -26;
}
// If there was nothing in the error message then it simply could not find the shader file itself.
else
{
MessageBox(0, fileName, L"Missing Shader File", MB_OK);
return -27;
}
}
// Create the pixel shader from the buffer.
hr = SystemClass::GetInstance()->mGrapInst->GetDevice()->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, ppPS);
if (FAILED(hr))
{
MessageBox(0, L"Failed to create pixel shader", 0, MB_OK);
return -28;
}
pixelShaderBuffer->Release();
return 0;
}
示例4: strlen
/*
* Class: org_lwjgl_d3d11_impl_d3dcompiler
* Method: nD3DCompileFromFile
* Signature: (JJJJJIIJJ)I
*/
extern "C" JNIEXPORT jint JNICALL Java_org_lwjgl_d3d11_impl_d3dcompiler_nD3DCompileFromFile
(JNIEnv * env, jclass clazz, jlong fileNamePtr, jlong definesPtr, jlong includePtr, jlong entryPointPtr,
jlong targetPtr, jint flags1, jint flags2, jlong codeOutPtr, jlong errorMsgsOutPtr) {
const char* fileNameCStr = (const char*)(intptr_t)fileNamePtr;
size_t fileNameSize = strlen(fileNameCStr) + 1;
wchar_t* wstr = (wchar_t*)malloc(sizeof(wchar_t) * fileNameSize);
mbstowcs(wstr, fileNameCStr, fileNameSize);
const D3D_SHADER_MACRO* defines = (const D3D_SHADER_MACRO*)(intptr_t)definesPtr;
ID3DInclude* include = (ID3DInclude*)includePtr;
LPCSTR entryPoint = (LPCSTR)(intptr_t)entryPointPtr;
LPCSTR target = (LPCSTR)(intptr_t)targetPtr;
UINT Flags1 = (UINT)flags1;
UINT Flags2 = (UINT)flags2;
ID3DBlob** codeOut = (ID3DBlob**)(intptr_t)codeOutPtr;
ID3DBlob** errorMsgsOut = (ID3DBlob**)(intptr_t)errorMsgsOutPtr;
HRESULT res = D3DCompileFromFile(wstr, defines, include, entryPoint, target, Flags1, Flags2, codeOut, errorMsgsOut);
free(wstr);
return (jint)res;
}
示例5: afCompileShader
ComPtr<ID3DBlob> afCompileShader(const char* name, const char* entryPoint, const char* target)
{
char path[MAX_PATH];
sprintf_s(path, sizeof(path), "%s.hlsl", name);
// sprintf_s(path, sizeof(path), "hlsl/%s.hlsl", name);
#ifdef _DEBUG
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
#else
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#endif
ComPtr<ID3DBlob> blob, err;
WCHAR wname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, path, -1, wname, dimof(wname));
D3DCompileFromFile(wname, nullptr, nullptr, entryPoint, target, flags, 0, &blob, &err);
if (err) {
MessageBoxA(nullptr, (const char*)err->GetBufferPointer(), name, MB_OK | MB_ICONERROR);
}
return blob;
}
示例6:
std::shared_ptr<Shader> Shader::CreateFromFile(RenderDevice* device, ShaderType type, const char* filePath)
{
std::shared_ptr<Shader> shader;
CComPtr<ID3DBlob> errorBlob;
CComPtr<ID3DBlob> shaderBlob;
if (SUCCEEDED(D3DCompileFromFile(convert(filePath).c_str(),
nullptr, nullptr, D3D11::ToShaderEntryPoint(type), D3D11::ToShaderLevel(type), 0, 0, &shaderBlob, &errorBlob)))
{
std::string debugName = filePath;
shader = Shader::CreateFromBlob(device, type, shaderBlob, "Shader: " + debugName);
}
else
{
const char* errorText = (const char*)errorBlob->GetBufferPointer();
TalonLog(errorText);
}
return shader;
}
示例7: MultiByteToWideChar
int EffectSystemD3D11::CreateEffect(const char *path)
{
// 先把char转成wchar_t
int wchar_size = MultiByteToWideChar(CP_ACP, 0, path, -1, nullptr, 0);
wchar_t *wchar_path = new wchar_t[wchar_size];
ZeroMemory(wchar_path, wchar_size);
MultiByteToWideChar(CP_ACP, 0, path, -1, wchar_path, wchar_size);
// compile
DWORD flags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef PE_DEBUG_MODE
flags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob *effectBlob = nullptr;
ID3DBlob *errorBlob = nullptr;
// dx11只能使用fx_5_0
HRESULT hr = D3DCompileFromFile(wchar_path, nullptr, nullptr, nullptr, "fx_5_0", flags, 0, &effectBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob != nullptr){
LogSystem::GetInstance().Log("编译%s出错, D3D Error:%s", path, (char*)errorBlob->GetBufferPointer());
errorBlob->Release();
}
return -1;
}
if (errorBlob != nullptr){
errorBlob->Release();
}
// create effect
ID3DX11Effect *effect;
hr = D3DX11CreateEffectFromMemory(effectBlob->GetBufferPointer(), effectBlob->GetBufferSize(), 0, mDevice, &effect);
if (FAILED(hr))
{
LogSystem::GetInstance().Log("创建%s出错", path);
return -1;
}
mEffects.push_back(effect);
return (mEffects.size() - 1);
}
示例8: CompileShader
// Extern function for shader compilation
HRESULT CompileShader(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob)
{
if (!srcFile || !entryPoint || !profile || !blob)
return E_INVALIDARG;
*blob = nullptr;
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3DCOMPILE_DEBUG;
#endif
const D3D_SHADER_MACRO defines[] =
{
"EXAMPLE_DEFINE", "1",
NULL, NULL
};
ID3DBlob* shaderBlob = nullptr;
ID3DBlob* errorBlob = nullptr;
HRESULT hr = D3DCompileFromFile(srcFile, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE,
entryPoint, profile,
flags, 0, &shaderBlob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob)
{
OutputDebugStringA((char*)errorBlob->GetBufferPointer());
errorBlob->Release();
}
if (shaderBlob)
shaderBlob->Release();
return hr;
}
*blob = shaderBlob;
return hr;
}
示例9: defined
HRESULT GenerationShader::compileShaderFromFile(WCHAR * FileName, LPCSTR EntryPoint, LPCSTR ShaderModel, ID3DBlob ** Outblob)
{
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debug output, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
dwShaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
ID3DBlob* errorBlob;
//DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
hr = D3DCompileFromFile(FileName, NULL, NULL, EntryPoint, ShaderModel,
dwShaderFlags, NULL, Outblob, &errorBlob);
if (FAILED(hr))
{
if (errorBlob != NULL)
{
OutputDebugStringA((char*)errorBlob->GetBufferPointer());
}
if (errorBlob)
{
errorBlob->Release();
}
return hr;
}
if (errorBlob) errorBlob->Release();
return S_OK;
}
示例10: defined
void ShaderFactory::compileShaderStage( const LPCWSTR &p_sourceFile,
const string &p_entryPoint,
const string &p_profile, ID3DBlob** p_blob )
{
HRESULT res = S_OK;
ID3DBlob* blobError = NULL;
ID3DBlob* shaderBlob = NULL;
*p_blob = NULL;
DWORD compileFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
compileFlags |= D3DCOMPILE_DEBUG;
compileFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
//compileFlags |= D3DCOMPILE_WARNINGS_ARE_ERRORS;
#else
compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
#endif
// Compile the programs
// vertex
res = D3DCompileFromFile(p_sourceFile, 0,
D3D_COMPILE_STANDARD_FILE_INCLUDE,
(LPCTSTR)p_entryPoint.c_str(), (LPCTSTR)p_profile.c_str(),
compileFlags, 0,
&shaderBlob, &blobError);
if ( FAILED(res) )
{
if (blobError!=NULL)
throw D3DException(blobError,__FILE__,__FUNCTION__,__LINE__);
else
throw D3DException(res,__FILE__,__FUNCTION__,__LINE__);
return;
}
*p_blob = shaderBlob;
}
示例11: defined
HRESULT Technique::setPixelShader(LPCWSTR filename, LPCSTR entryPoint, LPCSTR shaderModel, ID3D11Device* g_pd3dDevice){
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* pPSBlob = nullptr;
ID3DBlob* pErrorBlob = nullptr;
hr = D3DCompileFromFile(filename, nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, entryPoint, shaderModel,
dwShaderFlags, 0, &pPSBlob, &pErrorBlob);
if (FAILED(hr))
{
if (pErrorBlob)
{
std::ofstream fout("Shader_Debug.txt");
fout << reinterpret_cast<const char*>(pErrorBlob->GetBufferPointer());
OutputDebugStringA(reinterpret_cast<const char*>(pErrorBlob->GetBufferPointer()));
pErrorBlob->Release();
}
}
if (pErrorBlob) pErrorBlob->Release();
hr = g_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), nullptr, &g_pPixelShader);
if (FAILED(hr))
{
pPSBlob->Release();
}
pPSBlob->Release();
return hr;
}
示例12: D3DCompileFromFile
void Effect::ReadShaderFile(std::wstring filename, ID3DBlob **blob, char* target, char* entryPoint) {
HRESULT hr;
ID3DBlob* errMsg;
hr = D3DCompileFromFile(
filename.c_str(),
nullptr,
D3D_COMPILE_STANDARD_FILE_INCLUDE,
entryPoint,
target,
D3DCOMPILE_DEBUG,
0,
blob,
&errMsg
);
#ifdef DEBUG
if (errMsg)
{
Debug::Log((char*)errMsg->GetBufferPointer());
errMsg->Release();
}
#endif
HR(hr);
}
示例13: CompileShaderFromFile
HRESULT CompileShaderFromFile( WCHAR const* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3D10Blob** ppBlobOut )
{
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef _DEBUG
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
// Disable optimizations to further improve shader debugging
dwShaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
ID3D10Blob* pErrorBlob = nullptr;
HRESULT hr = D3DCompileFromFile( szFileName, nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, szEntryPoint, szShaderModel, dwShaderFlags, 0, ppBlobOut, &pErrorBlob );
if( FAILED(hr) )
{
if( pErrorBlob )
{
OutputDebugStringA( reinterpret_cast<const char*>( pErrorBlob->GetBufferPointer() ) );
MessageBoxA( nullptr, "The shader cannot be compiled. Check output for error info.", "Error", MB_OK );
}
}
#ifdef _DEBUG
else
{
OutputDebugStringA( "Shader compilation successful\n" );
}
#endif
if( pErrorBlob )
{
pErrorBlob->Release();
}
return hr;
}
示例14: D3DCompileFromFile
HRESULT ShaderProgram::_compileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef _DEBUG
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
// Disable optimizations to further improve shader debugging
dwShaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
ID3DBlob* pErrorBlob = nullptr;
// D3D_COMPILE_STANDARD_FILE_INCLUDE macro makes the compiler capable of interpreting #include directive.
hr = D3DCompileFromFile( szFileName, nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE, szEntryPoint, szShaderModel,
dwShaderFlags, 0, ppBlobOut, &pErrorBlob );
_processError( hr, pErrorBlob );
return hr;
}
示例15: defined
void PixelShader::Initialize(GraphicsSystem& gs, const wchar_t* pFileName, const char* pEntryPoint, const char* pPixelShaderModel)
{
DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(_DEBUG)
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
shaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* pShaderBlob = nullptr;
ID3DBlob* pErrorBlob = nullptr;
HRESULT hr = D3DCompileFromFile(pFileName, nullptr, nullptr, pEntryPoint, pPixelShaderModel, shaderFlags, 0, &pShaderBlob, &pErrorBlob);
if (FAILED(hr) && pErrorBlob != nullptr)
{
OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
}
SafeRelease(pErrorBlob);
// Create pixel buffer
hr = gs.GetDevice()->CreatePixelShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), nullptr, &mpPixelShader);
SafeRelease(pShaderBlob);
}