// File: /workspace/github_c_makefile_star2_O2/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, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x3094(%rip), %rdi      # 0x11d8f
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq 0x38(%r14), %rax
movq %r14, -0x30(%rbp)
subq 0x30(%r14), %rax
pushq $0x28
popq %rcx
cqto
idivq %rcx
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %eax
imulq $0x28, %rax, %r13
pushq $0x3
popq %r12
cmpq %r15, %r13
je 0xed90
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0xed55
leaq 0x3065(%rip), %rdi      # 0x11dac
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rcx
movzbl 0x78(%rcx), %eax
movq 0x80(%rcx), %rsi
cvtss2sd (%r14,%r15), %xmm0
addq %r15, %r14
cvtss2sd 0x4(%r14,%rax,4), %xmm1
xorb $0x1, %al
movzbl %al, %eax
cvtss2sd 0x4(%r14,%rax,4), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x2330
addq $0x28, %r15
jmp 0xed2e
leaq 0x2acf(%rip), %rdi      # 0x11866
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rax
cmpb $0x0, 0x6a(%rax)
je 0xee97
leaq 0x2ff6(%rip), %rdi      # 0x11db0
pushq $0x2c
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x30(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x30(%rcx), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
movq %rax, %r14
leaq 0x2ff3(%rip), %rdi      # 0x11ddd
pushq $0x1e
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2440
xorl %r12d, %r12d
cmpl $0x0, -0x3c(%rbp)
sete %r12b
xorl %r13d, %r13d
testl %r14d, %r14d
cmovlel %r13d, %r14d
movq %r14, -0x48(%rbp)
shll $0x3, %r12d
leaq 0xc(%r12), %r15
orq $0x10, %r12
cmpq %r13, -0x48(%rbp)
je 0xef65
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r13, %r13
je 0xee5d
testb $0x3, %r13b
je 0xee48
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x22e0
jmp 0xee5d
leaq 0x2f5d(%rip), %rdi      # 0x11dac
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rsi
cvtss2sd (%r14,%r15), %xmm0
movss 0x293e(%rip), %xmm1     # 0x117b4
subss (%r14,%r12), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2330
incq %r13
addq $0x28, %r15
addq $0x28, %r12
jmp 0xee1e
cmpb $0x1, 0x79(%rax)
jne 0xf04c
leaq 0x2f5b(%rip), %rdi      # 0x11e03
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x30(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x30(%rcx), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
movq %rax, %r14
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
xorl %r15d, %r15d
cmpq %r15, %r14
je 0xf037
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r13
testq %r15, %r15
je 0xef18
testb $0x3, %r15b
je 0xef03
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x22e0
jmp 0xef18
leaq 0x2ea2(%rip), %rdi      # 0x11dac
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rcx
movzbl 0x6c(%rcx), %eax
movq 0x88(%rcx), %rsi
xorl $0x1, %eax
leaq (,%rax,8), %rax
addq %r13, %rax
cvtss2sd 0xc(%r12,%rax), %xmm0
movss 0x2870(%rip), %xmm1     # 0x117b4
subss 0x10(%r12,%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2330
incq %r15
addq $0x28, %r12
jmp 0xeeda
leaq 0x28fa(%rip), %rdi      # 0x11866
pushq $0x5
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x2440
leaq 0x2e58(%rip), %rdi      # 0x11ddd
pushq $0x1e
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x2440
xorl %r13d, %r13d
cmpl $0x1, -0x3c(%rbp)
sete %r13b
shll $0x3, %r13d
leaq 0xc(%r13), %r12
orq $0x10, %r13
xorl %r15d, %r15d
cmpq %r15, -0x48(%rbp)
je 0xf022
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0xefe8
testb $0x3, %r15b
je 0xefd3
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x22e0
jmp 0xefe8
leaq 0x2dd2(%rip), %rdi      # 0x11dac
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rsi
cvtss2sd (%r14,%r12), %xmm0
movss 0x27b3(%rip), %xmm1     # 0x117b4
subss (%r14,%r13), %xmm1
cvtss2sd %xmm1, %xmm1
movq %rbx, %rdi
movb $0x2, %al
callq 0x2330
incq %r15
addq $0x28, %r12
addq $0x28, %r13
jmp 0xefad
leaq 0x2dd3(%rip), %rdi      # 0x11dfc
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
leaq 0x2828(%rip), %rdi      # 0x11866
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x30(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x30(%rcx), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
movq %rax, %r12
leaq 0x2dc1(%rip), %rdi      # 0x11e2b
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
xorl %r15d, %r15d
testl %r12d, %r12d
cmovlel %r15d, %r12d
pushq $0x24
popq %r13
cmpq %r15, %r12
je 0xf0f2
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r14
testq %r15, %r15
je 0xf0c0
testb $0x3, %r15b
je 0xf0ab
pushq $0x2c
popq %rdi
movq %rbx, %rsi
callq 0x22e0
jmp 0xf0c0
leaq 0x2cfa(%rip), %rdi      # 0x11dac
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2440
movq -0x38(%rbp), %rax
movq 0x90(%rax), %rsi
cvtss2sd -0x8(%r14,%r13), %xmm0
cvtss2sd -0x4(%r14,%r13), %xmm1
cvtss2sd (%r14,%r13), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x2330
incq %r15
addq $0x28, %r13
jmp 0xf086
leaq 0x276d(%rip), %rdi      # 0x11866
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2440
nop