[Solved] Scolling texture of numpy array, efficient way.

pepere

06-03-2009 00:36:38

Hello,

First I'm a newbie with 3D so perhaps, my way of thinking is surely not the way you'll do (some any comment welcomed!)

I've taken a look at an example on the web about how to integrate matplolib array into an ogre texture.
My objective is to do an hardware accelerated data viewer:
Basically an array sizex = 1, sizey = 512 come from network and I want to put it to the first line of the texture.
Then I rotate the texture with U,V mapping to do some hardware accelerated scrolling.
The full texture represent for example the data lines along the time.
So the final texture will be 2048x512.

Here is what I do to initialize the full texture at the beginning:

def frameStarted(...)
...
# Lock, copy and unlock the pixel buffer
pointer = self.pixelBuffer.lock (0, self.cbuffer_size, ogre.HardwareBuffer.HBL_DISCARD)
ctypes.memmove(ogre.CastInt(pointer), self.buffer.ctypes.data, self.cbuffer_size)
self.pixelBuffer.unlock()
...

That's pretty fast! Now I would like to update the texture:

from numpy.random import randint as rnd
self.buffer[0:1,:]= 0xFFFF0000 + rnd(0,255)

Ok this seems to change one line of the texture.
if I add a parameter line:
self.buffer[line:line+1,:]= 0xFFFF0000 + rnd(0,255)
line+=1

The whole texture is refreshed in 512 loop.

Now I've also added this code to 'move' quickly the texture:

V = self.app.texture_unit.getTextureVScroll()
self.app.texture_unit.setTextureVScroll(V-0.001)

The problem is that:
1) How can I tell "het only one pixel at a time please! V-0.001 should it be 1/512 ?_?
2) And is there a way to say: "Please for UV mapping lines that goes out of bound make them loopback to other side!"
(any U/V spherical mapping option?)

Thx for any comments help!

ps: I was thinking about a way to use a 16000 * 512 scolling. Seems I'm limited to 4096*4096 texture.
So is the best way to use 4 textures of 4096*512 and move last line of first one the first line of second one etc... and play with each u,v mapping?
(as you can see it should not take to much computation time... well I hope)

Does all video card support 4096 texture or is more common for example 512*512?

Is there best way to resolve this problem :) ?

cheers,
Laurent

bharling

06-03-2009 09:11:12

Hmm.. I can only answer question 2 I'm afraid:

2) And is there a way to say: "Please for UV mapping lines that goes out of bound make them loopback to other side!"
(any U/V spherical mapping option?)


You need to change the texture addressing mode to 'wrap' like this

tUnitState = myMaterial.getTechnique(0).getPass(0).getTextureUnitState(0)
tUnitState.setTextureAddressingMode( ogre.TextureUnitState.TAM_WRAP )


Though apparently thats the default setting anyway, so perhaps its something else. Try that first anyway!

pepere

06-03-2009 09:53:23

Yep thx! You've solved my question 2 :)

pepere

06-03-2009 23:35:42

Ho for your information, you where true!

#tUnitState.setTextureAddressingMode( ogre.TextureUnitState.TAM_CLAMP )
tUnitState = material_pass.getTextureUnitState(0)
tUnitState.setTextureAddressingMode( ogre.TextureUnitState.TAM_WRAP )


TAM_WRAP is the default but i had coied some code that seted up TAM_CLAMP :(

And finally I've found my answer 1)
To move texture of nb_pixel pixel of a texture_size:

V = self.app.texture_unit.getTextureVScroll()
self.app.texture_unit.setTextureVScroll(V+nb_pixel/float(texture_size))