Is there a way to use an union in GLSL?
<p>I was wondering if there is a way to use an union in GLSL. I haven't seen any documentation about this. If not, is there a clean workaround to using a union.</p>

<p>I basically want an array of something. And that something might be either of 2 things, therefore I would like to use a union to define it.</p>

<p>Thanks!</p>

<p>P.S. There might be some weird casting trick to do this that I don't know about, feel free to suggest a better method.</p>

<p><strong>Edit:</strong></p>

<p>Code example(would not compile because union is not available):</p>

<pre><code>struct A{
    bool isA;
    float value;
};
struct B{
    bool isA;
    int value;
};

/* union */
union AandB {
    A a;
    B b;
}

void main()
{
    AandB foo;
    if(foo.a.isA)
        /* process on A */

    else
        /* process on B */
}
</code></pre>

<p>Also, imagine A and B are huge, you wouldn't want to duplicate them.</p>

<p><strong>Edit 2:</strong></p>

<p>Here's some more information, hope it helps:</p>

<p>This data would come from "outside" and be vertex specific. It would have to be treated differently depending on the type(A or B). They'd probably be accessed from a VBO.</p>