Help me with GLES 2.0 VBOs
Moderator: Moderators
Help me with GLES 2.0 VBOs
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.
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 529 times
Re: Help me with GLES 2.0 VBOs
Hi Rado1,
Not exactly sure why you aren't using the Mesh component though.
K
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.Rado1 wrote:I want to rewrite a code which uses VBOs from OpenGL 1.* to GLES 2.0.
Not exactly sure why you aren't using the Mesh component though.
K
Re: Help me with GLES 2.0 VBOs
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.Kjell wrote:Not exactly sure why you aren't using the Mesh component though.
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
Hmm,
+ 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
K
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.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.
+ 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
K
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 510 times
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
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
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.Kjell wrote:Face optimization is generally a good idea too ..
- Attachments
-
- RW.zip
- wireframe version
- (161.74 KiB) Downloaded 520 times
Hi,
K
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.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.
K
Hmm,
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
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? ).Rado1 wrote:The update does not need to be dynamic.
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 522 times
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?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? ).
Thanks for the example I'm going to study it. BTW it crashes on Nexus 7.
Hi Rado1,
K
Certainly, that's what the MeshLoop component is forRado1 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?
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.Rado1 wrote:Thanks for the example I'm going to study it. BTW it crashes on Nexus 7.
K
Hi Kjell,
Rado1.
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?Kjell wrote:Certainly, that's what the MeshLoop component is for
Rado1.
Hi ~
K
You usually want to reset any global counters and such before you refresh / rebuild a Mesh. But you already know / knew that ..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.
ZGameEditor actually uses VBO's for Meshes internally It used to be that only meshes with at least 1024 triangles used a VBO, but Ville ( secretly? ) changed that some time ago.Rado1 wrote:BTW are not VBOs more efficient than ZGE Mesh components?
K