// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::UpdateOpenGL()
void RGBDSurface::
UpdateOpenGL(void) 
{
  // Check identifier
  if (opengl_texture_id > 0) return;
  
  // Create identifier
  GLuint identifier;
  glGenTextures(1, &identifier);

  // Allocate pixels
  unsigned char *pixels = new unsigned char [ width * height * 4];

  // Fill pixels
  unsigned char *pixelsp = pixels;
  for (int iy = 0; iy < height; iy++) {
    for (int ix = 0; ix < width; ix++) {
      RNRgb color = TexelColor(ix, iy);
      *pixelsp++ = (color.R() < 1.0) ? color.R() * 255 : 255;
      *pixelsp++ = (color.G() < 1.0) ? color.G() * 255 : 255;
      *pixelsp++ = (color.B() < 1.0) ? color.B() * 255 : 255;
      *pixelsp++ = 255;
    }
  }

  // Define texture
  glBindTexture(GL_TEXTURE_2D, identifier);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
    0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

  // Delete the pixels
  delete [] pixels;

  //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  // gluBuild2DMipmaps(GL_TEXTURE_2D, 3, rgb_image.Width(), rgb_image.Height(),
  //   GL_RGB, GL_UNSIGNED_BYTE, (const unsigned char *) rgb_image.Pixels());
 
  // Remember identifier
  opengl_texture_id = identifier;
}

// Assembly:
cmpl $0x0, 0x30(%rdi)
jle 0x1b1cb
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
pushq $0x1
popq %rdi
leaq 0x4(%rsp), %rsi
callq 0x11840
movl 0x28(%rbx), %r15d
movl 0x2c(%rbx), %r12d
movl %r15d, %eax
imull %r12d, %eax
shll $0x2, %eax
movslq %eax, %rdi
callq 0x11040
movq %rax, %r14
xorl %ebp, %ebp
movl $0xff, %r13d
movq %rax, 0x8(%rsp)
cmpl %r12d, %ebp
jge 0x1b2b7
xorl %r12d, %r12d
cmpl %r15d, %r12d
jge 0x1b2ac
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x19f90
movsd 0x10(%rsp), %xmm0
movsd 0x8cde0(%rip), %xmm1    # 0xa8028
ucomisd %xmm0, %xmm1
movsd 0x8dbc4(%rip), %xmm2    # 0xa8e18
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cmovbel %r13d, %eax
movsd 0x18(%rsp), %xmm0
ucomisd %xmm0, %xmm1
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %ecx
cmovbel %r13d, %ecx
movb %al, (%r14)
movsd 0x20(%rsp), %xmm0
ucomisd %xmm0, %xmm1
movb %cl, 0x1(%r14)
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cmovbel %r13d, %eax
movb %al, 0x2(%r14)
movb $-0x1, 0x3(%r14)
addq $0x4, %r14
incl %r12d
movl 0x28(%rbx), %r15d
jmp 0x1b21f
incl %ebp
movl 0x2c(%rbx), %r12d
jmp 0x1b213
movl 0x4(%rsp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x11750
pushq $0x4
popq %rsi
movl $0xcf5, %edi            # imm = 0xCF5
callq 0x112d0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x812f, %edx           # imm = 0x812F
callq 0x11820
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x812f, %edx           # imm = 0x812F
callq 0x11820
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
callq 0x11820
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
callq 0x11820
movl $0x2300, %edi           # imm = 0x2300
movl $0x2200, %esi           # imm = 0x2200
movl $0x2100, %edx           # imm = 0x2100
callq 0x11670
movl 0x28(%rbx), %ecx
movl 0x2c(%rbx), %r8d
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
xorl %r9d, %r9d
movq 0x10(%rsp), %r14
pushq %r14
pushq $0x1401                 # imm = 0x1401
pushq $0x1908                 # imm = 0x1908
callq 0x11220
addq $0x20, %rsp
movq %r14, %rdi
callq 0x117a0
movl 0x4(%rsp), %eax
movl %eax, 0x30(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq