diff options
author | 2015-05-27 12:07:35 +0200 | |
---|---|---|
committer | 2015-05-27 12:07:35 +0200 | |
commit | a163b2827775c215703723e0e3ab94aab63d359f (patch) | |
tree | 52e04089b7d0d954d646be0e9536486a7ea33827 | |
parent | 08bfa598dfc7b27942f41a6df63b78d233a1abd5 (diff) |
Update BGFX (nw)
81 files changed, 8111 insertions, 3994 deletions
diff --git a/3rdparty/bgfx/3rdparty/.editorconfig b/3rdparty/bgfx/3rdparty/.editorconfig new file mode 100644 index 00000000000..6bca1a7a2cf --- /dev/null +++ b/3rdparty/bgfx/3rdparty/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[ocornut-imgui/*] +indent_style = space +indent_size = 4 diff --git a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp index ee85b44bb8b..c7931fab7a4 100644 --- a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp +++ b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp @@ -172,7 +172,8 @@ es_lod_exists_in_stage(const _mesa_glsl_parse_state *state) * is enabled. */ return - state->stage == MESA_SHADER_FRAGMENT && +// BK - EXT_shader_texture_lod is available in vertex and fragment shaders. +// state->stage == MESA_SHADER_FRAGMENT && state->es_shader && state->is_version(110, 100) && state->EXT_shader_texture_lod_enable; diff --git a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp index e52ac1c988e..91beeb0ac0b 100644 --- a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp +++ b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp @@ -949,6 +949,13 @@ builtin_variable_generator::generate_fs_special_vars() var->enable_extension_warning("GL_EXT_shader_framebuffer_fetch"); } + { + // BK - gl_PrimitiveID + ir_variable *var; + var = add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID", glsl_precision_high); + var->data.interpolation = INTERP_QUALIFIER_FLAT; + } + if (state->ARB_sample_shading_enable) { add_system_value(SYSTEM_VALUE_SAMPLE_ID, int_t, "gl_SampleID", glsl_precision_high); add_system_value(SYSTEM_VALUE_SAMPLE_POS, vec2_t, "gl_SamplePosition", glsl_precision_high); diff --git a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp index 8e2569e42d9..d7628eed793 100644 --- a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp +++ b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp @@ -160,7 +160,7 @@ public: int uses_texlodproj_impl; // 3 bits per tex_dimension, bit set for each precision if any texture sampler needs the GLES2 lod workaround. }; -static void print_texlod_workarounds(int usage_bitfield, int usage_proj_bitfield, string_buffer &str) +void print_texlod_workarounds(int usage_bitfield, int usage_proj_bitfield, string_buffer &str) { static const char *precStrings[3] = {"lowp", "mediump", "highp"}; static const char *precNameStrings[3] = { "low_", "medium_", "high_" }; @@ -283,7 +283,9 @@ _mesa_print_ir_glsl(exec_list *instructions, delete ls; +#if 0 // BK - disable LOD workarounds. print_texlod_workarounds(uses_texlod_impl, uses_texlodproj_impl, str); +#endif // 0 // Add the optimized glsl code str.asprintf_append("%s", body.c_str()); @@ -821,7 +823,8 @@ void ir_print_glsl_visitor::visit(ir_texture *ir) sampler_uv_dim += 1; const bool is_proj = (uv_dim > sampler_uv_dim); const bool is_lod = (ir->op == ir_txl); - + +#if 0 // BK - disable LOD workarounds. if (is_lod && state->es_shader && state->language_version < 300 && state->stage == MESA_SHADER_FRAGMENT) { // Special workaround for GLES 2.0 LOD samplers to prevent a lot of debug spew. @@ -850,8 +853,8 @@ void ir_print_glsl_visitor::visit(ir_texture *ir) else uses_texlod_impl |= (1 << position); } +#endif // 0 - // texture function name //ACS: shadow lookups and lookups with dimensionality included in the name were deprecated in 130 if(state->language_version<130) diff --git a/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h b/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h index b544f550d92..17cad4a4b43 100644 --- a/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h +++ b/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h @@ -19,8 +19,6 @@ //#define IMGUI_API __declspec( dllimport ) //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions) -#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS -#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS #define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION #define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION @@ -30,7 +28,17 @@ //---- Include imgui_user.h at the end of imgui.h //#define IMGUI_INCLUDE_IMGUI_USER_H -//---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. +//---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions) +#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS +#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS + +//---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty) +//#define IMGUI_DISABLE_TEST_WINDOWS + +//---- Implement STB libraries in a namespace to avoid conflicts +//#define IMGUI_STB_NAMESPACE ImStb + +//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. /* #define IM_VEC2_CLASS_EXTRA \ ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ diff --git a/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp b/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp index fbec9b3901e..0971cf8950c 100644 --- a/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp +++ b/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp @@ -1,8 +1,8 @@ -// ImGui library v1.35 +// ImGui library v1.39 WIP // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui -// Developed by Omar Cornut and contributors. +// Developed by Omar Cornut and ImGui contributors. /* @@ -11,13 +11,19 @@ - END-USER GUIDE - PROGRAMMER GUIDE (read me!) - API BREAKING CHANGES (read me when you update!) - - FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING (read me!) + - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS + - How do I update to a newer version of ImGui? + - Can I have multiple widgets with the same label? (Yes) + - Why is my text output blurry? + - How can I load a different font than the default? + - How can I load multiple fonts? + - How can I display and input Chinese, Japanese, Korean characters? - ISSUES & TODO-LIST - CODE - SAMPLE CODE - FONT DATA - + MISSION STATEMENT ================= @@ -34,7 +40,7 @@ Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes: - doesn't look fancy, doesn't animate - limited layout features, intricate layouts are typically crafted in code - - occasionally uses statically sized buffers for string manipulations - won't crash, but some long text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction. + - occasionally uses statically sized buffers for string manipulations - won't crash, but some very long pieces of text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction. END-USER GUIDE @@ -66,16 +72,17 @@ - read the FAQ below this section! - your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention on your side, no state duplication, less sync, less bugs. - call and read ImGui::ShowTestWindow() for sample code demonstrating most features. - - see examples/ folder for standalone sample applications. - - customization: use the style editor or PushStyleColor/PushStyleVar to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme). + - see examples/ folder for standalone sample applications. e.g. examples/opengl_example/ + - customization: PushStyleColor()/PushStyleVar() or the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme). - getting started: - - initialisation: call ImGui::GetIO() and fill the 'Settings' data. - - every frame: + - initialisation: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the 'Settings' data. + - every frame: 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame(). 2/ use any ImGui function you want between NewFrame() and Render() 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure. - - all rendering information are stored into command-lists until ImGui::Render() is called. + - all rendering information are stored into command-lists until ImGui::Render() is called. + - ImGui never touches or know about your GPU state. the only function that knows about GPU is the RenderDrawListFn handler that you must provide. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations. - refer to the examples applications in the examples/ folder for instruction on how to setup your code. - a typical application skeleton may be: @@ -92,7 +99,7 @@ unsigned char* pixels; int width, height, bytes_per_pixels; io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height, &bytes_per_pixels); - // TODO: copy texture to graphics memory. + // TODO: copy texture to graphics memory. // TODO: store your texture pointer/identifier in 'io.Fonts->TexID' // Application main loop @@ -100,7 +107,7 @@ { // 1) get low-level input // e.g. on Win32, GetKeyboardState(), or poll your events, etc. - + // 2) TODO: fill all fields of IO structure and call NewFrame ImGuiIO& io = ImGui::GetIO(); io.MousePos = mouse_pos; @@ -120,7 +127,7 @@ // swap video buffer, etc. } - - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui + - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui wants to use your inputs. if it does you can discard/hide the inputs from the rest of your application. API BREAKING CHANGES @@ -128,9 +135,17 @@ Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. - + + - 2015/05/03 (1.39) - removed style.AutoFitPadding, using style.WindowPadding makes more sense (the default values were already the same). + - 2015/04/13 (1.38) - renamed IsClipped() to IsRectClipped(). Kept inline redirection function (will obsolete). + - 2015/04/09 (1.38) - renamed ImDrawList::AddArc() to ImDrawList::AddArcFast() for compatibility with future API + - 2015/04/03 (1.38) - removed ImGuiCol_CheckHovered, ImGuiCol_CheckActive, replaced with the more general ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive. + - 2014/04/03 (1.38) - removed support for passing -FLT_MAX..+FLT_MAX as the range for a SliderFloat(). Use DragFloat() or Inputfloat() instead. + - 2015/03/17 (1.36) - renamed GetItemRectMin()/GetItemRectMax()/IsMouseHoveringBox() to GetItemRectMin()/GetItemRectMax()/IsMouseHoveringRect(). Kept inline redirection function (will obsolete). + - 2015/03/15 (1.36) - renamed style.TreeNodeSpacing to style.IndentSpacing, ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing + - 2015/03/13 (1.36) - renamed GetWindowIsFocused() to IsWindowFocused(). Kept inline redirection function (will obsolete). - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth - - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond), kept inline redirection function. + - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond). Kept inline redirection function (will obsolete). - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once. - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now. - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior @@ -168,22 +183,39 @@ - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes - FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING - ================================================== - - If text or lines are blurry when integrating ImGui in your engine: - - - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) + FREQUENTLY ASKED QUESTIONS (FAQ), TIPS + ====================================== - A primer on the meaning and use of ID in ImGui: + Q: How do I update to a newer version of ImGui? + A: Overwrite the following files: + imgui.cpp + imgui.h + stb_rect_pack.h + stb_textedit.h + stb_truetype.h + Check the "API BREAKING CHANGES" sections for a list of occasional API breaking changes. If you have a problem with a function, search for its name + in the code, there will likely be a comment about it. Please report any issue to the GitHub page! - - widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget). + Q: Can I have multiple widgets with the same label? + A: Yes. A primer on the use of labels/IDs in ImGui.. + + - Interactive widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget). to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer. - + Button("OK"); // Label = "OK", ID = hash of "OK" Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel" - - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows. + - Elements that are not clickable, such as Text() items don't need an ID. + + - ID are uniquely scoped within windows, tree nodes, etc. so no conflict can happen if you have two buttons called "OK" in two different windows + or in two different locations of a tree. + + - if you have a same ID twice in the same location, you'll have a conflict: + + Button("OK"); + Button("OK"); // ID collision! Both buttons will be treated as the same. + + Fear not! this is easy to solve and there are many ways to solve it! - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases. use "##" to pass a complement to the ID that won't be visible to the end-user: @@ -191,48 +223,85 @@ Button("Play##0"); // Label = "Play", ID = hash of "Play##0" Button("Play##1"); // Label = "Play", ID = hash of "Play##1" (different from above) - use "###" to pass a label that isn't part of ID. You can use that to change labels while preserving a constant ID. + - occasionally (rarely) you might want change a label while preserving a constant ID. This allows you to animate labels. + use "###" to pass a label that isn't part of ID: Button("Hello###ID"; // Label = "Hello", ID = hash of "ID" Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above) - - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window: + - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window. + this is the most convenient way of distinguish ID if you are iterating and creating many UI elements. + you can push a pointer, a string or an integer value. remember that ID are formed from the addition of everything in the ID stack! - Button("Click"); // Label = "Click", ID = hash of "Click" - PushID("node"); - Button("Click"); // Label = "Click", ID = hash of "node" and "Click" for (int i = 0; i < 100; i++) { - PushID(i); - Button("Click"); // Label = "Click", ID = hash of "node" and i and "label" - PopID(); + PushID(i); + Button("Click"); // Label = "Click", ID = hash of integer + "label" (unique) + PopID(); } - PopID(); - PushID(my_ptr); - Button("Click"); // Label = "Click", ID = hash of ptr and "Click" + + for (int i = 0; i < 100; i++) + { + MyObject* obj = Objects[i]; + PushID(obj); + Button("Click"); // Label = "Click", ID = hash of pointer + "label" (unique) + PopID(); + } + + for (int i = 0; i < 100; i++) + { + MyObject* obj = Objects[i]; + PushID(obj->Name); + Button("Click"); // Label = "Click", ID = hash of string + "label" (unique) + PopID(); + } + + - more example showing that you can stack multiple prefixes into the ID stack: + + Button("Click"); // Label = "Click", ID = hash of "Click" + PushID("node"); + Button("Click"); // Label = "Click", ID = hash of "node" + "Click" + PushID(my_ptr); + Button("Click"); // Label = "Click", ID = hash of "node" + ptr + "Click" + PopID(); PopID(); - so if you have a loop creating multiple items, you can use PushID() / PopID() with the index of each item, or their pointer, etc. - some functions like TreeNode() implicitly creates a scope for you by calling PushID(). + - tree nodes implicitly creates a scope for you by calling PushID(). - - when working with trees, ID are used to preserve the opened/closed state of tree nodes. - depending on your use cases you may want to use strings, indices or pointers as ID. + Button("Click"); // Label = "Click", ID = hash of "Click" + if (TreeNode("node")) + { + Button("Click"); // Label = "Click", ID = hash of "node" + "Click" + TreePop(); + } + + - when working with trees, ID are used to preserve the opened/closed state of each tree node. + depending on your use cases you may want to use strings, indices or pointers as ID. e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change. e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense! - If you want to load a different font than the default (ProggyClean.ttf, size 13) + Q: Why is my text output blurry? + A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) + + Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13) + A: Use the font atlas to load the TTF file you want: io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() - If you want to load multiple fonts, use the font atlas to pack them into a single texture! + Q: How can I load multiple fonts? + A: Use the font atlas to pack them into a single texture: ImFont* font0 = io.Fonts->AddFontDefault(); ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels); io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() + // the first loaded font gets used by default + // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime - If you want to display Chinese, Japanese, Korean characters, pass custom Unicode ranges when loading a font: + Q: How can I render and input Chinese, Japanese, Korean characters? + A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board. + Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() @@ -248,39 +317,41 @@ ISSUES & TODO-LIST ================== - - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers + - misc: merge or clarify ImVec4 vs ImRect? - window: add horizontal scroll - window: fix resize grip rendering scaling along with Rounding style setting - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit? - - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. + - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - window: allow resizing of child windows (possibly given min/max for each axis?) - window: background options for child windows, border option (disable rounding) - window: resizing from any sides? + mouse cursor directives for app. - - widgets: clicking on widget b while widget a should activate widget b (doesn't anymore because of hover capture) - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. - - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay + - widgets: clean up widgets internal toward exposing everything. - main: considering adding EndFrame()/Init(). some constructs are awkward in the implementation because of the lack of them. - - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? -!- input number: very large int not reliably supported because of int<>float conversions. + - input text: add ImGuiInputTextFlags_EnterToApply? (off github issue #218) +!- input number: large int not reliably supported because of int<>float conversions. - input number: optional range min/max for Input*() functions - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) - input number: use mouse wheel to step up/down - input number: non-decimal input. + - text: proper alignment options - layout: horizontal layout helper (github issue #97) - layout: more generic alignment state (left/right/centered) for single items? - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. - - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) - - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) - - columns: columns header to act as button (~sort op) and allow resize/reorder - - columns: user specify columns size - - columns: tree node example, removing the last NextColumn() makes a padding difference (it should not) + - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (github issue #125) + - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) (github issue #125) + - columns: columns header to act as button (~sort op) and allow resize/reorder (github issue #125) + - columns: user specify columns size (github issue #125) + - popup: border options. richer api like BeginChild() perhaps? (github issue #197) + - combo: sparse combo boxes (via function call?) - combo: turn child handling code into pop up helper - combo: contents should extends to fit label if combo widget is small + - combo/listbox: keyboard control. need inputtext like non-active focus + key handling. considering keybord for custom listbox (see github pr #203) - listbox: multiple selection - listbox: user may want to initial scroll to focus on the one selected value? - ! menubar, menus + ! menubar, menus (github issue #126) - tabs - gauge: various forms of gauge/loading bars widgets - color: better color editor. @@ -289,22 +360,24 @@ - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID) - file selection widget -> build the tool in our codebase to improve model-dialog idioms - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space. same as scrollbar. + - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). + - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate. - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now. - text edit: centered text for slider as input text so it matches typical positioning. - - text edit: flag to disable live update of the user buffer. + - text edit: flag to disable live update of the user buffer. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text? - text edit: add multi-line text edit - tree: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings - settings: write more decent code to allow saving/loading new fields - - settings: api for per-tool simple persistent data (bool,int,float) in .ini file + - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost. - - style: checkbox: padding for "active" color should be a multiplier of the + - style: checkbox: padding for "active" color should be a multiplier of the - style: colorbox not always square? - text: simple markup language for color change? - log: LogButtons() options for specifying depth and/or hiding depth slider - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) - - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu? + - log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard) + - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs. - filters: set a current filter that tree node can automatically query to hide themselves - filters: handle wildcards (with implicit leading/trailing *), regexps - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus) @@ -312,18 +385,16 @@ - keyboard: full keyboard navigation and focus. - input: rework IO to be able to pass actual events to fix temporal aliasing issues. - input: support track pad style scrolling & slider edit. - - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen). - portability: big-endian test/support (github issue #81) - misc: mark printf compiler attributes on relevant functions - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL) - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? - style editor: color child window height expressed in multiple of line height. - - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui) + - optimization/render: use indexed rendering to reduce vertex data cost (e.g. for remote/networked imgui) - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)? - optimization: turn some the various stack vectors into statically-sized arrays - optimization: better clipping for multi-component widgets - - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?) */ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) @@ -331,14 +402,17 @@ #endif #include "imgui.h" -#include <ctype.h> // toupper -#include <math.h> // sqrtf -#include <stdint.h> // intptr_t -#include <stdio.h> // vsnprintf +#include <ctype.h> // toupper, isprint +#include <math.h> // sqrtf, fabsf, fmodf, powf, cosf, sinf, floorf, ceilf +#include <stdio.h> // vsnprintf, sscanf #include <new> // new (ptr) +#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier +#include <stddef.h> // intptr_t +#else +#include <stdint.h> // intptr_t +#endif #ifdef _MSC_VER -#pragma warning (disable: 4100) // unreferenced formal parameter #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif @@ -350,13 +424,11 @@ #pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code. #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. -#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // -#pragma clang diagnostic ignored "-Wunused-parameter" // warning: unused parameter ‘xxxx’ -#elif defined(__GNUC__) +#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // +#pragma clang diagnostic ignored "-Wmissing-noreturn" // warning : function xx could be declared with attribute 'noreturn' warning // GetDefaultFontData() asserts which some implementation makes it never return. +#endif +#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used -#pragma GCC diagnostic ignored "-Wunused-parameter" // warning: unused parameter ‘xxxx’ -#pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // warning: ‘xxxx’ may be used uninitialized in this function #endif //------------------------------------------------------------------------- @@ -398,6 +470,8 @@ namespace IMGUI_STB_NAMESPACE #endif #include "stb_truetype.h" +#undef STB_TEXTEDIT_STRING +#undef STB_TEXTEDIT_CHARTYPE #define STB_TEXTEDIT_STRING ImGuiTextEditState #define STB_TEXTEDIT_CHARTYPE ImWchar #include "stb_textedit.h" @@ -415,32 +489,34 @@ using namespace IMGUI_STB_NAMESPACE; // Forward Declarations //------------------------------------------------------------------------- +struct ImRect; struct ImGuiColMod; struct ImGuiStyleMod; -struct ImGuiAabb; struct ImGuiDrawContext; struct ImGuiTextEditState; struct ImGuiIniData; struct ImGuiState; struct ImGuiWindow; +typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_ -static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false); +static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags = 0); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); -static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max); +static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& pos_max, const ImVec2* clip_max = NULL, ImGuiAlign align = ImGuiAlign_Default); static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); +static void RenderCheckMark(ImVec2 pos, ImU32 col); static void SetFont(ImFont* font); -static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id); -static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); -static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset = NULL); +static bool ItemAdd(const ImRect& bb, const ImGuiID* id); +static void ItemSize(ImVec2 size, float text_offset_y = 0.0f); +static void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); static void PushColumnClipRect(int column_index = -1); -static bool IsClipped(const ImGuiAabb& bb); +static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged); -static bool IsMouseHoveringBox(const ImGuiAabb& bb); +static bool IsMouseHoveringRect(const ImRect& bb); static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); static void Scrollbar(ImGuiWindow* window); @@ -480,17 +556,6 @@ static void SetClipboardTextFn_DefaultImpl(const char* text); static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y); //----------------------------------------------------------------------------- -// Texture Atlas data -//----------------------------------------------------------------------------- - -// Technically we should use the rect pack API for that, but it's just simpler to hard-core the positions for now. -// As we start using more of the texture atlas (for rounded corners) we can change that. -static const ImVec2 TEX_ATLAS_SIZE(32, 32); -static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_BLACK(1, 3); -static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_WHITE(14, 3); -static const ImVec2 TEX_ATLAS_SIZE_MOUSE_CURSOR(12, 19); - -//----------------------------------------------------------------------------- // User facing structures //----------------------------------------------------------------------------- @@ -500,25 +565,30 @@ ImGuiStyle::ImGuiStyle() WindowPadding = ImVec2(8,8); // Padding within a window WindowMinSize = ImVec2(32,32); // Minimum window size WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + WindowTitleAlign = ImGuiAlign_Left; // Alignment for title bar text ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets) FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets). ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) - TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! - AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) + TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() - TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node + IndentSpacing = 22.0f; // Horizontal spacing when e.g. entering a tree node ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns ScrollbarWidth = 16.0f; // Width of the vertical scrollbar - GrabMinSize = 10.0f; // Minimum width/height of a slider or scrollbar grab + ScrollbarRounding = 0.0f; // Radius of grab corners rounding for scrollbar + GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar + DisplayWindowPadding = ImVec2(22,22); // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows. + DisplaySafeAreaPadding = ImVec2(4,4); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f); Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f); Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input + Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.90f, 0.80f, 0.80f, 0.40f); + Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.65f, 0.65f, 0.45f); Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f); Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f); Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f); @@ -526,8 +596,6 @@ ImGuiStyle::ImGuiStyle() Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); - Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); - Colors[ImGuiCol_CheckActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f); Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); @@ -537,9 +605,9 @@ ImGuiStyle::ImGuiStyle() Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f); Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f); Colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f); - Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f); - Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); + Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + Colors[ImGuiCol_ColumnHovered] = ImVec4(0.70f, 0.60f, 0.60f, 1.00f); + Colors[ImGuiCol_ColumnActive] = ImVec4(0.90f, 0.70f, 0.70f, 1.00f); Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f); @@ -574,6 +642,7 @@ ImGuiIO::ImGuiIO() MousePosPrev = ImVec2(-1,-1); MouseDoubleClickTime = 0.30f; MouseDoubleClickMaxDist = 6.0f; + MouseDragThreshold = 6.0f; UserData = NULL; // User functions @@ -608,9 +677,11 @@ void ImGuiIO::AddInputCharacter(ImWchar c) const float PI = 3.14159265358979323846f; #ifdef INT_MAX -#define IM_INT_MAX INT_MAX +#define IM_INT_MIN INT_MIN +#define IM_INT_MAX INT_MAX #else -#define IM_INT_MAX 2147483647 +#define IM_INT_MIN (-2147483647-1) +#define IM_INT_MAX (2147483647) #endif // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n. @@ -700,30 +771,30 @@ static const char* ImStristr(const char* haystack, const char* needle, const cha // Pass data_size==0 for zero-terminated string // Try to replace with FNV1a hash? -static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0) -{ +static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0) +{ static ImU32 crc32_lut[256] = { 0 }; if (!crc32_lut[1]) { const ImU32 polynomial = 0xEDB88320; - for (ImU32 i = 0; i < 256; i++) - { - ImU32 crc = i; - for (ImU32 j = 0; j < 8; j++) - crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial); - crc32_lut[i] = crc; + for (ImU32 i = 0; i < 256; i++) + { + ImU32 crc = i; + for (ImU32 j = 0; j < 8; j++) + crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial); + crc32_lut[i] = crc; } } seed = ~seed; - ImU32 crc = seed; + ImU32 crc = seed; const unsigned char* current = (const unsigned char*)data; if (data_size > 0) { // Known size - while (data_size--) - crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + while (data_size--) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; } else { @@ -732,7 +803,7 @@ static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0) { // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed. // Because this syntax is rarely used we are optimizing for the common case. - // - If we reach ### in the string we discard the hash so far and reset to the seed. + // - If we reach ### in the string we discard the hash so far and reset to the seed. // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller. if (c == '#' && current[0] == '#' && current[1] == '#') crc = seed; @@ -740,8 +811,8 @@ static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0) crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; } } - return ~crc; -} + return ~crc; +} static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) { @@ -794,7 +865,7 @@ void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593 // also http://en.wikipedia.org/wiki/HSL_and_HSV void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b) -{ +{ if (s == 0.0f) { // gray @@ -825,7 +896,6 @@ void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes) { IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size); - IM_ASSERT(padding_bytes >= 0); *out_file_data = NULL; *out_file_size = 0; @@ -865,6 +935,13 @@ static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, //----------------------------------------------------------------------------- +enum ImGuiButtonFlags_ +{ + ImGuiButtonFlags_Repeat = (1 << 0), + ImGuiButtonFlags_PressedOnClick = (1 << 1), + ImGuiButtonFlags_FlattenChilds = (1 << 2) +}; + struct ImGuiColMod // Color modifier, backup of modified data so we can restore it { ImGuiCol Col; @@ -877,31 +954,54 @@ struct ImGuiStyleMod // Style modifier, backup of modified data so we can res ImVec2 PreviousValue; }; -struct ImGuiAabb // 2D axis aligned bounding-box +struct ImRect // 2D axis aligned bounding-box { ImVec2 Min; ImVec2 Max; - ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); } - ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; } - ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; } - ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; } - - ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; } - ImVec2 GetSize() const { return Max-Min; } - float GetWidth() const { return (Max-Min).x; } - float GetHeight() const { return (Max-Min).y; } - ImVec2 GetTL() const { return Min; } - ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); } - ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); } - ImVec2 GetBR() const { return Max; } - bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; } - bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; } - bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; } - void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); } - void Add(const ImGuiAabb& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); } - void Expand(const ImVec2& sz) { Min -= sz; Max += sz; } - void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); } + ImRect() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); } + ImRect(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; } + ImRect(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; } + ImRect(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; } + + ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; } + ImVec2 GetSize() const { return Max-Min; } + float GetWidth() const { return (Max-Min).x; } + float GetHeight() const { return (Max-Min).y; } + ImVec2 GetTL() const { return Min; } + ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); } + ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); } + ImVec2 GetBR() const { return Max; } + bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; } + bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x < Max.x && r.Max.y < Max.y; } + bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; } + void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); } + void Add(const ImRect& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); } + void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } + void Expand(const ImVec2& amount) { Min -= amount; Max += amount; } + void Reduce(const ImVec2& amount) { Min += amount; Max -= amount; } + void Clip(const ImRect& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); } + ImVec2 GetClosestPoint(ImVec2 p, bool on_edge) const + { + if (!on_edge && Contains(p)) + return p; + if (p.x > Max.x) p.x = Max.x; + else if (p.x < Min.x) p.x = Min.x; + if (p.y > Max.y) p.y = Max.y; + else if (p.y < Min.y) p.y = Min.y; + return p; + } +}; +typedef ImRect ImGuiAabb; // FIXME-OBSOLETE + +struct ImGuiGroupData +{ + ImVec2 BackupCursorPos; + ImVec2 BackupCursorMaxPos; + float BackupColumnsStartX; + float BackupCurrentLineHeight; + float BackupCurrentLineTextBaseOffset; + float BackupLogLinePosY; }; // Temporary per-window data, reset at the beginning of the frame @@ -910,21 +1010,27 @@ struct ImGuiDrawContext ImVec2 CursorPos; ImVec2 CursorPosPrevLine; ImVec2 CursorStartPos; + ImVec2 CursorMaxPos; // Implicitly calculate the size of our contents, always extending. Saved into window->SizeContents at the end of the frame float CurrentLineHeight; + float CurrentLineTextBaseOffset; float PrevLineHeight; - float LogLineHeight; + float PrevLineTextBaseOffset; + float LogLinePosY; int TreeDepth; ImGuiID LastItemID; - ImGuiAabb LastItemAabb; - bool LastItemHovered; + ImRect LastItemRect; + bool LastItemHoveredAndUsable; + bool LastItemHoveredRect; ImVector<ImGuiWindow*> ChildWindows; ImVector<bool> AllowKeyboardFocus; ImVector<float> ItemWidth; // 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window ImVector<float> TextWrapPos; + ImVector<ImGuiGroupData> GroupStack; ImGuiColorEditMode ColorEditMode; ImGuiStorage* StateStorage; + int StackSizesBackup[5]; // store size of various stacks for asserting - float ColumnsStartX; // Start position from left of window (increased by TreePush/TreePop, etc.) + float ColumnsStartX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. int ColumnsCurrent; int ColumnsCount; @@ -937,14 +1043,17 @@ struct ImGuiDrawContext ImGuiDrawContext() { - CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f); + CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); CurrentLineHeight = PrevLineHeight = 0.0f; - LogLineHeight = -1.0f; + CurrentLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; + LogLinePosY = -1.0f; TreeDepth = 0; LastItemID = 0; - LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f); - LastItemHovered = false; + LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f); + LastItemHoveredAndUsable = LastItemHoveredRect = false; + ColorEditMode = ImGuiColorEditMode_RGB; StateStorage = NULL; + memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); ColumnsStartX = 0.0f; ColumnsOffsetX = 0.0f; @@ -962,8 +1071,8 @@ struct ImGuiTextEditState { ImGuiID Id; // widget id owning the text state ImWchar Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. - char InitialText[1024*4+1]; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) - int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. + char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) + size_t CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. size_t BufSizeA; // end-user buffer size, <= 1024 (or increase above) float Width; // widget width float ScrollX; @@ -1004,6 +1113,15 @@ struct ImGuiIniData ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } } }; +struct ImGuiMouseCursorData +{ + ImGuiMouseCursor Type; + ImVec2 Offset; + ImVec2 Size; + ImVec2 TexUvMin[2]; + ImVec2 TexUvMax[2]; +}; + // Main state for ImGui struct ImGuiState { @@ -1011,26 +1129,31 @@ struct ImGuiState ImGuiIO IO; ImGuiStyle Style; ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() - float FontSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. + float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize() + float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite float Time; int FrameCount; int FrameCountRendered; ImVector<ImGuiWindow*> Windows; + ImVector<ImGuiWindow*> WindowsSortBuffer; ImGuiWindow* CurrentWindow; // Being drawn into ImVector<ImGuiWindow*> CurrentWindowStack; + int CurrentPopupStackSize; ImGuiWindow* FocusedWindow; // Will catch keyboard inputs ImGuiWindow* HoveredWindow; // Will catch mouse inputs ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) - ImGuiID HoveredId; - ImGuiID ActiveId; + ImGuiID HoveredId; // Hovered widget + ImGuiID ActiveId; // Active widget ImGuiID ActiveIdPreviousFrame; bool ActiveIdIsAlive; + bool ActiveIdIsJustActivated; // Set when bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction. ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window. float SettingsDirtyTimer; ImVector<ImGuiIniData*> Settings; + int DisableHideTextAfterDoubleHash; ImVector<ImGuiColMod> ColorModifiers; ImVector<ImGuiStyleMod> StyleModifiers; ImVector<ImFont*> FontStack; @@ -1046,14 +1169,24 @@ struct ImGuiState ImGuiSetCond SetNextTreeNodeOpenedCond; // Render - ImVector<ImDrawList*> RenderDrawLists; - ImVector<ImGuiWindow*> RenderSortedWindows; + ImVector<ImDrawList*> RenderDrawLists[3]; + + // Mouse cursor + ImGuiMouseCursor MouseCursor; + ImDrawList MouseCursorDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + ImGuiMouseCursorData MouseCursorData[ImGuiMouseCursor_Count_]; // Widget state ImGuiTextEditState InputTextState; - ImGuiID SliderAsInputTextId; + ImGuiID ScalarAsInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiStorage ColorEditModeStorage; // for user selection ImGuiID ActiveComboID; + ImVec2 ActiveClickDeltaToCenter; + float DragCurrentValue; // current dragged value, always float, not rounded by end-user precision settings + ImVec2 DragLastMouseDelta; + float DragSpeedDefaultRatio; // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio + float DragSpeedScaleSlow; + float DragSpeedScaleFast; float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space char Tooltip[1024]; char* PrivateClipboard; // if no custom clipboard handler is defined @@ -1069,18 +1202,20 @@ struct ImGuiState float FramerateSecPerFrame[120]; // calculate estimate of framerate for user int FramerateSecPerFrameIdx; float FramerateSecPerFrameAccum; + char TempBuffer[1024*3+1]; // temporary text buffer ImGuiState() { Initialized = false; Font = NULL; - FontSize = 0.0f; + FontBaseSize = FontSize = 0.0f; FontTexUvWhitePixel = ImVec2(0.0f, 0.0f); Time = 0.0f; FrameCount = 0; FrameCountRendered = -1; CurrentWindow = NULL; + CurrentPopupStackSize = 0; FocusedWindow = NULL; HoveredWindow = NULL; HoveredRootWindow = NULL; @@ -1088,9 +1223,11 @@ struct ImGuiState ActiveId = 0; ActiveIdPreviousFrame = 0; ActiveIdIsAlive = false; + ActiveIdIsJustActivated = false; ActiveIdIsFocusedOnly = false; MovedWindow = NULL; SettingsDirtyTimer = 0.0f; + DisableHideTextAfterDoubleHash = 0; SetNextWindowPosVal = ImVec2(0.0f, 0.0f); SetNextWindowPosCond = 0; @@ -1102,12 +1239,20 @@ struct ImGuiState SetNextTreeNodeOpenedVal = false; SetNextTreeNodeOpenedCond = 0; - SliderAsInputTextId = 0; + ScalarAsInputTextId = 0; ActiveComboID = 0; + ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f); + DragCurrentValue = 0.0f; + DragLastMouseDelta = ImVec2(0.0f, 0.0f); + DragSpeedDefaultRatio = 0.01f; + DragSpeedScaleSlow = 0.01f; + DragSpeedScaleFast = 10.0f; ScrollbarClickDeltaToGrabCenter = 0.0f; memset(Tooltip, 0, sizeof(Tooltip)); PrivateClipboard = NULL; + MouseCursor = ImGuiMouseCursor_Arrow; + LogEnabled = false; LogFile = NULL; LogClipboard = NULL; @@ -1133,24 +1278,27 @@ struct ImGuiWindow ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) ImVec2 SizeFull; // Size when non collapsed ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame - ImVec2 SizeContentsCurrent; // Size of contents, currently extending + ImGuiID MoveID; // == window->GetID("#MOVE") float ScrollY; float NextScrollY; bool ScrollbarY; - bool Visible; // Set to true on Begin() + bool Active; // Set to true on Begin() + bool WasActive; bool Accessed; // Set to true when any widget access the current window bool Collapsed; // Set when collapsing window to become only title-bar bool SkipItems; // == Visible && !Collapsed int AutoFitFrames; bool AutoFitOnlyGrows; - int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call is allowed with this particular flag. - int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call is allowed with this particular flag. - int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call is allowed with this particular flag. - - ImGuiDrawContext DC; - ImVector<ImGuiID> IDStack; + int AutoPosLastDirection; + int HiddenFrames; + int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call will succeed with this particular flag. + int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call will succeed with this particular flag. + int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call will succeed with this particular flag. + + ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame + ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2. - ImGuiAabb ClippedAabb; // = ClipRectStack.front() after setup in Begin() + ImRect ClippedRect; // = ClipRectStack.front() after setup in Begin() int LastFrameDrawn; float ItemWidthDefault; ImGuiStorage StateStorage; @@ -1170,32 +1318,37 @@ public: ImGuiWindow(const char* name); ~ImGuiWindow(); - ImGuiID GetID(const char* str); + ImGuiID GetID(const char* str, const char* str_end = NULL); ImGuiID GetID(const void* ptr); - void AddToRenderList(); bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested void FocusItemUnregister(); - ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); } - ImFont* Font() const { return GImGui->Font; } - float FontSize() const { return GImGui->FontSize * FontWindowScale; } - ImVec2 CursorPos() const { return DC.CursorPos; } - float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; } - ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } - ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; } + ImRect Rect() const { return ImRect(Pos, Pos+Size); } + float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } + float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } + ImRect TitleBarRect() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } + ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders) && !(Flags & ImGuiWindowFlags_ComboBox)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; } ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); } ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); } }; static inline ImGuiWindow* GetCurrentWindow() { + // If this ever crash it probably means that ImGui::NewFrame() hasn't been called. We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) ImGuiState& g = *GImGui; - IM_ASSERT(g.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? g.CurrentWindow->Accessed = true; return g.CurrentWindow; } +static inline void SetCurrentWindow(ImGuiWindow* window) +{ + ImGuiState& g = *GImGui; + g.CurrentWindow = window; + if (window) + g.FontSize = window->CalcFontSize(); +} + static inline ImGuiWindow* GetParentWindow() { ImGuiState& g = *GImGui; @@ -1203,14 +1356,15 @@ static inline ImGuiWindow* GetParentWindow() return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2]; } -static void SetActiveId(ImGuiID id) +static void SetActiveId(ImGuiID id) { ImGuiState& g = *GImGui; - g.ActiveId = id; + g.ActiveId = id; g.ActiveIdIsFocusedOnly = false; + g.ActiveIdIsJustActivated = true; } -static void RegisterAliveId(const ImGuiID& id) +static void RegisterAliveId(ImGuiID id) { ImGuiState& g = *GImGui; if (g.ActiveId == id) @@ -1289,6 +1443,14 @@ float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val) return &it->val_f; } +void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val) +{ + ImVector<Pair>::iterator it = LowerBound(Data, key); + if (it == Data.end() || it->key != key) + it = Data.insert(it, Pair(key, default_val)); + return &it->val_p; +} + // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed. void ImGuiStorage::SetInt(ImU32 key, int val) @@ -1428,7 +1590,7 @@ bool ImGuiTextFilter::PassFilter(const char* val) const //----------------------------------------------------------------------------- -// On some platform vsnprintf() takes va_list by reference and modifies it. +// On some platform vsnprintf() takes va_list by reference and modifies it. // va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it. #ifndef va_copy #define va_copy(dest, src) (dest = src) @@ -1469,34 +1631,31 @@ void ImGuiTextBuffer::append(const char* fmt, ...) ImGuiWindow::ImGuiWindow(const char* name) { Name = ImStrdup(name); - ID = ImHash(name, 0); + ID = ImHash(name, 0); IDStack.push_back(ID); + MoveID = GetID("#MOVE"); Flags = 0; PosFloat = Pos = ImVec2(0.0f, 0.0f); Size = SizeFull = ImVec2(0.0f, 0.0f); - SizeContents = SizeContentsCurrent = ImVec2(0.0f, 0.0f); + SizeContents = ImVec2(0.0f, 0.0f); ScrollY = 0.0f; NextScrollY = 0.0f; ScrollbarY = false; - Visible = false; + Active = WasActive = false; Accessed = false; Collapsed = false; SkipItems = false; AutoFitFrames = -1; AutoFitOnlyGrows = false; - SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver; + AutoPosLastDirection = -1; + HiddenFrames = 0; + SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing; LastFrameDrawn = -1; ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; - if (ImLengthSqr(Size) < 0.00001f) - { - AutoFitFrames = 2; - AutoFitOnlyGrows = true; - } - DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList)); new(DrawList) ImDrawList(); RootWindow = NULL; @@ -1515,10 +1674,10 @@ ImGuiWindow::~ImGuiWindow() Name = NULL; } -ImGuiID ImGuiWindow::GetID(const char* str) +ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) { ImGuiID seed = IDStack.back(); - const ImGuiID id = ImHash(str, 0, seed); + const ImGuiID id = ImHash(str, str_end ? str_end - str : 0, seed); RegisterAliveId(id); return id; } @@ -1565,21 +1724,25 @@ void ImGuiWindow::FocusItemUnregister() FocusIdxTabCounter--; } -void ImGuiWindow::AddToRenderList() +static inline void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDrawList* draw_list) { - ImGuiState& g = *GImGui; - - if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty()) + if (!draw_list->commands.empty() && !draw_list->vtx_buffer.empty()) { - if (DrawList->commands.back().vtx_count == 0) - DrawList->commands.pop_back(); - g.RenderDrawLists.push_back(DrawList); + if (draw_list->commands.back().vtx_count == 0) + draw_list->commands.pop_back(); + out_render_list.push_back(draw_list); + GImGui->IO.MetricsRenderVertices += (int)draw_list->vtx_buffer.size(); } - for (size_t i = 0; i < DC.ChildWindows.size(); i++) +} + +static void AddWindowToRenderList(ImVector<ImDrawList*>& out_render_list, ImGuiWindow* window) +{ + AddDrawListToRenderList(out_render_list, window->DrawList); + for (size_t i = 0; i < window->DC.ChildWindows.size(); i++) { - ImGuiWindow* child = DC.ChildWindows[i]; - if (child->Visible) // clipped children may have been marked not Visible - child->AddToRenderList(); + ImGuiWindow* child = window->DC.ChildWindows[i]; + if (child->Active) // clipped children may have been marked not active + AddWindowToRenderList(out_render_list, child); } } @@ -1594,7 +1757,7 @@ void ImGui::MemFree(void* ptr) { return GImGui->IO.MemFreeFn(ptr); } - + static ImGuiIniData* FindWindowSettings(const char* name) { ImGuiState& g = *GImGui; @@ -1642,7 +1805,7 @@ static void LoadSettings() const char* line_end = line_start; while (line_end < buf_end && *line_end != '\n' && *line_end != '\r') line_end++; - + if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']') { char name[64]; @@ -1719,6 +1882,11 @@ static void MarkSettingsDirty() g.SettingsDirtyTimer = g.IO.IniSavingRate; } +const char* ImGui::GetVersion() +{ + return IMGUI_VERSION; +} + // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself // Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module void* ImGui::GetInternalState() @@ -1735,7 +1903,7 @@ void ImGui::SetInternalState(void* state, bool construct) { if (construct) new (state) ImGuiState(); - + GImGui = (ImGuiState*)state; } @@ -1801,8 +1969,13 @@ void ImGui::NewFrame() else { g.IO.MouseClickedTime[i] = g.Time; - g.IO.MouseClickedPos[i] = g.IO.MousePos; } + g.IO.MouseClickedPos[i] = g.IO.MousePos; + g.IO.MouseDragMaxDistanceSqr[i] = 0.0f; + } + else if (g.IO.MouseDown[i]) + { + g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i])); } } for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) @@ -1820,6 +1993,7 @@ void ImGui::NewFrame() SetActiveId(0); g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; + g.ActiveIdIsJustActivated = false; if (!g.ActiveId) g.MovedWindow = NULL; @@ -1852,6 +2026,7 @@ void ImGui::NewFrame() bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down]; g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0); g.IO.WantCaptureKeyboard = (g.ActiveId != 0); + g.MouseCursor = ImGuiMouseCursor_Arrow; // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. if (mouse_owned_by_application) @@ -1883,14 +2058,14 @@ void ImGui::NewFrame() if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse)) { const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; - window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; + window->NextScrollY -= g.IO.MouseWheel * window->CalcFontSize() * scroll_lines; } } } // Pressing TAB activate widget focus // NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus. - if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false)) + if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Active && IsKeyPressedMap(ImGuiKey_Tab, false)) { g.FocusedWindow->FocusIdxTabRequestNext = 0; } @@ -1899,7 +2074,8 @@ void ImGui::NewFrame() for (size_t i = 0; i != g.Windows.size(); i++) { ImGuiWindow* window = g.Windows[i]; - window->Visible = false; + window->WasActive = window->Active; + window->Active = false; window->Accessed = false; } @@ -1908,10 +2084,11 @@ void ImGui::NewFrame() g.CurrentWindowStack.resize(0); // Create implicit window - we will only render it if the user has added something to it. - ImGui::Begin("Debug", NULL, ImVec2(400,400)); + ImGui::SetNextWindowSize(ImVec2(400,400), ImGuiSetCond_FirstUseEver); + ImGui::Begin("Debug"); } -// NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations. +// NB: behavior of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations. void ImGui::Shutdown() { ImGuiState& g = *GImGui; @@ -1926,8 +2103,8 @@ void ImGui::Shutdown() ImGui::MemFree(g.Windows[i]); } g.Windows.clear(); + g.WindowsSortBuffer.clear(); g.CurrentWindowStack.clear(); - g.RenderDrawLists.clear(); g.FocusedWindow = NULL; g.HoveredWindow = NULL; g.HoveredRootWindow = NULL; @@ -1940,26 +2117,30 @@ void ImGui::Shutdown() g.ColorModifiers.clear(); g.StyleModifiers.clear(); g.FontStack.clear(); + for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + g.RenderDrawLists[i].clear(); + g.MouseCursorDrawList.ClearFreeMemory(); g.ColorEditModeStorage.Clear(); - if (g.LogFile && g.LogFile != stdout) - { - fclose(g.LogFile); - g.LogFile = NULL; - } - g.IO.Fonts->Clear(); - if (g.PrivateClipboard) { ImGui::MemFree(g.PrivateClipboard); g.PrivateClipboard = NULL; } + if (g.LogFile && g.LogFile != stdout) + { + fclose(g.LogFile); + g.LogFile = NULL; + } if (g.LogClipboard) { g.LogClipboard->~ImGuiTextBuffer(); ImGui::MemFree(g.LogClipboard); } + if (g.IO.Fonts) // Testing for NULL to allow user to NULLify in case of running Shutdown() on multiple contexts. Bit hacky. + g.IO.Fonts->Clear(); + g.Initialized = false; } @@ -1968,6 +2149,8 @@ static int ChildWindowComparer(const void* lhs, const void* rhs) { const ImGuiWindow* a = *(const ImGuiWindow**)lhs; const ImGuiWindow* b = *(const ImGuiWindow**)rhs; + if (int d = (a->Flags & ImGuiWindowFlags_Popup) - (b->Flags & ImGuiWindowFlags_Popup)) + return d; if (int d = (a->Flags & ImGuiWindowFlags_Tooltip) - (b->Flags & ImGuiWindowFlags_Tooltip)) return d; if (int d = (a->Flags & ImGuiWindowFlags_ComboBox) - (b->Flags & ImGuiWindowFlags_ComboBox)) @@ -1975,10 +2158,10 @@ static int ChildWindowComparer(const void* lhs, const void* rhs) return 0; } -static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>& sorted_windows) +static void AddWindowToSortedBuffer(ImVector<ImGuiWindow*>& out_sorted_windows, ImGuiWindow* window) { - sorted_windows.push_back(window); - if (window->Visible) + out_sorted_windows.push_back(window); + if (window->Active) { const size_t count = window->DC.ChildWindows.size(); if (count > 1) @@ -1986,8 +2169,8 @@ static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>& for (size_t i = 0; i < count; i++) { ImGuiWindow* child = window->DC.ChildWindows[i]; - if (child->Visible) - AddWindowToSortedBuffer(child, sorted_windows); + if (child->Active) + AddWindowToSortedBuffer(out_sorted_windows, child); } } } @@ -2003,7 +2186,10 @@ static void PushClipRect(const ImVec4& clip_rect, bool clipped = true) const ImVec4 cur_cr = window->ClipRectStack.back(); cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w)); } + cr.z = ImMax(cr.x, cr.z); + cr.w = ImMax(cr.y, cr.w); + IM_ASSERT(cr.x <= cr.z && cr.y <= cr.w); window->ClipRectStack.push_back(cr); window->DrawList->PushClipRect(cr); } @@ -2018,94 +2204,123 @@ static void PopClipRect() void ImGui::Render() { ImGuiState& g = *GImGui; - IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount); g.FrameCountRendered = g.FrameCount; - + if (first_render_of_the_frame) { - // Hide implicit window if it hasn't been used - IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End + // Hide implicit "Debug" window if it hasn't been used + IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End if (g.CurrentWindow && !g.CurrentWindow->Accessed) - g.CurrentWindow->Visible = false; + g.CurrentWindow->Active = false; ImGui::End(); - // Select window for move/focus when we're done with all our widgets (we use the root window ID here) - if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow != NULL && g.IO.MouseClicked[0]) + // Click to focus window and start moving (after we're done with all our widgets) + if (g.ActiveId == 0 && g.HoveredId == 0 && g.IO.MouseClicked[0]) { - IM_ASSERT(g.MovedWindow == NULL); - g.MovedWindow = g.HoveredWindow; - SetActiveId(g.HoveredRootWindow->GetID("#MOVE")); + if (g.HoveredRootWindow != NULL) + { + IM_ASSERT(g.MovedWindow == NULL); + g.MovedWindow = g.HoveredWindow; + SetActiveId(g.HoveredRootWindow->MoveID); + } + else if (g.FocusedWindow != NULL) + { + // Clicking on void disable focus + FocusWindow(NULL); + } } // Sort the window list so that all child windows are after their parent // We cannot do that on FocusWindow() because childs may not exist yet - g.RenderSortedWindows.resize(0); - g.RenderSortedWindows.reserve(g.Windows.size()); + g.WindowsSortBuffer.resize(0); + g.WindowsSortBuffer.reserve(g.Windows.size()); for (size_t i = 0; i != g.Windows.size(); i++) { ImGuiWindow* window = g.Windows[i]; - if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it - if (window->Visible) + if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is active its parent will add it + if (window->Active) continue; - AddWindowToSortedBuffer(window, g.RenderSortedWindows); + AddWindowToSortedBuffer(g.WindowsSortBuffer, window); } - IM_ASSERT(g.Windows.size() == g.RenderSortedWindows.size()); // we done something wrong - g.Windows.swap(g.RenderSortedWindows); + IM_ASSERT(g.Windows.size() == g.WindowsSortBuffer.size()); // we done something wrong + g.Windows.swap(g.WindowsSortBuffer); - // Clear data for next frame + // Clear Input data for next frame g.IO.MouseWheel = 0.0f; memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); } // Skip render altogether if alpha is 0.0 - // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place. + // Note that vertex buffers have been created, so it is best practice that you don't create windows in the first place, or respond to Begin() returning false if (g.Style.Alpha > 0.0f) { // Render tooltip if (g.Tooltip[0]) { - // Use a dummy window to render the tooltip ImGui::BeginTooltip(); ImGui::TextUnformatted(g.Tooltip); ImGui::EndTooltip(); } // Gather windows to render - g.RenderDrawLists.resize(0); + g.IO.MetricsRenderVertices = 0; + g.IO.MetricsActiveWindows = 0; + for (size_t i = 0; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + g.RenderDrawLists[i].resize(0); for (size_t i = 0; i != g.Windows.size(); i++) { ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) - window->AddToRenderList(); + if (window->Active && window->HiddenFrames <= 0 && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0) + { + // FIXME: Generalize this with a proper layering system so we can stack. + g.IO.MetricsActiveWindows++; + if (window->Flags & ImGuiWindowFlags_Popup) + AddWindowToRenderList(g.RenderDrawLists[1], window); + else if (window->Flags & ImGuiWindowFlags_Tooltip) + AddWindowToRenderList(g.RenderDrawLists[2], window); + else + AddWindowToRenderList(g.RenderDrawLists[0], window); + } } - for (size_t i = 0; i != g.Windows.size(); i++) + + // Flatten layers + size_t n = g.RenderDrawLists[0].size(); + size_t flattened_size = n; + for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) + flattened_size += g.RenderDrawLists[i].size(); + g.RenderDrawLists[0].resize(flattened_size); + for (size_t i = 1; i < IM_ARRAYSIZE(g.RenderDrawLists); i++) { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) - window->AddToRenderList(); + ImVector<ImDrawList*>& layer = g.RenderDrawLists[i]; + if (!layer.empty()) + { + memcpy(&g.RenderDrawLists[0][n], &layer[0], layer.size() * sizeof(ImDrawList*)); + n += layer.size(); + } } if (g.IO.MouseDrawCursor) { - const ImVec2 pos = g.IO.MousePos; - const ImVec2 size = TEX_ATLAS_SIZE_MOUSE_CURSOR; + const ImGuiMouseCursorData& cursor_data = g.MouseCursorData[g.MouseCursor]; + const ImVec2 pos = g.IO.MousePos - cursor_data.Offset; + const ImVec2 size = cursor_data.Size; const ImTextureID tex_id = g.IO.Fonts->TexID; - const ImVec2 tex_uv_scale(1.0f/g.IO.Fonts->TexWidth, 1.0f/g.IO.Fonts->TexHeight); - static ImDrawList draw_list; - draw_list.Clear(); - draw_list.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0x30000000); // Shadow - draw_list.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0x30000000); // Shadow - draw_list.AddImage(tex_id, pos, pos + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0xFF000000); // Black border - draw_list.AddImage(tex_id, pos, pos + size, TEX_ATLAS_POS_MOUSE_CURSOR_WHITE * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_WHITE + size) * tex_uv_scale, 0xFFFFFFFF); // White fill - g.RenderDrawLists.push_back(&draw_list); + g.MouseCursorDrawList.Clear(); + g.MouseCursorDrawList.PushTextureID(tex_id); + g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow + g.MouseCursorDrawList.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0x30000000); // Shadow + g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[1], cursor_data.TexUvMax[1], 0xFF000000); // Black border + g.MouseCursorDrawList.AddImage(tex_id, pos, pos + size, cursor_data.TexUvMin[0], cursor_data.TexUvMax[0], 0xFFFFFFFF); // White fill + g.MouseCursorDrawList.PopTextureID(); + AddDrawListToRenderList(g.RenderDrawLists[0], &g.MouseCursorDrawList); } // Render - if (!g.RenderDrawLists.empty()) - g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); - g.RenderDrawLists.resize(0); + if (!g.RenderDrawLists[0].empty()) + g.IO.RenderDrawListsFn(&g.RenderDrawLists[0][0], (int)g.RenderDrawLists[0].size()); } } @@ -2115,8 +2330,18 @@ static const char* FindTextDisplayEnd(const char* text, const char* text_end = const char* text_display_end = text; if (!text_end) text_end = (const char*)-1; - while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) - text_display_end++; + + ImGuiState& g = *GImGui; + if (g.DisableHideTextAfterDoubleHash > 0) + { + while (text_display_end < text_end && *text_display_end != '\0') + text_display_end++; + } + else + { + while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) + text_display_end++; + } return text_display_end; } @@ -2150,8 +2375,8 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en if (!text_end) text_end = FindTextDisplayEnd(text, text_end); - const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1; - window->DC.LogLineHeight = ref_pos.y; + const bool log_new_line = ref_pos.y > window->DC.LogLinePosY+1; + window->DC.LogLinePosY = ref_pos.y; const char* text_remaining = text; if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth @@ -2201,7 +2426,7 @@ static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x) wrap_pos_x = ImGui::GetContentRegionMax().x; if (wrap_pos_x > 0.0f) wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space - + const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f; return wrap_width; } @@ -2230,7 +2455,7 @@ static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool if (text_len > 0) { // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end); + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end); // Log as text if (g.LogEnabled) @@ -2249,37 +2474,36 @@ static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end const int text_len = (int)(text_end - text); if (text_len > 0) { - // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width); - - // Log as text + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_end, wrap_width); if (g.LogEnabled) LogText(pos, text, text_end); } } -static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& clip_max) +static void RenderTextClipped(ImVec2 pos, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& pos_max, const ImVec2* clip_max, ImGuiAlign align) { - ImGuiState& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - // Hide anything after a '##' string const char* text_display_end = FindTextDisplayEnd(text, text_end); const int text_len = (int)(text_display_end - text); - if (text_len > 0) - { - const ImVec2 text_size = text_size_if_known ? *text_size_if_known : ImGui::CalcTextSize(text, text_display_end, false, 0.0f); + if (text_len == 0) + return; + + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); - // Perform CPU side clipping for single clipped element to avoid using scissor state - const bool need_clipping = (pos.x + text_size.x >= clip_max.x) || (pos.y + text_size.y >= clip_max.y); + // Perform CPU side clipping for single clipped element to avoid using scissor state + const ImVec2 text_size = text_size_if_known ? *text_size_if_known : ImGui::CalcTextSize(text, text_display_end, false, 0.0f); + if (!clip_max) clip_max = &pos_max; + const bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y); - // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? &clip_max : NULL); + // Align + if (align & ImGuiAlign_Center) pos.x = ImMax(pos.x, (pos.x + pos_max.x - text_size.x) * 0.5f); + else if (align & ImGuiAlign_Right) pos.x = ImMax(pos.x, pos_max.x - text_size.x); - // Log as text - if (g.LogEnabled) - LogText(pos, text, text_display_end); - } + // Render + window->DrawList->AddText(g.Font, g.FontSize, pos, window->Color(ImGuiCol_Text), text, text_display_end, 0.0f, need_clipping ? clip_max : NULL); + if (g.LogEnabled) + LogText(pos, text, text_display_end); } // Render a rectangle shaped with optional rounding and borders @@ -2299,9 +2523,10 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, // Render a triangle to denote expanded/collapsed state static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow) { + ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - const float h = window->FontSize() * 1.00f; + const float h = g.FontSize * 1.00f; const float r = h * 0.40f * scale; ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale); @@ -2319,17 +2544,36 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool b = center + ImVec2(-0.500f,0.866f)*r; c = center + ImVec2(-0.500f,-0.866f)*r; } - + if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0) window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow)); window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text)); } +static void RenderCheckMark(ImVec2 pos, ImU32 col) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + + ImVec2 a, b, c; + float start_x = (float)(int)(g.FontSize * 0.307f + 0.5f); + float rem_third = (float)(int)((g.FontSize - start_x) / 3.0f); + a.x = pos.x + start_x; + b.x = a.x + rem_third; + c.x = a.x + rem_third * 3.0f; + b.y = pos.y + (float)(int)(g.Font->BaseLine * (g.FontSize / g.Font->FontSize) + 0.5f) + (float)(int)(g.Font->DisplayOffset.y); + a.y = b.y - rem_third; + c.y = b.y - rem_third * 2.0f; + + window->DrawList->AddLine(a, b, col); + window->DrawList->AddLine(b, c, col); +} + // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. // CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize) ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = *GImGui; const char* text_display_end; if (hide_text_after_double_hash) @@ -2337,12 +2581,12 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex else text_display_end = text_end; - ImFont* font = window->Font(); - const float font_size = window->FontSize(); + ImFont* font = g.Font; + const float font_size = g.FontSize; ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL); // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field) - const float font_scale = font_size / font->FontSize; + const float font_scale = font_size / font->FontSize; const float character_spacing_x = 1.0f * font_scale; if (text_size.x > 0.0f) text_size.x -= character_spacing_x; @@ -2350,7 +2594,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex return text_size; } -// Helper to calculate coarse clipping of large list of evenly sized items. +// Helper to calculate coarse clipping of large list of evenly sized items. // If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU. // { // float item_height = ImGui::GetTextLineHeightWithSpacing(); @@ -2395,43 +2639,43 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs) for (int i = (int)g.Windows.size()-1; i >= 0; i--) { ImGuiWindow* window = g.Windows[(size_t)i]; - if (!window->Visible) + if (!window->Active) continue; if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0) continue; // Using the clipped AABB so a child window will typically be clipped by its parent. - ImGuiAabb bb(window->ClippedAabb.Min - g.Style.TouchExtraPadding, window->ClippedAabb.Max + g.Style.TouchExtraPadding); + ImRect bb(window->ClippedRect.Min - g.Style.TouchExtraPadding, window->ClippedRect.Max + g.Style.TouchExtraPadding); if (bb.Contains(pos)) return window; } return NULL; } -// Test if mouse cursor is hovering given aabb -// NB- Box is clipped by our current clip setting -// NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) -static bool IsMouseHoveringBox(const ImGuiAabb& bb) +// Test if mouse cursor is hovering given rectangle +// NB- Rectangle is clipped by our current clip setting +// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) +static bool IsMouseHoveringRect(const ImRect& rect) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); // Clip - ImGuiAabb box_clipped = bb; + ImRect rect_clipped = rect; if (!window->ClipRectStack.empty()) { const ImVec4 clip_rect = window->ClipRectStack.back(); - box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w))); + rect_clipped.Clip(ImRect(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w))); } // Expand for touch input - const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding); - return box_for_touch.Contains(g.IO.MousePos); + const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); + return rect_for_touch.Contains(g.IO.MousePos); } -bool ImGui::IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max) +bool ImGui::IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max) { - return IsMouseHoveringBox(ImGuiAabb(box_min, box_max)); + return IsMouseHoveringRect(ImRect(rect_min, rect_max)); } bool ImGui::IsMouseHoveringWindow() @@ -2459,6 +2703,13 @@ static bool IsKeyPressedMap(ImGuiKey key, bool repeat) return ImGui::IsKeyPressed(key_index, repeat); } +bool ImGui::IsKeyDown(int key_index) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + return g.IO.KeysDown[key_index]; +} + bool ImGui::IsKeyPressed(int key_index, bool repeat) { ImGuiState& g = *GImGui; @@ -2477,6 +2728,13 @@ bool ImGui::IsKeyPressed(int key_index, bool repeat) return false; } +bool ImGui::IsMouseDown(int button) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDown[button]; +} + bool ImGui::IsMouseClicked(int button, bool repeat) { ImGuiState& g = *GImGui; @@ -2502,15 +2760,60 @@ bool ImGui::IsMouseDoubleClicked(int button) return g.IO.MouseDoubleClicked[button]; } +bool ImGui::IsMouseDragging(int button, float lock_threshold) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; +} + ImVec2 ImGui::GetMousePos() { return GImGui->IO.MousePos; } +ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + if (g.IO.MouseDown[button]) + if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold) + return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment). + return ImVec2(0.0f, 0.0f); +} + +void ImGui::ResetMouseDragDelta(int button) +{ + ImGuiState& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr + g.IO.MouseClickedPos[button] = g.IO.MousePos; +} + +ImGuiMouseCursor ImGui::GetMouseCursor() +{ + return GImGui->MouseCursor; +} + +void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type) +{ + GImGui->MouseCursor = cursor_type; +} + bool ImGui::IsItemHovered() { ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemHovered; + return window->DC.LastItemHoveredAndUsable; +} + +bool ImGui::IsItemHoveredRect() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemHoveredRect; } bool ImGui::IsItemActive() @@ -2530,16 +2833,37 @@ bool ImGui::IsAnyItemActive() return g.ActiveId != 0; } -ImVec2 ImGui::GetItemBoxMin() +bool ImGui::IsItemVisible() +{ + ImGuiWindow* window = GetCurrentWindow(); + ImRect r(window->ClipRectStack.back()); + return r.Overlaps(window->DC.LastItemRect); +} + +ImVec2 ImGui::GetItemRectMin() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemRect.Min; +} + +ImVec2 ImGui::GetItemRectMax() { ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemAabb.Min; + return window->DC.LastItemRect.Max; } -ImVec2 ImGui::GetItemBoxMax() +ImVec2 ImGui::GetItemRectSize() { ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemAabb.Max; + return window->DC.LastItemRect.GetSize(); +} + +ImVec2 ImGui::CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge, float outward) +{ + ImGuiWindow* window = GetCurrentWindow(); + ImRect rect = window->DC.LastItemRect; + rect.Expand(outward); + return rect.GetClosestPoint(pos, on_edge); } // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value. @@ -2567,11 +2891,19 @@ int ImGui::GetFrameCount() return GImGui->FrameCount; } +static ImVec4 GetVisibleRect() +{ + ImGuiState& g = *GImGui; + if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) + return ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y); + return ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); +} + void ImGui::BeginTooltip() { ImGuiState& g = *GImGui; - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_Tooltip; - ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, window_flags); + ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize; + ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, flags); } void ImGui::EndTooltip() @@ -2580,6 +2912,34 @@ void ImGui::EndTooltip() ImGui::End(); } +void ImGui::BeginPopup(bool* p_opened) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + IM_ASSERT(p_opened != NULL); // Must provide a bool at the moment + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGuiWindowFlags flags = ImGuiWindowFlags_Popup|ImGuiWindowFlags_ShowBorders|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize; + float alpha = 1.0f; + + char name[20]; + ImFormatString(name, 20, "##Popup%02d", g.CurrentPopupStackSize++); + ImGui::Begin(name, p_opened, ImVec2(0.0f, 0.0f), alpha, flags); + + if (!(window->Flags & ImGuiWindowFlags_ShowBorders)) + GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders; +} + +void ImGui::EndPopup() +{ + ImGuiState& g = *GImGui; + IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Popup); + IM_ASSERT(g.CurrentPopupStackSize > 0); + g.CurrentPopupStackSize--; + ImGui::End(); + ImGui::PopStyleVar(); +} + bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) { ImGuiState& g = *GImGui; @@ -2613,7 +2973,7 @@ bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, bool ret = ImGui::Begin(title, NULL, size, alpha, flags); if (!(window->Flags & ImGuiWindowFlags_ShowBorders)) - g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders; + GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders; return ret; } @@ -2637,17 +2997,18 @@ void ImGui::EndChild() } else { - // When using auto-filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic size-fitting. + // When using auto-filling child window, we don't provide full width/height to ItemSize so that it doesn't feed back into automatic size-fitting. + ImGuiState& g = *GImGui; ImVec2 sz = ImGui::GetWindowSize(); if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX) - sz.x = 0; + sz.x = ImMax(g.Style.WindowMinSize.x, sz.x - g.Style.WindowPadding.x); if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY) - sz.y = 0; - + sz.y = ImMax(g.Style.WindowMinSize.y, sz.y - g.Style.WindowPadding.y); + ImGui::End(); window = GetCurrentWindow(); - ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + sz); + ImRect bb(window->DC.CursorPos, window->DC.CursorPos + sz); ItemSize(sz); ItemAdd(bb, NULL); } @@ -2670,6 +3031,44 @@ void ImGui::EndChildFrame() ImGui::PopStyleColor(); } +// Save and compare stack sizes on Begin()/End() to detect usage errors +static void CheckStacksSize(ImGuiWindow* window, bool write) +{ + // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) + ImGuiState& g = *GImGui; + int* p_backup = &window->DC.StackSizesBackup[0]; + { int current = (int)window->IDStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopID() + { int current = (int)window->DC.GroupStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot EndGroup() + { int current = (int)g.ColorModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleColor() + { int current = (int)g.StyleModifiers.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopStyleVar() + { int current = (int)g.FontStack.size(); if (write) *p_backup = current; else IM_ASSERT(*p_backup == current); p_backup++; } // User forgot PopFont() + IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); +} + +static ImVec2 FindBestWindowPos(const ImVec2& mouse_pos, const ImVec2& size, int* last_dir, const ImRect& r_inner) +{ + const ImGuiStyle& style = GImGui->Style; + + // Clamp into visible area while not overlapping the cursor + ImRect r_outer(GetVisibleRect()); + r_outer.Reduce(style.DisplaySafeAreaPadding); + ImVec2 mouse_pos_clamped = ImClamp(mouse_pos, r_outer.Min, r_outer.Max - size); + + for (int n = (*last_dir != -1) ? -1 : 0; n < 4; n++) // Right, down, up, left. Favor last used direction. + { + const int dir = (n == -1) ? *last_dir : n; + ImRect rect(dir == 0 ? r_inner.Max.x : r_outer.Min.x, dir == 1 ? r_inner.Max.y : r_outer.Min.y, dir == 3 ? r_inner.Min.x : r_outer.Max.x, dir == 2 ? r_inner.Min.y : r_outer.Max.y); + if (rect.GetWidth() < size.x || rect.GetHeight() < size.y) + continue; + *last_dir = dir; + return ImVec2(dir == 0 ? r_inner.Max.x : dir == 3 ? r_inner.Min.x - size.x : mouse_pos_clamped.x, dir == 1 ? r_inner.Max.y : dir == 2 ? r_inner.Min.y - size.y : mouse_pos_clamped.y); + } + + // Fallback + *last_dir = -1; + return mouse_pos + ImVec2(2,2); +} + static ImGuiWindow* FindWindowByName(const char* name) { // FIXME-OPT: Store sorted hashes -> pointers. @@ -2725,20 +3124,37 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl size = settings->Size; window->Size = window->SizeFull = size; } + + if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) + { + window->AutoFitFrames = 2; + window->AutoFitOnlyGrows = false; + } + else if (ImLengthSqr(window->Size) < 0.00001f) + { + window->AutoFitFrames = 2; + window->AutoFitOnlyGrows = true; + } + g.Windows.push_back(window); return window; } -// Push a new ImGui window to add widgets to. +// Push a new ImGui window to add widgets to. // - 'size' for a regular window denote the initial size for first-time creation (no saved data) and isn't that useful. Use SetNextWindowSize() prior to calling Begin() for more flexible window manipulation. // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair. // - Begin/End can be called multiple times during the frame with the same window name to append content. -// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). +// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). // You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file. // - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned. // - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin(). -bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg_alpha, ImGuiWindowFlags flags) +bool ImGui::Begin(const char* name, bool* p_opened, ImGuiWindowFlags flags) +{ + return ImGui::Begin(name, p_opened, ImVec2(0.f, 0.f), -1.0f, flags); +} + +bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha, ImGuiWindowFlags flags) { ImGuiState& g = *GImGui; const ImGuiStyle& style = g.Style; @@ -2746,32 +3162,44 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg IM_ASSERT(name != NULL); // Must pass a name // Find or create + bool window_is_new = false; ImGuiWindow* window = FindWindowByName(name); if (!window) - window = CreateNewWindow(name, size, flags); + { + window = CreateNewWindow(name, size_on_first_use, flags); + window_is_new = true; + } window->Flags = (ImGuiWindowFlags)flags; + const int current_frame = ImGui::GetFrameCount(); + const bool window_was_visible = (window->LastFrameDrawn == current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on + // Add to stack + ImGuiWindow* parent_window = !g.CurrentWindowStack.empty() ? g.CurrentWindowStack.back() : NULL; g.CurrentWindowStack.push_back(window); - g.CurrentWindow = window; + SetCurrentWindow(window); + CheckStacksSize(window, true); // Process SetNextWindow***() calls bool window_pos_set_by_api = false; if (g.SetNextWindowPosCond) { - const ImVec2 backup_cursor_pos = window->DC.CursorPos; + const ImVec2 backup_cursor_pos = window->DC.CursorPos; // FIXME: not sure of the exact reason of this anymore :( need to look into that. + if (!window_was_visible) window->SetWindowPosAllowFlags |= ImGuiSetCond_Appearing; + window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.SetNextWindowPosCond) != 0; ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond); window->DC.CursorPos = backup_cursor_pos; - window_pos_set_by_api = true; g.SetNextWindowPosCond = 0; } if (g.SetNextWindowSizeCond) { + if (!window_was_visible) window->SetWindowSizeAllowFlags |= ImGuiSetCond_Appearing; ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond); g.SetNextWindowSizeCond = 0; } if (g.SetNextWindowCollapsedCond) { + if (!window_was_visible) window->SetWindowCollapsedAllowFlags |= ImGuiSetCond_Appearing; ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); g.SetNextWindowCollapsedCond = 0; } @@ -2781,9 +3209,6 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg g.SetNextWindowFocus = false; } - // Find parent - ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL; - // Update known root window (if we are a child window, otherwise window == window->RootWindow) size_t root_idx = g.CurrentWindowStack.size() - 1; while (root_idx > 0) @@ -2799,60 +3224,152 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg bg_alpha = style.WindowFillAlphaDefault; // When reusing window again multiple times a frame, just append content (don't need to setup again) - const int current_frame = ImGui::GetFrameCount(); const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame); if (first_begin_of_the_frame) { + window->Active = true; window->DrawList->Clear(); - window->Visible = true; + window->ClipRectStack.resize(0); + window->LastFrameDrawn = current_frame; + window->IDStack.resize(1); + } + + // Setup texture, outer clipping rectangle + window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) + PushClipRect(parent_window->ClipRectStack.back()); + else + PushClipRect(GetVisibleRect()); + if (first_begin_of_the_frame) + { // New windows appears in front - if (window->LastFrameDrawn < current_frame - 1) - FocusWindow(window); + if (!window_was_visible) + { + window->AutoPosLastDirection = -1; - window->LastFrameDrawn = current_frame; - window->ClipRectStack.resize(0); + if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip)) + { + FocusWindow(window); - // Reset contents size for auto-fitting - window->SizeContents = window->SizeContentsCurrent; - window->SizeContentsCurrent = ImVec2(0.0f, 0.0f); + // Popup first latch mouse position, will position itself when it appears next frame + if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api) + window->PosFloat = g.IO.MousePos; + } + } + // Collapse window by double-clicking on title bar + // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing + if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse)) + { + if (g.HoveredWindow == window && IsMouseHoveringRect(window->TitleBarRect()) && g.IO.MouseDoubleClicked[0]) + { + window->Collapsed = !window->Collapsed; + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); + FocusWindow(window); + } + } + else + { + window->Collapsed = false; + } + + const bool window_appearing_after_being_hidden = (window->HiddenFrames == 1); + if (window->HiddenFrames > 0) + window->HiddenFrames--; + + // SIZE + + // Save contents size from last frame for auto-fitting + window->SizeContents = window_is_new ? ImVec2(0.0f, 0.0f) : window->DC.CursorMaxPos - window->Pos; + window->SizeContents.y += window->ScrollY; + + // Hide popup/tooltip window when first appearing while we measure size (because we recycle them) + if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0 && !window->WasActive) + { + window->HiddenFrames = 1; + window->Size = window->SizeFull = window->SizeContents = ImVec2(0.f, 0.f); // TODO: We don't support SetNextWindowSize() for tooltips or popups yet + } + + // Calculate auto-fit size + ImVec2 size_auto_fit; + if ((flags & ImGuiWindowFlags_Tooltip) != 0) + { + // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. + size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); + } + else + { + size_auto_fit = ImClamp(window->SizeContents + style.WindowPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.WindowPadding)); + if (size_auto_fit.y < window->SizeContents.y + style.WindowPadding.y) + size_auto_fit.x += style.ScrollbarWidth; + size_auto_fit.y -= style.ItemSpacing.y; + } + + // Handle automatic resize + if (window->Collapsed) + { + // We still process initial auto-fit on collapsed windows to get a window width, + // But otherwise we don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed. + if (window->AutoFitFrames > 0) + window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit; + window->Size = window->TitleBarRect().GetSize(); + } + else + { + if (flags & ImGuiWindowFlags_AlwaysAutoResize) + { + window->SizeFull = size_auto_fit; + } + else if (window->AutoFitFrames > 0) + { + // Auto-fit only grows during the first few frames + window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit; + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); + } + window->Size = window->SizeFull; + } + + // Minimum window size + if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip)) + window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize); + + // POSITION + + // Position child window if (flags & ImGuiWindowFlags_ChildWindow) { parent_window->DC.ChildWindows.push_back(window); window->Pos = window->PosFloat = parent_window->DC.CursorPos; - window->SizeFull = size; + window->SizeFull = size_on_first_use; // NB: argument name 'size_on_first_use' misleading here, it's really just 'size' as provided by user. } - } - // Setup texture - window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); - - // Setup outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - PushClipRect(parent_window->ClipRectStack.back()); - else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) - PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y)); - else - PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + // Position popup + if ((flags & ImGuiWindowFlags_Popup) != 0 && window_appearing_after_being_hidden && !window_pos_set_by_api) + { + ImRect rect_to_avoid(window->PosFloat.x - 1, window->PosFloat.y - 1, window->PosFloat.x + 1, window->PosFloat.y + 1); + window->PosFloat = FindBestWindowPos(window->PosFloat, window->Size, &window->AutoPosLastDirection, rect_to_avoid); + } - // Setup and draw window - if (first_begin_of_the_frame) - { - // Reset ID stack - window->IDStack.resize(1); + // Position tooltip (always follows mouse) + if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api) + { + ImRect rect_to_avoid(g.IO.MousePos.x - 16, g.IO.MousePos.y - 8, g.IO.MousePos.x + 24, g.IO.MousePos.y + 24); // FIXME: Completely hard-coded. Perhaps center on cursor hit-point instead? + window->PosFloat = FindBestWindowPos(g.IO.MousePos, window->Size, &window->AutoPosLastDirection, rect_to_avoid); + } - // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows. - const ImGuiID move_id = window->GetID("#MOVE"); - RegisterAliveId(move_id); - if (g.ActiveId == move_id) + // User moving window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows. + RegisterAliveId(window->MoveID); + if (g.ActiveId == window->MoveID) { if (g.IO.MouseDown[0]) { - if (!(window->Flags & ImGuiWindowFlags_NoMove)) + if (!(flags & ImGuiWindowFlags_NoMove)) { window->PosFloat += g.IO.MouseDelta; - if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) MarkSettingsDirty(); } IM_ASSERT(g.MovedWindow != NULL); @@ -2865,30 +3382,20 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg } } - // Tooltips always follows mouse - if (!window_pos_set_by_api && (window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2; - } - - // Clamp into view - if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip)) + // Clamp into display + if (!(flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip)) { - // FIXME: Parameterize padding. - const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior. - if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. + if (window->AutoFitFrames <= 0 && g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. { - ImVec2 clip_min = pad; - ImVec2 clip_max = g.IO.DisplaySize - pad; - window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size; - window->PosFloat = ImMin(window->PosFloat, clip_max); + ImVec2 padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); + window->PosFloat = ImMax(window->PosFloat + window->Size, padding) - window->Size; + window->PosFloat = ImMin(window->PosFloat, g.IO.DisplaySize - padding); } - window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize); } window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); // Default item width. Make it proportional to window size if window manually resizes - if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize)) + if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize)) window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); else window->ItemWidthDefault = 200.0f; @@ -2905,131 +3412,87 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1; window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX; - ImGuiAabb title_bar_aabb = window->TitleBarAabb(); - - // Apply and ImClamp scrolling + // Apply scrolling window->ScrollY = window->NextScrollY; window->ScrollY = ImMax(window->ScrollY, 0.0f); if (!window->Collapsed && !window->SkipItems) window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y)); window->NextScrollY = window->ScrollY; - // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar - // Collapse window by double-clicking on title bar - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - { - if (!(window->Flags & ImGuiWindowFlags_NoCollapse) && g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0]) - { - window->Collapsed = !window->Collapsed; - if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); - FocusWindow(window); - } - } - else - { - window->Collapsed = false; - } - - const float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding; + // Draw window + handle manual resize + ImRect title_bar_rect = window->TitleBarRect(); + const float window_rounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding; if (window->Collapsed) { // Draw title bar only - window->Size = title_bar_aabb.GetSize(); - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding); - if (window->Flags & ImGuiWindowFlags_ShowBorders) + window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding); + if (flags & ImGuiWindowFlags_ShowBorders) { - window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding); - window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), window_rounding); + window->DrawList->AddRect(title_bar_rect.GetTL()+ImVec2(1,1), title_bar_rect.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding); + window->DrawList->AddRect(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border), window_rounding); } } else { - window->Size = window->SizeFull; - ImU32 resize_col = 0; - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. - const ImVec2 size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); - window->SizeFull = size_auto_fit; - } - else + if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFrames <= 0 && !(flags & ImGuiWindowFlags_NoResize)) { - const ImVec2 size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding)); - if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) + // Manual resize + const ImRect resize_rect(window->Rect().GetBR()-ImVec2(14,14), window->Rect().GetBR()); + const ImGuiID resize_id = window->GetID("#RESIZE"); + bool hovered, held; + ButtonBehavior(resize_rect, resize_id, &hovered, &held, true, ImGuiButtonFlags_FlattenChilds); + resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); + + if (hovered || held) + g.MouseCursor = ImGuiMouseCursor_ResizeNWSE; + + if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) { - // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored. + // Manual auto-fit when double-clicking window->SizeFull = size_auto_fit; - } - else if (window->AutoFitFrames > 0) - { - // Auto-fit only grows during the first few frames - if (window->AutoFitOnlyGrows) - window->SizeFull = ImMax(window->SizeFull, size_auto_fit); - else - window->SizeFull = size_auto_fit; - if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) MarkSettingsDirty(); + SetActiveId(0); } - else if (!(window->Flags & ImGuiWindowFlags_NoResize)) + else if (held) { - // Manual resize grip - const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); - const ImGuiID resize_id = window->GetID("#RESIZE"); - bool hovered, held; - ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); - resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); - - if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) - { - // Manual auto-fit when double-clicking - window->SizeFull = size_auto_fit; - window->Size = window->SizeFull; - if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); - } - else if (held) - { - // Resize - window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); - window->Size = window->SizeFull; - if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); - } + window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); + if (!(flags & ImGuiWindowFlags_NoSavedSettings)) + MarkSettingsDirty(); } - // Update aabb immediately so that rendering right below us isn't one frame late - title_bar_aabb = window->TitleBarAabb(); + window->Size = window->SizeFull; + title_bar_rect = window->TitleBarRect(); } // Scrollbar - window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar); + window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(flags & ImGuiWindowFlags_NoScrollbar); // Window background if (bg_alpha > 0.0f) { - if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) + if ((flags & ImGuiWindowFlags_ComboBox) != 0) window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding); - else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + else if ((flags & ImGuiWindowFlags_Tooltip) != 0) window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding); - else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0) + else if ((flags & ImGuiWindowFlags_ChildWindow) != 0) window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollbarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, bg_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF)); else window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding); } // Title bar - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), window_rounding, 1|2); + if (!(flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBg), window_rounding, 1|2); // Borders - if (window->Flags & ImGuiWindowFlags_ShowBorders) + if (flags & ImGuiWindowFlags_ShowBorders) { window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), window_rounding); window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), window_rounding); - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border)); + if (!(flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddLine(title_bar_rect.GetBL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_Border)); } // Scrollbar @@ -3038,10 +3501,10 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg // Render resize grip // (after the input handling so we don't have a frame of latency) - if (!(window->Flags & ImGuiWindowFlags_NoResize)) + if (!(flags & ImGuiWindowFlags_NoResize)) { const float r = window_rounding; - const ImVec2 br = window->Aabb().GetBR(); + const ImVec2 br = window->Rect().GetBR(); if (r == 0.0f) { window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col); @@ -3049,7 +3512,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg else { // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18) - window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true); + window->DrawList->AddArcFast(br - ImVec2(r,r), r, resize_col, 6, 9, true); window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col); window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col); } @@ -3062,10 +3525,12 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY); window->DC.CursorPos = window->DC.CursorStartPos; window->DC.CursorPosPrevLine = window->DC.CursorPos; + window->DC.CursorMaxPos = window->DC.CursorStartPos; window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f; - window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f; + window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; window->DC.ChildWindows.resize(0); - window->DC.ItemWidth.resize(0); + window->DC.ItemWidth.resize(0); window->DC.ItemWidth.push_back(window->ItemWidthDefault); window->DC.AllowKeyboardFocus.resize(0); window->DC.AllowKeyboardFocus.push_back(true); @@ -3078,37 +3543,63 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y; window->DC.TreeDepth = 0; window->DC.StateStorage = &window->StateStorage; + window->DC.GroupStack.resize(0); if (window->AutoFitFrames > 0) window->AutoFitFrames--; // Title bar - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) + if (!(flags & ImGuiWindowFlags_NoTitleBar)) { if (p_opened != NULL) CloseWindowButton(p_opened); + const ImVec2 text_size = CalcTextSize(name, NULL, true); + if (!(flags & ImGuiWindowFlags_NoCollapse)) + RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); + ImVec2 text_min = window->Pos + style.FramePadding; - if (!(window->Flags & ImGuiWindowFlags_NoCollapse)) + ImVec2 text_max = window->Pos + ImVec2(window->Size.x - style.FramePadding.x, style.FramePadding.y*2 + text_size.y); + ImVec2 clip_max = ImVec2(window->Pos.x + window->Size.x - (p_opened ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton() + bool pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0; + bool pad_right = (p_opened != NULL); + if (style.WindowTitleAlign & ImGuiAlign_Center) pad_right = pad_left; + if (pad_left) text_min.x += g.FontSize + style.ItemInnerSpacing.x; + if (pad_right) text_max.x -= g.FontSize + style.ItemInnerSpacing.x; + RenderTextClipped(text_min, name, NULL, &text_size, text_max, &clip_max, style.WindowTitleAlign); + } + if (flags & ImGuiWindowFlags_Popup) + { + if (p_opened) { - RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); - text_min.x += window->FontSize() + style.ItemInnerSpacing.x; + if (g.IO.MouseClicked[0] && (!g.HoveredWindow || g.HoveredWindow->RootWindow != window)) + *p_opened = false; + else if (!g.FocusedWindow) + *p_opened = false; + else if (g.FocusedWindow->RootWindow != window)// && !(g.FocusedWindow->RootWindow->Flags & ImGuiWindowFlags_Tooltip)) + *p_opened = false; } - - const ImVec2 text_size = CalcTextSize(name, NULL, true); - const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y*2 + text_size.y); - RenderTextClipped(text_min, name, NULL, &text_size, text_max); } // Save clipped aabb so we can access it in constant-time in FindHoveredWindow() - window->ClippedAabb = window->Aabb(); - window->ClippedAabb.Clip(window->ClipRectStack.front()); + window->ClippedRect = window->Rect(); + window->ClippedRect.Clip(window->ClipRectStack.front()); + + // Pressing CTRL+C while holding on a window copy its content to the clipboard + // This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope. + // Maybe we can support CTRL+C on every element? + /* + if (g.ActiveId == move_id) + if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) + ImGui::LogToClipboard(); + */ } // Inner clipping rectangle // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame - const ImGuiAabb title_bar_aabb = window->TitleBarAabb(); - ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f); + // Note that if our window is collapsed we will end up with a null clipping rectangle which is the correct behavior. + const ImRect title_bar_rect = window->TitleBarRect(); + ImVec4 clip_rect(title_bar_rect.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_rect.Max.y+0.5f, window->Rect().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Rect().Max.y-1.5f); if (window->ScrollbarY) clip_rect.z -= style.ScrollbarWidth; PushClipRect(clip_rect); @@ -3130,13 +3621,13 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg // We also hide the window from rendering because we've already added its border to the command list. // (we could perform the check earlier in the function but it is simpler at this point) if (window->Collapsed) - window->Visible = false; + window->Active = false; } if (style.Alpha <= 0.0f) - window->Visible = false; + window->Active = false; // Return false if we don't intend to display anything to allow user to perform an early out optimization - window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0); + window->SkipItems = (window->Collapsed || !window->Active) && window->AutoFitFrames <= 0; return !window->SkipItems; } @@ -3156,8 +3647,9 @@ void ImGui::End() // Pop // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin(). + CheckStacksSize(window, false); g.CurrentWindowStack.pop_back(); - g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); + SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back()); } // Vertical scrollbar @@ -3171,21 +3663,21 @@ static void Scrollbar(ImGuiWindow* window) const ImGuiID id = window->GetID("#SCROLLY"); // Render background - ImGuiAabb bb(window->Aabb().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Aabb().Max.x, window->Aabb().Max.y-1); + ImRect bb(window->Rect().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Rect().Max.x, window->Rect().Max.y-1); window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg)); - bb.Expand(ImVec2(-3,-3)); + bb.Expand(-3.0f); const float scrollbar_height = bb.GetHeight(); // The grabable box size generally represent the amount visible (vs the total scrollable amount) // But we maintain a minimum size in pixel to allow for the user to still aim inside. - const float grab_h_pixels = ImMax(style.GrabMinSize, scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y))); + const float grab_h_pixels = ImMin(ImMax(scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y)), style.GrabMinSize), scrollbar_height); const float grab_h_norm = grab_h_pixels / scrollbar_height; // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar(). bool held = false; bool hovered = false; const bool previously_held = (g.ActiveId == id); - ButtonBehaviour(bb, id, &hovered, &held, true); + ButtonBehavior(bb, id, &hovered, &held, true); const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y); float scroll_ratio = ImSaturate(window->ScrollY / scroll_max); @@ -3226,7 +3718,7 @@ static void Scrollbar(ImGuiWindow* window) // Render const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); - window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col); + window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col, style.ScrollbarRounding); } // Moving window to front of display (which happens to be back of our sorted list) @@ -3237,7 +3729,11 @@ static void FocusWindow(ImGuiWindow* window) // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing. g.FocusedWindow = window; - // And move its root window to the top of the pile + // Passing NULL allow to disable keyboard focus + if (!window) + return; + + // And move its root window to the top of the pile if (window->RootWindow) window = window->RootWindow; @@ -3259,6 +3755,19 @@ void ImGui::PushItemWidth(float item_width) window->DC.ItemWidth.push_back(item_width == 0.0f ? window->ItemWidthDefault : item_width); } +static void PushMultiItemsWidths(int components, float w_full = 0.0f) +{ + ImGuiWindow* window = GetCurrentWindow(); + const ImGuiStyle& style = GImGui->Style; + if (w_full <= 0.0f) + w_full = ImGui::CalcItemWidth(); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); + window->DC.ItemWidth.push_back(w_item_last); + for (int i = 0; i < components-1; i++) + window->DC.ItemWidth.push_back(w_item_one); +} + void ImGui::PopItemWidth() { ImGuiWindow* window = GetCurrentWindow(); @@ -3273,9 +3782,8 @@ float ImGui::CalcItemWidth() { // Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well. ImGuiState& g = *GImGui; - w = -w; float width_to_right_edge = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x; - w = ImMax(1.0f, width_to_right_edge - w - g.Style.FramePadding.x * 2.0f); + w = ImMax(1.0f, width_to_right_edge + w - g.Style.FramePadding.x * 2.0f); } w = (float)(int)w; return w; @@ -3288,7 +3796,8 @@ static void SetFont(ImFont* font) IM_ASSERT(font && font->IsLoaded()); IM_ASSERT(font->Scale > 0.0f); g.Font = font; - g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; + g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; + g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f; g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel; } @@ -3370,7 +3879,8 @@ static float* GetStyleVarFloatAddr(ImGuiStyleVar idx) case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding; case ImGuiStyleVar_ChildWindowRounding: return &g.Style.ChildWindowRounding; case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding; - case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing; + case ImGuiStyleVar_IndentSpacing: return &g.Style.IndentSpacing; + case ImGuiStyleVar_GrabMinSize: return &g.Style.GrabMinSize; } return NULL; } @@ -3442,6 +3952,8 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) case ImGuiCol_Border: return "Border"; case ImGuiCol_BorderShadow: return "BorderShadow"; case ImGuiCol_FrameBg: return "FrameBg"; + case ImGuiCol_FrameBgHovered: return "FrameBgHovered"; + case ImGuiCol_FrameBgActive: return "FrameBgActive"; case ImGuiCol_TitleBg: return "TitleBg"; case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; @@ -3449,8 +3961,6 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; case ImGuiCol_ComboBg: return "ComboBg"; - case ImGuiCol_CheckHovered: return "CheckHovered"; - case ImGuiCol_CheckActive: return "CheckActive"; case ImGuiCol_CheckMark: return "CheckMark"; case ImGuiCol_SliderGrab: return "SliderGrab"; case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; @@ -3480,13 +3990,27 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) return "Unknown"; } -bool ImGui::GetWindowIsFocused() +bool ImGui::IsWindowFocused() { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); return g.FocusedWindow == window; } +bool ImGui::IsRootWindowFocused() +{ + ImGuiState& g = *GImGui; + ImGuiWindow* root_window = GetCurrentWindow()->RootWindow; + return g.FocusedWindow == root_window; +} + +bool ImGui::IsRootWindowOrAnyChildFocused() +{ + ImGuiState& g = *GImGui; + ImGuiWindow* root_window = GetCurrentWindow()->RootWindow; + return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window; +} + float ImGui::GetWindowWidth() { ImGuiWindow* window = GetCurrentWindow(); @@ -3504,13 +4028,14 @@ static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond co // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowPosAllowFlags & cond) == 0) return; - window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); + window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing); // Set const ImVec2 old_pos = window->Pos; window->PosFloat = pos; window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor + window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor + window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected. } void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond) @@ -3537,7 +4062,7 @@ static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowSizeAllowFlags & cond) == 0) return; - window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); + window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing); // Set if (ImLengthSqr(size) > 0.00001f) @@ -3571,7 +4096,7 @@ static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond // Test condition (NB: bit 0 is always true) and clear flags for next time if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0) return; - window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); + window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver | ImGuiSetCond_Appearing); // Set window->Collapsed = collapsed; @@ -3604,9 +4129,16 @@ void ImGui::SetWindowFocus() void ImGui::SetWindowFocus(const char* name) { - ImGuiWindow* window = FindWindowByName(name); - if (window) - FocusWindow(window); + if (name) + { + ImGuiWindow* window = FindWindowByName(name); + if (window) + FocusWindow(window); + } + else + { + FocusWindow(NULL); + } } void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond) @@ -3671,15 +4203,14 @@ ImVec2 ImGui::GetWindowContentRegionMax() float ImGui::GetTextLineHeight() { - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize(); + ImGuiState& g = *GImGui; + return g.FontSize; } float ImGui::GetTextLineHeightWithSpacing() { ImGuiState& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize() + g.Style.ItemSpacing.y; + return g.FontSize + g.Style.ItemSpacing.y; } ImDrawList* ImGui::GetWindowDrawList() @@ -3690,20 +4221,22 @@ ImDrawList* ImGui::GetWindowDrawList() ImFont* ImGui::GetWindowFont() { - ImGuiWindow* window = GetCurrentWindow(); - return window->Font(); + ImGuiState& g = *GImGui; + return g.Font; } float ImGui::GetWindowFontSize() { - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize(); + ImGuiState& g = *GImGui; + return g.FontSize; } void ImGui::SetWindowFontScale(float scale) { + ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); window->FontWindowScale = scale; + g.FontSize = window->CalcFontSize(); } // NB: internally we store CursorPos in absolute screen coordinates because it is more convenient. @@ -3728,21 +4261,21 @@ void ImGui::SetCursorPos(const ImVec2& pos) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos = window->Pos + pos; - window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, pos + ImVec2(0.0f, window->ScrollY)); + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); } void ImGui::SetCursorPosX(float x) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos.x = window->Pos.x + x; - window->SizeContentsCurrent.x = ImMax(window->SizeContentsCurrent.x, x); + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); } void ImGui::SetCursorPosY(float y) { ImGuiWindow* window = GetCurrentWindow(); window->DC.CursorPos.y = window->Pos.y + y; - window->SizeContentsCurrent.y = ImMax(window->SizeContentsCurrent.y, y + window->ScrollY); + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); } ImVec2 ImGui::GetCursorScreenPos() @@ -3796,13 +4329,13 @@ ImGuiStorage* ImGui::GetStateStorage() void ImGui::TextV(const char* fmt, va_list args) { + ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; - static char buf[1024]; - const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - TextUnformatted(buf, text_end); + const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + TextUnformatted(g.TempBuffer, text_end); } void ImGui::Text(const char* fmt, ...) @@ -3861,22 +4394,22 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) { // Long text! // Perform manual coarse clipping to optimize for long multi-line text - // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled. + // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled. // We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line. const char* line = text; const float line_height = ImGui::GetTextLineHeight(); - const ImVec2 start_pos = window->DC.CursorPos; + const ImVec2 text_pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrentLineTextBaseOffset); const ImVec4 clip_rect = window->ClipRectStack.back(); ImVec2 text_size(0,0); - if (start_pos.y <= clip_rect.w) + if (text_pos.y <= clip_rect.w) { - ImVec2 pos = start_pos; + ImVec2 pos = text_pos; // Lines to skip (can't skip when logging text) if (!g.LogEnabled) { - int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1; + int lines_skippable = (int)((clip_rect.y - text_pos.y) / line_height) - 1; if (lines_skippable > 0) { int lines_skipped = 0; @@ -3893,11 +4426,11 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) // Lines to render if (line < text_end) { - ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height)); + ImRect line_rect(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height)); while (line < text_end) { const char* line_end = strchr(line, '\n'); - if (IsClipped(line_box)) + if (IsClippedEx(line_rect, NULL, false)) break; const ImVec2 line_size = CalcTextSize(line, line_end, false); @@ -3906,8 +4439,8 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) if (!line_end) line_end = text_end; line = line_end + 1; - line_box.Min.y += line_height; - line_box.Max.y += line_height; + line_rect.Min.y += line_height; + line_rect.Max.y += line_height; pos.y += line_height; } @@ -3924,9 +4457,10 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) pos.y += lines_skipped * line_height; } - text_size.y += (pos - start_pos).y; + text_size.y += (pos - text_pos).y; } - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); + + ImRect bb(text_pos, text_pos + text_size); ItemSize(bb); ItemAdd(bb, NULL); } @@ -3934,8 +4468,13 @@ void ImGui::TextUnformatted(const char* text, const char* text_end) { const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f; const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width); - ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); - ItemSize(bb.GetSize(), &bb.Min); + + // Account of baseline offset + ImVec2 text_pos = window->DC.CursorPos; + text_pos.y += window->DC.CurrentLineTextBaseOffset; + + ImRect bb(text_pos, text_pos + text_size); + ItemSize(bb.GetSize()); if (!ItemAdd(bb, NULL)) return; @@ -3952,7 +4491,7 @@ void ImGui::AlignFirstTextHeightToWidgets() return; // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height. - ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2)); + ItemSize(ImVec2(0, g.FontSize + g.Style.FramePadding.y*2), g.Style.FramePadding.y); ImGui::SameLine(0, 0); } @@ -3963,23 +4502,23 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; + const ImGuiStyle& style = g.Style; const float w = ImGui::CalcItemWidth(); - static char buf[1024]; - const char* value_text_begin = &buf[0]; - const char* value_text_end = value_text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + const char* value_text_begin = &g.TempBuffer[0]; + const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y)); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + label_size); - ItemSize(bb); - if (!ItemAdd(value_bb, NULL)) + const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2)); + const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, NULL)) return; // Render - RenderTextClipped(value_bb.Min, value_text_begin, value_text_end, NULL, value_bb.Max); - RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label); + RenderTextClipped(ImVec2(value_bb.Min.x, value_bb.Min.y + style.FramePadding.y), value_text_begin, value_text_end, NULL, value_bb.Max); + RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label); } void ImGui::LabelText(const char* label, const char* fmt, ...) @@ -3990,36 +4529,48 @@ void ImGui::LabelText(const char* label, const char* fmt, ...) va_end(args); } -static bool IsHovered(const ImGuiAabb& bb, const ImGuiID& id) +static inline bool IsWindowContentHoverable(ImGuiWindow* window) +{ + ImGuiState& g = *GImGui; + + // An active popup disable hovering on other windows (apart from its own children) + if (ImGuiWindow* focused_window = g.FocusedWindow) + if (ImGuiWindow* focused_root_window = focused_window->RootWindow) + if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) != 0 && focused_root_window->WasActive && focused_root_window != window->RootWindow) + return false; + + return true; +} + +static bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false) { ImGuiState& g = *GImGui; if (g.HoveredId == 0) { ImGuiWindow* window = GetCurrentWindow(); - if (g.HoveredRootWindow == window->RootWindow) - { - bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb); - return hovered; - } + if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow)) + if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringRect(bb)) + if (IsWindowContentHoverable(g.HoveredRootWindow)) + return true; } return false; } -static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click) +static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = IsHovered(bb, id); bool pressed = false; + const bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0); if (hovered) { g.HoveredId = id; - if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift)) + if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { if (g.IO.MouseClicked[0]) { - if (pressed_on_click) + if (flags & ImGuiButtonFlags_PressedOnClick) { pressed = true; SetActiveId(0); @@ -4030,7 +4581,7 @@ static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_ho } FocusWindow(window); } - else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true)) + else if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && ImGui::IsMouseClicked(0, true)) { pressed = true; } @@ -4069,21 +4620,21 @@ bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_h const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f); - ItemSize(bb); + const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : (label_size.x + style.FramePadding.x*2), size_arg.y != 0.0f ? size_arg.y : (label_size.y + style.FramePadding.y*2)); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + ItemSize(bb, style.FramePadding.y); if (!ItemAdd(bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, repeat_when_held ? ImGuiButtonFlags_Repeat : 0); // Render const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path) - RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path) + RenderTextClipped(bb.Min + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path) return pressed; } @@ -4100,13 +4651,15 @@ bool ImGui::SmallButton(const char* label) const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + label_size + ImVec2(style.FramePadding.x*2,0)); + ImVec2 text_pos = window->DC.CursorPos; + text_pos.y += window->DC.CurrentLineTextBaseOffset; + ImRect bb(text_pos, text_pos + label_size + ImVec2(style.FramePadding.x*2,0)); ItemSize(bb); if (!ItemAdd(bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true); // Render const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); @@ -4125,13 +4678,13 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size) return false; const ImGuiID id = window->GetID(str_id); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); ItemSize(bb); if (!ItemAdd(bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true); return pressed; } @@ -4143,10 +4696,10 @@ static bool CloseWindowButton(bool* p_opened) const ImGuiID id = window->GetID("#CLOSE"); const float size = window->TitleBarHeight() - 4.0f; - const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size)); + const ImRect bb(window->Rect().GetTR() + ImVec2(-3.0f-size,2.0f), window->Rect().GetTR() + ImVec2(-3.0f,2.0f+size)); bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true); // Render const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); @@ -4172,7 +4725,7 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& if (window->SkipItems) return; - ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size); + ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); if (border_col.w > 0.0f) bb.Max += ImVec2(2,2); ItemSize(bb); @@ -4210,14 +4763,14 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I ImGui::PopID(); const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding; - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2); - const ImGuiAabb image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2); + const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size); ItemSize(bb); if (!ItemAdd(bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true); // Render const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); @@ -4253,7 +4806,11 @@ void ImGui::LogToFile(int max_depth, const char* filename) if (g.LogEnabled) return; if (!filename) + { filename = g.IO.LogFilename; + if (!filename) + return; + } g.LogFile = fopen(filename, "ab"); if (!g.LogFile) @@ -4313,7 +4870,7 @@ void ImGui::LogButtons() ImGui::PushID("LogButtons"); const bool log_to_tty = ImGui::Button("Log To TTY"); - ImGui::SameLine(); + ImGui::SameLine(); const bool log_to_file = ImGui::Button("Log To File"); ImGui::SameLine(); const bool log_to_clipboard = ImGui::Button("Log To Clipboard"); @@ -4387,7 +4944,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display const ImVec2 label_size = CalcTextSize(label, NULL, true); const ImVec2 pos_min = window->DC.CursorPos; const ImVec2 pos_max = window->Pos + GetContentRegionMax(); - ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y)); + ImRect bb = ImRect(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y)); if (display_frame) { bb.Min.x -= window_padding.x*0.5f - 1; @@ -4395,10 +4952,11 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display bb.Max.y += style.FramePadding.y * 2; } - const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size); - ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit + // FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize + const ImRect text_bb(bb.Min, bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2*2,0) + label_size); + ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f); - // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour). + // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior). // NB- If we are above max depth we still allow manually opened nodes to be logged. if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) opened = true; @@ -4407,7 +4965,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display return opened; bool hovered, held; - bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false); + bool pressed = ButtonBehavior(display_frame ? bb : text_bb, id, &hovered, &held, false); if (pressed) { opened = !opened; @@ -4427,7 +4985,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display const char log_prefix[] = "\n##"; LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3); } - RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + RenderText(bb.Min + style.FramePadding + ImVec2(g.FontSize + style.FramePadding.x*2,0), label); if (g.LogEnabled) { const char log_suffix[] = "##"; @@ -4439,10 +4997,10 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display // Unframed typed for tree nodes if ((held && hovered) || hovered) RenderFrame(bb.Min, bb.Max, col, false); - RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false); + RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, g.FontSize*0.15f), opened, 0.70f, false); if (g.LogEnabled) LogText(bb.Min, ">"); - RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x*2,0), label); } return opened; @@ -4456,8 +5014,8 @@ void ImGui::Bullet() return; const ImGuiStyle& style = g.Style; - const float line_height = window->FontSize(); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height)); + const float line_height = g.FontSize; + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height)); ItemSize(bb); if (!ItemAdd(bb, NULL)) return; @@ -4477,15 +5035,14 @@ void ImGui::BulletTextV(const char* fmt, va_list args) ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; - - static char buf[1024]; - const char* text_begin = buf; - const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + + const char* text_begin = g.TempBuffer; + const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); const ImGuiStyle& style = g.Style; - const float line_height = window->FontSize(); + const float line_height = g.FontSize; const ImVec2 label_size = CalcTextSize(text_begin, text_end, true); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding ItemSize(bb); if (!ItemAdd(bb, NULL)) return; @@ -4493,7 +5050,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // Render const float bullet_size = line_height*0.15f; window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); - RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end); + RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2,0), text_begin, text_end); } void ImGui::BulletText(const char* fmt, ...) @@ -4507,14 +5064,18 @@ void ImGui::BulletText(const char* fmt, ...) // If returning 'true' the node is open and the user is responsible for calling TreePop bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args) { - static char buf[1024]; - ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); if (!str_id || !str_id[0]) str_id = fmt; ImGui::PushID(str_id); - const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access + const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false); ImGui::PopID(); if (opened) @@ -4535,14 +5096,18 @@ bool ImGui::TreeNode(const char* str_id, const char* fmt, ...) // If returning 'true' the node is open and the user is responsible for calling TreePop bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args) { - static char buf[1024]; - ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); if (!ptr_id) ptr_id = fmt; ImGui::PushID(ptr_id); - const bool opened = ImGui::CollapsingHeader(buf, "", false); + const bool opened = ImGui::CollapsingHeader(g.TempBuffer, "", false); ImGui::PopID(); if (opened) @@ -4578,6 +5143,12 @@ void ImGui::PushID(const char* str_id) window->IDStack.push_back(window->GetID(str_id)); } +void ImGui::PushID(const char* str_id_begin, const char* str_id_end) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->IDStack.push_back(window->GetID(str_id_begin, str_id_end)); +} + void ImGui::PushID(const void* ptr_id) { ImGuiWindow* window = GetCurrentWindow(); @@ -4603,6 +5174,12 @@ ImGuiID ImGui::GetID(const char* str_id) return window->GetID(str_id); } +ImGuiID ImGui::GetID(const char* str_id_begin, const char* str_id_end) +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->GetID(str_id_begin, str_id_end); +} + ImGuiID ImGui::GetID(const void* ptr_id) { ImGuiWindow* window = GetCurrentWindow(); @@ -4655,152 +5232,134 @@ static void ApplyNumericalTextInput(const char* buf, float *v) *v = op_v; } -// Use power!=1.0 for logarithmic sliders. -// Adjust display_format to decorate the value with a prefix or a suffix. -bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power) +// Create text input in place of a slider (when CTRL+Clicking on slider) +static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int decimal_precision) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); - const float w = ImGui::CalcItemWidth(); + char text_buf[64]; + ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v); - if (!display_format) - display_format = "%.3f"; + SetActiveId(g.ScalarAsInputTextId); + g.HoveredId = 0; - // Parse display precision back from the display format string - int decimal_precision = 3; - if (const char* p = strchr(display_format, '%')) + // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen) + window->FocusItemUnregister(); + + bool value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); + if (g.ScalarAsInputTextId == 0) + { + // First frame + IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible) + g.ScalarAsInputTextId = g.ActiveId; + g.HoveredId = id; + } + else if (g.ActiveId != g.ScalarAsInputTextId) + { + // Release + g.ScalarAsInputTextId = 0; + } + if (value_changed) { - p++; - while (*p >= '0' && *p <= '9') - p++; - if (*p == '.') + ApplyNumericalTextInput(text_buf, v); + } + return value_changed; +} + +// Parse display precision back from the display format string +static inline void ParseFormat(const char* fmt, int& decimal_precision) +{ + while ((fmt = strchr(fmt, '%')) != NULL) + { + fmt++; + if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%" + while (*fmt >= '0' && *fmt <= '9') + fmt++; + if (*fmt == '.') { - decimal_precision = atoi(p+1); + decimal_precision = atoi(fmt + 1); if (decimal_precision < 0 || decimal_precision > 10) decimal_precision = 3; } + break; } +} - const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); - const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); +static inline float RoundScalar(float value, int decimal_precision) +{ + // Round past decimal precision + // 0: 1, 1: 0.1, 2: 0.01, etc. + // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 + // FIXME: Investigate better rounding methods + const float min_step = 1.0f / powf(10.0f, (float)decimal_precision); + const float remainder = fmodf(value, min_step); + if (remainder <= min_step*0.5f) + value -= remainder; + else + value += (min_step - remainder); + return value; +} - // NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function - if (!ItemAdd(slider_bb, &id)) - { - ItemSize(bb); - return false; - } +static bool SliderScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + const ImGuiStyle& style = g.Style; - const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); + // Draw frame + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); - const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX; + const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f; - const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision? - float grab_size_in_pixels; - if (decimal_precision > 0 || is_unbound) - grab_size_in_pixels = style.GrabMinSize; + const float padding = horizontal ? style.FramePadding.x : style.FramePadding.y; + const float slider_sz = horizontal ? (frame_bb.GetWidth() - padding * 2.0f) : (frame_bb.GetHeight() - padding * 2.0f); + float grab_sz; + if (decimal_precision > 0) + grab_sz = ImMin(style.GrabMinSize, slider_sz); else - grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), style.GrabMinSize); // Integer sliders - const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels; - const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f; - const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f; + grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit + const float slider_usable_sz = slider_sz - grab_sz; + const float slider_usable_pos_min = (horizontal ? frame_bb.Min.x : frame_bb.Min.y) + padding + grab_sz*0.5f; + const float slider_usable_pos_max = (horizontal ? frame_bb.Max.x : frame_bb.Max.y) - padding - grab_sz*0.5f; + + bool value_changed = false; // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f float linear_zero_pos = 0.0f; // 0.0->1.0f - if (!is_unbound) + if (v_min * v_max < 0.0f) { - if (v_min * v_max < 0.0f) - { - // Different sign - const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power); - const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power); - linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); - } - else - { - // Same sign - linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f; - } + // Different sign + const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power); + const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power); + linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); } - - const bool hovered = IsHovered(slider_bb, id); - if (hovered) - g.HoveredId = id; - - bool start_text_input = false; - if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) + else { - SetActiveId(id); - FocusWindow(window); - - const bool is_ctrl_down = g.IO.KeyCtrl; - if (tab_focus_requested || is_ctrl_down || is_unbound) - { - start_text_input = true; - g.SliderAsInputTextId = 0; - } + // Same sign + linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f; } - // Tabbing or CTRL-clicking through slider turns into an input box - bool value_changed = false; - if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId)) - { - char text_buf[64]; - ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v); - - SetActiveId(g.SliderAsInputTextId); - g.HoveredId = 0; - window->FocusItemUnregister(); // Our replacement slider will override the focus ID (registered previously to allow for a TAB focus to happen) - value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); - if (g.SliderAsInputTextId == 0) - { - // First frame - IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible) - g.SliderAsInputTextId = g.ActiveId; - g.HoveredId = id; - } - else if (g.ActiveId != g.SliderAsInputTextId) - { - // Release - g.SliderAsInputTextId = 0; - } - if (value_changed) - { - ApplyNumericalTextInput(text_buf, v); - } - return value_changed; - } - - ItemSize(bb); - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); - // Process clicking on the slider if (g.ActiveId == id) { if (g.IO.MouseDown[0]) { - if (!is_unbound) - { - const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f); - - // Linear slider - //float new_value = ImLerp(v_min, v_max, normalized_pos); + const float mouse_abs_pos = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y; + float normalized_pos = ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f); + if (!horizontal) + normalized_pos = 1.0f - normalized_pos; + float new_value; + if (is_non_linear) + { // Account for logarithmic scale on both sides of the zero - float new_value; if (normalized_pos < linear_zero_pos) { // Negative: rescale to the negative range before powering float a = 1.0f - (normalized_pos / linear_zero_pos); a = powf(a, power); - new_value = ImLerp(ImMin(v_max,0.f), v_min, a); + new_value = ImLerp(ImMin(v_max,0.0f), v_min, a); } else { @@ -4813,22 +5372,20 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c a = powf(a, power); new_value = ImLerp(ImMax(v_min,0.0f), v_max, a); } + } + else + { + // Linear slider + new_value = ImLerp(v_min, v_max, normalized_pos); + } - // Round past decimal precision - // 0->1, 1->0.1, 2->0.01, etc. - // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 - const float min_step = 1.0f / powf(10.0f, (float)decimal_precision); - const float remainder = fmodf(new_value, min_step); - if (remainder <= min_step*0.5f) - new_value -= remainder; - else - new_value += (min_step - remainder); + // Round past decimal precision + new_value = RoundScalar(new_value, decimal_precision); - if (*v != new_value) - { - *v = new_value; - value_changed = true; - } + if (*v != new_value) + { + *v = new_value; + value_changed = true; } } else @@ -4837,13 +5394,10 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c } } - if (!is_unbound) + // Calculate slider grab positioning + float grab_t; + if (is_non_linear) { - // Linear slider - // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min); - - // Calculate slider grab positioning - float grab_t; float v_clamped = ImClamp(*v, v_min, v_max); if (v_clamped < 0.0f) { @@ -4855,29 +5409,152 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); } + } + else + { + // Linear slider + grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min); + } + + // Draw + if (!horizontal) + grab_t = 1.0f - grab_t; + const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t); + ImRect grab_bb; + if (horizontal) + grab_bb = ImRect(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + 2.0f), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - 2.0f)); + else + grab_bb = ImRect(ImVec2(frame_bb.Min.x + 2.0f, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - 2.0f, grab_pos + grab_sz*0.5f)); + window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab)); + + return value_changed; +} + +// Use power!=1.0 for logarithmic sliders. +// Adjust display_format to decorate the value with a prefix or a suffix. +// "%.3f" 1.234 +// "%5.2f secs" 01.23 secs +// "Gold: %.0f" Gold: 1 +bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = ImGui::CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + // NB- we don't call ItemSize() yet because we may turn into a text edit box below + if (!ItemAdd(total_bb, &id)) + { + ItemSize(total_bb, style.FramePadding.y); + return false; + } + + const bool hovered = IsHovered(frame_bb, id); + if (hovered) + g.HoveredId = id; + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = 3; + ParseFormat(display_format, decimal_precision); + + // Tabbing or CTRL-clicking on Slider turns it into an input box + bool start_text_input = false; + const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); + if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) + { + SetActiveId(id); + FocusWindow(window); + + const bool is_ctrl_down = g.IO.KeyCtrl; + if (tab_focus_requested || is_ctrl_down) + { + start_text_input = true; + g.ScalarAsInputTextId = 0; + } + } + if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) + return SliderFloatAsInputText(label, v, id, decimal_precision); + + ItemSize(total_bb, style.FramePadding.y); + + // Actual slider behavior + render grab + const bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, true); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + char value_buf[64]; + const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true); + RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, frame_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); - // Draw - const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t); - const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-2.0f)); - window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab)); + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + + return value_changed; +} + +bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size); + const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + ItemSize(bb, style.FramePadding.y); + if (!ItemAdd(frame_bb, &id)) + return false; + + const bool hovered = IsHovered(frame_bb, id); + if (hovered) + g.HoveredId = id; + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = 3; + ParseFormat(display_format, decimal_precision); + + if (hovered && g.IO.MouseClicked[0]) + { + SetActiveId(id); + FocusWindow(window); } - // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value. + // Actual slider behavior + render grab + bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, false); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + // For the vertical slider we allow centered text to overlap the frame padding char value_buf[64]; char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true); - RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); + RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x, frame_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label); + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); return value_changed; } -bool ImGui::SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max) +bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max) { - float v_deg = *v * 360.0f / (2*PI); + float v_deg = (*v_rad) * 360.0f / (2*PI); bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f); - *v = v_deg * (2*PI) / 360.0f; + *v_rad = v_deg * (2*PI) / 360.0f; return value_changed; } @@ -4891,38 +5568,40 @@ bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const cha return value_changed; } +bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = ImGui::VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + *v = (int)v_f; + return value_changed; +} + // Add multiple sliders on 1 line for compact edition of multiple components -static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power) +static bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - const ImGuiStyle& style = g.Style; - const float w_full = ImGui::CalcItemWidth(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1))); - bool value_changed = false; + ImGui::BeginGroup(); ImGui::PushID(label); - ImGui::PushItemWidth(w_item_one); + PushMultiItemsWidths(components); for (int i = 0; i < components; i++) { ImGui::PushID(i); - if (i + 1 == components) - { - ImGui::PopItemWidth(); - ImGui::PushItemWidth(w_item_last); - } value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); ImGui::PopID(); + ImGui::PopItemWidth(); } - ImGui::PopItemWidth(); ImGui::PopID(); ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); return value_changed; } @@ -4942,37 +5621,29 @@ bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max return SliderFloatN(label, v, 4, v_min, v_max, display_format, power); } -static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format) +static bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - const ImGuiStyle& style = g.Style; - const float w_full = ImGui::CalcItemWidth(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1))); - bool value_changed = false; + ImGui::BeginGroup(); ImGui::PushID(label); - ImGui::PushItemWidth(w_item_one); + PushMultiItemsWidths(components); for (int i = 0; i < components; i++) { ImGui::PushID(i); - if (i + 1 == components) - { - ImGui::PopItemWidth(); - ImGui::PushItemWidth(w_item_last); - } value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); ImGui::PopID(); + ImGui::PopItemWidth(); } - ImGui::PopItemWidth(); ImGui::PopID(); ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); return value_changed; } @@ -4992,6 +5663,244 @@ bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const return SliderIntN(label, v, 4, v_min, v_max, display_format); } +// FIXME-WIP: Work in progress. May change API / behavior. +static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + const ImGuiStyle& style = g.Style; + + // Draw frame + const ImU32 frame_col = window->Color(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); + RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding); + + bool value_changed = false; + + // Process clicking on the drag + if (g.ActiveId == id) + { + if (g.IO.MouseDown[0]) + { + if (g.ActiveIdIsJustActivated) + { + // Lock current value on click + g.DragCurrentValue = *v; + g.DragLastMouseDelta = ImVec2(0.f, 0.f); + } + + const ImVec2 mouse_drag_delta = ImGui::GetMouseDragDelta(0, 1.0f); + if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f) + { + float speed = v_speed; + if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX) + speed = (v_max - v_min) * g.DragSpeedDefaultRatio; + if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f) + speed = speed * g.DragSpeedScaleFast; + if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) + speed = speed * g.DragSpeedScaleSlow; + + float v_cur = g.DragCurrentValue; + float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed; + if (fabsf(power - 1.0f) > 0.001f) + { + // Logarithmic curve on both side of 0.0 + float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur; + float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f; + float v1 = powf(v0_abs, 1.0f / power) + (delta * v0_sign); + float v1_abs = v1 >= 0.0f ? v1 : -v1; + float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line + v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign + } + else + { + v_cur += delta; + } + g.DragLastMouseDelta.x = mouse_drag_delta.x; + + // Clamp + if (v_min < v_max) + v_cur = ImClamp(v_cur, v_min, v_max); + g.DragCurrentValue = v_cur; + + // Round to user desired precision, then apply + v_cur = RoundScalar(v_cur, decimal_precision); + if (*v != v_cur) + { + *v = v_cur; + value_changed = true; + } + } + } + else + { + SetActiveId(0); + } + } + + return value_changed; +} + +bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = ImGui::CalcItemWidth(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + + // NB- we don't call ItemSize() yet because we may turn into a text edit box below + if (!ItemAdd(total_bb, &id)) + { + ItemSize(total_bb, style.FramePadding.y); + return false; + } + + const bool hovered = IsHovered(frame_bb, id); + if (hovered) + g.HoveredId = id; + + if (!display_format) + display_format = "%.3f"; + int decimal_precision = 3; + ParseFormat(display_format, decimal_precision); + + // Tabbing or CTRL-clicking on Drag turns it into an input box + bool start_text_input = false; + const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); + if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0]))) + { + SetActiveId(id); + FocusWindow(window); + + if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0]) + { + start_text_input = true; + g.ScalarAsInputTextId = 0; + } + } + if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) + return SliderFloatAsInputText(label, v, id, decimal_precision); + + ItemSize(total_bb, style.FramePadding.y); + + // Actual drag behavior + const bool value_changed = DragScalarBehavior(frame_bb, id, v, v_speed, v_min, v_max, decimal_precision, power); + + // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. + char value_buf[64]; + const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true); + RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, inner_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); + + if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); + + return value_changed; +} + +static bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + bool value_changed = false; + ImGui::BeginGroup(); + ImGui::PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + value_changed |= ImGui::DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::PopID(); + ImGui::PopItemWidth(); + } + ImGui::PopID(); + + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); + + return value_changed; +} + +bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power); +} + +bool ImGui::DragFloat3(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power); +} + +bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power) +{ + return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power); +} + +// NB: v_speed is float to allow adjusting the drag speed with more precision +bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format) +{ + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool value_changed = ImGui::DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, display_format); + *v = (int)v_f; + return value_changed; +} + +static bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + bool value_changed = false; + ImGui::BeginGroup(); + ImGui::PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + value_changed |= ImGui::DragInt("##v", &v[i], v_speed, v_min, v_max, display_format); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::PopID(); + ImGui::PopItemWidth(); + } + ImGui::PopID(); + + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); + + return value_changed; +} + +bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format); +} + +bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format); +} + +bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format) +{ + return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format); +} + enum ImGuiPlotType { ImGuiPlotType_Lines, @@ -5009,15 +5918,15 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); if (graph_size.x == 0.0f) - graph_size.x = ImGui::CalcItemWidth(); + graph_size.x = ImGui::CalcItemWidth() + (style.FramePadding.x * 2); if (graph_size.y == 0.0f) - graph_size.y = label_size.y; + graph_size.y = label_size.y + (style.FramePadding.y * 2); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f); - const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); - ItemSize(bb); - if (!ItemAdd(bb, NULL)) + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y)); + const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, NULL)) return; // Determine scale from values if not specified @@ -5045,12 +5954,12 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett // Tooltip on hover int v_hovered = -1; - if (IsMouseHoveringBox(graph_bb)) + if (IsMouseHoveringRect(inner_bb)) { - const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f); + const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); IM_ASSERT(v_idx >= 0 && v_idx < values_count); - + const float v0 = values_getter(data, (v_idx + values_offset) % values_count); const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count); if (plot_type == ImGuiPlotType_Lines) @@ -5079,9 +5988,9 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett // NB- Draw calls are merged together by the DrawList system. if (plot_type == ImGuiPlotType_Lines) - window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base); + window->DrawList->AddLine(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base); else if (plot_type == ImGuiPlotType_Histogram) - window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base); + window->DrawList->AddRectFilled(ImLerp(inner_bb.Min, inner_bb.Max, p0), ImLerp(inner_bb.Min, inner_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base); t0 = t1; p0 = p1; @@ -5089,9 +5998,9 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett // Text overlay if (overlay_text) - RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text); + RenderTextClipped(ImVec2(ImMax(inner_bb.Min.x, inner_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f), frame_bb.Min.y + style.FramePadding.y), overlay_text, NULL, NULL, frame_bb.Max); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); } struct ImGuiPlotArrayGetterData @@ -5142,28 +6051,28 @@ bool ImGui::Checkbox(const char* label, bool* v) const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2)); - ItemSize(check_bb); + const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2)); + ItemSize(check_bb, style.FramePadding.y); - ImGuiAabb total_bb = check_bb; + ImRect total_bb = check_bb; if (label_size.x > 0) SameLine(0, (int)style.ItemInnerSpacing.x); - const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size); + const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size); if (label_size.x > 0) { - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y); + total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); } if (!ItemAdd(total_bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true); if (pressed) *v = !(*v); - RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), true, style.FrameRounding); + RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding); if (*v) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); @@ -5200,16 +6109,16 @@ bool ImGui::RadioButton(const char* label, bool active) const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1)); - ItemSize(check_bb); + const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1)); + ItemSize(check_bb, style.FramePadding.y); - ImGuiAabb total_bb = check_bb; + ImRect total_bb = check_bb; if (label_size.x > 0) SameLine(0, (int)style.ItemInnerSpacing.x); - const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size); + const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size); if (label_size.x > 0) { - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y); total_bb.Add(text_bb); } @@ -5222,9 +6131,9 @@ bool ImGui::RadioButton(const char* label, bool active) const float radius = check_bb.GetHeight() * 0.5f; bool hovered, held; - bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true); - window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); + window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16); if (active) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); @@ -5284,9 +6193,9 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) obj->CurLenW -= n; // Offset remaining text - const ImWchar* src = obj->Text + pos + n; + const ImWchar* src = obj->Text + pos + n; while (ImWchar c = *src++) - *dst++ = c; + *dst++ = c; *dst = '\0'; } @@ -5311,24 +6220,22 @@ static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const Im return true; } -enum -{ - STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left - STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right - STB_TEXTEDIT_K_UP, // keyboard input to move cursor up - STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down - STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line - STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line - STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text - STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text - STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor - STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor - STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo - STB_TEXTEDIT_K_REDO, // keyboard input to perform redo - STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word - STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word - STB_TEXTEDIT_K_SHIFT = 1 << 17 -}; +// We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols) +#define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left +#define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right +#define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up +#define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down +#define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line +#define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line +#define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text +#define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text +#define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor +#define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor +#define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo +#define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo +#define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word +#define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word +#define STB_TEXTEDIT_K_SHIFT 0x20000 #ifdef IMGUI_STB_NAMESPACE namespace IMGUI_STB_NAMESPACE @@ -5341,9 +6248,9 @@ namespace IMGUI_STB_NAMESPACE #endif void ImGuiTextEditState::OnKeyPressed(int key) -{ - stb_textedit_key(this, &StbState, key); - CursorAnimReset(); +{ + stb_textedit_key(this, &StbState, key); + CursorAnimReset(); } void ImGuiTextEditState::UpdateScrollOffset() @@ -5351,9 +6258,21 @@ void ImGuiTextEditState::UpdateScrollOffset() // Scroll in chunks of quarter width const float scroll_x_increment = Width * 0.25f; const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x; - if (ScrollX > cursor_offset_x) - ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment); - else if (ScrollX < cursor_offset_x - Width) + + // If widget became bigger than text (because of a resize), reset horizontal scrolling + if (ScrollX > 0.0f) + { + const float text_width = cursor_offset_x + Font->CalcTextSizeW(FontSize, FLT_MAX, Text+StbState.cursor, NULL, NULL).x; + if (text_width < Width) + { + ScrollX = 0.0f; + return; + } + } + + if (cursor_offset_x < ScrollX) + ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment); + else if (cursor_offset_x - Width >= ScrollX) ScrollX = cursor_offset_x - Width + scroll_x_increment; } @@ -5363,7 +6282,7 @@ ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display IM_ASSERT(text_end >= text_start); - const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width, text_start, text_end, NULL); + const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width+1, text_start, text_end, NULL); return offset; } @@ -5396,30 +6315,19 @@ const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float fo // [Static] void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x) { - // NB- We start drawing at character boundary - ImVec2 text_size; - const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL); - const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size); - - // We need to test for the possibility of malformed UTF-8 (instead of just text_end[0] != 0) - unsigned int text_end_char = 0; - ImTextCharFromUtf8(&text_end_char, text_end, NULL); - - // Draw a little clip symbol if we've got text on either left or right of the box - const char symbol_c = '~'; - const float symbol_w = font_size*0.40f; // FIXME: compute correct width - const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f; - const float clip_end = (text_end_char != 0 && text_end > text_start) ? symbol_w : 0.0f; + ImGuiWindow* window = GetCurrentWindow(); + const ImU32 font_color = window->Color(ImGuiCol_Text); + //window->DrawList->AddLine(pos, pos+ImVec2(width,0), 0xFF00FFFF); - // Draw text - RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false); + // Determine start and end of visible string + // FIXME-OPT: This is pretty slow for what it does. + const char* text_start = scroll_x <= 0.0f ? buf : GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL); + const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width + 1, NULL); // +1 to allow character spacing to fit outside the allowed width + window->DrawList->AddText(font, font_size, pos, font_color, text_start, text_end); - // Draw the clip symbol - const char s[2] = {symbol_c,'\0'}; - if (clip_begin > 0.0f) - RenderText(pos, s); - if (clip_end > 0.0f) - RenderText(pos+ImVec2(width-clip_end,0.0f), s); + // Log as text + if (GImGui->LogEnabled) + LogText(pos, buf, NULL); } bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags) @@ -5432,12 +6340,13 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, const ImGuiStyle& style = g.Style; const float w = ImGui::CalcItemWidth(); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + ImGui::BeginGroup(); ImGui::PushID(label); - const float button_sz = window->FontSize(); + const ImVec2 button_sz = ImVec2(g.FontSize, g.FontSize) + style.FramePadding * 2; if (step > 0.0f) - ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*2)); + ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2)); char buf[64]; if (decimal_precision < 0) @@ -5457,13 +6366,13 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, { ImGui::PopItemWidth(); ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - if (ImGui::Button("-", ImVec2(button_sz,button_sz), true)) + if (ImGui::Button("-", button_sz, true)) { *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; value_changed = true; } ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - if (ImGui::Button("+", ImVec2(button_sz,button_sz), true)) + if (ImGui::Button("+", button_sz, true)) { *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; value_changed = true; @@ -5475,10 +6384,12 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, if (label_size.x > 0) { ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - ItemSize(label_size); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label); + ItemSize(label_size, style.FramePadding.y); } + ImGui::EndGroup(); + return value_changed; } @@ -5565,8 +6476,8 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f { ImGuiTextEditCallbackData callback_data; memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData)); - callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; - callback_data.EventChar = ImWchar(c); + callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; + callback_data.EventChar = (ImWchar)c; callback_data.Flags = flags; callback_data.UserData = user_data; if (callback(&callback_data) != 0) @@ -5594,10 +6505,10 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const float w = ImGui::CalcItemWidth(); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); - ItemSize(bb); - if (!ItemAdd(frame_bb, &id)) + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, &id)) return false; // NB: we are only allowed to access 'edit_state' if we are the active widget. @@ -5605,13 +6516,17 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT const bool is_ctrl_down = io.KeyCtrl; const bool is_shift_down = io.KeyShift; + const bool is_alt_down = io.KeyAlt; const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent); const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code; const bool hovered = IsHovered(frame_bb, id); if (hovered) + { g.HoveredId = id; + g.MouseCursor = ImGuiMouseCursor_TextInput; + } const bool user_clicked = hovered && io.MouseClicked[0]; bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0; @@ -5624,9 +6539,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT // From the moment we focused we are ignoring the content of 'buf' ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf); const char* buf_end = NULL; - edit_state.CurLenW = (int)ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end); - edit_state.CurLenA = (int)(buf_end - buf); // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. - edit_state.Width = w; + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end); + edit_state.CurLenA = buf_end - buf; // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. + edit_state.Width = w + style.FramePadding.x; edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f); edit_state.CursorAnimReset(); @@ -5634,7 +6549,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT { edit_state.Id = id; edit_state.ScrollX = 0.0f; - stb_textedit_initialize_state(&edit_state.StbState, true); + stb_textedit_initialize_state(&edit_state.StbState, true); if (focus_requested_by_code) select_all = true; } @@ -5642,9 +6557,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT { // Recycle existing cursor/selection/undo stack but clamp position // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler. - edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, edit_state.CurLenW); - edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, edit_state.CurLenW); - edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, edit_state.CurLenW); + edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, (int)edit_state.CurLenW); + edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, (int)edit_state.CurLenW); + edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, (int)edit_state.CurLenW); } if (focus_requested_by_tab || (user_clicked && is_ctrl_down)) select_all = true; @@ -5669,18 +6584,22 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT bool value_changed = false; bool cancel_edit = false; bool enter_pressed = false; - static char text_tmp_utf8[IM_ARRAYSIZE(edit_state.InitialText)]; if (g.ActiveId == id) + //if (edit_state.Id == id) // Works, but double-click to select-all sets cursors to end which in turn tends to scroll toward the right when shrinking widget. { - // Edit in progress + // Update some data if we are active or last active + edit_state.Width = w + style.FramePadding.x; edit_state.BufSizeA = buf_size; - edit_state.Font = window->Font(); - edit_state.FontSize = window->FontSize(); - + edit_state.Font = g.Font; + edit_state.FontSize = g.FontSize; + edit_state.UpdateScrollOffset(); + } + if (g.ActiveId == id) + { + // Edit in progress const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x; - const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit + const float my = g.FontSize*0.5f; // Flatten mouse because we are doing a single-line edit - edit_state.UpdateScrollOffset(); if (select_all || (hovered && io.MouseDoubleClicked[0])) { edit_state.SelectAll(); @@ -5690,7 +6609,6 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT { stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my); edit_state.CursorAnimReset(); - } else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock) { @@ -5698,7 +6616,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT edit_state.CursorAnimReset(); } if (edit_state.SelectedAllMouseLock && !io.MouseDown[0]) - edit_state.SelectedAllMouseLock = false; + edit_state.SelectedAllMouseLock = false; if (g.IO.InputCharacters[0]) { @@ -5720,6 +6638,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT } const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0); + const bool is_ctrl_only = is_ctrl_down && !is_alt_down && !is_shift_down; if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); } else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); } else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } @@ -5728,10 +6647,10 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); } else if (IsKeyPressedMap(ImGuiKey_Enter)) { SetActiveId(0); enter_pressed = true; } else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveId(0); cancel_edit = true; } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); } - else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C))) + else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); } + else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); } + else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); } + else if (is_ctrl_only && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C))) { // Cut, Copy const bool cut = IsKeyPressedMap(ImGuiKey_X); @@ -5741,15 +6660,15 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (g.IO.SetClipboardTextFn) { const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; - const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW; - ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie); - g.IO.SetClipboardTextFn(text_tmp_utf8); + const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)edit_state.CurLenW; + ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text+ib, edit_state.Text+ie); + g.IO.SetClipboardTextFn(g.TempBuffer); } if (cut) stb_textedit_cut(&edit_state, &edit_state.StbState); } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V)) + else if (is_ctrl_only && IsKeyPressedMap(ImGuiKey_V)) { // Paste if (g.IO.GetClipboardTextFn) @@ -5795,7 +6714,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT // Note that as soon as we can focus into the input box, the in-widget value gets priority over any underlying modification of the input buffer // FIXME: We actually always render 'buf' in RenderTextScrolledClipped // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks - ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text, NULL); + ImTextStrToUtf8(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), edit_state.Text, NULL); // User callback if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0) @@ -5824,9 +6743,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0) { ImGuiTextEditCallbackData callback_data; - callback_data.EventFlag = event_flag; + callback_data.EventFlag = event_flag; callback_data.EventKey = event_key; - callback_data.Buf = text_tmp_utf8; + callback_data.Buf = g.TempBuffer; callback_data.BufSize = edit_state.BufSizeA; callback_data.BufDirty = false; callback_data.Flags = flags; @@ -5841,7 +6760,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT callback(&callback_data); // Read back what user may have modified - IM_ASSERT(callback_data.Buf == text_tmp_utf8); // Invalid to modify those fields + IM_ASSERT(callback_data.Buf == g.TempBuffer); // Invalid to modify those fields IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA); IM_ASSERT(callback_data.Flags == flags); if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); @@ -5849,24 +6768,25 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd); if (callback_data.BufDirty) { - ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), text_tmp_utf8, NULL); + edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), g.TempBuffer, NULL); + edit_state.CurLenA = strlen(g.TempBuffer); edit_state.CursorAnimReset(); } } } - if (strcmp(text_tmp_utf8, buf) != 0) + if (strcmp(g.TempBuffer, buf) != 0) { - ImFormatString(buf, buf_size, "%s", text_tmp_utf8); + ImFormatString(buf, buf_size, "%s", g.TempBuffer); value_changed = true; } } } - + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); - const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API - const ImVec2 font_off_dn = ImVec2(0.0f,2.0f); + const ImVec2 font_off_up = ImVec2(0.0f, g.FontSize+1.0f); // FIXME: those offsets are part of the style or font API + const ImVec2 font_off_dn = ImVec2(0.0f, 2.0f); if (g.ActiveId == id) { @@ -5881,7 +6801,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT } } - ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f); + //const float render_scroll_x = (g.ActiveId == id) ? edit_state.ScrollX : 0.0f; + const float render_scroll_x = (edit_state.Id == id) ? edit_state.ScrollX : 0.0f; + ImGuiTextEditState::RenderTextScrolledClipped(g.Font, g.FontSize, buf, frame_bb.Min + style.FramePadding, w + style.FramePadding.x, render_scroll_x); if (g.ActiveId == id) { @@ -5890,10 +6812,10 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT // Draw blinking cursor if (g.InputTextState.CursorIsVisible()) window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text)); - + // Notify OS of text input position for advanced IME if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f) - io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. + io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - g.FontSize)); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. edit_state.InputCursorScreenPos = cursor_pos; } @@ -5907,54 +6829,90 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT return value_changed; } -static bool InputFloatN(const char* label, float* v, int components, int decimal_precision) +static bool InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - const ImGuiStyle& style = g.Style; - const float w_full = ImGui::CalcItemWidth(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); + bool value_changed = false; + ImGui::BeginGroup(); + ImGui::PushID(label); + PushMultiItemsWidths(components); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision, extra_flags); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::PopID(); + ImGui::PopItemWidth(); + } + ImGui::PopID(); + + window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); + + return value_changed; +} + +bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 2, decimal_precision, extra_flags); +} + +bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 3, decimal_precision, extra_flags); +} + +bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags) +{ + return InputFloatN(label, v, 4, decimal_precision, extra_flags); +} + +static bool InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags) +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; bool value_changed = false; + ImGui::BeginGroup(); ImGui::PushID(label); - ImGui::PushItemWidth(w_item_one); + PushMultiItemsWidths(components); for (int i = 0; i < components; i++) { ImGui::PushID(i); - if (i + 1 == components) - { - ImGui::PopItemWidth(); - ImGui::PushItemWidth(w_item_last); - } - value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + value_changed |= ImGui::InputInt("##v", &v[i], 0, 0, extra_flags); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); ImGui::PopID(); + ImGui::PopItemWidth(); } - ImGui::PopItemWidth(); ImGui::PopID(); + window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y); ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::EndGroup(); return value_changed; } -bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision) +bool ImGui::InputInt2(const char* label, int v[2], ImGuiInputTextFlags extra_flags) { - return InputFloatN(label, v, 2, decimal_precision); + return InputIntN(label, v, 2, extra_flags); } -bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision) +bool ImGui::InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags) { - return InputFloatN(label, v, 3, decimal_precision); + return InputIntN(label, v, 3, extra_flags); } -bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision) +bool ImGui::InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags) { - return InputFloatN(label, v, 4, decimal_precision); + return InputIntN(label, v, 4, extra_flags); } static bool Items_ArrayGetter(void* data, int idx, const char** out_text) @@ -6019,17 +6977,17 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const float w = ImGui::CalcItemWidth(); const ImVec2 label_size = CalcTextSize(label, NULL, true); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0)); - ItemSize(bb); - if (!ItemAdd(frame_bb, &id)) + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); + const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, &id)) return false; - const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); + const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f); const bool hovered = IsHovered(frame_bb, id); bool value_changed = false; - const ImGuiAabb value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f)); + const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f)); RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true); @@ -6043,7 +7001,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi if (label_size.x > 0) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - + ImGui::PushID((int)id); bool menu_toggled = false; if (hovered) @@ -6057,7 +7015,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi FocusWindow(window); } } - + if (g.ActiveComboID == id) { // Size default to hold ~7 items @@ -6066,12 +7024,13 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const ImVec2 backup_pos = ImGui::GetCursorPos(); const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x; - const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y; - const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); - ImGui::SetCursorPos(popup_aabb.Min - window->Pos); + const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + (style.FramePadding.y * 3); + const ImRect popup_rect(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); + ImGui::SetCursorPos(popup_rect.Min - window->Pos); const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0); - ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding); + ImGui::BeginChild("#ComboBox", popup_rect.GetSize(), false, flags); ImGui::Spacing(); bool combo_item_active = false; @@ -6098,8 +7057,9 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi ImGui::PopID(); } ImGui::EndChild(); + ImGui::PopStyleVar(); ImGui::SetCursorPos(backup_pos); - + if (!combo_item_active && g.ActiveId != 0) g.ActiveComboID = 0; } @@ -6121,14 +7081,16 @@ bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - - const float w = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x; + + const float w = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - style.WindowPadding.x - window->DC.CursorPos.x); const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size); + ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); ItemSize(bb); + if (size_arg.x == 0.0f) + bb.Max.x += style.WindowPadding.x; // Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing. - ImGuiAabb bb_with_spacing = bb; + ImRect bb_with_spacing = bb; const float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f); const float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f); const float spacing_R = style.ItemSpacing.x - spacing_L; @@ -6141,7 +7103,7 @@ bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb_with_spacing, id, &hovered, &held, true, false, false); + bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true); // Render if (hovered || selected) @@ -6178,13 +7140,14 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar. ImVec2 size; - size.x = (size_arg.x != 0.0f) ? size_arg.x : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f; - size.y = (size_arg.y != 0.0f) ? size_arg.y : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y; + size.x = (size_arg.x != 0.0f) ? (size_arg.x) : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f; + size.y = (size_arg.y != 0.0f) ? (size_arg.y) : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y; const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y)); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); - window->DC.LastItemAabb = bb; + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); + const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); + window->DC.LastItemRect = bb; + ImGui::BeginGroup(); if (label_size.x > 0) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); @@ -6211,12 +7174,17 @@ bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_item void ImGui::ListBoxFooter() { ImGuiWindow* parent_window = GetParentWindow(); - const ImGuiAabb bb = parent_window->DC.LastItemAabb; - + const ImRect bb = parent_window->DC.LastItemRect; + const ImGuiStyle& style = ImGui::GetStyle(); + ImGui::EndChildFrame(); + // Redeclare item size so that it includes the label (we have stored the full size in LastItemRect) + // We call SameLine() to restore DC.CurrentLine* data + ImGui::SameLine(); parent_window->DC.CursorPos = bb.Min; - ItemSize(bb, NULL); + ItemSize(bb, style.FramePadding.y); + ImGui::EndGroup(); } bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items) @@ -6255,6 +7223,41 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v return value_changed; } +bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected) +{ + (void)shortcut; // FIXME-MENU: Shortcut are not supported yet. Argument is reserved. + + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImVec2 pos = ImGui::GetCursorScreenPos(); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + const float symbol_spacing = (float)(int)(g.FontSize * 1.50f + 0.5f); + const float w = ImMax(label_size.x + symbol_spacing, window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x); // Feedback to next frame + bool ret = ImGui::Selectable(label, false, ImVec2(w, 0.0f)); + + if (selected) + { + pos.x = window->Pos.x + ImGui::GetContentRegionMax().x - g.FontSize; + RenderCheckMark(pos, window->Color(ImGuiCol_Text)); + } + + return ret; +} + +bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected) +{ + if (ImGui::MenuItem(label, shortcut, p_selected ? *p_selected : false)) + { + if (p_selected) + *p_selected = !*p_selected; + return true; + } + return false; +} + // A little colored square. Return true when clicked. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border) { @@ -6265,14 +7268,14 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID("#colorbutton"); - const float square_size = window->FontSize(); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); - ItemSize(bb); + const float square_size = g.FontSize; + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); + ItemSize(bb, small_height ? 0.0f : style.FramePadding.y); if (!ItemAdd(bb, &id)) return false; bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true); RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding); if (hovered) @@ -6313,59 +7316,54 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); const float w_full = ImGui::CalcItemWidth(); - const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f); + const float square_sz = (g.FontSize + style.FramePadding.x * 2.0f); ImGuiColorEditMode edit_mode = window->DC.ColorEditMode; if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton) edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3; - float fx = col[0]; - float fy = col[1]; - float fz = col[2]; - float fw = col[3]; - const ImVec4 col_display(fx, fy, fz, 1.0f); + float f[4] = { col[0], col[1], col[2], col[3] }; if (edit_mode == ImGuiColorEditMode_HSV) - ImGui::ColorConvertRGBtoHSV(fx, fy, fz, fx, fy, fz); + ImGui::ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); - int ix = (int)(fx * 255.0f + 0.5f); - int iy = (int)(fy * 255.0f + 0.5f); - int iz = (int)(fz * 255.0f + 0.5f); - int iw = (int)(fw * 255.0f + 0.5f); + int i[4] = { (int)(f[0] * 255.0f + 0.5f), (int)(f[1] * 255.0f + 0.5f), (int)(f[2] * 255.0f + 0.5f), (int)(f[3] * 255.0f + 0.5f) }; int components = alpha ? 4 : 3; bool value_changed = false; + ImGui::BeginGroup(); ImGui::PushID(label); - bool hsv = (edit_mode == 1); + const bool hsv = (edit_mode == 1); switch (edit_mode) { case ImGuiColorEditMode_RGB: case ImGuiColorEditMode_HSV: { - // 0: RGB 0..255 Sliders - // 1: HSV 0..255 Sliders + // RGB/HSV 0..255 Sliders const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x); const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components)); const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1))); - ImGui::PushItemWidth(w_item_one); - value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f"); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f"); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - if (alpha) + const bool hide_prefix = (w_item_one <= CalcTextSize("M:999").x); + const char* ids[4] = { "##X", "##Y", "##Z", "##W" }; + const char* fmt_table[3][4] = { - value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - ImGui::PushItemWidth(w_item_last); - value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f"); - } - else + { "%3.0f", "%3.0f", "%3.0f", "%3.0f" }, + { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" }, + { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" } + }; + const char** fmt = hide_prefix ? fmt_table[0] : hsv ? fmt_table[2] : fmt_table[1]; + + ImGui::PushItemWidth(w_item_one); + for (int n = 0; n < components; n++) { - ImGui::PushItemWidth(w_item_last); - value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); + if (n > 0) + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + if (n + 1 == components) + ImGui::PushItemWidth(w_item_last); + value_changed |= ImGui::DragInt(ids[n], &i[n], 1.0f, 0, 255, fmt[n]); } ImGui::PopItemWidth(); ImGui::PopItemWidth(); @@ -6373,46 +7371,42 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) break; case ImGuiColorEditMode_HEX: { - // 2: RGB Hexadecimal + // RGB Hexadecimal Input const float w_slider_all = w_full - square_sz; char buf[64]; if (alpha) - sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw); + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", i[0], i[1], i[2], i[3]); else - sprintf(buf, "#%02X%02X%02X", ix, iy, iz); + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", i[0], i[1], i[2]); ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x); - value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal); + value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); ImGui::PopItemWidth(); char* p = buf; - while (*p == '#' || ImCharIsSpace(*p)) + while (*p == '#' || ImCharIsSpace(*p)) p++; // Treat at unsigned (%X is unsigned) - ix = iy = iz = iw = 0; + i[0] = i[1] = i[2] = i[3] = 0; if (alpha) - sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw); + sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]); else - sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz); + sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]); } break; } ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + + const ImVec4 col_display(col[0], col[1], col[2], 1.0f); if (ImGui::ColorButton(col_display)) - { - // Don't set local copy of 'edit_mode' right away! - g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); - } + g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away! if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton) { ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); const char* button_titles[3] = { "RGB", "HSV", "HEX" }; if (ImGui::Button(button_titles[edit_mode])) - { - // Don't set local copy of 'edit_mode' right away! - g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); - } + g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); // Don't set local copy of 'edit_mode' right away! ImGui::SameLine(); } else @@ -6423,23 +7417,22 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); // Convert back - fx = ix / 255.0f; - fy = iy / 255.0f; - fz = iz / 255.0f; - fw = iw / 255.0f; + for (int n = 0; n < 4; n++) + f[n] = i[n] / 255.0f; if (edit_mode == 1) - ImGui::ColorConvertHSVtoRGB(fx, fy, fz, fx, fy, fz); + ImGui::ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); if (value_changed) { - col[0] = fx; - col[1] = fy; - col[2] = fz; + col[0] = f[0]; + col[1] = f[1]; + col[2] = f[2]; if (alpha) - col[3] = fw; + col[3] = f[3]; } ImGui::PopID(); + ImGui::EndGroup(); return value_changed; } @@ -6460,7 +7453,12 @@ void ImGui::Separator() if (window->DC.ColumnsCount > 1) PopClipRect(); - const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y)); + float x1 = window->Pos.x; + float x2 = window->Pos.x + window->Size.x; + if (!window->DC.GroupStack.empty()) + x1 += window->DC.ColumnsStartX; + + const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y)); ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit if (!ItemAdd(bb, NULL)) { @@ -6471,6 +7469,10 @@ void ImGui::Separator() window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border)); + ImGuiState& g = *GImGui; + if (g.LogEnabled) + ImGui::LogText(STR_NEWLINE "--------------------------------"); + if (window->DC.ColumnsCount > 1) { PushColumnClipRect(); @@ -6489,66 +7491,132 @@ void ImGui::Spacing() } // Advance cursor given item size. -static void ItemSize(ImVec2 size, ImVec2* adjust_vertical_offset) +static void ItemSize(ImVec2 size, float text_offset_y) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; - const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); - if (adjust_vertical_offset) - adjust_vertical_offset->y = adjust_vertical_offset->y + (line_height - size.y) * 0.5f; - // Always align ourselves on pixel boundaries + const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); + const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y); window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); - window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, ImVec2(window->DC.CursorPosPrevLine.x - window->Pos.x, window->DC.CursorPos.y + window->ScrollY - window->Pos.y)); + //window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); // Debug window->DC.PrevLineHeight = line_height; - window->DC.CurrentLineHeight = 0.0f; + window->DC.PrevLineTextBaseOffset = text_base_offset; + window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f; } -static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset) -{ - ItemSize(bb.GetSize(), adjust_start_offset); +static inline void ItemSize(const ImRect& bb, float text_offset_y) +{ + ItemSize(bb.GetSize(), text_offset_y); } -static bool IsClipped(const ImGuiAabb& bb) +static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled) - return true; + if (!bb.Overlaps(ImRect(window->ClipRectStack.back()))) + { + if (!id || *id != GImGui->ActiveId) + if (clip_even_when_logged || !g.LogEnabled) + return true; + } return false; } -bool ImGui::IsClipped(const ImVec2& item_size) +bool ImGui::IsRectClipped(const ImVec2& size) { ImGuiWindow* window = GetCurrentWindow(); - return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size)); + return IsClippedEx(ImRect(window->DC.CursorPos, window->DC.CursorPos + size), NULL, true); } -static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id) +static bool ItemAdd(const ImRect& bb, const ImGuiID* id) { ImGuiWindow* window = GetCurrentWindow(); window->DC.LastItemID = id ? *id : 0; - window->DC.LastItemAabb = bb; - if (IsClipped(bb)) + window->DC.LastItemRect = bb; + if (IsClippedEx(bb, id, false)) { - window->DC.LastItemHovered = false; + window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false; return false; } // This is a sensible default, but widgets are free to override it after calling ItemAdd() - const bool hovered = IsMouseHoveringBox(bb); - //const bool hovered = (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb); // matching the behaviour of IsHovered(), not always what the user wants? - window->DC.LastItemHovered = hovered; + ImGuiState& g = *GImGui; + if (IsMouseHoveringRect(bb)) + { + // Matching the behavior of IsHovered() but ignore if ActiveId==window->MoveID (we clicked on the window background) + // So that clicking on items with no active id such as Text() still returns true with IsItemHovered() + window->DC.LastItemHoveredRect = true; + window->DC.LastItemHoveredAndUsable = false; + if (g.HoveredRootWindow == window->RootWindow) + if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly || (g.ActiveId == window->MoveID)) + if (IsWindowContentHoverable(window)) + window->DC.LastItemHoveredAndUsable = true; + } + else + { + window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false; + } + return true; } +void ImGui::BeginGroup() +{ + ImGuiWindow* window = GetCurrentWindow(); + + window->DC.GroupStack.resize(window->DC.GroupStack.size() + 1); + ImGuiGroupData& group_data = window->DC.GroupStack.back(); + group_data.BackupCursorPos = window->DC.CursorPos; + group_data.BackupCursorMaxPos = window->DC.CursorMaxPos; + group_data.BackupColumnsStartX = window->DC.ColumnsStartX; + group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight; + group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset; + group_data.BackupLogLinePosY = window->DC.LogLinePosY; + + window->DC.ColumnsStartX = window->DC.CursorPos.x - window->Pos.x; + window->DC.CursorMaxPos = window->DC.CursorPos; + window->DC.CurrentLineHeight = 0.0f; + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; +} + +void ImGui::EndGroup() +{ + ImGuiWindow* window = GetCurrentWindow(); + ImGuiStyle& style = ImGui::GetStyle(); + + IM_ASSERT(!window->DC.GroupStack.empty()); + + ImGuiGroupData& group_data = window->DC.GroupStack.back(); + + ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos); + group_bb.Max.y -= style.ItemSpacing.y; // Cancel out last vertical spacing because we are adding one ourselves. + group_bb.Max = ImMax(group_bb.Min, group_bb.Max); + + window->DC.CursorPos = group_data.BackupCursorPos; + window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos); + window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight; + window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset; // FIXME: Ideally we'll grab the base offset from the first line of the group. + window->DC.ColumnsStartX = group_data.BackupColumnsStartX; + window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; + + ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset); + ItemAdd(group_bb, NULL); + + window->DC.GroupStack.pop_back(); + + //window->DrawList->AddRect(group_bb.Min, group_bb.Max, 0xFFFF00FF); // Debug +} + // Gets back to previous line and continue with horizontal layout // column_x == 0 : follow on previous item // columm_x != 0 : align to specified column @@ -6560,7 +7628,7 @@ void ImGui::SameLine(int column_x, int spacing_w) ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; - + float x, y; if (column_x != 0) { @@ -6575,6 +7643,7 @@ void ImGui::SameLine(int column_x, int spacing_w) y = window->DC.CursorPosPrevLine.y; } window->DC.CurrentLineHeight = window->DC.PrevLineHeight; + window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; window->DC.CursorPos = ImVec2(x, y); } @@ -6604,9 +7673,10 @@ void ImGui::NextColumn() window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX); window->DC.CursorPos.y = window->DC.ColumnsCellMinY; window->DC.CurrentLineHeight = 0.0f; + window->DC.CurrentLineTextBaseOffset = 0.0f; PushColumnClipRect(); - ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); + ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); // FIXME } } @@ -6622,6 +7692,22 @@ int ImGui::GetColumnsCount() return window->DC.ColumnsCount; } +static float GetDraggedColumnOffset(int column_index) +{ + // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing + // window creates a feedback loop because we store normalized positions/ So while dragging we enforce absolute positioning + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets. + IM_ASSERT(g.ActiveId == window->DC.ColumnsSetID + ImGuiID(column_index)); + + float x = g.IO.MousePos.x + g.ActiveClickDeltaToCenter.x; + x -= window->Pos.x; + x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing); + + return x; +} + float ImGui::GetColumnOffset(int column_index) { ImGuiState& g = *GImGui; @@ -6629,6 +7715,13 @@ float ImGui::GetColumnOffset(int column_index) if (column_index < 0) column_index = window->DC.ColumnsCurrent; + if (g.ActiveId) + { + const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); + if (g.ActiveId == column_id) + return GetDraggedColumnOffset(column_index); + } + // Read from cache IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size()); const float t = window->DC.ColumnsOffsetsT[column_index]; @@ -6701,15 +7794,17 @@ void ImGui::Columns(int columns_count, const char* id, bool border) for (int i = 1; i < window->DC.ColumnsCount; i++) { float x = window->Pos.x + GetColumnOffset(i); - + const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i); - const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2)); + const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2)); - if (IsClipped(column_aabb)) + if (IsClippedEx(column_rect, &column_id, false)) continue; bool hovered, held; - ButtonBehaviour(column_aabb, column_id, &hovered, &held, true); + ButtonBehavior(column_rect, column_id, &hovered, &held, true); + if (hovered || held) + g.MouseCursor = ImGuiMouseCursor_ResizeEW; // Draw before resize so our items positioning are in sync with the line being drawn const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column); @@ -6718,16 +7813,19 @@ void ImGui::Columns(int columns_count, const char* id, bool border) if (held) { - x -= window->Pos.x; - x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing); + if (g.ActiveIdIsJustActivated) + g.ActiveClickDeltaToCenter.x = x - g.IO.MousePos.x; + + x = GetDraggedColumnOffset(i); SetColumnOffset(i, x); - x += window->Pos.x; } } } // Set state for first column + ImGui::PushID(0x11223344); // Differentiate column ID with an arbitrary/random prefix for cases where users name their columns set the same as another non-scope widget window->DC.ColumnsSetID = window->GetID(id ? id : ""); + ImGui::PopID(); window->DC.ColumnsCurrent = 0; window->DC.ColumnsCount = columns_count; window->DC.ColumnsShowBorders = border; @@ -6760,32 +7858,42 @@ void ImGui::Columns(int columns_count, const char* id, bool border) } } -void ImGui::TreePush(const char* str_id) +void ImGui::Indent() +{ + ImGuiState& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ColumnsStartX += g.Style.IndentSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX; +} + +void ImGui::Unindent() { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnsStartX += g.Style.TreeNodeSpacing; + window->DC.ColumnsStartX -= g.Style.IndentSpacing; window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX; +} + +void ImGui::TreePush(const char* str_id) +{ + ImGuiWindow* window = GetCurrentWindow(); + ImGui::Indent(); window->DC.TreeDepth++; PushID(str_id ? str_id : "#TreePush"); } void ImGui::TreePush(const void* ptr_id) { - ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnsStartX += g.Style.TreeNodeSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX; + ImGui::Indent(); window->DC.TreeDepth++; PushID(ptr_id ? ptr_id : (const void*)"#TreePush"); } void ImGui::TreePop() { - ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnsStartX -= g.Style.TreeNodeSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX; + ImGui::Unindent(); window->DC.TreeDepth--; PopID(); } @@ -6810,7 +7918,7 @@ void ImGui::Value(const char* prefix, float v, const char* float_format) if (float_format) { char fmt[64]; - sprintf(fmt, "%%s: %s", float_format); + ImFormatString(fmt, IM_ARRAYSIZE(fmt), "%%s: %s", float_format); ImGui::Text(fmt, prefix, v); } else @@ -6854,6 +7962,15 @@ void ImDrawList::Clear() texture_id_stack.resize(0); } +void ImDrawList::ClearFreeMemory() +{ + commands.clear(); + vtx_buffer.clear(); + vtx_write = NULL; + clip_rect_stack.clear(); + texture_id_stack.clear(); +} + void ImDrawList::AddDrawCmd() { ImDrawCmd draw_cmd; @@ -6862,6 +7979,8 @@ void ImDrawList::AddDrawCmd() draw_cmd.texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back(); draw_cmd.user_callback = NULL; draw_cmd.user_callback_data = NULL; + + IM_ASSERT(draw_cmd.clip_rect.x <= draw_cmd.clip_rect.z && draw_cmd.clip_rect.y <= draw_cmd.clip_rect.w); commands.push_back(draw_cmd); } @@ -6901,6 +8020,15 @@ void ImDrawList::PushClipRect(const ImVec4& clip_rect) UpdateClipRect(); } +void ImDrawList::PushClipRectFullScreen() +{ + PushClipRect(GNullClipRect); + + // This would be more correct but we're not supposed to access ImGuiState from here? + //ImGuiState& g = *GImGui; + //PushClipRect(GetVisibleRect()); +} + void ImDrawList::PopClipRect() { IM_ASSERT(clip_rect_stack.size() > 0); @@ -6935,92 +8063,128 @@ void ImDrawList::PopTextureID() UpdateTextureID(); } -void ImDrawList::ReserveVertices(unsigned int vtx_count) +void ImDrawList::PrimReserve(unsigned int vtx_count) { - if (vtx_count > 0) - { - ImDrawCmd& draw_cmd = commands.back(); - draw_cmd.vtx_count += vtx_count; - vtx_buffer.resize(vtx_buffer.size() + vtx_count); - vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count]; - } + ImDrawCmd& draw_cmd = commands.back(); + draw_cmd.vtx_count += vtx_count; + + size_t vtx_buffer_size = vtx_buffer.size(); + vtx_buffer.resize(vtx_buffer_size + vtx_count); + vtx_write = &vtx_buffer[vtx_buffer_size]; +} + +void ImDrawList::PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) +{ + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col; + vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col; + vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col; + vtx_write += 3; } -void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) +void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col) { - vtx_write->pos = pos; - vtx_write->col = col; - vtx_write->uv = GImGui->FontTexUvWhitePixel; - vtx_write++; + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + const ImVec2 b(c.x, a.y); + const ImVec2 d(a.x, c.y); + vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col; + vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col; + vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col; + vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col; + vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col; + vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col; + vtx_write += 6; } -void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv) +void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col) { - vtx_write->pos = pos; - vtx_write->col = col; - vtx_write->uv = uv; - vtx_write++; + const ImVec2 b(c.x, a.y); + const ImVec2 d(a.x, c.y); + const ImVec2 uv_b(uv_c.x, uv_a.y); + const ImVec2 uv_d(uv_a.x, uv_c.y); + vtx_write[0].pos = a; vtx_write[0].uv = uv_a; vtx_write[0].col = col; + vtx_write[1].pos = b; vtx_write[1].uv = uv_b; vtx_write[1].col = col; + vtx_write[2].pos = c; vtx_write[2].uv = uv_c; vtx_write[2].col = col; + vtx_write[3].pos = a; vtx_write[3].uv = uv_a; vtx_write[3].col = col; + vtx_write[4].pos = c; vtx_write[4].uv = uv_c; vtx_write[4].col = col; + vtx_write[5].pos = d; vtx_write[5].uv = uv_d; vtx_write[5].col = col; + vtx_write += 6; } -// NB: memory should be reserved for 6 vertices by the caller. -void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) +void ImDrawList::PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col) { - const float length = sqrtf(ImLengthSqr(b - a)); - const ImVec2 hn = (b - a) * (0.50f / length); // half normal - const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset - const ImVec2 hp1 = ImVec2(-hn.y, +hn.x); + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + vtx_write[0].pos = a; vtx_write[0].uv = uv; vtx_write[0].col = col; + vtx_write[1].pos = b; vtx_write[1].uv = uv; vtx_write[1].col = col; + vtx_write[2].pos = c; vtx_write[2].uv = uv; vtx_write[2].col = col; + vtx_write[3].pos = a; vtx_write[3].uv = uv; vtx_write[3].col = col; + vtx_write[4].pos = c; vtx_write[4].uv = uv; vtx_write[4].col = col; + vtx_write[5].pos = d; vtx_write[5].uv = uv; vtx_write[5].col = col; + vtx_write += 6; +} - // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls. - AddVtx(a + hp0, col); - AddVtx(b + hp0, col); - AddVtx(a + hp1, col); - AddVtx(b + hp0, col); - AddVtx(b + hp1, col); - AddVtx(a + hp1, col); +// FIXME-OPT: In many instances the caller could provide a normal. +void ImDrawList::PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness) +{ + const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a)); + const float dx = (b.x - a.x) * (thickness * 0.5f * inv_length); // line direction, halved + const float dy = (b.y - a.y) * (thickness * 0.5f * inv_length); // line direction, halved + + const ImVec2 pa(a.x + dy, a.y - dx); + const ImVec2 pb(b.x + dy, b.y - dx); + const ImVec2 pc(b.x - dy, b.y + dx); + const ImVec2 pd(a.x - dy, a.y + dx); + PrimQuad(pa, pb, pc, pd, col); } -void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col) +void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness) { if ((col >> 24) == 0) return; - ReserveVertices(6); - AddVtxLine(a, b, col); + PrimReserve(6); + PrimLine(a, b, col, thickness); } -void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) +void ImDrawList::AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min, int a_max, bool filled, const ImVec2& third_point_offset) { if ((col >> 24) == 0) return; - static ImVec2 circle_vtx[12]; + const int SAMPLES = 12; + static ImVec2 circle_vtx[SAMPLES]; static bool circle_vtx_builds = false; if (!circle_vtx_builds) { - for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++) + for (int i = 0; i < SAMPLES; i++) { - const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI; + const float a = ((float)i / (float)SAMPLES) * 2*PI; circle_vtx[i].x = cosf(a + PI); circle_vtx[i].y = sinf(a + PI); } circle_vtx_builds = true; } - - if (tris) + + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + if (filled) { - ReserveVertices((unsigned int)(a_max-a_min) * 3); - for (int a = a_min; a < a_max; a++) + PrimReserve((unsigned int)(a_max-a_min) * 3); + for (int a0 = a_min; a0 < a_max; a0++) { - AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col); - AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); - AddVtx(center + third_point_offset, col); + int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1; + PrimVtx(center + circle_vtx[a0] * radius, uv, col); + PrimVtx(center + circle_vtx[a1] * radius, uv, col); + PrimVtx(center + third_point_offset, uv, col); } } else { - ReserveVertices((unsigned int)(a_max-a_min) * 6); - for (int a = a_min; a < a_max; a++) - AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); + PrimReserve((unsigned int)(a_max-a_min) * 6); + for (int a0 = a_min; a0 < a_max; a0++) + { + int a1 = (a0 + 1 == SAMPLES) ? 0 : a0 + 1; + PrimLine(center + circle_vtx[a0] * radius, center + circle_vtx[a1] * radius, col); + } } } @@ -7035,24 +8199,24 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun if (r == 0.0f || rounding_corners == 0) { - ReserveVertices(4*6); - AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col); - AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col); - AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col); - AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col); + PrimReserve(4*6); + PrimLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col); + PrimLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col); + PrimLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col); + PrimLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col); } else { - ReserveVertices(4*6); - AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col); - AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col); - AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col); - AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col); + PrimReserve(4*6); + PrimLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col); + PrimLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col); + PrimLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col); + PrimLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col); - if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3); - if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6); - if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9); - if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12); + if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3); + if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6); + if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9); + if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12); } } @@ -7068,46 +8232,26 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa if (r == 0.0f || rounding_corners == 0) { // Use triangle so we can merge more draw calls together (at the cost of extra vertices) - ReserveVertices(6); - AddVtx(ImVec2(a.x,a.y), col); - AddVtx(ImVec2(b.x,a.y), col); - AddVtx(ImVec2(b.x,b.y), col); - AddVtx(ImVec2(a.x,a.y), col); - AddVtx(ImVec2(b.x,b.y), col); - AddVtx(ImVec2(a.x,b.y), col); + PrimReserve(6); + PrimRect(a, b, col); } else { - ReserveVertices(6+6*2); - AddVtx(ImVec2(a.x+r,a.y), col); - AddVtx(ImVec2(b.x-r,a.y), col); - AddVtx(ImVec2(b.x-r,b.y), col); - AddVtx(ImVec2(a.x+r,a.y), col); - AddVtx(ImVec2(b.x-r,b.y), col); - AddVtx(ImVec2(a.x+r,b.y), col); - + PrimReserve(6+6*2); + PrimRect(ImVec2(a.x+r,a.y), ImVec2(b.x-r,b.y), col); + float top_y = (rounding_corners & 1) ? a.y+r : a.y; float bot_y = (rounding_corners & 8) ? b.y-r : b.y; - AddVtx(ImVec2(a.x,top_y), col); - AddVtx(ImVec2(a.x+r,top_y), col); - AddVtx(ImVec2(a.x+r,bot_y), col); - AddVtx(ImVec2(a.x,top_y), col); - AddVtx(ImVec2(a.x+r,bot_y), col); - AddVtx(ImVec2(a.x,bot_y), col); + PrimRect(ImVec2(a.x,top_y), ImVec2(a.x+r,bot_y), col); top_y = (rounding_corners & 2) ? a.y+r : a.y; bot_y = (rounding_corners & 4) ? b.y-r : b.y; - AddVtx(ImVec2(b.x-r,top_y), col); - AddVtx(ImVec2(b.x,top_y), col); - AddVtx(ImVec2(b.x,bot_y), col); - AddVtx(ImVec2(b.x-r,top_y), col); - AddVtx(ImVec2(b.x,bot_y), col); - AddVtx(ImVec2(b.x-r,bot_y), col); + PrimRect(ImVec2(b.x-r,top_y), ImVec2(b.x,bot_y), col); - if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true); - if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true); - if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true); - if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true); + if (rounding_corners & 1) AddArcFast(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true); + if (rounding_corners & 2) AddArcFast(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true); + if (rounding_corners & 4) AddArcFast(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true); + if (rounding_corners & 8) AddArcFast(ImVec2(a.x+r,b.y-r), r, col, 9, 12, true); } } @@ -7116,10 +8260,8 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec if ((col >> 24) == 0) return; - ReserveVertices(3); - AddVtx(a, col); - AddVtx(b, col); - AddVtx(c, col); + PrimReserve(3); + PrimTriangle(a, b, c, col); } void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments) @@ -7127,13 +8269,13 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu if ((col >> 24) == 0) return; - ReserveVertices((unsigned int)num_segments*6); + PrimReserve((unsigned int)num_segments*6); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtxLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col); + PrimLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col); a0 = a1; } } @@ -7143,26 +8285,29 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, if ((col >> 24) == 0) return; - ReserveVertices((unsigned int)num_segments*3); + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + PrimReserve((unsigned int)num_segments*3); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, col); - AddVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, col); - AddVtx(centre, col); + PrimVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, uv, col); + PrimVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, uv, col); + PrimVtx(centre, uv, col); a0 = a1; } } -void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec2* cpu_clip_max) +void ImDrawList::AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec2* cpu_clip_max) { if ((col >> 24) == 0) return; if (text_end == NULL) text_end = text_begin + strlen(text_begin); + if (text_begin == text_end) + return; IM_ASSERT(font->ContainerAtlas->TexID == texture_id_stack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font. @@ -7170,9 +8315,9 @@ void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 const unsigned int char_count = (unsigned int)(text_end - text_begin); const unsigned int vtx_count_max = char_count * 6; const size_t vtx_begin = vtx_buffer.size(); - ReserveVertices(vtx_count_max); + PrimReserve(vtx_count_max); - font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write, wrap_width, cpu_clip_max); + font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, this, wrap_width, cpu_clip_max); // give back unused vertices vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front())); @@ -7186,17 +8331,13 @@ void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const Im if ((col >> 24) == 0) return; + // FIXME-OPT: This is wasting draw calls. const bool push_texture_id = texture_id_stack.empty() || user_texture_id != texture_id_stack.back(); if (push_texture_id) PushTextureID(user_texture_id); - ReserveVertices(6); - AddVtxUV(ImVec2(a.x,a.y), col, uv0); - AddVtxUV(ImVec2(b.x,a.y), col, ImVec2(uv1.x,uv0.y)); - AddVtxUV(ImVec2(b.x,b.y), col, uv1); - AddVtxUV(ImVec2(a.x,a.y), col, ImVec2(uv0.x,uv0.y)); - AddVtxUV(ImVec2(b.x,b.y), col, uv1); - AddVtxUV(ImVec2(a.x,b.y), col, ImVec2(uv0.x,uv1.y)); + PrimReserve(6); + PrimRectUV(a, b, uv0, uv1, col); if (push_texture_id) PopTextureID(); @@ -7229,7 +8370,7 @@ ImFontAtlas::ImFontAtlas() TexPixelsAlpha8 = NULL; TexPixelsRGBA32 = NULL; TexWidth = TexHeight = 0; - TexExtraDataPos = TexUvWhitePixel = ImVec2(0, 0); + TexUvWhitePixel = ImVec2(0, 0); } ImFontAtlas::~ImFontAtlas() @@ -7258,10 +8399,8 @@ void ImFontAtlas::ClearTexData() TexPixelsRGBA32 = NULL; } -void ImFontAtlas::Clear() +void ImFontAtlas::ClearFonts() { - ClearInputData(); - ClearTexData(); for (size_t i = 0; i < Fonts.size(); i++) { Fonts[i]->~ImFont(); @@ -7270,6 +8409,13 @@ void ImFontAtlas::Clear() Fonts.clear(); } +void ImFontAtlas::Clear() +{ + ClearInputData(); + ClearTexData(); + ClearFonts(); +} + void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size) { printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n"); @@ -7325,18 +8471,10 @@ static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsi // Load embedded ProggyClean.ttf at size 13 ImFont* ImFontAtlas::AddFontDefault() { - // Get compressed data unsigned int ttf_compressed_size; const void* ttf_compressed; GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size); - - // Decompress - const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)ttf_compressed); - unsigned char* buf_decompressed = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size); - stb_decompress(buf_decompressed, (unsigned char*)ttf_compressed, ttf_compressed_size); - - // Add - ImFont* font = AddFontFromMemoryTTF(buf_decompressed, buf_decompressed_size, 13.0f, GetGlyphRangesDefault(), 0); + ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0); font->DisplayOffset.y += 1; return font; } @@ -7351,13 +8489,12 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, return NULL; } - // Add - ImFont* font = AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no); + ImFont* font = AddFontFromMemoryTTF(data, (unsigned int)data_size, size_pixels, glyph_ranges, font_no); return font; } -// NB: ownership of 'data' is given to ImFontAtlas which will clear it. -ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no) +// Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build() +ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no) { // Create new font ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont)); @@ -7368,8 +8505,8 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_ ImFontAtlasData* data = (ImFontAtlasData*)ImGui::MemAlloc(sizeof(ImFontAtlasData)); memset(data, 0, sizeof(ImFontAtlasData)); data->OutFont = font; - data->TTFData = in_ttf_data; - data->TTFDataSize = in_ttf_data_size; + data->TTFData = ttf_data; + data->TTFDataSize = (size_t)ttf_size; data->SizePixels = size_pixels; data->GlyphRanges = glyph_ranges; data->FontNo = font_no; @@ -7381,13 +8518,25 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_ return font; } +ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no) +{ + // Decompress + const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data); + unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size); + stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size); + + // Add + ImFont* font = AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no); + return font; +} + bool ImFontAtlas::Build() { IM_ASSERT(InputData.size() > 0); TexID = NULL; TexWidth = TexHeight = 0; - TexExtraDataPos = TexUvWhitePixel = ImVec2(0, 0); + TexUvWhitePixel = ImVec2(0, 0); ClearTexData(); // Initialize font information early (so we can error without any cleanup) + count glyphs @@ -7396,10 +8545,10 @@ bool ImFontAtlas::Build() for (size_t input_i = 0; input_i < InputData.size(); input_i++) { ImFontAtlasData& data = *InputData[input_i]; - IM_ASSERT(data.OutFont && !data.OutFont->IsLoaded()); + IM_ASSERT(data.OutFont && (!data.OutFont->IsLoaded() || data.OutFont->ContainerAtlas == this)); const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)data.TTFData, data.FontNo); IM_ASSERT(font_offset >= 0); - if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset)) + if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset)) return false; if (!data.GlyphRanges) @@ -7420,12 +8569,13 @@ bool ImFontAtlas::Build() IM_ASSERT(ret); stbtt_PackSetOversampling(&spc, 1, 1); - // Pack our extra data rectangle first, so it will be on the upper-left corner of our texture (UV will have small values). - stbrp_rect extra_rect; - extra_rect.w = (stbrp_coord)TEX_ATLAS_SIZE.x; - extra_rect.h = (stbrp_coord)TEX_ATLAS_SIZE.y; - stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rect, 1); - TexExtraDataPos = ImVec2(extra_rect.x, extra_rect.y); + // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values). + ImVector<stbrp_rect> extra_rects; + RenderCustomTexData(0, &extra_rects); + stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rects[0], (int)extra_rects.size()); + for (size_t i = 0; i < extra_rects.size(); i++) + if (extra_rects[i].was_packed) + TexHeight = ImMax(TexHeight, extra_rects[i].y + extra_rects[i].h); // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0) int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0; @@ -7433,11 +8583,10 @@ bool ImFontAtlas::Build() stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyph_count * sizeof(stbrp_rect)); stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_glyph_range_count * sizeof(stbtt_pack_range)); memset(buf_packedchars, 0, total_glyph_count * sizeof(stbtt_packedchar)); - memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnessary but let's clear this for the sake of sanity. + memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnecessary but let's clear this for the sake of sanity. memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range)); - // First pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only) - int tex_height = extra_rect.y + extra_rect.h; + // First font pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only) for (size_t input_i = 0; input_i < InputData.size(); input_i++) { ImFontAtlasData& data = *InputData[input_i]; @@ -7473,14 +8622,14 @@ bool ImFontAtlas::Build() // Extend texture height for (int i = 0; i < n; i++) if (data.Rects[i].was_packed) - tex_height = ImMax(tex_height, data.Rects[i].y + data.Rects[i].h); + TexHeight = ImMax(TexHeight, data.Rects[i].y + data.Rects[i].h); } IM_ASSERT(buf_rects_n == total_glyph_count); IM_ASSERT(buf_packedchars_n == total_glyph_count); IM_ASSERT(buf_ranges_n == total_glyph_range_count); // Create texture - TexHeight = ImUpperPowerOfTwo(tex_height); + TexHeight = ImUpperPowerOfTwo(TexHeight); TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(TexWidth * TexHeight); memset(TexPixelsAlpha8, 0, TexWidth * TexHeight); spc.pixels = TexPixelsAlpha8; @@ -7509,6 +8658,8 @@ bool ImFontAtlas::Build() const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels); int font_ascent, font_descent, font_line_gap; stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap); + data.OutFont->BaseLine = (font_ascent * font_scale); + data.OutFont->Glyphs.resize(0); const float uv_scale_x = 1.0f / TexWidth; const float uv_scale_y = 1.0f / TexHeight; @@ -7546,53 +8697,100 @@ bool ImFontAtlas::Build() ImGui::MemFree(buf_ranges); buf_packedchars = NULL; buf_ranges = NULL; - ClearInputData(); // Render into our custom data block - RenderCustomTexData(); + RenderCustomTexData(1, &extra_rects); return true; } -void ImFontAtlas::RenderCustomTexData() -{ - IM_ASSERT(TexExtraDataPos.x == 0.0f && TexExtraDataPos.y == 0.0f); - - // Draw white pixel into texture and make UV points to it - TexPixelsAlpha8[0] = TexPixelsAlpha8[1] = TexPixelsAlpha8[TexWidth+0] = TexPixelsAlpha8[TexWidth+1] = 0xFF; - TexUvWhitePixel = ImVec2((TexExtraDataPos.x + 0.5f) / TexWidth, (TexExtraDataPos.y + 0.5f) / TexHeight); - - // Draw a mouse cursor into texture - // Because our font uses a single color channel, we have to spread the cursor in 2 layers (black/white) which will be rendered separately. - const char cursor_pixels[] = - { - "X " - "XX " - "X.X " - "X..X " - "X...X " - "X....X " - "X.....X " - "X......X " - "X.......X " - "X........X " - "X.........X " - "X..........X" - "X......XXXXX" - "X...X..X " - "X..X X..X " - "X.X X..X " - "XX X..X " - " X..X " - " XX " +void ImFontAtlas::RenderCustomTexData(int pass, void* p_rects) +{ + // . = white layer, X = black layer, others are blank + const int TEX_DATA_W = 90; + const int TEX_DATA_H = 27; + const char texture_data[TEX_DATA_W*TEX_DATA_H+1] = + { + "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX" + "..- -X.....X- X.X - X.X -X.....X - X.....X" + "--- -XXX.XXX- X...X - X...X -X....X - X....X" + "X - X.X - X.....X - X.....X -X...X - X...X" + "XX - X.X -X.......X- X.......X -X..X.X - X.X..X" + "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X" + "X..X - X.X - X.X - X.X -XX X.X - X.X XX" + "X...X - X.X - X.X - XX X.X XX - X.X - X.X " + "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X " + "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X " + "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X " + "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X " + "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X " + "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X " + "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X " + "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X " + "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX " + "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------" + "X.X X..X - -X.......X- X.......X - XX XX - " + "XX X..X - - X.....X - X.....X - X.X X.X - " + " X..X - X...X - X...X - X..X X..X - " + " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - " + "------------ - X - X -X.....................X- " + " ----------------------------------- X...XXXXXXXXXXXXX...X - " + " - X..X X..X - " + " - X.X X.X - " + " - XX XX - " }; - IM_ASSERT(sizeof(cursor_pixels)-1 == (int)TEX_ATLAS_SIZE_MOUSE_CURSOR.x * (int)TEX_ATLAS_SIZE_MOUSE_CURSOR.y); - for (int y = 0, n = 0; y < 19; y++) - for (int x = 0; x < 12; x++, n++) + + ImVector<stbrp_rect>& rects = *(ImVector<stbrp_rect>*)p_rects; + if (pass == 0) + { + stbrp_rect r; + memset(&r, 0, sizeof(r)); + r.w = (TEX_DATA_W*2)+1; + r.h = TEX_DATA_H+1; + rects.push_back(r); + } + else if (pass == 1) + { + // Copy pixels + const stbrp_rect& r = rects[0]; + for (int y = 0, n = 0; y < TEX_DATA_H; y++) + for (int x = 0; x < TEX_DATA_W; x++, n++) + { + const int offset0 = (int)(r.x + x) + (int)(r.y + y) * TexWidth; + const int offset1 = offset0 + 1 + TEX_DATA_W; + TexPixelsAlpha8[offset0] = texture_data[n] == '.' ? 0xFF : 0x00; + TexPixelsAlpha8[offset1] = texture_data[n] == 'X' ? 0xFF : 0x00; + } + const ImVec2 tex_uv_scale(1.0f / TexWidth, 1.0f / TexHeight); + TexUvWhitePixel = ImVec2(r.x + 0.5f, r.y + 0.5f) * tex_uv_scale; + + const ImVec2 cursor_datas[ImGuiMouseCursor_Count_][3] = + { + // Pos ........ Size ......... Offset ...... + { ImVec2(0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow + { ImVec2(13,0), ImVec2(7,16), ImVec2( 4, 8) }, // ImGuiMouseCursor_TextInput + { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_Move + { ImVec2(21,0), ImVec2( 9,23), ImVec2( 5,11) }, // ImGuiMouseCursor_ResizeNS + { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 5) }, // ImGuiMouseCursor_ResizeEW + { ImVec2(73,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNESW + { ImVec2(55,0), ImVec2(17,17), ImVec2( 9, 9) }, // ImGuiMouseCursor_ResizeNWSE + }; + + for (int type = 0; type < ImGuiMouseCursor_Count_; type++) { - TexPixelsAlpha8[((int)TEX_ATLAS_POS_MOUSE_CURSOR_BLACK.x + x) + ((int)TEX_ATLAS_POS_MOUSE_CURSOR_BLACK.y + y) * TexWidth] = (cursor_pixels[n] == 'X') ? 0xFF : 0x00; - TexPixelsAlpha8[((int)TEX_ATLAS_POS_MOUSE_CURSOR_WHITE.x + x) + ((int)TEX_ATLAS_POS_MOUSE_CURSOR_WHITE.y + y) * TexWidth] = (cursor_pixels[n] == '.') ? 0xFF : 0x00; + ImGuiMouseCursorData& cursor_data = GImGui->MouseCursorData[type]; + ImVec2 pos = cursor_datas[type][0] + ImVec2((float)r.x, (float)r.y); + const ImVec2 size = cursor_datas[type][1]; + cursor_data.Type = type; + cursor_data.Size = size; + cursor_data.Offset = cursor_datas[type][2]; + cursor_data.TexUvMin[0] = (pos) * tex_uv_scale; + cursor_data.TexUvMax[0] = (pos + size) * tex_uv_scale; + pos.x += TEX_DATA_W+1; + cursor_data.TexUvMin[1] = (pos) * tex_uv_scale; + cursor_data.TexUvMax[1] = (pos + size) * tex_uv_scale; } + } } //----------------------------------------------------------------------------- @@ -7606,10 +8804,21 @@ ImFont::ImFont() Clear(); } +ImFont::~ImFont() +{ + // Invalidate active font so that the user gets a clear crash instead of a dangling pointer. + // If you want to delete fonts you need to do it between Render() and NewFrame(). + ImGuiState& g = *GImGui; + if (g.Font == this) + g.Font = NULL; + Clear(); +} + void ImFont::Clear() { FontSize = 0.0f; DisplayOffset = ImVec2(-0.5f, 0.5f); + BaseLine = 0.0f; ContainerAtlas = NULL; Glyphs.clear(); FallbackGlyph = NULL; @@ -7647,7 +8856,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese() { // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1. // This encoding helps us reduce the source code size. - static const short offsets_from_0x4E00[] = + static const short offsets_from_0x4E00[] = { -1,0,1,3,0,0,0,0,1,0,5,1,1,0,7,4,6,10,0,1,9,9,7,1,3,19,1,10,7,1,0,1,0,5,1,0,6,4,2,6,0,0,12,6,8,0,3,5,0,1,0,9,0,0,8,1,1,3,4,5,13,0,0,8,2,17, 4,3,1,1,9,6,0,0,0,2,1,3,2,22,1,9,11,1,13,1,3,12,0,5,9,2,0,6,12,5,3,12,4,1,2,16,1,1,4,6,5,3,0,6,13,15,5,12,8,14,0,0,6,15,3,6,0,18,8,1,6,14,1, @@ -7777,10 +8986,10 @@ static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const *out_char = c; return 1; } - if ((*str & 0xe0) == 0xc0) + if ((*str & 0xe0) == 0xc0) { *out_char = 0; - if (in_text_end && in_text_end - (const char*)str < 2) return 0; + if (in_text_end && in_text_end - (const char*)str < 2) return 0; if (*str < 0xc2) return 0; c = (unsigned int)((*str++ & 0x1f) << 6); if ((*str & 0xc0) != 0x80) return 0; @@ -7788,7 +8997,7 @@ static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const *out_char = c; return 2; } - if ((*str & 0xf0) == 0xe0) + if ((*str & 0xf0) == 0xe0) { *out_char = 0; if (in_text_end && in_text_end - (const char*)str < 3) return 0; @@ -7802,7 +9011,7 @@ static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const *out_char = c; return 3; } - if ((*str & 0xf8) == 0xf0) + if ((*str & 0xf8) == 0xf0) { *out_char = 0; if (in_text_end && in_text_end - (const char*)str < 4) return 0; @@ -7866,13 +9075,13 @@ static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c) { size_t i = 0; size_t n = buf_size; - if (c < 0x80) + if (c < 0x80) { if (i+1 > n) return 0; buf[i++] = (char)c; return 1; - } - else if (c < 0x800) + } + else if (c < 0x800) { if (i+2 > n) return 0; buf[i++] = (char)(0xc0 + (c >> 6)); @@ -7882,8 +9091,8 @@ static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c) else if (c >= 0xdc00 && c < 0xe000) { return 0; - } - else if (c >= 0xd800 && c < 0xdc00) + } + else if (c >= 0xd800 && c < 0xdc00) { if (i+4 > n) return 0; buf[i++] = (char)(0xf0 + (c >> 18)); @@ -8064,6 +9273,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons } // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) + const char* prev_s = s; unsigned int c = (unsigned int)*s; if (c < 0x80) { @@ -8075,7 +9285,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons if (c == 0) break; } - + if (c == '\n') { text_size.x = ImMax(text_size.x, line_width); @@ -8083,10 +9293,13 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons line_width = 0.0f; continue; } - + const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance; if (line_width + char_width >= max_width) + { + s = prev_s; break; + } line_width += char_width; } @@ -8127,10 +9340,13 @@ ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_be line_width = 0.0f; continue; } - + const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance; if (line_width + char_width >= max_width) + { + s--; break; + } line_width += char_width; } @@ -8148,7 +9364,7 @@ ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_be return text_size; } -void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width, const ImVec2* cpu_clip_max) const +void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width, const ImVec2* cpu_clip_max) const { if (!text_end) text_end = text_begin + strlen(text_begin); @@ -8172,6 +9388,8 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re float x = pos.x; float y = pos.y; + ImDrawVert* out_vertices = draw_list->vtx_write; + const char* s = text_begin; while (s < text_end) { @@ -8259,6 +9477,7 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re } } + // NB: we are not calling PrimRectUV() here because non-inlined causes too much overhead in a debug build. out_vertices[0].pos = ImVec2(x1, y1); out_vertices[0].uv = ImVec2(u1, v1); out_vertices[0].col = col; @@ -8286,6 +9505,8 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re x += char_width; } + + draw_list->vtx_write = out_vertices; } //----------------------------------------------------------------------------- @@ -8308,9 +9529,9 @@ static const char* GetClipboardTextFn_DefaultImpl() ImGui::MemFree(buf_local); buf_local = NULL; } - if (!OpenClipboard(NULL)) + if (!OpenClipboard(NULL)) return NULL; - HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT); + HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT); if (wbuf_handle == NULL) return NULL; if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle)) @@ -8319,8 +9540,8 @@ static const char* GetClipboardTextFn_DefaultImpl() buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char)); ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL); } - GlobalUnlock(wbuf_handle); - CloseClipboard(); + GlobalUnlock(wbuf_handle); + CloseClipboard(); return buf_local; } @@ -8331,12 +9552,12 @@ static void SetClipboardTextFn_DefaultImpl(const char* text) return; const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1; - HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar)); + HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar)); if (wbuf_handle == NULL) return; - ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle); + ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle); ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL); - GlobalUnlock(wbuf_handle); + GlobalUnlock(wbuf_handle); EmptyClipboard(); SetClipboardData(CF_UNICODETEXT, wbuf_handle); CloseClipboard(); @@ -8392,12 +9613,21 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) #else -static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) +static void ImeSetInputScreenPosFn_DefaultImpl(int, int) { } #endif +#ifdef IMGUI_DISABLE_TEST_WINDOWS + +void ImGui::ShowUserGuide() {} +void ImGui::ShowStyleEditor(ImGuiStyle*) {} +void ImGui::ShowTestWindow(bool*) {} +void ImGui::ShowMetricsWindow(bool*) {} + +#else + //----------------------------------------------------------------------------- // HELP //----------------------------------------------------------------------------- @@ -8455,8 +9685,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); - ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f"); - ImGui::SliderFloat("ScrollBarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("IndentSpacing", &style.IndentSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("ScrollbarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 16.0f, "%.0f"); ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); ImGui::TreePop(); } @@ -8535,12 +9766,15 @@ static void ShowExampleAppCustomRendering(bool* opened); void ImGui::ShowTestWindow(bool* opened) { // Examples apps + static bool show_app_metrics = false; static bool show_app_console = false; static bool show_app_long_text = false; static bool show_app_auto_resize = false; static bool show_app_fixed_overlay = false; static bool show_app_custom_rendering = false; static bool show_app_manipulating_window_title = false; + if (show_app_metrics) + ImGui::ShowMetricsWindow(&show_app_metrics); if (show_app_console) ShowExampleAppConsole(&show_app_console); if (show_app_long_text) @@ -8576,13 +9810,14 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::End(); return; } - - ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels - //ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels + + //ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels + ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels ImGui::Text("ImGui says hello."); //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel); + //ImGui::Text("KeyMods %s%s%s", ImGui::GetIO().KeyCtrl ? "CTRL" : "", ImGui::GetIO().KeyShift ? "SHIFT" : "", ImGui::GetIO().KeyAlt? "ALT" : ""); //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse); //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard); @@ -8597,7 +9832,7 @@ void ImGui::ShowTestWindow(bool* opened) { ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150); ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300); - ImGui::Checkbox("no resize", &no_resize); + ImGui::Checkbox("no resize", &no_resize); ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150); ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300); ImGui::Checkbox("no collapse", &no_collapse); @@ -8609,7 +9844,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::TreePop(); } - if (ImGui::TreeNode("Fonts")) + if (ImGui::TreeNode("Fonts", "Fonts (%d)", (int)ImGui::GetIO().Fonts->Fonts.size())) { ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF()."); for (size_t i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++) @@ -8648,7 +9883,7 @@ void ImGui::ShowTestWindow(bool* opened) if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; } if (a) { - ImGui::SameLine(); + ImGui::SameLine(); ImGui::Text("Thanks for clicking me!"); } @@ -8699,14 +9934,14 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF); ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width); - ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF); + ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF); ImGui::PopTextWrapPos(); ImGui::Text("Test paragraph 2:"); ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF); ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width); ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh"); - ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF); + ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), 0xFF00FFFF); ImGui::PopTextWrapPos(); ImGui::TreePop(); @@ -8782,7 +10017,7 @@ void ImGui::ShowTestWindow(bool* opened) static bool selected[3] = { false, true, false }; ImGui::Selectable("1. I am selectable", &selected[0]); ImGui::Selectable("2. I am selectable", &selected[1]); - ImGui::Text("3. I am normal text"); + ImGui::Text("3. I am not selectable"); ImGui::Selectable("4. I am selectable", &selected[2]); ImGui::TreePop(); } @@ -8816,6 +10051,57 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::TreePop(); } + if (ImGui::TreeNode("Popup, Menus")) + { + static int selected_fish = -1; + const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" }; + static bool toggles[] = { true, false, false, false, false }; + + { + static bool popup_open = false; + if (ImGui::Button("Select..")) + popup_open = true; + ImGui::SameLine(); + ImGui::Text(selected_fish == -1 ? "<None>" : names[selected_fish]); + if (popup_open) + { + ImGui::BeginPopup(&popup_open); + ImGui::Text("Aquarium"); + ImGui::Separator(); + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + { + if (ImGui::Selectable(names[i])) + { + selected_fish = i; + popup_open = false; + } + } + ImGui::EndPopup(); + } + } + { + static bool popup_open = false; + if (ImGui::Button("Toggle..")) + popup_open = true; + if (popup_open) + { + ImGui::BeginPopup(&popup_open); + for (int i = 0; i < IM_ARRAYSIZE(names); i++) + if (ImGui::MenuItem(names[i], "", &toggles[i])) + popup_open = false; + + ImGui::Separator(); + ImGui::Text("Tooltip here"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("I am a tooltip over a popup"); + + ImGui::EndPopup(); + } + } + + ImGui::TreePop(); + } + if (ImGui::TreeNode("Filtered Text Input")) { static char buf1[64] = ""; ImGui::InputText("default", buf1, 64); @@ -8875,6 +10161,8 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Separator(); + ImGui::LabelText("label", "Value"); + static int item = 1; ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); @@ -8882,43 +10170,48 @@ void ImGui::ShowTestWindow(bool* opened) static int item2 = -1; ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items)); - static char str0[128] = "Hello, world!"; - static int i0=123; - static float f0=0.001f; - ImGui::InputText("string", str0, IM_ARRAYSIZE(str0)); - ImGui::InputInt("input int", &i0); - ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); - - static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; - //ImGui::InputFloat2("input float2", vec4a); - ImGui::InputFloat3("input float3", vec4a); - //ImGui::InputFloat4("input float4", vec4a); - - static int i1=0; - static int i2=42; - ImGui::SliderInt("int 0..3", &i1, 0, 3); - ImGui::SliderInt("int -100..100", &i2, -100, 100); - - static float f1=1.123f; - static float f2=0; - static float f3=0; - static float f4=123456789.0f; - ImGui::SliderFloat("float", &f1, 0.0f, 2.0f); - ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f); - ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f); - ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f"); - static float angle = 0.0f; - ImGui::SliderAngle("angle", &angle); - - static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f }; - //ImGui::SliderFloat2("slider float2", vec4b, 0.0f, 1.0f); - ImGui::SliderFloat3("slider float3", vec4b, 0.0f, 1.0f); - //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f); - - //static int vec4i[4] = { 1, 5, 100, 255 }; - //ImGui::SliderInt2("slider int2", vec4i, 0, 255); - //ImGui::SliderInt3("slider int3", vec4i, 0, 255); - //ImGui::SliderInt4("slider int4", vec4i, 0, 255); + { + static char str0[128] = "Hello, world!"; + static int i0=123; + static float f0=0.001f; + ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0)); + ImGui::InputInt("input int", &i0); + ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); + + static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + ImGui::InputFloat3("input float3", vec4a); + } + + { + static int i1=50; + static int i2=42; + ImGui::DragInt("drag int", &i1, 1); + ImGui::SameLine(); + ImGui::TextColored(ImColor(170,170,170,255), "(?)"); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input text"); + + ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%"); + + static float f1=1.00f; + static float f2=0.0067f; + ImGui::DragFloat("drag float", &f1, 1.0f); + ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns"); + } + + { + static int i1=0; + //static int i2=42; + ImGui::SliderInt("slider int 0..3", &i1, 0, 3); + //ImGui::SliderInt("slider int -100..100", &i2, -100, 100); + + static float f1=0.123f; + static float f2=0.0f; + ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f"); + ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f); + static float angle = 0.0f; + ImGui::SliderAngle("slider angle", &angle); + } static float col1[3] = { 1.0f,0.0f,0.2f }; static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; @@ -8933,6 +10226,127 @@ void ImGui::ShowTestWindow(bool* opened) //ImGui::PushItemWidth(-1); //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4); //ImGui::PopItemWidth(); + + if (ImGui::TreeNode("Multi-component Widgets")) + { + ImGui::Unindent(); + + static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + static int vec4i[4] = { 1, 5, 100, 255 }; + + ImGui::InputFloat2("input float2", vec4f); + ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f); + ImGui::DragInt2("drag int2", vec4i, 1, 0, 255); + ImGui::InputInt2("input int2", vec4i); + ImGui::SliderInt2("slider int2", vec4i, 0, 255); + + ImGui::InputFloat3("input float3", vec4f); + ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f); + ImGui::DragInt3("drag int3", vec4i, 1, 0, 255); + ImGui::InputInt3("input int3", vec4i); + ImGui::SliderInt3("slider int3", vec4i, 0, 255); + + ImGui::InputFloat4("input float4", vec4f); + ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f); + ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f); + ImGui::InputInt4("input int4", vec4i); + ImGui::DragInt4("drag int4", vec4i, 1, 0, 255); + ImGui::SliderInt4("slider int4", vec4i, 0, 255); + + ImGui::Indent(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Vertical Sliders")) + { + ImGui::Unindent(); + const float spacing = 4; + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, spacing)); + + static int int_value = 0; + ImGui::VSliderInt("##int", ImVec2(18,160), &int_value, 0, 5); + ImGui::SameLine(); + + static float values[7] = { 0.0f, 0.60f, 0.35f, 0.9f, 0.70f, 0.20f, 0.0f }; + ImGui::PushID("set1"); + for (int i = 0; i < 7; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(i/7.0f, 0.5f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImColor::HSV(i/7.0f, 0.6f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImColor::HSV(i/7.0f, 0.7f, 0.5f)); + ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(i/7.0f, 0.9f, 0.9f)); + ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, ""); + if (ImGui::IsItemActive() || ImGui::IsItemHovered()) + ImGui::SetTooltip("%.3f", values[i]); + ImGui::PopStyleColor(4); + ImGui::PopID(); + } + ImGui::PopID(); + + ImGui::SameLine(); + ImGui::PushID("set2"); + static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f }; + const int rows = 3; + const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows); + for (int nx = 0; nx < 4; nx++) + { + if (nx > 0) ImGui::SameLine(); + ImGui::BeginGroup(); + for (int ny = 0; ny < rows; ny++) + { + ImGui::PushID(nx*rows+ny); + ImGui::VSliderFloat("##v", small_slider_size, &values2[nx], 0.0f, 1.0f, ""); + if (ImGui::IsItemActive() || ImGui::IsItemHovered()) + ImGui::SetTooltip("%.3f", values2[nx]); + ImGui::PopID(); + } + ImGui::EndGroup(); + } + ImGui::PopID(); + + ImGui::SameLine(); + ImGui::PushID("set3"); + for (int i = 0; i < 4; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40); + ImGui::VSliderFloat("##v", ImVec2(40,160), &values[i], 0.0f, 1.0f, "%.2f"); + ImGui::PopStyleVar(); + ImGui::PopID(); + } + ImGui::PopID(); + ImGui::PopStyleVar(); + + ImGui::Indent(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Dragging")) + { + // You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget. + static ImVec2 value_raw(0.0f, 0.0f); + static ImVec2 value_with_lock_threshold(0.0f, 0.0f); + ImGui::Button("Drag Me"); + if (ImGui::IsItemActive()) + { + value_raw = ImGui::GetMouseDragDelta(0, 0.0f); + value_with_lock_threshold = ImGui::GetMouseDragDelta(0); + //ImGui::SetTooltip("Delta: %.1f, %.1f", value.x, value.y); + + // Draw a line between the button and the mouse cursor + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->PushClipRectFullScreen(); + draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f); + draw_list->PopClipRect(); + } + ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y); + ImGui::TreePop(); + } } if (ImGui::CollapsingHeader("Graphs widgets")) @@ -8941,84 +10355,198 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); static bool pause; - static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); } - static size_t values_offset = 0; - if (!pause) - { + static ImVector<float> values; if (values.empty()) { values.resize(90); memset(&values.front(), 0, values.size()*sizeof(float)); } + static size_t values_offset = 0; + if (!pause) + { // create dummy data at fixed 60 hz rate static float refresh_time = -1.0f; if (ImGui::GetTime() > refresh_time + 1.0f/60.0f) { refresh_time = ImGui::GetTime(); static float phase = 0.0f; - values[values_offset] = cosf(phase); - values_offset = (values_offset+1)%values.size(); - phase += 0.10f*values_offset; + values[values_offset] = cosf(phase); + values_offset = (values_offset+1)%values.size(); + phase += 0.10f*values_offset; } } - ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70)); - - ImGui::SameLine(); ImGui::Checkbox("pause", &pause); - ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70)); + ImGui::PlotLines("##Graph", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); + ImGui::SameLine(0, (int)ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::BeginGroup(); + ImGui::Text("Graph"); + ImGui::Checkbox("pause", &pause); + ImGui::EndGroup(); + ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80)); } - if (ImGui::CollapsingHeader("Horizontal Layout")) + if (ImGui::CollapsingHeader("Layout")) { - // Text - ImGui::Text("Hello"); - ImGui::SameLine(); - ImGui::Text("World"); + if (ImGui::TreeNode("Widgets Alignment")) + { + static float f = 0.0f; + ImGui::Text("Fixed: 100 pixels"); + ImGui::PushItemWidth(100); + ImGui::InputFloat("float##1", &f); + ImGui::PopItemWidth(); - // Button - if (ImGui::Button("Banana")) printf("Pressed!\n"); - ImGui::SameLine(); - ImGui::Button("Apple"); - ImGui::SameLine(); - ImGui::Button("Corniflower"); + ImGui::Text("Proportional: 50%% of window width"); + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f); + ImGui::InputFloat("float##2", &f); + ImGui::PopItemWidth(); - // Button - ImGui::Text("Small buttons"); - ImGui::SameLine(); - ImGui::SmallButton("Like this one"); - ImGui::SameLine(); - ImGui::Text("can fit within a text block."); + ImGui::Text("Right-aligned: Leave 100 pixels for label"); + ImGui::PushItemWidth(-100); + ImGui::InputFloat("float##3", &f); + ImGui::PopItemWidth(); - // Checkbox - static bool c1=false,c2=false,c3=false,c4=false; - ImGui::Checkbox("My", &c1); - ImGui::SameLine(); - ImGui::Checkbox("Tailor", &c2); - ImGui::SameLine(); - ImGui::Checkbox("Is", &c3); - ImGui::SameLine(); - ImGui::Checkbox("Rich", &c4); - - // Various - static float f0=1.0f, f1=2.0f, f2=3.0f; - ImGui::PushItemWidth(80); - const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" }; - static int item = -1; - ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); - ImGui::SameLine(); - ImGui::SliderFloat("X", &f0, 0.0f,5.0f); - ImGui::SameLine(); - ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); - ImGui::SameLine(); - ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); - ImGui::PopItemWidth(); + ImGui::TreePop(); + } - ImGui::PushItemWidth(80); - ImGui::Text("Lists:"); - static int selection[4] = { 0, 1, 2, 3 }; - for (int i = 0; i < 4; i++) + if (ImGui::TreeNode("Basic Horizontal Layout")) { - if (i > 0) ImGui::SameLine(); - ImGui::PushID(i); - ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items)); - ImGui::PopID(); - //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i); + ImGui::TextWrapped("(Use ImGui::SameLine() to keep adding items to the right of the preceeding item)"); + + // Text + ImGui::Text("Two items: Hello"); + ImGui::SameLine(); + ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); + + // Adjust spacing + ImGui::Text("More spacing: Hello"); + ImGui::SameLine(0, 20); + ImGui::TextColored(ImVec4(1,1,0,1), "Sailor"); + + // Button + ImGui::AlignFirstTextHeightToWidgets(); + ImGui::Text("Normal buttons"); ImGui::SameLine(); + ImGui::Button("Banana"); ImGui::SameLine(); + ImGui::Button("Apple"); ImGui::SameLine(); + ImGui::Button("Corniflower"); + + // Button + ImGui::Text("Small buttons"); ImGui::SameLine(); + ImGui::SmallButton("Like this one"); ImGui::SameLine(); + ImGui::Text("can fit within a text block."); + + // Aligned to arbitrary position. Easy/cheap column. + ImGui::Text("Aligned"); + ImGui::SameLine(150); ImGui::Text("x=150"); + ImGui::SameLine(300); ImGui::Text("x=300"); + ImGui::Text("Aligned"); + ImGui::SameLine(150); ImGui::SmallButton("x=150"); + ImGui::SameLine(300); ImGui::SmallButton("x=300"); + + // Checkbox + static bool c1=false,c2=false,c3=false,c4=false; + ImGui::Checkbox("My", &c1); ImGui::SameLine(); + ImGui::Checkbox("Tailor", &c2); ImGui::SameLine(); + ImGui::Checkbox("Is", &c3); ImGui::SameLine(); + ImGui::Checkbox("Rich", &c4); + + // Various + static float f0=1.0f, f1=2.0f, f2=3.0f; + ImGui::PushItemWidth(80); + const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" }; + static int item = -1; + ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine(); + ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine(); + ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine(); + ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); + ImGui::PopItemWidth(); + + ImGui::PushItemWidth(80); + ImGui::Text("Lists:"); + static int selection[4] = { 0, 1, 2, 3 }; + for (int i = 0; i < 4; i++) + { + if (i > 0) ImGui::SameLine(); + ImGui::PushID(i); + ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items)); + ImGui::PopID(); + //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i); + } + ImGui::PopItemWidth(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Groups")) + { + ImGui::TextWrapped("(Using ImGui::BeginGroup()/EndGroup() to layout items)"); + + ImVec2 size; + ImGui::BeginGroup(); + { + ImGui::BeginGroup(); + ImGui::Button("AAA"); + ImGui::SameLine(); + ImGui::Button("BBB"); + ImGui::SameLine(); + ImGui::BeginGroup(); + ImGui::Button("CCC"); + ImGui::Button("DDD"); + ImGui::EndGroup(); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip("Group hovered"); + ImGui::SameLine(); + ImGui::Button("EEE"); + ImGui::EndGroup(); + + // Capture the group size and create widgets using the same size + size = ImGui::GetItemRectSize(); + const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f }; + ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size); + } + ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); + ImGui::SameLine(); + ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); + ImGui::EndGroup(); + ImGui::SameLine(); + + ImGui::Button("LEVERAGE\nBUZZWORD", size); + ImGui::SameLine(); + + ImGui::ListBoxHeader("List", size); + ImGui::Selectable("Selected", true); + ImGui::Selectable("Not Selected", false); + ImGui::ListBoxFooter(); + + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Text Baseline Alignment")) + { + ImGui::TextWrapped("(This is testing the vertical alignment that occurs on text to keep it at the same baseline as widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets)"); + + ImGui::Text("One\nTwo\nThree"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("One\nTwo\nThree"); + + ImGui::Button("HOP"); ImGui::SameLine(); + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Button("HOP"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Button("TEST"); ImGui::SameLine(); + ImGui::Text("TEST"); ImGui::SameLine(); + ImGui::SmallButton("TEST"); + + ImGui::AlignFirstTextHeightToWidgets(); // If your line starts with text, call this to align it to upcoming widgets. + ImGui::Text("Text aligned to Widget"); ImGui::SameLine(); + ImGui::Button("Widget"); ImGui::SameLine(); + ImGui::Text("Widget"); ImGui::SameLine(); + ImGui::SmallButton("Widget"); + + ImGui::TreePop(); } - ImGui::PopItemWidth(); } if (ImGui::CollapsingHeader("Child regions")) @@ -9026,7 +10554,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Text("Without border"); static int line = 50; bool goto_line = ImGui::Button("Goto"); - ImGui::SameLine(); + ImGui::SameLine(); ImGui::PushItemWidth(100); goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::PopItemWidth(); @@ -9064,6 +10592,7 @@ void ImGui::ShowTestWindow(bool* opened) // Basic columns ImGui::Text("Basic:"); ImGui::Columns(4, "mycolumns"); + ImGui::Separator(); ImGui::Text("ID"); ImGui::NextColumn(); ImGui::Text("Name"); ImGui::NextColumn(); ImGui::Text("Path"); ImGui::NextColumn(); @@ -9075,7 +10604,7 @@ void ImGui::ShowTestWindow(bool* opened) { ImGui::Text("%04d", i); ImGui::NextColumn(); ImGui::Text(names[i]); ImGui::NextColumn(); - ImGui::Text(paths[i]); ImGui::NextColumn(); + ImGui::Text(paths[i]); ImGui::NextColumn(); ImGui::Text("...."); ImGui::NextColumn(); } ImGui::Columns(1); @@ -9084,7 +10613,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Spacing(); // Scrolling columns - /* + /* ImGui::Text("Scrolling:"); ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y)); ImGui::Columns(3); @@ -9107,7 +10636,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Separator(); ImGui::Spacing(); - */ + */ // Create multiple items in a same cell before switching to next column ImGui::Text("Mixed items:"); @@ -9115,24 +10644,24 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Separator(); static int e = 0; - ImGui::Text("Hello"); + ImGui::Text("Hello"); ImGui::Button("Banana"); - ImGui::RadioButton("radio a", &e, 0); + ImGui::RadioButton("radio a", &e, 0); ImGui::NextColumn(); - ImGui::Text("ImGui"); + ImGui::Text("ImGui"); ImGui::Button("Apple"); ImGui::RadioButton("radio b", &e, 1); static float foo = 1.0f; - ImGui::InputFloat("red", &foo, 0.05f, 0, 3); + ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::Text("An extra line here."); ImGui::NextColumn(); - - ImGui::Text("World!"); + + ImGui::Text("Sailor"); ImGui::Button("Corniflower"); ImGui::RadioButton("radio c", &e, 2); static float bar = 1.0f; - ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); + ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn(); if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn(); @@ -9147,8 +10676,8 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Text("Tree items:"); ImGui::Columns(2, "tree items"); ImGui::Separator(); - if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn(); - if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } ImGui::NextColumn(); + if (ImGui::TreeNode("Hello")) { ImGui::BulletText("Sailor"); ImGui::TreePop(); } ImGui::NextColumn(); + if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Marin"); ImGui::TreePop(); } ImGui::NextColumn(); ImGui::Columns(1); ImGui::Separator(); @@ -9211,7 +10740,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::BulletText("%s", lines[i]); } - if (ImGui::CollapsingHeader("Keyboard & Focus")) + if (ImGui::CollapsingHeader("Keyboard, Mouse & Focus")) { if (ImGui::TreeNode("Tabbing")) { @@ -9235,11 +10764,11 @@ void ImGui::ShowTestWindow(bool* opened) bool focus_3 = ImGui::Button("Focus on 3"); int has_focus = 0; static char buf[128] = "click on a button to set focus"; - + if (focus_1) ImGui::SetKeyboardFocusHere(); ImGui::InputText("1", buf, IM_ARRAYSIZE(buf)); if (ImGui::IsItemActive()) has_focus = 1; - + if (focus_2) ImGui::SetKeyboardFocusHere(); ImGui::InputText("2", buf, IM_ARRAYSIZE(buf)); if (ImGui::IsItemActive()) has_focus = 2; @@ -9251,15 +10780,32 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::PopAllowKeyboardFocus(); if (has_focus) ImGui::Text("Item with focus: %d", has_focus); - else + else ImGui::Text("Item with focus: <none>"); ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code."); ImGui::TreePop(); } + + if (ImGui::TreeNode("Mouse cursors")) + { + ImGui::TextWrapped("(Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. You can also set io.MouseDrawCursor to ask ImGui to render the cursor for you in software)"); + ImGui::Checkbox("io.MouseDrawCursor", &ImGui::GetIO().MouseDrawCursor); + ImGui::Text("Hover to see mouse cursors:"); + for (int i = 0; i < ImGuiMouseCursor_Count_; i++) + { + char label[32]; + sprintf(label, "Mouse cursor %d", i); + ImGui::Bullet(); ImGui::Selectable(label, false); + if (ImGui::IsItemHovered()) + ImGui::SetMouseCursor(i); + } + ImGui::TreePop(); + } } if (ImGui::CollapsingHeader("App Examples")) { + ImGui::Checkbox("Metrics", &show_app_metrics); ImGui::Checkbox("Console", &show_app_console); ImGui::Checkbox("Long text display", &show_app_long_text); ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize); @@ -9271,16 +10817,79 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::End(); } +void ImGui::ShowMetricsWindow(bool* opened) +{ + if (ImGui::Begin("ImGui Metrics", opened)) + { + ImGui::Text("ImGui %s", ImGui::GetVersion()); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::Text("%d vertices", ImGui::GetIO().MetricsRenderVertices); + ImGui::Separator(); + + struct Funcs + { + static void NodeDrawList(ImDrawList* draw_list, const char* label) + { + bool node_opened = ImGui::TreeNode(draw_list, "%s: %d vtx, %d cmds", label, draw_list->vtx_buffer.size(), draw_list->commands.size()); + if (draw_list == ImGui::GetWindowDrawList()) + { + ImGui::SameLine(); + ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered) + } + if (!node_opened) + return; + for (const ImDrawCmd* pcmd = draw_list->commands.begin(); pcmd < draw_list->commands.end(); pcmd++) + if (pcmd->user_callback) + ImGui::BulletText("Callback %p, user_data %p", pcmd->user_callback, pcmd->user_callback_data); + else + ImGui::BulletText("Draw %d vtx, tex = %p", pcmd->vtx_count, pcmd->texture_id); + ImGui::TreePop(); + } + + static void NodeWindows(ImVector<ImGuiWindow*>& windows, const char* label) + { + if (!ImGui::TreeNode(label, "%s (%d)", label, (int)windows.size())) + return; + for (int i = 0; i < (int)windows.size(); i++) + Funcs::NodeWindow(windows[i], "Window"); + ImGui::TreePop(); + } + + static void NodeWindow(ImGuiWindow* window, const char* label) + { + if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Active || window->WasActive, window)) + return; + NodeDrawList(window->DrawList, "DrawList"); + if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow"); + if (window->DC.ChildWindows.size() > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows"); + ImGui::TreePop(); + } + }; + + ImGuiState& g = *GImGui; // Access private state + g.DisableHideTextAfterDoubleHash++; // Not exposed (yet). Disable processing that hides text after '##' markers. + Funcs::NodeWindows(g.Windows, "Windows"); + if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", (int)g.RenderDrawLists[0].size())) + { + for (int i = 0; i < (int)g.RenderDrawLists[0].size(); i++) + Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList"); + ImGui::TreePop(); + } + g.DisableHideTextAfterDoubleHash--; + } + ImGui::End(); +} + static void ShowExampleAppAutoResize(bool* opened) { - if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize)) + if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::End(); return; } static int lines = 10; - ImGui::TextWrapped("Window will resize every-frame to the size of its content. Note that you don't want to query the window size to output your content because that would create a feedback loop."); + ImGui::Text("Window will resize every-frame to the size of its content.\nNote that you probably don't want to query the window size to\noutput your content because that would create a feedback loop."); ImGui::SliderInt("Number of lines", &lines, 1, 20); for (int i = 0; i < lines; i++) ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally @@ -9290,22 +10899,24 @@ static void ShowExampleAppAutoResize(bool* opened) static void ShowExampleAppFixedOverlay(bool* opened) { + ImGui::SetNextWindowPos(ImVec2(10,10)); if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings)) { ImGui::End(); return; } - ImGui::SetWindowPos(ImVec2(10,10)); ImGui::Text("Simple overlay\non the top-left side of the screen."); ImGui::Separator(); - ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); + ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); ImGui::End(); } -static void ShowExampleAppManipulatingWindowTitle(bool* /*opened*/) +static void ShowExampleAppManipulatingWindowTitle(bool* opened) { + (void)opened; + // By default, Windows are uniquely identified by their title. // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file! @@ -9320,9 +10931,9 @@ static void ShowExampleAppManipulatingWindowTitle(bool* /*opened*/) ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique."); ImGui::End(); - // Using "###" to display a changing title but keep a static identifier "MyWindow" + // Using "###" to display a changing title but keep a static identifier "AnimatedTitle" char buf[128]; - ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###MyWindow", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand()); + ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand()); ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver); ImGui::Begin(buf); ImGui::Text("This window has a changing title."); @@ -9412,14 +11023,14 @@ struct ExampleAppConsole ~ExampleAppConsole() { ClearLog(); - for (size_t i = 0; i < Items.size(); i++) - ImGui::MemFree(History[i]); + for (size_t i = 0; i < Items.size(); i++) + ImGui::MemFree(History[i]); } void ClearLog() { - for (size_t i = 0; i < Items.size(); i++) - ImGui::MemFree(Items[i]); + for (size_t i = 0; i < Items.size(); i++) + ImGui::MemFree(Items[i]); Items.clear(); ScrollToBottom = true; } @@ -9437,7 +11048,8 @@ struct ExampleAppConsole void Run(const char* title, bool* opened) { - if (!ImGui::Begin(title, opened, ImVec2(520,600))) + ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver); + if (!ImGui::Begin(title, opened)) { ImGui::End(); return; @@ -9449,8 +11061,8 @@ struct ExampleAppConsole // TODO: display from bottom // TODO: clip manually - if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); - if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine(); + if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); + if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine(); if (ImGui::SmallButton("Clear")) ClearLog(); //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); } @@ -9459,7 +11071,7 @@ struct ExampleAppConsole ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); static ImGuiTextFilter filter; filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180); - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + //if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover ImGui::PopStyleVar(); ImGui::Separator(); @@ -9497,7 +11109,9 @@ struct ExampleAppConsole strcpy(InputBuf, ""); } - if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover + // Demonstrate keeping auto focus on the input box + if (ImGui::IsItemHovered() || (ImGui::IsRootWindowOrAnyChildFocused() && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0))) + ImGui::SetKeyboardFocusHere(-1); // Auto focus ImGui::End(); } @@ -9654,7 +11268,8 @@ static void ShowExampleAppConsole(bool* opened) static void ShowExampleAppLongText(bool* opened) { - if (!ImGui::Begin("Example: Long text display", opened, ImVec2(520,600))) + ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver); + if (!ImGui::Begin("Example: Long text display", opened)) { ImGui::End(); return; @@ -9664,7 +11279,7 @@ static void ShowExampleAppLongText(bool* opened) static ImGuiTextBuffer log; static int lines = 0; ImGui::Text("Printing unusually long amount of text."); - ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped"); + ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped"); ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); if (ImGui::Button("Clear")) { log.clear(); lines = 0; } ImGui::SameLine(); @@ -9705,20 +11320,14 @@ static void ShowExampleAppLongText(bool* opened) } // End of Sample code +#endif //----------------------------------------------------------------------------- // FONT DATA //----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// ProggyClean.ttf -// Copyright (c) 2004, 2005 Tristan Grimmer -// MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) -// Download and more information at http://upperbounds.net -//----------------------------------------------------------------------------- // Compressed with stb_compress() then converted to a C array. -// Decompressor from stb.h (public domain) by Sean Barrett -// https://github.com/nothings/stb/blob/master/stb.h +// Use the program in extra_fonts/binary_to_compressed_c.cpp to create the array from a TTF file. +// Decompressor from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h //----------------------------------------------------------------------------- static unsigned int stb_decompress_length(unsigned char *input) @@ -9727,12 +11336,11 @@ static unsigned int stb_decompress_length(unsigned char *input) } static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4; - static unsigned char *stb__dout; static void stb__match(unsigned char *data, unsigned int length) { // INVERSE of memmove... write each byte before copying the next... - assert (stb__dout + length <= stb__barrier); + IM_ASSERT (stb__dout + length <= stb__barrier); if (stb__dout + length > stb__barrier) { stb__dout += length; return; } if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; } while (length--) *stb__dout++ = *data++; @@ -9740,7 +11348,7 @@ static void stb__match(unsigned char *data, unsigned int length) static void stb__lit(unsigned char *data, unsigned int length) { - assert (stb__dout + length <= stb__barrier); + IM_ASSERT (stb__dout + length <= stb__barrier); if (stb__dout + length > stb__barrier) { stb__dout += length; return; } if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; } memcpy(stb__dout, data, length); @@ -9817,225 +11425,231 @@ static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsi i = stb_decompress_token(i); if (i == old_i) { if (*i == 0x05 && i[1] == 0xfa) { - assert(stb__dout == output + olen); + IM_ASSERT(stb__dout == output + olen); if (stb__dout != output + olen) return 0; if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2)) return 0; return olen; } else { - assert(0); /* NOTREACHED */ + IM_ASSERT(0); /* NOTREACHED */ return 0; } } - assert(stb__dout <= output + olen); + IM_ASSERT(stb__dout <= output + olen); if (stb__dout > output + olen) return 0; } } +//----------------------------------------------------------------------------- +// ProggyClean.ttf +// Copyright (c) 2004, 2005 Tristan Grimmer +// MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) +// Download and more information at http://upperbounds.net +//----------------------------------------------------------------------------- static const unsigned int proggy_clean_ttf_compressed_size = 9583; static const unsigned int proggy_clean_ttf_compressed_data[9584/4] = { - 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e, - 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568, - 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c, - 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70, - 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008, - 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120, - 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc, - 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103, - 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501, - 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582, - 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384, - 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382, - 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682, - 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02, - 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09, - 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412, - 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a, - 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421, - 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658, - 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d, - 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636, - 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240, - 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648, - 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00, - 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221, - 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715, - 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039, - 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd, - 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff, - 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221, - 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb, - 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9, - 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209, - 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783, - 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123, - 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f, - 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1, - 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909, - 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906, - 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4, - 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb, - 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001, - 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100, - 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514, - 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42, - 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008, - 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a, - 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00, - 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715, - 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120, - 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857, - 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944, - 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5, - 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350, - 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4, - 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7, - 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1, - 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42, - 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205, - 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d, - 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b, - 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00, - 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05, - 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2, - 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596, - 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46, - 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723, - 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7, - 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f, - 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d, - 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585, - 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b, - 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff, - 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7, - 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983, - 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53, - 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169, - 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145, - 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b, - 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20, - 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005, - 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47, - 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c, - 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f, - 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f, - 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413, - 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888, - 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b, - 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a, - 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76, - 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f, - 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008, - 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128, - 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020, - 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006, - 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709, - 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f, - 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31, - 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523, - 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584, - 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff, - 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7, - 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42, - 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807, - 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c, - 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e, - 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120, - 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e, - 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3, - 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461, - 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429, - 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d, - 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618, - 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f, - 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682, - 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00, - 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218, - 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317, - 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280, - 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008, - 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977, - 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53, - 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c, - 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502, - 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159, - 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000, - 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c, - 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c, - 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63, - 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13, - 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213, - 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe, - 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755, - 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f, - 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349, - 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f, - 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41, - 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d, - 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9, - 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079, - 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805, - 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d, - 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c, - 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f, - 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84, - 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358, - 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830, - 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60, - 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783, - 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80, - 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108, - 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001, - 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748, - 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46, - 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52, - 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b, - 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342, - 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020, - 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7, - 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e, - 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743, - 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159, - 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c, - 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42, - 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745, - 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94, - 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c, - 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108, - 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d, - 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4, - 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c, - 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b, - 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810, - 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab, - 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443, - 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f, - 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a, - 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031, - 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785, - 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972, - 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200, - 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82, - 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102, - 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115, - 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f, - 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700, - 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00, - 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056, - 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d, - 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085, - 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa, - 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0, - 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073, - 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365, - 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d, - 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, - 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d, - 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, - 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, - 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9, + 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e, + 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568, + 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c, + 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70, + 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008, + 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120, + 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc, + 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103, + 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501, + 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582, + 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384, + 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382, + 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682, + 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02, + 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09, + 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412, + 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a, + 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421, + 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658, + 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d, + 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636, + 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240, + 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648, + 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00, + 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221, + 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715, + 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039, + 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd, + 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff, + 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221, + 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb, + 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9, + 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209, + 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783, + 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123, + 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f, + 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1, + 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909, + 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906, + 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4, + 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb, + 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001, + 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100, + 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514, + 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42, + 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008, + 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a, + 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00, + 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715, + 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120, + 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857, + 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944, + 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5, + 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350, + 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4, + 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7, + 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1, + 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42, + 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205, + 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d, + 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b, + 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00, + 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05, + 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2, + 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596, + 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46, + 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723, + 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7, + 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f, + 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d, + 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585, + 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b, + 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff, + 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7, + 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983, + 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53, + 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169, + 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145, + 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b, + 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20, + 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005, + 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47, + 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c, + 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f, + 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f, + 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413, + 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888, + 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b, + 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a, + 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76, + 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f, + 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008, + 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128, + 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020, + 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006, + 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709, + 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f, + 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31, + 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523, + 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584, + 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff, + 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7, + 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42, + 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807, + 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c, + 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e, + 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120, + 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e, + 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3, + 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461, + 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429, + 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d, + 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618, + 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f, + 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682, + 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00, + 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218, + 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317, + 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280, + 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008, + 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977, + 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53, + 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c, + 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502, + 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159, + 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000, + 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c, + 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c, + 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63, + 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13, + 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213, + 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe, + 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755, + 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f, + 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349, + 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f, + 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41, + 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d, + 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9, + 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079, + 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805, + 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d, + 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c, + 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f, + 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84, + 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358, + 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830, + 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60, + 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783, + 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80, + 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108, + 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001, + 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748, + 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46, + 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52, + 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b, + 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342, + 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020, + 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7, + 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e, + 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743, + 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159, + 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c, + 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42, + 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745, + 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94, + 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c, + 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108, + 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d, + 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4, + 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c, + 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b, + 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810, + 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab, + 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443, + 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f, + 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a, + 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031, + 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785, + 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972, + 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200, + 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82, + 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102, + 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115, + 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f, + 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700, + 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00, + 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056, + 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d, + 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085, + 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa, + 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0, + 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073, + 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365, + 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d, + 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, + 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d, + 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, + 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, + 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9, }; static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size) diff --git a/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h b/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h index dbea1bc0a45..19a233fb081 100644 --- a/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h +++ b/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.35 +// ImGui library v1.39 WIP // See .cpp file for documentation. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. @@ -9,9 +9,11 @@ #include "imconfig.h" // User-editable configuration file #include <float.h> // FLT_MAX #include <stdarg.h> // va_list -#include <stddef.h> // ptrdiff_t -#include <stdlib.h> // NULL, malloc -#include <string.h> // memset, memmove +#include <stddef.h> // ptrdiff_t, NULL +#include <stdlib.h> // NULL, malloc, free, qsort, atoi +#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp + +#define IMGUI_VERSION "1.39 WIP" // Define assertion handler. #ifndef IM_ASSERT @@ -34,26 +36,28 @@ struct ImGuiStorage; struct ImGuiStyle; typedef unsigned int ImU32; -typedef unsigned short ImWchar; // character for display +typedef unsigned short ImWchar; // character for keyboard input/display typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id) typedef ImU32 ImGuiID; // unique ID used by widgets (typically hashed from a stack of string) typedef int ImGuiCol; // enum ImGuiCol_ typedef int ImGuiStyleVar; // enum ImGuiStyleVar_ typedef int ImGuiKey; // enum ImGuiKey_ +typedef int ImGuiAlign; // enum ImGuiAlign_ typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_ +typedef int ImGuiMouseCursor; // enum ImGuiMouseCursor_ typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_ -typedef int ImGuiSetCond; // enum ImGuiSetCondition_ +typedef int ImGuiSetCond; // enum ImGuiSetCond_ typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_ -struct ImGuiTextEditCallbackData; // for advanced uses of InputText() +struct ImGuiTextEditCallbackData; // for advanced uses of InputText() typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); struct ImVec2 { float x, y; - ImVec2() {} + ImVec2() { x = y = 0.0f; } ImVec2(float _x, float _y) { x = _x; y = _y; } -#ifdef IM_VEC2_CLASS_EXTRA +#ifdef IM_VEC2_CLASS_EXTRA // Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2. IM_VEC2_CLASS_EXTRA #endif }; @@ -61,10 +65,10 @@ struct ImVec2 struct ImVec4 { float x, y, z, w; - ImVec4() {} + ImVec4() { x = y = z = w = 0.0f; } ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } -#ifdef IM_VEC4_CLASS_EXTRA +#ifdef IM_VEC4_CLASS_EXTRA // Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec4. IM_VEC4_CLASS_EXTRA #endif }; @@ -76,9 +80,9 @@ namespace ImGui IMGUI_API void MemFree(void* ptr); } -// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). +// Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). // Use '#define ImVector std::vector' if you want to use the STL type or your own type. -// Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need. +// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code! #ifndef ImVector template<typename T> class ImVector @@ -117,14 +121,14 @@ public: inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } - inline void reserve(size_t new_capacity) - { + inline void reserve(size_t new_capacity) + { if (new_capacity <= Capacity) return; T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type)); memcpy(new_data, Data, Size * sizeof(value_type)); ImGui::MemFree(Data); Data = new_data; - Capacity = new_capacity; + Capacity = new_capacity; } inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } @@ -140,11 +144,14 @@ public: // - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) +// - struct ImGuiTextEditCallbackData // Shared state of ImGui::InputText() when using custom callbacks +// - struct ImColor // Helper functions to created packed 32-bit RGBA color values // - struct ImDrawList // Draw command list -// - struct ImFont // TTF font loader, bake glyphs into bitmap +// - struct ImFontAtlas // Bake multiple fonts into a single texture, TTF font loader, bake glyphs into bitmap +// - struct ImFont // Single font // ImGui end-user API -// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types) +// In a namespace so that user can add extra functions in a separate file (e.g. Value() helpers for your vector or common types) namespace ImGui { // Main @@ -153,48 +160,49 @@ namespace ImGui IMGUI_API void NewFrame(); IMGUI_API void Render(); IMGUI_API void Shutdown(); - IMGUI_API void ShowUserGuide(); - IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); - IMGUI_API void ShowTestWindow(bool* open = NULL); + IMGUI_API void ShowUserGuide(); // help block + IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // style editor block + IMGUI_API void ShowTestWindow(bool* opened = NULL); // test window, demonstrate ImGui features + IMGUI_API void ShowMetricsWindow(bool* opened = NULL); // metrics window for debugging imgui // Window // See implementation in .cpp for details - IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, const ImVec2& initial_size = ImVec2(0,0), float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. + IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. 'bool* p_opened' creates a widget on the upper-right to close the window (which sets your bool to false). + IMGUI_API bool Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_use, float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // this is the older/longer API. call SetNextWindowSize() instead if you want to set a window size. For regular windows, 'size_on_first_use' only applies to the first time EVER the window is created and probably not what you want! maybe obsolete this API eventually. IMGUI_API void End(); - IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis. - IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // " + IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400). + IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // " IMGUI_API void EndChild(); - IMGUI_API bool GetWindowIsFocused(); IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries, in windows coordinates IMGUI_API ImVec2 GetWindowContentRegionMin(); // window boundaries, in windows coordinates IMGUI_API ImVec2 GetWindowContentRegionMax(); - IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives. + IMGUI_API ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives IMGUI_API ImFont* GetWindowFont(); IMGUI_API float GetWindowFontSize(); // size (also height in pixels) of current font with current scale applied - IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows. - IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing. - IMGUI_API ImVec2 GetWindowSize(); // get current window position. + IMGUI_API void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontGlobalScale if you want to scale all windows + IMGUI_API ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to do your own drawing + IMGUI_API ImVec2 GetWindowSize(); // get current window position IMGUI_API float GetWindowWidth(); IMGUI_API bool GetWindowCollapsed(); - IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin(). - IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit. - IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state. + IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin() + IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit + IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most - IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing. - IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. - IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set current window collapsed state. + IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing + IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing + IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set current window collapsed state IMGUI_API void SetWindowFocus(); // set current window to be focused / front-most - IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond = 0); // set named window position - call within Begin()/End(). may incur tearing. - IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0); // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. - IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0); // set named window collapsed state. - IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most + IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond = 0); // set named window position - call within Begin()/End(). may incur tearing + IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0); // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing + IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0); // set named window collapsed state + IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most. use NULL to remove focus. - IMGUI_API float GetScrollPosY(); // get scrolling position (0..GetScrollMaxY()) + IMGUI_API float GetScrollPosY(); // get scrolling position [0..GetScrollMaxY()] IMGUI_API float GetScrollMaxY(); // get maximum scrolling position == ContentSize.Y - WindowSize.Y - IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. - IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. - IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it). + IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position + IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget + IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it) IMGUI_API ImGuiStorage* GetStateStorage(); // Parameters stacks (shared) @@ -207,29 +215,37 @@ namespace ImGui IMGUI_API void PopStyleVar(int count = 1); // Parameters stacks (current window) - IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -0.01f always align width to the right side) + IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side) IMGUI_API void PopItemWidth(); IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position - IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. + IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets IMGUI_API void PopAllowKeyboardFocus(); - IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space. + IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space IMGUI_API void PopTextWrapPos(); // Tooltip - IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins. + IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins IMGUI_API void SetTooltipV(const char* fmt, va_list args); - IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text. + IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text IMGUI_API void EndTooltip(); + // Popup + IMGUI_API void BeginPopup(bool* p_opened); + IMGUI_API void EndPopup(); + // Layout + IMGUI_API void BeginGroup(); + IMGUI_API void EndGroup(); IMGUI_API void Separator(); // horizontal line - IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally - IMGUI_API void Spacing(); - IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns + IMGUI_API void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets or groups to layout them horizontally + IMGUI_API void Spacing(); // add vertical spacing + IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels + IMGUI_API void Unindent(); // move content position back to the left (cancel Indent) + IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1). IMGUI_API void NextColumn(); // next column IMGUI_API int GetColumnIndex(); // get current column index - IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this. - IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column. + IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this + IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column IMGUI_API float GetColumnWidth(int column_index = -1); // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset()) IMGUI_API int GetColumnsCount(); // number of columns (what was passed to Columns()) IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position @@ -238,20 +254,22 @@ namespace ImGui IMGUI_API void SetCursorPos(const ImVec2& pos); // " IMGUI_API void SetCursorPosX(float x); // " IMGUI_API void SetCursorPosY(float y); // " - IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize) - IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize) - IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets. + IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates [0..io.DisplaySize] + IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates [0..io.DisplaySize] + IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets IMGUI_API float GetTextLineHeight(); // height of font == GetWindowFontSize() IMGUI_API float GetTextLineHeightWithSpacing(); // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y // ID scopes - // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. + // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them // You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide') IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack! + IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); IMGUI_API void PushID(const void* ptr_id); IMGUI_API void PushID(const int int_id); IMGUI_API void PopID(); - IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed. + IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed + IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end); IMGUI_API ImGuiID GetID(const void* ptr_id); // Widgets @@ -261,8 +279,8 @@ namespace ImGui IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args); IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos(); IMGUI_API void TextWrappedV(const char* fmt, va_list args); - IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text. - IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets + IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text + IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args); IMGUI_API void Bullet(); IMGUI_API void BulletText(const char* fmt, ...); @@ -271,31 +289,12 @@ namespace ImGui IMGUI_API bool SmallButton(const char* label); IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0)); - IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,1), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no paddnig. + IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,1), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false); - IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders. - IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - IMGUI_API bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians - IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); - IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f"); - IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f"); - IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f"); - IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); - IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); IMGUI_API bool Checkbox(const char* label, bool* v); IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); IMGUI_API bool RadioButton(const char* label, bool active); IMGUI_API bool RadioButton(const char* label, int* v, int v_button); - IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); - IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); - IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1); - IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1); - IMGUI_API bool InputFloat4(const char* label, float v[4], int decimal_precision = -1); - IMGUI_API bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0); IMGUI_API bool Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1); IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items = -1); // separate items with \0, end item-list with \0\0 IMGUI_API bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); @@ -303,8 +302,46 @@ namespace ImGui IMGUI_API bool ColorEdit3(const char* label, float col[3]); IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true); IMGUI_API void ColorEditMode(ImGuiColorEditMode mode); + IMGUI_API void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); + IMGUI_API void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); + IMGUI_API void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); + IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); - // Trees + // Widgets: Sliders (tip: ctrl+click on a slider to input text) + IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders + IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); + IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + + // Widgets: Drags (tip: ctrl+click on a drag box to input text) + IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound + IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f); + IMGUI_API bool DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); // If v_min >= v_max we have no bound + IMGUI_API bool DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f"); + + // Widgets: Input + IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); + IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputFloat4(const char* label, float v[4], int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt2(const char* label, int v[2], ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0); + IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0); + + // Widgets: Trees IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // " IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // " @@ -315,8 +352,8 @@ namespace ImGui IMGUI_API void TreePop(); IMGUI_API void SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0); // set next tree node to be opened. - // Selectable / Lists - IMGUI_API bool Selectable(const char* label, bool selected, const ImVec2& size = ImVec2(0,0)); + // Widgets: Selectable / Lists + IMGUI_API bool Selectable(const char* label, bool selected = false, const ImVec2& size = ImVec2(0,0)); IMGUI_API bool Selectable(const char* label, bool* p_selected, const ImVec2& size = ImVec2(0,0)); IMGUI_API bool ListBox(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1); IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); @@ -324,7 +361,12 @@ namespace ImGui IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // " IMGUI_API void ListBoxFooter(); // terminate the scrolling region - // Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace! + // Widgets: Menus + // FIXME-WIP: v1.39 in development + IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false); // bool enabled = true + IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected); // bool enabled = true + + // Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare your own within the ImGui namespace!) IMGUI_API void Value(const char* prefix, bool b); IMGUI_API void Value(const char* prefix, int v); IMGUI_API void Value(const char* prefix, unsigned int v); @@ -332,7 +374,7 @@ namespace ImGui IMGUI_API void Color(const char* prefix, const ImVec4& v); IMGUI_API void Color(const char* prefix, unsigned int v); - // Logging: All text output from your interface are redirected to tty/file/clipboard. Tree nodes are automatically opened. + // Logging: all text output from interface is redirected to tty/file/clipboard. Tree nodes are automatically opened. IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard @@ -342,26 +384,40 @@ namespace ImGui // Utilities IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse? + IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active while we are hovering this IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) - IMGUI_API bool IsAnyItemActive(); // - IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item - IMGUI_API ImVec2 GetItemBoxMax(); // get bounding box of last item - IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization) - IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry + IMGUI_API bool IsAnyItemActive(); // + IMGUI_API bool IsItemVisible(); + IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space + IMGUI_API ImVec2 GetItemRectMax(); // " + IMGUI_API ImVec2 GetItemRectSize(); // " + IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others) + IMGUI_API bool IsRootWindowFocused(); // is current root window focused + IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused + IMGUI_API bool IsRectClipped(const ImVec2& size); // test if rectangle of given size starting from cursor pos is out of clipping region. to perform coarse clipping on user's side (as an optimization) + IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry + IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // " + IMGUI_API bool IsMouseDown(int button); IMGUI_API bool IsMouseClicked(int button, bool repeat = false); IMGUI_API bool IsMouseDoubleClicked(int button); IMGUI_API bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window) IMGUI_API bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window - IMGUI_API bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); // is mouse hovering given bounding box + IMGUI_API bool IsMouseHoveringRect(const ImVec2& rect_min, const ImVec2& rect_max);// is mouse hovering given bounding rect + IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls + IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking, also see: GetItemActiveDragDelta(). if lock_threshold < -1.0f uses io.MouseDraggingThreshold + IMGUI_API void ResetMouseDragDelta(int button = 0); + IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you + IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type IMGUI_API float GetTime(); IMGUI_API int GetFrameCount(); IMGUI_API const char* GetStyleColName(ImGuiCol idx); + IMGUI_API ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = +0.0f); // utility to find the closest point the last item bounding rectangle edge. useful to visually link items IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); - IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // helper to manually clip large list of items. see comments in implementation. + IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // helper to manually clip large list of items. see comments in implementation - IMGUI_API void BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame. + IMGUI_API void BeginChildFrame(ImGuiID id, const ImVec2& size); // helper to create a child window / scrolling region that looks like a normal widget frame IMGUI_API void EndChildFrame(); IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in); @@ -369,13 +425,19 @@ namespace ImGui IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself + IMGUI_API const char* GetVersion(); IMGUI_API void* GetInternalState(); IMGUI_API size_t GetInternalStateSize(); IMGUI_API void SetInternalState(void* state, bool construct = false); // Obsolete (will be removed) - IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); - static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } + IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); // OBSOLETE + static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } // OBSOLETE + static inline bool GetWindowIsFocused() { return ImGui::IsWindowFocused(); } // OBSOLETE + static inline ImVec2 GetItemBoxMin() { return GetItemRectMin(); } // OBSOLETE + static inline ImVec2 GetItemBoxMax() { return GetItemRectMax(); } // OBSOLETE + static inline bool IsClipped(const ImVec2& size) { return IsRectClipped(size); } // OBSOLETE + static inline bool IsMouseHoveringBox(const ImVec2& rect_min, const ImVec2& rect_max) { return IsMouseHoveringRect(rect_min, rect_max); } // OBSOLETE } // namespace ImGui @@ -397,7 +459,8 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 10, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 11, // For internal use by BeginChild() ImGuiWindowFlags_ComboBox = 1 << 12, // For internal use by ComboBox() - ImGuiWindowFlags_Tooltip = 1 << 13 // For internal use by BeginTooltip() + ImGuiWindowFlags_Tooltip = 1 << 13, // For internal use by BeginTooltip() + ImGuiWindowFlags_Popup = 1 << 14 // For internal use by BeginPopup() }; // Flags for ImGui::InputText() @@ -448,6 +511,8 @@ enum ImGuiCol_ ImGuiCol_Border, ImGuiCol_BorderShadow, ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input + ImGuiCol_FrameBgHovered, + ImGuiCol_FrameBgActive, ImGuiCol_TitleBg, ImGuiCol_TitleBgCollapsed, ImGuiCol_ScrollbarBg, @@ -455,8 +520,6 @@ enum ImGuiCol_ ImGuiCol_ScrollbarGrabHovered, ImGuiCol_ScrollbarGrabActive, ImGuiCol_ComboBg, - ImGuiCol_CheckHovered, - ImGuiCol_CheckActive, ImGuiCol_CheckMark, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive, @@ -496,7 +559,16 @@ enum ImGuiStyleVar_ ImGuiStyleVar_FrameRounding, // float ImGuiStyleVar_ItemSpacing, // ImVec2 ImGuiStyleVar_ItemInnerSpacing, // ImVec2 - ImGuiStyleVar_TreeNodeSpacing // float + ImGuiStyleVar_IndentSpacing, // float + ImGuiStyleVar_GrabMinSize // float +}; + +enum ImGuiAlign_ +{ + ImGuiAlign_Left = 1 << 0, + ImGuiAlign_Center = 1 << 1, + ImGuiAlign_Right = 1 << 2, + ImGuiAlign_Default = ImGuiAlign_Left, }; // Enumeration for ColorEditMode() @@ -509,13 +581,27 @@ enum ImGuiColorEditMode_ ImGuiColorEditMode_HEX = 2 }; +// Enumeration for GetMouseCursor() +enum ImGuiMouseCursor_ +{ + ImGuiMouseCursor_Arrow = 0, + ImGuiMouseCursor_TextInput, // When hovering over InputText, etc. + ImGuiMouseCursor_Move, // Unused + ImGuiMouseCursor_ResizeNS, // Unused + ImGuiMouseCursor_ResizeEW, // When hovering over a column + ImGuiMouseCursor_ResizeNESW, // Unused + ImGuiMouseCursor_ResizeNWSE, // When hovering over the bottom-right corner of a window + ImGuiMouseCursor_Count_ +}; + // Condition flags for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions // All those functions treat 0 as a shortcut to ImGuiSetCond_Always enum ImGuiSetCond_ { ImGuiSetCond_Always = 1 << 0, // Set the variable ImGuiSetCond_Once = 1 << 1, // Only set the variable on the first call per runtime session - ImGuiSetCond_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file + ImGuiSetCond_FirstUseEver = 1 << 2, // Only set the variable if the window doesn't exist in the .ini file + ImGuiSetCond_Appearing = 1 << 3 // Only set the variable if the window is appearing after being inactive (or the first time) }; struct ImGuiStyle @@ -524,18 +610,21 @@ struct ImGuiStyle ImVec2 WindowPadding; // Padding within a window ImVec2 WindowMinSize; // Minimum window size float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + ImGuiAlign WindowTitleAlign; // Alignment for title bar text float ChildWindowRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) - ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! - ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip) + ImVec2 TouchExtraPadding; // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() - float TreeNodeSpacing; // Horizontal spacing when entering a tree node + float IndentSpacing; // Horizontal indentation when e.g. entering a tree node float ColumnsMinSpacing; // Minimum horizontal spacing between two columns float ScrollbarWidth; // Width of the vertical scrollbar - float GrabMinSize; // Minimum width/height of a slider or scrollbar grab + float ScrollbarRounding; // Radius of grab corners for scrollbar + float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar + ImVec2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows. + ImVec2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. ImVec4 Colors[ImGuiCol_COUNT]; IMGUI_API ImGuiStyle(); @@ -556,6 +645,7 @@ struct ImGuiIO const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified). float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. + float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array void* UserData; // = NULL // Store your own data for retrieval by callbacks. @@ -569,9 +659,9 @@ struct ImGuiIO // User Functions //------------------------------------------------------------------ - // REQUIRED: rendering function. + // REQUIRED: rendering function. // See example code if you are unsure of how to implement this. - void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); + void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); // Optional: access OS clipboard // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) @@ -594,10 +684,11 @@ struct ImGuiIO ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button). Others buttons allows to track if mouse is being used by your application + available to user as a convenience via IsMouse** API. - float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. + float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. bool MouseDrawCursor; // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). bool KeyCtrl; // Keyboard modifier pressed: Control bool KeyShift; // Keyboard modifier pressed: Shift + bool KeyAlt; // Keyboard modifier pressed: Alt bool KeysDown[512]; // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data) ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. @@ -611,6 +702,8 @@ struct ImGuiIO bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input) bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input) float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames + int MetricsRenderVertices; // Vertices processed during last call to Render() + int MetricsActiveWindows; // Number of visible windows (exclude child windows) //------------------------------------------------------------------ // [Internal] ImGui will maintain those fields for you @@ -624,6 +717,7 @@ struct ImGuiIO bool MouseDoubleClicked[5]; // Has mouse button been double-clicked? bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds. float MouseDownTime[5]; // Time the mouse button has been down + float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the click point float KeysDownTime[512]; // Time the keyboard key has been down IMGUI_API ImGuiIO(); @@ -686,7 +780,6 @@ struct ImGuiTextBuffer ImVector<char> Buf; ImGuiTextBuffer() { Buf.push_back(0); } - ~ImGuiTextBuffer() { } const char* begin() const { return &Buf.front(); } const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator size_t size() const { return Buf.size()-1; } @@ -706,13 +799,13 @@ struct ImGuiTextBuffer // - You want to store custom debug data easily without adding or editing structures in your code. struct ImGuiStorage { - struct Pair - { - ImGuiID key; - union { int val_i; float val_f; void* val_p; }; - Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } - Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } - Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } + struct Pair + { + ImGuiID key; + union { int val_i; float val_f; void* val_p; }; + Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } + Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } + Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } }; ImVector<Pair> Data; @@ -727,13 +820,14 @@ struct ImGuiStorage IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL IMGUI_API void SetVoidPtr(ImGuiID key, void* val); - // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set. + // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set. // - References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer. // - A typical use case where this is convenient: // float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar; // - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application. IMGUI_API int* GetIntRef(ImGuiID key, int default_val = 0); IMGUI_API float* GetFloatRef(ImGuiID key, float default_val = 0); + IMGUI_API void** GetVoidPtrRef(ImGuiID key, void* default_val = NULL); // Use on your own storage if you know only integer are being stored (open/close all tree nodes) IMGUI_API void SetAllInt(int val); @@ -824,6 +918,7 @@ IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT; // At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future. // If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives. // You can interleave normal ImGui:: calls and adding primitives to the current draw list. +// All positions are in screen coordinates (0,0=top-left, 1 pixel per unit). Primitives are always added to the list and not culled (culling is done at render time and at a higher-level by ImGui:: functions). // Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl struct ImDrawList { @@ -833,38 +928,43 @@ struct ImDrawList // [Internal to ImGui] ImVector<ImVec4> clip_rect_stack; // [Internal] - ImVector<ImTextureID> texture_id_stack; // [Internal] + ImVector<ImTextureID> texture_id_stack; // [Internal] ImDrawVert* vtx_write; // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much) ImDrawList() { Clear(); } IMGUI_API void Clear(); + IMGUI_API void ClearFreeMemory(); IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2. + IMGUI_API void PushClipRectFullScreen(); IMGUI_API void PopClipRect(); IMGUI_API void PushTextureID(const ImTextureID& texture_id); IMGUI_API void PopTextureID(); - // Primitives - IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); - IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); - IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); + // Primitives + IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); + IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); + IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); - IMGUI_API void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris = false, const ImVec2& third_point_offset = ImVec2(0,0)); - IMGUI_API void AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL); + IMGUI_API void AddArcFast(const ImVec2& center, float radius, ImU32 col, int a_min_12, int a_max_12, bool filled = false, const ImVec2& third_point_offset = ImVec2(0,0)); // Angles in 0..12 range + IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL); IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF); // Advanced - IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'user_callback' in ImDrawCmd and call the function instead of rendering triangles. - IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible + IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'user_callback' in ImDrawCmd and call the function instead of rendering triangles. + IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible // Internal helpers - IMGUI_API void ReserveVertices(unsigned int vtx_count); - IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col); - IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv); - IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col); + IMGUI_API void PrimReserve(unsigned int vtx_count); + IMGUI_API void PrimTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); + IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col); + IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col); + IMGUI_API void PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col); + IMGUI_API void PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); IMGUI_API void UpdateClipRect(); IMGUI_API void UpdateTextureID(); + IMGUI_API void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { vtx_write->pos = pos; vtx_write->uv = uv; vtx_write->col = col; vtx_write++; } }; // Load and rasterize multiple TTF fonts into a same texture. @@ -874,16 +974,19 @@ struct ImDrawList // 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data. // 3. Upload the pixels data into a texture within your graphics system. // 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture. -// 5. Call ClearPixelsData() to free textures memory on the heap. +// 5. Call ClearTexData() to free textures memory on the heap. struct ImFontAtlas { IMGUI_API ImFontAtlas(); IMGUI_API ~ImFontAtlas(); IMGUI_API ImFont* AddFontDefault(); IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); - IMGUI_API ImFont* AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Pass ownership of 'in_ttf_data' memory. - IMGUI_API void ClearTexData(); // Saves RAM once the texture has been copied to graphics memory. - IMGUI_API void Clear(); + IMGUI_API ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build() + IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // 'compressed_ttf_data' untouched and still owned by caller. Compress with binary_to_compressed_c.cpp + IMGUI_API void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory. + IMGUI_API void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges) + IMGUI_API void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates) + IMGUI_API void Clear(); // Clear all // Retrieve texture data // User is in charge of copying the pixels into graphics memory, then call SetTextureUserID() @@ -895,7 +998,7 @@ struct ImFontAtlas IMGUI_API void SetTexID(void* id) { TexID = id; } // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list) - // (Those functions could be static, aren't so simple use case doesn't have to refer to the ImFontAtlas:: type ever if in their code) + // (Those functions could be static but aren't so most users don't have to refer to the ImFontAtlas:: name ever if in their code; just using io.Fonts->) IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs @@ -907,7 +1010,6 @@ struct ImFontAtlas unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4 int TexWidth; int TexHeight; - ImVec2 TexExtraDataPos; // Position of our rectangle where we draw non-font graphics ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block) ImVector<ImFont*> Fonts; @@ -915,8 +1017,7 @@ struct ImFontAtlas struct ImFontAtlasData; ImVector<ImFontAtlasData*> InputData; // Internal data IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions. - IMGUI_API void ClearInputData(); // Clear the input TTF data. - IMGUI_API void RenderCustomTexData(); + IMGUI_API void RenderCustomTexData(int pass, void* rects); }; // TTF font loading and rendering @@ -939,6 +1040,7 @@ struct ImFont signed short XOffset, YOffset; float U0, V0, U1, V1; // Texture coordinates }; + float BaseLine; // Distance from top to bottom of e.g. 'A' [0..FontSize] ImFontAtlas* ContainerAtlas; // What we has been loaded into ImVector<Glyph> Glyphs; const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) @@ -948,19 +1050,19 @@ struct ImFont // Methods IMGUI_API ImFont(); - IMGUI_API ~ImFont() { Clear(); } - IMGUI_API void Clear(); - IMGUI_API void BuildLookupTable(); - IMGUI_API const Glyph* FindGlyph(unsigned short c) const; - IMGUI_API void SetFallbackChar(ImWchar c); - IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; } + IMGUI_API ~ImFont(); + IMGUI_API void Clear(); + IMGUI_API void BuildLookupTable(); + IMGUI_API const Glyph* FindGlyph(unsigned short c) const; + IMGUI_API void SetFallbackChar(ImWchar c); + IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; } // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable. // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable. - IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8 - IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar - IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL) const; - IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const; + IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8 + IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar + IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL) const; + IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const; }; //---- Include imgui_user.h at the end of imgui.h diff --git a/3rdparty/bgfx/3rdparty/renderdoc/renderdoc_app.h b/3rdparty/bgfx/3rdparty/renderdoc/renderdoc_app.h index d941f586c89..f0df30e4fd1 100644 --- a/3rdparty/bgfx/3rdparty/renderdoc/renderdoc_app.h +++ b/3rdparty/bgfx/3rdparty/renderdoc/renderdoc_app.h @@ -182,7 +182,12 @@ enum InAppOverlay // API breaking change history: // Version 1 -> 2 - strings changed from wchar_t* to char* (UTF-8) -#define RENDERDOC_API_VERSION 2 +// Version 2 -> 3 - StartFrameCapture, EndFrameCapture and SetActiveWindow take +// 'device' pointer as well as window handles. +// This is either ID3D11Device* or the GL context (HGLRC/GLXContext) +// You can still pass NULL to both to capture the default, as long as +// there's only one device/window pair alive. +#define RENDERDOC_API_VERSION 3 ////////////////////////////////////////////////////////////////////////// // In-program functions @@ -191,6 +196,9 @@ enum InAppOverlay extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_GetAPIVersion(); typedef int (RENDERDOC_CC *pRENDERDOC_GetAPIVersion)(); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_Shutdown(); +typedef void (RENDERDOC_CC *pRENDERDOC_Shutdown)(); + extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetLogFile(const char *logfile); typedef void (RENDERDOC_CC *pRENDERDOC_SetLogFile)(const char *logfile); @@ -203,17 +211,17 @@ typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetCapture)(uint32_t idx, char *logfi extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetCaptureOptions(const CaptureOptions *opts); typedef void (RENDERDOC_CC *pRENDERDOC_SetCaptureOptions)(const CaptureOptions *opts); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetActiveWindow(void *wndHandle); -typedef void (RENDERDOC_CC *pRENDERDOC_SetActiveWindow)(void *wndHandle); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetActiveWindow(void *device, void *wndHandle); +typedef void (RENDERDOC_CC *pRENDERDOC_SetActiveWindow)(void *device, void *wndHandle); extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_TriggerCapture(); typedef void (RENDERDOC_CC *pRENDERDOC_TriggerCapture)(); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartFrameCapture(void *wndHandle); -typedef void (RENDERDOC_CC *pRENDERDOC_StartFrameCapture)(void *wndHandle); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartFrameCapture(void *device, void *wndHandle); +typedef void (RENDERDOC_CC *pRENDERDOC_StartFrameCapture)(void *device, void *wndHandle); -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EndFrameCapture(void *wndHandle); -typedef uint32_t (RENDERDOC_CC *pRENDERDOC_EndFrameCapture)(void *wndHandle); +extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EndFrameCapture(void *device, void *wndHandle); +typedef uint32_t (RENDERDOC_CC *pRENDERDOC_EndFrameCapture)(void *device, void *wndHandle); extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_GetOverlayBits(); typedef uint32_t (RENDERDOC_CC *pRENDERDOC_GetOverlayBits)(); diff --git a/3rdparty/bgfx/3rdparty/stb/stb_rect_pack.h b/3rdparty/bgfx/3rdparty/stb/stb_rect_pack.h index 64c30761b80..eb0ef2f268f 100644 --- a/3rdparty/bgfx/3rdparty/stb/stb_rect_pack.h +++ b/3rdparty/bgfx/3rdparty/stb/stb_rect_pack.h @@ -488,7 +488,6 @@ static int rect_height_compare(const void *a, const void *b) return (p->w > q->w) ? -1 : (p->w < q->w); } -#if 0 static int rect_width_compare(const void *a, const void *b) { stbrp_rect *p = (stbrp_rect *) a; @@ -499,7 +498,6 @@ static int rect_width_compare(const void *a, const void *b) return 1; return (p->h > q->h) ? -1 : (p->h < q->h); } -#endif static int rect_original_order(const void *a, const void *b) { diff --git a/3rdparty/bgfx/README.md b/3rdparty/bgfx/README.md index cd8c72bdfcc..725d50bcd60 100644 --- a/3rdparty/bgfx/README.md +++ b/3rdparty/bgfx/README.md @@ -27,11 +27,11 @@ Supported platforms: * asm.js/Emscripten (1.25.0) * FreeBSD * iOS - * Linux + * Linux /statusIcon) * Native Client (PPAPI 37+, ARM, x86, x64, PNaCl) * OSX (10.9) * RaspberryPi - * Windows (XP, Vista, 7, 8, 10) + * Windows (XP, Vista, 7, 8, 10) /statusIcon) * WinRT (WinPhone 8.0+) Supported compilers: @@ -48,16 +48,17 @@ Languages: * [D language API bindings](https://github.com/DerelictOrg/DerelictBgfx) * [Go language API bindings](https://github.com/james4k/go-bgfx) +Build status +------------ + +https://tc27.draster.com/guestAuth/overview.html + Who is using it? ---------------- http://airmech.com/ AirMech is a free-to-play futuristic action real-time strategy video game developed and published by Carbon Games. -http://loomsdk.com/ Loom Game Engine developed by The Engine Company. Loom -is a powerful 2D game engine with live reloading of code and assets, a friendly -scripting language, and an efficient command-line workflow. - https://github.com/dariomanesku/cmftStudio cmftStudio - cubemap filtering tool.  @@ -335,6 +336,8 @@ Building Steps bellow are for default build system inside bgfx repository. There is alterative way to build bgfx and examples with [fips](https://github.com/floooh/fips-bgfx/#fips-bgfx). +Binary builds (for Windows and Linux) are also available [here](https://tc27.draster.com/bgfx-bins/). + ### Getting source git clone git://github.com/bkaradzic/bx.git @@ -795,7 +798,7 @@ Miloš Tošić ([@milostosic](https://github.com/milostosic)) - 12-lod example. Dario Manesku ([@dariomanesku](https://github.com/dariomanesku)) - 13-stencil, 14-shadowvolumes, 15-shadowmaps-simple, 16-shadowmaps, 18-ibl James Gray ([@james4k](https://github.com/james4k)) - Go language API bindings. -p0nce ([@p0nce](https://github.com/p0nce)) - D language API bindings. +Guillaume Piolat ([@p0nce](https://github.com/p0nce)) - D language API bindings. Mike Popoloski ([@MikePopoloski](https://github.com/MikePopoloski)) - C#/VB/F# language API bindings, WinRT/WinPhone support. Kai Jourdan ([@questor](https://github.com/questor)) - 23-vectordisplay example @@ -803,7 +806,8 @@ Stanlo Slasinski ([@stanlo](https://github.com/stanlo)) - 24-nbody example Daniel Collin ([@emoon](https://github.com/emoon)) - Port of Ocornut's ImGui to bgfx. Andre Weissflog ([@floooh](https://github.com/floooh)) - Alternative build -system fips. +system fips. +Andrew Johnson ([@ajohnson23](https://github.com/ajohnson23)) - TeamCity build. [License (BSD 2-clause)](https://github.com/bkaradzic/bgfx/blob/master/LICENSE) ------------------------------------------------------------------------------- diff --git a/3rdparty/bgfx/examples/13-stencil/fs_stencil_texture_lightning.sc b/3rdparty/bgfx/examples/13-stencil/fs_stencil_texture_lightning.sc index 59477469532..9ffe0ce9dc6 100644 --- a/3rdparty/bgfx/examples/13-stencil/fs_stencil_texture_lightning.sc +++ b/3rdparty/bgfx/examples/13-stencil/fs_stencil_texture_lightning.sc @@ -18,12 +18,12 @@ uniform vec4 u_lightPosRadius[MAX_NUM_LIGHTS]; uniform vec4 u_lightRgbInnerR[MAX_NUM_LIGHTS]; SAMPLER2D(u_texColor, 0); -#define u_ambientPass u_params.x -#define u_lightningPass u_params.y -#define u_lightCount u_params.z -#define u_lightIndex u_params.w -#define u_specular u_specular_shininess.xyz -#define u_shininess u_specular_shininess.w +#define u_ambientPass u_params.x +#define u_lightingPass u_params.y +#define u_lightCount u_params.z +#define u_lightIndex u_params.w +#define u_specular u_specular_shininess.xyz +#define u_shininess u_specular_shininess.w vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir) { @@ -67,17 +67,18 @@ void main() for(int ii = 0; ii < MAX_NUM_LIGHTS; ++ii) { float condition = 0.0; - if (u_lightCount > 1.0) + if (u_lightCount > 1.0) // Stencil Reflection Scene. { - condition = 1.0 - step(u_lightCount, float(ii)); + condition = 1.0 - step(u_lightCount, float(ii)); // True for every light up to u_lightCount. } - else + else // Projection Shadows Scene. { - condition = float(float(ii) == u_lightIndex); + condition = float(float(ii) == u_lightIndex); // True only for current light. } + lightColor += calcLight(ii, v_view, normal, viewDir) * condition; } - lightColor *= u_lightningPass; + lightColor *= u_lightingPass; vec3 color = toLinear(texture2D(u_texColor, v_texcoord0)).xyz; diff --git a/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp b/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp index 9f7124c35ad..35eade7c6f8 100644 --- a/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp +++ b/3rdparty/bgfx/examples/15-shadowmaps-simple/shadowmaps_simple.cpp @@ -262,8 +262,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) float lightProj[16]; eye[0] = -lightPos[0]; - eye[0] = -lightPos[1]; - eye[0] = -lightPos[2]; + eye[1] = -lightPos[1]; + eye[2] = -lightPos[2]; at[0] = 0.0f; at[1] = 0.0f; diff --git a/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp b/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp index 2b30ef39e7b..4439dd03c64 100644 --- a/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp +++ b/3rdparty/bgfx/examples/20-nanovg/nanovg.cpp @@ -30,6 +30,7 @@ #include <bx/string.h> #include <bx/timer.h> #include "entry/entry.h" +#include "imgui/imgui.h" #include "nanovg/nanovg.h" BX_PRAGMA_DIAGNOSTIC_PUSH(); @@ -1221,6 +1222,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) , 0 ); + imguiCreate(); + NVGcontext* nvg = nvgCreate(1, 0); bgfx::setViewSeq(0, true); @@ -1266,6 +1269,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) nvgDelete(nvg); + imguiDestroy(); + // Shutdown bgfx. bgfx::shutdown(); diff --git a/3rdparty/bgfx/examples/24-nbody/cs_indirect.sc b/3rdparty/bgfx/examples/24-nbody/cs_indirect.sc new file mode 100644 index 00000000000..8dfc01935d4 --- /dev/null +++ b/3rdparty/bgfx/examples/24-nbody/cs_indirect.sc @@ -0,0 +1,16 @@ +/* + * Copyright 2014 Stanlo Slasinski. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include "bgfx_compute.sh" +#include "uniforms.sh" + +BUFFER_WR(indirectBuffer, uvec4, 0); + +NUM_THREADS(1, 1, 1) +void main() +{ + drawIndexedIndirect(indirectBuffer, 0, 6, u_dispatchSize * threadGroupUpdateSize, 0, 0, 0); + dispatchIndirect(indirectBuffer, 1, u_dispatchSize, 1, 1); +} diff --git a/3rdparty/bgfx/examples/24-nbody/nbody.cpp b/3rdparty/bgfx/examples/24-nbody/nbody.cpp index b006f0b1315..72da9e38a0f 100644 --- a/3rdparty/bgfx/examples/24-nbody/nbody.cpp +++ b/3rdparty/bgfx/examples/24-nbody/nbody.cpp @@ -118,7 +118,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) ); const bgfx::Caps* caps = bgfx::getCaps(); - const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE); + const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE); + const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT); if (computeSupported) { @@ -162,10 +163,17 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Uniform4fv, 3); - bgfx::ShaderHandle initInstancesShader = loadShader("cs_init_instances"); - bgfx::ProgramHandle initInstancesProgram = bgfx::createProgram(initInstancesShader, true); - bgfx::ShaderHandle updateInstancesShader = loadShader("cs_update_instances"); - bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(updateInstancesShader, true); + bgfx::ProgramHandle initInstancesProgram = bgfx::createProgram(loadShader("cs_init_instances"), true); + bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(loadShader("cs_update_instances"), true); + + bgfx::ProgramHandle indirectProgram = BGFX_INVALID_HANDLE; + bgfx::IndirectBufferHandle indirectBuffer = BGFX_INVALID_HANDLE; + + if (indirectSupported) + { + indirectProgram = bgfx::createProgram(loadShader("cs_indirect"), true); + indirectBuffer = bgfx::createIndirectBuffer(2); + } u_paramsDataStruct u_paramsData; InitializeParams(0, &u_paramsData); @@ -184,6 +192,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) int32_t scrollArea = 0; + bool useIndirect = false; + entry::MouseState mouseState; while (!entry::processEvents(width, height, debug, reset, &mouseState) ) { @@ -194,6 +204,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) const double freq = double(bx::getHPFrequency() ); const float deltaTime = float(frameTime/freq); + if (deltaTime > 1000.0) + { + abort(); + } + // Set view 0 default viewport. bgfx::setViewRect(0, 0, 0, width, height); @@ -225,6 +240,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiSlider("Particle intensity", u_paramsData.particleIntensity, 0.0f, 1.0f, 0.001f); imguiSlider("Particle size", u_paramsData.particleSize, 0.0f, 1.0f, 0.001f); imguiSlider("Particle power", u_paramsData.particlePower, 0.001f, 16.0f, 0.01f); + imguiSeparatorLine(); + if (imguiCheck("Use draw/dispatch indirect", useIndirect, indirectSupported) ) + { + useIndirect = !useIndirect; + } imguiEndScrollArea(); imguiEndFrame(); @@ -243,12 +263,27 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); } + if (useIndirect) + { + bgfx::setUniform(u_params, &u_paramsData, 3); + bgfx::setBuffer(0, indirectBuffer, bgfx::Access::Write); + bgfx::dispatch(0, indirectProgram); + } + bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Read); bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Read); bgfx::setBuffer(2, prevPositionBuffer1, bgfx::Access::Write); bgfx::setBuffer(3, currPositionBuffer1, bgfx::Access::Write); bgfx::setUniform(u_params, &u_paramsData, 3); - bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1); + + if (useIndirect) + { + bgfx::dispatch(0, updateInstancesProgram, indirectBuffer, 1); + } + else + { + bgfx::dispatch(0, updateInstancesProgram, u_paramsData.dispatchSize, 1, 1); + } bx::xchg(currPositionBuffer0, currPositionBuffer1); bx::xchg(prevPositionBuffer0, prevPositionBuffer1); @@ -305,7 +340,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) ); // Submit primitive for rendering to view 0. - bgfx::submit(0); + if (useIndirect) + { + bgfx::submit(0, indirectBuffer, 0); + } + else + { + bgfx::submit(0); + } // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. @@ -315,6 +357,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Cleanup. cameraDestroy(); imguiDestroy(); + + if (indirectSupported) + { + bgfx::destroyProgram(indirectProgram); + bgfx::destroyIndirectBuffer(indirectBuffer); + } + + bgfx::destroyUniform(u_params); bgfx::destroyDynamicVertexBuffer(currPositionBuffer0); bgfx::destroyDynamicVertexBuffer(currPositionBuffer1); diff --git a/3rdparty/bgfx/examples/24-nbody/uniforms.sh b/3rdparty/bgfx/examples/24-nbody/uniforms.sh index e77698e20fe..70540164dad 100644 --- a/3rdparty/bgfx/examples/24-nbody/uniforms.sh +++ b/3rdparty/bgfx/examples/24-nbody/uniforms.sh @@ -5,6 +5,8 @@ uniform vec4 u_params[3]; +#define threadGroupUpdateSize 512 + #define u_timeStep u_params[0].x #define u_dispatchSize floatBitsToUint(u_params[0].y) #define u_gravity u_params[0].z diff --git a/3rdparty/bgfx/examples/common/bgfx_utils.cpp b/3rdparty/bgfx/examples/common/bgfx_utils.cpp index a638e4e7d4b..5f19524e568 100644 --- a/3rdparty/bgfx/examples/common/bgfx_utils.cpp +++ b/3rdparty/bgfx/examples/common/bgfx_utils.cpp @@ -15,6 +15,7 @@ namespace stl = tinystl; #include <bgfx.h> #include <bx/readerwriter.h> #include <bx/fpumath.h> +#include <bx/string.h> #include "entry/entry.h" #include <ib-compress/indexbufferdecompression.h> @@ -62,6 +63,25 @@ static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const char* _filePa return NULL; } +static void* loadMem(bx::FileReaderI* _reader, bx::ReallocatorI* _allocator, const char* _filePath, uint32_t* _size) +{ + if (0 == bx::open(_reader, _filePath) ) + { + uint32_t size = (uint32_t)bx::getSize(_reader); + void* data = BX_ALLOC(_allocator, size); + bx::read(_reader, data, size); + bx::close(_reader); + + if (NULL != _size) + { + *_size = size; + } + return data; + } + + return NULL; +} + static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name) { char filePath[512]; @@ -112,15 +132,76 @@ bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName) return loadProgram(entry::getFileReader(), _vsName, _fsName); } +typedef unsigned char stbi_uc; +extern "C" stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); + bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info) { - char filePath[512]; - strcpy(filePath, "textures/"); + char filePath[512] = { '\0' }; + if (NULL == strchr(_name, '/') ) + { + strcpy(filePath, "textures/"); + } + strcat(filePath, _name); - const bgfx::Memory* mem = loadMem(_reader, filePath); + if (NULL != bx::stristr(_name, ".dds") + || NULL != bx::stristr(_name, ".pvr") + || NULL != bx::stristr(_name, ".ktx") ) + { + const bgfx::Memory* mem = loadMem(_reader, filePath); + if (NULL != mem) + { + return bgfx::createTexture(mem, _flags, _skip, _info); + } + + bgfx::TextureHandle handle = BGFX_INVALID_HANDLE; + DBG("Failed to load %s.", filePath); + return handle; + } + + bgfx::TextureHandle handle = BGFX_INVALID_HANDLE; + bx::ReallocatorI* allocator = entry::getAllocator(); + + uint32_t size = 0; + void* data = loadMem(_reader, allocator, filePath, &size); + if (NULL != data) + { + int width = 0; + int height = 0; + int comp = 0; + + uint8_t* img = NULL; + img = stbi_load_from_memory( (uint8_t*)data, size, &width, &height, &comp, 4); + + BX_FREE(allocator, data); + + handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1 + , bgfx::TextureFormat::RGBA8 + , _flags + , bgfx::copy(img, width*height*4) + ); + + free(img); + + if (NULL != _info) + { + bgfx::calcTextureSize(*_info + , uint16_t(width) + , uint16_t(height) + , 0 + , false + , 1 + , bgfx::TextureFormat::RGBA8 + ); + } + } + else + { + DBG("Failed to load %s.", filePath); + } - return bgfx::createTexture(mem, _flags, _skip, _info); + return handle; } bgfx::TextureHandle loadTexture(const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info) diff --git a/3rdparty/bgfx/examples/common/entry/entry.cpp b/3rdparty/bgfx/examples/common/entry/entry.cpp index 998f5cce6fb..07826f1d035 100644 --- a/3rdparty/bgfx/examples/common/entry/entry.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry.cpp @@ -118,13 +118,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (_argc > 1) { - if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) - || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) - || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) - || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) - || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) - || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) - || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_RENDER, 1, _argc, _argv) + if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) + || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) + || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) + || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) + || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) + || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) + || setOrToggle(s_reset, "flush", BGFX_RESET_FLUSH_AFTER_RENDER, 1, _argc, _argv) + || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_RENDER, 1, _argc, _argv) ) { return 0; @@ -178,7 +179,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" }, { entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" }, { entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" }, - { entry::Key::F9, entry::Modifier::None, 1, cmd, "graphics flip" }, + { entry::Key::F9, entry::Modifier::None, 1, cmd, "graphics flush" }, { entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" }, INPUT_BINDING_END diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp index b9564339c11..91bfef74865 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp @@ -12,6 +12,7 @@ #endif // BX_PLATFORM_WINDOWS #include <SDL2/SDL.h> +#include <SDL2/SDL_syswm.h> #include <bgfxplatform.h> #include <stdio.h> @@ -450,20 +451,28 @@ namespace entry uint8_t modifiers = translateKeyModifiers(kev.keysym.mod); Key::Enum key = translateKey(kev.keysym.scancode); - const uint8_t shiftMask = Modifier::LeftShift|Modifier::RightShift; - const bool nonShiftModifiers = (0 != (modifiers&(~shiftMask) ) ); - const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus); - const bool isText = isCharPressed && !nonShiftModifiers; - - if (isText) + // TODO: These keys are not captured by SDL_TEXTINPUT. Should be probably handled by SDL_TEXTEDITING. This is a workaround for now. + if (key == 1) // Escape + { + uint8_t pressedChar[4]; + pressedChar[0] = 0x1b; + m_eventQueue.postCharEvent(handle, 1, pressedChar); + } + else if (key == 2) // Enter + { + uint8_t pressedChar[4]; + pressedChar[0] = 0x0d; + m_eventQueue.postCharEvent(handle, 1, pressedChar); + } + else if (key == 5) // Backspace { uint8_t pressedChar[4]; - pressedChar[0] = keyToAscii(key, modifiers); + pressedChar[0] = 0x08; m_eventQueue.postCharEvent(handle, 1, pressedChar); } else { - m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); + m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); } } } diff --git a/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp b/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp index e7cf8214de6..1bca2de28da 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp @@ -26,10 +26,10 @@ static entry::EventQueue g_eventQueue; ref class App sealed : public IFrameworkView { - public: - App() - : m_windowVisible(true) - , m_windowClosed(false) +public: + App() + : m_windowVisible(true) + , m_windowClosed(false) { } @@ -57,13 +57,14 @@ ref class App sealed : public IFrameworkView thread.init(MainThreadFunc, nullptr); CoreWindow^ window = CoreWindow::GetForCurrentThread(); - if (window == nullptr) { - int i = 4; - i++; - } + auto bounds = window->Bounds; + auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi; - //auto bounds = window->Bounds; - //g_eventQueue.postSizeEvent(g_defaultWindow, bounds.Width, bounds.Height); + static const float dipsPerInch = 96.0f; + g_eventQueue.postSizeEvent(g_defaultWindow + , lround(floorf(bounds.Width * dpi / dipsPerInch + 0.5f)) + , lround(floorf(bounds.Height * dpi / dipsPerInch + 0.5f)) + ); while (!m_windowClosed) { @@ -92,12 +93,6 @@ private: void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) { - CoreWindow^ window = CoreWindow::GetForCurrentThread(); - if (window == nullptr) { - int i = 4; - i++; - } - CoreWindow::GetForCurrentThread()->Activate(); } diff --git a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp index 249b8a0483c..02d14316952 100644 --- a/3rdparty/bgfx/examples/common/entry/entry_x11.cpp +++ b/3rdparty/bgfx/examples/common/entry/entry_x11.cpp @@ -294,7 +294,6 @@ namespace entry | KeyPressMask | KeyReleaseMask | PointerMotionMask - | ResizeRedirectMask | StructureNotifyMask ; @@ -357,9 +356,6 @@ namespace entry case Expose: break; - case ConfigureNotify: - break; - case ClientMessage: if ( (Atom)event.xclient.data.l[0] == wmDeleteWindow) { @@ -449,14 +445,13 @@ namespace entry } break; - case ResizeRequest: + case ConfigureNotify: { - const XResizeRequestEvent& xresize = event.xresizerequest; - XResizeWindow(xresize.display, xresize.window, xresize.width, xresize.height); - WindowHandle handle = findHandle(xresize.window); + const XConfigureEvent& xev = event.xconfigure; + WindowHandle handle = findHandle(xev.window); if (isValid(handle) ) { - m_eventQueue.postSizeEvent(handle, xresize.width, xresize.height); + m_eventQueue.postSizeEvent(handle, xev.width, xev.height); } } break; diff --git a/3rdparty/bgfx/examples/common/imgui/fs_imgui_cubemap.bin.h b/3rdparty/bgfx/examples/common/imgui/fs_imgui_cubemap.bin.h index cfcb436a51c..db5b5da4de8 100644 --- a/3rdparty/bgfx/examples/common/imgui/fs_imgui_cubemap.bin.h +++ b/3rdparty/bgfx/examples/common/imgui/fs_imgui_cubemap.bin.h @@ -1,42 +1,28 @@ -static const uint8_t fs_imgui_cubemap_glsl[578] = +static const uint8_t fs_imgui_cubemap_glsl[363] = { - 0x46, 0x53, 0x48, 0x03, 0xe3, 0xc2, 0x5c, 0x65, 0x00, 0x00, 0x33, 0x02, 0x00, 0x00, 0x6c, 0x6f, // FSH....e..3...lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, // wp vec4 impl_low - 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, // _textureCubeLod - 0x20, 0x20, 0x28, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x43, // (lowp samplerC - 0x75, 0x62, 0x65, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x68, 0x69, 0x67, // ube sampler, hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6d, // hp vec3 coord, m - 0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c, 0x6f, 0x64, // ediump float lod - 0x29, 0x0a, 0x7b, 0x0a, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, // ).{.#if defined( - 0x47, 0x4c, 0x5f, 0x45, 0x58, 0x54, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x65, // GL_EXT_shader_te - 0x78, 0x74, 0x75, 0x72, 0x65, 0x5f, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, // xture_lod)..retu - 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, // rn textureCubeLo - 0x64, 0x20, 0x20, 0x20, 0x28, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, // d (sampler, co - 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6c, 0x73, 0x65, // ord, lod);.#else - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, // ..return texture - 0x43, 0x75, 0x62, 0x65, 0x28, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, // Cube(sampler, co - 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, // ord, lod);.#endi - 0x66, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, // f.}..varying hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, // hp vec3 v_normal - 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // ;.uniform highp - 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, // vec4 u_imageLodE - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, // nabled;.uniform - 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x43, 0x75, 0x62, 0x65, // lowp samplerCube - 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // s_texColor;.voi - 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, // d main ().{. lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, // wp vec4 tmpvar_1 - 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, // ;. tmpvar_1.xyz - 0x20, 0x3d, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, 0x5f, 0x74, 0x65, 0x78, 0x74, // = impl_low_text - 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, // ureCubeLod (s - 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, // _texColor, v_nor - 0x6d, 0x61, 0x6c, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, // mal, u_imageLodE - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, // nabled.x).xyz;. - 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, // tmpvar_1.w = (0 - 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, // .2 + (0.8 * u_im - 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, // ageLodEnabled.y) - 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, // );. gl_FragColo - 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, // r = tmpvar_1;.}. - 0x0a, 0x00, // .. + 0x46, 0x53, 0x48, 0x03, 0xe3, 0xc2, 0x5c, 0x65, 0x02, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH....e...u_ima + 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled.... + 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor... + 0x00, 0x01, 0x00, 0x33, 0x01, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...3...varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, // ighp vec3 v_norm + 0x61, 0x6c, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, // al;.uniform high + 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, // p vec4 u_imageLo + 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, // dEnabled;.unifor + 0x6d, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x43, 0x75, // m lowp samplerCu + 0x62, 0x65, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, // be s_texColor;.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // lowp vec4 tmpvar + 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, // _1;. tmpvar_1.x + 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, // yz = textureCube + 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, // Lod (s_texCol + 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x2c, 0x20, 0x75, 0x5f, // or, v_normal, u_ + 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, // imageLodEnabled. + 0x78, 0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // x).xyz;. tmpvar + 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, // _1.w = (0.2 + (0 + 0x2e, 0x38, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, // .8 * u_imageLodE + 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, // nabled.y));. gl + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, // _FragColor = tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // var_1;.}... }; static const uint8_t fs_imgui_cubemap_dx9[373] = { diff --git a/3rdparty/bgfx/examples/common/imgui/fs_imgui_image.bin.h b/3rdparty/bgfx/examples/common/imgui/fs_imgui_image.bin.h index 2882d0baee0..dd51fc825be 100644 --- a/3rdparty/bgfx/examples/common/imgui/fs_imgui_image.bin.h +++ b/3rdparty/bgfx/examples/common/imgui/fs_imgui_image.bin.h @@ -1,41 +1,28 @@ -static const uint8_t fs_imgui_image_glsl[567] = +static const uint8_t fs_imgui_image_glsl[360] = { - 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x28, 0x02, 0x00, 0x00, 0x6c, 0x6f, // FSH.o.><..(...lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, // wp vec4 impl_low - 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, // _texture2DLod - 0x28, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, // (lowp sampler2D - 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, // sampler, highp v - 0x65, 0x63, 0x32, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, // ec2 coord, mediu - 0x6d, 0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x7b, 0x0a, // mp float lod).{. - 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f, 0x45, // #if defined(GL_E - 0x58, 0x54, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, // XT_shader_textur - 0x65, 0x5f, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, // e_lod)..return t - 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x28, 0x73, // exture2DLod (s - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, // ampler, coord, l - 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, // od);.#else..retu - 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x28, 0x73, 0x61, 0x6d, // rn texture2D(sam - 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, // pler, coord, lod - 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, 0x61, 0x72, // );.#endif.}..var - 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, // ying highp vec2 - 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // v_texcoord0;.uni - 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, // form highp vec4 - 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, // u_imageLodEnable - 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, // d;.uniform sampl - 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, // er2D s_texColor; - 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, // .void main ().{. - 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, // lowp vec4 tmpv - 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, // ar_1;. tmpvar_1 - 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, 0x5f, // .xyz = impl_low_ - 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, // texture2DLod - 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, // (s_texColor, v_t - 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // excoord0, u_imag - 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, 0x78, // eLodEnabled.x).x - 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, // yz;. tmpvar_1.w - 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, 0x2a, // = (0.2 + (0.8 * - 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, // u_imageLodEnabl - 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, // ed.y));. gl_Fra - 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // gColor = tmpvar_ - 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // 1;.}... + 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x02, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima + 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled.... + 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor... + 0x00, 0x01, 0x00, 0x30, 0x01, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...0...varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // ighp vec4 u_imag + 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // eLodEnabled;.uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, // form sampler2D s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, // _texColor;.void + 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, // main ().{. lowp + 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, // vec4 tmpvar_1;. + 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, // tmpvar_1.xyz = + 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, // texture2DLod + 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, // (s_texColor, v_ + 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, // texcoord0, u_ima + 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, // geLodEnabled.x). + 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // xyz;. tmpvar_1. + 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, // w = (0.2 + (0.8 + 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, // * u_imageLodEnab + 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // led.y));. gl_Fr + 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // agColor = tmpvar + 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _1;.}... }; static const uint8_t fs_imgui_image_dx9[377] = { diff --git a/3rdparty/bgfx/examples/common/imgui/fs_imgui_image_swizz.bin.h b/3rdparty/bgfx/examples/common/imgui/fs_imgui_image_swizz.bin.h index 52e0e9ab34b..096e7ff1a26 100644 --- a/3rdparty/bgfx/examples/common/imgui/fs_imgui_image_swizz.bin.h +++ b/3rdparty/bgfx/examples/common/imgui/fs_imgui_image_swizz.bin.h @@ -1,44 +1,32 @@ -static const uint8_t fs_imgui_image_swizz_glsl[616] = +static const uint8_t fs_imgui_image_swizz_glsl[425] = { - 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x59, 0x02, 0x00, 0x00, 0x6c, 0x6f, // FSH.o.><..Y...lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, // wp vec4 impl_low - 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, // _texture2DLod - 0x28, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, // (lowp sampler2D - 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, // sampler, highp v - 0x65, 0x63, 0x32, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6d, 0x65, 0x64, 0x69, 0x75, // ec2 coord, mediu - 0x6d, 0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x7b, 0x0a, // mp float lod).{. - 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f, 0x45, // #if defined(GL_E - 0x58, 0x54, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, // XT_shader_textur - 0x65, 0x5f, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, // e_lod)..return t - 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x28, 0x73, // exture2DLod (s - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, // ampler, coord, l - 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, // od);.#else..retu - 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x28, 0x73, 0x61, 0x6d, // rn texture2D(sam - 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, // pler, coord, lod - 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, 0x61, 0x72, // );.#endif.}..var - 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, // ying highp vec2 - 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // v_texcoord0;.uni + 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x03, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima + 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled.... + 0x01, 0x00, 0x09, 0x75, 0x5f, 0x73, 0x77, 0x69, 0x7a, 0x7a, 0x6c, 0x65, 0x07, 0x01, 0x00, 0x00, // ...u_swizzle.... + 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor... + 0x00, 0x01, 0x00, 0x61, 0x01, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...a...varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // ighp vec4 u_imag + 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // eLodEnabled;.uni 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, // form highp vec4 - 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, // u_imageLodEnable - 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, // d;.uniform highp - 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x73, 0x77, 0x69, 0x7a, 0x7a, 0x6c, 0x65, 0x3b, // vec4 u_swizzle; - 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, // .uniform sampler - 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, // 2D s_texColor;.v - 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. - 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // lowp vec4 tmpvar - 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, // _1;. tmpvar_1.x - 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x33, 0x28, 0x64, 0x6f, 0x74, 0x20, 0x28, 0x69, // yz = vec3(dot (i - 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, // mpl_low_texture2 - 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, // DLod (s_texCo - 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, // lor, v_texcoord0 - 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, // , u_imageLodEnab - 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2c, 0x20, 0x75, 0x5f, 0x73, 0x77, 0x69, 0x7a, 0x7a, 0x6c, // led.x), u_swizzl - 0x65, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // e));. tmpvar_1. - 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, // w = (0.2 + (0.8 - 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, // * u_imageLodEnab - 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // led.y));. gl_Fr - 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // agColor = tmpvar - 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _1;.}... + 0x75, 0x5f, 0x73, 0x77, 0x69, 0x7a, 0x7a, 0x6c, 0x65, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, // u_swizzle;.unifo + 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, // rm sampler2D s_t + 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, // exColor;.void ma + 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, // in ().{. lowp v + 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, // ec4 tmpvar_1;. + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x76, // tmpvar_1.xyz = v + 0x65, 0x63, 0x33, 0x28, 0x64, 0x6f, 0x74, 0x20, 0x28, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, // ec3(dot (texture + 0x32, 0x44, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, // 2DLod (s_texC + 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, // olor, v_texcoord + 0x30, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, // 0, u_imageLodEna + 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2c, 0x20, 0x75, 0x5f, 0x73, 0x77, 0x69, 0x7a, 0x7a, // bled.x), u_swizz + 0x6c, 0x65, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, // le));. tmpvar_1 + 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, // .w = (0.2 + (0.8 + 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, // * u_imageLodEna + 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, // bled.y));. gl_F + 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // ragColor = tmpva + 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r_1;.}... }; static const uint8_t fs_imgui_image_swizz_dx9[441] = { diff --git a/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h b/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h index 82168acf27c..8c39751d083 100644 --- a/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h +++ b/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h @@ -1,60 +1,46 @@ -static const uint8_t fs_imgui_latlong_glsl[866] = +static const uint8_t fs_imgui_latlong_glsl[651] = { - 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x00, 0x00, 0x53, 0x03, 0x00, 0x00, 0x6c, 0x6f, // FSH.o.><..S...lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, // wp vec4 impl_low - 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, // _textureCubeLod - 0x20, 0x20, 0x28, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x43, // (lowp samplerC - 0x75, 0x62, 0x65, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x68, 0x69, 0x67, // ube sampler, hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6d, // hp vec3 coord, m - 0x65, 0x64, 0x69, 0x75, 0x6d, 0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c, 0x6f, 0x64, // ediump float lod - 0x29, 0x0a, 0x7b, 0x0a, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, // ).{.#if defined( - 0x47, 0x4c, 0x5f, 0x45, 0x58, 0x54, 0x5f, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x65, // GL_EXT_shader_te - 0x78, 0x74, 0x75, 0x72, 0x65, 0x5f, 0x6c, 0x6f, 0x64, 0x29, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, // xture_lod)..retu - 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, // rn textureCubeLo - 0x64, 0x20, 0x20, 0x20, 0x28, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, // d (sampler, co - 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6c, 0x73, 0x65, // ord, lod);.#else - 0x0a, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, // ..return texture - 0x43, 0x75, 0x62, 0x65, 0x28, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x63, 0x6f, // Cube(sampler, co - 0x6f, 0x72, 0x64, 0x2c, 0x20, 0x6c, 0x6f, 0x64, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, // ord, lod);.#endi - 0x66, 0x0a, 0x7d, 0x0a, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, // f.}..varying hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, // hp vec2 v_texcoo - 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, // rd0;.uniform hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, // hp vec4 u_imageL - 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, // odEnabled;.unifo - 0x72, 0x6d, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x43, // rm lowp samplerC - 0x75, 0x62, 0x65, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, // ube s_texColor;. - 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, // void main ().{. - 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x72, 0x65, 0x73, 0x75, // highp vec3 resu - 0x6c, 0x74, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x66, 0x6c, // lt_1;. highp fl - 0x6f, 0x61, 0x74, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, // oat tmpvar_2;. - 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x28, 0x76, 0x5f, 0x74, 0x65, // tmpvar_2 = (v_te - 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x78, 0x20, 0x2a, 0x20, 0x36, 0x2e, 0x32, 0x38, // xcoord0.x * 6.28 - 0x33, 0x31, 0x38, 0x35, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x66, // 3185);. highp f - 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x3b, 0x0a, 0x20, // loat tmpvar_3;. - 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x28, 0x76, 0x5f, 0x74, // tmpvar_3 = (v_t - 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x79, 0x20, 0x2a, 0x20, 0x33, 0x2e, 0x31, // excoord0.y * 3.1 - 0x34, 0x31, 0x35, 0x39, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, // 41593);. result - 0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, // _1.x = (-(sin(tm - 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, 0x28, 0x74, // pvar_3)) * sin(t - 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, // mpvar_2));. res - 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, // ult_1.y = cos(tm - 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, // pvar_3);. resul - 0x74, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, // t_1.z = (-(sin(t - 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x73, 0x28, // mpvar_3)) * cos( - 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, // tmpvar_2));. lo - 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // wp vec4 tmpvar_4 - 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, 0x79, 0x7a, // ;. tmpvar_4.xyz - 0x20, 0x3d, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x5f, 0x6c, 0x6f, 0x77, 0x5f, 0x74, 0x65, 0x78, 0x74, // = impl_low_text - 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, // ureCubeLod (s - 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, // _texColor, resul - 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, // t_1, u_imageLodE - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, // nabled.x).xyz;. - 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, // tmpvar_4.w = (0 - 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, // .2 + (0.8 * u_im - 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, // ageLodEnabled.y) - 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, // );. gl_FragColo - 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x7d, 0x0a, // r = tmpvar_4;.}. - 0x0a, 0x00, // .. + 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x02, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima + 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled.... + 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor... + 0x00, 0x01, 0x00, 0x53, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...S...varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // ighp vec4 u_imag + 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // eLodEnabled;.uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, // form lowp sample + 0x72, 0x43, 0x75, 0x62, 0x65, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // rCube s_texColor + 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, // ;.void main ().{ + 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x72, 0x65, // . highp vec3 re + 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // sult_1;. highp + 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, // float tmpvar_2;. + 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x28, 0x76, 0x5f, // tmpvar_2 = (v_ + 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x78, 0x20, 0x2a, 0x20, 0x36, 0x2e, // texcoord0.x * 6. + 0x32, 0x38, 0x33, 0x31, 0x38, 0x35, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, // 283185);. highp + 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x3b, // float tmpvar_3; + 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x28, 0x76, // . tmpvar_3 = (v + 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x79, 0x20, 0x2a, 0x20, 0x33, // _texcoord0.y * 3 + 0x2e, 0x31, 0x34, 0x31, 0x35, 0x39, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, // .141593);. resu + 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, // lt_1.x = (-(sin( + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, // tmpvar_3)) * sin + 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, // (tmpvar_2));. r + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, // esult_1.y = cos( + 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, // tmpvar_3);. res + 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, // ult_1.z = (-(sin + 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, // (tmpvar_3)) * co + 0x73, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, // s(tmpvar_2));. + 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // lowp vec4 tmpvar + 0x5f, 0x34, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, // _4;. tmpvar_4.x + 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, // yz = textureCube + 0x4c, 0x6f, 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, // Lod (s_texCol + 0x6f, 0x72, 0x2c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, // or, result_1, u_ + 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, // imageLodEnabled. + 0x78, 0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // x).xyz;. tmpvar + 0x5f, 0x34, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, // _4.w = (0.2 + (0 + 0x2e, 0x38, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, // .8 * u_imageLodE + 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, // nabled.y));. gl + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, // _FragColor = tmp + 0x76, 0x61, 0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // var_4;.}... }; static const uint8_t fs_imgui_latlong_dx9[537] = { diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index 6d2d566dbec..d44a4a46a45 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -604,12 +604,11 @@ struct Imgui bgfx::destroyUniform(u_imageSwizzle); bgfx::destroyUniform(s_texColor); #if !USE_NANOVG_FONT - for (uint16_t ii = 0; ii < IMGUI_CONFIG_MAX_FONTS; ++ii) + for (uint16_t ii = 0, num = m_fontHandle.getNumHandles(); ii < num; ++ii) { - if (bgfx::isValid(m_fonts[ii].m_texture) ) - { - bgfx::destroyTexture(m_fonts[ii].m_texture); - } + uint16_t idx = m_fontHandle.getHandleAt(0); + bgfx::destroyTexture(m_fonts[idx].m_texture); + m_fontHandle.free(idx); } #endif // !USE_NANOVG_FONT bgfx::destroyTexture(m_missingTexture); diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.h b/3rdparty/bgfx/examples/common/imgui/imgui.h index 87d744beda9..cb0622319ef 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.h +++ b/3rdparty/bgfx/examples/common/imgui/imgui.h @@ -204,4 +204,16 @@ bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, ImguiCubemap::En float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); bool imguiMouseOverArea(); +namespace ImGui +{ + // Helper function for passing bgfx::TextureHandle to ImGui::Image. + inline void Image(bgfx::TextureHandle _handle, const ImVec2& _size, const ImVec2& _uv0 = ImVec2(0, 0), const ImVec2& _uv1 = ImVec2(1, 1), const ImVec4& _tint_col = ImVec4(1, 1, 1, 1), const ImVec4& _border_col = ImVec4(0, 0, 0, 0)) + { + union { bgfx::TextureHandle handle; ImTextureID ptr; } texture; + texture.handle = _handle; + Image(texture.ptr, _size, _uv0, _uv1, _tint_col, _border_col); + } + +} // namespace ImGui + #endif // IMGUI_H_HEADER_GUARD diff --git a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp index 2ab657f7d3e..368d503a1ba 100644 --- a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp @@ -72,7 +72,13 @@ struct OcornutImguiContext , uint16_t(pcmd->clip_rect.z-pcmd->clip_rect.x) , uint16_t(pcmd->clip_rect.w-pcmd->clip_rect.y) ); - bgfx::setTexture(0, s_tex, m_texture); + union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->texture_id }; + + bgfx::setTexture(0, s_tex, 0 != texture.handle.idx + ? texture.handle + : m_texture + ); + bgfx::setVertexBuffer(&tvb, vtx_offset, pcmd->vtx_count); bgfx::setProgram(m_program); bgfx::submit(m_viewId); diff --git a/3rdparty/bgfx/examples/runtime/images/SplashScreen.png b/3rdparty/bgfx/examples/runtime/images/SplashScreen.png Binary files differnew file mode 100644 index 00000000000..fc6a2468ebe --- /dev/null +++ b/3rdparty/bgfx/examples/runtime/images/SplashScreen.png diff --git a/3rdparty/bgfx/examples/runtime/shaders/dx11/cs_indirect.bin b/3rdparty/bgfx/examples/runtime/shaders/dx11/cs_indirect.bin Binary files differnew file mode 100644 index 00000000000..fb332c36e55 --- /dev/null +++ b/3rdparty/bgfx/examples/runtime/shaders/dx11/cs_indirect.bin diff --git a/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_mesh.bin b/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_mesh.bin Binary files differindex 3b1e2a9d475..593b4035fd1 100644 --- a/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_mesh.bin +++ b/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_mesh.bin diff --git a/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_skybox.bin b/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_skybox.bin Binary files differindex 2391fe7b564..cf240542199 100644 --- a/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_skybox.bin +++ b/3rdparty/bgfx/examples/runtime/shaders/gles/fs_ibl_skybox.bin diff --git a/3rdparty/bgfx/examples/runtime/shaders/glsl/cs_indirect.bin b/3rdparty/bgfx/examples/runtime/shaders/glsl/cs_indirect.bin Binary files differnew file mode 100644 index 00000000000..575406b70eb --- /dev/null +++ b/3rdparty/bgfx/examples/runtime/shaders/glsl/cs_indirect.bin diff --git a/3rdparty/bgfx/include/bgfx.c99.h b/3rdparty/bgfx/include/bgfx.c99.h index 59928105623..17a1b0ad8b8 100644 --- a/3rdparty/bgfx/include/bgfx.c99.h +++ b/3rdparty/bgfx/include/bgfx.c99.h @@ -150,9 +150,23 @@ typedef enum bgfx_uniform_type } bgfx_uniform_type_t; +typedef enum bgfx_backbuffer_ratio +{ + BGFX_BACKBUFFER_RATIO_EQUAL, + BGFX_BACKBUFFER_RATIO_HALF, + BGFX_BACKBUFFER_RATIO_QUARTER, + BGFX_BACKBUFFER_RATIO_EIGHTH, + BGFX_BACKBUFFER_RATIO_SIXTEENTH, + BGFX_BACKBUFFER_RATIO_DOUBLE, + + BGFX_BACKBUFFER_RATIO_COUNT + +} bgfx_backbuffer_ratio_t; + #define BGFX_HANDLE_T(_name) \ typedef struct _name { uint16_t idx; } _name##_t; +BGFX_HANDLE_T(bgfx_indirect_buffer_handle); BGFX_HANDLE_T(bgfx_dynamic_index_buffer_handle); BGFX_HANDLE_T(bgfx_dynamic_vertex_buffer_handle); BGFX_HANDLE_T(bgfx_frame_buffer_handle); @@ -166,14 +180,10 @@ BGFX_HANDLE_T(bgfx_vertex_decl_handle); #undef BGFX_HANDLE_T -/** - * - */ +/**/ typedef void (*bgfx_release_fn_t)(void* _ptr, void* _userData); -/** - * - */ +/**/ typedef struct bgfx_memory { uint8_t* data; @@ -181,9 +191,7 @@ typedef struct bgfx_memory } bgfx_memory_t; -/** - * - */ +/**/ typedef struct bgfx_transform { float* data; @@ -191,9 +199,7 @@ typedef struct bgfx_transform } bgfx_transform_t; -/** - * Eye - */ +/**/ typedef struct bgfx_hmd_eye { float rotation[4]; @@ -204,9 +210,7 @@ typedef struct bgfx_hmd_eye } bgfx_hmd_eye_t; -/** - * HMD - */ +/**/ typedef struct bgfx_hmd { bgfx_hmd_eye_t eye[2]; @@ -215,9 +219,7 @@ typedef struct bgfx_hmd } bgfx_hmd_t; -/** - * Vertex declaration. - */ +/**/ typedef struct bgfx_vertex_decl { uint32_t hash; @@ -227,8 +229,7 @@ typedef struct bgfx_vertex_decl } bgfx_vertex_decl_t; -/** - */ +/**/ typedef struct bgfx_transient_index_buffer { uint8_t* data; @@ -238,8 +239,7 @@ typedef struct bgfx_transient_index_buffer } bgfx_transient_index_buffer_t; -/** - */ +/**/ typedef struct bgfx_transient_vertex_buffer { uint8_t* data; @@ -251,8 +251,7 @@ typedef struct bgfx_transient_vertex_buffer } bgfx_transient_vertex_buffer_t; -/** - */ +/**/ typedef struct bgfx_instance_data_buffer { uint8_t* data; @@ -264,8 +263,7 @@ typedef struct bgfx_instance_data_buffer } bgfx_instance_data_buffer_t; -/** - */ +/**/ typedef struct bgfx_texture_info { bgfx_texture_format_t format; @@ -279,8 +277,7 @@ typedef struct bgfx_texture_info } bgfx_texture_info_t; -/** - */ +/**/ typedef struct bgfx_caps_gpu { uint16_t vendorId; @@ -288,46 +285,28 @@ typedef struct bgfx_caps_gpu } bgfx_caps_gpu_t; -/** - * Renderer capabilities. - */ +/**/ typedef struct bgfx_caps { - /** - * Renderer backend type. - */ bgfx_renderer_type_t rendererType; - /** - * Supported functionality, it includes emulated functionality. - * Checking supported and not emulated will give functionality - * natively supported by renderer. - */ uint64_t supported; - uint32_t maxDrawCalls; /* < Maximum draw calls. */ - uint16_t maxTextureSize; /* < Maximum texture size. */ - uint16_t maxViews; /* < Maximum views. */ - uint8_t maxFBAttachments; /* < Maximum frame buffer attachments. */ - uint8_t numGPUs; /* < */ - - uint16_t vendorId; /* < */ - uint16_t deviceId; /* < */ - bgfx_caps_gpu_t gpu[4]; /* < */ - - /** - * Supported texture formats. - * `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported - * `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported - * `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated - * `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture - */ + uint32_t maxDrawCalls; + uint16_t maxTextureSize; + uint16_t maxViews; + uint8_t maxFBAttachments; + uint8_t numGPUs; + + uint16_t vendorId; + uint16_t deviceId; + bgfx_caps_gpu_t gpu[4]; + uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT]; } bgfx_caps_t; -/** - */ +/**/ typedef enum bgfx_fatal { BGFX_FATAL_DEBUG_CHECK, @@ -373,85 +352,40 @@ typedef enum bgfx_fatal # define BGFX_C_API BGFX_SHARED_LIB_API #endif // defined(__cplusplus) -/** - */ +/**/ typedef struct bgfx_callback_interface { const struct bgfx_callback_vtbl* vtbl; } bgfx_callback_interface_t; -/** - * Callback interface to implement application specific behavior. - * Cached items are currently used only for OpenGL binary shaders. - * - * NOTE: - * 'fatal' callback can be called from any thread. Other callbacks - * are called from the render thread. - */ +/**/ typedef struct bgfx_callback_vtbl { # define BGFX_VTBL_INTEFRACE bgfx_callback_interface_t void* ctor; - - /** - * If fatal code code is not BGFX_FATAL_DEBUG_CHECK this callback is - * called on unrecoverable error. It's not safe to continue, inform - * user and terminate application from this call. - */ void (BGFX_VTBL_CALL *fatal)(BGFX_VTBL_THIS_ bgfx_fatal_t _code, const char* _str); - - /** - * Return size of for cached item. Return 0 if no cached item was - * found. - */ uint32_t (BGFX_VTBL_CALL *cache_read_size)(BGFX_VTBL_THIS_ uint64_t _id); - - /** - * Read cached item. - */ bool (BGFX_VTBL_CALL *cache_read)(BGFX_VTBL_THIS_ uint64_t _id, void* _data, uint32_t _size); - - /** - * Write cached item. - */ void (BGFX_VTBL_CALL *cache_write)(BGFX_VTBL_THIS_ uint64_t _id, const void* _data, uint32_t _size); - - /** - * Screenshot captured. Screenshot format is always 4-byte BGRA. - */ void (BGFX_VTBL_CALL *screen_shot)(BGFX_VTBL_THIS_ const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip); - - /** - * Called when capture begins. - */ void (BGFX_VTBL_CALL *capture_begin)(BGFX_VTBL_THIS_ uint32_t _width, uint32_t _height, uint32_t _pitch, bgfx_texture_format_t _format, bool _yflip); - - /** - * Called when capture ends. - */ void (BGFX_VTBL_CALL *capture_end)(BGFX_VTBL_THIS); - - /** - * Captured frame. - */ void (BGFX_VTBL_CALL *capture_frame)(BGFX_VTBL_THIS_ const void* _data, uint32_t _size); # undef BGFX_VTBL_INTEFRACE } bgfx_callback_vtbl_t; -/** - */ +/**/ typedef struct bgfx_reallocator_interface { const struct bgfx_reallocator_vtbl* vtbl; } bgfx_reallocator_interface_t; -/** - */ +/**/ typedef struct bgfx_reallocator_vtbl { # define BGFX_VTBL_INTEFRACE bgfx_reallocator_interface_t @@ -465,955 +399,352 @@ typedef struct bgfx_reallocator_vtbl } bgfx_reallocator_vtbl_t; -/** - * Start vertex declaration. - */ +/**/ BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer); -/** - * Add attribute to vertex declaration. - * - * @param _attrib Attribute semantics. - * @param _num Number of elements 1, 2, 3 or 4. - * @param _type Element type. - * @param _normalized When using fixed point AttribType (f.e. Uint8) - * value will be normalized for vertex shader usage. When normalized - * is set to true, AttribType::Uint8 value in range 0-255 will be - * in range 0.0-1.0 in vertex shader. - * @param _asInt Packaging rule for vertexPack, vertexUnpack, and - * vertexConvert for AttribType::Uint8 and AttribType::Int16. - * Unpacking code must be implemented inside vertex shader. - * - * NOTE: - * Must be called between begin/end. - */ +/**/ BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt); -/** - * Skip _num bytes in vertex stream. - */ +/**/ BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _decl, uint8_t _num); -/** - * End vertex declaration. - */ +/**/ BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _decl); -/** - * Pack vec4 into vertex stream format. - */ +/**/ BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index); -/** - * Unpack vec4 from vertex stream format. - */ +/**/ BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index); -/** - * Converts vertex stream data from one vertex stream format to another. - * - * @param _destDecl Destination vertex stream declaration. - * @param _destData Destination vertex stream. - * @param _srcDecl Source vertex stream declaration. - * @param _srcData Source vertex stream data. - * @param _num Number of vertices to convert from source to destination. - */ +/**/ BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num); -/** - * Weld vertices. - * - * @param _output Welded vertices remapping table. The size of buffer - * must be the same as number of vertices. - * @param _decl Vertex stream declaration. - * @param _data Vertex stream. - * @param _num Number of vertices in vertex stream. - * @param _epsilon Error tolerance for vertex position comparison. - * @returns Number of unique vertices after vertex welding. - */ +/**/ BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon); -/** - * Swizzle RGBA8 image to BGRA8. - * - * @param _width Width of input image (pixels). - * @param _height Height of input image (pixels). - * @param _pitch Pitch of input image (bytes). - * @param _src Source image. - * @param _dst Destination image. Must be the same size as input image. - * _dst might be pointer to the same memory as _src. - */ +/**/ BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); -/** - * Downsample RGBA8 image with 2x2 pixel average filter. - * - * @param _width Width of input image (pixels). - * @param _height Height of input image (pixels). - * @param _pitch Pitch of input image (bytes). - * @param _src Source image. - * @param _dst Destination image. Must be at least quarter size of - * input image. _dst might be pointer to the same memory as _src. - */ +/**/ BGFX_C_API void bgfx_image_rgba8_downsample_2x2(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); -/** - * Returns supported backend API renderers. - */ +/**/ BGFX_C_API uint8_t bgfx_get_supported_renderers(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]); -/** - * Returns name of renderer. - */ +/**/ BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type); -/** - * Initialize bgfx library. - * - * @param _type Select rendering backend. When set to RendererType::Count - * default rendering backend will be selected. - * - * @param _callback Provide application specific callback interface. - * See: CallbackI - * - * @param _reallocator Custom allocator. When custom allocator is not - * specified, library uses default CRT allocator. The library assumes - * custom allocator is thread safe. - */ +/**/ BGFX_C_API void bgfx_init(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_reallocator_interface_t* _allocator); -/** - * Shutdown bgfx library. - */ +/**/ BGFX_C_API void bgfx_shutdown(); -/** - * Reset graphic settings. - */ +/**/ BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags); -/** - * Advance to next frame. When using multithreaded renderer, this call - * just swaps internal buffers, kicks render thread, and returns. In - * singlethreaded renderer this call does frame rendering. - * - * @returns Current frame number. This might be used in conjunction with - * double/multi buffering data outside the library and passing it to - * library via makeRef calls. - */ +/**/ BGFX_C_API uint32_t bgfx_frame(); -/** - * Returns current renderer backend API type. - * - * NOTE: - * Library must be initialized. - */ +/**/ BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type(); -/** - * Returns renderer capabilities. - * - * NOTE: - * Library must be initialized. - */ +/**/ BGFX_C_API const bgfx_caps_t* bgfx_get_caps(); -/** - * Returns HMD info. - */ +/**/ BGFX_C_API const bgfx_hmd_t* bgfx_get_hmd(); -/** - * Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx. - */ +/**/ BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size); -/** - * Allocate buffer and copy data into it. Data will be freed inside bgfx. - */ +/**/ BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size); -/** - * Make reference to data to pass to bgfx. Unlike bgfx::alloc this call - * doesn't allocate memory for data. It just copies pointer to data. - * You must make sure data is available for at least 2 bgfx::frame calls. - */ +/**/ BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size); -/** - * - */ +/**/ BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData); -/** - * Set debug flags. - * - * @param _debug Available flags: - * - * BGFX_DEBUG_IFH - Infinitely fast hardware. When this flag is set - * all rendering calls will be skipped. It's useful when profiling - * to quickly assess bottleneck between CPU and GPU. - * - * BGFX_DEBUG_STATS - Display internal statistics. - * - * BGFX_DEBUG_TEXT - Display debug text. - * - * BGFX_DEBUG_WIREFRAME - Wireframe rendering. All rendering - * primitives will be rendered as lines. - */ +/**/ BGFX_C_API void bgfx_set_debug(uint32_t _debug); -/** - * Clear internal debug text buffer. - */ +/**/ BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small); -/** - * Print into internal debug text buffer. - */ +/**/ BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...); -/** - * Draw image into internal debug text buffer. - * - * @param _x X position from top-left. - * @param _y Y position from top-left. - * @param _width Image width. - * @param _height Image height. - * @param _data Raw image data (character/attribute raw encoding). - * @param _pitch Image pitch in bytes. - */ +/**/ BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch); -/** - * Create static index buffer. - * - * NOTE: - * Only 16-bit index buffer is supported. - */ -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem); +/**/ +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags); -/** - * Destroy static index buffer. - */ +/**/ BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle); -/** - * Create static vertex buffer. - * - * @param _mem Vertex buffer data. - * @param _decl Vertex declaration. - * @returns Static vertex buffer handle. - */ -BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags); +/**/ +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags); -/** - * Destroy static vertex buffer. - * - * @param _handle Static vertex buffer handle. - */ +/**/ BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle); -/** - * Create empty dynamic index buffer. - * - * @param _num Number of indices. - * - * NOTE: - * Only 16-bit index buffer is supported. - */ -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num); +/**/ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags); -/** - * Create dynamic index buffer and initialized it. - * - * @param _mem Index buffer data. - * - * NOTE: - * Only 16-bit index buffer is supported. - */ -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem); +/**/ +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags); -/** - * Update dynamic index buffer. - * - * @param _handle Dynamic index buffer handle. - * @param _mem Index buffer data. - */ +/**/ BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, const bgfx_memory_t* _mem); -/** - * Destroy dynamic index buffer. - * - * @param _handle Dynamic index buffer handle. - */ +/**/ BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle); -/** - * Create empty dynamic vertex buffer. - * - * @param _num Number of vertices. - * @param _decl Vertex declaration. - */ -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint8_t _flags); +/**/ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags); -/** - * Create dynamic vertex buffer and initialize it. - * - * @param _mem Vertex buffer data. - * @param _decl Vertex declaration. - */ -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl); +/**/ +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags); -/** - * Update dynamic vertex buffer. - */ +/**/ BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, const bgfx_memory_t* _mem); -/** - * Destroy dynamic vertex buffer. - */ +/**/ BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle); -/** - * Returns true if internal transient index buffer has enough space. - * - * @param _num Number of indices. - */ +/**/ BGFX_C_API bool bgfx_check_avail_transient_index_buffer(uint32_t _num); -/** - * Returns true if internal transient vertex buffer has enough space. - * - * @param _num Number of vertices. - * @param _decl Vertex declaration. - */ +/**/ BGFX_C_API bool bgfx_check_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl); -/** - * Returns true if internal instance data buffer has enough space. - * - * @param _num Number of instances. - * @param _stride Stride per instance. - */ +/**/ BGFX_C_API bool bgfx_check_avail_instance_data_buffer(uint32_t _num, uint16_t _stride); -/** - * Returns true if both internal transient index and vertex buffer have - * enough space. - * - * @param _numVertices Number of vertices. - * @param _decl Vertex declaration. - * @param _numIndices Number of indices. - */ +/**/ BGFX_C_API bool bgfx_check_avail_transient_buffers(uint32_t _numVertices, const bgfx_vertex_decl_t* _decl, uint32_t _numIndices); -/** - * Allocate transient index buffer. - * - * @param[out] _tib TransientIndexBuffer structure is filled and is valid - * for the duration of frame, and it can be reused for multiple draw - * calls. - * @param _num Number of indices to allocate. - * - * NOTE: - * 1. You must call setIndexBuffer after alloc in order to avoid memory - * leak. - * 2. Only 16-bit index buffer is supported. - */ +/**/ BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num); -/** - * Allocate transient vertex buffer. - * - * @param[out] _tvb TransientVertexBuffer structure is filled and is valid - * for the duration of frame, and it can be reused for multiple draw - * calls. - * @param _num Number of vertices to allocate. - * @param _decl Vertex declaration. - * - * NOTE: - * You must call setVertexBuffer after alloc in order to avoid memory - * leak. - */ +/**/ BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl); -/** - * Check for required space and allocate transient vertex and index - * buffers. If both space requirements are satisfied function returns - * true. - * - * NOTE: - * Only 16-bit index buffer is supported. - */ +/**/ BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices); -/** - * Allocate instance data buffer. - * - * NOTE: - * You must call setInstanceDataBuffer after alloc in order to avoid - * memory leak. - */ +/**/ BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(uint32_t _num, uint16_t _stride); -/** - * Create shader from memory buffer. - */ +/**/ +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num); + +/**/ +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle); + +/**/ BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem); -/** - * Returns num of uniforms, and uniform handles used inside shader. - * - * @param _handle Shader handle. - * @param _uniforms UniformHandle array where data will be stored. - * @param _max Maximum capacity of array. - * @returns Number of uniforms used by shader. - * - * NOTE: - * Only non-predefined uniforms are returned. - */ +/**/ BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max); -/** - * Destroy shader. Once program is created with shader it is safe to - * destroy shader. - */ +/**/ BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle); -/** - * Create program with vertex and fragment shaders. - * - * @param _vsh Vertex shader. - * @param _fsh Fragment shader. - * @param _destroyShaders If true, shaders will be destroyed when - * program is destroyed. - * @returns Program handle if vertex shader output and fragment shader - * input are matching, otherwise returns invalid program handle. - */ +/**/ BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders); -/** - * Destroy program. - */ +/**/ +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders); + +/**/ BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle); -/** - * Calculate amount of memory required for texture. - */ +/**/ BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format); -/** - * Create texture from memory buffer. - * - * @param _mem DDS, KTX or PVR texture data. - * @param _flags Default texture sampling mode is linear, and wrap mode - * is repeat. - * - * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap - * mode. - * - * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic - * sampling. - * - * @param _skip Skip top level mips when parsing texture. - * @param _info Returns parsed texture information. - * @returns Texture handle. - */ +/**/ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info); -/** - * Create 2D texture. - * - * @param _width - * @param _height - * @param _numMips - * @param _format - * @param _flags - * @param _mem - */ +/**/ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); -/** - * Create 3D texture. - * - * @param _width - * @param _height - * @param _depth - * @param _numMips - * @param _format - * @param _flags - * @param _mem - */ +/**/ +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags); + +/**/ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); -/** - * Create Cube texture. - * - * @param _size - * @param _numMips - * @param _format - * @param _flags - * @param _mem - */ +/**/ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem); -/** - * Update 2D texture. - * - * @param _handle - * @param _mip - * @param _x - * @param _y - * @param _width - * @param _height - * @param _mem - * @param _pitch Pitch of input image (bytes). When _pitch is set to - * UINT16_MAX, it will be calculated internally based on _width. - */ +/**/ BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); -/** - * Update 3D texture. - * - * @param _handle - * @param _mip - * @param _x - * @param _y - * @param _z - * @param _width - * @param _height - * @param _depth - * @param _mem - */ +/**/ BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem); -/** - * Update Cube texture. - * - * @param _handle - * @param _side Cubemap side, where 0 is +X, 1 is -X, 2 is +Y, 3 is - * -Y, 4 is +Z, and 5 is -Z. - * - * +----------+ - * |-z 2| - * | ^ +y | - * | | | - * | +---->+x | - * +----------+----------+----------+----------+ - * |+y 1|+y 4|+y 0|+y 5| - * | ^ -x | ^ +z | ^ +x | ^ -z | - * | | | | | | | | | - * | +---->+z | +---->+x | +---->-z | +---->-x | - * +----------+----------+----------+----------+ - * |+z 3| - * | ^ -y | - * | | | - * | +---->+x | - * +----------+ - * - * @param _mip - * @param _x - * @param _y - * @param _width - * @param _height - * @param _mem - * @param _pitch Pitch of input image (bytes). When _pitch is set to - * UINT16_MAX, it will be calculated internally based on _width. - */ +/**/ BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch); -/** - * Destroy texture. - */ +/**/ BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle); -/** - * Create frame buffer (simple). - * - * @param _width Texture width. - * @param _height Texture height. - * @param _format Texture format. - * @param _textureFlags Texture flags. - */ +/**/ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint32_t _textureFlags); -/** - * Create frame buffer. - * - * @param _num Number of texture attachments. - * @param _handles Texture attachments. - * @param _destroyTextures If true, textures will be destroyed when - * frame buffer is destroyed. - */ +/**/ +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags); + +/**/ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures); -/** - * Create frame buffer for multiple window rendering. - * - * @param _nwh OS' target native window handle. - * @param _width Window back buffer width. - * @param _height Window back buffer height. - * @param _depthFormat Window back buffer depth format. - * - * NOTE: - * Frame buffer cannnot be used for sampling. - */ +/**/ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat); -/** - * Destroy frame buffer. - */ +/**/ BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle); -/** - * Create shader uniform parameter. - * - * @param _name Uniform name in shader. - * @param _type Type of uniform (See: UniformType). - * @param _num Number of elements in array. - * - * Predefined uniforms: - * - * u_viewRect vec4(x, y, width, height) - view rectangle for current - * view. - * - * u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse - * width and height - * - * u_view mat4 - view matrix - * - * u_invView mat4 - inverted view matrix - * - * u_proj mat4 - projection matrix - * - * u_invProj mat4 - inverted projection matrix - * - * u_viewProj mat4 - concatenated view projection matrix - * - * u_invViewProj mat4 - concatenated inverted view projection matrix - * - * u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices. - * - * u_modelView mat4 - concatenated model view matrix, only first - * model matrix from array is used. - * - * u_modelViewProj mat4 - concatenated model view projection matrix. - * - * u_alphaRef float - alpha reference value for alpha test. - */ +/**/ BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num); -/** - * Destroy shader uniform parameter. - */ +/**/ BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle); -/** - * Set clear color palette value. - * - * @param _index Index into palette. - * @param _rgba RGBA floating point value. - */ +/**/ BGFX_C_API void bgfx_set_clear_color(uint8_t _index, const float _rgba[4]); -/** - * Set view name. - * - * @param _id View id. - * @param _name View name. - * - * NOTE: - * This is debug only feature. - */ +/**/ BGFX_C_API void bgfx_set_view_name(uint8_t _id, const char* _name); -/** - * Set view rectangle. Draw primitive outside view will be clipped. - * - * @param _id View id. - * @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(uint8_t _id, 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. - * - * @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(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); -/** - * Set view clear flags. - * - * @param _id View id. - * @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear - * operation. See: BGFX_CLEAR_*. - * @param _rgba Color clear value. - * @param _depth Depth clear value. - * @param _stencil Stencil clear value. - */ +/**/ 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 - * frame buffer texture. Must use setClearColor to setup clear color - * palette. - - * @param _id View id. - * @param _flags Clear flags. Use BGFX_CLEAR_NONE to remove any clear - * operation. See: BGFX_CLEAR_*. - * @param _depth Depth clear value. - * @param _stencil Stencil clear value. - */ +/**/ 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 - * order in which submit calls were called. - */ +/**/ BGFX_C_API void bgfx_set_view_seq(uint8_t _id, bool _enabled); -/** - * Set view frame buffer. - * - * @param _id View id. - * @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(uint8_t _id, 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, all draw primitives in this - * view will use these matrices. - */ +/**/ BGFX_C_API void bgfx_set_view_transform_stereo(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR); -/** - * Sets debug marker. - */ +/**/ BGFX_C_API void bgfx_set_marker(const char* _marker); -/** - * Set render states for draw primitive. - * - * @param _state State flags. Default state for primitive type is - * triangles. See: BGFX_STATE_DEFAULT. - * - * BGFX_STATE_ALPHA_WRITE - Enable alpha write. - * BGFX_STATE_DEPTH_WRITE - Enable depth write. - * BGFX_STATE_DEPTH_TEST_* - Depth test function. - * BGFX_STATE_BLEND_* - See NOTE 1: BGFX_STATE_BLEND_FUNC. - * BGFX_STATE_BLEND_EQUATION_* - See NOTE 2. - * BGFX_STATE_CULL_* - Backface culling mode. - * BGFX_STATE_RGB_WRITE - Enable RGB write. - * BGFX_STATE_MSAA - Enable MSAA. - * BGFX_STATE_PT_[LINES/POINTS] - Primitive type. - * - * @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and - * BGFX_STATE_BLEND_INV_FACTOR blend modes. - * - * NOTE: - * 1. Use BGFX_STATE_ALPHA_REF, BGFX_STATE_POINT_SIZE and - * BGFX_STATE_BLEND_FUNC macros to setup more complex states. - * 2. BGFX_STATE_BLEND_EQUATION_ADD is set when no other blend - * equation is specified. - */ +/**/ BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba); -/** - * Set stencil test state. - * - * @param _fstencil Front stencil state. - * @param _bstencil Back stencil state. If back is set to BGFX_STENCIL_NONE - * _fstencil is applied to both front and back facing primitives. - */ +/**/ BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil); -/** - * Set scissor for draw primitive. For scissor for all primitives in - * view see setViewScissor. - * - * @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. - * @returns Scissor cache index. - */ +/**/ BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); -/** - * Set scissor from cache for draw primitive. - * - * @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive - * scissor and primitive will use view scissor instead. - */ +/**/ BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache); -/** - * Set model matrix for draw primitive. If it is not called model will - * be rendered with identity model matrix. - * - * @param _mtx Pointer to first matrix in array. - * @param _num Number of matrices in array. - * @returns index into matrix cache in case the same model matrix has - * to be used for other draw primitive call. - */ +/**/ BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num); -/** - * Reserve `_num` matrices in internal matrix cache. Pointer returned - * can be modifed until `bgfx::frame` is called. - * - * @param _transform Pointer to `Transform` structure. - * @param _num Number of matrices. - * @returns index into matrix cache. - */ +/**/ BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num); -/** - * Set model matrix from matrix cache for draw primitive. - * - * @param _cache Index in matrix cache. - * @param _num Number of matrices from cache. - */ +/**/ BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num); -/** - * Set shader uniform parameter for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num); -/** - * Set index buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); -/** - * Set index buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices); -/** - * Set index buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices); -/** - * Set vertex buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices); -/** - * Set vertex buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _numVertices); -/** - * Set vertex buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_transient_vertex_buffer(const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices); -/** - * Set instance data buffer for draw primitive. - */ +/**/ BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _num); -/** - * Set program for draw primitive. - */ +/**/ +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/**/ +BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num); + +/**/ BGFX_C_API void bgfx_set_program(bgfx_program_handle_t _handle); -/** - * Set texture stage for draw primitive. - * - * @param _stage Texture unit. - * @param _sampler Program sampler. - * @param _handle Texture handle. - * @param _flags Texture sampling mode. Default value UINT32_MAX uses - * texture sampling settings from the texture. - * - * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap - * mode. - * - * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic - * sampling. - * - * @param _flags Texture sampler filtering flags. UINT32_MAX use the - * sampler filtering mode set by texture. - */ +/**/ BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags); -/** - * Set texture stage for draw primitive. - * - * @param _stage Texture unit. - * @param _sampler Program sampler. - * @param _handle Frame buffer handle. - * @param _attachment Attachment index. - * @param _flags Texture sampling mode. Default value UINT32_MAX uses - * texture sampling settings from the texture. - * - * BGFX_TEXTURE_[U/V/W]_[MIRROR/CLAMP] - Mirror or clamp to edge wrap - * mode. - * - * BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC] - Point or anisotropic - * sampling. - */ +/**/ BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags); -/** - * Submit primitive for rendering into single view. - * - * @param _id View id. - * @param _depth Depth for sorting. - * @returns Number of draw calls. - */ +/**/ BGFX_C_API uint32_t bgfx_submit(uint8_t _id, int32_t _depth); -/** - * - */ +/**/ +BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _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_access_t _access, bgfx_texture_format_t _format); -/** - * - */ +/**/ BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format); -/** - * Dispatch compute. - */ -BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags); +/**/ +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access); -/** - * Discard all previously set state for draw call. - */ +/**/ +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access); + +/**/ +BGFX_C_API uint32_t bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags); + +/**/ +BGFX_C_API uint32_t bgfx_dispatch_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags); + +/**/ BGFX_C_API void bgfx_discard(); -/** - * Request screen shot. - * - * @param _filePath Will be passed to CallbackI::screenShot callback. - * - * NOTE: - * CallbackI::screenShot must be implemented. - */ +/**/ BGFX_C_API void bgfx_save_screen_shot(const char* _filePath); #endif // BGFX_C99_H_HEADER_GUARD diff --git a/3rdparty/bgfx/include/bgfx.h b/3rdparty/bgfx/include/bgfx.h index 5a623dd817a..5f67ddee438 100644 --- a/3rdparty/bgfx/include/bgfx.h +++ b/3rdparty/bgfx/include/bgfx.h @@ -193,13 +193,14 @@ namespace bgfx { enum Enum { - None, Equal, Half, Quarter, Eighth, Sixteenth, Double, + + Count }; }; @@ -209,6 +210,7 @@ namespace bgfx BGFX_HANDLE(DynamicVertexBufferHandle); BGFX_HANDLE(FrameBufferHandle); BGFX_HANDLE(IndexBufferHandle); + BGFX_HANDLE(IndirectBufferHandle); BGFX_HANDLE(ProgramHandle); BGFX_HANDLE(ShaderHandle); BGFX_HANDLE(TextureHandle); @@ -620,12 +622,21 @@ namespace bgfx const Caps* getCaps(); /// Returns HMD info. + /// + /// @attention C99 equivalent is `bgfx_get_hmd`. + /// const HMD* getHMD(); /// Allocate buffer to pass to bgfx calls. Data will be freed inside bgfx. + /// + /// @attention C99 equivalent is `bgfx_alloc`. + /// const Memory* alloc(uint32_t _size); /// Allocate buffer and copy data into it. Data will be freed inside bgfx. + /// + /// @attention C99 equivalent is `bgfx_copy`. + /// const Memory* copy(const void* _data, uint32_t _size); /// Make reference to data to pass to bgfx. Unlike `bgfx::alloc` this call @@ -634,6 +645,9 @@ namespace bgfx /// consumed, or you must make sure data is available for at least 2 /// `bgfx::frame` calls. `ReleaseFn` function must be able to be called /// called from any thread. + /// + /// @attention C99 equivalent are `bgfx_make_ref`, `bgfx_make_ref_release`. + /// const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn = NULL, void* _userData = NULL); /// Set debug flags. @@ -647,12 +661,20 @@ namespace bgfx /// - `BGFX_DEBUG_WIREFRAME` - Wireframe rendering. All rendering /// primitives will be rendered as lines. /// + /// @attention C99 equivalent is `bgfx_set_debug`. + /// void setDebug(uint32_t _debug); /// Clear internal debug text buffer. + /// + /// @attention C99 equivalent is `bgfx_dbg_text_clear`. + /// void dbgTextClear(uint8_t _attr = 0, bool _small = false); /// Print into internal debug text buffer. + /// + /// @attention C99 equivalent is `bgfx_dbg_text_printf`. + /// void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...); /// Draw image into internal debug text buffer. @@ -664,6 +686,8 @@ namespace bgfx /// @param _data Raw image data (character/attribute raw encoding). /// @param _pitch Image pitch in bytes. /// + /// @attention C99 equivalent is `bgfx_dbg_text_image`. + /// void dbgTextImage(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch); /// Create static index buffer. @@ -682,9 +706,14 @@ namespace bgfx /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on /// index buffers. /// - IndexBufferHandle createIndexBuffer(const Memory* _mem, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_index_buffer`. + /// + IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags = BGFX_BUFFER_NONE); /// Destroy static index buffer. + /// + /// @attention C99 equivalent is `bgfx_destroy_index_buffer`. + /// void destroyIndexBuffer(IndexBufferHandle _handle); /// Create static vertex buffer. @@ -693,12 +722,16 @@ namespace bgfx /// @param _decl Vertex declaration. /// @returns Static vertex buffer handle. /// - VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_vertex_buffer`. + /// + VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags = BGFX_BUFFER_NONE); /// Destroy static vertex buffer. /// /// @param _handle Static vertex buffer handle. /// + /// @attention C99 equivalent is `bgfx_destroy_vertex_buffer`. + /// void destroyVertexBuffer(VertexBufferHandle _handle); /// Create empty dynamic index buffer. @@ -717,7 +750,9 @@ namespace bgfx /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on /// index buffers. /// - DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_dynamic_index_buffer`. + /// + DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags = BGFX_BUFFER_NONE); /// Create dynamic index buffer and initialized it. /// @@ -735,19 +770,25 @@ namespace bgfx /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on /// index buffers. /// - DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_dynamic_index_buffer_mem`. + /// + DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags = BGFX_BUFFER_NONE); /// Update dynamic index buffer. /// /// @param _handle Dynamic index buffer handle. /// @param _mem Index buffer data. /// + /// @attention C99 equivalent is `bgfx_update_dynamic_index_buffer`. + /// void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem); /// Destroy dynamic index buffer. /// /// @param _handle Dynamic index buffer handle. /// + /// @attention C99 equivalent is `bgfx_destroy_dynamic_index_buffer`. + /// void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle); /// Create empty dynamic vertex buffer. @@ -767,7 +808,9 @@ namespace bgfx /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on /// index buffers. /// - DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_dynamic_vertex_buffer`. + /// + DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags = BGFX_BUFFER_NONE); /// Create dynamic vertex buffer and initialize it. /// @@ -786,18 +829,28 @@ namespace bgfx /// - `BGFX_BUFFER_INDEX32` - Buffer is using 32-bit indices. This flag has effect only on /// index buffers. /// - DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags = BGFX_BUFFER_NONE); + /// @attention C99 equivalent is `bgfx_create_dynamic_vertex_buffer_mem`. + /// + DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags = BGFX_BUFFER_NONE); /// Update dynamic vertex buffer. + /// + /// @attention C99 equivalent is `bgfx_update_dynamic_vertex_buffer`. + /// void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem); /// Destroy dynamic vertex buffer. + /// + /// @attention C99 equivalent is `bgfx_destroy_dynamic_vertex_buffer`. + /// void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle); /// Returns true if internal transient index buffer has enough space. /// /// @param _num Number of indices. /// + /// @attention C99 equivalent is `bgfx_check_avail_transient_index_buffer`. + /// bool checkAvailTransientIndexBuffer(uint32_t _num); /// Returns true if internal transient vertex buffer has enough space. @@ -805,6 +858,8 @@ namespace bgfx /// @param _num Number of vertices. /// @param _decl Vertex declaration. /// + /// @attention C99 equivalent is `bgfx_check_avail_transient_vertex_buffer`. + /// bool checkAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl); /// Returns true if internal instance data buffer has enough space. @@ -812,6 +867,8 @@ namespace bgfx /// @param _num Number of instances. /// @param _stride Stride per instance. /// + /// @attention C99 equivalent is `bgfx_check_avail_instance_data_buffer`. + /// bool checkAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride); /// Returns true if both internal transient index and vertex buffer have @@ -821,6 +878,8 @@ namespace bgfx /// @param _decl Vertex declaration. /// @param _numIndices Number of indices. /// + /// @attention C99 equivalent is `bgfx_check_avail_transient_buffers`. + /// bool checkAvailTransientBuffers(uint32_t _numVertices, const VertexDecl& _decl, uint32_t _numIndices); /// Allocate transient index buffer. @@ -835,6 +894,8 @@ namespace bgfx /// leak. /// 2. Only 16-bit index buffer is supported. /// + /// @attention C99 equivalent is `bgfx_alloc_transient_index_buffer`. + /// void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num); /// Allocate transient vertex buffer. @@ -849,6 +910,8 @@ namespace bgfx /// You must call setVertexBuffer after alloc in order to avoid memory /// leak. /// + /// @attention C99 equivalent is `bgfx_alloc_transient_vertex_buffer`. + /// void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl); /// Check for required space and allocate transient vertex and index @@ -858,6 +921,8 @@ namespace bgfx /// @remarks /// Only 16-bit index buffer is supported. /// + /// @attention C99 equivalent is `bgfx_alloc_transient_buffers`. + /// bool allocTransientBuffers(TransientVertexBuffer* _tvb, const VertexDecl& _decl, uint32_t _numVertices, TransientIndexBuffer* _tib, uint32_t _numIndices); /// Allocate instance data buffer. @@ -866,9 +931,26 @@ namespace bgfx /// You must call setInstanceDataBuffer after alloc in order to avoid /// memory leak. /// + /// @attention C99 equivalent is `bgfx_alloc_instance_data_buffer`. + /// const InstanceDataBuffer* allocInstanceDataBuffer(uint32_t _num, uint16_t _stride); + /// Create draw indirect buffer. + /// + /// @attention C99 equivalent is `bgfx_create_indirect_buffer`. + /// + IndirectBufferHandle createIndirectBuffer(uint32_t _num); + + /// Destroy draw indirect buffer. + /// + /// @attention C99 equivalent is `bgfx_destroy_indirect_buffer`. + /// + void destroyIndirectBuffer(IndirectBufferHandle _handle); + /// Create shader from memory buffer. + /// + /// @attention C99 equivalent is `bgfx_create_shader`. + /// ShaderHandle createShader(const Memory* _mem); /// Returns num of uniforms, and uniform handles used inside shader. @@ -881,10 +963,15 @@ namespace bgfx /// @remarks /// Only non-predefined uniforms are returned. /// + /// @attention C99 equivalent is `bgfx_get_shader_uniforms`. + /// uint16_t getShaderUniforms(ShaderHandle _handle, UniformHandle* _uniforms = NULL, uint16_t _max = 0); /// Destroy shader. Once program is created with shader it is safe to /// destroy shader. + /// + /// @attention C99 equivalent is `bgfx_destroy_shader`. + /// void destroyShader(ShaderHandle _handle); /// Create program with vertex and fragment shaders. @@ -896,6 +983,8 @@ namespace bgfx /// @returns Program handle if vertex shader output and fragment shader /// input are matching, otherwise returns invalid program handle. /// + /// @attention C99 equivalent is `bgfx_create_program`. + /// ProgramHandle createProgram(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders = false); /// Create program with compute shader. @@ -905,12 +994,20 @@ namespace bgfx /// program is destroyed. /// @returns Program handle. /// + /// @attention C99 equivalent is `bgfx_create_compute_program`. + /// ProgramHandle createProgram(ShaderHandle _csh, bool _destroyShader = false); /// Destroy program. + /// + /// @attention C99 equivalent is `bgfx_destroy_program`. + /// void destroyProgram(ProgramHandle _handle); /// Calculate amount of memory required for texture. + /// + /// @attention C99 equivalent is `bgfx_calc_texture_size`. + /// void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, TextureFormat::Enum _format); /// Create texture from memory buffer. @@ -927,6 +1024,8 @@ namespace bgfx /// @param[out] _info When non-`NULL` is specified it returns parsed texture information. /// @returns Texture handle. /// + /// @attention C99 equivalent is `bgfx_create_texture`. + /// TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, uint8_t _skip = 0, TextureInfo* _info = NULL); /// Create 2D texture. @@ -938,9 +1037,13 @@ namespace bgfx /// @param _flags /// @param _mem /// + /// @attention C99 equivalent is `bgfx_create_texture_2d`. + /// TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL); /// + /// @attention C99 equivalent is `bgfx_create_texture_2d_scaled`. + /// TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE); /// Create 3D texture. @@ -953,6 +1056,8 @@ namespace bgfx /// @param _flags /// @param _mem /// + /// @attention C99 equivalent is `bgfx_create_texture_3d`. + /// TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL); /// Create Cube texture. @@ -963,6 +1068,8 @@ namespace bgfx /// @param _flags /// @param _mem /// + /// @attention C99 equivalent is `bgfx_create_texture_cube`. + /// TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags = BGFX_TEXTURE_NONE, const Memory* _mem = NULL); /// Update 2D texture. @@ -977,6 +1084,8 @@ namespace bgfx /// @param _pitch Pitch of input image (bytes). When _pitch is set to /// UINT16_MAX, it will be calculated internally based on _width. /// + /// @attention C99 equivalent is `bgfx_update_texture_2d`. + /// void updateTexture2D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch = UINT16_MAX); /// Update 3D texture. @@ -991,6 +1100,8 @@ namespace bgfx /// @param _depth /// @param _mem /// + /// @attention C99 equivalent is `bgfx_update_texture_3d`. + /// void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem); /// Update Cube texture. @@ -1025,9 +1136,14 @@ namespace bgfx /// @param _pitch Pitch of input image (bytes). When _pitch is set to /// UINT16_MAX, it will be calculated internally based on _width. /// + /// @attention C99 equivalent is `bgfx_update_texture_cube`. + /// void updateTextureCube(TextureHandle _handle, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch = UINT16_MAX); /// Destroy texture. + /// + /// @attention C99 equivalent is `bgfx_destroy_texture`. + /// void destroyTexture(TextureHandle _handle); /// Create frame buffer (simple). @@ -1037,9 +1153,13 @@ namespace bgfx /// @param _format Texture format. /// @param _textureFlags Texture flags. /// + /// @attention C99 equivalent is `bgfx_create_frame_buffer`. + /// FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP); /// + /// @attention C99 equivalent is `bgfx_create_frame_buffer_scaled`. + /// FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint32_t _textureFlags = BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP); /// Create frame buffer. @@ -1049,6 +1169,8 @@ namespace bgfx /// @param _destroyTextures If true, textures will be destroyed when /// frame buffer is destroyed. /// + /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_handles`. + /// FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false); /// Create frame buffer for multiple window rendering. @@ -1063,9 +1185,14 @@ namespace bgfx /// @remarks /// Frame buffer cannnot be used for sampling. /// + /// @attention C99 equivalent is `bgfx_create_frame_buffer_from_nwh`. + /// FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat = TextureFormat::UnknownDepth); /// Destroy frame buffer. + /// + /// @attention C99 equivalent is `bgfx_destroy_frame_buffer`. + /// void destroyFrameBuffer(FrameBufferHandle _handle); /// Create shader uniform parameter. @@ -1094,12 +1221,16 @@ namespace bgfx /// - `u_modelViewProj mat4` - concatenated model view projection matrix. /// - `u_alphaRef float` - alpha reference value for alpha test. /// + /// @attention C99 equivalent is `bgfx_create_uniform`. + /// UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1); /// Destroy shader uniform parameter. /// /// @param _handle Handle to uniform object. /// + /// @attention C99 equivalent is `bgfx_destroy_uniform`. + /// void destroyUniform(UniformHandle _handle); /// Set clear color palette value. @@ -1107,6 +1238,8 @@ namespace bgfx /// @param _index Index into palette. /// @param _rgba Packed 32-bit RGBA value. /// + /// @attention C99 equivalent is ``. + /// void setClearColor(uint8_t _index, uint32_t _rgba); /// Set clear color palette value. @@ -1114,6 +1247,8 @@ namespace bgfx /// @param _index Index into palette. /// @param _r, _g, _b, _a RGBA floating point values. /// + /// @attention C99 equivalent is ``. + /// void setClearColor(uint8_t _index, float _r, float _g, float _b, float _a); /// Set clear color palette value. @@ -1121,6 +1256,8 @@ namespace bgfx /// @param _index Index into palette. /// @param _rgba RGBA floating point value. /// + /// @attention C99 equivalent is `bgfx_set_clear_color`. + /// void setClearColor(uint8_t _index, const float _rgba[4]); /// Set view name. @@ -1139,6 +1276,8 @@ namespace bgfx /// | +-- compute (C) /// +-- view id /// + /// @attention C99 equivalent is `bgfx_set_view_name`. + /// void setViewName(uint8_t _id, const char* _name); /// Set view rectangle. Draw primitive outside view will be clipped. @@ -1149,6 +1288,8 @@ namespace bgfx /// @param _width Width of view port region. /// @param _height Height of view port region. /// + /// @attention C99 equivalent is `bgfx_set_view_rect`. + /// void setViewRect(uint8_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); /// Set view scissor. Draw primitive outside view will be clipped. When @@ -1159,6 +1300,8 @@ namespace bgfx /// @param _width Width of scissor region. /// @param _height Height of scissor region. /// + /// @attention C99 equivalent is `bgfx_set_view_scissor`. + /// void setViewScissor(uint8_t _id, uint16_t _x = 0, uint16_t _y = 0, uint16_t _width = 0, uint16_t _height = 0); /// Set view clear flags. @@ -1170,6 +1313,8 @@ namespace bgfx /// @param _depth Depth clear value. /// @param _stencil Stencil clear value. /// + /// @attention C99 equivalent is `bgfx_set_view_clear`. + /// 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 @@ -1182,10 +1327,15 @@ namespace bgfx /// @param _depth Depth clear value. /// @param _stencil Stencil clear value. /// + /// @attention C99 equivalent is `bgfx_set_view_clear_mrt`. + /// 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. + /// + /// @attention C99 equivalent is `bgfx_set_view_seq`. + /// void setViewSeq(uint8_t _id, bool _enabled); /// Set view frame buffer. @@ -1198,10 +1348,25 @@ namespace bgfx /// @remarks /// Not persistent after `bgfx::reset` call. /// + /// @attention C99 equivalent is `bgfx_set_view_frame_buffer`. + /// void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle); /// Set view view and projection matrices, all draw primitives in this /// view will use these matrices. + /// + /// @param _id View id. + /// @param _view View matrix. + /// @param _projL Projection matrix. When using stereo rendering this projection matrix + /// represent projection matrix for left eye. + /// @param _flags View flags. Use + /// - `BGFX_VIEW_NONE` - View will be rendered only once if stereo mode is enabled. + /// - `BGFX_VIEW_STEREO` - View will be rendered for both eyes if stereo mode is enabled. When + /// stereo mode is disabled this flag doesn't have effect. + /// @param _projR Projection matrix for right eye in stereo mode. + /// + /// @attention C99 equivalent are `bgfx_set_view_transform`, `bgfx_set_view_transform_stereo`. + /// void setViewTransform(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags = BGFX_VIEW_STEREO, const void* _projR = NULL); /// Post submit view reordering. @@ -1211,9 +1376,14 @@ namespace bgfx /// @param _remap View remap id table. Passing `NULL` will reset view ids /// to default state. /// + /// @attention C99 equivalent is ``. + /// void setViewRemap(uint8_t _id = 0, uint8_t _num = UINT8_MAX, const void* _remap = NULL); /// Sets debug marker. + /// + /// @attention C99 equivalent is `bgfx_set_marker`. + /// void setMarker(const char* _marker); /// Set render states for draw primitive. @@ -1239,6 +1409,8 @@ namespace bgfx /// 2. `BGFX_STATE_BLEND_EQUATION_ADD` is set when no other blend /// equation is specified. /// + /// @attention C99 equivalent is `bgfx_set_state`. + /// void setState(uint64_t _state, uint32_t _rgba = 0); /// Set stencil test state. @@ -1247,6 +1419,8 @@ namespace bgfx /// @param _bstencil Back stencil state. If back is set to `BGFX_STENCIL_NONE` /// _fstencil is applied to both front and back facing primitives. /// + /// @attention C99 equivalent is `bgfx_set_stencil`. + /// void setStencil(uint32_t _fstencil, uint32_t _bstencil = BGFX_STENCIL_NONE); /// Set scissor for draw primitive. For scissor for all primitives in @@ -1258,6 +1432,8 @@ namespace bgfx /// @param _height Height of scissor region. /// @returns Scissor cache index. /// + /// @attention C99 equivalent is `bgfx_set_scissor`. + /// uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height); /// Set scissor from cache for draw primitive. @@ -1265,6 +1441,8 @@ namespace bgfx /// @param _cache Index in scissor cache. Passing UINT16_MAX unset primitive /// scissor and primitive will use view scissor instead. /// + /// @attention C99 equivalent is `bgfx_set_scissor_cached`. + /// void setScissor(uint16_t _cache = UINT16_MAX); /// Set model matrix for draw primitive. If it is not called model will @@ -1275,6 +1453,8 @@ namespace bgfx /// @returns index into matrix cache in case the same model matrix has /// to be used for other draw primitive call. /// + /// @attention C99 equivalent is `bgfx_set_transform`. + /// uint32_t setTransform(const void* _mtx, uint16_t _num = 1); /// Reserve `_num` matrices in internal matrix cache. Pointer returned @@ -1284,6 +1464,8 @@ namespace bgfx /// @param _num Number of matrices. /// @returns index into matrix cache. /// + /// @attention C99 equivalent is `bgfx_alloc_transform`. + /// uint32_t allocTransform(Transform* _transform, uint16_t _num); /// Set model matrix from matrix cache for draw primitive. @@ -1291,48 +1473,92 @@ namespace bgfx /// @param _cache Index in matrix cache. /// @param _num Number of matrices from cache. /// + /// @attention C99 equivalent is `bgfx_set_transform_cached`. + /// void setTransform(uint32_t _cache, uint16_t _num = 1); /// Set shader uniform parameter for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_uniform`. + /// void setUniform(UniformHandle _handle, const void* _value, uint16_t _num = 1); /// Set index buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_index_buffer`. + /// void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX); /// Set index buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_dynamic_index_buffer`. + /// void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex = 0, uint32_t _numIndices = UINT32_MAX); /// Set index buffer for draw primitive. + /// + /// @attention C99 equivalent is ``. + /// void setIndexBuffer(const TransientIndexBuffer* _tib); /// Set index buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_transient_index_buffer`. + /// void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices); /// Set vertex buffer for draw primitive. + /// + /// @attention C99 equivalent is ``. + /// void setVertexBuffer(VertexBufferHandle _handle); /// Set vertex buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_vertex_buffer`. + /// void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices); /// Set vertex buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_dynamic_vertex_buffer`. + /// void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices = UINT32_MAX); /// Set vertex buffer for draw primitive. + /// + /// @attention C99 equivalent is ``. + /// void setVertexBuffer(const TransientVertexBuffer* _tvb); /// Set vertex buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_transient_vertex_buffer`. + /// void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices); /// Set instance data buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_instance_data_buffer`. + /// void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _num = UINT32_MAX); /// Set instance data buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_instance_data_from_vertex_buffer`. + /// void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num); /// Set instance data buffer for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_instance_data_from_dynamic_vertex_buffer`. + /// void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num); /// Set program for draw primitive. + /// + /// @attention C99 equivalent is `bgfx_set_program`. + /// void setProgram(ProgramHandle _handle); /// Set texture stage for draw primitive. @@ -1350,6 +1576,8 @@ namespace bgfx /// @param _flags Texture sampler filtering flags. UINT32_MAX use the /// sampler filtering mode set by texture. /// + /// @attention C99 equivalent is `bgfx_set_texture`. + /// void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX); /// Set texture stage for draw primitive. @@ -1365,38 +1593,85 @@ namespace bgfx /// - `BGFX_TEXTURE_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic /// sampling. /// + /// @attention C99 equivalent is `bgfx_set_texture_from_frame_buffer`. + /// void setTexture(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment = 0, uint32_t _flags = UINT32_MAX); - /// Submit primitive for rendering into single view. + /// Submit primitive for rendering. /// /// @param _id View id. /// @param _depth Depth for sorting. /// @returns Number of draw calls. /// + /// @attention C99 equivalent is `bgfx_submit`. + /// uint32_t submit(uint8_t _id, int32_t _depth = 0); + /// Submit primitive for rendering with index and instance data info from + /// indirect buffer. + /// + /// @attention C99 equivalent is `bgfx_submit_indirect`. + /// + uint32_t submit(uint8_t _id, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, int32_t _depth = 0); + + /// + /// + /// @attention C99 equivalent is `bgfx_set_compute_index_buffer`. /// void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access); /// + /// + /// @attention C99 equivalent is `bgfx_set_compute_vertex_buffer`. + /// void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access); /// + /// + /// @attention C99 equivalent is `bgfx_set_compute_dynamic_index_buffer`. + /// void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access); /// + /// + /// @attention C99 equivalent is `bgfx_set_compute_dynamic_vertex_buffer`. + /// void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access); /// + /// + /// @attention C99 equivalent is `bgfx_set_compute_indirect_buffer`. + /// + void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access); + + /// Set compute image from texture. + /// + /// @attention C99 equivalent is `bgfx_set_image`. + /// void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count); + /// Set compute image from frame buffer texture. + /// + /// @attention C99 equivalent is `bgfx_set_image_from_frame_buffer`. /// void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, Access::Enum _access, TextureFormat::Enum _format = TextureFormat::Count); /// Dispatch compute. - void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST); + /// + /// @attention C99 equivalent is `bgfx_dispatch`. + /// + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST); + + /// Dispatch compute indirect. + /// + /// @attention C99 equivalent is `bgfx_dispatch_indirect`. + /// + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST); /// Discard all previously set state for draw or compute call. + /// + /// @attention C99 equivalent is `bgfx_discard`. + /// void discard(); /// Request screen shot. @@ -1406,6 +1681,8 @@ namespace bgfx /// @remarks /// `bgfx::CallbackI::screenShot` must be implemented. /// + /// @attention C99 equivalent is `bgfx_save_screen_shot`. + /// void saveScreenShot(const char* _filePath); } // namespace bgfx diff --git a/3rdparty/bgfx/include/bgfxdefines.h b/3rdparty/bgfx/include/bgfxdefines.h index dc51503f46e..cadb1d1a6d6 100644 --- a/3rdparty/bgfx/include/bgfxdefines.h +++ b/3rdparty/bgfx/include/bgfxdefines.h @@ -221,11 +221,31 @@ #define BGFX_DEBUG_TEXT UINT32_C(0x00000008) /// -#define BGFX_BUFFER_NONE UINT8_C(0x00) -#define BGFX_BUFFER_COMPUTE_READ UINT8_C(0x01) -#define BGFX_BUFFER_COMPUTE_WRITE UINT8_C(0x02) -#define BGFX_BUFFER_ALLOW_RESIZE UINT8_C(0x04) -#define BGFX_BUFFER_INDEX32 UINT8_C(0x08) +#define BGFX_BUFFER_NONE UINT16_C(0x0000) + +#define BGFX_BUFFER_COMPUTE_FORMAT_8x1 UINT16_C(0x0001) +#define BGFX_BUFFER_COMPUTE_FORMAT_8x2 UINT16_C(0x0002) +#define BGFX_BUFFER_COMPUTE_FORMAT_8x4 UINT16_C(0x0003) +#define BGFX_BUFFER_COMPUTE_FORMAT_16x1 UINT16_C(0x0004) +#define BGFX_BUFFER_COMPUTE_FORMAT_16x2 UINT16_C(0x0005) +#define BGFX_BUFFER_COMPUTE_FORMAT_16x4 UINT16_C(0x0006) +#define BGFX_BUFFER_COMPUTE_FORMAT_32x1 UINT16_C(0x0007) +#define BGFX_BUFFER_COMPUTE_FORMAT_32x2 UINT16_C(0x0008) +#define BGFX_BUFFER_COMPUTE_FORMAT_32x4 UINT16_C(0x0009) +#define BGFX_BUFFER_COMPUTE_FORMAT_SHIFT 0 +#define BGFX_BUFFER_COMPUTE_FORMAT_MASK UINT16_C(0x000f) + +#define BGFX_BUFFER_COMPUTE_TYPE_UINT UINT16_C(0x0010) +#define BGFX_BUFFER_COMPUTE_TYPE_INT UINT16_C(0x0020) +#define BGFX_BUFFER_COMPUTE_TYPE_FLOAT UINT16_C(0x0030) +#define BGFX_BUFFER_COMPUTE_TYPE_SHIFT 4 +#define BGFX_BUFFER_COMPUTE_TYPE_MASK UINT16_C(0x0030) + +#define BGFX_BUFFER_COMPUTE_READ UINT16_C(0x0100) +#define BGFX_BUFFER_COMPUTE_WRITE UINT16_C(0x0200) +#define BGFX_BUFFER_DRAW_INDIRECT UINT16_C(0x0400) +#define BGFX_BUFFER_ALLOW_RESIZE UINT16_C(0x0800) +#define BGFX_BUFFER_INDEX32 UINT16_C(0x1000) #define BGFX_BUFFER_COMPUTE_READ_WRITE (BGFX_BUFFER_COMPUTE_READ | BGFX_BUFFER_COMPUTE_WRITE) /// @@ -273,6 +293,7 @@ #define BGFX_TEXTURE_COMPARE_SHIFT 16 #define BGFX_TEXTURE_COMPARE_MASK UINT32_C(0x000f0000) #define BGFX_TEXTURE_COMPUTE_WRITE UINT32_C(0x00100000) +#define BGFX_TEXTURE_SRGB UINT32_C(0x00200000) #define BGFX_TEXTURE_RESERVED_SHIFT 24 #define BGFX_TEXTURE_RESERVED_MASK UINT32_C(0xff000000) @@ -303,7 +324,9 @@ #define BGFX_RESET_HMD UINT32_C(0x00000400) #define BGFX_RESET_HMD_DEBUG UINT32_C(0x00000800) #define BGFX_RESET_HMD_RECENTER UINT32_C(0x00001000) -#define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00002000) +#define BGFX_RESET_FLUSH_AFTER_RENDER UINT32_C(0x00002000) +#define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00004000) +#define BGFX_RESET_SRGB_BACKBUFFER UINT32_C(0x00008000) /// #define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000000001) @@ -319,12 +342,16 @@ #define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400) #define BGFX_CAPS_HMD UINT64_C(0x0000000000000800) #define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000001000) +#define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000002000) /// -#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) -#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01) -#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x02) -#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x04) +#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) +#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01) +#define BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB UINT8_C(0x02) +#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x04) +#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x08) +#define BGFX_CAPS_FORMAT_TEXTURE_IMAGE UINT8_C(0x10) +#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER UINT8_C(0x20) /// #define BGFX_VIEW_NONE UINT8_C(0x00) @@ -337,9 +364,10 @@ #define BGFX_SUBMIT_EYE_FIRST BGFX_SUBMIT_EYE_LEFT /// -#define BGFX_PCI_ID_NONE UINT16_C(0x0000) -#define BGFX_PCI_ID_AMD UINT16_C(0x1002) -#define BGFX_PCI_ID_INTEL UINT16_C(0x8086) -#define BGFX_PCI_ID_NVIDIA UINT16_C(0x10de) +#define BGFX_PCI_ID_NONE UINT16_C(0x0000) +#define BGFX_PCI_ID_SOFTWARE_RASTERIZER UINT16_C(0x0001) +#define BGFX_PCI_ID_AMD UINT16_C(0x1002) +#define BGFX_PCI_ID_INTEL UINT16_C(0x8086) +#define BGFX_PCI_ID_NVIDIA UINT16_C(0x10de) #endif // BGFX_DEFINES_H_HEADER_GUARD diff --git a/3rdparty/bgfx/include/bgfxplatform.c99.h b/3rdparty/bgfx/include/bgfxplatform.c99.h index 5adff2435e1..31c65bd6fd0 100644 --- a/3rdparty/bgfx/include/bgfxplatform.c99.h +++ b/3rdparty/bgfx/include/bgfxplatform.c99.h @@ -31,55 +31,16 @@ typedef enum bgfx_render_frame */ BGFX_C_API bgfx_render_frame_t bgfx_render_frame(); -#if BX_PLATFORM_ANDROID -# include <android/native_window.h> - -/** - * - */ -BGFX_C_API void bgfx_android_set_window(ANativeWindow* _window); - -#elif BX_PLATFORM_IOS - -/** - * - */ -BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer); - -#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI -# include <X11/Xlib.h> - -/** - * - */ -BGFX_C_API void bgfx_x11_set_display_window(Display* _display, Window _window); - -#elif BX_PLATFORM_NACL -# include <ppapi/c/ppb_graphics_3d.h> -# include <ppapi/c/ppb_instance.h> - -typedef void (*bgfx_post_swap_buffers_fn)(uint32_t _width, uint32_t _height); - -/** - * - */ -BGFX_C_API bool bgfx_nacl_set_interfaces(PP_Instance, const PPB_Instance*, const PPB_Graphics3D*, bgfx_post_swap_buffers_fn); - -#elif BX_PLATFORM_OSX - -/** - * - */ -BGFX_C_API void bgfx_osx_set_ns_window(void* _window); - -#elif BX_PLATFORM_WINDOWS -# include <windows.h> +typedef struct bgfx_platform_data +{ + void* ndt; + void* nwh; + void* context; + void* backBuffer; + void* backBufferDS; -/** - * - */ -BGFX_C_API void bgfx_win_set_hwnd(HWND _window); +} bgfx_platform_data_t; -#endif // BX_PLATFORM_ +BGFX_C_API void bgfx_set_platform_data(bgfx_platform_data_t* _pd); #endif // BGFX_PLATFORM_C99_H_HEADER_GUARD diff --git a/3rdparty/bgfx/include/bgfxplatform.h b/3rdparty/bgfx/include/bgfxplatform.h index 4598fc1e7d7..8a2cf5a0711 100644 --- a/3rdparty/bgfx/include/bgfxplatform.h +++ b/3rdparty/bgfx/include/bgfxplatform.h @@ -30,7 +30,19 @@ namespace bgfx /// allow creating separate rendering thread. If it is called before /// to bgfx::init, render thread won't be created by bgfx::init call. RenderFrame::Enum renderFrame(); -} + + struct PlatformData + { + void* ndt; //< Native display type + void* nwh; //< Native window handle + void* context; //< GL context, or D3D device + void* backBuffer; //< GL backbuffer, or D3D render target view + void* backBufferDS; //< Backbuffer depth/stencil. + }; + + void setPlatformData(const PlatformData& _hooks); + +} // namespace bgfx #if BX_PLATFORM_ANDROID # include <android/native_window.h> @@ -38,7 +50,16 @@ namespace bgfx namespace bgfx { /// - void androidSetWindow(::ANativeWindow* _window); + inline void androidSetWindow(::ANativeWindow* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx @@ -46,7 +67,16 @@ namespace bgfx namespace bgfx { /// - void iosSetEaglLayer(void* _layer); + inline void iosSetEaglLayer(void* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx @@ -55,7 +85,16 @@ namespace bgfx namespace bgfx { /// - void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL); + inline void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL) + { + PlatformData pd; + pd.ndt = _display; + pd.nwh = (void*)(uintptr_t)_window; + pd.context = _glx; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx @@ -76,7 +115,16 @@ namespace bgfx namespace bgfx { /// - void osxSetNSWindow(void* _window, void* _nsgl = NULL); + inline void osxSetNSWindow(void* _window, void* _nsgl = NULL) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = _nsgl; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx @@ -86,7 +134,16 @@ namespace bgfx namespace bgfx { /// - void winSetHwnd(::HWND _window); + inline void winSetHwnd(::HWND _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx @@ -96,18 +153,25 @@ namespace bgfx namespace bgfx { /// - void winrtSetWindow(IUnknown* _window); + inline void winrtSetWindow(::IUnknown* _window) + { + PlatformData pd; + pd.ndt = NULL; + pd.nwh = _window; + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); + } } // namespace bgfx #endif // BX_PLATFORM_ -#if defined(_SDL_H) -// If SDL.h is included before bgfxplatform.h we can enable SDL window +#if defined(_SDL_syswm_h) +// If SDL_syswm.h is included before bgfxplatform.h we can enable SDL window // interop convenience code. -# include <SDL2/SDL_syswm.h> - namespace bgfx { /// @@ -120,13 +184,21 @@ namespace bgfx return false; } + PlatformData pd; # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD - x11SetDisplayWindow(wmi.info.x11.display, wmi.info.x11.window); + pd.ndt = wmi.info.x11.display; + pd.nwh = (void*)(uintptr_t)wmi.info.x11.window; # elif BX_PLATFORM_OSX - osxSetNSWindow(wmi.info.cocoa.window); + pd.ndt = NULL; + pd.nwh = wmi.info.cocoa.window; # elif BX_PLATFORM_WINDOWS - winSetHwnd(wmi.info.win.window); + pd.ndt = NULL; + pd.nwh = wmi.info.win.window; # endif // BX_PLATFORM_ + pd.context = NULL; + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); return true; } @@ -153,19 +225,23 @@ namespace bgfx { inline void glfwSetWindow(GLFWwindow* _window) { + PlatformData pd; # if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD - ::Display* display = glfwGetX11Display(); - ::Window window = glfwGetX11Window(_window); - void* glx = glfwGetGLXContext(_window); - x11SetDisplayWindow(display, window, glx); + pd.ndt = glfwGetX11Display(); + pd.nwh = (void*)(uintptr_t)glfwGetX11Window(_window); + pd.context = glfwGetGLXContext(_window); # elif BX_PLATFORM_OSX - void* window = glfwGetCocoaWindow(_window); - void* nsgl = glfwGetNSGLContext(_window); - osxSetNSWindow(window, nsgl); + pd.ndt = NULL; + pd.nwh = glfwGetCocoaWindow(_window); + pd.context = glfwGetNSGLContext(_window); # elif BX_PLATFORM_WINDOWS - HWND hwnd = glfwGetWin32Window(_window); - winSetHwnd(hwnd); + pd.ndt = NULL; + pd.nwh = glfwGetWin32Window(_window); + pd.context = NULL; # endif // BX_PLATFORM_WINDOWS + pd.backBuffer = NULL; + pd.backBufferDS = NULL; + setPlatformData(pd); } } // namespace bgfx diff --git a/3rdparty/bgfx/scripts/bgfx.lua b/3rdparty/bgfx/scripts/bgfx.lua index a3b1899fbc7..693b7a3c6c2 100644 --- a/3rdparty/bgfx/scripts/bgfx.lua +++ b/3rdparty/bgfx/scripts/bgfx.lua @@ -81,7 +81,7 @@ function bgfxProject(_name, _kind, _defines) "$(DXSDK_DIR)/include", } - configuration { "winphone8*"} + configuration { "winphone8* or winstore8*"} linkoptions { "/ignore:4264" -- LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata } diff --git a/3rdparty/bgfx/scripts/example-common.lua b/3rdparty/bgfx/scripts/example-common.lua index 96040b6bfe5..37e53afaa83 100644 --- a/3rdparty/bgfx/scripts/example-common.lua +++ b/3rdparty/bgfx/scripts/example-common.lua @@ -48,7 +48,8 @@ project ("example-common") } end - configuration { "winphone8*"} + configuration { "winphone8* or winstore8*"} linkoptions { "/ignore:4264" -- LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata } + premake.vstudio.splashpath = "../../../examples/runtime/images/SplashScreen.png" diff --git a/3rdparty/bgfx/scripts/genie.lua b/3rdparty/bgfx/scripts/genie.lua index e77a40e22a6..87ef1392731 100644 --- a/3rdparty/bgfx/scripts/genie.lua +++ b/3rdparty/bgfx/scripts/genie.lua @@ -88,10 +88,7 @@ function exampleProject(_name) configuration {} - -- don't output debugdir for winphone builds - if "winphone81" ~= _OPTIONS["vs"] then - debugdir (path.join(BGFX_DIR, "examples/runtime")) - end + debugdir (path.join(BGFX_DIR, "examples/runtime")) includedirs { path.join(BX_DIR, "include"), @@ -221,7 +218,7 @@ function exampleProject(_name) "psapi", } - configuration { "winphone8*"} + configuration { "winphone8* or winstore8*" } removelinks { "DelayImp", "gdi32", @@ -234,7 +231,17 @@ function exampleProject(_name) linkoptions { "/ignore:4264" -- LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata } - -- WinRT targets need their own output directories are build files stomp over each other + + -- WinRT targets need their own output directories or build files stomp over each other + configuration { "x32", "winphone8* or winstore8*" } + targetdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "bin", _name)) + objdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "obj", _name)) + + configuration { "x64", "winphone8* or winstore8*" } + targetdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "bin", _name)) + objdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "obj", _name)) + + configuration { "ARM", "winphone8* or winstore8*" } targetdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "bin", _name)) objdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "obj", _name)) @@ -366,7 +373,11 @@ exampleProject("21-deferred") exampleProject("22-windows") exampleProject("23-vectordisplay") exampleProject("24-nbody") -exampleProject("25-c99") + +-- C99 source doesn't compile under WinRT settings +if not premake.vstudio.iswinrt() then + exampleProject("25-c99") +end if _OPTIONS["with-shared-lib"] then group "libs" diff --git a/3rdparty/bgfx/scripts/shaderc.lua b/3rdparty/bgfx/scripts/shaderc.lua index a52f74bbba6..5f6d4e4fd22 100644 --- a/3rdparty/bgfx/scripts/shaderc.lua +++ b/3rdparty/bgfx/scripts/shaderc.lua @@ -50,7 +50,7 @@ project "shaderc" "Cocoa.framework", } - configuration { "windows", "vs*" } + configuration { "vs*" } includedirs { path.join(GLSL_OPTIMIZER, "include/c99"), } @@ -61,10 +61,9 @@ project "shaderc" } - configuration { "windows" } + configuration { "vs* or mingw*" } links { "d3dcompiler", - "dxguid", } configuration {} diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 55a41dfb74f..1137ee04e32 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -7,7 +7,7 @@ namespace bgfx { -#define BGFX_MAIN_THREAD_MAGIC 0x78666762 +#define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) #if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS # define BGFX_CHECK_MAIN_THREAD() \ @@ -19,56 +19,6 @@ namespace bgfx # define BGFX_CHECK_RENDER_THREAD() #endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS -#if BX_PLATFORM_ANDROID - ::ANativeWindow* g_bgfxAndroidWindow = NULL; - - void androidSetWindow(::ANativeWindow* _window) - { - g_bgfxAndroidWindow = _window; - } -#elif BX_PLATFORM_IOS - void* g_bgfxEaglLayer = NULL; - - void iosSetEaglLayer(void* _layer) - { - g_bgfxEaglLayer = _layer; - } -#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD - void* g_bgfxX11Display; - uint32_t g_bgfxX11Window; - void* g_bgfxGLX; - - void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx) - { - g_bgfxX11Display = _display; - g_bgfxX11Window = _window; - g_bgfxGLX = _glx; - } -#elif BX_PLATFORM_OSX - void* g_bgfxNSWindow = NULL; - void* g_bgfxNSGL = NULL; - - void osxSetNSWindow(void* _window, void* _nsgl) - { - g_bgfxNSWindow = _window; - g_bgfxNSGL = _nsgl; - } -#elif BX_PLATFORM_WINDOWS - ::HWND g_bgfxHwnd = NULL; - - void winSetHwnd(::HWND _window) - { - g_bgfxHwnd = _window; - } -#elif BX_PLATFORM_WINRT - ::IUnknown* g_bgfxCoreWindow = NULL; - - void winrtSetWindow(::IUnknown* _window) - { - g_bgfxCoreWindow = _window; - } -#endif // BX_PLATFORM_* - #if BGFX_CONFIG_USE_TINYSTL void* TinyStlAllocator::static_allocate(size_t _bytes) { @@ -252,6 +202,22 @@ namespace bgfx static BX_THREAD uint32_t s_threadIndex = 0; static Context* s_ctx = NULL; static bool s_renderFrameCalled = false; + PlatformData g_platformData; + + void setPlatformData(const PlatformData& _pd) + { + if (NULL != s_ctx) + { + BGFX_FATAL(true + && g_platformData.ndt == _pd.ndt + && g_platformData.nwh == _pd.nwh + && g_platformData.context == _pd.context + , Fatal::UnableToInitialize + , "Only backbuffer pointer can be changed after initialization!" + ); + } + memcpy(&g_platformData, &_pd, sizeof(PlatformData) ); + } void setGraphicsDebuggerPresent(bool _present) { @@ -387,7 +353,6 @@ namespace bgfx void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem) { - BGFX_CHECK_RENDER_THREAD(); struct Vertex { float m_x; @@ -796,6 +761,7 @@ namespace bgfx if (NULL == s_ctx) { s_renderFrameCalled = true; + s_threadIndex = ~BGFX_MAIN_THREAD_MAGIC; return RenderFrame::NoContext; } @@ -871,6 +837,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_SWAP_CHAIN), CAPS_FLAGS(BGFX_CAPS_HMD), CAPS_FLAGS(BGFX_CAPS_INDEX32), + CAPS_FLAGS(BGFX_CAPS_DRAW_INDIRECT), #undef CAPS_FLAGS }; @@ -890,18 +857,24 @@ namespace bgfx } BX_TRACE("Supported texture formats:"); - BX_TRACE("\t +------ x = supported / * = emulated"); - BX_TRACE("\t |+----- vertex format"); - BX_TRACE("\t || +-- name"); + BX_TRACE("\t +--------- x = supported / * = emulated"); + BX_TRACE("\t |+-------- sRGB format"); + BX_TRACE("\t ||+------- vertex format"); + BX_TRACE("\t |||+------ image"); + BX_TRACE("\t ||||+----- framebuffer"); + BX_TRACE("\t ||||| +-- name"); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { uint8_t flags = g_caps.formats[ii]; - BX_TRACE("\t[%c%c] %s" - , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' ' - , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' + BX_TRACE("\t[%c%c%c%c%c] %s" + , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB ? 'l' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' + , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' , getName(TextureFormat::Enum(ii) ) ); BX_UNUSED(flags); @@ -946,16 +919,26 @@ namespace bgfx // When bgfx::renderFrame is called before init render thread // should not be created. BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread."); + m_singleThreaded = true + && !BX_ENABLED(BX_PLATFORM_OSX || BX_PLATFORM_IOS) + && ~BGFX_MAIN_THREAD_MAGIC == s_threadIndex + ; } else { BX_TRACE("Creating rendering thread."); m_thread.init(renderThread, this); + m_singleThreaded = false; } #else BX_TRACE("Multithreaded renderer is disabled."); + m_singleThreaded = true; #endif // BGFX_CONFIG_MULTITHREADED + BX_TRACE("Running in %s-threaded mode", m_singleThreaded ? "single" : "multi"); + + s_threadIndex = BGFX_MAIN_THREAD_MAGIC; + for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii) { m_viewRemap[ii] = uint8_t(ii); @@ -1004,6 +987,10 @@ namespace bgfx g_caps.rendererType = m_renderCtx->getRendererType(); initAttribTypeSizeTable(g_caps.rendererType); + g_caps.supported |= 0 + | (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) + ; + dumpCaps(); m_textVideoMemBlitter.init(); @@ -1012,9 +999,13 @@ namespace bgfx m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); frame(); - m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); - m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); - frame(); + + if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) + { + m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); + m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); + frame(); + } } void Context::shutdown() @@ -1060,6 +1051,8 @@ namespace bgfx m_render->destroy(); #endif // BGFX_CONFIG_MULTITHREADED + s_ctx = NULL; + m_submit->destroy(); if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) @@ -1187,7 +1180,8 @@ namespace bgfx bx::xchg(m_render, m_submit); - if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) + if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) + || m_singleThreaded) { renderFrame(); } @@ -1567,7 +1561,7 @@ again: Memory* mem; _cmdbuf.read(mem); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createIndexBuffer(handle, mem, flags); @@ -1617,7 +1611,7 @@ again: VertexDeclHandle declHandle; _cmdbuf.read(declHandle); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createVertexBuffer(handle, mem, declHandle, flags); @@ -1643,7 +1637,7 @@ again: uint32_t size; _cmdbuf.read(size); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicIndexBuffer(handle, size, flags); @@ -1687,7 +1681,7 @@ again: uint32_t size; _cmdbuf.read(size); - uint8_t flags; + uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicVertexBuffer(handle, size, flags); @@ -2007,9 +2001,6 @@ again: BX_TRACE("Init..."); memset(&g_caps, 0, sizeof(g_caps) ); - g_caps.supported = 0 - | (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) - ; g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS; g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS; g_caps.maxFBAttachments = 1; @@ -2037,8 +2028,6 @@ again: s_callbackStub = BX_NEW(g_allocator, CallbackStub); } - s_threadIndex = BGFX_MAIN_THREAD_MAGIC; - s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16); s_ctx->init(_type); @@ -2052,6 +2041,7 @@ again: BGFX_CHECK_MAIN_THREAD(); Context* ctx = s_ctx; // it's going to be NULLd inside shutdown. ctx->shutdown(); + BX_CHECK(NULL == s_ctx, "bgfx is should be uninitialized here."); BX_ALIGNED_DELETE(g_allocator, ctx, 16); @@ -2188,7 +2178,7 @@ again: s_ctx->dbgTextImage(_x, _y, _width, _height, _data, _pitch); } - IndexBufferHandle createIndexBuffer(const Memory* _mem, uint8_t _flags) + IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2201,7 +2191,7 @@ again: s_ctx->destroyIndexBuffer(_handle); } - VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags) + VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2215,13 +2205,13 @@ again: s_ctx->destroyVertexBuffer(_handle); } - DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags) + DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); return s_ctx->createDynamicIndexBuffer(_num, _flags); } - DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint8_t _flags) + DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2241,14 +2231,14 @@ again: s_ctx->destroyDynamicIndexBuffer(_handle); } - DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 != _decl.m_stride, "Invalid VertexDecl."); return s_ctx->createDynamicVertexBuffer(_num, _decl, _flags); } - DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); @@ -2337,6 +2327,18 @@ again: return s_ctx->allocInstanceDataBuffer(_num, _stride); } + IndirectBufferHandle createIndirectBuffer(uint32_t _num) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->createIndirectBuffer(_num); + } + + void destroyIndirectBuffer(IndirectBufferHandle _handle) + { + BGFX_CHECK_MAIN_THREAD(); + s_ctx->destroyIndirectBuffer(_handle); + } + ShaderHandle createShader(const Memory* _mem) { BGFX_CHECK_MAIN_THREAD(); @@ -2436,7 +2438,7 @@ again: { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _mem, "_mem can't be NULL"); - return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::None); + return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::Count); } void getTextureSizeFromRatio(BackbufferRatio::Enum _ratio, uint16_t& _width, uint16_t& _height) @@ -2482,7 +2484,7 @@ again: uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); - if (BackbufferRatio::None != _ratio) + if (BackbufferRatio::Count != _ratio) { _width = uint16_t(s_ctx->m_frame->m_resolution.m_width); _height = uint16_t(s_ctx->m_frame->m_resolution.m_height); @@ -2506,11 +2508,13 @@ again: TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) { - return createTexture2D(BackbufferRatio::None, _width, _height, _numMips, _format, _flags, _mem); + BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); + return createTexture2D(BackbufferRatio::Count, _width, _height, _numMips, _format, _flags, _mem); } TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) { + BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); return createTexture2D(_ratio, 0, 0, _numMips, _format, _flags, NULL); } @@ -2552,7 +2556,7 @@ again: tc.m_mem = _mem; bx::write(&writer, tc); - return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::None); + return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); } TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem) @@ -2592,7 +2596,7 @@ again: tc.m_mem = _mem; bx::write(&writer, tc); - return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::None); + return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count); } void destroyTexture(TextureHandle _handle) @@ -2657,6 +2661,7 @@ again: FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint32_t _textureFlags) { + BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_ratio, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); @@ -2960,6 +2965,12 @@ again: return s_ctx->submit(_id, _depth); } + uint32_t submit(uint8_t _id, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->submit(_id, _indirectHandle, _start, _num, _depth); + } + void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_MAIN_THREAD(); @@ -2984,6 +2995,12 @@ again: s_ctx->setBuffer(_stage, _handle, _access); } + void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) + { + BGFX_CHECK_MAIN_THREAD(); + s_ctx->setBuffer(_stage, _handle, _access); + } + void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { BGFX_CHECK_MAIN_THREAD(); @@ -2996,10 +3013,16 @@ again: s_ctx->setImage(_stage, _sampler, _handle, _attachment, _access, _format); } - void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) + { + BGFX_CHECK_MAIN_THREAD(); + return s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); + } + + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { BGFX_CHECK_MAIN_THREAD(); - s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); + return s_ctx->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } void discard() @@ -3033,6 +3056,7 @@ BX_STATIC_ASSERT(sizeof(bgfx::TransientVertexBuffer) == sizeof(bgfx_transient_ve BX_STATIC_ASSERT(sizeof(bgfx::InstanceDataBuffer) == sizeof(bgfx_instance_data_buffer_t) ); BX_STATIC_ASSERT(sizeof(bgfx::TextureInfo) == sizeof(bgfx_texture_info_t) ); BX_STATIC_ASSERT(sizeof(bgfx::Caps) == sizeof(bgfx_caps_t) ); +BX_STATIC_ASSERT(sizeof(bgfx::PlatformData) == sizeof(bgfx_platform_data_t) ); BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer) { @@ -3191,10 +3215,10 @@ BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, u bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); } -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags) { union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3204,7 +3228,7 @@ BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle) bgfx::destroyIndexBuffer(handle.cpp); } -BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint8_t _flags) +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle; @@ -3218,17 +3242,17 @@ BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle) bgfx::destroyVertexBuffer(handle.cpp); } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer(_num); + handle.cpp = bgfx::createDynamicIndexBuffer(_num, _flags); return handle.c; } -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem) +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags) { union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem); + handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem, _flags); return handle.c; } @@ -3244,7 +3268,7 @@ BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_hand bgfx::destroyDynamicIndexBuffer(handle.cpp); } -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint8_t _flags) +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; @@ -3252,11 +3276,11 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer return handle.c; } -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl) +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) { const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl); + handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags); return handle.c; } @@ -3316,6 +3340,19 @@ BGFX_C_API const bgfx_instance_data_buffer_t* bgfx_alloc_instance_data_buffer(ui return (bgfx_instance_data_buffer_t*)bgfx::allocInstanceDataBuffer(_num, _stride); } +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle; + handle.cpp = bgfx::createIndirectBuffer(_num); + return handle.c; +} + +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::destroyIndirectBuffer(handle.cpp); +} + BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem) { union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle; @@ -3344,6 +3381,14 @@ BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, return handle.c; } +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } csh = { _csh }; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle; + handle.cpp = bgfx::createProgram(csh.cpp, _destroyShaders); + return handle.c; +} + BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) { union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; @@ -3371,6 +3416,13 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_ return handle.c; } +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; + handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags); + return handle.c; +} + BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem) { union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; @@ -3416,6 +3468,13 @@ BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, return handle.c; } +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint32_t _textureFlags) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; + handle.cpp = bgfx::createFrameBuffer(bgfx::BackbufferRatio::Enum(_ratio), bgfx::TextureFormat::Enum(_format), _textureFlags); + return handle.c; +} + BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures) { union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; @@ -3585,6 +3644,18 @@ BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* bgfx::setInstanceDataBuffer( (const bgfx::InstanceDataBuffer*)_idb, _num); } +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + BGFX_C_API void bgfx_set_program(bgfx_program_handle_t _handle) { union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; @@ -3610,6 +3681,12 @@ 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_indirect(uint8_t _id, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + return bgfx::submit(_id, indirectHandle.cpp, _start, _num, _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_access_t _access, bgfx_texture_format_t _format) { union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; @@ -3624,61 +3701,65 @@ BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_ha bgfx::setImage(_stage, sampler.cpp, handle.cpp, _attachment, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ); } -BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) { - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - bgfx::dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags); + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API void bgfx_discard() +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::discard(); + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::saveScreenShot(_filePath); + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -BGFX_C_API bgfx_render_frame_t bgfx_render_frame() +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) { - return bgfx_render_frame_t(bgfx::renderFrame() ); + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -#if BX_PLATFORM_ANDROID -BGFX_C_API void bgfx_android_set_window(ANativeWindow* _window) +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) { - bgfx::androidSetWindow(_window); + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); } -#elif BX_PLATFORM_IOS -BGFX_C_API void bgfx_ios_set_eagl_layer(void* _layer) +BGFX_C_API uint32_t bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) { - bgfx::iosSetEaglLayer(_layer); + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; + return bgfx::dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags); } -#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_RPI -BGFX_C_API void bgfx_x11_set_display_window(::Display* _display, ::Window _window) +BGFX_C_API uint32_t bgfx_dispatch_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { - bgfx::x11SetDisplayWindow(_display, _window); + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + return bgfx::dispatch(_id, handle.cpp, indirectHandle.cpp, _start, _num, _flags); } -#elif BX_PLATFORM_NACL -BGFX_C_API bool bgfx_nacl_set_interfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, bgfx_post_swap_buffers_fn _postSwapBuffers) +BGFX_C_API void bgfx_discard() { - return bgfx::naclSetInterfaces(_instance, _instInterface, _graphicsInterface, _postSwapBuffers); + bgfx::discard(); } -#elif BX_PLATFORM_OSX -BGFX_C_API void bgfx_osx_set_ns_window(void* _window) +BGFX_C_API void bgfx_save_screen_shot(const char* _filePath) { - bgfx::osxSetNSWindow(_window); + bgfx::saveScreenShot(_filePath); } -#elif BX_PLATFORM_WINDOWS -BGFX_C_API void bgfx_win_set_hwnd(HWND _window) +BGFX_C_API bgfx_render_frame_t bgfx_render_frame() { - bgfx::winSetHwnd(_window); + return bgfx_render_frame_t(bgfx::renderFrame() ); } -#endif // BX_PLATFORM_* +BGFX_C_API void bgfx_set_platform_data(bgfx_platform_data_t* _pd) +{ + bgfx::setPlatformData(*(bgfx::PlatformData*)_pd); +} diff --git a/3rdparty/bgfx/src/bgfx_compute.sh b/3rdparty/bgfx/src/bgfx_compute.sh index fd38626c04c..eb405e45793 100644 --- a/3rdparty/bgfx/src/bgfx_compute.sh +++ b/3rdparty/bgfx/src/bgfx_compute.sh @@ -44,10 +44,11 @@ vec2 unpackHalf2x16(uint _x) #define SHARED groupshared -#define r32ui uint -#define r32f float -#define rg16f float2 -#define rgba8 float4 +#define r32ui uint +#define r32f float +#define rg16f float2 +#define rgba16f float4 +#define rgba8 float4 #define IMAGE2D_RO( _name, _format, _reg) Texture2D<_format> _name : register(t[_reg]) #define UIMAGE2D_RO(_name, _format, _reg) Texture2D<_format> _name : register(t[_reg]) @@ -99,6 +100,13 @@ ivec2 imageSize(Texture2D _image) return result; } +ivec2 imageSize(Texture2D<uint> _image) +{ + ivec2 result; + _image.GetDimensions(result.x, result.y); + return result; +} + ivec2 imageSize(RWTexture2D<float4> _image) { ivec2 result; @@ -186,6 +194,34 @@ uint atomicCompSwap(uint _mem, uint _compare, uint _data) #endif // BGFX_SHADER_LANGUAGE_HLSL +#define dispatchIndirect(_buffer \ + , _offset \ + , _numX \ + , _numY \ + , _numZ \ + ) \ + _buffer[_offset*2+0] = uvec4(_numX, _numY, _numZ, 0u) + +#define drawIndirect(_buffer \ + , _offset \ + , _numVertices \ + , _numInstances \ + , _startVertex \ + , _startInstance \ + ) \ + _buffer[_offset*2+0] = uvec4(_numVertices, _numInstances, _startVertex, _startInstance) + +#define drawIndexedIndirect(_buffer \ + , _offset \ + , _numIndices \ + , _numInstances \ + , _startIndex \ + , _startVertex \ + , _startInstance \ + ) \ + _buffer[_offset*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startInstance); \ + _buffer[_offset*2+1] = uvec4(_startInstance, 0u, 0u, 0u) + #endif // __cplusplus #endif // BGFX_COMPUTE_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index c9e57421e84..224100456e6 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -217,22 +217,7 @@ namespace stl namespace bgfx { -#if BX_PLATFORM_ANDROID - extern ::ANativeWindow* g_bgfxAndroidWindow; -#elif BX_PLATFORM_IOS - extern void* g_bgfxEaglLayer; -#elif BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD - extern void* g_bgfxX11Display; - extern uint32_t g_bgfxX11Window; - extern void* g_bgfxGLX; -#elif BX_PLATFORM_OSX - extern void* g_bgfxNSWindow; - extern void* g_bgfxNSGL; -#elif BX_PLATFORM_WINDOWS - extern ::HWND g_bgfxHwnd; -#elif BX_PLATFORM_WINRT - extern ::IUnknown* g_bgfxCoreWindow; -#endif // BX_PLATFORM_* + extern PlatformData g_platformData; #if BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10) typedef uint16_t RenderItemCount; @@ -1087,6 +1072,8 @@ namespace bgfx m_instanceDataOffset = 0; m_instanceDataStride = 0; m_numInstances = 1; + m_startIndirect = 0; + m_numIndirect = UINT16_MAX; m_num = 1; m_flags = BGFX_SUBMIT_EYE_FIRST; m_scissor = UINT16_MAX; @@ -1094,6 +1081,7 @@ namespace bgfx m_vertexDecl.idx = invalidHandle; m_indexBuffer.idx = invalidHandle; m_instanceDataBuffer.idx = invalidHandle; + m_indirectBuffer.idx = invalidHandle; for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) { @@ -1115,6 +1103,8 @@ namespace bgfx uint32_t m_instanceDataOffset; uint16_t m_instanceDataStride; uint16_t m_numInstances; + uint16_t m_startIndirect; + uint16_t m_numIndirect; uint16_t m_num; uint16_t m_scissor; uint8_t m_submitFlags; @@ -1123,6 +1113,7 @@ namespace bgfx VertexDeclHandle m_vertexDecl; IndexBufferHandle m_indexBuffer; VertexBufferHandle m_instanceDataBuffer; + IndirectBufferHandle m_indirectBuffer; }; struct RenderCompute @@ -1138,6 +1129,10 @@ namespace bgfx m_num = 0; m_submitFlags = BGFX_SUBMIT_EYE_FIRST; + m_indirectBuffer.idx = invalidHandle; + m_startIndirect = 0; + m_numIndirect = UINT16_MAX; + for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii) { m_bind[ii].m_idx = invalidHandle; @@ -1148,10 +1143,13 @@ namespace bgfx uint32_t m_constBegin; uint32_t m_constEnd; uint32_t m_matrix; + IndirectBufferHandle m_indirectBuffer; uint16_t m_numX; uint16_t m_numY; uint16_t m_numZ; + uint16_t m_startIndirect; + uint16_t m_numIndirect; uint16_t m_num; uint8_t m_submitFlags; }; @@ -1187,7 +1185,7 @@ namespace bgfx uint32_t m_offset; uint32_t m_size; uint32_t m_startIndex; - uint8_t m_flags; + uint16_t m_flags; }; struct DynamicVertexBuffer @@ -1199,7 +1197,7 @@ namespace bgfx uint32_t m_numVertices; uint16_t m_stride; VertexDeclHandle m_decl; - uint8_t m_flags; + uint16_t m_flags; }; BX_ALIGN_DECL_CACHE_LINE(struct) Frame @@ -1464,7 +1462,25 @@ namespace bgfx } uint32_t submit(uint8_t _id, int32_t _depth); + + uint32_t submit(uint8_t _id, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) + { + m_draw.m_startIndirect = _start; + m_draw.m_numIndirect = _num; + m_draw.m_indirectBuffer = _indirectHandle; + return submit(_id, _depth); + } + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _ngx, uint16_t _ngy, uint16_t _ngz, uint8_t _flags); + + uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) + { + m_compute.m_indirectBuffer = _indirectHandle; + m_compute.m_startIndirect = _start; + m_compute.m_numIndirect = _num; + return dispatch(_id, _handle, 0, 0, 0, _flags); + } + void sort(); bool checkAvailTransientIndexBuffer(uint32_t _num) @@ -1831,16 +1847,16 @@ namespace bgfx virtual RendererType::Enum getRendererType() const = 0; virtual const char* getRendererName() const = 0; virtual void flip(HMD& _hmd) = 0; - virtual void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) = 0; + virtual void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint16_t _flags) = 0; virtual void destroyIndexBuffer(IndexBufferHandle _handle) = 0; virtual void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) = 0; virtual void destroyVertexDecl(VertexDeclHandle _handle) = 0; - virtual void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint8_t _flags) = 0; + virtual void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) = 0; virtual void destroyVertexBuffer(VertexBufferHandle _handle) = 0; - virtual void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t _flags) = 0; + virtual void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) = 0; virtual void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) = 0; virtual void destroyDynamicIndexBuffer(IndexBufferHandle _handle) = 0; - virtual void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint8_t _flags) = 0; + virtual void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) = 0; virtual void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) = 0; virtual void destroyDynamicVertexBuffer(VertexBufferHandle _handle) = 0; virtual void createShader(ShaderHandle _handle, Memory* _mem) = 0; @@ -1894,6 +1910,7 @@ namespace bgfx , m_rendererInitialized(false) , m_exit(false) , m_flipAfterRender(false) + , m_singleThreaded(false) { } @@ -1936,7 +1953,7 @@ namespace bgfx { uint16_t textureIdx = m_textureHandle.getHandleAt(ii); const TextureRef& textureRef = m_textureRef[textureIdx]; - if (BackbufferRatio::None != textureRef.m_bbRatio) + if (BackbufferRatio::Count != textureRef.m_bbRatio) { TextureHandle handle = { textureIdx }; resizeTexture(handle @@ -1978,7 +1995,7 @@ namespace bgfx return NULL; } - BGFX_API_FUNC(IndexBufferHandle createIndexBuffer(const Memory* _mem, uint8_t _flags) ) + BGFX_API_FUNC(IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) ) { IndexBufferHandle handle = { m_indexBufferHandle.alloc() }; @@ -2019,7 +2036,7 @@ namespace bgfx return declHandle; } - BGFX_API_FUNC(VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t flags) ) + BGFX_API_FUNC(VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) ) { VertexBufferHandle handle = { m_vertexBufferHandle.alloc() }; @@ -2035,7 +2052,7 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(_mem); cmdbuf.write(declHandle); - cmdbuf.write(flags); + cmdbuf.write(_flags); } return handle; @@ -2062,7 +2079,7 @@ namespace bgfx m_vertexBufferHandle.free(_handle.idx); } - uint64_t allocDynamicIndexBuffer(uint32_t _size, uint8_t _flags) + uint64_t allocDynamicIndexBuffer(uint32_t _size, uint16_t _flags) { uint64_t ptr = m_dynIndexBufferAllocator.alloc(_size); if (ptr == NonLocalAllocator::invalidBlock) @@ -2086,7 +2103,7 @@ namespace bgfx return ptr; } - BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags) ) + BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags) ) { DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE; const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; @@ -2134,7 +2151,7 @@ namespace bgfx return handle; } - BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint8_t _flags) ) + BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags) ) { BX_CHECK(0 == (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Cannot initialize compute buffer from CPU."); const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; @@ -2211,7 +2228,7 @@ namespace bgfx m_dynamicIndexBufferHandle.free(_handle.idx); } - uint64_t allocDynamicVertexBuffer(uint32_t _size, uint8_t _flags) + uint64_t allocDynamicVertexBuffer(uint32_t _size, uint16_t _flags) { uint64_t ptr = m_dynVertexBufferAllocator.alloc(_size); if (ptr == NonLocalAllocator::invalidBlock) @@ -2236,7 +2253,7 @@ namespace bgfx return ptr; } - BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags) ) + BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags) ) { DynamicVertexBufferHandle handle = BGFX_INVALID_HANDLE; uint32_t size = bx::strideAlign16(_num*_decl.m_stride, _decl.m_stride); @@ -2283,7 +2300,7 @@ namespace bgfx return handle; } - BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint8_t _flags) ) + BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) ) { uint32_t numVertices = _mem->size/_decl.m_stride; BX_CHECK(numVertices <= UINT16_MAX, "Num vertices exceeds maximum (num %d, max %d).", numVertices, UINT16_MAX); @@ -2388,7 +2405,8 @@ namespace bgfx CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicIndexBuffer); cmdbuf.write(handle); cmdbuf.write(_size); - cmdbuf.write(uint8_t(BGFX_BUFFER_NONE) ); + uint16_t flags = BGFX_BUFFER_NONE; + cmdbuf.write(flags); tib = (TransientIndexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientIndexBuffer)+_size); tib->data = (uint8_t*)&tib[1]; @@ -2443,7 +2461,8 @@ namespace bgfx CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); cmdbuf.write(handle); cmdbuf.write(_size); - cmdbuf.write(false); + uint16_t flags = BGFX_BUFFER_NONE; + cmdbuf.write(flags); tvb = (TransientVertexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientVertexBuffer)+_size); tvb->data = (uint8_t*)&tvb[1]; @@ -2511,6 +2530,36 @@ namespace bgfx return idb; } + IndirectBufferHandle createIndirectBuffer(uint32_t _num) + { + BX_UNUSED(_num); + IndirectBufferHandle handle = { m_vertexBufferHandle.alloc() }; + + BX_WARN(isValid(handle), "Failed to allocate draw indirect buffer handle."); + if (isValid(handle) ) + { + uint32_t size = _num * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + uint16_t flags = BGFX_BUFFER_DRAW_INDIRECT; + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); + cmdbuf.write(handle); + cmdbuf.write(size); + cmdbuf.write(flags); + } + + return handle; + } + + void destroyIndirectBuffer(IndirectBufferHandle _handle) + { + VertexBufferHandle handle = { _handle.idx }; + BGFX_CHECK_HANDLE("destroyDrawIndirectBuffer", m_vertexBufferHandle, handle); + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyDynamicVertexBuffer); + cmdbuf.write(handle); + m_submit->free(handle); + } + BGFX_API_FUNC(ShaderHandle createShader(const Memory* _mem) ) { bx::MemoryReader reader(_mem->data, _mem->size); @@ -2810,7 +2859,7 @@ namespace bgfx void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) { const TextureRef& textureRef = m_textureRef[_handle.idx]; - BX_CHECK(BackbufferRatio::None != textureRef.m_bbRatio, ""); + BX_CHECK(BackbufferRatio::Count != textureRef.m_bbRatio, ""); getTextureSizeFromRatio(BackbufferRatio::Enum(textureRef.m_bbRatio), _width, _height); @@ -3304,6 +3353,12 @@ namespace bgfx return m_submit->submit(_id, _depth); } + BGFX_API_FUNC(uint32_t submit(uint8_t _id, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) ) + { + BGFX_CHECK_HANDLE("submit", m_vertexBufferHandle, _indirectHandle); + return m_submit->submit(_id, _indirectHandle, _start, _num, _depth); + } + BGFX_API_FUNC(void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) ) { BGFX_CHECK_HANDLE("setBuffer", m_indexBufferHandle, _handle); @@ -3330,6 +3385,13 @@ namespace bgfx m_submit->setBuffer(_stage, dvb.m_handle, _access); } + BGFX_API_FUNC(void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) ) + { + BGFX_CHECK_HANDLE("setBuffer", m_vertexBufferHandle, _handle); + VertexBufferHandle handle = { _handle.idx }; + m_submit->setBuffer(_stage, handle, _access); + } + BGFX_API_FUNC(void setImage(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) ) { _format = TextureFormat::Count == _format ? TextureFormat::Enum(m_textureRef[_handle.idx].m_format) : _format; @@ -3359,6 +3421,11 @@ namespace bgfx return m_submit->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); } + BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) ) + { + return m_submit->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); + } + BGFX_API_FUNC(void discard() ) { m_submit->discard(); @@ -3380,28 +3447,40 @@ namespace bgfx #if BGFX_CONFIG_MULTITHREADED void gameSemPost() { - m_gameSem.post(); + if (!m_singleThreaded) + { + m_gameSem.post(); + } } void gameSemWait() { - int64_t start = bx::getHPCounter(); - bool ok = m_gameSem.wait(); - BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok); - m_render->m_waitSubmit = bx::getHPCounter()-start; + if (!m_singleThreaded) + { + int64_t start = bx::getHPCounter(); + bool ok = m_gameSem.wait(); + BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok); + m_render->m_waitSubmit = bx::getHPCounter()-start; + } } void renderSemPost() { - m_renderSem.post(); + if (!m_singleThreaded) + { + m_renderSem.post(); + } } void renderSemWait() { - int64_t start = bx::getHPCounter(); - bool ok = m_renderSem.wait(); - BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok); - m_submit->m_waitRender = bx::getHPCounter() - start; + if (!m_singleThreaded) + { + int64_t start = bx::getHPCounter(); + bool ok = m_renderSem.wait(); + BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok); + m_submit->m_waitRender = bx::getHPCounter() - start; + } } bx::Semaphore m_renderSem; @@ -3532,6 +3611,7 @@ namespace bgfx bool m_rendererInitialized; bool m_exit; bool m_flipAfterRender; + bool m_singleThreaded; typedef UpdateBatchT<256> TextureUpdateBatch; BX_ALIGN_DECL_CACHE_LINE(TextureUpdateBatch m_textureUpdateBatch); diff --git a/3rdparty/bgfx/src/bgfx_shader.sh b/3rdparty/bgfx/src/bgfx_shader.sh index 52de12e84a0..c3d74bb9b6b 100644 --- a/3rdparty/bgfx/src/bgfx_shader.sh +++ b/3rdparty/bgfx/src/bgfx_shader.sh @@ -199,7 +199,6 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) # define SAMPLER2D(_name, _reg) uniform sampler2D _name : register(s ## _reg) # define texture2D(_sampler, _coord) tex2D(_sampler, _coord) -# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) # define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name : register(s ## _reg) @@ -208,12 +207,21 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) # define SAMPLER3D(_name, _reg) uniform sampler3D _name : register(s ## _reg) # define texture3D(_sampler, _coord) tex3D(_sampler, _coord) -# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) # define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : register(s[_reg]) # define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) -# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) -# endif // + +# if BGFX_SHADER_LANGUAGE_HLSL == 2 +# define texture2DLod(_sampler, _coord, _level) tex2D(_sampler, (_coord).xy) +# define texture3DLod(_sampler, _coord, _level) tex3D(_sampler, (_coord).xyz) +# define textureCubeLod(_sampler, _coord, _level) texCUBE(_sampler, (_coord).xyz) +# else +# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) +# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) +# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) +# endif // BGFX_SHADER_LANGUAGE_HLSL == 2 + +# endif // BGFX_SHADER_LANGUAGE_HLSL > 3 vec2 vec2_splat(float _x) { return vec2(_x, _x); } vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } diff --git a/3rdparty/bgfx/src/config.h b/3rdparty/bgfx/src/config.h index 1aeaf930b85..9323a1388c3 100644 --- a/3rdparty/bgfx/src/config.h +++ b/3rdparty/bgfx/src/config.h @@ -267,4 +267,6 @@ # define BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE 16 #endif // BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE +#define BGFX_CONFIG_DRAW_INDIRECT_STRIDE 32 + #endif // BGFX_CONFIG_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/fs_clear0.bin.h b/3rdparty/bgfx/src/fs_clear0.bin.h index 8a49f45759a..d473f46c1a2 100644 --- a/3rdparty/bgfx/src/fs_clear0.bin.h +++ b/3rdparty/bgfx/src/fs_clear0.bin.h @@ -1,14 +1,13 @@ -static const uint8_t fs_clear0_glsl[130] = +static const uint8_t fs_clear0_glsl[128] = { 0x46, 0x53, 0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x07, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x5c, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .....uniform vec + 0x00, 0x5a, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .Z...uniform vec 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[0];.}. - 0x0a, 0x00, // .. + 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, // ().{. gl_FragC + 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, // olor = bgfx_clea + 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r_color[0];.}... }; static const uint8_t fs_clear0_dx9[204] = { diff --git a/3rdparty/bgfx/src/fs_clear0.sc b/3rdparty/bgfx/src/fs_clear0.sc index f6ba277ea97..f6eb6a18c28 100644 --- a/3rdparty/bgfx/src/fs_clear0.sc +++ b/3rdparty/bgfx/src/fs_clear0.sc @@ -7,5 +7,5 @@ uniform vec4 bgfx_clear_color[8]; void main() { - gl_FragData[0] = bgfx_clear_color[0]; + gl_FragColor = bgfx_clear_color[0]; } diff --git a/3rdparty/bgfx/src/glcontext_eagl.mm b/3rdparty/bgfx/src/glcontext_eagl.mm index 73eedd2b587..1f1c0880264 100644 --- a/3rdparty/bgfx/src/glcontext_eagl.mm +++ b/3rdparty/bgfx/src/glcontext_eagl.mm @@ -18,7 +18,7 @@ namespace bgfx { namespace gl void GlContext::create(uint32_t _width, uint32_t _height) { BX_UNUSED(_width, _height); - CAEAGLLayer* layer = (CAEAGLLayer*)g_bgfxEaglLayer; + CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh; layer.opaque = true; layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys diff --git a/3rdparty/bgfx/src/glcontext_egl.cpp b/3rdparty/bgfx/src/glcontext_egl.cpp index 93990746c5b..2850121e5e4 100644 --- a/3rdparty/bgfx/src/glcontext_egl.cpp +++ b/3rdparty/bgfx/src/glcontext_egl.cpp @@ -14,48 +14,46 @@ # include <bcm_host.h> # endif // BX_PLATFORM_RPI -#ifndef EGL_CONTEXT_MAJOR_VERSION_KHR -# define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION -#endif // EGL_CONTEXT_MAJOR_VERSION_KHR - -#ifndef EGL_CONTEXT_MINOR_VERSION_KHR -# define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB -#endif // EGL_CONTEXT_MINOR_VERSION_KHR - namespace bgfx { namespace gl { +#ifndef EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR +# define EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008 +#endif // EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR + #if BGFX_USE_GL_DYNAMIC_LIB typedef void (*EGLPROC)(void); - typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPINTERVALPROC)(EGLDisplay dpy, EGLint interval); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); - typedef EGLContext (EGLAPIENTRY* PFNEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); - typedef EGLSurface (EGLAPIENTRY* PFNEGLCREATEWINDOWSURFACEPROC)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLCHOOSECONFIGPROC)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLINITIALIZEPROC)(EGLDisplay dpy, EGLint *major, EGLint *minor); - typedef EGLint (EGLAPIENTRY* PFNEGLGETERRORPROC)(void); - typedef EGLDisplay (EGLAPIENTRY* PFNEGLGETDISPLAYPROC)(EGLNativeDisplayType display_id); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLTERMINATEPROC)(EGLDisplay dpy); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYSURFACEPROC)(EGLDisplay dpy, EGLSurface surface); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYCONTEXTPROC)(EGLDisplay dpy, EGLContext ctx); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPBUFFERSPROC)(EGLDisplay dpy, EGLSurface surface); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLCHOOSECONFIGPROC)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); + typedef EGLContext (EGLAPIENTRY* PFNEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); + typedef EGLSurface (EGLAPIENTRY* PFNEGLCREATEWINDOWSURFACEPROC)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list); + typedef EGLint (EGLAPIENTRY* PFNEGLGETERRORPROC)(void); + typedef EGLDisplay (EGLAPIENTRY* PFNEGLGETDISPLAYPROC)(EGLNativeDisplayType display_id); + typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLINITIALIZEPROC)(EGLDisplay dpy, EGLint *major, EGLint *minor); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYCONTEXTPROC)(EGLDisplay dpy, EGLContext ctx); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYSURFACEPROC)(EGLDisplay dpy, EGLSurface surface); + typedef const char* (EGLAPIENTRY* PGNEGLQUERYSTRINGPROC)(EGLDisplay dpy, EGLint name); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPBUFFERSPROC)(EGLDisplay dpy, EGLSurface surface); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPINTERVALPROC)(EGLDisplay dpy, EGLint interval); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLTERMINATEPROC)(EGLDisplay dpy); #define EGL_IMPORT \ - EGL_IMPORT_FUNC(PFNEGLGETPROCADDRESSPROC, eglGetProcAddress); \ - EGL_IMPORT_FUNC(PFNEGLSWAPINTERVALPROC, eglSwapInterval); \ - EGL_IMPORT_FUNC(PFNEGLMAKECURRENTPROC, eglMakeCurrent); \ + EGL_IMPORT_FUNC(PFNEGLCHOOSECONFIGPROC, eglChooseConfig); \ EGL_IMPORT_FUNC(PFNEGLCREATECONTEXTPROC, eglCreateContext); \ EGL_IMPORT_FUNC(PFNEGLCREATEWINDOWSURFACEPROC, eglCreateWindowSurface); \ - EGL_IMPORT_FUNC(PFNEGLCHOOSECONFIGPROC, eglChooseConfig); \ - EGL_IMPORT_FUNC(PFNEGLINITIALIZEPROC, eglInitialize); \ - EGL_IMPORT_FUNC(PFNEGLGETERRORPROC, eglGetError); \ EGL_IMPORT_FUNC(PFNEGLGETDISPLAYPROC, eglGetDisplay); \ - EGL_IMPORT_FUNC(PFNEGLTERMINATEPROC, eglTerminate); \ - EGL_IMPORT_FUNC(PFNEGLDESTROYSURFACEPROC, eglDestroySurface); \ + EGL_IMPORT_FUNC(PFNEGLGETERRORPROC, eglGetError); \ + EGL_IMPORT_FUNC(PFNEGLGETPROCADDRESSPROC, eglGetProcAddress); \ EGL_IMPORT_FUNC(PFNEGLDESTROYCONTEXTPROC, eglDestroyContext); \ - EGL_IMPORT_FUNC(PFNEGLSWAPBUFFERSPROC, eglSwapBuffers); + EGL_IMPORT_FUNC(PFNEGLDESTROYSURFACEPROC, eglDestroySurface); \ + EGL_IMPORT_FUNC(PFNEGLINITIALIZEPROC, eglInitialize); \ + EGL_IMPORT_FUNC(PFNEGLMAKECURRENTPROC, eglMakeCurrent); \ + EGL_IMPORT_FUNC(PGNEGLQUERYSTRINGPROC, eglQueryString); \ + EGL_IMPORT_FUNC(PFNEGLSWAPBUFFERSPROC, eglSwapBuffers); \ + EGL_IMPORT_FUNC(PFNEGLSWAPINTERVALPROC, eglSwapInterval); \ + EGL_IMPORT_FUNC(PFNEGLTERMINATEPROC, eglTerminate); #define EGL_IMPORT_FUNC(_proto, _func) _proto _func EGL_IMPORT @@ -100,22 +98,7 @@ EGL_IMPORT # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL # include "glimports.h" - static const EGLint s_contextAttrs[] = - { -# if BGFX_CONFIG_RENDERER_OPENGLES >= 30 - EGL_CONTEXT_MAJOR_VERSION_KHR, 3, -# if BGFX_CONFIG_RENDERER_OPENGLES >= 31 - EGL_CONTEXT_MINOR_VERSION_KHR, 1, -# else - // EGL_CONTEXT_MINOR_VERSION_KHR, 0, -# endif // BGFX_CONFIG_RENDERER_OPENGLES >= 31 -# elif BGFX_CONFIG_RENDERER_OPENGLES - EGL_CONTEXT_MAJOR_VERSION_KHR, 2, - // EGL_CONTEXT_MINOR_VERSION_KHR, 0, -# endif // BGFX_CONFIG_RENDERER_ - - EGL_NONE - }; + static EGLint s_contextAttrs[16]; struct SwapChainGL { @@ -178,85 +161,154 @@ EGL_IMPORT m_eglLibrary = eglOpen(); - BX_UNUSED(_width, _height); - EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY; - EGLNativeWindowType nwh = (EGLNativeWindowType)NULL; + if (NULL == g_platformData.context) + { + BX_UNUSED(_width, _height); + EGLNativeDisplayType ndt = (EGLNativeDisplayType)g_platformData.ndt; + EGLNativeWindowType nwh = (EGLNativeWindowType )g_platformData.nwh; + # if BX_PLATFORM_WINDOWS - ndt = GetDC(g_bgfxHwnd); - nwh = g_bgfxHwnd; -# elif BX_PLATFORM_LINUX - ndt = (EGLNativeDisplayType)g_bgfxX11Display; - nwh = (EGLNativeWindowType)g_bgfxX11Window; -# endif // BX_PLATFORM_ - m_display = eglGetDisplay(ndt); - BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display); + if (NULL == g_platformData.ndt) + { + ndt = GetDC( (HWND)g_platformData.nwh); + } +# endif // BX_PLATFORM_WINDOWS - EGLint major = 0; - EGLint minor = 0; - EGLBoolean success = eglInitialize(m_display, &major, &minor); - BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor); + m_display = eglGetDisplay(ndt); + BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display); - EGLint attrs[] = - { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGLint major = 0; + EGLint minor = 0; + EGLBoolean success = eglInitialize(m_display, &major, &minor); + BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor); + + BX_TRACE("EGL info:"); + const char* clientApis = eglQueryString(m_display, EGL_CLIENT_APIS); + BX_TRACE(" APIs: %s", clientApis); BX_UNUSED(clientApis); + + const char* vendor = eglQueryString(m_display, EGL_VENDOR); + BX_TRACE(" Vendor: %s", vendor); BX_UNUSED(vendor); + + const char* version = eglQueryString(m_display, EGL_VERSION); + BX_TRACE("Version: %s", version); BX_UNUSED(version); + + const char* extensions = eglQueryString(m_display, EGL_EXTENSIONS); + BX_TRACE("Supported EGL extensions:"); + dumpExtensions(extensions); + + EGLint attrs[] = + { + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, # if BX_PLATFORM_ANDROID - EGL_DEPTH_SIZE, 16, + EGL_DEPTH_SIZE, 16, # else - EGL_DEPTH_SIZE, 24, + EGL_DEPTH_SIZE, 24, # endif // BX_PLATFORM_ - EGL_STENCIL_SIZE, 8, + EGL_STENCIL_SIZE, 8, - EGL_NONE - }; + EGL_NONE + }; - EGLint numConfig = 0; - success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig); - BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig"); + EGLint numConfig = 0; + success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig); + BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig"); # if BX_PLATFORM_ANDROID - EGLint format; - eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format); - nwh = g_bgfxAndroidWindow; + + EGLint format; + eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format); + ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format); + # elif BX_PLATFORM_RPI - DISPMANX_DISPLAY_HANDLE_T dispmanDisplay = vc_dispmanx_display_open(0); - DISPMANX_UPDATE_HANDLE_T dispmanUpdate = vc_dispmanx_update_start(0); - - VC_RECT_T dstRect = { 0, 0, _width, _height }; - VC_RECT_T srcRect = { 0, 0, _width << 16, _height << 16 }; - - DISPMANX_ELEMENT_HANDLE_T dispmanElement = vc_dispmanx_element_add(dispmanUpdate - , dispmanDisplay - , 0 - , &dstRect - , 0 - , &srcRect - , DISPMANX_PROTECTION_NONE - , NULL - , NULL - , DISPMANX_NO_ROTATE - ); - - s_dispmanWindow.element = dispmanElement; - s_dispmanWindow.width = _width; - s_dispmanWindow.height = _height; - nwh = &s_dispmanWindow; - - vc_dispmanx_update_submit_sync(dispmanUpdate); + DISPMANX_DISPLAY_HANDLE_T dispmanDisplay = vc_dispmanx_display_open(0); + DISPMANX_UPDATE_HANDLE_T dispmanUpdate = vc_dispmanx_update_start(0); + + VC_RECT_T dstRect = { 0, 0, _width, _height }; + VC_RECT_T srcRect = { 0, 0, _width << 16, _height << 16 }; + + DISPMANX_ELEMENT_HANDLE_T dispmanElement = vc_dispmanx_element_add(dispmanUpdate + , dispmanDisplay + , 0 + , &dstRect + , 0 + , &srcRect + , DISPMANX_PROTECTION_NONE + , NULL + , NULL + , DISPMANX_NO_ROTATE + ); + + s_dispmanWindow.element = dispmanElement; + s_dispmanWindow.width = _width; + s_dispmanWindow.height = _height; + nwh = &s_dispmanWindow; + + vc_dispmanx_update_submit_sync(dispmanUpdate); # endif // BX_PLATFORM_ANDROID - m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL); - BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface."); + m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL); + BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface."); + + const bool hasEglKhrCreateContext = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context"); + const bool hasEglKhrNoError = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context_no_error"); + + for (uint32_t ii = 0; ii < 2; ++ii) + { + bx::StaticMemoryBlockWriter writer(s_contextAttrs, sizeof(s_contextAttrs) ); + + EGLint flags = 0; + + if (hasEglKhrCreateContext) + { + bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR) ); + bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES / 10) ); + + bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR) ); + bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES % 10) ); + + flags |= BGFX_CONFIG_DEBUG && hasEglKhrNoError ? 0 + | EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR + : 0 + ; + + if (0 == ii) + { + flags |= BGFX_CONFIG_DEBUG ? 0 + | EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR +// | EGL_OPENGL_ES3_BIT_KHR + : 0 + ; + + bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR) ); + bx::write(&writer, flags); + } + } + else + { + bx::write(&writer, EGLint(EGL_CONTEXT_CLIENT_VERSION) ); + bx::write(&writer, 2); + } + + bx::write(&writer, EGLint(EGL_NONE) ); + + m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs); + if (NULL != m_context) + { + break; + } + + BX_TRACE("Failed to create EGL context with EGL_CONTEXT_FLAGS_KHR (%08x).", flags); + } - m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs); - BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context."); + BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context."); - success = eglMakeCurrent(m_display, m_surface, m_surface, m_context); - BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context."); - m_current = NULL; + success = eglMakeCurrent(m_display, m_surface, m_surface, m_context); + BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context."); + m_current = NULL; - eglSwapInterval(m_display, 0); + eglSwapInterval(m_display, 0); + } # if BX_PLATFORM_EMSCRIPTEN emscripten_set_canvas_size(_width, _height); @@ -267,11 +319,14 @@ EGL_IMPORT void GlContext::destroy() { - eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglDestroyContext(m_display, m_context); - eglDestroySurface(m_display, m_surface); - eglTerminate(m_display); - m_context = NULL; + if (NULL != m_display) + { + eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(m_display, m_context); + eglDestroySurface(m_display, m_surface); + eglTerminate(m_display); + m_context = NULL; + } eglClose(m_eglLibrary); @@ -283,14 +338,21 @@ EGL_IMPORT void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) { BX_UNUSED(_width, _height); + # if BX_PLATFORM_ANDROID - EGLint format; - eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format); - ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format); + if (NULL != m_display) + { + EGLint format; + eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format); + ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format); + } # endif // BX_PLATFORM_ANDROID - bool vsync = !!(_flags&BGFX_RESET_VSYNC); - eglSwapInterval(m_display, vsync ? 1 : 0); + if (NULL != m_display) + { + bool vsync = !!(_flags&BGFX_RESET_VSYNC); + eglSwapInterval(m_display, vsync ? 1 : 0); + } } bool GlContext::isSwapChainSupported() @@ -317,7 +379,10 @@ EGL_IMPORT if (NULL == _swapChain) { - eglSwapBuffers(m_display, m_surface); + if (NULL != m_display) + { + eglSwapBuffers(m_display, m_surface); + } } else { @@ -333,7 +398,10 @@ EGL_IMPORT if (NULL == _swapChain) { - eglMakeCurrent(m_display, m_surface, m_surface, m_context); + if (NULL != m_display) + { + eglMakeCurrent(m_display, m_surface, m_surface, m_context); + } } else { diff --git a/3rdparty/bgfx/src/glcontext_egl.h b/3rdparty/bgfx/src/glcontext_egl.h index 35a30c63f71..c8eb2d5d07c 100644 --- a/3rdparty/bgfx/src/glcontext_egl.h +++ b/3rdparty/bgfx/src/glcontext_egl.h @@ -9,6 +9,7 @@ #if BGFX_USE_EGL #include <EGL/egl.h> +#include <EGL/eglext.h> namespace bgfx { namespace gl { diff --git a/3rdparty/bgfx/src/glcontext_glx.cpp b/3rdparty/bgfx/src/glcontext_glx.cpp index 17ee8e825e7..270e14dbe07 100644 --- a/3rdparty/bgfx/src/glcontext_glx.cpp +++ b/3rdparty/bgfx/src/glcontext_glx.cpp @@ -29,23 +29,23 @@ namespace bgfx { namespace gl SwapChainGL(::Window _window, XVisualInfo* _visualInfo, GLXContext _context) : m_window(_window) { - m_context = glXCreateContext( (::Display*)g_bgfxX11Display, _visualInfo, _context, GL_TRUE); + m_context = glXCreateContext( (::Display*)g_platformData.ndt, _visualInfo, _context, GL_TRUE); } ~SwapChainGL() { - glXMakeCurrent( (::Display*)g_bgfxX11Display, 0, 0); - glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); + glXMakeCurrent( (::Display*)g_platformData.ndt, 0, 0); + glXDestroyContext( (::Display*)g_platformData.ndt, m_context); } void makeCurrent() { - glXMakeCurrent( (::Display*)g_bgfxX11Display, m_window, m_context); + glXMakeCurrent( (::Display*)g_platformData.ndt, m_window, m_context); } void swapBuffers() { - glXSwapBuffers( (::Display*)g_bgfxX11Display, m_window); + glXSwapBuffers( (::Display*)g_platformData.ndt, m_window); } Window m_window; @@ -56,14 +56,14 @@ namespace bgfx { namespace gl { BX_UNUSED(_width, _height); - m_context = (GLXContext)g_bgfxGLX; + m_context = (GLXContext)g_platformData.context; - if (NULL == g_bgfxGLX) + if (NULL == g_platformData.context) { - XLockDisplay( (::Display*)g_bgfxX11Display); + XLockDisplay( (::Display*)g_platformData.ndt); int major, minor; - bool version = glXQueryVersion( (::Display*)g_bgfxX11Display, &major, &minor); + bool version = glXQueryVersion( (::Display*)g_platformData.ndt, &major, &minor); BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version"); BGFX_FATAL( (major == 1 && minor >= 2) || major > 1 , Fatal::UnableToInitialize @@ -72,9 +72,9 @@ namespace bgfx { namespace gl , minor ); - int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display); + int32_t screen = DefaultScreen( (::Display*)g_platformData.ndt); - const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen); + const char* extensions = glXQueryExtensionsString( (::Display*)g_platformData.ndt, screen); BX_TRACE("GLX extensions:"); dumpExtensions(extensions); @@ -96,13 +96,13 @@ namespace bgfx { namespace gl GLXFBConfig bestConfig = NULL; int numConfigs; - GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs); + GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_platformData.ndt, screen, attrsGlx, &numConfigs); BX_TRACE("glX num configs %d", numConfigs); for (int ii = 0; ii < numConfigs; ++ii) { - m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]); + m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_platformData.ndt, configs[ii]); if (NULL != m_visualInfo) { BX_TRACE("---"); @@ -110,7 +110,7 @@ namespace bgfx { namespace gl for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2) { int value; - glXGetFBConfigAttrib( (::Display*)g_bgfxX11Display, configs[ii], attrsGlx[attr], &value); + glXGetFBConfigAttrib( (::Display*)g_platformData.ndt, configs[ii], attrsGlx[attr], &value); BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)" , ii , numConfigs @@ -146,7 +146,7 @@ namespace bgfx { namespace gl BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration."); BX_TRACE("Create GL 2.1 context."); - m_context = glXCreateContext( (::Display*)g_bgfxX11Display, m_visualInfo, 0, GL_TRUE); + m_context = glXCreateContext( (::Display*)g_platformData.ndt, m_visualInfo, 0, GL_TRUE); BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context."); #if BGFX_CONFIG_RENDERER_OPENGL >= 31 @@ -163,11 +163,11 @@ namespace bgfx { namespace gl 0, }; - GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs); + GLXContext context = glXCreateContextAttribsARB( (::Display*)g_platformData.ndt, bestConfig, 0, true, contextAttrs); if (NULL != context) { - glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); + glXDestroyContext( (::Display*)g_platformData.ndt, m_context); m_context = context; } } @@ -175,19 +175,19 @@ namespace bgfx { namespace gl BX_UNUSED(bestConfig); #endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 - XUnlockDisplay( (::Display*)g_bgfxX11Display); + XUnlockDisplay( (::Display*)g_platformData.ndt); } import(); - glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context); + glXMakeCurrent( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh, m_context); m_current = NULL; glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT"); if (NULL != glXSwapIntervalEXT) { BX_TRACE("Using glXSwapIntervalEXT."); - glXSwapIntervalEXT( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, 0); + glXSwapIntervalEXT( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh, 0); } else { @@ -210,15 +210,15 @@ namespace bgfx { namespace gl glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - glXSwapBuffers( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window); + glXSwapBuffers( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh); } void GlContext::destroy() { - glXMakeCurrent( (::Display*)g_bgfxX11Display, 0, 0); - if (NULL == g_bgfxGLX) + glXMakeCurrent( (::Display*)g_platformData.ndt, 0, 0); + if (NULL == g_platformData.context) { - glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); + glXDestroyContext( (::Display*)g_platformData.ndt, m_context); XFree(m_visualInfo); } m_context = NULL; @@ -232,7 +232,7 @@ namespace bgfx { namespace gl if (NULL != glXSwapIntervalEXT) { - glXSwapIntervalEXT( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, interval); + glXSwapIntervalEXT( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh, interval); } else if (NULL != glXSwapIntervalMESA) { @@ -265,7 +265,7 @@ namespace bgfx { namespace gl if (NULL == _swapChain) { - glXSwapBuffers( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window); + glXSwapBuffers( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh); } else { @@ -281,7 +281,7 @@ namespace bgfx { namespace gl if (NULL == _swapChain) { - glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context); + glXMakeCurrent( (::Display*)g_platformData.ndt, (::Window)g_platformData.nwh, m_context); } else { diff --git a/3rdparty/bgfx/src/glcontext_nsgl.mm b/3rdparty/bgfx/src/glcontext_nsgl.mm index 236809223f7..d39f7da3bb0 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.mm +++ b/3rdparty/bgfx/src/glcontext_nsgl.mm @@ -65,10 +65,10 @@ namespace bgfx { namespace gl BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!"); const AutoreleasePoolHolder pool; - NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow; - m_context = g_bgfxNSGL; + NSWindow* nsWindow = (NSWindow*)g_platformData.nwh; + m_context = g_platformData.context; - if (NULL == g_bgfxNSGL) + if (NULL == g_platformData.context) { #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) NSOpenGLPixelFormatAttribute profile = @@ -120,7 +120,7 @@ namespace bgfx { namespace gl void GlContext::destroy() { - if (NULL == g_bgfxNSGL) + if (NULL == g_platformData.context) { NSOpenGLView* glView = (NSOpenGLView*)m_view; [glView release]; diff --git a/3rdparty/bgfx/src/glcontext_wgl.cpp b/3rdparty/bgfx/src/glcontext_wgl.cpp index 19ca6d99f72..ef7f570df8b 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.cpp +++ b/3rdparty/bgfx/src/glcontext_wgl.cpp @@ -109,14 +109,14 @@ namespace bgfx { namespace gl wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)bx::dlsym(m_opengl32dll, "wglGetProcAddress"); BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress."); - // If g_bgfxHwnd is NULL, the assumption is that GL context was created + // If g_platformHooks.nwh is NULL, the assumption is that GL context was created // by user (for example, using SDL, GLFW, etc.) - BX_WARN(NULL != g_bgfxHwnd - , "bgfx::winSetHwnd with valid window is not called. This might " + BX_WARN(NULL != g_platformData.nwh + , "bgfx::setPlatform with valid window is not called. This might " "be intentional when GL context is created by the user." ); - if (NULL != g_bgfxHwnd) + if (NULL != g_platformData.nwh) { wglMakeCurrent = (PFNWGLMAKECURRENTPROC)bx::dlsym(m_opengl32dll, "wglMakeCurrent"); BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent."); @@ -127,7 +127,7 @@ namespace bgfx { namespace gl wglDeleteContext = (PFNWGLDELETECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglDeleteContext"); BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext."); - m_hdc = GetDC(g_bgfxHwnd); + m_hdc = GetDC( (HWND)g_platformData.nwh); BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!"); // Dummy window to peek into WGL functionality. @@ -188,7 +188,7 @@ namespace bgfx { namespace gl { result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &m_pixelFormat, &numFormats); if (0 == result - || 0 == numFormats) + || 0 == numFormats) { attrs[3] >>= 1; attrs[1] = attrs[3] == 0 ? 0 : 1; @@ -212,7 +212,7 @@ namespace bgfx { namespace gl ); result = SetPixelFormat(m_hdc, m_pixelFormat, &m_pfd); - // When window is created by SDL and SDL_WINDOW_OPENGL is set SetPixelFormat + // When window is created by SDL and SDL_WINDOW_OPENGL is set, SetPixelFormat // will fail. Just warn and continue. In case it failed for some other reason // create context will fail and it will error out there. BX_WARN(result, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() ); @@ -272,14 +272,14 @@ namespace bgfx { namespace gl void GlContext::destroy() { - if (NULL != g_bgfxHwnd) + if (NULL != g_platformData.nwh) { wglMakeCurrent(NULL, NULL); wglDeleteContext(m_context); m_context = NULL; - ReleaseDC(g_bgfxHwnd, m_hdc); + ReleaseDC( (HWND)g_platformData.nwh, m_hdc); m_hdc = NULL; } @@ -324,7 +324,7 @@ namespace bgfx { namespace gl if (NULL == _swapChain) { - if (NULL != g_bgfxHwnd) + if (NULL != g_platformData.nwh) { SwapBuffers(m_hdc); } diff --git a/3rdparty/bgfx/src/glimports.h b/3rdparty/bgfx/src/glimports.h index 6a67f8d8e16..d3cd99af083 100644 --- a/3rdparty/bgfx/src/glimports.h +++ b/3rdparty/bgfx/src/glimports.h @@ -26,6 +26,7 @@ #define GL_IMPORT_ANGLE(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## ANGLE) #define GL_IMPORT_ARB__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## ARB) #define GL_IMPORT_EXT__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## EXT) +#define GL_IMPORT_KHR__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## KHR) #define GL_IMPORT_NV___(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## NV) #define GL_IMPORT_OES__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## OES) #define GL_IMPORT_____x(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## XXXXX) @@ -94,15 +95,19 @@ typedef void (GL_APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint typedef void (GL_APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); typedef void (GL_APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect); typedef void (GL_APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect); typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount); typedef void (GL_APIENTRYP PFNGLDRAWBUFFERPROC) (GLenum mode); typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices); +typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect); typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount); typedef void (GL_APIENTRYP PFNGLENABLEPROC) (GLenum cap); typedef void (GL_APIENTRYP PFNGLENABLEIPROC) (GLenum cap, GLuint index); typedef void (GL_APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); typedef void (GL_APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLFINISHPROC) (); +typedef void (GL_APIENTRYP PFNGLFLUSHPROC) (); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); typedef void (GL_APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); @@ -143,6 +148,8 @@ typedef GLint (GL_APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint progra 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 PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); typedef void (GL_APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); typedef void (GL_APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); @@ -263,15 +270,19 @@ GL_IMPORT______(false, PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVert GL_IMPORT______(true, PFNGLDISPATCHCOMPUTEPROC, glDispatchCompute); GL_IMPORT______(true, PFNGLDISPATCHCOMPUTEINDIRECTPROC, glDispatchComputeIndirect); GL_IMPORT______(false, PFNGLDRAWARRAYSPROC, glDrawArrays); +GL_IMPORT______(true, PFNGLDRAWARRAYSINDIRECTPROC, glDrawArraysIndirect); GL_IMPORT______(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced); GL_IMPORT______(true, PFNGLDRAWBUFFERPROC, glDrawBuffer); GL_IMPORT______(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); GL_IMPORT______(false, PFNGLDRAWELEMENTSPROC, glDrawElements); +GL_IMPORT______(true, PFNGLDRAWELEMENTSINDIRECTPROC, glDrawElementsIndirect); GL_IMPORT______(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstanced); GL_IMPORT______(false, PFNGLENABLEPROC, glEnable); GL_IMPORT______(true, PFNGLENABLEIPROC, glEnablei); GL_IMPORT______(false, PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray); GL_IMPORT______(true, PFNGLENDQUERYPROC, glEndQuery); +GL_IMPORT______(false, PFNGLFINISHPROC, glFinish); +GL_IMPORT______(false, PFNGLFLUSHPROC, glFlush); GL_IMPORT______(true, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer); GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D); GL_IMPORT______(false, PFNGLGENBUFFERSPROC, glGenBuffers); @@ -312,6 +323,8 @@ GL_IMPORT______(false, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformL GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); GL_IMPORT______(false, PFNGLLINKPROGRAMPROC, glLinkProgram); GL_IMPORT______(true, PFNGLMEMORYBARRIERPROC, glMemoryBarrier); +GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); +GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); GL_IMPORT______(true, PFNGLOBJECTLABELPROC, glObjectLabel); GL_IMPORT______(true, PFNGLOBJECTPTRLABELPROC, glObjectPtrLabel); GL_IMPORT______(false, PFNGLPIXELSTOREIPROC, glPixelStorei); @@ -390,6 +403,9 @@ GL_IMPORT_ARB__(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers GL_IMPORT_ARB__(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); +GL_IMPORT_ARB__(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); +GL_IMPORT_ARB__(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); + GL_IMPORT_EXT__(true, PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer); GL_IMPORT_EXT__(true, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers); GL_IMPORT_EXT__(true, PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers); @@ -419,6 +435,11 @@ GL_IMPORT______(true, PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC, glGetTranslat GL_IMPORT_ANGLE(true, PFNGLBLITFRAMEBUFFERPROC, glBlitFramebuffer); GL_IMPORT_ANGLE(true, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC, glRenderbufferStorageMultisample); +GL_IMPORT_KHR__(true, PFNGLDEBUGMESSAGECONTROLPROC, glDebugMessageControl); +GL_IMPORT_KHR__(true, PFNGLDEBUGMESSAGEINSERTPROC, glDebugMessageInsert); +GL_IMPORT_KHR__(true, PFNGLDEBUGMESSAGECALLBACKPROC, glDebugMessageCallback); +GL_IMPORT_KHR__(true, PFNGLGETDEBUGMESSAGELOGPROC, glGetDebugMessageLog); + # if BGFX_CONFIG_RENDERER_OPENGLES < 30 GL_IMPORT_OES__(true, PFNGLTEXIMAGE3DPROC, glTexImage3D); GL_IMPORT_OES__(true, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D); @@ -433,6 +454,11 @@ GL_IMPORT_EXT__(true, PFNGLPUSHGROUPMARKEREXTPROC, glPushGroupMa GL_IMPORT_EXT__(true, PFNGLPOPGROUPMARKEREXTPROC, glPopGroupMarker); GL_IMPORT_EXT__(true, PFNGLOBJECTLABELPROC, glObjectLabel); +GL_IMPORT_EXT__(true, PFNGLDRAWARRAYSINDIRECTPROC, glDrawArraysIndirect); +GL_IMPORT_EXT__(true, PFNGLDRAWELEMENTSINDIRECTPROC, glDrawElementsIndirect); +GL_IMPORT_EXT__(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); +GL_IMPORT_EXT__(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); + GL_IMPORT_OES__(true, PFNGLGETPROGRAMBINARYPROC, glGetProgramBinary); GL_IMPORT_OES__(true, PFNGLPROGRAMBINARYPROC, glProgramBinary); @@ -481,7 +507,7 @@ GL_IMPORT_NV___(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObj GL_IMPORT (true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer, glDiscardFramebufferEXT); -#elif !BGFX_USE_GL_DYNAMIC_LIB +# elif !BGFX_USE_GL_DYNAMIC_LIB GL_IMPORT______(true, PFNGLTEXIMAGE3DPROC, glTexImage3D); GL_IMPORT______(true, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D); GL_IMPORT______(true, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D); @@ -541,6 +567,11 @@ GL_IMPORT______(true, PFNGLBEGINQUERYPROC, glBeginQuery) GL_IMPORT______(true, PFNGLENDQUERYPROC, glEndQuery); GL_IMPORT______(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObjectui64v); +GL_IMPORT______(true, PFNGLDRAWARRAYSINDIRECTPROC, glDrawArraysIndirect); +GL_IMPORT______(true, PFNGLDRAWELEMENTSINDIRECTPROC, glDrawElementsIndirect); +GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); +GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); + GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); # endif // BGFX_CONFIG_RENDERER_OPENGLES < 30 @@ -552,6 +583,7 @@ GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateF #undef GL_IMPORT______ #undef GL_IMPORT_ARB__ #undef GL_IMPORT_EXT__ +#undef GL_IMPORT_KHR__ #undef GL_IMPORT_NV___ #undef GL_IMPORT_OES__ #undef GL_IMPORT_____x diff --git a/3rdparty/bgfx/src/image.cpp b/3rdparty/bgfx/src/image.cpp index 37537a11cb3..b9fbeedd8d5 100644 --- a/3rdparty/bgfx/src/image.cpp +++ b/3rdparty/bgfx/src/image.cpp @@ -1251,33 +1251,42 @@ namespace bgfx #define DDS_G32R32F 115 #define DDS_A32B32G32R32F 116 -#define DDS_FORMAT_R32G32B32A32_FLOAT 2 -#define DDS_FORMAT_R32G32B32A32_UINT 3 -#define DDS_FORMAT_R16G16B16A16_FLOAT 10 -#define DDS_FORMAT_R16G16B16A16_UNORM 11 -#define DDS_FORMAT_R16G16B16A16_UINT 12 -#define DDS_FORMAT_R32G32_FLOAT 16 -#define DDS_FORMAT_R32G32_UINT 17 -#define DDS_FORMAT_R10G10B10A2_UNORM 24 -#define DDS_FORMAT_R16G16_FLOAT 34 -#define DDS_FORMAT_R16G16_UNORM 35 -#define DDS_FORMAT_R32_FLOAT 41 -#define DDS_FORMAT_R32_UINT 42 -#define DDS_FORMAT_R8G8_UNORM 49 -#define DDS_FORMAT_R16_FLOAT 54 -#define DDS_FORMAT_R16_UNORM 56 -#define DDS_FORMAT_R8_UNORM 61 -#define DDS_FORMAT_BC1_UNORM 71 -#define DDS_FORMAT_BC2_UNORM 74 -#define DDS_FORMAT_BC3_UNORM 77 -#define DDS_FORMAT_BC4_UNORM 80 -#define DDS_FORMAT_BC5_UNORM 83 -#define DDS_FORMAT_B5G6R5_UNORM 85 -#define DDS_FORMAT_B5G5R5A1_UNORM 86 -#define DDS_FORMAT_B8G8R8A8_UNORM 87 -#define DDS_FORMAT_BC6H_SF16 96 -#define DDS_FORMAT_BC7_UNORM 98 -#define DDS_FORMAT_B4G4R4A4_UNORM 115 +#define DDS_FORMAT_R32G32B32A32_FLOAT 2 +#define DDS_FORMAT_R32G32B32A32_UINT 3 +#define DDS_FORMAT_R16G16B16A16_FLOAT 10 +#define DDS_FORMAT_R16G16B16A16_UNORM 11 +#define DDS_FORMAT_R16G16B16A16_UINT 12 +#define DDS_FORMAT_R32G32_FLOAT 16 +#define DDS_FORMAT_R32G32_UINT 17 +#define DDS_FORMAT_R10G10B10A2_UNORM 24 +#define DDS_FORMAT_R11G11B10_FLOAT 26 +#define DDS_FORMAT_R8G8B8A8_UNORM 28 +#define DDS_FORMAT_R8G8B8A8_UNORM_SRGB 29 +#define DDS_FORMAT_R16G16_FLOAT 34 +#define DDS_FORMAT_R16G16_UNORM 35 +#define DDS_FORMAT_R32_FLOAT 41 +#define DDS_FORMAT_R32_UINT 42 +#define DDS_FORMAT_R8G8_UNORM 49 +#define DDS_FORMAT_R16_FLOAT 54 +#define DDS_FORMAT_R16_UNORM 56 +#define DDS_FORMAT_R8_UNORM 61 +#define DDS_FORMAT_R1_UNORM 66 +#define DDS_FORMAT_BC1_UNORM 71 +#define DDS_FORMAT_BC1_UNORM_SRGB 72 +#define DDS_FORMAT_BC2_UNORM 74 +#define DDS_FORMAT_BC2_UNORM_SRGB 75 +#define DDS_FORMAT_BC3_UNORM 77 +#define DDS_FORMAT_BC3_UNORM_SRGB 78 +#define DDS_FORMAT_BC4_UNORM 80 +#define DDS_FORMAT_BC5_UNORM 83 +#define DDS_FORMAT_B5G6R5_UNORM 85 +#define DDS_FORMAT_B5G5R5A1_UNORM 86 +#define DDS_FORMAT_B8G8R8A8_UNORM 87 +#define DDS_FORMAT_B8G8R8A8_UNORM_SRGB 91 +#define DDS_FORMAT_BC6H_SF16 96 +#define DDS_FORMAT_BC7_UNORM 98 +#define DDS_FORMAT_BC7_UNORM_SRGB 99 +#define DDS_FORMAT_B4G4R4A4_UNORM 115 #define DDSD_CAPS 0x00000001 #define DDSD_HEIGHT 0x00000002 @@ -1318,70 +1327,80 @@ namespace bgfx { uint32_t m_format; TextureFormat::Enum m_textureFormat; + bool m_srgb; }; static TranslateDdsFormat s_translateDdsFourccFormat[] = { - { DDS_DXT1, TextureFormat::BC1 }, - { DDS_DXT2, TextureFormat::BC2 }, - { DDS_DXT3, TextureFormat::BC2 }, - { DDS_DXT4, TextureFormat::BC3 }, - { DDS_DXT5, TextureFormat::BC3 }, - { DDS_ATI1, TextureFormat::BC4 }, - { DDS_BC4U, TextureFormat::BC4 }, - { DDS_ATI2, TextureFormat::BC5 }, - { DDS_BC5U, TextureFormat::BC5 }, - { DDS_A16B16G16R16, TextureFormat::RGBA16 }, - { DDS_A16B16G16R16F, TextureFormat::RGBA16F }, - { DDPF_RGB|DDPF_ALPHAPIXELS, TextureFormat::BGRA8 }, - { DDPF_INDEXED, TextureFormat::R8 }, - { DDPF_LUMINANCE, TextureFormat::R8 }, - { DDPF_ALPHA, TextureFormat::R8 }, - { DDS_R16F, TextureFormat::R16F }, - { DDS_R32F, TextureFormat::R32F }, - { DDS_A8L8, TextureFormat::RG8 }, - { DDS_G16R16, TextureFormat::RG16 }, - { DDS_G16R16F, TextureFormat::RG16F }, - { DDS_G32R32F, TextureFormat::RG32F }, - { DDS_A8R8G8B8, TextureFormat::BGRA8 }, - { DDS_A16B16G16R16, TextureFormat::RGBA16 }, - { DDS_A16B16G16R16F, TextureFormat::RGBA16F }, - { DDS_A32B32G32R32F, TextureFormat::RGBA32F }, - { DDS_R5G6B5, TextureFormat::R5G6B5 }, - { DDS_A4R4G4B4, TextureFormat::RGBA4 }, - { DDS_A1R5G5B5, TextureFormat::RGB5A1 }, - { DDS_A2B10G10R10, TextureFormat::RGB10A2 }, + { DDS_DXT1, TextureFormat::BC1, false }, + { DDS_DXT2, TextureFormat::BC2, false }, + { DDS_DXT3, TextureFormat::BC2, false }, + { DDS_DXT4, TextureFormat::BC3, false }, + { DDS_DXT5, TextureFormat::BC3, false }, + { DDS_ATI1, TextureFormat::BC4, false }, + { DDS_BC4U, TextureFormat::BC4, false }, + { DDS_ATI2, TextureFormat::BC5, false }, + { DDS_BC5U, TextureFormat::BC5, false }, + { DDS_A16B16G16R16, TextureFormat::RGBA16, false }, + { DDS_A16B16G16R16F, TextureFormat::RGBA16F, false }, + { DDPF_RGB|DDPF_ALPHAPIXELS, TextureFormat::BGRA8, false }, + { DDPF_INDEXED, TextureFormat::R8, false }, + { DDPF_LUMINANCE, TextureFormat::R8, false }, + { DDPF_ALPHA, TextureFormat::R8, false }, + { DDS_R16F, TextureFormat::R16F, false }, + { DDS_R32F, TextureFormat::R32F, false }, + { DDS_A8L8, TextureFormat::RG8, false }, + { DDS_G16R16, TextureFormat::RG16, false }, + { DDS_G16R16F, TextureFormat::RG16F, false }, + { DDS_G32R32F, TextureFormat::RG32F, false }, + { DDS_A8R8G8B8, TextureFormat::BGRA8, false }, + { DDS_A16B16G16R16, TextureFormat::RGBA16, false }, + { DDS_A16B16G16R16F, TextureFormat::RGBA16F, false }, + { DDS_A32B32G32R32F, TextureFormat::RGBA32F, false }, + { DDS_R5G6B5, TextureFormat::R5G6B5, false }, + { DDS_A4R4G4B4, TextureFormat::RGBA4, false }, + { DDS_A1R5G5B5, TextureFormat::RGB5A1, false }, + { DDS_A2B10G10R10, TextureFormat::RGB10A2, false }, }; static TranslateDdsFormat s_translateDxgiFormat[] = { - { DDS_FORMAT_BC1_UNORM, TextureFormat::BC1 }, - { DDS_FORMAT_BC2_UNORM, TextureFormat::BC2 }, - { DDS_FORMAT_BC3_UNORM, TextureFormat::BC3 }, - { DDS_FORMAT_BC4_UNORM, TextureFormat::BC4 }, - { DDS_FORMAT_BC5_UNORM, TextureFormat::BC5 }, - { DDS_FORMAT_BC6H_SF16, TextureFormat::BC6H }, - { DDS_FORMAT_BC7_UNORM, TextureFormat::BC7 }, - - { DDS_FORMAT_R8_UNORM, TextureFormat::R8 }, - { DDS_FORMAT_R16_UNORM, TextureFormat::R16 }, - { DDS_FORMAT_R16_FLOAT, TextureFormat::R16F }, - { DDS_FORMAT_R32_UINT, TextureFormat::R32 }, - { DDS_FORMAT_R32_FLOAT, TextureFormat::R32F }, - { DDS_FORMAT_R8G8_UNORM, TextureFormat::RG8 }, - { DDS_FORMAT_R16G16_UNORM, TextureFormat::RG16 }, - { DDS_FORMAT_R16G16_FLOAT, TextureFormat::RG16F }, - { DDS_FORMAT_R32G32_UINT, TextureFormat::RG32 }, - { DDS_FORMAT_R32G32_FLOAT, TextureFormat::RG32F }, - { DDS_FORMAT_B8G8R8A8_UNORM, TextureFormat::BGRA8 }, - { DDS_FORMAT_R16G16B16A16_UNORM, TextureFormat::RGBA16 }, - { DDS_FORMAT_R16G16B16A16_FLOAT, TextureFormat::RGBA16F }, - { DDS_FORMAT_R32G32B32A32_UINT, TextureFormat::RGBA32 }, - { DDS_FORMAT_R32G32B32A32_FLOAT, TextureFormat::RGBA32F }, - { DDS_FORMAT_B5G6R5_UNORM, TextureFormat::R5G6B5 }, - { DDS_FORMAT_B4G4R4A4_UNORM, TextureFormat::RGBA4 }, - { DDS_FORMAT_B5G5R5A1_UNORM, TextureFormat::RGB5A1 }, - { DDS_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2 }, + { DDS_FORMAT_BC1_UNORM, TextureFormat::BC1, false }, + { DDS_FORMAT_BC1_UNORM_SRGB, TextureFormat::BC1, true }, + { DDS_FORMAT_BC2_UNORM, TextureFormat::BC2, false }, + { DDS_FORMAT_BC2_UNORM_SRGB, TextureFormat::BC2, true }, + { DDS_FORMAT_BC3_UNORM, TextureFormat::BC3, false }, + { DDS_FORMAT_BC3_UNORM_SRGB, TextureFormat::BC3, true }, + { DDS_FORMAT_BC4_UNORM, TextureFormat::BC4, false }, + { DDS_FORMAT_BC5_UNORM, TextureFormat::BC5, false }, + { DDS_FORMAT_BC6H_SF16, TextureFormat::BC6H, false }, + { DDS_FORMAT_BC7_UNORM, TextureFormat::BC7, false }, + { DDS_FORMAT_BC7_UNORM_SRGB, TextureFormat::BC7, true }, + + { DDS_FORMAT_R1_UNORM, TextureFormat::R1, false }, + { DDS_FORMAT_R8_UNORM, TextureFormat::R8, false }, + { DDS_FORMAT_R16_UNORM, TextureFormat::R16, false }, + { DDS_FORMAT_R16_FLOAT, TextureFormat::R16F, false }, + { DDS_FORMAT_R32_UINT, TextureFormat::R32, false }, + { DDS_FORMAT_R32_FLOAT, TextureFormat::R32F, false }, + { DDS_FORMAT_R8G8_UNORM, TextureFormat::RG8, false }, + { DDS_FORMAT_R16G16_UNORM, TextureFormat::RG16, false }, + { DDS_FORMAT_R16G16_FLOAT, TextureFormat::RG16F, false }, + { DDS_FORMAT_R32G32_UINT, TextureFormat::RG32, false }, + { DDS_FORMAT_R32G32_FLOAT, TextureFormat::RG32F, false }, + { DDS_FORMAT_B8G8R8A8_UNORM, TextureFormat::BGRA8, false }, + { DDS_FORMAT_B8G8R8A8_UNORM_SRGB, TextureFormat::BGRA8, true }, + { DDS_FORMAT_R8G8B8A8_UNORM, TextureFormat::RGBA8, false }, + { DDS_FORMAT_R8G8B8A8_UNORM_SRGB, TextureFormat::RGBA8, true }, + { DDS_FORMAT_R16G16B16A16_UNORM, TextureFormat::RGBA16, false }, + { DDS_FORMAT_R16G16B16A16_FLOAT, TextureFormat::RGBA16F, false }, + { DDS_FORMAT_R32G32B32A32_UINT, TextureFormat::RGBA32, false }, + { DDS_FORMAT_R32G32B32A32_FLOAT, TextureFormat::RGBA32F, false }, + { DDS_FORMAT_B5G6R5_UNORM, TextureFormat::R5G6B5, false }, + { DDS_FORMAT_B4G4R4A4_UNORM, TextureFormat::RGBA4, false }, + { DDS_FORMAT_B5G5R5A1_UNORM, TextureFormat::RGB5A1, false }, + { DDS_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2, false }, + { DDS_FORMAT_R11G11B10_FLOAT, TextureFormat::R11G11B10F, false }, }; struct TranslateDdsPixelFormat @@ -1496,6 +1515,7 @@ namespace bgfx TextureFormat::Enum format = TextureFormat::Unknown; bool hasAlpha = pixelFlags & DDPF_ALPHAPIXELS; + bool srgb = false; if (dxgiFormat == 0) { @@ -1534,6 +1554,7 @@ namespace bgfx if (s_translateDxgiFormat[ii].m_format == dxgiFormat) { format = s_translateDxgiFormat[ii].m_textureFormat; + srgb = s_translateDxgiFormat[ii].m_srgb; break; } } @@ -1550,6 +1571,7 @@ namespace bgfx _imageContainer.m_hasAlpha = hasAlpha; _imageContainer.m_cubeMap = cubeMap; _imageContainer.m_ktx = false; + _imageContainer.m_srgb = srgb; return TextureFormat::Unknown != format; } @@ -1873,6 +1895,7 @@ namespace bgfx _imageContainer.m_hasAlpha = hasAlpha; _imageContainer.m_cubeMap = numFaces > 1; _imageContainer.m_ktx = false; + _imageContainer.m_srgb = colorSpace > 0; return TextureFormat::Unknown != format; } @@ -1918,6 +1941,7 @@ namespace bgfx _imageContainer.m_hasAlpha = false; _imageContainer.m_cubeMap = tc.m_cubeMap; _imageContainer.m_ktx = false; + _imageContainer.m_srgb = false; return true; } diff --git a/3rdparty/bgfx/src/image.h b/3rdparty/bgfx/src/image.h index ec7105e46cb..ab0efa0cdd7 100644 --- a/3rdparty/bgfx/src/image.h +++ b/3rdparty/bgfx/src/image.h @@ -23,6 +23,7 @@ namespace bgfx bool m_hasAlpha; bool m_cubeMap; bool m_ktx; + bool m_srgb; }; struct ImageMip diff --git a/3rdparty/bgfx/src/ovr.cpp b/3rdparty/bgfx/src/ovr.cpp index 194ba5edfc5..8a00608ae88 100644 --- a/3rdparty/bgfx/src/ovr.cpp +++ b/3rdparty/bgfx/src/ovr.cpp @@ -65,6 +65,7 @@ namespace bgfx break; #endif // BGFX_CONFIG_RENDERER_OPENGL + case ovrRenderAPI_None: default: BX_CHECK(false, "You should not be here!"); break; @@ -117,6 +118,7 @@ namespace bgfx | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive | ovrDistortionCap_NoRestore + | ovrDistortionCap_HqDistortion , eyeFov , m_erd ); @@ -174,6 +176,13 @@ ovrError: m_texture[1].Header.RenderViewport = rect; m_timing = ovrHmd_BeginFrame(m_hmd, 0); +#if OVR_VERSION > OVR_VERSION_042 + m_pose[0] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Left); + m_pose[1] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Right); +#else + m_pose[0] = ovrHmd_GetEyePose(m_hmd, ovrEye_Left); + m_pose[1] = ovrHmd_GetEyePose(m_hmd, ovrEye_Right); +#endif // OVR_VERSION > OVR_VERSION_042 } } diff --git a/3rdparty/bgfx/src/renderdoc.cpp b/3rdparty/bgfx/src/renderdoc.cpp index c6adc5f0c8f..84ae511257e 100644 --- a/3rdparty/bgfx/src/renderdoc.cpp +++ b/3rdparty/bgfx/src/renderdoc.cpp @@ -56,6 +56,7 @@ namespace bgfx } #define RENDERDOC_IMPORT \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_Shutdown); \ RENDERDOC_IMPORT_FUNC(RENDERDOC_SetLogFile); \ RENDERDOC_IMPORT_FUNC(RENDERDOC_GetCapture); \ RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureOptions); \ @@ -67,7 +68,8 @@ namespace bgfx RENDERDOC_IMPORT_FUNC(RENDERDOC_MaskOverlayBits); \ RENDERDOC_IMPORT_FUNC(RENDERDOC_SetFocusToggleKeys); \ RENDERDOC_IMPORT_FUNC(RENDERDOC_SetCaptureKeys); \ - RENDERDOC_IMPORT_FUNC(RENDERDOC_InitRemoteAccess); + RENDERDOC_IMPORT_FUNC(RENDERDOC_InitRemoteAccess); \ + RENDERDOC_IMPORT_FUNC(RENDERDOC_UnloadCrashHandler); #define RENDERDOC_IMPORT_FUNC(_func) p##_func _func RENDERDOC_IMPORT @@ -129,6 +131,7 @@ RENDERDOC_IMPORT { if (NULL != _renderdocdll) { + RENDERDOC_Shutdown(); bx::dlclose(_renderdocdll); } } diff --git a/3rdparty/bgfx/src/renderer.h b/3rdparty/bgfx/src/renderer.h index 738f5988e56..2404172c8f0 100644 --- a/3rdparty/bgfx/src/renderer.h +++ b/3rdparty/bgfx/src/renderer.h @@ -12,12 +12,19 @@ namespace bgfx { struct ViewState { + ViewState() { } ViewState(Frame* _render, bool _hmdEnabled) - : m_alphaRef(0.0f) - , m_invViewCached(UINT16_MAX) - , m_invProjCached(UINT16_MAX) - , m_invViewProjCached(UINT16_MAX) { + reset(_render, _hmdEnabled); + } + + void reset(Frame* _render, bool _hmdEnabled) + { + m_alphaRef = 0.0f; + m_invViewCached = UINT16_MAX; + m_invProjCached = UINT16_MAX; + m_invViewProjCached = UINT16_MAX; + m_view[0] = _render->m_view; m_view[1] = m_viewTmp[1]; diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index 24df2fd71d2..efcf1468a9e 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -8,6 +8,10 @@ #if BGFX_CONFIG_RENDERER_DIRECT3D11 # include "renderer_d3d11.h" +# if !defined(BGFX_D3D11_MAP_CONSTANT_BUFFERS) +# define BGFX_D3D11_MAP_CONSTANT_BUFFERS 0 +# endif + namespace bgfx { namespace d3d11 { static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; @@ -179,59 +183,60 @@ namespace bgfx { namespace d3d11 DXGI_FORMAT m_fmt; DXGI_FORMAT m_fmtSrv; DXGI_FORMAT m_fmtDsv; + DXGI_FORMAT m_fmtSrgb; }; static const TextureFormatInfo s_textureFormat[] = { - { DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN }, // BC1 - { DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN }, // BC2 - { DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN }, // BC3 - { DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_UNKNOWN }, // BC4 - { DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_UNKNOWN }, // BC5 - { DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_UNKNOWN }, // BC6H - { DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_UNKNOWN }, // BC7 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC1 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A1 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC22 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC24 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown - { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN }, // R1 - { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN }, // R8 - { DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN }, // R16 - { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN }, // R16F - { DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN }, // R32 - { DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN }, // R32F - { DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN }, // RG8 - { DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_UNKNOWN }, // RG16 - { DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN }, // RG16F - { DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN }, // RG32 - { DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN }, // RG32F - { DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN }, // BGRA8 - { DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN }, // RGBA8 - { DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_UNKNOWN }, // RGBA16 - { DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN }, // RGBA16F - { DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN }, // RGBA32 - { DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN }, // RGBA32F - { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN }, // R5G6B5 - { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN }, // RGBA4 - { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN }, // RGB5A1 - { DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN }, // RGB10A2 - { DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN }, // R11G11B10F - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // UnknownDepth - { DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM }, // D16 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT }, // D24 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT }, // D24S8 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT }, // D32 - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT }, // D16F - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT }, // D24F - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT }, // D32F - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT }, // D0S8 + { DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC1_UNORM_SRGB }, // BC1 + { DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC2_UNORM_SRGB }, // BC2 + { DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC3_UNORM_SRGB }, // BC3 + { DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC4 + { DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC5 + { DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC6H + { DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC7_UNORM_SRGB }, // BC7 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC1 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A1 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC22 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC24 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown + { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R1 + { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8 + { DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16 + { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16F + { DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R32 + { DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R32F + { DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG8 + { DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16 + { DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16F + { DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32 + { DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32F + { DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB }, // BGRA8 + { DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8 + { DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16 + { DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16F + { DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32 + { DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32F + { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R5G6B5 + { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA4 + { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB5A1 + { DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB10A2 + { DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R11G11B10F + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // UnknownDepth + { DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_UNKNOWN }, // D16 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D24 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D24S8 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D32 + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D16F + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D24F + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D32F + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D0S8 }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); @@ -347,6 +352,13 @@ namespace bgfx { namespace d3d11 static const GUID IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } }; static const GUID IID_IDXGIAdapter = { 0x2411e7e1, 0x12ac, 0x4ccf, { 0xbd, 0x14, 0x97, 0x98, 0xe8, 0x53, 0x4d, 0xc0 } }; static const GUID IID_ID3D11InfoQueue = { 0x6543dbb6, 0x1b48, 0x42f5, { 0xab, 0x82, 0xe9, 0x7e, 0xc7, 0x43, 0x26, 0xf6 } }; + static const GUID IID_IDXGIDeviceRenderDoc = { 0xa7aa6116, 0x9c8d, 0x4bba, { 0x90, 0x83, 0xb4, 0xd8, 0x16, 0xb7, 0x1b, 0x78 } }; + + enum D3D11_FORMAT_SUPPORT2 + { + D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD = 0x40, + D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE = 0x80, + }; static const GUID s_deviceIIDs[] = { @@ -430,21 +442,45 @@ namespace bgfx { namespace d3d11 struct RendererContextD3D11 : public RendererContextI { RendererContextD3D11() - : m_renderdocdll(NULL) + : m_d3d9dll(NULL) + , m_d3d11dll(NULL) + , m_dxgidll(NULL) + , m_renderdocdll(NULL) + , m_driverType(D3D_DRIVER_TYPE_NULL) + , m_featureLevel(D3D_FEATURE_LEVEL(0) ) + , m_adapter(NULL) + , m_factory(NULL) + , m_swapChain(NULL) , m_lost(0) + , m_numWindows(0) + , m_device(NULL) + , m_deviceCtx(NULL) + , m_infoQueue(NULL) , m_backBufferColor(NULL) , m_backBufferDepthStencil(NULL) + , m_currentColor(NULL) + , m_currentDepthStencil(NULL) , m_captureTexture(NULL) , m_captureResolve(NULL) , m_wireframe(false) , m_flags(BGFX_RESET_NONE) , m_maxAnisotropy(1) + , m_currentProgram(NULL) +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + , m_vsScratch(NULL) + , m_fsScratch(NULL) +#else , m_vsChanges(0) , m_fsChanges(0) +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS , m_rtMsaa(false) , m_ovrRtv(NULL) , m_ovrDsv(NULL) { + m_fbh.idx = invalidHandle; + memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); + memset(&m_scd, 0, sizeof(m_scd) ); + memset(&m_windows, 0xff, sizeof(m_windows) ); } ~RendererContextD3D11() @@ -509,116 +545,143 @@ namespace bgfx { namespace d3d11 BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create DXGI factory."); #endif // BX_PLATFORM_WINRT - m_adapter = NULL; - m_driverType = D3D_DRIVER_TYPE_HARDWARE; + m_device = (ID3D11Device*)g_platformData.context; - IDXGIAdapter* adapter; - for (uint32_t ii = 0 - ; DXGI_ERROR_NOT_FOUND != factory->EnumAdapters(ii, &adapter) && ii < BX_COUNTOF(g_caps.gpu) - ; ++ii - ) + if (NULL == m_device) { - DXGI_ADAPTER_DESC desc; - hr = adapter->GetDesc(&desc); - if (SUCCEEDED(hr) ) - { - BX_TRACE("Adapter #%d", ii); + m_adapter = NULL; + m_driverType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId + ? D3D_DRIVER_TYPE_WARP + : D3D_DRIVER_TYPE_HARDWARE + ; - char description[BX_COUNTOF(desc.Description)]; - wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) ); - BX_TRACE("\tDescription: %s", description); - BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x" - , desc.VendorId - , desc.DeviceId - , desc.SubSysId - , desc.Revision - ); - BX_TRACE("\tMemory: %" PRIi64 " (video), %" PRIi64 " (system), %" PRIi64 " (shared)" - , desc.DedicatedVideoMemory - , desc.DedicatedSystemMemory - , desc.SharedSystemMemory - ); + IDXGIAdapter* adapter; + for (uint32_t ii = 0 + ; DXGI_ERROR_NOT_FOUND != factory->EnumAdapters(ii, &adapter) && ii < BX_COUNTOF(g_caps.gpu) + ; ++ii + ) + { + DXGI_ADAPTER_DESC desc; + hr = adapter->GetDesc(&desc); + if (SUCCEEDED(hr) ) + { + BX_TRACE("Adapter #%d", ii); + + char description[BX_COUNTOF(desc.Description)]; + wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) ); + BX_TRACE("\tDescription: %s", description); + BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x" + , desc.VendorId + , desc.DeviceId + , desc.SubSysId + , desc.Revision + ); + BX_TRACE("\tMemory: %" PRIi64 " (video), %" PRIi64 " (system), %" PRIi64 " (shared)" + , desc.DedicatedVideoMemory + , desc.DedicatedSystemMemory + , desc.SharedSystemMemory + ); - g_caps.gpu[ii].vendorId = (uint16_t)desc.VendorId; - g_caps.gpu[ii].deviceId = (uint16_t)desc.DeviceId; - ++g_caps.numGPUs; + g_caps.gpu[ii].vendorId = (uint16_t)desc.VendorId; + g_caps.gpu[ii].deviceId = (uint16_t)desc.DeviceId; + ++g_caps.numGPUs; - if (NULL == m_adapter) - { - if ( (BGFX_PCI_ID_NONE != g_caps.vendorId || 0 != g_caps.deviceId) - && (BGFX_PCI_ID_NONE == g_caps.vendorId || desc.VendorId == g_caps.vendorId) - && ( 0 == g_caps.deviceId || desc.DeviceId == g_caps.deviceId) ) + if (NULL == m_adapter) { - m_adapter = adapter; - m_adapter->AddRef(); - m_driverType = D3D_DRIVER_TYPE_UNKNOWN; - } + if ( (BGFX_PCI_ID_NONE != g_caps.vendorId || 0 != g_caps.deviceId) + && (BGFX_PCI_ID_NONE == g_caps.vendorId || desc.VendorId == g_caps.vendorId) + && ( 0 == g_caps.deviceId || desc.DeviceId == g_caps.deviceId) ) + { + m_adapter = adapter; + m_adapter->AddRef(); + m_driverType = D3D_DRIVER_TYPE_UNKNOWN; + } - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) - && 0 != strstr(description, "PerfHUD") ) - { - m_adapter = adapter; - m_driverType = D3D_DRIVER_TYPE_REFERENCE; + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) + && 0 != strstr(description, "PerfHUD") ) + { + m_adapter = adapter; + m_driverType = D3D_DRIVER_TYPE_REFERENCE; + } } } + + DX_RELEASE(adapter, adapter == m_adapter ? 1 : 0); } + DX_RELEASE(factory, NULL != m_adapter ? 1 : 0); - DX_RELEASE(adapter, adapter == m_adapter ? 1 : 0); - } - DX_RELEASE(factory, NULL != m_adapter ? 1 : 0); + D3D_FEATURE_LEVEL features[] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; - D3D_FEATURE_LEVEL features[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1, - }; + for (;;) + { + uint32_t flags = 0 + | D3D11_CREATE_DEVICE_SINGLETHREADED + | D3D11_CREATE_DEVICE_BGRA_SUPPORT + | (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0) + ; + + hr = E_FAIL; + for (uint32_t ii = 0; ii < 3 && FAILED(hr);) + { + hr = D3D11CreateDevice(m_adapter + , m_driverType + , NULL + , flags + , &features[ii] + , BX_COUNTOF(features)-ii + , D3D11_SDK_VERSION + , &m_device + , &m_featureLevel + , &m_deviceCtx + ); + if (FAILED(hr) + && 0 != (flags & D3D11_CREATE_DEVICE_DEBUG) ) + { + // Try without debug in case D3D11 SDK Layers + // is not present? + flags &= ~D3D11_CREATE_DEVICE_DEBUG; + continue; + } - uint32_t flags = 0 - | D3D11_CREATE_DEVICE_SINGLETHREADED - | D3D11_CREATE_DEVICE_BGRA_SUPPORT - | (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0) - ; + // Enable debug flags. + flags |= (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0); + ++ii; + } + + if (FAILED(hr) + && D3D_DRIVER_TYPE_WARP != m_driverType) + { + // Try with WARP + m_driverType = D3D_DRIVER_TYPE_WARP; + continue; + } - D3D_FEATURE_LEVEL featureLevel; + break; + } + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - hr = E_FAIL; - for (uint32_t ii = 0; ii < 3 && FAILED(hr);) - { - hr = D3D11CreateDevice(m_adapter - , m_driverType - , NULL - , flags - , &features[ii] - , BX_COUNTOF(features)-ii - , D3D11_SDK_VERSION - , &m_device - , &featureLevel - , &m_deviceCtx - ); - if (FAILED(hr) - && 0 != (flags & D3D11_CREATE_DEVICE_DEBUG) ) + if (NULL != m_adapter) { - // Try without debug in case D3D11 SDK Layers - // is not present? - flags &= ~D3D11_CREATE_DEVICE_DEBUG; - continue; + DX_RELEASE(m_adapter, 2); } - - ++ii; } - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - - if (NULL != m_adapter) + else { - DX_RELEASE(m_adapter, 2); + m_device->GetImmediateContext(&m_deviceCtx); + BGFX_FATAL(NULL != m_deviceCtx, Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); } - IDXGIDevice* device = NULL; + IDXGIDevice* device = NULL; + IDXGIAdapter* adapter = NULL; hr = E_FAIL; for (uint32_t ii = 0; ii < BX_COUNTOF(s_deviceIIDs) && FAILED(hr); ++ii) { @@ -654,82 +717,106 @@ BX_PRAGMA_DIAGNOSTIC_POP(); // // This causes assert in debug. When debugger is present refcount // checks are off. - setGraphicsDebuggerPresent(2 != getRefCount(device) ); - DX_RELEASE(device, 2); + IDXGIDevice* renderdoc; + hr = m_device->QueryInterface(IID_IDXGIDeviceRenderDoc, (void**)&renderdoc); + if (SUCCEEDED(hr) ) + { + setGraphicsDebuggerPresent(true); +// DX_RELEASE(renderdoc, 0); + } + else + { + setGraphicsDebuggerPresent(2 != getRefCount(device) ); + DX_RELEASE(device, 2); + } hr = adapter->GetDesc(&m_adapterDesc); BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - g_caps.vendorId = (uint16_t)m_adapterDesc.VendorId; + g_caps.vendorId = 0 == m_adapterDesc.VendorId + ? BGFX_PCI_ID_SOFTWARE_RASTERIZER + : (uint16_t)m_adapterDesc.VendorId + ; g_caps.deviceId = (uint16_t)m_adapterDesc.DeviceId; + if (NULL == g_platformData.backBuffer) + { #if BX_PLATFORM_WINRT - hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - DX_RELEASE(adapter, 2); - - memset(&m_scd, 0, sizeof(m_scd) ); - m_scd.Width = BGFX_DEFAULT_WIDTH; - m_scd.Height = BGFX_DEFAULT_HEIGHT; - m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - m_scd.Stereo = false; - m_scd.SampleDesc.Count = 1; - m_scd.SampleDesc.Quality = 0; - m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - m_scd.BufferCount = 2; - m_scd.Scaling = DXGI_SCALING_NONE; - m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - - hr = m_factory->CreateSwapChainForCoreWindow(m_device - , g_bgfxCoreWindow - , &m_scd - , NULL - , &m_swapChain - ); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); - - DX_CHECK(m_factory->MakeWindowAssociation(g_bgfxHwnd, 0 - | DXGI_MWA_NO_WINDOW_CHANGES - | DXGI_MWA_NO_ALT_ENTER - ) ); + hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); + DX_RELEASE(adapter, 2); + + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.Width = BGFX_DEFAULT_WIDTH; + m_scd.Height = BGFX_DEFAULT_HEIGHT; + m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_scd.Stereo = false; + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + m_scd.BufferCount = 2; + m_scd.Scaling = DXGI_SCALING_NONE; + m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + + hr = m_factory->CreateSwapChainForCoreWindow(m_device + , (::IUnknown*)g_platformData.nwh + , &m_scd + , NULL + , &m_swapChain + ); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); #else - hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - DX_RELEASE(adapter, 2); + hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); + DX_RELEASE(adapter, 2); + + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; + m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; + m_scd.BufferDesc.RefreshRate.Numerator = 60; + m_scd.BufferDesc.RefreshRate.Denominator = 1; + m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + m_scd.BufferCount = 1; + m_scd.OutputWindow = (HWND)g_platformData.nwh; + m_scd.Windowed = true; + + hr = m_factory->CreateSwapChain(m_device + , &m_scd + , &m_swapChain + ); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); - memset(&m_scd, 0, sizeof(m_scd) ); - m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; - m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; - m_scd.BufferDesc.RefreshRate.Numerator = 60; - m_scd.BufferDesc.RefreshRate.Denominator = 1; - m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - m_scd.SampleDesc.Count = 1; - m_scd.SampleDesc.Quality = 0; - m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - m_scd.BufferCount = 1; - m_scd.OutputWindow = g_bgfxHwnd; - m_scd.Windowed = true; - - hr = m_factory->CreateSwapChain(m_device - , &m_scd - , &m_swapChain - ); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain."); + DX_CHECK(m_factory->MakeWindowAssociation((HWND)g_platformData.nwh, 0 + | DXGI_MWA_NO_WINDOW_CHANGES + | DXGI_MWA_NO_ALT_ENTER + )); #endif // BX_PLATFORM_WINRT + } + else + { + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + setBufferSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); + m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; + m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; + } m_numWindows = 1; #if !defined(__MINGW32__) if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { - ID3D11InfoQueue* infoQueue; - hr = m_device->QueryInterface(IID_ID3D11InfoQueue, (void**)&infoQueue); + hr = m_device->QueryInterface(IID_ID3D11InfoQueue, (void**)&m_infoQueue); if (SUCCEEDED(hr) ) { - infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true); - infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); - infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, false); + m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true); + m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, false); + m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, false); D3D11_INFO_QUEUE_FILTER filter; memset(&filter, 0, sizeof(filter) ); @@ -741,9 +828,9 @@ BX_PRAGMA_DIAGNOSTIC_POP(); }; filter.DenyList.NumCategories = BX_COUNTOF(catlist); filter.DenyList.pCategoryList = catlist; - infoQueue->PushStorageFilter(&filter); + m_infoQueue->PushStorageFilter(&filter); - DX_RELEASE(infoQueue, 3); + DX_RELEASE(m_infoQueue, 3); } else { @@ -759,30 +846,125 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_uniformReg.add(handle, getPredefinedUniformName(PredefinedUniform::Enum(ii) ), &m_predefinedUniforms[ii]); } - g_caps.supported |= ( 0 - | BGFX_CAPS_TEXTURE_3D - | BGFX_CAPS_TEXTURE_COMPARE_ALL - | BGFX_CAPS_INSTANCING - | BGFX_CAPS_VERTEX_ATTRIB_HALF - | BGFX_CAPS_FRAGMENT_DEPTH - | BGFX_CAPS_BLEND_INDEPENDENT - | BGFX_CAPS_COMPUTE - | (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0) - | BGFX_CAPS_SWAP_CHAIN - | (m_ovr.isInitialized() ? BGFX_CAPS_HMD : 0) - | BGFX_CAPS_INDEX32 - ); - g_caps.maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; - g_caps.maxFBAttachments = uint8_t(bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + g_caps.supported |= (0 + | BGFX_CAPS_TEXTURE_3D + | BGFX_CAPS_VERTEX_ATTRIB_HALF + | BGFX_CAPS_FRAGMENT_DEPTH + | (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0) + | BGFX_CAPS_SWAP_CHAIN + | (m_ovr.isInitialized() ? BGFX_CAPS_HMD : 0) + | BGFX_CAPS_DRAW_INDIRECT + ); + + if (m_featureLevel <= D3D_FEATURE_LEVEL_9_2) + { + g_caps.maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(D3D_FL9_1_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS)); + } + else if (m_featureLevel == D3D_FEATURE_LEVEL_9_3) + { + g_caps.maxTextureSize = D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION; + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(D3D_FL9_3_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + } + else + { + g_caps.supported |= BGFX_CAPS_TEXTURE_COMPARE_ALL; + g_caps.maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + } + + // 32-bit indices only supported on 9_2+. + if (m_featureLevel >= D3D_FEATURE_LEVEL_9_2) + { + g_caps.supported |= BGFX_CAPS_INDEX32; + } + + // Independent blend only supported on 10_1+. + if (m_featureLevel >= D3D_FEATURE_LEVEL_10_1) + { + g_caps.supported |= BGFX_CAPS_BLEND_INDEPENDENT; + } + + // Compute support is optional on 10_0 and 10_1 targets. + if (m_featureLevel == D3D_FEATURE_LEVEL_10_0 + || m_featureLevel == D3D_FEATURE_LEVEL_10_1) + { + struct D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS + { + BOOL ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x; + }; + + D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS data; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &data, sizeof(data) ); + if (SUCCEEDED(hr) + && data.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x) + { + g_caps.supported |= BGFX_CAPS_COMPUTE; + } + } + else if (m_featureLevel >= D3D_FEATURE_LEVEL_11_0) + { + g_caps.supported |= BGFX_CAPS_COMPUTE; + } + + // Instancing fully supported on 9_3+, optionally partially supported at lower levels. + if (m_featureLevel >= D3D_FEATURE_LEVEL_9_3) + { + g_caps.supported |= BGFX_CAPS_INSTANCING; + } + else + { + struct D3D11_FEATURE_DATA_D3D9_SIMPLE_INSTANCING_SUPPORT + { + BOOL SimpleInstancingSupported; + }; + + D3D11_FEATURE_DATA_D3D9_SIMPLE_INSTANCING_SUPPORT data; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE(11) /*D3D11_FEATURE_D3D9_SIMPLE_INSTANCING_SUPPORT*/, &data, sizeof(data) ); + if (SUCCEEDED(hr) + && data.SimpleInstancingSupported) + { + g_caps.supported |= BGFX_CAPS_INSTANCING; + } + } + + // shadow compare is optional on 9_1 through 9_3 targets + if (m_featureLevel <= D3D_FEATURE_LEVEL_9_3) + { + struct D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT + { + BOOL SupportsDepthAsTextureWithLessEqualComparisonFilter; + }; + + D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT data; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE(9) /*D3D11_FEATURE_D3D9_SHADOW_SUPPORT*/, &data, sizeof(data) ); + if (SUCCEEDED(hr) + && data.SupportsDepthAsTextureWithLessEqualComparisonFilter) + { + g_caps.supported |= BGFX_CAPS_TEXTURE_COMPARE_LEQUAL; + } + } for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { uint8_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; - if (DXGI_FORMAT_UNKNOWN != s_textureFormat[ii].m_fmt) + const DXGI_FORMAT fmt = isDepth(TextureFormat::Enum(ii) ) + ? s_textureFormat[ii].m_fmtDsv + : s_textureFormat[ii].m_fmt + ; + const DXGI_FORMAT fmtSrgb = s_textureFormat[ii].m_fmtSrgb; + + if (DXGI_FORMAT_UNKNOWN != fmt) { + struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + { + DXGI_FORMAT InFormat; + UINT OutFormatSupport; + }; + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 - data.InFormat = s_textureFormat[ii].m_fmt; + data.InFormat = fmt; hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) ) { @@ -803,11 +985,73 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_SHADER_LOAD + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_RENDER_TARGET + | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; } else { BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); } + + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) ) + { + // clear image flag for additional testing + support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE; + + data.InFormat = s_textureFormat[ii].m_fmt; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) ); + if (SUCCEEDED(hr) ) + { + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD + | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + } + } + + if (DXGI_FORMAT_UNKNOWN != fmtSrgb) + { + struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + { + DXGI_FORMAT InFormat; + UINT OutFormatSupport; + }; + + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 + data.InFormat = fmtSrgb; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); + if (SUCCEEDED(hr) ) + { + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE2D + | D3D11_FORMAT_SUPPORT_TEXTURE3D + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + else + { + BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + } } g_caps.formats[ii] = support; @@ -821,6 +1065,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } +#if !defined(__MINGW32__) + if (BX_ENABLED(BGFX_CONFIG_DEBUG) + && NULL != m_infoQueue) + { + m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); + } +#endif // !defined(__MINGW32__) + updateMsaa(); postReset(); } @@ -856,8 +1108,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_deviceCtx, 0); - DX_RELEASE(m_device, 0); DX_RELEASE(m_factory, 0); + DX_RELEASE(m_device, 0); unloadRenderDoc(m_renderdocdll); @@ -878,7 +1130,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); return BGFX_RENDERER_DIRECT3D11_NAME; } - void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) BX_OVERRIDE + void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags); } @@ -899,7 +1151,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { } - void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint8_t _flags) BX_OVERRIDE + void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) BX_OVERRIDE { m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); } @@ -909,7 +1161,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_vertexBuffers[_handle.idx].destroy(); } - void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t _flags) BX_OVERRIDE + void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_size, NULL, _flags); } @@ -924,7 +1176,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_indexBuffers[_handle.idx].destroy(); } - void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint8_t _flags) BX_OVERRIDE + void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) BX_OVERRIDE { VertexDeclHandle decl = BGFX_INVALID_HANDLE; m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); @@ -1061,6 +1313,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void saveScreenShot(const char* _filePath) BX_OVERRIDE { + BX_WARN(NULL != m_swapChain, "Unable to capture screenshot %s.", _filePath); + if (NULL == m_swapChain) + { + return; + } + ID3D11Texture2D* backBuffer; DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&backBuffer)); @@ -1202,6 +1460,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); float proj[16]; bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f); + prepareShaderConstants(); + PredefinedUniform& predefined = program.m_predefined[0]; uint8_t flags = predefined.m_type; setShaderUniform(flags, predefined.m_loc, proj, 4); @@ -1230,8 +1490,17 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { ovrPreReset(); - DX_RELEASE(m_backBufferDepthStencil, 0); - DX_RELEASE(m_backBufferColor, 0); + m_gpuTimer.preReset(); + + if (NULL == g_platformData.backBufferDS) + { + DX_RELEASE(m_backBufferDepthStencil, 0); + } + + if (NULL != m_swapChain) + { + DX_RELEASE(m_backBufferColor, 0); + } for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) { @@ -1245,11 +1514,27 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void postReset() { - ID3D11Texture2D* color; - DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&color)); + if (NULL != m_swapChain) + { + ID3D11Texture2D* color; + DX_CHECK(m_swapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&color)); + + D3D11_RENDER_TARGET_VIEW_DESC desc; + desc.ViewDimension = (m_flags & BGFX_RESET_MSAA_MASK) + ? D3D11_RTV_DIMENSION_TEXTURE2DMS + : D3D11_RTV_DIMENSION_TEXTURE2D + ; + desc.Texture2D.MipSlice = 0; + desc.Format = (m_flags & BGFX_RESET_SRGB_BACKBUFFER) + ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_R8G8B8A8_UNORM + ; - DX_CHECK(m_device->CreateRenderTargetView(color, NULL, &m_backBufferColor) ); - DX_RELEASE(color, 0); + DX_CHECK(m_device->CreateRenderTargetView(color, &desc, &m_backBufferColor) ); + DX_RELEASE(color, 0); + } + + m_gpuTimer.postReset(); ovrPostReset(); @@ -1381,10 +1666,19 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void updateResolution(const Resolution& _resolution) { bool recenter = !!(_resolution.m_flags & BGFX_RESET_HMD_RECENTER); - m_maxAnisotropy = !!(_resolution.m_flags & BGFX_RESET_MAXANISOTROPY) - ? D3D11_REQ_MAXANISOTROPY - : 1 + + if (!!(_resolution.m_flags & BGFX_RESET_MAXANISOTROPY) ) + { + m_maxAnisotropy = (m_featureLevel == D3D_FEATURE_LEVEL_9_1) + ? D3D_FL9_1_DEFAULT_MAX_ANISOTROPY + : D3D11_REQ_MAXANISOTROPY ; + } + else + { + m_maxAnisotropy = 1; + } + uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY); if ( getBufferWidth() != _resolution.m_width @@ -1407,38 +1701,47 @@ BX_PRAGMA_DIAGNOSTIC_POP(); preReset(); - if (resize) + if (NULL == m_swapChain) { - DX_CHECK(m_swapChain->ResizeBuffers(2 - , getBufferWidth() - , getBufferHeight() - , getBufferFormat() - , DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH - ) ); + // Updated backbuffer if it changed in PlatformData. + m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; + m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; } else { - updateMsaa(); - m_scd.SampleDesc = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + if (resize) + { + DX_CHECK(m_swapChain->ResizeBuffers(2 + , getBufferWidth() + , getBufferHeight() + , getBufferFormat() + , DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH + )); + } + else + { + updateMsaa(); + m_scd.SampleDesc = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; - DX_RELEASE(m_swapChain, 0); + DX_RELEASE(m_swapChain, 0); #if BX_PLATFORM_WINRT - HRESULT hr; - hr = m_factory->CreateSwapChainForCoreWindow(m_device - , g_bgfxCoreWindow - , &m_scd - , NULL - , &m_swapChain - ); + HRESULT hr; + hr = m_factory->CreateSwapChainForCoreWindow(m_device + , (::IUnknown*)g_platformData.nwh + , &m_scd + , NULL + , &m_swapChain + ); #else - HRESULT hr; - hr = m_factory->CreateSwapChain(m_device - , &m_scd - , &m_swapChain - ); + HRESULT hr; + hr = m_factory->CreateSwapChain(m_device + , &m_scd + , &m_swapChain + ); #endif // BX_PLATFORM_WINRT - BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); + BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); + } } postReset(); @@ -1455,12 +1758,16 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { memcpy(&m_fsScratch[_regIndex], _val, _numRegs*16); +#if !BGFX_D3D11_MAP_CONSTANT_BUFFERS m_fsChanges += _numRegs; +#endif } else { memcpy(&m_vsScratch[_regIndex], _val, _numRegs*16); +#if !BGFX_D3D11_MAP_CONSTANT_BUFFERS m_vsChanges += _numRegs; +#endif } } @@ -1474,8 +1781,37 @@ BX_PRAGMA_DIAGNOSTIC_POP(); setShaderUniform(_flags, _regIndex, _val, _numRegs); } + void prepareShaderConstants() + { +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + if (NULL != m_currentProgram->m_vsh->m_buffer) + { + D3D11_MAPPED_SUBRESOURCE mapped; + DX_CHECK(m_deviceCtx->Map(m_currentProgram->m_vsh->m_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); + m_vsScratch = (uint8_t*)mapped.pData; + } + if (NULL != m_currentProgram->m_fsh->m_buffer) + { + D3D11_MAPPED_SUBRESOURCE mapped; + DX_CHECK(m_deviceCtx->Map(m_currentProgram->m_fsh->m_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); + m_fsScratch = (uint8_t*)mapped.pData; + } +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS + } + void commitShaderConstants() { +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + if (NULL != m_vsScratch) + { + m_deviceCtx->Unmap(m_currentProgram->m_vsh->m_buffer, 0); + } + if (NULL != m_fsScratch) + { + m_deviceCtx->Unmap(m_currentProgram->m_fsh->m_buffer, 0); + } + m_vsScratch = m_fsScratch = 0; +#else if (0 < m_vsChanges) { if (NULL != m_currentProgram->m_vsh->m_buffer) @@ -1495,6 +1831,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_fsChanges = 0; } +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS } void setFrameBuffer(FrameBufferHandle _fbh, bool _msaa = true) @@ -1821,7 +2158,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); desc.DepthBias = 0; desc.DepthBiasClamp = 0.0f; desc.SlopeScaledDepthBias = 0.0f; - desc.DepthClipEnable = false; + desc.DepthClipEnable = m_featureLevel <= D3D_FEATURE_LEVEL_9_3; // disabling depth clip is only supported on 10_0+ desc.ScissorEnable = _scissor; desc.MultisampleEnable = !!(_state&BGFX_STATE_MSAA); desc.AntialiasedLineEnable = false; @@ -1910,8 +2247,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void commitTextureStage() { - m_deviceCtx->VSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv); - m_deviceCtx->VSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler); + // vertex texture fetch not supported on 9_1 through 9_3 + if (m_featureLevel > D3D_FEATURE_LEVEL_9_3) + { + m_deviceCtx->VSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv); + m_deviceCtx->VSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler); + } m_deviceCtx->PSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv); m_deviceCtx->PSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler); @@ -1943,7 +2284,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); config.D3D11.pDeviceContext = m_deviceCtx; config.D3D11.pBackBufferRT = m_backBufferColor; config.D3D11.pSwapChain = m_swapChain; - if (m_ovr.postReset(g_bgfxHwnd, &config.Config, !!(m_flags & BGFX_RESET_HMD_DEBUG) ) ) + if (m_ovr.postReset(g_platformData.nwh, &config.Config, !!(m_flags & BGFX_RESET_HMD_DEBUG) ) ) { uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); const Memory* mem = alloc(size); @@ -2233,6 +2574,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); deviceCtx->PSSetShader(fsh->m_pixelShader, NULL, 0); deviceCtx->PSSetConstantBuffers(0, 1, &fsh->m_buffer); +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + D3D11_MAPPED_SUBRESOURCE mapped; + DX_CHECK(deviceCtx->Map(fsh->m_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); + void* fsScratch = mapped.pData; +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; @@ -2242,7 +2589,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); memcpy(mrtClear[ii], _palette[index], 16); } +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + memcpy(fsScratch, mrtClear, sizeof(mrtClear)); +#else deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, mrtClear, 0, 0); +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS } else { @@ -2253,8 +2604,20 @@ BX_PRAGMA_DIAGNOSTIC_POP(); _clear.m_index[2]*1.0f/255.0f, _clear.m_index[3]*1.0f/255.0f, }; + +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + memcpy(fsScratch, rgba, sizeof(rgba)); +#else deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, rgba, 0, 0); +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS + } + +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + if (NULL != fsScratch) + { + deviceCtx->Unmap(fsh->m_buffer, 0); } +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS } else { @@ -2305,31 +2668,33 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } } -#if USE_D3D11_DYNAMIC_LIB void* m_d3d9dll; void* m_d3d11dll; void* m_dxgidll; -#endif // USE_D3D11_DYNAMIC_LIB void* m_renderdocdll; - D3D_DRIVER_TYPE m_driverType; - IDXGIAdapter* m_adapter; + D3D_DRIVER_TYPE m_driverType; + D3D_FEATURE_LEVEL m_featureLevel; + IDXGIAdapter* m_adapter; DXGI_ADAPTER_DESC m_adapterDesc; #if BX_PLATFORM_WINRT - IDXGIFactory2* m_factory; - IDXGISwapChain1* m_swapChain; + IDXGIFactory2* m_factory; + IDXGISwapChain1* m_swapChain; #else - IDXGIFactory* m_factory; - IDXGISwapChain* m_swapChain; -#endif + IDXGIFactory* m_factory; + IDXGISwapChain* m_swapChain; +#endif // BX_PLATFORM_WINRT uint16_t m_lost; uint16_t m_numWindows; FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; - ID3D11Device* m_device; + ID3D11Device* m_device; ID3D11DeviceContext* m_deviceCtx; + ID3D11InfoQueue* m_infoQueue; + TimerQueryD3D11 m_gpuTimer; + ID3D11RenderTargetView* m_backBufferColor; ID3D11DepthStencilView* m_backBufferDepthStencil; ID3D11RenderTargetView* m_currentColor; @@ -2359,6 +2724,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; Matrix4 m_predefinedUniforms[PredefinedUniform::Count]; UniformRegistry m_uniformReg; + ViewState m_viewState; StateCacheT<ID3D11BlendState> m_blendStateCache; StateCacheT<ID3D11DepthStencilState> m_depthStencilStateCache; @@ -2372,11 +2738,15 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ProgramD3D11* m_currentProgram; +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + uint8_t* m_vsScratch; + uint8_t* m_fsScratch; +#else uint8_t m_vsScratch[64<<10]; uint8_t m_fsScratch[64<<10]; - uint32_t m_vsChanges; uint32_t m_fsChanges; +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS FrameBufferHandle m_fbh; bool m_rtMsaa; @@ -2403,14 +2773,35 @@ BX_PRAGMA_DIAGNOSTIC_POP(); s_renderD3D11 = NULL; } - void BufferD3D11::create(uint32_t _size, void* _data, uint8_t _flags, uint16_t _stride, bool _vertex) + struct UavFormat + { + DXGI_FORMAT format[3]; + uint32_t stride; + }; + + static const UavFormat s_uavFormat[] = + { // BGFX_BUFFER_COMPUTE_TYPE_UINT, BGFX_BUFFER_COMPUTE_TYPE_INT, BGFX_BUFFER_COMPUTE_TYPE_FLOAT + { { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, 0 }, // ignored + { { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN }, 1 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x1 + { { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x2 + { { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x4 + { { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_FLOAT }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x1 + { { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x2 + { { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x4 + { { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x1 + { { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x2 + { { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_FLOAT }, 16 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x4 + }; + + void BufferD3D11::create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride, bool _vertex) { m_uav = NULL; m_size = _size; m_flags = _flags; - const bool needUav = 0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE); + const bool needUav = 0 != (_flags & (BGFX_BUFFER_COMPUTE_WRITE|BGFX_BUFFER_DRAW_INDIRECT) ); const bool needSrv = 0 != (_flags & BGFX_BUFFER_COMPUTE_READ); + const bool drawIndirect = 0 != (_flags & BGFX_BUFFER_DRAW_INDIRECT); m_dynamic = NULL == _data && !needUav; D3D11_BUFFER_DESC desc; @@ -2420,17 +2811,50 @@ BX_PRAGMA_DIAGNOSTIC_POP(); | (needUav ? D3D11_BIND_UNORDERED_ACCESS : 0) | (needSrv ? D3D11_BIND_SHADER_RESOURCE : 0) ; - desc.MiscFlags = 0; + desc.MiscFlags = 0 + | (drawIndirect ? D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS : 0) + ; desc.StructureByteStride = 0; - const DXGI_FORMAT indexFormat = 0 == (_flags & BGFX_BUFFER_INDEX32) - ? DXGI_FORMAT_R16_UINT - : DXGI_FORMAT_R32_UINT - ; - const DXGI_FORMAT format = _vertex - ? DXGI_FORMAT_R32G32B32A32_FLOAT - : indexFormat - ; + DXGI_FORMAT format; + uint32_t stride; + + if (drawIndirect) + { + format = DXGI_FORMAT_R32G32B32A32_UINT; + stride = 16; + } + else + { + uint32_t uavFormat = (_flags & BGFX_BUFFER_COMPUTE_FORMAT_MASK) >> BGFX_BUFFER_COMPUTE_FORMAT_SHIFT; + if (0 == uavFormat) + { + if (_vertex) + { + format = DXGI_FORMAT_R32G32B32A32_FLOAT; + stride = 16; + } + else + { + if (0 == (_flags & BGFX_BUFFER_INDEX32) ) + { + format = DXGI_FORMAT_R16_UINT; + stride = 2; + } + else + { + format = DXGI_FORMAT_R32_UINT; + stride = 4; + } + } + } + else + { + const uint32_t uavType = bx::uint32_satsub( (_flags & BGFX_BUFFER_COMPUTE_TYPE_MASK ) >> BGFX_BUFFER_COMPUTE_TYPE_SHIFT, 1); + format = s_uavFormat[uavFormat].format[uavType]; + stride = s_uavFormat[uavFormat].stride; + } + } ID3D11Device* device = s_renderD3D11->m_device; @@ -2443,18 +2867,18 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_CHECK(device->CreateBuffer(&desc , NULL , &m_ptr - )); + ) ); D3D11_UNORDERED_ACCESS_VIEW_DESC uavd; uavd.Format = format; uavd.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; uavd.Buffer.FirstElement = 0; - uavd.Buffer.NumElements = m_size / 16; + uavd.Buffer.NumElements = m_size / stride; uavd.Buffer.Flags = 0; DX_CHECK(device->CreateUnorderedAccessView(m_ptr , &uavd , &m_uav - )); + ) ); } else if (m_dynamic) { @@ -2464,7 +2888,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_CHECK(device->CreateBuffer(&desc , NULL , &m_ptr - )); + ) ); } else { @@ -2479,7 +2903,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_CHECK(device->CreateBuffer(&desc , &srd , &m_ptr - )); + ) ); } if (needSrv) @@ -2488,11 +2912,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); srvd.Format = format; srvd.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; srvd.Buffer.FirstElement = 0; - srvd.Buffer.NumElements = m_size / 16; + srvd.Buffer.NumElements = m_size / stride; DX_CHECK(device->CreateShaderResourceView(m_ptr , &srvd , &m_srv - )); + ) ); } } @@ -2550,7 +2974,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); #endif // 0 } - void VertexBufferD3D11::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint8_t _flags) + void VertexBufferD3D11::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) { m_decl = _declHandle; uint16_t stride = isValid(_declHandle) @@ -2715,9 +3139,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { D3D11_BUFFER_DESC desc; desc.ByteWidth = (size + 0xf) & ~0xf; +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; +#else desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = 0; +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.MiscFlags = 0; desc.StructureByteStride = 0; DX_CHECK(s_renderD3D11->m_device->CreateBuffer(&desc, NULL, &m_buffer) ); @@ -2841,18 +3270,31 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const bool bufferOnly = 0 != (m_flags&BGFX_TEXTURE_RT_BUFFER_ONLY); const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE); const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK); + const bool srgb = 0 != (m_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; const uint32_t msaaQuality = bx::uint32_satsub( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; D3D11_SHADER_RESOURCE_VIEW_DESC srvd; memset(&srvd, 0, sizeof(srvd) ); - srvd.Format = s_textureFormat[m_textureFormat].m_fmtSrv; - DXGI_FORMAT format = s_textureFormat[m_textureFormat].m_fmt; + DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN; if (swizzle) { - format = DXGI_FORMAT_R8G8B8A8_UNORM; - srvd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + format = srgb ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + srvd.Format = format; + } + else if (srgb) + { + format = s_textureFormat[m_textureFormat].m_fmtSrgb; + srvd.Format = format; + BX_WARN(format != DXGI_FORMAT_UNKNOWN, "sRGB not supported for texture format %d", m_textureFormat); + } + + if (format == DXGI_FORMAT_UNKNOWN) + { + // not swizzled and not sRGB, or sRGB unsupported + format = s_textureFormat[m_textureFormat].m_fmt; + srvd.Format = s_textureFormat[m_textureFormat].m_fmtSrv; } switch (m_type) @@ -3172,6 +3614,92 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } } + void TimerQueryD3D11::postReset() + { + ID3D11Device* device = s_renderD3D11->m_device; + + D3D11_QUERY_DESC query; + query.MiscFlags = 0; + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frame); ++ii) + { + Frame& frame = m_frame[ii]; + + query.Query = D3D11_QUERY_TIMESTAMP_DISJOINT; + DX_CHECK(device->CreateQuery(&query, &frame.m_disjoint) ); + + query.Query = D3D11_QUERY_TIMESTAMP; + DX_CHECK(device->CreateQuery(&query, &frame.m_start) ); + DX_CHECK(device->CreateQuery(&query, &frame.m_end) ); + } + + m_elapsed = 0; + m_frequency = 1; + m_control.reset(); + } + + void TimerQueryD3D11::preReset() + { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frame); ++ii) + { + Frame& frame = m_frame[ii]; + DX_RELEASE(frame.m_disjoint, 0); + DX_RELEASE(frame.m_start, 0); + DX_RELEASE(frame.m_end, 0); + } + } + + void TimerQueryD3D11::begin() + { + ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; + + while (0 == m_control.reserve(1) ) + { + get(); + } + + Frame& frame = m_frame[m_control.m_current]; + deviceCtx->Begin(frame.m_disjoint); + deviceCtx->End(frame.m_start); + } + + void TimerQueryD3D11::end() + { + ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; + Frame& frame = m_frame[m_control.m_current]; + deviceCtx->End(frame.m_end); + deviceCtx->End(frame.m_disjoint); + m_control.commit(1); + } + + bool TimerQueryD3D11::get() + { + if (0 != m_control.available() ) + { + ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; + Frame& frame = m_frame[m_control.m_read]; + + uint64_t end; + HRESULT hr = deviceCtx->GetData(frame.m_end, &end, sizeof(end), 0); + if (S_OK == hr) + { + m_control.consume(1); + + D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint; + deviceCtx->GetData(frame.m_disjoint, &disjoint, sizeof(disjoint), 0); + + uint64_t start; + deviceCtx->GetData(frame.m_start, &start, sizeof(start), 0); + + m_frequency = disjoint.Frequency; + m_elapsed = end - start; + + return true; + } + } + + return false; + } + void RendererContextD3D11::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit"); @@ -3183,6 +3711,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); int64_t elapsed = -bx::getHPCounter(); int64_t captureElapsed = 0; + if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) + { + m_gpuTimer.begin(); + } + if (0 < _render->m_iboffset) { TransientIndexBuffer* ib = _render->m_transientIb; @@ -3205,7 +3738,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug(); _render->m_hmdEnabled = hmdEnabled; - ViewState viewState(_render, hmdEnabled); + ViewState& viewState = m_viewState; + viewState.reset(_render, hmdEnabled); bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); bool scissorEnabled = false; @@ -3229,11 +3763,16 @@ BX_PRAGMA_DIAGNOSTIC_POP(); uint32_t statsNumPrimsSubmitted[BX_COUNTOF(s_primInfo)] = {}; uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {}; uint32_t statsNumInstances[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumDrawIndirect[BX_COUNTOF(s_primInfo)] = {}; uint32_t statsNumIndices = 0; uint32_t statsKeyType[2] = {}; if (0 == (_render->m_debug&BGFX_DEBUG_IFH) ) { + // reset the framebuffer to be the backbuffer; depending on the swap effect, + // if we don't do this we'll only see one frame of output and then nothing + setFrameBuffer(fbh); + bool viewRestart = false; uint8_t eye = 0; uint8_t restartState = 0; @@ -3462,7 +4001,27 @@ BX_PRAGMA_DIAGNOSTIC_POP(); deviceCtx->CSSetShaderResources(0, BX_COUNTOF(srv), srv); deviceCtx->CSSetSamplers(0, BX_COUNTOF(sampler), sampler); - deviceCtx->Dispatch(compute.m_numX, compute.m_numY, compute.m_numZ); + if (isValid(compute.m_indirectBuffer) ) + { + const VertexBufferD3D11& vb = m_vertexBuffers[compute.m_indirectBuffer.idx]; + ID3D11Buffer* ptr = vb.m_ptr; + + uint32_t numDrawIndirect = UINT16_MAX == compute.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : compute.m_numIndirect + ; + + uint32_t args = compute.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + deviceCtx->DispatchIndirect(ptr, args); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + } + } + else + { + deviceCtx->Dispatch(compute.m_numX, compute.m_numY, compute.m_numZ); + } continue; } @@ -3640,6 +4199,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { ProgramD3D11& program = m_program[programIdx]; +#if BGFX_D3D11_MAP_CONSTANT_BUFFERS + if (constantsChanged || 0 != program.m_numPredefined) + { + prepareShaderConstants(); + } +#endif // BGFX_D3D11_MAP_CONSTANT_BUFFERS if (constantsChanged) { ConstantBuffer* vcb = program.m_vsh->m_constantBuffer; @@ -3730,13 +4295,13 @@ BX_PRAGMA_DIAGNOSTIC_POP(); } else { - deviceCtx->IASetVertexBuffers(1, 0, NULL, NULL, NULL); + deviceCtx->IASetVertexBuffers(1, 1, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); setInputLayout(vertexDecl, m_program[programIdx], 0); } } else { - deviceCtx->IASetVertexBuffers(0, 0, NULL, NULL, NULL); + deviceCtx->IASetVertexBuffers(0, 1, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); } } @@ -3770,61 +4335,129 @@ BX_PRAGMA_DIAGNOSTIC_POP(); numVertices = vb.m_size/vertexDecl.m_stride; } - uint32_t numIndices = 0; + uint32_t numIndices = 0; uint32_t numPrimsSubmitted = 0; - uint32_t numInstances = 0; - uint32_t numPrimsRendered = 0; + uint32_t numInstances = 0; + uint32_t numPrimsRendered = 0; + uint32_t numDrawIndirect = 0; - if (isValid(draw.m_indexBuffer) ) + if (isValid(draw.m_indirectBuffer) ) { - if (UINT32_MAX == draw.m_numIndices) + const VertexBufferD3D11& vb = m_vertexBuffers[draw.m_indirectBuffer.idx]; + ID3D11Buffer* ptr = vb.m_ptr; + + if (isValid(draw.m_indexBuffer) ) { - const IndexBufferD3D11& ib = m_indexBuffers[draw.m_indexBuffer.idx]; - const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; - numIndices = ib.m_size/indexSize; - numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; - deviceCtx->DrawIndexedInstanced(numIndices - , draw.m_numInstances - , 0 - , draw.m_startVertex - , 0 - ); + uint32_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + deviceCtx->DrawIndexedInstancedIndirect(ptr, args); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + } } - else if (prim.m_min <= draw.m_numIndices) + else { - numIndices = draw.m_numIndices; - numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - - deviceCtx->DrawIndexedInstanced(numIndices - , draw.m_numInstances - , draw.m_startIndex - , draw.m_startVertex - , 0 - ); + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + + uint32_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + deviceCtx->DrawInstancedIndirect(ptr, args); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + } } } else { - numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + if (isValid(draw.m_indexBuffer) ) + { + if (UINT32_MAX == draw.m_numIndices) + { + const IndexBufferD3D11& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; + numIndices = ib.m_size/indexSize; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + if (numInstances > 1) + { + deviceCtx->DrawIndexedInstanced(numIndices + , draw.m_numInstances + , 0 + , draw.m_startVertex + , 0 + ); + } + else + { + deviceCtx->DrawIndexed(numIndices + , 0 + , draw.m_startVertex + ); + } + } + else if (prim.m_min <= draw.m_numIndices) + { + numIndices = draw.m_numIndices; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - deviceCtx->DrawInstanced(numVertices - , draw.m_numInstances - , draw.m_startVertex - , 0 - ); + if (numInstances > 1) + { + deviceCtx->DrawIndexedInstanced(numIndices + , draw.m_numInstances + , draw.m_startIndex + , draw.m_startVertex + , 0 + ); + } + else + { + deviceCtx->DrawIndexed(numIndices + , draw.m_startIndex + , draw.m_startVertex + ); + } + } + } + else + { + numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + if (numInstances > 1) + { + deviceCtx->DrawInstanced(numVertices + , draw.m_numInstances + , draw.m_startVertex + , 0 + ); + } + else + { + deviceCtx->Draw(numVertices + , draw.m_startVertex + ); + } + } } statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; statsNumPrimsRendered[primIndex] += numPrimsRendered; statsNumInstances[primIndex] += numInstances; - statsNumIndices += numIndices; + statsNumDrawIndirect[primIndex] += numDrawIndirect; + statsNumIndices += numIndices; } } @@ -3843,6 +4476,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + deviceCtx->Flush(); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); @@ -3867,6 +4505,20 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats"); + static uint32_t maxGpuLatency = 0; + static double maxGpuElapsed = 0.0f; + double elapsedGpuMs = 0.0; + + m_gpuTimer.end(); + + while (m_gpuTimer.get() ) + { + double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); + elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; + maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; + } + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); + TextVideoMem& tvm = m_textVideoMem; static int64_t next = now; @@ -3925,19 +4577,26 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ); double elapsedCpuMs = double(elapsed)*toMs; - tvm.printf(10, pos++, 0x8e, " Submitted: %4d (draw %4d, compute %4d) / CPU %3.4f [ms]" + tvm.printf(10, pos++, 0x8e, " Submitted: %4d (draw %4d, compute %4d) / CPU %3.4f [ms] %c GPU %3.4f [ms] (latency %d)" , _render->m_num , statsKeyType[0] , statsKeyType[1] , elapsedCpuMs + , elapsedCpuMs > maxGpuElapsed ? '>' : '<' + , maxGpuElapsed + , maxGpuLatency ); + maxGpuLatency = 0; + maxGpuElapsed = 0.0; + for (uint32_t ii = 0; ii < BX_COUNTOF(s_primName); ++ii) { - tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d" + tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d, indirect %7d" , s_primName[ii] , statsNumPrimsRendered[ii] , statsNumInstances[ii] , statsNumPrimsSubmitted[ii] + , statsNumDrawIndirect[ii] ); } diff --git a/3rdparty/bgfx/src/renderer_d3d11.h b/3rdparty/bgfx/src/renderer_d3d11.h index 22bf6a0ddce..2593fbb85c9 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.h +++ b/3rdparty/bgfx/src/renderer_d3d11.h @@ -19,10 +19,10 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas"); BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition #define D3D11_NO_HELPERS #if BX_PLATFORM_WINRT -#include <d3d11_2.h> +# include <d3d11_2.h> #else -#include <d3d11.h> -#endif +# include <d3d11.h> +#endif // BX_PLATFORM_WINRT BX_PRAGMA_DIAGNOSTIC_POP() #include "renderer.h" @@ -75,21 +75,8 @@ BX_PRAGMA_DIAGNOSTIC_POP() # define D3D11_REQ_MAXANISOTROPY 16 # endif // D3D11_REQ_MAXANISOTROPY -# ifndef D3D11_FEATURE_DATA_FORMAT_SUPPORT -typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT -{ - DXGI_FORMAT InFormat; - UINT OutFormatSupport; -} D3D11_FEATURE_DATA_FORMAT_SUPPORT; -# endif // D3D11_FEATURE_DATA_FORMAT_SUPPORT +typedef void ID3D11InfoQueue; -# ifndef D3D11_FEATURE_DATA_FORMAT_SUPPORT2 -typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT2 -{ - DXGI_FORMAT InFormat; - UINT OutFormatSupport2; -} D3D11_FEATURE_DATA_FORMAT_SUPPORT2; -# endif // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 #endif // __MINGW32__ namespace bgfx { namespace d3d11 @@ -105,7 +92,7 @@ namespace bgfx { namespace d3d11 { } - void create(uint32_t _size, void* _data, uint8_t _flags, uint16_t _stride = 0, bool _vertex = false); + void create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride = 0, bool _vertex = false); void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false); void destroy() @@ -124,7 +111,7 @@ namespace bgfx { namespace d3d11 ID3D11ShaderResourceView* m_srv; ID3D11UnorderedAccessView* m_uav; uint32_t m_size; - uint8_t m_flags; + uint16_t m_flags; bool m_dynamic; }; @@ -137,7 +124,7 @@ namespace bgfx { namespace d3d11 { } - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint8_t _flags); + void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags); VertexDeclHandle m_decl; }; @@ -310,6 +297,33 @@ namespace bgfx { namespace d3d11 TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; }; + struct TimerQueryD3D11 + { + TimerQueryD3D11() + : m_control(BX_COUNTOF(m_frame) ) + { + } + + void postReset(); + void preReset(); + void begin(); + void end(); + bool get(); + + struct Frame + { + ID3D11Query* m_disjoint; + ID3D11Query* m_start; + ID3D11Query* m_end; + }; + + uint64_t m_elapsed; + uint64_t m_frequency; + + Frame m_frame[4]; + bx::RingBufferControl m_control; + }; + } /* namespace d3d11 */ } // namespace bgfx #endif // BGFX_RENDERER_D3D11_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index faf5f98ac39..0406f33eb2f 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -272,6 +272,8 @@ namespace bgfx { namespace d3d9 RendererContextD3D9() : m_d3d9(NULL) , m_device(NULL) + , m_flushQuery(NULL) + , m_swapChain(NULL) , m_captureTexture(NULL) , m_captureSurface(NULL) , m_captureResolve(NULL) @@ -316,7 +318,7 @@ namespace bgfx { namespace d3d9 m_params.Windowed = true; RECT rect; - GetWindowRect(g_bgfxHwnd, &rect); + GetWindowRect( (HWND)g_platformData.nwh, &rect); m_params.BackBufferWidth = rect.right-rect.left; m_params.BackBufferHeight = rect.bottom-rect.top; @@ -356,8 +358,11 @@ namespace bgfx { namespace d3d9 BGFX_FATAL(m_d3d9, Fatal::UnableToInitialize, "Unable to create Direct3D."); - m_adapter = D3DADAPTER_DEFAULT; - m_deviceType = D3DDEVTYPE_HAL; + m_adapter = D3DADAPTER_DEFAULT; + m_deviceType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId + ? D3DDEVTYPE_REF + : D3DDEVTYPE_HAL + ; uint8_t numGPUs = uint8_t(bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ) ); for (uint32_t ii = 0; ii < numGPUs; ++ii) @@ -402,7 +407,10 @@ namespace bgfx { namespace d3d9 DX_CHECK(m_d3d9->GetAdapterIdentifier(m_adapter, 0, &m_identifier) ); m_amd = m_identifier.VendorId == BGFX_PCI_ID_AMD; m_nvidia = m_identifier.VendorId == BGFX_PCI_ID_NVIDIA; - g_caps.vendorId = (uint16_t)m_identifier.VendorId; + g_caps.vendorId = 0 == m_identifier.VendorId + ? BGFX_PCI_ID_SOFTWARE_RASTERIZER + : (uint16_t)m_identifier.VendorId + ; g_caps.deviceId = (uint16_t)m_identifier.DeviceId; uint32_t behaviorFlags[] = @@ -417,7 +425,7 @@ namespace bgfx { namespace d3d9 #if 0 // BGFX_CONFIG_RENDERER_DIRECT3D9EX DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter , m_deviceType - , g_bgfxHwnd + , g_platformHooks.nwh , behaviorFlags[ii] , &m_params , NULL @@ -426,7 +434,7 @@ namespace bgfx { namespace d3d9 #else DX_CHECK(m_d3d9->CreateDevice(m_adapter , m_deviceType - , g_bgfxHwnd + , (HWND)g_platformData.nwh , behaviorFlags[ii] , &m_params , &m_device @@ -527,11 +535,27 @@ namespace bgfx { namespace d3d9 support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter , m_deviceType , adapterFormat + , D3DUSAGE_QUERY_SRGBREAD + , D3DRTYPE_TEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat , D3DUSAGE_QUERY_VERTEXTEXTURE , D3DRTYPE_TEXTURE , s_textureFormat[ii].m_fmt ) ) ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX : BGFX_CAPS_FORMAT_TEXTURE_NONE; + support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter + , m_deviceType + , adapterFormat + , isDepth(TextureFormat::Enum(ii) ) ? D3DUSAGE_DEPTHSTENCIL : D3DUSAGE_RENDERTARGET + , D3DRTYPE_TEXTURE + , s_textureFormat[ii].m_fmt + ) ) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER : BGFX_CAPS_FORMAT_TEXTURE_NONE; + g_caps.formats[ii] = support; } } @@ -671,7 +695,7 @@ namespace bgfx { namespace d3d9 return BGFX_RENDERER_DIRECT3D9_NAME; } - void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) BX_OVERRIDE + void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags); } @@ -691,7 +715,7 @@ namespace bgfx { namespace d3d9 m_vertexDecls[_handle.idx].destroy(); } - void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint8_t /*_flags*/) BX_OVERRIDE + void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint16_t /*_flags*/) BX_OVERRIDE { m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle); } @@ -701,7 +725,7 @@ namespace bgfx { namespace d3d9 m_vertexBuffers[_handle.idx].destroy(); } - void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t _flags) BX_OVERRIDE + void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_size, NULL, _flags); } @@ -716,7 +740,7 @@ namespace bgfx { namespace d3d9 m_indexBuffers[_handle.idx].destroy(); } - void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint8_t /*_flags*/) BX_OVERRIDE + void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t /*_flags*/) BX_OVERRIDE { VertexDeclHandle decl = BGFX_INVALID_HANDLE; m_vertexBuffers[_handle.idx].create(_size, NULL, decl); @@ -860,11 +884,11 @@ namespace bgfx { namespace d3d9 ) ); RECT rc; - GetClientRect(g_bgfxHwnd, &rc); + GetClientRect( (HWND)g_platformData.nwh, &rc); POINT point; point.x = rc.left; point.y = rc.top; - ClientToScreen(g_bgfxHwnd, &point); + ClientToScreen( (HWND)g_platformData.nwh, &point); uint8_t* data = (uint8_t*)rect.pBits; uint32_t bytesPerPixel = rect.Pitch/dm.Width; @@ -1070,6 +1094,8 @@ namespace bgfx { namespace d3d9 DX_CHECK(m_device->SetRenderTarget(ii, NULL) ); } DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) ); + + DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, 0 != (m_flags & BGFX_RESET_SRGB_BACKBUFFER) )); } else { @@ -1091,6 +1117,8 @@ namespace bgfx { namespace d3d9 IDirect3DSurface9* depthStencil = frameBuffer.m_depthStencil; DX_CHECK(m_device->SetDepthStencilSurface(NULL != depthStencil ? depthStencil : m_backBufferDepthStencil) ); + + DX_CHECK(m_device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE) ); } m_fbh = _fbh; @@ -1146,7 +1174,7 @@ namespace bgfx { namespace d3d9 void flip(HMD& /*_hmd*/) BX_OVERRIDE { - if (NULL != m_device) + if (NULL != m_swapChain) { #if BGFX_CONFIG_RENDERER_DIRECT3D9EX if (NULL != m_deviceEx) @@ -1160,7 +1188,7 @@ namespace bgfx { namespace d3d9 HRESULT hr; if (0 == ii) { - hr = m_swapChain->Present(NULL, NULL, g_bgfxHwnd, NULL, 0); + hr = m_swapChain->Present(NULL, NULL, (HWND)g_platformData.nwh, NULL, 0); } else { @@ -1220,6 +1248,9 @@ namespace bgfx { namespace d3d9 capturePreReset(); + DX_RELEASE(m_flushQuery, 0); + m_gpuTimer.preReset(); + for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii) { m_indexBuffers[ii].preReset(); @@ -1247,6 +1278,9 @@ namespace bgfx { namespace d3d9 DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) ); DX_CHECK(m_device->GetDepthStencilSurface(&m_backBufferDepthStencil) ); + DX_CHECK(m_device->CreateQuery(D3DQUERYTYPE_EVENT, &m_flushQuery) ); + m_gpuTimer.postReset(); + capturePostReset(); for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii) @@ -1281,7 +1315,7 @@ namespace bgfx { namespace d3d9 void setSamplerState(uint8_t _stage, uint32_t _flags, bool _vertex = false) { - const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK); + const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK | BGFX_TEXTURE_SRGB); BX_CHECK(_stage < BX_COUNTOF(m_samplerFlags), ""); if (m_samplerFlags[_stage][_vertex] != flags) { @@ -1303,6 +1337,7 @@ namespace bgfx { namespace d3d9 DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAGFILTER, magFilter) ); DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MIPFILTER, mipFilter) ); DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy) ); + DX_CHECK(device->SetSamplerState(stage, D3DSAMP_SRGBTEXTURE, 0 != (flags & BGFX_TEXTURE_SRGB)) ); } } @@ -1579,22 +1614,29 @@ namespace bgfx { namespace d3d9 DX_CHECK(device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) ); DX_CHECK(device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE) ); - if (BGFX_CLEAR_DEPTH & _clear.m_flags) + if (BGFX_CLEAR_COLOR & _clear.m_flags) { - DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE) ); DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE , D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA ) ); + } + else + { + DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE, 0) ); + } + + if (BGFX_CLEAR_DEPTH & _clear.m_flags) + { + DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE) ); DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, TRUE) ); DX_CHECK(device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS) ); } else { DX_CHECK(device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE) ); - DX_CHECK(device->SetRenderState(D3DRS_COLORWRITEENABLE, 0) ); DX_CHECK(device->SetRenderState(D3DRS_ZENABLE, FALSE) ); } @@ -1699,8 +1741,10 @@ namespace bgfx { namespace d3d9 IDirect3DDevice9Ex* m_deviceEx; #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX - IDirect3D9* m_d3d9; + IDirect3D9* m_d3d9; IDirect3DDevice9* m_device; + IDirect3DQuery9* m_flushQuery; + TimerQueryD3D9 m_gpuTimer; D3DPOOL m_pool; IDirect3DSwapChain9* m_swapChain; @@ -1772,7 +1816,7 @@ namespace bgfx { namespace d3d9 s_renderD3D9 = NULL; } - void IndexBufferD3D9::create(uint32_t _size, void* _data, uint8_t _flags) + void IndexBufferD3D9::create(uint32_t _size, void* _data, uint16_t _flags) { m_size = _size; m_flags = _flags; @@ -2416,6 +2460,11 @@ namespace bgfx { namespace d3d9 createTexture(textureWidth, textureHeight, numMips); } + if (imageContainer.m_srgb) + { + m_flags |= BGFX_TEXTURE_SRGB; + } + BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s." , this - s_renderD3D9->m_textures , getName( (TextureFormat::Enum)m_textureFormat) @@ -2867,6 +2916,84 @@ namespace bgfx { namespace d3d9 ) ); } + void TimerQueryD3D9::postReset() + { + IDirect3DDevice9* device = s_renderD3D9->m_device; + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frame); ++ii) + { + Frame& frame = m_frame[ii]; + DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMPDISJOINT, &frame.m_disjoint) ); + DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &frame.m_start) ); + DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &frame.m_end) ); + DX_CHECK(device->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, &frame.m_freq) ); + } + + m_elapsed = 0; + m_frequency = 1; + m_control.reset(); + } + + void TimerQueryD3D9::preReset() + { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frame); ++ii) + { + Frame& frame = m_frame[ii]; + DX_RELEASE(frame.m_disjoint, 0); + DX_RELEASE(frame.m_start, 0); + DX_RELEASE(frame.m_end, 0); + DX_RELEASE(frame.m_freq, 0); + } + } + + void TimerQueryD3D9::begin() + { + while (0 == m_control.reserve(1) ) + { + get(); + } + + Frame& frame = m_frame[m_control.m_current]; + frame.m_disjoint->Issue(D3DISSUE_BEGIN); + frame.m_start->Issue(D3DISSUE_END); + } + + void TimerQueryD3D9::end() + { + Frame& frame = m_frame[m_control.m_current]; + frame.m_end->Issue(D3DISSUE_END); + frame.m_freq->Issue(D3DISSUE_END); + m_control.commit(1); + } + + bool TimerQueryD3D9::get() + { + if (0 != m_control.available() ) + { + Frame& frame = m_frame[m_control.m_read]; + + uint64_t freq; + HRESULT hr = frame.m_freq->GetData(&freq, sizeof(freq), 0); + if (S_OK == hr) + { + m_control.consume(1); + + uint64_t start; + DX_CHECK(frame.m_start->GetData(&start, sizeof(start), 0) ); + + uint64_t end; + DX_CHECK(frame.m_end->GetData(&end, sizeof(end), 0) ); + + m_frequency = freq; + m_elapsed = end - start; + + return true; + } + } + + return false; + } + void RendererContextD3D9::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { IDirect3DDevice9* device = m_device; @@ -2880,6 +3007,11 @@ namespace bgfx { namespace d3d9 device->BeginScene(); + if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) + { + m_gpuTimer.begin(); + } + if (0 < _render->m_iboffset) { TransientIndexBuffer* ib = _render->m_transientIb; @@ -3404,6 +3536,12 @@ namespace bgfx { namespace d3d9 if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + m_flushQuery->Issue(D3DISSUE_END); + m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); @@ -3428,6 +3566,20 @@ namespace bgfx { namespace d3d9 { PIX_BEGINEVENT(D3DCOLOR_RGBA(0x40, 0x40, 0x40, 0xff), L"debugstats"); + static uint32_t maxGpuLatency = 0; + static double maxGpuElapsed = 0.0f; + double elapsedGpuMs = 0.0; + + m_gpuTimer.end(); + + while (m_gpuTimer.get() ) + { + double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); + elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; + maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; + } + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); + TextVideoMem& tvm = m_textVideoMem; static int64_t next = now; @@ -3465,12 +3617,18 @@ namespace bgfx { namespace d3d9 ); double elapsedCpuMs = double(elapsed)*toMs; - tvm.printf(10, pos++, 0x8e, " Submitted: %4d (draw %4d, compute %4d) / CPU %3.4f [ms]" + tvm.printf(10, pos++, 0x8e, " Submitted: %4d (draw %4d, compute %4d) / CPU %3.4f [ms] %c GPU %3.4f [ms] (latency %d)" , _render->m_num , statsKeyType[0] , statsKeyType[1] , elapsedCpuMs + , elapsedCpuMs > maxGpuElapsed ? '>' : '<' + , maxGpuElapsed + , maxGpuLatency ); + maxGpuLatency = 0; + maxGpuElapsed = 0.0; + for (uint32_t ii = 0; ii < BX_COUNTOF(s_primName); ++ii) { tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d" diff --git a/3rdparty/bgfx/src/renderer_d3d9.h b/3rdparty/bgfx/src/renderer_d3d9.h index 429721fab9b..27acc7abc7d 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.h +++ b/3rdparty/bgfx/src/renderer_d3d9.h @@ -135,7 +135,7 @@ namespace bgfx { namespace d3d9 { } - void create(uint32_t _size, void* _data, uint8_t _flags); + void create(uint32_t _size, void* _data, uint16_t _flags); void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { void* buffer; @@ -164,7 +164,7 @@ namespace bgfx { namespace d3d9 IDirect3DIndexBuffer9* m_ptr; uint32_t m_size; - uint8_t m_flags; + uint16_t m_flags; bool m_dynamic; }; @@ -389,6 +389,34 @@ namespace bgfx { namespace d3d9 bool m_needResolve; }; + struct TimerQueryD3D9 + { + TimerQueryD3D9() + : m_control(BX_COUNTOF(m_frame) ) + { + } + + void postReset(); + void preReset(); + void begin(); + void end(); + bool get(); + + struct Frame + { + IDirect3DQuery9* m_disjoint; + IDirect3DQuery9* m_start; + IDirect3DQuery9* m_end; + IDirect3DQuery9* m_freq; + }; + + uint64_t m_elapsed; + uint64_t m_frequency; + + Frame m_frame[4]; + bx::RingBufferControl m_control; + }; + } /* namespace d3d9 */ } // namespace bgfx #endif // BGFX_RENDERER_D3D9_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index 38875bbd2d7..4545f55756a 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -178,6 +178,7 @@ namespace bgfx { namespace gl struct TextureFormatInfo { GLenum m_internalFmt; + GLenum m_internalFmtSrgb; GLenum m_fmt; GLenum m_type; bool m_supported; @@ -185,55 +186,55 @@ namespace bgfx { namespace gl static TextureFormatInfo s_textureFormat[] = { - { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1 - { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2 - { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3 - { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4 - { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5 - { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H - { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7 - { GL_ETC1_RGB8_OES, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1 - { GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2 - { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A - { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1 - { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12 - { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14 - { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A - { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A - { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22 - { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24 - { GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown - { GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1 - { GL_R8, GL_RED, GL_UNSIGNED_BYTE, false }, // R8 - { GL_R16, GL_RED, GL_UNSIGNED_SHORT, false }, // R16 - { GL_R16F, GL_RED, GL_HALF_FLOAT, false }, // R16F - { GL_R32UI, GL_RED, GL_UNSIGNED_INT, false }, // R32 - { GL_R32F, GL_RED, GL_FLOAT, false }, // R32F - { GL_RG8, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8 - { GL_RG16, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16 - { GL_RG16F, GL_RG, GL_FLOAT, false }, // RG16F - { GL_RG32UI, GL_RG, GL_UNSIGNED_INT, false }, // RG32 - { GL_RG32F, GL_RG, GL_FLOAT, false }, // RG32F - { GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8 - { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8 - { GL_RGBA16, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16 - { GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F - { GL_RGBA32UI, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32 - { GL_RGBA32F, GL_RGBA, GL_FLOAT, false }, // RGBA32F - { GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5 - { GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, false }, // RGBA4 - { GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, false }, // RGB5A1 - { GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2 - { GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // R11G11B10F - { GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth - { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16 - { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24 - { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8 - { GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32 - { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F - { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F - { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F - { GL_STENCIL_INDEX8, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8 + { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1 + { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2 + { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3 + { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4 + { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5 + { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H + { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7 + { GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1 + { GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2 + { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A + { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1 + { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12 + { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14 + { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A + { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A + { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22 + { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24 + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1 + { GL_R8, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8 + { GL_R16, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16 + { GL_R16F, GL_ZERO, GL_RED, GL_HALF_FLOAT, false }, // R16F + { GL_R32UI, GL_ZERO, GL_RED, GL_UNSIGNED_INT, false }, // R32 + { GL_R32F, GL_ZERO, GL_RED, GL_FLOAT, false }, // R32F + { GL_RG8, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8 + { GL_RG16, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16 + { GL_RG16F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG16F + { GL_RG32UI, GL_ZERO, GL_RG, GL_UNSIGNED_INT, false }, // RG32 + { GL_RG32F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG32F + { GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8 + { GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8 + { GL_RGBA16, GL_ZERO, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA16 + { GL_RGBA16F, GL_ZERO, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F + { GL_RGBA32UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32 + { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_FLOAT, false }, // RGBA32F + { GL_RGB565, GL_ZERO, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5 + { GL_RGBA4, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, false }, // RGBA4 + { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, false }, // RGB5A1 + { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2 + { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // R11G11B10F + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth + { GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16 + { GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24 + { GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8 + { GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32 + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F + { GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8 }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); @@ -352,6 +353,7 @@ namespace bgfx { namespace gl enum Enum { AMD_conservative_depth, + AMD_multi_draw_indirect, ANGLE_depth_texture, ANGLE_framebuffer_blit, @@ -373,6 +375,7 @@ namespace bgfx { namespace gl ARB_depth_buffer_float, ARB_depth_clamp, ARB_draw_buffers_blend, + ARB_draw_indirect, ARB_draw_instanced, ARB_ES3_compatibility, ARB_framebuffer_object, @@ -383,6 +386,7 @@ namespace bgfx { namespace gl ARB_instanced_arrays, ARB_invalidate_subdata, ARB_map_buffer_range, + ARB_multi_draw_indirect, ARB_multisample, ARB_occlusion_query, ARB_occlusion_query2, @@ -425,6 +429,7 @@ namespace bgfx { namespace gl EXT_compressed_ETC1_RGB8_sub_texture, EXT_debug_label, EXT_debug_marker, + EXT_debug_tool, EXT_discard_framebuffer, EXT_disjoint_timer_query, EXT_draw_buffers, @@ -432,6 +437,7 @@ namespace bgfx { namespace gl EXT_framebuffer_blit, EXT_framebuffer_object, EXT_framebuffer_sRGB, + EXT_multi_draw_indirect, EXT_occlusion_query_boolean, EXT_packed_float, EXT_read_format_bgra, @@ -468,6 +474,7 @@ namespace bgfx { namespace gl INTEL_fragment_shader_ordering, KHR_debug, + KHR_no_error, MOZ_WEBGL_compressed_texture_s3tc, MOZ_WEBGL_depth_texture, @@ -540,6 +547,7 @@ namespace bgfx { namespace gl static Extension s_extension[] = { { "AMD_conservative_depth", false, true }, + { "AMD_multi_draw_indirect", false, true }, { "ANGLE_depth_texture", false, true }, { "ANGLE_framebuffer_blit", false, true }, @@ -561,6 +569,7 @@ namespace bgfx { namespace gl { "ARB_depth_buffer_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_depth_clamp", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, { "ARB_draw_buffers_blend", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, + { "ARB_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, { "ARB_draw_instanced", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_ES3_compatibility", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, { "ARB_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, @@ -571,6 +580,7 @@ namespace bgfx { namespace gl { "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_multi_draw_indirect", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, { "ARB_multisample", false, true }, { "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_occlusion_query2", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, @@ -613,6 +623,7 @@ namespace bgfx { namespace gl { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. { "EXT_debug_label", false, true }, { "EXT_debug_marker", false, true }, + { "EXT_debug_tool", false, true }, // RenderDoc extension. { "EXT_discard_framebuffer", false, true }, // GLES2 extension. { "EXT_disjoint_timer_query", false, true }, // GLES2 extension. { "EXT_draw_buffers", false, true }, // GLES2 extension. @@ -620,6 +631,7 @@ namespace bgfx { namespace gl { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "EXT_multi_draw_indirect", false, true }, // GLES3.1 extension. { "EXT_occlusion_query_boolean", false, true }, { "EXT_packed_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "EXT_read_format_bgra", false, true }, @@ -656,6 +668,7 @@ namespace bgfx { namespace gl { "INTEL_fragment_shader_ordering", false, true }, { "KHR_debug", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "KHR_no_error", false, true }, { "MOZ_WEBGL_compressed_texture_s3tc", false, true }, { "MOZ_WEBGL_depth_texture", false, true }, @@ -805,6 +818,26 @@ namespace bgfx { namespace gl { } + static void GL_APIENTRY stubMultiDrawArraysIndirect(GLenum _mode, const void* _indirect, GLsizei _drawcount, GLsizei _stride) + { + const uint8_t* args = (const uint8_t*)_indirect; + for (GLsizei ii = 0; ii < _drawcount; ++ii) + { + GL_CHECK(glDrawArraysIndirect(_mode, (void*)args) ); + args += _stride; + } + } + + static void GL_APIENTRY stubMultiDrawElementsIndirect(GLenum _mode, GLenum _type, const void* _indirect, GLsizei _drawcount, GLsizei _stride) + { + const uint8_t* args = (const uint8_t*)_indirect; + for (GLsizei ii = 0; ii < _drawcount; ++ii) + { + GL_CHECK(glDrawElementsIndirect(_mode, _type, (void*)args) ); + args += _stride; + } + } + typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); static const char* getGLString(GLenum _name) @@ -863,30 +896,26 @@ namespace bgfx { namespace gl const char* toString(GLenum _enum) { -#if defined(GL_DEBUG_SOURCE_API_ARB) switch (_enum) { - case GL_DEBUG_SOURCE_API_ARB: return "API"; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: return "WinSys"; - case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: return "Shader"; - case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: return "3rdparty"; - case GL_DEBUG_SOURCE_APPLICATION_ARB: return "Application"; - case GL_DEBUG_SOURCE_OTHER_ARB: return "Other"; - case GL_DEBUG_TYPE_ERROR_ARB: return "Error"; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: return "Deprecated behavior"; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: return "Undefined behavior"; - case GL_DEBUG_TYPE_PORTABILITY_ARB: return "Portability"; - case GL_DEBUG_TYPE_PERFORMANCE_ARB: return "Performance"; - case GL_DEBUG_TYPE_OTHER_ARB: return "Other"; - case GL_DEBUG_SEVERITY_HIGH_ARB: return "High"; - case GL_DEBUG_SEVERITY_MEDIUM_ARB: return "Medium"; - case GL_DEBUG_SEVERITY_LOW_ARB: return "Low"; + case GL_DEBUG_SOURCE_API: return "API"; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: return "WinSys"; + case GL_DEBUG_SOURCE_SHADER_COMPILER: return "Shader"; + case GL_DEBUG_SOURCE_THIRD_PARTY: return "3rdparty"; + case GL_DEBUG_SOURCE_APPLICATION: return "Application"; + case GL_DEBUG_SOURCE_OTHER: return "Other"; + case GL_DEBUG_TYPE_ERROR: return "Error"; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: return "Deprecated behavior"; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: return "Undefined behavior"; + case GL_DEBUG_TYPE_PORTABILITY: return "Portability"; + case GL_DEBUG_TYPE_PERFORMANCE: return "Performance"; + case GL_DEBUG_TYPE_OTHER: return "Other"; + case GL_DEBUG_SEVERITY_HIGH: return "High"; + case GL_DEBUG_SEVERITY_MEDIUM: return "Medium"; + case GL_DEBUG_SEVERITY_LOW: return "Low"; default: break; } -#else - BX_UNUSED(_enum); -#endif // defined(GL_DEBUG_SOURCE_API_ARB) return "<unknown>"; } @@ -920,10 +949,35 @@ namespace bgfx { namespace gl tfi.m_type = _type; } - bool isTextureFormatValid(TextureFormat::Enum _format) + void initTestTexture(TextureFormat::Enum _format, bool srgb = false) { const TextureFormatInfo& tfi = s_textureFormat[_format]; - if (GL_ZERO == tfi.m_internalFmt) + GLenum internalFmt = srgb + ? tfi.m_internalFmtSrgb + : tfi.m_internalFmt + ; + + GLsizei size = (16*16*getBitsPerPixel(_format) )/8; + void* data = alloca(size); + + if (isCompressed(_format) ) + { + glCompressedTexImage2D(GL_TEXTURE_2D, 0, internalFmt, 16, 16, 0, size, data); + } + else + { + glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, 16, 16, 0, tfi.m_fmt, tfi.m_type, data); + } + } + + static bool isTextureFormatValid(TextureFormat::Enum _format, bool srgb = false) + { + const TextureFormatInfo& tfi = s_textureFormat[_format]; + GLenum internalFmt = srgb + ? tfi.m_internalFmtSrgb + : tfi.m_internalFmt + ; + if (GL_ZERO == internalFmt) { return false; } @@ -931,25 +985,109 @@ namespace bgfx { namespace gl GLuint id; GL_CHECK(glGenTextures(1, &id) ); GL_CHECK(glBindTexture(GL_TEXTURE_2D, id) ); + initTestTexture(_format); - GLsizei size = (16*16*getBitsPerPixel(_format) )/8; - void* data = alloca(size); + GLenum err = glGetError(); + BX_WARN(0 == err, "TextureFormat::%s is not supported (%x: %s).", getName(_format), err, glEnumName(err) ); - if (isCompressed(_format) ) + GL_CHECK(glDeleteTextures(1, &id) ); + + return 0 == err; + } + + static bool isImageFormatValid(TextureFormat::Enum _format) + { + if (GL_ZERO == s_imageFormat[_format]) { - glCompressedTexImage2D(GL_TEXTURE_2D, 0, tfi.m_internalFmt, 16, 16, 0, size, data); + return false; } - else + + GLuint id; + GL_CHECK(glGenTextures(1, &id) ); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, id) ); + GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, s_imageFormat[_format], 16, 16) ); + + glBindImageTexture(0 + , id + , 0 + , GL_FALSE + , 0 + , GL_READ_WRITE + , s_imageFormat[_format] + ); + GLenum err = glGetError(); + + GL_CHECK(glDeleteTextures(1, &id) ); + + return 0 == err; + } + + static bool isFramebufferFormatValid(TextureFormat::Enum _format, bool srgb = false) + { + const TextureFormatInfo& tfi = s_textureFormat[_format]; + GLenum internalFmt = srgb + ? tfi.m_internalFmtSrgb + : tfi.m_internalFmt + ; + if (GL_ZERO == internalFmt + || !tfi.m_supported) { - glTexImage2D(GL_TEXTURE_2D, 0, tfi.m_internalFmt, 16, 16, 0, tfi.m_fmt, tfi.m_type, data); + return false; } + GLuint fbo; + GL_CHECK(glGenFramebuffers(1, &fbo) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo) ); + + GLuint id; + GL_CHECK(glGenTextures(1, &id) ); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, id) ); + + initTestTexture(_format); + GLenum err = glGetError(); - BX_WARN(0 == err, "TextureFormat::%s is not supported (%x: %s).", getName(_format), err, glEnumName(err) ); + + GLenum attachment; + if (isDepth(_format) ) + { + const ImageBlockInfo& info = getBlockInfo(_format); + if (0 < info.stencilBits) + { + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + } + else if (0 == info.depthBits) + { + attachment = GL_STENCIL_ATTACHMENT; + } + else + { + attachment = GL_DEPTH_ATTACHMENT; + } + } + else + { + attachment = GL_COLOR_ATTACHMENT0; + } + + glFramebufferTexture2D(GL_FRAMEBUFFER + , attachment + , GL_TEXTURE_2D + , id + , 0 + ); + err = glGetError(); + + if (0 == err) + { + err = glCheckFramebufferStatus(GL_FRAMEBUFFER); + } + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); + GL_CHECK(glDeleteFramebuffers(1, &fbo) ); GL_CHECK(glDeleteTextures(1, &id) ); - return 0 == err; + return GL_FRAMEBUFFER_COMPLETE == err; } static void getFilters(uint32_t _flags, bool _hasMips, GLenum& _magFilter, GLenum& _minFilter) @@ -1235,6 +1373,12 @@ namespace bgfx { namespace gl if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) ) { setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT); + // internalFormat and format must match: + // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml + setTextureFormat(TextureFormat::RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); + setTextureFormat(TextureFormat::R5G6B5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); + setTextureFormat(TextureFormat::RGBA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); + setTextureFormat(TextureFormat::RGB5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); if (s_extension[Extension::OES_texture_half_float].m_supported || s_extension[Extension::OES_texture_float ].m_supported) @@ -1313,21 +1457,54 @@ namespace bgfx { namespace gl s_textureFormat[TextureFormat::R8].m_fmt = GL_LUMINANCE; } - if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { - for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) + if (TextureFormat::Unknown != ii + && TextureFormat::UnknownDepth != ii) { - if (TextureFormat::Unknown != ii - && TextureFormat::UnknownDepth != ii) - { - s_textureFormat[ii].m_supported = isTextureFormatValid( (TextureFormat::Enum)ii); - } + s_textureFormat[ii].m_supported = isTextureFormatValid(TextureFormat::Enum(ii) ); } } + if (BX_ENABLED(0) ) + { + // Disable all compressed texture formats. For testing only. + for (uint32_t ii = 0; ii < TextureFormat::Unknown; ++ii) + { + s_textureFormat[ii].m_supported = false; + } + } + + const bool computeSupport = false + || !!(BGFX_CONFIG_RENDERER_OPENGLES >= 31) + || s_extension[Extension::ARB_compute_shader].m_supported + ; + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { - g_caps.formats[ii] = s_textureFormat[ii].m_supported ? 1 : 0; + uint8_t supported = 0; + supported |= s_textureFormat[ii].m_supported + ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + supported |= isTextureFormatValid(TextureFormat::Enum(ii), true) + ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + supported |= computeSupport + && isImageFormatValid(TextureFormat::Enum(ii) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + supported |= isFramebufferFormatValid(TextureFormat::Enum(ii) ) + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + g_caps.formats[ii] = supported; } g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) @@ -1364,6 +1541,28 @@ namespace bgfx { namespace gl : 0 ; + const bool drawIndirectSupported = false + || s_extension[Extension::AMD_multi_draw_indirect].m_supported + || s_extension[Extension::ARB_draw_indirect ].m_supported + || s_extension[Extension::ARB_multi_draw_indirect].m_supported + || s_extension[Extension::EXT_multi_draw_indirect].m_supported + ; + + if (drawIndirectSupported) + { + if (NULL == glMultiDrawArraysIndirect + || NULL == glMultiDrawElementsIndirect) + { + glMultiDrawArraysIndirect = stubMultiDrawArraysIndirect; + glMultiDrawElementsIndirect = stubMultiDrawElementsIndirect; + } + } + + g_caps.supported |= drawIndirectSupported + ? BGFX_CAPS_DRAW_INDIRECT + : 0 + ; + g_caps.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) @@ -1436,8 +1635,7 @@ namespace bgfx { namespace gl : 0 ; - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGLES >= 31) - || s_extension[Extension::ARB_compute_shader].m_supported + g_caps.supported |= computeSupport ? BGFX_CAPS_COMPUTE : 0 ; @@ -1496,12 +1694,23 @@ namespace bgfx { namespace gl } } -#if BGFX_CONFIG_RENDERER_OPENGL if (s_extension[Extension::ARB_debug_output].m_supported || s_extension[Extension::KHR_debug].m_supported) { - GL_CHECK(glDebugMessageCallback(debugProcCb, NULL) ); - GL_CHECK(glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM_ARB, 0, NULL, GL_TRUE) ); + if (NULL != glDebugMessageControl + && NULL != glDebugMessageInsert + && NULL != glDebugMessageCallback + && NULL != glGetDebugMessageLog) + { + GL_CHECK(glDebugMessageCallback(debugProcCb, NULL) ); + GL_CHECK(glDebugMessageControl(GL_DONT_CARE + , GL_DONT_CARE + , GL_DEBUG_SEVERITY_MEDIUM + , 0 + , NULL + , GL_TRUE + ) ); + } } if (s_extension[Extension::ARB_seamless_cube_map].m_supported) @@ -1513,7 +1722,6 @@ namespace bgfx { namespace gl { GL_CHECK(glEnable(GL_DEPTH_CLAMP) ); } -#endif // BGFX_CONFIG_RENDERER_OPENGL if (NULL == glFrameTerminatorGREMEDY || !s_extension[Extension::GREMEDY_frame_terminator].m_supported) @@ -1530,6 +1738,8 @@ namespace bgfx { namespace gl ; } + setGraphicsDebuggerPresent(s_extension[Extension::EXT_debug_tool].m_supported); + if (NULL == glObjectLabel) { glObjectLabel = stubObjectLabel; @@ -1616,7 +1826,7 @@ namespace bgfx { namespace gl } } - void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) BX_OVERRIDE + void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags); } @@ -1637,9 +1847,9 @@ namespace bgfx { namespace gl { } - void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint8_t /*_flags*/) BX_OVERRIDE + void createVertexBuffer(VertexBufferHandle _handle, Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) BX_OVERRIDE { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) BX_OVERRIDE @@ -1647,7 +1857,7 @@ namespace bgfx { namespace gl m_vertexBuffers[_handle.idx].destroy(); } - void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t _flags) BX_OVERRIDE + void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) BX_OVERRIDE { m_indexBuffers[_handle.idx].create(_size, NULL, _flags); } @@ -1662,10 +1872,10 @@ namespace bgfx { namespace gl m_indexBuffers[_handle.idx].destroy(); } - void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint8_t /*_flags*/) BX_OVERRIDE + void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) BX_OVERRIDE { VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl); + m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) BX_OVERRIDE @@ -2239,9 +2449,9 @@ namespace bgfx { namespace gl config.OGL.Header.RTSize.h = m_resolution.m_height; # endif // OVR_VERSION > OVR_VERSION_043 config.OGL.Header.Multisample = 0; - config.OGL.Window = g_bgfxHwnd; - config.OGL.DC = GetDC(g_bgfxHwnd); - if (m_ovr.postReset(g_bgfxHwnd, &config.Config, !!(m_resolution.m_flags & BGFX_RESET_HMD_DEBUG) ) ) + config.OGL.Window = (HWND)g_platformData.nwh; + config.OGL.DC = GetDC(config.OGL.Window); + if (m_ovr.postReset(g_platformData.nwh, &config.Config, !!(m_resolution.m_flags & BGFX_RESET_HMD_DEBUG) ) ) { uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); const Memory* mem = alloc(size); @@ -3066,8 +3276,11 @@ namespace bgfx { namespace gl *array = '\0'; array++; char* end = strchr(array, ']'); - *end = '\0'; - offset = atoi(array); + if (NULL != end) + { // Some devices (Amazon Fire) might not return terminating brace. + *end = '\0'; + offset = atoi(array); + } } switch (gltype) @@ -3329,18 +3542,20 @@ namespace bgfx { namespace gl } } - bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint8_t _format, uint8_t _numMips, uint32_t _flags) + bool TextureGL::init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _format, uint8_t _numMips, uint32_t _flags) { - m_target = _target; + m_target = _target; m_numMips = _numMips; - m_flags = _flags; - m_currentFlags = UINT32_MAX; - m_width = _width; - m_height = _height; + m_flags = _flags; + m_width = _width; + m_height = _height; + m_depth = _depth; + m_currentFlags = UINT32_MAX; m_requestedFormat = _format; m_textureFormat = _format; - const bool bufferOnly = 0 != (m_flags&BGFX_TEXTURE_RT_BUFFER_ONLY); + const bool bufferOnly = 0 != (m_flags&BGFX_TEXTURE_RT_BUFFER_ONLY); + const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE ); if (!bufferOnly) { @@ -3361,6 +3576,7 @@ namespace bgfx { namespace gl const bool convert = false || (compressed && m_textureFormat != m_requestedFormat) || swizzle + || !s_textureFormat[m_requestedFormat].m_supported ; if (convert) @@ -3371,6 +3587,29 @@ namespace bgfx { namespace gl m_type = tfiRgba8.m_type; } + if (computeWrite) + { + if (_target == GL_TEXTURE_3D) + { + GL_CHECK(glTexStorage3D(_target + , _numMips + , s_textureFormat[m_textureFormat].m_internalFmt + , m_width + , m_height + , _depth + ) ); + } + else + { + GL_CHECK(glTexStorage2D(_target + , _numMips + , s_textureFormat[m_textureFormat].m_internalFmt + , m_width + , m_height + ) ); + } + } + setSamplerState(_flags); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) @@ -3439,9 +3678,15 @@ namespace bgfx { namespace gl uint8_t numMips = imageContainer.m_numMips; const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); numMips -= startLod; - const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); - const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); - const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); + uint32_t textureWidth; + uint32_t textureHeight; + uint32_t textureDepth; + { + const ImageBlockInfo& ibi = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); + textureWidth = bx::uint32_max(ibi.blockWidth, imageContainer.m_width >>startLod); + textureHeight = bx::uint32_max(ibi.blockHeight, imageContainer.m_height>>startLod); + textureDepth = imageContainer.m_depth; + } GLenum target = GL_TEXTURE_2D; if (imageContainer.m_cubeMap) @@ -3456,6 +3701,7 @@ namespace bgfx { namespace gl if (!init(target , textureWidth , textureHeight + , textureDepth , imageContainer.m_format , numMips , _flags @@ -3464,9 +3710,15 @@ namespace bgfx { namespace gl return; } + const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE); + const bool srgb = 0 != (m_flags&BGFX_TEXTURE_SRGB); + target = GL_TEXTURE_CUBE_MAP == m_target ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target; - const GLenum internalFmt = s_textureFormat[m_textureFormat].m_internalFmt; + const GLenum internalFmt = srgb + ? s_textureFormat[m_textureFormat].m_internalFmtSrgb + : s_textureFormat[m_textureFormat].m_internalFmt + ; const bool swizzle = true && TextureFormat::BGRA8 == m_requestedFormat @@ -3475,17 +3727,9 @@ namespace bgfx { namespace gl ; const bool compressed = isCompressed(TextureFormat::Enum(m_requestedFormat) ); const bool convert = false - || (compressed && m_textureFormat != m_requestedFormat) + || m_textureFormat != m_requestedFormat || swizzle ; - uint32_t blockWidth = 1; - uint32_t blockHeight = 1; - - if (convert && compressed) - { - blockWidth = blockInfo.blockWidth; - blockHeight = blockInfo.blockHeight; - } BX_TRACE("Texture%-4s %3d: %s (requested: %s), %dx%dx%d%s." , imageContainer.m_cubeMap ? "Cube" : (1 < imageContainer.m_depth ? "3D" : "2D") @@ -3520,14 +3764,15 @@ namespace bgfx { namespace gl for (uint8_t lod = 0, num = numMips; lod < num; ++lod) { - width = bx::uint32_max(blockWidth, width); - height = bx::uint32_max(blockHeight, height); + width = bx::uint32_max(1, width); + height = bx::uint32_max(1, height); depth = bx::uint32_max(1, depth); ImageMip mip; if (imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) { - if (compressed) + if (compressed + && !convert) { compressedTexImage(target+side , lod @@ -3546,7 +3791,13 @@ namespace bgfx { namespace gl if (convert) { - imageDecodeToRgba8(temp, mip.m_data, mip.m_width, mip.m_height, mip.m_width*4, mip.m_format); + imageDecodeToRgba8(temp + , mip.m_data + , mip.m_width + , mip.m_height + , mip.m_width*4 + , mip.m_format + ); data = temp; } @@ -3563,7 +3814,7 @@ namespace bgfx { namespace gl ); } } - else + else if (!computeWrite) { if (compressed) { @@ -3724,6 +3975,12 @@ namespace bgfx { namespace gl ) ); } + if (!convert + && unpackRowLength) + { + GL_CHECK(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0) ); + } + if (NULL != temp) { BX_FREE(g_allocator, temp); @@ -4133,11 +4390,14 @@ namespace bgfx { namespace gl writeString(&writer, "#version 140\n"); } + writeString(&writer, "#define texture2DLod textureLod\n"); + writeString(&writer, "#define texture3DLod textureLod\n"); + writeString(&writer, "#define textureCubeLod textureLod\n"); + if (m_type == GL_FRAGMENT_SHADER) { writeString(&writer, "#define varying in\n"); writeString(&writer, "#define texture2D texture\n"); - writeString(&writer, "#define texture2DLod textureLod\n"); writeString(&writer, "#define texture2DProj textureProj\n"); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) @@ -4152,9 +4412,7 @@ namespace bgfx { namespace gl } writeString(&writer, "#define texture3D texture\n"); - writeString(&writer, "#define texture3DLod textureLod\n"); writeString(&writer, "#define textureCube texture\n"); - writeString(&writer, "#define textureCubeLod textureLod\n"); uint32_t fragData = 0; @@ -4782,7 +5040,38 @@ namespace bgfx { namespace gl viewState.setPredefined<1>(this, view, eye, program, _render, compute); - GL_CHECK(glDispatchCompute(compute.m_numX, compute.m_numY, compute.m_numZ) ); + if (isValid(compute.m_indirectBuffer) ) + { + const VertexBufferGL& vb = m_vertexBuffers[compute.m_indirectBuffer.idx]; + if (currentState.m_indirectBuffer.idx != compute.m_indirectBuffer.idx) + { + currentState.m_indirectBuffer = compute.m_indirectBuffer; + GL_CHECK(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, vb.m_id) ); + } + + uint32_t numDrawIndirect = UINT16_MAX == compute.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : compute.m_numIndirect + ; + + uintptr_t args = compute.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + GL_CHECK(glDispatchComputeIndirect(args) ); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + } + } + else + { + if (isValid(currentState.m_indirectBuffer) ) + { + currentState.m_indirectBuffer.idx = invalidHandle; + GL_CHECK(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0) ); + } + + GL_CHECK(glDispatchCompute(compute.m_numX, compute.m_numY, compute.m_numZ) ); + } + GL_CHECK(glMemoryBarrier(barrier) ); } } @@ -4790,6 +5079,8 @@ namespace bgfx { namespace gl continue; } + bool resetState = viewChanged || wasCompute; + if (wasCompute) { wasCompute = false; @@ -4812,7 +5103,7 @@ namespace bgfx { namespace gl uint64_t changedStencil = currentState.m_stencil ^ draw.m_stencil; currentState.m_stencil = newStencil; - if (viewChanged) + if (resetState) { currentState.clear(); currentState.m_scissor = !draw.m_scissor; @@ -5310,61 +5601,116 @@ namespace bgfx { namespace gl numVertices = vb.m_size/vertexDecl.m_stride; } - uint32_t numIndices = 0; + uint32_t numIndices = 0; uint32_t numPrimsSubmitted = 0; - uint32_t numInstances = 0; - uint32_t numPrimsRendered = 0; + uint32_t numInstances = 0; + uint32_t numPrimsRendered = 0; + uint32_t numDrawIndirect = 0; - if (isValid(draw.m_indexBuffer) ) + if (isValid(draw.m_indirectBuffer) ) { - const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; - const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); - const GLenum indexFormat = hasIndex16 - ? GL_UNSIGNED_SHORT - : GL_UNSIGNED_INT - ; + const VertexBufferGL& vb = m_vertexBuffers[draw.m_indirectBuffer.idx]; + if (currentState.m_indirectBuffer.idx != draw.m_indirectBuffer.idx) + { + currentState.m_indirectBuffer = draw.m_indirectBuffer; + GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vb.m_id) ); + } - if (UINT32_MAX == draw.m_numIndices) + if (isValid(draw.m_indexBuffer) ) { - const uint32_t indexSize = hasIndex16 ? 2 : 4; - numIndices = ib.m_size/indexSize; - numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - - GL_CHECK(glDrawElementsInstanced(prim.m_type - , numIndices - , indexFormat - , (void*)0 - , draw.m_numInstances + const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); + const GLenum indexFormat = hasIndex16 + ? GL_UNSIGNED_SHORT + : GL_UNSIGNED_INT + ; + + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + + uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + GL_CHECK(glMultiDrawElementsIndirect(prim.m_type, indexFormat + , (void*)args + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE ) ); } - else if (prim.m_min <= draw.m_numIndices) + else { - numIndices = draw.m_numIndices; - numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; - GL_CHECK(glDrawElementsInstanced(prim.m_type - , numIndices - , indexFormat - , (void*)(uintptr_t)(draw.m_startIndex*2) - , draw.m_numInstances + uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + GL_CHECK(glMultiDrawArraysIndirect(prim.m_type + , (void*)args + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE ) ); } } else { - numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + if (isValid(currentState.m_indirectBuffer) ) + { + currentState.m_indirectBuffer.idx = invalidHandle; + GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0) ); + } - GL_CHECK(glDrawArraysInstanced(prim.m_type - , 0 - , numVertices - , draw.m_numInstances - ) ); + if (isValid(draw.m_indexBuffer) ) + { + const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); + const GLenum indexFormat = hasIndex16 + ? GL_UNSIGNED_SHORT + : GL_UNSIGNED_INT + ; + + if (UINT32_MAX == draw.m_numIndices) + { + const uint32_t indexSize = hasIndex16 ? 2 : 4; + numIndices = ib.m_size/indexSize; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + GL_CHECK(glDrawElementsInstanced(prim.m_type + , numIndices + , indexFormat + , (void*)0 + , draw.m_numInstances + ) ); + } + else if (prim.m_min <= draw.m_numIndices) + { + numIndices = draw.m_numIndices; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + GL_CHECK(glDrawElementsInstanced(prim.m_type + , numIndices + , indexFormat + , (void*)(uintptr_t)(draw.m_startIndex*2) + , draw.m_numInstances + ) ); + } + } + else + { + numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + GL_CHECK(glDrawArraysInstanced(prim.m_type + , 0 + , numVertices + , draw.m_numInstances + ) ); + } } statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; @@ -5379,6 +5725,11 @@ namespace bgfx { namespace gl if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + GL_CHECK(glFlush() ); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); @@ -5459,6 +5810,7 @@ namespace bgfx { namespace gl , elapsedCpuMs > elapsedGpuMs ? '>' : '<' , elapsedGpuMs ); + for (uint32_t ii = 0; ii < BX_COUNTOF(s_primInfo); ++ii) { tvm.printf(10, pos++, 0x8e, " %9s: %7d (#inst: %5d), submitted: %7d" diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h index 338550f0ad5..8c77fd2546c 100644 --- a/3rdparty/bgfx/src/renderer_gl.h +++ b/3rdparty/bgfx/src/renderer_gl.h @@ -305,6 +305,22 @@ typedef uint64_t GLuint64; # define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138 #endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG +#ifndef GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT +# define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54 +#endif // GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT + +#ifndef GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT +# define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55 +#endif // GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT + +#ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT +# define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56 +#endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT + +#ifndef GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT +# define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57 +#endif // GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT + #ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB # define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C #endif // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB @@ -321,6 +337,30 @@ typedef uint64_t GLuint64; # define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F #endif // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB +#ifndef GL_SRGB8_ALPHA8 +# define GL_SRGB8_ALPHA8 0x8C43 +#endif // GL_SRGB8_ALPHA8 + +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT +# define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT + +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT +# define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT + +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT +# define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT + +#ifndef GL_COMPRESSED_SRGB8_ETC2 +# define GL_COMPRESSED_SRGB8_ETC2 0x9275 +#endif // GL_COMPRESSED_SRGB8_ETC2 + +#ifndef GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 +# define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 +#endif // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 + #ifndef GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE # define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 #endif // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE @@ -582,6 +622,53 @@ typedef uint64_t GLuint64; # define GL_LOCATION 0x930E #endif // GL_LOCATION +// _KHR or _ARB... +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 +#define GL_DEBUG_TYPE_POP_GROUP 0x826A +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C +#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D +#define GL_MAX_LABEL_LENGTH 0x82E8 +#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES 0x9145 +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 + +#ifndef GL_DEPTH_CLAMP +# define GL_DEPTH_CLAMP 0x864F +#endif // GL_DEPTH_CLAMP + +#ifndef GL_TEXTURE_CUBE_MAP_SEAMLESS +# define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif // GL_TEXTURE_CUBE_MAP_SEAMLESS + +#ifndef GL_DRAW_INDIRECT_BUFFER +# define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#endif // GL_DRAW_INDIRECT_BUFFER + +#ifndef GL_DISPATCH_INDIRECT_BUFFER +# define GL_DISPATCH_INDIRECT_BUFFER 0x90EE +#endif // GL_DISPATCH_INDIRECT_BUFFER + #if BX_PLATFORM_NACL # include "glcontext_ppapi.h" #elif BX_PLATFORM_WINDOWS @@ -782,7 +869,7 @@ namespace bgfx { namespace gl struct IndexBufferGL { - void create(uint32_t _size, void* _data, uint8_t _flags) + void create(uint32_t _size, void* _data, uint16_t _flags) { m_size = _size; m_flags = _flags; @@ -820,37 +907,40 @@ namespace bgfx { namespace gl GLuint m_id; uint32_t m_size; VaoCacheRef m_vcref; - uint8_t m_flags; + uint16_t m_flags; }; struct VertexBufferGL { - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle) + void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) { m_size = _size; m_decl = _declHandle; + const bool drawIndirect = 0 != (_flags & BGFX_BUFFER_DRAW_INDIRECT); + + m_target = drawIndirect ? GL_DRAW_INDIRECT_BUFFER : GL_ARRAY_BUFFER; GL_CHECK(glGenBuffers(1, &m_id) ); BX_CHECK(0 != m_id, "Failed to generate buffer id."); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) ); - GL_CHECK(glBufferData(GL_ARRAY_BUFFER + GL_CHECK(glBindBuffer(m_target, m_id) ); + GL_CHECK(glBufferData(m_target , _size , _data , (NULL==_data) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW ) ); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); + GL_CHECK(glBindBuffer(m_target, 0) ); } void update(uint32_t _offset, uint32_t _size, void* _data) { BX_CHECK(0 != m_id, "Updating invalid vertex buffer."); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) ); - GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER + GL_CHECK(glBindBuffer(m_target, m_id) ); + GL_CHECK(glBufferSubData(m_target , _offset , _size , _data ) ); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); + GL_CHECK(glBindBuffer(m_target, 0) ); } void destroy(); @@ -861,6 +951,7 @@ namespace bgfx { namespace gl } GLuint m_id; + GLenum m_target; uint32_t m_size; VertexDeclHandle m_decl; VaoCacheRef m_vcref; @@ -880,7 +971,7 @@ namespace bgfx { namespace gl { } - bool init(GLenum _target, uint32_t _width, uint32_t _height, uint8_t _format, uint8_t _numMips, uint32_t _flags); + bool init(GLenum _target, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _format, uint8_t _numMips, uint32_t _flags); void create(const Memory* _mem, uint32_t _flags, uint8_t _skip); void destroy(); void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); @@ -896,6 +987,7 @@ namespace bgfx { namespace gl uint32_t m_currentFlags; uint32_t m_width; uint32_t m_height; + uint32_t m_depth; uint8_t m_numMips; uint8_t m_requestedFormat; uint8_t m_textureFormat; diff --git a/3rdparty/bgfx/tools/shaderc/shaderc.cpp b/3rdparty/bgfx/tools/shaderc/shaderc.cpp index 1388385f079..192a1f33a99 100644 --- a/3rdparty/bgfx/tools/shaderc/shaderc.cpp +++ b/3rdparty/bgfx/tools/shaderc/shaderc.cpp @@ -640,7 +640,7 @@ void help(const char* _error = NULL) " -i <include path> Include path (for multiple paths use semicolon).\n" " -o <file path> Output file path.\n" " --bin2c <file path> Generate C header file.\n" - " --depends <file path> Generate makefile style depends file.\n" + " --depends Generate makefile style depends file.\n" " --platform <platform> Target platform.\n" " android\n" " asm.js\n" @@ -1390,7 +1390,7 @@ int main(int _argc, const char* _argv[]) strins(const_cast<char*>(brace+1), "\nvec4 bgfx_VoidFrag;\n"); } - const bool hasFragCoord = NULL != strstr(input, "gl_FragCoord") || hlsl > 3; + const bool hasFragCoord = NULL != strstr(input, "gl_FragCoord") || hlsl > 3 || hlsl == 2; const bool hasFragDepth = NULL != strstr(input, "gl_FragDepth"); const bool hasFrontFacing = NULL != strstr(input, "gl_FrontFacing"); const bool hasPrimitiveId = NULL != strstr(input, "gl_PrimitiveID"); diff --git a/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp b/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp index f4b1d4e9bd2..e20e09543e6 100644 --- a/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp +++ b/3rdparty/bgfx/tools/shaderc/shaderc_hlsl.cpp @@ -7,6 +7,7 @@ #if SHADERC_CONFIG_HLSL +#define INITGUID #include <d3dcompiler.h> #include <d3d11shader.h> @@ -14,12 +15,6 @@ # define D3D_SVF_USED 2 #endif // D3D_SVF_USED -#ifndef IID_ID3D11ShaderReflection -// In case MinGW is missing IID... -static const GUID GUID_ID3D11ShaderReflection = { 0x0a233719, 0x3960, 0x4578, { 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1 } }; -# define IID_ID3D11ShaderReflection GUID_ID3D11ShaderReflection -#endif // IID_ID3D11ShaderReflection - struct CTHeader { uint32_t Size; @@ -525,7 +520,7 @@ bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::stri while (!reader.isEof() ) { std::string line = reader.getLine(); - for (UniformNameList::const_iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it) + for (UniformNameList::iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it) { size_t index = line.find("uniform "); if (index == std::string::npos) diff --git a/3rdparty/bx/include/bx/float4_ni.h b/3rdparty/bx/include/bx/float4_ni.h index f8a2a77bec2..c70915147d4 100644 --- a/3rdparty/bx/include/bx/float4_ni.h +++ b/3rdparty/bx/include/bx/float4_ni.h @@ -15,7 +15,7 @@ namespace bx const float4_t xAyB = float4_shuf_xAyB(_a, _b); const float4_t zCwD = float4_shuf_zCwD(_a, _b); const float4_t result = float4_shuf_xyAB(xAyB, zCwD); - + return result; } @@ -24,7 +24,7 @@ namespace bx const float4_t xAyB = float4_shuf_xAyB(_a, _b); const float4_t zCwD = float4_shuf_zCwD(_a, _b); const float4_t result = float4_shuf_zwCD(xAyB, zCwD); - + return result; } @@ -192,7 +192,7 @@ namespace bx const float4_t one = float4_splat(1.0f); const float4_t sqrt = float4_sqrt(_a); const float4_t result = float4_div(one, sqrt); - + return result; } @@ -206,7 +206,7 @@ namespace bx const float4_t three = float4_splat(3.0f); const float4_t three_sub_iter1 = float4_sub(three, iter1); const float4_t result = float4_mul(half_rsqrt, three_sub_iter1); - + return result; } @@ -375,7 +375,7 @@ namespace bx const float4_t expfpart = float4_logexp_detail::float4_exppoly(fpart); const float4_t result = float4_mul(expipart, expfpart); - + return result; } @@ -401,12 +401,21 @@ namespace bx BX_FLOAT4_INLINE float4_t float4_cross3_ni(float4_t _a, float4_t _b) { + // a.yzx * b.zxy - a.zxy * b.yzx == (a * b.yzx - a.yzx * b).yzx +#if 0 const float4_t a_yzxw = float4_swiz_yzxw(_a); const float4_t a_zxyw = float4_swiz_zxyw(_a); const float4_t b_zxyw = float4_swiz_zxyw(_b); const float4_t b_yzxw = float4_swiz_yzxw(_b); const float4_t tmp = float4_mul(a_yzxw, b_zxyw); const float4_t result = float4_nmsub(a_zxyw, b_yzxw, tmp); +#else + const float4_t a_yzxw = float4_swiz_yzxw(_a); + const float4_t b_yzxw = float4_swiz_yzxw(_b); + const float4_t tmp0 = float4_mul(_a, b_yzxw); + const float4_t tmp1 = float4_nmsub(a_yzxw, _b, tmp0); + const float4_t result = float4_swiz_yzxw(tmp1); +#endif return result; } @@ -416,7 +425,7 @@ namespace bx const float4_t dot3 = float4_dot3(_a, _a); const float4_t invSqrt = float4_rsqrt(dot3); const float4_t result = float4_mul(_a, invSqrt); - + return result; } diff --git a/3rdparty/bx/include/bx/macros.h b/3rdparty/bx/include/bx/macros.h index b50cfc57f33..5086b7e8d6d 100644 --- a/3rdparty/bx/include/bx/macros.h +++ b/3rdparty/bx/include/bx/macros.h @@ -62,7 +62,7 @@ # define BX_THREAD /* not supported right now */ # else # if (__GNUC__ == 4) && (__GNUC_MINOR__ <= 2) -# define BX_THREAD /* not supported right now */ +# define BX_THREAD /* not supported right now */ # else # define BX_THREAD __thread # endif // __GNUC__ <= 4.2 @@ -179,7 +179,7 @@ # define BX_TYPE_IS_POD(t) (!__is_class(t) || __is_pod(t)) #else # define BX_TYPE_IS_POD(t) false -#endif +#endif /// #define BX_CLASS_NO_DEFAULT_CTOR(_class) \ private: _class() diff --git a/3rdparty/bx/include/bx/readerwriter.h b/3rdparty/bx/include/bx/readerwriter.h index 63daa79a2af..3d681b8b0cb 100644 --- a/3rdparty/bx/include/bx/readerwriter.h +++ b/3rdparty/bx/include/bx/readerwriter.h @@ -96,6 +96,26 @@ namespace bx return _writer->write(_data, _size); } + /// Write repeat the same value. + inline int32_t writeRep(WriterI* _writer, uint8_t _byte, int32_t _size) + { + const uint32_t tmp0 = uint32_sels(64 - _size, 64, _size); + const uint32_t tmp1 = uint32_sels(256 - _size, 256, tmp0); + const uint32_t blockSize = uint32_sels(1024 - _size, 1024, tmp1); + uint8_t* temp = (uint8_t*)alloca(blockSize); + memset(temp, _byte, blockSize); + + int32_t size = 0; + while (0 < _size) + { + int32_t bytes = write(_writer, temp, uint32_min(blockSize, _size) ); + size += bytes; + _size -= bytes; + } + + return size; + } + /// Write value. template<typename Ty> inline int32_t write(WriterI* _writer, const Ty& _value) diff --git a/3rdparty/bx/include/bx/ringbuffer.h b/3rdparty/bx/include/bx/ringbuffer.h index 424c83e823f..6dff4f237fc 100644 --- a/3rdparty/bx/include/bx/ringbuffer.h +++ b/3rdparty/bx/include/bx/ringbuffer.h @@ -83,6 +83,13 @@ namespace bx return result; } + void reset() + { + m_current = 0; + m_write = 0; + m_read = 0; + } + const uint32_t m_size; uint32_t m_current; uint32_t m_write; @@ -164,6 +171,13 @@ namespace bx return result; } + void reset() + { + m_current = 0; + m_write = 0; + m_read = 0; + } + const uint32_t m_size; uint32_t m_current; uint32_t m_write; diff --git a/3rdparty/bx/include/bx/uint32_t.h b/3rdparty/bx/include/bx/uint32_t.h index 16ce229429c..48908f6511d 100644 --- a/3rdparty/bx/include/bx/uint32_t.h +++ b/3rdparty/bx/include/bx/uint32_t.h @@ -85,6 +85,11 @@ namespace bx return _a & _b; } + inline uint32_t uint32_andc(uint32_t _a, uint32_t _b) + { + return _a & ~_b; + } + inline uint32_t uint32_xor(uint32_t _a, uint32_t _b) { return _a ^ _b; @@ -95,14 +100,14 @@ namespace bx return !_a != !_b; } - inline uint32_t uint32_andc(uint32_t _a, uint32_t _b) + inline uint32_t uint32_or(uint32_t _a, uint32_t _b) { - return _a & ~_b; + return _a | _b; } - inline uint32_t uint32_or(uint32_t _a, uint32_t _b) + inline uint32_t uint32_orc(uint32_t _a, uint32_t _b) { - return _a | _b; + return _a | ~_b; } inline uint32_t uint32_sll(uint32_t _a, int _sa) @@ -271,6 +276,14 @@ namespace bx return result; } + inline uint32_t uint32_iclamp(uint32_t _a, uint32_t _min, uint32_t _max) + { + const uint32_t tmp = uint32_imax(_a, _min); + const uint32_t result = uint32_imin(tmp, _max); + + return result; + } + inline uint32_t uint32_incwrap(uint32_t _val, uint32_t _min, uint32_t _max) { const uint32_t inc = uint32_inc(_val); diff --git a/3rdparty/bx/include/compat/msvc/dirent.h b/3rdparty/bx/include/compat/msvc/dirent.h new file mode 100644 index 00000000000..6f959a50185 --- /dev/null +++ b/3rdparty/bx/include/compat/msvc/dirent.h @@ -0,0 +1,838 @@ +/* + * dirent.h - dirent API for Microsoft Visual Studio + * + * Copyright (C) 2006-2012 Toni Ronkko + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * ``Software''), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $ + */ +#ifndef DIRENT_H +#define DIRENT_H + +/* + * Define architecture flags so we don't need to include windows.h. + * Avoiding windows.h makes it simpler to use windows sockets in conjunction + * with dirent.h. + */ +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86) +# define _X86_ +#endif +#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64) +#define _AMD64_ +#endif + +#include <stdio.h> +#include <stdarg.h> +#include <windef.h> +#include <winbase.h> +#include <wchar.h> +#include <string.h> +#include <stdlib.h> +#include <malloc.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +/* Indicates that d_type field is available in dirent structure */ +#define _DIRENT_HAVE_D_TYPE + +/* Indicates that d_namlen field is available in dirent structure */ +#define _DIRENT_HAVE_D_NAMLEN + +/* Entries missing from MSVC 6.0 */ +#if !defined(FILE_ATTRIBUTE_DEVICE) +# define FILE_ATTRIBUTE_DEVICE 0x40 +#endif + +/* File type and permission flags for stat() */ +#if !defined(S_IFMT) +# define S_IFMT _S_IFMT /* File type mask */ +#endif +#if !defined(S_IFDIR) +# define S_IFDIR _S_IFDIR /* Directory */ +#endif +#if !defined(S_IFCHR) +# define S_IFCHR _S_IFCHR /* Character device */ +#endif +#if !defined(S_IFFIFO) +# define S_IFFIFO _S_IFFIFO /* Pipe */ +#endif +#if !defined(S_IFREG) +# define S_IFREG _S_IFREG /* Regular file */ +#endif +#if !defined(S_IREAD) +# define S_IREAD _S_IREAD /* Read permission */ +#endif +#if !defined(S_IWRITE) +# define S_IWRITE _S_IWRITE /* Write permission */ +#endif +#if !defined(S_IEXEC) +# define S_IEXEC _S_IEXEC /* Execute permission */ +#endif +#if !defined(S_IFIFO) +# define S_IFIFO _S_IFIFO /* Pipe */ +#endif +#if !defined(S_IFBLK) +# define S_IFBLK 0 /* Block device */ +#endif +#if !defined(S_IFLNK) +# define S_IFLNK 0 /* Link */ +#endif +#if !defined(S_IFSOCK) +# define S_IFSOCK 0 /* Socket */ +#endif + +#if defined(_MSC_VER) +# define S_IRUSR S_IREAD /* Read user */ +# define S_IWUSR S_IWRITE /* Write user */ +# define S_IXUSR 0 /* Execute user */ +# define S_IRGRP 0 /* Read group */ +# define S_IWGRP 0 /* Write group */ +# define S_IXGRP 0 /* Execute group */ +# define S_IROTH 0 /* Read others */ +# define S_IWOTH 0 /* Write others */ +# define S_IXOTH 0 /* Execute others */ +#endif + +/* Maximum length of file name */ +#if !defined(PATH_MAX) +# define PATH_MAX MAX_PATH +#endif +#if !defined(FILENAME_MAX) +# define FILENAME_MAX MAX_PATH +#endif +#if !defined(NAME_MAX) +# define NAME_MAX FILENAME_MAX +#endif + +/* File type flags for d_type */ +#define DT_UNKNOWN 0 +#define DT_REG S_IFREG +#define DT_DIR S_IFDIR +#define DT_FIFO S_IFIFO +#define DT_SOCK S_IFSOCK +#define DT_CHR S_IFCHR +#define DT_BLK S_IFBLK +#define DT_LNK S_IFLNK + +/* Macros for converting between st_mode and d_type */ +#define IFTODT(mode) ((mode) & S_IFMT) +#define DTTOIF(type) (type) + +/* + * File type macros. Note that block devices, sockets and links cannot be + * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are + * only defined for compatibility. These macros should always return false + * on Windows. + */ +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) + +/* Return the exact length of d_namlen without zero terminator */ +#define _D_EXACT_NAMLEN(p) ((p)->d_namlen) + +/* Return number of bytes needed to store d_namlen */ +#define _D_ALLOC_NAMLEN(p) (PATH_MAX) + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Wide-character version */ +struct _wdirent { + long d_ino; /* Always zero */ + unsigned short d_reclen; /* Structure size */ + size_t d_namlen; /* Length of name without \0 */ + int d_type; /* File type */ + wchar_t d_name[PATH_MAX]; /* File name */ +}; +typedef struct _wdirent _wdirent; + +struct _WDIR { + struct _wdirent ent; /* Current directory entry */ + WIN32_FIND_DATAW data; /* Private file data */ + int cached; /* True if data is valid */ + HANDLE handle; /* Win32 search handle */ + wchar_t *patt; /* Initial directory name */ +}; +typedef struct _WDIR _WDIR; + +static _WDIR *_wopendir (const wchar_t *dirname); +static struct _wdirent *_wreaddir (_WDIR *dirp); +static int _wclosedir (_WDIR *dirp); +static void _wrewinddir (_WDIR* dirp); + + +/* For compatibility with Symbian */ +#define wdirent _wdirent +#define WDIR _WDIR +#define wopendir _wopendir +#define wreaddir _wreaddir +#define wclosedir _wclosedir +#define wrewinddir _wrewinddir + + +/* Multi-byte character versions */ +struct dirent { + long d_ino; /* Always zero */ + unsigned short d_reclen; /* Structure size */ + size_t d_namlen; /* Length of name without \0 */ + int d_type; /* File type */ + char d_name[PATH_MAX]; /* File name */ +}; +typedef struct dirent dirent; + +struct DIR { + struct dirent ent; + struct _WDIR *wdirp; +}; +typedef struct DIR DIR; + +static DIR *opendir (const char *dirname); +static struct dirent *readdir (DIR *dirp); +static int closedir (DIR *dirp); +static void rewinddir (DIR* dirp); + + +/* Internal utility functions */ +static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp); +static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp); + +static int dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count); + +static int dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, + const wchar_t *wcstr, + size_t count); + +static void dirent_set_errno (int error); + +/* + * Open directory stream DIRNAME for read and return a pointer to the + * internal working area that is used to retrieve individual directory + * entries. + */ +static _WDIR* +_wopendir( + const wchar_t *dirname) +{ + _WDIR *dirp = NULL; + int error; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate new _WDIR structure */ + dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); + if (dirp != NULL) { + DWORD n; + + /* Reset _WDIR structure */ + dirp->handle = INVALID_HANDLE_VALUE; + dirp->patt = NULL; + dirp->cached = 0; + + /* Compute the length of full path plus zero terminator */ + n = GetFullPathNameW (dirname, 0, NULL, NULL); + + /* Allocate room for absolute directory name and search pattern */ + dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); + if (dirp->patt) { + + /* + * Convert relative directory name to an absolute one. This + * allows rewinddir() to function correctly even when current + * working directory is changed between opendir() and rewinddir(). + */ + n = GetFullPathNameW (dirname, n, dirp->patt, NULL); + if (n > 0) { + wchar_t *p; + + /* Append search pattern \* to the directory name */ + p = dirp->patt + n; + if (dirp->patt < p) { + switch (p[-1]) { + case '\\': + case '/': + case ':': + /* Directory ends in path separator, e.g. c:\temp\ */ + /*NOP*/; + break; + + default: + /* Directory name doesn't end in path separator */ + *p++ = '\\'; + } + } + *p++ = '*'; + *p = '\0'; + + /* Open directory stream and retrieve the first entry */ + if (dirent_first (dirp)) { + /* Directory stream opened successfully */ + error = 0; + } else { + /* Cannot retrieve first entry */ + error = 1; + dirent_set_errno (ENOENT); + } + + } else { + /* Cannot retrieve full path name */ + dirent_set_errno (ENOENT); + error = 1; + } + + } else { + /* Cannot allocate memory for search pattern */ + error = 1; + } + + } else { + /* Cannot allocate _WDIR structure */ + error = 1; + } + + /* Clean up in case of error */ + if (error && dirp) { + _wclosedir (dirp); + dirp = NULL; + } + + return dirp; +} + +/* + * Read next directory entry. The directory entry is returned in dirent + * structure in the d_name field. Individual directory entries returned by + * this function include regular files, sub-directories, pseudo-directories + * "." and ".." as well as volume labels, hidden files and system files. + */ +static struct _wdirent* +_wreaddir( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *datap; + struct _wdirent *entp; + + /* Read next directory entry */ + datap = dirent_next (dirp); + if (datap) { + size_t n; + DWORD attr; + + /* Pointer to directory entry to return */ + entp = &dirp->ent; + + /* + * Copy file name as wide-character string. If the file name is too + * long to fit in to the destination buffer, then truncate file name + * to PATH_MAX characters and zero-terminate the buffer. + */ + n = 0; + while (n + 1 < PATH_MAX && datap->cFileName[n] != 0) { + entp->d_name[n] = datap->cFileName[n]; + n++; + } + dirp->ent.d_name[n] = 0; + + /* Length of file name excluding zero terminator */ + entp->d_namlen = n; + + /* File type */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entp->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entp->d_type = DT_DIR; + } else { + entp->d_type = DT_REG; + } + + /* Reset dummy fields */ + entp->d_ino = 0; + entp->d_reclen = sizeof (struct _wdirent); + + } else { + + /* Last directory entry read */ + entp = NULL; + + } + + return entp; +} + +/* + * Close directory stream opened by opendir() function. This invalidates the + * DIR structure as well as any directory entry read previously by + * _wreaddir(). + */ +static int +_wclosedir( + _WDIR *dirp) +{ + int ok; + if (dirp) { + + /* Release search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + dirp->handle = INVALID_HANDLE_VALUE; + } + + /* Release search pattern */ + if (dirp->patt) { + free (dirp->patt); + dirp->patt = NULL; + } + + /* Release directory structure */ + free (dirp); + ok = /*success*/0; + + } else { + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + } + return ok; +} + +/* + * Rewind directory stream such that _wreaddir() returns the very first + * file name again. + */ +static void +_wrewinddir( + _WDIR* dirp) +{ + if (dirp) { + /* Release existing search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + } + + /* Open new search handle */ + dirent_first (dirp); + } +} + +/* Get first directory entry (internal) */ +static WIN32_FIND_DATAW* +dirent_first( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *datap; + + /* Open directory and retrieve the first entry */ + dirp->handle = FindFirstFileW (dirp->patt, &dirp->data); + if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* a directory entry is now waiting in memory */ + datap = &dirp->data; + dirp->cached = 1; + + } else { + + /* Failed to re-open directory: no directory entry in memory */ + dirp->cached = 0; + datap = NULL; + + } + return datap; +} + +/* Get next directory entry (internal) */ +static WIN32_FIND_DATAW* +dirent_next( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *p; + + /* Get next directory entry */ + if (dirp->cached != 0) { + + /* A valid directory entry already in memory */ + p = &dirp->data; + dirp->cached = 0; + + } else if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* Get the next directory entry from stream */ + if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) { + /* Got a file */ + p = &dirp->data; + } else { + /* The very last entry has been processed or an error occured */ + FindClose (dirp->handle); + dirp->handle = INVALID_HANDLE_VALUE; + p = NULL; + } + + } else { + + /* End of directory stream reached */ + p = NULL; + + } + + return p; +} + +/* + * Open directory stream using plain old C-string. + */ +static DIR* +opendir( + const char *dirname) +{ + struct DIR *dirp; + int error; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate memory for DIR structure */ + dirp = (DIR*) malloc (sizeof (struct DIR)); + if (dirp) { + wchar_t wname[PATH_MAX]; + size_t n; + + /* Convert directory name to wide-character string */ + error = dirent_mbstowcs_s (&n, wname, PATH_MAX, dirname, PATH_MAX); + if (!error) { + + /* Open directory stream using wide-character name */ + dirp->wdirp = _wopendir (wname); + if (dirp->wdirp) { + /* Directory stream opened */ + error = 0; + } else { + /* Failed to open directory stream */ + error = 1; + } + + } else { + /* + * Cannot convert file name to wide-character string. This + * occurs if the string contains invalid multi-byte sequences or + * the output buffer is too small to contain the resulting + * string. + */ + error = 1; + } + + } else { + /* Cannot allocate DIR structure */ + error = 1; + } + + /* Clean up in case of error */ + if (error && dirp) { + free (dirp); + dirp = NULL; + } + + return dirp; +} + +/* + * Read next directory entry. + * + * When working with text consoles, please note that file names returned by + * readdir() are represented in the default ANSI code page while any output to + * console is typically formatted on another code page. Thus, non-ASCII + * characters in file names will not usually display correctly on console. The + * problem can be fixed in two ways: (1) change the character set of console + * to 1252 using chcp utility and use Lucida Console font, or (2) use + * _cprintf function when writing to console. The _cprinf() will re-encode + * ANSI strings to the console code page so many non-ASCII characters will + * display correcly. + */ +static struct dirent* +readdir( + DIR *dirp) +{ + WIN32_FIND_DATAW *datap; + struct dirent *entp; + + /* Read next directory entry */ + datap = dirent_next (dirp->wdirp); + if (datap) { + size_t n; + int error; + + /* Attempt to convert file name to multi-byte string */ + error = dirent_wcstombs_s( + &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX); + + /* + * If the file name cannot be represented by a multi-byte string, + * then attempt to use old 8+3 file name. This allows traditional + * Unix-code to access some file names despite of unicode + * characters, although file names may seem unfamiliar to the user. + * + * Be ware that the code below cannot come up with a short file + * name unless the file system provides one. At least + * VirtualBox shared folders fail to do this. + */ + if (error && datap->cAlternateFileName[0] != '\0') { + error = dirent_wcstombs_s( + &n, dirp->ent.d_name, PATH_MAX, + datap->cAlternateFileName, PATH_MAX); + } + + if (!error) { + DWORD attr; + + /* Initialize directory entry for return */ + entp = &dirp->ent; + + /* Length of file name excluding zero terminator */ + entp->d_namlen = n - 1; + + /* File attributes */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entp->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entp->d_type = DT_DIR; + } else { + entp->d_type = DT_REG; + } + + /* Reset dummy fields */ + entp->d_ino = 0; + entp->d_reclen = sizeof (struct dirent); + + } else { + /* + * Cannot convert file name to multi-byte string so construct + * an errornous directory entry and return that. Note that + * we cannot return NULL as that would stop the processing + * of directory entries completely. + */ + entp = &dirp->ent; + entp->d_name[0] = '?'; + entp->d_name[1] = '\0'; + entp->d_namlen = 1; + entp->d_type = DT_UNKNOWN; + entp->d_ino = 0; + entp->d_reclen = 0; + } + + } else { + /* No more directory entries */ + entp = NULL; + } + + return entp; +} + +/* + * Close directory stream. + */ +static int +closedir( + DIR *dirp) +{ + int ok; + if (dirp) { + + /* Close wide-character directory stream */ + ok = _wclosedir (dirp->wdirp); + dirp->wdirp = NULL; + + /* Release multi-byte character version */ + free (dirp); + + } else { + + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + + } + return ok; +} + +/* + * Rewind directory stream to beginning. + */ +static void +rewinddir( + DIR* dirp) +{ + /* Rewind wide-character string directory stream */ + _wrewinddir (dirp->wdirp); +} + +/* Convert multi-byte string to wide character string */ +static int +dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to wide-character string (or count characters) */ + n = mbstowcs (wcstr, mbstr, sizeInWords); + if (!wcstr || n < count) { + + /* Zero-terminate output buffer */ + if (wcstr && sizeInWords) { + if (n >= sizeInWords) { + n = sizeInWords - 1; + } + wcstr[n] = 0; + } + + /* Length of resuting multi-byte string WITH zero terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Could not convert string */ + error = 1; + + } + +#endif + + return error; +} + +/* Convert wide-character string to multi-byte string */ +static int +dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, /* max size of mbstr */ + const wchar_t *wcstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to multi-byte string (or count the number of bytes needed) */ + n = wcstombs (mbstr, wcstr, sizeInBytes); + if (!mbstr || n < count) { + + /* Zero-terminate output buffer */ + if (mbstr && sizeInBytes) { + if (n >= sizeInBytes) { + n = sizeInBytes - 1; + } + mbstr[n] = '\0'; + } + + /* Lenght of resulting multi-bytes string WITH zero-terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Cannot convert string */ + error = 1; + + } + +#endif + + return error; +} + +/* Set errno variable */ +static void +dirent_set_errno( + int error) +{ +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 and later */ + _set_errno (error); + +#else + + /* Non-Microsoft compiler or older Microsoft compiler */ + errno = error; + +#endif +} + + +#ifdef __cplusplus +} +#endif +#endif /*DIRENT_H*/ + diff --git a/3rdparty/bx/include/tinystl/string.h b/3rdparty/bx/include/tinystl/string.h index 5397c98bb80..4d90c2ae4c0 100644 --- a/3rdparty/bx/include/tinystl/string.h +++ b/3rdparty/bx/include/tinystl/string.h @@ -27,6 +27,7 @@ #ifndef TINYSTL_STRING_H #define TINYSTL_STRING_H +#include <string.h> // strlen #include "stddef.h" #include "hash.h" diff --git a/3rdparty/bx/scripts/toolchain.lua b/3rdparty/bx/scripts/toolchain.lua index 358bfbc9b50..0422db1105b 100644 --- a/3rdparty/bx/scripts/toolchain.lua +++ b/3rdparty/bx/scripts/toolchain.lua @@ -46,6 +46,8 @@ function toolchain(_buildDir, _libDir) { "vs2015-xp", "Visual Studio 2015 targeting XP" }, { "winphone8", "Windows Phone 8.0" }, { "winphone81", "Windows Phone 8.1" }, + { "winstore81", "Windows Store 8.1" }, + { "winstore82", "Universal Windows App" } }, } @@ -281,9 +283,22 @@ function toolchain(_buildDir, _libDir) elseif "winphone81" == _OPTIONS["vs"] then premake.vstudio.toolset = "v120_wp81" + premake.vstudio.storeapp = "8.1" platforms { "ARM" } location (path.join(_buildDir, "projects", _ACTION .. "-winphone81")) + elseif "winstore81" == _OPTIONS["vs"] then + premake.vstudio.toolset = "v120" + premake.vstudio.storeapp = "8.1" + platforms { "ARM" } + location (path.join(_buildDir, "projects", _ACTION .. "-winstore81")) + + elseif "winstore82" == _OPTIONS["vs"] then + premake.vstudio.toolset = "v140" + premake.vstudio.storeapp = "8.2" + platforms { "ARM" } + location (path.join(_buildDir, "projects", _ACTION .. "-winstore82")) + elseif ("vs2012-xp") == _OPTIONS["vs"] then premake.vstudio.toolset = ("v110_xp") location (path.join(_buildDir, "projects", _ACTION .. "-xp")) @@ -334,7 +349,7 @@ function toolchain(_buildDir, _libDir) } targetsuffix "Release" - configuration { "vs*", "x86" } + configuration { "vs*", "x32" } flags { "EnableSSE2", } @@ -397,7 +412,7 @@ function toolchain(_buildDir, _libDir) targetdir (path.join(_buildDir, "win64_" .. _ACTION .. "-clang/bin")) objdir (path.join(_buildDir, "win64_" .. _ACTION .. "-clang/obj")) - configuration { "winphone8*" } + configuration { "winphone8* or winstore8*" } removeflags { "StaticRuntime", "NoExceptions", diff --git a/3rdparty/bx/tests/float4_t.cpp b/3rdparty/bx/tests/float4_t.cpp index a9a15af1737..04a060405c0 100644 --- a/3rdparty/bx/tests/float4_t.cpp +++ b/3rdparty/bx/tests/float4_t.cpp @@ -228,6 +228,11 @@ TEST(float4_arithmetic) , float4_madd(float4_ld(0.0f, 1.0f, 2.0f, 3.0f), float4_ld(4.0f, 5.0f, 6.0f, 7.0f), float4_ld(8.0f, 9.0f, 10.0f, 11.0f) ) , 8.0f, 14.0f, 22.0f, 32.0f ); + + float4_check_float("cross3" + , float4_cross3(float4_ld(1.0f, 0.0f, 0.0f, 0.0f), float4_ld(0.0f, 1.0f, 0.0f, 0.0f) ) + , 0.0f, 0.0f, 1.0f, 0.0f + ); } TEST(float4) diff --git a/3rdparty/bx/tools/bin/darwin/genie b/3rdparty/bx/tools/bin/darwin/genie Binary files differindex 2d6bd49e5b0..37ee10c896c 100644 --- a/3rdparty/bx/tools/bin/darwin/genie +++ b/3rdparty/bx/tools/bin/darwin/genie diff --git a/3rdparty/bx/tools/bin/linux/genie b/3rdparty/bx/tools/bin/linux/genie Binary files differindex 9e1c5a8ebb0..703dda3c553 100644 --- a/3rdparty/bx/tools/bin/linux/genie +++ b/3rdparty/bx/tools/bin/linux/genie diff --git a/3rdparty/bx/tools/bin/windows/genie.exe b/3rdparty/bx/tools/bin/windows/genie.exe Binary files differindex 8b788066d1c..7bb0013a709 100644 --- a/3rdparty/bx/tools/bin/windows/genie.exe +++ b/3rdparty/bx/tools/bin/windows/genie.exe |