# Easier way then 'GetParameterElement'?

This topic is 1976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 on other sites

thanks, will implement it

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×