Jump to content
  • Advertisement
Sign in to follow this  
freeworld

Would a UNION work for this scenerio?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to simplify, aswell as increase the amount of data that can be passed to a D3DXEffect shader in my 2D renderer. Right now I've got a very hack and slash method of allowing only a certain amount of matricies, textures and floats be passed through, and each type is stored in it's own arrays of those type. example
struct MyShaderData
{
    float floatValues[4];
    D3DXMATRIX matrixValues[4];
    ...etc
}

But would a union work to replace that idea, I've never used a UNION before so correct me if I'm wrong.
union ShaderData
{
    float floatValue;
    D3DXMATRIX matrixValue;
    ....etc;
}

struct MyShaderData
{
    std::vector<ShaderData> values;
}

And maybe store a data type id somehow that would let me know what value to extract, and what function to use to pass it to the shader?
if (dataType == MATRIX)
    shader->SetMatrix("MyMatrix", values[index].matrixValue);

Share this post


Link to post
Share on other sites
Advertisement
I don't understand.

What are all the possibilities for the kind of data you can legally pass to the shader? What are the limitations, and why do the limitations exist?

You have to think about requirements - in much more detail - before you can design implementation.

Share this post


Link to post
Share on other sites
union ShaderData
{
float floatValue;
D3DXMATRIX matrixValue;
....etc;
}


Do you want to access the underlying data in some situations as floats and in other situations as whatever D3DXMATRIX is?

I understand this in C, so using that convention, here's one example of using a union.

typedef union tagPointerData
{
unsigned long dword;
unsigned long *pointer;
}
PointerData;

PointerData foo;

foo.pointer = FunctionThatReturnsPointerToULong();

use foo.dword to use the value in foo as unsigned long rather than as a pointer to unsigned long.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!