// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::DrawImagePlane() const
void R3SurfelViewer::
DrawImagePlane(void) const
{
  // Get/check stuff
  if (!selected_image) return;
  if (selected_image->ImageWidth() <= 0) return;
  if (selected_image->ImageHeight() <= 0) return;
  if (!image_plane_visibility) return;

#if (RN_OS != RN_MAC)
  // For some unknown reason, drawing a textured quad hangs the GPU for some images
  // (very rarely, but it is repeatable). 

  // Get convenient variables
  RNLength depth = image_plane_depth;
  R3SurfelImage *image = selected_image;
  R3Point c = image->Viewpoint() + depth * image->Towards();
  c -= ((image->ImageCenter().X() - 0.5*image->ImageWidth()) / (0.5*image->ImageWidth())) * image->Right() * depth;
  c -= ((image->ImageCenter().Y() - 0.5*image->ImageHeight()) / (0.5*image->ImageHeight())) * image->Up() * depth;
  R3Vector dx = depth * tan(image->XFOV()) * image->Right();
  R3Vector dy = depth * tan(image->YFOV()) * image->Up();

  // Update selected image texture
  ((R3SurfelViewer *) this)->UpdateSelectedImageTexture();

  // Draw image as textured quad
  if (selected_image_texture_id > 0) {
    // Bind texture
    glBindTexture(GL_TEXTURE_2D, selected_image_texture_id);
    glEnable(GL_TEXTURE_2D);

    // Draw quad
    glDisable(GL_LIGHTING);
    RNLoadRgb(1.0, 1.0, 1.0);
    RNGrfxBegin(RN_GRFX_QUADS);
    R3LoadTextureCoords(0.0, 0.0);
    R3LoadPoint(c - dx - dy);
    R3LoadTextureCoords(1.0, 0.0);
    R3LoadPoint(c + dx - dy);
    R3LoadTextureCoords(1.0, 1.0);
    R3LoadPoint(c + dx + dy);
    R3LoadTextureCoords(0.0, 1.0);
    R3LoadPoint(c - dx + dy);
    RNGrfxEnd();

    // Unbind texture
    glBindTexture(GL_TEXTURE_2D, 0);
    glDisable(GL_TEXTURE_2D);
  }
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq 0x2d0(%rdi), %r12
testq %r12, %r12
je 0x2fc42
cmpl $0x0, 0x98(%r12)
jle 0x2fc42
cmpl $0x0, 0x9c(%r12)
jle 0x2fc42
movq %rdi, %rbx
cmpl $0x0, 0x328(%rdi)
je 0x2fc42
movsd 0x2e0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%r12), %r14
leaq 0x78(%r12), %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xc5400
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc5162
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xc4077
cvtsi2sdl 0x98(%r12), %xmm1
movapd %xmm1, %xmm0
mulsd 0x1089f5(%rip), %xmm0   # 0x138378
addsd 0xa0(%r12), %xmm0
mulsd 0x10867b(%rip), %xmm1   # 0x138010
divsd %xmm1, %xmm0
leaq 0x48(%r12), %r15
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0xc5162
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc5162
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc469a
xorps %xmm0, %xmm0
cvtsi2sdl 0x9c(%r12), %xmm0
movsd 0x108994(%rip), %xmm1   # 0x138378
mulsd %xmm0, %xmm1
addsd 0xa8(%r12), %xmm1
mulsd 0x108616(%rip), %xmm0   # 0x138010
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
leaq 0x60(%r12), %r14
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xc5162
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc5162
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0xc469a
movsd 0xb0(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jae 0x2fa6c
xorps %xmm0, %xmm0
cvtsi2sdl 0x98(%r12), %xmm0
mulsd 0x1085ad(%rip), %xmm0   # 0x138010
divsd %xmm1, %xmm0
callq 0x27780
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xc5162
movsd 0xb8(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jae 0x2fab6
xorps %xmm0, %xmm0
cvtsi2sdl 0x9c(%r12), %xmm0
mulsd 0x108563(%rip), %xmm0   # 0x138010
divsd %xmm1, %xmm0
callq 0x27780
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xc5162
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x260(%rax)
movl 0x5e8(%rbx), %esi
testl %esi, %esi
je 0x2fc42
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27bc0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27860
movl $0xb50, %edi            # imm = 0xB50
callq 0x27200
movsd 0x1084fa(%rip), %xmm0   # 0x138008
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ed0
movl $0x7, %edi
callq 0x271a0
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x28330
leaq 0x40(%rsp), %r12
leaq 0x70(%rsp), %rbx
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc4753
leaq 0x58(%rsp), %r13
leaq 0x10(%rsp), %r15
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc4753
movq %r13, %rdi
callq 0x271c0
xorps %xmm1, %xmm1
movsd 0x108492(%rip), %xmm0   # 0x138008
callq 0x28330
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc4077
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc4753
movq %r13, %rdi
callq 0x271c0
movsd 0x108457(%rip), %xmm0   # 0x138008
movapd %xmm0, %xmm1
callq 0x28330
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc4077
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc4077
movq %r13, %rdi
callq 0x271c0
xorpd %xmm0, %xmm0
movsd 0x108414(%rip), %xmm1   # 0x138008
callq 0x28330
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc4753
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc4077
movq %rbx, %rdi
callq 0x271c0
callq 0x27cb0
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x27bc0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27200
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq