Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  OffScreen rendering with EXT_framebuffer_object  (Read 3981 times)
0 Members and 1 Guest are viewing this topic.
Offline javazoid

Junior Devvie




Where's Flender?


« Posted 2005-08-25 08:20:35 »

After having successfully used the PBuffers for offscreen rendering with LWJGL I would like to use the FrameBuffer Object for doing offscreen graphics.

The docs are unclear (at least for me) and I didn't manage to have something working.
My aim is not to use render-to-texture, but only allocate an FBO, bind it to a ARGB 32bit Render Buffer Object and then read the pixels back from it.

My init code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
IntBuffer fbID = BufferUtils.createIntBuffer(1);
IntBuffer rbID = BufferUtils.createIntBuffer(1);

EXTFramebufferObject.glGenRenderbuffersEXT(rbID);
EXTFramebufferObject.glGenFramebuffersEXT(fbID);

EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,EXTBgra.GL_BGRA_EXT,getPhysicalWidth(), getPhysicalHeight());
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,fbID.get(0));
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, fbID.get(0));
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbID.get(0));

..
GL11.gl calls here.


checkError() signals an error when I call glRenderbufferStorageEXT().

What I'm missing ?

Help appreciated (Spasi, are you there ?).




Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2005-08-25 09:12:52 »

Code to help you debugging:

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  
   private final boolean isValidFramebuffer()
   {
      String message;

      int status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

      switch (status)
      {
         case GL_FRAMEBUFFER_COMPLETE_EXT:
            return true;
         case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
            message = "format unsupported";
            break;
         case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
            message = "image-attachments have different internal formats";
            break;
         case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
            message = "image-attachments have different dimensions";
            break;
         case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
            message = "duplicate image-attachment";
            break;
         case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
            message = "missing an image-attachment";
            break;
         default:
            message = "unknown: " + status;
      }

      System.out.println("isValidFramebuffer(\"" + message + "\")");

      return false;
   }


Hope this helps.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2005-08-25 09:17:58 »

.

1  
2  
3  
4  
5  
6  
7  
8  
9  
IntBuffer fbID = BufferUtils.createIntBuffer(1);
IntBuffer rbID = BufferUtils.createIntBuffer(1);

...

1. glRenderbufferStorageEXT(GL_FRAMEBUFFER_EXT,GL_BGRA_EXT,getPhysicalWidth(), getPhysicalHeight());
2. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbID.get(0));
3. glFramebufferRenderbuffer(EXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbID.get(0));
4. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbID.get(0));

In line 3 you try to bind the RenderBuffer to the FrameBuffer, but you pass the fbID instead of the rbID.
In line 2 and 4 you do the same, so line 4 is a no-op.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #3 - Posted 2005-08-25 09:50:41 »

1  
EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,EXTBgra.GL_BGRA_EXT,getPhysicalWidth(), getPhysicalHeight());


checkError() signals an error when I call glRenderbufferStorageEXT().

I don't think BGRA is a valid internal format for render buffers.

Quote
<internalformat> must be RGB, RGBA, DEPTH_COMPONENT, STENCIL_INDEX, or one of the internal formats from table 3.16 or table 2.nnn that has a base internal format of RGB, RGBA, DEPTH_COMPONENT, or STENCIL_INDEX.

And what Riven said.
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #4 - Posted 2005-08-25 13:45:24 »

What's unclear with the FBO is how to create it without a texture binding. I don't need to render-to-texture: I only need to create an FBO with an ARGB pixel format (so, binded to a framebufferobject).

A piece of sample code is worth a thousand posts, so don't be shy Wink

Mik

Offline Spasi
« Reply #5 - Posted 2005-08-25 16:09:54 »

Just use a standard RGBA format for the render buffer's internal format.

Besides, why is it a problem to use a texture? You can still read back the pixels.
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #6 - Posted 2005-08-25 17:13:46 »

So you suggest me to read pixels from the texture using glGetTexImage() ? Do you know how it performs compared to glReadPixels() ?

The problem for me is a bit more complex: I use a hierarchy of classes that implement a gl graphics "context". The context is abstract but it defines concrete methods for reading pixels. These methods use glReadPixels(); Ok, I could solve this issue by re-working the classes..

Anyway, I still have initialization problems. I'll do further checks and test. Any help appreciated.

Offline Spasi
« Reply #7 - Posted 2005-08-25 17:37:53 »

So you suggest me to read pixels from the texture using glGetTexImage() ? Do you know how it performs compared to glReadPixels() ?

Yes, exactly. I would expect similar performance to ReadPixels, since a renderable texture would have a memory layout similar to any other renderable surface.

Anyway, I still have initialization problems. I'll do further checks and test. Any help appreciated.

Could you post any errors you're getting?
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2005-08-25 18:12:51 »

You can glReadBuffer directly from the FBO.

Whether or not it is backed by a texture or not is irrelevant.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #9 - Posted 2005-08-26 07:10:39 »

At last I have the FBO working:

