Could glVertexAttribPointer() last at attribute value in OpenGL be a array ?









up vote
1
down vote

favorite












Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。



lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]

lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]


and this is the code about glVertexAttribPointer



let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)

let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)


the result for the gradient triangel in the iPhone










share|improve this question



























    up vote
    1
    down vote

    favorite












    Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
    I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。



    lazy var postions : [GLfloat] = [
    -0.5, -0.5, 0.0,
    0.5, -0.5, 0.0,
    0.0, 0.5, 0.0,
    ]

    lazy var colors : [GLfloat] = [
    1, 0, 0,
    0, 1, 0,
    0, 0, 1,
    ]


    and this is the code about glVertexAttribPointer



    let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
    glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
    glEnableVertexAttribArray(posistionAtt)

    let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
    let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
    glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
    glEnableVertexAttribArray(colorAtt)


    the result for the gradient triangel in the iPhone










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
      I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。



      lazy var postions : [GLfloat] = [
      -0.5, -0.5, 0.0,
      0.5, -0.5, 0.0,
      0.0, 0.5, 0.0,
      ]

      lazy var colors : [GLfloat] = [
      1, 0, 0,
      0, 1, 0,
      0, 0, 1,
      ]


      and this is the code about glVertexAttribPointer



      let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
      glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
      glEnableVertexAttribArray(posistionAtt)

      let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
      let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
      glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
      glEnableVertexAttribArray(colorAtt)


      the result for the gradient triangel in the iPhone










      share|improve this question















      Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
      I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。



      lazy var postions : [GLfloat] = [
      -0.5, -0.5, 0.0,
      0.5, -0.5, 0.0,
      0.0, 0.5, 0.0,
      ]

      lazy var colors : [GLfloat] = [
      1, 0, 0,
      0, 1, 0,
      0, 0, 1,
      ]


      and this is the code about glVertexAttribPointer



      let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
      glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
      glEnableVertexAttribArray(posistionAtt)

      let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
      let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
      glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
      glEnableVertexAttribArray(colorAtt)


      the result for the gradient triangel in the iPhone







      swift opengl-es opengl-es-2.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 18:04









      Rabbid76

      30k112842




      30k112842










      asked Nov 10 at 17:57









      ADDICE

      133




      133






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.



          See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:




          void VertexAttribPointer( uint index, int size, enum type, 
          boolean normalized, sizei stride,
          const void *pointer );


          ...
          For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.




          See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:




          ... When an array is sourced from
          a buffer object, the pointer value of that array is used to compute an offset, in basic
          machine units, into the data store of the buffer object. ...




          This means, in case of



          glBindBuffer(GL_ARRAY_BUFFER, 0)
          glVertexAttribPointer(...., pointer)


          pointer has to be a pointer to the vertex array data - the array of vertex array data.



          But in case of



          glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
          glVertexAttribPointer(...., offset)


          offset has to be an offset, to the data store of vbo.






          share|improve this answer






















          • could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
            – ADDICE
            Nov 12 at 8:47











          • @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
            – Rabbid76
            Nov 12 at 9:06










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241857%2fcould-glvertexattribpointer-last-at-attribute-value-in-opengl-be-a-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.



          See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:




          void VertexAttribPointer( uint index, int size, enum type, 
          boolean normalized, sizei stride,
          const void *pointer );


          ...
          For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.




          See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:




          ... When an array is sourced from
          a buffer object, the pointer value of that array is used to compute an offset, in basic
          machine units, into the data store of the buffer object. ...




          This means, in case of



          glBindBuffer(GL_ARRAY_BUFFER, 0)
          glVertexAttribPointer(...., pointer)


          pointer has to be a pointer to the vertex array data - the array of vertex array data.



          But in case of



          glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
          glVertexAttribPointer(...., offset)


          offset has to be an offset, to the data store of vbo.






          share|improve this answer






















          • could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
            – ADDICE
            Nov 12 at 8:47











          • @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
            – Rabbid76
            Nov 12 at 9:06














          up vote
          0
          down vote



          accepted










          If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.



          See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:




          void VertexAttribPointer( uint index, int size, enum type, 
          boolean normalized, sizei stride,
          const void *pointer );


          ...
          For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.




          See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:




          ... When an array is sourced from
          a buffer object, the pointer value of that array is used to compute an offset, in basic
          machine units, into the data store of the buffer object. ...




          This means, in case of



          glBindBuffer(GL_ARRAY_BUFFER, 0)
          glVertexAttribPointer(...., pointer)


          pointer has to be a pointer to the vertex array data - the array of vertex array data.



          But in case of



          glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
          glVertexAttribPointer(...., offset)


          offset has to be an offset, to the data store of vbo.






          share|improve this answer






















          • could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
            – ADDICE
            Nov 12 at 8:47











          • @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
            – Rabbid76
            Nov 12 at 9:06












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.



          See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:




          void VertexAttribPointer( uint index, int size, enum type, 
          boolean normalized, sizei stride,
          const void *pointer );


          ...
          For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.




          See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:




          ... When an array is sourced from
          a buffer object, the pointer value of that array is used to compute an offset, in basic
          machine units, into the data store of the buffer object. ...




          This means, in case of



          glBindBuffer(GL_ARRAY_BUFFER, 0)
          glVertexAttribPointer(...., pointer)


          pointer has to be a pointer to the vertex array data - the array of vertex array data.



          But in case of



          glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
          glVertexAttribPointer(...., offset)


          offset has to be an offset, to the data store of vbo.






          share|improve this answer














          If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.



          See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:




          void VertexAttribPointer( uint index, int size, enum type, 
          boolean normalized, sizei stride,
          const void *pointer );


          ...
          For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.




          See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:




          ... When an array is sourced from
          a buffer object, the pointer value of that array is used to compute an offset, in basic
          machine units, into the data store of the buffer object. ...




          This means, in case of



          glBindBuffer(GL_ARRAY_BUFFER, 0)
          glVertexAttribPointer(...., pointer)


          pointer has to be a pointer to the vertex array data - the array of vertex array data.



          But in case of



          glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
          glVertexAttribPointer(...., offset)


          offset has to be an offset, to the data store of vbo.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 9:05

























          answered Nov 10 at 18:16









          Rabbid76

          30k112842




          30k112842











          • could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
            – ADDICE
            Nov 12 at 8:47











          • @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
            – Rabbid76
            Nov 12 at 9:06
















          • could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
            – ADDICE
            Nov 12 at 8:47











          • @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
            – Rabbid76
            Nov 12 at 9:06















          could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
          – ADDICE
          Nov 12 at 8:47





          could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
          – ADDICE
          Nov 12 at 8:47













          @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
          – Rabbid76
          Nov 12 at 9:06




          @ADDICE Yes. For glBindBuffer(GL_ARRAY_BUFFER, 0) glVertexAttribPointer(..., array), array is the data array.
          – Rabbid76
          Nov 12 at 9:06

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241857%2fcould-glvertexattribpointer-last-at-attribute-value-in-opengl-be-a-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto