This commit is contained in:
Branimir Karadžić 2014-06-23 20:08:08 -07:00
parent 0ea1d84b21
commit 24d54b972e
3 changed files with 19 additions and 33 deletions

View File

@ -14,9 +14,6 @@
#include <vector> #include <vector>
#include <string> #include <string>
#define IMGUI_VIEWID 30
#define NANOVG_VIEWID 31
static bool s_flipV = false; static bool s_flipV = false;
static float s_texelHalf = 0.0f; static float s_texelHalf = 0.0f;
@ -447,9 +444,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiCreate(data); imguiCreate(data);
free(data); free(data);
NVGcontext* nvg = nvgCreate(512, 512, 1, NANOVG_VIEWID);
bgfx::setViewSeq(NANOVG_VIEWID, true);
// Uniforms. // Uniforms.
s_uniforms.init(); s_uniforms.init();
@ -563,13 +557,10 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0 , 0
, width , width
, height , height
, IMGUI_VIEWID
); );
nvgBeginFrame(nvg, int32_t(width), int32_t(height), 1.0f, NVG_STRAIGHT_ALPHA);
static int32_t rightScrollArea = 0; static int32_t rightScrollArea = 0;
imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea, nvg); imguiBeginScrollArea("Settings", width - 256 - 10, 10, 256, 426, &rightScrollArea);
imguiLabel("Shade:"); imguiLabel("Shade:");
imguiSeparator(); imguiSeparator();
@ -596,7 +587,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiEndScrollArea(); imguiEndScrollArea();
static int32_t leftScrollArea = 0; static int32_t leftScrollArea = 0;
imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea, nvg); imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea);
imguiLabel("Material properties:"); imguiLabel("Material properties:");
imguiSeparator(); imguiSeparator();
@ -670,7 +661,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiEndScrollArea(); imguiEndScrollArea();
nvgEndFrame(nvg);
imguiEndFrame(); imguiEndFrame();
s_uniforms.m_glossiness = settings.m_glossiness; s_uniforms.m_glossiness = settings.m_glossiness;
@ -723,7 +713,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bgfx::setViewRect(0, 0, 0, width, height); bgfx::setViewRect(0, 0, 0, width, height);
bgfx::setViewRect(1, 0, 0, width, height); bgfx::setViewRect(1, 0, 0, width, height);
bgfx::setViewRect(NANOVG_VIEWID, 0, 0, width, height);
// View 0. // View 0.
bgfx::setTexture(4, u_texCube, lightProbes[currentLightProbe].m_tex); bgfx::setTexture(4, u_texCube, lightProbes[currentLightProbe].m_tex);
@ -778,7 +767,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
s_uniforms.destroy(); s_uniforms.destroy();
nvgDelete(nvg);
imguiDestroy(); imguiDestroy();
// Shutdown bgfx. // Shutdown bgfx.

View File

@ -169,6 +169,8 @@ struct Imgui
bool create(const void* _data) bool create(const void* _data)
{ {
m_nvg = nvgCreate(512, 512, 1, m_view);
for (int32_t ii = 0; ii < NUM_CIRCLE_VERTS; ++ii) for (int32_t ii = 0; ii < NUM_CIRCLE_VERTS; ++ii)
{ {
float a = (float)ii / (float)NUM_CIRCLE_VERTS * (float)(M_PI * 2.0); float a = (float)ii / (float)NUM_CIRCLE_VERTS * (float)(M_PI * 2.0);
@ -239,6 +241,7 @@ struct Imgui
bgfx::destroyTexture(m_fontTexture); bgfx::destroyTexture(m_fontTexture);
bgfx::destroyProgram(m_colorProgram); bgfx::destroyProgram(m_colorProgram);
bgfx::destroyProgram(m_textureProgram); bgfx::destroyProgram(m_textureProgram);
nvgDelete(m_nvg);
} }
bool anyActive() const bool anyActive() const
@ -350,6 +353,8 @@ struct Imgui
void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view) void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view)
{ {
nvgBeginFrame(m_nvg, _width, _height, 1.0f, NVG_STRAIGHT_ALPHA);
m_view = _view; m_view = _view;
bgfx::setViewSeq(_view, true); bgfx::setViewSeq(_view, true);
bgfx::setViewRect(_view, 0, 0, _width, _height); bgfx::setViewRect(_view, 0, 0, _width, _height);
@ -378,9 +383,10 @@ struct Imgui
void endFrame() void endFrame()
{ {
clearInput(); clearInput();
nvgEndFrame(m_nvg);
} }
bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, NVGcontext* _nvg) bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll)
{ {
m_areaId++; m_areaId++;
m_widgetId = 0; m_widgetId = 0;
@ -419,16 +425,12 @@ struct Imgui
, imguiRGBA(255, 255, 255, 128) , imguiRGBA(255, 255, 255, 128)
); );
if (NULL != _nvg) nvgScissor(m_nvg
{ , float(_x + SCROLL_AREA_PADDING)
m_nvg = _nvg; , float(_y + SCROLL_AREA_PADDING)
nvgScissor(m_nvg , float(_width - SCROLL_AREA_PADDING * 4)
, float(_x + SCROLL_AREA_PADDING) , float(_height - AREA_HEADER - SCROLL_AREA_PADDING)
, float(_y + SCROLL_AREA_PADDING) );
, float(_width - SCROLL_AREA_PADDING * 4)
, float(_height - AREA_HEADER - SCROLL_AREA_PADDING)
);
}
m_scissor = bgfx::setScissor(uint16_t(_x + SCROLL_AREA_PADDING) m_scissor = bgfx::setScissor(uint16_t(_x + SCROLL_AREA_PADDING)
, uint16_t(_y + SCROLL_AREA_PADDING) , uint16_t(_y + SCROLL_AREA_PADDING)
@ -443,11 +445,7 @@ struct Imgui
{ {
// Disable scissoring. // Disable scissoring.
m_scissor = UINT16_MAX; m_scissor = UINT16_MAX;
if (NULL != m_nvg) nvgResetScissor(m_nvg);
{
nvgResetScissor(m_nvg);
m_nvg = NULL;
}
// Draw scroll bar // Draw scroll bar
int32_t xx = m_scrollRight + SCROLL_AREA_PADDING / 2; int32_t xx = m_scrollRight + SCROLL_AREA_PADDING / 2;
@ -1881,9 +1879,9 @@ void imguiEndFrame()
s_imgui.endFrame(); s_imgui.endFrame();
} }
bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, NVGcontext* _nvg) bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll)
{ {
return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _nvg); return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll);
} }
void imguiEndScrollArea() void imguiEndScrollArea()

View File

@ -57,7 +57,7 @@ void imguiDestroy();
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31); void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31);
void imguiEndFrame(); void imguiEndFrame();
bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, struct NVGcontext* _nvg = NULL); bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll);
void imguiEndScrollArea(); void imguiEndScrollArea();
void imguiIndent(); void imguiIndent();