// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::GLFaceRgbColorBufferObject() const
unsigned int R3Mesh::
GLFaceRgbColorBufferObject(void) const
{
  // Check if nothing to be done
  if (NFaces() == 0) return 0;

  // Update rgb color buffer
  if (vbo_face_rgb_color_buffer == 0) {
    glGenBuffers(1, (GLuint *) &vbo_face_rgb_color_buffer);
    if (vbo_face_rgb_color_buffer > 0) {
      std::vector<GLubyte> rgb_colors;
      for (int i = 0; i < NFaces(); i++) {
        R3MeshFace *face = Face(i);
        for (int j = 0; j < 3; j++){
          R3MeshVertex *vertex = VertexOnFace(face, j);
          const RNRgb& rgb_color = VertexColor(vertex);
          rgb_colors.push_back(255.0 * rgb_color.R());
          rgb_colors.push_back(255.0 * rgb_color.G());
          rgb_colors.push_back(255.0 * rgb_color.B());
          rgb_colors.push_back(255);
        }
      }
      glBindBuffer(GL_ARRAY_BUFFER, vbo_face_rgb_color_buffer);
      glBufferData(GL_ARRAY_BUFFER, rgb_colors.size() * sizeof(GLubyte), &rgb_colors[0], GL_STATIC_DRAW);
      glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
  }

  // Return rgb color buffer identifier
  return vbo_face_rgb_color_buffer;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x135a0
cmpl $0x0, %eax
jne 0x228f6
movl $0x0, 0xc4(%rsp)
jmp 0x22bb6
movq 0x58(%rsp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x22ba7
movq 0x58(%rsp), %rsi
movq 0x14c697(%rip), %rax    # 0x16efa8
movq (%rax), %rax
addq $0x5c, %rsi
movl $0x1, %edi
callq *%rax
movq 0x58(%rsp), %rax
cmpl $0x0, 0x5c(%rax)
jbe 0x22ba5
leaq 0xa0(%rsp), %rdi
callq 0x38c70
movl $0x0, 0x9c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x9c(%rsp), %eax
movl %eax, 0x50(%rsp)
callq 0x135a0
movl %eax, 0x54(%rsp)
jmp 0x22961
movl 0x50(%rsp), %eax
movl 0x54(%rsp), %ecx
cmpl %ecx, %eax
jge 0x22b19
movq 0x58(%rsp), %rdi
movl 0x9c(%rsp), %esi
callq 0x136d0
movq %rax, 0x48(%rsp)
jmp 0x22989
movq 0x48(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
cmpl $0x3, 0x7c(%rsp)
jge 0x22b01
movq 0x58(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl 0x7c(%rsp), %edx
callq 0x13700
movq %rax, 0x40(%rsp)
jmp 0x229c6
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
callq 0x368d0
movq %rax, 0x38(%rsp)
jmp 0x229e6
movq 0x38(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x38cb0
movsd %xmm0, 0x30(%rsp)
jmp 0x22a02
movsd 0x30(%rsp), %xmm0
movsd 0x110810(%rip), %xmm1   # 0x133220
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x67(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x67(%rsp), %rsi
callq 0x38c80
jmp 0x22a30
movq 0x68(%rsp), %rdi
callq 0x38cc0
movsd %xmm0, 0x28(%rsp)
jmp 0x22a42
movsd 0x28(%rsp), %xmm0
movsd 0x1107d0(%rip), %xmm1   # 0x133220
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x66(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x66(%rsp), %rsi
callq 0x38c80
jmp 0x22a70
movq 0x68(%rsp), %rdi
callq 0x38cd0
movsd %xmm0, 0x20(%rsp)
jmp 0x22a82
movsd 0x20(%rsp), %xmm0
movsd 0x110790(%rip), %xmm1   # 0x133220
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x65(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x65(%rsp), %rsi
callq 0x38c80
jmp 0x22ab0
movb $-0x1, 0x64(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x64(%rsp), %rsi
callq 0x38c80
jmp 0x22ac9
jmp 0x22acb
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x2299e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x38d20
jmp 0x22bc5
jmp 0x22b03
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x22946
movq 0x58(%rsp), %rcx
movq 0x14c49b(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x5c(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
jmp 0x22b34
movq 0x14c495(%rip), %rax    # 0x16efd0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0xa0(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x38ce0
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x38d00
movq 0x10(%rsp), %rsi
movq %rax, %rdx
movq 0x18(%rsp), %rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
jmp 0x22b83
movq 0x14c436(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *%rax
jmp 0x22b98
leaq 0xa0(%rsp), %rdi
callq 0x38d20
jmp 0x22ba7
movq 0x58(%rsp), %rax
movl 0x5c(%rax), %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
addq $0xc8, %rsp
retq
movq 0x90(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)