splitting a matrix into lots of textures using javascript

Feb 28, 2010 at 10:30pm

splitting a matrix into lots of textures using javascript

I have a 50 * 3000 image with 60 50*50 frames stacked vertically, each one with a knob at a different rotation (a la pictcontrol). I need to put each frame on the gpu as a texture. I managed to do it with poly~ and jit.gl.texture, but i can’t get the same thing working in javascript. Here is my attempt at doing it in JS:

var tempmatrix = new JitterMatrix(4,”char”,50,50);
tempmatrix.name = “tempmatrix”;
tempmatrix.usesrcdim = 1;
tempmatrix.adapt = 1;

var tempqtmovie = new JitterObject(“jit.qt.movie”);
tempqtmovie.dim = [50, 3000];
tempqtmovie.read(“es_knob.60.png”);

var textures = new Array();

for (i=0;i<60;i++)
{
tempmatrix.srcdimstart = [0,(i*50)];
tempmatrix.srcdimend = [50,(i*50)+50];
tempqtmovie.matrixcalc(tempmatrix, tempmatrix);

textures[i] = new JitterObject(“jit.gl.texture”,”ctxt”);
textures[i].name = “frame”+i;
textures[i].jit_matrix(“tempmatrix”);
}

which doesn’t work (i get scrambled frames). And here is what i do in with poly~:


----------begin_max5_patcher----------
720.3ocyX10jZBCEF9Z7WQFldUGWGRfnPuZ6uiN6rSDxpYGIXgPq6ty1e6Me
4pqEQrBQmwwP9.787jWNbv2F44OuXCsxG7MvO.dduMxySOjZ.OaeO+bxlzUj
J8x74zeWL+Y+wloDzMB8veEfC1N3ZhHcIiu3wRZpvbsCiClDLFfB0MgnIXYG
4wfGrmySEbAmjS0WruWxHq72alJ1q5YfH4oaFlWmy3qnBspP1AYY5yWJv6PI
96VYQsX6Rg1QMCIdYM0nPeFWp0GTS99nQpuFeYD4N.rC.Ivc.I1Y.oNeNsrk
fGYBdXjtAaIQuE7vFB9YMG7n1B9w.+4D9hd0Ubh6SPt+9DjqrEyqEhBdaAuw
IL6C+vAw9I2jgmYnz66t0ux.SCZ8FeaPBM23iC6YueC6vvi38CaEKi2012YF
WWr5k+.DzJwD0gJhQJWTARExEbbxAMVhHSCr2QWCNJHtYzEzev3YlXRNQTx1
.dpTpcPDHcIoTllP8495JZUYZFKuUSkEMgQ1rGICOZldlITkw4il3TYoFnLH
Patin+2TH3qcFDkc3mRGQwuXTv8p8coKHLHH3z69nY1mp5fce3UX2OmVUQVP
+GjURIYcfNFOQHVyn3A8QpmoIpewgIcAkmobNeoK0fZ7MIICOYhuAHSkfTJ.
m.MnOiloCOZRtpnQxjETQ6LAGrOSvNfIvoWUnTrlxkEp0JRz4TLlEbjCHRzE
QDsv7Ww3G9N+5XSM9mwTUQcY51K01ZIAnOhuLYMbLNQvjOUduEI21.6fvRVV
FUO+1nLmkstPVUoUDnjP064.CgpFbPxG8Nx1YupV0qFdNp8B0j5+kXuetl0T
rakTbGjzA5dv0zrtno3aPMgbplfcPRScphRt4TT7Mmh5jSB6VIg5fjbbNftX
tgtM8MtKRxsT5lSQphTNsjbq89fZR5GMYKUILNVWwBZWuKTsSGZ.J679n+h2
bR+N
-----------end_max5_patcher-----------

poly subpatch


