@@ -158,6 +158,10 @@ void ImGuiRenderer::renderDrawList(ImDrawData *draw_data)
158
158
glUniformMatrix4fv (g_AttribLocationProjMtx, 1 , GL_FALSE, &ortho_projection[0 ][0 ]);
159
159
glBindVertexArray (g_VaoHandle);
160
160
161
+ // Will project scissor/clipping rectangles into framebuffer space
162
+ ImVec2 clip_off = draw_data->DisplayPos ; // (0,0) unless using multi-viewports
163
+ ImVec2 clip_scale = draw_data->FramebufferScale ; // (1,1) unless using retina display which are often (2,2)
164
+
161
165
for (int n = 0 ; n < draw_data->CmdListsCount ; n++)
162
166
{
163
167
const ImDrawList* cmd_list = draw_data->CmdLists [n];
@@ -178,11 +182,19 @@ void ImGuiRenderer::renderDrawList(ImDrawData *draw_data)
178
182
}
179
183
else
180
184
{
185
+ // Project scissor/clipping rectangles into framebuffer space
186
+ ImVec2 clip_min ((pcmd->ClipRect .x - clip_off.x ) * clip_scale.x , (pcmd->ClipRect .y - clip_off.y ) * clip_scale.y );
187
+ ImVec2 clip_max ((pcmd->ClipRect .z - clip_off.x ) * clip_scale.x , (pcmd->ClipRect .w - clip_off.y ) * clip_scale.y );
188
+ if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y )
189
+ continue ;
190
+
191
+ // Apply scissor/clipping rectangle (Y is inverted in OpenGL)
192
+ glScissor ((int )clip_min.x , (int )(fb_height - clip_max.y ), (int )(clip_max.x - clip_min.x ), (int )(clip_max.y - clip_min.y ));
193
+
194
+ // Bind texture, Draw
181
195
glBindTexture (GL_TEXTURE_2D, (GLuint)(size_t )pcmd->TextureId );
182
- glScissor ((int )pcmd->ClipRect .x , (int )(fb_height - pcmd->ClipRect .w ), (int )(pcmd->ClipRect .z - pcmd->ClipRect .x ), (int )(pcmd->ClipRect .w - pcmd->ClipRect .y ));
183
- glDrawElements (GL_TRIANGLES, (GLsizei)pcmd->ElemCount , sizeof (ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
196
+ glDrawElements (GL_TRIANGLES, (GLsizei)pcmd->ElemCount , sizeof (ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset + pcmd->IdxOffset );
184
197
}
185
- idx_buffer_offset += pcmd->ElemCount ;
186
198
}
187
199
}
188
200
0 commit comments