// File: /workspace/github_c_makefile_star2_O3/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 0x4164(%rip), %rdi      # 0x8f40
movl $0x8b31, %esi           # imm = 0x8B31
callq 0x2d30
movl %eax, %ebx
leaq 0x416b(%rip), %rdi      # 0x8f5a
movl $0x8b30, %esi           # imm = 0x8B30
callq 0x2d30
movl %eax, %r14d
leaq -0x34(%rbp), %rdi
movl %ebx, (%rdi)
movl %eax, 0x4(%rdi)
movl $0x0, 0x8(%rdi)
callq 0x2e92
movl %eax, 0x7469(%rip)      # 0xc280
leaq 0x6a72(%rip), %r15      # 0xb890
movl %ebx, %edi
callq *(%r15)
movl %r14d, %edi
callq *(%r15)
leaq 0x6b90(%rip), %rax      # 0xb9c0
leaq 0x744d(%rip), %rsi      # 0xc284
movl $0x1, %edi
callq *(%rax)
leaq 0x6883(%rip), %r15      # 0xb6c8
movl 0x7439(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x68ee(%rip), %rax      # 0xb748
leaq 0x3e0f(%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 0x6b6b(%rip), %rax      # 0xb9f0
leaq 0x73fc(%rip), %rsi      # 0xc288
movl $0x1, %edi
callq *(%rax)
leaq 0x6876(%rip), %r14      # 0xb710
movl 0x73e8(%rip), %edi      # 0xc288
callq *(%r14)
leaq 0x6a96(%rip), %r12      # 0xb940
xorl %edi, %edi
callq *(%r12)
movl $0x1, %edi
callq *(%r12)
movl 0x73c5(%rip), %esi      # 0xc284
movl $0x8892, %edi           # imm = 0x8892
callq *(%r15)
leaq 0x7332(%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 0x6c90(%rip), %r14      # 0xbbb0
movl 0x735a(%rip), %edi      # 0xc280
leaq 0x4047(%rip), %rsi      # 0x8f74
callq *(%r14)
movl %eax, 0x7356(%rip)      # 0xc28c
movl 0x7344(%rip), %edi      # 0xc280
leaq 0x4042(%rip), %rsi      # 0x8f85
callq *(%r14)
movl %eax, 0x7344(%rip)      # 0xc290
movl 0x732e(%rip), %edi      # 0xc280
leaq 0x4038(%rip), %rsi      # 0x8f91
callq *(%r14)
movl %eax, 0x7332(%rip)      # 0xc294
movl $0x3f891a2a, 0x7334(%rip) # imm = 0x3F891A2A
xorps %xmm0, %xmm0
movups %xmm0, 0x732e(%rip)     # 0xc2a4
movl $0x3fb6cd8e, 0x7334(%rip) # imm = 0x3FB6CD8E
movups %xmm0, 0x7331(%rip)     # 0xc2b8
movsd 0x3c81(%rip), %xmm0     # 0x8c10
movups %xmm0, 0x7332(%rip)     # 0xc2c8
movl $0xbca3db3c, %eax       # imm = 0xBCA3DB3C
movq %rax, 0x7336(%rip)      # 0xc2d8
leaq 0x7337(%rip), %rax      # 0xc2e0
movss 0x2067(%rip), %xmm0     # 0x7018
xorl %ecx, %ecx
movaps %xmm0, %xmm1
cmpq %rcx, %rbx
je 0x4fbe
xorps %xmm1, %xmm1
movss %xmm1, (%rax,%rcx,4)
incq %rcx
cmpq $0x4, %rcx
jne 0x4fb3
incq %rbx
addq $0x10, %rax
cmpq $0x4, %rbx
jne 0x4fb1
leaq 0x7340(%rip), %rax      # 0xc320
xorl %ecx, %ecx
movss 0x202e(%rip), %xmm0     # 0x7018
xorl %edx, %edx
movaps %xmm0, %xmm1
cmpq %rdx, %rcx
je 0x4ff7
xorps %xmm1, %xmm1
movss %xmm1, (%rax,%rdx,4)
incq %rdx
cmpq $0x4, %rdx
jne 0x4fec
incq %rcx
addq $0x10, %rax
cmpq $0x4, %rcx
jne 0x4fea
leaq 0x6fc7(%rip), %rbx      # 0xbfe0
movl 0x7261(%rip), %edi      # 0xc280
callq *(%rbx)
leaq 0x6f98(%rip), %r14      # 0xbfc0
movl 0x725e(%rip), %edi      # 0xc28c
leaq 0x726b(%rip), %rcx      # 0xc2a0
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
movl 0x724b(%rip), %edi      # 0xc290
leaq 0x7294(%rip), %rcx      # 0xc2e0
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
movl 0x7238(%rip), %edi      # 0xc294
leaq 0x72bd(%rip), %rcx      # 0xc320
movl $0x1, %esi
xorl %edx, %edx
callq *(%r14)
xorl %edi, %edi
callq *(%rbx)
leaq 0x3f24(%rip), %rdi      # 0x8f9c
callq 0x2f08
leaq 0x3f29(%rip), %rdi      # 0x8fad
callq 0x2f08
movl %eax, 0x72d1(%rip)      # 0xc360
leaq 0x72da(%rip), %rbx      # 0xc370
movl $0x100, %r14d           # imm = 0x100
movb $0x0, 0x18(%rbx)
leaq 0x4(%rbx), %rsi
movl $0x1, %edi
leaq 0x6910(%rip), %rax      # 0xb9c0
callq *(%rax)
movl $0x1, %edi
movq %rbx, %rsi
leaq 0x692f(%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 0x6662(%rip), %rax      # 0xb748
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
callq *(%r15)
movl (%rbx), %edi
leaq 0x6615(%rip), %r13      # 0xb710
callq *(%r13)
xorl %edi, %edi
leaq 0x6838(%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 0x70c2(%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 0x509c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq