// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3TriangleArray.cpp
// Function: gaps::R3TriangleArray::DrawVBO(gaps::RNFlags) const
void R3TriangleArray::
DrawVBO(const R3DrawFlags draw_flags) const
{
#if (RN_3D_GRFX == RN_OPENGL)
  // Update vbo
  ((R3TriangleArray *) this)->UpdateVBO();

  // Check vbo
  if (vbo_id == 0) return;
  if (vbo_size == 0) return;

  // Bind vbo
  glBindBuffer(GL_ARRAY_BUFFER, vbo_id);

  // Set pointers
  static const unsigned int vertex_size = 12 * sizeof(GLfloat);
  glVertexPointer(3, GL_FLOAT, vertex_size, (char *) NULL);
  glNormalPointer(GL_FLOAT, vertex_size, (char *) NULL + 3 * sizeof(GLfloat));
  glColorPointer(3, GL_FLOAT, vertex_size, (char *) NULL + 6 * sizeof(GLfloat));
  glTexCoordPointer(2, GL_FLOAT, vertex_size, (char *) NULL + 9 * sizeof(GLfloat));

  // Enable client states
  R3DrawFlags flags(Flags() & draw_flags);
  glEnableClientState(GL_VERTEX_ARRAY);
  if (flags[R3_SURFACE_NORMALS_DRAW_FLAG] || flags[R3_VERTEX_NORMALS_DRAW_FLAG])
    glEnableClientState(GL_NORMAL_ARRAY);
  else glDisable(GL_NORMAL_ARRAY);
  if (flags[R3_VERTEX_COLORS_DRAW_FLAG])
    glEnableClientState(GL_COLOR_ARRAY);
  else glDisable(GL_COLOR_ARRAY);
  if (flags[R3_SURFACE_TEXTURE_DRAW_FLAG] || flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG])
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  else glDisable(GL_TEXTURE_COORD_ARRAY);
  
  // Draw triangles
  int nvertices = vbo_size / vertex_size;
  assert(nvertices == 3 * NTriangles());
  glDrawArrays(GL_TRIANGLES, 0, nvertices);
  
  // Disable client states
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

  glBindBuffer(GL_ARRAY_BUFFER, 0);

#endif
}

// Assembly:
subq $0x68, %rsp
movq %rsi, 0x60(%rsp)
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movq (%rdi), %rax
callq *0x258(%rax)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x9a001
jmp 0x9a21a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
jne 0x9a011
jmp 0x9a21a
movq 0x10(%rsp), %rcx
movq 0xd4fa3(%rip), %rax     # 0x16efc0
movq (%rax), %rax
movl 0x68(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x3, %edi
movl $0x1406, %esi           # imm = 0x1406
movl $0x30, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xf4f0
movl $0x1406, %edi           # imm = 0x1406
movl $0x30, %esi
movl $0xc, %edx
callq 0xf870
movl $0x3, %edi
movl $0x1406, %esi           # imm = 0x1406
movl $0x30, %edx
movl $0x18, %ecx
callq 0xf4e0
movl $0x2, %edi
movl $0x1406, %esi           # imm = 0x1406
movl $0x30, %edx
movl $0x24, %ecx
callq 0xf9b0
movq 0x10(%rsp), %rdi
callq 0x9a720
movq %rax, 0x48(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x13de0
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x13de0
movq 0x8(%rsp), %rsi
andq %rax, %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d80
movl $0x8074, %edi           # imm = 0x8074
callq 0xf2f0
leaq 0x40(%rsp), %rdi
movl $0x20, %esi
callq 0x13d80
movq 0x40(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
jne 0x9a112
leaq 0x38(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x13d80
movq 0x38(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x9a11e
movl $0x8075, %edi           # imm = 0x8075
callq 0xf2f0
jmp 0x9a128
movl $0x8075, %edi           # imm = 0x8075
callq 0xf150
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x13d80
movq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x9a157
movl $0x8076, %edi           # imm = 0x8076
callq 0xf2f0
jmp 0x9a161
movl $0x8076, %edi           # imm = 0x8076
callq 0xf150
leaq 0x28(%rsp), %rdi
movl $0x30, %esi
callq 0x13d80
movq 0x28(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
jne 0x9a1a7
leaq 0x20(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x13d80
movq 0x20(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x9a1b3
movl $0x8078, %edi           # imm = 0x8078
callq 0xf2f0
jmp 0x9a1bd
movl $0x8078, %edi           # imm = 0x8078
callq 0xf150
movq 0x10(%rsp), %rax
movl 0x6c(%rax), %eax
movl $0x30, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %edx
movl $0x4, %edi
xorl %esi, %esi
callq 0xf060
movl $0x8074, %edi           # imm = 0x8074
callq 0xf2c0
movl $0x8075, %edi           # imm = 0x8075
callq 0xf2c0
movl $0x8076, %edi           # imm = 0x8076
callq 0xf2c0
movl $0x8078, %edi           # imm = 0x8078
callq 0xf2c0
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
movq 0xd4da8(%rip), %rax     # 0x16efc0
callq *(%rax)
addq $0x68, %rsp
retq
nop