Пример #1
0
        static MyVertexLayouts()
        {
            var id = new VertexLayoutId {
                Index = Layouts.Allocate()
            };

            HashIndex[0]           = id;
            Layouts.Data[id.Index] = new MyVertexLayoutInfo
            {
                Elements = new InputElement[0],
                Macros   = new ShaderMacro[0],
            };

            Empty = id;
        }
Пример #2
0
        internal static MyMeshMaterialId GetMaterialId(ref MyMeshMaterialInfo desc, string assetFile = null)
        {
            var rk = CalculateRK(ref desc);

            if (!MaterialRkIndex.ContainsKey(rk))
            {
                var id = MaterialRkIndex[rk] = new MyMeshMaterialId {
                    Index = MaterialsPool.Allocate()
                };

                desc.Id = id;
                desc.RepresentationKey = rk;

                MaterialsPool.Data[id.Index] = desc;
                MaterialProxyIndex[id]       = MyMaterials1.AllocateProxy();

                MaterialQueryResourcesTable.Add(id);

                MaterialNameIndex[desc.Name] = id;

                if (MERGABLE_MATERIAL_NAMES.Contains(desc.Name))
                {
                    MergableRKs.Add(desc.RepresentationKey);
                }

                else if (assetFile != null)
                {
                    VRageRender.MyRender11.Log.WriteLine(String.Format("Asset {0} tries to overrwrite material {1} with different textures", assetFile, desc.Name.ToString()));
                }

                return(id);
            }

            return(MaterialRkIndex[rk]);
        }
Пример #3
0
        internal static FlareId Update(int parentGID, FlareId flareId, MyFlareDesc desc)
        {
            if (desc.Enabled)
            {
                if (flareId == FlareId.NULL)
                {
                    flareId = new FlareId {
                        Index = m_flares.Allocate()
                    }
                }
                ;

                var gid = parentGID;
                if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
                {
                    var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

                    Vector3.TransformNormal(ref desc.Direction, ref matrix, out desc.Direction);
                }

                desc.MaxDistance = (desc.MaxDistance > 0)
                    ? (float)Math.Min(MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE, desc.MaxDistance)
                    : MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE;

                m_flares.Data[flareId.Index] = desc;
            }
            else if (flareId != FlareId.NULL)
            {
                m_flares.Free(flareId.Index);
                flareId = FlareId.NULL;
            }
            return(flareId);
        }
Пример #4
0
        internal unsafe static InstancingId Create(uint GID, MyRenderInstanceBufferType type, string debugName)
        {
            var id = new InstancingId {
                Index = Instancings.Allocate()
            };

            Instancings.Data[id.Index] = new MyInstancingInfo
            {
                Type      = type,
                DebugName = debugName
            };

            MyArrayHelpers.Reserve(ref Data, id.Index + 1);
            Data[id.Index] = new MyInstancingData {
                VB = VertexBufferId.NULL
            };

            if (type == MyRenderInstanceBufferType.Cube)
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.CUBE_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatCubeInstance);
            }
            else
            {
                Instancings.Data[id.Index].Layout = MyVertexLayouts.GetLayout(new MyVertexInputComponent(MyVertexInputComponentType.GENERIC_INSTANCE, 2, MyVertexInputComponentFreq.PER_INSTANCE));
                Instancings.Data[id.Index].Stride = sizeof(MyVertexFormatGenericInstance);
            }

            Debug.Assert(!IdIndex.ContainsKey(GID), "Creating instance with ID that already exists!");
            IdIndex.Add(GID, id);

            return(id);
        }
Пример #5
0
        internal static StructuredBufferId CreateStructuredBuffer(BufferDescription description, IntPtr?data, string debugName)
        {
            var id = new StructuredBufferId {
                Index = SBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref SBuffersData, id.Index + 1);
            SBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };
            SBuffersData[id.Index] = new MyStructuredBufferData {
            };

            SbIndices.Add(id);

            if (!data.HasValue)
            {
                InitStructuredBuffer(id);
            }
            else
            {
                InitStructuredBuffer(id, data.Value);
            }

            return(id);
        }
