ios - How to manipulate texture content on the fly? -


i have ipad app working on , 1 possible feature contemplating allow user touch image , deform it.

basically image painting , when user drags fingers across image, image deform , pixels touched "dragged" along image. sorry if hard understand, bottom line want edit content of texture on fly user interacts it.

is there effective technique this? trying grasp of need done , how heavy operation be.

right thing can think of search through content of texture based on touched , copy pixel data , kind of blend on existing pixel data finger moves. reloading texture glteximage2d periodically effect.

there @ least 2 fundamentally different approaches:

1. update pixels (i assume mean in question)

the effective technique change pixels in texture called render-to-texture , can done in opengl/opengl es via fbos. on desktop opengl can use pixel buffer objects (pbos) manipulate pixel data directly on gpu (but opengl es not support yet).

on unextended opengl can change pixels in system memory , update texture glteximage2d/gltexsubimage2d - inefficient last resort solution , should avoided if possible. gltexsubimage2d faster since updates pixel inside existing texture, while glteximage2d creates entirely new texture (as benefit can change size , pixel format of texture). on other side, gltexsubimage2d allows update parts of texture.

you want work opengl es, propose following steps:

  • replace glteximage2d() gltexsubimage2d() - if gain enough performance that's it, let be;
  • implement render-to-texture fbos , shaders - require far more work rewrite code, give better performance.

for fbos code can this:

// setup fbo glgenframebuffers( 1, &fframebuffer ); glbindframebuffer( gl_framebuffer, fframebuffer ); glframebuffertexture2d( gl_framebuffer, gl_color_attachment0, gl_texture_2d, yourtextureid, 0 ); glbindframebuffer( gl_framebuffer, 0 );  // render fbo glbindframebuffer( gl_framebuffer, fframebuffer ); glviewport( 0, 0, yourtexturewidth, yourtextureheight ); rendering code goes here - draw directly texture glbindframebuffer( gl_framebuffer, 0 );  // cleanup glbindframebuffer( gl_framebuffer, 0 ); gldeleteframebuffers( 1, &fframebuffer ); 

keep in mind not pixel formats can rendered to. rgb/rgba fine.

2. update geometry

you can change geometry of object texture mapped on. geometry should tesselated enough allow smooth interaction , prevent artifacts appear. deformation of geometry can done via different methods: parametric surfaces, nurbs, patches.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -