From fc371fc24c0e03a8429cb8dce4e4e4d0e34bba23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 27 Sep 2014 11:31:04 -0700 Subject: [PATCH 01/10] Removing use of setView*Mask API. --- examples/08-update/update.cpp | 3 +- examples/09-hdr/hdr.cpp | 27 +++++++---------- .../shadowmaps_simple.cpp | 10 ++++--- examples/16-shadowmaps/shadowmaps.cpp | 26 +++-------------- examples/19-oit/oit.cpp | 3 +- examples/21-deferred/deferred.cpp | 29 +++++-------------- 6 files changed, 32 insertions(+), 66 deletions(-) diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index d5b1d38d..74e2fa7d 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -196,7 +196,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) while (!entry::processEvents(width, height, debug, reset) ) { // Set view 0 and 1 viewport. - bgfx::setViewRectMask(0x3, 0, 0, width, height); + bgfx::setViewRect(0, 0, 0, width, height); + bgfx::setViewRect(1, 0, 0, width, height); // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 4868b6a7..e6a00245 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -294,8 +294,12 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); // Set views. - bgfx::setViewRectMask(0x1f, 0, 0, width, height); - bgfx::setViewFrameBufferMask(0x3, fbh); + for (uint32_t ii = 0; ii < 6; ++ii) + { + bgfx::setViewRect(ii, 0, 0, width, height); + } + bgfx::setViewFrameBuffer(0, fbh); + bgfx::setViewFrameBuffer(1, fbh); bgfx::setViewRect(2, 0, 0, 128, 128); bgfx::setViewFrameBuffer(2, lum[0]); @@ -327,19 +331,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) bx::mtxOrtho(proj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); // Set view and projection matrix for view 0. - bgfx::setViewTransformMask(0 - |(1<<0) - |(1<<2) - |(1<<3) - |(1<<4) - |(1<<5) - |(1<<6) - |(1<<7) - |(1<<8) - |(1<<9) - , view - , proj - ); + for (uint32_t ii = 0; ii < 10; ++ii) + { + bgfx::setViewTransform(ii, view, proj); + } float at[3] = { 0.0f, 1.0f, 0.0f }; float eye[3] = { 0.0f, 1.0f, -2.5f }; @@ -357,7 +352,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bx::mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); // Set view and projection matrix for view 1. - bgfx::setViewTransformMask(1<<1, view, proj); + bgfx::setViewTransform(1, view, proj); bgfx::setUniform(u_mtx, mtx); diff --git a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 0681c00f..2c73df61 100644 --- a/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -16,10 +16,7 @@ #include "entry/entry.h" #define RENDER_SHADOW_PASS_ID 0 -#define RENDER_SHADOW_PASS_BIT (1< Date: Tue, 23 Sep 2014 15:34:05 +0200 Subject: [PATCH 02/10] Reordering imgui functions. --- examples/common/imgui/imgui.cpp | 87 ++++++++++++++++----------------- examples/common/imgui/imgui.h | 14 +++--- 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 397a2345..49671f2b 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -2796,6 +2796,16 @@ ImguiFontHandle imguiCreate(const void* _data, float _fontSize) return s_imgui.create(_data, _fontSize); } +void imguiDestroy() +{ + s_imgui.destroy(); +} + +ImguiFontHandle imguiCreateFont(const void* _data, float _fontSize) +{ + return s_imgui.createFont(_data, _fontSize); +} + void imguiSetFont(ImguiFontHandle _handle) { s_imgui.setFont(_handle); @@ -2807,16 +2817,6 @@ ImguiFontHandle imguiGetCurrentFont() return handle; } -ImguiFontHandle imguiCreateFont(const void* _data, float _fontSize) -{ - return s_imgui.createFont(_data, _fontSize); -} - -void imguiDestroy() -{ - s_imgui.destroy(); -} - void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar, uint8_t _view) { s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _view); @@ -2827,6 +2827,26 @@ void imguiEndFrame() s_imgui.endFrame(); } +void imguiDrawText(int32_t _x, int32_t _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb) +{ + s_imgui.drawText(_x, _y, _align, _text, _argb); +} + +void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb) +{ + s_imgui.drawLine(_x0, _y0, _x1, _y1, _r, _argb); +} + +void imguiDrawRoundedRect(float _x, float _y, float _width, float _height, float _r, uint32_t _argb) +{ + s_imgui.drawRoundedRect(_x, _y, _width, _height, _r, _argb); +} + +void imguiDrawRect(float _x, float _y, float _width, float _height, uint32_t _argb) +{ + s_imgui.drawRect(_x, _y, _width, _height, _argb); +} + bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled) { return s_imgui.borderButton(_border, _checked, _enabled); @@ -2867,7 +2887,6 @@ void imguiEndScrollArea(int32_t _r) s_imgui.endArea(); } - void imguiIndent(uint16_t _width) { s_imgui.indent(_width); @@ -2913,6 +2932,14 @@ bool imguiCheck(const char* _text, bool _checked, bool _enabled) return s_imgui.check(_text, _checked, _enabled); } +void imguiBool(const char* _text, bool& _flag, bool _enabled) +{ + if (imguiCheck(_text, _flag, _enabled) ) + { + _flag = !_flag; + } +} + bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled) { return s_imgui.collapse(_text, _subtext, _checked, _enabled); @@ -3016,34 +3043,6 @@ uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...) return _selected; } -void imguiDrawText(int32_t _x, int32_t _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb) -{ - s_imgui.drawText(_x, _y, _align, _text, _argb); -} - -void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb) -{ - s_imgui.drawLine(_x0, _y0, _x1, _y1, _r, _argb); -} - -void imguiDrawRoundedRect(float _x, float _y, float _width, float _height, float _r, uint32_t _argb) -{ - s_imgui.drawRoundedRect(_x, _y, _width, _height, _r, _argb); -} - -void imguiDrawRect(float _x, float _y, float _width, float _height, uint32_t _argb) -{ - s_imgui.drawRect(_x, _y, _width, _height, _argb); -} - -void imguiBool(const char* _text, bool& _flag, bool _enabled) -{ - if (imguiCheck(_text, _flag, _enabled) ) - { - _flag = !_flag; - } -} - void imguiColorWheel(float _rgb[3], bool _respectIndentation, bool _enabled) { s_imgui.colorWheelWidget(_rgb, _respectIndentation, _enabled); @@ -3089,11 +3088,6 @@ void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align); } -bool imguiMouseOverArea() -{ - return s_imgui.m_insideArea; -} - float imguiGetTextLength(const char* _text, ImguiFontHandle _handle) { #if !USE_NANOVG_FONT @@ -3103,3 +3097,8 @@ float imguiGetTextLength(const char* _text, ImguiFontHandle _handle) return 0.0f; #endif } + +bool imguiMouseOverArea() +{ + return s_imgui.m_insideArea; +} diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 5b4421d2..e55a139c 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -126,6 +126,11 @@ void imguiDestroy(); void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 31); void imguiEndFrame(); +void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb); +void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb); +void imguiDrawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb); +void imguiDrawRect(float _x, float _y, float _w, float _h, uint32_t _argb); + /// Notice: this function is not to be called between imguiBeginArea() and imguiEndArea(). bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = true); @@ -148,6 +153,7 @@ int32_t imguiGetWidgetY(); bool imguiButton(const char* _text, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, uint32_t _rgb0 = IMGUI_BUTTON_RGB0, int32_t _r = IMGUI_BUTTON_R); bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); +void imguiBool(const char* _text, bool& _flag, bool _enabled = true); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true); void imguiLabel(const char* _format, ...); void imguiLabel(uint32_t _rgba, const char* _format, ...); @@ -165,12 +171,6 @@ uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ImguiAlign::E uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...); #define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL) -void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb); -void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb); -void imguiDrawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb); -void imguiDrawRect(float _x, float _y, float _w, float _h, uint32_t _argb); - -void imguiBool(const char* _text, bool& _flag, bool _enabled = true); void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, bool _enabled = true); void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, bool _enabled = true); @@ -179,7 +179,7 @@ void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _asp void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); -bool imguiMouseOverArea(); float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); +bool imguiMouseOverArea(); #endif // IMGUI_H_HEADER_GUARD From 9a42955f6e514930cd872c71fe373ebab9645a77 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 23 Sep 2014 19:50:02 +0200 Subject: [PATCH 03/10] Added _originBottomLeft parameter for imguiImage(). --- examples/common/imgui/imgui.cpp | 22 +++++++++++----------- examples/common/imgui/imgui.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 49671f2b..9c564213 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1456,7 +1456,7 @@ struct Imgui return selected; } - void image(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) + void image(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft) { Area& area = getCurrentArea(); @@ -1485,7 +1485,7 @@ struct Imgui const int32_t yy = area.m_widgetY; area.m_widgetY += _height + DEFAULT_SPACING; - screenQuad(xx, yy, _width, _height); + screenQuad(xx, yy, _width, _height, _originBottomLeft); bgfx::setUniform(u_imageLod, &_lod); bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); @@ -1494,12 +1494,12 @@ struct Imgui bgfx::submit(m_view); } - void image(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align) + void image(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft) { const float width = _width*float(getCurrentArea().m_widgetW); const float height = width/_aspect; - image(_image, _lod, int32_t(width), int32_t(height), _align); + image(_image, _lod, int32_t(width), int32_t(height), _align, _originBottomLeft); } void imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) @@ -2330,7 +2330,7 @@ struct Imgui #endif // USE_NANOVG_FONT } - void screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height) + void screenQuad(int32_t _x, int32_t _y, int32_t _width, uint32_t _height, bool _originBottomLeft = false) { if (bgfx::checkAvailTransientVertexBuffer(6, PosUvVertex::ms_decl) ) { @@ -2350,8 +2350,8 @@ struct Imgui const float texelHalfH = m_halfTexel/heightf; const float minu = texelHalfW; const float maxu = 1.0f - texelHalfW; - const float minv = texelHalfH; - const float maxv = texelHalfH + 1.0f; + const float minv = _originBottomLeft ? texelHalfH+1.0f : texelHalfH ; + const float maxv = _originBottomLeft ? texelHalfH : texelHalfH+1.0f; vertex[0].m_x = minx; vertex[0].m_y = miny; @@ -3068,14 +3068,14 @@ void imguiColorWheel(const char* _text, float _rgb[3], bool& _activated, bool _e } } -void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) +void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft) { - s_imgui.image(_image, _lod, _width, _height, _align); + s_imgui.image(_image, _lod, _width, _height, _align, _originBottomLeft); } -void imguiImage(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align) +void imguiImage(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft) { - s_imgui.image(_image, _lod, _width, _aspect, _align); + s_imgui.image(_image, _lod, _width, _aspect, _align, _originBottomLeft); } void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index e55a139c..fd0357af 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -174,8 +174,8 @@ uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...); void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, bool _enabled = true); void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, bool _enabled = true); -void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); -void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); +void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false); +void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false); void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); From e051ed4feba65896cd6486de5f46162a49694cc2 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sat, 27 Sep 2014 20:43:05 +0200 Subject: [PATCH 04/10] Removed bgfx::*Mask() API. --- examples/13-stencil/stencil.cpp | 39 +++++++++++++++-- examples/14-shadowvolumes/shadowvolumes.cpp | 47 ++++++++++++++++----- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/examples/13-stencil/stencil.cpp b/examples/13-stencil/stencil.cpp index 39ee78f5..cdaaa31f 100644 --- a/examples/13-stencil/stencil.cpp +++ b/examples/13-stencil/stencil.cpp @@ -215,6 +215,39 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName) return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); } +void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewClear( (uint8_t)view, _flags, _rgba, _depth, _stencil); + } +} + +void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewTransform( (uint8_t)view, _view, _proj); + } +} + +void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewRect( (uint8_t)view, _x, _y, _width, _height); + } +} + void mtxReflected(float*__restrict _result , const float* __restrict _p /* plane */ , const float* __restrict _n /* normal */ @@ -619,7 +652,7 @@ void clearView(uint8_t _id, uint8_t _flags, const ClearValues& _clearValues) void clearViewMask(uint32_t _viewMask, uint8_t _flags, const ClearValues& _clearValues) { - bgfx::setViewClearMask(_viewMask + setViewClearMask(_viewMask , _flags , _clearValues.m_clearRgba , _clearValues.m_clearDepth @@ -1429,8 +1462,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) ); // Setup view rect and transform for all used views. - bgfx::setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); - bgfx::setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); + setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); + setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); s_viewMask = 0; // Advance to next frame. Rendering thread will be kicked to diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index d60747bb..f703d057 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -188,6 +188,39 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName) return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); } +void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewClear( (uint8_t)view, _flags, _rgba, _depth, _stencil); + } +} + +void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewTransform( (uint8_t)view, _view, _proj); + } +} + +void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) + { + viewMask >>= ntz; + view += ntz; + + bgfx::setViewRect( (uint8_t)view, _x, _y, _width, _height); + } +} + void mtxBillboard(float* __restrict _result , const float* __restrict _view , const float* __restrict _pos @@ -619,14 +652,6 @@ void submit(uint8_t _id, int32_t _depth = 0) s_viewMask |= 1 << _id; } -void submitMask(uint32_t _viewMask, int32_t _depth = 0) -{ - bgfx::submitMask(_viewMask, _depth); - - // Keep track of submited view ids. - s_viewMask |= _viewMask; -} - struct Aabb { float m_min[3]; @@ -2866,8 +2891,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) } // Setup view rect and transform for all used views. - bgfx::setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); - bgfx::setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); + setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); + setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); s_viewMask = 0; // Advance to next frame. Rendering thread will be kicked to @@ -2878,7 +2903,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) s_svAllocator.swap(); // Reset clear values. - bgfx::setViewClearMask(UINT32_MAX + setViewClearMask(UINT32_MAX , BGFX_CLEAR_NONE , clearValues.m_clearRgba , clearValues.m_clearDepth From 58b37542c89d4a270b411c044974ef22f7ca636c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 27 Sep 2014 12:07:40 -0700 Subject: [PATCH 05/10] Removed *Mask API. --- include/bgfx.c99.h | 58 -------------------- include/bgfx.h | 51 ------------------ src/bgfx.cpp | 129 --------------------------------------------- src/bgfx_p.h | 73 ------------------------- 4 files changed, 311 deletions(-) diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index 708a5409..c2c90e14 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -1062,17 +1062,6 @@ BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name); */ BGFX_C_API void bgfx_set_view_rect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); -/** - * Set view rectangle for multiple views. - * - * @param _viewMask Bit mask representing affected views. - * @param _x Position x from the left corner of the window. - * @param _y Position y from the top corner of the window. - * @param _width Width of view port region. - * @param _height Height of view port region. - */ -BGFX_C_API void bgfx_set_view_rect_mask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - /** * Set view scissor. Draw primitive outside view will be clipped. When * _x, _y, _width and _height are set to 0, scissor will be disabled. @@ -1084,19 +1073,6 @@ BGFX_C_API void bgfx_set_view_rect_mask(uint32_t _viewMask, uint16_t _x, uint16_ */ BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); -/** - * Set view scissor for multiple views. When _x, _y, _width and _height - * are set to 0, scissor will be disabled. - * - * @param _id View id. - * @param _viewMask Bit mask representing affected views. - * @param _x Position x from the left corner of the window. - * @param _y Position y from the top corner of the window. - * @param _width Width of scissor region. - * @param _height Height of scissor region. - */ -BGFX_C_API void bgfx_set_view_scissor_mask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - /** * Set view clear flags. * @@ -1122,22 +1098,12 @@ BGFX_C_API void bgfx_set_view_clear(uint8_t _id, uint8_t _flags, uint32_t _rgba, */ 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); -/** - * Set view clear flags for multiple views. - */ -BGFX_C_API void bgfx_set_view_clear_mask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil); - /** * Set view into sequential mode. Draw calls will be sorted in the same * order in which submit calls were called. */ BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled); -/** - * Set multiple views into sequential mode. - */ -BGFX_C_API void bgfx_set_view_seq_mask(uint32_t _viewMask, bool _enabled); - /** * Set view frame buffer. * @@ -1148,27 +1114,12 @@ BGFX_C_API void bgfx_set_view_seq_mask(uint32_t _viewMask, bool _enabled); */ BGFX_C_API void bgfx_set_view_frame_buffer(uint8_t _id, bgfx_frame_buffer_handle_t _handle); -/** - * Set view frame buffer for multiple views. - * - * @param _viewMask View mask. - * @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as - * frame buffer handle will draw primitives from this view into - * default back buffer. - */ -BGFX_C_API void bgfx_set_view_frame_buffer_mask(uint32_t _viewMask, bgfx_frame_buffer_handle_t _handle); - /** * Set view view and projection matrices, all draw primitives in this * view will use these matrices. */ BGFX_C_API void bgfx_set_view_transform(uint8_t _id, const void* _view, const void* _proj); -/** - * Set view view and projection matrices for multiple views. - */ -BGFX_C_API void bgfx_set_view_transform_mask(uint32_t _viewMask, const void* _view, const void* _proj); - /** * Sets debug marker. */ @@ -1341,15 +1292,6 @@ BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_ */ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth); -/** - * Submit primitive for rendering into multiple views. - * - * @param _viewMask Mask to which views to submit draw primitive calls. - * @param _depth Depth for sorting. - * @returns Number of draw calls. - */ -BGFX_C_API uint32_t bgfx_submit_mask(uint32_t _viewMask, int32_t _depth); - /** * */ diff --git a/include/bgfx.h b/include/bgfx.h index c42e276d..8d04572d 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -911,16 +911,6 @@ namespace bgfx /// void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - /// Set view rectangle for multiple views. - /// - /// @param _viewMask Bit mask representing affected views. - /// @param _x Position x from the left corner of the window. - /// @param _y Position y from the top corner of the window. - /// @param _width Width of view port region. - /// @param _height Height of view port region. - /// - void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); - /// Set view scissor. Draw primitive outside view will be clipped. When /// _x, _y, _width and _height are set to 0, scissor will be disabled. /// @@ -931,18 +921,6 @@ namespace bgfx /// void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0); - /// Set view scissor for multiple views. When _x, _y, _width and _height - /// are set to 0, scissor will be disabled. - /// - /// @param _id View id. - /// @param _viewMask Bit mask representing affected views. - /// @param _x Position x from the left corner of the window. - /// @param _y Position y from the top corner of the window. - /// @param _width Width of scissor region. - /// @param _height Height of scissor region. - /// - void setViewScissorMask(uint32_t _viewMask, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0); - /// Set view clear flags. /// /// @param _id View id. @@ -966,16 +944,10 @@ namespace bgfx /// 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); - /// Set view clear flags for multiple views. - void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0); - /// Set view into sequential mode. Draw calls will be sorted in the same /// order in which submit calls were called. void setViewSeq(uint8_t _id, bool _enabled); - /// Set multiple views into sequential mode. - void setViewSeqMask(uint32_t _viewMask, bool _enabled); - /// Set view frame buffer. /// /// @param _id View id. @@ -988,25 +960,10 @@ namespace bgfx /// void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle); - /// Set view frame buffer for multiple views. - /// - /// @param _viewMask View mask. - /// @param _handle Frame buffer handle. Passing BGFX_INVALID_HANDLE as - /// frame buffer handle will draw primitives from this view into - /// default back buffer. - /// - /// NOTE: - /// Not persistent after bgfx::reset call. - /// - void setViewFrameBufferMask(uint32_t _viewMask, FrameBufferHandle _handle); - /// Set view view and projection matrices, all draw primitives in this /// view will use these matrices. void setViewTransform(uint8_t _id, const void* _view, const void* _proj); - /// Set view view and projection matrices for multiple views. - void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj); - /// Sets debug marker. void setMarker(const char* _marker); @@ -1159,14 +1116,6 @@ namespace bgfx /// uint32_t submit(uint8_t _id, int32_t _depth = 0); - /// Submit primitive for rendering into multiple views. - /// - /// @param _viewMask Mask to which views to submit draw primitive calls. - /// @param _depth Depth for sorting. - /// @returns Number of draw calls. - /// - uint32_t submitMask(uint32_t _viewMask, int32_t _depth = 0); - /// void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 641690ea..e14c3d8d 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -723,57 +723,6 @@ namespace bgfx return m_num; } - uint32_t Frame::submitMask(uint32_t _viewMask, int32_t _depth) - { - if (m_discard) - { - discard(); - return m_num; - } - - if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= m_num - || (0 == m_draw.m_numVertices && 0 == m_draw.m_numIndices) ) - { - m_numDropped += bx::uint32_cntbits(_viewMask); - return m_num; - } - - m_constEnd = m_constantBuffer->getPos(); - - BX_WARN(invalidHandle != m_key.m_program, "Program with invalid handle"); - if (invalidHandle != m_key.m_program) - { - m_key.m_depth = _depth; - - for (uint32_t id = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, id += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - id += ntz; - - m_key.m_view = id; - m_key.m_seq = s_ctx->m_seq[id] & s_ctx->m_seqMask[id]; - s_ctx->m_seq[id]++; - - uint64_t key = m_key.encodeDraw(); - m_sortKeys[m_num] = key; - m_sortValues[m_num] = m_numRenderItems; - ++m_num; - } - - m_draw.m_constBegin = m_constBegin; - m_draw.m_constEnd = m_constEnd; - m_draw.m_flags |= m_flags; - m_renderItem[m_numRenderItems].draw = m_draw; - ++m_numRenderItems; - } - - m_draw.clear(); - m_constBegin = m_constEnd; - m_flags = BGFX_STATE_NONE; - - return m_num; - } - uint32_t Frame::dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ) { if (m_discard) @@ -2571,24 +2520,12 @@ again: s_ctx->setViewRect(_id, _x, _y, _width, _height); } - void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewRectMask(_viewMask, _x, _y, _width, _height); - } - void setViewScissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { BGFX_CHECK_MAIN_THREAD(); s_ctx->setViewScissor(_id, _x, _y, _width, _height); } - void setViewScissorMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewScissorMask(_viewMask, _x, _y, _width, _height); - } - void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) { BGFX_CHECK_MAIN_THREAD(); @@ -2601,48 +2538,24 @@ again: s_ctx->setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); } - void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewClearMask(_viewMask, _flags, _rgba, _depth, _stencil); - } - void setViewSeq(uint8_t _id, bool _enabled) { BGFX_CHECK_MAIN_THREAD(); s_ctx->setViewSeq(_id, _enabled); } - void setViewSeqMask(uint32_t _viewMask, bool _enabled) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewSeqMask(_viewMask, _enabled); - } - void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle) { BGFX_CHECK_MAIN_THREAD(); s_ctx->setViewFrameBuffer(_id, _handle); } - void setViewFrameBufferMask(uint32_t _mask, FrameBufferHandle _handle) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewFrameBufferMask(_mask, _handle); - } - void setViewTransform(uint8_t _id, const void* _view, const void* _proj) { BGFX_CHECK_MAIN_THREAD(); s_ctx->setViewTransform(_id, _view, _proj); } - void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj) - { - BGFX_CHECK_MAIN_THREAD(); - s_ctx->setViewTransformMask(_viewMask, _view, _proj); - } - void setMarker(const char* _marker) { BGFX_CHECK_MAIN_THREAD(); @@ -2775,12 +2688,6 @@ again: return s_ctx->submit(_id, _depth); } - uint32_t submitMask(uint32_t _viewMask, int32_t _depth) - { - BGFX_CHECK_MAIN_THREAD(); - return s_ctx->submitMask(_viewMask, _depth); - } - void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access) { BGFX_CHECK_MAIN_THREAD(); @@ -3243,21 +3150,11 @@ BGFX_C_API void bgfx_set_view_rect(uint8_t _id, uint16_t _x, uint16_t _y, uint16 bgfx::setViewRect(_id, _x, _y, _width, _height); } -BGFX_C_API void bgfx_set_view_rect_mask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - bgfx::setViewRectMask(_viewMask, _x, _y, _width, _height); -} - BGFX_C_API void bgfx_set_view_scissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { bgfx::setViewScissor(_id, _x, _y, _width, _height); } -BGFX_C_API void bgfx_set_view_scissor_mask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - bgfx::setViewScissorMask(_viewMask, _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::setViewClear(_id, _flags, _rgba, _depth, _stencil); @@ -3268,43 +3165,22 @@ BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _dept bgfx::setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); } -BGFX_C_API void bgfx_set_view_clear_mask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) -{ - bgfx::setViewClearMask(_viewMask, _flags, _rgba, _depth, _stencil); -} - BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled) { bgfx::setViewSeq(_id, _enabled); } -BGFX_C_API void bgfx_set_view_seq_mask(uint32_t _viewMask, bool _enabled) -{ - bgfx::setViewSeqMask(_viewMask, _enabled); -} - BGFX_C_API void bgfx_set_view_frame_buffer(uint8_t _id, bgfx_frame_buffer_handle_t _handle) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; bgfx::setViewFrameBuffer(_id, handle.cpp); } -BGFX_C_API void bgfx_set_view_frame_buffer_mask(uint32_t _viewMask, bgfx_frame_buffer_handle_t _handle) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::setViewFrameBufferMask(_viewMask, handle.cpp); -} - BGFX_C_API void bgfx_set_view_transform(uint8_t _id, const void* _view, const void* _proj) { bgfx::setViewTransform(_id, _view, _proj); } -BGFX_C_API void bgfx_set_view_transform_mask(uint32_t _viewMask, const void* _view, const void* _proj) -{ - bgfx::setViewTransformMask(_viewMask, _view, _proj); -} - BGFX_C_API void bgfx_set_marker(const char* _marker) { bgfx::setMarker(_marker); @@ -3410,11 +3286,6 @@ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth) return bgfx::submit(_id, _depth); } -BGFX_C_API uint32_t bgfx_submit_mask(uint32_t _viewMask, int32_t _depth) -{ - return bgfx::submitMask(_viewMask, _depth); -} - BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_texture_format_t _format, bgfx_access_t _access) { union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 410658fd..d5dad8dc 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1331,7 +1331,6 @@ namespace bgfx } uint32_t submit(uint8_t _id, int32_t _depth); - uint32_t submitMask(uint32_t _viewMask, int32_t _depth); uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _ngx, uint16_t _ngy, uint16_t _ngz); void sort(); @@ -2652,17 +2651,6 @@ namespace bgfx rect.m_height = bx::uint16_max(_height, 1); } - BGFX_API_FUNC(void setViewRectMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) ) - { - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - setViewRect( (uint8_t)view, _x, _y, _width, _height); - } - } - BGFX_API_FUNC(void setViewScissor(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) ) { Rect& scissor = m_scissor[_id]; @@ -2672,17 +2660,6 @@ namespace bgfx scissor.m_height = _height; } - BGFX_API_FUNC(void setViewScissorMask(uint32_t _viewMask, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) ) - { - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - setViewScissor( (uint8_t)view, _x, _y, _width, _height); - } - } - BGFX_API_FUNC(void setViewClear(uint8_t _id, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { Clear& clear = m_clear[_id]; @@ -2713,50 +2690,16 @@ namespace bgfx clear.m_stencil = _stencil; } - BGFX_API_FUNC(void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) - { - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - setViewClear( (uint8_t)view, _flags, _rgba, _depth, _stencil); - } - } - BGFX_API_FUNC(void setViewSeq(uint8_t _id, bool _enabled) ) { m_seqMask[_id] = _enabled ? 0xffff : 0x0; } - BGFX_API_FUNC(void setViewSeqMask(uint32_t _viewMask, bool _enabled) ) - { - uint16_t mask = _enabled ? 0xffff : 0x0; - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - m_seqMask[view] = mask; - } - } - BGFX_API_FUNC(void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle) ) { m_fb[_id] = _handle; } - BGFX_API_FUNC(void setViewFrameBufferMask(uint32_t _viewMask, FrameBufferHandle _handle) ) - { - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - m_fb[view] = _handle; - } - } - BGFX_API_FUNC(void setViewTransform(uint8_t _id, const void* _view, const void* _proj) ) { if (NULL != _view) @@ -2778,17 +2721,6 @@ namespace bgfx } } - BGFX_API_FUNC(void setViewTransformMask(uint32_t _viewMask, const void* _view, const void* _proj) ) - { - for (uint32_t view = 0, viewMask = _viewMask, ntz = bx::uint32_cnttz(_viewMask); 0 != viewMask; viewMask >>= 1, view += 1, ntz = bx::uint32_cnttz(viewMask) ) - { - viewMask >>= ntz; - view += ntz; - - setViewTransform( (uint8_t)view, _view, _proj); - } - } - BGFX_API_FUNC(void setMarker(const char* _marker) ) { m_submit->setMarker(_marker); @@ -2898,11 +2830,6 @@ namespace bgfx return m_submit->submit(_id, _depth); } - BGFX_API_FUNC(uint32_t submitMask(uint32_t _viewMask, int32_t _depth) ) - { - return m_submit->submitMask(_viewMask, _depth); - } - BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, TextureFormat::Enum _format, Access::Enum _access) ) { m_submit->setImage(_stage, _sampler, _handle, _mip, _format, _access); From d35c14164b4e71e8772aa4bd09e16bd4a952f50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 27 Sep 2014 14:15:56 -0700 Subject: [PATCH 06/10] Updated README. --- README.md | 16 +++++++++++++--- src/renderer_d3d9.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1a01d07..c05141e3 100644 --- a/README.md +++ b/README.md @@ -411,10 +411,22 @@ build errors. Debugging --------- +### RenderDoc + When using DX11 renderer, you can drop in `renderdoc.dll` into working directory, and it will be automatically loaded during bgfx initialization. This allows frame capture at any time by pressing **F11**. +Download: [RenderDoc](https://renderdoc.org/builds) + +### IntelGPA + +Right click **Intel GPA Monitor** tray icon, choose preferences, check +"Auto-detect launched applications" option. Find `InjectionList.txt` in GPA +directory and add `examples-*` to the list. + +Download: [IntelGPA](https://software.intel.com/en-us/vcsource/tools/intel-gpa) + Other debuggers: | Name | OS | DX9 | DX11 | GL | GLES | Source | @@ -424,11 +436,9 @@ Other debuggers: | IntelGPA | Linux/OSX/Win | x | x | | x | | | RenderDoc | Win | | x | | | x | +Download: [APITrace](https://apitrace.github.io/) [CodeXL](http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/) -[IntelGPA](https://software.intel.com/en-us/vcsource/tools/intel-gpa) -[RenderDoc](http://cryengine.com/renderdoc) - SDL, GLFW, etc. --------------- diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 7ecf1ac8..bfa94017 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -533,6 +533,19 @@ namespace bgfx m_fmtDepth = D3DFMT_D24FS8; #endif // BX_PLATFORM_WINDOWS + { + IDirect3DSwapChain9* swapChain; + DX_CHECK(m_device->GetSwapChain(0, &swapChain) ); + + // GPA increases swapchain ref count. + // + // This causes assert in debug. When debugger is present refcount + // checks are off. + setGraphicsDebuggerPresent(1 != getRefCount(swapChain) ); + + DX_RELEASE(swapChain, 0); + } + postReset(); m_initialized = true; From d705fbc9bde4c7f23843a12ec8d079c0d2cc2e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 27 Sep 2014 20:40:47 -0700 Subject: [PATCH 07/10] Fixed RenderDoc crash when IntelGPA is present. --- scripts/genie.lua | 1 + src/renderer_d3d11.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/scripts/genie.lua b/scripts/genie.lua index 07cd1d0c..01ca6342 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -77,6 +77,7 @@ function exampleProject(_name) } links { -- this is needed only for testing with GLES2/3 on Windows with VS2008 "DelayImp", + "psapi", } configuration { "vs201*" } diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index fec89a51..2261848c 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -7,6 +7,7 @@ #if BGFX_CONFIG_RENDERER_DIRECT3D11 # include "renderer_d3d11.h" +# include # include namespace bgfx @@ -423,8 +424,54 @@ RENDERDOC_IMPORT pRENDERDOC_GetAPIVersion RENDERDOC_GetAPIVersion; + bool findModule(const char* _name) + { + HANDLE process = GetCurrentProcess(); + DWORD size; + BOOL result = EnumProcessModules(process + , NULL + , 0 + , &size + ); + if (0 != result) + { + HMODULE* modules = (HMODULE*)alloca(size); + result = EnumProcessModules(process + , modules + , size + , &size + ); + + if (0 != result) + { + char moduleName[MAX_PATH]; + for (uint32_t ii = 0, num = uint32_t(size/sizeof(HMODULE) ); ii < num; ++ii) + { + result = GetModuleBaseNameA(process + , modules[ii] + , moduleName + , BX_COUNTOF(moduleName) + ); + if (0 != result + && 0 == bx::stricmp(_name, moduleName) ) + { + return true; + } + } + } + } + + return false; + } + void* loadRenderDoc() { + // Skip loading RenderDoc when IntelGPA is present to avoid RenderDoc crash. + if (findModule(BX_ARCH_32BIT ? "shimloader32.dll" : "shimloader64.dll") ) + { + return NULL; + } + void* renderdocdll = bx::dlopen("renderdoc.dll"); if (NULL != renderdocdll) From 80f2044a7c4ec3beee59563eb7a865739abf83a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 28 Sep 2014 11:03:47 -0700 Subject: [PATCH 08/10] Cleanup. --- examples/common/entry/entry_windows.cpp | 5 ++- src/renderer_d3d11.cpp | 58 +++++++++++++++---------- src/renderer_d3d11.h | 1 + 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index e0133ac6..9beadc5e 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -16,6 +16,9 @@ #include +#include +#include + enum { WM_USER_WINDOW_CREATE = WM_USER, @@ -89,7 +92,7 @@ namespace entry uint32_t m_width; uint32_t m_height; uint32_t m_flags; - std::string m_title; + tinystl::string m_title; }; struct Context diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2261848c..7398449e 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -7,8 +7,11 @@ #if BGFX_CONFIG_RENDERER_DIRECT3D11 # include "renderer_d3d11.h" -# include -# include + +# if BGFX_CONFIG_DEBUG_PIX +# include +# include +# endif // BGFX_CONFIG_DEBUG_PIX namespace bgfx { @@ -404,26 +407,7 @@ namespace bgfx return false; }; -#define RENDERDOC_IMPORT \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_SetLogFile); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_GetCapture); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureOptions); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_SetActiveWindow); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_TriggerCapture); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_StartFrameCapture); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_EndFrameCapture); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_GetOverlayBits); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_MaskOverlayBits); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_SetFocusToggleKeys); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureKeys); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_InitRemoteAccess); - -#define RENDERDOC_IMPORT_FUNC(_func) p##_func _func -RENDERDOC_IMPORT -#undef RENDERDOC_IMPORT_FUNC - - pRENDERDOC_GetAPIVersion RENDERDOC_GetAPIVersion; - +#if BGFX_CONFIG_DEBUG_PIX && BX_PLATFORM_WINDOWS bool findModule(const char* _name) { HANDLE process = GetCurrentProcess(); @@ -464,6 +448,26 @@ RENDERDOC_IMPORT return false; } +#define RENDERDOC_IMPORT \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_SetLogFile); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_GetCapture); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureOptions); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_SetActiveWindow); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_TriggerCapture); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_StartFrameCapture); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_EndFrameCapture); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_GetOverlayBits); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_MaskOverlayBits); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_SetFocusToggleKeys); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureKeys); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_InitRemoteAccess); + +#define RENDERDOC_IMPORT_FUNC(_func) p##_func _func + RENDERDOC_IMPORT +#undef RENDERDOC_IMPORT_FUNC + + pRENDERDOC_GetAPIVersion RENDERDOC_GetAPIVersion; + void* loadRenderDoc() { // Skip loading RenderDoc when IntelGPA is present to avoid RenderDoc crash. @@ -521,6 +525,16 @@ RENDERDOC_IMPORT bx::dlclose(_renderdocdll); } } +#else + void* loadRenderDoc() + { + return NULL; + } + + void unloadRenderDoc(void*) + { + } +#endif // BGFX_CONFIG_DEBUG_PIX struct RendererContextD3D11 : public RendererContextI { diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index 85748d0f..97830956 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -23,6 +23,7 @@ #else # include #endif // BX_COMPILER_MSVC + #include "renderer_d3d.h" #define D3DCOLOR_ARGB(_a, _r, _g, _b) ( (DWORD)( ( ( (_a)&0xff)<<24)|( ( (_r)&0xff)<<16)|( ( (_g)&0xff)<<8)|( (_b)&0xff) ) ) From c48226adc77de25575840ebf652a69e09f27dee4 Mon Sep 17 00:00:00 2001 From: Branimir Karadzic Date: Sun, 28 Sep 2014 12:10:34 -0700 Subject: [PATCH 09/10] Updated README. --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c05141e3..b38e8cfa 100644 --- a/README.md +++ b/README.md @@ -413,9 +413,10 @@ Debugging ### RenderDoc -When using DX11 renderer, you can drop in `renderdoc.dll` into working -directory, and it will be automatically loaded during bgfx initialization. This -allows frame capture at any time by pressing **F11**. +Loading of RenderDoc is integrated in bgfx when using DX11 renderer. You can +drop in `renderdoc.dll` from RenderDoc distribution into working directory, +and it will be automatically loaded during bgfx initialization. This allows +frame capture at any time by pressing **F11**. Download: [RenderDoc](https://renderdoc.org/builds) @@ -435,10 +436,12 @@ Other debuggers: | CodeXL | Linux/Win | | | x | | | | IntelGPA | Linux/OSX/Win | x | x | | x | | | RenderDoc | Win | | x | | | x | +| vogl | Linux | | | x | | x | Download: [APITrace](https://apitrace.github.io/) [CodeXL](http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/) +[vogl](https://github.com/ValveSoftware/vogl)-- SDL, GLFW, etc. --------------- From 290c39ca393d52f3322db1ddd24965d1bc330c28 Mon Sep 17 00:00:00 2001 From: Branimir Karadzic Date: Sun, 28 Sep 2014 12:11:52 -0700 Subject: [PATCH 10/10] Updated README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b38e8cfa..abc23e95 100644 --- a/README.md +++ b/README.md @@ -441,7 +441,7 @@ Other debuggers: Download: [APITrace](https://apitrace.github.io/) [CodeXL](http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/) -[vogl](https://github.com/ValveSoftware/vogl)-- +[vogl](https://github.com/ValveSoftware/vogl) SDL, GLFW, etc. ---------------