Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r497 - in branches/AFR: Core Core/XUtils Engine/Display Image


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r497 - in branches/AFR: Core Core/XUtils Engine/Display Image
  • Date: Thu, 25 Aug 2005 12:46:50 -0600 (MDT)

Author: abe
Date: Thu Aug 25 12:46:49 2005
New Revision: 497

Added:
   branches/AFR/Core/XUtils/
      - copied from r496, trunk/Core/XUtils/
Modified:
   branches/AFR/Core/CMakeLists.txt
   branches/AFR/Engine/Display/OpenGLDisplay.cc
   branches/AFR/Engine/Display/OpenGLDisplay.h
   branches/AFR/Image/SimpleImage.h
Log:
Merged more changes from trunk so that existing afr code works

Modified: branches/AFR/Core/CMakeLists.txt
==============================================================================
--- branches/AFR/Core/CMakeLists.txt    (original)
+++ branches/AFR/Core/CMakeLists.txt    Thu Aug 25 12:46:49 2005
@@ -36,3 +36,8 @@
 ADD_LIBRARY (Manta_Core ${CORE_SOURCES})
 
 TARGET_LINK_LIBRARIES(Manta_Core SCIRun_Core)
+
+# The Manta_Core_XUtils library
+ADD_LIBRARY (Manta_Core_XUtils XUtils/XHelper.cc)
+TARGET_LINK_LIBRARIES(Manta_Core_XUtils SCIRun_Core Manta_Core)
+TARGET_LINK_LIBRARIES(Manta_Core_XUtils ${OPENGL_LIBRARIES} ${X11_LIBRARIES})

Modified: branches/AFR/Engine/Display/OpenGLDisplay.cc
==============================================================================
--- branches/AFR/Engine/Display/OpenGLDisplay.cc        (original)
+++ branches/AFR/Engine/Display/OpenGLDisplay.cc        Thu Aug 25 12:46:49 
2005
@@ -2,7 +2,7 @@
 #include <Core/Thread/Thread.h>
 
 #include <Engine/Display/OpenGLDisplay.h>
-#include <Engine/Display/XHelper.h>
+#include <Core/XUtils/XHelper.h>
 #include <Core/Exceptions/IllegalArgument.h>
 #include <Core/Util/Args.h>
 #include <Image/NullImage.h>
@@ -61,6 +61,7 @@
   win = 0;
   // If this is zero then the value hasn't been used yet.
   last_frame_time = 0;
+  alwaysMakeContextCurrent = false;
 }
 
 OpenGLDisplay::~OpenGLDisplay()
@@ -85,19 +86,27 @@
     old_xres = xres;
     old_yres = yres;
   }
+  if(context.getMultipleGLWindows())
+  {
+    alwaysMakeContextCurrent = true;
+  }
 }
 
 void OpenGLDisplay::createWindow(int xres, int yres, XWindow* masterWindow)
 {
+  XHelper::Xlock.lock();
   // Open the display and make sure it has opengl
   dpy = XOpenDisplay(NULL);
-  if(!dpy)
-    throw InternalError("Error opening display", __FILE__, __LINE__ );
+  if(!dpy) {
+    XHelper::Xlock.unlock();
+    throw InternalError("Error opening display", __FILE__, __LINE__);
+  }
   int error, event;
   if ( !glXQueryExtension( dpy, &error, &event) ) {
     XCloseDisplay(dpy);
     dpy=0;
-    throw InternalError("GL extension NOT available!\n", __FILE__, __LINE__ 
);
+    XHelper::Xlock.unlock();
+    throw InternalError("GL extension NOT available!\n", __FILE__, __LINE__);
   }
   int screen=DefaultScreen(dpy);
     
@@ -121,7 +130,8 @@
     vi = glXChooseVisual(dpy, screen, &attribList[0]);
     if(!vi){
       // Cannot find anything suitable
-      throw InternalError("Error selecting OpenGL visual", __FILE__, 
__LINE__ );
+      XHelper::Xlock.unlock();
+      throw InternalError("Error selecting OpenGL visual", __FILE__, 
__LINE__);
     }
   }
 
@@ -174,9 +184,11 @@
   cx = glXCreateContext(dpy, vi, NULL, True);
   XFree(vi);
 
