Forums > Javascript

array of textures on the GPU with javascript

October 4, 2006 | 3:55 pm

Hello,

I’m trying to store textures on the GPU using javascript

My idea :

a matrix is sent to a jit.gl.texture, processed by a jit.gl.slab and
then stored in a new jit.gl.texture

I’m achieving this with the following Javascript code, but as I’m
really new to this shader/slab/texture thing, I’m wondering if there
is more efficient solutions.

thanks,

Bertrand

// reference texture
var reftexture = new JitterObject("jit.gl.texture","foo");

//slab
var myslab = new JitterObject("jit.gl.slab","foo");
myslab.file = "cf.gaussian.2p.jxs";
myslab.param("width",0.5,0);

//texture array
var desttexturetab= new Array();
// index of the array
var a=0;

//preview plane
var outplane = new JitterObject("jit.gl.videoplane","foo");

function jit_matrix(m)
{
// creation of an input matrix to get the size of the incomming matrix
//( the adapt attribute of jit.gl.slab doesn’t resize to input source ?)
var inputmatrix = new JitterMatrix(m);
var texture_w = inputmatrix.dim[0];
var texture_h = inputmatrix.dim[1];

reftexture.jit_matrix(inputmatrix.name);

// reference texture is sent and processed in jit.gl.slab
myslab.dim = [texture_w,texture_h];
myslab.texture = reftexture.name;
myslab.draw();

// increment the texture’s array index
a++;
// create the texture object
desttexturetab[a]= new JitterObject("jit.gl.texture","foo");
// name of the texture
desttexturetab[a].name = "texture_"+a;
//apply processed texture from slab to the destination texture
desttexturetab[a].jit_gl_texture(myslab.out_name);

// apply the destination texture to the previewvideoplane
outplane.texture = desttexturetab[a].name;
outplane.draw();
outlet(0,a)
}

http://www.bertrandgondouin.net


October 4, 2006 | 4:33 pm

On Oct 4, 2006, at 8:55 AM, bertrand wrote:
> a matrix is sent to a jit.gl.texture, processed by a jit.gl.slab and
> then stored in a new jit.gl.texture
>
> I’m achieving this with the following Javascript code, but as I’m
> really new to this shader/slab/texture thing, I’m wondering if there
> is more efficient solutions.

This should work. I’d like to note that you’ll need to use the
freepeer method so that perviously existing textures will be removed:

if (desttexturetab[a])
desttexturetab[a].freepeer();

then you can assign it, etc. See mailing list archives for more
information about the use of freepeer()

-Joshua


October 4, 2006 | 6:29 pm

thanks for anticipating my next question !

in fact, while running the script, I’m running into memory problems
with Windows XP max 4.6.2rc1, jitter 1.6.2

I can’t store more than 169 320*240 pictures on the GPU using the
script (the picture 170 makes max crash) , it’s quite few for the
memory size of my graphic card (128 Mo).

The size of the swap file is also increasing badly (around 400 Mo),
when filling up the GPU with the 169 pictures (but this may be normal,
I don’t know…)

I have been trying the freepeer() method with no sucess or improvement.

It’s seems to work ok on the OSX version of Max.

Bertrand

2006/10/4, Joshua Kit Clayton :
>
> On Oct 4, 2006, at 8:55 AM, bertrand wrote:
> > a matrix is sent to a jit.gl.texture, processed by a jit.gl.slab and
> > then stored in a new jit.gl.texture
> >
> > I’m achieving this with the following Javascript code, but as I’m
> > really new to this shader/slab/texture thing, I’m wondering if there
> > is more efficient solutions.
>
>
> This should work. I’d like to note that you’ll need to use the
> freepeer method so that perviously existing textures will be removed:
>
> if (desttexturetab[a])
> desttexturetab[a].freepeer();
>
> then you can assign it, etc. See mailing list archives for more
> information about the use of freepeer()
>
> -Joshua
>

http://www.bertrandgondouin.net


Viewing 3 posts - 1 through 3 (of 3 total)