Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Canvas alternative for high-polygon-count real-time updates?

3026511Sep 6 2015 — edited Sep 10 2015

Hello Guys!

I'm looking for the most efficient way to solve the following problem:

- A picture containing up to a very high polygon count (>10000, may overlap and be partially transparent) must be rendered

- a few polygons at once have to be moved in real-time in responce to mouse movements, while the most of the others will not be affected. I can not, however, know which will remain static, so caching may be a problem. As polygons can stretch throughout the entire screen, a single movement can cause the whole area to be invalidated.

The natural solution seemed to use a Canvas, so I made a simple test (ScalaFX ahead):

class MyCanvas extends Canvas {

  val gc = this.graphicsContext2D

  onMouseMoved = (me: MouseEvent) => {

   draw

   gc.strokeLine(0,0, me.x, me.y)

  }

  def draw = {

   gc.clearRect(0,0,500, 500)

   gc.fill = Color.GREEN
   for (i <- 10.0 to 500 by 0.1) {

   gc fillPolygon Seq(i -> i, i -> 5, (i - 2) -> 5, (i - 2) -> (i - 2))

  }

  }

}

This would draw a few thousand dummy polygons + a line to the mouse pointer on every move. Even with HW acceleration enabled, updates are beyond slow here (approx 1FPS).

Is there a way to accomplish this smoothly and what would be the best way to do it? Would I gain much by deriving NGNode myself? Especially, is there a way to make the code only care about the changed polygons instead of reiterating the whole model every frame?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2015
Added on Sep 6 2015
3 comments
786 views