I am trying to create an application in java that loads and configures a range of different GLSL shaders. Currently I've got something like the below, but will end up probably with lots more (30+) more similar classes - each loads an individual shader.
Ideally, I'd like to be able to put the shader classes in a list, and link them up to a GUI so that shader parameters can be retrieved and updated. Apart from same common logic (loading the GLSL file and returning a PShader), the variables (and getters/setters) may be quite different for each class (for example, some GLSL shaders I want to use have no variables, while others may have one or multiple variables - float, boolean, int etc).
I could have some kind of base class, and extend the class to handle different variables, but that still probably leads me at some point having to manage some kind of type checking / using a bunch of instanceOf statements. I'm struggling to see how polymorphism could be readily applied here. I've looked into java reflection, but that didn't get me too far, and have been looking at different design patterns.
Note - this isn't homework. It's just a personal project. So, I'm not concerned about having something that has to be maintained by others, but it has piqued my interest in different design patterns, and I'm wondering if there is a better way to structure this.
public class ChromaColor {
private Shader shader;
private float smoothing;
public Chroma(){
shader = loadShader("chroma.glsl");
setSmoothing(0.1F);
}
public Chroma setSmoothing(float f) {
if(shader != null) shader.set("smoothing", f);
this.smoothing = f;
return this;
}
public float getSmoothing() {
return smoothing;
}
public Shader shader() {
return shader;
}
}
Aucun commentaire:
Enregistrer un commentaire