|
|
@@ -1946,6 +1946,12 @@ namespace bgfx { namespace gl
|
|
|
);
|
|
|
updateCapture();
|
|
|
|
|
|
+ for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
|
|
|
+ {
|
|
|
+ FrameBufferGL& frameBuffer = m_frameBuffers[ii];
|
|
|
+ frameBuffer.postReset();
|
|
|
+ }
|
|
|
+
|
|
|
ovrPreReset();
|
|
|
ovrPostReset();
|
|
|
}
|
|
|
@@ -4267,128 +4273,140 @@ namespace bgfx { namespace gl
|
|
|
void FrameBufferGL::create(uint8_t _num, const TextureHandle* _handles)
|
|
|
{
|
|
|
GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) );
|
|
|
- GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
|
|
|
+ for (uint32_t ii = 0; ii < _num; ++ii)
|
|
|
+ {
|
|
|
+ m_th[ii] = _handles[ii];
|
|
|
+ }
|
|
|
+ m_numTh = _num;
|
|
|
+ postReset();
|
|
|
+ }
|
|
|
|
|
|
-// m_denseIdx = UINT16_MAX;
|
|
|
- bool needResolve = false;
|
|
|
+ void FrameBufferGL::postReset()
|
|
|
+ {
|
|
|
+ if (0 != m_fbo[0])
|
|
|
+ {
|
|
|
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
|
|
|
|
|
|
- GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
|
|
|
+ bool needResolve = false;
|
|
|
|
|
|
- uint32_t colorIdx = 0;
|
|
|
- for (uint32_t ii = 0; ii < _num; ++ii)
|
|
|
- {
|
|
|
- TextureHandle handle = _handles[ii];
|
|
|
- if (isValid(handle) )
|
|
|
- {
|
|
|
- const TextureGL& texture = s_renderGL->m_textures[handle.idx];
|
|
|
+ GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
|
|
|
|
|
|
- if (0 == colorIdx)
|
|
|
+ uint32_t colorIdx = 0;
|
|
|
+ for (uint32_t ii = 0; ii < m_numTh; ++ii)
|
|
|
+ {
|
|
|
+ TextureHandle handle = m_th[ii];
|
|
|
+ if (isValid(handle) )
|
|
|
{
|
|
|
- m_width = texture.m_width;
|
|
|
- m_height = texture.m_height;
|
|
|
- }
|
|
|
+ const TextureGL& texture = s_renderGL->m_textures[handle.idx];
|
|
|
|
|
|
- GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
|
|
|
- TextureFormat::Enum format = (TextureFormat::Enum)texture.m_textureFormat;
|
|
|
- if (isDepth(format) )
|
|
|
- {
|
|
|
- const ImageBlockInfo& info = getBlockInfo(format);
|
|
|
- if (0 < info.stencilBits)
|
|
|
+ if (0 == colorIdx)
|
|
|
{
|
|
|
- attachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
|
|
+ m_width = texture.m_width;
|
|
|
+ m_height = texture.m_height;
|
|
|
}
|
|
|
- else if (0 == info.depthBits)
|
|
|
+
|
|
|
+ GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
|
|
|
+ TextureFormat::Enum format = (TextureFormat::Enum)texture.m_textureFormat;
|
|
|
+ if (isDepth(format) )
|
|
|
{
|
|
|
- attachment = GL_STENCIL_ATTACHMENT;
|
|
|
+ const ImageBlockInfo& info = getBlockInfo(format);
|
|
|
+ if (0 < info.stencilBits)
|
|
|
+ {
|
|
|
+ attachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
|
|
+ }
|
|
|
+ else if (0 == info.depthBits)
|
|
|
+ {
|
|
|
+ attachment = GL_STENCIL_ATTACHMENT;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ attachment = GL_DEPTH_ATTACHMENT;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- attachment = GL_DEPTH_ATTACHMENT;
|
|
|
+ buffers[colorIdx] = attachment;
|
|
|
+ ++colorIdx;
|
|
|
}
|
|
|
+
|
|
|
+ if (0 != texture.m_rbo)
|
|
|
+ {
|
|
|
+ GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
|
|
|
+ , attachment
|
|
|
+ , GL_RENDERBUFFER
|
|
|
+ , texture.m_rbo
|
|
|
+ ) );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
|
|
|
+ , attachment
|
|
|
+ , texture.m_target
|
|
|
+ , texture.m_id
|
|
|
+ , 0
|
|
|
+ ) );
|
|
|
+ }
|
|
|
+
|
|
|
+ needResolve |= (0 != texture.m_rbo) && (0 != texture.m_id);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- buffers[colorIdx] = attachment;
|
|
|
- ++colorIdx;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ m_num = uint8_t(colorIdx);
|
|
|
|
|
|
- if (0 != texture.m_rbo)
|
|
|
+ if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
|
|
|
+ {
|
|
|
+ if (0 == colorIdx)
|
|
|
{
|
|
|
- GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER
|
|
|
- , attachment
|
|
|
- , GL_RENDERBUFFER
|
|
|
- , texture.m_rbo
|
|
|
- ) );
|
|
|
+ // When only depth is attached disable draw buffer to avoid
|
|
|
+ // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER.
|
|
|
+ GL_CHECK(glDrawBuffer(GL_NONE) );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
|
|
|
- , attachment
|
|
|
- , texture.m_target
|
|
|
- , texture.m_id
|
|
|
- , 0
|
|
|
- ) );
|
|
|
+ GL_CHECK(glDrawBuffers(colorIdx, buffers) );
|
|
|
}
|
|
|
|
|
|
- needResolve |= (0 != texture.m_rbo) && (0 != texture.m_id);
|
|
|
+ // Disable read buffer to avoid GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER.
|
|
|
+ GL_CHECK(glReadBuffer(GL_NONE) );
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- m_num = uint8_t(colorIdx);
|
|
|
+ frameBufferValidate();
|
|
|
|
|
|
- if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
|
|
|
- {
|
|
|
- if (0 == colorIdx)
|
|
|
+ if (needResolve)
|
|
|
{
|
|
|
- // When only depth is attached disable draw buffer to avoid
|
|
|
- // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER.
|
|
|
- GL_CHECK(glDrawBuffer(GL_NONE) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- GL_CHECK(glDrawBuffers(colorIdx, buffers) );
|
|
|
- }
|
|
|
+ GL_CHECK(glGenFramebuffers(1, &m_fbo[1]) );
|
|
|
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[1]) );
|
|
|
|
|
|
- // Disable read buffer to avoid GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER.
|
|
|
- GL_CHECK(glReadBuffer(GL_NONE) );
|
|
|
- }
|
|
|
-
|
|
|
- frameBufferValidate();
|
|
|
-
|
|
|
- if (needResolve)
|
|
|
- {
|
|
|
- GL_CHECK(glGenFramebuffers(1, &m_fbo[1]) );
|
|
|
- GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[1]) );
|
|
|
-
|
|
|
- colorIdx = 0;
|
|
|
- for (uint32_t ii = 0; ii < _num; ++ii)
|
|
|
- {
|
|
|
- TextureHandle handle = _handles[ii];
|
|
|
- if (isValid(handle) )
|
|
|
+ colorIdx = 0;
|
|
|
+ for (uint32_t ii = 0; ii < m_numTh; ++ii)
|
|
|
{
|
|
|
- const TextureGL& texture = s_renderGL->m_textures[handle.idx];
|
|
|
-
|
|
|
- if (0 != texture.m_id)
|
|
|
+ TextureHandle handle = m_th[ii];
|
|
|
+ if (isValid(handle) )
|
|
|
{
|
|
|
- GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
|
|
|
- if (!isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
|
|
|
+ const TextureGL& texture = s_renderGL->m_textures[handle.idx];
|
|
|
+
|
|
|
+ if (0 != texture.m_id)
|
|
|
{
|
|
|
- ++colorIdx;
|
|
|
- GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
|
|
|
- , attachment
|
|
|
- , texture.m_target
|
|
|
- , texture.m_id
|
|
|
- , 0
|
|
|
- ) );
|
|
|
+ GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
|
|
|
+ if (!isDepth( (TextureFormat::Enum)texture.m_textureFormat) )
|
|
|
+ {
|
|
|
+ ++colorIdx;
|
|
|
+ GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER
|
|
|
+ , attachment
|
|
|
+ , texture.m_target
|
|
|
+ , texture.m_id
|
|
|
+ , 0
|
|
|
+ ) );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ frameBufferValidate();
|
|
|
}
|
|
|
|
|
|
- frameBufferValidate();
|
|
|
+ GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) );
|
|
|
}
|
|
|
-
|
|
|
- GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) );
|
|
|
}
|
|
|
|
|
|
void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
|