// File: /workspace/github_cpp_makefile_star2_O3/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 0x4bf98b(%rip), %rsi    # 0x5352a0
callq 0x4dbc7
testl %eax, %eax
jne 0x75c46
movl 0x238(%rbx), %esi
testl %esi, %esi
jg 0x75a4e
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 0x7599b
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 0x75981
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 0xbaf99(%rip), %rax     # 0x1309f8
addq $0x10, %rax
leaq 0x70(%rsp), %r14
movq %rax, -0x8(%r14)
leaq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x7233e
leaq 0xf0(%rsp), %rdi
leaq 0xa8(%rbx), %rsi
callq 0x7233e
movq 0x128(%rbx), %rax
movq %rax, 0x170(%rsp)
movq %r14, %rdi
callq 0x72b80
leaq 0x68(%rsp), %rdi
callq 0x43ab6
movl $0xde1, %edi            # imm = 0xDE1
callq 0x13480
movss 0x69edd(%rip), %xmm0    # 0xdf99c
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 0xa2542
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 0xa2542
addq $0x130, %rbx            # imm = 0x130
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x97fd0
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x97fd0
movq %rsp, %rdi
leaq 0x58(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x9f766
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0x139c0
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x13390
movsd 0x675a9(%rip), %xmm0    # 0xdd148
xorpd %xmm1, %xmm1
callq 0x139c0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
callq 0x13390
movsd 0x67587(%rip), %xmm0    # 0xdd148
movaps %xmm0, %xmm1
callq 0x139c0
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x13390
movsd 0x67566(%rip), %xmm1    # 0xdd148
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 0x43af2
movq %rsp, %rdi
callq 0xa00b0
leaq 0x68(%rsp), %rdi
callq 0x700a8
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x7073c
jmp 0x75c7f
jmp 0x75c65
movq %rax, %rbx
jmp 0x75c75
movq %rax, %rbx
movq %rsp, %rdi
callq 0xa00b0
leaq 0x68(%rsp), %rdi
callq 0x700a8
movq %rbx, %rdi
callq 0x138b0
nop