Reputation: 906
I'm writing a Windows-UWP app in C# in which I want to include a 3D control. For that reason, I ported a program based on the Visual Studio DirectX UWP example over to a UWP DLL. However, when trying to load the included shaders, the program fails because it cannot find the compiled shader files.
The forum posts I have seen so far seem to suggest that resources like shaders won't be accessible inside of the AppX container and that the main project should include them. I thus tried to copy the compiled shaders over to the main project with the settings 'Always copy' and both 'AdditionalFiles' or 'Embedded resource' respectively which also did not work.
The code where I try to load the shaders looks like this:
void Scene3DRenderer::CreateDeviceDependentResources()
{
// Load shader asynchronously
auto loadVSTask = DX::ReadDataAsync(L"SampleVertexShader.cso");
auto createVSTask = loadVSTask.then([this](const std::vector<byte>& fileData) {
// Creating the vertex shader on the graphics device
});
// some other stuff
}
While this worked in the standalone app, waiting for the loadVSTask
to finish always throws a Platform::COMException ^
stating the system cannot find the specified file when used as a library for the C# project.
How to load the shaders correctly in this scenario?
Upvotes: 0
Views: 765
Reputation: 2907
You should make the shader compiler output header files instead of .cso files. You can do it in individual shader properties in VS:
Then, you can just include that shader (SampleVertexShader.h in this case), and pass those bytes directly to ID3D11Device::CreateVertexShader:
#include "SampleVertexShader.h"
Microsoft::WRL::ComPtr<ID3D11VertexShader> vertexShader;
auto hr = d3dDevice->CreateVertexShader(g_SampleVertexShader, sizeof(g_SampleVertexShader), nullptr, &vertexShader);
if (FAILED(hr))
{
// handle error
}
Upvotes: 4