Пример #6
0
        internal static IndexBufferId CreateIndexBuffer(BufferDescription description, Format format, IntPtr?data, string debugName)
        {
            var id = new IndexBufferId {
                Index = IBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref IBuffersData, id.Index + 1);
            IBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };
            IBuffersData[id.Index] = new MyIndexBufferData {
                Format = format
            };

            IbIndices.Add(id);

            if (!data.HasValue)
            {
                InitIndexBuffer(id);
            }
            else
            {
                InitIndexBuffer(id, data.Value);
            }

            return(id);
        }
Пример #7
0
        internal static void Init()
        {
            var id = new VertexLayoutId {
                Index = Layouts.Allocate()
            };

            HashIndex[0]           = id;
            Layouts.Data[id.Index] = new MyVertexLayoutInfo
            {
                Elements           = new InputElement[0],
                SourceDeclarations = "struct __VertexInput { \n \n \n };",
                SourceDataMove     = ""
            };

            Empty = id;
        }
Пример #8
0
        internal static MyMeshMaterialId GetMaterialId(ref MyMeshMaterialInfo desc)
        {
            var rk = CalculateRK(ref desc);

            if (!MaterialRkIndex.ContainsKey(rk))
            {
                var id = MaterialRkIndex[rk] = new MyMeshMaterialId {
                    Index = MaterialsPool.Allocate()
                };

                desc.Id = id;
                desc.RepresentationKey = rk;

                MaterialsPool.Data[id.Index] = desc;
                MaterialProxyIndex[id]       = MyMaterials1.AllocateProxy();

                MaterialQueryResourcesTable.Add(id);

                var nameIndex = desc.Name;

                if (MERGABLE_MATERIAL_NAMES.Contains(nameIndex))
                {
                    MergableRKs.Add(desc.RepresentationKey);
                }

                MaterialNameIndex[nameIndex] = id;

                return(id);
            }

            return(MaterialRkIndex[rk]);
        }
Пример #9
0
        internal static VertexBufferId CreateVertexBuffer(BufferDescription description, int stride, IntPtr?data, string debugName)
        {
            if (description.SizeInBytes == 0)
            {
                return(VertexBufferId.NULL);
            }

            var id = new VertexBufferId {
                Index = VBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref VBuffersData, id.Index + 1);
            VBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };
            VBuffersData[id.Index] = new MyVertexBufferData {
                Stride = stride
            };

            VbIndices.Add(id);

            if (!data.HasValue)
            {
                InitVertexBuffer(id);
            }
            else
            {
                InitVertexBuffer(id, data.Value);
            }

            return(id);
        }
Пример #10
0
        internal static ComputeShaderId CreateCs(string file, string func, string header = "")
        {
            var bytecode = CreateBytecode();

            var id = new ComputeShaderId {
                Index = ComputeShaders.Allocate()
            };

            ComputeShaders.Data[id.Index] = new MyShaderInfo
            {
                Bytecode = bytecode
            };
            MyArrayHelpers.Reserve(ref CsObjects, id.Index + 1);

            // compile at once

            Shaders[bytecode] = new MyShaderCompilationInfo
            {
                File     = X.TEXT(file),
                Function = X.TEXT(func),
                Profile  = MyShaderProfileEnum.CS_5_0,
                Header   = header,
                Name     = String.Format("cs_[{0}][{1}]{2}", file, func, header != null ? header.Replace(Environment.NewLine, "_") : "")
            };

            CsObjects[id.Index] = null;

            InitCs(id);
            CsIndex.Add(id);

            return(id);
        }
Пример #11
0
        internal static MyMaterialShadersBundleId Get(MyStringId material, MyStringId materialPass, VertexLayoutId vertexLayout, MyShaderUnifiedFlags flags)
        {
            int hash = 0;

            MyHashHelper.Combine(ref hash, material.GetHashCode());
            MyHashHelper.Combine(ref hash, materialPass.GetHashCode());
            MyHashHelper.Combine(ref hash, vertexLayout.GetHashCode());
            MyHashHelper.Combine(ref hash, unchecked ((int)flags));

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

            var id = new MyMaterialShadersBundleId {
                Index = BundleInfo.Allocate()
            };

            MyArrayHelpers.Reserve(ref Bundles, id.Index + 1);

            HashIndex[hash]           = id;
            BundleInfo.Data[id.Index] = new MyMaterialShadersInfo
            {
                Material = material,
                Pass     = materialPass,
                Layout   = vertexLayout,
                Flags    = flags
            };
            Bundles[id.Index] = new MyMaterialShadersBundle {
            };

            InitBundle(id);

            return(id);
        }
