IDirect3DDevice9::EndScene()涔嬮棿銆傚涓嬫墍紺?
g_pd3dDevice->BeginScene();

// Capture the Rendering onto CDxToMovie's Render Target
g_MovieRecorder.StartRecordingMovie(g_pd3dDevice);
// Render as usual
..
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,200),1,0);
g_pd3dDevice->SetStreamSource(0,g_pVB,0,sizeof(CUSTOMVERTEX));
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
g_MovieRecorder.PauseRecordingMovie(g_pd3dDevice);

// Copy the CDxToMovie's Render Target content back onto BackBuffer's Surface
g_pd3dDevice->StretchRect(g_MovieRecorder.RecordingSurface(),
NULL,pBackSurface,
0,D3DTEXF_NONE);

g_pd3dDevice->EndScene();
鍦ㄤ笂闈㈢殑浠g爜孌典腑錛?nbsp;g_MovieRecorder.StartRecordingMovie(g_pd3dDevice)
灝嗘墍鏈夐殢鍚庣殑娓叉煋鍦–DxToMovie鐨勫唴閮ㄦ覆鏌撶洰鏍囩洿鍒?font face="Courier New">g_MovieRecorder.PauseRecordingMovie(g_pd3dDevice)琚皟鐢ㄣ傛墍鏈夌殑娓叉煋宸ヤ綔鍦–DxToMovie鐨勫唴閮ㄦ覆鏌撶洰鏍囦笂鍋氾紝浣犵殑紼嬪簭back surface灝嗘病鏈変換浣曟湁鏁堢殑鍐呭鏄劇ず鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忕獥鍙c傝繖涓嶈绱?濡傛灉浣犵殑鐢寵涓嶅彧鏄垱浣滆繖閮ㄧ數(shù)褰辨病鏈変換浣曞姩鐢葷洿鎺ュ憟鐜板湪灞忓箷涓娿傜劧鑰?濡傛灉浣犺褰曠數(shù)褰變粠涓涓簰鍔ㄦ父鎴忎細(xì)璇濅笂,瀹冧細(xì)鍙樺潖灞忓箷涓嶆洿鏂板埌鏈鏂扮殑娓叉煋鐨勫唴瀹?鍥犱負(fù)閫氳繃閲嶆柊娓叉煋鐩爣錛孋DxToMovie鍐呭琚伔浜?銆備負(fù)浜嗛伩鍏嶅畠,浣犲彲浠ラ夋嫨鎬у湴澶嶅埗鍥濩DxToMovie鍐呴儴鐨勬覆鏌撶洰鏍囩殑鍐呭鍒頒綘鐨勫簲鐢ㄧ▼搴忕殑back surface 浣跨敤鏂規(guī)硶IDirect3DDevice9:StretchRect(),鍏舵鏄父瑙佺殑g_pd3dDevice - > EndScene()鍜実_pd3dDevice - >Present()鐨勮姹備細(xì)鏇存柊鍐呭鐨勫憟鐜板湪灞忓箷涓婅儗緙撳啿鍖?浣垮睆騫曚笂鏇存柊銆?br />濡傛灉浣犳兂閬垮厤涓浜涘撫琚夋嫨鎬ц褰曞湪榪欓儴鐢?shù)濯?鍙槸涓嶈鍙玤_MovieRecorder.StartRecordingMovie鍜実_MovieRecorder.PauseRecordingMovie()(鐩稿簲鐨?g_pd3dDevice - > StretchRect())瀵歸偅浜涘撫,騫朵細(xì)鐩存帴娓叉煋鍔ㄧ敾鍦ㄥ睆騫曚笂(娌℃湁琚噸瀹氬悜鍒癈DxToMovie鍐呴儴鐨勬覆鏌撶洰鏍?銆?br />婕旂ず浠g爜鎻愪緵榪欎釜欏圭洰鎻愪緵浜嗕竴涓畝鍗曠殑搴旂敤紼嬪簭,浣垮緱DirectX灞忓箷涓婄殑涓涓笁瑙掑艦鐨勫姩浣?榧犳爣縐誨姩紿楁埛涓?榪欏皢simulatenously琚覆鏌撴垚鐢?shù)濯勬枃錃g鍜岃褰?鍚嶅彨output.avi)銆傝窇婕旂ず鐨勫彲鎵ц紼嬪簭,紜繚浣犳湁MPG4緙栬В鐮佸櫒鐨勮綆楁満涓婂畨瑁?鐩綍鏈夊啓鏉冮檺鍘誨垱寤鴻緭鍑虹數(shù)褰辨枃浠躲傝鎯呰璁劇疆瑙g爜鍣ㄥ拰騫寵 ,璇峰弬鑰冭繖綃囨枃绔?a >Create Movie from HBitmapDescribes the presentation parameters.
typedef struct D3DPRESENT_PARAMETERS { UINT BackBufferWidth, BackBufferHeight; D3DFORMAT BackBufferFormat; UINT BackBufferCount; D3DMULTISAMPLE_TYPE MultiSampleType; DWORD MultiSampleQuality; D3DSWAPEFFECT SwapEffect; HWND hDeviceWindow; BOOL Windowed; BOOL EnableAutoDepthStencil; D3DFORMAT AutoDepthStencilFormat; DWORD Flags; UINT FullScreen_RefreshRateInHz; UINT PresentationInterval; } D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;
In fact, D3DFMT_UNKNOWN can be specified for the BackBufferFormat while in windowed mode. This tells the runtime to use the current display-mode format and eliminates the need to call IDirect3DDevice9::GetDisplayMode.
For windowed applications, the back buffer format no longer needs to match the display-mode format because color conversion can now be done by the hardware (if the hardware supports color conversion). The set of possible back buffer formats is constrained, but the runtime will allow any valid back buffer format to be presented to any desktop format. (There is the additional requirement that the device be operable in the desktop mode; devices typically do not operate in 8 bits per pixel modes.)
Full-screen applications cannot do color conversion.
The method fails if one back buffer cannot be created. The value of BackBufferCount influences what set of swap effects are allowed. Specifically, any D3DSWAPEFFECT_COPY swap effect requires that there be exactly one back buffer.
D3DSWAPEFFECT_COPY requires that BackBufferCount be set to 1.
D3DSWAPEFFECT_DISCARD will be enforced in the debug runtime by filling any buffer with noise after it is presented.
Differences between Direct3D9 and Direct3D9Ex In Direct3D9Ex, D3DSWAPEFFECT_FLIPEX is added to designate when an application is adopting flip mode. That is, whan an application's frame is passed in window's mode (instead of copied) to the Desktop Window Manager(DWM) for composition. Flip mode provides more efficient memory bandwidth and enables an application to take advantage of full-screen-present statistics. It does not change full screen behavior. Flip mode behavior is available beginning with Windows 7. |
For a full-screen application, this is a handle to the top window (which is the focus window).
For applications that use multiple full-screen devices (such as a multimonitor system), exactly one device can use the focus window as the device window. All other devices must have unique device windows.
Note that no attempt is made by the runtime to reflect user changes in window size. The back buffer is not implicitly reset when this window is reset. However, the IDirect3DDevice9::Present method does automatically track window position changes.
If EnableAutoDepthStencil is TRUE, then AutoDepthStencilFormat must be a valid depth-stencil format.
Header: Declared in D3D9Types.h.
鍑犱釜閲嶈鐨勫弬鏁板姞浠ヨВ閲婅鏄庝竴涓嬶紝鍏朵腑BackBufferWidth鍜孊ackBufferHeight鎸囧畾鍚庡彴緙撳瓨鍖虹殑瀹介珮錛堜互鍍忕礌涓哄崟浣嶏級銆傚鏋滃浘褰互紿楀彛鏂瑰紡鏄劇ず騫朵笖璇ユ垚鍛樺彉閲忚璁劇疆涓?錛屽垯緋葷粺鑷姩浣跨敤鏄劇ず紿楀彛瀹㈡埛鍖虹殑瀹介珮浣滀負(fù)鍚庡彴緙撳啿鍖虹殑瀹介珮銆侭ackBufferCount鎸囧畾鍚庡彴緙撳啿鍖虹殑鏁伴噺銆傝鍊煎彲浠ヤ負(fù)0銆?銆?銆?錛屽叾涓?鍜?鏃墮兘琛ㄧず鍒涘緩涓涓悗鍙扮紦鍐插尯銆傞氬父浣跨敤涓涓悗鍙扮紦鍐插尯鍜屼竴涓富緙撳瓨錛屼富緙撳瓨灝嗗叾鏄劇ず鍦ㄥ睆騫曚笂銆?br />
BOOL CD3DCameraViewWnd::GetImageInfo(DWORD* pPixelBuffer, int& width,int& height) { BOOL result = FALSE; IDirect3DSurface9 *_surfaceback = NULL; if (FAILED(m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_surfaceback))) { result = FALSE; } D3DSURFACE_DESC surfaceDesc; if (!FAILED(_surfaceback->GetDesc(&surfaceDesc))) { width = surfaceDesc.Width; height = surfaceDesc.Height; } D3DLOCKED_RECT lockedRect; HRESULT hr = _surfaceback->LockRect( &lockedRect,0, 0); /* pointer to receive locked data鎸囧悜鐢寵鍒扮殑鍐呭瓨鍖哄煙*/ /* lock entire surface*/// no lock flags specified if (!FAILED(hr)) { pPixelBuffer = (DWORD*)lockedRect.pBits; result = TRUE; } _surfaceback->UnlockRect(); _surfaceback->Release(); return result; }
鐜板湪鍏抽敭鐨勯棶棰樺氨鍦ㄤ簬,璧勬簮閿佸畾鐨勬搷浣滈熷害鎬繪槸闈炲父涔嬫參.褰撶劧,浣犱細(xì)璺熸垜鎻? OpenGL浼間箮鑳藉蹇嵎鍦板畬鎴愯繖欏逛換鍔?浣嗘槸,鍦―irect3D涓?璧勬簮閿佸畾鎿嶄綔紜疄鏄緢鎱㈢殑.榪欓噷闈竴涓富瑕佺殑鍘熷洜鏄?API,椹卞姩,浠ュ強(qiáng)紜歡瑕佸鐞嗕竴浜涗笉鍙洖閬跨殑鍚庡彴鎿嶄綔.閭e氨鏄疓PU涓嶤PU鏄茍琛岃繍琛岀殑,鑻ヤ笉鍔犱換浣曟帾鏂?灝嗗紩璧風(fēng)被浼煎綰跨▼紼嬪簭鍚屾鏃剁殑绔炴佹潯浠剁殑闂.
濡傛灉浣犺瘯鍥懼幓淇敼鐨勮祫婧愭鍚屾椂琚竴涓綅浜嶨PU澶勭悊搴忓垪涓殑鎸囦護(hù)浣跨敤,閭d箞鏁翠釜娓叉煋嫻佺▼灝變細(xì)鍥犱負(fù)浣犵殑璧勬簮閿佸畾鑰屽仠欏挎垨寮哄埗鍒鋒柊(stalls and flushes).鍋滈】(stall)浼?xì)涓鐩存寔緇埌浣犲畬鎴愪簡瀵硅祫婧愮殑淇敼騫惰皟鐢║nlock().鑰屽己鍒跺埛鏂?flush)鍒欎細(xì)瑕佹眰GPU鍦ㄤ綘寰楀埌榪欎釜璧勬簮鐨勮闂潈涔嬪墠瀹屾垚鐩墠鎵鏈夌殑浠誨姟.
濡備綍鍘昏В鍐寵繖涓棶棰橈紵涓嬮潰鐨勫弬鑰冭祫鏂欎腑鏈変竴浜涜В鍐蟲柟妗堬紝鎴戞病鏈夌粡榪囪鐪熸祴璇曪紝鎴戣瘯浜嗗叾涓竴涓狦etRenderTargetData 榪欐牱鐨勪竴縐嶆柟娉?錛屾劅瑙変笉澶ソ鐢紝why璇風(fēng)湅Reference3
涓嬮潰緇欏嚭鎴戠殑瑙e喅鏂規(guī)
BOOL CD3DCameraViewWnd::GetImageInfo(DWORD* pPixelBuffer, int& width,int& height) { BOOL result = FALSE; IDirect3DSurface9 *_surfaceback = NULL; if (FAILED(m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_surfaceback))) { result = FALSE; } D3DSURFACE_DESC surfaceDesc; if (!FAILED(_surfaceback->GetDesc(&surfaceDesc))) { width = surfaceDesc.Width; height = surfaceDesc.Height; }
LPDIREC3DSURFACE9 surf;
if(FAILED(m_pDevice->CreateOffscreenPlainSurface(width, height,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM, &surf,NULL)))
{
result = FALSE;
}
D3DXLoadSurfaceFromSurface(surf, NULL,NULL,_surfaceback,NULL,NULL,D3DX_FILTER_NONE,0);
D3DLOCKED_RECT lockedRect;
HRESULT hr = surf->LockRect( &lockedRect,0, 0); /* pointer to receive locked data鎸囧悜鐢寵鍒扮殑鍐呭瓨鍖哄煙*/ /* lock entire surface*/// no lock flags specified
if (!FAILED(hr))
{
pPixelBuffer = (DWORD*)lockedRect.pBits;
result = TRUE;
}
surf->UnlockRect();
surf->Release();
_surfaceback->Release();
return result;
}
鍙傝冭祫鏂欙細(xì)Reference1.http://www.cnblogs.com/mixiyou/archive/2010/02/25/1673060.html
Reference 2.http://www.cnblogs.com/mixiyou/archive/2010/02/25/1673425.html
Reference 3.http://blog.csdn.net/Nightmare/article/details/1707362
Reference 4.http://www.cnblogs.com/lancidie/archive/2011/3/14.html