Help me with GLES 2.0 VBOs

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Help me with GLES 2.0 VBOs

Post 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.
Attachments
X.zgeproj
example project
(295.24 KiB) Downloaded 430 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: Help me with GLES 2.0 VBOs

Post 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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: Help me with GLES 2.0 VBOs

Post 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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: Help me with GLES 2.0 VBOs

Post 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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
Attachments
RW.zip
more complex demo; mouse - change view, LMB - move forward, RMB - move backward, Space - initial position
(161.88 KiB) Downloaded 416 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
Attachments
RW.zip
wireframe version
(161.74 KiB) Downloaded 424 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
VBO.zgeproj
(2.92 KiB) Downloaded 424 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Post Reply