// Geometric Tools, Inc.
// http://www.geometrictools.com
// Copyright (c) 1998-2005.  All Rights Reserved
//
// The Wild Magic Library (WM3) source code is supplied under the terms of
// the license agreement
//     http://www.geometrictools.com/License/WildMagic3License.pdf
// and may not be copied or disclosed except in accordance with the terms
// of that agreement.

#include "Wm3SkinningVShader.h"
using namespace Wm3;

WM3_IMPLEMENT_RTTI(Wm3,SkinningVShader,VertexShader);
WM3_IMPLEMENT_STREAM(SkinningVShader);
WM3_IMPLEMENT_DEFAULT_STREAM(SkinningVShader,VertexShader);
WM3_IMPLEMENT_DEFAULT_NAME_ID(SkinningVShader,VertexShader);

//----------------------------------------------------------------------------
SkinningVShader::SkinningVShader ()
{
    // shader program (load the type of the current renderer)
    m_acProgram = ms_aacProgram[Renderer::GetType()];

    // shader constants
    int iType, iOption, iReg, iRegQuantity;
    ShaderConstant* pkConst;

    // model-to-view * projection matrix (4x4)
    iType = ShaderConstant::SC_TRANSFORM_MVP;
    iOption = ShaderConstant::SCO_MATRIX;
    iReg = 0;
    iRegQuantity = 4;
    pkConst = new ShaderConstant(iType,iOption,iReg,iRegQuantity);
    m_kConstant.Append(pkConst);

    // user defined array (register 4)
    // SkinningMat
    iType = ShaderConstant::SC_USER_DEFINED;
    iOption = ShaderConstant::SCO_NONE;
    iReg = 4;
    iRegQuantity = 16;
    pkConst = new ShaderConstant(iType,iOption,iReg,iRegQuantity);
    m_kConstant.Append(pkConst);

}
//----------------------------------------------------------------------------
SkinningVShader::~SkinningVShader ()
{
    // empty
}
//----------------------------------------------------------------------------
const char* SkinningVShader::ms_aacProgram[Renderer::RT_QUANTITY] =
{
"!!ARBvp1.0\n"
"# ARB_vertex_program generated by NVIDIA Cg compiler\n"
"# cgc version 1.1.0003, build date Mar  4 2003  12:32:10\n"
"# command line args: -q -profile arbvp1 -entry vmain\n"
"# nv30vp backend compiling 'vmain' program\n"
"#vendor NVIDIA Corporation\n"
"#version 1.0.02\n"
"#profile arbvp1\n"
"#program vmain\n"
"#semantic vmain.Wm3TransformMVP\n"
"#semantic vmain.SkinningMat\n"
"#var float4 i_f4Position : $vin.POSITION : POSITION : 0 : 1\n"
"#var float4 i_f4Color : $vin.COLOR : COLOR : 1 : 1\n"
"#var float2 i_f2Weights0 : $vin.TEXCOORD0 : TEXCOORD0 : 2 : 1\n"
"#var float2 i_f2Weights1 : $vin.TEXCOORD1 : TEXCOORD1 : 3 : 1\n"
"#var float4 o_f4Position : $vout.POSITION : POSITION : 4 : 1\n"
"#var float4 o_f4Color : $vout.COLOR : COLOR : 5 : 1\n"
"#var float4x4 Wm3TransformMVP :  : c[0], 4 : 6 : 1\n"
"#var float4x4 SkinningMat[0] :  : c[4], 4 : 7 : 1\n"
"#var float4x4 SkinningMat[1] :  : c[8], 4 : 7 : 1\n"
"#var float4x4 SkinningMat[2] :  : c[12], 4 : 7 : 1\n"
"#var float4x4 SkinningMat[3] :  : c[16], 4 : 7 : 1\n"
"TEMP R0, R1, R2, R3;\n"
"ATTRIB v25 = vertex.texcoord[1];\n"
"ATTRIB v24 = vertex.texcoord[0];\n"
"ATTRIB v19 = vertex.color;\n"
"ATTRIB v16 = vertex.position;\n"
"PARAM c0[4] = { program.local[0..3] };\n"
"PARAM c4[16] = { program.local[4..19] };\n"
"	MOV result.color.front.primary, v19;\n"
"	DP4 R3.x, c4[12], v16;\n"
"	DP4 R3.y, c4[13], v16;\n"
"	DP4 R3.z, c4[14], v16;\n"
"	DP4 R3.w, c4[15], v16;\n"
"	DP4 R2.x, c4[8], v16;\n"
"	DP4 R2.y, c4[9], v16;\n"
"	DP4 R2.z, c4[10], v16;\n"
"	DP4 R2.w, c4[11], v16;\n"
"	DP4 R1.x, c4[0], v16;\n"
"	DP4 R1.y, c4[1], v16;\n"
"	DP4 R1.z, c4[2], v16;\n"
"	DP4 R1.w, c4[3], v16;\n"
"	DP4 R0.x, c4[4], v16;\n"
"	DP4 R0.y, c4[5], v16;\n"
"	DP4 R0.z, c4[6], v16;\n"
"	DP4 R0.w, c4[7], v16;\n"
"	MUL R0, R0, v24.y;\n"
"	MAD R0, R1, v24.x, R0;\n"
"	MAD R0, R2, v25.x, R0;\n"
"	MAD R0, R3, v25.y, R0;\n"
"	DP4 result.position.x, c0[0], R0;\n"
"	DP4 result.position.y, c0[1], R0;\n"
"	DP4 result.position.z, c0[2], R0;\n"
"	DP4 result.position.w, c0[3], R0;\n"
"END\n"
"# 25 instructions\n"
"# 4 temp registers\n"
"# End of program\n"
,
"vs_1_1\n"
"// DX9 Vertex shader generated by NVIDIA Cg compiler\n"
"// cgc version 1.1.0003, build date Mar  4 2003  12:32:10\n"
"// command line args: -q -profile vs_1_1 -entry vmain -profileopts dcls -strict\n"
"// nv30vp backend compiling 'vmain' program\n"
"//vendor NVIDIA Corporation\n"
"//version 1.0.02\n"
"//profile vs_1_1\n"
"//program vmain\n"
"//semantic vmain.Wm3TransformMVP\n"
"//semantic vmain.SkinningMat\n"
"//var float4 i_f4Position : $vin.POSITION : POSITION : 0 : 1\n"
"//var float4 i_f4Color : $vin.COLOR : COLOR : 1 : 1\n"
"//var float2 i_f2Weights0 : $vin.TEXCOORD0 : TEXCOORD0 : 2 : 1\n"
"//var float2 i_f2Weights1 : $vin.TEXCOORD1 : TEXCOORD1 : 3 : 1\n"
"//var float4 o_f4Position : $vout.POSITION : POSITION : 4 : 1\n"
"//var float4 o_f4Color : $vout.COLOR : COLOR : 5 : 1\n"
"//var float4x4 Wm3TransformMVP :  : c[0], 4 : 6 : 1\n"
"//var float4x4 SkinningMat[0] :  : c[4], 4 : 7 : 1\n"
"//var float4x4 SkinningMat[1] :  : c[8], 4 : 7 : 1\n"
"//var float4x4 SkinningMat[2] :  : c[12], 4 : 7 : 1\n"
"//var float4x4 SkinningMat[3] :  : c[16], 4 : 7 : 1\n"
"dcl_texcoord1 v8\n"
"dcl_texcoord0 v7\n"
"dcl_color v5\n"
"dcl_position v0\n"
"	mov oD0, v5\n"
"	dp4 r3.x, c16, v0\n"
"	dp4 r3.y, c17, v0\n"
"	dp4 r3.z, c18, v0\n"
"	dp4 r3.w, c19, v0\n"
"	dp4 r2.x, c12, v0\n"
"	dp4 r2.y, c13, v0\n"
"	dp4 r2.z, c14, v0\n"
"	dp4 r2.w, c15, v0\n"
"	dp4 r1.x, c4, v0\n"
"	dp4 r1.y, c5, v0\n"
"	dp4 r1.z, c6, v0\n"
"	dp4 r1.w, c7, v0\n"
"	dp4 r0.x, c8, v0\n"
"	dp4 r0.y, c9, v0\n"
"	dp4 r0.z, c10, v0\n"
"	dp4 r0.w, c11, v0\n"
"	mul r0, r0, v7.y\n"
"	mad r0, r1, v7.x, r0\n"
"	mad r0, r2, v8.x, r0\n"
"	mad r0, r3, v8.y, r0\n"
"	dp4 oPos.x, c0, r0\n"
"	dp4 oPos.y, c1, r0\n"
"	dp4 oPos.z, c2, r0\n"
"	dp4 oPos.w, c3, r0\n"
"// 25 instructions\n"
"// 4 temp registers\n"
"// End of program\n"
};