Пример #12
0
        internal static LightId Create(uint GID)
        {
            var id = new LightId {
                Index = Lights.Allocate()
            };

            Lights.Data[id.Index] = new MyLightInfo
            {
            };

            MyArrayHelpers.Reserve(ref Pointlights, id.Index + 1);
            MyArrayHelpers.Reserve(ref Spotlights, id.Index + 1);

            Pointlights[id.Index] = new MyPointlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId            = -1
            };

            Spotlights[id.Index] = new MySpotlightInfo
            {
                LastBvhUpdatePosition = Vector3.PositiveInfinity,
                BvhProxyId            = -1
            };

            IdIndex[GID] = id;

            return(id);
        }
Пример #13
0
        static ShaderBytecodeId CreateBytecode()
        {
            var id = new ShaderBytecodeId {
                Index = Bytecodes.Allocate()
            };

            return(id);
        }
Пример #14
0
        internal static RasterizerId CreateRasterizerState(RasterizerStateDescription description)
        {
            var id = new RasterizerId {
                Index = RasterizerStates.Allocate()
            };

            MyArrayHelpers.Reserve(ref RasterizerObjects, id.Index + 1);

            RasterizerStates.Data[id.Index] = description;

            InitRasterizerState(id);
            RasterizerIndices.Add(id);

            return(id);
        }
Пример #15
0
        internal static SamplerId CreateSamplerState(SamplerStateDescription description)
        {
            var id = new SamplerId {
                Index = SamplerStates.Allocate()
            };

            MyArrayHelpers.Reserve(ref SamplerObjects, id.Index + 1);

            SamplerStates.Data[id.Index] = description;

            InitSamplerState(id);
            SamplerIndices.Add(id);

            return(id);
        }
Пример #16
0
        internal static DepthStencilId CreateDepthStencil(DepthStencilStateDescription description)
        {
            var id = new DepthStencilId {
                Index = DepthStencilStates.Allocate()
            };

            MyArrayHelpers.Reserve(ref DepthStencilObjects, id.Index + 1);

            DepthStencilStates.Data[id.Index] = description;

            InitDepthStencilState(id);
            DepthStencilIndices.Add(id);

            return(id);
        }
Пример #17
0
        internal static BlendId CreateBlendState(BlendStateDescription description)
        {
            var id = new BlendId {
                Index = BlendStates.Allocate()
            };

            MyArrayHelpers.Reserve(ref BlendObjects, id.Index + 1);

            BlendStates.Data[id.Index] = description.Clone();

            InitBlendState(id);
            BlendIndices.Add(id);

            return(id);
        }
Пример #18
0
        internal static FlareId Set(FlareId flareId, MyFlareDesc desc)
        {
            if (desc.Enabled)
            {
                if (flareId == FlareId.NULL)
                {
                    flareId = new FlareId {
                        Index = m_flares.Allocate()
                    };
                }
                if (Math.Abs(desc.Intensity) > 0.01f)
                {
                    if (m_flares.Data[flareId.Index].Query == null)
                    {
                        m_flares.Data[flareId.Index].Query = MyOcclusionQueryRenderer.Get(desc.Material.ToString());
                    }
                }
                else if (m_flares.Data[flareId.Index].Query != null)
                {
                    MyOcclusionQueryRenderer.Remove(m_flares.Data[flareId.Index].Query);
                    m_flares.Data[flareId.Index].Query = null;
                }

                if (desc.MaxDistance > 0)
                {
                    if (m_flares.Data[flareId.Index].Desc.Type != Lights.MyGlareTypeEnum.Distant)
                    {
                        desc.MaxDistance = Math.Min(MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE, desc.MaxDistance);
                    }
                }
                else
                {
                    desc.MaxDistance = MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE;
                }

                m_flares.Data[flareId.Index].Desc = desc;
                if (desc.ParentGID == -1)
                {
                    m_flares.Data[flareId.Index].DirectionWorld = desc.Direction;
                }
            }
            else
            {
                Remove(flareId);
                flareId = FlareId.NULL;
            }
            return(flareId);
        }
