📄 support.cpp
字号:
// ___ ___ ___ ___ ___ // /\__\ ___ /\__\ /\ \ /\__\ /\ \. // /::| | /\ \ /::| | /::\ \ /:/ / /::\ \. // /:|:| | \:\ \ /:|:| | /:/\:\ \ /:/ / /:/\:\ \. // /:/|:|__|__ /::\__\ /:/|:| |__ /:/ \:\ \ /:/ / /::\~\:\ \.// /:/ |::::\__\ __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/ /:/\:\ \:\__\.// \/__/~~/:/ / /\/:/ / \/__|:|/:/ / \:\ /\ \/__/ \:\ \ \:\~\:\ \/__/// /:/ / \::/__/ |:/:/ / \:\ \:\__\ \:\ \ \:\ \:\__\. // /:/ / \:\__\ |::/ / \:\/:/ / \:\ \ \:\ \/__/ // /:/ / \/__/ /:/ / \::/ / \:\__\ \:\__\. // \/__/ \/__/ \/__/ \/__/ \/__/ // // =============================================================================// Minimalist OpenGL Environment// Parallel Rendering Extension// =============================================================================//// Copyright 2007 Balazs Domonkos// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA./// @file Support.cpp/// ParaComp parallel rendering support#include <paracomp/include/Support.h>#include <paracomp/include/MasterPart.h>#include <paracomp/include/SlavePart.h>#if MINGLE_PARACOMP_SUPPORT == 1#include <pcapi.h>#include <unistd.h>namespace MinGLE {#define PCCHECKERROR(method, err) if(err!=PC_NO_ERROR) Except(method, pcGetErrorString(err))#define FIND_PARACOMP_PART(window, method) \ dynamic_cast<ParaCompPart *>(_findProxiedWindow(window)); \ Assert(part, method);ParaCompSupport::ParaCompSupport(unsigned sessionId, std::vector<std::string> hostlist) : mSessionId(sessionId), mNetId(PC_ID_DEFAULT), mHostList(hostlist) { // Start off PC operations by loading shared library. // This program was linked against a stub library (libpcstub.so) that dynamically // loads the real shared library (libparcomp.so) using the call below. This // delayed loading makes it possible to load either the standard implementation // or the HP implementation at runtime based on program logic. // 0 indicates searching in the default directory { PCerr err = pcSystemInitialize(0); PCCHECKERROR("ParaCompSupport::ParaCompSupport", err); } // Create a session using the sessionId given on the command line // Note that all the other hosts must also be started with the same // sessionId, else they won't connect to this each other! // This is call is unlikely to fail { PCerr err = pcSessionCreate(mSessionId); PCCHECKERROR("ParaCompSupport::ParaCompSupport", err); }}ParaCompSupport::~ParaCompSupport() { // Destroy the Session // Note that if you destroy the session it will destroy any // contexts created in that session. { PCerr err = pcSessionDestroy(); PCCHECKERROR("ParaCompSupport::~ParaCompSupport", err); } // Un-initialize the PC Library // This will unload the PC library loaded during pcSystemInitialize(). // To use PC again, you will have to call pcSystemInitialize(). { PCerr err = pcSystemFinalize(); PCCHECKERROR("ParaCompSupport::~ParaCompSupport", err); }}void ParaCompSupport::_addParallelSupport(Window *window, ParallelRenderingSupport::CompositingOperator compositingOperator, ParallelRenderingSupport::SystemPart part) { switch(part) { case MASTER: _addParallelSupportMaster(window, compositingOperator); break; case SLAVE: _addParallelSupportSlave(window, compositingOperator); break; default: // Autodetect if(mHostList.size()>1) _addParallelSupportMaster(window, compositingOperator); else _addParallelSupportSlave(window, compositingOperator); }}void ParaCompSupport::_addParallelSupportMaster(Window *window, ParallelRenderingSupport::CompositingOperator compositingOperator) { ParaCompMasterPart *masterPart = new ParaCompMasterPart(window, mHostList, this, compositingOperator); window->insertWindowProxy(masterPart);}void ParaCompSupport::_addParallelSupportSlave(Window *window, ParallelRenderingSupport::CompositingOperator compositingOperator) { WindowProxy *slavePart = new ParaCompSlavePart(window, mHostList[0], this, compositingOperator); window->insertWindowProxy(slavePart);}void ParaCompSupport::_setParameter(const unsigned type, const void *value) {}int ParaCompSupport::_getRendererCount(Window *window) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_getRendererCount"); return part->getRendererCount();}int ParaCompSupport::_getThisRenderer(Window *window) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_getThisRenderer"); return part->getThisRenderer();}void ParaCompSupport::_setPartition(Window *window, BoxPartitioner<double>::Partition *partition) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_setPartition"); part->setPartition(partition);}void ParaCompSupport::_setSortOrder(Window *window, unsigned order) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_setSortOrder"); part->setSortOrder(order);}unsigned ParaCompSupport::_getDisplayDebug(Window *window) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_getDisplayDebug"); return part->getDisplayDebug();}void ParaCompSupport::_setDisplayDebug(Window *window, const unsigned displayDebug) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_setDisplayDebug"); part->setDisplayDebug(displayDebug);}void ParaCompSupport::_toggleDisplayDebug(Window *window, const ParallelRenderingSupport::DisplayDebug flag) { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_toggleDisplayDebug"); part->toggleDisplayDebug(flag);}/*void ParaCompSupport::_setBoundingBox(Window *window, const double *offset, const double *size) { ParaCompPart *part = dynamic_cast<ParaCompPart *>(_findProxiedWindow(window)); Assert(part, "ParaCompSupport::_setBoundingBox"); part->setBoundingBox(offset, size);}*/ParallelRenderingSupport::SystemPart ParaCompSupport::_getSystemPart(Window *window) const { ParaCompPart *part = FIND_PARACOMP_PART(window, "ParaCompSupport::_getSystemPart"); if(dynamic_cast<ParaCompMasterPart *>(part)) return MASTER; else if(dynamic_cast<ParaCompSlavePart *>(part)) return SLAVE; Except("ParaCompSupport::_getSystemPart", "The specified window does not belong to ParaComp parallel rendering system."); return MASTER; // Avoid warning of the compiler}void ParaCompSupport::_getBlendingFactors(const CompositingOperator op, unsigned& sfactorRGB, unsigned& dfactorRGB, unsigned& sfactorAlpha, unsigned& dfactorAlpha) const { switch(op) { case DEPTH_OPERATOR: sfactorRGB = GL_ONE, dfactorRGB = GL_ZERO, sfactorAlpha = GL_ONE, dfactorAlpha = GL_ZERO; break; case ALPHA_BLEND_OPERATOR: sfactorRGB = GL_SRC_ALPHA, dfactorRGB = GL_ONE_MINUS_SRC_ALPHA, sfactorAlpha = GL_ONE, dfactorAlpha = GL_ONE_MINUS_SRC_ALPHA; break; default: Except("ParaCompSupport::_getBlendingFactors()", "Invalid operator. Cannot determine blending factors. Possibly, you got this error because of an internal error in mingle-paracomp. Please report this bug. Thank you."); }}ParaCompPart* ParaCompSupport::_findProxiedWindow(Window *window) const { return WindowProxy::findProxiedWindow<ParaCompPart>(window); /* for(;;) { // Check the proxy of the window. // If it is a ParaCompPart window proxy return it. ParaCompPart *part = dynamic_cast<ParaCompPart *>(window->getWindowProxy()); if(part) return part; // Otherwise, check whether the window is a window proxy itself // and shedule invertigation its proxied window in the next iteration. // (Ie. step up along the proxy chain.) WindowProxy* proxy = dynamic_cast<WindowProxy *>(window); if(proxy) window = proxy->getProxiedWindow(); // Otherwise, return null pointer // (This should be checked when using.) else return 0; } return 0; */}#undef FIND_PARACOMP_PART#undef PCCHECKERROR} // namespace MinGLE#endif // MINGLE_PARACOMP_SUPPORT == 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -