How to Map a RenderTexture of a Plane by Native Code
I've done it in a way of sharing, but the copy of the content seems to perform better. 1.InitFuction: ID3D11ShaderResourceView* m_Texture; ID3D11Texture2D * pcolorBuffer = NULL; ID3D11Texture2D * pdepthBuffer = NULL; ID3D11Texture2D *pTexture = NULL; D3D11_TEXTURE2D_DESC mdesc; ZeroMemory(&mdesc, sizeof(mdesc)); mdesc.Width = 1920; mdesc.Height = 1080; mdesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; mdesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; // This texture will be shared // A DirectX 11 texture with D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX is not compatible with DirectX 9 // so a general named mutex is used for all texture types mdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; mdesc.Usage = D3D11_USAGE_DEFAULT; // Multisampling quality and count // The default sampler mode, with no anti-aliasing, has a count of 1 and a quality level of 0. mdesc.SampleDesc.Quality = 0; mdesc.SampleDesc.Count = 1; mdesc.MipLevels = 1; mdesc.ArraySize = 1; m_Device->CreateTexture2D(&mdesc, NULL, &pTexture); // QI IDXGIResource interface to synchronized shared surface. IDXGIResource* pDXGIResource = NULL; pTexture->QueryInterface(__uuidof(IDXGIResource), (LPVOID*)&pDXGIResource); HANDLE handle = NULL; // obtain handle to IDXGIResource object. pDXGIResource->GetSharedHandle(&handle); pDXGIResource->Release(); ID3D11Resource * tempResource11; HRESULT openResult = m_Device->OpenSharedResource(handle, __uuidof(ID3D11Resource), (void**)(&tempResource11)); m_Device->CreateShaderResourceView(tempResource11, NULL, &m_Texture); 2. SetRenderTexture: void RenderAPI_D3D11::SetRenderTexture(void* colorBuffer, void* depthBuffer, int textureWidth, int textureHeight) { pcolorBuffer = (ID3D11Texture2D *)colorBuffer; pdepthBuffer = (ID3D11Texture2D *)depthBuffer; } 3.UpdateRenderPass: void RenderAPI_D3D11::RenderDistrutionPass() { ID3D11DeviceContext* m_deviceContext = NULL; m_Device->GetImmediateContext(&m_deviceContext); if (pcolorBuffer&&pTexture){ [link text][1]//It's the time-consuming copy of the content, if it's large. m_deviceContext->CopyResource(pTexture, pcolorBuffer); } //... m_deviceContext->Release(); }
[1]: /storage/temp/133444-userenderingplugin.txt
Your answer
Follow this Question
Related Questions
Finding the gameobject closest to the centre of the screen (WorldToViewportPoint) 0 Answers
Preventing world interactions when using an UI element with an Orthographic 3D camera 0 Answers
code error CS0119 field of view script 1 Answer
How to access camera Dont Clear in camera clear flags using c# 1 Answer
Translate between C# and javascript 1 Answer