Пример #19
0
        internal static ConstantsBufferId CreateConstantsBuffer(BufferDescription description, string debugName)
        {
            var id = new ConstantsBufferId {
                Index = CBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref CBuffersData, id.Index + 1);
            CBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };

            CbIndices.Add(id);
            InitConstantsBuffer(id);

            return(id);
        }
Пример #20
0
        public static void CreateBlendState(ref BlendId id, BlendStateDescription description)
        {
            if (id == BlendId.NULL)
            {
                id = new BlendId(BlendStates.Allocate());
                MyArrayHelpers.Reserve(ref BlendObjects, id.Index + 1);
                BlendIndices.Add(id);
            }
            else
            {
                BlendObjects[id.Index].Dispose();
            }

            BlendStates.Data[id.Index] = description.Clone();
            InitBlendState(id);
        }
Пример #21
0
        public static void CreateDepthStencil(ref DepthStencilId id, DepthStencilStateDescription description)
        {
            if (id == DepthStencilId.NULL)
            {
                id = new DepthStencilId(DepthStencilStates.Allocate());
                MyArrayHelpers.Reserve(ref DepthStencilObjects, id.Index + 1);
                DepthStencilIndices.Add(id);
            }
            else
            {
                DepthStencilObjects[id.Index].Dispose();
            }

            DepthStencilStates.Data[id.Index] = description;
            InitDepthStencilState(id);
        }
Пример #22
0
        internal static void AddDecal(uint ID, uint ParentID, Matrix localOBB)
        {
            var handle = Decals.Allocate();

            Decals.Data[handle].ID       = ID;
            Decals.Data[handle].ParentID = ParentID;
            Decals.Data[handle].LocalOBB = localOBB;

            IdIndex[ID] = handle;

            if (!EntityDecals.ContainsKey(ParentID))
            {
                EntityDecals[ParentID] = new List <int>();
            }
            EntityDecals[ParentID].Add(handle);
        }
Пример #23
0
        internal static void Create(uint GID)
        {
            var id = new GPUEmitterId {
                Index = m_emitters.Allocate()
            };

            MyRenderProxy.Assert(m_freeBufferIndices.Count > 0, "Too many live emitters!");

            m_emitters.Data[id.Index] = new MyLiveData
            {
                BufferIndex = m_freeBufferIndices.Dequeue(),
                TextureId   = Resources.TexId.NULL,
                DieAt       = float.MaxValue
            };

            m_idIndex[GID] = id;
        }
Пример #24
0
        internal static void AddDecal(uint ID, uint ParentID, Matrix localOBB, string material)
        {
            var handle = Decals.Allocate();

            Decals.Data[handle].ID       = ID;
            Decals.Data[handle].ParentID = ParentID;
            Decals.Data[handle].LocalOBB = localOBB;
            Decals.Data[handle].Material = MyStringId.GetOrCompute(material);

            IdIndex[ID] = handle;

            if (!EntityDecals.ContainsKey(ParentID))
            {
                EntityDecals[ParentID] = new List <int>();
            }
            EntityDecals[ParentID].Add(handle);

            Debug.Assert(MyIDTracker <MyActor> .FindByID(ParentID) != null, "Decal added to non-existing render entity");
        }
Пример #25
0
        internal static InputLayoutId CreateIL(ShaderBytecodeId bytecode, VertexLayoutId layout)
        {
            var id = new InputLayoutId {
                Index = InputLayouts.Allocate()
            };

            MyArrayHelpers.Reserve(ref ILObjects, id.Index + 1);

            InputLayouts.Data[id.Index] = new InputLayoutInfo
            {
                BytecodeId = bytecode,
                VLayoutId  = layout
            };

            ILObjects[id.Index] = null;

            InitIL(id);
            ILIndex.Add(id);

            return(id);
        }
