// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::GLVertexNormalBufferObject() const
unsigned int R3Mesh::
GLVertexNormalBufferObject(void) const
{
  // Check if nothing to be done
  if (NVertices() == 0) return 0;
  
  // Update normal buffer
  if (vbo_vertex_normal_buffer == 0) {
    glGenBuffers(1, (GLuint *) &vbo_vertex_normal_buffer);
    if (vbo_vertex_normal_buffer > 0) {
      std::vector<GLfloat> normals;
      for (int i = 0; i < NVertices(); i++) {
        R3MeshVertex *vertex = Vertex(i);
        const R3Vector& normal = VertexNormal(vertex);
        normals.push_back(normal.X());
        normals.push_back(normal.Y());
        normals.push_back(normal.Z());
      }
      glBindBuffer(GL_ARRAY_BUFFER, vbo_vertex_normal_buffer);
      glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(GLfloat), &normals[0], GL_STATIC_DRAW);
      glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
  }

  // Return normal buffer identifier
  return vbo_vertex_normal_buffer;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x135e0
cmpl $0x0, %eax
jne 0x23096
movl $0x0, 0xb4(%rsp)
jmp 0x232d1
movq 0x50(%rsp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x232c2
movq 0x50(%rsp), %rsi
movq 0x14bef7(%rip), %rax    # 0x16efa8
movq (%rax), %rax
addq $0x68, %rsi
movl $0x1, %edi
callq *%rax
movq 0x50(%rsp), %rax
cmpl $0x0, 0x68(%rax)
jbe 0x232c0
leaq 0x90(%rsp), %rdi
callq 0x38b40
movl $0x0, 0x8c(%rsp)
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x48(%rsp)
callq 0x135e0
movl %eax, 0x4c(%rsp)
jmp 0x23101
movl 0x48(%rsp), %eax
movl 0x4c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x23230
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %esi
callq 0x13630
movq %rax, 0x40(%rsp)
jmp 0x23129
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
callq 0x36860
movq %rax, 0x38(%rsp)
jmp 0x23149
movq 0x38(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x38c20
movsd %xmm0, 0x30(%rsp)
jmp 0x23165
movsd 0x30(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x64(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x64(%rsp), %rsi
callq 0x38b50
jmp 0x23189
movq 0x68(%rsp), %rdi
callq 0x38c30
movsd %xmm0, 0x28(%rsp)
jmp 0x2319b
movsd 0x28(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x60(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x38b50
jmp 0x231bf
movq 0x68(%rsp), %rdi
callq 0x38c40
movsd %xmm0, 0x20(%rsp)
jmp 0x231d1
movsd 0x20(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x5c(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
callq 0x38b50
jmp 0x231f5
jmp 0x231f7
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x230e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x38bc0
jmp 0x232e0
movq 0x50(%rsp), %rcx
movq 0x14bd84(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl 0x68(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
jmp 0x2324b
movq 0x14bd7e(%rip), %rax    # 0x16efd0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x38b80
movq 0x8(%rsp), %rdi
shlq $0x2, %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x38ba0
movq 0x10(%rsp), %rsi
movq %rax, %rdx
movq 0x18(%rsp), %rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
jmp 0x2329e
movq 0x14bd1b(%rip), %rax    # 0x16efc0
movq (%rax), %rax
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *%rax
jmp 0x232b3
leaq 0x90(%rsp), %rdi
callq 0x38bc0
jmp 0x232c2
movq 0x50(%rsp), %rax
movl 0x68(%rax), %eax
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
movq 0x80(%rsp), %rdi
callq 0xf890
nopl (%rax)