Ejemplo n.º 1
0
        internal static VertexLayoutId GetLayout(params MyVertexInputComponent[] components)
        {
            if (components == null || components.Length == 0)
            {
                return(Empty);
            }

            var hash = 0;

            foreach (var c in components)
            {
                MyHashHelper.Combine(ref hash, c.GetHashCode());
            }

            if (HashIndex.ContainsKey(hash))
            {
                return(HashIndex[hash]);
            }

            var id = new VertexLayoutId {
                Index = Layouts.Allocate()
            };

            HashIndex[hash] = id;

            var declarationBuilder = new StringBuilder();
            var sourceBuilder      = new StringBuilder();
            var semanticDict       = new Dictionary <string, int>();

            // Might save some allocations when each AddComponent only adds one element as then we can use GetInternalArray and Capacity set does nothing
            var elementsList = new List <InputElement>(components.Length);

            foreach (var component in components)
            {
                MyVertexInputLayout.m_mapComponent[component.Type].AddComponent(component, elementsList, semanticDict, declarationBuilder, sourceBuilder);
            }

            elementsList.Capacity = elementsList.Count;
            Debug.Assert(elementsList.Count == elementsList.Capacity);

            Layouts.Data[id.Index] = new MyVertexLayoutInfo {
                Components   = components,
                Elements     = elementsList.GetInternalArray(),
                Macros       = MyComponent.GetComponentMacros(declarationBuilder.ToString(), sourceBuilder.ToString()),
                HasBonesInfo = components.Any(x => x.Type == MyVertexInputComponentType.BLEND_INDICES)
            };

            return(id);
        }
Ejemplo n.º 2
0
        private void Build()
        {
            var declarationBuilder = new StringBuilder();
            var sourceBuilder      = new StringBuilder();
            var elementsList       = new List <InputElement>();
            var semanticDict       = new Dictionary <string, int>();

            foreach (var component in m_components)
            {
                m_mapComponent[component.Type].AddComponent(component, elementsList, semanticDict, declarationBuilder, sourceBuilder);
            }

            m_elements = elementsList.ToArray();
            m_macros   = MyComponent.GetComponentMacros(declarationBuilder.ToString(), sourceBuilder.ToString());
        }