// File: /workspace/github_cpp_makefile_star2_O1/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 0x33fb9
cmpl $0xe, %ebp
je 0x33fc4
movsd 0x2e8(%rbx), %xmm0
jmp 0x33fdc
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sdl 0x118(%rbx), %xmm0
mulsd 0x107054(%rip), %xmm0   # 0x13b028
addsd 0x10702c(%rip), %xmm0   # 0x13b008
cvtsd2ss %xmm0, %xmm2
movl 0x490(%rbx), %r15d
cmpl $0x2, %r15d
jl 0x34008
cmpl $0x0, 0x49c(%rbx)
jne 0x34010
cmpl $0x0, 0x4a0(%rbx)
jne 0x34010
cmpl $0x0, 0x4a4(%rbx)
jne 0x34010
movl $0x1, %r15d
jmp 0x3405c
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x34028
sqrtsd %xmm0, %xmm0
jmp 0x34039
movss %xmm2, 0x4(%rsp)
callq 0x27700
movss 0x4(%rsp), %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
callq 0x270a0
movss 0x4(%rsp), %xmm2
movl 0x608(%rbx), %edi
testl %edi, %edi
je 0x3409c
movq 0x18af53(%rip), %rax    # 0x1befc0
movss %xmm2, 0x4(%rsp)
callq *(%rax)
movq 0x18ae2c(%rip), %rax    # 0x1beea8
movl 0x608(%rbx), %edi
leaq 0x107863(%rip), %rsi    # 0x13b8ec
callq *(%rax)
movq 0x18aebe(%rip), %rcx    # 0x1bef50
movl %eax, %edi
movss 0x4(%rsp), %xmm0
callq *(%rcx)
movl 0x5f8(%rbx), %esi
testl %esi, %esi
je 0x340da
movq 0x18aecb(%rip), %rax    # 0x1bef78
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 0x3416a
movl 0x600(%rbx), %esi
testl %esi, %esi
je 0x34125
movl 0x604(%rbx), %eax
leal (%rax,%rax,2), %r14d
movq 0x18ae7a(%rip), %rax    # 0x1bef78
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 0x34223
movq 0x18ae2f(%rip), %rax    # 0x1bef78
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 0x34223
cmpl $0x1, %ebp
jne 0x341dd
movl 0x5fc(%rbx), %esi
testl %esi, %esi
je 0x341a5
movq 0x18adf8(%rip), %rax    # 0x1bef78
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
shll $0x2, %r15d
leal (%r15,%r15,2), %esi
movl $0x1406, %edi           # imm = 0x1406
xorl %edx, %edx
callq 0x280b0
movl $0x8075, %edi           # imm = 0x8075
callq 0x275c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x27860
movsd 0x107221(%rip), %xmm0   # 0x13b3d8
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ee0
movl 0x604(%rbx), %edx
xorl %edi, %edi
xorl %esi, %esi
callq 0x27070
movl $0xb50, %edi            # imm = 0xB50
callq 0x27200
jmp 0x34223
movl 0x600(%rbx), %esi
testl %esi, %esi
je 0x34214
movq 0x18ad8a(%rip), %rax    # 0x1bef78
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 0x18ad78(%rip), %rax    # 0x1befc0
xorl %edi, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *(%rax)