From bb96d76c0ab6084b497db240d4ebe48491e43db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 11 Jan 2015 18:00:08 -0800 Subject: [PATCH] Added discard framebuffer resources after use. --- examples/09-hdr/hdr.cpp | 14 +++---- include/bgfx.c99.h | 4 +- include/bgfx.h | 4 +- include/bgfxdefines.h | 37 +++++++++++++++---- src/bgfx.cpp | 8 ++-- src/bgfx_p.h | 22 +++++++---- src/glcontext_glx.cpp | 6 +-- src/glimports.h | 15 ++++++-- src/renderer_gl.cpp | 82 ++++++++++++++++++++++++++++++++++++----- src/renderer_gl.h | 5 ++- 10 files changed, 148 insertions(+), 49 deletions(-) diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 385dc321e..9611bda71 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -8,12 +8,7 @@ #include "imgui/imgui.h" static float s_texelHalf = 0.0f; -static bool s_originBottomLeft = false; - -inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) -{ - bx::mtxProj(_result, _fovy, _aspect, _near, _far, s_originBottomLeft); -} +static bool s_originBottomLeft = false; struct PosColorTexCoord0Vertex { @@ -232,7 +227,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) uint32_t oldWidth = 0; uint32_t oldHeight = 0; uint32_t oldReset = reset; - + float speed = 0.37f; float middleGray = 0.18f; float white = 1.1f; @@ -318,6 +313,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) } bgfx::setViewFrameBuffer(0, fbh); bgfx::setViewFrameBuffer(1, fbh); + bgfx::setViewClear(1, BGFX_CLEAR_DISCARD_DEPTH|BGFX_CLEAR_DISCARD_STENCIL); bgfx::setViewRect(2, 0, 0, 128, 128); bgfx::setViewFrameBuffer(2, lum[0]); @@ -361,7 +357,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bx::mtxRotateXY(mtx , 0.0f , time - ); + ); float temp[4]; bx::vec3MulMtx(temp, eye, mtx); @@ -453,7 +449,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) screenSpaceQuad( (float)width, (float)height, s_originBottomLeft); bgfx::submit(9); - // Advance to next frame. Rendering thread will be kicked to + // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); } diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index aea82ba4c..afc1c44ed 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -1129,7 +1129,7 @@ BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uin * @param _depth Depth clear value. * @param _stencil Stencil clear value. */ -BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); +BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); /** * Set view clear flags with different clear color for each @@ -1142,7 +1142,7 @@ BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint8_t _flags, uint32_t _rgba, * @param _depth Depth clear value. * @param _stencil Stencil clear value. */ -BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7); +BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7); /** * Set view into sequential mode. Draw calls will be sorted in the same diff --git a/include/bgfx.h b/include/bgfx.h index 77e471972..1a8059cb0 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -1049,7 +1049,7 @@ namespace bgfx /// @param _depth Depth clear value. /// @param _stencil Stencil clear value. /// - void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0); + void setViewClear(uint8_t _id, uint16_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0); /// Set view clear flags with different clear color for each /// frame buffer texture. Must use setClearColor to setup clear color @@ -1061,7 +1061,7 @@ namespace bgfx /// @param _depth Depth clear value. /// @param _stencil Stencil clear value. /// - void setViewClear(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0 = UINT8_MAX, uint8_t _1 = UINT8_MAX, uint8_t _2 = UINT8_MAX, uint8_t _3 = UINT8_MAX, uint8_t _4 = UINT8_MAX, uint8_t _5 = UINT8_MAX, uint8_t _6 = UINT8_MAX, uint8_t _7 = UINT8_MAX); + void setViewClear(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0 = UINT8_MAX, uint8_t _1 = UINT8_MAX, uint8_t _2 = UINT8_MAX, uint8_t _3 = UINT8_MAX, uint8_t _4 = UINT8_MAX, uint8_t _5 = UINT8_MAX, uint8_t _6 = UINT8_MAX, uint8_t _7 = UINT8_MAX); /// Set view into sequential mode. Draw calls will be sorted in the same /// order in which submit calls were called. diff --git a/include/bgfxdefines.h b/include/bgfxdefines.h index bcebcf265..881ee7211 100644 --- a/include/bgfxdefines.h +++ b/include/bgfxdefines.h @@ -182,13 +182,36 @@ #define BGFX_STENCIL_FUNC_RMASK(_mask) ( (uint32_t(_mask)<setViewScissor(_id, _x, _y, _width, _height); } - void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) + void setViewClear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(_id < BGFX_CONFIG_MAX_VIEWS, "Invalid view id: %d", _id); s_ctx->setViewClear(_id, _flags, _rgba, _depth, _stencil); } - void setViewClear(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) + void setViewClear(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(_id < BGFX_CONFIG_MAX_VIEWS, "Invalid view id: %d", _id); @@ -3270,12 +3270,12 @@ BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uin bgfx::setViewScissor(_id, _x, _y, _width, _height); } -BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) +BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) { bgfx::setViewClear(_id, _flags, _rgba, _depth, _stencil); } -BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) +BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) { bgfx::setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 354008646..ea0b4b6e6 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -94,7 +94,13 @@ namespace bgfx #define BGFX_CHUNK_MAGIC_TEX BX_MAKEFOURCC('T', 'E', 'X', 0x0) #define BGFX_CHUNK_MAGIC_VSH BX_MAKEFOURCC('V', 'S', 'H', 0x3) -#define BGFX_CLEAR_COLOR_USE_PALETTE_BIT UINT8_C(0x80) +#define BGFX_CLEAR_COLOR_USE_PALETTE UINT16_C(0x8000) +#define BGFX_CLEAR_MASK (0 \ + | BGFX_CLEAR_COLOR \ + | BGFX_CLEAR_DEPTH \ + | BGFX_CLEAR_STENCIL \ + | BGFX_CLEAR_COLOR_USE_PALETTE \ + ) #include // mingw wants it to be before tr1/unordered_*... @@ -204,10 +210,10 @@ namespace bgfx struct Clear { - uint8_t m_index[8]; - float m_depth; - uint8_t m_stencil; - uint8_t m_flags; + uint8_t m_index[8]; + float m_depth; + uint8_t m_stencil; + uint16_t m_flags; }; struct Rect @@ -2852,7 +2858,7 @@ namespace bgfx scissor.m_height = _height; } - BGFX_API_FUNC(void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) + BGFX_API_FUNC(void setViewClear(uint8_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { Clear& clear = m_clear[_id]; clear.m_flags = _flags; @@ -2864,11 +2870,11 @@ namespace bgfx clear.m_stencil = _stencil; } - BGFX_API_FUNC(void setViewClear(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) ) + BGFX_API_FUNC(void setViewClear(uint8_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) ) { Clear& clear = m_clear[_id]; clear.m_flags = (_flags & ~BGFX_CLEAR_COLOR) - | (0xff != (_0&_1&_2&_3&_4&_5&_6&_7) ? BGFX_CLEAR_COLOR|BGFX_CLEAR_COLOR_USE_PALETTE_BIT : 0) + | (0xff != (_0&_1&_2&_3&_4&_5&_6&_7) ? BGFX_CLEAR_COLOR|BGFX_CLEAR_COLOR_USE_PALETTE : 0) ; clear.m_index[0] = _0; clear.m_index[1] = _1; diff --git a/src/glcontext_glx.cpp b/src/glcontext_glx.cpp index 6bf103e44..4f9c4009e 100644 --- a/src/glcontext_glx.cpp +++ b/src/glcontext_glx.cpp @@ -15,9 +15,9 @@ namespace bgfx typedef int (*PFNGLXSWAPINTERVALMESAPROC)(uint32_t _interval); PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB; - PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; - PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; - PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; + PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; + PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func # include "glimports.h" diff --git a/src/glimports.h b/src/glimports.h index bc47b57f2..69e5aff92 100644 --- a/src/glimports.h +++ b/src/glimports.h @@ -31,7 +31,7 @@ #define GL_IMPORT_____x(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## XXXXX) #if GL_IMPORT_TYPEDEFS -typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); +typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); typedef void (GL_APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); typedef void (GL_APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); typedef void (GL_APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); @@ -140,6 +140,7 @@ typedef void (GL_APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, typedef void (GL_APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); typedef const GLubyte* (GL_APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); typedef GLint (GL_APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (GL_APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); typedef void (GL_APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); typedef void (GL_APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); typedef void (GL_APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); @@ -308,6 +309,7 @@ GL_IMPORT______(false, PFNGLGETSHADERIVPROC, glGetShaderiv GL_IMPORT______(false, PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog); GL_IMPORT______(false, PFNGLGETSTRINGPROC, glGetString); GL_IMPORT______(false, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation); +GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); GL_IMPORT______(false, PFNGLLINKPROGRAMPROC, glLinkProgram); GL_IMPORT______(true, PFNGLMEMORYBARRIERPROC, glMemoryBarrier); GL_IMPORT______(true, PFNGLOBJECTLABELPROC, glObjectLabel); @@ -386,6 +388,8 @@ GL_IMPORT_ARB__(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElement GL_IMPORT_ARB__(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); +GL_IMPORT_ARB__(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); + GL_IMPORT_EXT__(true, PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer); GL_IMPORT_EXT__(true, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers); GL_IMPORT_EXT__(true, PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers); @@ -474,6 +478,9 @@ GL_IMPORT_NV___(true, PFNGLDELETEQUERIESPROC, glDeleteQueri GL_IMPORT_NV___(true, PFNGLBEGINQUERYPROC, glBeginQuery); GL_IMPORT_NV___(true, PFNGLENDQUERYPROC, glEndQuery); GL_IMPORT_NV___(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObjectui64v); + +GL_IMPORT (true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer, glDiscardFramebufferEXT); + #else GL_IMPORT______(true, PFNGLTEXIMAGE3DPROC, glTexImage3D); GL_IMPORT______(true, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D); @@ -505,7 +512,7 @@ GL_IMPORT______(true, PFNGLBLENDEQUATIONIPROC, glBlendEquati GL_IMPORT______(true, PFNGLBLENDEQUATIONSEPARATEIPROC, glBlendEquationSeparatei); GL_IMPORT______(true, PFNGLBLENDFUNCIPROC, glBlendFunci); GL_IMPORT______(true, PFNGLBLENDFUNCSEPARATEIPROC, glBlendFuncSeparatei); - + GL_IMPORT______(true, PFNGLDRAWBUFFERPROC, glDrawBuffer); GL_IMPORT______(true, PFNGLREADBUFFERPROC, glReadBuffer); GL_IMPORT______(true, PFNGLGENSAMPLERSPROC, glGenSamplers); @@ -513,7 +520,7 @@ GL_IMPORT______(true, PFNGLDELETESAMPLERSPROC, glDeleteSampl GL_IMPORT______(true, PFNGLBINDSAMPLERPROC, glBindSampler); GL_IMPORT______(true, PFNGLSAMPLERPARAMETERFPROC, glSamplerParameterf); GL_IMPORT______(true, PFNGLSAMPLERPARAMETERIPROC, glSamplerParameteri); - + GL_IMPORT______(true, PFNGLBINDBUFFERBASEPROC, glBindBufferBase); GL_IMPORT______(true, PFNGLBINDBUFFERRANGEPROC, glBindBufferRange); GL_IMPORT______(true, PFNGLBINDIMAGETEXTUREPROC, glBindImageTexture); @@ -534,6 +541,8 @@ GL_IMPORT______(true, PFNGLBEGINQUERYPROC, glBeginQuery) GL_IMPORT______(true, PFNGLENDQUERYPROC, glEndQuery); GL_IMPORT______(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObjectui64v); +GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); + # endif // BGFX_CONFIG_RENDERER_OPENGLES < 30 #endif // !BGFX_CONFIG_RENDERER_OPENGL diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 45e79d331..a6d67894f 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -322,6 +322,7 @@ namespace bgfx ARB_half_float_pixel, ARB_half_float_vertex, ARB_instanced_arrays, + ARB_invalidate_subdata, ARB_map_buffer_range, ARB_multisample, ARB_occlusion_query, @@ -363,6 +364,7 @@ namespace bgfx EXT_compressed_ETC1_RGB8_sub_texture, EXT_debug_label, EXT_debug_marker, + EXT_discard_framebuffer, EXT_draw_buffers, EXT_frag_depth, EXT_framebuffer_blit, @@ -480,6 +482,7 @@ namespace bgfx { "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "ARB_instanced_arrays", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, + { "ARB_invalidate_subdata", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, { "ARB_map_buffer_range", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "ARB_multisample", false, true }, { "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, @@ -521,6 +524,7 @@ namespace bgfx { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. { "EXT_debug_label", false, true }, { "EXT_debug_marker", false, true }, + { "EXT_discard_framebuffer", false, true }, // GLES2 extension. { "EXT_draw_buffers", false, true }, // GLES2 extension. { "EXT_frag_depth", false, true }, // GLES2 extension. { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, @@ -691,6 +695,10 @@ namespace bgfx { } + static void GL_APIENTRY stubInvalidateFramebuffer(GLenum /*_target*/, GLsizei /*_numAttachments*/, const GLenum* /*_attachments*/) + { + } + typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); static const char* getGLString(GLenum _name) @@ -843,6 +851,7 @@ namespace bgfx RendererContextGL() : m_numWindows(1) , m_rtMsaa(false) + , m_fbDiscard(BGFX_CLEAR_NONE) , m_capture(NULL) , m_captureSize(0) , m_maxAnisotropy(0.0f) @@ -1364,6 +1373,11 @@ namespace bgfx glObjectLabel = stubObjectLabel; } + if (NULL == glInvalidateFramebuffer) + { + glInvalidateFramebuffer = stubInvalidateFramebuffer; + } + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) { m_queries.create(); @@ -1756,14 +1770,24 @@ namespace bgfx ) ); } - uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, bool _msaa = true) + uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint8_t _discard = BGFX_CLEAR_NONE, bool _msaa = true) { if (isValid(m_fbh) && m_fbh.idx != _fbh.idx - && m_rtMsaa) + && (BGFX_CLEAR_NONE != m_fbDiscard || m_rtMsaa) ) { FrameBufferGL& frameBuffer = m_frameBuffers[m_fbh.idx]; - frameBuffer.resolve(); + if (m_rtMsaa) + { + frameBuffer.resolve(); + } + + if (BGFX_CLEAR_NONE != m_fbDiscard) + { + frameBuffer.discard(m_fbDiscard); + } + + m_fbDiscard = BGFX_CLEAR_NONE; } m_glctx.makeCurrent(NULL); @@ -1788,8 +1812,9 @@ namespace bgfx } } - m_fbh = _fbh; - m_rtMsaa = _msaa; + m_fbh = _fbh; + m_fbDiscard = _discard; + m_rtMsaa = _msaa; return _height; } @@ -2258,7 +2283,7 @@ namespace bgfx GLuint flags = 0; if (BGFX_CLEAR_COLOR & _clear.m_flags) { - if (BGFX_CLEAR_COLOR_USE_PALETTE_BIT & _clear.m_flags) + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE-1, _clear.m_index[0]); const float* rgba = _palette[index]; @@ -2380,7 +2405,7 @@ namespace bgfx GL_CHECK(glUseProgram(program.m_id) ); program.bindAttributes(vertexDecl, 0); - if (BGFX_CLEAR_COLOR_USE_PALETTE_BIT & _clear.m_flags) + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; for (uint32_t ii = 0; ii < numMrt; ++ii) @@ -2433,6 +2458,7 @@ namespace bgfx bool m_rtMsaa; FrameBufferHandle m_fbh; + uint32_t m_fbDiscard; Resolution m_resolution; void* m_capture; @@ -4100,6 +4126,42 @@ namespace bgfx } } + void FrameBufferGL::discard(uint8_t _flags) + { + GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS+2]; + uint32_t idx = 0; + + if (BGFX_CLEAR_NONE != (_flags & BGFX_CLEAR_DISCARD_COLOR_MASK) ) + { + for (uint32_t ii = 0, num = m_num; ii < num; ++ii) + { + if (BGFX_CLEAR_NONE != (_flags & (BGFX_CLEAR_DISCARD_COLOR_0<m_hmd.height : _render->m_resolution.m_height ; - height = setFrameBuffer(fbh, height); + height = setFrameBuffer(fbh, height, discardFlags); } viewRestart = ( (BGFX_VIEW_STEREO == (_render->m_viewFlags[view] & BGFX_VIEW_STEREO) ) ); @@ -4284,8 +4347,9 @@ namespace bgfx ) ); Clear& clear = _render->m_clear[view]; + discardFlags = clear.m_flags & BGFX_CLEAR_DISCARD_MASK; - if (BGFX_CLEAR_NONE != clear.m_flags) + if (BGFX_CLEAR_NONE != (clear.m_flags & BGFX_CLEAR_MASK) ) { clearQuad(_clearQuad, viewState.m_rect, clear, height, _render->m_clearColor); } diff --git a/src/renderer_gl.h b/src/renderer_gl.h index d2cd32dc5..544448465 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -519,8 +519,8 @@ typedef uint64_t GLuint64; # define glClearDepth glClearDepthf #endif // !BGFX_CONFIG_RENDERER_OPENGL -namespace bgfx -{ +namespace bgfx +{ class ConstantBuffer; void dumpExtensions(const char* _extensions); @@ -835,6 +835,7 @@ namespace bgfx void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); uint16_t destroy(); void resolve(); + void discard(uint8_t _flags); SwapChainGL* m_swapChain; GLuint m_fbo[2];