/// <summary> /// Called when the selection of the top ListView has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ListViewItemSelectionChangedEventArgs"/> instance containing the event data.</param> private void OnListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (!e.IsSelected) { e.Item.BackColor = System.Drawing.Color.Transparent; return; } else { e.Item.BackColor = System.Drawing.Color.LightBlue; } ListView actListView = sender as ListView; actListView.EnsureNotNull(nameof(actListView)); e.Item.EnsureNotNull($"{nameof(e)}.{nameof(e.Item)}"); SampleDescription sampleInfo = e.Item.Tag as SampleDescription; sampleInfo.EnsureNotNull(nameof(sampleInfo)); // Clear selection on other ListViews foreach (ListView actOtherListView in m_generatedListViews) { if (actOtherListView == actListView) { continue; } actOtherListView.SelectedItems.Clear(); } // Now apply the sample this.ApplySample(sampleInfo); }
public ScreenContext(Control owner, RenderContext context, MatrixManager manager) : base(context) { Device device = context.DeviceManager.Device; SampleDescription sampleDesc = new SampleDescription(1, 0); this.SwapChain = new SwapChain(context.DeviceManager.Factory, device, getSwapChainDescription(owner, sampleDesc)); //Set rasterizer //Initialization of the depth stencil Buffa using (Texture2D depthBuffer = new Texture2D(device, getDepthBufferTexture2DDescription(owner, sampleDesc))) { this.DepthTargetView = new DepthStencilView(device, depthBuffer); } //Initializing render targets using (Texture2D renderTexture = Resource.FromSwapChain <Texture2D>(this.SwapChain, 0)) { this.RenderTargetView = new RenderTargetView(device, renderTexture); } this.WorldSpace = new WorldSpace(context); this.BindedControl = owner; this.MatrixManager = manager; this.PanelObserver = new PanelObserver(owner); SetViewport(); this.HitChekcer = new TexturedBufferHitChecker(this.Context, this); this.HitChekcer.Resize(owner.ClientSize); owner.MouseMove += owner_MouseMove; owner.MouseDown += owner_MouseDown; owner.MouseUp += owner_MouseUp; }
internal void LoadWithAA(int AA) { var AntiAliasing = new SampleDescription(AA, 0); Utilities.Dispose(ref ShadowShader); ShadowShader = new ShadowShader(Device); Utilities.Dispose(ref AntiAliasedBackBuffer); AntiAliasedBackBuffer = new Texture2D(Device, new Texture2DDescription { Format = Resolution.Format, Width = Resolution.Width, Height = Resolution.Height, ArraySize = 1, MipLevels = 1, BindFlags = BindFlags.RenderTarget, SampleDescription = AntiAliasing }); Utilities.Dispose(ref CameraDepth); CameraDepth = new Depth(Device, Resolution, AntiAliasing); Utilities.Dispose(ref ShadowDepth); ShadowDepth = new Depth(Device, new ModeDescription { Width = 1650 * AA, Height = 1650 * AA }, new SampleDescription(1, 0)); Utilities.Dispose(ref CameraShader); CameraShader = new CameraShader(Device, Resolution, ShadowDepth.DepthStencilView.Resource, AA); }
// Create or dispose the MSAA buffers private void UpdateMsaaBackBuffer(int width, int height, int multisamplingCount) { if (multisamplingCount <= 0 || width <= 0 || height <= 0) { DiposeMsaaBuffers(); return; } if (_msaaBackBuffer != null && _msaaBackBufferDescription.Width == width && _msaaBackBufferDescription.Height == height && _msaaBackBufferDescription.SampleDescription.Count == multisamplingCount) { // We already have the correct MSAA back buffer return; } // Dispose existing buffers DiposeMsaaBuffers(); var sampleDescription = new SampleDescription(multisamplingCount, 0); var dxDevice = parentDXScene.DXDevice; _msaaBackBufferDescription = dxDevice.CreateTexture2DDescription(width, height, sampleDescription, isRenderTarget: true, isSharedResource: false, isStagingTexture: false, isShaderResource: false, format: Format.B8G8R8A8_UNorm); _msaaBackBuffer = dxDevice.CreateTexture2D(_msaaBackBufferDescription); _msaaBackBufferRenderTargetView = new RenderTargetView(dxDevice.Device, _msaaBackBuffer); _msaaDepthStencilView = dxDevice.CreateDepthStencilView(width, height, sampleDescription, DXDevice.StandardDepthStencilFormat); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; _vsync = vsync; FeatureLevel[] features = { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0 }; SharpDX.Direct3D11.Device dev11 = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.None, features); _dev = dev11.QueryInterfaceOrNull <SharpDX.Direct3D11.Device1>(); SampleDescription sampleDesc = new SampleDescription(); do { if (_dev.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, (int)samples) > 0) { sampleDesc.Count = (int)samples; sampleDesc.Quality = 0; break; } else { samples >>= 1; } } while (samples > 0); SwapChainDescription1 desc = new SwapChainDescription1(); desc.Width = 0; desc.Height = 0; desc.Format = sRGB ? Format.R8G8B8A8_UNorm_SRgb : Format.R8G8B8A8_UNorm; desc.Scaling = Scaling.None; desc.SampleDescription = sampleDesc; desc.Usage = Usage.RenderTargetOutput; desc.BufferCount = 2; desc.SwapEffect = SwapEffect.FlipSequential; desc.Flags = SwapChainFlags.None; SharpDX.DXGI.Device2 dev = _dev.QueryInterface <SharpDX.DXGI.Device2>(); Adapter adapter = dev.Adapter; Factory2 factory = adapter.GetParent <Factory2>(); if (display == IntPtr.Zero) { GCHandle handle = (GCHandle)window; SharpDX.ComObject coreWindow = new SharpDX.ComObject(handle.Target as object); _swapChain = new SwapChain1(factory, _dev, coreWindow, ref desc); } else { _swapChain = new SwapChain1(factory, _dev, window, ref desc); } _device = new RenderDeviceD3D11(_dev.ImmediateContext.NativePointer, sRGB); }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared) { _msSampleDescription = GraphicsDevice.GetSupportedSampleDescription(SharpDXHelper.ToFormat(this.Format), this.MultiSampleCount); GenerateIfRequired(); }
public ScreenContext(Control owner, 行列管理 manager) : base() { // SwapChain の生成 var d3ddevice = RenderContext.Instance.DeviceManager.D3DDevice; var sampleDesc = new SampleDescription(1, 0); this.SwapChain = new SwapChain(RenderContext.Instance.DeviceManager.DXGIFactory, d3ddevice, getSwapChainDescription(owner, sampleDesc)); //ラスタライザの設定 //深度ステンシルバッファの初期化 using (var depthBuffer = new Texture2D(d3ddevice, getDepthBufferTexture2DDescription(owner, sampleDesc))) { this.深度ステンシルビュー = new DepthStencilView(d3ddevice, depthBuffer); } //レンダーターゲットの初期化 using (Texture2D renderTexture = Resource.FromSwapChain <Texture2D>(SwapChain, 0)) { this.D3Dレンダーターゲットビュー = new RenderTargetView(d3ddevice, renderTexture); } // その他 this.ワールド空間 = new ワールド空間(); this.BindedControl = owner; this.行列管理 = manager; this.パネル監視 = new マウス監視(owner); this.ビューポートを設定する(); }
private ShaderResourceViewProxy CreateRenderTarget(int width, int height, MSAALevel msaa) { #if MSAA MSAA = msaa; #endif TargetWidth = width; TargetHeight = height; DisposeBuffers(); ColorBufferSampleDesc = GetMSAASampleDescription(); OnCreateRenderTargetAndDepthBuffers(width, height, UseDepthStencilBuffer, out colorBuffer, out depthStencilBuffer); backBuffer = OnCreateBackBuffer(width, height); backBuffer.CreateRenderTargetView(); fullResPPBuffer = Collect(new PingPongColorBuffers(Format, width, height, this.deviceResources)); fullResDepthStencilPool = Collect(new TexturePool(this.deviceResources, new Texture2DDescription() { Width = width, Height = height, ArraySize = 1, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0) })); Initialized = true; OnNewBufferCreated?.Invoke(this, new Texture2DArgs(backBuffer)); return(backBuffer); }
private void CreateSwapChainForDesktop() { ModeDescription BackBufferDesc = new ModeDescription() { Width = Description.BackBufferWidth, Height = Description.BackBufferHeight, Format = Format.R8G8B8A8_UNorm, RefreshRate = new Rational() { Numerator = 60, Denominator = 1 }, ScanlineOrdering = ModeScanlineOrder.Unspecified, Scaling = ModeScaling.Unspecified, }; SampleDescription sampleDescription = new SampleDescription() { Count = 1, Quality = 0 }; SwapChainFlags Flags = Description.Settings.Fullscreen ? SwapChainFlags.None : SwapChainFlags.AllowModeSwitch; SwapChainDescription swapChainDesc = new SwapChainDescription() // Initialize the swap chain description. { BufferCount = bufferCount, // Set to a single back buffer. BufferDescription = BackBufferDesc, // Set the width and height of the back buffer. Usage = Usage.Backbuffer | Usage.RenderTargetOutput, // Set the usage of the back buffer. OutputWindow = Description.DeviceHandle, // Set the handle for the window to render to. SampleDescription = sampleDescription, // Turn multisampling off. IsWindowed = true, // Set to full screen or windowed mode. Flags = Flags, // Don't set the advanced flags. SwapEffect = SwapEffect.FlipDiscard, // Discard the back buffer content after presenting. }; IDXGIFactory4 Factory = GraphicsDevice.NativeAdapter.NativeFactory; IDXGISwapChain swapChain = Factory.CreateSwapChain(GraphicsDevice.NativeDirectCommandQueue.Queue, swapChainDesc); if (Description.Settings.Fullscreen) { // Before fullscreen switch swapChain.ResizeTarget(BackBufferDesc); // Switch to full screen swapChain.SetFullscreenState(true, default); // This is really important to call ResizeBuffers AFTER switching to IsFullScreen swapChain.ResizeBuffers(3, Description.BackBufferWidth, Description.BackBufferHeight, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch); } NativeSwapChain = swapChain.QueryInterface <IDXGISwapChain3>(); }
public DX11CubeDepthStencil(DX11RenderContext context, int size, SampleDescription sd, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, MipLevels = 1 }; this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.SliceDSV = new DX11SliceDepthStencil[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize= 6, Dimension = DepthStencilViewDimension.Texture2DArray, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format), MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); for (int i = 0; i < 6; i++) { this.SliceDSV[i] = new DX11SliceDepthStencil(context, this, i, DepthFormatsHelper.GetDepthFormat(format)); } }
public static void CreateDeviceSwapChainAndRenderTarget(Form form, out Device device, out SwapChain swapChain, out RenderTargetView renderTarget) { try { // the debug mode requires the sdk to be installed otherwise an exception is thrown device = new Device(DeviceCreationFlags.Debug); } catch (Direct3D10Exception) { device = new Device(DeviceCreationFlags.None); } var swapChainDescription = new SwapChainDescription(); var modeDescription = new ModeDescription(); var sampleDescription = new SampleDescription(); modeDescription.Format = Format.R8G8B8A8_UNorm; modeDescription.RefreshRate = new Rational(60, 1); modeDescription.Scaling = DisplayModeScaling.Unspecified; modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified; modeDescription.Width = WIDTH; modeDescription.Height = HEIGHT; sampleDescription.Count = 1; sampleDescription.Quality = 0; swapChainDescription.ModeDescription = modeDescription; swapChainDescription.SampleDescription = sampleDescription; swapChainDescription.BufferCount = 1; swapChainDescription.Flags = SwapChainFlags.None; swapChainDescription.IsWindowed = true; swapChainDescription.OutputHandle = form.Handle; swapChainDescription.SwapEffect = SwapEffect.Discard; swapChainDescription.Usage = Usage.RenderTargetOutput; using (var factory = new Factory()) { swapChain = new SwapChain(factory, device, swapChainDescription); } using (var resource = swapChain.GetBuffer<Texture2D>(0)) { renderTarget = new RenderTargetView(device, resource); } var viewport = new Viewport { X = 0, Y = 0, Width = WIDTH, Height = HEIGHT, MinZ = 0.0f, MaxZ = 1.0f }; device.Rasterizer.SetViewports(viewport); device.OutputMerger.SetTargets(renderTarget); }
private void CreateDeviceAndSwapChain(SampleDescription sampleDesc) { Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, new SwapChainDescription { BufferCount = 2, ModeDescription = new ModeDescription { Width = viewportControl.Width, Height = viewportControl.Height, RefreshRate = new Rational(60, 1), Format = Format.R8G8B8A8_UNorm }, IsWindowed = true, OutputHandle = viewportControl.Handle, //sample desc of render target and depth buffers must match SampleDescription = sampleDesc, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }, out device, out swapChain); FeatureLevel level = Device.GetSupportedFeatureLevel(); factory = swapChain.GetParent <Factory>(); backBufferTex = Texture2D.FromSwapChain <Texture2D>(swapChain, 0); backBufView = new RenderTargetView(device, backBufferTex); }
public TextureTargetContext(RenderContext context, Size size, SampleDescription sampleDesc) : this(context, new MatrixManager(new BasicWorldMatrixProvider(), new BasicCamera(new Vector3(0, 20, -200), new Vector3(0, 3, 0), new Vector3(0, 1, 0)), new BasicProjectionMatrixProvider()) , size, sampleDesc) { this.MatrixManager.ProjectionMatrixManager.InitializeProjection((float)Math.PI / 4f, (float)size.Width / size.Height, 1, 2000); }
private void CreateDepthStencilAndViews(SampleDescription sampleDesc) { depthBufferTex = new Texture2D(device, new Texture2DDescription { Format = Format.R32_Typeless, ArraySize = 1, MipLevels = 1, Width = viewportControl.Width, Height = viewportControl.Height, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); depthBufView = new DepthStencilView(device, depthBufferTex, new DepthStencilViewDescription { Dimension = DepthStencilViewDimension.Texture2D, Format = Format.D32_Float }); depthShaderView = new ShaderResourceView(device, depthBufferTex, new ShaderResourceViewDescription { Dimension = ShaderResourceViewDimension.Texture2D, Format = Format.R32_Float, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1 } }); }
public SwapChainDescription CreateSwapChain(int PBufferCount, Usage PUsage, IntPtr PFormHandle, bool PIsWindowed, int PModeDescriptionWidth, int PModeDescriptionHeight, Rational PModeDescriptionRefreshRate, Format PModeDescriptionFormat, int PSampleDescriptionCount, int PSampleDescriptionQuality, SwapChainFlags PSwapChainFlags, SwapEffect PSwapEffect) { this._BufferCount = PBufferCount; this._Usage = PUsage; this._FormHandle = PFormHandle; this._IsWindowed = PIsWindowed; this._ModeDescriptionWidth = PModeDescriptionWidth; this._ModeDescriptionHeight = PModeDescriptionHeight; this._ModeDescriptionRefreshRate = PModeDescriptionRefreshRate; this._ModeDescriptionFormat = PModeDescriptionFormat; this._SampleDescriptionCount = PSampleDescriptionCount; this._SampleDescriptionQuality = PSampleDescriptionQuality; this._SwapChainFlags = PSwapChainFlags; this._SwapEffect = PSwapEffect; _SampleDescription = new SampleDescription(_SampleDescriptionCount, _SampleDescriptionQuality); _ModeDescription = new ModeDescription(_ModeDescriptionWidth, _ModeDescriptionHeight, _ModeDescriptionRefreshRate, _ModeDescriptionFormat); _SwapChainDesc = new SwapChainDescription() { BufferCount = _BufferCount, Usage = _Usage, OutputHandle = _FormHandle, IsWindowed = _IsWindowed, ModeDescription = _ModeDescription, SampleDescription = _SampleDescription, Flags = _SwapChainFlags, SwapEffect = _SwapEffect }; return(_SwapChainDesc); }
internal Depth(Device Device, ModeDescription Resolution, SampleDescription AA) { this.Resolution = Resolution; DepthStencilTexture = new Texture2D(Device, new Texture2DDescription { Width = Resolution.Width, Height = Resolution.Height, MipLevels = 1, ArraySize = 1, Format = Format.R32_Typeless, SampleDescription = AA, Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); DepthStencilView = new DepthStencilView(Device, DepthStencilTexture, new DepthStencilViewDescription { Format = Format.D32_Float, Dimension = (AA.Count > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D), Texture2D = new DepthStencilViewDescription.Texture2DResource { MipSlice = 0 } }); }
private void PlatformConstruct( int width, int height, bool mipmap, SurfaceFormat format, SurfaceType type, bool shared) { Shared = shared; Mipmap = mipmap; SampleDescription = new SampleDescription(1, 0); }
public DX11SwapChain(DX11RenderContext context, IntPtr handle, Format format, SampleDescription sampledesc) { this.context = context; this.handle = handle; SwapChainDescription sd = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), format), IsWindowed = true, OutputHandle = handle, SampleDescription = sampledesc, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput | Usage.ShaderInput, Flags = SwapChainFlags.None }; if (sd.SampleDescription.Count == 1 && context.IsFeatureLevel11) { sd.Usage |= Usage.UnorderedAccess; this.allowuav = true; } this.swapchain = new SwapChain(context.Device.Factory, context.Device, sd); this.Resource = Texture2D.FromSwapChain<Texture2D>(this.swapchain, 0); this.context.Factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter); this.RTV = new RenderTargetView(context.Device, this.Resource); this.SRV = new ShaderResourceView(context.Device, this.Resource); if (this.allowuav) { this.UAV = new UnorderedAccessView(context.Device, this.Resource); } this.desc = this.Resource.Description; }
/// <summary> /// Initializes a new instance of the <see cref="ResourceDescription1"/> struct. /// </summary> /// <param name="dimension"></param> /// <param name="alignment"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="depthOrArraySize"></param> /// <param name="mipLevels"></param> /// <param name="format"></param> /// <param name="sampleCount"></param> /// <param name="sampleQuality"></param> /// <param name="layout"></param> /// <param name="flags"></param> /// <param name="samplerFeedbackMipRegionWidth"></param> /// <param name="samplerFeedbackMipRegionHeight"></param> /// <param name="samplerFeedbackMipRegionDepth"></param> public ResourceDescription1( ResourceDimension dimension, ulong alignment, ulong width, int height, ushort depthOrArraySize, ushort mipLevels, Format format, int sampleCount, int sampleQuality, TextureLayout layout, ResourceFlags flags, int samplerFeedbackMipRegionWidth = 0, int samplerFeedbackMipRegionHeight = 0, int samplerFeedbackMipRegionDepth = 0) { Dimension = dimension; Alignment = alignment; Width = width; Height = height; DepthOrArraySize = depthOrArraySize; MipLevels = mipLevels; Format = format; SampleDescription = new SampleDescription(sampleCount, sampleQuality); Layout = layout; Flags = flags; SamplerFeedbackMipRegion = new MipRegion(samplerFeedbackMipRegionWidth, samplerFeedbackMipRegionHeight, samplerFeedbackMipRegionDepth); }
/// <summary> /// Creating a new D3DEngine with an associated window for rendering /// </summary> /// <param name="startingSize">Windows starting size</param> /// <param name="windowCaption">Window Caption</param> /// <param name="RenderResolution">if not passed or equal to 0;0 then the resolution will be the one from the Windows Size</param> public D3DEngine(Size startingSize, string windowCaption, SampleDescription samplingMode, Size renderResolution = default(Size)) { IsShuttingDownRequested = false; //Create the MainRendering Form _renderForm = new RenderForm() { Text = windowCaption, ClientSize = startingSize, StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen }; WindowHandle = _renderForm.Handle; _renderForm.KeyUp += new System.Windows.Forms.KeyEventHandler(_renderForm_KeyUp); this.RenderResolution = renderResolution; this.CurrentMSAASampling = samplingMode; string errorInit; isInitialized = false; if (Initialize(out errorInit) == false) { errorInit = "DirectX initialization error, cannot start the game : " + errorInit; System.Windows.Forms.MessageBox.Show(errorInit); logger.Error(errorInit); return; } isInitialized = true; //Init State repo RenderStatesRepo.Initialize(this); }
public ScreenContext(Control owner, RenderContext context, MatrixManager manager) : base(context) { Device device = context.DeviceManager.Device; SampleDescription sampleDesc = new SampleDescription(1, 0); SwapChain = new SwapChain(context.DeviceManager.Factory, device, getSwapChainDescription(owner, sampleDesc)); //ラスタライザの設定 //深度ステンシルバッファの初期化 using (Texture2D depthBuffer = new Texture2D(device, getDepthBufferTexture2DDescription(owner, sampleDesc))) { DepthTargetView = new DepthStencilView(device, depthBuffer); } //レンダーターゲットの初期化 using (Texture2D renderTexture = Resource.FromSwapChain <Texture2D>(SwapChain, 0)) { RenderTargetView = new RenderTargetView(device, renderTexture); } WorldSpace = new WorldSpace(context); BindedControl = owner; MatrixManager = manager; PanelObserver = new PanelObserver(owner); SetViewport(); HitChekcer = new TexturedBufferHitChecker(Context, this); HitChekcer.Resize(owner.ClientSize); owner.MouseMove += owner_MouseMove; owner.MouseDown += owner_MouseDown; owner.MouseUp += owner_MouseUp; }
public void Update(DX11RenderContext context, int w, int h, SampleDescription sd) { if (this.currentmode == eDepthBufferMode.Standard) { DX11DepthStencil ds; if (this.NeedReset || !this.depthoutputpin.IOObject[0].Data.ContainsKey(context)) { if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(context); } if (sd.Count > 1) { if (!context.IsAtLeast101) { host.Log(TLogType.Warning, "Device Feature Level Needs at least 10.1 to create Multisampled Depth Buffer, rolling back to 1"); sd.Count = 1; } } ds = new DX11DepthStencil(context, w, h, sd, DeviceFormatHelper.GetFormat(this.depthformatpin.IOObject[0].Name)); #if DEBUG ds.Resource.DebugName = "DepthStencil"; #endif this.depthoutputpin.IOObject[0][context] = ds; } } }
public StandardTarget(Device device, Size2 size) { var sampleDescription = new SampleDescription( MsaaSampleCount, (int)StandardMultisampleQualityLevels.StandardMultisamplePattern); RenderTexture = new Texture2D(device, new Texture2DDescription { Format = ColorFormat, Width = size.Width, Height = size.Height, ArraySize = 1, SampleDescription = sampleDescription, MipLevels = 1, Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource }); RenderSourceView = new ShaderResourceView(device, RenderTexture); RenderTargetView = new RenderTargetView(device, RenderTexture); DepthTexture = new Texture2D(device, new Texture2DDescription { Width = size.Width, Height = size.Height, ArraySize = 1, Format = DepthTextureFormat, SampleDescription = sampleDescription, MipLevels = 1, Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource }); DepthTargetView = new DepthStencilView(device, DepthTexture, new DepthStencilViewDescription { Format = DepthTargetFormat, Dimension = DepthStencilViewDimension.Texture2DMultisampled }); DepthResourceView = new ShaderResourceView(device, DepthTexture, new ShaderResourceViewDescription { Format = DepthResourceFormat, Dimension = ShaderResourceViewDimension.Texture2DMultisampled, Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1, MostDetailedMip = 0 } }); ResolveTexture = new Texture2D(device, new Texture2DDescription() { Format = ColorFormat, Width = size.Width, Height = size.Height, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1, Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource }); ResolveTargetView = new RenderTargetView(device, ResolveTexture); ResolveSourceView = new ShaderResourceView(device, ResolveTexture); }
internal override Resource CreateTexture() { // TODO: Move this to SetData() if we want to make Immutable textures! var desc = GetTexture2DDescription(); // Save sampling description. _sampleDescription = desc.SampleDescription; return(new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, desc)); }
public GBuffer(int width, int height, SampleDescription sampleDesc, params SharpDX.DXGI.Format[] targetFormats) { System.Diagnostics.Debug.Assert(targetFormats != null && targetFormats.Length > 0 && targetFormats.Length < 9, "Between 1 and 8 target formats must be provided"); this.width = width; this.height = height; this.sampleDescription = sampleDesc; RTFormats = targetFormats; }
private Texture2D CreateTexture(int width, int height, bool multiSampling) { var description = new SlimDX.Direct3D10.Texture2DDescription(); description.ArraySize = 1; description.BindFlags = SlimDX.Direct3D10.BindFlags.RenderTarget | SlimDX.Direct3D10.BindFlags.ShaderResource; description.CpuAccessFlags = CpuAccessFlags.None; description.Format = Format.B8G8R8A8_UNorm; description.MipLevels = 1; //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; // Multi-sample anti-aliasing //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; int count; if (multiSampling) { count = 8; } else { count = 1; } int quality = device.CheckMultisampleQualityLevels(description.Format, count); if (count == 1) { quality = 1; } // Multi-sample anti-aliasing SampleDescription sampleDesc = new SampleDescription(count, 0); description.SampleDescription = sampleDesc; RasterizerStateDescription rastDesc = new RasterizerStateDescription(); rastDesc.CullMode = CullMode.Back; rastDesc.FillMode = FillMode.Solid; rastDesc.IsMultisampleEnabled = false; rastDesc.IsAntialiasedLineEnabled = false; //rastDesc.DepthBias = 0; //rastDesc.DepthBiasClamp = 0; //rastDesc.IsDepthClipEnabled = true; //rastDesc.IsFrontCounterclockwise = false; //rastDesc.IsScissorEnabled = true; //rastDesc.SlopeScaledDepthBias = 0; device.Rasterizer.State = RasterizerState.FromDescription(device, rastDesc); description.Usage = ResourceUsage.Default; description.OptionFlags = ResourceOptionFlags.Shared; description.Height = (int)height; description.Width = (int)width; return(new Texture2D(device, description)); }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; if (this.updateddevices.Contains(context)) { return; } int samplecount = Convert.ToInt32(FInAASamplesPerPixel[0].Name); SampleDescription sd = new SampleDescription(samplecount, 0); if (this.FResized || this.FInvalidateSwapChain || this.FOutBackBuffer[0][context] == null) { this.FOutBackBuffer[0].Dispose(context); List <SampleDescription> sds = context.GetMultisampleFormatInfo(Format.R8G8B8A8_UNorm); int maxlevels = sds[sds.Count - 1].Count; if (sd.Count > maxlevels) { logger.Log(LogType.Warning, "Multisample count too high for this format, reverted to: " + maxlevels); sd.Count = maxlevels; } this.FOutBackBuffer[0][context] = new DX11SwapChain(context, this.Handle, Format.R8G8B8A8_UNorm, sd, 60, this.FInBufferCount[0]); #if DEBUG this.FOutBackBuffer[0][context].Resource.DebugName = "BackBuffer"; #endif this.depthmanager.NeedReset = true; } DX11SwapChain sc = this.FOutBackBuffer[0][context]; if (this.FResized) { //if (!sc.IsFullScreen) //{ // sc.Resize(); // } //this.FInvalidateSwapChain = true; } if (!this.renderers.ContainsKey(context)) { this.renderers.Add(context, new DX11GraphicsRenderer(this.FHost, context)); } this.depthmanager.Update(context, sc.Width, sc.Height, sd); this.updateddevices.Add(context); }
private void PlatformConstruct(GraphicsDevice graphicsDevice, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Create one render target view per cube map face. _renderTargetViews = new RenderTargetView[6]; for (int i = 0; i < _renderTargetViews.Length; i++) { var renderTargetViewDescription = new RenderTargetViewDescription { Dimension = RenderTargetViewDimension.Texture2DArray, Format = SharpDXHelper.ToFormat(preferredFormat), Texture2DArray = { ArraySize = 1, FirstArraySlice = i, MipSlice = 0 } }; _renderTargetViews[i] = new RenderTargetView(graphicsDevice._d3dDevice, GetTexture(), renderTargetViewDescription); } // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } var sampleDescription = new SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { sampleDescription.Count = preferredMultiSampleCount; sampleDescription.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } var depthStencilDescription = new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = size, Height = size, SampleDescription = sampleDescription, BindFlags = BindFlags.DepthStencil, }; using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, depthStencilDescription)) { var depthStencilViewDescription = new DepthStencilViewDescription { Dimension = DepthStencilViewDimension.Texture2D, Format = SharpDXHelper.ToFormat(preferredDepthFormat), }; _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, depthStencilViewDescription); } }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; if (this.updateddevices.Contains(context)) { return; } SampleDescription sd = new SampleDescription(1, 0); if (this.FResized || this.FInvalidateSwapChain || this.swapchain == null) { if (this.swapchain != null) { this.swapchain.Dispose(); } this.swapchain = new DX11SwapChain(context, this.form.Handle, Format.R8G8B8A8_UNorm, sd, this.FInRate[0]); } if (this.renderer == null) { this.renderer = new DX11GraphicsRenderer(this.FHost, context); } this.updateddevices.Add(context); if (this.FInFullScreen[0] != this.swapchain.IsFullScreen) { if (this.FInFullScreen[0]) { this.prevx = this.form.Width; this.prevy = this.form.Height; /*Screen screen = Screen.FromControl(this.form);*/ this.form.FormBorderStyle = FormBorderStyle.None; this.form.Width = Convert.ToInt32(this.FInRes[0].X); this.form.Height = Convert.ToInt32(this.FInRes[0].Y); this.swapchain.Resize(); this.swapchain.SetFullScreen(true); this.setfull = false; } else { this.swapchain.SetFullScreen(false); this.form.FormBorderStyle = FormBorderStyle.Fixed3D; this.form.Width = this.prevx; this.form.Height = this.prevy; this.swapchain.Resize(); } } }
public static TargetResourceTexture Create(Format format, SampleDescription? sampleDescription = null, int mipLevels = 1) { return new TargetResourceTexture(new Texture2DDescription { MipLevels = mipLevels, ArraySize = 1, Format = format, SampleDescription = sampleDescription ?? DefaultSampleDescription, Usage = ResourceUsage.Default, BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); }
public ResourceDescription(ResourceDimension dimension, long alignment, long width, int height, short depthOrArraySize, short mipLevels, Format format, int sampleCount, int sampleQuality, TextureLayout layout, ResourceOptionFlags optionFlags) { Dimension = dimension; Alignment = alignment; Width = width; Height = height; DepthOrArraySize = depthOrArraySize; MipLevels = mipLevels; Format = format; SampleDescription = new SampleDescription(sampleCount, sampleQuality); Layout = layout; OptionFlags = optionFlags; }
public GBuffer(int width, int height, SampleDescription sampleDesc, Device dv, params SharpDX.DXGI.Format[] targetFormats) { System.Diagnostics.Debug.Assert(targetFormats != null && targetFormats.Length > 0 && targetFormats.Length < 9, "Between 1 and 8 render target formats must be provided"); this.width = width; this.height = height; this.sampleDescription = sampleDesc; RTFormats = targetFormats; device = dv; CreateDeviceDependentResources(); }
public DX11DepthStencil(DX11RenderContext context, int w, int h, SampleDescription sd, Format format) { this.context = context; var depthBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = h, Width = w, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default }; this.Resource = new Texture2D(context.Device, depthBufferDesc); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = 1, Format = DepthFormatsHelper.GetSRVFormat(format), Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = DepthFormatsHelper.GetDepthFormat(format), Dimension = sd.Count == 1 ? DepthStencilViewDimension.Texture2D : DepthStencilViewDimension.Texture2DMultisampled, MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); //Read only dsv only supported in dx11 minimum if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.desc = depthBufferDesc; this.isowner = true; }
//Constructed Engine public Game(Size startingWindowsSize, string WindowsCaption, SampleDescription sampleDescription, Size ResolutionSize = default(Size), bool withDebugObjectTracking = false) { Engine = ToDispose(new D3DEngine(startingWindowsSize, WindowsCaption, sampleDescription, ResolutionSize)); if (Engine.isInitialized) { Engine.GameWindow.FormClosing += GameWindow_FormClosing; _visibleDrawable = new List <DrawableComponentHolder>(); _enabledUpdatable = new List <IUpdatableComponent>(); _gameComponents = ToDispose(new GameComponentCollection()); gameInitialize(withDebugObjectTracking); } }
/// <summary> /// 深度ステンシルバッファの設定を取得します。 /// 深度ステンシルバッファの設定を変えたい場合はオーバーライドしてください。 /// </summary> /// <param name="control">適用するコントロールへの参照</param> /// <returns>深度ステンシルバッファ用のTexture2Dの設定</returns> protected virtual Texture2DDescription getDepthBufferTexture2DDescription(Control control, SampleDescription desc) { return(new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float, Width = control.Width, Height = control.Height, MipLevels = 1, SampleDescription = desc }); }
public DX11CubeRenderTarget(DX11RenderContext context, int size, SampleDescription sd, Format format, bool genMipMaps, int mmLevels) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, }; if (genMipMaps && sd.Count == 1) { texBufferDesc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; texBufferDesc.MipLevels = mmLevels; } else { //Make sure we enforce 1 here, as we dont generate texBufferDesc.MipLevels = 1; } this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.FaceRTVs = new RenderTargetView[6]; this.FaceSRVs = new ShaderResourceView[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = format, MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); this.CreateSliceViews(context.Device, format); }
public DX11RenderTarget2D(DX11RenderContext context, int w, int h, SampleDescription sd, Format format, bool genMipMaps, int mmLevels, bool allowUAV, bool allowShare) { this.context = context; this.shared = allowShare; var texBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default, }; this.requestedMipsLevel = mmLevels; if (sd.Count == 1 && allowUAV && context.IsFeatureLevel11) { texBufferDesc.BindFlags |= BindFlags.UnorderedAccess; this.allowuav = true; } if (sd.Count == 1 && genMipMaps == false && allowShare) { texBufferDesc.OptionFlags = /*ResourceOptionFlags.KeyedMutex |*/ ResourceOptionFlags.Shared; } if (genMipMaps && sd.Count == 1) { texBufferDesc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps; texBufferDesc.MipLevels = mmLevels; this.genmm = true; } else { //Make sure we enforce 1 here, as we dont generate texBufferDesc.MipLevels = 1; this.genmm = false; } this.Resource = new Texture2D(context.Device, texBufferDesc); this.RTV = new RenderTargetView(context.Device, this.Resource); this.SRV = new ShaderResourceView(context.Device, this.Resource); this.desc = texBufferDesc; }
protected override void OnUpdate(DX11RenderContext context) { var maxSamples = SlimDX.Direct3D11.Device.MultisampleCountMaximum; SampleDescription sd = new SampleDescription((int)Math.Min(FInAASamplesPerPixel[0], maxSamples), FInAAQuality[0]); if (this.resized || this.invalidatesc || this.FOutBackBuffer[0][context] == null) { EnumEntry bbf = this.FCfgBackBufferFormat[0]; this.FOutBackBuffer[0].Dispose(context); //NOTE ENUM BROKEN Format fmt = (Format)Enum.Parse(typeof(Format), this.FCfgBackBufferFormat[0].Name); this.FOutBackBuffer[0][context] = new DX11SwapChain(context, this.Handle, fmt, sd); this.depthmanager.NeedReset = true; } }
/// <summary> /// /// </summary> private void CreateAndBindTargets() { surfaceD3D.SetRenderTargetDX11(null); int width = System.Math.Max((int)ActualWidth, 100); int height = System.Math.Max((int)ActualHeight, 100); Disposer.RemoveAndDispose(ref colorBufferView); Disposer.RemoveAndDispose(ref depthStencilBufferView); Disposer.RemoveAndDispose(ref colorBuffer); Disposer.RemoveAndDispose(ref depthStencilBuffer); #if MSAA Disposer.RemoveAndDispose(ref renderTargetNMS); int sampleCount = 1; int sampleQuality = 0; if (MSAA != MSAALevel.Disable) { do { var newSampleCount = sampleCount * 2; var newSampleQuality = device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, newSampleCount) - 1; if (newSampleQuality < 0) break; sampleCount = newSampleCount; sampleQuality = newSampleQuality; if (sampleCount == (int)MSAA) { break; } } while (sampleCount < 32); } var sampleDesc = new SampleDescription(sampleCount, sampleQuality); var optionFlags = ResourceOptionFlags.None; #else var sampleDesc = new SampleDescription(1, 0); var optionFlags = ResourceOptionFlags.Shared; #endif var colordesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = optionFlags, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, //Format = Format.D24_UNorm_S8_UInt, Format = Format.D32_Float_S8X24_UInt, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1, }; colorBuffer = new Texture2D(device, colordesc); depthStencilBuffer = new Texture2D(device, depthdesc); colorBufferView = new RenderTargetView(device, colorBuffer); depthStencilBufferView = new DepthStencilView(device, depthStencilBuffer); #if MSAA var colordescNMS = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; renderTargetNMS = new Texture2D(device, colordescNMS); device.ImmediateContext.ResolveSubresource(colorBuffer, 0, renderTargetNMS, 0, Format.B8G8R8A8_UNorm); surfaceD3D.SetRenderTargetDX11(renderTargetNMS); #else this.surfaceD3D.SetRenderTargetDX11(this.colorBuffer); #endif }
public TeapotScene(TeapotRenderer teapotRenderer) { // Create a description of the display mode ModeDescription modeDescription = new ModeDescription() { Format = Format.R8G8B8A8_UNorm, RefreshRate = new Rational(60, 1), Width = 512, Height = 512 }; // Create a description of the multisampler SampleDescription sampleDescription = new SampleDescription() { Count = 1, Quality = 0 }; // Create a description of the swap chain SwapChainDescription swapChainDescription = new SwapChainDescription() { ModeDescription = modeDescription, SampleDescription = sampleDescription, BufferCount = 1, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, IsWindowed = false }; // Create a hardware accelarated rendering device renderingDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport); // Create the shared texture Texture2DDescription colordesc = new Texture2DDescription(); colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; colordesc.Format = Format.B8G8R8A8_UNorm; colordesc.Width = 512; colordesc.Height = 512; colordesc.MipLevels = 1; colordesc.SampleDescription = new SampleDescription(1, 0); colordesc.Usage = ResourceUsage.Default; colordesc.OptionFlags = ResourceOptionFlags.Shared; colordesc.CpuAccessFlags = CpuAccessFlags.None; colordesc.ArraySize = 1; SharedTexture = new Texture2D(renderingDevice, colordesc); // Create the render target view renderTargetView = new RenderTargetView(renderingDevice, SharedTexture); // Creat the depth/stencil buffer DepthStencilStateDescription depthStencilStateDescription = new DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthWriteMask = DepthWriteMask.All, DepthComparison = Comparison.Less, }; depthStencilState = DepthStencilState.FromDescription(renderingDevice, depthStencilStateDescription); Texture2DDescription depthStencilTextureDescription = new Texture2DDescription() { Width = 512, Height = 512, MipLevels = 1, ArraySize = 1, Format = Format.D32_Float, SampleDescription = sampleDescription, Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; DepthStencilViewDescription depthStencilViewDescription = new DepthStencilViewDescription() { Format = depthStencilTextureDescription.Format, Dimension = depthStencilTextureDescription.SampleDescription.Count > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D, MipSlice = 0 }; using (Texture2D depthStencilTexture = new Texture2D(renderingDevice, depthStencilTextureDescription)) { depthStencilView = new DepthStencilView(renderingDevice, depthStencilTexture, depthStencilViewDescription); } // Setup the default output targets renderingDevice.ImmediateContext.OutputMerger.SetTargets(depthStencilView, renderTargetView); // Setup the viewport Viewport viewPort = new Viewport() { X = 0, Y = 0, Width = 512, Height = 512, MinZ = 0, MaxZ = 1 }; renderingDevice.ImmediateContext.Rasterizer.SetViewports(viewPort); // Create the teappot teapotObject = new TeapotObject(teapotRenderer, renderingDevice); // Create the camera camera = new ThirdPersonCamera(teapotObject); }
public DX11ResourcePoolEntry<DX11RenderTarget2D> LockRenderTarget(int w, int h, Format format, SampleDescription sd, bool genMM = false, int mmLevels = 1) { return this.targetpool.Lock(w, h, format, sd, genMM, mmLevels); }
public DX11ResourcePoolEntry<DX11DepthStencil> LockDepth(int w, int h, SampleDescription sd, Format format) { return this.depthpool.Lock(w, h, format,sd); }
/// <summary> /// Create our OutsideWindow app, but do not initialize Direct3D. /// </summary> /// <param name="hInstance">hInstance of the application</param> protected OutsideWindowBase(IntPtr hInstance) { AppInst = hInstance; MainWindowCaption = "Outside Engine"; ClientWidth = 800; ClientHeight = 600; Window = null; AppPaused = false; Minimized = false; Maximized = false; Resizing = false; _isD3DInitialized = false; BackBufferFormat = Format.R8G8B8A8_UNorm; DepthStencilBufferFormat = Format.D24_UNorm_S8_UInt; DeviceCreationFlags = DeviceCreationFlags.None; #if DEBUG //DeviceCreationFlags |= DeviceCreationFlags.Debug; //DeviceCreationFlags |= DeviceCreationFlags.SingleThreaded; #endif SampleDescription = new SampleDescription(1, 0); DriverType = DriverType.Hardware; Device = null; ImmediateContext = null; SwapChain = null; DepthStencilView = null; DepthStencilBuffer = null; RenderTargetView = null; Viewport = new Viewport(); Timer = new GameTimer(); }
public SwapChainDescription(int width, int height) { Width = width; Height = height; SampleDescription = new SampleDescription(1); }
public void Update(DX11RenderContext context, int w, int h,SampleDescription sd) { if (this.currentmode == eDepthBufferMode.Standard) { DX11DepthStencil ds; if (this.NeedReset || !this.depthoutputpin.IOObject[0].Data.ContainsKey(context)) { if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(context); } if (sd.Count > 1) { if (!context.IsAtLeast101) { host.Log(TLogType.Warning, "Device Feature Level Needs at least 10.1 to create Multisampled Depth Buffer, rolling back to 1"); sd.Count = 1; } } ds = new DX11DepthStencil(context, w, h, sd, DeviceFormatHelper.GetFormat(this.depthformatpin.IOObject[0].Name)); #if DEBUG ds.Resource.DebugName = "DepthStencil"; #endif this.depthoutputpin.IOObject[0][context] = ds; } } }
public DX11RenderTarget2D(DX11RenderContext context, int w, int h, SampleDescription sd, Format format, bool genMipMaps, int mmLevels) : this(context,w,h,sd,format,genMipMaps,mmLevels,true,false) {}
private Texture2D CreateTexture(int width, int height, bool multiSampling) { var description = new SlimDX.Direct3D10.Texture2DDescription(); description.ArraySize = 1; description.BindFlags = SlimDX.Direct3D10.BindFlags.RenderTarget | SlimDX.Direct3D10.BindFlags.ShaderResource; description.CpuAccessFlags = CpuAccessFlags.None; description.Format = Format.B8G8R8A8_UNorm; description.MipLevels = 1; //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; // Multi-sample anti-aliasing //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; int count; if (multiSampling) count = 8; else count = 1; int quality = device.CheckMultisampleQualityLevels(description.Format, count); if (count == 1) quality = 1; // Multi-sample anti-aliasing SampleDescription sampleDesc = new SampleDescription(count, 0); description.SampleDescription = sampleDesc; RasterizerStateDescription rastDesc = new RasterizerStateDescription(); rastDesc.CullMode = CullMode.Back; rastDesc.FillMode = FillMode.Solid; rastDesc.IsMultisampleEnabled = false; rastDesc.IsAntialiasedLineEnabled = false; //rastDesc.DepthBias = 0; //rastDesc.DepthBiasClamp = 0; //rastDesc.IsDepthClipEnabled = true; //rastDesc.IsFrontCounterclockwise = false; //rastDesc.IsScissorEnabled = true; //rastDesc.SlopeScaledDepthBias = 0; device.Rasterizer.State = RasterizerState.FromDescription(device, rastDesc); description.Usage = ResourceUsage.Default; description.OptionFlags = ResourceOptionFlags.Shared; description.Height = (int)height; description.Width = (int)width; return new Texture2D(device, description); }
public DX11RenderTarget2D(DX11RenderContext context, int w, int h, SampleDescription sd, Format format) : this(context,w,h,sd,format,false,1) { }
public DX11DepthStencil(DX11RenderContext context, int w, int h, SampleDescription sd) : this(context, w, h, sd, Format.D32_Float) { }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; if (this.updateddevices.Contains(context)) { return; } SampleDescription sd = new SampleDescription(1, 0); if (this.FResized || this.FInvalidateSwapChain || this.swapchain == null) { if (this.swapchain != null) { this.swapchain.Dispose(); } this.swapchain = new DX11SwapChain(context, this.form.Handle, Format.R8G8B8A8_UNorm, sd,this.FInRate[0],1); } if (this.renderer == null) { this.renderer = new DX11GraphicsRenderer(this.FHost, context); } this.updateddevices.Add(context); if (this.FInFullScreen[0] != this.swapchain.IsFullScreen) { if (this.FInFullScreen[0]) { this.prevx = this.form.Width; this.prevy = this.form.Height; /*Screen screen = Screen.FromControl(this.form);*/ this.form.FormBorderStyle = FormBorderStyle.None; this.form.Width = Convert.ToInt32(this.FInRes[0].X); this.form.Height = Convert.ToInt32(this.FInRes[0].Y); this.swapchain.Resize(); this.swapchain.SetFullScreen(true); this.setfull = false; } else { this.swapchain.SetFullScreen(false); this.form.FormBorderStyle = FormBorderStyle.Fixed3D; this.form.Width = this.prevx; this.form.Height = this.prevy; this.swapchain.Resize(); } } }
/// <summary> /// /// </summary> private void CreateAndBindTargets() { this.surfaceD3D.SetRenderTargetDX11(null); int width = System.Math.Max((int)this.ActualWidth, 100); int height = System.Math.Max((int)this.ActualHeight, 100); Disposer.RemoveAndDispose(ref this.colorBufferView); Disposer.RemoveAndDispose(ref this.depthStencilBufferView); Disposer.RemoveAndDispose(ref this.colorBuffer); Disposer.RemoveAndDispose(ref this.depthStencilBuffer); #if MSAA Disposer.RemoveAndDispose(ref this.renderTargetNMS); // check 8,4,2,1 int sampleCount = 8; int sampleQuality = 0; if (this.IsMSAAEnabled) { do { sampleQuality = this.device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, sampleCount) - 1; if (sampleQuality > 0) { break; } else { sampleCount /= 2; } if (sampleCount == 1) { sampleQuality = 0; break; } } while (true); } else { sampleCount = 1; sampleQuality = 0; } var sampleDesc = new SampleDescription(sampleCount, sampleQuality); var optionFlags = ResourceOptionFlags.None; #else var sampleDesc = new SampleDescription(1, 0); var optionFlags = ResourceOptionFlags.Shared; #endif var colordesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = optionFlags, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, //Format = Format.D24_UNorm_S8_UInt, Format = Format.D32_Float_S8X24_UInt, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1, }; this.colorBuffer = new Texture2D(this.device, colordesc); this.depthStencilBuffer = new Texture2D(this.device, depthdesc); this.colorBufferView = new RenderTargetView(this.device, this.colorBuffer); this.depthStencilBufferView = new DepthStencilView(this.device, this.depthStencilBuffer); #if MSAA var colordescNMS = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; this.renderTargetNMS = new Texture2D(this.device, colordescNMS); this.device.ImmediateContext.ResolveSubresource(this.colorBuffer, 0, this.renderTargetNMS, 0, Format.B8G8R8A8_UNorm); this.surfaceD3D.SetRenderTargetDX11(this.renderTargetNMS); #else this.surfaceD3D.SetRenderTargetDX11(this.colorBuffer); #endif }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; if (this.updateddevices.Contains(context)) { return; } int samplecount = Convert.ToInt32(FInAASamplesPerPixel[0].Name); SampleDescription sd = new SampleDescription(samplecount, 0); if (this.FResized || this.FInvalidateSwapChain || this.FOutBackBuffer[0][context] == null) { EnumEntry bbf = this.FCfgBackBufferFormat[0]; this.FOutBackBuffer[0].Dispose(context); //NOTE ENUM BROKEN Format fmt = (Format)Enum.Parse(typeof(Format), this.FCfgBackBufferFormat[0].Name); this.FOutBackBuffer[0][context] = new DX11SwapChain(context,this.Handle, fmt, sd); #if DEBUG this.FOutBackBuffer[0][context].Resource.DebugName = "BackBuffer"; #endif this.depthmanager.NeedReset = true; } DX11SwapChain sc = this.FOutBackBuffer[0][context]; if (this.FResized) { //if (!sc.IsFullScreen) //{ // sc.Resize(); // } //this.FInvalidateSwapChain = true; } if (!this.renderers.ContainsKey(context)) { this.renderers.Add(context, new DX11GraphicsRenderer(this.FHost, context)); } this.depthmanager.Update(context, sc.Width, sc.Height, sd); this.updateddevices.Add(context); }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; if (this.updateddevices.Contains(context)) { return; } int samplecount = Convert.ToInt32(FInAASamplesPerPixel[0].Name); SampleDescription sd = new SampleDescription(samplecount, 0); if (this.FResized || this.FInvalidateSwapChain || this.FOutBackBuffer[0][context] == null) { this.FOutBackBuffer[0].Dispose(context); List<SampleDescription> sds = context.GetMultisampleFormatInfo(Format.R8G8B8A8_UNorm); int maxlevels = sds[sds.Count - 1].Count; if (sd.Count > maxlevels) { logger.Log(LogType.Warning, "Multisample count too high for this format, reverted to: " + maxlevels); sd.Count = maxlevels; } this.FOutBackBuffer[0][context] = new DX11SwapChain(context, this.Handle, Format.R8G8B8A8_UNorm, sd, 60, this.FInBufferCount[0]); #if DEBUG this.FOutBackBuffer[0][context].Resource.DebugName = "BackBuffer"; #endif this.depthmanager.NeedReset = true; } DX11SwapChain sc = this.FOutBackBuffer[0][context]; if (this.FResized) { //if (!sc.IsFullScreen) //{ // sc.Resize(); // } //this.FInvalidateSwapChain = true; } if (!this.renderers.ContainsKey(context)) { this.renderers.Add(context, new DX11GraphicsRenderer(this.FHost, context)); } this.depthmanager.Update(context, sc.Width, sc.Height, sd); this.updateddevices.Add(context); }
private SwapChainDescription CreateSwapChainDescription() { var sampleDescription = new SampleDescription { Count = 1, Quality = 0 }; return new SwapChainDescription { ModeDescription = CreateModeDescription(), SampleDescription = sampleDescription, BufferCount = 1, Flags = SwapChainFlags.None, IsWindowed = mIsWindowed, OutputHandle = mWindowHandle, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; }
/// <summary> /// Get Device (could be temporary, could be not), set proper SampleDescription /// </summary> private Device InitializeDevice() { Debug.Assert(Initialized == false); var device = new Device(DriverType.Hardware, DeviceCreationFlags.None); if (device.FeatureLevel < FeatureLevel) { throw new Exception($"Direct3D Feature {FeatureLevel} unsupported"); } if (UseMsaa) { var msaaQuality = device.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, 4); SampleDescription = new SampleDescription(4, msaaQuality - 1); } return device; }