GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
Hi,
 gl = drawable.getGL().getGL2ES2();
 gl.glEnableClientState(GL2ES2.GL_VERTEX_ARRAY);   ==> enum doesn't exist with GL2ES2

and
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);  ==> method undefined for GL2ES2 type.

If i understand, we cannot activate the VA, and there will be not rendering at all through glDrawElements

So, how to use VBO with ES2 ?

Thanks,

Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
Hi

Rather use glVertexAttrib, glVertexAttribPointer, glEnableVertexAttribArray and glDisableVertexAttribArray.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
// -----
// Using ... :
// -----
    private static final float triangleVertices[] =
            {
                    -0.5f, 0.0f, 0.0f,
                     0.0f, 1.0f, 0.0f,
                     0.5f, 0.0f, 0.0f
            };

    private static final short triangleIndices[] = {0,3,6};
// ... and ...
    private static final String vshTriangleSource =
                        "attribute vec3 a_vertex; \n" +
                        "void main() \n" +
                        "{ gl_Position = vec4(a_vertex, 1.0); }";

        private static final String fshTriangleSource =
                        "void main() \n" +
                        "{ gl_FragColor = vec4 (1.0, 1.0, 1.0, 1.0); }";

// -----
// Settings : no compile, link error ; debug/trace don't show any errors on VBO creation ; VBO exists when binded.
// i use ByteBuffer(from Array..)  with nativeOrder and put it to VBO.
// -----

// -----
// Displaying, following this sequence ;
// -----
gl.glUseProgram(programId);
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, objectIds[0]);
gl.glVertexAttribPointer(attributes[A_VERTEX], 3 , GL2ES2.GL_FLOAT, false, 0, 0L); // Call to VAttribPointer make really VBO as a source
gl.glEnableVertexAttribArray(attributes[A_VERTEX]);   //Enable our VertexAttribPointer set above
// VertexAttribPointer reads a global variable from VBO and stores it in the VAO,    
gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, objectIds[1]);
// Draws the triangles, starting by the index 0 in the IBO.    
gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangleIndices.length, GL2ES2.GL_UNSIGNED_SHORT, 0);
gl.glFlush();      
drawable.swapBuffers(); // i don't use autodrawable here
gl.glDisableVertexAttribArray(attributes[A_VERTEX]); // Disable our Pointer
gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);

// Lead to a black screen !
// I must say that glClear + color work well.

My comments : as said here (http://www.opengl.org/wiki/VBO#Vertex_Buffer_Object) :
"Note: The GL_ARRAY_BUFFER​ binding is NOT part of the VAO's state! I know that's confusing, but that's the way it is."

Conclusion : calling gl.glEnableVertexAttribArray make VBO as a part of VAO ? (so, w/o using glEnableClientState) ?

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
If you don't understand how VAO can be used with JOGL, have a look at how we use them in JMonkeyEngine 3.0.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
Thank you, but i'm using JOGL "headless" on a Pi + your marvelous Newt API. My current work : trying to make PRocessing render engine working with Newt (w/o its AWT Applet head).
I must say that Xerxes examples work well for me, but a grep to all of his sources don't lead me to find a way to use "raw" VBO ; the only one demo - DemoGL2ES1Plain.java - use your GLArrayDataWrapper facilities and was evolved for GLES1, not GLES2. I'm sticky on it since 2 days and don't understand why some c++ GLES2 works, and JoglES2 don't, using the same way. I'm not an OpenGL expert at all, but i read specs and some things are sometimes weird. Perhaps a misunderstanding from me ...
Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
JMonkeyEngine 3 can still be a nice source of inspiration, look at this class, it uses glVertexAttrib, glVertexAttribPointer, glEnableVertexAttribArray and glDisableVertexAttribArray.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
Thanks, get it on my svn perspective and come back ... at first view, they use VBO the way you were talking about. Looking inside ..  
See you soon (:o)

v/
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
In reply to this post by gouessej
Ok, this sequence - ie VBO w/o element VBO - work :
        gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, objectIds[0]);
        gl.glVertexAttribPointer(attributes[A_VERTEX], 3 , GL2ES2.GL_FLOAT, false, 0, 0L);
        gl.glEnableVertexAttribArray(attributes[A_VERTEX]);
        gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); // or at the end, no matter.
        gl.glDrawArrays(GL2ES2.GL_TRIANGLES, 0, triangleIndices.length);
        gl.glFlush();
        swapBuffers();
        gl.glDisableVertexAttribArray(attributes[A_VERTEX]);

but this one - ie VBO w/ element VBO - don't :
        gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, objectIds[0]);
        gl.glVertexAttribPointer(attributes[A_VERTEX], 3 , GL2ES2.GL_FLOAT, false, 0, 0L);
        gl.glEnableVertexAttribArray(attributes[A_VERTEX]);
        gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0); // or at the end, no matter.
        gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, objectIds[1]);
        gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangleIndices.length, GL2ES2.GL_SHORT, 0);
        gl.glFlush();
        swapBuffers();
        gl.glDisableVertexAttribArray(attributes[A_VERTEX]);
        gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0);

