// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::DrawVBO(int) const
void R3SurfelViewer::
DrawVBO(int color_scheme) const
{
#if (R3_SURFEL_VIEWER_DRAW_METHOD == R3_SURFEL_VIEWER_DRAW_WITH_VBO)
  // Update VBO
  ((R3SurfelViewer *) this)->UpdateVBO();

  // Check VBO
  if (vbo_nsurfels == 0) return;

  // Determine stride and point size
  int subsampling = 1;
  float pointSize = SurfelSize();
  if (color_scheme == R3_SURFEL_VIEWER_COLOR_BY_PICK_INDEX)
    pointSize = 0.01 * Viewport().Width() + 1;
  if (subsampling_multiplier_when_mouse_down > 1) {
    if (mouse_button[0] || mouse_button[1] || mouse_button[2]) {
      subsampling = subsampling_multiplier_when_mouse_down;
      pointSize *= sqrt(subsampling_multiplier_when_mouse_down);
      glPointSize(pointSize);
    }
  }

  // Assign shader and its variables
  if (shader_program > 0) {
    glUseProgram(shader_program);
    int pointSizeLocation = glGetUniformLocation(shader_program, "pointSize");
    glUniform1f(pointSizeLocation, pointSize);
  }

  // Enable position buffer
  if (vbo_position_buffer > 0) {
    glBindBuffer(GL_ARRAY_BUFFER, vbo_position_buffer);
    glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat) * subsampling, 0);
    glEnableClientState(GL_VERTEX_ARRAY);
  }

  // Enable color/normal buffers
  if (color_scheme == R3_SURFEL_VIEWER_COLOR_BY_PICK_INDEX) {
    // Enable color buffer to draw pick colors 
    if (vbo_color_buffer > 0) {
      // Set color pointer to second half of buffer where pick colors are
      void *pick_color_offset = (void *) (3 * vbo_nsurfels * sizeof(GLubyte));
      glBindBuffer(GL_ARRAY_BUFFER, vbo_color_buffer);
      glColorPointer(3, GL_UNSIGNED_BYTE, 3 * sizeof(GLubyte) * subsampling, pick_color_offset);
      glEnableClientState(GL_COLOR_ARRAY);
    }

    // Draw points with pick color
    glDrawArrays(GL_POINTS, 0, vbo_nsurfels);

    // Reset color pointer to start of buffer where regular colors are
    if (vbo_color_buffer > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_color_buffer);
      glColorPointer(3, GL_UNSIGNED_BYTE,  3 * sizeof(GLubyte) * subsampling, 0);
    }
  }
  else if (color_scheme == R3_SURFEL_VIEWER_COLOR_BY_SHADING) {
    // Enable normal buffer
    if (vbo_normal_buffer > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_normal_buffer);
      glNormalPointer(GL_FLOAT,  3 * sizeof(GLfloat) * subsampling, 0);
      glEnableClientState(GL_NORMAL_ARRAY);
    }

    // Draw points with shading
    glEnable(GL_LIGHTING);
    RNLoadRgb(0.8, 0.8, 0.8);
    glDrawArrays(GL_POINTS, 0, vbo_nsurfels);
    glDisable(GL_LIGHTING);
  }
  else {
    // Enable color buffer
    if (vbo_color_buffer > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_color_buffer);
      glColorPointer(3, GL_UNSIGNED_BYTE, 3 * sizeof(GLubyte) * subsampling, 0);
      glEnableClientState(GL_COLOR_ARRAY);
    }

    // Draw points with color
    glDrawArrays(GL_POINTS, 0, vbo_nsurfels);
  }

  // Disable client state
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);

  // Reset shader
  glUseProgram(0);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x380(%rax)
