Crosscompiler Java -> GLSL?

Hi!

I got a bit inspired by Google’s GWT and their crosscompilation (source-to-source translation) from Java to JavaScript and thought about doing the same for Java to GLSL.

Are you aware of any existing projects that can do this?

Personally, I think it is a fantastic idea because then you could debug your (emulated and slow) shaders using e.g. Eclipse and then just translate and get the (fast) shader code.

Actually GLSL and Java are so different in scope, verbosity and data access, that such a thing could hardly be useful.

I am still optimistic, but you might be right :slight_smile:

There would have to be special Java classes for each primitive GLSL type (+ in, out and all other interfacing types) and a lot of other restrictions. I think that the debugging and coding part would be so much easier and the possibility to translate to different versions would make it useful anyway.

You use Netbeans and (perhaps develop?) the OpenGL tools right? Are there any similar tools for Eclipse?

It might be more useful to make a GLSL->bytecode compiler, so that you could at least step through a shader in the Eclipse debugger.

Cas :slight_smile:

Hmm, good idea!

Got any good Java GLSL parser somewhere?

I’ll go look in the Netbeans OpenGL tools and see if there is one with which you can traverse the AST.

The biggest problem is converting scalar code into vector (SIMD). You could make a classes that mimic the GPU types, but then you might as well directly write GPU code. If you want to be able to debugger shader code, there are tools for that.

If there is a very good tool available for GPU code that supports refactoring and immediate feedback through continuous compilation and all that nice Eclipse/Netbeans-like stuff, I would certainly prefer that. Besides, it very nice to be able to simulate different GPUs in software. You could for example simulate several different GPUs without owning the actual hardware. Such an effort will require the combined forces of 1000 gods though :wink:

krasse, even a simple Java dialect to write GLSL shaders would be interesting on my view. It would be fine if we could choose which GLSL version it should support in order to use the proper keywords. If a shader is modified, it should simply reset it (glShaderSource) and recompile it, shouldn’t it?

I’m trying to make Java2GLSL.(used ASM)
About 3weeks to work, and soon i make the alpha version.

Concept. (Current progress)

Java Code


VertexShader vtxShader = new VertexShader() {
	public void main() {
		mat4 mat1 = new mat4();
		mat4 mat2 = new mat4();
		gl_Position = mat1.mult(mat2).mult((vec4)gl_Position);
	}
};
StringWriter writer = new StringWriter();
J2GLSLConverter glslConverter = new J2GLSLConverter();
//glslConverter.debugOpCodeStack = true;
glslConverter.compile( writer, vtxShader );
System.out.println( writer.toString() );

Output GLSL Code


void main(  )
{
	mat4 mat1;
	mat4 mat2;
	gl_Position = mat1 * mat2 * gl_Position;
}

Cool!
I had forgot about this thread. It was back in the good old days when I had the “do absolutely everything in Java”-syndrome :slight_smile:

Still think it is a great idea though!

Nice try ;D

I just can’t see the benefit of this

If I would want to generate shader code on the fly, there would be many simpler ways to do it.

Debugging shaders with Java? I don’t think that you could do anything usefull with it.

I’m quite happy right now with my shader hot-reload function and auto binding system I have

Your point is that you don’t need public solution X, because you developed private solution Y. How does that help us? :slight_smile:

all my stuff is opensource and accessable at github. It might not be that well documented and so on. I would be happy to discuss, share and help with things like that. I just wanted to point out my take on shader development.

Update: some additional thoughts, I liked the netbeans opengl pack which gave autocomplete, code highlighting + compiler warnings for GLSL, but it somehow don’t work for me anymore. There is also GeDebugger(?) out there (now owned by AMD) which is made into a visual studio plugin, but return as a standalone also I think. The last time I tried it with JOGL it didn’t quite work, but I guess with some experimenting we should get it to run.

Netbeans OpenGL pack is no more maintained, I’m really sorry.

Please ask some help on the official JogAmp forum. As far as I know, Sven succeeded in using multiple tools to do that, including one from Nvidia.

Thank you for sharing your source code.

I released the alpha version.

Check this
http://code.google.com/p/j2glsl/

Source code (SVN)
http://j2glsl.googlecode.com/svn/trunk/

And there included example of using j2glsl.

it is indeed a very interesting project.
Looking forward for support of modern GLSL.

Have to think if this can be of use for me in anyway.

one plus of it would be compile time type checking, does it do that(how verbose is your error output btw?)

Aside from error checking when writing the shaders, are there any other benefits? :-\

I think a more elegant solution for this would be an IDE plugin or standalone tool that has auto-correct and automatic error checking as you type (for e.g. “error assigning vec3 to vec2”).

[quote]I think a more elegant solution for this would be an IDE plugin or standalone tool that has auto-correct and automatic error checking as you type (for e.g. “error assigning vec3 to vec2”).
[/quote]
Yeah i think so too. Maybe IDE plugin has better solution.

[quote]one plus of it would be compile time type checking, does it do that(how verbose is your error output btw?)
[/quote]
No.
That shader java code must be compiled. It is why i used ASM.
Currently, It is throw simple exception. But i will add more error-checking code in the future.

in addition my english is terrible. sorry about that. :’(

If you can also implement the operations and create a software shader, I think that you also get the benefit of debugging.