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:
parent
523337ea20
commit
c913f00d21
@ -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)
|
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)
|
ADD_DEFINITIONS(-D_AFXDLL)
|
||||||
SET(CMAKE_MFC_FLAG 2)
|
SET(REQUIRE_WINMAIN_FLAG 1)
|
||||||
|
|
||||||
#### end var setup ###
|
#### end var setup ###
|
||||||
#SETUP_EXAMPLE(osgviewerMFC)
|
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()
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
cOSG::cOSG(HWND hWnd) :
|
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
|
// 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
|
// if you have multiple OSG windows up
|
||||||
// and you exit one then all stop rendering
|
// and you exit one then all stop rendering
|
||||||
AfxMessageBox("Exit Rendering Thread");
|
AfxMessageBox("Exit Rendering Thread");
|
||||||
|
|
||||||
|
// Set Done to indicate that thread has exited
|
||||||
|
osg->Done(true);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,14 @@ public:
|
|||||||
void SetupCamera(void);
|
void SetupCamera(void);
|
||||||
void PreFrameUpdate(void);
|
void PreFrameUpdate(void);
|
||||||
void PostFrameUpdate(void);
|
void PostFrameUpdate(void);
|
||||||
|
void Done(bool value) { mDone = value; }
|
||||||
|
bool Done(void) { return mDone; }
|
||||||
static void Render(void* ptr);
|
static void Render(void* ptr);
|
||||||
|
|
||||||
osgViewer::Viewer* getViewer() { return mViewer.get(); }
|
osgViewer::Viewer* getViewer() { return mViewer.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool mDone;
|
||||||
std::string m_ModelName;
|
std::string m_ModelName;
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
||||||
|
@ -77,13 +77,11 @@ void CMFC_OSG_MDIView::OnDestroy()
|
|||||||
// Make sure OSG was created before we try to close it.
|
// Make sure OSG was created before we try to close it.
|
||||||
if(mOSG)
|
if(mOSG)
|
||||||
{
|
{
|
||||||
// Force osg Viewer to shut down
|
|
||||||
mOSG->getViewer()->setDone(true);
|
|
||||||
|
|
||||||
// Wait while the Viewer closes
|
// 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
|
// Remove mOSG
|
||||||
|
Loading…
Reference in New Issue
Block a user