// File: /workspace/github_c_makefile_star2_O2/k0n10pl4tr[P]minimal_crafter/rendering.c
// Function: initRenderingSystem
void
initRenderingSystem()
{
	unsigned int cubeRenderingVertex = loadShader("shaders/cubeRendering.vsh", GL_VERTEX_SHADER);
	unsigned int cubeRenderingFragment = loadShader("shaders/cubeRendering.fsh", GL_FRAGMENT_SHADER);

	unsigned int cubeRenderingShaderShaders[] = { cubeRenderingVertex, cubeRenderingFragment, 0 };
	cubeRenderingShader = createProgram(cubeRenderingShaderShaders);

	glDeleteShader(cubeRenderingVertex);
	glDeleteShader(cubeRenderingFragment);

	glGenBuffers(1, &cubeVertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, cubeVertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(cubeBufferData), cubeBufferData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenVertexArrays(1, &cubeVertexArray);
	glBindVertexArray(cubeVertexArray);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, cubeVertexBuffer);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(0));
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)(36 * 3 * sizeof(float)));
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);

	cubeUniformProjectionLocation = glGetUniformLocation(cubeRenderingShader, "projectionMatrix");
	cubeUniformModelLocation      = glGetUniformLocation(cubeRenderingShader, "modelMatrix");
	cubeUniformViewLocation       = glGetUniformLocation(cubeRenderingShader, "viewMatrix");

	mat4x4_perspective(projectionMatrix, TO_RADIANS(70.0), 4.0/3.0, 0.01, 100.0);
	mat4x4_identity(modelMatrix);
	mat4x4_identity(viewMatrix);

	glUseProgram(cubeRenderingShader);
	glUniformMatrix4fv(cubeUniformProjectionLocation, 1, GL_FALSE, &projectionMatrix[0][0]);
	glUniformMatrix4fv(cubeUniformModelLocation,      1, GL_FALSE, &modelMatrix[0][0]);
	glUniformMatrix4fv(cubeUniformViewLocation,       1, GL_FALSE, &viewMatrix[0][0]);
	glUseProgram(0);
	
	cubeTexture        = loadTextureFarbfeld("textures/test.ff");
	cubeTerrainTexture = loadTextureFarbfeld("textures/terrain.ff");

	for(unsigned int i = 0; i < NUM_CHUNK_CACHED; i++) {
		chunkCached[i].canDraw = 0;
		glGenBuffers(1, &chunkCached[i].vbo);
		glGenVertexArrays(1, &chunkCached[i].vao);
			
		glBindBuffer(GL_ARRAY_BUFFER, chunkCached[i].vbo);
		glBufferData(GL_ARRAY_BUFFER, WORLD_CHUNK_NBLOCKS * 30 * 6 * sizeof(float), NULL, GL_DYNAMIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);

		glBindVertexArray(chunkCached[i].vao);
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);
		glBindBuffer(GL_ARRAY_BUFFER, chunkCached[i].vbo);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, (void*)(0));
		glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)(WORLD_CHUNK_NBLOCKS * 18 * 6 * sizeof(float)));
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x4098(%rip), %rdi      # 0x8f40
movl $0x8b31, %esi           # imm = 0x8B31
callq 0x2cc8
movl %eax, %ebx
leaq 0x409f(%rip), %rdi      # 0x8f5a
movl $0x8b30, %esi           # imm = 0x8B30
callq 0x2cc8
movl %eax, %r14d
leaq -0x34(%rbp), %rdi
movl %ebx, (%rdi)
movl %eax, 0x4(%rdi)
andl $0x0, 0x8(%rdi)
callq 0x2e22
movl %eax, 0x73a0(%rip)      # 0xc280
leaq 0x69a9(%rip), %r15      # 0xb890
movl %ebx, %edi
callq *(%r15)
movl %r14d, %edi
callq *(%r15)
leaq 0x6ac7(%rip), %rax      # 0xb9c0
leaq 0x7384(%rip), %rsi      # 0xc284
pushq $0x1
popq %rbx
movl %ebx, %edi
callq *(%rax)
leaq 0x67ba(%rip), %r15      # 0xb6c8
movl 0x7370(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x6825(%rip), %rax      # 0xb748
leaq 0x3d46(%rip), %rdx      # 0x8c70
movl $0x2d0, %esi            # imm = 0x2D0
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
leaq 0x6aa4(%rip), %rax      # 0xb9f0
leaq 0x7335(%rip), %rsi      # 0xc288
movl %ebx, %edi
callq *(%rax)
leaq 0x67b2(%rip), %r14      # 0xb710
movl 0x7324(%rip), %edi      # 0xc288
callq *(%r14)
leaq 0x69d2(%rip), %r12      # 0xb940
xorl %edi, %edi
callq *(%r12)
movl %ebx, %edi
callq *(%r12)
movl 0x7304(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x7271(%rip), %r12      # 0xc200
pushq $0x3
popq %rsi
pushq $0xc
popq %r8
xorl %edi, %edi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
xorl %r9d, %r9d
callq *(%r12)
pushq $0x2
popq %rsi
pushq $0x8
popq %r8
movl $0x1b0, %r9d            # imm = 0x1B0
movl %ebx, %edi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
callq *(%r12)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
xorl %edi, %edi
callq *(%r14)
leaq 0x6bda(%rip), %r14      # 0xbbb0
movl 0x72a4(%rip), %edi      # 0xc280
leaq 0x3f91(%rip), %rsi      # 0x8f74
callq *(%r14)
movl %eax, 0x72a0(%rip)      # 0xc28c
movl 0x728e(%rip), %edi      # 0xc280
leaq 0x3f8c(%rip), %rsi      # 0x8f85
callq *(%r14)
movl %eax, 0x728e(%rip)      # 0xc290
movl 0x7278(%rip), %edi      # 0xc280
leaq 0x3f82(%rip), %rsi      # 0x8f91
callq *(%r14)
movl %eax, 0x727c(%rip)      # 0xc294
movl $0x3f891a2a, 0x727e(%rip) # imm = 0x3F891A2A
xorps %xmm0, %xmm0
movups %xmm0, 0x7278(%rip)     # 0xc2a4
movl $0x3fb6cd8e, 0x727e(%rip) # imm = 0x3FB6CD8E
movups %xmm0, 0x727b(%rip)     # 0xc2b8
movsd 0x3bcb(%rip), %xmm0     # 0x8c10
movups %xmm0, 0x727c(%rip)     # 0xc2c8
movl $0xbca3db3c, %eax       # imm = 0xBCA3DB3C
movq %rax, 0x7280(%rip)      # 0xc2d8
leaq 0x7281(%rip), %r14      # 0xc2e0
movq %r14, %rdi
callq 0x51ea
leaq 0x72b2(%rip), %r12      # 0xc320
movq %r12, %rdi
callq 0x51ea
leaq 0x6f63(%rip), %r15      # 0xbfe0
movl 0x71fd(%rip), %edi      # 0xc280
callq *(%r15)
leaq 0x6f33(%rip), %r13      # 0xbfc0
movl 0x71f9(%rip), %edi      # 0xc28c
movl %ebx, %esi
xorl %edx, %edx
leaq 0x7202(%rip), %rcx      # 0xc2a0
callq *(%r13)
movl 0x71e8(%rip), %edi      # 0xc290
movl %ebx, %esi
xorl %edx, %edx
movq %r14, %rcx
callq *(%r13)
movl 0x71db(%rip), %edi      # 0xc294
movl %ebx, %esi
xorl %edx, %edx
movq %r12, %rcx
callq *(%r13)
xorl %edi, %edi
callq *(%r15)
leaq 0x3ecc(%rip), %rdi      # 0x8f9c
callq 0x2e8b
leaq 0x3ed1(%rip), %rdi      # 0x8fad
callq 0x2e8b
movl %eax, 0x7279(%rip)      # 0xc360
movl $0x100, %r13d           # imm = 0x100
leaq 0x727c(%rip), %r14      # 0xc370
subq $0x1, %r13
jb 0x51db
movb $0x0, 0x18(%r14)
leaq 0x4(%r14), %rsi
pushq $0x1
popq %rbx
movl %ebx, %edi
leaq 0x68ad(%rip), %rax      # 0xb9c0
callq *(%rax)
movl %ebx, %edi
movq %r14, %rsi
leaq 0x68cf(%rip), %rax      # 0xb9f0
callq *(%rax)
movl 0x4(%r14), %esi
movl $0x8892, %edi           # imm = 0x8892
leaq 0x6595(%rip), %rbx      # 0xb6c8
callq *(%rbx)
movl $0x2d0000, %esi         # imm = 0x2D0000
movl $0x8892, %edi           # imm = 0x8892
xorl %edx, %edx
movl $0x88e8, %ecx           # imm = 0x88E8
leaq 0x65fb(%rip), %rax      # 0xb748
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%rbx)
movl (%r14), %edi
leaq 0x65ae(%rip), %r12      # 0xb710
callq *(%r12)
xorl %edi, %edi
leaq 0x67d1(%rip), %r15      # 0xb940
callq *(%r15)
pushq $0x1
popq %r12
movl %r12d, %edi
callq *(%r15)
movl 0x4(%r14), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *(%rbx)
xorl %edi, %edi
pushq $0x3
popq %rsi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
pushq $0xc
popq %r8
xorl %r9d, %r9d
leaq 0x705f(%rip), %r15      # 0xc200
callq *(%r15)
movl $0x1b0000, %r9d         # imm = 0x1B0000
movl %r12d, %edi
pushq $0x2
popq %rsi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
pushq $0x8
popq %r8
callq *(%r15)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%rbx)
xorl %edi, %edi
leaq 0x6540(%rip), %rax      # 0xb710
callq *(%rax)
addq $0x1c, %r14
jmp 0x50f4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq