// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/vformat.cpp
// Function: VertexPool::SaveVRML2(_IO_FILE*, int, VFormatOptions&)
void VertexPool::SaveVRML2(FILE *fph, int lightMapStage, VFormatOptions &options)
{
  
  if ( 1 )
  {
    fprintf(fph,"coord Coordinate {\npoint [\n\t");
    int count = mVtxs.size();
    for (int i=0; i<count; i++)
    {
      const LightMapVertex &vtx = mVtxs[i];
	  
	  if (i>0) { 
			fprintf(fph,",\n\t");
	  }		
	   
      if (options.yzFlip)
		  fprintf(fph,options.VFORMAT,vtx.mPos.x,vtx.mPos.z,vtx.mPos.y);
      else fprintf(fph,options.VFORMAT,vtx.mPos.x,vtx.mPos.y,vtx.mPos.z);

    }
    fprintf(fph,"\n]\n}\n");
  }

  if (options.useMultiTexturing) { // PROPOSAL MultiTextureCoodinate 
    fprintf(fph,"texCoord  MultiTextureCoordinate {\ncoord [\n\t");
    int count = mVtxs.size();

	// channel 0
    fprintf(fph,"\tTextureCoordinate {\npoint [\n\t");


    for (int i=0; i<count; i++)
    {
      const LightMapVertex &vtx = mVtxs[i];

	  if (i>0) { 
			if ( (i%4) == 0) fprintf(fph,",\n\t");
			else fprintf(fph,",");
	  }		
      if (lightMapStage == 0)
		  fprintf(fph,options.TFORMAT,vtx.mTexel2.x,1.0f-vtx.mTexel2.y);
      else fprintf(fph,options.TFORMAT,vtx.mTexel1.x,1.0f-vtx.mTexel1.y);

    }
    fprintf(fph,"\n]\n}\n");
	
	//if (lightMapStage == 1) 
	{

	// channel 1
	fprintf(fph,"\tTextureCoordinate {\npoint [\n\t");

    for (int i=0; i<count; i++)
    {
      const LightMapVertex &vtx = mVtxs[i];

	  if (i>0) { 
			if ( (i%4) == 0) fprintf(fph,",\n\t");
			else fprintf(fph,",");
	  }		
      if (lightMapStage == 1)
		  fprintf(fph,options.TFORMAT,vtx.mTexel2.x,1.0f-vtx.mTexel2.y);
      else fprintf(fph,options.TFORMAT,vtx.mTexel1.x,1.0f-vtx.mTexel1.y);
	}
    fprintf(fph,"\n\t]\n}\n");
	
	}
    fprintf(fph,"\n]\n}\n");


  } else	
  if ( options.noTextureCoordinates )
  {
    fprintf(fph,"texCoord  TextureCoordinate {\npoint [\n\t");
    int count = mVtxs.size();

    for (int i=0; i<count; i++)
    {
      const LightMapVertex &vtx = mVtxs[i];

	  if (i>0) {
			if ( (i%4) == 0) fprintf(fph,",\n\t");
			else fprintf(fph,",");
	  }		


      if ( !options.tex1 ) // if saving second U/V channel.
      {
         fprintf(fph,options.TFORMAT,vtx.mTexel2.x,1.0f-vtx.mTexel2.y);
      }
      else
      {
          fprintf(fph,options.TFORMAT,vtx.mTexel1.x,1.0f-vtx.mTexel1.y);
      }
    }
    fprintf(fph,"\n]\n}\n");

  }

   //if (options.useVertexColor) 
   {
    int count = mVtxs.size();
	// channel 0
    fprintf(fph,"\tcolor Color {\ncolor [\n\t");


    for (int i=0; i<count; i++)
    {
      const LightMapVertex &vtx = mVtxs[i];

	  if (i>0) { 
			if ( (i%4) == 0) fprintf(fph,",\n\t");
			else fprintf(fph,",");
	  }		
      fprintf(fph,options.CFORMAT,vtx.mColor.x,vtx.mColor.y,vtx.mColor.z);

    }
    fprintf(fph,"\n]\n}\n");
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, -0x40(%rbp)
movl %edx, -0x44(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x39a2(%rip), %rdi      # 0x13d7b
movl $0x1c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq 0x38(%r14), %r12
movq %r14, -0x30(%rbp)
subq 0x30(%r14), %r12
sarq $0x3, %r12
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r12
testl %r12d, %r12d
jle 0x1048b
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r15d, %r15d
xorl %r13d, %r13d
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r13, %r13
je 0x10441
movl $0x3, %esi
movl $0x1, %edx
leaq 0x395f(%rip), %rdi      # 0x13d98
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rcx
movzbl 0x78(%rcx), %eax
movq 0x80(%rcx), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r15), %xmm0
addq %r15, %r14
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r14,%rax,4), %xmm1
xorb $0x1, %al
movzbl %al, %eax
xorps %xmm2, %xmm2
cvtss2sd 0x4(%r14,%rax,4), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x2300
incq %r13
addq $0x28, %r15
cmpq %r13, %r12
jne 0x1041b
leaq 0x33c0(%rip), %rdi      # 0x13852
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %r14
cmpb $0x0, 0x6a(%r14)
je 0x10696
leaq 0x38e2(%rip), %rdi      # 0x13d9c
movl $0x2c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r14
subq 0x30(%rax), %r14
sarq $0x3, %r14
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r14
leaq 0x38d8(%rip), %rdi      # 0x13dc9
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
testl %r14d, %r14d
jle 0x10786
xorl %r13d, %r13d
cmpl $0x0, -0x44(%rbp)
sete %r13b
movq %r14, -0x50(%rbp)
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r14, -0x38(%rbp)
shll $0x3, %r13d
leaq 0xc(%r13), %r12
orq $0x10, %r13
xorl %r15d, %r15d
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0x10570
testb $0x3, %r15b
je 0x10557
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x10570
movl $0x3, %esi
movl $0x1, %edx
leaq 0x3830(%rip), %rdi      # 0x13d98
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12), %xmm0
movss 0x3214(%rip), %xmm1     # 0x137a0
subss (%r14,%r13), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2300
incq %r15
addq $0x28, %r12
addq $0x28, %r13
cmpq %r15, -0x38(%rbp)
jne 0x10535
leaq 0x329a(%rip), %rdi      # 0x13852
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
leaq 0x37f8(%rip), %rdi      # 0x13dc9
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x50(%rbp), %rax
testl %eax, %eax
jle 0x107b8
xorl %r13d, %r13d
cmpl $0x1, -0x44(%rbp)
sete %r13b
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll $0x3, %r13d
leaq 0xc(%r13), %r12
orq $0x10, %r13
xorl %r15d, %r15d
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0x1064d
testb $0x3, %r15b
je 0x10634
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x1064d
movl $0x3, %esi
movl $0x1, %edx
leaq 0x3753(%rip), %rdi      # 0x13d98
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12), %xmm0
movss 0x3137(%rip), %xmm1     # 0x137a0
subss (%r14,%r13), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2300
incq %r15
addq $0x28, %r12
addq $0x28, %r13
movq -0x50(%rbp), %rax
cmpq %r15, %rax
jne 0x10612
jmp 0x107b8
cmpb $0x1, 0x79(%r14)
jne 0x107ea
leaq 0x3747(%rip), %rdi      # 0x13def
movl $0x27, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq %rcx, -0x38(%rbp)
testl %ecx, %ecx
jle 0x107d1
movq -0x38(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x38(%rbp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r13
testq %r12, %r12
je 0x10732
testb $0x3, %r12b
je 0x10719
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x10732
movl $0x3, %esi
movl $0x1, %edx
leaq 0x366e(%rip), %rdi      # 0x13d98
movq %rbx, %rcx
callq 0x2410
movzbl 0x6c(%r14), %eax
movq 0x88(%r14), %rsi
xorl $0x1, %eax
leaq (,%rax,8), %rax
addq %r13, %rax
xorps %xmm0, %xmm0
cvtss2sd 0xc(%r15,%rax), %xmm0
movss 0x3042(%rip), %xmm1     # 0x137a0
subss 0x10(%r15,%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2300
incq %r12
addq $0x28, %r15
cmpq %r12, -0x38(%rbp)
jne 0x106f7
jmp 0x107d1
leaq 0x30c5(%rip), %rdi      # 0x13852
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
leaq 0x3623(%rip), %rdi      # 0x13dc9
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
leaq 0x3629(%rip), %rdi      # 0x13de8
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
leaq 0x307a(%rip), %rdi      # 0x13852
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r13
subq 0x30(%rax), %r13
sarq $0x3, %r13
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r13
leaq 0x3608(%rip), %rdi      # 0x13e17
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
testl %r13d, %r13d
jle 0x108b3
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl $0x24, %r15d
xorl %r12d, %r12d
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r12, %r12
je 0x10875
testb $0x3, %r12b
je 0x1085c
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x10875
movl $0x3, %esi
movl $0x1, %edx
leaq 0x352b(%rip), %rdi      # 0x13d98
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rax
movq 0x90(%rax), %rsi
xorps %xmm0, %xmm0
cvtss2sd -0x8(%r14,%r15), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x4(%r14,%r15), %xmm1
xorps %xmm2, %xmm2
cvtss2sd (%r14,%r15), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x2300
incq %r12
addq $0x28, %r15
cmpq %r12, %r13
jne 0x1083a
leaq 0x2f98(%rip), %rdi      # 0x13852
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410