// File: 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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x2d0(%rax)
jne 0x32452
jmp 0x32604
movq 0x18(%rsp), %rcx
movq 0x2d0(%rcx), %rax
cmpq 0x5f0(%rcx), %rax
jne 0x3246c
jmp 0x32604
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x258(%rax)
movq 0x18(%rsp), %rdi
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3de90
cmpl $0x0, %eax
jg 0x32495
jmp 0x32604
movq 0x18(%rsp), %rdi
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3dea0
cmpl $0x0, %eax
jg 0x324b0
jmp 0x32604
movq 0x18(%rsp), %rdi
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3deb0
cmpl $0x3, %eax
je 0x324cb
jmp 0x32604
movq 0x18(%rsp), %rax
cmpl $0x0, 0x5e8(%rax)
jne 0x32504
movq 0x18(%rsp), %rsi
addq $0x5e8, %rsi            # imm = 0x5E8
movl $0x1, %edi
callq 0x28ee0
movq 0x18(%rsp), %rax
cmpl $0x0, 0x5e8(%rax)
ja 0x32502
jmp 0x32604
jmp 0x32504
movq 0x18(%rsp), %rax
cmpl $0x0, 0x5e8(%rax)
jbe 0x325f1
movq 0x18(%rsp), %rax
movl 0x5e8(%rax), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x28d30
movl $0x2300, %edi           # imm = 0x2300
movl $0x2200, %esi           # imm = 0x2200
movl $0x2100, %edx           # imm = 0x2100
callq 0x28b80
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2900, %edx           # imm = 0x2900
callq 0x28ea0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2900, %edx           # imm = 0x2900
callq 0x28ea0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x28ea0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2703, %edx           # imm = 0x2703
callq 0x28ea0
movq 0x18(%rsp), %rdi
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3de90
movq 0x18(%rsp), %rdi
movl %eax, 0x10(%rsp)
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3dea0
movq 0x18(%rsp), %rdi
movl %eax, 0x14(%rsp)
addq $0x5c8, %rdi            # imm = 0x5C8
callq 0x3dec0
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x3, %esi
movl $0x1907, %r8d           # imm = 0x1907
movl $0x1401, %r9d           # imm = 0x1401
movq %rax, (%rsp)
callq 0x285a0
movq 0x18(%rsp), %rax
movq 0x2d0(%rax), %rcx
movq %rcx, 0x5f0(%rax)
addq $0x28, %rsp
retq
nopl (%rax)