// File: /workspace/github_cpp_makefile_star2_O3/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 0x1c27a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %r12
movl 0x30(%rdi), %esi
testl %esi, %esi
jg 0x1be66
movq (%r12), %rax
movq %r12, %rdi
callq *0xe0(%rax)
movl 0x30(%r12), %esi
testl %esi, %esi
jle 0x1c26c
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11750
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11540
movq (%r12), %rax
movq %r12, %rdi
movl %ebp, %esi
callq *0x80(%rax)
cmpq $0x0, 0x80(%r12)
je 0x1bf42
movl $0x7, %edi
callq 0x11150
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0x11ba0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c033
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4b612
movsd 0x68(%r14), %xmm0
xorps 0x9f162(%rip), %xmm0    # 0xbb050
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
callq 0x4b9e4
movsd 0x70(%r14), %xmm0
xorpd 0x9f135(%rip), %xmm0    # 0xbb050
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4b9e4
jmp 0x1c044
cmpq $0x0, 0x88(%r12)
je 0x1c256
cmpl $0x0, 0x28(%r12)
jle 0x1c256
cmpl $0x0, 0x2c(%r12)
jle 0x1c256
movl $0x4, %edi
callq 0x11150
movq 0x88(%r12), %rax
cmpl $0x0, 0x34(%rax)
jle 0x1c251
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 0x6f0d4
addq $0x48, %r12
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %r12
callq 0x6f0e0
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 0x1bfa8
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x88(%r12), %rax
movslq 0x34(%rax), %rcx
cmpq %rcx, %rdx
jl 0x1bf91
jmp 0x1c251
leaq 0xe9b66(%rip), %rsi     # 0x105ba0
leaq 0x8(%rsp), %rdi
callq 0x4b612
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0x9efd2(%rip), %xmm0    # 0xbb028
xorpd %xmm1, %xmm1
callq 0x11ba0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c0e5
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4b612
movsd 0x68(%r14), %xmm0
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
callq 0x4b9e4
movsd 0x70(%r14), %xmm0
xorpd 0x9ef8f(%rip), %xmm0    # 0xbb050
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4b9e4
jmp 0x1c0f6
leaq 0xe9ab4(%rip), %rsi     # 0x105ba0
leaq 0x8(%rsp), %rdi
callq 0x4b612
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0x9ef20(%rip), %xmm0    # 0xbb028
movapd %xmm0, %xmm1
callq 0x11ba0
movq 0x80(%r12), %r14
movsd 0x68(%r14), %xmm0
minsd 0x70(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c18f
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4b612
movsd 0x68(%r14), %xmm0
leaq 0x20(%r14), %rsi
movq %r12, %rbx
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
callq 0x4b9e4
movsd 0x70(%r14), %xmm0
addq $0x38, %r14
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4ca32
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r12
callq 0x4b9e4
jmp 0x1c1a0
leaq 0xe9a0a(%rip), %rsi     # 0x105ba0
leaq 0x8(%rsp), %rdi
callq 0x4b612
leaq 0x8(%rsp), %rdi
callq 0x11170
movsd 0x9ee76(%rip), %xmm1    # 0xbb028
xorpd %xmm0, %xmm0
callq 0x11ba0
movq 0x80(%r12), %rbx
movsd 0x68(%rbx), %xmm0
minsd 0x70(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x1c236
leaq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x4b612
movsd 0x68(%rbx), %xmm0
xorps 0x9ee5c(%rip), %xmm0    # 0xbb050
leaq 0x20(%rbx), %rsi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x4ca32
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b9e4
movsd 0x70(%rbx), %xmm0
addq $0x38, %rbx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4ca32
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b9e4
jmp 0x1c247
leaq 0xe9963(%rip), %rsi     # 0x105ba0
leaq 0x8(%rsp), %rdi
callq 0x4b612
leaq 0x8(%rsp), %rdi
callq 0x11170
callq 0x117c0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11180
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x11750
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop