Author Topic: GLCanvasRender performance and mouse events  (Read 3304 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
GLCanvasRender performance and mouse events
« on: September 30, 2008, 09:17:01 pm »
Hello.

The following code gives many fps when using the GLCanvasRender:

Code: [Select]
while (true) {
            matrix.rotateY(0.1f);
            renderScene();
}

But when the rotating is done by using the mouse (drag event), the fps I get is somewhat opposit the mouse speed. To avoid unnecessary rendering drag events are ignored if mouse point equals previous mouse point. Test shows that the mouse speed does not affect the number of events. So why the low fps when using the mouse? Any ideas?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: GLCanvasRender performance and mouse events
« Reply #1 on: September 30, 2008, 09:19:11 pm »
Not from that small piece of code. What does renderScene() does and how do you count fps?

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: GLCanvasRender performance and mouse events
« Reply #2 on: September 30, 2008, 09:24:19 pm »
Render method:

Code: [Select]
public void render() {
   buffer.clear(backgroundColor);
   world.renderScene(buffer);
   world.draw(buffer);
   buffer.update();
   buffer.displayGLOnly();
   glCanvas.repaint();
}

Counting FPS:
Code: [Select]
long time;
int frames = 0;

while (true) {
    matrix.rotateY(0.1f);
    renderScene();
    frames++;
    if (time+1000<System.currentTimeMillis()) {
        time = System.currentTimeMillis();
        System.out.println("FPS: "+frames);
        frames = 0;
    }
}

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: GLCanvasRender performance and mouse events
« Reply #3 on: September 30, 2008, 09:27:29 pm »
Info: The mouse drag events dont seem to have same effect on the software render.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: GLCanvasRender performance and mouse events
« Reply #4 on: September 30, 2008, 09:52:45 pm »
Your fps-counter is not good for the AWTGLRenderer, because it behaves like Swing/AWT, i.e. a repaint() just schedules a repaint, it doesn't immediatly triggers one. You can easily make 1000 calls to repaint() but only get one actual repaint. Use an IPaintListener and put the fps-counter in one of its methods and see if the behaviour changes.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: GLCanvasRender performance and mouse events
« Reply #5 on: October 01, 2008, 09:31:35 am »
The issue is not the fps-counter, but the fps I get when using the mouse compared to the infinite loop (above). The visual result is still the same: smooth scene movement in the loop, and very poor fps on mouse drag - the mouse drag is calling the render method less times than the loop. The rendering nearly stops if i move the mouse quick enough - and thats not very fast. With software rendering the fps are also fine when rotating with mouse drag events.

Does anyone have experience with the GLCanvasRender and mouse events?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: GLCanvasRender performance and mouse events
« Reply #6 on: October 01, 2008, 09:38:18 am »
Maybe you are doing something expensive in the mouse event handling code? I would correct the fps-counter regardless of this, because then we have some numbers to work with instead of just a gut feeling, that i can't comment on, because i don't experience it.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: GLCanvasRender performance and mouse events
« Reply #7 on: October 01, 2008, 09:49:19 am »
From an experienced gamer's point of view I'd say 30+ frames/s in the loop regardless of render, and same fps with mouse using the software render.

Compared to:

Less than 1 frame/s using the mouse (same code) and the opengl canvas render.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: GLCanvasRender performance and mouse events
« Reply #8 on: October 01, 2008, 09:56:43 am »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: GLCanvasRender performance and mouse events
« Reply #9 on: October 01, 2008, 12:42:52 pm »
I tried to reproduce the problem, but i can't. This (very old) example of mine doesn't change speed on my machine when adding a MouseMotionListener. How does it behave on your system?

Code: [Select]
import com.threed.jpct.*;
import com.threed.jpct.util.*;
import java.awt.*;
import java.awt.event.*;

public class AWTTest extends Frame {

public static void main(String[] args) {
new AWTTest();
System.exit(0);
}

AWTTest() {
Canvas canvas = null;
Config.maxPolysVisible = 5000;
Config.saveMemory = true;

setTitle("AWTTest");
setSize(640, 480);
setLayout(null);

final FrameBuffer buffer = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
canvas = buffer.enableGLCanvasRenderer();
add(canvas);

canvas.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent me) {
System.out.println(me.getX()+"/"+me.getY());
}
});

World world = new World();

Object3D box = Primitives.getSphere(30, 10);
world.addObject(box);
box.calcNormals();
world.setAmbientLight(055, 055, 055);
world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 50);
world.getCamera().lookAt(SimpleVector.ORIGIN);
world.addLight(new SimpleVector(10, -50, 0), Color.red);
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);

TextureManager.getInstance().addTexture("test", new Texture("test.jpg"));
TextureManager.getInstance().addTexture("test2", new Texture("test2.jpg"));
Texture text = new Texture("text.jpg");
box.calcTextureWrap();
TextureInfo ti = new TextureInfo(TextureManager.getInstance().getTextureID("test"));
ti.add(TextureManager.getInstance().getTextureID("test2"), TextureInfo.MODE_MODULATE);
box.setTexture(ti);
box.build();

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setResizable(true);
setVisible(true);
boolean exit = false;

KeyMapper mapper = new KeyMapper(this);

while (!exit) {
if (buffer.isInitialized()) {
try {
KeyState ks = null;
do {
ks = mapper.poll();
if (ks.getKeyCode() == KeyEvent.VK_ESCAPE) {
exit = true;
}
} while (ks != KeyState.NONE);
buffer.clear(Color.blue);
world.renderScene(buffer);

world.draw(buffer);
buffer.blit(text, 0, 0, 100, 100, 256, 256, FrameBuffer.TRANSPARENT_BLITTING);
buffer.update();
buffer.displayGLOnly();

box.rotateX(0.003f);
canvas.repaint();
                                        Thread.yield();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

}


Edit: Added a Thread.yield() to work better on single cores. However, even when restricting the application to one core, i can't reproduce the problem.
« Last Edit: October 01, 2008, 12:58:59 pm by EgonOlsen »