Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        void SetupShadersAndLayouts()
        {
            ps = PixelShader == null ? null : new D3DPixelShader(device.Device, PixelShader.Bytecode);
            vs = VertexShader == null ? null : new D3DVertexShader(device.Device, VertexShader.Bytecode);
            gs = GeometryShader == null ? null : new D3DGeometryShader(device.Device, GeometryShader.Bytecode);
            hs = HullShader == null ? null : new D3DHullShader(device.Device, HullShader.Bytecode);
            ds = DomainShader == null ? null : new D3DDomainShader(device.Device, DomainShader.Bytecode);
            cs = ComputeShader == null ? null : new D3DComputeShader(device.Device, ComputeShader.Bytecode);

            if (cs != null)
            {
                if (ps != null || vs != null || gs != null || hs != null || ds != null)
                {
                    throw new InvalidOperationException("If ComputeShader is set, other shader must be set null.");
                }
            }
            else
            {
                if (vs == null)
                {
                    throw new InvalidOperationException("Vertex shader must be set.");
                }
            }



            if (VertexInputElements == null)
            {
                inputLayout = null;
            }
            else
            {
                inputLayout = new InputLayout(device.Device, VertexShader.Bytecode, VertexInputElement.Convert(VertexInputElements));
            }



            if (VertexOutputElements != null)
            {
                if (GeometryShader == null)
                {
                    throw new InvalidOperationException("Geometry shader is required for vertex output.");
                }

                var outputElements  = VertexOutputElement.Convert(VertexOutputElements);
                int maxBuffers      = outputElements.Max(oe => oe.OutputSlot) + 1;
                var bufferedStrides = new int[maxBuffers];

                for (int i = 0; i < maxBuffers; i++)
                {
                    bufferedStrides[i] = outputElements
                                         .Where(oe1 => oe1.OutputSlot == i)
                                         .Sum(oe2 => oe2.ComponentCount) * 4;
                }

                gs = new D3DGeometryShader(device.Device, GeometryShader.Bytecode, outputElements, bufferedStrides, RasterizedStream);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Converts VertexOutputElement to StreamOutputElement
		/// </summary>
		/// <param name="elements"></param>
		/// <returns></returns>
		static internal StreamOutputElement[] Convert ( VertexOutputElement[] elements )
		{
			return elements.Select( e => new StreamOutputElement() {
					ComponentCount	=	e.ComponentCount,
					OutputSlot		=	e.OutputSlot,
					SemanticIndex	=	e.SemanticIndex,
					SemanticName	=	e.SemanticName,
					StartComponent	=	e.StartComponent,
					Stream			=	e.Stream
				} ).ToArray();
		}