Exemplo n.º 1
0
        void SetNoteShaderConstants(DeviceContext context, NotesGlobalConstants constants)
        {
            DataStream data;

            context.MapSubresource(globalNoteConstants, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out data);
            data.Write(constants);
            context.UnmapSubresource(globalNoteConstants, 0);
            context.VertexShader.SetConstantBuffer(0, globalNoteConstants);
            context.GeometryShader.SetConstantBuffer(0, globalNoteConstants);
            data.Dispose();
        }
Exemplo n.º 2
0
        void Attach()
        {
            disposer = new DisposeGroup();

            var device = Renderer.Device;

            string noteShaderData;
            var    assembly = Assembly.GetExecutingAssembly();

            using (var stream = assembly.GetManifestResourceStream("Iris.Previews.DX11.notes.fx"))
                using (var reader = new IO.StreamReader(stream))
                    noteShaderData = reader.ReadToEnd();
            notesShader = disposer.Add(new ShaderManager(
                                           device,
                                           ShaderBytecode.Compile(noteShaderData, "VS_Note", "vs_4_0", ShaderFlags.None, EffectFlags.None),
                                           ShaderBytecode.Compile(noteShaderData, "PS", "ps_4_0", ShaderFlags.None, EffectFlags.None),
                                           ShaderBytecode.Compile(noteShaderData, "GS_Note", "gs_4_0", ShaderFlags.None, EffectFlags.None)
                                           ));

            noteLayout = disposer.Add(new InputLayout(device, ShaderSignature.GetInputSignature(notesShader.vertexShaderByteCode), new[] {
                new InputElement("START", 0, Format.R32_Float, 0, 0),
                new InputElement("END", 0, Format.R32_Float, 4, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 8, 0),
            }));

            noteConstants = new NotesGlobalConstants()
            {
                NoteBorder   = 0.002f,
                NoteLeft     = -0.2f,
                NoteRight    = 0.0f,
                ScreenAspect = 1f
            };

            noteBuffer = new Buffer(device, new BufferDescription()
            {
                BindFlags           = BindFlags.VertexBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = 40 * noteBufferLength,
                Usage               = ResourceUsage.Dynamic,
                StructureByteStride = 0
            });

            globalNoteConstants = new Buffer(device, new BufferDescription()
            {
                BindFlags           = BindFlags.ConstantBuffer,
                CpuAccessFlags      = CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.None,
                SizeInBytes         = 32,
                Usage               = ResourceUsage.Dynamic,
                StructureByteStride = 0
            });

            var renderTargetDesc = new RenderTargetBlendDescription();

            renderTargetDesc.IsBlendEnabled        = true;
            renderTargetDesc.SourceBlend           = BlendOption.SourceAlpha;
            renderTargetDesc.DestinationBlend      = BlendOption.InverseSourceAlpha;
            renderTargetDesc.BlendOperation        = BlendOperation.Add;
            renderTargetDesc.SourceAlphaBlend      = BlendOption.One;
            renderTargetDesc.DestinationAlphaBlend = BlendOption.One;
            renderTargetDesc.AlphaBlendOperation   = BlendOperation.Add;
            renderTargetDesc.RenderTargetWriteMask = ColorWriteMaskFlags.All;

            BlendStateDescription desc = new BlendStateDescription();

            desc.AlphaToCoverageEnable  = false;
            desc.IndependentBlendEnable = false;
            desc.RenderTarget[0]        = renderTargetDesc;

            var blendStateEnabled = new BlendState(device, desc);

            device.ImmediateContext.OutputMerger.SetBlendState(blendStateEnabled);

            RasterizerStateDescription renderStateDesc = new RasterizerStateDescription
            {
                CullMode                 = CullMode.None,
                DepthBias                = 0,
                DepthBiasClamp           = 0,
                FillMode                 = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = false,
                IsFrontCounterClockwise  = false,
                IsMultisampleEnabled     = true,
                IsScissorEnabled         = false,
                SlopeScaledDepthBias     = 0
            };
            var rasterStateSolid = new RasterizerState(device, renderStateDesc);

            device.ImmediateContext.Rasterizer.State = rasterStateSolid;
        }