// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::DrawFaces(int) const
void RGBDSurface::
DrawFaces(int color_scheme) const
{
  // Enable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_LIGHTING);
  }

  // Load color
  LoadColor(color_scheme);

  // Draw faces
  if (rectangle) {
    rectangle->Draw();
  }
  else if (mesh) {
    RNGrfxBegin(RN_GRFX_TRIANGLES);
    for (int i = 0; i < mesh->NFaces(); i++) {
      R3MeshFace *face = mesh->Face(i);
      R3MeshVertex *v0 = mesh->VertexOnFace(face, 0);
      R3MeshVertex *v1 = mesh->VertexOnFace(face, 1);
      R3MeshVertex *v2 = mesh->VertexOnFace(face, 2);
      if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) {
        RNLoadRgb(mesh->VertexColor(v0));
        R3LoadPoint(mesh->VertexPosition(v0));
        RNLoadRgb(mesh->VertexColor(v1));
        R3LoadPoint(mesh->VertexPosition(v1));
        RNLoadRgb(mesh->VertexColor(v2));
        R3LoadPoint(mesh->VertexPosition(v2));
      }
      else if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
        R3LoadNormal(mesh->FaceNormal(face));
        R3LoadPoint(mesh->VertexPosition(v0));
        R3LoadPoint(mesh->VertexPosition(v1));
        R3LoadPoint(mesh->VertexPosition(v2));
      }
      else {
        R3LoadPoint(mesh->VertexPosition(v0));
        R3LoadPoint(mesh->VertexPosition(v1));
        R3LoadPoint(mesh->VertexPosition(v2));
      }
    }
    RNGrfxEnd();
  }

  // Disable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_LIGHTING);
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x2, 0x4c(%rsp)
jne 0x25861
movl $0xb57, %edi            # imm = 0xB57
callq 0x12640
movl $0x408, %edi            # imm = 0x408
movl $0x1602, %esi           # imm = 0x1602
callq 0x12460
movl $0xb50, %edi            # imm = 0xB50
callq 0x12640
movq 0x10(%rsp), %rdi
movl 0x4c(%rsp), %esi
movq (%rdi), %rax
callq *0x80(%rax)
movq 0x10(%rsp), %rax
cmpq $0x0, 0x80(%rax)
je 0x258ba
movq 0x10(%rsp), %rax
movq 0x80(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x772, %esi            # imm = 0x772
callq 0x1a6b0
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq (%rdi), %rax
callq *0xa8(%rax)
jmp 0x25b40
movq 0x10(%rsp), %rax
cmpq $0x0, 0x88(%rax)
je 0x25b3e
movl $0x4, %edi
callq 0x27c00
movl $0x0, 0x3c(%rsp)
movq 0x10(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, 0x4(%rsp)
movq 0x88(%rax), %rdi
callq 0x19f00
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x25b39
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movl 0x3c(%rsp), %esi
callq 0x22bb0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x30(%rsp)
movq 0x88(%rax), %rdi
movq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x22be0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq 0x88(%rax), %rdi
movq 0x30(%rsp), %rsi
movl $0x1, %edx
callq 0x22be0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq 0x88(%rax), %rdi
movq 0x30(%rsp), %rsi
movl $0x2, %edx
callq 0x22be0
movq %rax, 0x18(%rsp)
cmpl $0x1, 0x4c(%rsp)
jne 0x25a4a
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x27c70
movq %rax, %rdi
callq 0x27c20
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x27c70
movq %rax, %rdi
callq 0x27c20
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x27c70
movq %rax, %rdi
callq 0x27c20
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
jmp 0x25b27
cmpl $0x2, 0x4c(%rsp)
jne 0x25acb
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x30(%rsp), %rsi
callq 0x27910
movq %rax, %rdi
callq 0x27cb0
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
jmp 0x25b25
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
movq 0x10(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x22b70
movq %rax, %rdi
callq 0x27c90
jmp 0x25b27
jmp 0x25b29
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x258df
callq 0x27cd0
jmp 0x25b40
cmpl $0x2, 0x4c(%rsp)
jne 0x25b5b
movl $0xb57, %edi            # imm = 0xB57
callq 0x121c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x121c0
addq $0x58, %rsp
retq