// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsp, %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xc32d9(%rip), %rdi     # 0x4c5004
leaq 0xe0595(%rip), %rsi     # 0x4e22c7
callq 0x42e5c0
movq %rax, %r14
leaq 0xc9150(%rip), %r15     # 0x4cae91
leaq 0x24(%rsp), %rdx
movq %rax, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41ff30
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41ff30
leaq 0x1c(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41ff30
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41ff30
leaq 0xe0ad4(%rip), %r15     # 0x4e2864
xorl %r12d, %r12d
movslq 0x18(%rsp), %rax
cmpq %rax, %r12
jge 0x401db6
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x41ff30
incq %r12
addq $0x4, %rbx
jmp 0x401d93
movq %r14, %rdi
callq 0x42e180
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x401fc2
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
movq %rbx, %rdi
callq 0x401ff2
movl 0x1c(%rsp), %eax
testl %eax, %eax
je 0x401e3f
cmpl $0x1, %eax
je 0x401e1c
cmpl $0x2, %eax
jne 0x401e54
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 0x402064
jmp 0x401e54
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
leaq 0x28(%rsp), %rdi
callq 0x403594
jmp 0x401e54
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
leaq 0x28(%rsp), %rdi
callq 0x403e7e
leaq 0xc31b6(%rip), %rdi     # 0x4c5011
leaq 0xc4331(%rip), %rsi     # 0x4c6193
callq 0x42e5c0
movq %rax, %rbx
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
leaq 0xc31a3(%rip), %r15     # 0x4c501c
movq %r14, %rdi
callq 0x40419a
cltq
cmpq %rax, %r12
jge 0x401eac
movq 0x40(%rsp), %rax
cvtss2sd (%rax,%r12,8), %xmm0
cvtss2sd 0x4(%rax,%r12,8), %xmm1
movq %rbx, %rdi
movq %r15, %rsi
movb $0x2, %al
callq 0x41fdb0
incq %r12
jmp 0x401e79
movq %rbx, %rdi
callq 0x42e180
leaq 0xc316e(%rip), %rdi     # 0x4c5029
leaq 0xc42d1(%rip), %rsi     # 0x4c6193
callq 0x42e5c0
movq %rax, %rbx
leaq 0x28(%rsp), %r14
leaq 0xc315f(%rip), %r15     # 0x4c5035
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x40419e
cltq
cmpq %rax, %r12
jge 0x401f03
movq 0x48(%rsp), %rax
movl (%rax,%r12,4), %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41fdb0
incq %r12
jmp 0x401ed9
movq %rbx, %rdi
callq 0x42e180
leaq 0x28(%rsp), %rdi
callq 0x401fce
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x401f2a
jmp 0x401f2a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x401fce
movq %rbx, %rdi
callq 0x413950
nop