⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameprocessor.cpp

📁 光滑质点无网格法SPH并行计算程序
💻 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 FrameProcessor.h/// Generic ParaComp frame processor#include <paracomp/include/FrameProcessor.h>#if MINGLE_PARACOMP_SUPPORT == 1namespace MinGLE {#define PCCHECKERROR(method, err) 	if(err!=PC_NO_ERROR) Except(method, pcGetErrorString(err))FrameProcessor::FrameProcessor(PCcontext context, bool needSorting) :	mContext(context), mFrameId(0), mNeedSorting(needSorting), mSortOrder(0){}FrameProcessor::~FrameProcessor() {}void FrameProcessor::displayOutput(const unsigned left, const unsigned top, const unsigned width, const unsigned height) {	PCchannel channel;    GLint type = GL_UNSIGNED_BYTE;	{ PCerr err = pcFrameResultChannel(mContext, mFrameId, left, top, width, height, PC_CHANNEL_COLOR, &channel);	PCCHECKERROR("FrameProcessor::displayOutput", err); }	// Convert ParaComp pixel format to OpenGL pixel format	GLint format = convertPixelFormat(channel.pixelFormat);	// Setup the proper alignment for glDrawPixels to work cleanly    glPixelStorei(GL_UNPACK_ALIGNMENT, channel.alignment);    // Setup ROW_LENGTH if needed, again needed for glDrawPixels    if(channel.rowLength != (PCint) channel.width)		glPixelStorei(GL_UNPACK_ROW_LENGTH, channel.rowLength);	else		// This is also the default		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);	// Setup the raster position to the bottom left of the window    glWindowPos2iARB(0,0);    // Draw the results    GLboolean depthTestIsEnabled = glIsEnabled(GL_DEPTH_TEST);	glDisable(GL_DEPTH_TEST);    glDrawPixels(channel.width, channel.height, format, type, channel.address);    if(depthTestIsEnabled) glEnable(GL_DEPTH_TEST);}int FrameProcessor::convertPixelFormat(int pcPixelFormat) {	// Decide the pixel format to use with GL from the channel structure	// NOTE: We set BGR8 when creating the context, so we'll get that back	// The code below is just intended to show how to handle the general case	switch(pcPixelFormat)  {		case PC_PF_BGRA8: return GL_BGRA;        case PC_PF_BGR8:  return GL_BGR;		case PC_PF_RGBA8: return GL_RGBA;		default:			Except("FrameProcessor::convertPixelFormat", "Invalid pixel format. Internal ParaComp error.");	}		return -1;}// =============================================================================FrameProcessorHP::FrameProcessorHP(PCcontext context, bool needSorting) :	FrameProcessor(context, needSorting){}void FrameProcessorHP::displayOutput(const unsigned left, const unsigned top, const unsigned width, const unsigned height) {		// TODO left, top, width, and height are totally ignored!	    GLboolean depthTestIsEnabled = glIsEnabled(GL_DEPTH_TEST);	glDisable(GL_DEPTH_TEST);	// Clear the rendered image so that the composited result is clear    glClear(GL_COLOR_BUFFER_BIT);	// Error code	PCerr err;		// PCresult is available only in the HP supplied pcapi.h	PCresult result;	// The master will get the composite of all the framelets and render it    // The master will get each piece that the API provides and render it. If	// PC_ALL_OUTPUT_RETURNED is returned, then the last piece was returned by	// the previous call	while((err = pcFrameWaitOutputHP(mContext, mFrameId, &result)) != PC_ALL_OUTPUT_RETURNED) {		// Catch any errors that could have happened		PCCHECKERROR("FrameProcessorHP::displayOutput", err);		PCchannel channel;    	GLint type = GL_UNSIGNED_BYTE;		err = pcResultGetChannelHP(result, PC_CHANNEL_COLOR, &channel);		PCCHECKERROR("FrameProcessorHP::displayOutput", err);		// Convert ParaComp pixel format to OpenGL pixel format		GLint format = convertPixelFormat(channel.pixelFormat);				// Setup the proper alignment for glDrawPixels to work cleanly    	glPixelStorei(GL_UNPACK_ALIGNMENT, channel.alignment);    	// Setup ROW_LENGTH if needed, again needed for glDrawPixels    	if(channel.rowLength != (PCint) channel.width)			glPixelStorei(GL_UNPACK_ROW_LENGTH, channel.rowLength);		else			// This is also the default			glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);		// Setup the raster position to start pixel of the result    	glWindowPos2iARB(channel.xOffset, channel.yOffset);		    	// Draw the results    	glDrawPixels(channel.width, channel.height, format, type, channel.address);	}    if(depthTestIsEnabled) glEnable(GL_DEPTH_TEST);}#undef PCCHECKERROR} // namespace MinGLE#endif // MINGLE_PARACOMP_SUPPORT == 1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -