Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Delete TexBuffer ?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Location
    Paris
    Posts
    17

    Delete TexBuffer ?

    Hi,
    Recently I made a simple OpenGL program that works.

    Today, I decided to copy this code in another new project, in order to re-use it.

    The surprise is that this same code is not working.
    Code :
        // Create the VAOs used for the update and render passes
        glGenVertexArrays(2, update_vao);
        glGenVertexArrays(2, render_vao);
     
    	// Two buffers for each of position and velocity
        glGenBuffers(2, position_buffer);
     
    	// Setup Update VAO 1
    	glBindVertexArray(update_vao[0]);
    		glBindBuffer(GL_ARRAY_BUFFER, position_buffer[0]);
    		glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), positions.constData(), GL_DYNAMIC_COPY);
    		glEnableVertexAttribArray(0);
    		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    	// Setup Update VAO 2
        glBindVertexArray(update_vao[1]);
    		glBindBuffer(GL_ARRAY_BUFFER, position_buffer[1]);
    		glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), NULL, GL_DYNAMIC_COPY);
    		glEnableVertexAttribArray(0);
    		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
     
    	// Setup Render VAOs
        for (int i = 0; i < 2; i++)
        {
            glBindVertexArray(render_vao[i]);
    			glBindBuffer(GL_ARRAY_BUFFER, position_buffer[i]);
    			glEnableVertexAttribArray(0);
    			glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
     
    			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem_array);
    			glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(GL_FLOAT), elements.constData(), GL_STATIC_DRAW);
        }
     
    	// Setup position and velocity TBOs
        glGenTextures(2, position_tbo);
     
        // Done with VAOs
        glBindVertexArray(0);
     
        // Set up TBOs
        for (int i = 0; i < 2; i++)
        {
            glBindTexture(GL_TEXTURE_BUFFER, position_tbo[i]);
            glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, position_buffer[i]);
        }
    I am having exceptions regarding the glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, flock_position[i]) ? I really don't understand why? Maybe it is because I did not clean up everything after my rendering was done.

    Here is the content of the destructor of my class :
    Code :
    	glDeleteTextures(2,position_tbo);
    	glDeleteVertexArrays(2,update_vao);
    	glDeleteVertexArrays(2,render_vao);
    	glDeleteBuffers(2,position_buffer);
    I never heard of a glDeleteTexBuffer and in this case the buffer I am binding to the TexBuffer is position_buffer.

    Right now, If I run the first program, it works,
    If I run the copy of the first program I have an exception (for memory allocation).

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    445
    You can have problems if you include OpenGL calls in constructors/destructors if the context is not current when they are called, see http://www.opengl.org/wiki/Common_Mi...nguage_Problem

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Location
    Paris
    Posts
    17
    Sorry but it did not help.
    I only have problems when doing this :

    glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, position_buffer[i]);

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Location
    Paris
    Posts
    17
    UP
    If you you can just tell me in which order I have to delete all what I have created it would be great.
    So I have VAO, some Buffer Objects and 2 textures.
    If I delete a VAO with Buffer bound into it , will they be deleted too ??

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    If I delete a VAO with Buffer bound into it , will they be deleted too ??
    I don't believe it is deleted until it is unbound.

    Put a some glGetError calls in your code. This is always a good idea

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •