public bool AddDrawCommand(GlobalGeometryPartBlockNew part, Bucket sourceBucket, InstanceInfo instanceInfo)
        {
            var primitiveType =
                part.GlobalGeometryPartNewFlags.HasFlag(
                    GlobalGeometryPartBlockNew.Flags.OverrideTriangleList)
                    ? PrimitiveType.Triangles
                    : PrimitiveType.TriangleStrip;

            if (primitiveType != PrimitiveType)
            {
                return(false);
            }
            if (sourceBucket != SourceBucket)
            {
                return(false);
            }

            var locations = sourceBucket[part];
            var command   = new DrawIndirectCmd(
                part.StripLength,
                instanceInfo.Count,
                // Divide by two because this is an offset and we need an index
                locations.IndexBaseOffset / sizeof(ushort) + part.StripStartIndex,
                locations.VertexBaseOffset,
                instanceInfo.BaseInstance);

            CommandBuffers.Add(command);
            return(true);
        }
Ejemplo n.º 2
0
        public void AssignShader(GlobalGeometryPartBlockNew part, CacheKey cacheKey, TagIdent shaderIdent)
        {
            var glocalKey = new TagGlobalKey(cacheKey, shaderIdent);

            //  Does this work now?
            _shaderDictionary[part] = glocalKey;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates an instance object for the given part
        /// </summary>
        /// <param name="part">The part to be instanced</param>
        /// <param name="instance">The instance data</param>
        /// <remarks>
        /// i.   Every part many be instanced zero or many times
        /// ii.  Instances should refer to a collection of parts
        /// iii. Instance data is linked to a single instance
        /// </remarks>
        public void CreateInstance(GlobalGeometryPartBlockNew part, IH2ObjectInstance instance,
                                   bool supportsPermutations)
        {
            // 1. Check if the part is already in dictionary and initialize it into the dictionary if not
            HashSet <InstanceKey> instances;

            if (!PartInstances.TryGetValue(part, out instances))
            {
                // Initialize a collection of instance identifiers
                instances = new HashSet <InstanceKey>( );
                PartInstances.Add(part, instances);
            }
            // 2. Check to see if this instance has already been added
            InstanceKey key;

            if (!InstanceKeys.TryGetValue(instance, out key))
            {
                // (a) Create a key for the new instance and (b) link the key with the instance
                key = CreateInstanceKey( );
                InstanceKeys.Add(instance, key);
                // (c) Link the key with the intance data
                InstanceData.Add(key, new InstanceData(instance, supportsPermutations));
            }
            // 3. Check to see if the part is already linked with the instance
            instances.Add(key);
        }
Ejemplo n.º 4
0
 public void AddInstances(GlobalGeometryPartBlockNew part, IEnumerable <Matrix4> instanceWorldMatrices)
 {
     if (!Instances.ContainsKey(part))
     {
         Instances[part] = new List <Matrix4>(instanceWorldMatrices);
         return;
     }
     Instances[part].AddRange(instanceWorldMatrices);
 }
Ejemplo n.º 5
0
        public Bucket GetBucketResource(GlobalGeometryPartBlockNew part, out int indexBaseOffset,
                                        out int vertexBaseOffset)
        {
            var bucket    = _buckets.Single(u => u.Contains(part));
            var locations = bucket.GetBufferLocation(part);

            indexBaseOffset  = locations.IndexBaseOffset;
            vertexBaseOffset = locations.VertexBaseOffset;
            return(bucket);
        }
Ejemplo n.º 6
0
        public InstanceData[] GetInstancesOf(GlobalGeometryPartBlockNew part)
        {
            var instanceDatum = new InstanceData[PartInstances[part].Count];
            int index         = 0;

            foreach (var instanceKey in PartInstances[part])
            {
                instanceDatum[index++] = InstanceData[instanceKey];
            }
            return(instanceDatum);
        }
Ejemplo n.º 7
0
        public bool RemoveInstance(GlobalGeometryPartBlockNew part, dynamic instance)
        {
            if (!PartInstances.ContainsKey(part))
            {
                return(false);
            }
            if (!InstanceKeys.ContainsKey(instance))
            {
                return(false);
            }

            var key = InstanceKeys[instance];

            if (!PartInstances[part].Contains(key))
            {
                return(false);
            }
            PartInstances[part].Remove(key);
            return(true);
        }
Ejemplo n.º 8
0
 public InstanceInfo this[GlobalGeometryPartBlockNew key]
 {
     get { return(InstanceInfos[key]); }
 }
Ejemplo n.º 9
0
 public void RemoveInstance(GlobalGeometryPartBlockNew part, dynamic instance)
 {
     InstanceManager.RemoveInstance(part, instance);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Creates an instance object for the given part
 /// </summary>
 /// <param name="part">The part to be instanced</param>
 /// <param name="instance">The instance data</param>
 public void CreateInstance(GlobalGeometryPartBlockNew part, IH2ObjectInstance instance,
                            bool supportsPermutations)
 {
     InstanceManager.CreateInstance(part, instance, supportsPermutations);
 }
Ejemplo n.º 11
0
 public Bucket GetBucketResource(GlobalGeometryPartBlockNew part)
 {
     return(_buckets.Single(u => u.Contains(part)));
 }
Ejemplo n.º 12
0
 public int GetInstanceCount(GlobalGeometryPartBlockNew part)
 {
     return(PartInstances[part].Count);
 }
Ejemplo n.º 13
0
 public PatchData(GlobalGeometryPartBlockNew part, InstanceData data)
 {
     Part = part;
     Data = data;
 }