// File: /workspace/github_c_makefile_star2_O0/FredTheDino[P]Fog/src/engine/renderer/opengl_renderer.cpp
// Function: Renderer::Impl::upload_texture(Image*, int)
FOG_EXPORT
u32 upload_texture(Image *image, s32 index) {
    ASSERT(0 <= index && index <= OPENGL_TEXTURE_DEPTH, "Invalid index.");
    ASSERT(0 < image->components && image->components < 5,
           "Invalid number of components");
    u32 data_format;
    switch (image->components) {
        case (1):
            data_format = GL_RED;
            break;
        case (2):
            data_format = GL_RG;
            break;
        case (3):
            data_format = GL_RGB;
            break;
        case (4):
            data_format = GL_RGBA;
            break;
        default:
            UNREACHABLE;
            return 0;
    }
#if FOG_VERBOSE // A verbose warning, usually just noise.
    CHECK(image->width == OPENGL_TEXTURE_WIDTH &&
              image->height == OPENGL_TEXTURE_HEIGHT,
          "Not using the entire texture 'slice'.");
#endif
    glBindTexture(GL_TEXTURE_2D_ARRAY, sprite_texture_array);
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, index, image->width,
                    image->height, 1, data_format, GL_UNSIGNED_BYTE, image->data);
    return index;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl -0x1c(%rbp), %ecx
movb %al, -0x21(%rbp)
jg 0x2cce9
cmpl $0x100, -0x1c(%rbp)     # imm = 0x100
setle %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
leaq 0x19345(%rip), %rdi     # 0x46045
movl $0x1f3, %esi            # imm = 0x1F3
leaq 0x19412(%rip), %rdx     # 0x4611e
movzbl %al, %ecx
callq 0xb210
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %edx
xorl %eax, %eax
xorl %ecx, %ecx
cmpl %edx, %ecx
movb %al, -0x22(%rbp)
jge 0x2cd38
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x5, %eax
setl %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
movzbl %al, %ecx
andl $0x1, %ecx
leaq 0x192fd(%rip), %rdi     # 0x46045
leaq 0x193fa(%rip), %rdx     # 0x46149
movl $0x1f5, %esi            # imm = 0x1F5
callq 0xb210
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x3, %eax
ja 0x2cda6
movq -0x30(%rbp), %rax
leaq 0x186f7(%rip), %rcx     # 0x45470
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1903, -0x20(%rbp)    # imm = 0x1903
jmp 0x2cde7
movl $0x8227, -0x20(%rbp)    # imm = 0x8227
jmp 0x2cde7
movl $0x1907, -0x20(%rbp)    # imm = 0x1907
jmp 0x2cde7
movl $0x1908, -0x20(%rbp)    # imm = 0x1908
jmp 0x2cde7
movq 0x3c233(%rip), %rax     # 0x68fe0
movq (%rax), %rsi
leaq 0x18d8a(%rip), %rdi     # 0x45b41
leaq 0x19287(%rip), %rdx     # 0x46045
movl $0x205, %ecx            # imm = 0x205
leaq 0x193cc(%rip), %r8      # 0x46196
leaq 0x18d9d(%rip), %r9      # 0x45b6e
movb $0x0, %al
callq 0xb100
callq 0xb1f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2330
leaq 0x51cf2(%rip), %rax     # 0x7eae0
movq (%rax), %rax
leaq 0x58438(%rip), %rcx     # 0x85230
movl (%rcx), %esi
movl $0x8c1a, %edi           # imm = 0x8C1A
callq *%rax
leaq 0x52cb0(%rip), %rax     # 0x7fab8
movq (%rax), %rax
movl -0x1c(%rbp), %r8d
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %r9d
movq -0x18(%rbp), %rcx
movl 0xc(%rcx), %ebx
movl -0x20(%rbp), %r11d
movq -0x18(%rbp), %rcx
movq (%rcx), %r10
movl $0x8c1a, %edi           # imm = 0x8C1A
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
movl %ebx, (%rsp)
movl $0x1, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl $0x1401, 0x18(%rsp)     # imm = 0x1401
movq %r10, 0x20(%rsp)
callq *%rax
movl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)