public AnimatedCursor(Context context, IRenderDevice device, iPipelineStateFactory stateFactory, iShaderFactory shaderFactory, iStorageFolder assets) { constantBuffer = device.CreateDynamicUniformBuffer <AnimatedConstantBuffer>("Animated cursor CB"); PipelineStateDesc desc = createStateDesc(context); desc.premultipliedBlendingMaxAlpha(); initState(stateFactory, shaderFactory, assets, "AniCursorVS.hlsl", "AniCursorPS.hlsl", "Animated cursor"); stateFactory.apply(ref desc); pipelineState = device.CreatePipelineState(ref desc); pipelineState.GetStaticVariableByName(ShaderType.Vertex, "CursorCB").Set(constantBuffer); pipelineState.GetStaticVariableByName(ShaderType.Pixel, "CursorCB").Set(constantBuffer); bindings = pipelineState.CreateShaderResourceBinding(true); textureVariable = bindings.GetVariableByName(ShaderType.Pixel, "g_Texture"); animatedConstants = default; timers = context.animation.timers; lastFrameSwitch = timers[animationTimer]; lastRendered = lastFrameSwitch; frameDuration = default; animationFrames = 0; }
public Nv12State(IRenderDevice device, TextureFormat format, Nv12Texture[] textures, ref sDecodedVideoSize videoSize) { // Create the pipeline state var pso = new PipelineStateDesc(false); pso.GraphicsPipeline.DepthStencilDesc.DepthEnable = false; pso.GraphicsPipeline.RasterizerDesc.CullMode = CullMode.None; pso.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList; pso.GraphicsPipeline.NumRenderTargets = 1; pso.GraphicsPipeline.setRTVFormat(0, format); pso.ResourceLayout.DefaultVariableType = ShaderResourceVariableType.Static; var compiler = device.GetShaderFactory(); iStorageFolder assets = StorageFolder.embeddedResources(System.Reflection.Assembly.GetExecutingAssembly(), resourceFolder); using (var psf = device.CreatePipelineStateFactory()) { psf.setName("Video PSO"); using (var vs = compiler.compileHlslFile(assets, "VideoVS.hlsl", ShaderType.Vertex)) psf.graphicsVertexShader(vs); using (var ps = compilePixelShader(compiler, assets)) psf.graphicsPixelShader(ps); psf.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Dynamic, varTexture); var sampler = samplerDesc(); psf.layoutStaticSampler(ShaderType.Pixel, ref sampler, varTexture); psf.apply(ref pso); pipelineState = device.CreatePipelineState(ref pso); } // Create resource binding and cache the variable binding = pipelineState.CreateShaderResourceBinding(true); textureVariable = binding.GetVariableByName(ShaderType.Pixel, varTexture); // Copy views of the textures into array sourceTextures = new ITextureView[textures.Length]; for (int i = 0; i < textures.Length; i++) { sourceTextures[i] = textures[i].view; } // Create GL viewport structure with weird values for cropping the video viewport = new Viewport(false) { TopLeftX = -videoSize.cropRect.left, // TopLeftY = videoSize.cropRect.top, // OpenGL uses opposite Y direction there. TopLeftY = videoSize.cropRect.bottom - videoSize.size.cy, Width = videoSize.size.cx, Height = videoSize.size.cy, }; }
public RenderBase(IRenderDevice device, CSize renderTargetSize, SwapChainFormats formats, Vector4 borderColor, sDecodedVideoSize videoSize) { this.videoSize = videoSize; // Create vertex buffer vertexBuffer = createVideoVertexBuffer(device, renderTargetSize, ref videoSize); // Create pipeline state var pso = new PipelineStateDesc(false); pso.GraphicsPipeline.DepthStencilDesc.DepthEnable = false; pso.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList; pso.GraphicsPipeline.NumRenderTargets = 1; pso.GraphicsPipeline.setRTVFormat(0, formats.color); pso.GraphicsPipeline.DSVFormat = formats.depth; pso.ResourceLayout.DefaultVariableType = ShaderResourceVariableType.Static; var compiler = device.GetShaderFactory(); iStorageFolder assets = StorageFolder.embeddedResources(System.Reflection.Assembly.GetExecutingAssembly(), resourceFolder); using (var psf = device.CreatePipelineStateFactory()) { psf.setName("Video PSO"); setupVideoInputLayout(psf); using (var vs = compiler.compileHlslFile(assets, "VideoVS.hlsl", ShaderType.Vertex)) psf.graphicsVertexShader(vs); (string uvMin, string uvMax) = videoUvCroppedRect(ref videoSize); string colorString = Utils.printFloat4(borderColor); using (var ps = compilePixelShader(compiler, assets, uvMin, uvMax, colorString)) psf.graphicsPixelShader(ps); psf.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Dynamic, varTexture); var sampler = new SamplerDesc(false) { MipFilter = FilterType.Point, }; psf.layoutStaticSampler(ShaderType.Pixel, ref sampler, varTexture); psf.apply(ref pso); pipelineState = device.CreatePipelineState(ref pso); } // Create resource binding and cache the variable, we gonna need both on every frame rendered binding = pipelineState.CreateShaderResourceBinding(true); textureVariable = binding.GetVariableByName(ShaderType.Pixel, varTexture); }
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; }
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; }