// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::DrawTexture(int) const
void RGBDSurface::
DrawTexture(int color_scheme) const
{
  // Check channels
  if (NChannels() == 0) return;
  
  // Update/select opengl texture
  if (opengl_texture_id <= 0) ((RGBDSurface *) this)->UpdateOpenGL();
  if (opengl_texture_id <= 0) return;
  glBindTexture(GL_TEXTURE_2D, opengl_texture_id);
  glEnable(GL_TEXTURE_2D);

  // Load color
  LoadColor(color_scheme);

  // Draw rectangle
  if (rectangle) {
    RNGrfxBegin(RN_GRFX_QUADS);
    R3LoadTextureCoords(0.0, 0.0);
    R3LoadPoint(rectangle->Corner(0,0));
    R3LoadTextureCoords(1.0, 0.0);
    R3LoadPoint(rectangle->Corner(1,0));
    R3LoadTextureCoords(1.0, 1.0);
    R3LoadPoint(rectangle->Corner(1,1));
    R3LoadTextureCoords(0.0, 1.0);
    R3LoadPoint(rectangle->Corner(0,1));
    RNGrfxEnd();
  }
  else if (mesh) {
    if ((width > 0) && (height > 0)) {
      RNGrfxBegin(RN_GRFX_TRIANGLES);
      for (int i = 0; i < mesh->NFaces(); i++) {
        R3MeshFace *face = mesh->Face(i);
        for (int j = 0; j < 3; j ++) {
          R3MeshVertex *vertex = mesh->VertexOnFace(face, j);
          const R3Point& world_position = mesh->VertexPosition(vertex);
          R2Point texture_position, surface_position = mesh->VertexTextureCoords(vertex);
          TransformSurfaceToTexture(surface_position, texture_position);
          texture_position[0] = texture_position[0] / width;
          texture_position[1] = texture_position[1] / height;
          R3LoadTextureCoords(texture_position);
          R3LoadPoint(world_position);
        }
      }
      RNGrfxEnd();
    }
  }

  // Unselect opengl texture
  glDisable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, 0);
}

// Assembly:
cmpl $0x0, 0x24(%rdi)
je 0x1c49f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %r12
cmpl $0x0, 0x30(%rdi)
jg 0x1c07e
movq (%r12), %rax
movq %r12, %rdi
callq *0xe0(%rax)
movl 0x30(%r12), %esi
testl %esi, %esi
jle 0x1c491
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11760
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11540
movq (%r12), %rax
movq %r12, %rdi
movl %ebp, %esi
callq *0x80(%rax)
cmpq $0x0, 0x80(%r12)
je 0x1c167
movl $0x7, %edi
callq 0x11150
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0x11bb0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c258
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4be56
movsd 0x68(%r14), %xmm0
xorps 0xa0f3d(%rip), %xmm0    # 0xbd050
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
callq 0x4c22e
movsd 0x70(%r14), %xmm0
xorpd 0xa0f10(%rip), %xmm0    # 0xbd050
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4c22e
jmp 0x1c269
cmpq $0x0, 0x88(%r12)
je 0x1c47b
cmpl $0x0, 0x28(%r12)
jle 0x1c47b
cmpl $0x0, 0x2c(%r12)
jle 0x1c47b
movl $0x4, %edi
callq 0x11150
movq 0x88(%r12), %rax
cmpl $0x0, 0x34(%rax)
jle 0x1c476
xorl %edx, %edx
leaq 0x20(%rsp), %r14
leaq 0x8(%rsp), %r15
movq 0x28(%rax), %rax
movq %rdx, 0x38(%rsp)
movq (%rax,%rdx,8), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %ebx
movq %r12, %rbp
movq 0x40(%rsp), %rax
movq (%rax,%rbx,8), %r12
leaq 0x18(%r12), %r13
movq %r14, %rdi
callq 0x6fee4
addq $0x48, %r12
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %r12
callq 0x6fef0
movq (%rbp), %rax
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x40(%rax)
cvtdq2pd 0x28(%rbp), %xmm0
movapd 0x20(%rsp), %xmm1
divpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movq %r14, %rdi
callq 0x11160
movq %r13, %rdi
callq 0x11170
incq %rbx
cmpq $0x4, %rbx
jne 0x1c1cd
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x88(%r12), %rax
movslq 0x34(%rax), %rcx
cmpq %rcx, %rdx
jl 0x1c1b6
jmp 0x1c476
leaq 0xeb951(%rip), %rsi     # 0x107bb0
leaq 0x8(%rsp), %rdi
callq 0x4be56
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0xa0dad(%rip), %xmm0    # 0xbd028
xorpd %xmm1, %xmm1
callq 0x11bb0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c30a
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4be56
movsd 0x68(%r14), %xmm0
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
callq 0x4c22e
movsd 0x70(%r14), %xmm0
xorpd 0xa0d6a(%rip), %xmm0    # 0xbd050
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4c22e
jmp 0x1c31b
leaq 0xeb89f(%rip), %rsi     # 0x107bb0
leaq 0x8(%rsp), %rdi
callq 0x4be56
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0xa0cfb(%rip), %xmm0    # 0xbd028
movapd %xmm0, %xmm1
callq 0x11bb0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c3b4
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4be56
movsd 0x68(%r14), %xmm0
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
callq 0x4c22e
movsd 0x70(%r14), %xmm0
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4d2ae
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4c22e
jmp 0x1c3c5
leaq 0xeb7f5(%rip), %rsi     # 0x107bb0
leaq 0x8(%rsp), %rdi
callq 0x4be56
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0xa0c51(%rip), %xmm1    # 0xbd028
xorpd %xmm0, %xmm0
callq 0x11bb0
movq 0x80(%r12), %rbx
movsd 0x68(%rbx), %xmm0
minsd 0x70(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c45b
leaq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4be56
movsd 0x68(%rbx), %xmm0
xorps 0xa0c37(%rip), %xmm0    # 0xbd050
leaq 0x20(%rbx), %rsi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x4d2ae
movq %r14, %rdi
movq %r15, %rsi
callq 0x4c22e
movsd 0x70(%rbx), %xmm0
addq $0x38, %rbx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4d2ae
movq %r14, %rdi
movq %r15, %rsi
callq 0x4c22e
jmp 0x1c46c
leaq 0xeb74e(%rip), %rsi     # 0x107bb0
leaq 0x8(%rsp), %rdi
callq 0x4be56
leaq 0x8(%rsp), %rdi
callq 0x11170
callq 0x117d0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11180
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x11760
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq