0

I have a Procedural Texture generation algorithm which generates a texture.The texture is simply a BufferedImage.

This texture is basically mapped to an object in Java3D. Now since the texture is not going to change during the execution of the program, I want to precompute the texture during compilation itself so that during execution it uses the precomputed texture.

If the texture instead was generated during runtime it lead to delay in startup of the program.

My Question is,

Is it possible to precompute the texture during the compilation phase itself ?

Extreme Coders
  • 3,441
  • 2
  • 39
  • 55
  • You could run the texture generation software once, save the texture into a file, then load the same texture when you begin your program. – Name Feb 11 '13 at 16:41
  • You can do whatever as part of your project build, but how this is done depends on how you build your project in the first place. `javac` doesn't really let you run arbitrary code as part of the compile (unless you count `apt`), while IDEs or `maven` are much more flexible. – millimoose Feb 11 '13 at 16:44
  • @millimoose If i add a `final` modifier to the field, will it make a difference, i.e. will the compiler recognize that field as constant and precompute it. – Extreme Coders Feb 11 '13 at 16:51
  • @ExtremeCoders I strongly doubt the Java compiler can precompute nonprimitive constants. (Give or take `String`s.) – millimoose Feb 11 '13 at 16:53

1 Answers1

2

I don't think so, but you could write a separate Java program to compute the textures and save the BufferedImages to files, to be read by the game Java program.

It's up to you to determine whether the time saved is worth the storage space.

Edited to add: Most games either have you sit through a video during texture calculation, or they tell you that they're calculating textures. Anyone else remember "Reticulating Splines"?

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • If i add a `final` modifier to the field, will it make a difference, i.e. will the compiler recognize that field as constant and precompute it. – Extreme Coders Feb 11 '13 at 16:52
  • Nope. final just means that the value is set once, either as part of the definition or in the constructor. The value is computed during execution, not compilation. – Gilbert Le Blanc Feb 11 '13 at 17:01