00001 00002 /****************************************************************************\ 00003 * REQUIRED HEADERS * 00004 \****************************************************************************/ 00005 00006 #include "CGLRenderThread.h" 00007 #include "CGLSurface.h" 00008 00009 /****************************************************************************\ 00010 * PRIVATE DEFINITIONS * 00011 \****************************************************************************/ 00012 00013 /****************************************************************************\ 00014 * PUBLIC CLASS FUNCTIONS * 00015 \****************************************************************************/ 00016 00017 //CONSTRUCTOR 00018 CGLRenderThread::CGLRenderThread(CGLSurface *newSurface) 00019 : QThread(),render_flag(true),resize_flag(false),surface(newSurface) 00020 { 00021 assert( newSurface!=NULL || "Null Pointer was passed in Constructor CGLRenderThread!!"); 00022 } 00023 00024 //DESTRUCTOR 00025 CGLRenderThread::~CGLRenderThread() 00026 { 00027 00028 } 00029 00030 /****************************************************************************\ 00031 * PRIVATE CLASS FUNCTIONS * 00032 \****************************************************************************/ 00033 00034 void CGLRenderThread::run( ) 00035 { 00036 // make the render context current for this thread 00037 surface->render_mutex.lock(); 00038 surface->makeCurrent(); 00039 00040 //initialize 00041 if(!surface->initialized){ 00042 surface->onInitialize(); 00043 surface->initialized = true; 00044 } 00045 00046 while(render_flag) 00047 { 00048 //resize the GL viewport if requested 00049 if (resize_flag){ 00050 surface->onResize(); 00051 resize_flag = false; 00052 } 00053 00054 //do all the rendering - swapBuffers should be called 00055 if(surface->bRenderWithOverlay){ 00056 surface->onInitialize(); 00057 surface->onOverlayDraw(surface->pPainter); 00058 }else{ 00059 surface->onDraw(); 00060 } 00061 00062 //release the GL render context for other threads 00063 surface->doneCurrent(); 00064 00065 //wait until another render is issued 00066 surface->render_condition.wait(&surface->render_mutex); 00067 00068 //get the GL render context back 00069 surface->makeCurrent(); 00070 } 00071 00072 //call the virtual function for deinitialisation every time the Render is stoped 00073 surface->onFinishRendering(); 00074 00075 //unlock the render mutex before exit 00076 surface->doneCurrent(); 00077 surface->render_mutex.unlock(); 00078 }