Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling Java classes to GLSL #1

Open
jarble opened this issue Aug 20, 2019 · 2 comments
Open

Compiling Java classes to GLSL #1

jarble opened this issue Aug 20, 2019 · 2 comments

Comments

@jarble
Copy link

jarble commented Aug 20, 2019

In some cases, it should be possible to translate Java classes to GLSL structs, but I'm not sure if JLSL can do this yet. This is a simple Java class with instance methods that can be converted to GLSL:

public class Rectangle{
    public float width;
    public float height;
 
    public Rectangle(float width,float height){
        this.width = width;
        this.height = height;
    }
    public float area(){
        return this.width*this.height;
    }
    public float perimeter(){
        return (this.width+this.height)*2.0;
    }
}

Then the JLSL compiler's output might look like this:

struct Rectangle{
    float width;
    float height;
};
 
Rectangle new(float width,float height){
    Rectangle self;
    self.width = width;
    self.height = height;
    return self;
}
 
float area(Rectangle self){
    return self.width*self.height;
}
 
float perimeter(Rectangle self){
    return (self.width+self.height)*2.0;
}

An instance of the class could also be initialized:

Rectangle shape = new(1.0,1.0);
float area = area(shape);

Would it be feasible to implement this feature in JLSL?

@jglrxavpok
Copy link
Owner

This project has not been updated in years. Maybe if I get back to it I will implement such a feature but no promises.

(And translating JVM bytecode to SPIR-V bytecode would be nice too)

@jarble
Copy link
Author

jarble commented Sep 1, 2019

Alternatively, you could modify a tool like ShaderGen to generate GLSL source code. It takes C# source code as its input, so you would only need a few small modifications to make it work with Java.

It is probably easier to translate Java to HLSL than to GLSL, since HLSL supports classes and interfaces (and GLSL doesn't.)

The Slang shading language also supports classes, so it might be feasible to compile Java classes to Slang and then compile them to GLSL.

@jarble jarble closed this as completed Sep 1, 2019
@jarble jarble reopened this Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants