Exemplo n.º 1
0
        public void Compute(IDrawableGroupStrategy drawableGroupStrategy, List <MyInstanceComponent> visibleInstances, int passId, int maxLodId)
        {
            int drawnLodsCount, sumInstanceMaterials;

            PrecomputeCounts(out sumInstanceMaterials, out drawnLodsCount, ref m_tmpInstancesCounts, visibleInstances, passId, maxLodId);
            drawableGroupStrategy.Init(drawnLodsCount + sumInstanceMaterials);
            PrepareDrawableContainers(ref m_rawDrawableGroups, ref m_tmpInstancesOffsets, drawableGroupStrategy,
                                      m_tmpInstancesCounts, visibleInstances, passId, maxLodId);
        }
Exemplo n.º 2
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;
                }
            }
        }