So I was wondering if there is a better way to deal with the multiple buffers/arrays/etc when I'm loading a heightmap (or other resource) because I'm producing a lot of duplicate data in the process.
Currently I point to the image and read it. From that I have a BufferedImage (I'm using Java) that holds all the heights.
That BufferedImage isn't directly usable for what I'm trying to do so I construct a vertex array out of its pixels, which is a plain array of floats (ie, XYZ-XYZ-XYZ and so on).
Now I read another image to get color data for each pixel (no texturing yet), again, I need to extract the data from that BufferedImage so I construct a new plain array of floats with a color per vertex (RGB-RGB-RGB and so on).
After that I construct an array of normals out of the vertex array I made before.
There I have all the data in 3 different arrays. I want an interleaved array to pass to OpenGL so I create a new array interleaving the data of the three float arrays.
Since OpenGL and Java don't get along that well, I also need to construct a FloatBuffer out of that interleaved array so I can pass the data to OpenGL.
Moreover, since I only retain the interleaved array, that's the one I'm using to get height information of the terrain to calculate the camera's height in the world. That means lots of offset this and offset that to get around the color and normal data in the array.
Summing up, I have massive amounts of duplicate data (two redundant BufferedImages and 3 float arrays, plus the needed FloatBuffer) while I'm loading it to only retain the interleaved array and the FloatBuffer.
Am I missing something important here? The garbage collector should get rid of the redundant stuff since I don't reference it anymore but it still quite a jump of used memory to load a single asset. It probably can get out of hand loading many things.
Edited by TheChubu, 19 March 2013 - 08:31 AM.