Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JOGL TextureRenderer slow?  (Read 2405 times)
0 Members and 1 Guest are viewing this topic.
Offline Zoomby

Junior Newbie





« Posted 2007-11-20 09:27:59 »

Hi,

I'm still fighting to get some Graphics2D onto my JOGL scene.
I'm using TextureRenderer to create a small 100*100 texture. But then TextureRenderer.getTexture() is damn slow!
If I call it only 10 times in a row, the CPU usage jumps to over 60%.
I used "-Dsun.java2d.opengl=True"

What am I doing wrong? Isn't there a simple and efficient way to draw some 2D graphics?

Bye
Chris
Offline emzic

Senior Duke





« Reply #1 - Posted 2007-11-20 11:30:06 »

maybe if you can post some of your code, we can look into this.

as for drawing 2D graphics, maybe the Overlay-class which uses the TextureRenderer is more useful.

www.embege.com - personal website
webstart blendinspect - OpenGL BlendingModes visualization.
Offline Zoomby

Junior Newbie





« Reply #2 - Posted 2007-11-20 12:09:08 »

Hi emzic,

Here is my quick test-routine which I call every frame (Imagine I'd like to create animated 2D graphics).
I guess it does the same as the Overlay class (I took a look into the Overlay and TextureRenderer source to see how it works)

As I noted, when I call my "render2D" 10 times in a loop the CPU usage rises to over 60%.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
  TextureRenderer renderer = null;

  int render2D(GL gl, GLDrawable gld)
  {

    if (renderer == null)
    {          
      renderer = new TextureRenderer(100,100,true);
       renderer.setSmoothing(false);
    }
   
   
    Graphics2D g2 = renderer.createGraphics();

    g2.setBackground(new Color(0,0,0,0)); //transparent background
    g2.clearRect(0,0,100,100); //clear all
   
    g2.fillRect(0,0,10,10);
    g2.setPaint(new Color(99,0,255));
    g2.drawRect(0,0,22,22);

    g2.dispose();
   
   
   
    renderer.markDirty(0,0,500,500);    
    Texture tex = renderer.getTexture();
    tex.bind();
   
   
    //draw orthogonal quad.
    int x = 45;
    int y = 45;
    int w = 100;
    int h = 100;
   
    y = gld.getHeight()-y;
   
    gl.glBegin(GL.GL_QUADS);
       
    gl.glTexCoord2i(0,1);
    gl.glVertex3d(x,y-h,0f);
   
    gl.glTexCoord2i(1,1);
    gl.glVertex3d(x+w,y-h,0f);
   
    gl.glTexCoord2i(1,0);
    gl.glVertex3d(x+w,y,0f);
   
    gl.glTexCoord2i(0,0);
    gl.glVertex3d(x,y,0f);
   
   
    gl.glEnd();
 

     return 0;
  }
 
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2007-11-20 15:42:31 »

Just something that seemed odd to me but why are you marking the TextureRenderer dirty from (0,0) to (500,500) since the width and height of the renderer are 100 each. 

Offline Zoomby

Junior Newbie





« Reply #4 - Posted 2007-11-20 16:38:10 »

Quote
Just something that seemed odd to me but why are you marking the TextureRenderer dirty from (0,0) to (500,500) since the width and height of the renderer are 100 each.

That's because it's messy test code.  Wink . But it doesn't solve the actual problem...


Offline MartinFischbach

Senior Newbie




Java und Jogl rock :-D


« Reply #5 - Posted 2007-11-21 10:03:07 »

Try not to create Graphics2D with each render cycle, but instead reuse it!

Not:
1  
2  
3  
Graphics2D g2 = renderer.createGraphics();
...
g2.dispose();


But:

1  
2  
3  
4  
5  
6  
Graphics2D g2; // somewhere in field declaration

// and within render2D()
if (g2 == null) {
    g2 = renderer.createGraphics();
}
Offline Zoomby

Junior Newbie





« Reply #6 - Posted 2007-11-21 13:55:24 »

Hi Martin,

sorry, but that doesn't help  Sad
I think renderer.getTexture() is the bottleneck...
Offline lhkbob

JGO Knight


Medals: 32



« Reply #7 - Posted 2007-11-21 14:16:40 »

Could you try profiling it just to make sure?

Offline Zoomby

Junior Newbie





« Reply #8 - Posted 2007-11-21 15:44:33 »

Quote
Could you try profiling it just to make sure?

I've never used a java-profiler before...
I can only say:
If I remove the call to getTexture the CPU usage is 7 times smaller.

Offline emzic

Senior Duke





« Reply #9 - Posted 2007-11-21 16:26:10 »

well getTexture() does update all of the texture that you have markedDirty before. so it does quite a bit of work.

to profile it, just put a System.nanoTime() before and after and measure the difference.

also try making the texturenderer resolution a power of two. 128x128 and not 100x100.
also, never mark something dirty that is outside this resolution since it will result in an openGL error which has a big impact on performance.

www.embege.com - personal website
webstart blendinspect - OpenGL BlendingModes visualization.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MartinFischbach

Senior Newbie




Java und Jogl rock :-D


« Reply #10 - Posted 2007-11-22 08:54:29 »

Hi Zoomby,

I mean, what do you expect?

10 times

creating graphics content
Drawing a 100x100 picture
uploading that picture as texture
displaying texture

PER Frame.

I assume you are running with at least 30fps.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (41 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (60 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!