//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- HRESULT CDXGraphicsContext::ResizeD3DEnvironment() { HRESULT hr; // Release all vidmem objects if( FAILED( hr = CleanDeviceObjects() ) ) return hr; // Reset the device if( IsResultGood( hr = m_pd3dDevice->Reset( &m_d3dpp ), true ) ) { while ( hr == D3DERR_DEVICELOST ) { Pause(true); hr = m_pd3dDevice->Reset( &m_d3dpp ); } } else { return hr; } // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer; m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Initialize the app's device-dependent objects if ( CRender::IsAvailable() ) { CRender::GetRender()->InitDeviceObjects(); } return S_OK; }
__forceinline bool CDecDXVA2::CopyFrame(LAVFrame *pFrame) { HRESULT hr; LPDIRECT3DSURFACE9 pSurface = (LPDIRECT3DSURFACE9)pFrame->data[3]; pFrame->format = LAVPixFmt_NV12; D3DSURFACE_DESC surfaceDesc; pSurface->GetDesc(&surfaceDesc); D3DLOCKED_RECT LockedRect; hr = pSurface->LockRect(&LockedRect, NULL, D3DLOCK_READONLY); if (FAILED(hr)) { DbgLog((LOG_TRACE, 10, L"pSurface->LockRect failed (hr: %X)", hr)); return false; } // Free AVFrame based buffers again FreeLAVFrameBuffers(pFrame); // Allocate memory buffers AllocLAVFrameBuffers(pFrame, LockedRect.Pitch); // Copy surface onto memory buffers CopyFrameNV12((BYTE *)LockedRect.pBits, pFrame->data[0], pFrame->data[1], surfaceDesc.Height, pFrame->height, LockedRect.Pitch); pSurface->UnlockRect(); return true; }
ErrorCode Surface::createFromPointer(LPDIRECT3DSURFACE9 surf) { if (this->surf != 0) { this->surf->Release(); this->surf = 0; } if (surf == 0) return ErrorHandle(mamain->err, ErrorInv); D3DSURFACE_DESC desc; HRESULT res = surf->GetDesc(&desc); if (FAILED(res)) return ErrorHandle(mamain->err, ErrorD3D9, res, "GetDesc"); surfUsage = desc.Usage; surfPool = desc.Pool; surfWidth = desc.Width; surfHeight = desc.Height; this->surf = surf; surf->AddRef(); return ErrorOk; }
HRESULT XD3DView::CreateView( HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice, D3DFORMAT backBufferFormat ) { SafeRelease( &m_pd3dChain ); // CMainFrame *pMainFrm = g_pMainFrm; m_hWnd = hWnd; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; // Use the current display mode. // d3dpp.BackBufferFormat = g_pMainFrm->m_d3dpp.BackBufferFormat; d3dpp.BackBufferFormat = backBufferFormat; // m_hWnd contains child window handle d3dpp.hDeviceWindow=m_hWnd; // m_pSwapChain is IDirect3DSwapChain * HRESULT hr = pd3dDevice->CreateAdditionalSwapChain( &d3dpp, &m_pd3dChain ); // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; // XBREAK( m_pd3dChain == NULL ); if( m_pd3dChain ) { m_pd3dChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); } return S_OK; }
//************************************************************ // Function: DrawSurface // Vars: dest - The destination surface to draw to // x - The location in the destination to draw to // y // source - The source image to draw from // Process: This draws from a source surface area to a specific // locatio in the destination // Returns: None //************************************************************ void DirectX::DrawSurface( LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source ) { D3DSURFACE_DESC desc; //Describes surface information source->GetDesc ( &desc); //get width/height data from source RECT source_rect = { //Source rect to use in drawing 0, // x position 0, // y position desc.Width, // image width desc.Height // image height }; RECT dest_rect = { //Dest rect to use in drawing x, // x position to draw to y, // y position to draw to x+desc.Width, // image width y+desc.Height // image height }; d3ddev->StretchRect ( //Draw from source using source rect // Size to dest using dest rect size source, // source texture &source_rect, // source size dest, // dest texture &dest_rect, // dest size D3DTEXF_NONE // No Texture filter ); }
// Figure out if we can render some puff or not (note that this is state dependent), // I'm assuming it called with the render states set as they will be during rendering... void CD3D_Device::PreCalcSomeDeviceCaps() { if (!m_pD3DDevice) return; // Figure out if we can do specular highlights on models. // ModelSpecularStateBackup stateBackup; // SetModelSpecularStates(&stateBackup); unsigned long nPasses = 0; // m_ExtraDevCaps.m_bModelSpecularCapable = (m_pD3DDevice->ValidateDevice((unsigned long*)&nPasses) == D3D_OK); // UnsetModelSpecularStates(&stateBackup); // SetDetailTextureStates(); // m_ExtraDevCaps.m_bDetailTextureCapable = (m_pD3DDevice->ValidateDevice((unsigned long*)&nPasses) == D3D_OK); // if (m_DeviceCaps.MaxSimultaneousTextures < 2) { m_ExtraDevCaps.m_bDetailTextureCapable = false; } // UnsetDetailTextureStates(); // Check for stencil buffer & get the format... LPDIRECT3DSURFACE9 pDepthStencilBuffer = NULL; m_pD3DDevice->GetDepthStencilSurface(&pDepthStencilBuffer); if (pDepthStencilBuffer) { D3DSURFACE_DESC SurfDesc; pDepthStencilBuffer->GetDesc(&SurfDesc); m_ExtraDevCaps.m_DepthStencilBufferFormat = SurfDesc.Format; uint32 iZDepth,iStencilDepth; d3d_GetDepthStencilBits(m_ExtraDevCaps.m_DepthStencilBufferFormat,iZDepth,iStencilDepth); m_ExtraDevCaps.m_bHasZBuffer = (iZDepth>0 ? true : false); m_ExtraDevCaps.m_bHasStencilBuffer = (iStencilDepth>0 ? true : false); int iRefCnt = pDepthStencilBuffer->Release(); } }
void Render::Draw(IDirect3DSurface9* renderTarget, D3DXMATRIX* view, D3DXMATRIX* projection) { // Get or create device LPDIRECT3DDEVICE9 device = GetDevice(); if (device == NULL) return; // Load shaders if it is required // if (!EnsureShaders()) return; // Prepare depth surface D3DSURFACE_DESC renderTargetDescription; renderTarget->GetDesc(&renderTargetDescription); D3DSURFACE_DESC depthSurfaceDescription; if (depthSurface != NULL) depthSurface->GetDesc(&depthSurfaceDescription); if (depthSurface == NULL || depthSurfaceDescription.Width != renderTargetDescription.Width || depthSurfaceDescription.Height != renderTargetDescription.Height) { if (depthSurface != NULL) depthSurface->Release(); device->CreateDepthStencilSurface(renderTargetDescription.Width, renderTargetDescription.Height, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, FALSE, &depthSurface, NULL); if (depthSurface == NULL) return; } device->SetRenderTarget(0, renderTarget); device->SetDepthStencilSurface(depthSurface); device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0); if (lowPolySphere == NULL) { // Create spheres lowPolySphere = CreateSphere(2); middlePolySphere = CreateSphere(3); highPolySphere = CreateSphere(5); // Create cylinders lowPolyCylinder = CreateCylinder(3); middlePolyCylinder = CreateCylinder(12); highPolyCylinder = CreateCylinder(24); } // FIXME: light dir must be slightly different! D3DVECTOR lightDirection; lightDirection.x = view->_13; lightDirection.y = view->_23; lightDirection.z = view->_33; D3DVECTOR viewDirection; viewDirection.x = view->_13; viewDirection.y = view->_23; viewDirection.z = view->_33; elementMaterials[0].SetViewLightDirection(&viewDirection, &lightDirection); // Rendering device->BeginScene(); DrawAtoms(view, projection); DrawBonds(view, projection); DrawResidues(view, projection); device->EndScene(); }
// I'm assuming it called with the render states set as they will be during rendering... void CD3D_Device::PreCalcSomeDeviceCaps() { if (!m_pD3DDevice) return; // Fix some issues on ATI cards if( m_pAdapter->AdapterID.VendorId == 0x1002 ) { g_pStruct->RunConsoleString( "Use0WeightsForDisable 1" ); } // Check for TableFog... if ((m_DeviceCaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) && ((m_DeviceCaps.RasterCaps & D3DPRASTERCAPS_ZFOG) || (m_DeviceCaps.RasterCaps & D3DPRASTERCAPS_WFOG)) && g_CV_TableFog.m_Val) { m_ExtraDevCaps.m_bUsingTableFog = true; } else { m_ExtraDevCaps.m_bUsingTableFog = false; } // Check for stencil buffer & get the format... LPDIRECT3DSURFACE9 pDepthStencilBuffer = NULL; D3D_CALL(m_pD3DDevice->GetDepthStencilSurface(&pDepthStencilBuffer)); if (pDepthStencilBuffer) { D3DSURFACE_DESC SurfDesc; // SurfDesc.Size = sizeof(SurfDesc); D3D_CALL(pDepthStencilBuffer->GetDesc(&SurfDesc)); m_ExtraDevCaps.m_DepthStencilBufferFormat = SurfDesc.Format; uint32 iZDepth,iStencilDepth; d3d_GetDepthStencilBits(m_ExtraDevCaps.m_DepthStencilBufferFormat,iZDepth,iStencilDepth); m_ExtraDevCaps.m_bHasStencilBuffer = (iStencilDepth>0 ? true : false); int iRefCnt = pDepthStencilBuffer->Release(); } }
void teTexture::UpdateSize() { LPDIRECT3DSURFACE9 surface; texture->GetSurfaceLevel(0, &surface); D3DSURFACE_DESC desc; surface->GetDesc(&desc); size.x = desc.Width; size.y = desc.Height; surface->Release(); }
/*This function will draw a SURFACE object. It takes the source(the object we want to draw) grabs the dimensions, creates a RECT for the source, RECT for the destination(this is where our source RECT will be drawn) then uses StretchRect to put our source into destination*/ void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source) { //get width and height of the source rectangle D3DSURFACE_DESC desc; source->GetDesc(&desc); //create rects for both RECT sourceRect = { 0,0,(long)desc.Width,(long)desc.Height }; RECT destRect = { (long)x,(long)y,(long)x + desc.Width,(long)y + desc.Height }; //draw the surface onto the destination d3ddev->StretchRect(source, &sourceRect, dest, &destRect, D3DTEXF_NONE); }
HRESULT VertexObject::CreateTextureFromSurface(LPDIRECT3DSURFACE9 pSurface, RECT* pSrcRect, RECT* pDestRect, LPDIRECT3DTEXTURE9* ppTexture) { int width, height; RECT Src; D3DSURFACE_DESC surfDesc; pSurface->GetDesc(&surfDesc); if( !pSrcRect ) { width = surfDesc.Width; height = surfDesc.Height; Src.left = Src.top = 0; Src.right = width; Src.bottom = height; } else { width = pSrcRect->right - pSrcRect->left; // + 1; height = pSrcRect->bottom - pSrcRect->top; // + 1; Src = *pSrcRect; } D3DXCreateTexture(DDevice, width, height, 1, 0, surfDesc.Format, D3DPOOL_DEFAULT, ppTexture) ; // Retrieve the surface image of the texture. LPDIRECT3DSURFACE9 pTexSurface; LPDIRECT3DTEXTURE9 pTexture = *ppTexture; pTexture->GetLevelDesc(0, &surfDesc); pTexture->GetSurfaceLevel(0, &pTexSurface); // Create a clean surface to clear the texture with. LPDIRECT3DSURFACE9 pCleanSurface; D3DLOCKED_RECT lockRect; DDevice->CreateOffscreenPlainSurface( surfDesc.Width, surfDesc.Height, surfDesc.Format, D3DPOOL_DEFAULT, &pCleanSurface, NULL); pCleanSurface->LockRect(&lockRect, NULL, 0) ; memset((BYTE*)lockRect.pBits, 0, surfDesc.Height * lockRect.Pitch); pCleanSurface->UnlockRect() ; DDevice->UpdateSurface(pCleanSurface, NULL, pTexSurface, NULL); pCleanSurface->Release(); // Copy the image to the texture. POINT destPoint = { 0, 0 }; DDevice->UpdateSurface(pSurface, &Src, pTexSurface, &destPoint); pTexSurface->Release(); return S_OK; }
D3DSURFACE_DESC RenderWin32DX9Imp::getRenderTargetDesc() { LPDIRECT3DSURFACE9 currentRenderTarget = NULL; const HRESULT hr = getD3D9Device()->GetRenderTarget( 0, & currentRenderTarget ); if( FAILED( hr ) ) { DXUT_ERR( L"RenderWin32DX9Imp::getHeight", hr ); throw exception(); } D3DSURFACE_DESC desc; currentRenderTarget->GetDesc( & desc ); SAFE_RELEASE( currentRenderTarget ); return desc; }
void DrawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source) { //get width/height from source surface D3DSURFACE_DESC desc; source->GetDesc(&desc); //create rects for drawing RECT source_rect = {0, 0, (long)desc.Width, (long)desc.Height }; RECT dest_rect = { (long)x, (long)y, (long)x+desc.Width, (long)y+desc.Height}; //draw the source surface onto the dest d3ddev->StretchRect(source, &source_rect, dest, &dest_rect, D3DTEXF_NONE); }
bool restore_objects() { if ( retry_count ) { if ( --retry_count ) return false; release_objects(); if ( lpdev->Reset( &dpp ) != D3D_OK ) return false; } retry_count = 0; LPDIRECT3DSURFACE9 lpbb; HRESULT hr; if( SUCCEEDED( hr = lpdev->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, & lpbb ) ) ) { lpbb->GetDesc( & d3dsd ); lpbb->Release(); } lpdev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); lpdev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); lpdev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); lpdev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); lpdev->SetRenderState(D3DRS_LIGHTING, false); lpdev->SetRenderState(D3DRS_ZENABLE, false); lpdev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); lpdev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); lpdev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); lpdev->SetRenderState(D3DRS_ALPHABLENDENABLE, false); lpdev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); if ( lpdev->CreateVertexBuffer( sizeof(d3dvertex) * 4, flags.v_usage, D3DFVF_XYZRHW | D3DFVF_TEX1, (D3DPOOL)flags.v_pool, &lpvbuf, NULL ) != D3D_OK ) return false; update_filtering( 1 ); lpdev->SetRenderState( D3DRS_DITHERENABLE, TRUE ); if ( lpdev->CreateTexture( surface_width, surface_height, 1, flags.t_usage, D3DFMT_X8R8G8B8, (D3DPOOL)flags.t_pool, &lptex, NULL ) != D3D_OK ) return false; return true; }
/** Draw a surface to the screen given the source and destination surfaces; uses StretchRect x, y are the points you want to draw at (top-left of rectangle) Note that this uses the size of the source surface to determine how big you want to draw */ void DirectXStuff::drawSurface(LPDIRECT3DSURFACE9 dest, float x, float y, LPDIRECT3DSURFACE9 source) { //get width and height of source surface //useful so you only need to define source surface width / height when creating it rather than keeping track D3DSURFACE_DESC desc; source->GetDesc(&desc); //rectangles for drawing; note destination rectangle is equal size to source rectangle //apparently you can define them like enum; are they structs? RECT source_rect = {0, 0, (long)desc.Width, (long)desc.Height}; RECT dest_rect = {(long)x, (long)y, (long)x + desc.Width, (long)y + desc.Height}; //draw the source surface on to the destination d3ddev->StretchRect(source, &source_rect, dest, &dest_rect, D3DTEXF_NONE); }//end drawSurface
void D3DOverdrawWindow:: SetupViewport(void) { LPDIRECT3DSURFACE9 back; d3d->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back); D3DSURFACE_DESC desc; back->GetDesc(&desc); back->Release(); D3DVIEWPORT9 full; full.X = full.Y = 0; full.Width = desc.Width; full.Height = desc.Height; full.MinZ = 0; full.MaxZ = 1; d3d->SetViewport(&full); }
void SRRasterization::CopyToScreen() { g_pd3dDevice->BeginScene(); LPDIRECT3DSURFACE9 backBuffer; HRESULT ret = g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); D3DSURFACE_DESC surfacedesc; HRESULT ret2 = backBuffer->GetDesc(&surfacedesc); const TCHAR * message1 = DXGetErrorString(ret2); const TCHAR * message2 = DXGetErrorDescription(ret2); m_colorBuffer->CopyBufferToSurface(backBuffer); g_pd3dDevice->EndScene(); // Present the backbuffer contents to the display g_pd3dDevice->Present(NULL, NULL, NULL, NULL); }
bool EC_WidgetCanvas::Blit(const QImage &source, Ogre::TexturePtr destination) { #if defined(DIRECTX_ENABLED) && defined(WIN32) Ogre::HardwarePixelBufferSharedPtr pb = destination->getBuffer(); Ogre::D3D9HardwarePixelBuffer *pixelBuffer = dynamic_cast<Ogre::D3D9HardwarePixelBuffer*>(pb.get()); if (!pixelBuffer) return false; LPDIRECT3DSURFACE9 surface = pixelBuffer->getSurface(Ogre::D3D9RenderSystem::getActiveD3D9Device()); if (surface) { D3DSURFACE_DESC desc; HRESULT hr = surface->GetDesc(&desc); if (SUCCEEDED(hr)) { D3DLOCKED_RECT lock; HRESULT hr = surface->LockRect(&lock, 0, 0); if (SUCCEEDED(hr)) { const int bytesPerPixel = 4; ///\todo Count from Ogre::PixelFormat! const int sourceStride = bytesPerPixel * source.width(); if (lock.Pitch == sourceStride) memcpy(lock.pBits, source.bits(), sourceStride * source.height()); else for(int y = 0; y < source.height(); ++y) memcpy((u8*)lock.pBits + lock.Pitch * y, source.bits() + sourceStride * y, sourceStride); surface->UnlockRect(); } } } #else if (!destination->getBuffer().isNull()) { Ogre::Box update_box(0, 0, source.width(), source.height()); Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)source.bits()); destination->getBuffer()->blitFromMemory(pixel_box, update_box); } #endif return true; }
void DirectXEngine::InitDeviceObjects(LPDIRECT3D9 pd3d, LPDIRECT3DDEVICE9 pd3dDevice, IDirect3DSwapChain9* pd3dSwapChain) { m_pD3D = pd3d; m_pd3dDevice = pd3dDevice; m_pd3dSwapChain = pd3dSwapChain; // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; if(m_pd3dSwapChain) { m_pd3dSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); } else if(m_pd3dDevice) { m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); } pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Store device Caps m_pd3dDevice->GetDeviceCaps( &m_d3dCaps ); }
void Texture::SetAsHardwareCursor(const Vector2 & hotSpot) { if (id) { LPDIRECT3DSURFACE9 textureMainSurface; HRESULT hr = id->GetSurfaceLevel(0, &textureMainSurface); RENDER_VERIFY(hr); // Check surface format // D3DSURFACE_DESC desc; ZeroMemory(&desc, sizeof(desc)); RENDER_VERIFY(textureMainSurface->GetDesc(&desc)); LPDIRECT3DDEVICE9 device = RenderManager::Instance()->GetD3DDevice(); hr = device->SetCursorProperties((UINT)hotSpot.x, (UINT)hotSpot.y, textureMainSurface); RENDER_VERIFY(hr); D3DSafeRelease(textureMainSurface); } }
//-------------------------------------------------------------------------------------- // RenderToTexture( ) // // DESC: // A simple utility function that draws, as a TL Quad, one texture to another // such that a pixel shader (configured before this function is called) can // operate on the texture. Used by MeasureLuminance() to perform the // downsampling and filtering. // // PARAMS: // pDevice : The currently active device // // NOTES: // n/a // //-------------------------------------------------------------------------------------- HRESULT RenderToTexture( IDirect3DDevice9* pDev ) { D3DSURFACE_DESC desc; LPDIRECT3DSURFACE9 pSurfRT; pDev->GetRenderTarget( 0, &pSurfRT ); pSurfRT->GetDesc( &desc ); pSurfRT->Release(); // To correctly map from texels->pixels we offset the coordinates // by -0.5f: float fWidth = static_cast< float >( desc.Width ) - 0.5f; float fHeight = static_cast< float >( desc.Height ) - 0.5f; // Now we can actually assemble the screen-space geometry PostProcess::TLVertex v[4]; v[0].p = D3DXVECTOR4( -0.5f, -0.5f, 0.0f, 1.0f ); v[0].t = D3DXVECTOR2( 0.0f, 0.0f ); v[1].p = D3DXVECTOR4( fWidth, -0.5f, 0.0f, 1.0f ); v[1].t = D3DXVECTOR2( 1.0f, 0.0f ); v[2].p = D3DXVECTOR4( -0.5f, fHeight, 0.0f, 1.0f ); v[2].t = D3DXVECTOR2( 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fWidth, fHeight, 0.0f, 1.0f ); v[3].t = D3DXVECTOR2( 1.0f, 1.0f ); // Configure the device and render.. pDev->SetVertexShader( NULL ); pDev->SetFVF( PostProcess::FVF_TLVERTEX ); pDev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( PostProcess::TLVertex ) ); return S_OK; }
bool CWinRenderer::CreateIntermediateRenderTarget() { // Initialize a render target for intermediate rendering - same size as the video source LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice(); D3DFORMAT format = D3DFMT_X8R8G8B8; DWORD usage = D3DUSAGE_RENDERTARGET; if (g_Windowing.IsTextureFormatOk(D3DFMT_A2R10G10B10, usage)) format = D3DFMT_A2R10G10B10; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A2B10G10R10, usage)) format = D3DFMT_A2B10G10R10; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8R8G8B8, usage)) format = D3DFMT_A8R8G8B8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8B8G8R8, usage)) format = D3DFMT_A8B8G8R8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_X8R8G8B8, usage)) format = D3DFMT_X8R8G8B8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_X8B8G8R8, usage)) format = D3DFMT_X8B8G8R8; else if (g_Windowing.IsTextureFormatOk(D3DFMT_R8G8B8, usage)) format = D3DFMT_R8G8B8; CLog::Log(LOGDEBUG, __FUNCTION__": format %i", format); if(!m_IntermediateTarget.Create(m_sourceWidth, m_sourceHeight, 1, usage, format, D3DPOOL_DEFAULT)) { CLog::Log(LOGERROR, __FUNCTION__": render target creation failed. Going back to bilinear scaling.", format); return false; } //Pixel shaders need a matching depth-stencil surface. LPDIRECT3DSURFACE9 tmpSurface; D3DSURFACE_DESC tmpDesc; //Use the same depth stencil format as the backbuffer. pD3DDevice->GetDepthStencilSurface(&tmpSurface); tmpSurface->GetDesc(&tmpDesc); tmpSurface->Release(); if (!m_IntermediateStencilSurface.Create(m_sourceWidth, m_sourceHeight, 1, D3DUSAGE_DEPTHSTENCIL, tmpDesc.Format, D3DPOOL_DEFAULT)) { CLog::Log(LOGERROR, __FUNCTION__": Failed to create depth stencil. Going back to bilinear scaling."); m_IntermediateTarget.Release(); return false; } return true; }
//----------------------------------------------------------------------------- // Name: setFullscreenViewport // Desc: Initializes the rendering depth utilized for this layer. The layer will not // render beyond this Z range. Note that elements are positioned according to // a 'depth' value, which is not the same thing as the 'z' value. The depth value // ranges from 0.0f to 1.0f always (anything else is not rendered), and maps into // the range of Z values specified by this method when rendered. // This method fails silently if the layer has not been created successfully. //----------------------------------------------------------------------------- void GUILayer::setFullscreenViewport(float minZ, float maxZ) { // Store the Z-coordinates in the viewport myViewport.MinZ = minZ; myViewport.MaxZ = maxZ; // Fail here unless we have a device pointer if (!d3d_device_) return; // Get the device's size LPDIRECT3DSURFACE9 backBufferSurface; if (FAILED(d3d_device_->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBufferSurface))) return; // Get the back buffer description, and release the surface D3DSURFACE_DESC backBufferDesc; backBufferSurface->GetDesc(&backBufferDesc); backBufferSurface->Release(); // Initialize the rest of the viewport myViewport.X = 0; myViewport.Y = 0; myViewport.Width = backBufferDesc.Width; myViewport.Height = backBufferDesc.Height; // Make sure that the primary canvas mirrors this information myPrimaryCanvas.alignXLeft(0); myPrimaryCanvas.alignYTop(0); myPrimaryCanvas.absoluteWidth(backBufferDesc.Width); myPrimaryCanvas.absoluteHeight(backBufferDesc.Height); //myPrimaryCanvas.realign(); // Set up the projection matrix. This sets the bottom as the minimum Y-coordinate so that // the matrix will be created in the right Y-orientation (increasing Y coordinates from top to bottom) D3DXMatrixOrthoOffCenterLH(&myProjectionMatrix, 0.0f, (float)backBufferDesc.Width, (float)backBufferDesc.Height, 0.0f, 0.0f, 1.0f); }
static HRESULT GetBackBufferDesc(LPDIRECT3DDEVICE9 pd3dDevice, D3DSURFACE_DESC* pBackBufferSurfaceDesc) { HRESULT hr = E_FAIL; HRESULT hrResult = E_FAIL; LPDIRECT3DSURFACE9 pBackBuffer = NULL; KGLOG_PROCESS_ERROR(pd3dDevice); KGLOG_PROCESS_ERROR(pBackBufferSurfaceDesc); hr = pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); KGLOG_COM_PROCESS_ERROR(hr); memset(pBackBufferSurfaceDesc, 0, sizeof(D3DSURFACE_DESC)); hr = pBackBuffer->GetDesc(pBackBufferSurfaceDesc); KGLOG_COM_PROCESS_ERROR(hr); hrResult = S_OK; Exit0: SAFE_RELEASE(pBackBuffer); return hrResult; }
void D3DOverdrawWindow:: Clear(void) { D3DVIEWPORT9 old; d3d->GetViewport(&old); LPDIRECT3DSURFACE9 back; d3d->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back); D3DSURFACE_DESC desc; back->GetDesc(&desc); back->Release(); D3DVIEWPORT9 full; full.X = full.Y = 0; full.Width = desc.Width; full.Height = desc.Height; full.MinZ = 0; full.MaxZ = 1; d3d->SetViewport(&full); d3d->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, //d3d->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3d->SetViewport(&old); }
HRESULT CDxtexDoc::LoadVolumeSliceFromSurface(LPDIRECT3DVOLUME9 pVolume, UINT iSlice, LPDIRECT3DSURFACE9 psurf) { HRESULT hr; D3DSURFACE_DESC sd; D3DVOLUME_DESC vd; D3DLOCKED_RECT lr; D3DBOX boxSrc; D3DBOX boxDest; psurf->GetDesc(&sd); pVolume->GetDesc(&vd); boxSrc.Left = 0; boxSrc.Right = sd.Width; boxSrc.Top = 0; boxSrc.Bottom = sd.Height; boxSrc.Front = 0; boxSrc.Back = 1; boxDest.Left = 0; boxDest.Right = vd.Width; boxDest.Top = 0; boxDest.Bottom = vd.Height; boxDest.Front = iSlice; boxDest.Back = iSlice + 1; hr = psurf->LockRect(&lr, NULL, 0); if (FAILED(hr)) return hr; hr = D3DXLoadVolumeFromMemory(pVolume, NULL, &boxDest, lr.pBits, sd.Format, lr.Pitch, 0, NULL, &boxSrc, D3DX_DEFAULT, 0); psurf->UnlockRect(); return hr; }
void RenderController::CreateGBuffers() { LPDIRECT3DSURFACE9 pOldRT; D3DSURFACE_DESC desc; Renderer::theDevicePtr->GetRenderTarget(0, &pOldRT ); pOldRT->GetDesc(&desc); if(pOldRT) { pOldRT->Release(); pOldRT = 0; } m_GDepthRenderTarget.Create(desc.Width, desc.Height, D3DFMT_R32F); m_GDiffuseRenderTarget.Create(desc.Width, desc.Height, D3DFMT_A8R8G8B8); m_GNormalRenderTarget.Create(desc.Width, desc.Height);//, D3DFMT_G16R16); m_GSpecularRenderTarget.Create(desc.Width, desc.Height); m_SharedParameterContext.GetEffect()->SetTexture("diffuseGBuffer", m_GDiffuseRenderTarget.GetTexture()->GetHandle()); m_SharedParameterContext.GetEffect()->SetTexture("normalGBuffer", m_GNormalRenderTarget.GetTexture()->GetHandle()); m_SharedParameterContext.GetEffect()->SetTexture("depthGBuffer", m_GDepthRenderTarget.GetTexture()->GetHandle()); m_SharedParameterContext.GetEffect()->SetTexture("specularGBuffer", m_GSpecularRenderTarget.GetTexture()->GetHandle()); // Occlusion testing render target visibilityTestTarget.Create(desc.Width, desc.Height); }
//------------------------------------------------------------- // Name: InitDeviceObjects() // Desc: 디바이스가 생성된후의 초기화 // 프레임버퍼 포맷과 디바이스 종류가 변한뒤에 호출 // 여기서 확보한 메모리는 DeleteDeviceObjects()에서 해제 //------------------------------------------------------------- HRESULT CMyD3DApplication::InitDeviceObjects() { HRESULT hr; LPDIRECT3DSURFACE9 pSurf; D3DSURFACE_DESC desc; // 텍스처 읽기 D3DXCreateTextureFromFile(m_pd3dDevice, "fujiyama.bmp" , &m_pTex); m_pTex->GetSurfaceLevel(0,&pSurf); pSurf->GetDesc(&desc); m_TexWidth = desc.Width; m_TexHeight = desc.Height; SAFE_RELEASE(pSurf); // 셰이더 읽기 LPD3DXBUFFER pErr; if( FAILED( hr = D3DXCreateEffectFromFile( m_pd3dDevice, "hlsl.fx", NULL, NULL, D3DXSHADER_DEBUG , NULL, &m_pEffect, &pErr ))){ MessageBox( NULL, (LPCTSTR)pErr->GetBufferPointer() , "ERROR", MB_OK); return DXTRACE_ERR( "CreateEffectFromFile", hr ); } m_hTechnique = m_pEffect->GetTechniqueByName( "TShader" ); m_htSrcMap = m_pEffect->GetParameterByName( NULL, "SrcMap" ); // 정점선언 오브젝트 생성 if( FAILED( hr = m_pd3dDevice->CreateVertexDeclaration( decl, &m_pDecl ) ) ) return DXTRACE_ERR( "CreateVertexDeclaration", hr ); // 폰트 m_pFont->InitDeviceObjects( m_pd3dDevice ); return S_OK; }
int surface_getpixel_alpha(int id, int x, int y) { get_surfacev(surface,id,-1); if (x < 0) x = 0; if (y < 0) y = 0; if (x > surface->width || y > surface->height) return 0; d3dmgr->EndShapesBatching(); LPDIRECT3DSURFACE9 pBuffer = surface->surf; d3dmgr->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); D3DSURFACE_DESC desc; pBackBuffer->GetDesc(&desc); D3DLOCKED_RECT rect; pBuffer->LockRect(&rect, NULL, D3DLOCK_READONLY); unsigned char* bitmap = static_cast<unsigned char*>(rect.pBits); unsigned offset = y * rect.Pitch + x * 4; int ret = bitmap[offset]; pBuffer->UnlockRect(); delete[] bitmap; return ret; }
INT CrenderTarget::CreateRenderSurface() { HRESULT hr=-1; DWORD dMip = 1; LPDIRECT3DSURFACE9 pSfC = NULL; LPDIRECT3DSURFACE9 pSfD = NULL; D3DSURFACE_DESC dscC; D3DSURFACE_DESC dscD; D3DCAPS9 m_Caps; m_pDev->GetRenderTarget(0,&pSfC); m_pDev->GetDepthStencilSurface(&pSfD); pSfC->GetDesc(&dscC); pSfD->GetDesc(&dscD); m_pDev->GetDeviceCaps(&m_Caps); pSfC->Release(); pSfD->Release(); if(m_iW<0) m_iW = dscC.Width; if(m_iH<0) m_iH = dscC.Height; m_dC = dscC.Format; m_dD = dscD.Format; if(LCX_TARGET_HDR16 == m_nType) m_dC = D3DFMT_A16B16G16R16F; if(LCX_TARGET_HDR32 == m_nType) m_dC = D3DFMT_A32B32G32R32F; hr = D3DXCreateRenderToSurface(m_pDev , m_iW , m_iH , (D3DFORMAT)m_dC , TRUE , (D3DFORMAT)m_dD , &m_pRts); if(FAILED(hr)) return -1; hr = D3DXCreateTexture(m_pDev , m_iW , m_iH , dMip , D3DUSAGE_RENDERTARGET , (D3DFORMAT)m_dC , D3DPOOL_DEFAULT , &m_pTxP); if(FAILED(hr)) return -1; hr = m_pTxP->GetSurfaceLevel(0, &m_pSfc); if(FAILED(hr)) return -1; // Clear 0x0 m_pDev->ColorFill(m_pSfc, NULL, 0x0); return hr; }