Page 1 of 1

Help me with GLES 2.0 VBOs

Posted: Tue May 07, 2013 8:09 pm
by Rado1
Hi,

I just start to learn GLES 2.0 but I think that you (Kjell?) can help me more quickly. I want to rewrite a code which uses VBOs from OpenGL 1.* to GLES 2.0. The attached example defines model called EnvironmentModel which is rendered by VBOs. It works on Windows (OpenGL 1.*) in Compatible model but not on Android in ES2/GL3 mode. The project contains 2 shaders to be used for WallMaterial - LightShader for OpenGL 1.*, LightShaderES for GLES 2.0. Could you please give me some hints how to use VBOs and change the code for Android?

Note: The example project is just a snippet of larger project, so some parts can seem to be unnecessary complex.

Thanks in advance.
Rado1.

Re: Help me with GLES 2.0 VBOs

Posted: Tue May 07, 2013 8:29 pm
by Kjell
Hi Rado1,
Rado1 wrote:I want to rewrite a code which uses VBOs from OpenGL 1.* to GLES 2.0.
For starters, the fixed-function attribute functions ( glVertexPointer, glNormalPointer etc. ) and accompanying glEnableClientState are not available in ES 2.0. You need to replace those with glVertexAttribPointer.

Not exactly sure why you aren't using the Mesh component though.

K

Re: Help me with GLES 2.0 VBOs

Posted: Tue May 07, 2013 9:37 pm
by Rado1
Kjell wrote:Not exactly sure why you aren't using the Mesh component though.
Hi Kjell, the reason is that in real project the mesh is dynamically computed as an inner space obtained by union of arbitrary boxes (AABB boxes) possibly get from a file.

Could you please try to describe in details how to define vertex position and normal VBOs and what to use for their drawing? The best would be to use my example. Thanks.

Re: Help me with GLES 2.0 VBOs

Posted: Tue May 07, 2013 10:06 pm
by Kjell
Hmm,
Rado1 wrote:the reason is that in real project the mesh is dynamically computed as an inner space obtained by union of arbitrary boxes (AABB boxes) possibly get from a file.
A static VBO containing the maximum ( or X ) number of boxes and a uniform array containing their coordinates might be the better option ( less bandwidth ) .. not sure though, depends on what your exact situation is.

+ I personally think it's always best to simply ask for a solution for what you're trying to achieve instead of asking how to pull off a specific technique. It's ( unfortunately ) not uncommon for people to ask how a soldering iron works and what alloy they should use, while they are actually trying to fix a flat tire :roll:

K

Posted: Wed May 08, 2013 7:35 am
by Rado1
Ok, my problem is to rework the attached project to Android. The environment is defined as "inner space" of union of blocks. All faces are computed from blocks and rendered by VBOs. The reason for computation of faces is that user will be allowed to change the environment on runtime in a simple editor; so static meshes would not help.

Posted: Wed May 08, 2013 9:43 am
by Kjell
Hi Rado1,

Ah, that's not what i was imagining at all :)

Anyway, for a Minecraft type engine you still want to use static Meshes / VBO's. Since the environments are ( mostly ) sparse you wouldn't want to allocate memory for all voxels just so you could update individual subsets of a buffer. Instead, the common approach is to split the world into chunks ( clusters of for example 16x16x16 voxels ) that are rebuild when modified. Face optimization is generally a good idea too ..

K

Posted: Wed May 08, 2013 10:54 am
by Rado1
Kjell wrote:Face optimization is generally a good idea too ..
Actually, the application does not stupidly put simple box by box to form the world. It really computes intersections of boxes and optimize number of faces/triangles. See the attached version rendered by wireframe. For instance, the current scene has only 624 triangles (312 faces). Originally I use GL_QUADS, but since they are not further supported by OpenGL, had to change them to GL_TRIANGLES.

Posted: Wed May 08, 2013 11:30 am
by Kjell
Hi,
Rado1 wrote:Actually, the application does not stupidly put simple box by box to form the world. It really computes intersections of boxes and optimize number of faces/triangles.
Okay, good .. that's what you want yes :) Not sure how you'd want to update that dynamically ( opposed to re-creating a chunk ), unless you keep a list of all faces and their "address" in the VBO.

K

Posted: Wed May 08, 2013 12:47 pm
by Rado1
Kjell wrote:Not sure how you'd want to update that dynamically ( opposed to re-creating a chunk ), unless you keep a list of all faces and their "address" in the VBO.
The update does not need to be dynamic. There will be editing mode and playing mode. After each editing, VBOs will be recomputed.

Posted: Wed May 08, 2013 1:52 pm
by Kjell
Hmm,
Rado1 wrote:The update does not need to be dynamic.
In that case .. not sure why you can't / don't want to use the Mesh component ( perhaps you're simply more comfortable with plain OpenGL? ).

Anyway, attached is a minimal ES 2.0 compatible VBO example*

*Normally you'd want to set the attribute locations during shader creation, but that's not possible when you use the Shader component .. so it's better / safer to create the shader using OpenGL calls as well.

K

Posted: Wed May 08, 2013 5:44 pm
by Rado1
Kjell wrote:In that case .. not sure why you can't / don't want to use the Mesh component ( perhaps you're simply more comfortable with plain OpenGL? ).
I just learn OpenGL, so this is not the case :-) But how to use Mesh component if number of vertices (and their linking to triangles) varies? I'm maybe missing some trick in ZGE ...? Is it possible to generate arbitrary mesh based , e.g., on values in array or from file?

Thanks for the example I'm going to study it. BTW it crashes on Nexus 7.

Posted: Wed May 08, 2013 5:56 pm
by Kjell
Hi Rado1,
Rado1 wrote:But how to use Mesh component if number of vertices (and their linking to triangles) varies? I'm maybe missing some trick in ZGE ...? Is it possible to generate arbitrary mesh based , e.g., on values in array or from file?
Certainly, that's what the MeshLoop component is for :)
Rado1 wrote:Thanks for the example I'm going to study it. BTW it crashes on Nexus 7.
Weird .. haven't actually checked it on a Android device though ( don't have the Android SDK installed, and the ZGE Android debugger is ES 1.1 only afaik ). I'll put together a example that only uses OpenGL calls instead of the Shader / Material component.

K

Posted: Wed May 08, 2013 6:55 pm
by Rado1
Hi Kjell,
Kjell wrote:Certainly, that's what the MeshLoop component is for :)
Stupid me :-), I never use it in something working. But after some experiments I see it can be maybe used... Anyway, I have some problems with using global variables, such as iterators, in MeshLoop. BTW are not VBOs more efficient than ZGE Mesh components?

Rado1.

Posted: Wed May 08, 2013 7:32 pm
by Kjell
Hi ~
Rado1 wrote:Stupid me :-), I never use it in something working. But after some experiments I see it can be maybe used... Anyway, I have some problems with using global variables, such as iterators, in MeshLoop.
You usually want to reset any global counters and such before you refresh / rebuild a Mesh. But you already know / knew that ..
Rado1 wrote:BTW are not VBOs more efficient than ZGE Mesh components?
ZGameEditor actually uses VBO's for Meshes internally :wink: It used to be that only meshes with at least 1024 triangles used a VBO, but Ville ( secretly? ) changed that some time ago.

K