mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-09-26 04:05:58 +00:00
Added swap-chain. (#3959)
This commit is contained in:
committed by
GitHub
parent
ad4a0173d6
commit
01dbbbc08c
@@ -2270,9 +2270,11 @@ namespace bgfx { namespace gl
|
||||
|
||||
m_fbh = BGFX_INVALID_HANDLE;
|
||||
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
|
||||
bx::memSet(&m_resolution, 0, sizeof(m_resolution) );
|
||||
bx::memSet(&m_mainSwapChain, 0, sizeof(m_mainSwapChain) );
|
||||
|
||||
setRenderContextSize(_init.resolution);
|
||||
m_reset = _init.reset & ~BGFX_RESET_INTERNAL_FORCE;
|
||||
|
||||
setRenderContextSize(_init.swapChain);
|
||||
|
||||
m_vendor = getGLString(GL_VENDOR);
|
||||
m_renderer = getGLString(GL_RENDERER);
|
||||
@@ -3202,6 +3204,12 @@ namespace bgfx { namespace gl
|
||||
FrameBufferGL& frameBuffer = m_frameBuffers[m_windows[ii].idx];
|
||||
if (frameBuffer.m_needPresent)
|
||||
{
|
||||
if (0 != frameBuffer.m_fbo[0])
|
||||
{
|
||||
m_glctx.makeCurrent(frameBuffer.m_swapChain);
|
||||
frameBuffer.blitSwapChainFbo();
|
||||
}
|
||||
|
||||
m_glctx.swap(frameBuffer.m_swapChain);
|
||||
frameBuffer.m_needPresent = false;
|
||||
}
|
||||
@@ -3659,11 +3667,6 @@ namespace bgfx { namespace gl
|
||||
release(mem);
|
||||
}
|
||||
|
||||
void overrideInternal(TextureHandle _handle, uintptr_t _ptr, uint16_t /*_layerIndex*/) override
|
||||
{
|
||||
m_textures[_handle.idx].overrideInternal(_ptr);
|
||||
}
|
||||
|
||||
uintptr_t getInternal(TextureHandle _handle) override
|
||||
{
|
||||
return uintptr_t(m_textures[_handle.idx].m_id);
|
||||
@@ -3679,12 +3682,16 @@ namespace bgfx { namespace gl
|
||||
m_frameBuffers[_handle.idx].create(_num, _attachment);
|
||||
}
|
||||
|
||||
void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override
|
||||
void createFrameBuffer(FrameBufferHandle _handle, const SwapChain& _desc) override
|
||||
{
|
||||
BX_UNUSED(_format, _depthFormat);
|
||||
uint16_t denseIdx = m_numWindows++;
|
||||
m_windows[denseIdx] = _handle;
|
||||
m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height);
|
||||
m_frameBuffers[_handle.idx].create(denseIdx, _desc);
|
||||
}
|
||||
|
||||
void resizeFrameBuffer(FrameBufferHandle _handle, const SwapChain& _desc) override
|
||||
{
|
||||
m_frameBuffers[_handle.idx].update(_desc);
|
||||
}
|
||||
|
||||
void destroyFrameBuffer(FrameBufferHandle _handle) override
|
||||
@@ -3735,8 +3742,8 @@ namespace bgfx { namespace gl
|
||||
void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override
|
||||
{
|
||||
SwapChainGL* swapChain = NULL;
|
||||
uint32_t width = m_resolution.width;
|
||||
uint32_t height = m_resolution.height;
|
||||
uint32_t width = m_mainSwapChain.width;
|
||||
uint32_t height = m_mainSwapChain.height;
|
||||
|
||||
if (isValid(_handle) )
|
||||
{
|
||||
@@ -3745,6 +3752,12 @@ namespace bgfx { namespace gl
|
||||
width = frameBuffer.m_width;
|
||||
height = frameBuffer.m_height;
|
||||
}
|
||||
else if (NULL == m_mainSwapChain.nwh
|
||||
&& NULL == g_platformData.context)
|
||||
{
|
||||
BX_TRACE("Unable to capture screenshot %s, no back buffer.", _filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == width
|
||||
|| 0 == height)
|
||||
@@ -3755,6 +3768,17 @@ namespace bgfx { namespace gl
|
||||
|
||||
m_glctx.makeCurrent(swapChain);
|
||||
|
||||
if (isValid(_handle)
|
||||
&& NULL != m_frameBuffers[_handle.idx].m_swapChain
|
||||
&& 0 != m_frameBuffers[_handle.idx].m_fbo[0])
|
||||
{
|
||||
FrameBufferGL& frameBuffer = m_frameBuffers[_handle.idx];
|
||||
|
||||
frameBuffer.resolveSwapChainFbo();
|
||||
|
||||
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, frameBuffer.swapChainReadFbo() ) );
|
||||
}
|
||||
|
||||
uint32_t length = width*height*4;
|
||||
uint8_t* data = (uint8_t*)bx::alloc(g_allocator, length);
|
||||
|
||||
@@ -3855,12 +3879,39 @@ namespace bgfx { namespace gl
|
||||
|
||||
void submit(Frame* _render, const ClearQuad& _clearQuad, const MipGen& _mipGen, TextVideoMemBlitter& _textVideoMemBlitter) override;
|
||||
|
||||
void dbgTextRenderBegin(TextVideoMemBlitter& _blitter) override
|
||||
void dbgTextRenderBegin(TextVideoMemBlitter& _blitter, FrameBufferHandle _handle) override
|
||||
{
|
||||
uint32_t width = m_resolution.width;
|
||||
uint32_t height = m_resolution.height;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
if (isValid(_handle) )
|
||||
{
|
||||
FrameBufferGL& frameBuffer = m_frameBuffers[_handle.idx];
|
||||
width = frameBuffer.m_width;
|
||||
height = frameBuffer.m_height;
|
||||
|
||||
if (UINT16_MAX != frameBuffer.m_denseIdx)
|
||||
{
|
||||
m_glctx.makeCurrent(frameBuffer.m_swapChain);
|
||||
frameBuffer.m_needPresent = true;
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_glctx.makeCurrent(NULL);
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
width = m_mainSwapChain.width;
|
||||
height = m_mainSwapChain.height;
|
||||
|
||||
m_glctx.makeCurrent(NULL);
|
||||
m_needPresent = true;
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
|
||||
}
|
||||
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
|
||||
GL_CHECK(glViewport(0, 0, width, height) );
|
||||
|
||||
GL_CHECK(glDisable(GL_SCISSOR_TEST) );
|
||||
@@ -3939,9 +3990,9 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
}
|
||||
|
||||
void updateResolution(const Resolution& _resolution)
|
||||
void updateResolution(const SwapChain& _swapChain, uint32_t _reset)
|
||||
{
|
||||
float maxAnisotropy = !!(_resolution.reset & BGFX_RESET_MAXANISOTROPY)
|
||||
float maxAnisotropy = !!(_reset & BGFX_RESET_MAXANISOTROPY)
|
||||
? m_maxAnisotropyDefault
|
||||
: 0.0f
|
||||
;
|
||||
@@ -3954,7 +4005,7 @@ namespace bgfx { namespace gl
|
||||
|
||||
if (s_extension[Extension::ARB_depth_clamp].m_supported)
|
||||
{
|
||||
if (!!(_resolution.reset & BGFX_RESET_DEPTH_CLAMP) )
|
||||
if (!!(_reset & BGFX_RESET_DEPTH_CLAMP) )
|
||||
{
|
||||
GL_CHECK(glEnable(GL_DEPTH_CLAMP) );
|
||||
}
|
||||
@@ -3970,19 +4021,21 @@ namespace bgfx { namespace gl
|
||||
| BGFX_RESET_SUSPEND
|
||||
);
|
||||
|
||||
if (m_resolution.width != _resolution.width
|
||||
|| m_resolution.height != _resolution.height
|
||||
|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
|
||||
if (m_mainSwapChain.width != _swapChain.width
|
||||
|| m_mainSwapChain.height != _swapChain.height
|
||||
|| m_mainSwapChain.nwh != _swapChain.nwh
|
||||
|| m_mainSwapChain.ndt != _swapChain.ndt
|
||||
|| (m_reset&maskFlags) != (_reset&maskFlags) )
|
||||
{
|
||||
uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE);
|
||||
uint32_t flags = _reset & (~BGFX_RESET_INTERNAL_FORCE);
|
||||
|
||||
m_resolution = _resolution;
|
||||
m_resolution.reset = flags;
|
||||
m_mainSwapChain = _swapChain;
|
||||
m_reset = flags;
|
||||
|
||||
m_textVideoMem.resize(false, _resolution.width, _resolution.height);
|
||||
m_textVideoMem.resize(false, _swapChain.width, _swapChain.height);
|
||||
m_textVideoMem.clear();
|
||||
|
||||
setRenderContextSize(m_resolution);
|
||||
setRenderContextSize(m_mainSwapChain);
|
||||
updateCapture();
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
|
||||
@@ -4059,7 +4112,7 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glFrontFace(GL_CW) );
|
||||
|
||||
frameBuffer.m_needPresent = true;
|
||||
m_currentFbo = 0;
|
||||
m_currentFbo = frameBuffer.m_fbo[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4079,7 +4132,12 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
if (0 == m_currentFbo)
|
||||
{
|
||||
if (0 != (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) )
|
||||
const uint32_t surfaceFlags = isValid(_fbh)
|
||||
? m_frameBuffers[_fbh.idx].m_desc.flags
|
||||
: m_mainSwapChain.flags
|
||||
;
|
||||
|
||||
if (0 != (surfaceFlags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER) )
|
||||
{
|
||||
GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB) );
|
||||
}
|
||||
@@ -4121,7 +4179,7 @@ namespace bgfx { namespace gl
|
||||
&& 1 < _msaa
|
||||
&& !m_glctx.m_msaaContext)
|
||||
{
|
||||
GLenum storageFormat = m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER
|
||||
GLenum storageFormat = m_mainSwapChain.flags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER
|
||||
? GL_SRGB8_ALPHA8
|
||||
: GL_RGBA8
|
||||
;
|
||||
@@ -4333,8 +4391,8 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_msaaBackBufferFbo) );
|
||||
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
|
||||
|
||||
const uint32_t width = m_resolution.width;
|
||||
const uint32_t height = m_resolution.height;
|
||||
const uint32_t width = m_mainSwapChain.width;
|
||||
const uint32_t height = m_mainSwapChain.height;
|
||||
const GLenum filter = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
|
||||
? GL_NEAREST
|
||||
: GL_LINEAR
|
||||
@@ -4367,22 +4425,22 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void setRenderContextSize(const Resolution& _resolution)
|
||||
void setRenderContextSize(const SwapChain& _swapChain)
|
||||
{
|
||||
if (!m_glctx.isValid() )
|
||||
{
|
||||
m_glctx.create(_resolution);
|
||||
m_glctx.create(_swapChain, m_reset);
|
||||
}
|
||||
else
|
||||
{
|
||||
destroyMsaaFbo();
|
||||
|
||||
m_glctx.resize(_resolution);
|
||||
m_glctx.resize(_swapChain, m_reset);
|
||||
|
||||
uint32_t msaa = (_resolution.reset & BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
|
||||
uint32_t msaa = (_swapChain.flags & BGFX_SWAP_CHAIN_MSAA_MASK)>>BGFX_SWAP_CHAIN_MSAA_SHIFT;
|
||||
msaa = bx::min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
|
||||
|
||||
createMsaaFbo(_resolution.width, _resolution.height, msaa);
|
||||
createMsaaFbo(_swapChain.width, _swapChain.height, msaa);
|
||||
}
|
||||
|
||||
m_flip = true;
|
||||
@@ -4511,11 +4569,11 @@ namespace bgfx { namespace gl
|
||||
|
||||
void updateCapture()
|
||||
{
|
||||
if (m_resolution.reset&BGFX_RESET_CAPTURE)
|
||||
if (m_reset&BGFX_RESET_CAPTURE)
|
||||
{
|
||||
m_captureSize = m_resolution.width*m_resolution.height*4;
|
||||
m_captureSize = m_mainSwapChain.width*m_mainSwapChain.height*4;
|
||||
m_capture = bx::realloc(g_allocator, m_capture, m_captureSize);
|
||||
g_callback->captureBegin(m_resolution.width, m_resolution.height, m_resolution.width*4, TextureFormat::BGRA8, true);
|
||||
g_callback->captureBegin(m_mainSwapChain.width, m_mainSwapChain.height, m_mainSwapChain.width*4, TextureFormat::BGRA8, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4529,8 +4587,8 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
GL_CHECK(glReadPixels(0
|
||||
, 0
|
||||
, m_resolution.width
|
||||
, m_resolution.height
|
||||
, m_mainSwapChain.width
|
||||
, m_mainSwapChain.height
|
||||
, m_readPixelsFmt
|
||||
, GL_UNSIGNED_BYTE
|
||||
, m_capture
|
||||
@@ -4540,11 +4598,11 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
bimg::imageSwizzleBgra8(
|
||||
m_capture
|
||||
, m_resolution.width*4
|
||||
, m_resolution.width
|
||||
, m_resolution.height
|
||||
, m_mainSwapChain.width*4
|
||||
, m_mainSwapChain.width
|
||||
, m_mainSwapChain.height
|
||||
, m_capture
|
||||
, m_resolution.width*4
|
||||
, m_mainSwapChain.width*4
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5096,7 +5154,8 @@ namespace bgfx { namespace gl
|
||||
FrameBufferHandle m_fbh;
|
||||
uint16_t m_fbDiscard;
|
||||
|
||||
Resolution m_resolution;
|
||||
SwapChain m_mainSwapChain;
|
||||
uint32_t m_reset;
|
||||
void* m_capture;
|
||||
uint32_t m_captureSize;
|
||||
float m_maxAnisotropy;
|
||||
@@ -6396,13 +6455,6 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::overrideInternal(uintptr_t _ptr)
|
||||
{
|
||||
destroy();
|
||||
m_flags |= BGFX_SAMPLER_INTERNAL_SHARED;
|
||||
m_id = (GLuint)_ptr;
|
||||
}
|
||||
|
||||
void TextureGL::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem)
|
||||
{
|
||||
const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_requestedFormat) );
|
||||
@@ -7177,6 +7229,11 @@ namespace bgfx { namespace gl
|
||||
|
||||
void FrameBufferGL::postReset()
|
||||
{
|
||||
if (NULL != m_swapChain)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 != m_fbo[0])
|
||||
{
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
|
||||
@@ -7339,19 +7396,298 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height)
|
||||
void FrameBufferGL::create(uint16_t _denseIdx, const SwapChain& _desc)
|
||||
{
|
||||
m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height);
|
||||
m_width = _width;
|
||||
m_height = _height;
|
||||
m_swapChain = s_renderGL->m_glctx.createSwapChain(
|
||||
_desc.nwh
|
||||
, int32_t(_desc.width)
|
||||
, int32_t(_desc.height)
|
||||
);
|
||||
m_desc = _desc;
|
||||
m_width = _desc.width;
|
||||
m_height = _desc.height;
|
||||
m_numTh = 0;
|
||||
m_denseIdx = _denseIdx;
|
||||
m_needPresent = false;
|
||||
|
||||
createSwapChainFbo(_desc);
|
||||
}
|
||||
|
||||
void FrameBufferGL::update(const SwapChain& _desc)
|
||||
{
|
||||
m_desc = _desc;
|
||||
m_width = _desc.width;
|
||||
m_height = _desc.height;
|
||||
|
||||
destroySwapChainFbo();
|
||||
createSwapChainFbo(_desc);
|
||||
}
|
||||
|
||||
void FrameBufferGL::createSwapChainFbo(const SwapChain& _desc)
|
||||
{
|
||||
uint32_t msaa = (_desc.flags & BGFX_SWAP_CHAIN_MSAA_MASK)>>BGFX_SWAP_CHAIN_MSAA_SHIFT;
|
||||
msaa = bx::min<uint32_t>(s_renderGL->m_maxMsaa, 0 == msaa ? 1 : 1<<msaa);
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) )
|
||||
{
|
||||
msaa = 1;
|
||||
}
|
||||
|
||||
const bool srgb = 0 != (_desc.flags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER);
|
||||
|
||||
m_swapChainMsaa = msaa;
|
||||
|
||||
if (1 == msaa
|
||||
&& !srgb
|
||||
&& !isValid(_desc.depth) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const GLenum colorFormat = srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8;
|
||||
|
||||
s_renderGL->m_glctx.makeCurrent(m_swapChain);
|
||||
|
||||
GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) );
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
|
||||
|
||||
if (1 < msaa)
|
||||
{
|
||||
GL_CHECK(glGenRenderbuffers(1, &m_swapChainColorRbo) );
|
||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_swapChainColorRbo) );
|
||||
GL_CHECK(glRenderbufferStorageMultisample(
|
||||
GL_RENDERBUFFER
|
||||
, msaa
|
||||
, colorFormat
|
||||
, _desc.width
|
||||
, _desc.height
|
||||
) );
|
||||
GL_CHECK(glFramebufferRenderbuffer(
|
||||
GL_FRAMEBUFFER
|
||||
, GL_COLOR_ATTACHMENT0
|
||||
, GL_RENDERBUFFER
|
||||
, m_swapChainColorRbo
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glGenTextures(1, &m_swapChainColorTex) );
|
||||
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_swapChainColorTex) );
|
||||
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) );
|
||||
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) );
|
||||
GL_CHECK(glTexImage2D(
|
||||
GL_TEXTURE_2D
|
||||
, 0
|
||||
, colorFormat
|
||||
, _desc.width
|
||||
, _desc.height
|
||||
, 0
|
||||
, GL_RGBA
|
||||
, GL_UNSIGNED_BYTE
|
||||
, NULL
|
||||
) );
|
||||
GL_CHECK(glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER
|
||||
, GL_COLOR_ATTACHMENT0
|
||||
, GL_TEXTURE_2D
|
||||
, m_swapChainColorTex
|
||||
, 0
|
||||
) );
|
||||
}
|
||||
|
||||
if (isValid(_desc.depth) )
|
||||
{
|
||||
const TextureGL& depth = s_renderGL->m_textures[_desc.depth.idx];
|
||||
|
||||
GL_CHECK(glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER
|
||||
, attachmentFor(TextureFormat::Enum(depth.m_textureFormat) )
|
||||
, depth.m_target
|
||||
, depth.m_id
|
||||
, 0
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glGenRenderbuffers(1, &m_swapChainDepthRbo) );
|
||||
GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_swapChainDepthRbo) );
|
||||
|
||||
if (1 < msaa)
|
||||
{
|
||||
GL_CHECK(glRenderbufferStorageMultisample(
|
||||
GL_RENDERBUFFER
|
||||
, msaa
|
||||
, GL_DEPTH24_STENCIL8
|
||||
, _desc.width
|
||||
, _desc.height
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glRenderbufferStorage(
|
||||
GL_RENDERBUFFER
|
||||
, GL_DEPTH24_STENCIL8
|
||||
, _desc.width
|
||||
, _desc.height
|
||||
) );
|
||||
}
|
||||
|
||||
GL_CHECK(glFramebufferRenderbuffer(
|
||||
GL_FRAMEBUFFER
|
||||
, GL_DEPTH_STENCIL_ATTACHMENT
|
||||
, GL_RENDERBUFFER
|
||||
, m_swapChainDepthRbo
|
||||
) );
|
||||
}
|
||||
|
||||
BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
||||
, "glCheckFramebufferStatus failed 0x%08x"
|
||||
, glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
||||
);
|
||||
|
||||
if (1 < msaa)
|
||||
{
|
||||
GL_CHECK(glGenTextures(1, &m_swapChainColorTex) );
|
||||
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_swapChainColorTex) );
|
||||
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) );
|
||||
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) );
|
||||
GL_CHECK(glTexImage2D(
|
||||
GL_TEXTURE_2D
|
||||
, 0
|
||||
, colorFormat
|
||||
, _desc.width
|
||||
, _desc.height
|
||||
, 0
|
||||
, GL_RGBA
|
||||
, GL_UNSIGNED_BYTE
|
||||
, NULL
|
||||
) );
|
||||
|
||||
GL_CHECK(glGenFramebuffers(1, &m_fbo[1]) );
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[1]) );
|
||||
GL_CHECK(glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER
|
||||
, GL_COLOR_ATTACHMENT0
|
||||
, GL_TEXTURE_2D
|
||||
, m_swapChainColorTex
|
||||
, 0
|
||||
) );
|
||||
|
||||
BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
||||
, "glCheckFramebufferStatus failed 0x%08x"
|
||||
, glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
||||
);
|
||||
}
|
||||
|
||||
s_renderGL->m_glctx.makeCurrent(NULL);
|
||||
}
|
||||
|
||||
void FrameBufferGL::destroySwapChainFbo()
|
||||
{
|
||||
if (0 == m_fbo[0])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_renderGL->m_glctx.makeCurrent(m_swapChain);
|
||||
|
||||
GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
|
||||
|
||||
if (0 != m_swapChainColorTex)
|
||||
{
|
||||
GL_CHECK(glDeleteTextures(1, &m_swapChainColorTex) );
|
||||
}
|
||||
|
||||
if (0 != m_swapChainColorRbo)
|
||||
{
|
||||
GL_CHECK(glDeleteRenderbuffers(1, &m_swapChainColorRbo) );
|
||||
}
|
||||
|
||||
if (0 != m_swapChainDepthRbo)
|
||||
{
|
||||
GL_CHECK(glDeleteRenderbuffers(1, &m_swapChainDepthRbo) );
|
||||
}
|
||||
|
||||
m_fbo[0] = 0;
|
||||
m_fbo[1] = 0;
|
||||
m_swapChainColorTex = 0;
|
||||
m_swapChainColorRbo = 0;
|
||||
m_swapChainDepthRbo = 0;
|
||||
m_swapChainMsaa = 1;
|
||||
|
||||
s_renderGL->m_glctx.makeCurrent(NULL);
|
||||
}
|
||||
|
||||
void FrameBufferGL::resolveSwapChainFbo()
|
||||
{
|
||||
if (0 == m_fbo[1])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GL_CHECK(glDisable(GL_SCISSOR_TEST) );
|
||||
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) );
|
||||
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo[1]) );
|
||||
GL_CHECK(glBlitFramebuffer(
|
||||
0
|
||||
, 0
|
||||
, m_width
|
||||
, m_height
|
||||
, 0
|
||||
, 0
|
||||
, m_width
|
||||
, m_height
|
||||
, GL_COLOR_BUFFER_BIT
|
||||
, GL_NEAREST
|
||||
) );
|
||||
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
|
||||
}
|
||||
|
||||
void FrameBufferGL::blitSwapChainFbo()
|
||||
{
|
||||
if (0 == m_fbo[0])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GL_CHECK(glDisable(GL_SCISSOR_TEST) );
|
||||
GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) );
|
||||
GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) );
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) )
|
||||
{
|
||||
GL_CHECK(glUseProgram(s_renderGL->m_msaaBlitProgram) );
|
||||
GL_CHECK(glActiveTexture(GL_TEXTURE0) );
|
||||
GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_swapChainColorTex) );
|
||||
GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 3) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GL_CHECK(glBlitFramebuffer(
|
||||
0
|
||||
, 0
|
||||
, m_width
|
||||
, m_height
|
||||
, 0
|
||||
, 0
|
||||
, m_width
|
||||
, m_height
|
||||
, GL_COLOR_BUFFER_BIT
|
||||
, GL_NEAREST
|
||||
) );
|
||||
}
|
||||
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
|
||||
}
|
||||
|
||||
uint16_t FrameBufferGL::destroy()
|
||||
{
|
||||
if (0 != m_fbo[0])
|
||||
if (NULL != m_swapChain)
|
||||
{
|
||||
destroySwapChainFbo();
|
||||
}
|
||||
else if (0 != m_fbo[0])
|
||||
{
|
||||
GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
|
||||
m_num = 0;
|
||||
@@ -8136,7 +8472,7 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) );
|
||||
GL_CHECK(glFrontFace(GL_CW) );
|
||||
|
||||
updateResolution(_render->m_resolution);
|
||||
updateResolution(_render->m_mainSwapChain, _render->m_reset);
|
||||
|
||||
int64_t timeBegin = bx::getHPCounter();
|
||||
int64_t captureElapsed = 0;
|
||||
@@ -8184,7 +8520,7 @@ namespace bgfx { namespace gl
|
||||
UniformCacheState ucs(_render);
|
||||
BlitState bs(_render);
|
||||
|
||||
int32_t resolutionHeight = _render->m_resolution.height;
|
||||
int32_t resolutionHeight = _render->m_mainSwapChain.height;
|
||||
uint32_t blendFactor = 0;
|
||||
|
||||
uint8_t primIndex;
|
||||
@@ -8280,7 +8616,7 @@ namespace bgfx { namespace gl
|
||||
if (_render->m_view[view].m_fbh.idx != fbh.idx)
|
||||
{
|
||||
fbh = _render->m_view[view].m_fbh;
|
||||
resolutionHeight = _render->m_resolution.height;
|
||||
resolutionHeight = _render->m_mainSwapChain.height;
|
||||
resolutionHeight = setFrameBuffer(fbh, resolutionHeight, discardFlags);
|
||||
}
|
||||
|
||||
@@ -9319,7 +9655,7 @@ namespace bgfx { namespace gl
|
||||
|
||||
if (0 < _render->m_numRenderItems)
|
||||
{
|
||||
if (0 != (m_resolution.reset & BGFX_RESET_FLUSH_AFTER_RENDER) )
|
||||
if (0 != (m_reset & BGFX_RESET_FLUSH_AFTER_RENDER) )
|
||||
{
|
||||
GL_CHECK(glFlush() );
|
||||
}
|
||||
@@ -9430,12 +9766,12 @@ namespace bgfx { namespace gl
|
||||
, freq/frameTime
|
||||
);
|
||||
|
||||
const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
|
||||
const uint32_t msaa = (m_mainSwapChain.flags&BGFX_SWAP_CHAIN_MSAA_MASK)>>BGFX_SWAP_CHAIN_MSAA_SHIFT;
|
||||
tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy "
|
||||
, !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' '
|
||||
, !!(m_reset&BGFX_RESET_VSYNC) ? '\xfe' : ' '
|
||||
, 0 != msaa ? '\xfe' : ' '
|
||||
, 1<<msaa
|
||||
, !!(m_resolution.reset&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' '
|
||||
, !!(m_reset&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' '
|
||||
);
|
||||
|
||||
double elapsedCpuMs = double(frameTime)*toMs;
|
||||
@@ -9563,7 +9899,7 @@ namespace bgfx { namespace gl
|
||||
max = frameTime;
|
||||
}
|
||||
|
||||
dbgTextSubmit(this, _textVideoMemBlitter, tvm);
|
||||
dbgTextSubmit(this, _textVideoMemBlitter, tvm, _render->m_debugFrameBuffer, _render->m_debugTextScale);
|
||||
|
||||
BGFX_GL_PROFILER_END();
|
||||
}
|
||||
@@ -9571,7 +9907,7 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
BGFX_GL_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame);
|
||||
|
||||
dbgTextSubmit(this, _textVideoMemBlitter, _render->m_textVideoMem);
|
||||
dbgTextSubmit(this, _textVideoMemBlitter, _render->m_textVideoMem, _render->m_debugFrameBuffer, _render->m_debugTextScale);
|
||||
|
||||
BGFX_GL_PROFILER_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user