// File: /workspace/github_cpp_makefile_star2_O2/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), %r14
testq %r14, %r14
je 0x2e99d
cmpl $0x0, 0x98(%r14)
jle 0x2e99d
cmpl $0x0, 0x9c(%r14)
jle 0x2e99d
movq %rdi, %rbx
cmpl $0x0, 0x328(%rdi)
je 0x2e99d
movsd 0x2e0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%r14), %r15
leaq 0x78(%r14), %rsi
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0xb3446
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xb31d6
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xb25e7
cvtsi2sdl 0x98(%r14), %xmm1
movapd %xmm1, %xmm0
mulsd 0xebc3c(%rip), %xmm0    # 0x11a378
addsd 0xa0(%r14), %xmm0
mulsd 0xeb8c3(%rip), %xmm1    # 0x11a010
divsd %xmm1, %xmm0
leaq 0x48(%r14), %r15
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xb31d6
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xb31d6
movq %r12, %rdi
movq %rbp, %rsi
callq 0xb29b8
cvtsi2sdl 0x9c(%r14), %xmm0
movsd 0xebbe1(%rip), %xmm1    # 0x11a378
mulsd %xmm0, %xmm1
addsd 0xa8(%r14), %xmm1
mulsd 0xeb864(%rip), %xmm0    # 0x11a010
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
leaq 0x60(%r14), %r13
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0xb31d6
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xb31d6
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0xb29b8
movq %r14, %rdi
callq 0x32b5c
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xb31d6
movq %r14, %rdi
callq 0x32b88
callq 0x274e0
mulsd 0x8(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb31d6
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x260(%rax)
movl 0x5e8(%rbx), %esi
testl %esi, %esi
je 0x2e99d
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27bc0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27870
movl $0xb50, %edi            # imm = 0xB50
callq 0x27220
movsd 0xeb79d(%rip), %xmm0    # 0x11a008
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x27ef0
pushq $0x7
popq %rdi
callq 0x271a0
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x28370
leaq 0x40(%rsp), %r12
leaq 0x70(%rsp), %rbx
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xb2a71
leaq 0x58(%rsp), %r13
leaq 0x10(%rsp), %r15
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xb2a71
movq %r13, %rdi
callq 0x271c0
xorps %xmm1, %xmm1
movsd 0xeb737(%rip), %xmm0    # 0x11a008
callq 0x28370
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xb25e7
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xb2a71
movq %r13, %rdi
callq 0x271c0
movsd 0xeb6fc(%rip), %xmm0    # 0x11a008
movapd %xmm0, %xmm1
callq 0x28370
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xb25e7
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xb25e7
movq %r13, %rdi
callq 0x271c0
xorpd %xmm0, %xmm0
movsd 0xeb6b9(%rip), %xmm1    # 0x11a008
callq 0x28370
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xb2a71
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xb25e7
movq %rbx, %rdi
callq 0x271c0
callq 0x27cc0
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x27bc0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27220
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop