bool CSingleView::SwitchWindowed(void)
{
// Get current mode
VIDEOMODE stCurrMode;
this->GetVideoMode(&stCurrMode);
stCurrMode.bWindowed = !stCurrMode.bWindowed;
// a) fullscreen => windowed
if (stCurrMode.bWindowed)
{
stCurrMode.enBBFormat = this->m_stDesktopMode.enFormat;
stCurrMode.enAdapterFormat = this->m_stDesktopMode.enFormat;
}
// b) windowed => fullscreen
else
{
stCurrMode.wHrzRes = this->m_wModeWidth;
stCurrMode.wVrtRes = this->m_wModeHeight;
stCurrMode.enBBFormat = this->m_enModeFormat;
stCurrMode.enAdapterFormat = this->m_enModeFormat;
// Resize depth buffer if necessary
if (this->m_pcDepthStencil != NULL)
{
if (this->m_wDSWidth < this->m_wModeWidth)
this->m_wDSWidth = this->m_wModeWidth;
if (this->m_wDSHeight < this->m_wModeHeight)
this->m_wDSHeight = this->m_wModeHeight;
}
}
this->AdjustRenderWindow();
if (!this->InitalizeMode(&stCurrMode, this->m_RenderParams.enSwapEffect,
this->m_wDSWidth, this->m_wDSHeight, this->m_RenderParams.nBBCount,
this->m_hFocusWnd, this->m_RenderParams.dwPresInterval, this->m_RenderParams.dwFlags,
this->m_RenderParams.dwFlags)
return false
// Re-position the window
if(stCurrMode.bWindowed)
SetWindowPos((HWND) this->m_apcRenderViews[0]->GetRenderWindow(), HWND_NOTOPMOST,
this->m_stRect.dwLeft, this->m_stRect.dwTop, this->m_stRect.dwRight -
this->m_stRect.dwLeft, this->m_stRect.dwBottom - this->m_stRect.dwTop,
SWP_SHOWWINDOW);
return true;
}
void CSingleView::AdjustRenderWindow(void)
{
if (!this->m_RenderParams.bWindowed)
{
SetWindowLong((HWND) this->m_apcRenderViews[0]->GetRenderWindow(), GWL_STYLE,
m_dwWindowStyle);
}
else
{
SetWindowLong((HWND) this->m_apcRenderViews[0]->GetRenderWindow(), GWL_STYLE,
WS_POPUP | WS_SYSMENU | WS_VISIBLE);
}
return ;
}
Help: Switching Windowed - Fullscreen takes too long
Hi,
I've got a switching method for toggling windowed - fullscreen, which works good - if I don't render anything. The time needed to switch then is hardly 1 second.
If I render a simple cube, it takes almost 10 seconds!
But there are neither D3D errors nor warnings, and the device is never lost.
Here are my switching methods:
Can someone tell me why it takes 10 seconds if I render?
I don't know what you should do about your problem, but I would like to point out that your code includes a lot of unnecesary characters. You keep writing
this->(some class function)
The
this->
is totally unnecessary; it is implied. For example, on line 7, you wrote
this->GetVideoMode(&stCurrMode);
Unless you have another function in your program called GetVideoMode() with a VIDEOMODE object as its only argument, you can and should simply write
GetVideoMode(&stCurrMode);
The this keyword does not exist to allow one to access class member variables and functions inside of member functions -- they can be accessed directly as I showed above. The purpose of the this keyword is mostly so that if an object needs a pointer to itself to pass to another non-member function or to initialize some variable external to the class object, it has one. Unless you have something really weird in the rest of your code, the following code should work just as well as what you have in your post.
EDIT: Oops! I forgot to actually remove the
this->
stuff from my revised source code. Now it should be ok.
this->(some class function)
The
this->
is totally unnecessary; it is implied. For example, on line 7, you wrote
this->GetVideoMode(&stCurrMode);
Unless you have another function in your program called GetVideoMode() with a VIDEOMODE object as its only argument, you can and should simply write
GetVideoMode(&stCurrMode);
The this keyword does not exist to allow one to access class member variables and functions inside of member functions -- they can be accessed directly as I showed above. The purpose of the this keyword is mostly so that if an object needs a pointer to itself to pass to another non-member function or to initialize some variable external to the class object, it has one. Unless you have something really weird in the rest of your code, the following code should work just as well as what you have in your post.
bool CSingleView::SwitchWindowed(void){ // Get current mode VIDEOMODE stCurrMode; GetVideoMode(&stCurrMode); stCurrMode.bWindowed = !stCurrMode.bWindowed; // a) fullscreen => windowed if (stCurrMode.bWindowed) { stCurrMode.enBBFormat = m_stDesktopMode.enFormat; stCurrMode.enAdapterFormat = m_stDesktopMode.enFormat; } // b) windowed => fullscreen else { stCurrMode.wHrzRes = m_wModeWidth; stCurrMode.wVrtRes = m_wModeHeight; stCurrMode.enBBFormat = m_enModeFormat; stCurrMode.enAdapterFormat = m_enModeFormat; // Resize depth buffer if necessary if (m_pcDepthStencil != NULL) { if (m_wDSWidth < m_wModeWidth) m_wDSWidth = m_wModeWidth; if (m_wDSHeight < m_wModeHeight) m_wDSHeight = m_wModeHeight; } } AdjustRenderWindow(); if (!InitalizeMode(&stCurrMode, m_RenderParams.enSwapEffect, m_wDSWidth, m_wDSHeight, m_RenderParams.nBBCount, m_hFocusWnd, m_RenderParams.dwPresInterval, m_RenderParams.dwFlags, m_RenderParams.dwFlags) return false // Re-position the window if(stCurrMode.bWindowed) SetWindowPos((HWND) m_apcRenderViews[0]->GetRenderWindow(), HWND_NOTOPMOST, m_stRect.dwLeft, m_stRect.dwTop, m_stRect.dwRight - m_stRect.dwLeft, m_stRect.dwBottom - m_stRect.dwTop, SWP_SHOWWINDOW); return true;}void CSingleView::AdjustRenderWindow(void){ if (!m_RenderParams.bWindowed) { SetWindowLong((HWND) m_apcRenderViews[0]->GetRenderWindow(), GWL_STYLE, m_dwWindowStyle); } else { SetWindowLong((HWND) m_apcRenderViews[0]->GetRenderWindow(), GWL_STYLE, WS_POPUP | WS_SYSMENU | WS_VISIBLE); } return ;}
EDIT: Oops! I forgot to actually remove the
this->
stuff from my revised source code. Now it should be ok.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement