Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Ternary Operator in Netbeans OpenGL plugin GLSL Editor  (Read 4871 times)
0 Members and 1 Guest are viewing this topic.
Offline AI Guy

Senior Newbie





« Posted 2007-11-11 01:38:53 »

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!
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #1 - Posted 2007-11-11 19:48:07 »

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.
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?

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?
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...

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!
thanks, i put it on the TODO Stack.

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 very much!

Offline AI Guy

Senior Newbie





« Reply #2 - Posted 2007-11-12 16:57:53 »

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.
 
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #3 - Posted 2007-11-12 23:34:52 »

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

Offline bienator

Senior Member




OutOfCoffeeException


« Reply #4 - Posted 2007-11-14 00:14:02 »

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.

Offline AI Guy

Senior Newbie





« Reply #5 - Posted 2007-11-14 17:33:43 »

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

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);
}


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!
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #6 - Posted 2007-11-14 22:52:58 »

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.
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.

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.
Interesting, so you are doing GPGPU (general purpose computations on the GPU)?

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.
Interesting workflow Smiley

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)

Offline AI Guy

Senior Newbie





« Reply #7 - Posted 2007-11-15 20:10:27 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (14 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!