// File: /workspace/github_cpp_makefile_star2_O2/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 0x1acb6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movl 0x30(%rdi), %esi
testl %esi, %esi
jg 0x1ab97
movq (%rbx), %rax
movq %rbx, %rdi
callq *0xe0(%rax)
movl 0x30(%rbx), %esi
testl %esi, %esi
jle 0x1aca8
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11750
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11550
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x80(%rax)
cmpq $0x0, 0x80(%rbx)
je 0x1acb7
pushq $0x7
popq %rdi
callq 0x11150
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x11be0
movq 0x80(%rbx), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1b80a
movq %r14, %rdi
callq 0x11170
movsd 0x8d426(%rip), %xmm0    # 0xa8028
xorps %xmm1, %xmm1
callq 0x11be0
movq 0x80(%rbx), %rsi
leaq 0x10(%rsp), %r14
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x1b80a
movq %r14, %rdi
callq 0x11170
movsd 0x8d3f3(%rip), %xmm0    # 0xa8028
movaps %xmm0, %xmm1
callq 0x11be0
movq 0x80(%rbx), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl %ebp, %edx
movl %ebp, %ecx
callq 0x1b80a
movq %r14, %rdi
callq 0x11170
xorps %xmm0, %xmm0
movsd 0x8d3c0(%rip), %xmm1    # 0xa8028
callq 0x11be0
movq 0x80(%rbx), %rsi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
movl %ebp, %ecx
callq 0x1b80a
movq %rbx, %rdi
callq 0x11170
callq 0x117d0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x111a0
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
cmpq $0x0, 0x88(%rbx)
je 0x1ac92
cmpl $0x0, 0x28(%rbx)
jle 0x1ac92
cmpl $0x0, 0x2c(%rbx)
jle 0x1ac92
pushq $0x4
popq %rdi
callq 0x11150
xorl %edx, %edx
leaq 0x10(%rsp), %r14
movq %rbx, 0x8(%rsp)
movq 0x88(%rbx), %rax
movslq 0x34(%rax), %rcx
cmpq %rcx, %rdx
jge 0x1ac8d
movq 0x28(%rax), %rax
movq %rdx, 0x30(%rsp)
movq (%rax,%rdx,8), %rbp
pushq $0x1
popq %r15
cmpq $0x4, %r15
je 0x1ad6f
movq (%rbp,%r15,8), %r12
leaq 0x18(%r12), %r13
movq %r14, %rdi
callq 0x6663e
addq $0x48, %r12
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6664a
movq 0x8(%rsp), %r12
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq *0x40(%rax)
cvtdq2pd 0x28(%r12), %xmm0
movapd 0x10(%rsp), %xmm1
divpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movq %r14, %rdi
callq 0x11160
movq %r13, %rdi
callq 0x11170
incq %r15
jmp 0x1ad02
movq 0x30(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rbx
jmp 0x1ace1
nop