コード例 #1
0
        public GpuDevice(GpuAdapter adapter)
        {
            //set member to null
            mVertexShader = null;
            mPixelShader  = null;
            mInputLayout  = null;

            //set the adapter
            Adapter = adapter;

#if DEBUG
            //creation flag, we use debug flag
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#else
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.None;
#endif
            //fetuares level: 11_0, 12_0
            var fetuares = new SharpDX.Direct3D.FeatureLevel[2]
            {
                SharpDX.Direct3D.FeatureLevel.Level_11_0,
                SharpDX.Direct3D.FeatureLevel.Level_12_0
            };

            //create device with current adapter
            mDevice           = new SharpDX.Direct3D11.Device(Adapter.Adapter, creationFlags, fetuares);
            mImmediateContext = Device.ImmediateContext;

            LogEmitter.Apply(LogLevel.Information, "[Initialize Graphics Device with {0}]", adapter.Description);
            LogEmitter.Apply(LogLevel.Information, "[Graphics Device Feature Level = {0}]", Device.FeatureLevel);
        }
コード例 #2
0
        public void SetVertexShader(GpuVertexShader vertexShader)
        {
            //set vertex shader
            mVertexShader = vertexShader;

            //set vertex shader Direct3D instance to pipeline
            ImmediateContext.VertexShader.SetShader(mVertexShader.VertexShader, null, 0);
        }
コード例 #3
0
        public void Reset()
        {
            //clear all state and reset it

            mVertexShader = null;
            mPixelShader  = null;
            mInputLayout  = null;

            ImmediateContext.ClearState();
        }
コード例 #4
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);
        }