Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r607 - in branches/itanium2: Core/Shm Engine/Display StandAlone
- Date: Fri, 7 Oct 2005 18:50:27 -0600 (MDT)
Author: abe
Date: Fri Oct 7 18:50:26 2005
New Revision: 607
Modified:
branches/itanium2/Core/Shm/MFStreamData.cc
branches/itanium2/Engine/Display/OpenGLDisplay.cc
branches/itanium2/StandAlone/mf_stream_test.cc
Log:
Added GLX rendering to mf_stream_test. Hard coded 2fps refresh. It looks like
the manta side of shm image display is working.
bin/manta -np 8 -scene "lib/libscene_boeing777.so( -file
/dev/shm/cockpit.v3c1 -np 8 )" -ui "camerapath( -file cockpit-path1.txt
-behavior loop )" -ui null -imagedisplay "mf( -key 1000 )" &
bin/mf_stream_test -key 1000 -x
M Core/Shm/MFStreamData.cc
M StandAlone/mf_stream_test.cc
M Engine/Display/OpenGLDisplay.cc
Modified: branches/itanium2/Core/Shm/MFStreamData.cc
==============================================================================
--- branches/itanium2/Core/Shm/MFStreamData.cc (original)
+++ branches/itanium2/Core/Shm/MFStreamData.cc Fri Oct 7 18:50:26 2005
@@ -174,11 +174,7 @@
// Naive copy
for (int i=0;i<total;++i) {
- // dest[i] = src[i];
- dest[i].r = 0;
- dest[i].g = 255;
- dest[i].b = 255;
- dest[i].a = 255;
+ dest[i] = src[i];
}
}
Modified: branches/itanium2/Engine/Display/OpenGLDisplay.cc
==============================================================================
--- branches/itanium2/Engine/Display/OpenGLDisplay.cc (original)
+++ branches/itanium2/Engine/Display/OpenGLDisplay.cc Fri Oct 7 18:50:26
2005
@@ -42,14 +42,14 @@
if(args[i] == "-parentWindow"){
long window;
if(!getLongArg(i, args, window))
- throw IllegalArgument("OpenGLDisplay -parentWindow", i, args);
+ throw new IllegalArgument("OpenGLDisplay -parentWindow", i, args);
else
parentWindow = static_cast<Window>(window);
} else if(args[i] == "-displayProc"){
if(!getIntArg(i, args, displayProc))
- throw IllegalArgument("OpenGLDisplay -displayProc", i, args);
+ throw new IllegalArgument("OpenGLDisplay -displayProc", i, args);
if(displayProc < 0)
- throw IllegalValue<int>("Display processor should be >= 0",
displayProc);
+ throw new IllegalValue<int>("Display processor should be >= 0",
displayProc);
} else {
throw IllegalArgument("OpenGLDisplay", i, args);
}
@@ -92,12 +92,12 @@
// Open the display and make sure it has opengl
dpy = XOpenDisplay(NULL);
if(!dpy)
- throw InternalError("Error opening display", __FILE__, __LINE__ );
+ throw new 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__
);
+ throw new InternalError("GL extension NOT available!\n", __FILE__,
__LINE__ );
}
int screen=DefaultScreen(dpy);
@@ -127,7 +127,7 @@
vi = glXChooseVisual(dpy, screen, &attribList[0]);
if(!vi){
// Cannot find anything suitable
- throw InternalError("Error selecting OpenGL visual", __FILE__,
__LINE__ );
+ throw new InternalError("Error selecting OpenGL visual", __FILE__,
__LINE__ );
}
}
@@ -181,7 +181,7 @@
XFree(vi);
if(!glXMakeCurrent(dpy, win, cx))
- throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+ throw new InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
glClearColor(.05, .1, .2, 0);
glClear(GL_COLOR_BUFFER_BIT);
@@ -191,13 +191,13 @@
// 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__ );
+ throw new InternalError("getX11Font failed!\n", __FILE__, __LINE__ );
fontbase = XHelper::getGLFont(fontInfo);
if (fontbase == 0)
- throw InternalError("getGLFont failed!\n", __FILE__, __LINE__ );
+ throw new InternalError("getGLFont failed!\n", __FILE__, __LINE__ );
if(!glXMakeCurrent(dpy, None, NULL))
- throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+ throw new InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
}
void OpenGLDisplay::displayImage(const DisplayContext& context,
Modified: branches/itanium2/StandAlone/mf_stream_test.cc
==============================================================================
--- branches/itanium2/StandAlone/mf_stream_test.cc (original)
+++ branches/itanium2/StandAlone/mf_stream_test.cc Fri Oct 7 18:50:26
2005
@@ -1,22 +1,177 @@
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+#include <GL/glu.h>
+#include <vector>
#include <string>
#include <iostream>
#include <Core/Shm/MFStreamData.h>
#include <SCIRun/Core/Exceptions/Exception.h>
+#include <SCIRun/Core/Exceptions/InternalError.h>
#include <SCIRun/Core/Thread/Time.h>
using namespace std;
using namespace Manta;
+using namespace SCIRun;
+
+
+Window parent;
+Window win;
+Display* dpy;
+int screen;
+GLXContext cx;
+
+void createWindow( MFStreamData *stream_data ) {
+
+ // Open the display and make sure it has opengl
+ dpy = XOpenDisplay(NULL);
+ if(!dpy)
+ throw new InternalError("Error opening display", __FILE__, __LINE__ );
+
+ int error, event;
+ if ( !glXQueryExtension( dpy, &error, &event) ) {
+ XCloseDisplay(dpy);
+ dpy=0;
+ throw new InternalError("GL extension NOT available!\n", __FILE__,
__LINE__ );
+ }
+
+ int screen=DefaultScreen(dpy);
+ // Form the criteria for the
+ vector<int> attribList;
+ attribList.push_back(GLX_RGBA);
+ attribList.push_back(GLX_RED_SIZE); attribList.push_back(1);
+ attribList.push_back(GLX_GREEN_SIZE); attribList.push_back(1);
+ attribList.push_back(GLX_BLUE_SIZE); attribList.push_back(1);
+ attribList.push_back(GLX_ALPHA_SIZE); attribList.push_back(0);
+ attribList.push_back(GLX_DEPTH_SIZE); attribList.push_back(0);
+
+ attribList.push_back(GLX_DOUBLEBUFFER); // This must be the last one
+ attribList.push_back(None);
+
+ XVisualInfo* vi = glXChooseVisual(dpy, screen, &attribList[0]);
+ if(!vi){
+ // We failed to choose a visual. Try again without the double-buffer
flag
+ attribList.pop_back();
+ attribList.pop_back();
+ attribList.push_back(None);
+ vi = glXChooseVisual(dpy, screen, &attribList[0]);
+ if(!vi){
+ // Cannot find anything suitable
+ throw new InternalError("Error selecting OpenGL visual", __FILE__,
__LINE__ );
+ }
+ }
+
+ Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, screen),
+ vi->visual, AllocNone);
+
+ XSetWindowAttributes atts;
+ int flags=CWColormap|CWEventMask|CWBackPixmap|CWBorderPixel;
+ atts.background_pixmap = None;
+ atts.border_pixmap = None;
+ atts.border_pixel = 0;
+ atts.colormap=cmap;
+ atts.event_mask=StructureNotifyMask;
+
+ parent = RootWindow(dpy, screen);
+
+ // Determine resolution
+ int xres, yres;
+ xres = stream_data->xres;
+ yres = stream_data->yres;
+
+ win = XCreateWindow(dpy, parent, 0, 0, xres, yres, 0, vi->depth,
+ InputOutput, vi->visual, flags, &atts);
+
+ XMapWindow(dpy, win);
+
+ // Wait for the window to appear before proceeding
+ for(;;){
+ XEvent e;
+ XNextEvent(dpy, &e);
+ if(e.type == MapNotify)
+ break;
+ }
+
+ // Turn off events from this window
+ atts.event_mask = 0;
+ XChangeWindowAttributes(dpy, win, CWEventMask, &atts);
+
+ cx = glXCreateContext(dpy, vi, NULL, True);
+ XFree(vi);
+
+ if(!glXMakeCurrent(dpy, win, cx))
+ throw new InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+
+ glClearColor(1.0, 1.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glXSwapBuffers(dpy, win);
+ glFinish();
+};
+
+void closeWindow() {
+
+ if(win) {
+ XDestroyWindow(dpy, win);
+ }
+ if(dpy) {
+ XCloseDisplay(dpy);
+ }
+}
+
+void display( MFStreamData *stream_data ) {
+
+ int xres, yres;
+ xres = stream_data->xres;
+ yres = stream_data->yres;
+
+ if(!glXMakeCurrent(dpy, win, cx))
+ throw new InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__ );
+
+ // Setup the camera.
+ glViewport(0, 0, xres, yres);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0, xres, 0, yres);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.375, 0.375, 0.0);
+
+ // Draw the pixels.
+ glDrawBuffer(GL_BACK);
+ glRasterPos2i(0,0);
+ glDrawPixels( xres, yres, GL_RGBA, GL_UNSIGNED_BYTE,
+ stream_data->pixelPool[stream_data->frontBuffer] );
+
+ glFinish();
+
+ // Swap buffers.
+ glXSwapBuffers(dpy, win);
+ // Check for opengl errors.
+ GLenum errcode = glGetError();
+ if(errcode != GL_NO_ERROR) {
+ std::cerr << "OpenGLDisplay: "
+ << __FILE__ << ":"
+ << __LINE__ << " error: "
+ << gluErrorString(errcode) << std::endl;
+ }
+
+ // Suck up X events to keep opengl happy
+ while (XPending(dpy)) {
+ XEvent e;
+ XNextEvent(dpy, &e);
+ }
+
+}
int main( int argc, char **argv ) {
int key = 0;
-
+ bool use_x = false;
// Parse args.
for (int i=0;i<argc;++i) {
@@ -25,27 +180,54 @@
if (arg == "-key") {
key = atoi( argv[++i] );
}
+ if (arg == "-x") {
+ use_x = true;
+ }
}
+ // Check that we have a key
+ if (key == 0) {
+ std::cerr << "Usage: -key <id> [-x]" << std::endl;
+ return 1;
+ }
+
+ // Attach to an existing shared memory segment.
MFStreamData *stream_data;
try {
+
stream_data = new(key, false) MFStreamData;
std::cerr << "Acquired Successfully" << std::endl;
- for (int i=0;i<10;++i) {
- std::cerr << "front: " << stream_data->frontBuffer << " back: " <<
stream_data->backBuffer << std::endl;
- SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.5 );
+
+ // Create a display window.
+ if (use_x) {
+ createWindow( stream_data );
+
+ while (1) {
+ display( stream_data );
+ SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.5 );
+ };
+
+ closeWindow();
+ }
+
+ // Otherwise output to console only.
+ else {
+ for (int i=0;i<5;++i) {
+ std::cerr << "front: " << stream_data->frontBuffer << " back: " <<
stream_data->backBuffer << std::endl;
+ SCIRun::Time::waitUntil( SCIRun::Time::currentSeconds()+0.5 );
+ }
}
delete stream_data;
+ std::cerr << "Detached/Removed successfully." << std::endl;
}
+
+ // Catch any exceptions.
catch (SCIRun::Exception *e) {
std::cerr << "Caught Exception: " << e->message() << std::endl;
}
-
-
-
return 1;
};
- [MANTA] r607 - in branches/itanium2: Core/Shm Engine/Display StandAlone, abe, 10/07/2005
Archive powered by MHonArc 2.6.16.