Performance issues

Started by laginimaineb, May 27, 2007, 19:57:03

Previous topic - Next topic

laginimaineb

Hello, I am very new to LWJGL and OpenGL which is why I am using two classes called BigTexture and SmallTexture to manage all of my textures (sources attached - thanks to vermin exterminator). Anyway, I just created a small app to check how many FPS I can get to. In the example I have one BigTexture whose size is 1600x1600 and one SmallTexture whose size is 32x32. Anyway, I am only getting 34-33 FPS which probably means I am doing something really really wrong. Perhaps it is something with the BigTexture and SmallTexture classes. I would like to hear somebody's opinion  :)

P.S - I am running the application on a 3.1 GHz processor with Ge-Force FX 5200.

With Thanks,
laginimaineb.

Orangy Tang

Er, why have different classes for BigTexture and SmallTexture? Can't you just use a single Texture class which can handle mulitple sizes?

Regardless, the speed problems are likely from your big texture. 1600x1600 is a horrible size for a texture. For best results texture sizes should be power-of-two in size (eg. 256x256, 1024x1024), non-power-of-two texture are either unsupported on some hardware, or, in your case, run much slower.

laginimaineb

Hey, sorry I forgot to mention, the BigTexture class actually breaks up the texture into tiles which are sized by powers of two. Anyway, you mentioned 1600x1600 is too big for a texture, which leads me to my next question - if so then what should I do in order to draw the background terrain? (I'm working on a 2D-shooter).

With Thanks,
laginimaineb.

bobjob

just curious, do you know how display lists work?

if not that could be a way to dramatically increase performance. i dont understand why you are getting such a performce hit after your splitting the image like that.

laginimaineb

Hey, I just found out something strange... without rendering at-all I am still achieving 34-35 FPS. This led me to think the game logic consumes a lot of effort, however, just running the rendering mechanism without the game logic also gets only 34-35 FPS. Since this was quite frustrating, I decided to test the application on a different stronger computer with a 3.3 GHz processor and a good ATI Radeon (can't remember which) achieved a better but still frustrating 42-43 FPS. There must be some big issue I am missing... Perhaps my initialization code is wrong. Just to keep on the safe side, I'll post it :)

public static void initFullscreen(String title){
    // set display mode and create fullscreen window
    try{
      Display.create();
      Display.setTitle(title);
      Display.setFullscreen(true);
      Display.setVSyncEnabled(true);
      System.out.println("Created OpenGL.");
    } catch(Exception e){
      System.err.println("Failed to create OpenGL due to " + e);
      System.exit(1);
    }

    try{
      Keyboard.create();
      Mouse.create();
    } catch(Exception e){
      System.err.println("Failed to create Keybourd and Mouse due to " + e);
      System.exit(1);
    }

    // enable texture mapping
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // alpha test/ blending
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.5f);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    GL11.glDisable(GL11.GL_DEPTH_TEST);

    // set up 2D mode
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), 0);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
  }



*Edit - I just noticed another thing, when the window isn't seen (minimized or entirely blocked from view by other windows) the FPS shoot up to 200-210 which is very very good. More than enough. Oh and by the way, even with a 1024x1024 sized map I get 33-34.

With Lots of Thanks,
laginimaineb.

laginimaineb

Hey, sorry for posting another message however I found out some of the reasons for the slow FPS. One of my mistakes was that I was making a direct call to Display.swapBuffers() which is made by Display.update() anyway so it was unnecessary. This has enabled me to advance to 50 FPS, however I believe my game can achieve more than that. After several re-runs, each time disabling a different thing, I found out that without running the game logic and by only rendering a small square using GL_QUADS, I only get to 60-61 FPS. It seems as though the Display.update() is consuming a lot of time, is there something I can do about it?

With Thanks,
laginimaineb.

Matzon

Display.setVSyncEnabled(false);

laginimaineb

Hey, I tried turning off VSync, however, I still get the same FPS. Using only the following code, I get 60 FPS:
while(!OpenGLUtils.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
            Mouse.poll();
            Keyboard.poll();
            logic();
            render();
            Display.update();
}

private void render() {
            GL11.glBegin(GL11.GL_QUADS);
            {
                        GL11.glVertex2i(50,50);
                        GL11.glVertex2i(50,100);
                        GL11.glVertex2i(100,100);
                        GL11.glVertex2i(100,50);
            }
            GL11.glEnd();
}


Is this to be expected?

With Thanks,
laginimaineb.

Matzon

depends on what logic() does ...

remove the             Mouse.poll();
            Keyboard.poll(); - they're not needed, it's done in Display.update();

check your drivers aren't forcing vsync

laginimaineb

I removed the poll()s, thanks. Anyway, I completely disabled VSync via the driver and suddenly the FPS shot up to 90, which is really surprising since vSync is supposed to limit the FPS to the actual refresh rate of the monitor and mine has 100Hz... Without the vSync there are some graphics abnormalities. That is, sometimes I see the remains of a previous frame flickering in the background. By the way, isn't it weird that even though I called Display.setVSyncEnabled(false), vSync is still apparently being used? Anyway, what should I do to avoid the flickers? Should I manually call swapBuffers()? Can I really disable vSync via the application and not via the card? Is the choice between vSync and FPS really the question of speed over quality?

With thanks,
laginimaineb.

Matzon

first of all, I dont get why you have such a slow fps - I get several thousand in an empty loop:

package org.lwjgl.test;

import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class EmptyLoopTest {

	public boolean initialize() {
		try {
			Display.setDisplayMode(new DisplayMode(640, 480));
			Display.create();
			return true;
		} catch (LWJGLException le) {
			le.printStackTrace();
		}
		return false;
	}
	
	private void execute() {
		long time = Sys.getTime();
		int fps = 0;
		while (!Display.isCloseRequested()) {
			render();
			Display.update();
			fps++;
			
			if(Sys.getTime() > time + Sys.getTimerResolution()) {
				System.out.println("FPS: " + fps);
				fps = 0;
				time = Sys.getTime();
			}
		}
		
		Display.destroy();
	}

	private void render() {
		GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2i(50,50);
        GL11.glVertex2i(50,100);
        GL11.glVertex2i(100,100);
        GL11.glVertex2i(100,50);
        GL11.glEnd();
	}
	
	public static void main(String[] args) {
		EmptyLoopTest test = new EmptyLoopTest();
		if(test.initialize()) {
			test.execute();
		}
	}
}

laginimaineb

Wow, that's it! It was just that I was rendering in full screen. When I ran what you gave me I got 990 FPS and then I changed it to full screen and got 90. So I guess it's mystery solved. :P

With Thanks,
laginimaineb.

Fool Running

You should get equal or even better frame rates in fullscreen view...
Thats very strange :-\

Are you doing fullscreen view at a high resolution?
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D