Sign in to follow this  
Hannesnisula

[SlimDX] Compile shader

Recommended Posts

Hello I've been trying to compile shaders with SlimDX and ShaderBytecode.CompileShader() but I always get the exception that says unexpected 'something' and that something is always the first character in the shader. I've also tried with different shader profiles as "vs_1_0", "vs_3_0" etc so I guess that's not the problem. I set the entry point to the name of the function, for my testing I put it as "vertexShaderEntry" am I supposed to specify parameters or something in that string in the CompileShader() call as well?

From what I've tried I believe there's something wrong with my byte array made from the string containing my whole shader code.

[code]

byte[] byteArray = new byte[currentShader.shaderData.Length * 2];
byte[] tempBytes = null;

for(int i = 0; i < currentShader.shaderData.Length; ++i)
{
tempBytes = BitConverter.GetBytes(currentShader.shaderData.ToCharArray()[i]);
byteArray[i * 2] = tempBytes[0];
byteArray[i * 2 + 1] = tempBytes[1];
}
[/code]

This is the code where I take the shaderData string, consisting of the full shader code, and turn it into a byte array. The string is taken from a multiline textbox control.

I can't seem to find any errors so I'd appreciate if anyone else finds any.

Share this post


Link to post
Share on other sites
To get byte array from string just use Encoding class:
[code]byte[] sourceBytes = System.Text.Encoding.UTF8.GetBytes(sourceString);[/code]

And afaik ShaderBytecode.CompileShader can accept string as shader source - there is no need to convert it to byte array:
http://slimdx.mdxinfo.com/latestdocs/help/html/M_SlimDX_D3DCompiler_ShaderBytecode_Compile_2_f3570541.htm

Share this post


Link to post
Share on other sites
[quote name='Martins Mozeiko' timestamp='1318093908' post='4870528']
To get byte array from string just use Encoding class:
[code]byte[] sourceBytes = System.Text.Encoding.UTF8.GetBytes(sourceString);[/code]

And afaik ShaderBytecode.CompileShader can accept string as shader source - there is no need to convert it to byte array:
[url="http://slimdx.mdxinfo.com/latestdocs/help/html/M_SlimDX_D3DCompiler_ShaderBytecode_Compile_2_f3570541.htm"]http://slimdx.mdxinf..._2_f3570541.htm[/url]
[/quote]

Oh man, so embarrassing to have missed that one. Thanks a ton, it works like a charm now!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this