13.07.2015 Views

Paper - IDAV: Institute for Data Analysis and Visualization

Paper - IDAV: Institute for Data Analysis and Visualization

Paper - IDAV: Institute for Data Analysis and Visualization

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

34 · Lefohn, Kniss, Strzodka, Sengupta, <strong>and</strong> OwensCGparameter virtSizeParam = cgGetNamedParameter(prog, "virtSize");cgSetParameter4v( virtSizeParam, virtArraySize.data() );CGparameter physSizeParam = cgGetNamedParameter(prog, "physSize");cgSetParameter2v( physSizeParam, physArraySize.data() );CGparameter sizeConstParam = cgGetNamedParameter(prog, "sizeConst");cgSetParameter4v( sizeConstParam, sizeConst.data() );// Specialize size parameterscgSetParameterVariability(virtSizeParam, CG_LITERAL);cgSetParameterVariability(physSizeParam, CG_LITERAL);cgSetParameterVariability(sizeConstParam, CG_LITERAL);// Compile <strong>and</strong> load shadercgCompileProgram(prog);cgGLLoadProgram(prog);// Create Framebuffer Object <strong>and</strong> attach "array2" to COLOR0GLuint fboId;glGenFramebuffersEXT(1, &fboId);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, array2_texId, 0 );// Render screen-aligned quad (physArraySize.x(), physArraySize.y())glMatrixMode(GL_PROJECTION); glLoadIdentity();glMatrixMode(GL_MODELVIEW); glLoadIdentity();glViewport(0, 0, physArraySize.x(), physArraySize.y());glBegin(GL_QUADS);glVertex2f(-1.0f, -1.0f); glVertex2f(+1.0f, -1.0f);glVertex2f(+1.0f, +1.0f); glVertex2f(-1.0f, +1.0f);glEnd();✝✞In contrast, the C++ code <strong>for</strong> the Glift version is:// ... Initialize OpenGL rendering context ...typedef glift::ArrayGpu ArrayType;✆☎// Allocate 2 arrays that hold vec4f valuesvec4i virtArraySize(10, 10, 10, 10);ArrayType array1( virtArraySize );ArrayType array2( virtArraySize );// Create Cg shaderCGprogram prog = cgCreateProgramFromFile( cgCreateContext(), CG_SOURCE, "laplacianGlift.cg",CG_PROFILE_FP40, "main", NULL);// Instantiate Glift Cg typesGliftType arrayTypeCg = glift::cgGetTemplateType();prog = glift::cgInstantiateParameter( prog, "array1", arrayTypeCg );GliftType iterTypeCg = glift::cgGetTemplateType();prog = glift::cgInstantiateParameter( prog, "it", iterTypeCg );// Get GPU range iterator <strong>for</strong> all elements in array2// - This is a neighborhood iterator that permits relative// indexing within the specified neighborhood.vec4i origin(0, 0, 0, 0);vec4i size = virtArraySize;vec4i minNeighborhood(-1, -1, -1, -1);vec4i maxNeighborhood(+1, +1, +1, +1);ArrayType::gpu_neighbor_range rit = array2.gpu_neighbor_range( origin, size, minNeighborhood, maxNeighborhood );// Bind parameters to shaderCGparameter array1Param = cgGetNamedParameter(prog, "array1");array1.bind_<strong>for</strong>_read( array1Param );CGparameter iterParam = cgGetNamedParameter(prog, "it");rit.bind_<strong>for</strong>_read( iterParam );ACM Transactions on Graphics, Vol. 25, No. 1, January 2006.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!