Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (806)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL 3 VAO Rendering (Performance Optimizations?)  (Read 942 times)
0 Members and 1 Guest are viewing this topic.
Offline Feuerrohr

Junior Newbie





« Posted 2020-02-11 13:05:19 »

So I'm working on my game engine for about a year. I start from immediate mode to VBO and now to VAO.
My current Renderer works fine and for example i can draw 10.000 Quads (Split in two triangles) and i have 1600-1800 fps with a gtx 1080 and i7 6700K.

I also use JNI. For that i create a method that copies my vertexData into the buffer (gives also a good performance boost).

My current Mesh.java http://paste.myplayplanet.net/sozucacobe.java
So my questions is: Can i optimize more or is that good how it is?

for BufferUtils.copy I use JNI (memcpy)
Offline princec

« JGO Spiffy Duke »


Medals: 1146
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2020-02-11 13:24:32 »

One thing @theagentd asserted while we've been working on our Voxoid engine is that VAOs don't really bring much value - extra complexity for no particular gain in performance. It seems to have been a bit of an ill-conceived API/concept. We simply bind one at the very startup of our engine and leave it.

Cas Smiley

Offline VaTTeRGeR
« Reply #2 - Posted 2020-02-11 13:40:52 »

You could pack the color attribute into one float to save 12 bytes per vertex if you don't need the precision, but apart from that idk.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h.pernpeintner

JGO Ninja


Medals: 107



« Reply #3 - Posted 2020-02-11 14:03:37 »

I recently implemented programmable vertex pulling and can approve the results in https://github.com/nlguillemot/ProgrammablePulling . While not exactly bringing a performance gain, I find the improvements in API usage and API overhead very nice. Dunno but if your use case also includes multiple VAO,VBOs (for example for multiple entities, formats whatever), then you would also have a performance gain I think Smiley
Offline yboya
« Reply #4 - Posted 2020-02-11 14:15:35 »

If you call the method "setVertices()" just once, it is ok, but if you call it often, it can slow down your program as it makes a copy in memory.
Instead of working with a float array for vertices, you could use the class I wrote, FloatMemoryBuffer :

https://github.com/YvesBoyadjian/Koin3D/blob/master/Koin3D/jscenegraph/src/jscenegraph/port/memorybuffer/FloatMemoryBuffer.java

So there is no more memory copy.
Offline Guerra2442

JGO Knight


Medals: 82
Exp: 4 years


Guerra24


« Reply #5 - Posted 2020-02-11 15:46:18 »

There are some small changes.

Line 17, new allocated buffers doesn't need to be flipped.

Line 52, OpenGL methods accept direct array reference so you can remove the FloatBuffer entirely and pass the array into glBufferData.

Line 76, you're defeating the entire purpose of vaos, glEnableVertexAttribArray state is preserved in the vao so ideally you should enable them once when you create the vao (line 26) and in the render just bind the vao.

Working on Anarchy Engine.
Offline Feuerrohr

Junior Newbie





« Reply #6 - Posted 2020-02-16 12:34:45 »

Ok thanks but why all examples use a buffer when its possible to use a float array directly?
Offline Feuerrohr

Junior Newbie





« Reply #7 - Posted 2020-02-16 12:38:36 »

And another questions is: How big should I make the buffer?
Because I test it and currently I use 1000 * (count of X, Y, Z, R, G, B, A, U, V) = 9000 [9000 * 4 Bytes -> Float -> 36000]

I test it with higher values but then the fps are 500 and with 1000 i have 1600 fps
Offline Guerra2442

JGO Knight


Medals: 82
Exp: 4 years


Guerra24


« Reply #8 - Posted 2020-02-16 16:32:17 »

Ok thanks but why all examples use a buffer when its possible to use a float array directly?

That depends on what are you using to load meshes, usually they are already in *Buffer form and because the performance depends on the JVM if it supports critical natives but since this is a load method and is expected to not run as much you can justify the performance hit. But that's up to you.

And another questions is: How big should I make the buffer?
Because I test it and currently I use 1000 * (count of X, Y, Z, R, G, B, A, U, V) = 9000 [9000 * 4 Bytes -> Float -> 36000]

I test it with higher values but then the fps are 500 and with 1000 i have 1600 fps

You don't need to keep the buffer allocated during the execution, you can allocate the buffer in setVertices with size vertices.length, upload the data to OpenGL and then free it. (or pass the array directly)

This is also a bit of memory optimization because you can create a mesh with a single triangle but the buffer is way too large for it so you're wasting both ram and vram (in the example).

Performance-wise it depends on the driver and gpu, and how it treats buffer that are larger than the requested vertex count so it can vary quite a bit. You should keep them at the same size of the input data.

Working on Anarchy Engine.
Offline Feuerrohr

Junior Newbie





« Reply #9 - Posted 2020-02-16 17:36:36 »

Ok thx

Do you have Discord and I can ask you questions if i had one?

// Rendering
I code a ShapeRenderer like LibGDX and i store all vertices in a array.
Now i dont use a buffer and put the complete array directly with glBufferData.

It increase the fps a bit from 1600 to 1700/1800 (10K quads)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Guerra2442

JGO Knight


Medals: 82
Exp: 4 years


Guerra24


« Reply #10 - Posted 2020-02-16 18:30:30 »

Ok thx

Do you have Discord and I can ask you questions if i had one?


Yeah Guerra24#9300, as long I'm online you can ask me anything.

Working on Anarchy Engine.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (587 views)
2019-09-04 15:33:17

hadezbladez (5533 views)
2018-11-16 13:46:03

hadezbladez (2411 views)
2018-11-16 13:41:33

hadezbladez (5794 views)
2018-11-16 13:35:35

hadezbladez (1233 views)
2018-11-16 13:32:03

EgonOlsen (4669 views)
2018-06-10 19:43:48

EgonOlsen (5688 views)
2018-06-10 19:43:44

EgonOlsen (3205 views)
2018-06-10 19:43:20

DesertCoockie (4104 views)
2018-05-13 18:23:11

nelsongames (5125 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!