----------begin_max5_patcher----------
461.3ocuU1rTCBCDG+L8oHSTu01oIzVKdymCGGlzRJMNPBCInUcpO6F1P09g
1RUfKIS1cyx+8G6Bu2yCOWslqwn6POf77dummGXpzfW0YObJa8hDlFBCK4un
l+Dtuykgu1.lERDYqwLlYwJgLNLmuv3x8siFNpOhD.a9vJ0thdr5JKURijkx
gbcetfkf2wiV7F3gPsWzYVVjJjIbCHJRkQQDbeq9FDf+NPUg4vHclLulwc5C
i+RJZ1y7nPaNrhOjYL4h4EFGi7.l.gsA1f0M85++X2fShN5XG6bTymNbRixN
5wra5ExNgzJ0GaNdjnXQyYx3SAEJPCGZl1A8SiuPl.5uIghNK2x4knk41x5F
w4YS0vV.o8gi+kOr0bfwrRnyTIu9w4QxLXcxr1mHzelHzSMB0u4mjdRXFFmL
r7bQNGc0o9NCwwHpaZZVP6CIxkRIa4DFmDVUNk.6uQqTtVyh4GgqxpCcM47M
RUaSl.CZyZyOFS9WyVftvIB4g+jGpsR66iIspHew1TU83QeWcQbsQHYFgRta
Lz8BZkHJhC92ViohnLks2tRC+x6r5JI+5HoNUQiqgh5VFQqghl1oJZZMTjem
pnf1t01dXSuOAfWBgNF
-----------end_max5_patcher-----------

Any ideas?

#48830
Mar 2, 2010 at 8:06pm

Haven’t had times to check out your patch and script in action, but what happens if you use a separate matrix for each jit.gl.texture. Also make sure you set adapt to zero for your destination matrix. Otherwise, it will resize.

#175510
Mar 3, 2010 at 11:10am

I tried with separate matrices with the same results. Here is a stripped down example which shows the problem. I think the srcdim settings are being ignored, since it appears that each frame contains the entire 50*3000 image.

cheers,

oli

Attachments:
  1. texturetest.zip
#175511
Mar 3, 2010 at 5:10pm

Okay. Looking closer, here’s the deal:

1. setting a matrix’s srcdim/dstdim attributes doesn’t work for some other object’s matrix calc method. It works when copying from one matrix to another in the frommatrix method. This is solved by creating one matrix to render the movie into and then using the destination matrix’s frommatrix method to copy each slice. jit.qt.movie does have some ability to render to a sub region with srcrect/dstrect by setting the jit.qt.movie’s attributes, but I wouldn’t recommend it since this is less efficient than doing in the matrix copy (QT’s scaling/cropping/rotation features significantly slow down the image decompression).

var tempmatrix = new JitterMatrix(4,"char",50,50);
tempmatrix.name = "tempmatrix";
tempmatrix.usesrcdim = 1;
tempmatrix.adapt = 0;

var tempqtmovie = new JitterObject("jit.qt.movie");
tempqtmovie.dim = [50, 3000];
tempqtmovie.read("es_knob.60.png");

var textures = new Array();

// render jit.qt.movie to the size of the movie matrix once
// then copy that matrix with the frommatrix method
var moviematrix = new JitterMatrix(4,"char",50,3000);
tempqtmovie.matrixcalc(moviematrix, moviematrix);

for (i=0;i<60;i++)
{
tempmatrix.srcdimstart = [0,(i*50)];
tempmatrix.srcdimend = [50,(i*50)+50];

// *this* function is where a matrix srcdim/dstdim
// is taken into account
tempmatrix.frommatrix(moviematrix);

textures[i] = new JitterObject("jit.gl.texture","ctxt");
textures[i].name = "frame"+i;
textures[i].jit_matrix("tempmatrix");
}

2. your patch has stack overflows since you are not popping the transform and modelview matrices you push. These need to be matched by adding the following to the bottom of your draw method.


glmatrixmode("modelview");
glpopmatrix();
glmatrixmode("projection");
glpopmatrix();

Side note: if you want to use sliced textures like this, you can also use one large texture with offsets rather than many textures. Simply adjust your texture coordinates to match the subregion of the larger texture, or if it’s easier for your code, set the texture matrix transform accordingly.

Hope this helps.

#175512
Mar 4, 2010 at 11:46am

>Hope this helps.

extremely helpful as usual. thanks

>Side note: if you want to use sliced textures like this, you can also use one large texture with offsets rather than >many textures. Simply adjust your texture coordinates to match the subregion of the larger texture, or if it’s >easier for your code, set the texture matrix transform accordingly.

would you recommend this approach (would it be more efficient)? The first thing you mention is what i tried first, but i couldn’t figure out how to set the texture coordinates based on pixels.

#175513

You must be logged in to reply to this topic.