# Framebuffer not bliting depth buffer

**URL:** <https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280>\
**Category:** OpenGL: Advanced Coding\
**Created:** [December 1, 2011, 9:33am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280 "2011-12-01T09:33:33Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 1, 2011, 9:33am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/1 "2011-12-01T09:33:33Z")

</div>

Hi,

I have a framebuffer I use for storing the color and depth buffer after drawing the environment of my simulation (the camera moving seldom, it’s better to blit it if possible).

Problem is, the depth is not blited, therefor when i draw the mobile elements, well, no depth buffer. Tried playing with multisample, with glDepthMask, with GL\_DEPTH\_COMPONENT precision, no change.

Blitting to buffer after each camera displacement :

```auto

glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, BackupFBO);
glBlitFramebuffer(0, 0, currentWindowWidth, currentWindowHeight,
		0, 0, currentWindowWidth, currentWindowHeight, 
		GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

```

Blitting from buffer when no movement:

```auto

glBindFramebuffer(GL_READ_FRAMEBUFFER, BackupFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, currentWindowWidth, currentWindowHeight,
		0, 0, currentWindowWidth, currentWindowHeight, 
		GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

```

Framebuffer creation :

```auto

glGenRenderbuffers(1, &BackupFBO_colorRBO);
glBindRenderbuffer(GL_RENDERBUFFER, theatreBackupFBO_colorRBO);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, openGLFSAASamples, GL_RGBA, 1920, 1080);

glGenRenderbuffers(1, &BackupFBO_depthRBO);
glBindRenderbuffer(GL_RENDERBUFFER, theatreBackupFBO_depthRBO);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, openGLFSAASamples, GL_DEPTH_COMPONENT32, 1920, 1080);
glBindRenderbuffer(GL_RENDERBUFFER, 0);

glGenFramebuffers(1, &BackupFBO);
glBindFramebuffer(GL_FRAMEBUFFER, BackupFBO);

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, BackupFBO_colorRBO);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, BackupFBO_depthRBO);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

```

Something I missed ?  
depthbuffer is active all along, the code path is exactly the same in both cases…  
I’ve got no clue.

edit : forgot an essential part … Firepro v5800, latest drivers, win7 64.

---

<div class="post-metadata">

**Author:** ![thokra](https://community.khronos.org/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thokra](https://community.khronos.org/u/thokra)\
**Post date:** [December 1, 2011, 11:09am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/2 "2011-12-01T11:09:01Z")

</div>

This looks correct. Are there any errors anywhere during blitting? Have you had a try with framebuffer textures instead of renderbuffers? BTW, why renderbuffers anyway?

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 1, 2011, 11:41am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/3 "2011-12-01T11:41:59Z")

</div>

oops, didn’t check for errors, since colors where correctly blited, I assumed it was Ok ☹ Can only tell you tomorrow, since I’m back home.

I didn’t try with textures instead of renderbuffers.

I went for renderbuffers as it seemed to me more appropriate, and supported for a longer time than texture, especially considering the multisample necessity.

---

<div class="post-metadata">

**Author:** ![BionicBytes](https://community.khronos.org/user_avatar/community.khronos.org/bionicbytes/32/137_2.png) [@BionicBytes](https://community.khronos.org/u/BionicBytes)\
**Post date:** [December 1, 2011, 12:14pm UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/4 "2011-12-01T12:14:08Z")

</div>

AMD have had a driver bug for some time when blitting depth and colour buffers in one call. Do them separately !  
Are you using Radeons?

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 1, 2011, 12:20pm UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/5 "2011-12-01T12:20:00Z")

</div>

I’m using a FirePro v5800 (based on a Radeon 5770), with the latest FirePro drivers (september I think)

I’ll try them separatly then and let you know (tomorrow, here it’s 9 pm already), thx for the input.

Is there any reason to prefer textures to renderbuffers and vice versa ?

---

<div class="post-metadata">

**Author:** ![BionicBytes](https://community.khronos.org/user_avatar/community.khronos.org/bionicbytes/32/137_2.png) [@BionicBytes](https://community.khronos.org/u/BionicBytes)\
**Post date:** [December 1, 2011, 12:26pm UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/6 "2011-12-01T12:26:30Z")

</div>

> Is there any reason to prefer textures to renderbuffers and vice versa

Not really. AMD did have a bug some time ago with depth stencil textures and renderbuffers were the only available alternative.  
Renderbuffers are better supported on mobile devices from what I gather.

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 1:01am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/7 "2011-12-02T01:01:33Z")

</div>

Doing it in two copies of one buffer doesn’t work.  
It’s as if i didn’t do the GL\_DEPTH\_BUFFER\_BIT copy.

Ok there is an error : GL\_INVALID\_OPERATION.

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 1:22am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/8 "2011-12-02T01:22:46Z")

</div>

