Results 1 to 3 of 3

Thread: When to call glEnableVertexAttribArray()

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    6

    When to call glEnableVertexAttribArray()

    Hello,

    i a new to OpenGL (ES) and have difficulties understanding when to do which system call in order to get the things done.

    More precisely, i want to draw Triangles using glDrawElements with Vertex Buffer Objects. I do something like this:

    ---------- Initialization -------------
    #Load Shaders
    #Attach Shaders to Program
    #BindAttributeLocation of a Position Attribute in the Vertex Shader
    #Link Program
    #use Program

    #Generate GL_ARRAY_BUFFER Buffers
    #Load Vertex Information using glBufferData
    #Call glVertexAttribPointer for the Position attribute

    #Generate GL_ELEMENT_ARRAY_BUFFER Buffers
    #Load Indexes Information

    ------- Draw Routine ---------------
    #Call glClear
    #Call glEnableVertexAttribArray on the Position Array
    #Call glDrawElements
    #Call eglSwapBuffers


    Thats a order to do things that seem to work. But i dont get why for example i have to call glEnableVertexAttribArray every time before doing the drawing with glDrawElements, althoug i dont touch any buffer. Same thing with the glVertexAttribPointer() call in the Initialization phase. If i move the call before the generation of VOB, i get a segment fault.

    It may be obvious when to call when with deeper insight in OpenGL, but for me this things almost look random. If for example i want to change a vertex buffer and not touch the rest, do i have to to load the other buffers as well, do i have to specify glVertexAttribPointer()?

    Thank you very much!

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: When to call glEnableVertexAttribArray()

    Quote Originally Posted by ManuelP
    But i dont get why for example i have to call glEnableVertexAttribArray every time before doing the drawing with glDrawElements, althoug i dont touch any buffer.
    You don't have to repeatedly call glEnableVertexAttribArray, unless you are calling any code which might disable it.

    Same thing with the glVertexAttribPointer() call in the Initialization phase. If i move the call before the generation of VOB, i get a segment fault.
    That's because glVertexAttribPointer sets up the vertex attribute to use the buffer object bound to GL_ARRAY_BUFFER at the time you call glVertexAttribPointer. If no buffer object is bound at that time, the pointer you pass to glVertexAttribPointer is interpreted as a pointer to client memory.

    So if you want a vertex attribute to be fed data from a buffer object, that buffer object must already exist and be bound to GL_ARRAY_BUFFER when you call glVertexAttribPointer. You can, however, initialise or update data contained in the buffer object at a later time without having to call glVertexAttribPointer again.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    6

    Re: When to call glEnableVertexAttribArray()

    Hello!

    thank you for the insight!

Similar Threads

  1. Is it possible to call one kernel in another?
    By GPUworker in forum OpenCL
    Replies: 10
    Last Post: 02-08-2011, 04:15 AM
  2. Why does EGL call glGetIntegerv when I call wglSwapBuffer?
    By teriba in forum Cross API and window system integration
    Replies: 0
    Last Post: 07-23-2009, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •