// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Graphics/R2Texture.cpp
// Function: gaps::R2Texture::Load() const
void R2Texture::
Load(void) const
{
  // Check if needs to be loaded
  if (id >= 0) return;
  assert(image);

  // Create texture id
  GLuint i;
  glGenTextures(1, &i);
  ((R2Texture *) this)->id = i;
  assert(id > 0);

  // Begin texture definition
  glBindTexture(GL_TEXTURE_2D, id);

  // Define texture parameters
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, s_wrap);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, t_wrap);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, blend);

  // Determine texture format
  GLenum format = GL_RGB;
  if (image->Depth() == 1) format = GL_LUMINANCE;
  else if (image->Depth() == 2) format = GL_LUMINANCE_ALPHA;
  else if (image->Depth() == 3) format = GL_RGB;
  else if (image->Depth() == 4) format = GL_RGBA;
  else RNAbort("Illegal texture image");

#ifdef AT_ONE_POINT_THIS_WAS_NEEDED_FOR_MESA
  // For some reason, gluBuild2DMipmaps segfaults in mesa
  glTexImage2D(GL_TEXTURE_2D, 0, format, image->Width(), image->Height(),
    0, format, GL_UNSIGNED_BYTE, (const unsigned char *) image->Pixels());
#else
  // Define texture
  if ((min_filter == R2_NEAREST_MIPMAP_NEAREST_TEXTURE_FILTER) ||
      (min_filter == R2_NEAREST_MIPMAP_LINEAR_TEXTURE_FILTER) ||
      (min_filter == R2_LINEAR_MIPMAP_NEAREST_TEXTURE_FILTER) ||
      (min_filter == R2_LINEAR_MIPMAP_LINEAR_TEXTURE_FILTER)) {
    gluBuild2DMipmaps(GL_TEXTURE_2D, format, image->Width(), image->Height(),
      format, GL_UNSIGNED_BYTE, (const unsigned char *) image->Pixels());
  }
  else {
    glTexImage2D(GL_TEXTURE_2D, 0, format, image->Width(), image->Height(),
      0, format, GL_UNSIGNED_BYTE, (const unsigned char *) image->Pixels());
  }
#endif

  // End texture definition
  glBindTexture(GL_TEXTURE_2D, 0);
}

// Assembly:
cmpl $0x0, 0x48(%rdi)
js 0x44d37
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x4(%rsp), %r14
movl $0x1, %edi
movq %r14, %rsi
callq 0x21ce0
movl (%r14), %esi
movl %esi, 0x48(%rbx)
movl $0xde1, %edi            # imm = 0xDE1
callq 0x21b70
movl 0x28(%rbx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
callq 0x21ca0
movl 0x2c(%rbx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
callq 0x21ca0
movl 0x30(%rbx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
callq 0x21ca0
movl 0x34(%rbx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
callq 0x21ca0
movl 0x38(%rbx), %edx
movl $0x2300, %edi           # imm = 0x2300
movl $0x2200, %esi           # imm = 0x2200
callq 0x219d0
movq 0x20(%rbx), %rax
movl 0x8(%rax), %eax
decl %eax
cmpl $0x4, %eax
jae 0x44dd6
movl %eax, %eax
leaq 0x9705f(%rip), %rcx     # 0xdbe30
movl (%rcx,%rax,4), %eax
jmp 0x44de9
leaq 0x97067(%rip), %rdi     # 0xdbe44
xorl %eax, %eax
callq 0x8a022
movl $0x1907, %eax           # imm = 0x1907
movl 0x30(%rbx), %edx
andl $-0x4, %edx
movq 0x20(%rbx), %rsi
movl (%rsi), %ecx
movl 0x4(%rsi), %r8d
movq 0x10(%rsi), %r10
subq $0x8, %rsp
cmpl $0x2700, %edx           # imm = 0x2700
jne 0x44e2b
movl $0xde1, %edi            # imm = 0xDE1
movl %eax, %esi
movl %ecx, %edx
movl %r8d, %ecx
movl %eax, %r8d
movl $0x1401, %r9d           # imm = 0x1401
pushq %r10
callq 0x21500
addq $0x10, %rsp
jmp 0x44e48
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl %eax, %edx
xorl %r9d, %r9d
pushq %r10
pushq $0x1401                 # imm = 0x1401
pushq %rax
callq 0x21340
addq $0x20, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
callq 0x21b70
addq $0x8, %rsp
popq %rbx
popq %r14
retq