// File: /workspace/github_cpp_makefile_star2_O3/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 0x33f79
cmpl $0xe, %ebp
je 0x33f84
movsd 0x2e8(%rbx), %xmm0
jmp 0x33f9c
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sdl 0x118(%rbx), %xmm0
mulsd 0x104094(%rip), %xmm0   # 0x138028
addsd 0x10406c(%rip), %xmm0   # 0x138008
cvtsd2ss %xmm0, %xmm1
movl 0x490(%rbx), %r15d
cmpl $0x2, %r15d
jl 0x33fc8
cmpl $0x0, 0x49c(%rbx)
jne 0x33fd0
cmpl $0x0, 0x4a0(%rbx)
jne 0x33fd0
cmpl $0x0, 0x4a4(%rbx)
jne 0x33fd0
movl $0x1, %r15d
jmp 0x33ffc
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
sqrtsd %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
callq 0x270a0
movss 0x4(%rsp), %xmm1
movl 0x608(%rbx), %edi
testl %edi, %edi
je 0x3403c
movq 0x187fb3(%rip), %rax    # 0x1bbfc0
movss %xmm1, 0x4(%rsp)
callq *(%rax)
movq 0x187e8c(%rip), %rax    # 0x1bbea8
movl 0x608(%rbx), %edi
leaq 0x104923(%rip), %rsi    # 0x13894c
callq *(%rax)
movq 0x187f1e(%rip), %rcx    # 0x1bbf50
movl %eax, %edi
movss 0x4(%rsp), %xmm0
callq *(%rcx)
movl 0x5f8(%rbx), %esi
testl %esi, %esi
je 0x3407a
movq 0x187f2b(%rip), %rax    # 0x1bbf78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (,%r15,4), %eax
leal (%rax,%rax,2), %edx
movl $0x3, %edi
movl $0x1406, %esi           # imm = 0x1406
xorl %ecx, %ecx
callq 0x27980
movl $0x8074, %edi           # imm = 0x8074
callq 0x275c0
cmpl $0xe, %ebp
jne 0x3410a
movl 0x600(%rbx), %esi
movl 0x604(%rbx), %edx
testl %esi, %esi
je 0x340cb
leal (%rdx,%rdx,2), %r14d
movq 0x187eda(%rip), %rax    # 0x1bbf78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
movl $0x3, %edi
movl $0x1401, %esi           # imm = 0x1401
movq %r14, %rcx
callq 0x27950
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 0x341c3
movq 0x187e8f(%rip), %rax    # 0x1bbf78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
movl $0x3, %edi
movl $0x1401, %esi           # imm = 0x1401
xorl %ecx, %ecx
callq 0x27950
jmp 0x341c3
cmpl $0x1, %ebp
jne 0x3417d
movl 0x5fc(%rbx), %esi
testl %esi, %esi
je 0x34145
movq 0x187e58(%rip), %rax    # 0x1bbf78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
shll $0x2, %r15d
leal (%r15,%r15,2), %esi
movl $0x1406, %edi           # imm = 0x1406
xorl %edx, %edx
callq 0x280a0
movl $0x8075, %edi           # imm = 0x8075
callq 0x275c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x27860
movsd 0x104281(%rip), %xmm0   # 0x1383d8
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ed0
movl 0x604(%rbx), %edx
xorl %edi, %edi
xorl %esi, %esi
callq 0x27070
movl $0xb50, %edi            # imm = 0xB50
callq 0x27200
jmp 0x341c3
movl 0x600(%rbx), %esi
testl %esi, %esi
je 0x341b4
movq 0x187dea(%rip), %rax    # 0x1bbf78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leal (%r15,%r15,2), %edx
movl $0x3, %edi
movl $0x1401, %esi           # imm = 0x1401
xorl %ecx, %ecx
callq 0x27950
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 0x187dd8(%rip), %rax    # 0x1bbfc0
xorl %edi, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *(%rax)