Пример #26
0
        internal void AddEntity(uint ID, MeshId model)
        {
            var instanceIndex = m_perInstance.Allocate();

            m_entities[ID] = new MyInstanceInfo {
                InstanceIndex = instanceIndex, PageHandles = new List <MyPackedPoolHandle>()
            };

            foreach (var id in m_meshTable.Pages(MyMeshTableSRV.MakeKey(model)))
            {
                var pageHandle = m_instancingTable.Allocate();

                m_instancingTable.Data[m_instancingTable.AsIndex(pageHandle)] = new MyInstancingTableEntry {
                    InstanceId = instanceIndex, InnerMeshId = id
                };
                m_entities[ID].PageHandles.Add(pageHandle);
            }

            m_perInstance.Data[instanceIndex] = MyPerInstanceData.FromWorldMatrix(ref MatrixD.Zero);

            m_tablesDirty = true;
        }
Пример #27
0
        internal void AddEntity(MyActor actor, MeshId model)
        {
            uint ID            = actor.ID;
            var  instanceIndex = m_perInstance.Allocate();
            var  entityIndex   = m_entityInfos.Allocate();

            Debug.Assert(instanceIndex == entityIndex);

            m_entities[ID] = new MyInstanceInfo {
                InstanceIndex = instanceIndex, PageHandles = new List <MyPackedPoolHandle>()
            };

            int pageOffset = -1;
            var key        = MyMeshTableSrv.MakeKey(model);

            foreach (var id in m_meshTable.Pages(key))
            {
                if (pageOffset == -1)
                {
                    pageOffset = id;
                }

                var pageHandle = m_instancingTable.Allocate();

                m_instancingTable.Data[m_instancingTable.AsIndex(pageHandle)] = new MyInstancingTableEntry {
                    InstanceId = instanceIndex, InnerMeshId = id
                };

                m_entities[ID].PageHandles.Add(pageHandle);
            }

            m_perInstance.Data[instanceIndex] = MyPerInstanceData.FromWorldMatrix(ref MatrixD.Zero, 0);
            m_entityInfos.Data[instanceIndex] = new MyInstanceEntityInfo {
                EntityId = ID, PageOffset = pageOffset
            };

            m_tableDirty = true;
        }
Пример #28
0
        internal static GeometryShaderId CreateGs(string file, string func, string header = "", MyShaderStreamOutputInfo?streamOut = null)
        {
            var bytecode = CreateBytecode();

            var id = new GeometryShaderId {
                Index = GeometryShaders.Allocate()
            };

            GeometryShaders.Data[id.Index] = new MyShaderInfo
            {
                Bytecode = bytecode
            };
            MyArrayHelpers.Reserve(ref GsObjects, id.Index + 1);

            // compile at once

            Shaders[bytecode] = new MyShaderCompilationInfo
            {
                File     = X.TEXT(file),
                Function = X.TEXT(func),
                Profile  = MyShaderProfileEnum.GS_5_0,
                Header   = header,
                Name     = String.Format("gs_[{0}][{1}]{2}", file, func, header != null ? header.Replace(Environment.NewLine, "_") : "")
            };

            GsObjects[id.Index] = null;

            if (streamOut.HasValue)
            {
                StreamOutputs[id] = streamOut.Value;
            }

            InitGs(id);
            GsIndex.Add(id);

            return(id);
        }
Пример #29
0
        internal static FlareId Update(FlareId flareId, MyFlareDesc desc)
        {
            if (desc.Enabled)
            {
                if (flareId == FlareId.NULL)
                {
                    flareId = new FlareId {
                        Index = m_flares.Allocate()
                    };
                }

                desc.MaxDistance = (desc.MaxDistance > 0)
                    ? (float)Math.Min(MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE, desc.MaxDistance)
                    : MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE;

                m_flares.Data[flareId.Index] = desc;
            }
            else if (flareId != FlareId.NULL)
            {
                m_flares.Free(flareId.Index);
                flareId = FlareId.NULL;
            }
            return(flareId);
        }
Пример #30
0
 internal static MyMaterialProxyId AllocateProxy()
 {
     return(new MyMaterialProxyId {
         Index = ProxyPool.Allocate()
     });
 }