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


C# GraphicsDevice.SetVertexBuffers方法代码示例

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


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

示例1: RenderToGBuffer

        public void RenderToGBuffer(Camera camera, GraphicsDevice graphicsDevice)
        {
            if (_subMeshes.Count == 0)
                return;

            // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
            Mesh.SubMesh subMesh = _subMeshes[0];
            ModelMeshPart meshPart = subMesh._meshPart;
            graphicsDevice.SetVertexBuffers(
                new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
                new VertexBufferBinding(_instanceVertexBuffer, 0, 1)
            );

            subMesh.RenderEffect.SetCurrentTechnique(3);
            subMesh.RenderEffect.SetMatrices(Matrix.Identity, camera.EyeTransform, camera.ProjectionTransform);
            //our first pass is responsible for rendering into GBuffer
            subMesh.RenderEffect.SetFarClip(camera.FarClip);

            //no individual skinned models for now
            if (subMesh._parent.BoneMatrixes != null)
                subMesh.RenderEffect.SetBones(subMesh._parent.BoneMatrixes);

            subMesh.RenderEffect.Apply();

            graphicsDevice.Indices = meshPart.IndexBuffer;

            graphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                               meshPart.NumVertices, meshPart.StartIndex,
                                                               meshPart.PrimitiveCount, _subMeshes.Count);


        }
开发者ID:justshiv,项目名称:LightSavers,代码行数:32,代码来源:InstancingGroup.cs

示例2: RenderToGBufferInstanced

        public void RenderToGBufferInstanced(Model model, Matrix[] modelBones, Matrix[] instances, Camera.Camera camera, GraphicsDevice graphicsDevice)
        {
            if (instances.Length == 0)
                return;

            // If we have more instances than room in our vertex buffer, grow it to the neccessary size.
            if ((instanceVertexBuffer == null) ||
                (instances.Length > instanceVertexBuffer.VertexCount))
            {
                if (instanceVertexBuffer != null)
                    instanceVertexBuffer.Dispose();

                instanceVertexBuffer = new DynamicVertexBuffer(graphicsDevice, instanceVertexDeclaration, instances.Length, BufferUsage.WriteOnly);
            }

            // Transfer the latest instance transform matrices into the instanceVertexBuffer.
            instanceVertexBuffer.SetData(instances, 0, instances.Length, SetDataOptions.Discard);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
                    graphicsDevice.SetVertexBuffers(new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0), new VertexBufferBinding(instanceVertexBuffer, 0, 1));

                    graphicsDevice.Indices = meshPart.IndexBuffer;

                    // Set up the instance rendering effect.
                    Effect effect = _effect;

                    effect.CurrentTechnique = effect.Techniques["HardwareInstancing"];
                    //our first pass is responsible for rendering into GBuffer
                    effect.Parameters["World"].SetValue(modelBones[mesh.ParentBone.Index]);
                    effect.Parameters["View"].SetValue(camera.View);
                    effect.Parameters["Projection"].SetValue(camera.Projection);
                    effect.Parameters["WorldView"].SetValue(modelBones[mesh.ParentBone.Index] * camera.View);
                    effect.Parameters["WorldViewProjection"].SetValue(modelBones[mesh.ParentBone.Index] * camera.View * camera.Projection);
                    effect.Parameters["FarClip"].SetValue(camera.FarPlane);

                    if (((MeshTag)meshPart.Tag) != null)
                    if (((MeshTag)meshPart.Tag).Texture != null)
                    {
                        effect.Parameters["TextureEnabled"].SetValue(true);
                        effect.Parameters["Texture"].SetValue(((MeshTag)meshPart.Tag).Texture);
                    }
                    else effect.Parameters["TextureEnabled"].SetValue(false);
                    //if (effect.Parameters["Size"] != null)
                    //{
                        effect.Parameters["Size"].SetValue(new Vector2(scale.Z, scale.Y) * 10000);
                        effect.Parameters["Up"].SetValue(mode == BillboardMode.Spherical ? Up : (mode == BillboardMode.None ? Vector3.Zero : Vector3.Up));
                        effect.Parameters["Side"].SetValue(mode != BillboardMode.None ? Right : Vector3.Zero);
                    //}

                    effect.CurrentTechnique.Passes[0].Apply();
                    graphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount, instances.Length);
                }
            }
        }
