Beispiel #1
0
        static void PrepareDrawableContainers(ref List <MyRawDrawableGroup> out_drawableGroups, ref MyInstancesCounters out_instancesGroupOffset,
                                              IDrawableGroupStrategy strategy, MyInstancesCounters precalcCounts, List <MyInstanceComponent> visibleInstances, int passId, int maxLodId)
        {
            MyRenderProxy.Assert(strategy != null);
            out_drawableGroups.Clear();
            out_instancesGroupOffset.PrepareByNegativeOnes(maxLodId);

            int groupsCount          = 0;
            int instanceBufferOffset = 0;

            foreach (var instance in visibleInstances)
            {
                int lodsCount = instance.GetLodsCount(passId);
                for (int i = 0; i < lodsCount; i++)
                {
                    // get info about current instanced lod:
                    MyLod lod;
                    MyInstanceLodState state;
                    float stateData;
                    instance.GetLod(passId, i, out lod, out state, out stateData);
                    int lodId        = lod.UniqueId;
                    int directOffset = out_instancesGroupOffset.GetDirectOffset(lodId, state);

                    // if the lod group is not added into the output, add it
                    if (out_instancesGroupOffset.At(lodId, state) == -1)
                    {
                        MyRenderProxy.Assert(groupsCount == out_drawableGroups.Count,
                                             "The values are different, internal error");
                        out_instancesGroupOffset.SetAt(lodId, state, groupsCount);

                        int instancesCount = precalcCounts.At(lodId, state);
                        MyRawDrawableGroup rawDrawableGroup = new MyRawDrawableGroup
                        {
                            Lod   = lod,
                            State = state,
                            OffsetInInstanceBuffer = instanceBufferOffset,
                            InstancesCount         = instancesCount,
                            InstancesIncrement     = 0,
                            InstanceMaterialsCount = lod.InstanceMaterialsCount,
                        };
                        out_drawableGroups.Add(rawDrawableGroup);

                        instanceBufferOffset += instancesCount * (1 + lod.InstanceMaterialsCount);
                        groupsCount++;
                    }

                    // Fill data:
                    int groupOffset          = out_instancesGroupOffset.AtByDirectOffset(directOffset);
                    MyRawDrawableGroup group = out_drawableGroups[groupOffset];
                    int bufferOffset         = group.OffsetInInstanceBuffer + group.InstancesIncrement;
                    int multiTransformCount  = instance.GetMultiTransformCount();
                    for (int multiTransformI = 0; multiTransformI < multiTransformCount; multiTransformI++)
                    {
                        strategy.Fill(bufferOffset + multiTransformI, instance, lod, multiTransformI, -1, state,
                                      stateData);
                    }
                    List <int> instanceMaterialDataOffsets = lod.GetInstanceMaterialDataOffsets();
                    for (int instanceMaterialOffsetInLod = 0;
                         instanceMaterialOffsetInLod < lod.InstanceMaterialsCount;
                         instanceMaterialOffsetInLod++)
                    {
                        bufferOffset = group.OffsetInInstanceBuffer + group.InstancesIncrement +
                                       group.InstancesCount * (instanceMaterialOffsetInLod + 1);
                        int instanceMaterialDataOffset = instanceMaterialDataOffsets[instanceMaterialOffsetInLod];
                        for (int multiTransformI = 0; multiTransformI < multiTransformCount; multiTransformI++)
                        {
                            strategy.Fill(bufferOffset + multiTransformI, instance, lod, multiTransformI,
                                          instanceMaterialDataOffset, state, stateData);
                        }
                    }

                    // Update group data:
                    group.InstancesIncrement       += multiTransformCount;
                    out_drawableGroups[groupOffset] = group;
                }
            }
        }
Beispiel #2
0
        static void PrecomputeCounts(out int out_sumInstanceMaterials, out int out_drawnLodsCount, ref MyInstancesCounters out_counters, List <MyInstanceComponent> visibleInstances, int passId, int maxLodId)
        {
            out_drawnLodsCount       = 0;
            out_sumInstanceMaterials = 0;
            out_counters.PrepareByZeroes(maxLodId);

            foreach (var instance in visibleInstances)
            {
                for (int i = 0; i < instance.GetLodsCount(passId); i++)
                {
                    MyLod lod;
                    MyInstanceLodState state;
                    float stateData;
                    instance.GetLod(passId, i, out lod, out state, out stateData);
                    int multiTransformCount = instance.GetMultiTransformCount();

                    out_counters.Add(lod.UniqueId, state, multiTransformCount);
                    out_sumInstanceMaterials += lod.InstanceMaterialsCount * multiTransformCount;
                    out_drawnLodsCount       += multiTransformCount;
                }
            }
        }