Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CodeHog

Analyzing the BackBuffer

This topic is 5183 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I want to render a Red primitive on a white background and manually check whether each Pixel Blended Properly. Since we cant get the BackBuffer data, - I called CreateRenderTarget - then setting my Render Target using SetRenderTarget, - I drew the primitive on the RenderTarget. 1. I already have the render Target. Do I need a GetRendetTargetData? 2. How can I calculate the value of an alpha blended Pixel for the different BackBuffer Formats ? 3. I had to stretch Rect the RenderTarget on the BackBuffer and call Present. Is there a way to present the RenderTarget, ignoring the Backbuffer altogether? Thanks. Code: HRESULT MyClass::DrawAndCheck() { hr = m_lpD3DDevice->BeginScene(); hr = m_lpD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 0.0 ),1.0f,1); hr = RenderPrimitive(m_RenderTarget); hr = m_lpD3DDevice->StretchRect(m_RenderTarget, NULL, m_lpDDSBackBuffer, NULL, D3DTEXF_NONE); hr = m_lpD3DDevice->EndScene(); hr = m_lpD3DDevice->Present( NULL, NULL, NULL, NULL); AnalyzeSurface(m_RenderTarget); return hr; } HRESULT MyClass::RenderPrimitive(void) { hr = m_lpD3DDevice->ColorFill(m_lpD3DRenderTarget, NULL, 0xffffffff); // Color it white. hr = m_lpD3DDevice->SetRenderTarget(0, m_lpD3DRenderTarget); // DrawPrimitive on RenderTarget. hr = RenderPrimitive(m_lpDDSBackBuffer, &DstRect, m_lpD3DSTexture, &SrcRect, m_Alpha); hr = m_lpD3DDevice->SetRenderTarget(0, m_lpDDSBackBuffer); return hr; } HRESULT MyClass::AnalyzeSurface( int *pDiff, RECT * rBox, LPDIRECT3DSURFACE9 pDDS, LPRECT prSrc ) { // Get RenderTarget Format hr = pDDS->GetDesc(&d3dsd); // BackBuffer __try { D3DLOCKED_RECT LockedRect; hr = pDDS->LockRect(&LockedRect, NULL , 0 ); DWORD BytesPerPixel = 0; // Parameter used by compare Rectangle. switch( d3dsd.Format) { case D3DFMT_R5G6B5:// 565 BytesPerPixel = 2; // 16 bit format // AnalyzePixels (ARGB565 *) LockedRect.pBits, break; case D3DFMT_A1R5G5B5: // 555 BytesPerPixel = 2; // 16 bit format // AnalyzePixels (ARGB1555 *) LockedRect.pBits, break; case D3DFMT_A8R8G8B8: case D3DFMT_X8R8G8B8: BytesPerPixel = 4; // 32 bit format // AnalyzePixels (ARG8888 *) LockedRect.pBits, break; default: // Unsupported BackBuffer Format break; } } __finally { pDDS->UnlockRect(); } return hr; } Heres My device Creation. HRESULT MyClass::CreateDevice() { if( NULL == ( m_lpD3D = Direct3DCreate9(D3D_SDK_VERSION) ) ) { Err Handling } D3DDISPLAYMODE d3ddm; if( FAILED( m_lpD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ) { Err Handling } ZeroMemory( &m_d3dpp, sizeof(m_d3dpp) ); m_d3dpp.BackBufferFormat = d3ddm.Format; m_d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; // leave Back buffer intact after PRESENT. m_d3dpp.Windowed = TRUE ; m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // For creating application lockable Surfaces m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; if( FAILED((hr = m_lpD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_d3dpp, &m_lpD3DDevice ) ) ) ) { Err Handling ; } }

Share this post


Link to post
Share on other sites
Advertisement
quote:
Since we cant get the BackBuffer data,
- I called CreateRenderTarget
- then setting my Render Target using SetRenderTarget,
- I drew the primitive on the RenderTarget.

You can get the back-buffer data. Create your device with D3DPRESENT_LOCKABLE_BACKBUFFER flag set in D3DPRESENT_PARAMETER.Flags (The names might not be 100% correct), and then you can retrieve the back-buffer surface, and lock it.

quote:
1. I already have the render Target. Do I need a GetRendetTargetData?

Well, if you want access to its bits, you need it.

quote:
2. How can I calculate the value of an alpha blended Pixel for the different BackBuffer Formats ?

I don''t understand what you mean.

quote:
3. I had to stretch Rect the RenderTarget on the BackBuffer and
call Present. Is there a way to present the RenderTarget, ignoring the Backbuffer altogether?

You can render a screen-aligned quad textured with the RenderTarget.

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -

Share this post


Link to post
Share on other sites
Hi, Thanks a ton!

What I meant by the blended alpha value for individual Pixels was:

The back Buffer can have these formats:
A2R10G10B10
A8R8G8B8
X8R8G8B8
A1R5G5B5
X1R5G5B5
R5G6B5

So in A8R8G8B8 format
a 50% Transparent Red pixel is 0x80ff0000
When this is blended with a white Pixel 0xffffffff
What Value should the Blended Pixel have ?

Assuming:
m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

I want to do the same for other formats such as R5G6B5 or
X1R5G5B5. Is there a reference I can study for the Pixel formats.

Thanks again and thanks in advance.

Share this post


Link to post
Share on other sites
quote:
When this is blended with a white Pixel 0xffffffff
What Value should the Blended Pixel have ?

For each color channel:
Final = Src * SrcAlpha + Dest * ( 1 - SrcAlpha )

Where,
Final: The color that's going to be written to the render-target (By default: The back-buffer)
Src: The source channel, from 0x7fff0000
SrcAlpha: 0x7f == 127
Dest: The dest channel, that's the channel of the pixel already in the back-buffer (that's going to be overwritten by Final)

Out of curiosity, why do you need this? Are you writing some sort of driver/hardware testing/benchmarking suite or some 3DMark-Beater?
You might want to consider comparing HAL results against REF results if you're doing something like this.

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -

[edit]Correction

[edited by - Coder on April 12, 2004 1:28:06 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!