Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to access some variables in my shader, but I think I'm doing this wrong. Say I have a constant buffer that looks like this:

cbuffer perFrame
{
    float foo;
    float bar;
};

I got an ID3D10EffectConstantBuffer reference to it, and I can get a specific index by calling GetMemberByIndex, but how can I figure out how many members perFrame has so that I can get each member without going out of bounds?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If you have an ID3DX10EffectVariable that represents perFrame, then you should be able to call GetType to get an ID3DX10EffectType for perFrame. Then you can call GetDesc on that type instance to get a D3DX10_EFFECT_TYPE_DESC which has a Members field which should give you want you need.

That said, I think accessing members by index is generally fairly brittle and that giving fields semantics whenever possible to more desirable.

Note that I have never actually tried this on structures denoted cbuffer so there may be some additional hoops you need to jump through if things don't quite work out -- constant buffers may have some specialized rules or handling via the effect interface. But I'm reasonably sure this will at least set you on the right track given that constant buffers seem to be well-understood by the API.

EDIT: I retargetted all the links to point at the D3D10 versions and not the D3D11 versions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.