// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::DrawQuads(int, int) const
void RGBDImage::
DrawQuads(int color_scheme, int skip) const
{
  // Get info about current view
  GLint viewport[4];
  GLdouble modelview_matrix[16];
  GLdouble projection_matrix[16];
  glGetIntegerv(GL_VIEWPORT, viewport);
  glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
  glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);

  // Push transformation
  CameraToWorld().Push();

  // Enable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_LIGHTING);
  }

  // Draw color
  LoadColor(color_scheme);

  // Draw quads
  RNGrfxBegin(RN_GRFX_TRIANGLES);
  for (int ix = 0; ix < NPixels(RN_X)-skip; ix += skip) {
    for (int iy = 0; iy < NPixels(RN_Y)-skip; iy += skip) {
      R3Point p1, p2, p3, p4;
      if (!RGBDTransformImageToCamera(R2Point(ix, iy), p1, this)) continue;
      if (!RGBDTransformImageToCamera(R2Point(ix+skip, iy), p2, this)) continue;
      if (!RGBDTransformImageToCamera(R2Point(ix+skip, iy+skip), p3, this)) continue;
      if (!RGBDTransformImageToCamera(R2Point(ix, iy+skip), p4, this)) continue;
      R3Plane plane(p1, p2, p3);
      RNScalar dot = plane.Normal().Dot(p1.Vector());
      if (dot < -0.5) {
        if ((fabs(p1.Z() - p2.Z())/-p1.Z() < 0.05) &&
            (fabs(p2.Z() - p3.Z())/-p2.Z() < 0.05) &&
            (fabs(p3.Z() - p1.Z())/-p3.Z() < 0.05)) {
          R3LoadNormal(plane.Normal());
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix, iy));
          R3LoadPoint(p1);
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix+skip, iy));
          R3LoadPoint(p2);
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix+skip, iy+skip));
          R3LoadPoint(p3);
        }
        if ((fabs(p1.Z() - p3.Z())/-p1.Z() < 0.05) &&
            (fabs(p3.Z() - p4.Z())/-p3.Z() < 0.05) &&
            (fabs(p4.Z() - p1.Z())/-p4.Z() < 0.05)) {
          R3LoadNormal(plane.Normal());
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix, iy));
          R3LoadPoint(p1);
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix+skip, iy+skip));
          R3LoadPoint(p3);
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix, iy+skip));
          R3LoadPoint(p4);
        }
      }
    }
  }
  RNGrfxEnd();

  // Disable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_LIGHTING);
  }

  // Pop transformation
  CameraToWorld().Pop();
}

// Assembly:
subq $0x318, %rsp            # imm = 0x318
movq %rdi, 0x310(%rsp)
movl %esi, 0x30c(%rsp)
movl %edx, 0x308(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x2f0(%rsp), %rsi
movl $0xba2, %edi            # imm = 0xBA2
callq 0x12680
leaq 0x270(%rsp), %rsi
movl $0xba6, %edi            # imm = 0xBA6
callq 0x12800
leaq 0x1f0(%rsp), %rsi
movl $0xba7, %edi            # imm = 0xBA7
callq 0x12800
movq 0x70(%rsp), %rdi
callq 0x22710
movq %rax, %rdi
movq (%rdi), %rax
callq *0xb0(%rax)
cmpl $0x2, 0x30c(%rsp)
jne 0x2c3d3
movl $0xb57, %edi            # imm = 0xB57
callq 0x12640
movl $0x408, %edi            # imm = 0x408
movl $0x1602, %esi           # imm = 0x1602
callq 0x12460
movl $0xb50, %edi            # imm = 0xB50
callq 0x12640
movq 0x70(%rsp), %rdi
movl 0x30c(%rsp), %esi
movq (%rdi), %rax
callq *0xf0(%rax)
movl $0x4, %edi
callq 0x27c00
movl $0x0, 0x1ec(%rsp)
movq 0x70(%rsp), %rdi
movl 0x1ec(%rsp), %eax
movl %eax, 0x6c(%rsp)
xorl %esi, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x6c(%rsp), %eax
subl 0x308(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2cb7b
movl $0x0, 0x1e8(%rsp)
movq 0x70(%rsp), %rdi
movl 0x1e8(%rsp), %eax
movl %eax, 0x68(%rsp)
movl $0x1, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x68(%rsp), %eax
subl 0x308(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2cb5f
leaq 0x1d0(%rsp), %rdi
callq 0x8a990
leaq 0x1b8(%rsp), %rdi
callq 0x8a990
leaq 0x1a0(%rsp), %rdi
callq 0x8a990
leaq 0x188(%rsp), %rdi
callq 0x8a990
cvtsi2sdl 0x1ec(%rsp), %xmm0
cvtsi2sdl 0x1e8(%rsp), %xmm1
leaq 0x178(%rsp), %rdi
callq 0xcfd80
movq 0x70(%rsp), %rdx
leaq 0x178(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c4de
jmp 0x2c4e3
jmp 0x2cb45
movl 0x1ec(%rsp), %eax
addl 0x308(%rsp), %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x1e8(%rsp), %xmm1
leaq 0x168(%rsp), %rdi
callq 0xcfd80
movq 0x70(%rsp), %rdx
leaq 0x168(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c533
jmp 0x2c538
jmp 0x2cb45
movl 0x1ec(%rsp), %eax
addl 0x308(%rsp), %eax
cvtsi2sd %eax, %xmm0
movl 0x1e8(%rsp), %eax
addl 0x308(%rsp), %eax
cvtsi2sd %eax, %xmm1
leaq 0x158(%rsp), %rdi
callq 0xcfd80
movq 0x70(%rsp), %rdx
leaq 0x158(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c591
jmp 0x2c596
jmp 0x2cb45
cvtsi2sdl 0x1ec(%rsp), %xmm0
movl 0x1e8(%rsp), %eax
addl 0x308(%rsp), %eax
cvtsi2sd %eax, %xmm1
leaq 0x148(%rsp), %rdi
callq 0xcfd80
movq 0x70(%rsp), %rdx
leaq 0x148(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c5e6
jmp 0x2c5eb
jmp 0x2cb45
leaq 0x128(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
leaq 0x1a0(%rsp), %rcx
callq 0x88490
leaq 0x128(%rsp), %rdi
callq 0x28110
movq %rax, 0x60(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x30640
movq 0x60(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x8c110
movsd %xmm0, 0x120(%rsp)
movsd 0x139f06(%rip), %xmm0   # 0x166560
ucomisd 0x120(%rsp), %xmm0
jbe 0x2cb43
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, 0x50(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd 0x50(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139ee3(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movsd 0x58(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a92b(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2c8d9
leaq 0x1b8(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, 0x40(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139e65(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x19ec0
movsd 0x48(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a8ad(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2c8d9
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, 0x30(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139de7(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movsd 0x38(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a82f(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2c8d9
leaq 0x128(%rsp), %rdi
callq 0x28110
movq %rax, %rdi
callq 0x27cb0
cmpl $0x1, 0x30c(%rsp)
jne 0x2c82f
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
movl 0x1e8(%rsp), %ecx
leaq 0xf0(%rsp), %rdi
callq 0x29420
leaq 0xf0(%rsp), %rdi
callq 0x27c20
leaq 0x1d0(%rsp), %rdi
callq 0x27c90
cmpl $0x1, 0x30c(%rsp)
jne 0x2c87a
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
addl 0x308(%rsp), %edx
movl 0x1e8(%rsp), %ecx
leaq 0xd8(%rsp), %rdi
callq 0x29420
leaq 0xd8(%rsp), %rdi
callq 0x27c20
leaq 0x1b8(%rsp), %rdi
callq 0x27c90
cmpl $0x1, 0x30c(%rsp)
jne 0x2c8cc
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
addl 0x308(%rsp), %edx
movl 0x1e8(%rsp), %ecx
addl 0x308(%rsp), %ecx
leaq 0xc0(%rsp), %rdi
callq 0x29420
leaq 0xc0(%rsp), %rdi
callq 0x27c20
leaq 0x1a0(%rsp), %rdi
callq 0x27c90
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, 0x20(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139c73(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movsd 0x28(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a6bb(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2cb41
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, 0x10(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139bf5(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x19ec0
movsd 0x18(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a63d(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2cb41
leaq 0x188(%rsp), %rdi
callq 0x19ec0
movsd %xmm0, (%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x19ec0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movaps 0x139b79(%rip), %xmm1   # 0x166580
pand %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x19ec0
movsd 0x8(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13a5c1(%rip), %xmm0   # 0x167008
ucomisd %xmm1, %xmm0
jbe 0x2cb41
leaq 0x128(%rsp), %rdi
callq 0x28110
movq %rax, %rdi
callq 0x27cb0
cmpl $0x1, 0x30c(%rsp)
jne 0x2ca9d
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
movl 0x1e8(%rsp), %ecx
leaq 0xa8(%rsp), %rdi
callq 0x29420
leaq 0xa8(%rsp), %rdi
callq 0x27c20
leaq 0x1d0(%rsp), %rdi
callq 0x27c90
cmpl $0x1, 0x30c(%rsp)
jne 0x2caef
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
addl 0x308(%rsp), %edx
movl 0x1e8(%rsp), %ecx
addl 0x308(%rsp), %ecx
leaq 0x90(%rsp), %rdi
callq 0x29420
leaq 0x90(%rsp), %rdi
callq 0x27c20
leaq 0x1a0(%rsp), %rdi
callq 0x27c90
cmpl $0x1, 0x30c(%rsp)
jne 0x2cb34
movq 0x70(%rsp), %rsi
movl 0x1ec(%rsp), %edx
movl 0x1e8(%rsp), %ecx
addl 0x308(%rsp), %ecx
leaq 0x78(%rsp), %rdi
callq 0x29420
leaq 0x78(%rsp), %rdi
callq 0x27c20
leaq 0x188(%rsp), %rdi
callq 0x27c90
jmp 0x2cb43
jmp 0x2cb45
movl 0x308(%rsp), %eax
addl 0x1e8(%rsp), %eax
movl %eax, 0x1e8(%rsp)
jmp 0x2c434
jmp 0x2cb61
movl 0x308(%rsp), %eax
addl 0x1ec(%rsp), %eax
movl %eax, 0x1ec(%rsp)
jmp 0x2c3fd
callq 0x27cd0
cmpl $0x2, 0x30c(%rsp)
jne 0x2cb9e
movl $0xb57, %edi            # imm = 0xB57
callq 0x121c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x121c0
movq 0x70(%rsp), %rdi
callq 0x22710
movq %rax, %rdi
movq (%rdi), %rax
callq *0xb8(%rax)
addq $0x318, %rsp            # imm = 0x318
retq
nopl (%rax)