We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › [SOLVED] Performance issue with Patterns
Pages: 1 2 
[SOLVED] Performance issue with Patterns (Read 1717 times)
[SOLVED] Performance issue with Patterns
Feb 26th, 2008, 2:56pm
 
Hi all

I need your help and advices here Smiley

I discovered processing a few days ago and programmed a pattern generation tool with it. Programmed in one night, it was used for live visuals during a party on 4 screens driven by 2 MacBooks and one PC laptop.

You can have an idea of the thing here :
http://www.youtube.com/watch?v=gmpb9YYEPLU

The basic idea is to generate a pattern that can be slightly or completely different at each frame, then scale it, rotate it, and pave the whole screen with that pattern.

However i am facing a performance issue. therefore i am looking for some advices. I am unsure which approach to choose. so far i tried :

-use size(x,y) rotate() and scale() the referential and draw each pattern in using triangle(),quad().

-same as above but with size(x,y,OPENGL)

-use size(x,y) and draw the pattern once in a PGraphics object and replicate it on screen.

-same as above but with size(x,y,OPENGL)

None of these where fast enough. and i believe that with today's computer and using openGL, i could either:

- build up on the fly a texture of the pattern, make a quad() of the size of the screen, and pave it with the texture. however i didn't an option to make the texture repeat itself on the object. I didn't manage to use Pgraphics object as quad() texture anyways Sad

- Draw each shape of the pattern using openGL triangles and fill them with the appropriate color. I thought switching to size(x,y,OPENGL); would do the trick. But when i look at the performance it seems it didn't Sad

i am surely missing some basic thing here.

Any ideas or thoughts ?

PS: if some of you are interested, i can send you the source.

henri
Re: Performance issue with Patterns
Reply #1 - Feb 26th, 2008, 6:34pm
 
> build up on the fly a texture of the pattern, make a quad() of the size of the screen, and pave it with the texture. however i didn't an option to make the texture repeat itself on the object.

don't openGL quads tile themselves automatically if you specify a texture co-ord that's > 1? (yes, they do). don't know how processing would do this though.

backdrop looks fine in that video, doesn't look like it's underperforming.
Re: Performance issue with Patterns
Reply #2 - Feb 26th, 2008, 7:48pm
 
like i said i used processing only a few hours, so i am not really familiar with this openGL thingie yet.

but i'll try to look in to this then ! thanks !

in the mean time other advices are welcome too :)


edit:
quickly tried this coordinate >1 and it does not work. it repeats the border of the texture. i tried this
import processing.opengl.*;
import javax.media.opengl.*;
import com.sun.opengl.util.texture.*;  

Texture tex;  

void setup()  
{  
 size(1200,800, OPENGL);
 try{
  tex=TextureIO.newTexture(new File(dataPath("lines.IMG_2301.taglight.tagsmoke.JPG")),true); }
 catch(Exception e) { println(e); }
}  

void draw()  
{  
 if(tex!=null){
 background(128);
 PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;  
 GL gl = pgl.beginGL();  
 tex.bind();  
 tex.enable();  
 gl.glBegin(GL.GL_QUADS);
 gl.glNormal3f( -1.0f, -1.0f, -1.0f);
 gl.glTexCoord2f(0, 0); gl.glVertex2f(0,500);
 gl.glTexCoord2f(2, 0); gl.glVertex2f(500, 500);
 gl.glTexCoord2f(2, 2); gl.glVertex2f(500, 0);
 gl.glTexCoord2f(0, 2); gl.glVertex2f(0, 0);
 gl.glEnd();  
 tex.disable();
 pgl.endGL();
 }
}
Re: Performance issue with Patterns
Reply #3 - Feb 26th, 2008, 10:22pm
 
opengl redbook chapter 9 has a way of specifying what happens with textures at their edges:

http://glprogramming.com/red/chapter09.html

glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_S_WRAP, GL_REPEAT);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_T_WRAP, GL_REPEAT);

Re: Performance issue with Patterns
Reply #4 - Feb 26th, 2008, 10:40pm
 
how would you use this in processing ?
i tried :

 gl.glTexParameterfv(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_S_WRAP, GL.GL_REPEAT);  
 gl.glTexParameterfv(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_T_WRAP, GL.GL_REPEAT);
 

c:/temp/build29781.tmp/Temporary_1699_8000.java:24:44:24:60: Semantic Error: No accessible field named "GL_TEXTURE_T_WRAP" was found in type "javax.media.opengl.GL".
Re: Performance issue with Patterns
Reply #5 - Feb 27th, 2008, 10:37am
 
yes, i tried it myself after posting it and got the same problems. appears the documentation was wrong.

the TEXTURE_WRAP arguments are GL_TEXTURE_WRAP_x rather than GL_TEXTURE_x_WRAP and they are single integers rather than arrays of floats so:

gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

