PCMRendererPlugin.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00025 //
00026 // Inner includes
00027 //
00028 
00029 #include "../include/PCMRendererPlugin.h"
00030 
00031 #include "../include/PCMRenderer.h"
00032 
00033 #include "../include/PCMOpenGLRenderingEngine.h"
00034 
00035 #include "../include/PCMOpenGLExtensionLoader.h"
00036 
00037 #include "../include/PCMNode.h"
00038 
00039 namespace ParCompMark
00040 {
00041 
00042   //
00043   // Constructors & destructor
00044   //
00045 
00046   RendererPlugin::RendererPlugin(const Plugin::PluginType & type, const std::string & name,
00047                                  const std::string & filename):
00048         // Parent initializer 
00049   Plugin(type                   /* Type of the plugin. */
00050          , name         /* Name of the plugin. */
00051          , filename             /* Plugin file name. */
00052         )
00053         // You have to initialize the following attributes:
00054         // - mNeededOpenGLExts
00055         // - mPcmOnResize
00056         // - mPcmGetSortOrder
00057         // - mPcmOnRender
00058   {
00059         mPcmOnResize = 0;
00060         mPcmGetSortOrder = 0;
00061         mPcmOnRender = 0;
00062 
00063         _setBufferGetter();
00064   }
00065 
00066  /*----------------------------------------------------------------------*/
00067 
00068   RendererPlugin::~RendererPlugin()
00069   {
00070   }
00071 
00072  /*----------------------------------------------------------------------*/
00073 
00074   //
00075   // Class methods
00076   //
00077 
00078   void RendererPlugin::_bufferGetter(const void *pRenderer, const char *bufferName, void *pBufferData)
00079   {
00080         // Be careful! This method has to be reentrant
00081 
00082         // Get correspondent Renderer object
00083         Assert(pRenderer, NULL_POINTER_ERROR, "RendererPlugin::_bufferGetter()");
00084         const Renderer *renderer = static_cast < const Renderer * >(pRenderer);
00085 
00086         Assert(renderer, INVALID_OBJECT_ERROR, "RendererPlugin::_bufferGetter()");
00087 
00088         // Step up the the Node
00089         Node *node = renderer->getParent()->getParent()->getParent();
00090 
00091         // Get buffer
00092         Buffer::Pointer buffer = node->getBuffer(bufferName);
00093 
00094         // Getting the buffer
00095         if(pBufferData)
00096         {
00097          // Lock buffer
00098          //buffer.lock();
00099 
00100          PluginBuffer *bufferData = static_cast < PluginBuffer * >(pBufferData);
00101 
00102          Assert(bufferData, INVALID_OBJECT_ERROR, "RendererPlugin::_bufferGetter()");
00103 
00104          // Retrieve data
00105          bufferData->left = (unsigned) buffer->getLeft();
00106          bufferData->top = (unsigned) buffer->getTop();
00107          bufferData->width = (unsigned) buffer->getWidth();
00108          bufferData->height = (unsigned) buffer->getHeight();
00109          bufferData->colour = (unsigned char *) buffer->getColour();
00110         }
00111         // Releasing the buffer
00112         else
00113         {
00114          // Release buffer lock
00115          //buffer.unlock();
00116         }
00117   }
00118 
00119  /*----------------------------------------------------------------------*/
00120 
00121   //
00122   // Methods
00123   //
00124 
00125   Renderer *RendererPlugin::createRenderer(GLXRenderWindow::Pointer window, OpenGLRenderingEngine * parent)
00126   {
00127         Assert(parent, NULL_POINTER_ERROR, "RendererPlugin::createRenderer()");
00128 
00129         // Jump out and create renderer without handle if no such function
00130         if(!hasFunction("pcmOnCreateRenderer"))
00131          return new Renderer(this, 0, parent);
00132 
00133         pcmOnCreateRendererType pcmOnCreateRenderer = (pcmOnCreateRendererType) getFunction("pcmOnCreateRenderer");
00134 
00135         // Create ParCompMark::Renderer object without corresponding plugin object
00136         Renderer *renderer = new Renderer(this, 0, parent);
00137 
00138         // Create plugin object
00139         window.lock();
00140         void *rendererHandle =
00141          pcmOnCreateRenderer((void *) renderer, window->getDisplay()->getDisplay(), window->getWindow(),
00142                                 window->getGLXGLContext()->getVisualInfo(),
00143                                 window->getGLXGLContext()->getGLXContext());
00144 
00145         window.unlock();
00146         Assert(rendererHandle, NULL_POINTER_ERROR, "RendererPlugin::createRenderer()");
00147 
00148         // Set plugin object to the ParCompMark::Renderer
00149         // This later setter is needed (instead of constructor parameter), 
00150         //because ParCompMark::Renderer need a pointer to the plugin object and back
00151         renderer->setRendererHandle(rendererHandle);
00152 
00153         Logger::getInstance()->log(Logger::DEBUG,
00154                                  "pcmOnCreateRenderer event handler is called for renderer plugin `" + mName + "\'.");
00155 
00156         return renderer;
00157   }
00158 
00159  /*----------------------------------------------------------------------*/
00160 
00161   void RendererPlugin::destroyRenderer(Renderer * renderer)
00162   {
00163         // Jump out if no such function
00164         if(!hasFunction("pcmOnDestroyRenderer"))
00165          return;
00166 
00167         pcmOnDestroyRendererType pcmOnDestroyRenderer = (pcmOnDestroyRendererType) getFunction("pcmOnDestroyRenderer");
00168 
00169         mLastError = pcmOnDestroyRenderer(renderer->getRendererHandle());
00170         _checkError();
00171 
00172         Logger::getInstance()->log(Logger::DEBUG,
00173                                  "pcmOnDestroyRenderer event handler is called for renderer plugin `" + mName +
00174                                  "\'.");
00175   }
00176 
00177  /*----------------------------------------------------------------------*/
00178 
00179   void RendererPlugin::_initializeSpecific()
00180   {
00181         _getNeededOpenGLExts();
00182 
00183         // Get an load OpenGL extensions
00184         _initFastFunctions();
00185         OpenGLExtensionLoader::load(mNeededOpenGLExts);
00186   }
00187 
00188  /*----------------------------------------------------------------------*/
00189 
00190   void RendererPlugin::_finalizeSpecific()
00191   {
00192   }
00193 
00194  /*----------------------------------------------------------------------*/
00195 
00196   void RendererPlugin::_setBufferGetter()
00197   {
00198         // Jump out if no such function
00199         if(!hasFunction("pcmSetBufferGetter"))
00200          return;
00201 
00202         pcmSetBufferGetterType pcmSetBufferGetter = (pcmSetBufferGetterType) getFunction("pcmSetBufferGetter");
00203 
00204         mLastError = pcmSetBufferGetter(RendererPlugin::_bufferGetter);
00205         _checkError();
00206 
00207         Logger::getInstance()->log(Logger::DEBUG,
00208                                  "Buffer getter function is set for renderer plugin `" + mName + "\'.");
00209   }
00210 
00211  /*----------------------------------------------------------------------*/
00212 
00213   void RendererPlugin::_getNeededOpenGLExts()
00214   {
00215         // Jump out if no such function
00216         if(!hasFunction("pcmGetNeededOpenGLExts"))
00217          return;
00218 
00219         pcmGetNeededOpenGLExtsType pcmGetNeededOpenGLExts =
00220          (pcmGetNeededOpenGLExtsType) getFunction("pcmGetNeededOpenGLExts");
00221         const char **neededOpenGLExts = pcmGetNeededOpenGLExts();
00222 
00223         if(neededOpenGLExts)
00224          for(const char **ext = neededOpenGLExts; *ext; ext++)
00225                 mNeededOpenGLExts.push_back(*ext);
00226 
00227         Logger::getInstance()->log(Logger::DEBUG,
00228                                  "Needed OpenGL extensions are retrieved from renderer plugin `" + mName + "\'.");
00229   }
00230 
00231  /*----------------------------------------------------------------------*/
00232 
00233   void RendererPlugin::_initFastFunctions()
00234   {
00235         Assert(hasFunction("pcmOnResize")
00236            && hasFunction("pcmOnRender"), INVALID_NAME_ERROR, "Plugin::_initFastFunctions()");
00237 
00238         // "Must have functions"
00239         mPcmOnResize = (pcmOnResizeType) getFunction("pcmOnResize");
00240         mPcmOnRender = (pcmOnRenderType) getFunction("pcmOnRender");
00241 
00242         // Optional function
00243         mPcmGetSortOrder = hasFunction("pcmGetSortOrder") ? (pcmGetSortOrderType) getFunction("pcmGetSortOrder") : 0;
00244 
00245         Logger::getInstance()->log(Logger::DEBUG,
00246                                  "pcmOnResize and pcmOnRender function pointers are set for renderer plugin `" +
00247                                  mName + "\'.");
00248   }
00249 
00250  /*----------------------------------------------------------------------*/
00251 
00252 }