Sign in to follow this  
cozzie

Easier way then 'GetParameterElement'?

Recommended Posts

Hi,

 

I'm trying to set float arrays to my HLSL parameter arrays.

Example:

 

The fx/effect file:

#define MaxPointLights 2

float3		PointLightPos[MaxPointLights];

In my code (C++) I achieve the expected resulted one of these 2 ways:

 

// one way

mEffect->SetFloatArray("PointLightPos[0]", myfloatarray, 3);

// another way

D3DXHANDLE param = mEffect->GetParameterElement("PointLightPos", 0);
mEffect->SetFloatArray(param, myfloatarray, 3);


Both ways work, where the 2nd is the most flexible (in the 1st one I need for hard code "PointLightPos[0]", [1] etc (or make a D3DXHANDLE adding strings etc.).

 

My question;

Is the 2nd option I do the best one, or is there a better/ easier way to set the element of a parameter in a d3dxeffect?

 

Share this post


Link to post
Share on other sites

The second one is better as long as you cache the handle to the parameter.  You are essentially looking up the text based name of the parameter, so if you only do that once at startup, and then set the value with the handle thereafter, then you should be doing very well from an efficiency standpoint.

Share this post


Link to post
Share on other sites
Thanks.
What i could do then is use one and the same handle for static lights, set to the effect once at initial setup. And for dynamic lights save all d3dxhandles in my light class. Wouldn't the needed memory for that take away the advantage?

For example, one point light would need 5 different d3dxhandles.
On the other hand the number of dynamc lights is relatively low and i could do it with a dynamic array, only created for objects of my light class, where dynamic==true.

Share this post


Link to post
Share on other sites

IIRC, the handle is just a single integer value that maps easily to the handle.  You won't see any negative performance effects due to the usage of the handles - back in my D3D9 engine I did the exact same thing that we are discussing and it was perfectly fine.

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