From Michael Hartman, "CMakeLists.txt:

Changed this back to setup_example since WIN32 flag is now supported.

 

MFC_OSG.h:

   Added flag to indicate when the rendering thread has exited.

 

MFC_OSG.cpp:

   Code modifications to support rendering flag thread exit.

 

MFC_OSG_MDIView.cpp:

   Change to OnDestroy function to wait until we get render thread exit flag is true before we close the window.

 

 

Main Exit Process:

   User presses escape button

   Viewer captures escape button and stops threading etc.

   Viewer sets Done when shutdown is complete

   MFC Render Thread monitors viewer->done for true

   MFC Render Thread exits while loop and sets MFC Done flag

   MFC View Window monitors MFC Done flag and then closes/destroys the window

"
This commit is contained in:
Robert Osfield 2007-06-01 21:28:18 +00:00
parent 523337ea20
commit c913f00d21
4 changed files with 12 additions and 33 deletions

View File

@ -2,32 +2,7 @@ SET(TARGET_SRC MFC_OSG_MDI.cpp MFC_OSG_MDI.rc MFC_OSG_MDIDoc.cpp MFC_OSG_MDIView
SET(TARGET_H MFC_OSG_MDI.h MFC_OSG_MDIDoc.h MFC_OSG_MDIView.h stdafx.h MFC_OSG.h MainFrm.h ChildFrm.h Resource.h)
ADD_DEFINITIONS(-D_AFXDLL)
SET(CMAKE_MFC_FLAG 2)
SET(REQUIRE_WINMAIN_FLAG 1)
#### end var setup ###
#SETUP_EXAMPLE(osgviewerMFC)
#
#Extracted from SETUP_EXAMPLES
#
SET(TARGET_NAME osgviewerMFC)
#
#Extracted from SETUP_EXE
#
IF(NOT TARGET_TARGETNAME)
SET(TARGET_TARGETNAME "${TARGET_DEFAULT_PREFIX}${TARGET_NAME}")
ENDIF(NOT TARGET_TARGETNAME)
IF(NOT TARGET_LABEL)
SET(TARGET_LABEL "${TARGET_DEFAULT_LABEL_PREFIX} ${TARGET_NAME}")
ENDIF(NOT TARGET_LABEL)
# This is the important line because it adds WIN32 which tells CMake that this is an MFC/Windows appliation
# and not a console application
ADD_EXECUTABLE(${TARGET_TARGETNAME} WIN32 ${TARGET_SRC} ${TARGET_H})
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}")
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME})
SETUP_LINK_LIBRARIES()
SETUP_EXAMPLE(osgviewerMFC)

View File

@ -5,7 +5,7 @@
cOSG::cOSG(HWND hWnd) :
m_hWnd(hWnd)
m_hWnd(hWnd), mDone(false)
{
//
// We must set the pixelformat before we can create the OSG Rendering Surface
@ -182,4 +182,7 @@ void cOSG::Render(void* ptr)
// if you have multiple OSG windows up
// and you exit one then all stop rendering
AfxMessageBox("Exit Rendering Thread");
// Set Done to indicate that thread has exited
osg->Done(true);
}

View File

@ -25,11 +25,14 @@ public:
void SetupCamera(void);
void PreFrameUpdate(void);
void PostFrameUpdate(void);
void Done(bool value) { mDone = value; }
bool Done(void) { return mDone; }
static void Render(void* ptr);
osgViewer::Viewer* getViewer() { return mViewer.get(); }
private:
bool mDone;
std::string m_ModelName;
HWND m_hWnd;
osg::ref_ptr<osgViewer::Viewer> mViewer;

View File

@ -77,13 +77,11 @@ void CMFC_OSG_MDIView::OnDestroy()
// Make sure OSG was created before we try to close it.
if(mOSG)
{
// Force osg Viewer to shut down
mOSG->getViewer()->setDone(true);
// Wait while the Viewer closes
while(!mOSG->getViewer()->done())
while(!mOSG->Done())
{
Sleep(0); // Allow others processor time
Sleep(10); // Allow others processor time
}
// Remove mOSG