Help with CGFX

Started by
7 comments, last by drjaydenm 11 years, 1 month ago

Hi,

I am making a game engine with multiple rendering interfaces (currently only DX10 and OpenGL 3) and am trying to integrate CGFX into my pipeline. I have looked at the docs for CGFX but cannot seem to find anything that suits my needs.

What I am trying to do is compile a CGFX file to HLSL byte code as I can then just use my DX10Effect class to load the bytecode to a DX10 effect and DX will be happy. Looking at the docs for CGFX it seems I cannot get the DX10 bytecode from a CGFX effect. This means I will have to use CG to do all the effect technique and parameter work instead of DX itself.

Does anyone know if it is possible to get the DX10 bytecode from a CGFX effect?

Thanks.

Advertisement
I'm not sure if this is possible/impossible, but personally, I just compile my CG files with FXC myself as the syntax is basically the same as HLSL...

Thanks for your help,

I could just do that but I am trying to look for a universal solution where I can take the CGFX effect, compile to the specific rendering API like DX10, save the results as a DX10 effect and then load the DX10 effect at runtime without using the CGFX API to set each parameter and so on.

I could always just compile the effect using CGFX, get all programs in the effect, extract the DX10 data and make a DX10 effect out of that, although I am pretty sure I would lose the information on techniques and parameters.

Any ideas guys?

Thanks.

cgD3D10GetCompiledProgram is suppose to return the compiled shader code. You might be right in that you could loose technique information. You may also loose any data that was compiled out.

I had ALOT of issues with using cg in a similar situation to yours. Kept hitting a limitation with cg, made a work around for it then hit another limitation....this went on for a while. In the end I used HLSL2GLSL. It was made for dx9 and pre ogl3 but the source is available so you can modify it to work with dx10 and suit your own needs. There is also an updated forked version made for unity so that might be worth checking out too.

Thanks for your advice,

I will take a look at HLSL2GLSL as it does look promising. It is sad though, that CG is not able to output an effect file as DX bytecode and requires you to use their runtime instead of DX's. If it allowed you to do that, it would be an efficient solution to cross platform shaders.

It is sad though, that CG is not able to output an effect file as DX bytecode

cgD3D10GetCompiledProgram will return a ID3D10Blob object. From that object you can call GetBufferPointer and that will be the compiled code for a program. It is that data that you pass into say ID3D10Device::CreateVertexShader to create your shaders. If you're after the whole effect file as byte code then I don't think cg will do that (or directx for that matter).

requires you to use their runtime instead of DX's

If you can do without effects and just use programs, then you could also compile these shaders in an offline mode and save the compiled data to file. That way your runtime engine could just use dx libs instead of cg? Runtime loading would also be a bit faster. Of course though you would need to check that all this works with the cross-platformness of your engine.

I was thinking about using just the Vertex and Fragment programs instead of the whole effect file. Is there any benefit (other than the fact I can use techniques and passes), of using effects instead of the individual programs if I am doing all my state changes in my program code instead of in the effect? I can't think of any reason off the top of my head.

Looks like i'll try using individual programs and see how it goes.

Is there any benefit (other than the fact I can use techniques and passes) of using effects instead of the individual programs

Not that I know of. I personally use programs rather than effects. I guess the downside is you need to do all the state changes manually, but you're doing that already anyway.

Alright, thanks for your help :)

This topic is closed to new replies.

Advertisement