bool LTPixelShaderImp::Recreate() { FreeDeviceObject(); if (NULL == m_pByteCode) { return false; } HRESULT hr; // Should we assemble the shader? If this is true, then the byte code must be raw text. if (m_bCompileShader) { // Assemble the shader. LPD3DXBUFFER pCode = NULL; hr = D3DXAssembleShader((const TCHAR*)m_pByteCode, m_ByteCodeSize, NULL, NULL, 0, &pCode, NULL); if (FAILED(hr)) { OUTPUT_D3D_ERROR(1, hr); Term(); return false; } // Create the pixel shader. hr = PD3DDEVICE->CreatePixelShader((const DWORD*)pCode->GetBufferPointer(), &m_pShader); if (FAILED(hr)) { OUTPUT_D3D_ERROR(1, hr); Term(); return false; } } else { // Create the pixel shader directly from the byte code. hr = PD3DDEVICE->CreatePixelShader((const DWORD*)m_pByteCode, &m_pShader); if (FAILED(hr)) { OUTPUT_D3D_ERROR(1, hr); Term(); return false; } } // Try to install the pixel shader once for good measure. hr = PD3DDEVICE->SetPixelShader(m_pShader); if (FAILED(hr)) { // Failed to setup the shader; it isn't supported. OUTPUT_D3D_ERROR(1, hr); Term(); return false; } // We successfully installed it, so clear it out now. PD3DDEVICE->SetPixelShader(NULL); return true; }
bool LTPixelShaderMgr::SetPixelShaderConstants(LTPixelShader *pShader) { LTPixelShaderImp *pShaderImp = (LTPixelShaderImp*)pShader; // Make sure we have valid data. if (pShaderImp == NULL || !pShaderImp->IsValidShader()) { return false; } // Get the constants. float *pConstants = pShaderImp->GetConstants(); if (pConstants == NULL) { return false; } // Set the user-defined constants. HRESULT hr = PD3DDEVICE->SetPixelShaderConstantF(0, pConstants, LTPixelShader::MAX_CONSTANT_REGISTERS); if (FAILED(hr)) { OUTPUT_D3D_ERROR(1, hr); return false; } return true; }
bool LTPixelShaderMgr::InstallPixelShader(LTPixelShader *pShader) const { LTPixelShaderImp *pShaderImp = (LTPixelShaderImp*)pShader; if (pShaderImp == NULL || !pShaderImp->IsValidShader()) { return false; } // Setup the pixel shader. HRESULT hr = PD3DDEVICE->SetPixelShader(pShaderImp->GetShader()); if (FAILED(hr)) { OUTPUT_D3D_ERROR(1, hr); return false; } return true; }
// Create the Sucka... bool CD3D_Device::CreateDevice(D3DAdapterInfo* pAdapter,D3DDeviceInfo* pDevice,D3DModeInfo* pMode) { FreeDevice(); // Make sure it's all released and groovie... m_pAdapter = pAdapter; // Initialization... m_pDevice = pDevice; m_pMode = pMode; // Create the sucka... uint32 BehaviorFlags = D3DCREATE_MULTITHREADED; if (pDevice->d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) BehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING; else BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; D3DPRESENT_PARAMETERS PresentationParam; SetPresentationParams(PresentationParam,pMode); IDirect3DDevice9 *pD3DDevice; HRESULT hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd,BehaviorFlags,&PresentationParam,&pD3DDevice); if ((hResult != D3D_OK) || !pD3DDevice) { // Give it more more try - Presentation params might have been changed by D3D to something acceptable... OUTPUT_D3D_ERROR(1,hResult); // Report the error... OutputDebugString("Warning: Create failed. Attempting to fall back...\n"); TryFallingBack_OnFailedDevCreate(&PresentationParam); hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd,BehaviorFlags,&PresentationParam,&pD3DDevice); if ((hResult != D3D_OK) || !pD3DDevice) { OUTPUT_D3D_ERROR(0,hResult); FreeDevice(); return false; } } // Create our wrapper, which we're going to present to the world as an actual D3D device LT_MEM_TRACK_ALLOC(m_pD3DDevice = new CDirect3DDevice9Wrapper,LT_MEM_TYPE_RENDERER); m_pD3DDevice->SetDevice(pD3DDevice); if (FAILED(m_pD3DDevice->GetDeviceCaps(&m_DeviceCaps))) { FreeDevice(); return false; } SetDefaultRenderStates(); // Set the default render states... PreCalcSomeDeviceCaps(); // Do some precalcing of device caps (figure out if we can do some puff)... m_pD3DDevice->SetStates(); // Display a warning message if (m_pDevice->DeviceType == D3DDEVTYPE_REF) AddDebugMessage(1,"Warning: Couldn\'t find any HAL devices, Using reference rasterizer"); //make sure to clear out the back buffer so it isn't filled with left over garbage LTRGBColor ClearColor; ClearColor.dwordVal = 0; d3d_Clear(NULL, CLEARSCREEN_SCREEN | CLEARSCREEN_RENDER, ClearColor); //create the end of frame query events PD3DDEVICE->CreateQuery(D3DQUERYTYPE_EVENT, &m_pEndOfFrameQuery); // Initialize the render target manager. CRenderTargetMgr::GetSingleton().Init(); return true; }