2007-01-17 Gwenole Beauchesne <gbeauchesne@mandriva.com> * 64-bit fixes. --- nucleo-20061224/nucleo/gl/scenegraph/sgNode.H.64bit-fixes 2006-11-29 12:37:37.000000000 +0100 +++ nucleo-20061224/nucleo/gl/scenegraph/sgNode.H 2007-01-17 16:18:29.000000000 +0100 @@ -24,6 +24,8 @@ namespace nucleo { class sgNode { + GLuint _id ; + public: typedef enum {NODL, USE, CREATE} dlPolicy ; @@ -65,7 +67,17 @@ namespace nucleo { void debug(std::ostream& out, int curdepth=0) const ; - // -------------------------------------------------------- + // ------------------------------------------------------- + + GLuint getId() const { + return _id ; + } + + static GLuint createId(sgNode * const node); + static sgNode * const lookupId(GLuint id); + static void destroyId(GLuint id); + + // ------------------------------------------------------- std::string &getName() { return _name ; --- nucleo-20061224/nucleo/gl/scenegraph/sgNode.cxx.64bit-fixes 2006-11-29 12:37:37.000000000 +0100 +++ nucleo-20061224/nucleo/gl/scenegraph/sgNode.cxx 2007-01-18 16:04:53.000000000 +0100 @@ -15,6 +15,17 @@ #include <math.h> +#if defined __GNUC__ +#include <ext/hash_map> +typedef __gnu_cxx::hash_map<GLuint, void *> sgNodeMap; +#endif + +#if defined __LP64__ +/* 64-bit Linux platforms may be able to set this to 0 assuming there + is no memory leak and/or brk() can grow reasonably (2^31 nowadays?). */ +#define USE_SG_NODE_MAP 1 +#endif + static GLfloat Identity[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, @@ -173,6 +184,46 @@ namespace nucleo { // ------------------------------------------------------------------------ + static sgNodeMap sgNodes; + + GLuint + sgNode::createId(sgNode * const node) { +#if USE_SG_NODE_MAP + static GLuint id = 0x66600000; /* FIXME: set to 0 when debugged! */ + sgNodes[++id] = (void *)node; + if (debugMode) + std::cout << "sgNode::createId: node " << std::hex << node << ", id " << id << std::endl; + return id; +#else + if ((((uintptr_t)node) >> 32) != 0) + std::cout << "sgNode::createId: got a 64-bit addressed node " << std::hex << node << std::endl; + return (uintptr_t)node; +#endif + } + + sgNode * const + sgNode::lookupId(GLuint id) { +#if USE_SG_NODE_MAP + sgNodeMap::const_iterator it = sgNodes.find(id); + if (it != sgNodes.end()) + return (sgNode *)(*it).second; + if (debugMode) + std::cout << "sgNode::lookupId: id " << std::hex << id << " not found" << std::endl; + return NULL; +#else + return (sgNode *)(uintptr_t)id; +#endif + } + + void + sgNode::destroyId(GLuint id) { +#if USE_SG_NODE_MAP + sgNodes.erase(id); +#endif + } + + // ------------------------------------------------------------------------ + void sgNode::debug(std::ostream& out, int curdepth) const { for (int i=0; i<curdepth; ++i) out << " " ; @@ -197,10 +248,12 @@ namespace nucleo { memmove(_savedTransformations,Identity,16*sizeof(GLfloat)) ; _changed = true ; _hidden = false; + _id = sgNode::createId(this); } sgNode::~sgNode(void) { if (_displaylist) glDeleteLists(_displaylist,1) ; + sgNode::destroyId(_id); } // ------------------------------------------------------------------------ @@ -285,8 +338,8 @@ namespace nucleo { // if (debugMode) std::cout << "select '" << _name << "' (" << this << ")" << std::endl ; if (_hidden) return; if (debugPushName) - std::cerr << "sgNode::selectGraph: pushing " << std::hex << (GLuint)this << " " << (GLuint)(sgNode *)this << std::dec << std::endl ; - glPushName((GLuint)(sgNode *)this) ; + std::cerr << "sgNode::selectGraph: pushing " << std::hex << this << " " << (sgNode *)this << std::dec << std::endl ; + glPushName(getId()) ; glPushMatrix() ; glMultMatrixf((const GLfloat *)_transformations) ; select() ; --- nucleo-20061224/nucleo/gl/scenegraph/sgViewpoint.cxx.64bit-fixes 2006-11-29 23:34:31.000000000 +0100 +++ nucleo-20061224/nucleo/gl/scenegraph/sgViewpoint.cxx 2007-01-17 16:18:29.000000000 +0100 @@ -131,7 +131,7 @@ namespace nucleo { glGetDoublev(GL_PROJECTION_MATRIX, projmatrix) ; for (int i=0; i<selectionBufferSize; ++i) { - sgNode *o = (sgNode *)selectionBuffer[i] ; + sgNode *o = sgNode::lookupId(selectionBuffer[i]) ; #if DEBUG_LEVEL>=1 std::cerr << o->getName() << " < " << std::flush ; #endif @@ -174,7 +174,7 @@ namespace nucleo { for (int i=0; i<selectionBufferSize; ++i) { - sgNode *o = (sgNode *)selectionBuffer[i] ; + sgNode *o = sgNode::lookupId(selectionBuffer[i]) ; o->applyTransformations() ; } --- nucleo-20061224/nucleo/gl/window/glWindow_GLX.cxx.64bit-fixes 2006-11-29 23:34:31.000000000 +0100 +++ nucleo-20061224/nucleo/gl/window/glWindow_GLX.cxx 2007-01-18 16:07:00.000000000 +0100 @@ -1378,7 +1382,8 @@ namespace nucleo { e->time = CurrentTime; break; case ClientMessage: - if ((unsigned)xe.xclient.data.l[0] == wmDeleteWindow) { + if (xe.xclient.format == 32 && + (unsigned long)xe.xclient.data.l[0] == wmDeleteWindow) { e->type = glWindow::event::destroy; } e->time = CurrentTime;