Thread: GPGPU Woes (Fluid Dynamics)
i have 2d array allocated 1d array (pgridlocations). array represents points on flat 2d grid. each point pair of gluints (e.g. bottom left (0,0), top right point (width,height)). integral values.
want pass array of pairs shader fancy calculations , write out results texture (bound via fbo) of same width / height grid dimensions. each texel (i use single channel) contains z-displacement value of wave @ position on surface.
finding though getting pairs shader difficult , i've gone through lot of documentation , cannot seem work. whether gldrawarrays called or not, buffer seems contain same junk.
here initialize pairs:
here try pass data shader:code:// initialize grid location pairs... // calculate required storage space location pairs... gluint const storage = m_width * m_height * sizeof(gluint) * 2; // allocate... gluint *pgridlocations = (gluint *) malloc(storage); // initialize vertex ordinals across grid... for(gluint currenty = 0; currenty < m_height; ++currenty) for(gluint currentx = 0; currentx < m_width; ++currentx) { // calculate current location... gluint *pcurrentlocation = pgridlocations + (2 * ((currenty * m_width) + currentx)); // store grid index... pcurrentlocation[0] = currentx; pcurrentlocation[1] = currenty; } // initialize vertex buffer object vertex pairs... // allocate... glgenbuffers(1, &m_vbo_gridlocations); // select... glbindbuffer(gl_array_buffer, m_vbo_gridlocations); // commit grid indices card... glbufferdata(gl_array_buffer, storage, pgridlocations, gl_static_draw); // associate data generic vertex attribute... glvertexattribipointer(m_gva_gridlocations, 2, gl_unsigned_int, 0, bufferoffset(0));
vertex shader:code:// redirect rendering through our framebuffer object... glbindframebuffer(gl_framebuffer, m_framebufferobject); // check opengl errors... printopenglerrors(); // make sure data written texture replaces , doesn't modulate... gltexenvi(gl_texture_env, gl_texture_env_mode, gl_replace); // send grid location data program... // install program... gluseprogram(m_po_evaluatewaves); // select z map texture... glbindtexture(gl_texture_2d, m_zmaps_textureid[0]); // enable required vertex arrays... glenablevertexattribarray(m_gva_gridlocations); // select grid indices... glbindbuffer(gl_array_buffer, m_vbo_gridlocations); // commit data shader... gldrawarrays(gl_points, 0, m_width * m_height); // disable required vertex arrays... gldisablevertexattribarray(m_gva_gridlocations);
and fragment shader:code:// want @ least glsl 1.50... #version 150 // input variables... // grid location... in uvec2 gridlocation; // variables fragment shader, none of need interpolated... // grid location... flat out uvec2 location; // entry point... void main() { location = gridlocation; }
and passes 0 or other test value on fragment shader writes logical buffer gl_color_attachment0, nothing happens.code:// want @ least glsl 1.50... #version 150 // input variables... // grid location... flat in uvec2 location; // output variables... // z-displacement... out float storedz_0; // entry point... void main() { float temp = min(float(location.x), 0.5); temp = max(temp, 0.5); storedz_0 = temp; }
i've been stumped on days , appreciated.
kip
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk GPGPU Woes (Fluid Dynamics)
Ubuntu
Comments
Post a Comment