-  if(!glXMakeCurrent(dpy, win, cx))
-    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
-
+  if(!glXMakeCurrent(dpy, win, cx)) {
+    XHelper::Xlock.unlock();
+    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+  }
+    
   glClearColor(.05, .1, .2, 0);
   glClear(GL_COLOR_BUFFER_BIT);
   glXSwapBuffers(dpy, win);
@@ -184,14 +196,22 @@
 
   // Get the fonts.  You need to call this with a current GL context.
   fontInfo = XHelper::getX11Font(dpy);
-  if (!fontInfo)
-    throw InternalError("getX11Font failed!\n", __FILE__, __LINE__ );
+  if (!fontInfo) {
+    XHelper::Xlock.unlock();
+    throw InternalError("getX11Font failed!\n", __FILE__, __LINE__);
+  }
   fontbase = XHelper::getGLFont(fontInfo);
-  if (fontbase == 0)
-    throw InternalError("getGLFont failed!\n", __FILE__, __LINE__ );
+  if (fontbase == 0) {
+    XHelper::Xlock.unlock();
+    throw InternalError("getGLFont failed!\n", __FILE__, __LINE__);
+  }
 
-  if(!glXMakeCurrent(dpy, None, NULL))
-    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+  if(!glXMakeCurrent(dpy, None, NULL)) {
+    XHelper::Xlock.unlock();
+    throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
+  }
+  
+  XHelper::Xlock.unlock();
 }
 
 void OpenGLDisplay::displayImage(const DisplayContext& context,
@@ -211,9 +231,9 @@
   // Compute the framerate
   double currentTime = SCIRun::Time::currentSeconds();
 
-  if(!madeCurrent){
+  if(!madeCurrent || alwaysMakeContextCurrent){
     if(!glXMakeCurrent(dpy, win, cx))
-      throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+      throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
     madeCurrent=true;
   }
   bool stereo;
@@ -226,7 +246,6 @@
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.375, 0.375, 0.0);
-
   if(typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)){
     const SimpleImage<RGBA8Pixel>* si = dynamic_cast<const 
SimpleImage<RGBA8Pixel>*>(image);
     if(stereo){
@@ -284,7 +303,8 @@
       glDrawPixels(xres, yres, GL_RGB, GL_FLOAT, si->getRaw(0));
     }
   } else {
-    throw InternalError("Unknown image type in OpenGLDisplay", __FILE__, 
__LINE__ );
+    throw InternalError("Unknown image type in OpenGLDisplay",
+                        __FILE__, __LINE__);
   }
 
   display_frame_rate(1.0/(currentTime-last_frame_time));

Modified: branches/AFR/Engine/Display/OpenGLDisplay.h
==============================================================================
--- branches/AFR/Engine/Display/OpenGLDisplay.h (original)
+++ branches/AFR/Engine/Display/OpenGLDisplay.h Thu Aug 25 12:46:49 2005
@@ -45,6 +45,7 @@
 
     // Used to display the frame rate on the screen
     void display_frame_rate(double framerate);
+    bool alwaysMakeContextCurrent;
   };
 }
 

Modified: branches/AFR/Image/SimpleImage.h
==============================================================================
--- branches/AFR/Image/SimpleImage.h    (original)
+++ branches/AFR/Image/SimpleImage.h    Thu Aug 25 12:46:49 2005
@@ -104,6 +104,7 @@
   template<class Pixel>
   void SimpleImage<Pixel>::set(const Fragment& fragment)
   {
+    //cout << "inside set image" << endl;
     if(fragment.getFlags() & (Fragment::ConsecutiveX|Fragment::ConstantEye) 
          == (Fragment::ConsecutiveX|Fragment::ConstantEye)){
       int nf = fragment.getSize();
@@ -113,6 +114,8 @@
     } else {
       for(int i=0;i<fragment.getSize();i++){
        const Fragment::Element& f = fragment.get(i);
+        //cout << "setting " << f.x << ", " << f.y << endl;
+        if(f.x<xres && f.x>=0 && f.y<yres && f.y>=0)
        convertToPixel(eyeStart[f.which_eye][f.y][f.x], f.color.convertRGB());
       }
     }




  • [MANTA] r497 - in branches/AFR: Core Core/XUtils Engine/Display Image, abe, 08/25/2005

Archive powered by MHonArc 2.6.16.

Top of page