Esempio n. 1
0
        private void SetShaderMatrices()
        {
            VSMatrix vsm = new VSMatrix();

            vsm.wvp = DXMatrixHelper.Transpose(DXMatrixHelper.ToMatrix4x4F(worldMatrix));

            if (wvpBuffer == null)
            {
                var bd = new BufferDescription
                {
                    BindingOptions   = BindingOptions.ConstantBuffer,
                    CpuAccessOptions = CpuAccessOptions.Write,
                    //MiscellaneousResourceOptions = MiscellaneousResourceOptions.None,
                    //MiscFlags = ResourceMiscFlag.Undefined,
                    Usage     = Usage.Dynamic,
                    ByteWidth = (uint)Marshal.SizeOf(vsm)
                };

                wvpBuffer = device.CreateBuffer(bd);
            }

            MappedSubresource mappedResource = (MappedSubresource)deviceContext.Map(wvpBuffer, 0, Map.WriteDiscard, WindowsAPICodePack.DirectX.Direct3D11.MapOptions.None);

            Marshal.StructureToPtr(vsm, mappedResource.Data, true);
            deviceContext.Unmap(wvpBuffer, 0);
            deviceContext.VS.SetConstantBuffers(0, new D3DBuffer[] { wvpBuffer });
        }
Esempio n. 2
0
        private void SetShaderMatrices()
        {
            VSMatrix vsm = new VSMatrix();

            vsm.wvp = DXMatrixHelper.Transpose(MatrixExtensions.ToMatrix4x4F(worldMatrix));

            if (wvpBuffer == null)
            {
                wvpBuffer = device.CreateBuffer(
                    new BufferDescription
                {
                    BindFlags      = BindFlag.ConstantBuffer,
                    CpuAccessFlags = CpuAccessFlag.Write,
                    MiscFlags      = ResourceMiscFlag.Undefined,
                    Usage          = Usage.Dynamic,
                    ByteWidth      = (uint)Marshal.SizeOf(vsm)
                });
            }

            MappedSubresource mappedResource = (MappedSubresource)deviceContext.Map(wvpBuffer, 0, Map.WriteDiscard, MapFlag.Unspecified);

            Marshal.StructureToPtr(vsm, mappedResource.Data, true);
            deviceContext.Unmap(wvpBuffer, 0);
            deviceContext.VS.SetConstantBuffers(0, new D3DBuffer[] { wvpBuffer });
        }
Esempio n. 3
0
        private void SetShaderMatrices()
        {
            VSMatrix vsm = new VSMatrix();
            vsm.wvp = DXMatrixHelper.Transpose(MatrixExtensions.ToMatrix4x4F(worldMatrix));

            if (wvpBuffer == null)
            {
                wvpBuffer = device.CreateBuffer(
                new BufferDescription
                    {
                        BindFlags = BindFlag.ConstantBuffer,
                        CpuAccessFlags = CpuAccessFlag.Write,
                        MiscFlags = ResourceMiscFlag.Undefined,
                        Usage = Usage.Dynamic,
                        ByteWidth = (uint)Marshal.SizeOf(vsm)
                    });
            }

            MappedSubresource mappedResource = (MappedSubresource)deviceContext.Map(wvpBuffer, 0, Map.WriteDiscard, MapFlag.Unspecified);
            Marshal.StructureToPtr(vsm, mappedResource.Data, true);
            deviceContext.Unmap(wvpBuffer, 0);
            deviceContext.VS.SetConstantBuffers(0, new D3DBuffer[] { wvpBuffer });
        }