init
1  
2  
3  
4  
5  
6  
7  
8  
EXTFramebufferObject.glGenFramebuffersEXT(fbIDbuf);
EXTFramebufferObject.glGenRenderbuffersEXT(rbIDbuf);

EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbIDbuf.get(0));
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, rbIDbuf.get(0));

EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_RGBA, getPhysicalWidth(), getPhysicalHeight());
EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, rbIDbuf.get(0));


make current:
1  
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbIDbuf.get(0));


dispose
1  
2  
3  
4  
5  
EXTFramebufferObject.glDeleteRenderbuffersEXT(rbIDbuf);
EXTFramebufferObject.glDeleteFramebuffersEXT(fbIDbuf);
         
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);


For a "windowless" application I have to create a shared PBuffer first.
The strange thing is that I get a 1280 error after disposing the FBO and making the shared PBuffer current.

From the performance point of view, I get 1:1 against the PBuffers version, but the API is much simpler.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2005-08-26 10:32:04 »

When you do frequent buffer-switches (a couple per frame), FBOs really shine (performance wise).

You can even make it faster by using the same FBO and only switching the RenderBuffer/Texture 'behind' it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #11 - Posted 2005-08-26 13:32:33 »

One question about the renderbuffer format: how can I specify stencil bits, depth, alpha bits, etc. ?

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2005-08-26 19:07:41 »

1  
2  
3  
4  
5  
6  
// init depth-buffer
depthBufferHandle = BufferUtils.createIntBuffer(1);
glGenRenderbuffersEXT(depthBufferHandle);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBufferHandle.get(0));
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, dim, dim);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBufferHandle.get(0));


Don't be afraid to read the FBO spec  Tongue

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #13 - Posted 2005-08-27 12:59:33 »

Thanks for the code. I already did that (by reading the specs Tongue).
I also tried to create an 8 bit stencil buffer by implementing similar code but even if  it doesn't give any error, it does not work.
I've double checked the source and it seems to be ok.
First I created the color buffer and attached it, then the depth buffer and last the stencil. All attached to the same FBO.

Offline Spasi
« Reply #14 - Posted 2005-08-27 14:20:16 »

Stencil renderbuffers are not supported by any hardware right now. A new extension is planned that will provide a packed depth-stencil format, which should be available on most cards.
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #15 - Posted 2005-08-29 07:12:25 »

Many thanks Spasi. You saved me a lot of improductive testing.
FBO is indeed a nice feature but I suppose it's still too much early stage. I read somewhere that FBOs cannot be created when Anisotropic Filtering is on. Also NVIDIA says they will support anti-aliasing in FBO in future drivers, but they do not say anything about AF.

Cheers,

Mik

Offline Spasi
« Reply #16 - Posted 2005-08-29 09:39:05 »

Yes, a new extension (or an update of the current one) is planned for AA with FBO. That's the most important feature missing right now. The AF limitation is probably a bug in current drivers.

I'm curious, why do you need to use a stencil buffer with FBO? I'm sure you could live without that, right?
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #17 - Posted 2005-08-29 13:36:26 »

I've implemented Java2D Shape clipping in my SGL engine through stencil buffers. That's why I need stencils.
I hope to see FBO improvements/fixes very soon. By this time, LWJG Pbuffers work very well..

How can you be so well informed about the FBO status ? Have you got an account on developer.nvidia.com ?

Offline Spasi
« Reply #18 - Posted 2005-08-29 14:18:38 »

FBO is the hottest OpenGL topic lately, so it's natural that I've learned everything about it. Smiley

Yes, I'm registered to both nvdeveloper and ATI developers relations. But there's not much info there, they're only useful for early access drivers/tools and if you want to contact them directly for specific issues and bug reports.

I get most information from forums, papers and presentations (GDC, Siggraph, etc). I have a 3 gig PDF collection and that's for graphics only. Wink
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #19 - Posted 2005-08-29 15:59:34 »

What you are working on lately ?

Offline Spasi
« Reply #20 - Posted 2005-08-29 17:44:31 »

<OT warning>

For the past 14 months, I spend most of my time working on the ETOUR platform. It's an internet based B2B software for travel agents and anyone involved in the tourism business. It has a unique concept and a lot of unique features, but it's still in development after 3 years. It's zD's main project, but not owned by us, we're developing it in cooperation with another company (they throw the money, they have the rights, they do the marketing, you know...). We already have clients all over Greece, so it's our first big project and the main source of income.

At the same time, we're actively developing the Marathon Engine. Time is limited of course, but we've got big plans. Things are looking good and only an investment is missing (that will come someday, we're sure).

There are other things that keep our artists busy, like 3D visualizations (e.g. for architects) and some multimedia productions. We've also just started another project related to GPS vehicle tracking.

</OT warning>

Lately... er... I was on vacation. Grin
Offline javazoid

Junior Devvie




Where's Flender?


« Reply #21 - Posted 2005-08-30 07:31:14 »

A lot of work ahead!
Maybe I saw something of the Marathon Engine. Snapshots from a early stage game, if I remember. Impressive..

Best wishes for everything!

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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (105 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!