// File: /workspace/github_cpp_makefile_star2_O1/YiweiMao[P]tessDX/src/tess_exp.cpp
// Function: main
int main(void) { //int argc, char** argv) {

    int partitionScheme;
    int outputPrimitive;
    int domain;
    int numTFs;
    float tfs[6] = {0};

    FILE *fp;
    fp = fopen("settings.txt", "r");
    fscanf(fp, "%d", &partitionScheme);
    fscanf(fp, "%d", &outputPrimitive);
    fscanf(fp, "%d", &domain);
    fscanf(fp, "%d", &numTFs);

    for (int i=0; i <numTFs; i++) {
        fscanf(fp, "%f", &tfs[i]);
    }
    fclose(fp);

    CHWTessellator hwTess;
    hwTess.Init((D3D11_TESSELLATOR_PARTITIONING)partitionScheme,(D3D11_TESSELLATOR_OUTPUT_PRIMITIVE)outputPrimitive);

    switch (domain)
    {
    case 0:
        hwTess.TessellateIsoLineDomain(tfs[0],tfs[1]);
        break;
    case 1:
        hwTess.TessellateTriDomain(tfs[0],tfs[1],tfs[2],tfs[3]);
        break;
    case 2:
        hwTess.TessellateQuadDomain(tfs[0],tfs[1],tfs[2],tfs[3],tfs[4],tfs[5]);
        break;
    default:
        break;
    }

    fp = fopen("points.csv", "w");
    //printf("get point count is %d\n",hwTess.GetPointCount());
    for(int i=0;i<hwTess.GetPointCount();i++){
        //printf("%.2f,%.2f\t",hwTess.m_Point[i].u,hwTess.m_Point[i].v);
        fprintf(fp,"%.16f,%.16f\n",hwTess.m_Point[i].u,hwTess.m_Point[i].v);
    }
    fclose(fp);

    fp = fopen("indexes.csv", "w");
    //printf("\nget index count is %d\n",hwTess.GetIndexCount());
    for(int i=0;i<hwTess.GetIndexCount();i++){
        //printf("%d\t",hwTess.m_Index[i]);
        fprintf(fp,"%d\n",hwTess.m_Index[i]);
    }
    fclose(fp);

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xc42d7(%rip), %rdi     # 0x4c6004
leaq 0xe1513(%rip), %rsi     # 0x4e3247
callq 0x42edc0
movq %rax, %rbx
leaq 0xca0ce(%rip), %r14     # 0x4cbe11
leaq 0x24(%rsp), %rdx
movq %rax, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x420730
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x420730
leaq 0x1c(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x420730
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x420730
cmpl $0x0, (%r15)
jle 0x401dc2
movq %rsp, %r14
leaq 0xe1a46(%rip), %r15     # 0x4e37e4
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x420730
incq %r12
movslq 0x18(%rsp), %rax
addq $0x4, %r14
cmpq %rax, %r12
jl 0x401da1
movq %rbx, %rdi
callq 0x42e980
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x401fd6
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
movq %rbx, %rdi
callq 0x402006
movl 0x1c(%rsp), %eax
testl %eax, %eax
je 0x401e4b
cmpl $0x1, %eax
je 0x401e28
cmpl $0x2, %eax
jne 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
movss 0x10(%rsp), %xmm4
movss 0x14(%rsp), %xmm5
leaq 0x28(%rsp), %rdi
callq 0x402072
jmp 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
leaq 0x28(%rsp), %rdi
callq 0x4037ea
jmp 0x401e60
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
leaq 0x28(%rsp), %rdi
callq 0x404210
leaq 0xc41aa(%rip), %rdi     # 0x4c6011
leaq 0xc5295(%rip), %rsi     # 0x4c7103
callq 0x42edc0
movq %rax, %rbx
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
leaq 0xc4197(%rip), %r15     # 0x4c601c
movq %r14, %rdi
callq 0x40468c
cltq
cmpq %rax, %r12
jge 0x401ebe
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,8), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax,%r12,8), %xmm1
movq %rbx, %rdi
movq %r15, %rsi
movb $0x2, %al
callq 0x4205b0
incq %r12
jmp 0x401e85
movq %rbx, %rdi
callq 0x42e980
leaq 0xc415c(%rip), %rdi     # 0x4c6029
leaq 0xc522f(%rip), %rsi     # 0x4c7103
callq 0x42edc0
movq %rax, %rbx
leaq 0x28(%rsp), %r14
leaq 0xc414d(%rip), %r15     # 0x4c6035
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x404690
cltq
cmpq %rax, %r12
jge 0x401f15
movq 0x48(%rsp), %rax
movl (%rax,%r12,4), %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x4205b0
incq %r12
jmp 0x401eeb
movq %rbx, %rdi
callq 0x42e980
leaq 0x28(%rsp), %rdi
callq 0x401fe2
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x401f3c
jmp 0x401f3c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x401fe2
movq %rbx, %rdi
callq 0x414150
nopl (%rax)