Author Topic: Rendering 1 World to 2 FrameBuffers  (Read 4011 times)

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Rendering 1 World to 2 FrameBuffers
« on: May 09, 2006, 01:39:05 pm »
There seems to be a problem with textures when I render the same world into two different FrameBuffers. The textures don't appear on the second rendered frame buffer. Is this a known issue? Here's the code I'm using:

Code: [Select]

frameBufferA.clear();
world.renderScene(frameBufferA);
world.draw(frameBufferA);
frameBufferA.update();
frameBufferA.displayGLOnly();
viewingCanvasA.repaint();

frameBufferB.clear();
world.renderScene(frameBufferB);
world.draw(frameBufferB);
frameBufferB.update();
frameBufferB.displayGLOnly();
viewingCanvasB.repaint();


This problem only occurs with hardware rendering; in software rendering mode it works fine.

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Rendering 1 World to 2 FrameBuffers
« Reply #1 on: May 09, 2006, 02:44:18 pm »
I just tried creating a seperate world for the second FrameBuffer and I still get the same texture problems. I know the TextureManager is a Singleton, does it have any dependancy on the World object that may prevent it from being shared in two different worlds?

By the way, this is the 3rd world in my application. At first I had 2 worlds; the 1st one is rendered to its own FrameBuffer and the 2nd one was the one I rendered to 2 different FrameBuffers (as in my last post).

So now even after creating a 3rd world, I still have the same problem with the textures; they either don't appear, or are mapped to the wrong objects randomly  :?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Rendering 1 World to 2 FrameBuffers
« Reply #2 on: May 09, 2006, 02:49:05 pm »
Which renderer is that? GL or AWTGL?

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Rendering 1 World to 2 FrameBuffers
« Reply #3 on: May 09, 2006, 02:52:48 pm »
I'm using:

Code: [Select]

viewingCanvasA = frameBufferA.enableGLCanvasRenderer(IRenderer.MODE_OPENGL);


So I guess it's GL  :?:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Rendering 1 World to 2 FrameBuffers
« Reply #4 on: May 09, 2006, 02:56:45 pm »
No, that's AWTGL. I've already thought so, because i think that you can't even do what you do with the native LWJGL window (cause there can be only one). I'll check out if this is a jPCT or LWJGL problem that you are experiencing.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Rendering 1 World to 2 FrameBuffers
« Reply #5 on: May 09, 2006, 07:04:48 pm »
There was a problem with the different FrameBuffers using different renderers running in different contexts. I've uploaded version 1.11a which should fix this problem (see News-section). Keep in mind that the contexts don't share ressources, i.e. three framebuffers mean three times the texture memory needed.

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Rendering 1 World to 2 FrameBuffers
« Reply #6 on: May 09, 2006, 07:29:17 pm »
EgonOlsen,

Thank-you for the fix.

Quote

Keep in mind that the contexts don't share ressources, i.e. three framebuffers mean three times the texture memory needed.


Why is the TextureManager a Singleton? Why could it not have been instanciated in the World class and used through the World's API? This way each world would contain its own set of textures. Also, it seems excessive to allocate space for all textures everytime a FrameBuffer is created...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Rendering 1 World to 2 FrameBuffers
« Reply #7 on: May 09, 2006, 07:37:43 pm »
Quote from: "Mr.Marbles"
Why is the TextureManager a Singleton? Why could it not have been instanciated in the World class and used through the World's API? This way each world would contain its own set of textures. Also, it seems excessive to allocate space for all textures everytime a FrameBuffer is created...
Making the TextureManager a singleton makes a lot of things easier internally. Instead of passing around the World and get the Textures from it, each class can access the TextureManager without knowing anything about a world.
Making it a World's attribute won't help memory wise either. The textures are not doubled inside the manager or something when creating a new FrameBuffer. On the Java side, they exist exactly one time no matter how many FrameBuffers you are using. However, they will be uploaded multiple times to  the graphics card when used in different contexts. That's the way OpenGL works. But it's lazy uploading, i.e. they won't be uploaded until needed in the context.

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Rendering 1 World to 2 FrameBuffers
« Reply #8 on: May 09, 2006, 08:12:52 pm »
Quote from: "EgonOlsen"
However, they will be uploaded multiple times to  the graphics card when used in different contexts. That's the way OpenGL works. But it's lazy uploading, i.e. they won't be uploaded until needed in the context.


Ok I understand now, so the graphics bandwidth increases with every context that is rendered to. With the worse case being completely different contexts, which in my case shouldn't be so bad since I'm rendering the exact same scene twice.