// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::UpdateSelectedImageTexture()
void R3SurfelViewer::
UpdateSelectedImageTexture(void)
{
  // Check stuff
  if (!selected_image) return;
  if (selected_image == previous_texture_image) return;

  // Get color image
  UpdateSelectedImageColorPixels();
  if (selected_image_color_pixels.Width() <= 0) return;
  if (selected_image_color_pixels.Height() <= 0) return;
  if (selected_image_color_pixels.Depth() != 3) return;

  // Generate a texture id
  if (selected_image_texture_id == 0) {
    glGenTextures(1, &selected_image_texture_id);
    if (selected_image_texture_id <= 0) return;
  }

  // Load texture
  if (selected_image_texture_id > 0) {
    glBindTexture(GL_TEXTURE_2D, selected_image_texture_id);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    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_MAG_FILTER, GL_LINEAR);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, selected_image_color_pixels.Width(), selected_image_color_pixels.Height(), 0, GL_RGB, GL_UNSIGNED_BYTE, selected_image_color_pixels.Pixels() );
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, selected_image_color_pixels.Width(), selected_image_color_pixels.Height(), GL_RGB, GL_UNSIGNED_BYTE, selected_image_color_pixels.Pixels());
  }

  // Remember last selected image
  previous_texture_image = selected_image;
}

// Assembly:
movq 0x2d0(%rdi), %rax
testq %rax, %rax
je 0x2e0fb
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpq 0x5f0(%rdi), %rax
je 0x2e0f4
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x258(%rax)
cmpl $0x0, 0x5c8(%rbx)
jle 0x2e0f4
cmpl $0x0, 0x5cc(%rbx)
jle 0x2e0f4
cmpl $0x3, 0x5d0(%rbx)
jne 0x2e0f4
movl 0x5e8(%rbx), %esi
testl %esi, %esi
jne 0x2e046
leaq 0x5e8(%rbx), %r14
movl $0x1, %edi
movq %r14, %rsi
callq 0x27d40
movl (%r14), %esi
testl %esi, %esi
je 0x2e0f4
movl $0xde1, %edi            # imm = 0xDE1
callq 0x27bc0
movl $0x2300, %edi           # imm = 0x2300
movl $0x2200, %esi           # imm = 0x2200
movl $0x2100, %edx           # imm = 0x2100
callq 0x27a20
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2900, %edx           # imm = 0x2900
callq 0x27d00
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2900, %edx           # imm = 0x2900
callq 0x27d00
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x27d00
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2703, %edx           # imm = 0x2703
callq 0x27d00
movl 0x5c8(%rbx), %edx
movl 0x5cc(%rbx), %ecx
movq 0x5d8(%rbx), %rax
movq %rax, (%rsp)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x3, %esi
movl $0x1907, %r8d           # imm = 0x1907
movl $0x1401, %r9d           # imm = 0x1401
callq 0x27520
movq 0x2d0(%rbx), %rax
movq %rax, 0x5f0(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq