예제 #1
0
        public StaticCursor(Context context, IRenderDevice device, iPipelineStateFactory stateFactory, iShaderFactory shaderFactory, iStorageFolder assets, IShader vs)
        {
            constantBuffer = device.CreateDynamicUniformBuffer <Vector4>("Cursor CB");

            PipelineStateDesc desc = createStateDesc(context);

            desc.premultipliedAlphaBlending();

            initState(stateFactory, shaderFactory, assets, vs, "CursorPS.hlsl", "Cursor");

            stateFactory.apply(ref desc);
            pipelineState = device.CreatePipelineState(ref desc);
            pipelineState.GetStaticVariableByName(ShaderType.Vertex, "CursorCB").Set(constantBuffer);

            bindings        = pipelineState.CreateShaderResourceBinding(true);
            textureVariable = bindings.GetVariableByName(ShaderType.Pixel, "g_Texture");

            position = default;
        }
예제 #2
0
        public Blender(Context context, IRenderDevice device, byte samplesCount)
        {
            PipelineStateDesc desc = new PipelineStateDesc(false);

            desc.setBufferFormats(context);
            desc.premultipliedAlphaBlending();
            desc.GraphicsPipeline.PrimitiveTopology            = PrimitiveTopology.TriangleList;
            desc.GraphicsPipeline.RasterizerDesc.CullMode      = CullMode.None;
            desc.GraphicsPipeline.DepthStencilDesc.DepthEnable = false;

            iShaderFactory shaderFactory = device.GetShaderFactory();
            iStorageFolder assets        = StorageFolder.embeddedResources(Assembly.GetExecutingAssembly(), resourceSubfolder);

            using (iPipelineStateFactory stateFactory = device.CreatePipelineStateFactory())
            {
                stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, textureVarName);

                stateFactory.graphicsVertexShader(shaderFactory.compileShader(assets, "Blend", ShaderType.Vertex));

                ShaderSourceInfo ssi;
                string           src;
                if (RuntimeEnvironment.operatingSystem == eOperatingSystem.Windows)
                {
                    ssi = new ShaderSourceInfo(ShaderType.Pixel, ShaderSourceLanguage.Hlsl);
                    src = "BlendPS.hlsl";
                }
                else
                {
                    ssi = new ShaderSourceInfo(ShaderType.Pixel, ShaderSourceLanguage.Glsl);
                    ssi.combinedTextureSamplers = true;
                    src = "BlendPS.glsl";
                }

                string name = $"BlendPS { samplesCount }x";
                var    ps   = shaderFactory.compileFromFile(assets, src, ssi, name, shaderMacros(samplesCount));
                stateFactory.graphicsPixelShader(ps);

                stateFactory.apply(ref desc);
                pipelineState = device.CreatePipelineState(ref desc);
            }
            this.samplesCount = samplesCount;
        }
예제 #3
0
        public MonoCursor(Context context, IRenderDevice device, iPipelineStateFactory stateFactory, iShaderFactory shaderFactory, iStorageFolder assets, IShader vs)
        {
            constantBuffer = device.CreateDynamicUniformBuffer <Vector4>("Cursor CB");

            PipelineStateDesc desc = createStateDesc(context);

            // === First pass, setup that weird blending to invert colors ===
            RenderTargetBlendDesc blendDesc = new RenderTargetBlendDesc(false)
            {
                BlendEnable = true,
                SrcBlend    = BlendFactor.InvDestColor,
                DestBlend   = BlendFactor.Zero,
            };

            desc.GraphicsPipeline.BlendDesc.setRenderTarget(blendDesc);
            initState(stateFactory, shaderFactory, assets, vs, "CursorMaskPS.hlsl", "Invert bits");

            stateFactory.apply(ref desc);
            psoInvert = device.CreatePipelineState(ref desc);
            psoInvert.GetStaticVariableByName(ShaderType.Vertex, "CursorCB").Set(constantBuffer);

            bindingsInvert        = psoInvert.CreateShaderResourceBinding(true);
            textureVariableInvert = bindingsInvert.GetVariableByName(ShaderType.Pixel, "g_Texture");

            // === Second pass, normal alpha blending ===
            desc.premultipliedAlphaBlending();
            initState(stateFactory, shaderFactory, assets, vs, "CursorColorPS.hlsl", "Monochrome cursor");

            stateFactory.apply(ref desc);
            psoRgb = device.CreatePipelineState(ref desc);
            psoRgb.GetStaticVariableByName(ShaderType.Vertex, "CursorCB").Set(constantBuffer);

            bindingsRgb        = psoRgb.CreateShaderResourceBinding(true);
            textureVariableRgb = bindingsRgb.GetVariableByName(ShaderType.Pixel, "g_Texture");

            position = default;
        }