just after the tex.enable(). worked like a charm.
Re: Performance issue with Patterns
Reply #6 - Feb 27th, 2008, 11:15am
 
thanks !
works,

i now have to find a way to build the texture on the fly from a PGraphics object instead of a file ?
tex=TextureIO.newTexture(new File(dataPath("lines.IMG_2301.taglight.tagsmoke.JPG")),true);


any idea ?
Re: Performance issue with Patterns
Reply #7 - Feb 27th, 2008, 11:43am
 
no 8)

the processing texture methods do this easily

http://processing.org/reference/texture_.html

PImage a = loadImage("arch.jpg");
texture(a);

but i don't know about getting those textures into the Texture.

the drawing of the quad also looks very easy in processing (where last two arguments are texture coords) but i'm pretty sure after trying things last night that the native methods clamp the texture to 0-1 (or to the image size if you're using that textureMode)

beginShape();
texture(a);
vertex(10, 20, 0, 0);
vertex(80, 5, 100, 0);
vertex(95, 90, 100, 100);
vertex(40, 95, 0, 100);
endShape();

(am more used to doing this using xscreensaver and C, sorry)

will think about it.
Re: Performance issue with Patterns
Reply #8 - Feb 27th, 2008, 11:55am
 
Texture has an updateImage method that takes a TextureData which has the usual width, height, data. you could fill this TextureData from a PGraphics object (or render directly to it) and then call updateImage for your texture. very low level though and you may lose a lot of the speed increase doing this.

http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/texture/Texture.html
Re: Performance issue with Patterns
Reply #9 - Feb 27th, 2008, 12:14pm
 
> i'm pretty sure after trying things last night that the native methods clamp the texture to 0-1 (or to the image size if you're using that textureMode)

it does:

http://dev.processing.org/source/index.cgi/trunk/processing/core/src/processing/core/PGraphics.java?view=markup

Code:

/**
* Set (U, V) coords for the next vertex in the current shape.
* This is ugly as its own function, and will (almost?) always be
* coincident with a call to vertex. As of beta, this was moved to
* the protected method you see here, and called from an optional
* param of and overloaded vertex().
* <p/>
* The parameters depend on the current textureMode. When using
* textureMode(IMAGE), the coordinates will be relative to the size
* of the image texture, when used with textureMode(NORMAL),
* they'll be in the range 0..1.
* <p/>
* Used by both PGraphics2D (for images) and PGraphics3D.
*/
protected void textureVertex(float u, float v) {
if (textureImage == null) {
throw new RuntimeException("need to set an image with texture() " +
"before using u and v coordinates");
}
if (textureMode == IMAGE) {
u /= (float) textureImage.width;
v /= (float) textureImage.height;
}

textureU = u;
textureV = v;

if (textureU < 0) textureU = 0;
else if (textureU > 1) textureU = 1;

if (textureV < 0) textureV = 0;
else if (textureV > 1) textureV = 1;
}


maybe it shouldn't (or supply an additional method which doesn't). would mean your code wouldn't need any of the low-level jogl stuff.
Re: Performance issue with Patterns
Reply #10 - Feb 27th, 2008, 2:15pm
 
i have to say i am pretty surprised there is no way to tile a texture over an object in processing. but that is maybe the price to pay to have such a simple and easy to use piece of software Smiley

The other approach would be to draw each triangle in openGL.
my goal is to be able to draw about a maximum 100*100 patterns on screen. each pattern is made of nine shape. each shape is about 3 triangles in average.

so it would be about 300 000 triangles untextured per frame.
is that unrealistic ?

Re: Performance issue with Patterns
Reply #11 - Feb 27th, 2008, 4:28pm
 
there's a class in the PGraphicsOpenGL.java called ImageCache which seems to do everything i mentioned above in that it takes a PImage, rips the pixels out of it and calls the usual       gl.glTexImage2D() with the resulting bytes (this is all in the ImageCache.rebind() method)

ImageCache is private though and my attempts to copy it elsewhere for external use have met with lots of white screen where textures should be...
Re: Performance issue with Patterns
Reply #12 - Feb 27th, 2008, 6:01pm
 
hum, i think i'll stick to my first version (rendered shapes via the normal processing API) and then and try to improve it. as it seems that using lowlevel openGL to repeat the texture will cause more harm than it will help.

if there are any tips for improving performance while drawing many shapes on screen, please tell me Smiley



Re: Performance issue with Patterns
Reply #13 - Feb 27th, 2008, 7:12pm
 
opengl display lists. oh, wait... 8)

(i would be interested in seeing the whole of the code btw)
Re: Performance issue with Patterns
Reply #14 - Feb 28th, 2008, 11:24am
 
hi !

i put the code available to all there (lets consider it's GPL Wink):
http://motscousus.com/stuff/2008-02_Processing.org_patterns/

this it the version that draws the shape on screen using normal processing triangle(); quad(); and fill() methods.


what are these opengl display lists ?
Pages: 1 2