Difference between “buffer” and “array” in OpenGL?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












When I read doc on webGL or OpenGL there can be seen some patterns in how names of functions and objects are used. But I can't understand the difference between buffer object and an array.



There are "vertex buffer objects", "vertex array objects" and even some kind of "buffer array" or "arraybuffer".



In OpenGL context, When something is "array" and when it should be called a "buffer" instead?










share|improve this question



























    up vote
    3
    down vote

    favorite












    When I read doc on webGL or OpenGL there can be seen some patterns in how names of functions and objects are used. But I can't understand the difference between buffer object and an array.



    There are "vertex buffer objects", "vertex array objects" and even some kind of "buffer array" or "arraybuffer".



    In OpenGL context, When something is "array" and when it should be called a "buffer" instead?










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      When I read doc on webGL or OpenGL there can be seen some patterns in how names of functions and objects are used. But I can't understand the difference between buffer object and an array.



      There are "vertex buffer objects", "vertex array objects" and even some kind of "buffer array" or "arraybuffer".



      In OpenGL context, When something is "array" and when it should be called a "buffer" instead?










      share|improve this question













      When I read doc on webGL or OpenGL there can be seen some patterns in how names of functions and objects are used. But I can't understand the difference between buffer object and an array.



      There are "vertex buffer objects", "vertex array objects" and even some kind of "buffer array" or "arraybuffer".



      In OpenGL context, When something is "array" and when it should be called a "buffer" instead?







      opengl webgl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      coobit

      1374




      1374




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote














          A Vertex Array Object (VAO) is an object which contains one or more
          Vertex Buffer Objects and is designed to store the information for a
          complete rendered object.




          (pulled from khronos)



          Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.



          That's one way. The other ways this can work are:



          • All of the attributes are stored interleaved in a single buffer, OR

          • Some of the attributes exist in their own dedicated buffers, while others share buffers.

          The below diagram describes these latter two cases.



          enter image description here



          Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which is a very different thing indeed from a buffer.



          EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.






          share|improve this answer






















          • So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
            – coobit
            12 mins ago










          • 1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
            – Arcane Engineer
            2 mins ago











          • 2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
            – Arcane Engineer
            2 mins ago


















          up vote
          0
          down vote













          I havent worked with OpenGL in a while, so I might only be half-right. Generally speaking: Buffers store an array of unformatted memory. An array is a general term of contiguous memory.



          A buffer needs to be bound to the context, whereas an array is just an array of data. If i recall correctly, the data in the buffer is meant to be copied onto the graphics card (hence the binding).



          Hope this helps a bit






          share|improve this answer








          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
            – coobit
            1 hour ago










          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          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: "53"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fgamedev.stackexchange.com%2fquestions%2f164992%2fdifference-between-buffer-and-array-in-opengl%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote














          A Vertex Array Object (VAO) is an object which contains one or more
          Vertex Buffer Objects and is designed to store the information for a
          complete rendered object.




          (pulled from khronos)



          Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.



          That's one way. The other ways this can work are:



          • All of the attributes are stored interleaved in a single buffer, OR

          • Some of the attributes exist in their own dedicated buffers, while others share buffers.

          The below diagram describes these latter two cases.



          enter image description here



          Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which is a very different thing indeed from a buffer.



          EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.






          share|improve this answer






















          • So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
            – coobit
            12 mins ago










          • 1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
            – Arcane Engineer
            2 mins ago











          • 2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
            – Arcane Engineer
            2 mins ago















          up vote
          2
          down vote














          A Vertex Array Object (VAO) is an object which contains one or more
          Vertex Buffer Objects and is designed to store the information for a
          complete rendered object.




          (pulled from khronos)



          Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.



          That's one way. The other ways this can work are:



          • All of the attributes are stored interleaved in a single buffer, OR

          • Some of the attributes exist in their own dedicated buffers, while others share buffers.

          The below diagram describes these latter two cases.



          enter image description here



          Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which is a very different thing indeed from a buffer.



          EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.






          share|improve this answer






















          • So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
            – coobit
            12 mins ago










          • 1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
            – Arcane Engineer
            2 mins ago











          • 2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
            – Arcane Engineer
            2 mins ago













          up vote
          2
          down vote










          up vote
          2
          down vote










          A Vertex Array Object (VAO) is an object which contains one or more
          Vertex Buffer Objects and is designed to store the information for a
          complete rendered object.




          (pulled from khronos)



          Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.



          That's one way. The other ways this can work are:



          • All of the attributes are stored interleaved in a single buffer, OR

          • Some of the attributes exist in their own dedicated buffers, while others share buffers.

          The below diagram describes these latter two cases.



          enter image description here



          Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which is a very different thing indeed from a buffer.



          EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.






          share|improve this answer















          A Vertex Array Object (VAO) is an object which contains one or more
          Vertex Buffer Objects and is designed to store the information for a
          complete rendered object.




          (pulled from khronos)



          Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.



          That's one way. The other ways this can work are:



          • All of the attributes are stored interleaved in a single buffer, OR

          • Some of the attributes exist in their own dedicated buffers, while others share buffers.

          The below diagram describes these latter two cases.



          enter image description here



          Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which is a very different thing indeed from a buffer.



          EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 13 mins ago

























          answered 1 hour ago









          Arcane Engineer

          25.3k355111




          25.3k355111











          • So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
            – coobit
            12 mins ago










          • 1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
            – Arcane Engineer
            2 mins ago











          • 2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
            – Arcane Engineer
            2 mins ago

















          • So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
            – coobit
            12 mins ago










          • 1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
            – Arcane Engineer
            2 mins ago











          • 2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
            – Arcane Engineer
            2 mins ago
















          So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
          – coobit
          12 mins ago




          So buffers are: 1.reside in GPU, 2.most of the time contain one kind of data (only vertex, only color ect), 3.Data is interleaved, that is 111122223333 ect. 4. provide no method to access data (not buffer[2] or buffer[vertex_3434]) Now, arrays are: 1.collection of buffers, 2.store information on how to parse buffers which it contains.(that is array store stride, size of an element, offsets, so data from buffers can be accessed correctly. right?
          – coobit
          12 mins ago












          1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
          – Arcane Engineer
          2 mins ago





          1. Buffers exist on both ends and transfer between CPU and GPU (back AND forth potentially), else how would you populate the data to be uploaded to GPU when loading a mesh from disk?. Yes, elements are of uniform type throughout the buffer, but depending on the tech you are using, each buffer element can be either a primitive or a struct type. Data may be interleaved or be completely uniform, per buffer. You can index into them, just as with a traditional C array on the CPU. Array objects (use this correct terminology or end up confusing yourself!)
          – Arcane Engineer
          2 mins ago













          2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
          – Arcane Engineer
          2 mins ago





          2. Lastly, yes, and you need to explicitly make sure your in-shader buffer declarations will match those specifications you set on your VAO on the CPU side: "All state related to the definition of data used by the vertex processor is encapsulated in a vertex array object." (khronos docs)
          – Arcane Engineer
          2 mins ago













          up vote
          0
          down vote













          I havent worked with OpenGL in a while, so I might only be half-right. Generally speaking: Buffers store an array of unformatted memory. An array is a general term of contiguous memory.



          A buffer needs to be bound to the context, whereas an array is just an array of data. If i recall correctly, the data in the buffer is meant to be copied onto the graphics card (hence the binding).



          Hope this helps a bit






          share|improve this answer








          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
            – coobit
            1 hour ago














          up vote
          0
          down vote













          I havent worked with OpenGL in a while, so I might only be half-right. Generally speaking: Buffers store an array of unformatted memory. An array is a general term of contiguous memory.



          A buffer needs to be bound to the context, whereas an array is just an array of data. If i recall correctly, the data in the buffer is meant to be copied onto the graphics card (hence the binding).



          Hope this helps a bit






          share|improve this answer








          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
            – coobit
            1 hour ago












          up vote
          0
          down vote










          up vote
          0
          down vote









          I havent worked with OpenGL in a while, so I might only be half-right. Generally speaking: Buffers store an array of unformatted memory. An array is a general term of contiguous memory.



          A buffer needs to be bound to the context, whereas an array is just an array of data. If i recall correctly, the data in the buffer is meant to be copied onto the graphics card (hence the binding).



          Hope this helps a bit






          share|improve this answer








          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          I havent worked with OpenGL in a while, so I might only be half-right. Generally speaking: Buffers store an array of unformatted memory. An array is a general term of contiguous memory.



          A buffer needs to be bound to the context, whereas an array is just an array of data. If i recall correctly, the data in the buffer is meant to be copied onto the graphics card (hence the binding).



          Hope this helps a bit







          share|improve this answer








          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 1 hour ago









          Juicef

          91




          91




          New contributor




          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Juicef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.











          • What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
            – coobit
            1 hour ago
















          • What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
            – coobit
            1 hour ago















          What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
          – coobit
          1 hour ago




          What is GL_ARRAY_BUFFER then? Why it was called so? According to you hypothesis it is "Unformatted contiguous memory" :)
          – coobit
          1 hour ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f164992%2fdifference-between-buffer-and-array-in-opengl%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery