// File: /workspace/github_c_makefile_star2_O2/Hazematman[P]BSP-Renderer/texture.c
// Function: readPltTex
Texture *readPltTex(uint8_t *texData, int width, int height, Palette *plt, const char *name){
	Texture *tex = malloc(sizeof(Texture));
	tex->width = width;
	tex->height = height;
	tex->data = malloc(sizeof(colour3UByte)*width*height);
	tex->name = malloc(strlen(name)+1);

	// Copy name
	strcpy(tex->name, name);

	// Load and convert all paletted colour data	
	for(int i = 0; i < width*height; i++){
		tex->data[i] = getPaletteColour(plt, texData[i]);
	}

	glGenTextures(1, &tex->glId);
	glBindTexture(GL_TEXTURE_2D, tex->glId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,
			0,
			GL_RGB,
			width,
			height,
			0,
			GL_RGB,
			GL_UNSIGNED_BYTE,
			tex->data);


	return tex;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, (%rsp)
movq %rcx, %r15
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r12
pushq $0x20
popq %rdi
callq 0x1160
movq %rax, %rbp
movl %ebx, 0xc(%rax)
movl %r14d, 0x10(%rax)
movslq %ebx, %rax
movslq %r14d, %rcx
imulq %rax, %rcx
leaq (%rcx,%rcx,2), %rdi
callq 0x1160
movq %rax, %r13
movq %rax, 0x18(%rbp)
movq (%rsp), %rdi
callq 0x1080
leaq 0x1(%rax), %rdi
callq 0x1160
movq %rbp, 0x10(%rsp)
movq %rax, (%rbp)
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x10f0
movl %r14d, (%rsp)
movl %r14d, %ebp
movl %ebx, 0xc(%rsp)
imull %ebx, %ebp
xorl %r14d, %r14d
testl %ebp, %ebp
cmovlel %r14d, %ebp
cmpq %r14, %rbp
je 0x665a
movzbl (%r12,%r14), %esi
movq %r15, %rdi
callq 0x645b
movw %ax, (%r13)
shrl $0x10, %eax
movb %al, 0x2(%r13)
incq %r14
addq $0x3, %r13
jmp 0x6633
leaq 0x5cc7(%rip), %rax      # 0xc328
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
addq $0x8, %rsi
pushq $0x1
popq %rdi
callq *(%rax)
leaq 0x5c6f(%rip), %rax      # 0xc2e8
movl 0x8(%rbx), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *(%rax)
leaq 0x5c46(%rip), %r14      # 0xc2d0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
callq *(%r14)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
callq *(%r14)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2901, %edx           # imm = 0x2901
callq *(%r14)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2901, %edx           # imm = 0x2901
callq *(%r14)
leaq 0x5bdf(%rip), %rax      # 0xc2b8
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1907, %edx           # imm = 0x1907
movl 0x14(%rsp), %ecx
movl 0x8(%rsp), %r8d
xorl %r9d, %r9d
pushq 0x18(%rbx)
pushq $0x1401                 # imm = 0x1401
pushq $0x1907                 # imm = 0x1907
callq *(%rax)
addq $0x20, %rsp
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq