Login  Register

Re: Negating some JNI call overhead by doing transformations in Java

Posted by gouessej on Jul 21, 2011; 1:43pm
URL: https://forum.jogamp.org/Negating-some-JNI-call-overhead-by-doing-transformations-in-Java-tp3188212p3188541.html

GiGurra, you overestimate the overhead due to JNI in my humble opinion. The ancestor of my first person shooter was written in C++ and I have never observed such differences of performance between C/C++ and Java when using OpenGL. I agree with Wade. If you don't want to use shaders, you should at least avoid using immediate rendering and look at Wade's tutorial about VBOs.

Demoscene Passivist, I meant "CPU". I looked at the source code of JMonkeyEngine 3.0 which is heavily shader-based, I asked some people to explain to me some things I didn't understand. Most of the transforms are done in the CPU side and then are sent to the shader. Momoko_Fan, one of the author of JMonkeyEngine explained this to me there:
http://www.java-gaming.org/index.php/topic,23544.0.html

A shader-oriented engine, does not use the predefined OpenGL uniforms such as gl_ModelViewProjectionMatrix, or the glPushMatrix/PopMatrix calls.

Instead the matrices are composed by the engine before the object is rendered and then those matrices are available through custom-defined uniforms to the shader.
Someone else wrote that:
When I was profiling old versions of my graphics engine, I found out that because of JNI overhead, it is actually slower to use glPush and glPop and make multiple glMatrix commands to set up the transform for each object.  It's faster to combine a scene graphs transforms in memory and track a final model transform for each object.  Then in the fixed pipeline it's only one graphics call, and in a shader engine, you only need to have one mat4 for the model.  HTH and I can explain better if you have questions.
Julien Gouesse | Personal blog | Website