   Effects replacing Materials
  I am in the act of developing an abstraction of OpenGL, D3D9 and D3D10..I don't want to include structures like D3DMATERIAL9 and like D3DLIGHT9.. Instead, effects will exhibit ID3DXEffect like behavior, this is for the three of APIs.However it still sounds messy, and the parameter passing should prove ugly I think.. I'd really like some help with this design since am very incompetent in OpenGL, and perhaps even in the whole Effect scene.   
  I assume you just mean an ID3DXEffect-esque interface?  You can always look into something like CG, which is cross platform and handles many of the state changes that you'll need to handle.  To do it manually shouldn't be difficult, though.  You just need to setup some type of interface for setting different values (lights, materials, programs, etc), then define how each API does it internally.class IEffect{   virtual HRESULT SetRenderState(int iState, int iValue) = 0;   virtual HRESULT SetMaterial(MATERIAL *pkMaterial) = 0;   ...};Taking D3D as an example, you'd just create a CEffectD3D class, then fill those functions in specific to that API.  For basic fixed function rendering this is simple, you can encapsulate everything needed (the device, textures, etc), and give virtual access to everything.  The problem comes when you want to add vertex/pixel programs to the mix, since each API has it's own language for programming the GPU.  You'll need to abstract that language, as well, or use something like CG (the CG compiler itself can compile to whatever API language you need).   ;Quote:Original post by arithmaI am in the act of developing an abstraction of OpenGL, D3D9 and D3D10..I don't want to include structures like D3DMATERIAL9 and like D3DLIGHT9.. Instead, effects will exhibit ID3DXEffect like behavior, this is for the three of APIs.D3DMATERIAL9 and D3DLIGHT9 structures belong to the now obsolete Fixed Function Pipeline. There's no point in implementing them since Programmable Function Pipeline is a superset of FFP. D3D10 has even dropped support for FFP, so don't look for equivalent structures there. You can implement FFP-style lighting and materials via shaders. A Fixed Function Shader in HLSLQuote:However it still sounds messy, and the parameter passing should prove ugly I think.. I'd really like some help with this design since am very incompetent in OpenGL, and perhaps even in the whole Effect scene.You have basically several options here. As already pointed out, Cg is a viable option. It's API-agnostic and has back-ends for both Direct3D and OpenGL. You can either directly use Cg in your code or write interfaces and leave the door open for later opportunities. Personally, I have interfaces with implementations for both ID3DXEffet and Cg. That's probably overkill. Kind of like chasing a mouse with a rifle [wink].   ;  I've been looking into this also. I've come across a limitation that I am not sure how to get around.  The Effects framework cannot load textures from my PAK file system.  How I can use FX files to define my texture stages without having a separate file to define the filenames for my textures?   ;  I know cg can be used with directx 9 and opengl, but can it be used with directx 10 also? i was looking into this same exact thing a while back and I wanst able to find any way to interface cg with directx10...I also heard that ati cards have trouble with cg sometimes (i dont have an ati card so i dont know for sure)   ;Quote:original post by paradoxnj:I've been looking into this also. I've come across a limitation that I am not sure how to get around. The Effects framework cannot load textures from my PAK file system.How I can use FX files to define my texture stages without having a separate file to define the filenames for my textures?First of all, it's not the job of the Effects framework to load your art assets. You have to explicitly write loaders to load your art assets and have those effect-specific parameters point to the now loaded, memory resident copies of those art assets.If you want to reuse the same shader for several meshes with different effect-specific properties, such as textures or specular power in a phong shader for instance, which is usually the case, you have to bind these properties at loading time or otherwise you'd end up with a million shaders with hard-coded parameters, which is not practical except for very small scenes. The required information about this assignment process must come from somewhere then, be it simple home-made scripts or mesh files themselves. It's totally up to you. If you really want to hard-code these properties you might want to look at annotations. Look for "DirectX Standard Annotations and Semantics Reference" in DirectX SDK.Quote: original post by arithma:I know cg can be used with directx 9 and opengl, but can it be used with directx 10 also? i was looking into this same exact thing a while back and I wanst able to find any way to interface cg with directx10...I also heard that ati cards have trouble with cg sometimes (i dont have an ati card so i dont know for sure)AFAIK Cg doesn't currently support shader model 4.0, but it has an active community, so who knows?DirectX10 effects shouldn't really pose a threat given that you have clear interfaces to take care of it. As they say, everything in computer science can be solved by an extra level of indirection [wink]. You can have interfaces with implementations for CgFX, ID3DXEffect and ID3D10Effect, but I wouldn't really expect for such an interface  to fully cover those three different APIs 100%. You will come to a point where most of the common behavior is covered but there's always that one little extra feature exposed by one API that others don't support. So be prepared. As a work-around I expose pointers to API-specific interfaces in derived classes for people who really want to work with those extra features. So they can downcast and get a pointer to ID3D10Effect for instance and live a happy life ever after. This is somehow against OOP merits, but its a painful decision we have to make in a far from perfect world.I don't have an ATI card either. I'd be grateful if someone with some statistics could jump in and give us a hand.[Edited by - Ashkan on August 30, 2007 5:58:39 AM];  Ashkan, what you said makes perfect sense.  I am using AngelScript for my scripting language.  Maybe I can use that to make mappings to the FX files.   ;  You may also want to look into EffectParam sample from DirectX SDK. It demonstrates how to extract such info from .X files. It's a good example of how mesh files can encode such info.   