Rendering stutter at the beginning

Started by kkl, November 02, 2014, 12:36:19 PM

Previous topic - Next topic

kkl

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:

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'

EgonOlsen

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...

kkl

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?

EgonOlsen

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. That might be slower one some devices, but it reduces some overhead.

kkl

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)

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?

EgonOlsen

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

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.

kkl

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?

EgonOlsen

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.

kkl

#8
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?

EgonOlsen


kkl

Thanks alot egon. Tat solves everything ; )