// File: /workspace/github_c_makefile_star2_O2/FredTheDino[P]Fog/src/engine/renderer/opengl_renderer.cpp
// Function: Renderer::Impl::create_frame_buffers(int, int)
void create_frame_buffers(int width, int height) {
    glGenTextures(OPENGL_NUM_CAMERAS, (GLuint *) &screen_textures);
    glGenFramebuffers(OPENGL_NUM_CAMERAS, (GLuint *) &screen_fbos);
    glGenRenderbuffers(OPENGL_NUM_CAMERAS, (GLuint *) &screen_rbos);
    for (u32 cam = 0; cam < OPENGL_NUM_CAMERAS; cam++) {
        GLuint fbo = screen_fbos[cam];
        GLuint rbo = screen_rbos[cam];
        GLuint texture = screen_textures[cam];

        glBindTexture(GL_TEXTURE_2D, texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
                GL_UNSIGNED_BYTE, NULL);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glBindTexture(GL_TEXTURE_2D, 0);

        glBindFramebuffer(GL_FRAMEBUFFER, fbo);
        {
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                    GL_TEXTURE_2D, texture, 0);

            glBindRenderbuffer(GL_RENDERBUFFER, rbo);
            {
                glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
                        width, height);
            }
            glBindRenderbuffer(GL_RENDERBUFFER, 0);

            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
                    GL_RENDERBUFFER, rbo);

            if (glCheckFramebufferStatus(fbo) != GL_FRAMEBUFFER_COMPLETE)
                ERR("Incomplete framebuffer");
        }
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    Vec4 quad_verticies[] = {
        V4(-1, -1, 0, 0),
        V4( 1, -1, 1, 0),
        V4( 1,  1, 1, 1),

        V4(-1, -1, 0, 0),
        V4( 1,  1, 1, 1),
        V4(-1,  1, 0, 1),
    };

    glGenVertexArrays(1, &screen_quad_vao);
    glBindVertexArray(screen_quad_vao);

    glGenBuffers(1, &screen_quad_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, screen_quad_vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(quad_verticies), &quad_verticies,
                 GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vec4),
                          (void *) offsetof(Vec4, x));
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vec4),
                          (void *) offsetof(Vec4, z));
    glBindVertexArray(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %esi, -0x2c(%rbp)
movl %edi, -0x30(%rbp)
leaq 0x416aa(%rip), %rax     # 0x5ffb8
leaq 0x478ff(%rip), %rsi     # 0x66214
pushq $0x2
popq %r15
movl %r15d, %edi
callq *(%rax)
leaq 0x41673(%rip), %rax     # 0x5ff98
leaq 0x478d8(%rip), %rsi     # 0x66204
movl %r15d, %edi
callq *(%rax)
leaq 0x41678(%rip), %rax     # 0x5ffb0
leaq 0x478cd(%rip), %rsi     # 0x6620c
movl %r15d, %edi
callq *(%rax)
xorl %ebx, %ebx
movl -0x30(%rbp), %r15d
cmpq $0x2, %rbx
je 0x1eace
leaq 0x478a9(%rip), %rax     # 0x66204
movl (%rax,%rbx,4), %eax
movl %eax, -0x34(%rbp)
leaq 0x478a4(%rip), %rax     # 0x6620c
movl (%rax,%rbx,4), %eax
movl %eax, -0x38(%rbp)
leaq 0x4789f(%rip), %rax     # 0x66214
movl (%rax,%rbx,4), %r13d
movl $0xde1, %edi            # imm = 0xDE1
movl %r13d, %esi
leaq 0x41128(%rip), %rax     # 0x5fab0
callq *(%rax)
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1907, %edx           # imm = 0x1907
movl %r15d, %ecx
movl -0x2c(%rbp), %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x1401                 # imm = 0x1401
pushq $0x1907                 # imm = 0x1907
leaq 0x42071(%rip), %rax     # 0x60a28
callq *(%rax)
addq $0x20, %rsp
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2601, %edx           # imm = 0x2601
leaq 0x42095(%rip), %r12     # 0x60a68
callq *(%r12)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq *(%r12)
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
leaq 0x410b8(%rip), %rax     # 0x5fab0
callq *(%rax)
movl $0x8d40, %edi           # imm = 0x8D40
movl -0x34(%rbp), %r12d
movl %r12d, %esi
leaq 0x41093(%rip), %rax     # 0x5faa0
callq *(%rax)
movl $0x8d40, %edi           # imm = 0x8D40
movl $0x8ce0, %esi           # imm = 0x8CE0
movl $0xde1, %edx            # imm = 0xDE1
movl %r13d, %ecx
xorl %r8d, %r8d
leaq 0x4153d(%rip), %rax     # 0x5ff68
callq *(%rax)
movl $0x8d41, %edi           # imm = 0x8D41
movl -0x38(%rbp), %r13d
movl %r13d, %esi
leaq 0x41068(%rip), %r14     # 0x5faa8
callq *(%r14)
movl $0x8d41, %edi           # imm = 0x8D41
movl $0x88f0, %esi           # imm = 0x88F0
movl %r15d, %edx
movl -0x2c(%rbp), %ecx
leaq 0x41d4e(%rip), %rax     # 0x607a8
callq *(%rax)
movl $0x8d41, %edi           # imm = 0x8D41
xorl %esi, %esi
callq *(%r14)
movl $0x8d40, %edi           # imm = 0x8D40
movl $0x821a, %esi           # imm = 0x821A
movl $0x8d41, %edx           # imm = 0x8D41
movl %r13d, %ecx
leaq 0x414d1(%rip), %rax     # 0x5ff50
callq *(%rax)
movl %r12d, %edi
leaq 0x4108d(%rip), %rax     # 0x5fb18
callq *(%rax)
cmpl $0x8cd5, %eax           # imm = 0x8CD5
je 0x1eac6
movq 0x2b535(%rip), %rax     # 0x49fd0
movq (%rax), %rsi
leaq 0xd1d2(%rip), %rdi      # 0x2bc77
leaq 0xd5a1(%rip), %rdx      # 0x2c04d
movl $0x11c, %ecx            # imm = 0x11C
leaq 0xd5bd(%rip), %r8       # 0x2c075
leaq 0xd5cb(%rip), %r9       # 0x2c08a
xorl %eax, %eax
callq 0x683a
incq %rbx
jmp 0x1e94a
movl $0x8d40, %edi           # imm = 0x8D40
xorl %esi, %esi
leaq 0x40fc4(%rip), %rax     # 0x5faa0
callq *(%rax)
movsd 0xcf5a(%rip), %xmm0     # 0x2ba40
leaq -0xa0(%rbp), %r14
movaps %xmm0, (%r14)
movsd 0xc787(%rip), %xmm1     # 0x2b280
movss 0xc503(%rip), %xmm2     # 0x2b004
movlhps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
movaps %xmm1, 0x10(%r14)
movaps 0xc780(%rip), %xmm1     # 0x2b290
shufps $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movaps %xmm1, 0x20(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm1, 0x40(%r14)
movaps 0xc776(%rip), %xmm0     # 0x2b2a0
movaps %xmm0, 0x50(%r14)
leaq 0x4148a(%rip), %rax     # 0x5ffc0
leaq 0x476df(%rip), %r15     # 0x6621c
pushq $0x1
popq %rbx
movl %ebx, %edi
movq %r15, %rsi
callq *(%rax)
leaq 0x40f6a(%rip), %r12     # 0x5fab8
movl (%r15), %edi
callq *(%r12)
leaq 0x41434(%rip), %rax     # 0x5ff90
leaq 0x476bd(%rip), %r15     # 0x66220
movl %ebx, %edi
movq %r15, %rsi
callq *(%rax)
leaq 0x40f0f(%rip), %rax     # 0x5fa80
movl (%r15), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *(%rax)
leaq 0x40f76(%rip), %rax     # 0x5faf8
pushq $0x60
popq %rsi
movl $0x8892, %edi           # imm = 0x8892
movq %r14, %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rax)
leaq 0x412ad(%rip), %r14     # 0x5fe48
xorl %edi, %edi
callq *(%r14)
movl %ebx, %edi
callq *(%r14)
leaq 0x422ac(%rip), %r13     # 0x60e58
pushq $0x2
popq %r14
pushq $0x10
popq %r15
xorl %edi, %edi
movl %r14d, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl %r15d, %r8d
xorl %r9d, %r9d
callq *(%r13)
pushq $0x8
popq %r9
movl %ebx, %edi
movl %r14d, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl %r15d, %r8d
callq *(%r13)
xorl %edi, %edi
callq *(%r12)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq