Void CImplDirectXStatesBlend::Acquire() { if( m_State ) m_State->Release(); D3D10_BLEND_DESC desc; MemoryFill( &desc, 0, sizeof( desc ) ); UInt32 i; for(i=0;i<8;i++) { desc.BlendEnable[i] = m_PublicImpl->GetDesc().BlendEnable[i]; desc.RenderTargetWriteMask[i] = TranslateWriteMask( m_PublicImpl->GetDesc().WriteMask[0] ); } desc.BlendOp = TranslateBlendOp( m_PublicImpl->GetDesc().ColorBlendOp ); desc.BlendOpAlpha = TranslateBlendOp( m_PublicImpl->GetDesc().AlphaBlendOp ); desc.SrcBlend = TranslateBlend( m_PublicImpl->GetDesc().SrcColorBlend ); desc.DestBlend = TranslateBlend( m_PublicImpl->GetDesc().DstColorBlend ); desc.SrcBlendAlpha = TranslateBlend( m_PublicImpl->GetDesc().SrcAlphaBlend ); desc.DestBlendAlpha = TranslateBlend( m_PublicImpl->GetDesc().DstAlphaBlend ); desc.AlphaToCoverageEnable = FALSE; ID3D10Device* device = CImplDirectXGraphicsManagerHelper::GetDevice(); AssertDXCall( device->CreateBlendState( &desc, &m_State ) ); }
bool xGL2RenderTexture::grabRenderTagetData(int x , int y , int w , int h , void* pData) { if(m_bLockable == false || m_pSysTexture == NULL) return false; ID3D10Device* pDevice = m_pGL2Api->d10Device(); pDevice->CopyResource(m_pSysTexture , m_pTexture); xTextureLockArea lockInfo; lock(eLock_Read , lockInfo); const char* pSrcLine = (const char*)lockInfo.m_pixels + x * m_TexInfo.m_nBytePerPixel; pSrcLine += lockInfo.m_picth * y; char* pDstLine = (char*)pData; int dstPitch = m_TexInfo.m_nBytePerPixel * w; int line_len = dstPitch; int max_len = lockInfo.m_picth - x * m_TexInfo.m_nBytePerPixel; if(dstPitch > max_len ) line_len = max_len; for(int _y = 0 ; _y < (int)h ; _y ++ ) { memcpy(pDstLine , pSrcLine , line_len ); pDstLine += dstPitch; pSrcLine += lockInfo.m_picth; } unlock(lockInfo); return true; }
bool TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) { mSize = aSize; ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE); newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX; HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture)); if (FAILED(hr)) { LOGD3D11("Error creating texture for client!"); return false; } // Defer clearing to the next time we lock to avoid an extra (expensive) lock. mNeedsClear = aFlags & ALLOC_CLEAR_BUFFER; mNeedsClearWhite = aFlags & ALLOC_CLEAR_BUFFER_WHITE; return true; }
bool BlondeIndexBufferDX::Fill( void* data ) { if (EngineGlobals::renderAPI_DirectX && EngineGlobals::renderAPI_DirectXVersion == 9) { void * bufferPointer; HRESULT result = indexBufferDx9->Lock(0, numIndices * indexSize, &bufferPointer, 0); if (FAILED(result)) { EngineMessageHandler::SendMessageErrorConsole("Error locking the index buffer for writing."); return false; } memcpy(bufferPointer, data, indexSize * numIndices); indexBufferDx9->Unlock(); return true; } else if(EngineGlobals::renderAPI_DirectX && EngineGlobals::renderAPI_DirectXVersion == 10) { // Get the DirectX 10 device. ID3D10Device* pDevice = (ID3D10Device*) BlondeGraphics::GetCurrentDevice(); pDevice->UpdateSubresource(indexBufferDx10, 0, NULL, data, 0, 0); return true; } return false; }
static bool grabFrameD3D10(IDXGISwapChain *swap) { ID3D10Device *device = 0; ID3D10Texture2D *tex = 0, *captureTex = 0; if (FAILED(swap->GetBuffer(0, IID_ID3D10Texture2D, (void**)&tex))) return false; D3D10_TEXTURE2D_DESC desc; tex->GetDevice(&device); tex->GetDesc(&desc); // re-creating the capture staging texture each frame is definitely not the most efficient // way to handle things, but it frees me of all kind of resource management trouble, so // here goes... desc.MipLevels = 1; desc.ArraySize = 1; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D10_USAGE_STAGING; desc.BindFlags = 0; desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; desc.MiscFlags = 0; if(FAILED(device->CreateTexture2D(&desc,0,&captureTex))) printLog("video/d3d10: couldn't create staging texture for gpu->cpu download!\n"); else setCaptureResolution(desc.Width,desc.Height); if(device) device->CopySubresourceRegion(captureTex,0,0,0,0,tex,0,0); D3D10_MAPPED_TEXTURE2D mapped; bool grabOk = false; if(captureTex && SUCCEEDED(captureTex->Map(0,D3D10_MAP_READ,0,&mapped))) { switch(desc.Format) { case DXGI_FORMAT_R8G8B8A8_UNORM: blitAndFlipRGBAToCaptureData((unsigned char *) mapped.pData,mapped.RowPitch); grabOk = true; break; default: printLog("video/d3d10: unsupported backbuffer format, can't grab pixels!\n"); break; } captureTex->Unmap(0); } tex->Release(); if(captureTex) captureTex->Release(); if(device) device->Release(); return grabOk; }
bool CGutFontUniCodeDX10::AccessTexture(WCHAR c, int &x, int &y) { bool bUpdateTexture = CGutFontUniCode::AccessTexture(c, x, y); if ( bUpdateTexture ) { ID3D10Device *pDevice = GutGetGraphicsDeviceDX10(); float tX = (float)x / (float)m_iLayoutW; float tY = (float)y / (float)m_iLayoutH; float tW = 1.0f/(float)m_iLayoutW; float tH = 1.0f/(float)m_iLayoutH; int left = tX * m_iTextureW; int width = tW * m_iTextureW; int right = left + width; int top = tY * m_iTextureH; int height = tH * m_iTextureH; int bottom = top + height; unsigned char *pBuffer = new unsigned char[width*height]; unsigned char *buffer = pBuffer; for ( int y=0; y<height; y++ ) { for ( int x=0; x<width; x++ ) { COLORREF rgb = GetPixel(m_MemDC, x, y); buffer[0] = GetRValue(rgb); buffer++; } } D3D10_BOX box; box.left = left; box.right = right; box.top = top; box.bottom = bottom; box.front = 0; box.back = 1; pDevice->UpdateSubresource( m_pFontTexture2D, 0, &box, pBuffer, width, width*height); delete [] pBuffer; } return true; }
/** * @fn Render() * * @brief Renders the quad */ void CDXQuad::Render() { // Get the output device ID3D10Device *pDev = DXUTGetD3D10Device(); // Set the output topology pDev->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // Set the vertex buffer and input layout, then render UINT offset = 0; pDev->IASetVertexBuffers(0, 1, &m_pVBuff, (UINT*)&m_vertexSize, &offset); pDev->Draw(4, 0); }
void TextureClientD3D11::Unlock() { MOZ_ASSERT(mIsLocked, "Unlocked called while the texture is not locked!"); if (!mIsLocked) { return; } if (mDrawTarget) { // see the comment on TextureClient::BorrowDrawTarget. // This DrawTarget is internal to the TextureClient and is only exposed to the // outside world between Lock() and Unlock(). This assertion checks that no outside // reference remains by the time Unlock() is called. MOZ_ASSERT(mDrawTarget->refCount() == 1); mDrawTarget->Flush(); } if (mReadbackSink && mTexture10) { ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); D3D10_TEXTURE2D_DESC desc; mTexture10->GetDesc(&desc); desc.BindFlags = 0; desc.Usage = D3D10_USAGE_STAGING; desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; desc.MiscFlags = 0; RefPtr<ID3D10Texture2D> tex; HRESULT hr = device->CreateTexture2D(&desc, nullptr, byRef(tex)); if (FAILED(hr)) { gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(mSize))) << "[D3D11] CreateTexture2D failure " << mSize << " Code: " << gfx::hexa(hr); return; } if (SUCCEEDED(hr)) { device->CopyResource(tex, mTexture10); gfxWindowsPlatform::GetPlatform()->GetReadbackManager()->PostTask(tex, mReadbackSink); } else { mReadbackSink->ProcessReadback(nullptr); } } // The DrawTarget is created only once, and is only usable between calls // to Lock and Unlock. if (mTexture) { UnlockD3DTexture(mTexture.get()); } else { UnlockD3DTexture(mTexture10.get()); } mIsLocked = false; }
Void CImplDirectXStatesBlend::Activate() { Float32 BlendFactor[4]; BlendFactor[0] = 1.0f; BlendFactor[1] = 1.0f; BlendFactor[2] = 1.0f; BlendFactor[3] = 1.0f; ID3D10Device* device = CImplDirectXGraphicsManagerHelper::GetDevice(); DebugAssert( m_State ); device->OMSetBlendState ( m_State, BlendFactor, 0xffffffff ); }
bool xGL2DepthBuffer::create(ID3D10Resource* pTexture , xGL2TexInfo& TexInfo) { destory(); ID3D10Device* pDevice = m_pGL2Api->d10Device(); //创建深度缓冲 GL2_DEPTH_STENCIL_VIEW_DESC descDSV; descDSV.Format = TexInfo.m_RTViewFmt; descDSV.ViewDimension = GL2_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; HRESULT hr = pDevice->CreateDepthStencilView( pTexture, &descDSV, &m_pDepthView ); return !FAILED(hr); }
bool DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize, gfxContentType aType) { D3D10_TEXTURE2D_DESC desc; if (mTexture) { mTexture->GetDesc(&desc); if (desc.Width == aSize.width && desc.Height == aSize.height) { return true; } mTexture = nullptr; mSurface = nullptr; ClearDT(); } mSize = aSize; ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE); newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX; HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture)); if (FAILED(hr)) { LOGD3D11("Error creating texture for client!"); return false; } RefPtr<IDXGIResource> resource; mTexture->QueryInterface((IDXGIResource**)byRef(resource)); HANDLE sharedHandle; hr = resource->GetSharedHandle(&sharedHandle); if (FAILED(hr)) { LOGD3D11("Error getting shared handle for texture."); return false; } mDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle, aType == GFX_CONTENT_COLOR_ALPHA); mContentType = aType; return true; }
/** * @fn Resize (int w, int h) * * @brief Resizes the render target, creates new textures and views * * @param w - New resource width * * @param h - New resource height */ void CDXRenderTarget::Resize(int resW, int resH) { HRESULT hr; SAFE_RELEASE(m_pSRV); SAFE_RELEASE(m_pRTV); SAFE_RELEASE(m_pTexture); SAFE_RELEASE(m_pTextureCPU); // Save the new values m_width = resW; m_height = resH; // Get the device ID3D10Device *pDev = DXUTGetD3D10Device(); // Create the texture here CD3D10_TEXTURE2D_DESC desc(m_fmt, resW, resH, 1, 1); desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; desc.Usage = D3D10_USAGE_DEFAULT; hr = pDev->CreateTexture2D(&desc, NULL, &m_pTexture); assert(hr == S_OK); // Create the CPU version of the texture here CD3D10_TEXTURE2D_DESC descCPU(m_fmt, resW, resH, 1, 1); descCPU.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; descCPU.Usage = D3D10_USAGE_DYNAMIC; hr = pDev->CreateTexture2D(&descCPU, NULL, &m_pTextureCPU); assert(hr == S_OK); // Create the shader resource view D3D10_SHADER_RESOURCE_VIEW_DESC resDesc; resDesc.Format = m_fmt; resDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; resDesc.Texture2D.MipLevels = 1; resDesc.Texture2D.MostDetailedMip = 0; hr = pDev->CreateShaderResourceView(m_pTexture, &resDesc, &m_pSRV); assert(hr == S_OK); // Create the render target view D3D10_RENDER_TARGET_VIEW_DESC rtDesc; rtDesc.Format = m_fmt; rtDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; rtDesc.Texture2D.MipSlice = 0; hr = pDev->CreateRenderTargetView(m_pTexture, &rtDesc, &m_pRTV); assert(hr == S_OK); } // End of resize()
void D10State::newTexture(unsigned int w, unsigned int h) { HRESULT hr; ods("D3D10: newTexture %d %d", w, h); if (pTexture) { pTexture->Release(); pTexture = NULL; } if (pSRView) { pSRView->Release(); pSRView = NULL; } D3D10_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Width = w; desc.Height = h; desc.MipLevels = desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Usage = D3D10_USAGE_DYNAMIC; desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture); if (FAILED(hr)) { pTexture = NULL; ods("D3D10: Failed to create texture."); return; } D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = desc.Format; srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = desc.MipLevels; hr = pDevice->CreateShaderResourceView(pTexture, &srvDesc, &pSRView); if (FAILED(hr)) { pSRView = NULL; pTexture->Release(); pTexture = NULL; ods("D3D10: Failed to create resource view."); return; } }
Void CImplDirectXViewport::Activate() { ID3D10Device* device = CImplDirectXGraphicsManagerHelper::GetDevice(); D3D10_VIEWPORT viewports[1]; //define viewports viewports[0].Width = m_PublicImpl->GetWidth(); viewports[0].Height = m_PublicImpl->GetHeight(); viewports[0].MinDepth = m_PublicImpl->GetMinDepth(); viewports[0].MaxDepth = m_PublicImpl->GetMaxDepth(); viewports[0].TopLeftX = m_PublicImpl->GetTopLeftX(); viewports[0].TopLeftY = m_PublicImpl->GetTopLeftY(); device->RSSetViewports( 1, viewports ); }
void D10State::draw() { clock_t t = clock(); float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC; ++frameCount; if (elapsed > OVERLAY_FPS_INTERVAL) { OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; om.omh.uiType = OVERLAY_MSGTYPE_FPS; om.omh.iLength = sizeof(OverlayMsgFps); om.omf.fps = frameCount / elapsed; sendMessage(om); frameCount = 0; timeT = t; } dwMyThread = GetCurrentThreadId(); checkMessage(vp.Width, vp.Height); if (a_ucTexture && pSRView && (uiLeft != uiRight)) { HRESULT hr; pOrigStateBlock->Capture(); pMyStateBlock->Apply(); D3D10_TECHNIQUE_DESC techDesc; pTechnique->GetDesc(&techDesc); // Set vertex buffer UINT stride = sizeof(SimpleVertex); UINT offset = 0; pDevice->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset); hr = pDiffuseTexture->SetResource(pSRView); if (! SUCCEEDED(hr)) ods("D3D10: Failed to set resource"); for (UINT p = 0; p < techDesc.Passes; ++p) { pTechnique->GetPassByIndex(p)->Apply(0); pDevice->DrawIndexed(6, 0, 0); } pOrigStateBlock->Apply(); } dwMyThread = 0; }
void D3D10Texture::Allocate(UINT Width, UINT Height, bool ConstructMipmaps, DXGI_FORMAT Format, const Bitmap &Bmp) { FreeMemory(); PersistentAssert(_GD != NULL, "D3D10Texture::Allocate on unassociated texture"); ID3D10Device* Device = _GD->CastD3D10().GetDevice(); D3D10_TEXTURE2D_DESC TextureDesc; TextureDesc.Width = Width; TextureDesc.Height = Height; TextureDesc.MipLevels = 0; if(!ConstructMipmaps) { TextureDesc.MipLevels = 1; } TextureDesc.ArraySize = 1; TextureDesc.Format = Format; TextureDesc.SampleDesc.Count = 1; TextureDesc.SampleDesc.Quality = 0; TextureDesc.Usage = D3D10_USAGE_DEFAULT; TextureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; TextureDesc.CPUAccessFlags = 0; TextureDesc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; D3D10_SUBRESOURCE_DATA Data[12]; for(UINT Index = 0; Index < 12; Index++) { Data[Index].pSysMem = &(Bmp[0][0]); Data[Index].SysMemPitch = Bmp.Width() * sizeof(RGBColor); } HRESULT hr = Device->CreateTexture2D(&TextureDesc, Data, &_Texture); PersistentAssert(SUCCEEDED(hr), "CreateTexture2D failed"); _Texture->GetDesc(&TextureDesc); D3D10_SHADER_RESOURCE_VIEW_DESC ViewDesc; ViewDesc.Format = Format; ViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; ViewDesc.Texture2D.MostDetailedMip = 0; ViewDesc.Texture2D.MipLevels = TextureDesc.MipLevels; hr = Device->CreateShaderResourceView(_Texture, &ViewDesc, &_View); PersistentAssert(SUCCEEDED(hr), "CreateShaderResourceView failed"); Device->GenerateMips(_View); }
Texture3D::Texture3D(Texture3D_Desc& desc, Renderer* pRender) { HRESULT hr; ID3D10Device* pDevice = pRender->GetDevice(); V(pDevice->CreateTexture3D( &desc, //[in] const D3D10_TEXTURE3D_DESC *pDesc, NULL, //[in] const D3D10_SUBRESOURCE_DATA *pInitialData, &_ptr //[out] ID3D10Texture3D **ppTexture3D )); if (SUCCEEDED(hr)) { _width = (float)desc.Width; _height = (float)desc.Height; _depth = (float)desc.Depth; _invW = 1.0f / _width; _invH = 1.0f / _height; _invD = 1.0f / _depth; D3D10_SHADER_RESOURCE_VIEW_DESC resourceViewDesc; resourceViewDesc.Format = desc.Format; resourceViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE3D; resourceViewDesc.Texture3D.MostDetailedMip = 0; resourceViewDesc.Texture3D.MipLevels = desc.MipLevels; ID3D10ShaderResourceView* pResourceView; V(pDevice->CreateShaderResourceView( (ID3D10Resource *)_ptr, //[in] ID3D10Resource *pResource, &resourceViewDesc, //[in] const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc, &pResourceView //[out] ID3D10ShaderResourceView **ppSRView )); if (SUCCEEDED(hr)) { _ResourceView = pResourceView; } } else { _ptr = NULL; _width = 0; _height = 0; _depth = 0; _invW = 0; _invH = 0; _invD = 0; } }
ReturnCode LandscapeView::draw() { //Make sure we have a proper handle to our device ID3D10Device* pobjDevice = BattleViewManager::getInstance()->getDevice(); if(!pobjDevice || !m_pobjIndexBuffer || !m_pobjVertexBuffer) return RC_ERR_INVALID_STATE; //Set up our buffers UINT offset = 0; UINT stride = m_uiStride; pobjDevice->IASetVertexBuffers(0, 1, &m_pobjVertexBuffer, &stride, &offset); pobjDevice->IASetIndexBuffer(m_pobjIndexBuffer, DXGI_FORMAT_R32_UINT, 0); //Draw! pobjDevice->DrawIndexed(m_uiNumIndices, 0, 0); return RC_OK; }
void ScreenAlignedTexture::Draw() { ID3D10Device * device = Graphics::GetInstance()->Device(); m_effect->SetWorldViewProjection(m_world, m_view, m_projection); device->IASetInputLayout(m_effect->InputLayout); UINT stride = sizeof(VertexPositionTextureNormal); UINT offset = 0; device->IASetVertexBuffers(0,1, &VertexBuffer, &stride, &offset); //// set the index buffer device->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0); // Set primitive topology device->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP ); D3D10_TECHNIQUE_DESC techDesc; m_effect->CurrentTechnique->GetDesc(&techDesc); for(UINT p = 0; p < techDesc.Passes; ++p) { m_effect->CurrentTechnique->GetPassByIndex(p)->Apply(0); device->DrawIndexed(4, 0 , 0); } }
// D3D10 specific logic for the Present function. void presentD3D10(IDXGISwapChain *pSwapChain) { ID3D10Device *pDevice = NULL; HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D10Device), (void **) &pDevice); if (SUCCEEDED(hr) && pDevice) { SwapchainMap::iterator it = chains.find(pSwapChain); D10State *ds = it != chains.end() ? it->second : NULL; if (ds && ds->pDevice != pDevice) { ods("D3D10: SwapChain device changed"); devices.erase(ds->pDevice); delete ds; ds = NULL; } if (ds == NULL) { ods("D3D10: New state"); ds = new D10State(pSwapChain, pDevice); if (!ds->init()) { pDevice->Release(); delete ds; return; } chains[pSwapChain] = ds; devices[pDevice] = ds; } ds->draw(); pDevice->Release(); } else { #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT // DXGI is used for multiple D3D versions. Thus, it is possible a device // associated with the DXGISwapChain may very well not be a D3D10 one, // in which case we can safely ignore it. ods("D3D10: Could not draw because ID3D10Device could not be retrieved."); #endif } }
void DeprecatedTextureClientD3D11::SetDescriptor(const SurfaceDescriptor& aDescriptor) { if (aDescriptor.type() == SurfaceDescriptor::Tnull_t) { EnsureAllocated(mSize, mContentType); return; } mDescriptor = aDescriptor; mSurface = nullptr; ClearDT(); if (aDescriptor.type() == SurfaceDescriptor::T__None) { return; } MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10); ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(), __uuidof(ID3D10Texture2D), (void**)(ID3D10Texture2D**)byRef(mTexture)); }
//-------------------------------------------------------------------------------------- void CDXUTTextHelper::Init( ID3DXFont* pFont9, ID3DXSprite* pSprite9, ID3DX10Font* pFont10, ID3DX10Sprite* pSprite10, int nLineHeight ) { m_pFont9 = pFont9; m_pSprite9 = pSprite9; m_pFont10 = pFont10; m_pSprite10 = pSprite10; m_clr = D3DXCOLOR( 1, 1, 1, 1 ); m_pt.x = 0; m_pt.y = 0; m_nLineHeight = nLineHeight; m_pFontBlendState10 = NULL; // Create a blend state if a sprite is passed in if( pSprite10 ) { ID3D10Device* pDev = NULL; pSprite10->GetDevice( &pDev ); if( pDev ) { D3D10_BLEND_DESC StateDesc; ZeroMemory( &StateDesc, sizeof( D3D10_BLEND_DESC ) ); StateDesc.AlphaToCoverageEnable = FALSE; StateDesc.BlendEnable[0] = TRUE; StateDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; StateDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; StateDesc.BlendOp = D3D10_BLEND_OP_ADD; StateDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; StateDesc.DestBlendAlpha = D3D10_BLEND_ZERO; StateDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; StateDesc.RenderTargetWriteMask[0] = 0xf; pDev->CreateBlendState( &StateDesc, &m_pFontBlendState10 ); pDev->Release(); } } }
bool CGutFontUniCodeDX10::CreateTexture(int w, int h) { m_iTextureW = w; m_iTextureH = h; ID3D10Device *pDevice = GutGetGraphicsDeviceDX10(); // { D3D10_TEXTURE2D_DESC desc; ZeroMemory( &desc, sizeof(desc) ); desc.Width = w; desc.Height = h; desc.MipLevels = 1; desc.ArraySize = 1; desc.SampleDesc.Count = 1; desc.Format = DXGI_FORMAT_A8_UNORM; desc.Usage = D3D10_USAGE_DEFAULT; desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; pDevice->CreateTexture2D( &desc, NULL, &m_pFontTexture2D ); } // { D3D10_SHADER_RESOURCE_VIEW_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Format = DXGI_FORMAT_A8_UNORM; desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; desc.Texture2D.MostDetailedMip = 0; desc.Texture2D.MipLevels = 1; pDevice->CreateShaderResourceView(m_pFontTexture2D, &desc, &m_pFontTexture); } return true; }
static HRESULT __stdcall myPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags) { HRESULT hr; // ods("DXGI: Device Present"); ID3D10Device *pDevice = NULL; ods("DXGI: DrawBegin"); hr = pSwapChain->GetDevice(__uuidof(ID3D10Device), (void **) &pDevice); if (pDevice) { D10State *ds = chains[pSwapChain]; if (ds && ds->pDevice != pDevice) { ods("DXGI: SwapChain device changed"); devices.erase(ds->pDevice); delete ds; ds = NULL; } if (! ds) { ods("DXGI: New state"); ds = new D10State(pSwapChain, pDevice); chains[pSwapChain] = ds; devices[pDevice] = ds; ds->init(); } ds->draw(); pDevice->Release(); ods("DXGI: DrawEnd"); } PresentType oPresent = (PresentType) hhPresent.call; hhPresent.restore(); hr = oPresent(pSwapChain, SyncInterval, Flags); hhPresent.inject(); return hr; }
/** * @fn RenderBoundary(XFormMaterial &mat, int techIndex) * * @brief Renders the quad * * @param mat - The material to render * * @param techIndex - Technique index */ void CDXQuadWithBoundary::RenderBoundary(XFormMaterial &mat, int techIndex) { D3DXVECTOR4 xform[2]; // Construct the transformation vector Region2XForm(xform[0], -1.0f, -1.0f, 1.0f, 1.0f); Region2XForm(xform[1], 0.0f, 0.0f, 1.0f, 1.0f); // Set it mat.SetXForm(xform); // Apply the rendering techique mat.Apply(techIndex); // Get the device ID3D10Device *pDev = DXUTGetD3D10Device(); // Set the output topology pDev->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP); // Set the index buffer pDev->IASetIndexBuffer(m_pIB, DXGI_FORMAT_R32_UINT, 0); // Set the vertex buffer and input layout, then render UINT offset = 0; pDev->IASetVertexBuffers(0, 1, &m_pVBuff, (UINT*)&m_vertexSize, &offset); // Draw four lines pDev->DrawIndexed(4, 0, 0); }
UINT STDMETHODCALLTYPE DeviceReleaseHook() { ID3D10Device *device = (ID3D10Device*)this; device->AddRef(); ULONG refVal = (*(RELEASEPROC)oldD3D11Release)(device); if(bHasTextures) { if(refVal == 5) //our two textures are holding the reference up, so always clear at 3 { ClearD3D11Data(); lpCurrentDevice = NULL; bTargetAcquired = false; } } else if(refVal == 1) { lpCurrentDevice = NULL; bTargetAcquired = false; } return (*(RELEASEPROC)oldD3D11Release)(device); }
static ID3D10ShaderResourceView *BrightnessImage(ID3D10ShaderResourceView *pTexture, sImageInfo *pInfo) { ID3D10Device *device = GutGetGraphicsDeviceDX10(); int w = pInfo->m_iWidth/4; int h = pInfo->m_iHeight/4; float fTexelW = 1.0f/(float)w; float fTexelH = 1.0f/(float)h; D3D10_VIEWPORT vp = {0, 0, w, h, 0.0f, 1.0f}; device->RSSetViewports(1, &vp); device->VSSetShader(g_pBlurVS); device->PSSetShader(g_pBrightnessPS); ID3D10Buffer *buffer_array[2] = {g_pVSConstantBuffer, g_pBrightnessConstantBuffer}; device->VSSetConstantBuffers(0, 2, buffer_array); device->PSSetConstantBuffers(0, 2, buffer_array); UINT stride = sizeof(Vertex_VT); UINT offset = 0; g_pDevice->IASetInputLayout(g_pVertexLayout); g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset); device->OMSetRenderTargets(1, &g_pFrameRTView[1], NULL); Vector4 *pConstants; g_pBrightnessConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstants); pConstants[0] = g_vBrightnessOffset; pConstants[1] = g_vBrightnessScale; g_pBrightnessConstantBuffer->Unmap(); g_pDevice->PSSetShaderResources(0, 1, &pTexture); g_pDevice->Draw(4, 0); return g_pFrameSRView[1]; }
void PeaksAndValleys::render() { ID3D10Device *device = DirectEngine::getInstance()->getDevice(); device->IASetInputLayout(_inputLayout); device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); D3DXMATRIX mvpMatrix = _modelMatrix * _viewMatrix * _projMatrix; _mvpMatrixV->SetMatrix((float*)&mvpMatrix); _effectTech->GetPassByIndex(0)->Apply(0); unsigned vertexStride = sizeof(float)*7; unsigned offset = 0; device->IASetVertexBuffers(0, 1, &_vertexBuffer, &vertexStride, &offset); device->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R16_UINT, 0); device->DrawIndexed(_indexCount, 0, 0); }
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data) { ID3D10Device* ctx = g_pd3dDevice; // Create and grow vertex/index buffers if needed if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) { if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } g_VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D10_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); desc.Usage = D3D10_USAGE_DYNAMIC; desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert); desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; desc.MiscFlags = 0; if (ctx->CreateBuffer(&desc, NULL, &g_pVB) < 0) return; } if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) { if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } g_IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D10_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D10_BUFFER_DESC)); desc.Usage = D3D10_USAGE_DYNAMIC; desc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx); desc.BindFlags = D3D10_BIND_INDEX_BUFFER; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; if (ctx->CreateBuffer(&desc, NULL, &g_pIB) < 0) return; } // Copy and convert all vertices into a single contiguous buffer ImDrawVert* vtx_dst = NULL; ImDrawIdx* idx_dst = NULL; g_pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst); g_pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; memcpy(vtx_dst, &cmd_list->VtxBuffer[0], cmd_list->VtxBuffer.size() * sizeof(ImDrawVert)); memcpy(idx_dst, &cmd_list->IdxBuffer[0], cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx)); vtx_dst += cmd_list->VtxBuffer.size(); idx_dst += cmd_list->IdxBuffer.size(); } g_pVB->Unmap(); g_pIB->Unmap(); // Setup orthographic projection matrix into our constant buffer { void* mapped_resource; if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) return; VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource; const float L = 0.0f; const float R = ImGui::GetIO().DisplaySize.x; const float B = ImGui::GetIO().DisplaySize.y; const float T = 0.0f; const float mvp[4][4] = { { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, { 0.0f, 0.0f, 0.5f, 0.0f }, { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, }; memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); g_pVertexConstantBuffer->Unmap(); } // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) struct BACKUP_DX10_STATE { UINT ScissorRectsCount, ViewportsCount; D3D10_RECT ScissorRects[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; D3D10_VIEWPORT Viewports[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; ID3D10RasterizerState* RS; ID3D10BlendState* BlendState; FLOAT BlendFactor[4]; UINT SampleMask; UINT StencilRef; ID3D10DepthStencilState* DepthStencilState; ID3D10ShaderResourceView* PSShaderResource; ID3D10SamplerState* PSSampler; ID3D10PixelShader* PS; ID3D10VertexShader* VS; D3D10_PRIMITIVE_TOPOLOGY PrimitiveTopology; ID3D10Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; DXGI_FORMAT IndexBufferFormat; ID3D10InputLayout* InputLayout; }; BACKUP_DX10_STATE old; old.ScissorRectsCount = old.ViewportsCount = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); ctx->RSGetState(&old.RS); ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); ctx->PSGetSamplers(0, 1, &old.PSSampler); ctx->PSGetShader(&old.PS); ctx->VSGetShader(&old.VS); ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); ctx->IAGetInputLayout(&old.InputLayout); // Setup viewport D3D10_VIEWPORT vp; memset(&vp, 0, sizeof(D3D10_VIEWPORT)); vp.Width = (UINT)ImGui::GetIO().DisplaySize.x; vp.Height = (UINT)ImGui::GetIO().DisplaySize.y; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = vp.TopLeftY = 0; ctx->RSSetViewports(1, &vp); // Bind shader and vertex buffers unsigned int stride = sizeof(ImDrawVert); unsigned int offset = 0; ctx->IASetInputLayout(g_pInputLayout); ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ctx->VSSetShader(g_pVertexShader); ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); ctx->PSSetShader(g_pPixelShader); ctx->PSSetSamplers(0, 1, &g_pFontSampler); // Setup render state const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff); ctx->OMSetDepthStencilState(g_pDepthStencilState, 0); ctx->RSSetState(g_pRasterizerState); // Render command lists int vtx_offset = 0; int idx_offset = 0; for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list, pcmd); } else { const D3D10_RECT r = { (LONG)pcmd->ClipRect.x, (LONG)pcmd->ClipRect.y, (LONG)pcmd->ClipRect.z, (LONG)pcmd->ClipRect.w }; ctx->PSSetShaderResources(0, 1, (ID3D10ShaderResourceView**)&pcmd->TextureId); ctx->RSSetScissorRects(1, &r); ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset); } idx_offset += pcmd->ElemCount; } vtx_offset += cmd_list->VtxBuffer.size(); } // Restore modified DX state ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); ctx->RSSetViewports(old.ViewportsCount, old.Viewports); ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); ctx->PSSetShader(old.PS); if (old.PS) old.PS->Release(); ctx->VSSetShader(old.VS); if (old.VS) old.VS->Release(); ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); ctx->IASetPrimitiveTopology(old.PrimitiveTopology); ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); }
// Detour function that replaces the IDXGISwapChain::Present() API DllExport HRESULT __stdcall hook_DXGISwapChainPresent( IDXGISwapChain * This, UINT SyncInterval, UINT Flags ) { static int frame_interval; static LARGE_INTEGER initialTv, captureTv, freq; static int capture_initialized = 0; // int i; struct pooldata *data; struct vsource_frame *frame; // DXGI_SWAP_CHAIN_DESC pDESC; HRESULT hr = pDXGISwapChainPresent(This, SyncInterval, Flags); if(resolution_retrieved == 0) { if(DXGI_get_resolution(This) >= 0) { resolution_retrieved = 1; } return hr; } if(vsource_initialized == 0) { ga_error("video source not initialized.\n"); return hr; } This->GetDesc(&pDESC); pDXGI_FORMAT = pDESC.BufferDesc.Format; // extract screen format for sws_scale if(pDESC.BufferDesc.Width != game_width || pDESC.BufferDesc.Height != game_height) { ga_error("game width/height mismatched (%dx%d) != (%dx%d)\n", pDESC.BufferDesc.Width, pDESC.BufferDesc.Height, game_width, game_height); return hr; } // if (enable_server_rate_control && ga_hook_video_rate_control() < 0) return hr; if (dx_version == dx_none) { //bool check_result = FALSE; if (check_dx_device_version(This, IID_ID3D10Device)) { dx_version = dx_10; ga_error("[DXGISwapChain] DirectX 10\n"); } else if (check_dx_device_version(This, IID_ID3D10Device1)) { dx_version = dx_10_1; ga_error("[DXGISwapChain] DirectX 10.1\n"); } else if (check_dx_device_version(This, IID_ID3D11Device)) { dx_version = dx_11; ga_error("[DXGISwapChain] DirectX 11\n"); } } if (capture_initialized == 0) { frame_interval = 1000000/video_fps; // in the unif of us frame_interval++; QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&initialTv); capture_initialized = 1; } else { QueryPerformanceCounter(&captureTv); } hr = 0; // d3d10 / d3d10.1 if (dx_version == dx_10 || dx_version == dx_10_1) { void *ppDevice; ID3D10Device *pDevice; //IUnknown *pDevice; if (dx_version == dx_10) { This->GetDevice(IID_ID3D10Device, &ppDevice); pDevice = (ID3D10Device *)ppDevice; } else if (dx_version == dx_10_1) { This->GetDevice(IID_ID3D10Device1, &ppDevice); pDevice = (ID3D10Device1 *)ppDevice; } else { OutputDebugString("Invalid DirectX version in IDXGISwapChain::Present"); return hr; } ID3D10RenderTargetView *pRTV = NULL; ID3D10Resource *pSrcResource = NULL; pDevice->OMGetRenderTargets(1, &pRTV, NULL); pRTV->GetResource(&pSrcResource); ID3D10Texture2D* pSrcBuffer = (ID3D10Texture2D *)pSrcResource; ID3D10Texture2D* pDstBuffer = NULL; D3D10_TEXTURE2D_DESC desc; pSrcBuffer->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; desc.Usage = D3D10_USAGE_STAGING; hr = pDevice->CreateTexture2D(&desc, NULL, &pDstBuffer); if (FAILED(hr)) { OutputDebugString("Failed to create texture2D"); //assert(exp_state == exp_none); } pDevice->CopyResource(pDstBuffer, pSrcBuffer); D3D10_MAPPED_TEXTURE2D mapped_screen; hr = pDstBuffer->Map(0, D3D10_MAP_READ, 0, &mapped_screen); if (FAILED(hr)) { OutputDebugString("Failed to map from DstBuffer"); //assert(exp_state == exp_none); } // copy image do { unsigned char *src, *dst; data = g_pipe[0]->allocate_data(); frame = (struct vsource_frame*) data->ptr; frame->pixelformat = PIX_FMT_BGRA; frame->realwidth = desc.Width; frame->realheight = desc.Height; frame->realstride = desc.Width<<2; frame->realsize = frame->realwidth * frame->realstride; frame->linesize[0] = frame->realstride;//frame->stride; // src = (unsigned char*) mapped_screen.pData; dst = (unsigned char*) frame->imgbuf; for (i = 0; i < encoder_height; i++) { CopyMemory(dst, src, frame->realstride/*frame->stride*/); src += mapped_screen.RowPitch; dst += frame->realstride;//frame->stride; } frame->imgpts = pcdiff_us(captureTv, initialTv, freq)/frame_interval; } while(0); // duplicate from channel 0 to other channels for(i = 1; i < SOURCES; i++) { int j; struct pooldata *dupdata; struct vsource_frame *dupframe; dupdata = g_pipe[i]->allocate_data(); dupframe = (struct vsource_frame*) dupdata->ptr; // vsource_dup_frame(frame, dupframe); // g_pipe[i]->store_data(dupdata); g_pipe[i]->notify_all(); } g_pipe[0]->store_data(data); g_pipe[0]->notify_all(); pDstBuffer->Unmap(0); pDevice->Release(); pSrcResource->Release(); pSrcBuffer->Release(); pRTV->Release(); pDstBuffer->Release(); // d11 } else if (dx_version == dx_11) { void *ppDevice; This->GetDevice(IID_ID3D11Device, &ppDevice); ID3D11Device *pDevice = (ID3D11Device*) ppDevice; This->GetDevice(IID_ID3D11DeviceContext, &ppDevice); ID3D11DeviceContext *pDeviceContext = (ID3D11DeviceContext *) ppDevice; ID3D11RenderTargetView *pRTV = NULL; ID3D11Resource *pSrcResource = NULL; pDeviceContext->OMGetRenderTargets(1, &pRTV, NULL); pRTV->GetResource(&pSrcResource); ID3D11Texture2D *pSrcBuffer = (ID3D11Texture2D *)pSrcResource; ID3D11Texture2D *pDstBuffer = NULL; D3D11_TEXTURE2D_DESC desc; pSrcBuffer->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; hr = pDevice->CreateTexture2D(&desc, NULL, &pDstBuffer); if (FAILED(hr)) { OutputDebugString("Failed to create buffer"); //assert(exp_state == exp_none); } pDeviceContext->CopyResource(pDstBuffer, pSrcBuffer); D3D11_MAPPED_SUBRESOURCE mapped_screen; hr = pDeviceContext->Map(pDstBuffer, 0, D3D11_MAP_READ, 0, &mapped_screen); if (FAILED(hr)) { OutputDebugString("Failed to map from DeviceContext"); //assert(exp_state == exp_none); } // copy image do { unsigned char *src, *dst; data = g_pipe[0]->allocate_data(); frame = (struct vsource_frame*) data->ptr; frame->pixelformat = PIX_FMT_BGRA; frame->realwidth = desc.Width; frame->realheight = desc.Height; frame->realstride = desc.Width<<2; frame->realsize = frame->realwidth * frame->realstride; frame->linesize[0] = frame->realstride;//frame->stride; // src = (unsigned char*) mapped_screen.pData; dst = (unsigned char*) frame->imgbuf; for (i = 0; i < encoder_height; i++) { CopyMemory(dst, src, frame->realstride/*frame->stride*/); src += mapped_screen.RowPitch; dst += frame->realstride;//frame->stride; } frame->imgpts = pcdiff_us(captureTv, initialTv, freq)/frame_interval; } while(0); // duplicate from channel 0 to other channels for(i = 1; i < SOURCES; i++) { int j; struct pooldata *dupdata; struct vsource_frame *dupframe; dupdata = g_pipe[i]->allocate_data(); dupframe = (struct vsource_frame*) dupdata->ptr; // vsource_dup_frame(frame, dupframe); // g_pipe[i]->store_data(dupdata); g_pipe[i]->notify_all(); } g_pipe[0]->store_data(data); g_pipe[0]->notify_all(); pDeviceContext->Unmap(pDstBuffer, 0); pDevice->Release(); pDeviceContext->Release(); pSrcResource->Release(); pSrcBuffer->Release(); pRTV->Release(); pDstBuffer->Release(); } return hr; }