Ternary Operator in Netbeans OpenGL plugin GLSL Editor

The ternary operator “?:” works in both 2.0 GLSL & the ARB version. When typed into this editor it signals there is a syntax error when there is not. I am only using this facility for debugging, since my primary development is on MAC OS, and there is no production Java 1.6 yet. This plug-in does tries to do things that are not in 1.5. I reported 2 exceptions incountered, but not sure how to report a non-exception based problem. I have other Mac specific issues with Netbeans 6.0 beta 2. How do you report them?

Hope this is not too messy to deal with. I would have just used a max() function, but does not handle int datatypes.

It is still a very useful tool, even when having to copy code to a windows machine to see what is wrong! The compiler for ATI Radeon 9600 is useless at saying what is wrong, thru that info log call, when there is more than 1 thing wrong. Do not ever feed that thing a zero length string as a source line, or you will be screwed! It did eventually compile on the ATI card, ternary and all. Could not have ever done it without this tool telling me what was wrong. Great Job!

Thank you for reporting that, the editor uses a more or less handwritten grammar for cross platform syntax valitation. It is possible that I overlooked some rules in the spec.
Could you please provide a compileable code snippet?

NetBeans 6.0 should be compatible down to java 1.5 and run on Mac. I think the right place to report that kind of bugs is ether the mailinglist (http://www.nabble.com/Netbeans---Users-f2605.html) or directly via the bugtracking system somewhere at netbeans.org. I really hope that we will see some Mac OpenJDK builds soon. I personally do not expect any positive news regarding java 6 and mac from the Apple side…

thanks, i put it on the TODO Stack.

Thank you very much!

Here is the shortest compilable & linkage fragment shader showing the ternary operator in line 1 of main. This compiled on:
vendor: ATI Technologies Inc.
renderer: ATI Radeon 9600 OpenGL Engine
version: 1.5 ATI-1.4.18

/* Prototype from Open GL Programming Guide, Fith Edition, pg 652 */
float HornerEvalPolynomial(float coeff[10], float x);
void main() {
int a = (5 > 4) ? 25 : 62;
gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);
}

I also forgot to mention another thing the editor reports as a syntax error when none exists, function prototyes. My final fragment program is going to be composed 4 shaders all linked together. I put in function prototypes, like the one I copied from the Red Book. The editor does not like them.

thank you for the testcase. I will definitive fix the grammar but I am currently swamped… So please be patient :slight_smile:

the function prototype and ternary operator bug has been fixed.
GLSL editor v 1.3.1 is now available via update center. Please update and see if it is working for you.

For testing, rather problem illustration, I made a nasty version of the example:

[b]flat HornerEvalPolynomial(flat coeff, flat x);
void main() {
Bool g = false;
int a = g ? 25 : ((3 >4) ? 16 : 42);

HornerEvalPolynomial(1.0, 1.0);

gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);
}[/b]

The ternary part worked fine. It was not fooled into thinking something was wrong.

You seemed to give a complete free pass now to function prototypes. There is no type or struct named flat. You even let me call HornerEvalPolynomial, passing floats as args. You are now too far in the other direction.

I am still impressed at how fast you responded. Any further work, do at your own pace. Multiple shaders linked to a single program might be a rare practice, since I am not even doing rendering. I am converting some of my pre-existing classes to GLSL shaders, so that I can offer a cheap, optional way to speed up a very computationally intense process. Just so I can be positive both Java & GLSL sources stay in-sync in CVS, I am storing the GLSL source in a function of the same class, returned as a string. I was printing this to system.out, and clipboarding into your editor to find my errors. So you are not holding me up! I do not even know what you are supposed to do with the files saved from this editor.

Thanks again!

yes thats right. The editor does currently just syntax validation, context sensitive validation is not yet supported. (But you should see an error annotation at this line with your drivers compiler/linker error message)
flat HornerEvalPolynomial(flat coeff, flat x);
is a valid statement in the GLSL syntax so no error.

I know the function prototype fix is very hacky because i noticed in meantime some other problems with NetBeans RC1.

Interesting, so you are doing GPGPU (general purpose computations on the GPU)?

Interesting workflow :slight_smile:

Why are you storing your shaders in Strings (this is just good practice in demo aps) instead of loading them at runtime from simple textfiles. This has several advantages (eg you don’t need to recompile your stuff if you change something)

GPGPU, yes this is a Portfolio Managment System. With these shader, I am writing an alternate way to perform the inner loops of an AI goal seeker, trying to determine the best sets of values for 20 unknowns in the model being used.

I am not just dropping the “all Java” version of the goal seeker, since some may not have the neccessary hardware, or might have been knocked back to OpenGL 1.1 on a Vista “upgrade”. It is also crucial that the only difference between the two ways be execution time. This is an overriding factor, that if it causes extra compiles, no biggy. If one version needs changing in the future, probably so does the other. Now both are in the same file to be easily seen together, and so CVS will have no choice but provide matching verison histories.

I would never drop the “all Java” version, since it is a lot easier to debug with stops, etc. The GLSL version is debugged by verifying it produced the same result.

Finally, returning GLSL from a Java function call allows for dynamic GLSL source creation, to get around compiler restrictions. An example: functions cannot return an array. You can return a structure like:

struct ArrayWrapper{
float values[MAX_SZ]; // where MAX_SZ is a literal number when source generated
int inUse;
};

In this application, MAX_SZ can change outside my control, based on the market. You could use a defined constant, but still the source for that would have to dynamically written. An arbitrary high value, is wasteful & dangerous if one day it was suddenly too low.