2

I have the following code segment in a GLSL 4.0 core geometry shader:

void pushVertex(const int i)
{
    gl_Position = gl_in[i].gl_Position;
    // Some other stuff
    EmitVertex();
}

Later I basically call pushVertex(0); pushVertex(1); and so on.

This actually works on Windows with Nvidia drivers, however MaxOSX throws the error Indirect index into implicitly-sized array. Any ideas on a workaround?

1 Answer 1

1

Basically, you need to convince the GLSL compiler to inline this function so that the index becomes a constant, and indirect indexing isn't needed. Since the compiler apparently doesn't do it for you, you could try defining pushVertex as a macro:

#define pushVertex(I) if(1) {              \
    gl_Position = gl_in[I].gl_Position;    \
    /* other stuff */                      \
    EmitVertex();                          \
} else

Of course, if the compiler is so weak that it can't inline, it may have trouble with the macro.

Sign up to request clarification or add additional context in comments.

5 Comments

Yeah I solved it with a macro. I actually didn't know that GLSL supports macros to the extent of the C preprocessor. You might want to remove the trailing else though.
Oh okay, but wouldn't it work without the else? Wouldn't it also work without the if and just with curly braces?
Sure, as long as you don't try to use it like if (p) pushVertex(1); else pushVertex(2);
Oh I see. That is also the reason why people do it with do-while: #define doSomething(...) do {...} while(0). Honestly I think that is less confusing than the trailing else statement. Also: Macro programming has so many pitfalls that even I with now 10 years of C++ experience just learned something :D
The problem with do..while is that it's more likely to break from failing to optimize properly on a broken GLSL compiler that can't inline properly...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.