www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: kkl on November 02, 2014, 12:36:19 pm

Title: Rendering stutter at the beginning
Post by: kkl on November 02, 2014, 12:36:19 pm
Hi Egon,

I have an issue where the rendering stutters at the beginning of the onDrawFrame. I checked from log and found out it compiles shader and create buffer for VBO during rendering when object become visible. Is there any way to compile everything including shader and VBO in surfaceChanged before it starts rendering frame? I tried to call buildAllObjects() and compileAllObjects() but it seems not helping.

Here's the log during rendering:
Code: [Select]
11-02 19:25:50.231: I/jPCT-AE(32481): Compiling shader program!
11-02 19:25:50.231: I/jPCT-AE(32481): Handles of 2520036: 3/28/5
11-02 19:25:50.231: I/jPCT-AE(32481): Creating buffers...
11-02 19:25:50.231: I/jPCT-AE(32481): VBO created for object 'foreground_fish_1'
Title: Re: Rendering stutter at the beginning
Post by: EgonOlsen on November 02, 2014, 01:48:06 pm
Is this the app's first start or a resume after a pause? In the latter case, you might want to check if the GL context has actually changed and create a new FrameBuffer only if it had. Otherwise reuse the old one, which should skip these steps. But anyway, i fail to see the actual problem in this case... Judging from your log, all this happens at the same time stamp. I don't see a delay here...
Title: Re: Rendering stutter at the beginning
Post by: kkl on November 02, 2014, 02:31:41 pm
it happens in app's first start. The log happens during rendering (onDrawFrame), also the time when I see the stutter. Do you compile object if object is not visible at the beginning?
Title: Re: Rendering stutter at the beginning
Post by: EgonOlsen on November 02, 2014, 02:44:14 pm
Yes, but only if you don't use the compileAllObjects()-method. You have to distinguish between compilation (which can happen before the rendering) and uploading the data to the GPU, which has to happen in the correct GL context.
Again, i don't see the problem, at least not from this part of the log. You can skip VBO creation by not using them: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#useVBO (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#useVBO). That might be slower one some devices, but it reduces some overhead.
Title: Re: Rendering stutter at the beginning
Post by: kkl on November 02, 2014, 03:27:02 pm
Mayb I got the context wrong. Does compileAllObjects() compile shader and creating VBO buffer? From your explanation, I mayb referred to uploading data to gpu.

Here's the log for more details. It was drawing frame and it stuttered a short while to create buffer and upload VBO (the log with com.kisionlab shows it is drawing)
Code: [Select]
11-02 22:15:43.781: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 58fps, slept: 6
11-02 22:15:44.796: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 58fps, slept: 4
11-02 22:15:45.811: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 56fps, slept: 8
11-02 22:15:45.951: I/jPCT-AE(29094): Compiling shader program!
11-02 22:15:46.206: I/jPCT-AE(29094): Handles of 2940042: 3/47/5
11-02 22:15:46.206: I/jPCT-AE(29094): Creating buffers...
11-02 22:15:46.206: I/jPCT-AE(29094): VBO created for object 'goggles'
11-02 22:15:46.211: I/jPCT-AE(29094): Creating attribute/handle mapping!
11-02 22:15:46.826: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 44fps, slept: 5
11-02 22:15:47.831: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 58fps, slept: 5
11-02 22:15:48.841: V/Kision(29094): com.kisionlab.oceanblue3d.SceneSettingRenderer@4327ae30: 57fps, slept: 3

My question is, is there any way to upload the VBO and compile the shader before frame drawing happens?
Title: Re: Rendering stutter at the beginning
Post by: EgonOlsen on November 02, 2014, 04:03:14 pm
Uploading the VBO is not an  issue as you can see in the timings. Compiling the shader and assigning the vertex attributes is. I've added a compile(List<VertexAttributes> attribs)-method to GLSLShader to support compilation before rendering. You can get this version here: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

Just call it on your shader and give it (optional, otherwise just set them to null) the VertexAttributes instances that the Object3D that uses this shader has assigned to it via it's Mesh instance. I need those to determine the proper handles before rendering.

Please let he know if this a) works and b) helps.
Title: Re: Rendering stutter at the beginning
Post by: kkl on November 03, 2014, 11:30:19 am
Yup, that works! No more stuttering anymore. BTW, it's actually quite difficult to implement the function as I have many objects with different shaders. Can we have a generic function like compileAllObjects to compile the shaders and vertex attributes automatically? Is it difficult to implement?
Title: Re: Rendering stutter at the beginning
Post by: EgonOlsen on November 03, 2014, 12:16:44 pm
You should be able to do that yourself simply by iterating over your Object3Ds, get the shader and the attributes and then call the compile()-method.
Title: Re: Rendering stutter at the beginning
Post by: kkl on November 03, 2014, 02:00:24 pm
Is it safe/redundant to call the method for multiple time for the same shader object?

I have a few custom shaders in which a few default uniforms and attributes are removed. Does the compilation affect that?
Title: Re: Rendering stutter at the beginning
Post by: EgonOlsen on November 03, 2014, 03:31:31 pm
No, it's safe to do that.
Title: Re: Rendering stutter at the beginning
Post by: kkl on November 03, 2014, 03:40:30 pm
Thanks alot egon. Tat solves everything ; )