Ok, let’s proceed step by step.  
I don’t have the error if i remove the depth mask bit.  
I have the error without multisampled renderbuffers.

```auto

GL_INVALID_OPERATION is generated if mask contains any of the GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT and filter is not GL_NEAREST. 

```

not the case, i’m using GL\_NEAREST.

```auto

GL_INVALID_OPERATION is generated if mask contains GL_DEPTH_BUFFER_BIT or GL_DEPTH_BUFFER_BIT and the source and destination depth and stencil formats do not match. 

```

I tried several things here : D24\_S8 at window creation and renderbuffer depth\_component24, or D32\_S0 and renderbuffer depth\_component32, or the same two but with renderbuffer depth\_component. None works better.

```auto

GL_INVALID_OPERATION is generated if filter is GL_LINEAR and the read buffer contains integer data. 

```

Not the case.

```auto

GL_INVALID_OPERATION is generated if the value of GL_SAMPLES for the read and draw buffers is not identical. 

```

They are identical. Plus colors get copied anyway.

```auto

GL_INVALID_OPERATION is generated if GL_SAMPLE_BUFFERS for both read and draw buffers greater than zero and the dimensions of the source and destination rectangles is not identical. 

```

It’s the same size. Plus colors get copied anyway.

```auto

GL_INVALID_FRAMEBUFFER_OPERATION is generated if the objects bound to GL_DRAW_FRAMEBUFFER_BINDING or GL_READ_FRAMEBUFFER_BINDING are not framebuffer complete.

```

They are framebuffer complete.

```auto

GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT and any of the following conditions hold: 

The read buffer contains fixed-point or floating-point values and any draw buffer contains neither fixed-point nor floating-point values.

The read buffer contains unsigned integer values and any draw buffer does not contain unsigned integer values.

The read buffer contains signed integer values and any draw buffer does not contain signed integer values.

```

Colors get copied anyway.

Any ideas ?

My drivers :

```auto

Driver Packaging Version	8.85.7.2-110901a1-125182C	
Provider	ATI Technologies Inc.	
2D Driver Version	8.01.01.1152	
2D Driver File Path	/REGISTRY/MACHINE/SYSTEM/ControlSet001/Control/CLASS/{4D36E968-E325-11CE-BFC1-08002BE10318}/0000	
Direct3D Version	7.14.10.0833	
OpenGL Version	6.14.10.10792	
Catalyst Pro Control Center Version	2011.0901.2230.38549	

```

---

<div class="post-metadata">

**Author:** ![BionicBytes](https://community.khronos.org/user_avatar/community.khronos.org/bionicbytes/32/137_2.png) [@BionicBytes](https://community.khronos.org/u/BionicBytes)\
**Post date:** [December 2, 2011, 1:44am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/9 "2011-12-02T01:44:23Z")

</div>

After checking my code, it looks like I have to work around AMD drivers when blitting FBOs.

```auto

procedure TFramebuffer.BlitDepthStencil(SrcbufferID,DstbufferID: integer);
begin
    glBindFramebuffer( GL_READ_FRAMEBUFFER, FrameBuffers [SrcbufferID].FBid );
    glReadBuffer(GL_NONE);
    glBindFramebuffer( GL_DRAW_FRAMEBUFFER, FrameBuffers [DstbufferID].FBid);
    glDrawBuffer(GL_NONE);
    //AMD cat 10.7 driver bug? Cant combine depth and stencil blits //VendorATI
    glBlitFramebuffer( 0, 0, FrameBuffers [SrcbufferID].Width, FrameBuffers [SrcbufferID].Height, 0, 0, FrameBuffers [DstbufferID].Width, FrameBuffers [DstbufferID].Height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
    glBlitFramebuffer( 0, 0, FrameBuffers [SrcbufferID].Width, FrameBuffers [SrcbufferID].Height, 0, 0, FrameBuffers [DstbufferID].Width, FrameBuffers [DstbufferID].Height, GL_STENCIL_BUFFER_BIT, GL_NEAREST);
// glBlitFramebuffer( 0, 0, FrameBuffers [SrcbufferID].Width, FrameBuffers [SrcbufferID].Height, 0, 0, FrameBuffers [DstbufferID].Width, FrameBuffers [DstbufferID].Height, GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer (GL_FRAMEBUFFER, 0);
end;

```

So it looks like I break down the number of blits into three calls.  
The first blits only the colour attachments, the second and third are dealt with by the code above, which blits the depth and then blits the stencil.

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 1:55am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/10 "2011-12-02T01:55:27Z")

</div>

Maybe i should add a stencil renderbuffer to be sure i have a frambuffer that mirrors my default framebuffer completely ?

Why are you setting your glDrawBuffer and glReadBuffer like that ?

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 2:04am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/11 "2011-12-02T02:04:06Z")

</div>

Ok the glDraw/glRead buffer things doesn’t help.  
I’ll try textures instead of renderbuffers, who knows …

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 2:29am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/12 "2011-12-02T02:29:06Z")

