當前位置: 首頁>>代碼示例>>C#>>正文


C# Direct3D11.InputElement類代碼示例

本文整理匯總了C#中SharpDX.Direct3D11.InputElement的典型用法代碼示例。如果您正苦於以下問題:C# InputElement類的具體用法?C# InputElement怎麽用?C# InputElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InputElement類屬於SharpDX.Direct3D11命名空間,在下文中一共展示了InputElement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EffectSignatureLayout

 public EffectSignatureLayout(InputElement[] inputElements, byte[] signature)
 {
     InputElements = inputElements;
     ShaderSignature = signature;
     inputElementsHashCode = InputElements.Aggregate(InputElements.Length, (current, inputElement) => (current * 397) ^ inputElement.GetHashCode());
     inputElementsHashCode = (inputElementsHashCode * 397) ^ ShaderSignature.GetHashCode();
 }
開發者ID:h78hy78yhoi8j,項目名稱:xenko,代碼行數:7,代碼來源:EffectSignatureLayout.cs

示例2: GetInputLayout

 public static InputLayout GetInputLayout(Device device, CompilationResult vertexShaderByteCode)
 {
     var inputElements = new InputElement[]
     {
         new InputElement
         {
             SemanticName = "POSITION",
             SemanticIndex = 0,
             Format = Format.R32G32B32_Float,
             Slot = 0,
             AlignedByteOffset = 0,
             Classification = InputClassification.PerVertexData,
             InstanceDataStepRate = 0
         },
         new InputElement
         {
             SemanticName = "COLOR",
             SemanticIndex = 0,
             Format = Format.R32G32B32A32_Float,
             Slot = 0,
             AlignedByteOffset = LightShader.Vertex.AppendAlignedElement1,
             Classification = InputClassification.PerVertexData,
             InstanceDataStepRate = 0
         }
     };
     return new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
 }
開發者ID:ndech,項目名稱:PlaneSimulator,代碼行數:27,代碼來源:VertexDefinition.cs

示例3: InitShaders

        public override void InitShaders(ref Device device)
        {
            ShaderBytecode vertexShaderByteCode =
                ShaderBytecode.CompileFromFile(@"Shader/basicShaders.hlsl", "VShader", "vs_4_0");

            ShaderBytecode pixelShaderByteCode =
                ShaderBytecode.CompileFromFile(@"Shader/basicShaders.hlsl", "PShader", "ps_4_0");

            _deviceContext = device.ImmediateContext;
            _deviceContext.VertexShader.Set(new VertexShader(device, vertexShaderByteCode));
            _deviceContext.PixelShader.Set(new PixelShader(device, pixelShaderByteCode));

            //----

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR"   , 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 16, 0),
            };

            _deviceContext.InputAssembler.InputLayout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), elements);

            Vertex[] vertices = new Vertex[]
            {
                new Vertex(0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f),
                new Vertex(0.5f, -.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f),
                new Vertex(-.5f, -.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f),
            };

            BufferDescription description = new BufferDescription(32 * 3, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            _vertexBuffer = Buffer.Create(device, vertices, description);
        }
開發者ID:HirokiKihibori,項目名稱:CV-GameController,代碼行數:32,代碼來源:Renderers.cs

示例4: MeshFactory

        public MeshFactory(SharpDX11Graphics graphics)
        {
            this.device = graphics.Device;
            this.inputAssembler = device.ImmediateContext.InputAssembler;
            this.demo = graphics.Demo;

            instanceDataDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
            };

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
                new InputElement("WORLD", 0, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 1, Format.R32G32B32A32_Float, 16, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 2, Format.R32G32B32A32_Float, 32, 1, InputClassification.PerInstanceData, 1),
                new InputElement("WORLD", 3, Format.R32G32B32A32_Float, 48, 1, InputClassification.PerInstanceData, 1),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 64, 1, InputClassification.PerInstanceData, 1)
            };
            inputLayout = new InputLayout(device, graphics.GetEffectPass().Description.Signature, elements);

            groundColor = ColorToUint(Color.Green);
            activeColor = ColorToUint(Color.Orange);
            passiveColor = ColorToUint(Color.OrangeRed);
            softBodyColor = ColorToUint(Color.LightBlue);
        }
開發者ID:RainsSoft,項目名稱:BulletSharpPInvoke,代碼行數:31,代碼來源:MeshFactory.cs

示例5: LoadEffect

 /// <summary>
 /// Получить эффект
 /// </summary>
 /// <param name="FileName"></param>
 /// <param name="inputElement"></param>
 /// <returns></returns>
 public static EffectContainer LoadEffect(string FileName, InputElement[] inputElement)
 {
     string Origin = FileName;
     if (Effects.ContainsKey(Origin) && Effects[Origin].IsAlive)
     {
         //Уже есть
         EffectContainer t = (EffectContainer)Effects[Origin].Target;
         return t;
     }
     else
     {
         //нужно загрузить
         if (File.Exists(FileName + ".fx"))
         {
             FileName += ".fx";
         }
         else if (File.Exists(FileName + ".ees"))
         {
             FileName += ".ees";
         }
         EffectContainer t = new EffectContainer(ModelViewer.Program.device, FileName, inputElement);
         t.Name = Origin;
         WeakReference wr = new WeakReference(t, false);
         Effects.Add(Origin, wr);
         return t;
         //TODO проверка на валидность загрузки
     }
 }
開發者ID:MagistrAVSH,項目名稱:my-spacegame-engine,代碼行數:34,代碼來源:ContentManager.cs

示例6: PhysicsDebugDraw

        public PhysicsDebugDraw(DeviceManager manager)
        {
            device = manager.Direct3DDevice;
            inputAssembler = device.ImmediateContext.InputAssembler;
            lineArray = new PositionColored[0];

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "VSMain", "vs_5_0"))
            {
                vertexShader = new VertexShader(device, bc);

                InputElement[] elements = new InputElement[]
                {
                    new InputElement("SV_POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                    new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
                };
                inputLayout = new InputLayout(device, bc, elements);
            }

            vertexBufferDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write
            };

            vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);

            using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "PSMain", "ps_5_0"))
                pixelShader = new PixelShader(device, bc);
        }
開發者ID:QamarWaqar,項目名稱:Direct3D-Rendering-Cookbook,代碼行數:30,代碼來源:PhysicsDebugDraw.cs

示例7: InputLayout

 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.InputLayout" /> object to describe the
 ///   input-buffer data for the input-assembler stage.
 /// </summary>
 /// <unmanaged>ID3D11Device::CreateInputLayout</unmanaged>
 /// <param name = "device">The device used to create the layout.</param>
 /// <param name = "elements">An array of input elements describing the layout of the input data.</param>
 /// <param name = "shaderBytecode">The compiled shader used to validate the input elements.</param>
 public InputLayout(Device device, byte[] shaderBytecode, InputElement[] elements)
     : base(IntPtr.Zero)
 {
     unsafe
     {
         fixed (void* pBuffer = shaderBytecode)
             device.CreateInputLayout(elements, elements.Length, (IntPtr)pBuffer, shaderBytecode.Length,  this);
     }
 }
開發者ID:alexey-bez,項目名稱:SharpDX,代碼行數:17,代碼來源:InputLayout.cs

示例8: VertexElement

        public VertexElement(string semantic, int index, int components, DataType dataType = DataType.Float, bool normalized = false, int slot = 0, bool instanceData = false)
        {
            mDescription = new InputElement
            {
                AlignedByteOffset = InputElement.AppendAligned,
                Classification = instanceData ? InputClassification.PerInstanceData : InputClassification.PerVertexData,
                InstanceDataStepRate = instanceData ? 1 : 0,
                SemanticIndex = index,
                SemanticName = semantic,
                Slot = slot
            };

            if(dataType == DataType.Byte)
            {
                switch(components)
                {
                    case 1:
                        mDescription.Format = normalized ? Format.R8_UNorm : Format.R8_UInt;
                        break;

                    case 2:
                        mDescription.Format = normalized ? Format.R8G8_UNorm : Format.R8G8_UInt;
                        break;

                    case 4:
                        mDescription.Format = normalized ? Format.R8G8B8A8_UNorm : Format.R8G8B8A8_UInt;
                        break;

                    default:
                        throw new ArgumentException("Invalid combination of data type and component count");
                }
            }
            else
            {
                switch(components)
                {
                    case 1:
                        mDescription.Format = Format.R32_Float;
                        break;

                    case 2:
                        mDescription.Format = Format.R32G32_Float;
                        break;

                    case 3:
                        mDescription.Format = Format.R32G32B32_Float;
                        break;

                    case 4:
                        mDescription.Format = Format.R32G32B32A32_Float;
                        break;

                    default:
                        throw new ArgumentException("Invalid combination of data type and component count");
                }
            }
        }
