GLCanvasRender performance and mouse events

Started by ErDetEnAnd?, September 30, 2008, 09:17:01 PM

Previous topic - Next topic

ErDetEnAnd?

Hello.

The following code gives many fps when using the GLCanvasRender:

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?

EgonOlsen

Not from that small piece of code. What does renderScene() does and how do you count fps?

ErDetEnAnd?

Render method:

public void render() {
   buffer.clear(backgroundColor);
   world.renderScene(buffer);
   world.draw(buffer);
   buffer.update();
   buffer.displayGLOnly();
   glCanvas.repaint();
}


Counting FPS:

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;
    }
}

ErDetEnAnd?

Info: The mouse drag events dont seem to have same effect on the software render.

EgonOlsen

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.

ErDetEnAnd?

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?

EgonOlsen

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.

ErDetEnAnd?

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.


EgonOlsen

#9
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?


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.