예제 #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 GpuInputLayout(GpuDevice device, InputElement[] inputElements, GpuVertexShader vertexShader)
        {
            GpuDevice     = device;
            InputElements = new SharpDX.Direct3D11.InputElement[inputElements.Length];

            for (int i = 0; i < InputElements.Length; i++)
            {
                var element      = inputElements[i];
                var inputElement = new SharpDX.Direct3D11.InputElement();

                inputElement.SemanticName         = element.Name;
                inputElement.SemanticIndex        = element.Index;
                inputElement.Slot                 = 0;
                inputElement.Classification       = SharpDX.Direct3D11.InputClassification.PerVertexData;
                inputElement.InstanceDataStepRate = 0;

                if (i == 0)
                {
                    inputElement.AlignedByteOffset = 0;
                }
                else
                {
                    inputElement.AlignedByteOffset = InputElements[i - 1].AlignedByteOffset + inputElements[i - 1].Size;
                }

                switch (inputElements[i].Size)
                {
                case 4:
                    inputElement.Format = SharpDX.DXGI.Format.R32_Float; break;

                case 8:
                    inputElement.Format = SharpDX.DXGI.Format.R32G32_Float; break;

                case 12:
                    inputElement.Format = SharpDX.DXGI.Format.R32G32B32_Float; break;

                case 16:
                    inputElement.Format = SharpDX.DXGI.Format.R32G32B32A32_Float; break;

                default:
                    break;
                }

                InputElements[i] = inputElement;
            }

            mInputLayout = new SharpDX.Direct3D11.InputLayout(GpuDevice.Device, vertexShader.ByteCode, InputElements);
        }
예제 #4
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);
            }
        }
예제 #5
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)
            });
        }
예제 #6
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);
        }
예제 #7
0
 public GpuVertexShader(GpuDevice device, byte[] byteCode) : base(device, byteCode)
 {
     mVertexShader = new SharpDX.Direct3D11.VertexShader(GpuDevice.Device, ByteCode);
 }
예제 #8
0
 public GpuShader(GpuDevice device, byte[] byteCode)
 {
     ByteCode  = byteCode;
     GpuDevice = device;
 }
예제 #9
0
 public GpuSamplerState(GpuDevice device,
                        GpuTextureAddressMode addressUVW = GpuTextureAddressMode.Clamp,
                        GpuTextureFilter filter          = GpuTextureFilter.MinMagMipLinear) : this(device, addressUVW, addressUVW, addressUVW, filter)
 {
 }