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


C# DeviceContext.UpdateSubresource方法代码示例

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


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

示例1: UpdateBuffer

        /****************************************************************************************************
         * 
         ****************************************************************************************************/
        public void UpdateBuffer(DeviceContext context, Matrix world, ICamera camera)
        {
            var view = camera.CreateViewMatrix();
            var projection = camera.CreateProjectionMatrix(Resolution);
            Matrices[0] = Matrix.Transpose(world);
            Matrices[1] = Matrix.Transpose(view);
            Matrices[2] = Matrix.Transpose(projection);
            Matrices[3] = Matrix.Transpose(world * view);
            Matrices[4] = Matrix.Transpose(world * view * projection);
            Matrices[5] = Matrix.Transpose(view * projection);
            Matrices[6] = Matrix.Invert(world);
            Matrices[7] = Matrix.Invert(world * view);
            Matrices[8] = Matrix.Transpose(Matrix.Identity * Matrix.Scaling(LightPosition));
            Matrices[9] = new Matrix(new float[] 
            {
                LerpTime, AbsoluteTime, Resolution.X, Resolution.Y,
                BeatTime, Lead,0,0,
                Nisse0, Nisse1, Nisse2, Nisse3,
                0,0,0,0,
            });
            if (Buffer == null)
            {
                Buffer = new Buffer(context.Device, Matrices.Length * Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            }

            context.UpdateSubresource(Matrices, Buffer);
        }
开发者ID:JoltSoftwareDevelopment,项目名称:Jolt.MashRoom,代码行数:30,代码来源:ShaderEnvironment.cs

示例2: Apply

 public void Apply(DeviceContext context)
 {
     var worldViewProj = World * (View * Projection);
     worldViewProj.Transpose();
     context.UpdateSubresource(ref worldViewProj, constantBuffer);
     context.VertexShader.Set(vertexShader);
     context.VertexShader.SetConstantBuffer(0, constantBuffer);
     context.PixelShader.Set(pixelShader);
     context.PixelShader.SetConstantBuffer(0, constantBuffer);
     context.InputAssembler.InputLayout = layout;
 }
开发者ID:oguna,项目名称:AssimpSharp,代码行数:11,代码来源:BasicEffect.cs

示例3: Draw

 public static void Draw(DeviceContext context, float scale = 1f, float offset = 0f)
 {
     data.scale = scale;
     data.offset = offset;
     context.UpdateSubresource<cBuffer>(ref data, buffer, 0, 0, 0, null);
     context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
     context.InputAssembler.InputLayout = layout;
     context.InputAssembler.SetVertexBuffers(0, binding);
     context.VertexShader.Set(vertexShader);
     context.VertexShader.SetConstantBuffer(1, buffer);
     context.Draw(6, 0);
 }
开发者ID:romanchom,项目名称:Luna,代码行数:12,代码来源:ScreenQuad.cs

示例4: SetCameraParameters

 public void SetCameraParameters(DeviceContext context, Camera camera)
 {
     Contract.Requires<ArgumentNullException>(context != null, "Parameter context must not be null.");
     Contract.Requires<ArgumentNullException>(camera != null, "Parameter camera must not be null.");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(CameraCBuffer)), true, true))
     {
         data.Write(camera.Position);
         data.Write(0f);
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), cameraConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(cameraConstantBuffer, 1);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:13,代码来源:LightShader.cs

示例5: SetFogParameters

 public void SetFogParameters(DeviceContext context, float start, float end, Color3 fogColour)
 {
     Contract.Requires<ArgumentNullException>(fogColour != null, "fogColour");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(FogCBuffer)), true, true))
     {
         data.Write(start);
         data.Write(end);
         data.Write(fogColour);
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), fogConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(fogConstantBuffer, 0);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:13,代码来源:FogShader.cs

示例6: SetTransparencyParameters

 /// <summary>
 /// Sets the shader parameters.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="world">The world.</param>
 /// <param name="view">The view.</param>
 /// <param name="projection">The projection.</param>
 public virtual void SetTransparencyParameters(DeviceContext context, float opacity)
 {
     /*Contract.Requires<ArgumentNullException>(context != null, "Parameter context must not be null.");
     Contract.Requires<ArgumentNullException>(ambientColour != null, "Parameter ambientColour must not be null.");
     Contract.Requires<ArgumentNullException>(diffuseColour != null, "Parameter diffuseColour must not be null.");
     Contract.Requires<ArgumentNullException>(lightDirection != null, "Parameter lightDirection must not be null.");
     Contract.Requires<ArgumentNullException>(specularColour != null, "Parameter specularColour must not be null.");*/
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(TransparencyCBuffer)), true, true))
     {
         data.Write(opacity);
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), transparencyConstantBuffer, 0);
         context.PixelShader.SetConstantBuffer(transparencyConstantBuffer, 0);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:22,代码来源:TransparencyShader.cs

