// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3PlanarGrid.cpp
// Function: gaps::R3PlanarGrid::Draw() const
void R3PlanarGrid::
Draw(void) const
{
  // Just checking
  if (R3Contains(plane, R3null_plane)) return;

  // Define texture
  if (texture_id <= 0) {
    // Create texture id
    GLuint i;
    glGenTextures(1, &i);
    ((R3PlanarGrid *) this)->texture_id = i;
    assert(texture_id > 0);

    // Create texture pixels
    float *pixels = new float [ 4 * grid.NEntries() ];
    for (int i = 0; i < grid.NEntries(); i++) {
      pixels[4*i + 0] = grid.GridValue(i);
      pixels[4*i + 1] = grid.GridValue(i);
      pixels[4*i + 2] = grid.GridValue(i);
      pixels[4*i + 3] = grid.GridValue(i);
    }

    // Begin texture definition
    glBindTexture(GL_TEXTURE_2D, texture_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, grid.XResolution(), grid.YResolution(), 0, GL_RGBA, GL_FLOAT, pixels);

    // Delete texture pixels
    delete [] pixels;
  }

  // Set texture
  glBindTexture(GL_TEXTURE_2D, texture_id);

  // Push transformation
  R3Affine inverse(transformation);
  inverse.Invert();
  inverse.Push();

  // Set rendering modes
  glEnable(GL_TEXTURE_2D);
  glAlphaFunc(GL_GREATER, 0.1);
  glEnable(GL_ALPHA_TEST);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
  glDisable(GL_CULL_FACE);

  // Draw polygon
  R3BeginPolygon();
  const R2Box& bbox = grid.WorldBox();
  R3LoadTextureCoords(0.0, 0.0);  R2LoadPoint(bbox[0][0], bbox[0][1]);
  R3LoadTextureCoords(1.0, 0.0);  R2LoadPoint(bbox[1][0], bbox[0][1]);
  R3LoadTextureCoords(1.0, 1.0);  R2LoadPoint(bbox[1][0], bbox[1][1]);
  R3LoadTextureCoords(0.0, 1.0);  R2LoadPoint(bbox[0][0], bbox[1][1]);
  R3EndPolygon();

  // Reset rendering modes
  glEnable(GL_CULL_FACE);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  glDisable(GL_ALPHA_TEST);
  glDisable(GL_TEXTURE_2D);

  // Pop transformation
  inverse.Pop();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
leaq 0x4bfbc5(%rip), %rsi    # 0x5362a0
callq 0x4e367
testl %eax, %eax
jne 0x76a0b
cmpl $0x0, 0x238(%rbx)
jg 0x7680d
leaq 0x68(%rsp), %r14
movl $0x1, %edi
movq %r14, %rsi
callq 0x13700
movl (%r14), %ebp
movl %ebp, 0x238(%rbx)
movslq 0x1fc(%rbx), %r15
movq %r15, %rax
shlq $0x4, %rax
testq %r15, %r15
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x13030
movq %rax, %r14
testq %r15, %r15
jle 0x76760
movq 0x1e8(%rbx), %rax
shlq $0x3, %r15
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsd2ss (%rax,%rcx), %xmm0
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movups %xmm0, (%r14,%rcx,2)
addq $0x8, %rcx
cmpq %rcx, %r15
jne 0x76746
movl $0xde1, %edi            # imm = 0xDE1
movl %ebp, %esi
callq 0x13620
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2900, %edx           # imm = 0x2900
callq 0x136e0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2900, %edx           # imm = 0x2900
callq 0x136e0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2601, %edx           # imm = 0x2601
callq 0x136e0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x136e0
movl $0x2300, %edi           # imm = 0x2300
movl $0x2200, %esi           # imm = 0x2200
movl $0x2100, %edx           # imm = 0x2100
callq 0x13580
movl 0x1f0(%rbx), %ecx
movl 0x1f4(%rbx), %r8d
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
xorl %r9d, %r9d
pushq %r14
pushq $0x1406                 # imm = 0x1406
pushq $0x1908                 # imm = 0x1908
callq 0x131e0
addq $0x20, %rsp
movq %r14, %rdi
callq 0x13680
movl 0x238(%rbx), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x13620
leaq 0xbb1d4(%rip), %rax     # 0x1319f8
addq $0x10, %rax
leaq 0x70(%rsp), %r14
movq %rax, -0x8(%r14)
leaq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x73052
leaq 0xf0(%rsp), %rdi
leaq 0xa8(%rbx), %rsi
callq 0x73052
movq 0x128(%rbx), %rax
movq %rax, 0x170(%rsp)
movq %r14, %rdi
callq 0x73894
leaq 0x68(%rsp), %rdi
callq 0x43e4e
movl $0xde1, %edi            # imm = 0xDE1
callq 0x13480
movss 0x6a120(%rip), %xmm0    # 0xe09a4
movl $0x204, %edi            # imm = 0x204
callq 0x13120
movl $0xbc0, %edi            # imm = 0xBC0
callq 0x13480
movl $0xb52, %edi            # imm = 0xB52
movl $0x1, %esi
callq 0x130f0
movl $0xb44, %edi            # imm = 0xB44
callq 0x13160
movl $0x9, %edi
callq 0x13130
leaq 0x38(%rsp), %rdi
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0xa3776
movl 0x1f0(%rbx), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0x1f4(%rbx), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
leaq 0x28(%rsp), %rdi
callq 0xa3776
addq $0x130, %rbx            # imm = 0x130
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x99214
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x99214
movq %rsp, %rdi
leaq 0x58(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xa0992
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0x139c0
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x13390
movsd 0x677ec(%rip), %xmm0    # 0xde150
xorpd %xmm1, %xmm1
callq 0x139c0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x13390
movsd 0x677ca(%rip), %xmm0    # 0xde150
movaps %xmm0, %xmm1
callq 0x139c0
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x13390
movsd 0x677a9(%rip), %xmm1    # 0xde150
xorps %xmm0, %xmm0
callq 0x139c0
movsd 0x8(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x13390
callq 0x136a0
movl $0xb44, %edi            # imm = 0xB44
callq 0x13480
movl $0xb52, %edi            # imm = 0xB52
xorl %esi, %esi
callq 0x130f0
movl $0xbc0, %edi            # imm = 0xBC0
callq 0x13160
movl $0xde1, %edi            # imm = 0xDE1
callq 0x13160
leaq 0x68(%rsp), %rdi
callq 0x43e8a
movq %rsp, %rdi
callq 0xa12e4
leaq 0x68(%rsp), %rdi
callq 0x70d14
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x7139c
jmp 0x76a44
jmp 0x76a2a
movq %rax, %rbx
jmp 0x76a3a
movq %rax, %rbx
movq %rsp, %rdi
callq 0xa12e4
leaq 0x68(%rsp), %rdi
callq 0x70d14
movq %rbx, %rdi
callq 0x138b0