maniel34
maniel34

Reputation: 187

Use static methods or methods from initialized objects for OpenGL stuff?

Is it more efficient to use static methods for OpenGL stuff rather than initialized objects?

So, instead of an object "Model" which contains data of one model, I have just the ID of the VAO, because I used a static method to load in the model and return the VAO ID. Same thing for shaders: Is it better to have a shader program object or just the ID of the shader program (static methods create the shader and return the ID)? Are there any downsides with this way? Is it more efficient, or should I just use objects?

(LWJGL3, Java)

Upvotes: 0

Views: 186

Answers (1)

GhostCat
GhostCat

Reputation: 140523

That really depends. If the methods are doing the same things, then there shouldn't be much of a difference. There would need to be millions of method invocation to make a real significant difference. And then the JIT should kick in anyway1

In general, relying on static methods does three things:

  • it creates a hard dependency to the class with the static method
  • it kills "polymorphism", you can't just go in and override methods to achieve different outcomes
  • it makes testing your code considerably harder

So, long story short: you typically lean towards non-static solutions, to avoid all the disadvantages outlined above.

Upvotes: 1

Related Questions