示例7: SetWVPMatrices

 /// <summary>
 /// Sets the shader parameters.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="world">The world.</param>
 /// <param name="view">The view.</param>
 /// <param name="projection">The projection.</param>
 public virtual void SetWVPMatrices(DeviceContext context, Matrix world, Matrix view, Matrix projection)
 {
     Contract.Requires<ArgumentNullException>(context != null, "context");
     Contract.Requires<ArgumentNullException>(world != null, "world");
     Contract.Requires<ArgumentNullException>(view != null, "view");
     Contract.Requires<ArgumentNullException>(projection != null, "projection");
     using (DataStream data = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(MatrixCBuffer)), true, true))
     {
         data.Write(Matrix.Transpose(world));
         data.Write(Matrix.Transpose(view));
         data.Write(Matrix.Transpose(projection));
         data.Position = 0;
         context.UpdateSubresource(new DataBox(0, 0, data), matrixConstantBuffer, 0);
         context.VertexShader.SetConstantBuffer(matrixConstantBuffer, 0);
     }
 }
开发者ID:nickudell,项目名称:PigmentFramework,代码行数:23,代码来源:WVPTransformShader.cs

示例8: ResizeAndUpdateStaticStructuredBuffer

 internal static void ResizeAndUpdateStaticStructuredBuffer(ref StructuredBufferId id, int capacity, int stride, IntPtr data, string debugName, DeviceContext context = null)
 {
     if (id == StructuredBufferId.NULL)
     {
         id = CreateStructuredBuffer(capacity, stride, false, data, debugName);
     }
     else 
     {
         Debug.Assert(stride == id.Stride);
         Debug.Assert(false == id.Dynamic);
         if (id.Capacity < capacity)
         {
             SBuffersData[id.Index].Buffer.Dispose();
             SBuffers.Data[id.Index].Description.SizeInBytes = stride * capacity;
             InitStructuredBuffer(id, data);
         }
         else
         {
             if (context == null)
                 context = MyRender11.DeviceContext;
             context.UpdateSubresource(new DataBox(data, stride * capacity, 0), id.Buffer);
         }
     }
 }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:24,代码来源:MyResource.cs

示例9: Use

        public static void Use(DeviceContext context, bool instanced)
        {
            if (instance == null)
            {
                initialize();
            }

            if (layout == null)
            {
                // Layout from VertexShader input signature
                layout = new InputLayout(RenderContext11.PrepDevice, ShaderSignature.GetInputSignature(instance.VertexShaderBytecode), new[]
                    {
                        new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0),
                        new InputElement("POINTSIZE", 0, SharpDX.DXGI.Format.R32_Float, 12, 0),
                        new InputElement("COLOR", 0, SharpDX.DXGI.Format.R8G8B8A8_UNorm, 16, 0),
                        new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 20, 0),
                        new InputElement("CORNER", 0, SharpDX.DXGI.Format.R8G8B8A8_UNorm, 28, 0),
                    });
            }

            if (instancedLayout == null)
            {
                instancedLayout = new InputLayout(RenderContext11.PrepDevice, ShaderSignature.GetInputSignature(instance.VertexShaderBytecode), new[]
                    {
                        new InputElement("CORNER",    0, SharpDX.DXGI.Format.R8G8B8A8_UNorm,   0, 0, InputClassification.PerVertexData,   0),
                        new InputElement("POSITION",  0, SharpDX.DXGI.Format.R32G32B32_Float,  0, 1, InputClassification.PerInstanceData, 1),
                        new InputElement("POINTSIZE", 0, SharpDX.DXGI.Format.R32_Float,       12, 1, InputClassification.PerInstanceData, 1),
                        new InputElement("COLOR",     0, SharpDX.DXGI.Format.R8G8B8A8_UNorm,  16, 1, InputClassification.PerInstanceData, 1),
                        new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,     20, 1, InputClassification.PerInstanceData, 1),
                    });
            }
            if (instanced)
            {
                context.InputAssembler.InputLayout = instancedLayout;
            }
            else
            {
                context.InputAssembler.InputLayout = layout;
            }

            context.VertexShader.Set(instance.CompiledVertexShader);
            context.VertexShader.SetConstantBuffer(0, constantBuffer);
            context.GeometryShader.Set(null);

            context.PixelShader.Set(instance.CompiledPixelShader);

            context.UpdateSubresource(ref Constants, constantBuffer);
        }
开发者ID:china-vo,项目名称:wwt-windows-client,代码行数:48,代码来源:Shaders11.cs

示例10: use

        public void use(DeviceContext context)
        {
            //pass.Apply(context);

            // Copy data to constant buffer
            context.UpdateSubresource(ref constants, constantBuffer);

            context.VertexShader.SetConstantBuffer(0, constantBuffer);
            context.PixelShader.SetConstantBuffer(0, constantBuffer);
            context.VertexShader.Set(vertexShader);
            context.PixelShader.Set(pixelShader);

            // Set vertex shader
        }
开发者ID:china-vo,项目名称:wwt-windows-client,代码行数:14,代码来源:Shaders11.cs

示例11: Render

        public void Render(DeviceContext context, vsBuffer vsBuffer, psBuffer psBuffer)
        {
            context.InputAssembler.InputLayout = layout;
            if (isTesselated)
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith3ControlPoints;
            }
            else
            {
                context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            }
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.vertexBuffer, mesh._vertexStream.vertexType.SizeOf(), 0));
            context.InputAssembler.SetIndexBuffer(mesh.indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0);
            context.VertexShader.Set(_shaderSolution.vs);
            for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.VertexShader].Length; i++)
            {
                context.VertexShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.VertexShader][i]);

            }
            context.PixelShader.Set(_shaderSolution.ps);
            for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.PixelShader].Length; i++)
            {
                context.PixelShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.PixelShader][i]);
            }
            if (this.isTesselated)
            {
                context.HullShader.Set(_shaderSolution.hs);
                for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.HullShader].Length; i++)
                {
                    context.HullShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.HullShader][i]);
                }
                context.DomainShader.Set(_shaderSolution.ds);
                for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.DomainShader].Length; i++)
                {
                    context.DomainShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.DomainShader][i]);
                }
                context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.DomainShader][0]);
            }
            else
            {
                context.HullShader.Set(null);
                context.DomainShader.Set(null);
            }
            for(int i = 0; i<material.textures.Count; i++)
            {
                context.PixelShader.SetShaderResource(i, material.textures[i]);
            }
            context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.VertexShader][0]);

            // !!!!!!!!!!!!!!!!!!!!!!! not normal (be careful of shader being optimized and stripped of unused constant buffer)
            //context.UpdateSubresource(ref psBuffer, _shaderSolution.shaders_buffers[Shaders.PixelShader][0]);
            context.PixelShader.SetSampler(0, sampler);
            context.DrawIndexed(mesh._indexStream.getIndexCount(), 0, 0);
        }
开发者ID:sinushawa,项目名称:ROD,代码行数:54,代码来源:Model.cs

示例12: CreateTexture2DArray

        public static ShaderResourceView CreateTexture2DArray(Device device, DeviceContext context, string[] filePaths, TextureLoadOptions options) {
            var srcTex = new Texture2D[filePaths.Length];
            for (var i = 0; i < filePaths.Length; i++) {
                srcTex[i] = CreateTextureFromFile(device, filePaths[i], options);
            }
            var texElementDesc = srcTex[0].Description;

            var texArrayDesc = new Texture2DDescription {
                Width = texElementDesc.Width,
                Height = texElementDesc.Height,
                MipLevels = texElementDesc.MipLevels,
                ArraySize = srcTex.Length,
                Format = texElementDesc.Format,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };

            var texArray = new Texture2D(device, texArrayDesc);
            texArray.DebugName = "texture array: + " + filePaths.Aggregate((i, j) => i + ", " + j);
            for (int texElement = 0; texElement < srcTex.Length; texElement++) {
                for (int mipLevel = 0; mipLevel < texElementDesc.MipLevels; mipLevel++) {
                    int mippedSize;
                    DataBox mappedTex2D;
                    mappedTex2D = context.MapSubresource(srcTex[texElement], mipLevel, 0, MapMode.Read, MapFlags.None, out mippedSize);

                    context.UpdateSubresource(
                        mappedTex2D,
                        texArray,
                        Resource.CalculateSubResourceIndex(mipLevel, texElement, texElementDesc.MipLevels)
                        );
                    context.UnmapSubresource(srcTex[texElement], mipLevel);
                }
            }
            var viewDesc = new ShaderResourceViewDescription {
                Format = texArrayDesc.Format,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Texture2DArray = new ShaderResourceViewDescription.Texture2DArrayResource() {
                    MostDetailedMip = 0,
                    MipLevels = texArrayDesc.MipLevels,
                    FirstArraySlice = 0,
                    ArraySize = srcTex.Length
                }
            };

            var texArraySRV = new ShaderResourceView(device, texArray, viewDesc);

            Utilities.Dispose(ref texArray);
            for (int i = 0; i < srcTex.Length; i++) {
                Utilities.Dispose(ref srcTex[i]);
            }

            return texArraySRV;
        }
开发者ID:Hozuki,项目名称:Noire,代码行数:56,代码来源:TextureLoader.cs


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