简体   繁体   English

复制fbo图像时内存泄漏

[英]Memory leak while copy fbo image

As you can see in the Image I've a memory leak while copying the fbo to a QImage . 正如您在图像中看到的那样,在将fbo复制到QImage时会出现内存泄漏。 Anyone out there who knows a possible solution? 谁知道可能的解决方案?

在此输入图像描述

QOpenGLFramebufferObject *fbo;

void GLANN::render(){

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        // Set random seed
        //program.setUniformValue("seedX", ((float)qrand()/RAND_MAX));
        //program.setUniformValue("seedY", ((float)qrand()/RAND_MAX));

        //Set number of alredy rendered passes
        //program.setUniformValue("numRenderPass",mRenderPasses);

        //Set program to fbo render mode
        program.setUniformValue("fbo",true);

        //Bind last rendered Image
        //pixelsRenderedImage = bindTexture(*renderedImage);

        //Load Identity
        //glLoadIdentity();

        //Move to rendering point
        //glTranslatef( -1.0, -1.0, 0.0f );

        // Draw geometry
        // Tell OpenGL which VBOs to use

         // Render to our framebuffer
         fbo->bind();
         glViewport(0,0,TexWidth,TexHeight);

         // Tell OpenGL which VBOs to use
         glBindBuffer(GL_ARRAY_BUFFER, vboId0);
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId1);

         // Offset for position
         int offset = 0;

         // Tell OpenGL programmable pipeline how to locate vertex position data
         int vertexLocation = program.attributeLocation("a_position");
         program.enableAttributeArray(vertexLocation);
         glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);

         // Offset for texture coordinate
         offset += sizeof(QVector3D);

         // Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
         int texcoordLocation = program.attributeLocation("a_texcoord");
         program.enableAttributeArray(texcoordLocation);
         glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);

         //glEnable(GL_TEXTURE_2D);

         glActiveTexture(GL_TEXTURE0);
         glBindTexture(GL_TEXTURE_2D, pixelsRenderedImage);

         // Draw cube geometry using indices from VBO 1
         glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, 0);

//         qDebug() << glGetError() << "Line 183";

         fbo->release();

     renderedImage.~QImage();
     renderedImage = QImage();
     renderedImage = fbo->toImage().copy();
     pixelsRenderedImage = QGLWidget::bindTexture(renderedImage);
     //Set Program to screen frendering
     program.setUniformValue("fbo",false);
     //Set Viewport back to default
     glViewport(0,0,width,height);
     //Render To Screen
     //glEnable(GL_TEXTURE_2D);
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_2D, pixelsRenderedImage);

     // Draw quad geometry using indices from VBO 1
     glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, 0);


}

Found the bug in the part of "bindTexture". 在“bindTexture”部分找到了错误。

Added: 添加:

 glDeleteTextures(1,&pixelsRenderedImage);

solved the problem. 解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM