PCMRendererPlugin.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00044
00045
00046 RendererPlugin::RendererPlugin(const Plugin::PluginType & type, const std::string & name,
00047 const std::string & filename):
00048
00049 Plugin(type
00050 , name
00051 , filename
00052 )
00053
00054
00055
00056
00057
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
00076
00077
00078 void RendererPlugin::_bufferGetter(const void *pRenderer, const char *bufferName, void *pBufferData)
00079 {
00080
00081
00082
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
00089 Node *node = renderer->getParent()->getParent()->getParent();
00090
00091
00092 Buffer::Pointer buffer = node->getBuffer(bufferName);
00093
00094
00095 if(pBufferData)
00096 {
00097
00098
00099
00100 PluginBuffer *bufferData = static_cast < PluginBuffer * >(pBufferData);
00101
00102 Assert(bufferData, INVALID_OBJECT_ERROR, "RendererPlugin::_bufferGetter()");
00103
00104
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
00112 else
00113 {
00114
00115
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 Renderer *RendererPlugin::createRenderer(GLXRenderWindow::Pointer window, OpenGLRenderingEngine * parent)
00126 {
00127 Assert(parent, NULL_POINTER_ERROR, "RendererPlugin::createRenderer()");
00128
00129
00130 if(!hasFunction("pcmOnCreateRenderer"))
00131 return new Renderer(this, 0, parent);
00132
00133 pcmOnCreateRendererType pcmOnCreateRenderer = (pcmOnCreateRendererType) getFunction("pcmOnCreateRenderer");
00134
00135
00136 Renderer *renderer = new Renderer(this, 0, parent);
00137
00138
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
00149
00150
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
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
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
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
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
00239 mPcmOnResize = (pcmOnResizeType) getFunction("pcmOnResize");
00240 mPcmOnRender = (pcmOnRenderType) getFunction("pcmOnRender");
00241
00242
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 }