void QD3DWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) { QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); QDirect3DPaintEngine *engine = qt_d3dEngine(); LPDIRECT3DSWAPCHAIN9 swapchain = engine->swapChain(d_ptr->m_widget); if (swapchain) { QRect br = rgn.boundingRect(); QRect wbr = br.translated(-wOffset); RECT destrect; destrect.left = wbr.x(); destrect.top = wbr.y(); destrect.right = destrect.left + wbr.width(); destrect.bottom = destrect.top + wbr.height(); RECT srcrect; srcrect.left = br.x() + offset.x(); srcrect.top = br.y() + offset.y(); srcrect.right = wbr.width() + srcrect.left; srcrect.bottom = wbr.height() + srcrect.top; int devwidth = d_ptr->m_lastSize.width(); int devheight = d_ptr->m_lastSize.height(); if (devwidth <= srcrect.right) { int diff = srcrect.right - devwidth; srcrect.right -= diff; destrect.right -= diff; if (srcrect.right <= srcrect.left) return; } if (devheight <= srcrect.bottom) { int diff = srcrect.bottom - devheight; srcrect.bottom -= diff; destrect.bottom -= diff; if (srcrect.bottom <= srcrect.top) return; } if (FAILED(swapchain->Present(&srcrect, &destrect, widget->winId(), 0, 0))) qWarning("QDirect3DPaintEngine: failed to present back buffer."); #ifdef D3D_DEBUG_BACKBUFFER qDebug() << widget << srcrect.left << srcrect.top << wbr.width() << wbr.height() << "Dest: " << destrect.left << destrect.top; IDirect3DSurface9 *surface; swapchain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &surface); QString filename("C:\\test.bmp"); D3DXSaveSurfaceToFile(filename.utf16(), D3DXIFF_BMP, surface, 0, 0); surface->Release(); #endif } }
LRESULT CALLBACK windowMessageCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { // Send the WM_QUIT message, terminating the message loop case WM_CREATE: { create(); }break; case WM_DESTROY: { ::PostQuitMessage(0); } break; case WM_SIZE: { D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; vp.Width = LOWORD(lParam); vp.Height = HIWORD(lParam); vp.MinZ = 0; vp.MaxZ = 1; //gDevice->SetViewport(&vp); // LPDIRECT3DSWAPCHAIN9 sc; gDevice->GetSwapChain(0, &sc); sc->Release(); // D3DPRESENT_PARAMETERS pp; sc->GetPresentParameters(&pp); pp.BackBufferWidth = vp.Width; pp.BackBufferHeight = vp.Height; gDevice->Reset(&pp);//会重设viewport,仅设vp而不reset是错误的 }break; default: { } break; } // Forward any other messages we didn't handle above to the default window procedure return ::DefWindowProc(hWnd, message, wParam, lParam); }
bool GnDX9SwapChainBuffer::CreateBufferData(D3DPRESENT_PARAMETERS d3dpp, LPDIRECT3DDEVICE9 pDevice, LPDIRECT3DSWAPCHAIN9& pSwapChain, LPDIRECT3DSURFACE9& pSurface) { HRESULT hr = S_OK; if ( FAILED(hr = pDevice->CreateAdditionalSwapChain(&d3dpp, &pSwapChain)) ) return false; if ( FAILED(pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurface)) ) { GnDxRelease(pSwapChain); return false; } return true; }
/** * Render the Oculus Rift View. ***/ void* OculusRenderer::Provoke(void* pThis, int eD3D, int eD3DInterface, int eD3DMethod, DWORD dwNumberConnected, int& nProvokerIndex) { // return if wrong call if ((eD3D >= (int)AQU_DirectXVersion::DirectX_9_0) && (eD3D <= (int)AQU_DirectXVersion::DirectX_9_29)) { if (((eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) && (eD3DMethod == METHOD_IDIRECT3DDEVICE9_PRESENT)) || ((eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) && (eD3DMethod == METHOD_IDIRECT3DDEVICE9_ENDSCENE)) || ((eD3DInterface == INTERFACE_IDIRECT3DSWAPCHAIN9) && (eD3DMethod == METHOD_IDIRECT3DSWAPCHAIN9_PRESENT))) { (pThis); } else return nullptr; } else return nullptr; // get input data if (m_paInput[(int)ORN_Decommanders::LeftTexture]) m_pcTextureLeft = *(LPDIRECT3DTEXTURE9*)m_paInput[(int)ORN_Decommanders::LeftTexture]; else m_pcTextureLeft = nullptr; if (m_paInput[(int)ORN_Decommanders::RightTexture]) m_pcTextureRight = *(LPDIRECT3DTEXTURE9*)m_paInput[(int)ORN_Decommanders::RightTexture]; else m_pcTextureRight = nullptr; if (m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft]) if (*(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft]) m_pcDistortionVertexBufferLeft = **(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferLeft]; else m_pcDistortionVertexBufferLeft = nullptr; else m_pcDistortionVertexBufferLeft = nullptr; if (m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight]) if (*(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight]) m_pcDistortionVertexBufferRight = **(LPDIRECT3DVERTEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionVertexBufferRight]; else m_pcDistortionVertexBufferRight = nullptr; else m_pcDistortionVertexBufferRight = nullptr; if (m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft]) if (*(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft]) m_pcDistortionIndexBufferLeft = **(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferLeft]; else m_pcDistortionIndexBufferLeft = nullptr; else m_pcDistortionIndexBufferLeft = nullptr; if (m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight]) if (*(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight]) m_pcDistortionIndexBufferRight = **(LPDIRECT3DINDEXBUFFER9**)m_paInput[(int)ORN_Decommanders::DistortionIndexBufferRight]; else m_pcDistortionIndexBufferRight = nullptr; else m_pcDistortionIndexBufferRight = nullptr; if (m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration]) if (*(LPDIRECT3DVERTEXDECLARATION9**)m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration]) m_pcVertexDecl = **(LPDIRECT3DVERTEXDECLARATION9**)m_paInput[(int)ORN_Decommanders::OculusVertexDeclaration]; else m_pcVertexDecl = nullptr; else m_pcVertexDecl = nullptr; if (m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft]) if (*(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft]) m_psFOVPortLeft = *(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovLeft]; else m_psFOVPortLeft = nullptr; else m_psFOVPortLeft = nullptr; if (m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight]) if (*(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight]) m_psFOVPortRight = *(ovrFovPort**)m_paInput[(int)ORN_Decommanders::DefaultEyeFovRight]; else m_psFOVPortRight = nullptr; else m_psFOVPortRight = nullptr; // get device LPDIRECT3DDEVICE9 pcDevice = nullptr; bool bReleaseDevice = false; if (eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) { pcDevice = (LPDIRECT3DDEVICE9)pThis; } else if (eD3DInterface == INTERFACE_IDIRECT3DSWAPCHAIN9) { LPDIRECT3DSWAPCHAIN9 pSwapChain = (LPDIRECT3DSWAPCHAIN9)pThis; if (!pSwapChain) { OutputDebugString(L"Oculus Renderer Node : No swapchain !"); return nullptr; } pSwapChain->GetDevice(&pcDevice); bReleaseDevice = true; } if (!pcDevice) { OutputDebugString(L"Oculus Renderer Node : No device !"); return nullptr; } // Original code (LibOVR) : // pShaderCode = ShaderCompile("precompiledVertexShaderSrc",VertexShaderSrc,"vs_2_0"); // pShaderCode = ShaderCompile("precompiledVertexShaderTimewarpSrc",VertexShaderTimewarpSrc,"vs_3_0"); // pShaderCode = ShaderCompile("precompiledPixelShaderSrc",PixelShaderSrc,"ps_3_0"); // pixel shader created ? if (!m_pcOculusPixelShader) { LPD3DXBUFFER pShader; // compile and create shader if (SUCCEEDED(D3DXCompileShader(PixelShaderSrc,strlen(PixelShaderSrc),NULL,NULL,"main","ps_3_0",NULL,&pShader,NULL,&m_pcOculusPixelShaderCT))) { OutputDebugString(L"Pixel shader compiled!"); pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusPixelShader); } } // vertex shader created ? if (!m_pcOculusVertexShader) { LPD3DXBUFFER pShader; // compile and create shader if (SUCCEEDED(D3DXCompileShader(VertexShaderSrc,strlen(VertexShaderSrc),NULL,NULL,"main","vs_2_0",NULL,&pShader,NULL,&m_pcOculusVertexShaderCT))) { OutputDebugString(L"Vertex shader compiled!"); pcDevice->CreateVertexShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusVertexShader); } } // side by side pixel shader ? if (!m_pcSideBySidePixelShader) { LPD3DXBUFFER pShader; // compile and create shader if (SUCCEEDED(D3DXCompileShader(PixelShaderSrcSideBySide,strlen(PixelShaderSrcSideBySide),NULL,NULL,"SBS","ps_2_0",NULL,&pShader,NULL,&m_pcSideBySidePixelShaderCT))) { OutputDebugString(L"Pixel shader compiled!"); pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcSideBySidePixelShader); } } // test textures created ? if ((!m_pcTextureRightTest) || (!m_pcTextureLeftTest)) { HMODULE hModule = GetModuleHandle(L"OculusRenderer.dll"); if (!m_pcTextureLeftTest) { // create a test texture if (SUCCEEDED(D3DXCreateTextureFromResource(pcDevice, hModule, MAKEINTRESOURCE(IMG_BACKGROUND01), &m_pcTextureLeftTest))) OutputDebugString(L"Texture created !"); else m_pcTextureLeftTest = nullptr; } if (!m_pcTextureRightTest) { // create a test texture if (SUCCEEDED(D3DXCreateTextureFromResource(pcDevice, hModule, MAKEINTRESOURCE(IMG_BACKGROUND02), &m_pcTextureRightTest))) OutputDebugString(L"Texture created !"); else m_pcTextureRightTest = nullptr; } } // default vertex buffer ? if (!m_pcVertexBufferDefault) { InitDefaultVertexBuffer(pcDevice); if (!m_pcVertexBufferDefault) return nullptr; } // vertex buffers ? index buffers ? not all present ? if ((!m_pcDistortionVertexBufferLeft) || (!m_pcDistortionVertexBufferRight) || (!m_pcDistortionIndexBufferLeft) || (!m_pcDistortionIndexBufferRight) || (!m_pcVertexDecl)) { if (m_bBuffersConnected) { // clear all descriptions for safety ZeroMemory(&m_sVertexBufferDescLeft, sizeof(D3DVERTEXBUFFER_DESC)); ZeroMemory(&m_sVertexBufferDescRight, sizeof(D3DVERTEXBUFFER_DESC)); ZeroMemory(&m_sIndexBufferDescLeft, sizeof(D3DINDEXBUFFER_DESC)); ZeroMemory(&m_sIndexBufferDescRight, sizeof(D3DINDEXBUFFER_DESC)); m_bBuffersConnected = false; } } else { m_bBuffersConnected = true; // vertex buffer description ? left if (!m_sVertexBufferDescLeft.Size) m_pcDistortionVertexBufferLeft->GetDesc(&m_sVertexBufferDescLeft); // vertex buffer length matches oculus vertex type ? if ((m_sVertexBufferDescLeft.Size % sizeof(ovrDistortionVertex)) != 0) { OutputDebugString(L"OculusRenderer Node : Connected vertex buffer size mismatch !"); return nullptr; } // and right if (!m_sVertexBufferDescRight.Size) m_pcDistortionVertexBufferRight->GetDesc(&m_sVertexBufferDescRight); // vertex buffer length matches oculus vertex type ? if ((m_sVertexBufferDescRight.Size % sizeof(ovrDistortionVertex)) != 0) { OutputDebugString(L"OculusRenderer Node : Connected vertex buffer size mismatch !"); return nullptr; } // index buffer ? if ((!m_pcDistortionIndexBufferLeft) || (!m_pcDistortionIndexBufferRight)) return nullptr; // index buffer description ? if (!m_sIndexBufferDescLeft.Size) { m_pcDistortionIndexBufferLeft->GetDesc(&m_sIndexBufferDescLeft); // index buffer length matches vertex buffer size ? TODO !! /*if () { OutputDebugString(L"OculusRenderer Node : Connected index buffer size mismatch !"); return nullptr; }*/ } if (!m_sIndexBufferDescRight.Size) { m_pcDistortionIndexBufferRight->GetDesc(&m_sIndexBufferDescRight); // index buffer length matches vertex buffer size ? TODO !! /*if () { OutputDebugString(L"OculusRenderer Node : Connected index buffer size mismatch !"); return nullptr; }*/ } } // start to render pcDevice->BeginScene(); // save states IDirect3DStateBlock9* pStateBlock = nullptr; pcDevice->CreateStateBlock(D3DSBT_ALL, &pStateBlock); // set ALL render states to default SetAllRenderStatesDefault(pcDevice); // set states pcDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); pcDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); pcDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); pcDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT); pcDevice->SetTextureStageState(0, D3DTSS_CONSTANT, 0xffffffff); pcDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); pcDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); pcDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); pcDevice->SetSamplerState(0, D3DSAMP_SRGBTEXTURE, 0); pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(0, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); pcDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); pcDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); D3DCOLOR clearColor = D3DCOLOR_RGBA(0, 0, 0, 0); pcDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 0, 0); // required fields D3DSURFACE_DESC sSurfaceDesc; ovrSizei sTextureSize; ovrRecti sRenderViewport; ovrVector2f UVScaleOffset[2]; // LEFT EYE : // left eye, first set stream source, indices if (m_bBuffersConnected) { // no timewarp here, use standard vertex shader, set pixel shader, set vertex declaration pcDevice->SetVertexShader( m_pcOculusVertexShader); pcDevice->SetPixelShader( m_pcOculusPixelShader ); pcDevice->SetVertexDeclaration( m_pcVertexDecl ); // set texture if (m_pcTextureLeft) pcDevice->SetTexture( 0, m_pcTextureLeft ); else if (m_pcTextureLeftTest) pcDevice->SetTexture( 0, m_pcTextureLeftTest ); else pcDevice->SetTexture( 0, 0); // get texture size if (m_pcTextureLeft) m_pcTextureLeft->GetLevelDesc(0, &sSurfaceDesc); else if (m_pcTextureLeftTest) m_pcTextureLeftTest->GetLevelDesc(0, &sSurfaceDesc); else ZeroMemory(&sSurfaceDesc, sizeof(D3DSURFACE_DESC)); sTextureSize.w = (int)sSurfaceDesc.Width; sTextureSize.h = (int)sSurfaceDesc.Height; // set render viewport size the same size as the texture size (!) sRenderViewport.Pos.x = 0; sRenderViewport.Pos.y = 0; sRenderViewport.Size.w = sTextureSize.w; sRenderViewport.Size.h = sTextureSize.h; // get and set scale and offset if (m_psFOVPortLeft) ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset); else ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortLeft, sTextureSize, sRenderViewport, UVScaleOffset); pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 ); pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 ); pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferLeft,0, sizeof(ovrDistortionVertex) ); pcDevice->SetIndices( m_pcDistortionIndexBufferLeft); // draw pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescLeft.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescLeft.Size / 6 ); } else { pcDevice->SetSamplerState(1, D3DSAMP_SRGBTEXTURE, 0); pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(1, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP); pcDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); pcDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); pcDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE); // side by side render pcDevice->SetVertexShader(NULL); pcDevice->SetPixelShader(m_pcSideBySidePixelShader); pcDevice->SetVertexDeclaration( NULL ); pcDevice->SetFVF(D3DFVF_TEXVERTEX); // set textures if (m_pcTextureLeft) pcDevice->SetTexture( 0, m_pcTextureLeft ); else if (m_pcTextureLeftTest) pcDevice->SetTexture( 0, m_pcTextureLeftTest ); else pcDevice->SetTexture( 0, 0); if (m_pcTextureRight) pcDevice->SetTexture( 1, m_pcTextureRight ); else if (m_pcTextureRightTest) pcDevice->SetTexture( 1, m_pcTextureRightTest ); else pcDevice->SetTexture( 1, 0); // set stream and draw pcDevice->SetStreamSource( 0, m_pcVertexBufferDefault,0, sizeof(TEXVERTEX) ); pcDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2); } // RIGHT EYE: if (m_bBuffersConnected) { // set texture if (m_pcTextureRight) pcDevice->SetTexture( 0, m_pcTextureRight ); else if (m_pcTextureRightTest) pcDevice->SetTexture( 0, m_pcTextureRightTest ); else pcDevice->SetTexture( 0, 0); // get texture size if (m_pcTextureRight) m_pcTextureRight->GetLevelDesc(0, &sSurfaceDesc); else if (m_pcTextureRightTest) m_pcTextureRightTest->GetLevelDesc(0, &sSurfaceDesc); else ZeroMemory(&sSurfaceDesc, sizeof(D3DSURFACE_DESC)); sTextureSize.w = (int)sSurfaceDesc.Width; sTextureSize.h = (int)sSurfaceDesc.Height; // get and set scale and offset if (m_psFOVPortRight) ovrHmd_GetRenderScaleAndOffset(*m_psFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset); else ovrHmd_GetRenderScaleAndOffset(m_sDefaultFOVPortRight, sTextureSize, sRenderViewport, UVScaleOffset); pcDevice->SetVertexShaderConstantF( 0, ( FLOAT* )&UVScaleOffset[0], 1 ); pcDevice->SetVertexShaderConstantF( 2, ( FLOAT* )&UVScaleOffset[1], 1 ); // set stream source, indices, draw pcDevice->SetStreamSource( 0, m_pcDistortionVertexBufferRight,0, sizeof(ovrDistortionVertex) ); pcDevice->SetIndices( m_pcDistortionIndexBufferRight); // draw pcDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0, m_sVertexBufferDescRight.Size / sizeof(ovrDistortionVertex) , 0, m_sIndexBufferDescRight.Size / 6 ); } pcDevice->EndScene(); // apply and release state block if (pStateBlock) { pStateBlock->Apply(); pStateBlock->Release(); } // release device if provided by swapchain if (bReleaseDevice) pcDevice->Release(); return nullptr; }
bool D3DCubeTextureRenderTarget::CreateTextures( uint texture_size, TextureFormat::Format texture_format ) { m_CubeTextureSize = texture_size; m_TextureFormat = texture_format; D3DFORMAT d3d_fmt; if( texture_format == TextureFormat::Invalid ) /* || any ohter texture formats invalid for cube mapping ) */ { LOG_PRINT_ERROR( fmt_string("An unsupported texture format: %d", texture_format) ); return false; } d3d_fmt = ConvertTextureFormatToD3DFORMAT( texture_format ); LPDIRECT3DDEVICE9 pd3dDevice = DIRECT3D9.GetDevice(); HRESULT hr; m_NumCubes = 1; // always use the single cube texture /* if( d3d_fmt == D3DFMT_A16B16G16R16F ) { // Create the cube textures ZeroMemory( m_apCubeMapFp, sizeof( m_apCubeMapFp ) ); hr = pd3dDevice->CreateCubeTexture( m_CubeTextureSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &m_apCubeMapFp[0], NULL ); m_pCurrentCubeMap = m_apCubeMapFp[0]; } */ hr = pd3dDevice->CreateCubeTexture( m_CubeTextureSize, 1, D3DUSAGE_RENDERTARGET, d3d_fmt, D3DPOOL_DEFAULT, &m_pCubeMap32, NULL ); if( FAILED(hr) || !m_pCubeMap32 ) { LOG_PRINT_WARNING( "CreateCubeTexture() failed. Cannot create cube texture." ); return false; } m_pCurrentCubeMap = m_pCubeMap32; // DXUTDeviceSettings d3dSettings = DXUTGetDeviceSettings(); LPDIRECT3DSWAPCHAIN9 pSwapChain; pd3dDevice->GetSwapChain( 0, &pSwapChain ); D3DPRESENT_PARAMETERS pp; pSwapChain->GetPresentParameters( &pp ); hr = pd3dDevice->CreateDepthStencilSurface( m_CubeTextureSize, m_CubeTextureSize, // d3dSettings.d3d9.pp.AutoDepthStencilFormat, pp.AutoDepthStencilFormat, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pDepthCube, NULL ); if( FAILED(hr) || !m_pCurrentCubeMap ) { LOG_PRINT_WARNING( "CreateDepthStencilSurface() failed. Cannot create depth stencil surface." ); return false; } /* // Initialize the number of cube maps required when using floating point format // IDirect3D9* pD3D = DXUTGetD3D9Object(); // D3DCAPS9 caps; // hr = pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType, &caps ); // if( FAILED( pD3D->CheckDeviceFormat( caps.AdapterOrdinal, caps.DeviceType, // pDeviceSettings->d3d9.AdapterFormat, D3DUSAGE_RENDERTARGET, // D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F ) ) ) if( FAILED( pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, DIRECT3D9.GetDeviceType(), DIRECT3D9.GetAdapterFormat(), D3DUSAGE_RENDERTARGET, D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F ) ) ) { m_NumCubes = m_NumFpCubeMap = 2; } else { m_NumCubes = m_NumFpCubeMap = 1; } // If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW // then switch to SWVP. // if( (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 || // caps.VertexShaderVersion < D3DVS_VERSION(1,1) ) // { // pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // }*/ return true; }