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); } }
void GR_rmanPtc::renderWire( GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset &ptinfo, const GR_DisplayOption *dopt, float lod, const GU_PrimGroupClosure *hidden_geometry ) { int i, nprim; GEO_Primitive *prim; UT_Vector3 v3; rmanPtcSop::rmanPtcDetail *detail = dynamic_cast<rmanPtcSop::rmanPtcDetail*>(gdp); if ( !detail ) return; // rebuild our display list if ( detail->redraw ) { srand(0); GEO_PointList &points = detail->points(); int display_channel = detail->display_channel; // render as points GEO_Point *pt = 0; UT_Vector4 pos; float col[3] = {1.0,1.0,1.0}; if ( !detail->use_disk ) { ren.pushPointSize(detail->point_size); ren.beginPoint(); } for ( unsigned int i=0; i<points.entries(); ++i ) { if ( rand()/(float)RAND_MAX<=detail->display_probability ) { // point position pt = points[i]; pos = pt->getPos(); // display colour float *ptr = NULL; if (detail->attributes.size() >0) { ptr = pt->castAttribData<float>( detail->attributes[display_channel] ); if (ptr) { if ( detail->attribute_size[display_channel]==1) col[0] = col[1] = col[2] = ptr[0]; else { col[0] = ptr[0]; col[1] = ptr[1]; col[2] = ptr[2]; } } } // draw point if ( !detail->use_cull_bbox || detail->cull_bbox.isInside( pos ) ) { if ( !detail->use_disk ) { // render as points ren.setColor( col[0], col[1], col[2], 1 ); ren.vertex3DW( pos.x(), pos.y(), pos.z() ); } else { // render as disks UT_Vector3 n = *pt->castAttribData<UT_Vector3>(detail->N_attrib); float r = *pt->castAttribData<float>(detail->R_attrib); n.normalize(); UT_Vector3 ref(1,0,0); UT_Vector3 up = ref; up.cross(n); up.normalize(); UT_Vector3 right = up; right.cross(n); right.normalize(); UT_DMatrix4 mat( right.x(), right.y(), right.z(), 0, up.x(), up.y(), up.z(), 0, n.x(), n.y(), n.z(), 0, pos.x(), pos.y(), pos.z(), 1 ); ren.pushMatrix(); ren.multiplyMatrix(mat); ren.pushColor( UT_Color( UT_RGB, col[0], col[1], col[2] ) ); ren.circlefW( 0, 0, detail->point_size * r, 8 ); ren.popColor(); ren.popMatrix(); } } } } if ( !detail->use_disk ) { ren.endPoint(); } } }