Exemplo n.º 1
0
bool NavigationLine::CreateDeviceObjects()
{
	if (!m_visible)
		return true;

	ID3DXBuffer* errors = 0;
	HRESULT hr;

	hr = D3DXCreateTextureFromFileA(g_pDevice, m_textureFile.c_str(), &m_lineTexture);
	if (FAILED(hr))
	{
		DebugSpewAlways("Failed to load texture!");

		InvalidateDeviceObjects();
		return false;
	}

	hr = D3DXCreateEffectFromFileA(g_pDevice, m_shaderFile.c_str(),
		NULL, NULL, 0, NULL, &m_effect, &errors);
	if (FAILED(hr))
	{
		if (errors)
		{
			DebugSpewAlways("Effect error: %s", errors->GetBufferPointer());

			errors->Release();
			errors = nullptr;
		}

		InvalidateDeviceObjects();
		return false;
	}

	D3DVERTEXELEMENT9 vertexElements[] =
	{
		{ 0,  0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,  0 },
		{ 0, 12,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,  0 },
		{ 0, 24,  D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  0 },
		{ 0, 40,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  1 },
		D3DDECL_END()
	};

	hr = g_pDevice->CreateVertexDeclaration(vertexElements, &m_vDeclaration);
	if (FAILED(hr))
	{
		InvalidateDeviceObjects();
		return false;
	}

	m_effect->SetTexture("lineTexture", m_lineTexture);
	m_loaded = true;

	return true;
}
Exemplo n.º 2
0
CAnimationModel::~CAnimationModel()
{
	InvalidateDeviceObjects();
	DeleteDeviceObjects();

	SAFE_DELETE_ARRAY( m_pXFileName );
}
Exemplo n.º 3
0
void CWndAbout::OnDestroy()
{
	InvalidateDeviceObjects();
	DeleteDeviceObjects();
	
	SAFE_DELETE(m_pFont);
}
Exemplo n.º 4
0
void CTailEffectBelt::Destroy( void )
{
	InvalidateDeviceObjects();
	SAFE_RELEASE( m_pTexture );
	SAFE_DELETE_ARRAY( m_pPool );
	Init();
}
Exemplo n.º 5
0
void CStdGL::Clear()
{
	NoPrimaryClipper();
	// cannot unlock TexMgr here or we can't preserve textures across GL reinitialization as required when changing multisampling
	InvalidateDeviceObjects();
	NoPrimaryClipper();
	RenderTarget = NULL;
	// Clear all shaders
	SpriteShader.Clear();
	SpriteShaderMod2.Clear();
	SpriteShaderBase.Clear();
	SpriteShaderBaseMod2.Clear();
	SpriteShaderBaseOverlay.Clear();
	SpriteShaderBaseOverlayMod2.Clear();
	SpriteShaderLight.Clear();
	SpriteShaderLightMod2.Clear();
	SpriteShaderLightBase.Clear();
	SpriteShaderLightBaseMod2.Clear();
	SpriteShaderLightBaseOverlay.Clear();
	SpriteShaderLightBaseOverlayMod2.Clear();
	SpriteShaderLightBaseNormal.Clear();
	SpriteShaderLightBaseNormalMod2.Clear();
	SpriteShaderLightBaseNormalOverlay.Clear();
	SpriteShaderLightBaseNormalOverlayMod2.Clear();
	// clear context
	if (pCurrCtx) pCurrCtx->Deselect();
	pMainCtx=0;
	C4Draw::Clear();
}
Exemplo n.º 6
0
BOOL CDxtexApp::HandlePossibleLostDevice(VOID)
{
    HRESULT hr;

    if( !m_bDeviceLost )
        return TRUE; // ok to render
    
    hr = m_pd3ddev->TestCooperativeLevel();

    if( hr == D3DERR_DEVICELOST )
        return FALSE; // not ready to reset, but not ok to render

    if( hr == D3DERR_DEVICENOTRESET )
    {
        InvalidateDeviceObjects();
        D3DPRESENT_PARAMETERS presentParams;

        ZeroMemory(&presentParams, sizeof(presentParams));
        presentParams.Windowed = TRUE;
        presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
        presentParams.BackBufferWidth = 8;
        presentParams.BackBufferHeight = 8;
        presentParams.BackBufferFormat = D3DFMT_UNKNOWN;
        hr = m_pd3ddev->Reset( &presentParams );
        if( FAILED( hr ) )
            return FALSE;

        RestoreDeviceObjects();
        m_bDeviceLost = FALSE;
    }

    return TRUE;
}
Exemplo n.º 7
0
void CDirect3D::DestroyD3D(void)
{
#if D3D_THREAD
    // Kill child thread
    if(thread != NULL) {
	Wait(false);
	thread_run = false;
	thread_command = D3D_IDLE;
	LeaveCriticalSection(&cs);
	SDL_SemPost(thread_sem);
	SDL_WaitThread(thread, NULL);
	thread = NULL;
    }
#endif

    InvalidateDeviceObjects();

    // Delete D3D device
    SAFE_RELEASE(pD3DDevice9);
    SAFE_RELEASE(pD3D9);

    if(modes) {
	free(modes);
	modes = NULL;
    }
}
Exemplo n.º 8
0
void CTailEffectModel::Destroy( void )
{
	InvalidateDeviceObjects();
	m_pModel->DeleteDeviceObjects();
	SAFE_DELETE(m_pModel);	
	m_vecTail.clear();
	Init();
}
Exemplo n.º 9
0
void Terrain::RestoreDeviceObjects(void) {
    InvalidateDeviceObjects();
    LoadTexture();
    LoadTerrainFromFile(m_sTerrainFile.c_str());
    /*if (FAILED(m_pd3dDevice->CreateVertexBuffer(m_uNumVertices * sizeof(TerrainVertex),
                                                D3DUSAGE_WRITEONLY, TerrainVertex::FVF_Flags,
                                                D3DPOOL_MANAGED, &m_pVertexBuffer, 0))) {
        return;
    }
    TerrainVertex *pVertices = NULL;
    if (SUCCEEDED(m_pVertexBuffer->Lock(0, 0, (void **)&pVertices, 0))) {
        float fStartX = -m_fTerrainWidth / 2.0f, fEndX = m_fTerrainWidth / 2.0f;
        float fStartZ = m_fTerrainDepth / 2.0f,  fEndZ = -m_fTerrainDepth / 2.0f;
        float fTextureU = 10.0f / (float)m_uCellsPerRow;
        float fTextureV = 10.0f / (float)m_uCellsPerCol;

        int nIndex = 0, i = 0;
        for (float z = fStartZ; z >= fEndZ; z -= m_fCellsSpace, ++i) {
            int j = 0;
            for (float x = fStartX; x <= fEndX; x += m_fCellsSpace, ++j) {
                nIndex = i * m_uCellsPerRow + j;
                pVertices[nIndex] = TerrainVertex(x, m_vHeightData[nIndex], z, j * fTextureU, i * fTextureV);
                ++nIndex;
            }
        }

        m_pVertexBuffer->Unlock();
    }*/
    UINT uWidth = (int)sqrt((float)m_uNumVertices);
    if (FAILED(m_pd3dDevice->CreateVertexBuffer(m_uNumVertices * sizeof(Vertex),
                                                D3DUSAGE_WRITEONLY, Vertex::FVF_Flags,
                                                D3DPOOL_MANAGED, &m_pVertexBuffer, 0))) {
        return;
    }
    Vertex *pVertices = NULL;
    if (SUCCEEDED(m_pVertexBuffer->Lock(0, 0, (void **)&pVertices, 0))) {
        GenerateTerrainVertex(pVertices, &m_vHeightData[0], uWidth, uWidth);
        m_pVertexBuffer->Unlock();
    }

    m_uNumIndices = GetIndicesNum(uWidth, uWidth);
    if (FAILED(m_pd3dDevice->CreateIndexBuffer(m_uNumIndices * sizeof(int),
                                               D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_pIndexBuffer, 0))) {
        return;
    }
    int *pIndices = NULL;
    if (SUCCEEDED(m_pIndexBuffer->Lock(0, 0, (void **)&pIndices, 0))) {
        GenerateIndices(pIndices, uWidth, uWidth);
        m_pIndexBuffer->Unlock();
    }
    ZeroMemory(&m_d3dMaterial, sizeof(D3DMATERIAL9));
    m_d3dMaterial.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
    m_d3dMaterial.Diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
    m_d3dMaterial.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
    m_d3dMaterial.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
    m_d3dMaterial.Power = 0.0f;
}
Exemplo n.º 10
0
//-----------------------------------------------------------------------------
// Name: ~CParticleSystem()
// Desc:
//-----------------------------------------------------------------------------
ParticleSystem::~ParticleSystem()
{
    InvalidateDeviceObjects();

    while( m_pFreeList )
    {
        Particle *pParticle = m_pFreeList;
        m_pFreeList = pParticle->m_pNext;
        delete pParticle;
    }
    m_pFreeList = NULL;
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
// Name:
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DMesh::Destroy()
{
    InvalidateDeviceObjects();
    for( UINT i=0; i<m_dwNumMaterials; i++ )
        SAFE_RELEASE( m_pTextures[i] );
    SAFE_DELETE_ARRAY( m_pTextures );
    SAFE_DELETE_ARRAY( m_pMaterials );

    SAFE_RELEASE( m_pSysMemMesh );

    m_dwNumMaterials = 0L;

    return S_OK;
}
Exemplo n.º 12
0
void NavigationLine::SetVisible(bool visible)
{
	if (m_visible != visible)
	{
		m_visible = visible;

		if (m_visible) {
			m_needsUpdate = true;
			CreateDeviceObjects();
		}
		else
			InvalidateDeviceObjects();
	}
}
Exemplo n.º 13
0
//-----------------------------------------------------------------------------
// Name: ~CParticleSystem()
// Desc:
//-----------------------------------------------------------------------------
CParticleSystem::~CParticleSystem()
{
    InvalidateDeviceObjects();

    while( m_pPlanes ) // Repeat till null...
    {
        Plane *pPlane = m_pPlanes;   // Hold onto the first one
        m_pPlanes = pPlane->m_pNext; // Move down to the next one
        delete pPlane;               // Delete the one we're holding
    }

	Particle* pParticle = 0;
    while( m_pActiveList )
    {
        pParticle = m_pActiveList;
        m_pActiveList = pParticle->m_pNext;
        delete pParticle;
    }
    m_pActiveList = NULL;

    while( m_pFreeList )
    {
        Particle *pParticle = m_pFreeList;
        m_pFreeList = pParticle->m_pNext;
        delete pParticle;
    }
    m_pFreeList = NULL;

	if( m_chTexFile != NULL )
	{
		delete [] m_chTexFile;
		m_chTexFile = NULL;
	}

    if( m_ptexParticle != NULL )
        m_ptexParticle->Release();
}
Exemplo n.º 14
0
HRESULT CDirect3D::RestoreDeviceObjects(void)
{
    unsigned int vertexbuffersize = sizeof(TLVERTEX) * 4;
    preProcess = false;

#if C_D3DSHADERS
    if(psActive) {
	// Set up pixel shaders
	LoadPixelShader();

	if(psEffect && psEffect->hasPreprocess()) {
#if LOG_D3D
	    LOG_MSG("D3D:Pixel shader preprocess active");
#endif
	    preProcess = true;
	    vertexbuffersize = sizeof(TLVERTEX) * 8;
	}
    }
#endif
    // Initialize vertex
    pD3DDevice9->SetFVF(D3DFVF_TLVERTEX);

    // Create vertex buffer
    if(FAILED(pD3DDevice9->CreateVertexBuffer(vertexbuffersize, D3DUSAGE_WRITEONLY,
        D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL))) {
	LOG_MSG("D3D:Failed to create Vertex Buffer");
	return E_FAIL;
    }

    // Lock vertex buffer and set vertices
    CreateVertex();

    pD3DDevice9->SetStreamSource(0, vertexBuffer, 0, sizeof(TLVERTEX));

    // Turn off culling
    pD3DDevice9->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

    // Turn off D3D lighting
    pD3DDevice9->SetRenderState(D3DRS_LIGHTING, false);

    // Turn off the zbuffer
    pD3DDevice9->SetRenderState(D3DRS_ZENABLE, false);

    CreateDisplayTexture();
    SetupSceneScaled();

    if(!psActive) {
	pD3DDevice9->SetTexture(0, lpTexture);

	// Disable Shaders
	pD3DDevice9->SetVertexShader(0);
	pD3DDevice9->SetPixelShader(0);

	pD3DDevice9->SetTransform(D3DTS_PROJECTION, &m_matProj);
	pD3DDevice9->SetTransform(D3DTS_VIEW, &m_matView);
	pD3DDevice9->SetTransform(D3DTS_WORLD, &m_matWorld);
    }
#if C_D3DSHADERS
    else if(psEffect) {
	if(preProcess) {
	    // Projection is (0,0,0) -> (1,1,1)
	    D3DXMatrixOrthoOffCenterLH(&m_matPreProj, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);

	    // Align texels with pixels
	    D3DXMatrixTranslation(&m_matPreView, -0.5f/dwTexWidth, 0.5f/dwTexHeight, 0.0f);

	    // Identity for world
	    D3DXMatrixIdentity(&m_matPreWorld);

	} else if(FAILED(psEffect->SetMatrices(m_matProj, m_matView, m_matWorld))) {
	    LOG_MSG("D3D:Set matrices failed.");
	    InvalidateDeviceObjects();
	    return E_FAIL;
	}
    }
#endif

    return S_OK;
}
		void ImGuiDX9::Shutdown()
		{
			InvalidateDeviceObjects();
			ImGui::DestroyContext();
		}
Exemplo n.º 16
0
CWndCredit::~CWndCredit() 
{ 
	InvalidateDeviceObjects();
	DeleteDeviceObjects();
} 
Exemplo n.º 17
0
NavigationLine::~NavigationLine()
{
	InvalidateDeviceObjects();
}
Exemplo n.º 18
0
HRESULT CWndGHTeleporter::DeleteDeviceObjects()
{
	CWndNeuz::DeleteDeviceObjects();
	return InvalidateDeviceObjects();
}
Exemplo n.º 19
0
void Shutdown() {
    InvalidateDeviceObjects();
    ImGui::Shutdown();
    glDeleteProgram(g_ShaderHandle);
}
//-----------------------------------------------------------------------------
// Name: Initialize3DEnvironment()
// Desc: Usually this function is not overridden.  Here's what this function does:
//       - Sets the windowed flag to be either windowed or fullscreen
//       - Sets parameters for z-buffer depth and back buffer
//       - Creates the D3D device
//       - Sets the window position (if windowed, that is)
//       - Makes some determinations as to the abilites of the driver (HAL, etc)
//       - Sets up some cursor stuff
//       - Calls InitDeviceObjects()
//       - Calls RestoreDeviceObjects()
//       - If all goes well, m_bActive is set to TRUE, and the function returns
//       - Otherwise, initialization is reattempted using the reference device
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Initialize3DEnvironment()
{
    HRESULT hr;

    D3DAdapterInfo* pAdapterInfo = m_d3dSettings.PAdapterInfo();
    D3DDeviceInfo*  pDeviceInfo  = m_d3dSettings.PDeviceInfo();

    m_bWindowed = m_d3dSettings.IsWindowed;

    // Prepare window for possible windowed/fullscreen change
    AdjustWindowForChange();

    // Set up the presentation parameters
    BuildPresentParamsFromSettings();

    if( pDeviceInfo->Caps.PrimitiveMiscCaps & D3DPMISCCAPS_NULLREFERENCE )
    {
        // Warn user about null ref device that can't render anything
        DisplayErrorMsg( D3DAPPERR_NULLREFDEVICE, 0 );
    }

    DWORD behaviorFlags;
    if (m_d3dSettings.GetVertexProcessingType() == SOFTWARE_VP)
        behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
    else if (m_d3dSettings.GetVertexProcessingType() == MIXED_VP)
        behaviorFlags = D3DCREATE_MIXED_VERTEXPROCESSING;
    else if (m_d3dSettings.GetVertexProcessingType() == HARDWARE_VP)
        behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else if (m_d3dSettings.GetVertexProcessingType() == PURE_HARDWARE_VP)
        behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE;
    else
        behaviorFlags = 0; // TODO: throw exception

    // Add multithreaded flag if requested by app
    if( m_bCreateMultithreadDevice )
        behaviorFlags |= D3DCREATE_MULTITHREADED;

    // Create the device
    hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
                               m_hWndFocus, behaviorFlags, &m_d3dpp,
                               &m_pd3dDevice );

    if( SUCCEEDED(hr) )
    {
        // When moving from fullscreen to windowed mode, it is important to
        // adjust the window size after recreating the device rather than
        // beforehand to ensure that you get the window size you want.  For
        // example, when switching from 640x480 fullscreen to windowed with
        // a 1000x600 window on a 1024x768 desktop, it is impossible to set
        // the window size to 1000x600 until after the display mode has
        // changed to 1024x768, because windows cannot be larger than the
        // desktop.
        if( m_bWindowed )
        {
            SetWindowPos( m_hWnd, HWND_NOTOPMOST,
                          m_rcWindowBounds.left, m_rcWindowBounds.top,
                          ( m_rcWindowBounds.right - m_rcWindowBounds.left ),
                          ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ),
                          SWP_HIDEWINDOW );
        }

        // Store device Caps
        m_pd3dDevice->GetDeviceCaps( &m_d3dCaps );
        m_dwCreateFlags = behaviorFlags;

        // Store device description
        if( pDeviceInfo->DevType == D3DDEVTYPE_REF )
            lstrcpy( m_strDeviceStats, TEXT("REF") );
        else if( pDeviceInfo->DevType == D3DDEVTYPE_HAL )
            lstrcpy( m_strDeviceStats, TEXT("HAL") );
        else if( pDeviceInfo->DevType == D3DDEVTYPE_SW )
            lstrcpy( m_strDeviceStats, TEXT("SW") );

        if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING &&
            behaviorFlags & D3DCREATE_PUREDEVICE )
        {
            if( pDeviceInfo->DevType == D3DDEVTYPE_HAL )
                lstrcat( m_strDeviceStats, TEXT(" (pure hw vp)") );
            else
                lstrcat( m_strDeviceStats, TEXT(" (simulated pure hw vp)") );
        }
        else if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
        {
            if( pDeviceInfo->DevType == D3DDEVTYPE_HAL )
                lstrcat( m_strDeviceStats, TEXT(" (hw vp)") );
            else
                lstrcat( m_strDeviceStats, TEXT(" (simulated hw vp)") );
        }
        else if( behaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
        {
            if( pDeviceInfo->DevType == D3DDEVTYPE_HAL )
                lstrcat( m_strDeviceStats, TEXT(" (mixed vp)") );
            else
                lstrcat( m_strDeviceStats, TEXT(" (simulated mixed vp)") );
        }
        else if( behaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
        {
            lstrcat( m_strDeviceStats, TEXT(" (sw vp)") );
        }

        if( pDeviceInfo->DevType == D3DDEVTYPE_HAL )
        {
            // Be sure not to overflow m_strDeviceStats when appending the adapter 
            // description, since it can be long.  Note that the adapter description
            // is initially CHAR and must be converted to TCHAR.
            lstrcat( m_strDeviceStats, TEXT(": ") );
            const int cchDesc = sizeof(pAdapterInfo->AdapterIdentifier.Description);
            TCHAR szDescription[cchDesc];
            DXUtil_ConvertAnsiStringToGenericCch( szDescription, 
                pAdapterInfo->AdapterIdentifier.Description, cchDesc );
            int maxAppend = sizeof(m_strDeviceStats) / sizeof(TCHAR) -
                lstrlen( m_strDeviceStats ) - 1;
            _tcsncat( m_strDeviceStats, szDescription, maxAppend );
        }

        // Store render target surface desc
        LPDIRECT3DSURFACE9 pBackBuffer = NULL;
        m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
        pBackBuffer->GetDesc( &m_d3dsdBackBuffer );
        pBackBuffer->Release();

        // Set up the fullscreen cursor
        if( m_bShowCursorWhenFullscreen && !m_bWindowed )
        {
            HCURSOR hCursor;
#ifdef _WIN64
            hCursor = (HCURSOR)GetClassLongPtr( m_hWnd, GCLP_HCURSOR );
#else
            hCursor = (HCURSOR)ULongToHandle( GetClassLong( m_hWnd, GCL_HCURSOR ) );
#endif
            D3DUtil_SetDeviceCursor( m_pd3dDevice, hCursor, true );
            m_pd3dDevice->ShowCursor( true );
        }

        // Confine cursor to fullscreen window
        if( m_bClipCursorWhenFullscreen )
        {
            if (!m_bWindowed )
            {
                RECT rcWindow;
                GetWindowRect( m_hWnd, &rcWindow );
                ClipCursor( &rcWindow );
            }
            else
            {
                ClipCursor( NULL );
            }
        }

        // Initialize the app's device-dependent objects
        hr = InitDeviceObjects();
        if( FAILED(hr) )
        {
            DeleteDeviceObjects();
        }
        else
        {
            m_bDeviceObjectsInited = true;
            hr = RestoreDeviceObjects();
            if( FAILED(hr) )
            {
                InvalidateDeviceObjects();
            }
            else
            {
                m_bDeviceObjectsRestored = true;
                return S_OK;
            }
        }

        // Cleanup before we try again
        Cleanup3DEnvironment();
    }

    // If that failed, fall back to the reference rasterizer
    if( hr != D3DAPPERR_MEDIANOTFOUND && 
        hr != HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) && 
        pDeviceInfo->DevType == D3DDEVTYPE_HAL )
    {
        if (FindBestWindowedMode(false, true))
        {
            m_bWindowed = true;
            AdjustWindowForChange();
            // Make sure main window isn't topmost, so error message is visible
            SetWindowPos( m_hWnd, HWND_NOTOPMOST,
                          m_rcWindowBounds.left, m_rcWindowBounds.top,
                          ( m_rcWindowBounds.right - m_rcWindowBounds.left ),
                          ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ),
                          SWP_SHOWWINDOW );

            // Let the user know we are switching from HAL to the reference rasterizer
            DisplayErrorMsg( hr, MSGWARN_SWITCHEDTOREF );

            hr = Initialize3DEnvironment();
        }
    }
    return hr;
}
Exemplo n.º 21
0
void Shutdown()
{
    InvalidateDeviceObjects();
    ImGui::Shutdown();
}
Exemplo n.º 22
0
HRESULT CCollectingWnd::DeleteDeviceObjects()
{
	CWndBase::DeleteDeviceObjects();
	return InvalidateDeviceObjects();
}
Exemplo n.º 23
0
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: Message proc function to handle key and menu input
//-----------------------------------------------------------------------------
LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                                    LPARAM lParam )
{
    // Pass mouse messages to the ArcBall so it can build internal matrices
    m_ArcBall.HandleMouseMessages( hWnd, uMsg, wParam, lParam );

    // Trap the context menu
    if( WM_CONTEXTMENU==uMsg )
        return 0;

    if( uMsg == WM_COMMAND )
    {
        // Toggle mesh optimization
        if( LOWORD(wParam) == IDM_SHOWNONOPTIMIZEDMESH )
        {
            m_bShowVertexCacheOptimized = FALSE;
            m_bShowStripReordered = FALSE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_CHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED );
        }
        else if( LOWORD(wParam) == IDM_SHOWVCACHEOPTIMIZED )
        {
            m_bShowVertexCacheOptimized = TRUE;
            m_bShowStripReordered = FALSE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_CHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED );
        }
        else if( LOWORD(wParam) == IDM_SHOWSTRIPREORDERED )
        {
            m_bShowVertexCacheOptimized = FALSE;
            m_bShowStripReordered = TRUE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_CHECKED );
        }
        // Toggle strips
        else if( LOWORD(wParam) == IDM_SHOWTRILIST )
        {
            m_bShowStrips = FALSE;
            m_bShowSingleStrip = FALSE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_CHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED );
        }
        else if( LOWORD(wParam) == IDM_SHOWONESTRIP )
        {
            m_bShowStrips = FALSE;
            m_bShowSingleStrip = TRUE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_CHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED );
        }
        else if( LOWORD(wParam) == IDM_SHOWMANYSTRIPS )
        {
            m_bShowStrips = TRUE;
            m_bShowSingleStrip = FALSE;

            CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED );
            CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_CHECKED );
        }
        // Toggle vertex buffer mode
        else if( LOWORD(wParam) == IDM_DYNAMICVB )
        {
            if (m_dwMemoryOptions == D3DXMESH_DYNAMIC)
            {
                m_dwMemoryOptions = D3DXMESH_MANAGED;
                CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_UNCHECKED );
            }
            else
            {
                m_dwMemoryOptions = D3DXMESH_DYNAMIC;
                CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_CHECKED );
            }
            // Destroy and recreate everything
            InvalidateDeviceObjects();
            RestoreDeviceObjects();
        }        
        else if( LOWORD(wParam) == IDM_FORCE32BYTEVERTEX )
        {
            m_bForce32ByteFVF = !m_bForce32ByteFVF;

            CheckMenuItem( GetMenu(hWnd), IDM_FORCE32BYTEVERTEX, m_bForce32ByteFVF ? MF_CHECKED : MF_UNCHECKED );

            // Destroy and recreate everything
            InvalidateDeviceObjects();
            DeleteDeviceObjects();
            InitDeviceObjects();
            RestoreDeviceObjects();
        }
        // Handle the open file command
        else if( LOWORD(wParam) == IDM_OPENFILE )
        {
            TCHAR g_strFilename[512]   = _T("");

            // Display the OpenFileName dialog. Then, try to load the specified file
            OPENFILENAME ofn = { sizeof(OPENFILENAME), NULL, NULL,
                                _T(".X Files (.x)\0*.x\0\0"), 
                                NULL, 0, 1, m_strMeshFilename, 512, g_strFilename, 512, 
                                m_strInitialDir, _T("Open Mesh File"), 
                                OFN_FILEMUSTEXIST, 0, 1, NULL, 0, NULL, NULL };

            if( TRUE == GetOpenFileName( &ofn ) )
            {
                _tcscpy( m_strInitialDir, m_strMeshFilename );
                TCHAR* pLastSlash =  _tcsrchr( m_strInitialDir, _T('\\') );
                if( pLastSlash )
                    *pLastSlash = 0;
                SetCurrentDirectory( m_strInitialDir );

                // Destroy and recreate everything
                InvalidateDeviceObjects();
                DeleteDeviceObjects();
                InitDeviceObjects();
                RestoreDeviceObjects();
            }
        }

        else if ((LOWORD(wParam) >= ID_OPTIONS_DISPLAY1) && (LOWORD(wParam) <= ID_OPTIONS_DISPLAY36))
        {
            // uncheck old item
            CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_UNCHECKED );

            // calc new item
            m_cObjectsPerSide = LOWORD(wParam) - ID_OPTIONS_DISPLAY1 + 1;

            // check new item
            CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_CHECKED );
        }
    }

    return CD3DApplication::MsgProc( hWnd, uMsg, wParam, lParam );
}
Exemplo n.º 24
0
void CParticles::Destroy( void )
{
	InvalidateDeviceObjects();
	SAFE_RELEASE( m_pParticleTexture );
	SAFE_DELETE_ARRAY( m_pPool );
}
Exemplo n.º 25
0
//-----------------------------------------------------------------------------
// Name: ~CD3DFont()
// Desc: Font class destructor
//-----------------------------------------------------------------------------
CD3DFont::~CD3DFont()
{
    InvalidateDeviceObjects();
    DeleteDeviceObjects();
}
Exemplo n.º 26
0
HRESULT CDirect3D::Resize3DEnvironment(void)
{
    // Release all vidmem objects
    HRESULT hr;

#if LOG_D3D
    LOG_MSG("D3D:Resize3DEnvironment() called");
#endif

    if(FAILED(hr=InvalidateDeviceObjects())) {
	LOG_MSG("D3D:Failed to invalidate objects");
	return hr;
    }

    // Reset the device
reset_device:
    Bitu i = 20;
    // Don't bother too much, when device is already lost
    if(deviceLost) i = 5;
    deviceLost = false;

    if(FAILED(hr=pD3DDevice9->Reset(&d3dpp))) {
	if(hr==D3DERR_DEVICELOST) {
	    while((hr=pD3DDevice9->TestCooperativeLevel()) != D3DERR_DEVICENOTRESET) {
		if(hr==D3DERR_DRIVERINTERNALERROR) {
		    LOG_MSG("D3D:Driver internal error when resetting device!");
		    return hr;
		}
#if LOG_D3D
		LOG_MSG("D3D:Wait for D3D device to become available...");
#endif
		Sleep(50); i--;
		if(i == 0) {
		    deviceLost = true;
#if LOG_D3D
		    LOG_MSG("D3D:Giving up on D3D wait...");
#endif
		    // Return ok or dosbox will quit, we'll try to reset the device later
		    return S_OK;
		}
	    }
#if LOG_D3D
	    LOG_MSG("D3D:Performing another reset...");
#endif
	    goto reset_device;
	} else {
	    LOG_MSG("D3D:Failed to reset device!");
	    return hr;
	}
    }

	backbuffer_clear_countdown = 2;
	if (d3dpp.BackBufferCount == 2) backbuffer_clear_countdown++;

#if 0
    // Clear all backbuffers
    pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    pD3DDevice9->Present(NULL, NULL, NULL, NULL);
    pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    if(d3dpp.BackBufferCount == 2) {
	pD3DDevice9->Present(NULL, NULL, NULL, NULL);
	pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    }
#endif

#if LOG_D3D
    LOG_MSG("D3D:Mode: %dx%d (x %.2fx%.2f) --> scaled size: %dx%d", dwWidth, dwHeight,
		    (float)dwScaledWidth/dwWidth, (float)dwScaledHeight/dwHeight, dwScaledWidth, dwScaledHeight);
#endif

    return RestoreDeviceObjects();
}
Exemplo n.º 27
0
RenderHandler::~RenderHandler()
{
	InvalidateDeviceObjects();
}
Exemplo n.º 28
0
	~ModelData()
	{
		InvalidateDeviceObjects();
	}
Exemplo n.º 29
0
RenderObj::~RenderObj() {
    InvalidateDeviceObjects();
}