// File: /workspace/github_c_makefile_star2_O1/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 0x4158(%rip), %rdi      # 0x8f40
movl $0x8b31, %esi           # imm = 0x8B31
callq 0x2d3c
movl %eax, %ebx
leaq 0x415f(%rip), %rdi      # 0x8f5a
movl $0x8b30, %esi           # imm = 0x8B30
callq 0x2d3c
movl %eax, %r14d
leaq -0x34(%rbp), %rdi
movl %ebx, (%rdi)
movl %eax, 0x4(%rdi)
movl $0x0, 0x8(%rdi)
callq 0x2e9c
movl %eax, 0x745d(%rip)      # 0xc280
leaq 0x6a66(%rip), %r15      # 0xb890
movl %ebx, %edi
callq *(%r15)
movl %r14d, %edi
callq *(%r15)
leaq 0x6b84(%rip), %rax      # 0xb9c0
leaq 0x7441(%rip), %rsi      # 0xc284
movl $0x1, %edi
callq *(%rax)
leaq 0x6877(%rip), %r15      # 0xb6c8
movl 0x742d(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x68e2(%rip), %rax      # 0xb748
leaq 0x3e03(%rip), %rdx      # 0x8c70
movl $0x2d0, %esi            # imm = 0x2D0
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rax)
xorl %ebx, %ebx
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
leaq 0x6b5f(%rip), %rax      # 0xb9f0
leaq 0x73f0(%rip), %rsi      # 0xc288
movl $0x1, %edi
callq *(%rax)
leaq 0x686a(%rip), %r14      # 0xb710
movl 0x73dc(%rip), %edi      # 0xc288
callq *(%r14)
leaq 0x6a8a(%rip), %r12      # 0xb940
xorl %edi, %edi
callq *(%r12)
movl $0x1, %edi
callq *(%r12)
movl 0x73b9(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x7326(%rip), %r12      # 0xc200
xorl %edi, %edi
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0xc, %r8d
xorl %r9d, %r9d
callq *(%r12)
movl $0x1b0, %r9d            # imm = 0x1B0
movl $0x1, %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x8, %r8d
callq *(%r12)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
xorl %edi, %edi
callq *(%r14)
leaq 0x6c84(%rip), %r14      # 0xbbb0
movl 0x734e(%rip), %edi      # 0xc280
leaq 0x403b(%rip), %rsi      # 0x8f74
callq *(%r14)
movl %eax, 0x734a(%rip)      # 0xc28c
movl 0x7338(%rip), %edi      # 0xc280
leaq 0x4036(%rip), %rsi      # 0x8f85
callq *(%r14)
movl %eax, 0x7338(%rip)      # 0xc290
movl 0x7322(%rip), %edi      # 0xc280
leaq 0x402c(%rip), %rsi      # 0x8f91
callq *(%r14)
movl %eax, 0x7326(%rip)      # 0xc294
movl $0x3f891a2a, 0x7328(%rip) # imm = 0x3F891A2A
xorps %xmm0, %xmm0
movups %xmm0, 0x7322(%rip)     # 0xc2a4
movl $0x3fb6cd8e, 0x7328(%rip) # imm = 0x3FB6CD8E
movups %xmm0, 0x7325(%rip)     # 0xc2b8
movsd 0x3c75(%rip), %xmm0     # 0x8c10
movups %xmm0, 0x7326(%rip)     # 0xc2c8
movl $0xbca3db3c, %eax       # imm = 0xBCA3DB3C
movq %rax, 0x732a(%rip)      # 0xc2d8
leaq 0x732b(%rip), %rax      # 0xc2e0
movss 0x205b(%rip), %xmm0     # 0x7018
xorl %ecx, %ecx
movaps %xmm0, %xmm1
cmpq %rcx, %rbx
je 0x4fca
xorps %xmm1, %xmm1
movss %xmm1, (%rax,%rcx,4)
incq %rcx
cmpq $0x4, %rcx
jne 0x4fbf
incq %rbx
addq $0x10, %rax
cmpq $0x4, %rbx
jne 0x4fbd
leaq 0x7334(%rip), %rax      # 0xc320
xorl %ecx, %ecx
movss 0x2022(%rip), %xmm0     # 0x7018
xorl %edx, %edx
movaps %xmm0, %xmm1
cmpq %rdx, %rcx
je 0x5003
xorps %xmm1, %xmm1
movss %xmm1, (%rax,%rdx,4)
incq %rdx
cmpq $0x4, %rdx
jne 0x4ff8
incq %rcx
addq $0x10, %rax
cmpq $0x4, %rcx
jne 0x4ff6
leaq 0x6fbb(%rip), %rbx      # 0xbfe0
movl 0x7255(%rip), %edi      # 0xc280
callq *(%rbx)
leaq 0x6f8c(%rip), %r14      # 0xbfc0
movl 0x7252(%rip), %edi      # 0xc28c
leaq 0x725f(%rip), %rcx      # 0xc2a0
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
movl 0x723f(%rip), %edi      # 0xc290
leaq 0x7288(%rip), %rcx      # 0xc2e0
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
movl 0x722c(%rip), %edi      # 0xc294
leaq 0x72b1(%rip), %rcx      # 0xc320
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
xorl %edi, %edi
callq *(%rbx)
leaq 0x3f18(%rip), %rdi      # 0x8f9c
callq 0x2f12
leaq 0x3f1d(%rip), %rdi      # 0x8fad
callq 0x2f12
movl %eax, 0x72c5(%rip)      # 0xc360
leaq 0x72ce(%rip), %rbx      # 0xc370
movl $0x100, %r14d           # imm = 0x100
movb $0x0, 0x18(%rbx)
leaq 0x4(%rbx), %rsi
movl $0x1, %edi
leaq 0x6904(%rip), %rax      # 0xb9c0
callq *(%rax)
movl $0x1, %edi
movq %rbx, %rsi
leaq 0x6923(%rip), %rax      # 0xb9f0
callq *(%rax)
movl 0x4(%rbx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
movl $0x2d0000, %esi         # imm = 0x2D0000
movl $0x8892, %edi           # imm = 0x8892
xorl %edx, %edx
movl $0x88e8, %ecx           # imm = 0x88E8
leaq 0x6656(%rip), %rax      # 0xb748
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
movl (%rbx), %edi
leaq 0x6609(%rip), %r13      # 0xb710
callq *(%r13)
xorl %edi, %edi
leaq 0x682c(%rip), %r12      # 0xb940
callq *(%r12)
movl $0x1, %edi
callq *(%r12)
movl 0x4(%rbx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
xorl %edi, %edi
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0xc, %r8d
xorl %r9d, %r9d
leaq 0x70b6(%rip), %r12      # 0xc200
callq *(%r12)
movl $0x1b0000, %r9d         # imm = 0x1B0000
movl $0x1, %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x8, %r8d
callq *(%r12)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
xorl %edi, %edi
callq *(%r13)
addq $0x1c, %rbx
decq %r14
jne 0x50a8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq