예제 #1
0
        public GpuTexture2D(
            Size size,
            GpuPixelFormat pixelFormat,
            GpuDevice device,
            GpuResourceInfo resourceInfo) :
            base(device, size.Width * size.Height * GpuConvert.SizeOfInBytes(pixelFormat), resourceInfo)
        {
            Size        = new Size(size.Width, size.Height);
            PixelFormat = pixelFormat;

            mRowPitch = Size.Width * GpuConvert.SizeOfInBytes(PixelFormat);

            mResource = new SharpDX.Direct3D11.Texture2D(GpuDevice.Device, new SharpDX.Direct3D11.Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = GpuConvert.ToBindUsage(ResourceInfo.BindUsage),
                CpuAccessFlags    = GpuConvert.ToCpuAccessFlag(ResourceInfo.CpuAccessFlag),
                Format            = GpuConvert.ToPixelFormat(PixelFormat),
                Width             = Size.Width,
                Height            = Size.Height,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = GpuConvert.ToHeapType(ResourceInfo.HeapType)
            });
        }
예제 #2
0
        public GpuSamplerState(GpuDevice device,
                               GpuTextureAddressMode addressU,
                               GpuTextureAddressMode addressV,
                               GpuTextureAddressMode addressW,
                               GpuTextureFilter filter = GpuTextureFilter.MinMagMipLinear)
        {
            GpuDevice = device;

            //set address mode
            AddressU = addressU;
            AddressV = addressV;
            AddressW = addressW;

            Filter = filter;

            mSamplerState = new SharpDX.Direct3D11.SamplerState(GpuDevice.Device, new SharpDX.Direct3D11.SamplerStateDescription()
            {
                AddressU           = GpuConvert.ToTextureAddressMode(AddressU),
                AddressV           = GpuConvert.ToTextureAddressMode(AddressV),
                AddressW           = GpuConvert.ToTextureAddressMode(AddressW),
                Filter             = GpuConvert.ToTextureFilter(Filter),
                ComparisonFunction = SharpDX.Direct3D11.Comparison.Never,
                MinimumLod         = float.MinValue,
                MaximumLod         = float.MaxValue,
                BorderColor        = new SharpDX.Mathematics.Interop.RawColor4(1, 1, 1, 1),
                MaximumAnisotropy  = 4,
                MipLodBias         = 0.0f
            });
        }
예제 #3
0
        public void SetIndexBuffer(GpuBuffer buffer)
        {
            //set index buffer to input stage

            //test if the buffer can be set
            Debug.Assert(GpuConvert.HasBindUsage(buffer.ResourceInfo.BindUsage, GpuBindUsage.IndexBuffer) == true);

            //set index buffer
            ImmediateContext.InputAssembler.SetIndexBuffer(buffer.Resource as SharpDX.Direct3D11.Buffer,
                                                           SharpDX.DXGI.Format.R32_UInt, 0);
        }
예제 #4
0
        public void SetVertexBuffer(GpuBuffer buffer)
        {
            //set vertex buffer to input stage

            //test if the buffer can be set
            Debug.Assert(GpuConvert.HasBindUsage(buffer.ResourceInfo.BindUsage, GpuBindUsage.VertexBufferr) == true);

            //create buffer binding
            var bufferBinding = new SharpDX.Direct3D11.VertexBufferBinding(
                buffer.Resource as SharpDX.Direct3D11.Buffer,
                buffer.ElementSize, 0);

            //set vertex buffer
            ImmediateContext.InputAssembler.SetVertexBuffers(0, bufferBinding);
        }
