当前位置: 首页>>代码示例>>C#>>正文


C# Device.ResetStreamSourceFrequency方法代码示例

本文整理汇总了C#中Device.ResetStreamSourceFrequency方法的典型用法代码示例。如果您正苦于以下问题:C# Device.ResetStreamSourceFrequency方法的具体用法?C# Device.ResetStreamSourceFrequency怎么用?C# Device.ResetStreamSourceFrequency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.ResetStreamSourceFrequency方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderXMeshesWithInstancing


//.........这里部分代码省略.........
            foreach (SlimDX.Direct3D9.Mesh mesh in meshes.Keys)
            {
                device.Indices = meshes[mesh].IndexBuffer;

                foreach (Texture texture in meshes[mesh].Textures.Keys)
                {
                    bool first = true;
                    int numberOfInstancedDraws = 0;

                    DataStream ds = null;

                    foreach (Common.Tuple<Graphics.Content.Model9, Entity, string> renderObject in meshes[mesh].Textures[texture].RenderObjects)
                    {
                        Entity entity = renderObject.Second;

                        if (entity.ActiveInMain == Frame)
                        {
                            if (first)
                            {
                                MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);

                                //if (Settings.PriorityRelation[metaModel.Visible] + Settings.TerrainQualityPriorityRelation[Settings.TerrainQuality] < 3)
                                //    break;

                                effect.SetTexture(EHTexture, texture);
                                ds = optimizedVB[k % optimizedVB.Length].Lock(0, meshes[mesh].Textures[texture].RenderObjects.Count * (Vector4.SizeInBytes * 4), LockFlags.None);

                                if (renderObject.First.SpecularTexture != null)
                                    effect.SetTexture(EHSpecularMap, renderObject.First.SpecularTexture);

                                UpdateEffectWithMetaModel(effect, metaModel, false);

                                effect.CommitChanges();
                                first = false;
                            }

                            Matrix worldMatrix;
                            //Matrix normalMatrix;

                            if (renderObject.First.SkinnedMesh != null)
                            {
                                Matrix[] storedMatrices =
                                    GetLatestMetaModel(renderObject.Second, renderObject.Third).StoredFrameMatrices[mesh][0];
                                worldMatrix = storedMatrices[0];
                                //normalMatrix = storedMatrices.Second[0];
                            }
                            else
                            {
                                MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);
                                worldMatrix = metaModel.GetWorldMatrix(Scene.Camera, renderObject.Second);
                                //normalMatrix = Matrix.Transpose(Matrix.Invert(worldMatrix));
                            }

                            ds.Write(worldMatrix);

                            //ThreeTimesThreeMatrix matrix;

                            //matrix.M11 = normalMatrix.M11;
                            //matrix.M12 = normalMatrix.M12;
                            //matrix.M13 = normalMatrix.M13;
                            //matrix.M21 = normalMatrix.M21;
                            //matrix.M22 = normalMatrix.M22;
                            //matrix.M23 = normalMatrix.M23;
                            //matrix.M31 = normalMatrix.M31;
                            //matrix.M32 = normalMatrix.M32;
                            //matrix.M33 = normalMatrix.M33;
                            //ds.Write(matrix);

                            numberOfInstancedDraws++;
                        }
                    }

            #if RENDERER_STATISTICS
                    if (maxNumberOfInstancedDrawCalls < numberOfInstancedDraws)
                        maxNumberOfInstancedDrawCalls = numberOfInstancedDraws;
                    if (minNumberOfInstancedDrawCalls > numberOfInstancedDraws)
                        minNumberOfInstancedDrawCalls = numberOfInstancedDraws;
            #endif

                    if (numberOfInstancedDraws == 0)
                        continue;

                    optimizedVB[k % optimizedVB.Length].Unlock();

                    DrawInstancedIndexedPrimitives(device, mesh, meshes[mesh].VertexBuffer, optimizedVB[k % optimizedVB.Length], instancedVertexElements,
                            numberOfInstancedDraws);

                    k++;
                }
            }

            effect.EndPass();
            effect.End();

            device.SetStreamSourceFrequency(0, 1, StreamSource.IndexedData);
            device.SetStreamSourceFrequency(1, 0, StreamSource.InstanceData);
            device.SetStreamSource(0, null, 0, 0);
            device.SetStreamSource(1, null, 0, 0);
            device.ResetStreamSourceFrequency(0);
        }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:101,代码来源:SortedTestRenderer.cs

