コード例 #1
0
ファイル: GR_Fluid.C プロジェクト: UIKit0/cudaFluid
void GR_Fluid::renderWire(GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset & /*ptinfo*/,
		    const GR_DisplayOption *dopt, float /*lod*/, const GU_PrimGroupClosure * /*hidden_geometry*/)
{

	GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview");
	fluidAh.setElement(gdp);

	GEO_AttributeHandle fluid3DAh= gdp->getDetailAttribute("cudaFluid3DPreview");
	fluid3DAh.setElement(gdp);

	GEO_AttributeHandle fluid3DSliceAh= gdp->getDetailAttribute("sliceDisplay");
	fluid3DSliceAh.setElement(gdp);

	GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview");
	fluidAh.setElement(gdp);

	GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId");
	fluidIdAh.setElement(gdp);

	if (fluidAh.getI()== 1) {

		VHFluidSolver* currSolver = VHFluidSolver::solverList[fluidIdAh.getI()];

		UT_Vector4 fluidPos(0,0,0);
		UT_Vector3D fluidRot(0,0,0);

		if(gdp->volumeCount() == 1) {
			GEO_Primitive* pprim = gdp->primitives().head();
			GU_PrimVolume* volume = (GU_PrimVolume *)pprim;
			UT_Matrix4 fluidRotMat;
			volume->getTransform4(fluidRotMat);

			UT_XformOrder rotOrder;
			UT_Vector3D scale, trans;
			fluidRotMat.explode(rotOrder, fluidRot, scale, trans);
			fluidRot.radToDeg();
			fluidPos = volume->getVertex().getPt()->getPos();
		}

		float sizeX = currSolver->fluidSize.x*0.5;
		float sizeY = currSolver->fluidSize.y*0.5;

		int newResX = currSolver->res.x;
		int newResY = currSolver->res.y;


		if(displayX != newResX || displayY != newResY) {
			displayX = newResX;
			displayY = newResY;
			initPixelBuffer(true);
		}
					
		cu::cutilSafeCall(cu::cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
		cu::float4 *d_output;
		size_t num_bytes; 
		cu::cutilSafeCall(cu::cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes,  cuda_pbo_resource));
		cu::cudaMemset(d_output, 0, displayX*displayY*sizeof(cu::float4));

		currSolver->renderFluid(d_output);

		cu::cutilSafeCall(cu::cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

		//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
		glBindTexture(GL_TEXTURE_2D, gl_Tex);
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, displayX, displayY, GL_RGBA, GL_FLOAT, 0);
		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

		glEnable(GL_TEXTURE_2D);

		glPushMatrix();
		glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z());
		glRotatef(fluidRot.z(),0,0,1);
		glRotatef(fluidRot.y(),0,1,0);
		glRotatef(fluidRot.x(),1,0,0);

		//glColor3f(1.0,1.0,1.0);
		//glDisable(GL_BLEND);
		//glDisable(GL_LIGHTING);

		//glBegin( GL_QUADS );
		//glTexCoord2f(0.0f, 0.0f); glVertex3f(-sizeX,-sizeY,0.0f);
		//glTexCoord2f(0.0f, 1.0f); glVertex3f(-sizeX,sizeY,0.0f);
		//glTexCoord2f(1.0f, 1.0f); glVertex3f(sizeX,sizeY,0.0f);
		//glTexCoord2f(1.0f, 0.0f); glVertex3f(sizeX,-sizeY,0.0f);
		//glEnd();

		ren.setColor(1,1,1,1);
		ren.blend(0);
		ren.toggleLighting(0);


		const float t0[] = {0,0};
		const float t1[] = {0,1};
		const float t2[] = {1,1};
		const float t3[] = {1,0};

		ren.beginQuads();
		ren.t2DW(t0); ren.vertex3DW(-sizeX,-sizeY,0.0f);
		ren.t2DW(t1); ren.vertex3DW(-sizeX,sizeY,0.0f);
		ren.t2DW(t2); ren.vertex3DW(sizeX,sizeY,0.0f);
		ren.t2DW(t3); ren.vertex3DW(sizeX,-sizeY,0.0f);
		ren.endQuads();

		glDisable(GL_TEXTURE_2D);

		glBindTexture(GL_TEXTURE_2D, 0);

		ren.beginClosedLine();
		ren.vertex3DW(-sizeX,-sizeY,0.0f);
		ren.vertex3DW(-sizeX,sizeY,0.0f);
		ren.vertex3DW(sizeX,sizeY,0.0f);
		ren.vertex3DW(sizeX,-sizeY,0.0f);
		ren.endClosedLine();

		ren.toggleLighting(1);

		glPopMatrix();

	}

	if (fluid3DAh.getI() == 1 || fluid3DSliceAh.getI()== 1) {

		ren.toggleLighting(0);

		VHFluidSolver3D* curr3DSolver = VHFluidSolver3D::solverList[fluidIdAh.getI()];

		UT_Vector4 fluidPos(0,0,0);
		UT_Vector3D fluidRot(0,0,0);

		if(gdp->volumeCount() == 1) {
			GEO_Primitive* pprim = gdp->primitives().head();
			GU_PrimVolume* volume = (GU_PrimVolume *)pprim;
			UT_Matrix4 fluidRotMat;
			volume->getTransform4(fluidRotMat);

			UT_XformOrder rotOrder;
			UT_Vector3D scale, trans;
			fluidRotMat.explode(rotOrder, fluidRot, scale, trans);
			fluidRot.radToDeg();
			fluidPos = volume->getVertex().getPt()->getPos();
		}


		float sizeX = curr3DSolver->fluidSize.x*0.5;
		float sizeY = curr3DSolver->fluidSize.y*0.5;
		float sizeZ = curr3DSolver->fluidSize.z*0.5;

		if(curr3DSolver->drawCube) {
			glPushMatrix();
			glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z());
			glRotatef(fluidRot.z(),0,0,1);
			glRotatef(fluidRot.y(),0,1,0);
			glRotatef(fluidRot.x(),1,0,0);
			drawWireCube(sizeX,sizeY,sizeZ, ren);
			glPopMatrix();
		}

			if (fluid3DAh.getI()== 1) {

				curr3DSolver->drawFluid();


			}

			if (fluid3DSliceAh.getI()== 1) {

				curr3DSolver->drawFluidSlice();


			}

			ren.toggleLighting(1);

		}



}
コード例 #2
0
ファイル: GR_CudaHardware.C プロジェクト: UIKit0/cudaFluid
void GR_CudaHardware::renderWire(GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset & /*ptinfo*/,
		    const GR_DisplayOption *dopt, float /*lod*/, const GU_PrimGroupClosure * /*hidden_geometry*/)
{

	GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview");
	fluidAh.setElement(gdp);

	if (fluidAh.getI()== 1) {

		GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId");
		fluidIdAh.setElement(gdp);

		VHFluidSolver* currSolver = VHFluidSolver::solverList[fluidIdAh.getI()];

		UT_Vector4 fluidPos(0,0,0);
		UT_Vector3D fluidRot(0,0,0);

		if(gdp->volumeCount() == 1) {
			GEO_Primitive* pprim = gdp->primitives().head();
			GU_PrimVolume* volume = (GU_PrimVolume *)pprim;
			UT_Matrix4 fluidRotMat;
			volume->getTransform4(fluidRotMat);

			UT_XformOrder rotOrder;
			UT_Vector3D scale, trans;
			fluidRotMat.explode(rotOrder, fluidRot, scale, trans);
			fluidRot.radToDeg();
			fluidPos = volume->getVertex().getPt()->getPos();
		}

		currSolver->drawFluid(fluidRot.x(), fluidRot.y(), fluidRot.z(),
										fluidPos.x(), fluidPos.y(), fluidPos.z());

	}

	GEO_AttributeHandle partsAh= gdp->getDetailAttribute("cudaParticlesPreview");
	partsAh.setElement(gdp);

	if (partsAh.getI()== 1) {

		GEO_AttributeHandle partsIdAh= gdp->getDetailAttribute("systemId");
		partsIdAh.setElement(gdp);

		ren.toggleLighting(0);

		VHParticlesSystem* currSystem = VHParticlesSystem::systemsList[partsIdAh.getI()];

		glClear(GL_COLOR_BUFFER_BIT);

		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE );

		currSystem->draw();

		glDisable( GL_BLEND );

		ren.toggleLighting(1);

	
	}

	GEO_AttributeHandle fluid3DAh= gdp->getDetailAttribute("cudaFluid3DPreview");
	fluid3DAh.setElement(gdp);

	GEO_AttributeHandle fluid3DSliceAh= gdp->getDetailAttribute("sliceDisplay");
	fluid3DSliceAh.setElement(gdp);

	if (fluid3DAh.getI() == 1 || fluid3DSliceAh.getI()== 1) {

		GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId");
		fluidIdAh.setElement(gdp);

		ren.toggleLighting(0);

		VHFluidSolver3D* curr3DSolver = VHFluidSolver3D::solverList[fluidIdAh.getI()];

		UT_Vector4 fluidPos(0,0,0);
		UT_Vector3D fluidRot(0,0,0);

		if(gdp->volumeCount() > 0) {
			GEO_Primitive* pprim = gdp->primitives().head();
			GU_PrimVolume* volume = (GU_PrimVolume *)pprim;
			UT_Matrix4 fluidRotMat;
			volume->getTransform4(fluidRotMat);

			UT_XformOrder rotOrder;
			UT_Vector3D scale, trans;
			fluidRotMat.explode(rotOrder, fluidRot, scale, trans);
			fluidRot.radToDeg();
			fluidPos = volume->getVertex().getPt()->getPos();
		}


		float sizeX = curr3DSolver->fluidSize.x*0.5;
		float sizeY = curr3DSolver->fluidSize.y*0.5;
		float sizeZ = curr3DSolver->fluidSize.z*0.5;

		if(curr3DSolver->drawCube) {
			glPushMatrix();
			glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z());
			glRotatef(fluidRot.z(),0,0,1);
			glRotatef(fluidRot.y(),0,1,0);
			glRotatef(fluidRot.x(),1,0,0);
			drawWireCube(sizeX,sizeY,sizeZ, ren);
			glPopMatrix();
		}

			if (fluid3DAh.getI()== 1) {

				curr3DSolver->drawFluid(fluidRot.x(), fluidRot.y(), fluidRot.z(),
										fluidPos.x(), fluidPos.y(), fluidPos.z());

			}

			if (fluid3DSliceAh.getI()== 1) {

				curr3DSolver->drawFluidSlice(fluidRot.x(), fluidRot.y(), fluidRot.z(),
										fluidPos.x(), fluidPos.y(), fluidPos.z());

			}

			ren.toggleLighting(1);

		}




}