예제 #5
0
        public GpuSwapChain(
            IntPtr handle,
            Size <int> size,
            GpuPixelFormat pixelFormat,
            GpuDevice device)
        {
            //size property
            Size        = size;
            PixelFormat = pixelFormat;
            GpuDevice   = device;

            //get factory
            using (var factory = GpuDevice.Adapter.Adapter.GetParent <SharpDX.DXGI.Factory>())
            {
                //set swapchain desc
                var swapChainDesc = new SharpDX.DXGI.SwapChainDescription()
                {
                    BufferCount     = 1,
                    Flags           = SharpDX.DXGI.SwapChainFlags.None,
                    IsWindowed      = true,
                    ModeDescription = new SharpDX.DXGI.ModeDescription()
                    {
                        Format           = GpuConvert.ToPixelFormat(PixelFormat),
                        Height           = Size.Height,
                        Width            = Size.Width,
                        RefreshRate      = new SharpDX.DXGI.Rational(60, 1),
                        Scaling          = SharpDX.DXGI.DisplayModeScaling.Unspecified,
                        ScanlineOrdering = SharpDX.DXGI.DisplayModeScanlineOrder.Unspecified
                    },
                    OutputHandle      = handle,
                    SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                    SwapEffect        = SharpDX.DXGI.SwapEffect.Discard,
                    Usage             = SharpDX.DXGI.Usage.RenderTargetOutput
                };

                mSwapChain = new SharpDX.DXGI.SwapChain(factory, GpuDevice.Device, swapChainDesc);

                //report error, if create swapchain failed
                LogEmitter.Assert(mSwapChain != null, LogLevel.Error,
                                  "[Create SwapChain Failed] [Width = {0}] [Height = {1}] [Format = {2}]", Size.Width, Size.Height, PixelFormat);

                RenderTarget = new GpuRenderTarget(GpuDevice, this);
            }
        }
예제 #6
0
        public void SetBuffer(GpuBuffer buffer, int register, GpuShaderType target = GpuShaderType.All)
        {
            //set buffer Direct3D instance to pipeline's shader
            //we use target shader to flag which shader the buffer will set to

            //test if the buffer can be set
            Debug.Assert(GpuConvert.HasBindUsage(buffer.ResourceInfo.BindUsage, GpuBindUsage.ConstantBuffer) == true);

            //we can use "&" to make sure if we need set buffer to vertex shader
            if ((target & GpuShaderType.VertexShader) != GpuShaderType.None)
            {
                ImmediateContext.VertexShader.SetConstantBuffer(register, buffer.Resource as SharpDX.Direct3D11.Buffer);
            }

            //we can use "&" to make sure if we need set buffer to pixel shader
            if ((target & GpuShaderType.PixelShader) != GpuShaderType.None)
            {
                ImmediateContext.PixelShader.SetConstantBuffer(register, buffer.Resource as SharpDX.Direct3D11.Buffer);
            }
        }
예제 #7
0
        public GpuBufferArray(
            int elementSize,
            int elementCount,
            GpuDevice device,
            GpuResourceInfo resourceInfo) : base(device, elementCount * elementSize, resourceInfo)
        {
            ElementSize  = elementSize;
            ElementCount = elementCount;

            mResource = new SharpDX.Direct3D11.Buffer(GpuDevice.Device,
                                                      new SharpDX.Direct3D11.BufferDescription()
            {
                BindFlags           = GpuConvert.ToBindUsage(ResourceInfo.BindUsage),
                CpuAccessFlags      = GpuConvert.ToCpuAccessFlag(ResourceInfo.CpuAccessFlag),
                OptionFlags         = SharpDX.Direct3D11.ResourceOptionFlags.BufferStructured,
                SizeInBytes         = SizeInBytes,
                StructureByteStride = ElementSize,
                Usage = GpuConvert.ToHeapType(ResourceInfo.HeapType)
            });
        }
예제 #8
0
        public GpuBuffer(
            int bufferSize,
            int elementSize,
            GpuDevice device,
            GpuResourceInfo resourceInfo) : base(device, bufferSize, resourceInfo)
        {
            ElementSize = elementSize;

            mResource = new SharpDX.Direct3D11.Buffer(GpuDevice.Device,
                                                      new SharpDX.Direct3D11.BufferDescription()
            {
                BindFlags           = GpuConvert.ToBindUsage(ResourceInfo.BindUsage),
                CpuAccessFlags      = GpuConvert.ToCpuAccessFlag(ResourceInfo.CpuAccessFlag),
                OptionFlags         = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SizeInBytes         = SizeInBytes,
                StructureByteStride = ElementSize,
                Usage = GpuConvert.ToHeapType(ResourceInfo.HeapType)
            });

            Debug.Assert(bufferSize % elementSize == 0);
        }
예제 #9
0
 public void SetPrimitiveType(GpuPrimitiveType primitiveType)
 {
     //set primitive type
     ImmediateContext.InputAssembler.PrimitiveTopology = GpuConvert.ToPrimitiveType(primitiveType);
 }