// File: /workspace/github_cpp_makefile_star2_O1/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 0x2fd90
cmpl $0x0, 0x98(%r12)
jle 0x2fd90
cmpl $0x0, 0x9c(%r12)
jle 0x2fd90
movq %rdi, %rbx
cmpl $0x0, 0x328(%rdi)
je 0x2fd90
movsd 0x2e0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%r12), %r14
leaq 0x78(%r12), %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xc6a4c
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc6786
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xc5669
cvtsi2sdl 0x98(%r12), %xmm1
movapd %xmm1, %xmm0
mulsd 0x10b8a7(%rip), %xmm0   # 0x13b378
addsd 0xa0(%r12), %xmm0
mulsd 0x10b52d(%rip), %xmm1   # 0x13b010
divsd %xmm1, %xmm0
leaq 0x48(%r12), %r15
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0xc6786
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc6786
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc5c8c
xorps %xmm0, %xmm0
cvtsi2sdl 0x9c(%r12), %xmm0
movsd 0x10b846(%rip), %xmm1   # 0x13b378
mulsd %xmm0, %xmm1
addsd 0xa8(%r12), %xmm1
mulsd 0x10b4c8(%rip), %xmm0   # 0x13b010
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
leaq 0x60(%r12), %r14
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xc6786
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xc6786
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0xc5c8c
movsd 0xb0(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jae 0x2fbba
xorps %xmm0, %xmm0
cvtsi2sdl 0x98(%r12), %xmm0
mulsd 0x10b45f(%rip), %xmm0   # 0x13b010
divsd %xmm1, %xmm0
callq 0x27780
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xc6786
movsd 0xb8(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jae 0x2fc04
xorps %xmm0, %xmm0
cvtsi2sdl 0x9c(%r12), %xmm0
mulsd 0x10b415(%rip), %xmm0   # 0x13b010
divsd %xmm1, %xmm0
callq 0x27780
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xc6786
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x260(%rax)
movl 0x5e8(%rbx), %esi
testl %esi, %esi
je 0x2fd90
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27bd0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27860
movl $0xb50, %edi            # imm = 0xB50
callq 0x27200
movsd 0x10b3ac(%rip), %xmm0   # 0x13b008
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ee0
movl $0x7, %edi
callq 0x271a0
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x28340
leaq 0x40(%rsp), %r12
leaq 0x70(%rsp), %rbx
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc5d45
leaq 0x58(%rsp), %r13
leaq 0x10(%rsp), %r15
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc5d45
movq %r13, %rdi
callq 0x271c0
xorps %xmm1, %xmm1
movsd 0x10b344(%rip), %xmm0   # 0x13b008
callq 0x28340
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc5669
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc5d45
movq %r13, %rdi
callq 0x271c0
movsd 0x10b309(%rip), %xmm0   # 0x13b008
movapd %xmm0, %xmm1
callq 0x28340
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc5669
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc5669
movq %r13, %rdi
callq 0x271c0
xorpd %xmm0, %xmm0
movsd 0x10b2c6(%rip), %xmm1   # 0x13b008
callq 0x28340
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xc5d45
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc5669
movq %rbx, %rdi
callq 0x271c0
callq 0x27cc0
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x27bd0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27200
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq