14 typedef u64 SortKeyValue;
16 static const u32 LayerFieldWidth = 6;
17 static const u32 LayerFieldShift = 58;
18 static const u64 LayerFieldMask = ((((u64)1) << LayerFieldWidth) - 1);
19 static const SortKeyValue LayerFieldInPlaceMask = (LayerFieldMask << LayerFieldShift);
20 static const SortKeyValue LayerFieldInPlaceInverseMask = (~LayerFieldInPlaceMask);
22 static const u32 UserDefinedFieldWidth = 8;
23 static const u32 UserDefinedFieldShift = 50;
24 static const u64 UserDefinedFieldMask = ((((u64)1) << UserDefinedFieldWidth) - 1);
25 static const SortKeyValue UserDefinedInPlaceMask = (UserDefinedFieldMask << UserDefinedFieldShift);
26 static const SortKeyValue UserDefinedInPlaceInverseMask = (~UserDefinedInPlaceMask);
28 static const u32 TranslucencyTypeFieldWidth = 2;
29 static const u32 TranslucencyTypeFieldShift = 48;
30 static const u64 TranslucencyTypeFieldMask = ((((u64)1) << TranslucencyTypeFieldWidth) - 1);
31 static const SortKeyValue TranslucencyTypeFieldInPlaceMask = (TranslucencyTypeFieldMask << TranslucencyTypeFieldShift);
32 static const SortKeyValue TranslucencyTypeFieldInPlaceInverseMask = (~TranslucencyTypeFieldInPlaceMask);
34 static const u32 DepthFieldWidth = 24;
35 static const u32 DepthFieldShift = 24;
36 static const u64 DepthFieldMask = ((((u64)1) << DepthFieldWidth) - 1);
37 static const SortKeyValue DepthFieldInPlaceMask = (DepthFieldMask << DepthFieldShift);
38 static const SortKeyValue DepthFieldInPlaceInverseMask = (~DepthFieldInPlaceMask);
40 static const u32 ShaderProgramFieldWidth = 8;
41 static const u32 ShaderProgramFieldShift = 16;
42 static const u64 ShaderProgramFieldMask = ((((u64)1) << ShaderProgramFieldWidth) - 1);
43 static const SortKeyValue ShaderProgramFieldInPlaceMask = (ShaderProgramFieldMask << ShaderProgramFieldShift);
44 static const SortKeyValue ShaderProgramFieldInPlaceInverseMask = (~ShaderProgramFieldInPlaceMask);
46 static const u32 MaterialFieldWidth = 11;
47 static const u32 MaterialFieldShift = 5;
48 static const u64 MaterialFieldMask = ((((u64)1) << MaterialFieldWidth) - 1);
49 static const SortKeyValue MaterialFieldInPlaceMask = (MaterialFieldMask << MaterialFieldShift);
50 static const SortKeyValue MaterialFieldInPlaceInverseMask = (~MaterialFieldInPlaceMask);
54 static const u64 MaxLayerValue = LayerFieldMask;
55 static const u64 MaxTranslucencyValue = TranslucencyTypeFieldMask;
56 static const u64 MaxShaderProgramValue = ShaderProgramFieldMask;
57 static const u64 MaxMaterialValue = MaterialFieldMask;
58 static const u64 MaxDepthValue = DepthFieldMask;
65 inline void SetUserDefined(u64 userDefined)
67 Eegeo_ASSERT(userDefined <= UserDefinedFieldMask,
"user defined %ld is greater than maximum allowed value %ld", userDefined, UserDefinedFieldMask);
68 m_key = (m_key & UserDefinedInPlaceInverseMask) | (userDefined << UserDefinedFieldShift);
71 inline u64 GetUserDefined()
const
73 return ((m_key & UserDefinedInPlaceMask) >> UserDefinedFieldShift);
76 inline void SetLayer(u64 layer)
78 Eegeo_ASSERT(layer <= LayerFieldMask,
"layer %ld is greater than maximum allowed value %ld", layer, LayerFieldMask);
79 m_key = (m_key & LayerFieldInPlaceInverseMask) | (layer << LayerFieldShift);
82 inline u64 GetLayer()
const
84 return ((m_key & LayerFieldInPlaceMask) >> LayerFieldShift);
87 inline void SetTranslucencyType(u64 translucencyType)
89 Eegeo_ASSERT(translucencyType <= TranslucencyTypeFieldMask,
"translucencyType %ld is greater than maximum allowed value %ld", translucencyType, TranslucencyTypeFieldMask);
90 m_key = (m_key & TranslucencyTypeFieldInPlaceInverseMask) | (translucencyType << TranslucencyTypeFieldShift);
93 inline u64 GetTranslucencyType()
const
95 return ((m_key & TranslucencyTypeFieldInPlaceMask) >> TranslucencyTypeFieldShift);
98 inline void SetShaderProgram(u64 shaderProgram)
100 Eegeo_ASSERT(shaderProgram <= ShaderProgramFieldMask);
101 m_key = (m_key & ShaderProgramFieldInPlaceInverseMask) | (shaderProgram << ShaderProgramFieldShift);
104 inline u64 GetShaderProgram()
const
106 return ((m_key & ShaderProgramFieldInPlaceMask) >> ShaderProgramFieldShift);
109 inline void SetMaterial(u64 materialId)
111 Eegeo_ASSERT(materialId <= MaterialFieldMask);
112 m_key = (m_key & MaterialFieldInPlaceInverseMask) | (materialId << MaterialFieldShift);
115 inline u64 GetMaterial()
const
117 return ((m_key & MaterialFieldInPlaceMask) >> MaterialFieldShift);
120 inline void SetDepth(u64 depth)
122 Eegeo_ASSERT(depth <= DepthFieldMask,
"depth index %ld is greater than maximum allowed value %ld", depth, DepthFieldMask);
123 m_key = (m_key & DepthFieldInPlaceInverseMask) | (depth << DepthFieldShift);
126 inline u64 GetDepth()
const
128 return ((m_key & DepthFieldInPlaceMask) >> DepthFieldShift);
131 inline SortKeyValue GetKey()
const
136 inline bool operator< (
const SortKey &otherKey)
const
138 return m_key < otherKey.m_key;
141 inline bool operator!= (
const SortKey &otherKey)
const
143 return m_key != otherKey.m_key;
146 static std::string ToString(
const SortKey& key)
148 std::stringstream stream;
150 stream <<
"Lyer:" << key.GetLayer() <<
"\tUD:" << key.GetUserDefined() <<
"\tTrns:" << key.GetTranslucencyType() <<
"\tShdr:" << key.GetShaderProgram() <<
"\tMtl:" << key.GetMaterial() <<
"\tDep:" << key.GetDepth();