开发者ID:razvanalex,项目名称:XNAEnvironment,代码行数:58,代码来源:BillboardsSystem.cs

示例3: Draw

 public void Draw(GraphicsDevice g, List<VertexHealthInstance> insts)
 {
     fxPass.Apply();
     g.Indices = ib;
     int i = insts.Count;
     while(i > MAX_COUNT) {
         insts.CopyTo(i - MAX_COUNT, instances, 0, MAX_COUNT);
         dvb.SetData(instances, 0, MAX_COUNT);
         g.SetVertexBuffers(vbBinds);
         g.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2, MAX_COUNT);
         i -= MAX_COUNT;
         g.SetVertexBuffers(null);
     }
     insts.CopyTo(0, instances, 0, i);
     dvb.SetData(instances, 0, i);
     g.SetVertexBuffers(vbBinds);
     g.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2, i);
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:18,代码来源:HealthViewer.cs

示例4: DrawEmitter

        private void DrawEmitter(GraphicsDevice device, Effect effect, ParticleEmitter emitter)
        {
            if (emitter.LiveParticles == 0)
                return;

            effect.Parameters["Time"].SetValue(emitter.Time);
            effect.Parameters["Acceleration"].SetValue(emitter.Acceleration);
            effect.Parameters["LifeSpan"].SetValue(emitter.LifeSpan);

            ParticleStateType[] instances = emitter.Particles;

            if (m_InstanceBuffer.VertexCount < instances.Length)
            {
                m_InstanceBuffer.Dispose();
                m_InstanceBuffer = new DynamicVertexBuffer(device, typeof(ParticleStateType), 2 * instances.Length, BufferUsage.WriteOnly);
            }

            m_InstanceBuffer.SetData(instances, 0, emitter.LiveParticles, SetDataOptions.Discard);

            var particleres = m_ParticleBuffer.GetResource();
            device.SetVertexBuffers(
                new VertexBufferBinding(particleres.Buffer, 0, 0),
                new VertexBufferBinding(m_InstanceBuffer, 0, 1)
                );

            device.Indices = m_IndexBuffer;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawInstancedPrimitives(PrimitiveType.TriangleList,
                    0, 0, particleres.NumVertices, 0, particleres.PrimitiveCount, emitter.LiveParticles);
            }
        }
开发者ID:jumonb,项目名称:hideandsneeze,代码行数:34,代码来源:ParticleEffect.cs