Note : VBO and ElementVBO created the same way. Element VBO is simply {0,3,6} ; check against VBO binding always done.

In our last case, the way JMonkey use glDrawElements is :
        gl.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());

where indexBuf is a JMonkey VertexBuffer, and getData() is a Java Buffer.  
So, they use
    glDrawElements() with a pointer to vertices data and an element-VBO,
OR,
    glDrawArray() with a VBO,
but - IMHO -
they don't use glDrawElements() with VBO (ie GL_ARRAY_BUFFER) + element-VBO (ie GL_ELEMENT_ARRAY_BUFFER) together.

Any idea ? I don't want to take your time here, if your don't have any Jogl solutions, it will be ok with me, findind out another solutions.
Anyway, thank you for your help,
v/


Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
This post was updated on .
vslash wrote
if your don't have any Jogl solutions, it will be ok with me, findind out another solutions.
If it is doable with plain C OpenGL, it is doable with JOGL, otherwise it is doable neither with plain C OpenGL nor with JOGL. I'm not sure that what you're trying to achieve is doable in plain C OpenGL. If you find another solution, let us know.

Edit.: glDrawElements seems to take into account the offset bound to GL_ELEMENT_ARRAY_BUFFER but not the offset bound to GL_ARRAY_BUFFER.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
Sure it work in C ; you'll find a C++ example - ie using VBO + elementVBO - here :
http://www.songho.ca/opengl/gl_vbo.html#draw
(vbo.zip::main.cpp(673G))

but not GL2ES2 by the way.
I translate my own Java code to C++, and i'll come back if needed,

Thanks !

v/
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
In reply to this post by gouessej
Ok, i got it :
IMHO :
1) GL2ES1 : when using a VBO (ARRAY_BUFFER) and an element-VBO (ELEMENT_ARRAY_BUFFER) it appear glVertexPointer() call do the task (Jogl : GPointerFunc package set it, as for glColorPointer(), glNormalPointer() and so forth). Sequence is simply to
- binding VBO and elementVBO.
- enabling data in use (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR ...),
- then using the right pointer (vertex, normal, colors ...)

2) GPointerFunc.* is not available on GL2ES2 because we use programmable pipeline,  instead we are using a VertexAttribPointer that "link" our data with the shader pipeline.
So, elementVBO is used through the shader too.

3) GL2ES2 : as specified by "OpenGL ES 2.0 API Quick Reference Card" :
--->
void DrawElements(enum mode, sizei count, enum type, void *indices);
If an ELEMENT_ARRAY_BUFFER is bound, the indices will be read from the bound buffer, and indices is treated as an offset within the buffer.
<---

4) i still don't understand why my case don't work upon Jogl/GL2ES2 (ie using VBO and elementVBO together).
Binding the elementVBO would be sufficient, as specified above.

Should you ask anybody using this feature ? I understand that i would be outside the use of Jogl and perhaps the role of this forum.

Anyway, thanks for your assistance,
v/
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
Have you a working example in C using OpenGL-ES 2.0?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
No, i'll try to get time to make one.
But i'm sure the use of VBO+IBO + glDrawElements() works on Android .. which use Opengl upon ES2, and it work the way i described here. It could be an error on my side, check it out tomorrow.
It's a matter of system-side memory, which is not a "big fat one" on embedded system. Use of IBO could sometimes make a big difference.
++

v/
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
Ok, in this case it could be interesting for Ardor3D and JMonkeyEngine too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
Ok, got it : as expected, i was wrong ; for those reading this post, i wrote the entire program in C++, and find 2 interesting things :
1) indices element : represent the vertex number, not the vertex position inside the buffer eg :
  vertices[] = {x0,y0,z0,x1,x2,z2}
  indices[] = {0,3} ==> BAD
  indices[] = {0,1} ==> GOOD

2) indices type seem to be expected as uBYTE, nothing else (like uSHORT), despite the fact we specify it at the 3rd args of dlDrawElements. I'll investigate more on this.

3) I'll post here the 3 methods using VBO binding (drawArrays with VBO, drawElements with VBO + indices as an array, drawElements with VBO + indices as a VBO).

4) Conclusion : then, in our case, Jogl API works like in C, there's no issue.
++
v/
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

gouessej
Administrator
Thank you very much for your feedback, it will avoid some people to waste some time on unclear limitations/bugs and/or misunderstandings.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL2ES2 : glEnableClientState(GL2ES2.GL_VERTEX_ARRAY) issue

vslash
I know we are at Jogamp here (Java), but for those interested in C++ i just released the NWTPI API, a very simple one ; it would like to mimic some NEWT concept in the future ; a full example is included into project (using VBO and VBE bindings ..).
Use is as simple as possible :

NWTPI * drawable = new NWTPI("MyDrawable",width,height);
MyGlObject * Triangle = new MyGlObject();
Triangle->drawScene();
drawable->swapBuffers();

That's all !

DispmanX is a bit tricky and difficult to understand. A readme file will give you some tips.

https://code.google.com/p/nwtpi/

Source -> Browse -> Trunk
or svn checkout ..

Designed upon Raspbian 3.6.11.

Val.