// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::DrawFaces(gaps::RNFlags) const
void R3Mesh::
DrawFaces(const R3DrawFlags draw_flags) const
{
  // Bind face position buffer
  if (GLFacePositionBufferObject() <= 0) return;
  glBindBuffer(GL_ARRAY_BUFFER, vbo_face_position_buffer);
  glVertexPointer(3, GL_FLOAT, 0, 0);
  glEnableClientState(GL_VERTEX_ARRAY);
  
  // Bind face normal buffer
  if (draw_flags & R3_SURFACE_NORMALS_DRAW_FLAG) {  
    if (GLFaceNormalBufferObject() > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_face_normal_buffer);
      glNormalPointer(GL_FLOAT, 0, 0);
      glEnableClientState(GL_NORMAL_ARRAY);
    }
  }
  
  // Bind face texcoord buffer
  if (draw_flags & R3_SURFACE_TEXTURE_DRAW_FLAG) {  
    if (GLFaceTextureCoordBufferObject() > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_face_texcoord_buffer);
      glTexCoordPointer(2, GL_FLOAT, 0, 0);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    }
  }
  
  // Bind face color buffer
  if (draw_flags[R3_SURFACE_PICK_DRAW_FLAG]) {
    if (GLFacePickColorBufferObject() > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_face_pick_color_buffer);
      glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
      glEnableClientState(GL_COLOR_ARRAY);
    }
  }
  else if (draw_flags[R3_VERTEX_COLORS_DRAW_FLAG]) {
    if (GLFaceRgbColorBufferObject() > 0) {
      glBindBuffer(GL_ARRAY_BUFFER, vbo_face_rgb_color_buffer);
      glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
      glEnableClientState(GL_COLOR_ARRAY);
    }
  }
  
  // Draw vertices
  glDrawArrays(GL_TRIANGLES, 0, 3 * NFaces());

  // Reset everything
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
}

// Assembly:
subq $0x28, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, (%rsp)
movq (%rdi), %rax
callq *0x240(%rax)
cmpl $0x0, %eax
ja 0x23e8a
jmp 0x240a8
movq (%rsp), %rcx
movq 0x14b12b(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x50(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x3, %edi
movl $0x1406, %esi           # imm = 0x1406
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xf4f0
movl $0x8074, %edi           # imm = 0x8074
callq 0xf2f0
leaq 0x20(%rsp), %rdi
callq 0x13de0
andq $0x20, %rax
cmpq $0x0, %rax
je 0x23f1b
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x248(%rax)
cmpl $0x0, %eax
jbe 0x23f19
movq (%rsp), %rcx
movq 0x14b0ce(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x54(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x1406, %edi           # imm = 0x1406
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xf870
movl $0x8075, %edi           # imm = 0x8075
callq 0xf2f0
jmp 0x23f1b
leaq 0x20(%rsp), %rdi
callq 0x13de0
andq $0x30, %rax
cmpq $0x0, %rax
je 0x23f7a
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x250(%rax)
cmpl $0x0, %eax
jbe 0x23f78
movq (%rsp), %rcx
movq 0x14b074(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x58(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x2, %edi
movl $0x1406, %esi           # imm = 0x1406
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xf9b0
movl $0x8078, %edi           # imm = 0x8078
callq 0xf2f0
jmp 0x23f7a
leaq 0x10(%rsp), %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x13d80
movq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x23fe8
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x260(%rax)
cmpl $0x0, %eax
jbe 0x23fe6
movq (%rsp), %rcx
movq 0x14b006(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x60(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x4, %edi
movl $0x1401, %esi           # imm = 0x1401
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xf4e0
movl $0x8076, %edi           # imm = 0x8076
callq 0xf2f0
jmp 0x24058
leaq 0x8(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x13d80
movq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x24056
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x258(%rax)
cmpl $0x0, %eax
jbe 0x24054
movq (%rsp), %rcx
movq 0x14af98(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x5c(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x4, %edi
movl $0x1401, %esi           # imm = 0x1401
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xf4e0
movl $0x8076, %edi           # imm = 0x8076
callq 0xf2f0
jmp 0x24056
jmp 0x24058
movq (%rsp), %rdi
callq 0x135a0
imull $0x3, %eax, %edx
movl $0x4, %edi
xorl %esi, %esi
callq 0xf060
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
movq 0x14af42(%rip), %rax    # 0x16efc0
callq *(%rax)
movl $0x8074, %edi           # imm = 0x8074
callq 0xf2c0
movl $0x8075, %edi           # imm = 0x8075
callq 0xf2c0
movl $0x8078, %edi           # imm = 0x8078
callq 0xf2c0
movl $0x8076, %edi           # imm = 0x8076
callq 0xf2c0
addq $0x28, %rsp
retq
nopl (%rax)