diff options
author | Manoj Rajagopalan <manoj@nanorex.com> | 2008-03-04 14:14:41 +0000 |
---|---|---|
committer | Manoj Rajagopalan <manoj@nanorex.com> | 2008-03-04 14:14:41 +0000 |
commit | d44c0a294ea46db0f3ba34cbbf7f8d51eedacd3f (patch) | |
tree | a2d840aac9fd92b93a34892b3af3aea1ba3a0f24 /cad/plugins/NanoVision-1/src/Plugins | |
parent | 9e069801685b20a9015c804c99b3e2d3fef9c29a (diff) | |
download | nanoengineer-d44c0a294ea46db0f3ba34cbbf7f8d51eedacd3f.tar.gz nanoengineer-d44c0a294ea46db0f3ba34cbbf7f8d51eedacd3f.zip |
Fortified Scenegraph API
Working NXOpenGLRenderingEngineTest
Diffstat (limited to 'cad/plugins/NanoVision-1/src/Plugins')
16 files changed, 174 insertions, 178 deletions
diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/color.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/color.cpp index 664920d7e..b4b6e548b 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/color.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/color.cpp @@ -13,7 +13,7 @@ */ #include <string> - +#include <iostream> #include <cassert> #include <cstdio> diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/glt_error.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/glt_error.h index e4a376b9c..7f1c88791 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/glt_error.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/glt_error.h @@ -36,6 +36,7 @@ */ +#include <ostream> #include <string> /*! \define GLERROR @@ -45,27 +46,28 @@ */ #if defined(NDEBUG) - #define GLERROR +// #define GLERROR #else #include "glt_config.h" #include "glt_gl.h" #include "glt_glu.h" - #include <iostream> - - #define GLERROR(strm) \ - { \ - GLenum code = glGetError(); \ - while (code!=GL_NO_ERROR) \ - { \ - strm << __FILE__; \ - strm << ':' << __LINE__; \ - strm << ' ' << (char *) gluErrorString(code) << std::endl; \ - code = glGetError(); \ - } \ - } + #endif + +inline GLenum GLERROR(std::ostream& strm) +{ + GLenum firstCode = glGetError(); + for(GLenum code = firstCode; code!=GL_NO_ERROR; code = glGetError()) + { + strm << __FILE__; + strm << ':' << __LINE__; + strm << ' ' << (char *) gluErrorString(code) << std::endl; + } + return firstCode; +} + /// Display warning void gltError(const std::string &message); diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/light.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/light.cpp index 2536fb6ae..783046bc5 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/light.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/light.cpp @@ -14,6 +14,7 @@ #include <cstring> #include <cassert> +#include <iostream> using namespace std; #include "glt_error.h" diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/lightm.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/lightm.cpp index 3dca6fea8..ac854068d 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/lightm.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/lightm.cpp @@ -15,6 +15,7 @@ #include "glt_error.h" #include <cstring> +#include <iostream> using namespace std; GltLightModel::GltLightModel(const bool getIt) diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/material.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/material.cpp index 013c306cc..ff3c9932f 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/material.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/material.cpp @@ -16,6 +16,7 @@ #include <cassert> #include <cstring> +#include <iostream> using namespace std; GltMaterial::GltMaterial(const GLenum face,const bool getIt) diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/viewport.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/viewport.cpp index 716b8cbad..d8e2e7048 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/viewport.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/viewport.cpp @@ -22,6 +22,7 @@ #include "glt_bbox.h" #include <cstring> +#include <iostream> using namespace std; GltViewport::GltViewport(bool getIt) diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.cpp index 44f964383..7490c52fe 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.cpp @@ -9,7 +9,7 @@ using namespace std; namespace Nanorex { - +NXCommandResult NXOpenGLRendererPlugin::_s_commandResult; NXSGOpenGLRenderable *NXOpenGLRendererPlugin::_s_canonicalSphereNode(NULL); NXSGOpenGLRenderable *NXOpenGLRendererPlugin::_s_canonicalCylinderNode(NULL); @@ -109,7 +109,7 @@ void NXOpenGLRendererPlugin::InitializeCanonicalSphereNode(void) bool beginRenderOK = _s_canonicalSphereNode->beginRender(); if(!beginRenderOK) { - NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetContextError(); + NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetCommandResult(); _s_commandResult.setResult(NX_PLUGIN_REPORTS_ERROR); _s_commandResult.setParamVector(scenegraphCtxtError->getParamVector()); delete _s_canonicalSphereNode; @@ -128,7 +128,7 @@ void NXOpenGLRendererPlugin::InitializeCanonicalSphereNode(void) bool endRenderOK = _s_canonicalSphereNode->endRender(); if(!endRenderOK) { - NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetContextError(); + NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetCommandResult(); _s_commandResult.setResult(NX_PLUGIN_REPORTS_ERROR); _s_commandResult.setParamVector(scenegraphCtxtError->getParamVector()); delete _s_canonicalSphereNode; @@ -159,7 +159,7 @@ void NXOpenGLRendererPlugin::InitializeCanonicalCylinderNode(void) bool beginRenderOK = _s_canonicalCylinderNode->beginRender(); if(!beginRenderOK) { - NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetContextError(); + NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetCommandResult(); _s_commandResult.setResult(NX_PLUGIN_REPORTS_ERROR); _s_commandResult.setParamVector(scenegraphCtxtError->getParamVector()); delete _s_canonicalCylinderNode; @@ -180,7 +180,7 @@ void NXOpenGLRendererPlugin::InitializeCanonicalCylinderNode(void) bool endRenderOK = _s_canonicalCylinderNode->endRender(); if(!endRenderOK) { - NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetContextError(); + NXCommandResult *scenegraphCtxtError = NXSGOpenGLNode::GetCommandResult(); _s_commandResult.setResult(NX_PLUGIN_REPORTS_ERROR); _s_commandResult.setParamVector(scenegraphCtxtError->getParamVector()); delete _s_canonicalCylinderNode; @@ -286,19 +286,14 @@ void NXOpenGLRendererPlugin::DrawOpenGLCanonicalSphere(void) glEnd(); - GLenum const err = glGetError(); + ostringstream errMsgStream; + GLenum const err = GLERROR(errMsgStream); if(err == GL_NO_ERROR) { _s_commandResult.setResult(NX_CMD_SUCCESS); } else { -#ifdef NX_DEBUG - ostringstream errMsgStream; - GLERROR(errMsgStream); // glt_error.h SetError(_s_commandResult, ("Error drawing openGL unit sphere"+errMsgStream.str()).c_str()); -#else - SetError(_s_commandResult, "Error drawing openGL unit sphere"); -#endif } } @@ -374,19 +369,14 @@ void NXOpenGLRendererPlugin::DrawOpenGLCanonicalCylinder(void) glEnd(); - GLenum const err = glGetError(); + ostringstream errMsgStream; + GLenum const err = GLERROR(errMsgStream); if(err == GL_NO_ERROR) { _s_commandResult.setResult(NX_CMD_SUCCESS); } else { -#ifdef NX_DEBUG - ostringstream errMsgStream; - GLERROR(errMsgStream); // glt_error.h SetError(_s_commandResult, ("Error drawing openGL unit cylinder"+errMsgStream.str()).c_str()); -#else - SetError(_s_commandResult, "Error drawing openGL unit cylinder"); -#endif } } diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.h index c8b177fac..11578136d 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRendererPlugin.h @@ -27,18 +27,18 @@ class NXOpenGLRendererPlugin : public NXRendererPlugin { public: NXOpenGLRendererPlugin() {} - virtual ~NXOpenGLRendererPlugin() {} + virtual ~NXOpenGLRendererPlugin() { cleanup(); } NXCommandResult* initialize(void); NXCommandResult* cleanup(void); /// Call plugin to render the atom display list and return the scenegraph node. /// Must set commandResult to indicate success or failure - NXSGOpenGLNode* renderAtom(NXAtomRenderData const&); + virtual NXSGOpenGLNode* renderAtom(NXAtomRenderData const&) { return NULL; } /// Call plugin to render the bond display list and return the scenegraph node. /// Must set commandResult to indicate success or failure - NXSGOpenGLNode* renderBond(NXBondRenderData const&); + virtual NXSGOpenGLNode* renderBond(NXBondRenderData const&) { return NULL; } NXCommandResult const& getCommandResult(void) const { return commandResult; } diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp index a12d66f84..b02bd974c 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp @@ -62,6 +62,7 @@ NXOpenGLRenderingEngine::NXOpenGLRenderingEngine(QWidget *parent) NXOpenGLRenderingEngine::~NXOpenGLRenderingEngine() { + cleanupPlugins(); } @@ -233,6 +234,8 @@ void NXOpenGLRenderingEngine::initializeGL(void) camera.glViewport(0, 0, width(), height()); camera.gluPerspective(55, (GLdouble)width()/(GLdouble)height(), 0.1, 50); + initializePlugins(); + } @@ -848,7 +851,7 @@ bool NXOpenGLRenderingEngine::setRenderer(NXOpenGLRendererPlugin *const plugin) bool NXOpenGLRenderingEngine::initializePlugins(void) { - makeCurrent(); + // called from initializeGL so context is current NXCommandResult *rendererInitializationResult = renderer->initialize(); rendererInitialized = (rendererInitializationResult->getResult() == (int) NX_CMD_SUCCESS); diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h index 89a5aa2e4..a49da04e8 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h @@ -115,9 +115,7 @@ private: void deleteSceneGraph ( void ) { - if ( rootSceneGraphNode != ( NXSGOpenGLNode* ) NULL ) - { - rootSceneGraphNode->deleteRecursive(); + if ( rootSceneGraphNode != ( NXSGOpenGLNode* ) NULL ) { delete rootSceneGraphNode; rootSceneGraphNode = ( NXSGOpenGLNode* ) NULL; } diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp index 43f7ac74e..3b1070194 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp @@ -55,10 +55,10 @@ int main(int argc, char *argv[]) mainWindow.setCentralWidget(renderingEngine); NXBallAndStickOpenGLRenderer *renderer = new NXBallAndStickOpenGLRenderer; - renderingEngine->setPlugin(renderer); + renderingEngine->setRenderer(renderer); NXMoleculeSet theMoleculeSet; - OBMol *molPtr = theMoleculeSet.newMolecule(); + // OBMol *molPtr = theMoleculeSet.newMolecule(); // makeC2H6(molPtr); makeTheMoleculeSet(theMoleculeSet); diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp index 53b3b96b2..444ce356e 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp @@ -2,14 +2,21 @@ #include "NXOpenGLSceneGraph.h" #include <Nanorex/Interface/NXNanoVisionResultCodes.h> +#include "GLT/glt_error.h" +#include <sstream> using namespace std; namespace Nanorex { +// static data +GLint NXSGOpenGLNode::_s_maxModelViewStackDepth; + + // OpenGL Scenegraph context - only one per application bool NXSGOpenGLNode::InitializeContext(void) { + /// @todo Mutex locks bool success = true; // Read model-view stack max-depth @@ -24,27 +31,22 @@ bool NXSGOpenGLNode::InitializeContext(void) } -void NXSGOpenGLNode::SetError(int errCode, char const *const errMsg) +bool NXSGOpenGLNode::initializeContext(void) { - commandResult.setResult(errCode); - vector<QString> message; - message.push_back(QObject::tr(errMsg)); - commandResult.setParamVector(message); + bool const baseClassContextInitialized = NXSGNode::initializeContext(); + bool const thisClassContextInitialized = InitializeContext(); + bool const ok = baseClassContextInitialized && thisClassContextInitialized; + return ok; } -#if 0 // unused class - commented out -bool NXSGOpenGLGenericTransform::apply(void) const throw () +bool NXSGOpenGLNode::cleanupContext(void) { - glMultMatrixd(matrix); - GLenum const err = glGetError(); - return (err == GL_NO_ERROR) ? true : false; + bool const baseClassContextCleanedUp = NXSGNode::cleanupContext(); + return baseClassContextCleanedUp; } -#endif - - bool NXSGOpenGLNode::addChild(NXSGNode *const /*child*/) { SetError(NX_INTERNAL_ERROR, @@ -59,10 +61,6 @@ bool NXSGOpenGLNode::addChild(NXSGOpenGLNode *const child) if(included) { child->newParentModelViewStackDepth(modelViewStackDepth); } - else { - SetError(NX_INTERNAL_ERROR, - "Could not include child node possibly because of lack of memory"); - } return included; } @@ -132,43 +130,35 @@ NXSGOpenGLModelViewTransform::newParentModelViewStackDepth(int parentMVStackDept /// restores it afterwards bool NXSGOpenGLModelViewTransform::applyRecursive(void) const throw() { - // Record OpenGL current-matrix state - // GLenum currentMatrixMode; - // glGetIntegerv(GL_MATRIX_MODE, (GLint*)¤tMatrixMode); - // Save the modelview matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); // trap stack overflow/underflow GLenum glError = glGetError(); bool ok = (glError == GL_NO_ERROR); - bool childrenOK = true; - - if(ok) { - ok = apply(); - if(ok) { - ChildrenList::const_iterator child_iter; - for(child_iter = children.begin(); - child_iter != children.end() && childrenOK; - ++child_iter) - { - childrenOK = (*child_iter)->applyRecursive(); - } - } - glPopMatrix(); - } - - // Setup error info if this node caused the failure if(!ok) { SetError(NX_INTERNAL_ERROR, - "Failure applying model-view transform in OpenGL scenegraph " - "context"); + "OpenGL modelview stack overflow or invalid operation"); + return false; } - ok = ok && childrenOK; - // restore the OpenGL matrix mode - // glMatrixMode(currentMatrixMode); - return ok; + // apply transform and quit if error + bool appliedOK = apply(); + if(!appliedOK) + return false; + + bool childrenOK = true; + ChildrenList::const_iterator child_iter; + for(child_iter = children.begin(); + child_iter != children.end() && childrenOK; + ++child_iter) + { + childrenOK = (*child_iter)->applyRecursive(); + } + // Restore model-view matrix + glPopMatrix(); + + return childrenOK; } @@ -233,60 +223,30 @@ NXSGOpenGLRenderable::~NXSGOpenGLRenderable() throw (NXException) bool NXSGOpenGLRenderable::beginRender(void) const throw () { glNewList(display_list_id, GL_COMPILE); - GLenum const err = glGetError(); - bool ok = (err == GL_NO_ERROR); - if(!ok) { -#ifdef NX_DEBUG - switch(err) { - case GL_INVALID_VALUE: - SetError(NX_INTERNAL_ERROR, "Begin-render with display list id = 0"); - break; - case GL_INVALID_OPERATION: - SetError(NX_INTERNAL_ERROR, "Invalid begin-render operation"); - break; - case GL_OUT_OF_MEMORY: - SetError(NX_INTERNAL_ERROR, "Insufficient memory for begin-render op"); - break; - default: - SetError(NX_INTERNAL_ERROR, "Unknown error in begin-render"); - break; - } -#else + ostringstream errMsgStream; + GLenum const err = GLERROR(errMsgStream); + if(err != GL_NO_ERROR) { SetError(NX_INTERNAL_ERROR, - "Failure creating new OpenGL scenegraph display list"); -#endif + errMsgStream.str().c_str()); + return false; } - return ok; + + return true; } bool NXSGOpenGLRenderable::endRender(void) const throw () { glEndList(); - GLenum const err = glGetError(); - bool ok = (err == GL_NO_ERROR); - if(!ok) { -#ifdef NX_DEBUG - switch(err) { - case GL_INVALID_VALUE: - SetError(NX_INTERNAL_ERROR, "Begin-render with display list id = 0"); - break; - case GL_INVALID_OPERATION: - SetError(NX_INTERNAL_ERROR, "Invalid begin-render operation"); - break; - case GL_OUT_OF_MEMORY: - SetError(NX_INTERNAL_ERROR, "Insufficient memory for begin-render op"); - break; - default: - SetError(NX_INTERNAL_ERROR, "Unknown error in begin-render"); - break; - } -#else + ostringstream errMsgStream; + GLenum const err = GLERROR(errMsgStream); + if(err != GL_NO_ERROR) { SetError(NX_INTERNAL_ERROR, - "Failure creating new OpenGL scenegraph display list"); -#endif + errMsgStream.str().c_str()); + return false; } - return ok; + + return true; } #if 0 diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.h index b56dc053f..7f1608108 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.h @@ -33,6 +33,10 @@ public: NXSGOpenGLNode() : modelViewStackDepth(0) {} ~NXSGOpenGLNode() {} + // Override virtual methods + bool initializeContext(void); + bool cleanupContext(void); + /// Prevent addition of generic nodes so that children are OpenGL /// scenegraph nodes. Required to be able to propagate context checks bool addChild(NXSGNode *const child); @@ -42,20 +46,13 @@ public: int getModelViewStackDepth(void) { return modelViewStackDepth; } + /// @todo - making this protected created compilation errors - gcc bug? /// Called by parent when its stack depth is updated to recursively /// propagate this info to leaves virtual bool newParentModelViewStackDepth(int newMVStackDepth); // static members - /// Assess OpenGL context limits. - /// Must be called after the OpenGL context is made current and - /// before OpenGL scenegraph module is used - bool InitializeContext(void); - - /// Last error in the context - static NXCommandResult* GetContextError(void) { return &commandResult; } - static GLint const& GetMaxModelViewStackDepth(void) { return _s_maxModelViewStackDepth; } @@ -68,11 +65,11 @@ protected: /// model-view stack-size limit static GLint _s_maxModelViewStackDepth; - /// Most recent error - to be set by failing node - /// All calling nodes propagate boolean result back up to root - static NXCommandResult commandResult; + /// Assess OpenGL context limits. + /// Must be called after the OpenGL context is made current and + /// before OpenGL scenegraph module is used + bool InitializeContext(void); - static void SetError(int errCode, char const *const errMsg); }; @@ -101,20 +98,17 @@ public: class NXSGOpenGLModelViewTransform : public NXSGOpenGLTransform { public: NXSGOpenGLModelViewTransform() throw() - : NXSGOpenGLTransform() { ++modelViewStackDepth; /* must be >= 1 */ } ~NXSGOpenGLModelViewTransform() throw() {} - bool addChild(NXSGOpenGLNode *child); + // bool addChild(NXSGOpenGLNode *child); + + bool applyRecursive(void) const throw(); /// Re-implement base-class method because this class increments /// model-view stack-depth bool newParentModelViewStackDepth(int parentMVStackDepth); - - bool applyRecursive(void) const throw(); - - void deleteRecursive(void) { } }; @@ -224,8 +218,6 @@ public: /// Calls glEndList(). Call after the plugin does its OpenGL rendering. bool endRender(void) const throw (); - void deleteRecursive(void) { } - #ifdef NX_DEBUG GLuint getDisplayListID(void) const { return display_list_id; } #endif @@ -244,8 +236,6 @@ public: /// Copy assignment from GL-material // NXSGOpenGLMaterial& operator = (NXOpenGLMaterial const& mat) throw (); bool apply(void) const throw (); - - void deleteRecursive(void) { } }; } // Nanorex diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp index 72ce4e2be..8f3974b15 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp @@ -125,6 +125,7 @@ void NXBallAndStickOpenGLRenderer::InitializeCanonicalTripleBondNode(void) try { translateNode1 = new NXSGOpenGLTranslate(1.5*BOND_WIDTH, 0.0, 0.0); translateNode2 = new NXSGOpenGLTranslate(1.5*(-BOND_WIDTH), 0.0, 0.0); + _s_canonicalBondNode[2] = new NXSGOpenGLNode; } catch(...) { tripleBondOK = false; @@ -149,6 +150,10 @@ void NXBallAndStickOpenGLRenderer::InitializeCanonicalTripleBondNode(void) delete translateNode1; if(translateNode2 != NULL) delete translateNode2; + if(_s_canonicalBondNode[2] != NULL) { + delete _s_canonicalBondNode[2]; + _s_canonicalBondNode[2] = NULL; + } } } } @@ -157,24 +162,51 @@ void NXBallAndStickOpenGLRenderer::InitializeCanonicalTripleBondNode(void) /* static */ void NXBallAndStickOpenGLRenderer::InitializeCanonicalAromaticBondNode(void) { - /// @todo - _s_canonicalBondNode[3] = _s_canonicalBondNode[0]; + /// @todo check NE-1 for aromatic bond representation and implement + try { + _s_canonicalBondNode[3] = new NXSGOpenGLNode; + if(!_s_canonicalBondNode[3]->addChild(_s_canonicalBondNode[0])) { + delete _s_canonicalBondNode[3]; + _s_canonicalBondNode[3] = NULL; + } + } + catch(...) { + _s_canonicalBondNode[3] = NULL; + } } /* static */ void NXBallAndStickOpenGLRenderer::InitializeCanonicalCarbomericBondNode(void) { - /// @todo - _s_canonicalBondNode[4] = _s_canonicalBondNode[0]; + /// @todo check NE-1 for carbomeric bond representation and implement + try { + _s_canonicalBondNode[4] = new NXSGOpenGLNode; + if(!_s_canonicalBondNode[4]->addChild(_s_canonicalBondNode[0])) { + delete _s_canonicalBondNode[4]; + _s_canonicalBondNode[4] = NULL; + } + } + catch(...) { + _s_canonicalBondNode[4] = NULL; + } } /* static */ void NXBallAndStickOpenGLRenderer::InitializeCanonicalGraphiticBondNode(void) { - /// @todo - _s_canonicalBondNode[5] = _s_canonicalBondNode[0]; + /// @todo check NE-1 for graphitic bond representation and implement + try { + _s_canonicalBondNode[5] = new NXSGOpenGLNode; + if(!_s_canonicalBondNode[5]->addChild(_s_canonicalBondNode[0])) { + delete _s_canonicalBondNode[5]; + _s_canonicalBondNode[5] = NULL; + } + } + catch(...) { + _s_canonicalBondNode[5] = NULL; + } } @@ -273,7 +305,7 @@ NXSGOpenGLNode* NXBallAndStickOpenGLRenderer::renderBond(NXBondRenderData const& // note x-y displacements are not affected by z-scaling for length // single bond - if(!bondScale->addChild(_s_canonicalBondNode[info.getOrder()])) { + if(!bondScale->addChild(_s_canonicalBondNode[info.getOrder()-1])) { SetError(commandResult, "Error including canonical bond node in bond scenegraph"); delete bondNode; diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.cpp index 3a9bd1cdf..06ad0466f 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.cpp @@ -38,7 +38,9 @@ mat_shininess(50.0) TestMainWindow::~TestMainWindow() { + makeCurrent(); if(renderer != NULL) { + renderer->cleanup(); delete renderer; renderer = NULL; } @@ -291,20 +293,38 @@ void TestMainWindow::setupScene(void) delete scene; scene = NULL; } - scene = new NXSGNode; - NXSGNode *atom1 = renderer->renderAtom(atomRenderData); - NXSGNode *atom1Move = new NXSGOpenGLTranslate(0.0f, 1.0f, 1.0f); - NXSGNode *atom2 = renderer->renderAtom(atomRenderData); - NXSGNode *atom2Move = new NXSGOpenGLTranslate(0.0f, -1.0f, -1.0f); - scene->addChild(atom1Move); - atom1Move->addChild(atom1); - scene->addChild(atom2Move); - atom2Move->addChild(atom2); - NXSGNode *bond12 = renderer->renderBond(bondRenderData); + scene = new NXSGOpenGLNode; + NXSGOpenGLNode *atom1 = renderer->renderAtom(atomRenderData); + NXSGOpenGLNode *atom1Move = new NXSGOpenGLTranslate(0.0f, 1.0f, 1.0f); + NXSGOpenGLNode *atom2 = renderer->renderAtom(atomRenderData); + NXSGOpenGLNode *atom2Move = new NXSGOpenGLTranslate(0.0f, -1.0f, -1.0f); + bool nodesCreated = (scene != NULL && + atom1 != NULL && atom1Move != NULL && + atom2 != NULL && atom2Move != NULL ); + bool addedChildren = true; + if(nodesCreated) { + addedChildren = scene->addChild(atom1Move); + addedChildren = addedChildren && atom1Move->addChild(atom1); + addedChildren = addedChildren && scene->addChild(atom2Move); + addedChildren = addedChildren && atom2Move->addChild(atom2); + } + else { + cerr << "scene: Failed to create nodes" << endl; + } + if(!addedChildren) { + cerr << "scene: Failed to add children" << endl; + return; + } + NXSGOpenGLNode *bond12 = renderer->renderBond(bondRenderData); GLfloat const BOND_WIDTH = 0.25f; - NXSGNode *bond12Rotate = new NXSGOpenGLRotate(-45.0, 1.0, 0.0, 0.0); - scene->addChild(bond12Rotate); - bond12Rotate->addChild(bond12); + NXSGOpenGLNode *bond12Rotate = new NXSGOpenGLRotate(-45.0, 1.0, 0.0, 0.0); + if(bond12 != NULL && bond12Rotate != NULL) { + scene->addChild(bond12Rotate); + bond12Rotate->addChild(bond12); + } + else { + cerr << "scene: Failed to create bond nodes" << endl; + } } @@ -353,10 +373,7 @@ void TestMainWindow::initializeGL(void) glLoadIdentity(); gluLookAt(-4, -2, 3, 0, 0, 0, 0, 1, 0); - // draw canonical sphere in this OpenGL context - NXBallAndStickOpenGLRenderer::RenderCanonicalSphere(); - NXBallAndStickOpenGLRenderer::RenderCanonicalCylinder(); - + renderer->initialize(); setupScene(); } diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.h index 92e12eadc..d07c2861f 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRendererTest.h @@ -51,7 +51,7 @@ private: NXBondRenderData bondRenderData; NXBallAndStickOpenGLRenderer *renderer; - NXSGNode *scene; + NXSGOpenGLNode *scene; #ifndef NO_GLT // using GLT Vector4 position; |