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

📄 othercomputationsongpu.cpp

📁 PDE simulator on GPU.
💻 CPP
字号:
// OtherComputationsOnGPU.cpp: implementation of the OtherComputationsOnGPU class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "shadow.h"
#include "OtherComputationsOnGPU.h"

#include "FragmentProgram.h"
#include "CommonHW.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////////
///////Sort the data on GPU
///////Just support RECT in one Channel
//////////////////////////////////////////////////////////////////////////
void BitonicSortOnGPU(CVectorOnGPU& input)
{
	////Determine How Many Passes Needed Here!
	int i, nPass = 5;
	////////////////////////////////////////////
	///Ax---->Matrix-Vector Product
	unsigned int ShaderID;

	unsigned int _iTextureTarget = input.GetTextureTarget();
	int Width  = input.GetWidth();
	int Height = input.GetHeight(); 


	if(_iTextureTarget == GL_TEXTURE_2D)
	{
		AfxMessageBox("Not support GL_TEXTURE_2D in current system(BitonicSortOnGPU) for the reason of float precision!");
		return;
		//ShaderID = GlobeShaderID[CL_SORT_VECTOR_2D].ShaderID;
		//LoadFragmentProgramFromFile("..\\BitonicSort.fp", ShaderID);
	}
	else
	{
		ShaderID = GlobeShaderID[CL_SORT_VECTOR_RECT].ShaderID;
		//LoadFragmentProgramFromFile("..\\BitonicSortRECT.fp", ShaderID);
	}

	//////////////////////////////////////////////
	///// Clear the framebuffer firstly to avoid the previous computation
	///// This step is important to avoid computation errors
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glDisable(GL_DEPTH_TEST);

	///// Bind the Fragment Program to current drawing
	glEnable(GL_FRAGMENT_PROGRAM_NV);

	unsigned char strTexPara[] = "TexPARA";
	int len = strlen((const char*)strTexPara);
	float TexelPara[4];
	//# TexPARA.x = Offset
	//# TexPARA.y = Width of Data Texture
	//# TexPARA.z = Stage
	//# TexPARA.w = StepNo
	TexelPara[0] = 0;
	TexelPara[1] = Width;
	TexelPara[2] = 0;
	TexelPara[3] = 0;
	
	glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, ShaderID);
	
	//////////////////////////////////////////////
	//# Stored Data in Tex0 which need to sort
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(_iTextureTarget, input.GetTextureID());	

	///Following: 
	for(i=0; i<nPass; i++)
	{	
		/// Determine the StepNo of Each Pass
		TexelPara[3] = i;
		glProgramNamedParameter4fvNV(ShaderID,  len, strTexPara, TexelPara);
		
		glBegin( GL_QUADS );
			glVertex2d( 0, 0 );
			glVertex2d( Width, 0 );
			glVertex2d( Width, Height );
			glVertex2d( 0, Height );
		glEnd();

		// Now we need to copy the resulting pixels into the output
		// save the result texture into result
		glBindTexture(_iTextureTarget, input.GetTextureID());
		glCopyTexSubImage2D(_iTextureTarget, 0, 0, 0, 0, 0, Width, Height);
	}

	glDisable(GL_FRAGMENT_PROGRAM_NV);

	return;
}

⌨️ 快捷键说明

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