Easier way then 'GetParameterElement'?

Started by
3 comments, last by cozzie 11 years, 2 months ago

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?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

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.

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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.

thanks, will implement it

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement