这篇教程C++ D3DCompileFromFile函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中D3DCompileFromFile函数的典型用法代码示例。如果您正苦于以下问题:C++ D3DCompileFromFile函数的具体用法?C++ D3DCompileFromFile怎么用?C++ D3DCompileFromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了D3DCompileFromFile函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: D3DCompileFromFilebool 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;}
开发者ID:dastyk,项目名称:Engine,代码行数:46,
示例2: CompileComputeShader//Helper for compiling compute shaders taken from DirectX documentationHRESULT 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;}
开发者ID:KieronHusain,项目名称:GPU-Particle-System,代码行数:46,
示例3: D3DCompileFromFileint 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;}
开发者ID:dastyk,项目名称:ProjectZalowee,代码行数:44,
示例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;}
开发者ID:Zellcore,项目名称:lwjgl3-d3d11,代码行数:24,
示例5: afCompileShaderComPtr<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;}
开发者ID:yorung,项目名称:DirectX-Graphics-Samples,代码行数:19,
示例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; }
开发者ID:kienhdpr,项目名称:Talon,代码行数:20,
示例7: MultiByteToWideCharint 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);}
开发者ID:yyyyl,项目名称:PokeEngine,代码行数:41,
示例8: CompileShader// Extern function for shader compilationHRESULT 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;}
开发者ID:antoinenry,项目名称:learning-d3d11,代码行数:42,
示例9: definedHRESULT 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;}
开发者ID:Tabbers,项目名称:SPG,代码行数:40,
示例10: definedvoid 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;}
开发者ID:MattiasLiljeson,项目名称:Amalgamation,代码行数:40,
示例11: definedHRESULT 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;}
开发者ID:NikolaTT,项目名称:D3D11_Initialization_Class_Test,代码行数:40,
示例12: D3DCompileFromFilevoid 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);}
开发者ID:z530989673,项目名称:Rendering_Demo,代码行数:23,
示例13: CompileShaderFromFileHRESULT 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;}
开发者ID:mpj500,项目名称:creepy-capsicum,代码行数:36,
示例14: D3DCompileFromFileHRESULT 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;}
开发者ID:devgoeson,项目名称:d3dtest,代码行数:24,
示例15: definedvoid 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);}
开发者ID:Khillasaurus,项目名称:School,代码行数:24,
示例16: outputShaderErrorMessagebool LightShader::initializeShader(ID3D11Device * device, HWND hwnd, const WCHAR * vsFilename, const WCHAR * psFilename) { ID3D10Blob* errorBlob; ID3D10Blob* vertexShaderBlob; ID3D10Blob* pixelShaderBlob; UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;#if _DEBUG flags |= D3DCOMPILE_DEBUG;#endif // Compile the vertex shader code. if (FAILED(D3DCompileFromFile(vsFilename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "DiffuseLightVertexShader", Globals::VERTEX_SHADER_VERSION, flags, 0, &vertexShaderBlob, &errorBlob))) { if (errorBlob) { outputShaderErrorMessage(errorBlob, hwnd, vsFilename); } else { MessageBox(hwnd, vsFilename, L"Missing Vertex Shader File", MB_OK); } return false; } if (FAILED(D3DCompileFromFile(psFilename, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, "DiffuseLightPixelShader", Globals::PIXEL_SHADER_VERSION, flags, 0, &pixelShaderBlob, &errorBlob))) { if (errorBlob) { outputShaderErrorMessage(errorBlob, hwnd, psFilename); } else { MessageBox(hwnd, psFilename, L"Missing Pixel Shader File", MB_OK); } return false; } // Create the vertex shader from the buffer. if (FAILED(device->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), NULL, &vertexShader))) { MessageBox(NULL, L"Error creating Vertex Shader", L"ERROR", MB_OK); return false; } // Create the pixel shader from the buffer. if (FAILED(device->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), NULL, &pixelShader))) { MessageBox(NULL, L"Error creating Pixel Shader", L"ERROR", MB_OK); return false; } if (FAILED(initInputLayout(device, vertexShaderBlob))) { MessageBox(NULL, L"Error creating Input Layout Buffer", L"ERROR", MB_OK); return false; } safeRelease(vertexShaderBlob); safeRelease(pixelShaderBlob); if (FAILED(initMatrixBuffer(device))) { MessageBox(NULL, L"Error creating Constant (Matrix) Buffer", L"ERROR", MB_OK); return false; } if (FAILED(initSamplerState(device))) { MessageBox(NULL, L"Error creating Sampler Shader", L"ERROR", MB_OK); return false; } if (FAILED(initLightBuffer(device))) { return false; } return true;}
开发者ID:TheDizzler,项目名称:D3DGameEngine,代码行数:77,
示例17: D3DCompileFromFilebool Shader::initialize( comptr<ID3D11Device> const device, const std::string& coreFname){ comptr<ID3D10Blob> errorMessage; std::string vFilename = IOManager::get().getFormatPath(IOManager::VER) + "v_" + coreFname; std::string pFilename = IOManager::get().getFormatPath(IOManager::PIX) + "p_" + coreFname; /* Vertex shader compilation */ HRESULT result; result = D3DCompileFromFile( util::stringToWString(vFilename).c_str(), NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, d3dconst::SHADER_FUNC, d3dconst::VS_PROFILE, D3D10_SHADER_ENABLE_STRICTNESS, NULL, &m_pVSBuffer, &errorMessage); if (FAILED(result)) { if (errorMessage) { std::wstring compileError = L"Shader compile error: " + util::stringToWString(vFilename); char* errorDesc = static_cast<char*>(errorMessage->GetBufferPointer()); MessageBox(NULL, errorDesc, "Fatal Error", MB_ICONERROR); } else { std::string missingFile = "Missing shader file: " + vFilename; MessageBox(NULL, missingFile.c_str(), "Fatal Error", MB_ICONERROR); } return false; } /* Vertex shader creation */ HR(device->CreateVertexShader( m_pVSBuffer->GetBufferPointer(), m_pVSBuffer->GetBufferSize(), NULL, &m_pVertexShader)); /* Pixel shader compilation */ result = D3DCompileFromFile( util::stringToWString(pFilename).c_str(), NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, d3dconst::SHADER_FUNC, d3dconst::PS_PROFILE, D3D10_SHADER_ENABLE_STRICTNESS, NULL, &m_pPSBuffer, &errorMessage); if (FAILED(result)) { if (errorMessage) { std::wstring compileError = L"Shader compile error: " + util::stringToWString(pFilename); char* errorDesc = static_cast<char*>(errorMessage->GetBufferPointer()); MessageBox(NULL, errorDesc, "Fatal Error", MB_ICONERROR); } else { std::string missingFile = "Missing shader file: " + pFilename; MessageBox(NULL, missingFile.c_str(), "Fatal Error", MB_ICONERROR); } return false; } /* Pixel shader creation */ HR(device->CreatePixelShader( m_pPSBuffer->GetBufferPointer(), m_pPSBuffer->GetBufferSize(), NULL, &m_pPixelShader)); /* Initialize constant matrix buffer */ D3D11_BUFFER_DESC mcbd = {}; mcbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; mcbd.ByteWidth = sizeof(MatrixBuffer); mcbd.CPUAccessFlags = 0; mcbd.Usage = D3D11_USAGE_DEFAULT; mcbd.StructureByteStride = 0; mcbd.MiscFlags = 0; HR(device->CreateBuffer(&mcbd, NULL, &m_pMatrixBuffer)); /* Initialize constant color buffer */ mcbd.ByteWidth = sizeof(ColorBuffer); HR(device->CreateBuffer(&mcbd, NULL, &m_pColorBuffer)); return true;}
开发者ID:AlexKoukoulas2074245K,项目名称:Code-PR,代码行数:97,
示例18: ThrowIfFailed// Load the sample assets.void D3D1211on12::LoadAssets(){ // Create an empty root signature. { CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_d3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); } // Create the pipeline state, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#if DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; // Describe and create the graphics pipeline state object (PSO). D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_d3d12Device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); } ThrowIfFailed(m_d3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocators[m_frameIndex].Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList))); // Create D2D/DWrite objects for rendering text. { ThrowIfFailed(m_d2dDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &m_textBrush)); ThrowIfFailed(m_dWriteFactory->CreateTextFormat( L"Verdana", NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 50, L"en-us", &m_textFormat )); ThrowIfFailed(m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)); ThrowIfFailed(m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER)); } ComPtr<ID3D12Resource> vertexBufferUpload; // Create the vertex buffer. { // Define the geometry for a triangle. Vertex triangleVertices[] = { { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }, { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, { { -0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } } }; const UINT vertexBufferSize = sizeof(triangleVertices); ThrowIfFailed(m_d3d12Device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_vertexBuffer))); ThrowIfFailed(m_d3d12Device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize),//.........这里部分代码省略.........
开发者ID:souxiaosou,项目名称:DirectX-Graphics-Samples,代码行数:101,
示例19: D3DCompileFromFilevoid pipeline::InitShaders(){ HRESULT error; // load and compile the two shaders error = D3DCompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, &VS, 0); if (FAILED(error)) { MessageBox(NULL,L"OH NOES VShader Compile!",L"QUIT",NULL); } error = D3DCompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, &PS, 0); if (FAILED(error)) { MessageBox(NULL,L"OH NOES PShader Compile!",L"QUIT",NULL); } error = D3DCompileFromFile(L"shaders.hlsl", 0, 0, "VShaderTex", "vs_4_0", 0, 0, &VSTex, &bloberror); if (FAILED(error)) { MessageBox(NULL,L"OH NOES VShaderTex Compile!",L"QUIT",NULL); } error = D3DCompileFromFile(L"shaders.hlsl", 0, 0, "PShaderTex", "ps_4_0", 0, 0, &PSTex, 0); if (FAILED(error)) { MessageBox(NULL,L"OH NOES PShaderTex Compile!!",L"QUIT",NULL); } //char* errortext = (char*)bloberror->GetBufferPointer(); // encapsulate both shaders into shader objects std::ostringstream os; error = Device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS); //MessageBox(NULL,(LPCWSTR)os.str().c_str(),(LPCWSTR)os.str().c_str(),NULL); os << (LONG)error; if (FAILED(error)) { MessageBoxA(NULL,os.str().c_str(),"QUIT",NULL); } error = Device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS); //if (FAILED(error)) { MessageBox(NULL,L"OH NOES PS CREATE!",L"QUIT",NULL); } os << (LONG)error; if (FAILED(error)) { MessageBoxA(NULL,os.str().c_str(),"QUIT",NULL); } error = Device->CreateVertexShader(VSTex->GetBufferPointer(), VSTex->GetBufferSize(), NULL, &pVSTex); //if (FAILED(error)) { MessageBox(NULL,L"OH NOES VSTEX CREATE!",L"QUIT",NULL); } os << (LONG)error; if (FAILED(error)) { MessageBoxA(NULL,os.str().c_str(),"QUIT",NULL); } error = Device->CreatePixelShader(PSTex->GetBufferPointer(), PSTex->GetBufferSize(), NULL, &pPSTex); //if (FAILED(error)) { MessageBox(NULL,L"OH NOES PSTEXT CREATE!",L"QUIT",NULL); } os << (LONG)error; if (FAILED(error)) { MessageBoxA(NULL,os.str().c_str(),"QUIT",NULL); } //load the picture to a shader resource view error = CreateWICTextureFromFile(Device, devcon, L"./images/aship.JPEG",nullptr,&shiptexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES WICLOADER BRICKS!",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/aprojectile.png",nullptr,&projtexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES WICLOADER SHIP",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/aasteroid.png",nullptr,&asttexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES WICLOADER SHIP",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/alvl1back1.png",nullptr,&lvl1back1texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES LVL1BACK1",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/alvl1back2.png",nullptr,&lvl1back2texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES LVL1BACK2",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/alvl1back3.png",nullptr,&lvl1back3texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES LVL1BACK3",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/alvl1back4.png",nullptr,&lvl1back4texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES LVL1BACK4",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/gameovertext.tif",nullptr,&gameovertexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES gameover",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/armourtext.tif",nullptr,&armourtexttexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES armourtext",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/shieldtext.tif",nullptr,&shieldtexttexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES shieldtext",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/0text.tif",nullptr,&text0texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES 0text",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/1text.tif",nullptr,&text1texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES 1text",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/2text.tif",nullptr,&text2texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES 2text",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/3text.tif",nullptr,&text3texture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES 3text",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/shield.tif",nullptr,&shieldtexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES shield",L"QUIT",NULL); } error = CreateWICTextureFromFile(Device, devcon, L"./images/levelcleartext.tif",nullptr,&levelcompletetexture); if (FAILED(error)) { MessageBox(NULL,L"OH NOES levelcleartext",L"QUIT",NULL); } //sampler description D3D11_SAMPLER_DESC samplerDesc; ZeroMemory(&samplerDesc, sizeof(samplerDesc)); samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.MaxAnisotropy = 0; // Specify how texture coordinates outside of the range 0..1 are resolved. samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; // Use no special MIP clamping or bias. samplerDesc.MipLODBias = 0.0f; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; // Don't use a comparison function. samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; // Border address mode is not used, so this parameter is ignored. samplerDesc.BorderColor[0] = 0.0f; samplerDesc.BorderColor[1] = 0.0f; samplerDesc.BorderColor[2] = 0.0f; samplerDesc.BorderColor[3] = 0.0f; //make the sampler error = Device->CreateSamplerState(&samplerDesc,&pSampler); if (FAILED(error)) { MessageBox(NULL,L"OH NOES SAMPLER!",L"QUIT",NULL); } //set shader resource to that made from picture and set sampler//.........这里部分代码省略.........
开发者ID:OhHey,项目名称:OhHeyProject,代码行数:101,
示例20: D3D12SerializeRootSignature void Triangle::init_shader(ComPtr<ID3D12Device> pD3D12Device) { CD3DX12_DESCRIPTOR_RANGE ranges[1]; CD3DX12_ROOT_PARAMETER rootParameters[1]; ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0); rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_VERTEX); // Allow input layout and deny uneccessary access to certain pipeline stages. D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS; //Create a root signature CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSignatureFlags); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error); pD3D12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_pRootSignature)); //Create the pipeline state, which includes compiling and loading shaders ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#ifdef _DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif D3DCompileFromFile(L"triangle.vsh", nullptr, nullptr, "VS_MAIN", "vs_5_0", compileFlags, 0, &vertexShader, nullptr); D3DCompileFromFile(L"triangle.psh", nullptr, nullptr, "PS_MAIN", "ps_5_0", compileFlags, 0, &pixelShader, nullptr); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; //Descrbe and create the graphics pipeline state object (PSO) D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = {inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_pRootSignature.Get(); psoDesc.VS = {vertexShader->GetBufferPointer(), vertexShader->GetBufferSize() }; psoDesc.PS = {pixelShader->GetBufferPointer(), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; HRESULT res = pD3D12Device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pPipelineState)); assert(res == S_OK); }
开发者ID:byhj,项目名称:byhj-Render,代码行数:61,
示例21: ThrowIfFailed// Load the sample assets.void D3D12HeterogeneousMultiadapter::LoadAssets(){ // Create the root signatures. { CD3DX12_ROOT_PARAMETER rootParameters[2]; rootParameters[0].InitAsConstantBufferView(0, 0, D3D12_SHADER_VISIBILITY_VERTEX); rootParameters[1].InitAsConstantBufferView(1, 0, D3D12_SHADER_VISIBILITY_PIXEL); CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_devices[Primary]->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); CD3DX12_DESCRIPTOR_RANGE ranges[1]; ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0); CD3DX12_ROOT_PARAMETER blurRootParameters[3]; blurRootParameters[0].InitAsConstantBufferView(0, 0, D3D12_SHADER_VISIBILITY_PIXEL); blurRootParameters[1].InitAsDescriptorTable(_countof(ranges), ranges, D3D12_SHADER_VISIBILITY_PIXEL); blurRootParameters[2].InitAsConstantBufferView(1, 0, D3D12_SHADER_VISIBILITY_PIXEL); CD3DX12_STATIC_SAMPLER_DESC staticPointSampler(0); staticPointSampler.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; staticPointSampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; CD3DX12_STATIC_SAMPLER_DESC staticLinearSampler(1); staticLinearSampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR; staticLinearSampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; D3D12_STATIC_SAMPLER_DESC staticSamplers[] = { staticPointSampler, staticLinearSampler }; rootSignatureDesc.Init(_countof(blurRootParameters), blurRootParameters, _countof(staticSamplers), staticSamplers, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_devices[Secondary]->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_blurRootSignature))); } // Create the pipeline states, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader; ComPtr<ID3DBlob> vertexShaderBlur; ComPtr<ID3DBlob> pixelShaderBlurU; ComPtr<ID3DBlob> pixelShaderBlurV; ComPtr<ID3DBlob> error;#if defined(_DEBUG) // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VShader", "vs_5_0", compileFlags, 0, &vertexShader, &error)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PShader", "ps_5_0", compileFlags, 0, &pixelShader, &error)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"blurShaders.hlsl").c_str(), nullptr, nullptr, "VSSimpleBlur", "vs_5_0", compileFlags, 0, &vertexShaderBlur, &error)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"blurShaders.hlsl").c_str(), nullptr, nullptr, "PSSimpleBlurU", "ps_5_0", compileFlags, 0, &pixelShaderBlurU, &error)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"blurShaders.hlsl").c_str(), nullptr, nullptr, "PSSimpleBlurV", "ps_5_0", compileFlags, 0, &pixelShaderBlurV, &error)); // Define the vertex input layouts. const D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, }; const D3D12_INPUT_ELEMENT_DESC blurInputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, }; // Describe and create the graphics pipeline state objects (PSOs). D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader.Get()); psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader.Get()); psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT); psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_devices[Primary]->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); psoDesc.InputLayout = { blurInputElementDescs, _countof(blurInputElementDescs) }; psoDesc.pRootSignature = m_blurRootSignature.Get(); psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShaderBlur.Get()); psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShaderBlurU.Get()); psoDesc.DepthStencilState.DepthEnable = false; psoDesc.DSVFormat = DXGI_FORMAT_UNKNOWN; ThrowIfFailed(m_devices[Secondary]->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_blurPipelineStates[0])));//.........这里部分代码省略.........
开发者ID:GeorgeKps,项目名称:nBodyD3D12,代码行数:101,
示例22: OutputDebugStringA //test code to compile Test.hlsl bool Renderer::createShadersAndInputLayouts(void) { UINT flags1 = 0;#if _DEBUG flags1 |= D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG; #endif ID3DBlob *vShaderCode = nullptr; ID3DBlob *pShaderCode = nullptr; ID3DBlob *gShaderCode = nullptr; ID3DBlob *errorCode = nullptr; HRESULT res; D3D11_INPUT_ELEMENT_DESC positionInputElement; positionInputElement.AlignedByteOffset = 0; positionInputElement.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; positionInputElement.InputSlot = 0; positionInputElement.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; positionInputElement.InstanceDataStepRate = 0; positionInputElement.SemanticName = "POSITION"; positionInputElement.SemanticIndex = 0; //create Texture shaders------------------------------------------------------------------------------------------------------------ if(FAILED(D3DCompileFromFile(GetShaderPath(L"Texture.hlsl").data(), nullptr, nullptr, "VShader", "vs_5_0", flags1, 0, &vShaderCode, &errorCode))) { SafeRelease<ID3DBlob>(&vShaderCode); if(errorCode) { OutputDebugStringA((LPCSTR)errorCode->GetBufferPointer()); SafeRelease<ID3DBlob>(&errorCode); } return false; } if(FAILED(D3DCompileFromFile(GetShaderPath(L"Texture.hlsl").data(), nullptr, nullptr, "PShader", "ps_5_0", flags1, 0, &pShaderCode, &errorCode))) { SafeRelease<ID3DBlob>(&pShaderCode); if(errorCode) { OutputDebugStringA((LPCSTR)errorCode->GetBufferPointer()); SafeRelease<ID3DBlob>(&errorCode); } return false; } if(FAILED(this->device->CreatePixelShader(pShaderCode->GetBufferPointer(), pShaderCode->GetBufferSize(), nullptr, &this->texturePShader))) { OutputDebugString("/n create texture pixel shader failed /n"); return false; } if(FAILED(this->device->CreateVertexShader(vShaderCode->GetBufferPointer(), vShaderCode->GetBufferSize(), nullptr, &this->textureVShader))) { OutputDebugString("/n create texture vertex shader failed /n"); return false; } D3D11_INPUT_ELEMENT_DESC textureInputElement; textureInputElement.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; textureInputElement.Format = DXGI_FORMAT_R32G32_FLOAT; textureInputElement.InputSlot = 0; textureInputElement.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; textureInputElement.InstanceDataStepRate = 0; textureInputElement.SemanticIndex = 0; textureInputElement.SemanticName = "TEXCOORD"; D3D11_INPUT_ELEMENT_DESC textureShaderInput[] = {positionInputElement, textureInputElement}; if(FAILED(this->device->CreateInputLayout(textureShaderInput, 2, vShaderCode->GetBufferPointer(), vShaderCode->GetBufferSize(), &this->textureInputLayout))) { OutputDebugString("/n Create textureShaderInput failed /n"); return false; } SafeRelease<ID3DBlob>(&vShaderCode); SafeRelease<ID3DBlob>(&pShaderCode); //create color shaders and input layout --------------------------------------------------------------------------------------------- if(FAILED(D3DCompileFromFile(GetShaderPath(L"Colored.hlsl").data(), nullptr, nullptr, "VShader", "vs_5_0", flags1, 0, &vShaderCode, &errorCode))) { SafeRelease<ID3DBlob>(&vShaderCode); if(errorCode) { OutputDebugStringA((LPCSTR)errorCode->GetBufferPointer()); SafeRelease<ID3DBlob>(&errorCode); } return false; } if(FAILED(D3DCompileFromFile(GetShaderPath(L"Colored.hlsl").data(), nullptr, nullptr, "PShader", "ps_5_0", flags1, 0, &pShaderCode, &errorCode))) {//.........这里部分代码省略.........
开发者ID:jwasinger,项目名称:jwasinger_engine,代码行数:101,
示例23: ThrowIfFailed// Load the sample assets.void D3D12HelloTexture::LoadAssets(){ // Create the root signature. { CD3DX12_DESCRIPTOR_RANGE ranges[1]; ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0); CD3DX12_ROOT_PARAMETER rootParameters[1]; rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_PIXEL); D3D12_STATIC_SAMPLER_DESC sampler = {}; sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT; sampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER; sampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER; sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER; sampler.MipLODBias = 0; sampler.MaxAnisotropy = 0; sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; sampler.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK; sampler.MinLOD = 0.0f; sampler.MaxLOD = D3D12_FLOAT32_MAX; sampler.ShaderRegister = 0; sampler.RegisterSpace = 0; sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 1, &sampler, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); } // Create the pipeline state, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#ifdef _DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; // Describe and create the graphics pipeline state object (PSO). D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); } // Create the command list. ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList))); // Create the vertex buffer. { // Define the geometry for a triangle. Vertex triangleVertices[] = { { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 0.5f, 0.0f } }, { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 1.0f, 1.0f } }, { { -0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f } } }; const UINT vertexBufferSize = sizeof(triangleVertices); // Note: using upload heaps to transfer static data like vert buffers is not // recommended. Every time the GPU needs it, the upload heap will be marshalled // over. Please read up on Default Heap usage. An upload heap is used here for // code simplicity and because there are very few verts to actually transfer. ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,//.........这里部分代码省略.........
开发者ID:MaybeS,项目名称:DirectX-Graphics-Samples,代码行数:101,
示例24: CompileShaderstatic ID3DBlob* CompileShader(const wchar* path, const char* functionName, const char* profile, const D3D_SHADER_MACRO* defines, bool forceOptimization, vector<wstring>& filePaths){ // Make a hash off the expanded shader code string shaderCode = GetExpandedShaderCode(path, filePaths); wstring cacheName = MakeShaderCacheName(shaderCode, functionName, profile, defines); if(FileExists(cacheName.c_str())) { File cacheFile(cacheName.c_str(), File::OpenRead); const uint64 shaderSize = cacheFile.Size(); vector<uint8> compressedShader; compressedShader.resize(shaderSize); cacheFile.Read(shaderSize, compressedShader.data()); ID3DBlob* decompressedShader[1] = { nullptr }; uint32 indices[1] = { 0 }; DXCall(D3DDecompressShaders(compressedShader.data(), shaderSize, 1, 0, indices, 0, decompressedShader, nullptr)); return decompressedShader[0]; } std::printf("Compiling shader %s %s %s/n", WStringToAnsi(GetFileName(path).c_str()).c_str(), profile, MakeDefinesString(defines).c_str()); // Loop until we succeed, or an exception is thrown while(true) { UINT flags = D3DCOMPILE_WARNINGS_ARE_ERRORS; #ifdef _DEBUG flags |= D3DCOMPILE_DEBUG; if(forceOptimization == false) flags |= D3DCOMPILE_SKIP_OPTIMIZATION; #endif ID3DBlob* compiledShader; ID3DBlobPtr errorMessages; HRESULT hr = D3DCompileFromFile(path, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, functionName, profile, flags, 0, &compiledShader, &errorMessages); if(FAILED(hr)) { if(errorMessages) { wchar message[1024] = { 0 }; char* blobdata = reinterpret_cast<char*>(errorMessages->GetBufferPointer()); MultiByteToWideChar(CP_ACP, 0, blobdata, static_cast<int>(errorMessages->GetBufferSize()), message, 1024); std::wstring fullMessage = L"Error compiling shader file /""; fullMessage += path; fullMessage += L"/" - "; fullMessage += message; // Pop up a message box allowing user to retry compilation int retVal = MessageBoxW(nullptr, fullMessage.c_str(), L"Shader Compilation Error", MB_RETRYCANCEL); if(retVal != IDRETRY) throw DXException(hr, fullMessage.c_str()); #if EnableShaderCaching_ shaderCode = GetExpandedShaderCode(path); cacheName = MakeShaderCacheName(shaderCode, functionName, profile, defines); #endif } else { _ASSERT(false); throw DXException(hr); } } else { // Compress the shader D3D_SHADER_DATA shaderData; shaderData.pBytecode = compiledShader->GetBufferPointer(); shaderData.BytecodeLength = compiledShader->GetBufferSize(); ID3DBlobPtr compressedShader; DXCall(D3DCompressShaders(1, &shaderData, D3D_COMPRESS_SHADER_KEEP_ALL_PARTS, &compressedShader)); // Create the cache directory if it doesn't exist if(DirectoryExists(baseCacheDir.c_str()) == false) Win32Call(CreateDirectory(baseCacheDir.c_str(), nullptr)); if(DirectoryExists(cacheDir.c_str()) == false) Win32Call(CreateDirectory(cacheDir.c_str(), nullptr)); File cacheFile(cacheName.c_str(), File::OpenWrite); // Write the compiled shader to disk uint64 shaderSize = compressedShader->GetBufferSize(); cacheFile.Write(shaderSize, compressedShader->GetBufferPointer()); return compiledShader; } }}
开发者ID:MehdiNS,项目名称:Shadows,代码行数:98,
示例25: ThrowIfFailed// Load the sample assets.void D3D12HelloTriangle::LoadAssets(){ // Create an empty root signature. { CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); } // Create the pipeline state, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#if defined(_DEBUG) // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; // Describe and create the graphics pipeline state object (PSO). D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); } // Create the command list. ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList))); // Command lists are created in the recording state, but there is nothing // to record yet. The main loop expects it to be closed, so close it now. ThrowIfFailed(m_commandList->Close()); // Create the vertex buffer. { // Define the geometry for a triangle. Vertex triangleVertices[] = { { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }, { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, { { -0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } } }; const UINT vertexBufferSize = sizeof(triangleVertices); // Note: using upload heaps to transfer static data like vert buffers is not // recommended. Every time the GPU needs it, the upload heap will be marshalled // over. Please read up on Default Heap usage. An upload heap is used here for // code simplicity and because there are very few verts to actually transfer. ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&m_vertexBuffer))); // Copy the triangle data to the vertex buffer. UINT8* pVertexDataBegin; CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. ThrowIfFailed(m_vertexBuffer->Map(0, &readRange, reinterpret_cast<void**>(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBuffer->Unmap(0, nullptr); // Initialize the vertex buffer view. m_vertexBufferView.BufferLocation = m_vertexBuffer->GetGPUVirtualAddress(); m_vertexBufferView.StrideInBytes = sizeof(Vertex); m_vertexBufferView.SizeInBytes = vertexBufferSize; } // Create synchronization objects and wait until assets have been uploaded to the GPU. {//.........这里部分代码省略.........
开发者ID:nairdan2,项目名称:DirectX-Graphics-Samples,代码行数:101,
示例26: ThrowIfFailed//.........这里部分代码省略......... sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER; sampler.MipLODBias = 0; sampler.MaxAnisotropy = 0; sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; sampler.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK; sampler.MinLOD = 0.0f; sampler.MaxLOD = D3D12_FLOAT32_MAX; sampler.ShaderRegister = i; sampler.RegisterSpace = 0; sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; } CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, GX2_NUM_SAMPLERS, samplers, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(gDX.device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&gDX.rootSignature))); } // Create the pipeline state, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#ifdef _DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(L"resources/shaders/screendraw.hlsl", nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(L"resources/shaders/screendraw.hlsl", nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; { D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = gDX.rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(gDX.device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&gDX.emuPipelineState))); } } gDX.pipelineMgr = new DXPipelineMgr(); // Create the command list. gDX.frameIndex = gDX.swapChain->GetCurrentBackBufferIndex();
开发者ID:Flaw,项目名称:decaf-emu,代码行数:67,
示例27: ThrowIfFailed// Load the sample assets.void D3D12HelloConstBuffers::LoadAssets(){ // Create a root signature consisting of a single CBV parameter. { CD3DX12_DESCRIPTOR_RANGE ranges[1]; CD3DX12_ROOT_PARAMETER rootParameters[1]; ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0); rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_VERTEX); // Allow input layout and deny uneccessary access to certain pipeline stages. D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS | D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS; CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSignatureFlags); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); } // Create the pipeline state, which includes compiling and loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#if DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = 0;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); // Define the vertex input layout. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; // Describe and create the graphics pipeline state object (PSO). D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) }; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); } // Create the command list. ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList))); // Command lists are created in the recording state, but there is nothing // to record yet. The main loop expects it to be closed, so close it now. ThrowIfFailed(m_commandList->Close()); // Create the vertex buffer. { // Define the geometry for a triangle. Vertex triangleVertices[] = { { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }, { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, { { -0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } } }; const UINT vertexBufferSize = sizeof(triangleVertices); // Note: using upload heaps to transfer static data like vert buffers is not // recommended. Every time the GPU needs it, the upload heap will be marshalled // over. Please read up on Default Heap usage. An upload heap is used here for // code simplicity and because there are very few verts to actually transfer. ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&m_vertexBuffer)));//.........这里部分代码省略.........
开发者ID:souxiaosou,项目名称:DirectX-Graphics-Samples,代码行数:101,
示例28: SetCurrentDirectory void CubeDemo::initialize() { SetCurrentDirectory(Utility::ExecutableDirectory().c_str()); UINT shaderFlags = 0;#if defined(DEBUG) || defined(_DEBUG) shaderFlags |= D3DCOMPILE_DEBUG; shaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;#endif ID3D10Blob * compiledShader = nullptr; ID3D10Blob * errorMessages = nullptr; HRESULT hr = D3DCompileFromFile(L"Content//Effects//BasicEffect.fx", nullptr, nullptr, nullptr, "fx_5_0", shaderFlags, 0, &compiledShader, &errorMessages); //if (errorMessages != nullptr) //{ // char * message = (char*)errorMessages->GetBufferPointer(); // GameException ex((wchar_t*)errorMessages->GetBufferPointer(), hr); // ReleaseObject(errorMessages); // throw ex; // //ReleaseObject(compiledShader); //} if (FAILED(hr)) { throw GameException(L"D3DX11CompileFromFile() failed.", hr); } hr = D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, mGame->device(), &mEffect); if (FAILED(hr)) { throw GameException(L"D3DX11CreateEffectFromMemory() failed", hr); } ReleaseObject(compiledShader); mTechnique = mEffect->GetTechniqueByName("main11"); if (mTechnique == nullptr) { throw GameException(L"ID3D11Effect::GetTechniqueByName() unable to find techique main11.", hr); } mPass = mTechnique->GetPassByName("p0"); if (mPass == nullptr) { throw GameException(L"ID3D11EffectTechnique::GetPassByName() unable to find pass p0", hr); } ID3DX11EffectVariable * variable = mEffect->GetVariableByName("WorldViewProjection"); if (variable == nullptr) { throw GameException(L"ID3DX11Effect::GetVariableByName() unable to find variable WorldViewProjection"); } mWvpVariable = variable->AsMatrix(); if (!mWvpVariable->IsValid()) { throw GameException(L"Invaild effect variable cast"); } D3DX11_PASS_DESC passDesc; mPass->GetDesc(&passDesc); D3D11_INPUT_ELEMENT_DESC inputElementDescriptions[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; if (FAILED(hr = mGame->device()->CreateInputLayout(inputElementDescriptions, ARRAYSIZE(inputElementDescriptions), passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &mInputLayout))) { throw GameException(L"ID3D11Device::CreateInputLayout() failed", hr); } BasicEffectVertex vertices[] = { BasicEffectVertex(XMFLOAT4(-1.0f, 1.0f, -1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::RED))), BasicEffectVertex(XMFLOAT4(1.0f, 1.0f, -1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::GREEN))), BasicEffectVertex(XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::BLACK))) , BasicEffectVertex(XMFLOAT4(-1.0f, 1.0f, 1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::WHITE))), BasicEffectVertex(XMFLOAT4(-1.0f,- 1.0f, 1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::YELLOW))), BasicEffectVertex(XMFLOAT4(+1.0f, -1.0f, +1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::BLACK))), BasicEffectVertex(XMFLOAT4(1.0f, -1.0f, -1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::CYAN))), BasicEffectVertex(XMFLOAT4(-1.0f, -1.0f, -1.0f, 1.0f), XMFLOAT4(reinterpret_cast<float*>(&Colors::GREEN))) }; D3D11_BUFFER_DESC vertexBufferDesc; ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc)); vertexBufferDesc.ByteWidth = sizeof(BasicEffectVertex)* ARRAYSIZE(vertices); vertexBufferDesc.Usage = D3D11_USAGE_IMMUTABLE; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA vertexSubResourceData;//.........这里部分代码省略.........
开发者ID:DarriusWright,项目名称:Capstone_WrightD,代码行数:101,
示例29: ThrowIfFailed// Load the sample assets.void D3D12Multithreading::LoadAssets(){ // Create the root signature. { CD3DX12_DESCRIPTOR_RANGE ranges[4]; // Perfomance TIP: Order from most frequent to least frequent. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 2, 1); // 2 frequently changed diffuse + normal textures - using registers t1 and t2. ranges[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0); // 1 frequently changed constant buffer. ranges[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0); // 1 infrequently changed shadow texture - starting in register t0. ranges[3].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 2, 0); // 2 static samplers. CD3DX12_ROOT_PARAMETER rootParameters[4]; rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_PIXEL); rootParameters[1].InitAsDescriptorTable(1, &ranges[1], D3D12_SHADER_VISIBILITY_ALL); rootParameters[2].InitAsDescriptorTable(1, &ranges[2], D3D12_SHADER_VISIBILITY_PIXEL); rootParameters[3].InitAsDescriptorTable(1, &ranges[3], D3D12_SHADER_VISIBILITY_PIXEL); CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature))); } // Create the pipeline state, which includes loading shaders. { ComPtr<ID3DBlob> vertexShader; ComPtr<ID3DBlob> pixelShader;#ifdef _DEBUG // Enable better shader debugging with the graphics debugging tools. UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;#else UINT compileFlags = D3DCOMPILE_OPTIMIZATION_LEVEL3;#endif ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "VSMain", "vs_5_0", compileFlags, 0, &vertexShader, nullptr)); ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L"shaders.hlsl").c_str(), nullptr, nullptr, "PSMain", "ps_5_0", compileFlags, 0, &pixelShader, nullptr)); D3D12_INPUT_LAYOUT_DESC inputLayoutDesc; inputLayoutDesc.pInputElementDescs = SampleAssets::StandardVertexDescription; inputLayoutDesc.NumElements = _countof(SampleAssets::StandardVertexDescription); CD3DX12_DEPTH_STENCIL_DESC depthStencilDesc(D3D12_DEFAULT); depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL; depthStencilDesc.StencilEnable = FALSE; // Describe and create the PSO for rendering the scene. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.InputLayout = inputLayoutDesc; psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psoDesc.DepthStencilState = depthStencilDesc; psoDesc.SampleMask = UINT_MAX; psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT; psoDesc.SampleDesc.Count = 1; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))); // Alter the description and create the PSO for rendering // the shadow map. The shadow map does not use a pixel // shader or render targets. psoDesc.PS.pShaderBytecode = 0; psoDesc.PS.BytecodeLength = 0; psoDesc.RTVFormats[0] = DXGI_FORMAT_UNKNOWN; psoDesc.NumRenderTargets = 0; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineStateShadowMap))); } // Create temporary command list for initial GPU setup. ComPtr<ID3D12GraphicsCommandList> commandList; ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), m_pipelineState.Get(), IID_PPV_ARGS(&commandList))); // Create render target views (RTVs). CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart()); for (UINT i = 0; i < FrameCount; i++) { ThrowIfFailed(m_swapChain->GetBuffer(i, IID_PPV_ARGS(&m_renderTargets[i]))); m_device->CreateRenderTargetView(m_renderTargets[i].Get(), nullptr, rtvHandle); rtvHandle.Offset(1, m_rtvDescriptorSize); } // Create the depth stencil. { CD3DX12_RESOURCE_DESC shadowTextureDesc( D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, static_cast<UINT>(m_viewport.Width), static_cast<UINT>(m_viewport.Height), //.........这里部分代码省略.........
开发者ID:horzelski,项目名称:DirectX-Graphics-Samples,代码行数:101,
示例30: D3DCompileFromFilebool FogFX::InitialiseShader(ID3D11Device* device, HWND hwnd, WCHAR* sFilename){ bool result; unsigned int numElements; ID3D10Blob* errorMessage; ID3D10Blob* vertexShaderBuffer; ID3D10Blob* pixelShaderBuffer; D3D11_INPUT_ELEMENT_DESC polygonLayout[2]; D3D11_BUFFER_DESC constantBufferDesc; D3D11_SAMPLER_DESC samplerDesc; D3D11_BUFFER_DESC fogBufferDesc; numElements = 0; errorMessage = 0; vertexShaderBuffer = nullptr; pixelShaderBuffer = nullptr; // Read Vertex Shader result = D3DCompileFromFile(sFilename, NULL, NULL, "VS", "vs_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertexShaderBuffer, &errorMessage); if (FAILED(result)) { if (errorMessage) OutputShaderErrorMessage(errorMessage, hwnd, sFilename); else MessageBox(hwnd, sFilename, L"Missing VS", MB_OK); return false; } //Create the vertex shader from the buffer result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &_pVertexShader); if (FAILED(result)) return false; // Read Pixel Shader result = D3DCompileFromFile(sFilename, NULL, NULL, "PS", "ps_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, &errorMessage); if (FAILED(result)) { if (errorMessage) OutputShaderErrorMessage(errorMessage, hwnd, sFilename); else MessageBox(hwnd, sFilename, L"Missing PS", MB_OK); return false; } result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &_pPixelShader); if (FAILED(result)) return false; // Create the Input Layour description polygonLayout[0].SemanticName = "POSITION"; polygonLayout[0].SemanticIndex = 0; polygonLayout[0].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0; polygonLayout[1].SemanticName = "TEXCOORD"; polygonLayout[1].SemanticIndex = 0; polygonLayout[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = 0; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0; numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]); result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &_pInputLayout); if (FAILED(result)) return false; vertexShaderBuffer->Release(); pixelShaderBuffer->Release(); constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC; constantBufferDesc.ByteWidth = sizeof(ConstantBuffer); constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; constantBufferDesc.MiscFlags = 0; constantBufferDesc.StructureByteStride = 0; if (FAILED(result)) return false; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 1; samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; samplerDesc.BorderColor[0] = 0; samplerDesc.BorderColor[1] = 0; samplerDesc.BorderColor[2] = 0; samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;//.........这里部分代码省略.........
开发者ID:GRMaverick,项目名称:DirectX_FGGC,代码行数:101,
注:本文中的D3DCompileFromFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ D3DPS_VERSION函数代码示例 C++ D3DCOLOR_RGBA函数代码示例 |