Merge pull request #161 from dariomanesku/master

Minor imgui changes + removed bgfx::*Mask() API from 13-stencil and 14-shadowvolumes.
This commit is contained in:
Branimir Karadžić 2014-09-27 12:00:58 -07:00
commit 4255618a37
4 changed files with 135 additions and 78 deletions

View file

@ -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 */); 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 void mtxReflected(float*__restrict _result
, const float* __restrict _p /* plane */ , const float* __restrict _p /* plane */
, const float* __restrict _n /* normal */ , 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) void clearViewMask(uint32_t _viewMask, uint8_t _flags, const ClearValues& _clearValues)
{ {
bgfx::setViewClearMask(_viewMask setViewClearMask(_viewMask
, _flags , _flags
, _clearValues.m_clearRgba , _clearValues.m_clearRgba
, _clearValues.m_clearDepth , _clearValues.m_clearDepth
@ -1429,8 +1462,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
); );
// Setup view rect and transform for all used views. // Setup view rect and transform for all used views.
bgfx::setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height);
bgfx::setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj);
s_viewMask = 0; s_viewMask = 0;
// Advance to next frame. Rendering thread will be kicked to // Advance to next frame. Rendering thread will be kicked to

View file

@ -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 */); 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 void mtxBillboard(float* __restrict _result
, const float* __restrict _view , const float* __restrict _view
, const float* __restrict _pos , const float* __restrict _pos
@ -619,14 +652,6 @@ void submit(uint8_t _id, int32_t _depth = 0)
s_viewMask |= 1 << _id; 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 struct Aabb
{ {
float m_min[3]; float m_min[3];
@ -2866,8 +2891,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
} }
// Setup view rect and transform for all used views. // Setup view rect and transform for all used views.
bgfx::setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height); setViewRectMask(s_viewMask, 0, 0, viewState.m_width, viewState.m_height);
bgfx::setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj); setViewTransformMask(s_viewMask, viewState.m_view, viewState.m_proj);
s_viewMask = 0; s_viewMask = 0;
// Advance to next frame. Rendering thread will be kicked to // Advance to next frame. Rendering thread will be kicked to
@ -2878,7 +2903,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
s_svAllocator.swap(); s_svAllocator.swap();
// Reset clear values. // Reset clear values.
bgfx::setViewClearMask(UINT32_MAX setViewClearMask(UINT32_MAX
, BGFX_CLEAR_NONE , BGFX_CLEAR_NONE
, clearValues.m_clearRgba , clearValues.m_clearRgba
, clearValues.m_clearDepth , clearValues.m_clearDepth

View file

@ -1456,7 +1456,7 @@ struct Imgui
return selected; 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(); Area& area = getCurrentArea();
@ -1485,7 +1485,7 @@ struct Imgui
const int32_t yy = area.m_widgetY; const int32_t yy = area.m_widgetY;
area.m_widgetY += _height + DEFAULT_SPACING; area.m_widgetY += _height + DEFAULT_SPACING;
screenQuad(xx, yy, _width, _height); screenQuad(xx, yy, _width, _height, _originBottomLeft);
bgfx::setUniform(u_imageLod, &_lod); bgfx::setUniform(u_imageLod, &_lod);
bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture); bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
@ -1494,12 +1494,12 @@ struct Imgui
bgfx::submit(m_view); 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 width = _width*float(getCurrentArea().m_widgetW);
const float height = width/_aspect; 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) 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 #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) ) if (bgfx::checkAvailTransientVertexBuffer(6, PosUvVertex::ms_decl) )
{ {
@ -2350,8 +2350,8 @@ struct Imgui
const float texelHalfH = m_halfTexel/heightf; const float texelHalfH = m_halfTexel/heightf;
const float minu = texelHalfW; const float minu = texelHalfW;
const float maxu = 1.0f - texelHalfW; const float maxu = 1.0f - texelHalfW;
const float minv = texelHalfH; const float minv = _originBottomLeft ? texelHalfH+1.0f : texelHalfH ;
const float maxv = texelHalfH + 1.0f; const float maxv = _originBottomLeft ? texelHalfH : texelHalfH+1.0f;
vertex[0].m_x = minx; vertex[0].m_x = minx;
vertex[0].m_y = miny; vertex[0].m_y = miny;
@ -2796,6 +2796,16 @@ ImguiFontHandle imguiCreate(const void* _data, float _fontSize)
return s_imgui.create(_data, _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) void imguiSetFont(ImguiFontHandle _handle)
{ {
s_imgui.setFont(_handle); s_imgui.setFont(_handle);
@ -2807,16 +2817,6 @@ ImguiFontHandle imguiGetCurrentFont()
return handle; 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) 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); s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _view);
@ -2827,6 +2827,26 @@ void imguiEndFrame()
s_imgui.endFrame(); 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) bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled)
{ {
return s_imgui.borderButton(_border, _checked, _enabled); return s_imgui.borderButton(_border, _checked, _enabled);
@ -2867,7 +2887,6 @@ void imguiEndScrollArea(int32_t _r)
s_imgui.endArea(); s_imgui.endArea();
} }
void imguiIndent(uint16_t _width) void imguiIndent(uint16_t _width)
{ {
s_imgui.indent(_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); 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) bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled)
{ {
return s_imgui.collapse(_text, _subtext, _checked, _enabled); return s_imgui.collapse(_text, _subtext, _checked, _enabled);
@ -3016,34 +3043,6 @@ uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...)
return _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) void imguiColorWheel(float _rgb[3], bool _respectIndentation, bool _enabled)
{ {
s_imgui.colorWheelWidget(_rgb, _respectIndentation, _enabled); s_imgui.colorWheelWidget(_rgb, _respectIndentation, _enabled);
@ -3069,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) void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align)
@ -3089,11 +3088,6 @@ void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod,
s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align); s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align);
} }
bool imguiMouseOverArea()
{
return s_imgui.m_insideArea;
}
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle) float imguiGetTextLength(const char* _text, ImguiFontHandle _handle)
{ {
#if !USE_NANOVG_FONT #if !USE_NANOVG_FONT
@ -3103,3 +3097,8 @@ float imguiGetTextLength(const char* _text, ImguiFontHandle _handle)
return 0.0f; return 0.0f;
#endif #endif
} }
bool imguiMouseOverArea()
{
return s_imgui.m_insideArea;
}

View file

@ -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 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 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(). /// Notice: this function is not to be called between imguiBeginArea() and imguiEndArea().
bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = true); 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 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 imguiItem(const char* _text, bool _enabled = true);
bool imguiCheck(const char* _text, bool _checked, 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); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true);
void imguiLabel(const char* _format, ...); void imguiLabel(const char* _format, ...);
void imguiLabel(uint32_t _rgba, const char* _format, ...); void imguiLabel(uint32_t _rgba, const char* _format, ...);
@ -165,21 +171,15 @@ uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ImguiAlign::E
uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...); uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...);
#define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL) #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(float _rgb[3], bool _respectIndentation = false, bool _enabled = true);
void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, 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, 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); 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, 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); 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); float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);
bool imguiMouseOverArea();
#endif // IMGUI_H_HEADER_GUARD #endif // IMGUI_H_HEADER_GUARD