public override void Load(ChunkMeta meta, BinaryReader br) { base.Load(meta, br); parentId = br.ReadUInt64(); // pResource pDesc = D3D11Reader.Read_D3D11_Nullable <D3D11_RENDER_TARGET_VIEW_DESC>(br); resourceId = br.ReadUInt64(); // pView }
public virtual void GetDesc( out D3D11_RENDER_TARGET_VIEW_DESC pDesc ) { var fp = GetFunctionPointer(8); if (m_GetDescFunc == null) { m_GetDescFunc = (GetDescFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetDescFunc)); } m_GetDescFunc(m_ptr, out pDesc); }
public virtual int CreateRenderTargetView( ID3D11Resource pResource, ref D3D11_RENDER_TARGET_VIEW_DESC pDesc, out ID3D11RenderTargetView ppRTView ) { var fp = GetFunctionPointer(9); if (m_CreateRenderTargetViewFunc == null) { m_CreateRenderTargetViewFunc = (CreateRenderTargetViewFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(CreateRenderTargetViewFunc)); } ppRTView = new ID3D11RenderTargetView(); return(m_CreateRenderTargetViewFunc(m_ptr, pResource != null ? pResource.Ptr : IntPtr.Zero, ref pDesc, out ppRTView.PtrForNew)); }
ID3D11RenderTargetView Begin(IntPtr hWnd, out float width, out float height) { using (var texture = m_swapchain.GetBackbuffer(m_d3d11.Device, hWnd)) { texture.GetDesc(out D3D11_TEXTURE2D_DESC desc); width = (float)desc.Width; height = (float)desc.Height; var rtv_desc = new D3D11_RENDER_TARGET_VIEW_DESC { Format = desc.Format, ViewDimension = D3D11_RTV_DIMENSION._TEXTURE2D }; var rtv = new ID3D11RenderTargetView(); m_d3d11.Device.CreateRenderTargetView(texture, ref rtv_desc, out rtv).ThrowIfFailed(); return(rtv); } }
private void SwapChain_SizeChanged(object sender, SizeChangedEventArgs e) { uint width, height; if (sender is Tuple <double, double> size) { width = (uint)size.Item1; height = (uint)size.Item2; } else { width = (uint)e.NewSize.Width; height = (uint)e.NewSize.Height; } if (width <= 0 || height <= 0) { return; } InitPipeline(); m_d3dContext.Get()->ClearState(); m_renderTargetView.Dispose(); m_depthStencilView.Dispose(); m_renderTargetView = new ComPtr <ID3D11RenderTargetView>(); m_depthStencilView = new ComPtr <ID3D11DepthStencilView>(); // resize the swap chain int hr = m_swapChain.Get()->ResizeBuffers( 0, // Don't change buffer count width, height, DXGI_FORMAT.DXGI_FORMAT_UNKNOWN, // Don't change format 0 // No flags ); Marshal.ThrowExceptionForHR(hr); // (re)-create the render target view ComPtr <ID3D11Texture2D> backBuffer = new ComPtr <ID3D11Texture2D>(); var d3d11Text2D = typeof(ID3D11Texture2D).GUID; D3D11_RENDER_TARGET_VIEW_DESC desc = new D3D11_RENDER_TARGET_VIEW_DESC { ViewDimension = D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_BUFFER }; m_renderTargetView = new ComPtr <ID3D11RenderTargetView>(); if (FAILED(m_swapChain.Get()->GetBuffer(0, InteropUtilities.AsPointer(ref d3d11Text2D), (void **)backBuffer.GetAddressOf()))) { throw new Exception("Direct3D was unable to acquire the back buffer!"); } if (FAILED(m_d3dDevice.Get()->CreateRenderTargetView( (ID3D11Resource *)backBuffer.Get(), null, m_renderTargetView.GetAddressOf()))) { throw new Exception("Direct3D was unable to create the render target view!"); } // create the depth and stencil buffer D3D11_TEXTURE2D_DESC dsd; ComPtr <ID3D11Texture2D> dsBuffer = new ComPtr <ID3D11Texture2D>(); backBuffer.Get()->GetDesc(&dsd); dsd.Format = DXGI_FORMAT.DXGI_FORMAT_D24_UNORM_S8_UINT; dsd.Usage = D3D11_USAGE.D3D11_USAGE_DEFAULT; dsd.BindFlags = (uint)D3D11_BIND_FLAG.D3D11_BIND_DEPTH_STENCIL; if (FAILED(m_d3dDevice.Get()->CreateTexture2D(&dsd, null, dsBuffer.GetAddressOf()))) { throw new Exception("Direct3D was unable to create a 2D-texture!"); } if (FAILED(m_d3dDevice.Get()->CreateDepthStencilView((ID3D11Resource *)dsBuffer.Get(), null, m_depthStencilView.GetAddressOf()))) { throw new Exception("Direct3D was unable to create the depth and stencil buffer!"); } // activate the depth and stencil buffer m_d3dContext.Get()->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get()); // set the viewport to the entire backbuffer D3D11_VIEWPORT vp; vp.TopLeftX = 0; vp.TopLeftY = 0; vp.Width = dsd.Width; vp.Height = dsd.Height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; m_d3dContext.Get()->RSSetViewports(1, &vp); Present(); //m_renderTargetView.Get()->Release(); backBuffer.Get()->Release(); }
static bool UpdateOuput(IntPtr opaque, RenderConfig *config, ref OutputConfig output) { ReleaseTextures(); var renderFormat = DXGI_FORMAT_R8G8B8A8_UNORM; var texDesc = new D3D11_TEXTURE2D_DESC { MipLevels = 1, SampleDesc = new DXGI_SAMPLE_DESC { Count = 1 }, BindFlags = (uint)(D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE), Usage = D3D11_USAGE_DEFAULT, CPUAccessFlags = 0, ArraySize = 1, Format = renderFormat, Height = config->Height, Width = config->Width, MiscFlags = (uint)(D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_NTHANDLE) }; fixed(ID3D11Texture2D **texture = &_texture) ThrowIfFailed(_d3dDevice->CreateTexture2D(&texDesc, null, texture)); IDXGIResource1 *sharedResource = null; var iid = IID_IDXGIResource1; _texture->QueryInterface(&iid, (void **)&sharedResource); fixed(void *handle = &_sharedHandle) ThrowIfFailed(sharedResource->CreateSharedHandle(null, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, null, (IntPtr *)handle)); sharedResource->Release(); ID3D11Device1 *d3d11VLC1; iid = IID_ID3D11Device1; _d3deviceVLC->QueryInterface(&iid, (void **)&d3d11VLC1); iid = IID_ID3D11Texture2D; fixed(ID3D11Texture2D **texture = &_textureVLC) ThrowIfFailed(d3d11VLC1->OpenSharedResource1(_sharedHandle, &iid, (void **)texture)); d3d11VLC1->Release(); var shaderResourceViewDesc = new D3D11_SHADER_RESOURCE_VIEW_DESC { ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D, Format = texDesc.Format }; shaderResourceViewDesc.Texture2D.MipLevels = 1; ID3D11Resource *res; iid = IID_ID3D11Resource; _texture->QueryInterface(&iid, (void **)&res); fixed(ID3D11ShaderResourceView **tsi = &_textureShaderInput) { ThrowIfFailed(_d3dDevice->CreateShaderResourceView(res, &shaderResourceViewDesc, tsi)); res->Release(); _d3dctx->PSSetShaderResources(0, 1, tsi); } var renderTargetViewDesc = new D3D11_RENDER_TARGET_VIEW_DESC { Format = texDesc.Format, ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D }; iid = IID_ID3D11Resource; _textureVLC->QueryInterface(&iid, (void **)&res); fixed(ID3D11RenderTargetView **trt = &_textureRenderTarget) { ThrowIfFailed(_d3deviceVLC->CreateRenderTargetView(res, &renderTargetViewDesc, trt)); res->Release(); _d3dctxVLC->OMSetRenderTargets(1, trt, null); } output.Union.DxgiFormat = (int)renderFormat; output.FullRange = true; output.ColorSpace = ColorSpace.BT709; output.ColorPrimaries = ColorPrimaries.BT709; output.TransferFunction = TransferFunction.SRGB; return(true); }
public static object Read_D3D11_RENDER_TARGET_VIEW_DESC(BinaryReader br) { D3D11_RENDER_TARGET_VIEW_DESC desc = new D3D11_RENDER_TARGET_VIEW_DESC(); desc.offset = br.BaseStream.Position; desc.Format = (DXGI_FORMAT)br.ReadUInt32(); desc.ViewDimension = (D3D11_RTV_DIMENSION)br.ReadUInt32(); switch (desc.ViewDimension) { case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_UNKNOWN: break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_BUFFER: desc.Buffer = new D3D11_BUFFER_RTV(); desc.Buffer.FirstElement = br.ReadUInt32(); desc.Buffer.NumElements = br.ReadUInt32(); desc.Buffer.ElementOffset = desc.Buffer.FirstElement; desc.Buffer.ElementWidth = desc.Buffer.NumElements; break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE1D: desc.Texture1D = new D3D11_TEX1D_RTV(); desc.Texture1D.MipSlice = br.ReadUInt32(); break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE1DARRAY: desc.Texture1DArray = new D3D11_TEX1D_ARRAY_RTV(); desc.Texture1DArray.MipSlice = br.ReadUInt32(); desc.Texture1DArray.FirstArraySlice = br.ReadUInt32(); desc.Texture1DArray.ArraySize = br.ReadUInt32(); break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE2D: desc.Texture2D = new D3D11_TEX2D_RTV(); desc.Texture2D.MipSlice = br.ReadUInt32(); break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE2DARRAY: desc.Texture2DArray = new D3D11_TEX2D_ARRAY_RTV(); desc.Texture2DArray.MipSlice = br.ReadUInt32(); desc.Texture2DArray.FirstArraySlice = br.ReadUInt32(); desc.Texture2DArray.ArraySize = br.ReadUInt32(); break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE2DMS: desc.Texture2DMS = new D3D11_TEX2DMS_RTV(); desc.Texture2DMS.UnusedField_NothingToDefine = 0; // dummy break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY: desc.Texture2DMSArray = new D3D11_TEX2DMS_ARRAY_RTV(); desc.Texture2DMSArray.FirstArraySlice = br.ReadUInt32(); desc.Texture2DMSArray.ArraySize = br.ReadUInt32(); break; case D3D11_RTV_DIMENSION.D3D11_RTV_DIMENSION_TEXTURE3D: desc.Texture3D = new D3D11_TEX3D_RTV(); desc.Texture3D.MipSlice = br.ReadUInt32(); desc.Texture3D.FirstWSlice = br.ReadUInt32(); desc.Texture3D.WSize = br.ReadUInt32(); break; default: throw new Exception($"Unrecognised RTV Dimension {desc.ViewDimension}"); } desc.length = br.BaseStream.Position - desc.offset; return(desc); }