// File: /workspace/github_c_makefile_star2_O1/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 0x38fc(%rip), %rdi      # 0x13d9f
movl $0x1c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq 0x38(%r14), %r12
movq %r14, -0x38(%rbp)
subq 0x30(%r14), %r12
sarq $0x3, %r12
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r12
testl %r12d, %r12d
jle 0x10555
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r15d, %r15d
xorl %r13d, %r13d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r14
testq %r13, %r13
je 0x1050b
movl $0x3, %esi
movl $0x1, %edx
leaq 0x38b9(%rip), %rdi      # 0x13dbc
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rcx
movzbl 0x78(%rcx), %eax
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
movq 0x80(%rcx), %rsi
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 0x104e5
leaq 0x331a(%rip), %rdi      # 0x13876
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %r14
cmpb $0x0, 0x6a(%r14)
je 0x1077a
leaq 0x383c(%rip), %rdi      # 0x13dc0
movl $0x2c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x38(%rbp), %rax
movq 0x38(%rax), %r14
subq 0x30(%rax), %r14
sarq $0x3, %r14
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r14
leaq 0x3832(%rip), %rdi      # 0x13ded
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq %r14, -0x30(%rbp)
testl %r14d, %r14d
jle 0x1067d
xorl %r13d, %r13d
cmpl $0x0, -0x44(%rbp)
sete %r13b
movq -0x30(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x50(%rbp)
shll $0x3, %r13d
leaq 0xc(%r13), %r12
orq $0x10, %r13
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0x1063c
testb $0x3, %r15b
je 0x10623
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x1063c
movl $0x3, %esi
movl $0x1, %edx
leaq 0x3788(%rip), %rdi      # 0x13dbc
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12), %xmm0
movss 0x316c(%rip), %xmm1     # 0x137c4
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, -0x50(%rbp)
jne 0x10601
leaq 0x31f2(%rip), %rdi      # 0x13876
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
leaq 0x3750(%rip), %rdi      # 0x13ded
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
cmpl $0x0, -0x30(%rbp)
jle 0x1075c
xorl %r13d, %r13d
cmpl $0x1, -0x44(%rbp)
sete %r13b
movq -0x30(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x30(%rbp)
shll $0x3, %r13d
leaq 0xc(%r13), %r12
orq $0x10, %r13
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0x1071b
testb $0x3, %r15b
je 0x10702
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x1071b
movl $0x3, %esi
movl $0x1, %edx
leaq 0x36a9(%rip), %rdi      # 0x13dbc
movq %rbx, %rcx
callq 0x2410
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12), %xmm0
movss 0x308d(%rip), %xmm1     # 0x137c4
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, -0x30(%rbp)
jne 0x106e0
leaq 0x36a9(%rip), %rdi      # 0x13e0c
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
jmp 0x10868
cmpb $0x1, 0x79(%r14)
jne 0x10881
leaq 0x3687(%rip), %rdi      # 0x13e13
movl $0x27, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq %rcx, -0x30(%rbp)
testl %ecx, %ecx
jle 0x10868
movq -0x30(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x30(%rbp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r13
testq %r12, %r12
je 0x10816
testb $0x3, %r12b
je 0x107fd
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x10816
movl $0x3, %esi
movl $0x1, %edx
leaq 0x35ae(%rip), %rdi      # 0x13dbc
movq %rbx, %rcx
callq 0x2410
movzbl 0x6c(%r14), %eax
xorl $0x1, %eax
movq 0x88(%r14), %rsi
leaq (,%rax,8), %rax
addq %r13, %rax
xorps %xmm0, %xmm0
cvtss2sd 0xc(%r15,%rax), %xmm0
movss 0x2f82(%rip), %xmm1     # 0x137c4
subss 0x10(%r15,%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2300
incq %r12
addq $0x28, %r15
cmpq %r12, -0x30(%rbp)
jne 0x107db
leaq 0x3007(%rip), %rdi      # 0x13876
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
movq -0x38(%rbp), %rax
movq 0x38(%rax), %r13
subq 0x30(%rax), %r13
sarq $0x3, %r13
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r13
leaq 0x3595(%rip), %rdi      # 0x13e3b
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2410
testl %r13d, %r13d
jle 0x1094a
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl $0x24, %r15d
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r14
testq %r12, %r12
je 0x1090c
testb $0x3, %r12b
je 0x108f3
movl $0x2c, %edi
movq %rbx, %rsi
callq 0x22e0
jmp 0x1090c
movl $0x3, %esi
movl $0x1, %edx
leaq 0x34b8(%rip), %rdi      # 0x13dbc
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 0x108d1
leaq 0x2f25(%rip), %rdi      # 0x13876
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
nop