Jump to content
  • Advertisement
Sign in to follow this  

Beginner question

This topic is 3714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'v got a massive array of about half a million elements. Each element is an object that when set to TRUE, will display a square on the screen, but when FALSE will display nothing. My program currently loops through the whole array to render each frame. This is proving to be very inefficient as a lot of the objects remain inactive over long periods. Is there any way I can get only the active objects to be rendered while keeping the inactive ones on the screen from frame to frame? Thanx

Share this post


Link to post
Share on other sites
Advertisement
Not quite sure what you mean -
Are you asking if you can pass vertex data to OpenGL and then have OpenGL render those elements in future frames without specifying them again? If that's the issue - then no...OpenGL won't do that.

You might consider some other optimizations - such as level-of-detail or view frustum culling algorithms.
It's difficult to help without knowing a little more about how you are rendering those objects, or what they are. (or why you need half a million elements in a single scene).

Share this post


Link to post
Share on other sites
well im trying to simulate a colony of termites, and the environment is represented as a grid of cells in which they move around. Some of these cells are earth (building material) while others are empty, and the termites are able to build stuff with the earth, so each piece of earth must be represented individually so it can be picked up and placed somewhere else. This is why i need so much elements.

I think I just found the root of the problem, and it was indeed like u said, the level of detail. I'm using spheres to represent building material, and its the spheres that are taking so much time to render. I turned the level of detail down and the program runs much faster.

But are you saying that it is impossible to render individual things to the screen while keeping things from a previous frame?

So if I have 10000 elements and only one of them changes position I have to re render the other 9999 elements as well?

Share this post


Link to post
Share on other sites
No, you can render to a frame buffer and use that as a texture, saving it and not clearing it.

I don't know if you can use the accumulation buffer (never used it).

You can save the "picture" but the picture doesn't contain a lot of important stuff in 3D rendering.

Share this post


Link to post
Share on other sites
Yes, Boder, you're right - you can save the frame buffer as a texture. Then, you only need to render that texture, and any changes on top of it.

Also, if you have a 3D grid of these cells, interior cells which are not seen (because they are obscured by something in front of them) don't need to be rendered either. I don't know what kind of camera angles you're dealing with, but you might be able to reduce the number of spheres as well.

Share this post


Link to post
Share on other sites
why don't you also consider packing all the active stuff to the beginning of the array, that way you dont need to loop through the entire array you just need to proceed until you come to a false item. Depending on how much the different items are toggled could make this a considerably large optimization, but if things are fairly consistently changing then the amount of shuffling around to accommodate the packing could take more clock cycles than your original vanilla for loop.

if it's not much being changed from frame to frame then all you need to do is pack everything at the initialization, keep a record of the first false item, then anytime a false is changed to true you swap it's position with the recorded first false item and then record the first false item as the next position... and any time a true item is changed to false you just swap it with the item -1 from the recorded first false item, and then record the first false item as -1 from its current value.

i think that's right.

[edit] actually this means you don't even need to record whether something is true / false, as anything below the value you record is true and anything from it to the end of the array is false, so storing a boolean for this is redundant.

Share this post


Link to post
Share on other sites
was expecting someone to flame that idea... guess i killed the thread

oops........bump

Share this post


Link to post
Share on other sites
I quite like the idea of an ordered array with all the ones that need updating at the start.

Another option could be to have each object inform another which keeps a list of changed objects by array position (so just a vector of integers), so then you can just iterate through the objects listed then clear the vector?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!