示例5: SetInstances

 public void SetInstances(GraphicsDevice g)
 {
     g.SetVertexBuffers(
         new VertexBufferBinding(vbModel),
         new VertexBufferBinding(dvbInstances, 0, 1)
         );
     g.Indices = ibModel;
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:8,代码来源:RTSUnitModel.cs

示例6: SetLightning

 public void SetLightning(GraphicsDevice g)
 {
     fxParticle.ApplyLightning(g, tLightningMap);
     g.SetVertexBuffers(plBolts.VBBinds);
     g.Indices = plBolts.IBuffer;
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:6,代码来源:ParticleRenderer.cs

示例7: SetFire

 public void SetFire(GraphicsDevice g)
 {
     fxParticle.ApplyFire(g, tFireColor, tFireNoise, tFireAlpha);
     g.SetVertexBuffers(plFires.VBBinds);
     g.Indices = plFires.IBuffer;
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:6,代码来源:ParticleRenderer.cs

示例8: SetBullets

 public void SetBullets(GraphicsDevice g)
 {
     fxParticle.ApplySimple(g, tBullet);
     g.SetVertexBuffers(plBullets.VBBinds);
     g.Indices = plBullets.IBuffer;
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:6,代码来源:ParticleRenderer.cs

示例9: SetBloods

 public void SetBloods(GraphicsDevice g)
 {
     fxParticle.ApplyAlert(g, tBlood);
     g.SetVertexBuffers(plBloods.VBBinds);
     g.Indices = plBloods.IBuffer;
 }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:6,代码来源:ParticleRenderer.cs

示例10: Draw

        public void Draw(GraphicsDevice graphicsDevice)
        {
            if (cubes.Length > 0)
            {
                Debug.AddString("Drawing cubes: " + cubes.Length);
                Array.Resize(ref instanceTransforms, cubes.Length);

                for (int i = 0; i < cubes.Length; i++)
                {
                    instanceTransforms[i] = Matrix.CreateTranslation(cubes[i].Position);
                }
                // Rysujemy wszystko za jednym zamachem

                // Poszerzany bufory jeśli potrzeba.
                if ((instanceVertexBuffer == null) || (cubes.Length > instanceVertexBuffer.VertexCount))
                {
                    if (instanceVertexBuffer != null)
                    {
                        instanceVertexBuffer.Dispose();
                    }

                    instanceVertexBuffer = new DynamicVertexBuffer(graphicsDevice, instanceVertexDeclaration,
                                                                   cubes.Length, BufferUsage.WriteOnly);
                }

                instanceVertexBuffer.SetData(instanceTransforms, 0, instanceTransforms.Length, SetDataOptions.Discard);

                foreach (ModelMesh mesh in instancedModel.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
                        graphicsDevice.SetVertexBuffers(
                            new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
                            new VertexBufferBinding(instanceVertexBuffer, 0, 1)
                            );

                        graphicsDevice.Indices = meshPart.IndexBuffer;

                        // Set up the instance rendering effect.
                        Effect effect = meshPart.Effect;

                        effect.CurrentTechnique = effect.Techniques["SKraft"];

                        effect.Parameters["World"].SetValue(instancedModelBones[mesh.ParentBone.Index]);
                        effect.Parameters["View"].SetValue(Camera.ActiveCamera.View);
                        effect.Parameters["Projection"].SetValue(Camera.ActiveCamera.Projection);
                        //effect.Parameters["Texture"].SetValue(content.Load<Texture2D>(@"textures\texture2low2"));

                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();

                            graphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                                   meshPart.NumVertices, meshPart.StartIndex,
                                                                   meshPart.PrimitiveCount, cubes.Length);
                        }
                    }
                }
            }
        }
开发者ID:arkadiuszneuman,项目名称:SKraft,代码行数:61,代码来源:Map.cs

示例11: ReconstructShading

        public void ReconstructShading(Camera camera, GraphicsDevice graphicsDevice)
        {

            if (_subMeshes.Count == 0)
                return;

            // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
            Mesh.SubMesh subMesh = _subMeshes[0];
            ModelMeshPart meshPart = subMesh._meshPart;
            graphicsDevice.SetVertexBuffers(
                new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
                new VertexBufferBinding(_instanceVertexBuffer, 0, 1)
            );

            subMesh.RenderEffect.SetCurrentTechnique(4);

            subMesh.RenderEffect.Apply();

            graphicsDevice.Indices = meshPart.IndexBuffer;

            graphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                               meshPart.NumVertices, meshPart.StartIndex,
                                                               meshPart.PrimitiveCount, _subMeshes.Count);


        }
开发者ID:justshiv,项目名称:LightSavers,代码行数:26,代码来源:InstancingGroup.cs

示例12: RenderShadowMap

        public virtual void RenderShadowMap(ref Matrix viewProj, GraphicsDevice graphicsDevice)
        {
            if (_subMeshes.Count == 0)
                return;

            // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer.
            Mesh.SubMesh subMesh = _subMeshes[0];
            ModelMeshPart meshPart = subMesh._meshPart;
            graphicsDevice.SetVertexBuffers(
                new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0),
                new VertexBufferBinding(_instanceVertexBuffer, 0, 1)
            );

            subMesh.RenderEffect.SetCurrentTechnique(5);
            subMesh.RenderEffect.SetLightViewProj(viewProj);


            //we need to set this every frame, there are situations where the object is not on screen but it still cast shadows
            subMesh.RenderEffect.SetWorld(Matrix.Identity);
            //no individual skinned models for now
            if (subMesh._parent.BoneMatrixes != null)
                subMesh.RenderEffect.SetBones(subMesh._parent.BoneMatrixes);


            subMesh.RenderEffect.Apply();

            graphicsDevice.Indices = meshPart.IndexBuffer;

            graphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                               meshPart.NumVertices, meshPart.StartIndex,
                                                               meshPart.PrimitiveCount, _subMeshes.Count);

        }
开发者ID:justshiv,项目名称:LightSavers,代码行数:33,代码来源:InstancingGroup.cs


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