// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::UpdateVBO()
void R3SurfelViewer::
UpdateVBO(void)
{
#if (R3_SURFEL_VIEWER_DRAW_METHOD == R3_SURFEL_VIEWER_DRAW_WITH_VBO)
  // Check if VBO is uptodate
  if (vbo_nsurfels > 0) return;

  // Compute VBO buffers
  std::vector<GLfloat> surfel_positions;
  std::vector<GLfloat> surfel_normals;
  std::vector<GLubyte> surfel_colors;
  ComputeVBOBuffers(surfel_positions, surfel_normals, surfel_colors);

  // Get/check number of surfels
  vbo_nsurfels = surfel_positions.size() / 3;
  if (vbo_nsurfels <= 0) return;
  assert(surfel_positions.size() == 3 * vbo_nsurfels);
  assert(surfel_normals.size() == 3 * vbo_nsurfels);
  assert(surfel_colors.size() == 2 * 3 * vbo_nsurfels);

  // Generate VBO buffers (first time only)
  if (vbo_position_buffer == 0) glGenBuffers(1, &vbo_position_buffer);
  if (vbo_normal_buffer == 0) glGenBuffers(1, &vbo_normal_buffer);
  if (vbo_color_buffer == 0) glGenBuffers(1, &vbo_color_buffer);

  // Load VBO buffers
  if (vbo_position_buffer) {
    glBindBuffer(GL_ARRAY_BUFFER, vbo_position_buffer);
    glBufferData(GL_ARRAY_BUFFER, 3 * vbo_nsurfels * sizeof(GLfloat), &surfel_positions[0], GL_STATIC_DRAW);
    glVertexPointer(3, GL_FLOAT, 0, 0);
  }
  if (vbo_normal_buffer) {
    glBindBuffer(GL_ARRAY_BUFFER, vbo_normal_buffer);
    glBufferData(GL_ARRAY_BUFFER, 3 * vbo_nsurfels * sizeof(GLfloat), &surfel_normals[0], GL_STATIC_DRAW);
    glNormalPointer(GL_FLOAT, 0, 0);
  }
  if (vbo_color_buffer) {
    glBindBuffer(GL_ARRAY_BUFFER, vbo_color_buffer);
    glBufferData(GL_ARRAY_BUFFER, 2 * 3 * vbo_nsurfels * sizeof(GLubyte), &surfel_colors[0], GL_STATIC_DRAW);
    glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
   }
#endif
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x604(%rax)
jbe 0x3c5fa
jmp 0x3c941
leaq 0x98(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x3f060
leaq 0x80(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x3f060
leaq 0x68(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x3f070
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq (%rdi), %rax
movq 0x348(%rax), %rax
callq *%rax
jmp 0x3c64f
leaq 0x98(%rsp), %rdi
callq 0x3f080
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq 0x50(%rsp), %rax
movl %ecx, 0x604(%rax)
cmpl $0x0, 0x604(%rax)
ja 0x3c6c1
movl $0x1, 0x58(%rsp)
jmp 0x3c91d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x3f0a0
leaq 0x80(%rsp), %rdi
callq 0x3f100
leaq 0x98(%rsp), %rdi
callq 0x3f100
jmp 0x3c949
movq 0x50(%rsp), %rax
cmpl $0x0, 0x5f8(%rax)
jne 0x3c6f0
movq 0x50(%rsp), %rsi
movq 0x28687d(%rip), %rax    # 0x2c2f58
movq (%rax), %rax
addq $0x5f8, %rsi            # imm = 0x5F8
movl $0x1, %edi
callq *%rax
jmp 0x3c6ee
jmp 0x3c6f0
movq 0x50(%rsp), %rax
cmpl $0x0, 0x5fc(%rax)
jne 0x3c71f
movq 0x50(%rsp), %rsi
movq 0x28684e(%rip), %rax    # 0x2c2f58
movq (%rax), %rax
addq $0x5fc, %rsi            # imm = 0x5FC
movl $0x1, %edi
callq *%rax
jmp 0x3c71d
jmp 0x3c71f
movq 0x50(%rsp), %rax
cmpl $0x0, 0x600(%rax)
jne 0x3c74e
movq 0x50(%rsp), %rsi
movq 0x28681f(%rip), %rax    # 0x2c2f58
movq (%rax), %rax
addq $0x600, %rsi            # imm = 0x600
movl $0x1, %edi
callq *%rax
jmp 0x3c74c
jmp 0x3c74e
movq 0x50(%rsp), %rax
cmpl $0x0, 0x5f8(%rax)
je 0x3c7e9
movq 0x50(%rsp), %rcx
movq 0x286834(%rip), %rax    # 0x2c2fa0
movq (%rax), %rax
movl 0x5f8(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
jmp 0x3c77e
movq 0x50(%rsp), %rax
movq 0x28682e(%rip), %rcx    # 0x2c2fb8
movq (%rcx), %rcx
movq %rcx, 0x30(%rsp)
movl 0x604(%rax), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
shlq $0x2, %rax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x98(%rsp), %rdi
callq 0x3f020
movq 0x28(%rsp), %rsi
movq %rax, %rdx
movq 0x30(%rsp), %rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
jmp 0x3c7d2
xorl %edx, %edx
movl %edx, %ecx
movl $0x3, %edi
movl $0x1406, %esi           # imm = 0x1406
callq 0x28aa0
jmp 0x3c7e7
jmp 0x3c7e9
movq 0x50(%rsp), %rax
cmpl $0x0, 0x5fc(%rax)
je 0x3c87f
movq 0x50(%rsp), %rcx
movq 0x286799(%rip), %rax    # 0x2c2fa0
movq (%rax), %rax
movl 0x5fc(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
jmp 0x3c819
movq 0x50(%rsp), %rax
movq 0x286793(%rip), %rcx    # 0x2c2fb8
movq (%rcx), %rcx
movq %rcx, 0x20(%rsp)
movl 0x604(%rax), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
shlq $0x2, %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x80(%rsp), %rdi
callq 0x3f020
movq 0x18(%rsp), %rsi
movq %rax, %rdx
movq 0x20(%rsp), %rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
jmp 0x3c86d
xorl %esi, %esi
movl %esi, %edx
movl $0x1406, %edi           # imm = 0x1406
callq 0x29250
jmp 0x3c87d
jmp 0x3c87f
movq 0x50(%rsp), %rax
cmpl $0x0, 0x600(%rax)
je 0x3c915
movq 0x50(%rsp), %rcx
movq 0x286703(%rip), %rax    # 0x2c2fa0
movq (%rax), %rax
movl 0x600(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
jmp 0x3c8af
movq 0x50(%rsp), %rax
movq 0x2866fd(%rip), %rcx    # 0x2c2fb8
movq (%rcx), %rcx
movq %rcx, 0x10(%rsp)
movl 0x604(%rax), %ecx
addl %ecx, %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x68(%rsp), %rdi
callq 0x3f040
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq 0x10(%rsp), %rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
jmp 0x3c8fe
xorl %edx, %edx
movl %edx, %ecx
movl $0x3, %edi
movl $0x1401, %esi           # imm = 0x1401
callq 0x28a70
jmp 0x3c913
jmp 0x3c915
movl $0x0, 0x58(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x3f0a0
leaq 0x80(%rsp), %rdi
callq 0x3f100
leaq 0x98(%rsp), %rdi
callq 0x3f100
addq $0xb8, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x292e0
nopw %cs:(%rax,%rax)