forked from Green-Sky/tomato
Green Sky
1dccce8097
070c046cd1f Internals: rename recently added TreeNodeIsOpen() -> TreeNodeGetOpen(). (#7553, #1131, #2958, #2079, #722) 7c6d4ff28de TreeNode: Internals: facilitate dissociating item ID from storage ID (useful for 1861) 8bab3eab6a8 Clipper: added SeekCursorForItem() function, for use when using ImGuiListClipper::Begin(INT_MAX). (#1311) 74a1854db9a Nav, Demo: comments. 669021be4cd Style: close button and collapse/window-menu button hover highlight made rectangular instead of round. 67e9aa4d3df Demo: Property Editor: add basic filter. 4247f190c23 Demo: Property Editor: rearrange code + replace use of bool to proper ImGuiChildFlags. 9c1f922b02b Fixed pvs-studio warning. 0e4dcfa5529 Obsoleted PushTabStop()/PopTabStop() in favor of using new PushItemFlag()/PopItemFlag() with ImGuiItemFlags_NoTabStop. 3de75138d1c (Breaking) Renamed ImGuiSelectableFlags_DontClosePopups to ImGuiSelectableFlags_NoAutoClosePopups. (#1379, #1468, #2200, #4936, #5216, #7302, #7573) 0de88a928d7 Added ImGuiItemFlags_AutoClosePopups as a replacement for internal's ImGuiItemFlags_SelectableDontClosePopup. (#1379, #1468, #2200, #4936, #5216, #7302, #7573) b4ca869c407 (Breaking) Obsoleted PushButtonRepeat()/PopButtonRepeat() in favor of using new PushItemFlag()/PopItemFlag() with ImGuiItemFlags_ButtonRepeat. 7e0800e7186 Added PushItemFlag(), PopItemFlag(), ImGuiItemFlags. 46691d172ec Demo: Reworked "Property Editor" demo in a manner that more ressemble the tree data and struct description data that a real application would want to use. bc9e5b62b6b Added ImGuiDataType_Bool for convenience. ac7d6fb5ca0 Internals: Added TreeNodeIsOpen() to facilitate discoverability. (#7553, #1131, #2958, #2079, #722) 9c2f6003e4f Backends: SDL3: fixed typo leading to PlatformHandleRaw not being set leading to SHOWNA path not working for multi-viewports. df3a74389e8 Backends: SDL3: Update for API changes: SDL_GetProperty() change to SDL_GetPointerProperty(). (#7794) 126569ad5b3 Fix definition check (#7793) c3c90b49e03 Examples: SDL3+OpenGL: Update for API changes: SDL_GL_DeleteContext() renamed to SDL_GL_DestroyContext(). a8e96ae21a4 Backends: GLFW+Emscripten: Fixed build (#7647) 2937339c175 Backends: GLFW+Emscripten: Added support for GLFW3 contrib port. (#7647) 6816789a6b0 Backends: GLFW+Emscripten: (Breaking) Renamed ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback() to ImGui_ImplGlfw_InstallEmscriptenCallbacks(), added GLFWwindow* parameter. (#7647, #7600) 9504068f66c Backends: Win32: fixed ImGuiMod_Super being mapped to VK_APPS instead of VK_LWIN||VK_RWIN (#7768, #4858, #2622) 6b6026b1332 DemosFix typo in help text in demo Tables/Borders (#7780) 1ec1f7a3de2 Fixed Unix version of PlatformOpenInShellFn_DefaultImpl. (#7772, #7660) 2d0baaabe62 TreeNode: rename/rework ImGuiNavTreeNodeData system to be usable by more features. (#2920, #1131, #7553) 0a73c6ec3f6 Misc tweaks, comments. 0ebf49b4c1f IO: amend PlatformOpenInShellFn specs to return a bool. (#7660) 380b3559c6d Backends: GLFW,SDL2: Added ioPlatformOpenInShellFn handler for web/Emscripten versions. (#7660) 05a4f280596 Internals: added FontScale storage (amend 0f63d3e). 5496050f5f2 Added TextLink(), TextLinkOpenURL() hyperlink widgets. (#7660) 0f63d3e9164 Internals: added FontScale storage. dadf9cd039b IO: disable default io.PlatformOpenInShellFn() implementation on iPhone, as compiler errors that system() is not available on iOS. 43925b9fa4c Build fix for non Windows platforms. ddd4c9d6b95 Commented out obsolete ImGuiModFlags and ImGuiModFlags_XXX values (renamed to ImGuiKeyChord and ImGuiMod_XXX in 1.89). (#4921, #456) fb799bba7fd (Breaking) IO, IME: renamed platform IME hook io.SetPlatformImeDataFn() -> io.PlatformSetImeDataFn() and added explicit context. 8f367980357 IO: added io.PlatformOpenInShellFn handler to open a link/folder/file in OS shell, added IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS. (#7660) 0250dc903ef Demo: changed style editor inline block to its own window. ae708e3bcd7 Backends: SDL3: add default case to fix warnings. (#7763) 7e0b3b9caf8 Debug Log: Added "Configure Outputs.." button. (#5855) a62794359aa Debug Tools: Added IMGUI_DEBUG_LOG(), ImGui::DebugLog() in public API. (#5855) a489585f843 Backends: SDL3: Updated comments (IME seems fixed in SDL3). Added SDL3 examples to Visual Studio solution. 12f92518bc5 Backends: SDL3: Update for API changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762) 84cc72f3720 Version 1.91.0 WIP cb16be3a3fc Version 1.90.9 c554c402d30 IO: do not claim io.WantCaptureMouse=true on the mouse release frame of a button which was pressed over void. (#1392) 50a0f18e6ae imgui_freetype: fixed divide by zero while handling FT_PIXEL_MODE_BGRA glyphs. (#7267, #3369) dd5c30d2d75 Disabled: Reworked 1.90.8 behavior of Begin() not inheriting current BeginDisabled() state. Only tooltip are clearing that state. (#211, #7640) 67216910fb0 Examples: SDL3: Remove use of SDL_HINT_IME_NATIVE_UI. ccf3ee674a0 Backends: SDL3: update for SDL_SetTextInputRect() -> SDL_SetTextInputArea() api change. (#7760, #7754) 751bbf38ba5 Backends: SDLRenderer3: Update for SDL_RenderGeometryRaw() API changes. f2c07ed7175 Backends: Allegro5: Correctly handle unstable bit in version checks (#7755) c47928ffc0f Checkbox: minor tidying up to simplify work on multi-select branch. 372eebbeb29 Fix typo, rename ImGuisliderFlags_WrapAround flag to ImGuiSliderFlags_WrapAround. (#7752, #7749) 0403096a9d3 Drags: added ImGuisliderFlags_WrapAround flag for DragInt(), DragFloat() etc. (#7749) c7df9c71214 Backends: Win32: Fixed warning with old MinGW/GCC versions. 404af570049 Backends: OpenGL2, OpenGL3: ImGui_ImplOpenGL3_NewFrame() recreates font texture if it has been destroyed by ImGui_ImplOpenGL3_DestroyFontsTexture(). (#7748) 0582f7678a4 Nav: store NavJustMovedToIsTabbing + shuffle a few nav related fields. 77d582fa37b Windows: BeginChild(): fixed a glitch when during a resize of a child window which is tightly close to the boundaries of its parent. (#7706) 953d40c929f Tables: moved TableGetHoveredColumn() to public API. (#7715, #3740) fbb903e1580 Inputs: fixed using Shortcut() or SetNextItemShortcut() within a disabled block bypassing the disabled state. (#7726) dbffb702f83 ImGuiStorage: tweak impl for BuildSortByKey(). 0c2650e8339 Backends: OSX: build fix. Amend 32f9dfc 22b36bef9e6 Examples: undo adding SDL3 example to Visual Studio sln. 7c2476986b5 Backends: SDL3: Update for SDL_StartTextInput()/SDL_StopTextInput() API changes. (#7735) 32f9dfc1261 Viewports: Backported 'void* ImGuiViewport::PlatformHandle' from docking branch for use by backends. eb1cc4b8b4e Metrics/Debugger: Browsing a Storage perform hover lookup on identifier. a18fb406ace Backends: Vulkan: Remove Volk/ from volk.h #include directives (#7722, #6582, #4854) aab27130a61 Demo: Style Editor: clarify how _CalcCircleAutoSegmentCount() doesn't always get exact final segment count. (#7731) 48e7e7bfe85 Backends: SDL3: Follow SDL3 removal of keysym field in SDL_KeyboardEvent (#7729) 755bf2b8c2e (Breaking) Move ImGuiWindowFlags_NavFlattened to ImGuiChildFlags_NavFlattened. (#7687) 2c8cc58fd16 Internals: storing HoveredWindowBeforeClear for use by multi-context compositor drag and drop propagation. 7f20a4b0415 Nav: CTRL+Tab overlay display context name if any. e3971079cf5 IO: added ImGuiConfigFlags_NoKeyboard for consistency and convenience. (#4921) 8067d05f744 IO: added ClearInputMouse(). made ClearInputKeys() not clear mouse data. (#4921) 21581cf70ce Fixed build warning. 7e7c97ac5f9 Ignore .ini file with other suffixes. 77d9f80754e Drag and Drop: Added ImGuiDragDropFlags_PayloadNoCrossContext and ImGuiDragDropFlags_PayloadNoCrossProcess flags. 8c318dc7702 Drag and Drop: (Breaking) renamed ImGuiDragDropFlags_SourceAutoExpirePayload to ImGuiDragDropFlags_PayloadAutoExpire. (#1725, #143) 50709454b3f Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceExtern assume a mouse button being pressed. (#143) 413c056359b Drag and Drop: comments, debug log entries. 37c243bb35a Internals: added ImGuiContext::ContextName optionally used by debug log and to facilitate debugging. 8c517fee357 Drag and Drop: Fixes an issue when elapsing payload would be based on last payload frame instead of last drag source frame. 32a037c030f Drag and Drop: BeginDragDropSource() with ImGuiDragDropFlags_SourceExtern. (#143) 21bda2ed994 TabBar, Style: added ImGuiTabBarFlags_DrawSelectedOverline and ImGuiCol_TabSelectedOverline, ImGuiCol_TabDimmedSelectedOverline. 1b9593e8894 Style: (Breaking) renamed ImGuiCol_TabActive -> ImGuiCol_TabSelected, ImGuiCol_TabUnfocused -> ImGuiCol_TabDimmed, ImGuiCol_TabUnfocusedActive -> ImGuiCol_TabDimmedSelected. b902fa4c449 IO: do not disable io.ConfigWindowsResizeFromEdges when ImGuiBackendFlags_HasMouseCursors is not set by backend. 8caf7afbad6 Internals: made ImLowerBound() accessible in internals + take a span. + rearrange child/popup/tooltips section. 22d65c7949d Removed old nested structure: renaming ImGuiStorage::ImGuiStoragePair type to ImGuiStoragePair (simpler for many languages). 7538ca6f405 Examples: SDL+Vulkan: handle swap chain resize even without Vulkan returning VK_SUBOPTIMAL_KHR (#7671) a47bfb1b5b1 Examples: GLFW+Vulkan: handle swap chain resize even without Vulkan returning VK_SUBOPTIMAL_KHR (#7671) d46a0aa0693 Internals: renamed HoveredIdDisabled to HoveredIdIsDisabled for consistency. 7260bb51cfc Version 1.90.9 WIP git-subtree-dir: external/imgui/imgui git-subtree-split: 070c046cd1fcbe694e3f19e2f5eaff9df0cb6357
307 lines
15 KiB
C++
307 lines
15 KiB
C++
// dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline)
|
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
|
|
|
// Implemented features:
|
|
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
|
|
|
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
|
// Learn about Dear ImGui:
|
|
// - FAQ https://dearimgui.com/faq
|
|
// - Getting Started https://dearimgui.com/getting-started
|
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
|
// - Introduction, links and more at the top of imgui.cpp
|
|
|
|
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
|
|
// **Prefer using the code in imgui_impl_opengl3.cpp**
|
|
// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
|
|
// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
|
|
// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
|
|
// confuse your GPU driver.
|
|
// The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
|
|
|
|
// CHANGELOG
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
// 2024-06-28: OpenGL: ImGui_ImplOpenGL2_NewFrame() recreates font texture if it has been destroyed by ImGui_ImplOpenGL2_DestroyFontsTexture(). (#7748)
|
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
// 2021-12-08: OpenGL: Fixed mishandling of the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
|
|
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
|
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
// 2021-01-03: OpenGL: Backup, setup and restore GL_SHADE_MODEL state, disable GL_STENCIL_TEST and disable GL_NORMAL_ARRAY client state to increase compatibility with legacy OpenGL applications.
|
|
// 2020-01-23: OpenGL: Backup, setup and restore GL_TEXTURE_ENV to increase compatibility with legacy OpenGL applications.
|
|
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
|
|
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
// 2018-08-03: OpenGL: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications.
|
|
// 2018-06-08: Misc: Extracted imgui_impl_opengl2.cpp/.h away from the old combined GLFW/SDL+OpenGL2 examples.
|
|
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
|
|
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplOpenGL2_RenderDrawData() in the .h file so you can call it yourself.
|
|
// 2017-09-01: OpenGL: Save and restore current polygon mode.
|
|
// 2016-09-10: OpenGL: Uploading font texture as RGBA32 to increase compatibility with users shaders (not ideal).
|
|
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
|
|
|
|
#include "imgui.h"
|
|
#ifndef IMGUI_DISABLE
|
|
#include "imgui_impl_opengl2.h"
|
|
#include <stdint.h> // intptr_t
|
|
|
|
// Clang/GCC warnings with -Weverything
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used
|
|
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
|
|
#endif
|
|
|
|
// Include OpenGL header (without an OpenGL loader) requires a bit of fiddling
|
|
#if defined(_WIN32) && !defined(APIENTRY)
|
|
#define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY.
|
|
#endif
|
|
#if defined(_WIN32) && !defined(WINGDIAPI)
|
|
#define WINGDIAPI __declspec(dllimport) // Some Windows OpenGL headers need this
|
|
#endif
|
|
#if defined(__APPLE__)
|
|
#define GL_SILENCE_DEPRECATION
|
|
#include <OpenGL/gl.h>
|
|
#else
|
|
#include <GL/gl.h>
|
|
#endif
|
|
|
|
struct ImGui_ImplOpenGL2_Data
|
|
{
|
|
GLuint FontTexture;
|
|
|
|
ImGui_ImplOpenGL2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
|
};
|
|
|
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData()
|
|
{
|
|
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
}
|
|
|
|
// Functions
|
|
bool ImGui_ImplOpenGL2_Init()
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
IMGUI_CHECKVERSION();
|
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
|
|
// Setup backend capabilities flags
|
|
ImGui_ImplOpenGL2_Data* bd = IM_NEW(ImGui_ImplOpenGL2_Data)();
|
|
io.BackendRendererUserData = (void*)bd;
|
|
io.BackendRendererName = "imgui_impl_opengl2";
|
|
|
|
return true;
|
|
}
|
|
|
|
void ImGui_ImplOpenGL2_Shutdown()
|
|
{
|
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
ImGui_ImplOpenGL2_DestroyDeviceObjects();
|
|
io.BackendRendererName = nullptr;
|
|
io.BackendRendererUserData = nullptr;
|
|
IM_DELETE(bd);
|
|
}
|
|
|
|
void ImGui_ImplOpenGL2_NewFrame()
|
|
{
|
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL2_Init()?");
|
|
|
|
if (!bd->FontTexture)
|
|
ImGui_ImplOpenGL2_CreateDeviceObjects();
|
|
if (!bd->FontTexture)
|
|
ImGui_ImplOpenGL2_CreateFontsTexture();
|
|
}
|
|
|
|
static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
|
|
{
|
|
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
//glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // In order to composite our output buffer we need to preserve alpha
|
|
glDisable(GL_CULL_FACE);
|
|
glDisable(GL_DEPTH_TEST);
|
|
glDisable(GL_STENCIL_TEST);
|
|
glDisable(GL_LIGHTING);
|
|
glDisable(GL_COLOR_MATERIAL);
|
|
glEnable(GL_SCISSOR_TEST);
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
glDisableClientState(GL_NORMAL_ARRAY);
|
|
glEnable(GL_TEXTURE_2D);
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
glShadeModel(GL_SMOOTH);
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
// If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
|
|
// you may need to backup/reset/restore other state, e.g. for current shader using the commented lines below.
|
|
// (DO NOT MODIFY THIS FILE! Add the code in your calling function)
|
|
// GLint last_program;
|
|
// glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
|
// glUseProgram(0);
|
|
// ImGui_ImplOpenGL2_RenderDrawData(...);
|
|
// glUseProgram(last_program)
|
|
// There are potentially many more states you could need to clear/setup that we can't access from default headers.
|
|
// e.g. glBindBuffer(GL_ARRAY_BUFFER, 0), glDisable(GL_TEXTURE_CUBE_MAP).
|
|
|
|
// Setup viewport, orthographic projection matrix
|
|
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
|
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glPushMatrix();
|
|
glLoadIdentity();
|
|
glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glPushMatrix();
|
|
glLoadIdentity();
|
|
}
|
|
|
|
// OpenGL2 Render function.
|
|
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
|
|
// This is in order to be able to run within an OpenGL engine that doesn't do so.
|
|
void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
|
|
{
|
|
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
|
|
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
|
|
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
|
|
if (fb_width == 0 || fb_height == 0)
|
|
return;
|
|
|
|
// Backup GL state
|
|
GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
|
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
|
|
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
|
|
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
|
|
GLint last_shade_model; glGetIntegerv(GL_SHADE_MODEL, &last_shade_model);
|
|
GLint last_tex_env_mode; glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_tex_env_mode);
|
|
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
|
|
|
|
// Setup desired GL state
|
|
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
|
|
|
// Will project scissor/clipping rectangles into framebuffer space
|
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
|
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
|
|
|
// Render command lists
|
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
|
{
|
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
|
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
|
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
|
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, pos)));
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, uv)));
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, col)));
|
|
|
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
{
|
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
if (pcmd->UserCallback)
|
|
{
|
|
// User callback, registered via ImDrawList::AddCallback()
|
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
|
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
|
|
else
|
|
pcmd->UserCallback(cmd_list, pcmd);
|
|
}
|
|
else
|
|
{
|
|
// Project scissor/clipping rectangles into framebuffer space
|
|
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
|
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
|
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
|
|
continue;
|
|
|
|
// Apply scissor/clipping rectangle (Y is inverted in OpenGL)
|
|
glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y));
|
|
|
|
// Bind texture, Draw
|
|
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID());
|
|
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Restore modified GL state
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glPopMatrix();
|
|
glMatrixMode(GL_PROJECTION);
|
|
glPopMatrix();
|
|
glPopAttrib();
|
|
glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]);
|
|
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
|
|
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
|
|
glShadeModel(last_shade_model);
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_tex_env_mode);
|
|
}
|
|
|
|
bool ImGui_ImplOpenGL2_CreateFontsTexture()
|
|
{
|
|
// Build texture atlas
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
unsigned char* pixels;
|
|
int width, height;
|
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
|
|
|
|
// Upload texture to graphics system
|
|
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
|
GLint last_texture;
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
|
glGenTextures(1, &bd->FontTexture);
|
|
glBindTexture(GL_TEXTURE_2D, bd->FontTexture);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
|
|
|
// Store our identifier
|
|
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
|
|
|
|
// Restore state
|
|
glBindTexture(GL_TEXTURE_2D, last_texture);
|
|
|
|
return true;
|
|
}
|
|
|
|
void ImGui_ImplOpenGL2_DestroyFontsTexture()
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
|
|
if (bd->FontTexture)
|
|
{
|
|
glDeleteTextures(1, &bd->FontTexture);
|
|
io.Fonts->SetTexID(0);
|
|
bd->FontTexture = 0;
|
|
}
|
|
}
|
|
|
|
bool ImGui_ImplOpenGL2_CreateDeviceObjects()
|
|
{
|
|
return ImGui_ImplOpenGL2_CreateFontsTexture();
|
|
}
|
|
|
|
void ImGui_ImplOpenGL2_DestroyDeviceObjects()
|
|
{
|
|
ImGui_ImplOpenGL2_DestroyFontsTexture();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic pop
|
|
#endif
|
|
|
|
#endif // #ifndef IMGUI_DISABLE
|