public virtual Task ShowWallpaper(WallpaperModel wallpaper, params uint[] screenIndexs) { return(Task.Run(() => { foreach (var index in screenIndexs) { RenderControl renderControl = null; if (!_controls.ContainsKey(index)) { WallpaperManager.UIInvoke(() => { renderControl = _controls[index] = new RenderControl(); renderControl.InitRender(); }); } else { renderControl = _controls[index]; } var host = RenderHost.GetHost(index); WallpaperManager.UIInvoke(() => { host !.ShowWallpaper(renderControl); }); renderControl.Load(wallpaper.Path); } })); }
/// <summary /> public ShaderLibrary(RenderHost renderHost) { Shaders.Add(ShaderDefault = new Default.Shader(renderHost)); Shaders.Add(ShaderPosition = new Position.Shader(renderHost)); Shaders.Add(ShaderPositionColor = new PositionColor.Shader(renderHost)); Shaders.Add(ShaderPositionTexture = new PositionTexture.Shader(renderHost)); }
public virtual void CloseWallpaper(params int[] screenIndexs) { foreach (var(screenIndex, control) in GetControls(screenIndexs)) { control.Stop(); var screen = RenderHost.GetHost(screenIndex); screen.RemoveWallpaper(control); } }
/// <summary /> protected GfxModel(RenderHost renderHost, IModel model) { RenderHost = renderHost; Model = model; if (!(Model.TextureResource is null)) { Texture = RenderHost.TextureLibrary.GetTexture(Model.TextureResource); } }
public ViewModelBase(SWF.IWin32Window hiddenForm, RenderHost renderHost) { this.renderHost = renderHost; colorTextures = new ColorTextures(); textureCache = new TextureCache(colorTextures, renderHost); renderer = new Renderer.Renderer(hiddenForm, renderHost, colorTextures, textureCache); mapLoaded = false; cameraPanScale = 1.0f; cameraScrollScale = 1.0f; }
public virtual void CloseWallpaper(params uint[] screenIndexs) { foreach (var(screenIndex, control) in GetControls(screenIndexs)) { control.Stop(); var host = RenderHost.GetHost(screenIndex, false); if (host != null) { host.RemoveWallpaper(control); } _controls.Remove(screenIndex); } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { EffectsManager = null; RenderHost?.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null disposedValue = true; } }
/// <summary> /// Construct graphics model. /// </summary> public static IGfxModel Factory(RenderHost renderHost, IModel model) { // TODO: solve without switch switch (model.ShaderType) { case ShaderType.Position: return(new Position.GfxModel(renderHost, model)); case ShaderType.PositionColor: return(new PositionColor.GfxModel(renderHost, model)); default: throw new ArgumentOutOfRangeException(nameof(model.ShaderType), model.ShaderType, default); } }
public virtual Task ShowWallpaper(WallpaperModel wallpaper, params int[] screenIndexs) { foreach (var index in screenIndexs) { if (!_controls.ContainsKey(index)) { _controls[index] = new RenderControl(); _controls[index].InitRender(); } var screen = RenderHost.GetHost(index); screen.ShowWallpaper(_controls[index]); _controls[index].Load(wallpaper.Path); } return(Task.CompletedTask); }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { EffectsManager = null; Camera = null; Items.Clear(); RenderHost.Dispose(); CameraController.Dispose(); DisplayInformation.GetForCurrentView().DpiChanged -= Viewport3DX_DpiChanged; } disposedValue = true; } }
/// <summary> /// Renders this instance. /// </summary> public void Render() { RenderHost.UpdateAndRender(); }
/// <summary> /// Resizes the specified width. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public void Resize(int width, int height) { ActualWidth = width; ActualHeight = height; RenderHost.Resize(width, height); }
/// <summary> /// Invalidates the scene graph. /// </summary> public void InvalidateSceneGraph() { RenderHost.InvalidateSceneGraph(); }
/// <summary /> public GfxModel(RenderHost renderHost, IModel model) : base(model, renderHost.ShaderLibrary.ShaderPosition, new BufferBinding(model.Positions)) { Shader = renderHost.ShaderLibrary.ShaderPosition; }
public GfxModel(RenderHost renderHost, IModel model) : base(renderHost, model, renderHost.ShaderLibrary.ShaderPositionColor, new BufferBinding(model.Positions, model.Colors)) { Shader = renderHost.ShaderLibrary.ShaderPositionColor; }
public GfxModel(RenderHost renderHost, IModel model) : base(renderHost, model, renderHost.ShaderLibrary.ShaderPositionTexture, new BufferBinding(model.Positions, model.TextureCoordinates)) { Shader = renderHost.ShaderLibrary.ShaderPositionTexture; }
/// <summary> /// Invalidates the render. /// </summary> public void InvalidateRender() { RenderHost.InvalidateRender(); }
public TextureCache(ColorTextures colorTextures, RenderHost renderHost) { this.colorTextures = colorTextures; this.renderHost = renderHost; textures = new ConcurrentDictionary <string, TextureAndSRV>(); }
/// <summary /> protected GfxModel(RenderHost renderHost, IModel model, IShader <TVsIn, TPsIn> shader, IBufferBinding <TVsIn> bufferBinding) : base(renderHost, model) { Shader = shader; BufferBinding = bufferBinding; }
/// <inheritdoc /> protected Shader(RenderHost renderHost) { RenderHost = renderHost; Pipeline = new Pipeline <TVsIn, TPsIn>(this); }
/// <summary> /// Starts the d3 d. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public void StartD3D(int width, int height) { RenderHost.StartD3D(width, height); }
/// <summary> /// Ends the d3 d. /// </summary> public void EndD3D() { RenderHost.EndD3D(); }
private void Items_Invalidated(object sender, InvalidateTypes e) { RenderHost?.Invalidate(e); }
/// <summary /> public ShaderLibrary(RenderHost renderHost) { Shaders.Add(ShaderPosition = new Position.Shader(renderHost)); Shaders.Add(ShaderPositionColor = new PositionColor.Shader(renderHost)); }
/// <summary /> public GfxModel(RenderHost renderHost, IModel model) { RenderHost = renderHost; Model = model; Textures = Model.TextureResources?.Select(tr => RenderHost.TextureLibrary.GetTexture(tr)).ToArray(); }
public Shader(RenderHost renderHost) : base(renderHost) { }
public Renderer(IWin32Window form, RenderHost renderHost, ColorTextures colorTextures, TextureCache textureCache) { this.renderHost = renderHost; this.textureCache = textureCache; this.colorTextures = colorTextures; sceneElements = new List <SceneElement>(); // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(100, 100, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; #if DEBUG var flag = DeviceCreationFlags.Debug; #else var flag = DeviceCreationFlags.None; #endif // Create Device and SwapChain Device.CreateWithSwapChain(DriverType.Hardware, flag | DeviceCreationFlags.BgraSupport, desc, out device, out swapChain); immediateContext = device.ImmediateContext; // Initialize helper classes colorTextures.Initialize(device); textureCache.Initialize(device); // Load the Vertex and Pixel shaders ShaderBytecode vertexShaderByteCode; using (var stream = new MemoryStream(Resources.vs)) { vertexShaderByteCode = ShaderBytecode.FromStream(stream); vertexShader = new VertexShader(device, vertexShaderByteCode); } immediateContext.VertexShader.Set(vertexShader); ShaderBytecode pixelShaderByteCode; using (var stream = new MemoryStream(Resources.ps)) { pixelShaderByteCode = ShaderBytecode.FromStream(stream); pixelShader = new PixelShader(device, pixelShaderByteCode); } immediateContext.PixelShader.Set(pixelShader); // Create the input layout for the COMPLEX vertex inputLayout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0) }); immediateContext.InputAssembler.InputLayout = inputLayout; immediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; // Release the bytecode vertexShaderByteCode.Dispose(); pixelShaderByteCode.Dispose(); // Create Constant Buffer vertexShaderPerFrameConstantBuffer = new Buffer(device, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); immediateContext.VertexShader.SetConstantBuffer(0, vertexShaderPerFrameConstantBuffer); // Create the default texture sampler textureSamplerWrap = new SamplerState(device, new SamplerStateDescription { Filter = Filter.MinMagMipPoint, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0.0f, 0.0f, 0.0f, 0.0f), ComparisonFunction = Comparison.Always, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = 0, MaximumLod = 3.402823466e+38f//D3D11_FLOAT32_MAX }); textureSamplerBorder = new SamplerState(device, new SamplerStateDescription { Filter = Filter.MinMagMipPoint, AddressU = TextureAddressMode.Border, AddressV = TextureAddressMode.Border, AddressW = TextureAddressMode.Border, BorderColor = new Color4(0.0f, 0.0f, 0.0f, 0.0f), ComparisonFunction = Comparison.Always, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = 0, MaximumLod = 3.402823466e+38f//D3D11_FLOAT32_MAX }); // Prepare the camera Camera = new Camera(); // Create the depth stencil state depthStencilState = new DepthStencilState(device, new DepthStencilStateDescription { IsDepthEnabled = true, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.GreaterEqual, IsStencilEnabled = false, StencilReadMask = 0xff, //D3D11_DEFAULT_STENCIL_READ_MASK StencilWriteMask = 0xff, //D3D11_DEFAULT_STENCIL_WRITE_MASK FrontFace = new DepthStencilOperationDescription { DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Replace, Comparison = Comparison.Always }, BackFace = new DepthStencilOperationDescription { DepthFailOperation = StencilOperation.Keep, FailOperation = StencilOperation.Keep, PassOperation = StencilOperation.Replace, Comparison = Comparison.Always } }); // Create the raster state defaultRastState = new RasterizerState(device, new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.Back, DepthBias = 0, DepthBiasClamp = 0.0f, IsDepthClipEnabled = true, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }); wireframeOverlayRastState = new RasterizerState(device, new RasterizerStateDescription { IsAntialiasedLineEnabled = false, CullMode = CullMode.Back, DepthBias = (int)(Math.Pow(2.0, 23.0) / 1000), DepthBiasClamp = 0.001f, IsDepthClipEnabled = true, FillMode = FillMode.Wireframe, IsFrontCounterClockwise = false, IsMultisampleEnabled = true, IsScissorEnabled = false, SlopeScaledDepthBias = 0 }); // Create the blend state var blendDesc = new BlendStateDescription { AlphaToCoverageEnable = false, IndependentBlendEnable = false }; for (var i = 0; i < 8; ++i) { blendDesc.RenderTarget[i].IsBlendEnabled = true; blendDesc.RenderTarget[i].BlendOperation = BlendOperation.Add; blendDesc.RenderTarget[i].AlphaBlendOperation = BlendOperation.Add; blendDesc.RenderTarget[i].DestinationBlend = BlendOption.InverseSourceAlpha; blendDesc.RenderTarget[i].DestinationAlphaBlend = BlendOption.One; blendDesc.RenderTarget[i].RenderTargetWriteMask = ColorWriteMaskFlags.All; blendDesc.RenderTarget[i].SourceBlend = BlendOption.SourceAlpha; blendDesc.RenderTarget[i].SourceAlphaBlend = BlendOption.One; } blendState = new BlendState(device, blendDesc); // Prepare the stages that don't change per frame immediateContext.OutputMerger.SetDepthStencilState(depthStencilState); immediateContext.OutputMerger.SetBlendState(blendState); immediateContext.PixelShader.SetSampler(0, textureSamplerWrap); }