简体   繁体   中英

DirectX Compile Shader from Memory?

Using shaders compiled from files like this works:

    D3DX11CompileFromFile(filename, NULL, NULL, "main", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, 
                   &vertexShaderBuffer, &errorMessage, NULL);

But if I replace the above line with this one:

D3DX11CompileFromMemory(vs, strlen(vs), NULL, NULL, NULL, "main", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, 
                   &vertexShaderBuffer, &errorMessage, NULL);

While vs is a char* of the shader file (if I print vs out using std::cout , it prints correctly).

It just crashes at that line...

What am I doing wrong?

D3DX APIs are deprecated, you should use the D3DCompile APIs instead from D3DCompiler.h . Mostly the same things with D3DX11 replaced by D3D so transition is simple.

Edit your message with at least a callstack or output log because wihtout more information, it is hard to be more specific on an answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM