// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::DrawImage(int, double) const
void RGBDImage::
DrawImage(int color_scheme, RNLength depth) const
{
  // Check image
  if ((width == 0) || (height == 0)) return;

  // Update/select opengl texture
  if (opengl_texture_id <= 0) ((RGBDImage *) this)->UpdateOpenGL();
  if (opengl_texture_id <= 0) return;
  glBindTexture(GL_TEXTURE_2D, opengl_texture_id);
  glEnable(GL_TEXTURE_2D);

  // Set color
  glDisable(GL_LIGHTING);
  RNLoadRgb(1.0, 1.0, 1.0);

  // Check depth
  if (depth > 0) {
    // Draw textured polygon on view plane
    R3Point viewpoint = WorldViewpoint();
    R3Vector towards = WorldTowards();
    R3Vector right = WorldRight();
    R3Vector up = WorldUp();
    R3Point c = viewpoint + depth * towards;
    R3Vector dx = (depth * 0.5*width / intrinsics[0][0]) * right;
    R3Vector dy = (depth * 0.5*height / intrinsics[1][1]) * up;
    c -= dx*(intrinsics[0][2] - 0.5*width)/width;
    c -= dy*(intrinsics[1][2] - 0.5*height)/height;
    RNGrfxBegin(RN_GRFX_QUADS);
    R3LoadTextureCoords(0, 0);
    R3LoadPoint(c - dx - dy);
    R3LoadTextureCoords(1, 0);
    R3LoadPoint(c + dx - dy);
    R3LoadTextureCoords(1, 1);
    R3LoadPoint(c + dx + dy);
    R3LoadTextureCoords(0, 1);
    R3LoadPoint(c - dx + dy);
    RNGrfxEnd();
  }
  else {
    // Draw textured polygon on screen plane (in pixels)
    RNGrfxBegin(RN_GRFX_QUADS);
    R3LoadTextureCoords(0, 0);
    R3LoadPoint(0, 0, 0);
    R3LoadTextureCoords(1, 0);
    R3LoadPoint(width-1, 0, 0);
    R3LoadTextureCoords(1, 1);
    R3LoadPoint(width-1, height-1, 0);
    R3LoadTextureCoords(0, 1);
    R3LoadPoint(0, height-1, 0);
    RNGrfxEnd();
  }
  
  // Unselect opengl texture
  glDisable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, 0);
}

// Assembly:
cmpl $0x0, 0x28(%rdi)
je 0x1d4c0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x2c(%rdi)
je 0x1d4af
movl 0x1c8(%rbx), %esi
testl %esi, %esi
movsd %xmm0, 0x8(%rsp)
jg 0x1d1a6
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x1d0(%rax)
movl 0x1c8(%rbx), %esi
testl %esi, %esi
jle 0x1d4af
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11750
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11550
movl $0xb50, %edi            # imm = 0xB50
callq 0x111a0
movsd 0x8ae5c(%rip), %xmm0    # 0xa8028
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
callq 0x11910
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1d42d
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x155fc
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x15686
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1fa3c
leaq 0x88(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x197a6
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movsd 0x8(%rsp), %xmm0
callq 0x46c02
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x46013
movsd 0x8(%rsp), %xmm1
mulsd 0x8ada8(%rip), %xmm1    # 0xa8018
movsd %xmm1, 0x8(%rsp)
cvtsi2sdl 0x28(%rbx), %xmm0
mulsd %xmm1, %xmm0
divsd 0x140(%rbx), %xmm0
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x46c02
cvtsi2sdl 0x2c(%rbx), %xmm0
mulsd 0x8(%rsp), %xmm0
divsd 0x160(%rbx), %xmm0
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x46c02
cvtsi2sdl 0x28(%rbx), %xmm0
mulsd 0x8bd09(%rip), %xmm0    # 0xa8fd0
addsd 0x150(%rbx), %xmm0
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x46c02
cvtsi2sdl 0x28(%rbx), %xmm0
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x46f1e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x463e4
cvtsi2sdl 0x2c(%rbx), %xmm0
mulsd 0x8bcc4(%rip), %xmm0    # 0xa8fd0
addsd 0x168(%rbx), %xmm0
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x46c02
cvtsi2sdl 0x2c(%rbx), %xmm0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x46f1e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x463e4
pushq $0x7
popq %rdi
callq 0x11150
xorl %edi, %edi
xorl %esi, %esi
callq 0x11440
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4649d
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4649d
movq %r13, %rdi
callq 0x11170
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %esi, %esi
callq 0x11440
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x46013
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4649d
movq %rbp, %rdi
callq 0x11170
movl %ebx, %edi
movl %ebx, %esi
callq 0x11440
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x46013
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x46013
movq %rbp, %rdi
callq 0x11170
xorl %edi, %edi
movl %ebx, %esi
callq 0x11440
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4649d
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x46013
movq %r14, %rdi
callq 0x11170
jmp 0x1d494
pushq $0x7
popq %rdi
callq 0x11150
xorl %edi, %edi
xorl %esi, %esi
callq 0x11440
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11470
pushq $0x1
popq %rbp
movl %ebp, %edi
xorl %esi, %esi
callq 0x11440
movl 0x28(%rbx), %edi
decl %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11470
movl %ebp, %edi
movl %ebp, %esi
callq 0x11440
movl 0x28(%rbx), %edi
movl 0x2c(%rbx), %esi
decl %edi
decl %esi
xorl %edx, %edx
callq 0x11470
xorl %edi, %edi
movl %ebp, %esi
callq 0x11440
movl 0x2c(%rbx), %esi
decl %esi
xorl %edi, %edi
xorl %edx, %edx
callq 0x11470
callq 0x117d0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x111a0
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x11750
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop