Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1018 - in trunk: Engine/Display fox/dm_demo
- Date: Thu, 27 Apr 2006 23:33:20 -0600 (MDT)
Author: sparker
Date: Thu Apr 27 23:33:18 2006
New Revision: 1018
Modified:
trunk/Engine/Display/CMakeLists.txt
trunk/Engine/Display/GLXImageDisplay.cc
trunk/Engine/Display/OpenGLDisplay.cc
trunk/Engine/Display/OpenGLDisplay.h
trunk/fox/dm_demo/dm_demo.cc
Log:
Merged GLXImageDisplay functionality into OpenGLDisplay
Modified: trunk/Engine/Display/CMakeLists.txt
==============================================================================
--- trunk/Engine/Display/CMakeLists.txt (original)
+++ trunk/Engine/Display/CMakeLists.txt Thu Apr 27 23:33:18 2006
@@ -2,8 +2,6 @@
SET (Manta_Display_SRCS
Display/FileDisplay.cc
Display/FileDisplay.h
- Display/GLXImageDisplay.cc
- Display/GLXImageDisplay.h
Display/MultiDisplay.cc
Display/MultiDisplay.h
Display/NullDisplay.cc
Modified: trunk/Engine/Display/GLXImageDisplay.cc
==============================================================================
--- trunk/Engine/Display/GLXImageDisplay.cc (original)
+++ trunk/Engine/Display/GLXImageDisplay.cc Thu Apr 27 23:33:18 2006
@@ -26,7 +26,12 @@
glx_drawable( glx_drawable_ ),
x_display( 0 )
{
-
+ int x = 0x12345678;
+ char* p = (char*)&x;
+ if(p[0] == 0x12)
+ big_endian = true;
+ else
+ big_endian = false;
}
GLXImageDisplay::GLXImageDisplay( bool use_stereo_, GLXDrawable
glx_drawable_ )
@@ -36,6 +41,12 @@
glx_drawable( glx_drawable_ ),
x_display( 0 )
{
+ int x = 0x12345678;
+ char* p = (char*)&x;
+ if(p[0] == 0x12)
+ big_endian = true;
+ else
+ big_endian = false;
}
GLXImageDisplay::~GLXImageDisplay() {
@@ -140,147 +151,73 @@
void GLXImageDisplay::displayImage( const DisplayContext &context, const
Image* image ) {
// Check to see if this processor should display the image.
- if (context.proc == 0) {
+ if (context.proc != 0)
+ return;
+ const SimpleImageBase* si = dynamic_cast<const SimpleImageBase*>(image);
+ if(!si)
+ return;
- // Determine the image resolution.
- int xres, yres;
- bool stereo;
+ // Determine the image resolution.
+ int xres, yres;
+ bool stereo;
- image->getResolution( stereo, xres, yres );
+ image->getResolution( stereo, xres, yres );
- // This code is from OpenGLImageDisplay.
- 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);
+ // This code is from OpenGLImageDisplay.
+ 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);
- if(typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)){
- const SimpleImage<RGBA8Pixel>* si = dynamic_cast<const
SimpleImage<RGBA8Pixel>*>(image);
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA, GL_UNSIGNED_BYTE,
si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- }
- } else if(typeid(*image) == typeid(SimpleImage<ABGR8Pixel>)){
- const SimpleImage<ABGR8Pixel>* si = dynamic_cast<const
SimpleImage<ABGR8Pixel>*>(image);
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_BYTE,
si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- }
- } else if(typeid(*image) == typeid(SimpleImage<ARGB8Pixel>)){
- const SimpleImage<ARGB8Pixel>* si = dynamic_cast<const
SimpleImage<ARGB8Pixel>*>(image);
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV,
si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV,
si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_ABGR_EXT, GL_UNSIGNED_INT_8_8_8_8_REV,
si->getRawPixels(0));
- }
- } else if(typeid(*image) == typeid(SimpleImage<RGB8Pixel>)){
- const SimpleImage<RGB8Pixel>* si = dynamic_cast<const
SimpleImage<RGB8Pixel>*>(image);
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_UNSIGNED_BYTE,
si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_UNSIGNED_BYTE,
si->getRawPixels(0));
- }
- } else if(typeid(*image) == typeid(SimpleImage<RGBAfloatPixel>)){
- const SimpleImage<RGBAfloatPixel>* si = dynamic_cast<const
SimpleImage<RGBAfloatPixel>*>(image);
-
-
///////////////////////////////////////////////////////////////////////////
- // Assuming this is a performance image: normalize the image values.
- int total_size = xres * yres;
- RGBAfloatPixel *pixel = si->getRawPixels(0);
-
- float max_p, min_p;
- max_p = min_p = pixel[0].r;
-
- // Determine min and max.
- for (int i=1;i<total_size;++i) {
- if (pixel[i].r > max_p) max_p = pixel[i].r;
- else if (pixel[i].r < min_p) min_p = pixel[i].r;
- }
-
- // Determine scale and bias.
- float scale = 1 / (max_p - min_p);
-
- for (int i=0;i<total_size;++i) {
- float v = (pixel[i].r - min_p) * scale;
- pixel[i].r = pixel[i].g = pixel[i].b = pixel[i].a = v;
- }
-
-
///////////////////////////////////////////////////////////////////////////
-
-
-
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA, GL_FLOAT, si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA, GL_FLOAT, si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGBA , GL_FLOAT, si->getRawPixels(0));
- }
- } else if(typeid(*image) == typeid(SimpleImage<RGBfloatPixel>)){
- const SimpleImage<RGBfloatPixel>* si = dynamic_cast<const
SimpleImage<RGBfloatPixel>*>(image);
- if(stereo){
- glDrawBuffer(GL_BACK_LEFT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_FLOAT, si->getRawPixels(0));
- glDrawBuffer(GL_BACK_RIGHT);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_FLOAT, si->getRawPixels(1));
- } else {
- glDrawBuffer(GL_BACK);
- glRasterPos2i(0,0);
- glDrawPixels(xres, yres, GL_RGB, GL_FLOAT, si->getRawPixels(0));
- }
- }
-
- // Output fps.
- // display_frame_rate( 1.0 );
-
- // Swap buffers.
- glXSwapBuffers( x_display, glx_drawable );
-
- // Check for any gl error.
- GLenum errcode = glGetError();
- if(errcode != GL_NO_ERROR) {
- std::cerr << "GLXImageDisplay: Error code from OpenGL: " <<
gluErrorString(errcode) << std::endl;
- }
+ GLenum format;
+ GLenum type;
+ if(typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)){
+ format = GL_RGBA;
+ type = GL_UNSIGNED_BYTE;
+ } else if(typeid(*image) == typeid(SimpleImage<RGB8Pixel>)){
+ format = GL_RGB;
+ type = GL_UNSIGNED_BYTE;
+ } else if(typeid(*image) == typeid(SimpleImage<ABGR8Pixel>)){
+ format = GL_ABGR_EXT;
+ type = GL_UNSIGNED_BYTE;
+ } else if(typeid(*image) == typeid(SimpleImage<ARGB8Pixel>)){
+ format = GL_BGRA;
+ type = big_endian?GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_INT_8_8_8_8;
+ } else if(typeid(*image) == typeid(SimpleImage<RGBAfloatPixel>)){
+ format = GL_RGBA;
+ type = GL_FLOAT;
+ } else if(typeid(*image) == typeid(SimpleImage<RGBfloatPixel>)){
+ format = GL_RGB;
+ type = GL_FLOAT;
+ } else {
+ return false;
+ }
+ if(stereo){
+ glDrawBuffer(GL_BACK_LEFT);
+ glRasterPos2i(0,0);
+ glDrawPixels(xres, yres, format, type, si->getRawData(0));
+ glDrawBuffer(GL_BACK_RIGHT);
+ glRasterPos2i(0,0);
+ glDrawPixels(xres, yres, format, type, si->getRawData(1));
+ } else {
+ glDrawBuffer(GL_BACK);
+ glRasterPos2i(0,0);
+ glDrawPixels(xres, yres, format, type, si->getRawData(0));
+ }
+
+ // Output fps.
+ // display_frame_rate( 1.0 );
+
+ // Swap buffers.
+ glXSwapBuffers( x_display, glx_drawable );
+
+ // Check for any gl error.
+ GLenum errcode = glGetError();
+ if(errcode != GL_NO_ERROR) {
+ std::cerr << "GLXImageDisplay: Error code from OpenGL: " <<
gluErrorString(errcode) << std::endl;
}
}
Modified: trunk/Engine/Display/OpenGLDisplay.cc
==============================================================================
--- trunk/Engine/Display/OpenGLDisplay.cc (original)
+++ trunk/Engine/Display/OpenGLDisplay.cc Thu Apr 27 23:33:18 2006
@@ -80,37 +80,59 @@
OpenGLDisplay::OpenGLDisplay(const vector<string>& args)
{
// Open X window
- parentWindow = 0;
- displayProc = 0;
- mode = "texture";
+ setDefaults();
int argc = (int)args.size();
for(int i=0;i<argc;i++){
if(args[i] == "-parentWindow"){
long window;
if(!getLongArg(i, args, window))
- throw new IllegalArgument("OpenGLDisplay -parentWindow", i, args);
+ throw IllegalArgument("OpenGLDisplay -parentWindow", i, args);
else
parentWindow = static_cast<Window>(window);
} else if(args[i] == "-displayProc"){
if(!getIntArg(i, args, displayProc))
- throw new IllegalArgument("OpenGLDisplay -displayProc", i, args);
+ throw IllegalArgument("OpenGLDisplay -displayProc", i, args);
if(displayProc < 0)
- throw new IllegalValue<int>("Display processor should be >= 0",
displayProc);
+ throw IllegalValue<int>("Display processor should be >= 0",
displayProc);
} else if(args[i] == "-mode"){
if(!getStringArg(i, args, mode))
- throw new IllegalArgument("OpenGLDisplay -mode", i, args);
+ throw IllegalArgument("OpenGLDisplay -mode", i, args);
if(mode != "image" && mode != "texture")
- throw new IllegalValue<string>("Illegal dispay mode", mode);
-
+ throw IllegalValue<string>("Illegal dispay mode", mode);
+ } else if(args[i] == "-displayFrameRate"){
+ displayFrameRate = true;
+ } else if(args[i] == "-nodisplayFrameRate"){
+ displayFrameRate = false;
} else {
throw IllegalArgument("OpenGLDisplay", i, args);
}
}
+ vi = 0;
+ win = 0;
+ setup();
+}
+
+OpenGLDisplay::OpenGLDisplay(XVisualInfo* visualInfo, Window window)
+{
+ setDefaults();
+ vi = visualInfo;
+ win = window;
+ setup();
+}
+
+void OpenGLDisplay::setDefaults()
+{
+ parentWindow = 0;
+ displayProc = 0;
+ displayFrameRate = true;
+ mode = "texture";
+}
+void OpenGLDisplay::setup()
+{
madeCurrent = false;
windowOpen = false;
dpy = 0;
- win = 0;
// If this is zero then the value hasn't been used yet.
last_frame_time = 0;
need_texids = true;
@@ -181,7 +203,8 @@
attribList.push_back(GLX_DOUBLEBUFFER); // This must be the last one
attribList.push_back(None);
- XVisualInfo* vi = glXChooseVisual(dpy, screen, &attribList[0]);
+ bool free_vi = (vi == 0?true:false);
+ vi = glXChooseVisual(dpy, screen, &attribList[0]);
if(!vi){
// We failed to choose a visual. Try again without the double-buffer
flag
attribList.pop_back();
@@ -195,60 +218,66 @@
}
}
- 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;
- Window parent = parentWindow;
- if(!parent){
- if(masterWindow){
- parent = masterWindow->window;
+ if(!win){
+ 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;
+ Window parent = parentWindow;
+ if(!parent){
+ if(masterWindow){
+ parent = masterWindow->window;
+ } else {
+ parent = RootWindow(dpy, screen);
+ }
}
- else
- parent = RootWindow(dpy, screen);
- }
- win=XCreateWindow(dpy, parent, 0, 0, xres, yres, 0, vi->depth,
- InputOutput, vi->visual, flags, &atts);
+ win = XCreateWindow(dpy, parent, 0, 0, xres, yres, 0, vi->depth,
+ InputOutput, vi->visual, flags, &atts);
- if(!parentWindow){
- XTextProperty tp;
- char* name = "Manta";
- XStringListToTextProperty(&name, 1, &tp);
- XSizeHints sh;
- sh.flags = USPosition|USSize;
-
- XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
- }
+ if(!parentWindow){
+ XTextProperty tp;
+ char* name = "Manta";
+ XStringListToTextProperty(&name, 1, &tp);
+ XSizeHints sh;
+ sh.flags = USPosition|USSize;
+
+ XSetWMProperties(dpy, win, &tp, &tp, 0, 0, &sh, 0, 0);
+ }
- XMapWindow(dpy, win);
+ XMapWindow(dpy, win);
- // Wait for the window to appear before proceeding
- for(;;){
- XEvent e;
- XNextEvent(dpy, &e);
- if(e.type == MapNotify)
- break;
- }
+ // 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);
+ // Turn off events from this window
+ atts.event_mask = 0;
+ XChangeWindowAttributes(dpy, win, CWEventMask, &atts);
+ }
windowOpen = true;
cx = glXCreateContext(dpy, vi, NULL, True);
- XFree(vi);
+ if(free_vi){
+ XFree(vi);
+ vi = 0;
+ }
if(!glXMakeCurrent(dpy, win, cx)) {
XHelper::Xlock.unlock();
throw InternalError("glXMakeCurrent failed!\n", __FILE__, __LINE__);
}
-
+
+ glDisable(GL_DEPTH_TEST);
glClearColor(.05, .1, .2, 0);
glClear(GL_COLOR_BUFFER_BIT);
glXSwapBuffers(dpy, win);
@@ -331,7 +360,8 @@
gluOrtho2D(0, xres, 0, yres);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- display_frame_rate(1.0/(currentTime-last_frame_time));
+ if(displayFrameRate)
+ display_frame_rate(1.0/(currentTime-last_frame_time));
last_frame_time = currentTime;
glXSwapBuffers(dpy, win);
Modified: trunk/Engine/Display/OpenGLDisplay.h
==============================================================================
--- trunk/Engine/Display/OpenGLDisplay.h (original)
+++ trunk/Engine/Display/OpenGLDisplay.h Thu Apr 27 23:33:18 2006
@@ -17,6 +17,7 @@
class OpenGLDisplay : public ImageDisplay {
public:
OpenGLDisplay(const vector<string>& args);
+ OpenGLDisplay(XVisualInfo* visualInfo, Window window);
virtual ~OpenGLDisplay();
virtual void setupDisplayChannel(SetupContext&);
virtual void displayImage(const DisplayContext& context, const Image*
image);
@@ -27,6 +28,7 @@
void createWindow(bool stereo, int xres, int yres, XWindow*
masterWindow);
Window parentWindow;
+ XVisualInfo* vi;
Window win;
Display* dpy;
int screen;
@@ -48,6 +50,8 @@
bool have_texturerange;
bool big_endian;
+ bool displayFrameRate;
+
// This is when the last frame started displaying. Use it to
// compute the framerate.
double last_frame_time;
@@ -60,6 +64,9 @@
bool drawImage_pixels(const Image* image);
bool have_extension(const char* name);
+
+ void setDefaults();
+ void setup();
};
}
Modified: trunk/fox/dm_demo/dm_demo.cc
==============================================================================
--- trunk/fox/dm_demo/dm_demo.cc (original)
+++ trunk/fox/dm_demo/dm_demo.cc Thu Apr 27 23:33:18 2006
@@ -170,7 +170,7 @@
// Create a glx image display.
glx_image_display =
- new GLXImageDisplay( (XVisualInfo
*)manta_frame->getVisual()->getInfo(),
+ new OpenGLDisplay( (XVisualInfo *)manta_frame->getVisual()->getInfo(),
(Window) manta_frame->id() );
// std::cout << "X Window id: " << manta_frame->id() << std::endl;
- [MANTA] r1018 - in trunk: Engine/Display fox/dm_demo, sparker, 04/27/2006
Archive powered by MHonArc 2.6.16.