This commit is contained in:
Branimir Karadžić 2015-01-18 12:58:56 -08:00
parent 9e34736c49
commit 8cd9ecfd18

View file

@ -21,9 +21,6 @@ static uint8_t s_viewId;
static void imguiRender(ImDrawList** const cmd_lists, int cmd_lists_count) static void imguiRender(ImDrawList** const cmd_lists, int cmd_lists_count)
{ {
(void)cmd_lists;
(void)cmd_lists_count;
const float width = ImGui::GetIO().DisplaySize.x; const float width = ImGui::GetIO().DisplaySize.x;
const float height = ImGui::GetIO().DisplaySize.y; const float height = ImGui::GetIO().DisplaySize.y;
@ -33,7 +30,6 @@ static void imguiRender(ImDrawList** const cmd_lists, int cmd_lists_count)
bgfx::setViewTransform(0, NULL, ortho); bgfx::setViewTransform(0, NULL, ortho);
// Render command lists // Render command lists
for (int n = 0; n < cmd_lists_count; n++) for (int n = 0; n < cmd_lists_count; n++)
{ {
bgfx::TransientVertexBuffer tvb; bgfx::TransientVertexBuffer tvb;
@ -42,12 +38,19 @@ static void imguiRender(ImDrawList** const cmd_lists, int cmd_lists_count)
const ImDrawList* cmd_list = cmd_lists[n]; const ImDrawList* cmd_list = cmd_lists[n];
const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin(); const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin();
(void)vtx_buffer;
const ImDrawCmd* pcmd_end_t = cmd_list->commands.end(); const ImDrawCmd* pcmd_begin = cmd_list->commands.begin();
const ImDrawCmd* pcmd_end = cmd_list->commands.end();
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end_t; pcmd++) for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
{
vtx_size += (uint32_t)pcmd->vtx_count; vtx_size += (uint32_t)pcmd->vtx_count;
}
if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, s_vertexDecl) )
{
// not enough space in transient buffer just quit drawing the rest...
break;
}
bgfx::allocTransientVertexBuffer(&tvb, vtx_size, s_vertexDecl); bgfx::allocTransientVertexBuffer(&tvb, vtx_size, s_vertexDecl);
@ -56,8 +59,7 @@ static void imguiRender(ImDrawList** const cmd_lists, int cmd_lists_count)
memcpy(verts, vtx_buffer, vtx_size * sizeof(ImDrawVert) ); memcpy(verts, vtx_buffer, vtx_size * sizeof(ImDrawVert) );
uint32_t vtx_offset = 0; uint32_t vtx_offset = 0;
const ImDrawCmd* pcmd_end = cmd_list->commands.end(); for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++)
{ {
bgfx::setState(0 bgfx::setState(0
| BGFX_STATE_RGB_WRITE | BGFX_STATE_RGB_WRITE
@ -85,32 +87,32 @@ void IMGUI_setup(int _width, int _height, uint8_t _viewId)
io.DeltaTime = 1.0f / 60.0f; io.DeltaTime = 1.0f / 60.0f;
io.PixelCenterOffset = 0.0f; io.PixelCenterOffset = 0.0f;
const bgfx::Memory* vs_imgui2; const bgfx::Memory* vsmem;
const bgfx::Memory* fs_imgui2; const bgfx::Memory* fsmem;
switch (bgfx::getRendererType() ) switch (bgfx::getRendererType() )
{ {
case bgfx::RendererType::Direct3D9: case bgfx::RendererType::Direct3D9:
vs_imgui2 = bgfx::makeRef(vs_ocornut_imgui_dx9, sizeof(vs_ocornut_imgui_dx9)); vsmem = bgfx::makeRef(vs_ocornut_imgui_dx9, sizeof(vs_ocornut_imgui_dx9) );
fs_imgui2 = bgfx::makeRef(fs_ocornut_imgui_dx9, sizeof(fs_ocornut_imgui_dx9)); fsmem = bgfx::makeRef(fs_ocornut_imgui_dx9, sizeof(fs_ocornut_imgui_dx9) );
break; break;
case bgfx::RendererType::Direct3D11: case bgfx::RendererType::Direct3D11:
vs_imgui2 = bgfx::makeRef(vs_ocornut_imgui_dx11, sizeof(vs_ocornut_imgui_dx11)); vsmem = bgfx::makeRef(vs_ocornut_imgui_dx11, sizeof(vs_ocornut_imgui_dx11) );
fs_imgui2 = bgfx::makeRef(fs_ocornut_imgui_dx11, sizeof(fs_ocornut_imgui_dx11)); fsmem = bgfx::makeRef(fs_ocornut_imgui_dx11, sizeof(fs_ocornut_imgui_dx11) );
break; break;
default: default:
vs_imgui2 = bgfx::makeRef(vs_ocornut_imgui_glsl, sizeof(vs_ocornut_imgui_glsl)); vsmem = bgfx::makeRef(vs_ocornut_imgui_glsl, sizeof(vs_ocornut_imgui_glsl) );
fs_imgui2 = bgfx::makeRef(fs_ocornut_imgui_glsl, sizeof(fs_ocornut_imgui_glsl)); fsmem = bgfx::makeRef(fs_ocornut_imgui_glsl, sizeof(fs_ocornut_imgui_glsl) );
break; break;
} }
bgfx::ShaderHandle vsh; bgfx::ShaderHandle vsh;
bgfx::ShaderHandle fsh; bgfx::ShaderHandle fsh;
vsh = bgfx::createShader(vs_imgui2); vsh = bgfx::createShader(vsmem);
fsh = bgfx::createShader(fs_imgui2); fsh = bgfx::createShader(fsmem);
s_imguiProgram = bgfx::createProgram(vsh, fsh); s_imguiProgram = bgfx::createProgram(vsh, fsh);
bgfx::destroyShader(vsh); bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh); bgfx::destroyShader(fsh);
@ -126,8 +128,8 @@ void IMGUI_setup(int _width, int _height, uint8_t _viewId)
s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Uniform1i); s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Uniform1i);
ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
int tex_x, tex_y, pitch, tex_comp;
int tex_x, tex_y, pitch, tex_comp;
void* tex_data = stbi_load_from_memory( (const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); void* tex_data = stbi_load_from_memory( (const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
pitch = tex_x * 4; pitch = tex_x * 4;
@ -135,7 +137,13 @@ void IMGUI_setup(int _width, int _height, uint8_t _viewId)
const bgfx::Memory* mem = bgfx::alloc( (uint32_t)(tex_y * pitch) ); const bgfx::Memory* mem = bgfx::alloc( (uint32_t)(tex_y * pitch) );
memcpy(mem->data, tex_data, size_t(pitch * tex_y) ); memcpy(mem->data, tex_data, size_t(pitch * tex_y) );
s_textureId = bgfx::createTexture2D((uint16_t)tex_x, (uint16_t)tex_y, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT, mem); s_textureId = bgfx::createTexture2D( (uint16_t)tex_x
, (uint16_t)tex_y
, 1
, bgfx::TextureFormat::BGRA8
, BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT
, mem
);
stbi_image_free(tex_data); stbi_image_free(tex_data);