</div>

Just tested on a quadro fx3800 (based on a GTX260), and the depth buffer is copied, but performances are awefull (its slower to blit than actually draw).

So it looks like driver troubles.

---

<div class="post-metadata">

**Author:** ![thokra](https://community.khronos.org/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thokra](https://community.khronos.org/u/thokra)\
**Post date:** [December 2, 2011, 3:12am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/13 "2011-12-02T03:12:29Z")

</div>

What driver are you using? In my case its 285.62 on a GF540GT M and i’ve never had any trouble with blitting.

Still, you can’t confirm that something works on an AMD board with NVidia board! 🙂

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 3:28am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/14 "2011-12-02T03:28:07Z")

</div>

Yup, but at least my code is correct for the nVidia.

The only thing i’m not sure of is :  
GL\_INVALID\_OPERATION is generated if mask contains GL\_DEPTH\_BUFFER\_BIT or GL\_DEPTH\_BUFFER\_BIT and the source and destination depth and stencil formats do not match.

I’m not creating the window myself (I use SFML), so i’m not sure how it creates the context exactly.

---

<div class="post-metadata">

**Author:** ![danbartlett](https://community.khronos.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@danbartlett](https://community.khronos.org/u/danbartlett)\
**Post date:** [December 2, 2011, 3:41am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/15 "2011-12-02T03:41:00Z")

</div>

I think

> GL\_INVALID\_OPERATION is generated if mask contains GL\_DEPTH\_BUFFER\_BIT or GL\_DEPTH\_BUFFER\_BIT and the source and destination depth and stencil formats do not match.

is meant to read:

> GL\_INVALID\_OPERATION is generated if mask contains GL\_DEPTH\_BUFFER\_BIT or GL\_STENCIL\_BUFFER\_BIT and the source and destination depth and stencil formats do not match.

How many bits are you requesting for depth + stencil, and how many are you actually getting? A common format for default framebuffer is 24 bit depth, 8 bit stencil interleaved although I’m not sure how you query if it’s actually using an interleaved format or separate buffers - and also querying the default framebuffer bit depths using the technique specified in the core profile spec was buggy on drivers when I last checked. I guess for best performance when blitting an interleaved depth/stencil buffer, like when clearing, both the depth + stencil buffers should probably be copied at the same time for best performance.

---

<div class="post-metadata">

**Author:** ![sunaiac](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/eada6e/32.png) [@sunaiac](https://community.khronos.org/u/sunaiac)\
**Post date:** [December 2, 2011, 3:55am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/16 "2011-12-02T03:55:49Z")

</div>

That was the bug. I got the thing to work. just changed my depth renderbuffer from DEPTH\_COMPONENT to GL\_DEPTH24\_STENCIL8.

It should be more obvious, you see it nowhere on the framebuffer pages, they only explain what theory should do.

you find a quick note about practice in the image format page :

> Legacy Note: The original GL\_EXT\_framebuffer\_object defined stencil-only image formats that had no depth component. No drivers ever supported these, and they were abandoned in favor of combined depth/stencil buffers in the 3.0 core and the ARB version of the FBO extension. Do not use them, even if your implementation does not support GL\_EXT\_packed\_depth\_stencil.

Seriously, one shouldn’t have so much trouble finding this information.

Anyway, working now, thanks for everything ppl 🙂

---

<div class="post-metadata">

**Author:** ![BionicBytes](https://community.khronos.org/user_avatar/community.khronos.org/bionicbytes/32/137_2.png) [@BionicBytes](https://community.khronos.org/u/BionicBytes)\
**Post date:** [December 2, 2011, 6:35am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/17 "2011-12-02T06:35:20Z")

</div>

> Why are you setting your glDrawBuffer and glReadBuffer like that ?

Do you mean these?  
glReadBuffer(GL\_NONE);  
glDrawBuffer(GL\_NONE);

…because I’m not using the colour attachments.  
Granted, it may be overkill for a routine which only blits from one FBO to another…

---

<div class="post-metadata">

**Author:** ![skynet](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/919ad9/32.png) [@skynet](https://community.khronos.org/u/skynet)\
**Post date:** [December 2, 2011, 9:25am UTC](https://community.khronos.org/t/framebuffer-not-bliting-depth-buffer/66280/18 "2011-12-02T09:25:13Z")

</div>

Try using GL\_DEPTH24\_STENCIL8 as your renderbuffer format. When blitting stencil or depth values, the corresponding pixel formats of source and destination MUST match. You might argue that the depthbuffer actually had the same format, but obviously, GL\_DEPTH\_COMPONENT24 and GL\_DEPTh24\_STENCIL8 are seen as completely different formats.

Btw, beware not to include GL\_STENCIL\_BIT in your mask. AMD has/had a bug where when you do this, the blitted depthvalues get screwed up. I don’t know if they fixed that yet.