開發者ID:Linrasis,項目名稱:WoWEditor,代碼行數:57,代碼來源:VertexElement.cs

示例9: VertexArrayLayout

        /// <summary>
        /// Initializes a new instance of the <see cref="VertexArrayLayout"/> class.
        /// </summary>
        /// <param name="inputElements">The input elements.</param>
        /// <exception cref="System.ArgumentNullException">inputElements</exception>
        public VertexArrayLayout(InputElement[] inputElements)
        {
            if (inputElements == null) throw new ArgumentNullException("inputElements");

            this.InputElements = inputElements;
            hashCode = inputElements.Length;
            for (int i = 0; i < inputElements.Length; i++)
            {
                hashCode = (hashCode * 397) ^ inputElements[i].GetHashCode();
            }
        }
開發者ID:h78hy78yhoi8j,項目名稱:xenko,代碼行數:16,代碼來源:VertexArrayLayout.Direct3D.cs

示例10: Style

        public Style(String vertexShaderFilename, String pixelShaderFilename, InputElement[] layoutElements, int floatsPerVertex, DeviceManager deviceManager)
        {
            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Read pre-compiled shader byte code relative to current directory
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\" + vertexShaderFilename);
            this.pixelShader = new PixelShader(deviceManager.DeviceDirect3D, NativeFile.ReadAllBytes(path + "\\" + pixelShaderFilename));
            this.vertexShader = new VertexShader(deviceManager.DeviceDirect3D, vertexShaderByteCode);

            // Specify the input layout for the new style
            this.layout = new InputLayout(deviceManager.DeviceDirect3D, vertexShaderByteCode, layoutElements);
            this.floatsPerVertex = floatsPerVertex;
        }
開發者ID:philyum,項目名稱:TheAmazingFishy,代碼行數:13,代碼來源:Style.cs

示例11: ColorShader

        public ColorShader(Device device)
        {
            var vertexShaderByteCode = ShaderBytecode.CompileFromFile(VertexShaderFileName, "ColorVertexShader", "vs_4_0", ShaderFlags.None, EffectFlags.None);
            var pixelShaderByteCode = ShaderBytecode.CompileFromFile(PixelShaderFileName, "ColorPixelShader", "ps_4_0", ShaderFlags.None, EffectFlags.None);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader = new PixelShader(device, pixelShaderByteCode);

            var inputElements = new InputElement[]
            {
                new InputElement
                {
                    SemanticName = "POSITION",
                    SemanticIndex = 0,
                    Format = Format.R32G32B32_Float,
                    Slot = 0,
                    AlignedByteOffset = 0,
                    Classification = InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new InputElement
                {
                    SemanticName = "COLOR",
                    SemanticIndex = 0,
                    Format = Format.R32G32B32A32_Float,
                    Slot = 0,
                    AlignedByteOffset = ColorShader.Vertex.AppendAlignedElement,
                    Classification = InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };
            Layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
            var matrixBufferDesc = new BufferDescription
            {
                Usage = ResourceUsage.Dynamic, // Updated each frame
                SizeInBytes = Utilities.SizeOf<MatrixBuffer>(), // Contains three matrices
                BindFlags = BindFlags.ConstantBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            };
            ConstantMatrixBuffer = new Buffer(device, matrixBufferDesc);
        }
開發者ID:ndech,項目名稱:PlaneSimulator,代碼行數:48,代碼來源:ColorShader.cs

示例12: GetLayout

        public static InputLayout GetLayout(GxContext context, InputElement[] elements, Mesh mesh, ShaderProgram program)
        {
            Dictionary<ShaderProgram, InputLayout> meshEntry;
            InputLayout layout;

            if (Layouts.TryGetValue(mesh, out meshEntry))
            {
                if (meshEntry.TryGetValue(program, out layout))
                    return layout;

                layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements);
                meshEntry.Add(program, layout);
                return layout;
            }

            bool hasInstance = false, hasVertex = false;

            for(var i = 0; i < elements.Length; ++i)
            {
                if (hasInstance && hasVertex)
                    break;

                if(elements[i].Classification == InputClassification.PerInstanceData && hasInstance == false)
                {
                    elements[i].AlignedByteOffset = 0;
                    hasInstance = true;
                    continue;
                }

                if(elements[i].Classification == InputClassification.PerVertexData && hasVertex == false)
                {
                    elements[i].AlignedByteOffset = 0;
                    hasVertex = true;
                }
            }

            layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements);
            meshEntry = new Dictionary<ShaderProgram, InputLayout>()
            {
                {program, layout}
            };

            Layouts.Add(mesh, meshEntry);
            return layout;
        }
