// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::Redraw()
int R3SurfelViewer::
Redraw(void)
{
  // Check scene
  if (!scene) return 0;

  // Set viewing transformation
  viewer.Camera().Load();

  // Clear window 
  glClearColor(background_color[0], background_color[1], background_color[2], 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Set lights
  static GLfloat light0_position[] = { 3.0, 4.0, 5.0, 0.0 };
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  static GLfloat light1_position[] = { -3.0, -2.0, -3.0, 0.0 };
  glLightfv(GL_LIGHT1, GL_POSITION, light1_position);

  // Set opengl modes
  if (backfacing_visibility) glDisable(GL_CULL_FACE);
  else glEnable(GL_CULL_FACE);
  glDisable(GL_LIGHTING);
  glPointSize(1);
  glLineWidth(1);

  // Draw everything (without culling to viewing extent)
  DrawSelectedPoint();
  DrawScanViewpoints();
  DrawImageViewpoints();
  DrawImagePlane();
  DrawImageInset();
  DrawAxes();

  // Set viewing extent
  DrawViewingExtent();
  EnableViewingExtent();
  UpdateViewingFrustum();

  // Draw everything else (with culling to viewing extent)
  DrawSurfels(surfel_color_scheme);
  DrawNormals();
  DrawObjectPrincipalAxes();
  DrawObjectOrientedBBoxes();
  DrawObjectRelationships();
  DrawObjectBBoxes();
  DrawNodeBBoxes();
  DrawBlockBBoxes();
  DrawImagePoints();
  DrawCenterPoint();

  // Reset viewing modes
  DisableViewingExtent();

  // Capture image
  if (screenshot_name) {
    CaptureImage(screenshot_name);
    free(screenshot_name);
    screenshot_name = NULL;
  }

  // Update the frame time
  if (frame_time < 0) frame_time = 0.05;
  else frame_time = frame_timer.Elapsed();
  frame_timer.Read();

  // Adapt working set
  AdaptWorkingSet();

  // Check if there are any GL errors
  GLenum status = glGetError();
  if (status != GL_NO_ERROR) {
    printf("Error in OpenGL: %d\n", (int) status);
  }

  // Return whether need redraw
  return 0;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rax)
jne 0x361e7
movl $0x0, 0x24(%rsp)
jmp 0x364ea
movq 0x8(%rsp), %rdi
addq $0x78, %rdi
callq 0x2f6d0
movq %rax, %rdi
xorl %esi, %esi
callq 0xd1a70
movq 0x8(%rsp), %rdi
addq $0x380, %rdi            # imm = 0x380
xorl %esi, %esi
callq 0x2f720
movq 0x8(%rsp), %rdi
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
addq $0x380, %rdi            # imm = 0x380
movl $0x1, %esi
callq 0x2f720
movq 0x8(%rsp), %rdi
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
addq $0x380, %rdi            # imm = 0x380
movl $0x2, %esi
callq 0x2f720
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movsd (%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
movss 0x20b7b8(%rip), %xmm3   # 0x241a2c
callq 0x29030
movl $0x4100, %edi           # imm = 0x4100
callq 0x28230
movl $0x4000, %edi           # imm = 0x4000
movl $0x1203, %esi           # imm = 0x1203
leaq 0x28d87c(%rip), %rdx    # 0x2c3b10
callq 0x292c0
movl $0x4001, %edi           # imm = 0x4001
movl $0x1203, %esi           # imm = 0x1203
leaq 0x28d876(%rip), %rdx    # 0x2c3b20
callq 0x292c0
movq 0x8(%rsp), %rax
cmpl $0x0, 0x2f8(%rax)
je 0x362c9
movl $0xb44, %edi            # imm = 0xB44
callq 0x28240
jmp 0x362d3
movl $0xb44, %edi            # imm = 0xB44
callq 0x28960
movl $0xb50, %edi            # imm = 0xB50
callq 0x28240
movss 0x20b747(%rip), %xmm0   # 0x241a2c
callq 0x280b0
movss 0x20b73a(%rip), %xmm0   # 0x241a2c
callq 0x29370
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2c0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2c8(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2d0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2e0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2d8(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2f0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x240(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x230(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x248(%rax)
movq 0x8(%rsp), %rdi
movl 0x360(%rdi), %esi
movq (%rdi), %rax
callq *0x270(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x280(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x288(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x290(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x298(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2a0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2a8(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2b0(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2e8(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x2b8(%rax)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x238(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x4f0(%rax)
je 0x3645a
movq 0x8(%rsp), %rdi
movq 0x4f0(%rdi), %rsi
movq (%rdi), %rax
callq *0x2f8(%rax)
movq 0x8(%rsp), %rax
movq 0x4f0(%rax), %rdi
callq 0x28c80
movq 0x8(%rsp), %rax
movq $0x0, 0x4f0(%rax)
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd 0x4e8(%rax), %xmm0
jbe 0x36483
movq 0x8(%rsp), %rax
movsd 0x20b0cf(%rip), %xmm0   # 0x241548
movsd %xmm0, 0x4e8(%rax)
jmp 0x364a1
movq 0x8(%rsp), %rdi
addq $0x4d8, %rdi            # imm = 0x4D8
callq 0x1a2180
movq 0x8(%rsp), %rax
movsd %xmm0, 0x4e8(%rax)
movq 0x8(%rsp), %rdi
addq $0x4d8, %rdi            # imm = 0x4D8
callq 0x2ef40
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x268(%rax)
callq 0x284e0
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x364e2
movl 0x14(%rsp), %esi
leaq 0x20b5ee(%rip), %rdi    # 0x241ac9
movb $0x0, %al
callq 0x28090
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)