MCPcopy Create free account
hub / github.com/SFML/imgui-sfml / RenderDrawLists

Function RenderDrawLists

imgui-SFML.cpp:947–1076  ·  view source on GitHub ↗

Rendering callback

Source from the content-addressed store, hash-verified

945
946// Rendering callback
947void RenderDrawLists(ImDrawData* draw_data)
948{
949 ImGui::GetDrawData();
950 if (draw_data->CmdListsCount == 0)
951 {
952 return;
953 }
954
955 const ImGuiIO& io = ImGui::GetIO();
956 assert(io.Fonts->TexID != (ImTextureID) nullptr); // You forgot to create and set font texture
957
958 // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates !=
959 // framebuffer coordinates)
960 const int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
961 const int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
962 if (fb_width == 0 || fb_height == 0)
963 return;
964 draw_data->ScaleClipRects(io.DisplayFramebufferScale);
965
966 // Backup GL state
967 // Backup GL state
968 GLint last_texture = 0;
969 glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
970 GLint last_polygon_mode[2];
971 glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
972 GLint last_viewport[4];
973 glGetIntegerv(GL_VIEWPORT, last_viewport);
974 GLint last_scissor_box[4];
975 glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
976 GLint last_shade_model = 0;
977 glGetIntegerv(GL_SHADE_MODEL, &last_shade_model);
978 GLint last_tex_env_mode = 0;
979 glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_tex_env_mode);
980
981#ifdef GL_VERSION_ES_CL_1_1
982 GLint last_array_buffer;
983 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
984 GLint last_element_array_buffer;
985 glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);
986#else
987 glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
988#endif
989
990 // Setup desired GL state
991 SetupRenderState(draw_data, fb_width, fb_height);
992
993 // Will project scissor/clipping rectangles into framebuffer space
994 const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
995 const ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display
996 // which are often (2,2)
997
998 // Render command lists
999 for (int n = 0; n < draw_data->CmdListsCount; n++)
1000 {
1001 const ImDrawList* cmd_list = draw_data->CmdLists[n];
1002 const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
1003 const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
1004 glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, pos)));

Callers 1

RenderFunction · 0.85

Calls 2

SetupRenderStateFunction · 0.85

Tested by

no test coverage detected