Hello Guest

Rendering 2D quads using GL_POINTS and custom Geometry shader. (LWJGL3)

  • 7 Replies
  • 7057 Views
Hello!, i'm trying to write a game engine for my game; i'm using Geometry shader for expanding a single GL_POINTS into a quad using GL_TRIANGLES_STRIP. The thing is i'm getting low fps 40 fps rendering 4000 sprites (Batched on the same draw call).

The geometry shader is: https://github.com/Ghrum/Ghrum/blob/master/LibMultimedia/src/main/resources/shader/Basic_Geometry.glsl
And my Batcher class: https://github.com/Ghrum/Ghrum/blob/master/LibMultimedia/src/main/java/com/ghrum/multimedia/render/SpriteBatcher.java

What is that i'm doing wrong?, also swapBuffers and pollEvents seems to run slow (On an empty loop it slowdown to 200fps), according to YouKIT 95% of the time is executing glfwSwapBuffers:
Code: [Select]
       
        GLFW.glfwSwapBuffers(...);
        GLFW.glfwPollEvents();

Finally the render code:
Code: [Select]
        if (!pDisplay.isCloseRequested()) {
            pDisplay.update();
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

            mBatcher.begin();
            {
                mBatcher.setCamera(mCamera);
                for (int z = 0; z < 100; z++)
                    for (int x = 0; x < 8; x++)
                        for (int y = 0; y < 6; y++)
                            mBatcher.drawTexturedQuad(mTexture, x * 128, y * 128, 128, 128);
            }
            mBatcher.end();

            final long m = System.currentTimeMillis();
            if (m - mLastTime >= 1000)
            {
                mLastTime = m;
                System.out.println("FPS: " + mFPS);
                mFPS = 0;
            } else {
                mFPS++;
            }
        }

Thanks!
« Last Edit: February 26, 2015, 04:54:43 by Wolftein1 »

*

Offline Cornix

  • *****
  • 488
I dont know if anything is wrong with your code, but why do you not just draw triangles to begin with? Is there any reason at all not to do what everbody else is doing?

I dont know if anything is wrong with your code, but why do you not just draw triangles to begin with? Is there any reason at all not to do what everbody else is doing?

I'm trying to take advantage of OpenGL 3.X features; by rendering with a Geometry Shader i was able to reduce vertex bandwith by a lot.

Using GL_TRIANGLES or GL_TRIANGLE_STRIP will require 80 bytes per sprite, while this method only requires 36 bytes per sprite. (Using Position, Color and Texture)
« Last Edit: February 26, 2015, 15:13:43 by Wolftein1 »

Decreasing the bandwidth you're using is unlikely to have any performance benefit unless you were already close to the max. Which you probably aren't. On the other hand, using the geometry shader so heavily could have performance implications. It sounds like a lot of extra work for no benefit.

After rebooting it seems i'm getting 177fps rendering 12.000 sprites.

*

Offline Cornix

  • *****
  • 488
That doesnt say anything.
I get 1200 fps rendering 2.000.000 sprites. If each sprite is less then 1 pixel in size.

What you do sounds like a really bad idea performance wise. Cutting bytes in half is not going to get you too much if each quad needs 10 times more processing time to be rendered.

That doesnt say anything.
I get 1200 fps rendering 2.000.000 sprites. If each sprite is less then 1 pixel in size.

What you do sounds like a really bad idea performance wise. Cutting bytes in half is not going to get you too much if each quad needs 10 times more processing time to be rendered.

Isn't that how point sprites works?, what would the best way to render multiple sprites (Point sprites, Geometry shader, or IBO + VBO + Triangles), also would be better to manipulate a buffer using mapping instead of glBufferXXXData?

Note: Is it normal to get 250fps just using swapBuffers in a empty loop? i'm running an i7 + gtx 570 (LWJGL3)

Thanks!
« Last Edit: February 26, 2015, 20:01:44 by Wolftein1 »

That doesnt say anything.
I get 1200 fps rendering 2.000.000 sprites. If each sprite is less then 1 pixel in size.

What you do sounds like a really bad idea performance wise. Cutting bytes in half is not going to get you too much if each quad needs 10 times more processing time to be rendered.

Finally fixed, wasn't related to it; changed some GLFW flags and i was able to get where i wanted. I tried both Geometry and GL_TRIANGLE batching; geometry gave me more perfomance than rendering with GL_TRIANGLES + IBO.