1

When using glBegin/glEnd, is it equivalent to one draw call?

I mean, when using glDrawArrays, as I understand, that's the point when data is transferred to GPU (client side to server side). When using glBegin/glEnd, is data transferred to GPU only at the glEnd call? Or vertex are transferred one by one every glVertex/glNormal/glTexCoord call?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ray
  • 123
  • 2
  • 9
  • see nicols answer for exact details but its pretty safe to think of one glBegin/glEnd as one draw call – Justin Meiners Aug 24 '13 at 15:46
  • So, can I suppose that using glBegin/glEnd is similar in performance to using Vertex Arrays and glDrawArrays? Both are immediate mode. – Ray Aug 25 '13 at 18:59
  • @Ray No, you definitely can't. Vertex arrays are *not* immediate mode. The advantage of `glDrawArrays` over `glBegin/glEnd` does not just come from using GPU data right away (i.e. when using VBOs), but also from the fact that you don't make a driver call for each and every stupid little vertex. And that is a strength that plays out even for client side vertex arrays. So while in practice anything is possible and depends on your application and implementation the general rule is, that `glBegin/glEnd` is likely slower than `glDrawArrays` (no matter if using VBOs or not). – Christian Rau Aug 26 '13 at 14:30
  • @Cristian Thanks for clarification. I just read in another answer that Vertex Arrays could be considered "immediate mode" because vertex data is stored in client side ([link](http://stackoverflow.com/questions/6733934/what-does-immediate-mode-mean-in-opengl)). – Ray Aug 27 '13 at 17:23

1 Answers1

5

How these work is implementation dependent. At the very least, you can know that nothing gets transferred to the GPU until you call glVertex/glVertexAttrib(0), since those are what provokes a vertex (ie: causes the attribute state to be sent). Whether vertex data are transferred immediately upon calling a provoking function, or if they are buffered and transferred at glEnd time, or perhaps even later than that, is entirely implementation dependent.

Also... you shouldn't care. If you're using immediate mode, it should be because you don't care about performance. If you cared, you'd be using buffer objects and modern rendering functionality, not immediate mode.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Could really be an inplementation that transfers every vertex at every glVertex call? I understand that every transfer to GPU incurs a performance cost that can be quite large. – Ray Aug 25 '13 at 18:57
  • @Ray: There could be. It's all up to how the implementation wants to implement it. And "transfers a vertex" doesn't necessarily mean "issues a rendering command". All it means is copying that vertex's data into some internal piece of memory, such that the GPU will eventually see and process that vertex. – Nicol Bolas Aug 25 '13 at 22:37