Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Quickest way to calculate what to draw (jogl)  (Read 2937 times)
0 Members and 1 Guest are viewing this topic.
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Posted 2009-03-13 10:58:27 »

Hi all,

I posted a thread yesterday regarding VBO/Displaylist for speed but during writing it I realized that the problem wasn't the VBO's but the calculations around them.

I am currently doing as follows:
Fill 160 VBO's with 1024 triangles each (3072 vertices). After that I store the buffer ids into a hashmap that looks something like this:
Hashmap<Position, Buffer>.

When my view has changed I do an unproject on each corner of my application against z=0 to get a rectangle (getRedrawViewport) containing what coordinates I can see. I don't think that the unproject is a problem because I get the same fps when I move my camera and when I don't.

My loop in the display function to pick up the correct hashmaps looks like this:

(Containers.getContainersize() is the size of the VBOs, they are all of the same size)

for (int i=(int) Math.floor(getRedrawViewport().getX()/Containers.getContainersize());i<Math.ceil(getRedrawViewport().getMaxX()/Containers.getContainersize());i++){
   for (int j=(int) Math.floor(getRedrawViewport().getY()/Containers.getContainersize());j<Math.ceil(getRedrawViewport().getMaxY()/Containers.getContainersize());j++){
      CurrentPos=new Point2D.Double(i,j);
      int[] ids = Containers.GetBufferIds(CurrentPos);
      //Draw the buffers
   }
}

What is the quickest way to do this because I don't think I'm doing it right.

If you want more info just give a shout.

Thanks in advance.

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline gouessej

« In padded room »



TUER


« Reply #1 - Posted 2009-03-13 11:09:33 »

What about using some space partitioning method(s)? BSP trees? Octrees? Cells and portals?

Offline cylab

JGO Knight


Medals: 34



« Reply #2 - Posted 2009-03-13 11:12:03 »

I don't get this loop (maybe you can eloborate), but this way you would have a lot of checks especially with bigger redraw viewports. Another problem might be, that you don't take the zaxis and perspective projection into account.

I think what you are after is view frustum culling: http://www.lighthouse3d.com/opengl/viewfrustum/

Edit: Later you can look into space partinioning, but with 160 objects you probably can check each every frame.

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #3 - Posted 2009-03-13 12:18:06 »

What about using some space partitioning method(s)? BSP trees? Octrees? Cells and portals?

Those words meant nothing to me but I'll google them Smiley

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #4 - Posted 2009-03-13 12:28:16 »

I don't get this loop (maybe you can eloborate), but this way you would have a lot of checks especially with bigger redraw viewports. Another problem might be, that you don't take the zaxis and perspective projection into account.

Sure, the loop goes as following:
Each container has an incrementing x and y value (so 0,0;0,1;1,0;1,1 and 156 more). I have created a rectangle of which of these are currently visible (so if the rectangle is (7,7,2,2) I loop through the x values 7, 8 and 9 and the y values 7, 8 and 9 and for each combination I do a get on my hashmap to get the FBO buffers I should draw.

The z values and perspective projection are taken into account when I generate the rectangle of what I can see, I have a fixed range for z.

I think what you are after is view frustum culling: http://www.lighthouse3d.com/opengl/viewfrustum/

Edit: Later you can look into space partinioning, but with 160 objects you probably can check each every frame.

They do it the other way around. Instead of saying "This is what you see, get all the objects inside it" they loop through all objects and ask "do I see this object?" Is that preffered when it comes to performance?

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline cylab

JGO Knight


Medals: 34



« Reply #5 - Posted 2009-03-13 12:42:41 »

They do it the other way around. Instead of saying "This is what you see, get all the objects inside it" they loop through all objects and ask "do I see this object?" Is that preffered when it comes to performance?

Yep. It's the standard way of doing it and combined with spatial partitioning and hierarchical bounds very fast even with a lot of objects.

The z values and perspective projection are taken into account when I generate the rectangle of what I can see, I have a fixed range for z.

So all of your objects are coplanar at a fixed z-value?

Those words meant nothing to me but I'll google them Smiley

Actually your approach seems to be some kind of space partitioning, but flat and not hierarchical, which would make out the benefit of space partitioning. The theory is that you can rule out groups of partitions because the test criterion for the parent partition already discards the spatial area in the check.

Mathias - I Know What [you] Did Last Summer!
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #6 - Posted 2009-03-13 13:06:43 »

Yep. It's the standard way of doing it and combined with spatial partitioning and hierarchical bounds very fast even with a lot of objects.

I'll change it around and see what happens, also, it is fine for performance to have the combination position and buffers in a hashmap or should I do it in another way?

So all of your objects are coplanar at a fixed z-value?

Nope, but they do have a max and a min so when I generate the rectangle of what is visible I do the calculation 8 times and take the points furthest away (once per corner per absolute z value).

Actually your approach seems to be some kind of space partitioning, but flat and not hierarchical, which would make out the benefit of space partitioning. The theory is that you can rule out groups of partitions because the test criterion for the parent partition already discards the spatial area in the check.

Sounds reasonable, I'll look into partitioning and the buzz words in the previous post.

Thanks alot everyone Smiley

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline cylab

JGO Knight


Medals: 34



« Reply #7 - Posted 2009-03-13 13:19:01 »

I'll change it around and see what happens, also, it is fine for performance to have the combination position and buffers in a hashmap or should I do it in another way?

Leave alone the hashmap, they will likely be slower than flat lists for only 160 objects and the sole position is unsufficient for fustum culling anyway. Store the 160 VBOs along with their position and bounds (spherical for starters, since sphere<->plane intersections are are fast and easy to compute) in a simple list/array/whatever and iterate over them every frame. Once you grasped spatial partitioning trees you can make your own container hierarchy.

Mathias - I Know What [you] Did Last Summer!
Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #8 - Posted 2009-03-13 18:28:20 »

After messing with performance during the whole day I have some other tips as well:

Only call gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); when you really, really need to, it takes alot of time (relatively) to clear.

Avoid both new as well as hashmaps in your display loop.

If using overlay only draw what really needs to be drawn.

Thanks alot guys.

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!