開發者ID:Linrasis,項目名稱:WoWEditor,代碼行數:45,代碼來源:InputLayoutCache.cs

示例13: Shader

        public Shader(Device device, string shaderFile, string vertexTarget, string pixelTraget, InputElement[] layouts)
        {
            var shaderString = ShaderBytecode.PreprocessFromFile(shaderFile);

            using (var bytecode = ShaderBytecode.Compile(shaderString, vertexTarget, "vs_4_0"))
            {
                layout = new InputLayout(device, ShaderSignature.GetInputSignature(bytecode), layouts);
                vertShader = new VertexShader(device, bytecode);
            }

            using (var bytecode = ShaderBytecode.Compile(shaderString, pixelTraget, "ps_4_0"))
            {
                pixShader = new PixelShader(device, bytecode);
            }

            OnCleanup += vertShader.Dispose;
            OnCleanup += pixShader.Dispose;
            OnCleanup += layout.Dispose;
        }
開發者ID:Earthmark,項目名稱:Struct-of-Structs,代碼行數:19,代碼來源:Shader.cs

示例14: VertexArrayObject

        private VertexArrayObject(GraphicsDevice graphicsDevice, EffectInputSignature shaderSignature, IndexBufferBinding indexBufferBinding, VertexBufferBinding[] vertexBufferBindings)
            : base(graphicsDevice)
        {
            this.vertexBufferBindings = vertexBufferBindings;
            this.indexBufferBinding = indexBufferBinding;
            this.EffectInputSignature = shaderSignature;

            // Calculate Direct3D11 InputElement
            int inputElementCount = vertexBufferBindings.Sum(t => t.Declaration.VertexElements.Length);
            var inputElements = new InputElement[inputElementCount];

            int j = 0;
            for (int i = 0; i < vertexBufferBindings.Length; i++)
            {
                var declaration = vertexBufferBindings[i].Declaration;
                vertexBufferBindings[i].Buffer.AddReferenceInternal();
                foreach (var vertexElementWithOffset in declaration.EnumerateWithOffsets())
                {
                    var vertexElement = vertexElementWithOffset.VertexElement;
                    inputElements[j++] = new InputElement
                        {
                            Slot = i,
                            SemanticName = vertexElement.SemanticName,
                            SemanticIndex = vertexElement.SemanticIndex,
                            AlignedByteOffset = vertexElementWithOffset.Offset,
                            Format = (SharpDX.DXGI.Format)vertexElement.Format,
                        };
                }
            }

            Layout = VertexArrayLayout.GetOrCreateLayout(new VertexArrayLayout(inputElements));

            if (indexBufferBinding != null)
            {
                indexBufferBinding.Buffer.AddReferenceInternal();
                indexBufferOffset = indexBufferBinding.Offset;
                indexFormat = (indexBufferBinding.Is32Bit ? SharpDX.DXGI.Format.R32_UInt : SharpDX.DXGI.Format.R16_UInt);
            }

            CreateResources();
        }
開發者ID:Powerino73,項目名稱:paradox,代碼行數:41,代碼來源:VertexArrayObject.Direct3D.cs

示例15: PhysicsDebugDraw

        public PhysicsDebugDraw(SharpDX11Graphics graphics)
        {
            device = graphics.Device;
            inputAssembler = device.ImmediateContext.InputAssembler;

            InputElement[] elements = new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
            };
            inputLayout = new InputLayout(device, graphics.GetDebugDrawPass().Description.Signature, elements);

            vertexBufferDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write
            };

            vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);
        }
開發者ID:rhynodegreat,項目名稱:BulletSharp,代碼行數:21,代碼來源:PhysicsDebugDraw.cs


注:本文中的SharpDX.Direct3D11.InputElement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。