opengl - How to copy CUDA generated PBO to Texture with Mipmapping -
i'm trying copy pbo texture automipmapping enabled, seems top level texture generated (in other words, no mipmapping occuring).
i'm building pbo using
//generate buffer id called pbo (pixel buffer object) glgenbuffers(1, pbo); //make current unpack buffer glbindbuffer(gl_pixel_unpack_buffer, *pbo); //allocate data buffer. 4-channel 8-bit image glbufferdata(gl_pixel_unpack_buffer, size_tex_data, null, gl_dynamic_copy); cudaglregisterbufferobject(*pbo);
and i'm buildilng texture using
// enable texturing glenable(gl_texture_2d); // generate texture identifier glgentextures(1,textureid); // make current texture (remember gl state-based) glbindtexture( gl_texture_2d, *textureid); // allocate texture memory. last parameter null since // want allocate memory, not initialize glteximage2d(gl_texture_2d, 0, gl_rgba_float32_ati, size_x, size_y, 0, gl_rgba, gl_float, null); // must set filter mode, gl_linear enables interpolation when scaling gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear_mipmap_linear); gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear); gltexparameteri(gl_texture_2d, gl_generate_mipmap, gl_true);
later in kernel modify pbo using like:
float4* aryptr = null; cudaglmapbufferobject((void**)&aryptr, *pbo); //pixel* gpupixelsrawptr = thrust::raw_pointer_cast(&gpupixels[0]); //... cuda stuff aryptr ... //if don't unmap pbo opengl won't able use it: cudaglunmapbufferobject(*pbo);
now, before draw screen using texture generated above call: (note rtmipmaptex = *textureid above , rtresultpbo = *pbo above)
glenable(gl_depth); glenable(gl_texture_2d); glbindtexture(gl_texture_2d, rtmipmaptex); glbindbuffer(gl_pixel_unpack_buffer, rtresultpbo); gltexsubimage2d(gl_texture_2d, 0, 0, 0, canvassize.x, canvassize.y, gl_rgba, gl_float, null);
this works fine , correctly displays texture. but, if change last line
gltexsubimage2d(gl_texture_2d, 1, 0, 0, canvassize.x, canvassize.y, gl_rgba, gl_float, null);
which, far understand, should show me first level instead of zeroth level texture in texture pyramid, blank white texture.
how copy texture pbo in such way auto-mipmapping triggered?
thanks.
i being idiot. above code works perfectly, problem
gltexsubimage2d(gl_texture_2d, 1, 0, 0, canvassize.x, canvassize.y, gl_rgba, gl_float, null);
doesn't select mipmap level texture, selects pbo, not mipmapped. instead can display particular mipmapped level with:
gltexenvi(gl_texture_filter_control,gl_texture_lod_bias, 4);
Comments
Post a Comment