@@ -303,6 +303,66 @@ void RenderedTarget::paintSvg(QNanoPainter *painter)
303303 context->makeCurrent (oldSurface);
304304}
305305
306+ void RenderedTarget::updateHullPoints (QOpenGLFramebufferObject *fbo)
307+ {
308+ if (m_stageModel)
309+ return ; // hull points are useless for the stage
310+
311+ Q_ASSERT (fbo);
312+ int width = fbo->width ();
313+ int height = fbo->height ();
314+ m_hullPoints.clear ();
315+ m_hullPoints.reserve (width * height);
316+
317+ // Blit multisampled FBO to a custom FBO
318+ QOpenGLFramebufferObject customFbo (fbo->size ());
319+ glBindFramebuffer (GL_READ_FRAMEBUFFER_EXT, fbo->handle ());
320+ glBindFramebuffer (GL_DRAW_FRAMEBUFFER_EXT, customFbo.handle ());
321+ glBlitFramebuffer (0 , 0 , width, height, 0 , 0 , width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
322+ glBindFramebuffer (GL_FRAMEBUFFER_EXT, customFbo.handle ());
323+
324+ // Read pixels from framebuffer
325+ size_t size = width * height * 4 ;
326+ GLubyte *pixelData = new GLubyte[size];
327+ glReadPixels (0 , 0 , width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
328+ glBindFramebuffer (GL_FRAMEBUFFER_EXT, 0 );
329+ fbo->bind ();
330+
331+ // Flip vertically
332+ int rowSize = width * 4 ;
333+ GLubyte *tempRow = new GLubyte[rowSize];
334+
335+ for (size_t i = 0 ; i < height / 2 ; ++i) {
336+ size_t topRowIndex = i * rowSize;
337+ size_t bottomRowIndex = (height - 1 - i) * rowSize;
338+
339+ // Swap rows
340+ memcpy (tempRow, &pixelData[topRowIndex], rowSize);
341+ memcpy (&pixelData[topRowIndex], &pixelData[bottomRowIndex], rowSize);
342+ memcpy (&pixelData[bottomRowIndex], tempRow, rowSize);
343+ }
344+
345+ delete[] tempRow;
346+
347+ // Fill hull points vector
348+ for (int y = 0 ; y < height; y++) {
349+ for (int x = 0 ; x < width; x++) {
350+ int index = (y * width + x) * 4 ; // RGBA channels
351+
352+ // Check alpha channel
353+ if (pixelData[index + 3 ] > 0 )
354+ m_hullPoints.push_back (QPointF (x, y));
355+ }
356+ }
357+
358+ delete[] pixelData;
359+ }
360+
361+ const std::vector<QPointF> &RenderedTarget::hullPoints () const
362+ {
363+ return m_hullPoints;
364+ }
365+
306366void RenderedTarget::calculateSize (Target *target, double costumeWidth, double costumeHeight)
307367{
308368 if (m_costume) {
0 commit comments