示例2: RenderXMeshesWithInstancingShadows

        private void RenderXMeshesWithInstancingShadows(Dictionary<SlimDX.Direct3D9.Mesh, RenderMesh> meshes, Device device)
        {
            int k = 0;

            device.VertexFormat = VertexFormat.None;
            device.VertexDeclaration = vd;

            foreach (SlimDX.Direct3D9.Mesh mesh in meshes.Keys)
            {
                device.Indices = meshes[mesh].IndexBuffer;

                foreach (Texture texture in meshes[mesh].Textures.Keys)
                {
                    bool first = true;
                    int numberOfInstancedDraws = 0;

                    DataStream ds = null;

                    foreach (Common.Tuple<Graphics.Content.Model9, Entity, string> renderObject in meshes[mesh].Textures[texture].RenderObjects)
                    {
                        Entity entity = renderObject.Second;

                        if (entity.ActiveInShadowMap == Frame)
                        {
                            MetaModel metaModel = GetLatestMetaModel(entity, renderObject.Third);

                            if (first)
                            {
                                //if ((Settings.TerrainQualityPriorityRelation[Settings.TerrainQuality] + Settings.PriorityRelation[metaModel.Visible] < 3) ||
                                //    !(Settings.PriorityRelation[metaModel.CastShadows] + Settings.ShadowQualityPriorityRelation[Settings.ShadowQuality] > 3))
                                //    break;

                                meshEffect.SetTexture(EHTexture, texture);
                                ds = optimizedVB[k % optimizedVB.Length].Lock(0, meshes[mesh].Textures[texture].RenderObjects.Count * (Vector4.SizeInBytes * 4), LockFlags.None);

                                UpdateEffectWithMetaModel(meshEffect, metaModel, true);

                                meshEffect.CommitChanges();
                                first = false;
                            }

                            Matrix worldMatrix;

                            if (renderObject.First.SkinnedMesh != null)
                                worldMatrix = metaModel.StoredFrameMatrices[mesh][0][0];
                            else
                                worldMatrix = metaModel.GetWorldMatrix(Scene.Camera, renderObject.Second);

                            ds.Write(worldMatrix);

                            numberOfInstancedDraws++;
                        }
                    }

                    if (numberOfInstancedDraws == 0)
                        continue;

                    optimizedVB[k % optimizedVB.Length].Unlock();

                    DrawInstancedIndexedPrimitives(device, mesh, meshes[mesh].VertexBuffer, optimizedVB[k % optimizedVB.Length], instancedVertexElements,
                        numberOfInstancedDraws);

                    k++;
                }
            }

            device.SetStreamSourceFrequency(0, 1, StreamSource.IndexedData);
            device.SetStreamSourceFrequency(1, 0, StreamSource.InstanceData);
            device.SetStreamSource(0, null, 0, 0);
            device.SetStreamSource(1, null, 0, 0);
            device.ResetStreamSourceFrequency(0);
        }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:72,代码来源:SortedTestRenderer.cs

示例3: RenderInstances

        private void RenderInstances(Device dev)
        {
            InstanceLoader.UpdateVisibility();
            if (Meshes.Count == 0 || Textures.Count == 0 || InstanceDataBuffer == null || numInstances == 0)
                return;

            mModelInfo.BoneAnimator.OnFrame();

            int counter = 0;
            var shdr = Video.ShaderCollection.MDXShader;
            dev.VertexDeclaration = InstanceDeclaration;
            dev.SetRenderState(RenderState.VertexBlend, VertexBlend.Weights3);

            foreach (VertexBuffer vb in Meshes)
            {
                dev.SetStreamSource(0, vb, 0, Marshal.SizeOf(typeof(Models.MDX.MdxVertex)));
                dev.SetStreamSourceFrequency(0, numInstances, StreamSource.IndexedData);

                dev.SetStreamSource(1, InstanceDataBuffer, 0, Marshal.SizeOf(typeof(Models.MDX.MdxInstanceData)));
                dev.SetStreamSourceFrequency(1, 1, StreamSource.InstanceData);

                setRenderValues(counter);

                dev.Indices = Indices[counter];

                shdr.SetTexture("MeshTexture", Textures[counter]);
                if (mModelInfo.Passes[counter].BoneMatrices.Length == 0 || mModelInfo.Passes[counter].BoneMatrices.Length > 50)
                {
                    shdr.SetValue("useAnimation", false);
                }
                else
                {
                    shdr.SetValue<Matrix>("BoneMatrices", mModelInfo.Passes[counter].BoneMatrices);
                    shdr.SetValue("useAnimation", mModelInfo.Passes[counter].BoneMatrices.Length > 0);
                }

                shdr.DoRender((device) =>
                    {
                        dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, NumTriangles[counter] * 3, 0, NumTriangles[counter]);
                    }
                );

                unsetRenderValues();

                ++counter;
            }
            dev.VertexDeclaration = null;

            dev.ResetStreamSourceFrequency(0);
            dev.ResetStreamSourceFrequency(1);
            dev.SetRenderState(RenderState.VertexBlend, VertexBlend.Disable);
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:52,代码来源:M2BatchRenderer.cs


注:本文中的Device.ResetStreamSourceFrequency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。