cmpl $0x0, 0x604(%rbx)
je 0x323c7
cmpl $0xe, %ebp
je 0x323d2
movsd 0x2e8(%rbx), %xmm0
jmp 0x323ea
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sdl 0x118(%rbx), %xmm0
mulsd 0xe7c46(%rip), %xmm0    # 0x11a028
addsd 0xe7c1e(%rip), %xmm0    # 0x11a008
cvtsd2ss %xmm0, %xmm1
movl 0x490(%rbx), %r15d
pushq $0x1
popq %rax
cmpl $0x2, %r15d
jl 0x32419
cmpl $0x0, 0x49c(%rbx)
jne 0x3241e
cmpl $0x0, 0x4a0(%rbx)
jne 0x3241e
cmpl $0x0, 0x4a4(%rbx)
jne 0x3241e
movl %eax, %r15d
jmp 0x32444
cvtsi2sd %r15d, %xmm0
sqrtsd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
callq 0x270a0
movss 0x4(%rsp), %xmm1
movl 0x608(%rbx), %edi
testl %edi, %edi
je 0x32484
movq 0x174b73(%rip), %rax    # 0x1a6fc8
movss %xmm1, 0x4(%rsp)
callq *(%rax)
movq 0x174a64(%rip), %rax    # 0x1a6ec8
movl 0x608(%rbx), %edi
leaq 0xe848b(%rip), %rsi     # 0x11a8fc
callq *(%rax)
movq 0x174aee(%rip), %rcx    # 0x1a6f68
movl %eax, %edi
movss 0x4(%rsp), %xmm0
callq *(%rcx)
movl 0x5f8(%rbx), %esi
testl %esi, %esi
je 0x324b9
movq 0x174aeb(%rip), %rax    # 0x1a6f80
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
imull $0xc, %r15d, %edx
pushq $0x3
popq %rdi
movl $0x1406, %esi           # imm = 0x1406
xorl %ecx, %ecx
callq 0x27990
movl $0x8074, %edi           # imm = 0x8074
callq 0x275c0
cmpl $0xe, %ebp
jne 0x32545
movl 0x600(%rbx), %esi
movl 0x604(%rbx), %edx
testl %esi, %esi
je 0x32508
leal (%rdx,%rdx,2), %r14d
movq 0x174aa3(%rip), %rax    # 0x1a6f80
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
pushq $0x3
popq %rdi
movl $0x1401, %esi           # imm = 0x1401
movq %r14, %rcx
callq 0x27960
movl $0x8076, %edi           # imm = 0x8076
callq 0x275c0
movl 0x604(%rbx), %edx
xorl %edi, %edi
xorl %esi, %esi
callq 0x27070
movl 0x600(%rbx), %esi
testl %esi, %esi
je 0x325f8
movq 0x174a5a(%rip), %rax    # 0x1a6f80
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
pushq $0x3
popq %rdi
movl $0x1401, %esi           # imm = 0x1401
xorl %ecx, %ecx
callq 0x27960
jmp 0x325f8
cmpl $0x1, %ebp
jne 0x325b4
movl 0x5fc(%rbx), %esi
testl %esi, %esi
je 0x3257c
movq 0x174a25(%rip), %rax    # 0x1a6f80
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
imull $0xc, %r15d, %esi
movl $0x1406, %edi           # imm = 0x1406
xorl %edx, %edx
callq 0x280c0
movl $0x8075, %edi           # imm = 0x8075
callq 0x275c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x27870
movsd 0xe7e4a(%rip), %xmm0    # 0x11a3d8
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ef0
movl 0x604(%rbx), %edx
xorl %edi, %edi
xorl %esi, %esi
callq 0x27070
movl $0xb50, %edi            # imm = 0xB50
callq 0x27220
jmp 0x325f8
movl 0x600(%rbx), %esi
testl %esi, %esi
je 0x325e9
movq 0x1749bb(%rip), %rax    # 0x1a6f80
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
pushq $0x3
popq %rdi
movl $0x1401, %esi           # imm = 0x1401
xorl %ecx, %ecx
callq 0x27960
movl $0x8076, %edi           # imm = 0x8076
callq 0x275c0
movl 0x604(%rbx), %edx
xorl %edi, %edi
xorl %esi, %esi
callq 0x27070
movl $0x8074, %edi           # imm = 0x8074
callq 0x27560
movl $0x8075, %edi           # imm = 0x8075
callq 0x27560
movl $0x8076, %edi           # imm = 0x8076
callq 0x27560
movq 0x1749ab(%rip), %rax    # 0x1a6fc8
xorl %edi, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *(%rax)
nop