• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Neosettler

Delete VBOs at run time?

7 posts in this topic

Greetings GL Masters,

I recently run my application with gDEBugger GL: http://www.gremedy.com/download.php

I was chock to my very core that all these years, I had video memory leaks. After endless efforts, I managed to find the source of the leaks. All I needed to do was to match every glGenBuffers with glDeleteBuffers and my life was peachy again.

 

each VBO looks somewhat like this:

glGenBuffers(1, &l_id1);
glBindBuffer(GL_ARRAY_BUFFER...
glBufferData(GL_ARRAY_BUFFER...
glBufferSubData(GL_ARRAY_BUFFER...

glGenBuffers(1, &l_id2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER...
glBufferData(GL_ELEMENT_ARRAY_BUFFER...

glDeleteBuffers(1, &l_id1)
glDeleteBuffers(1, &l_id2)
 
The problem is, all the while this is working fine when opening and closing the API. Deleting buffers at run time makes the next draw call ends with an access violation.
 
I cant find any relevant info on how to properly delete VBOs buffers at run time so far. Any wisdom of the ancestral would be very welcome.
 
Thx

Edited by Neosettler
0

Share this post


Link to post
Share on other sites
Thank you for your input Bob,  I used this to delete the VBO now:

glBindBuffer(GL_ARRAY_BUFFER, in_id); 
        for (UInt i = 0; i < 16; ++i) 
        { 
            glDisableVertexAttribArray(i); 
        } 
        glBindBuffer(GL_ARRAY_BUFFER, 0); 
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 
        glDeleteBuffers(1, &in_id);

The crash is gone but I'm still not sure if this is the right way of doing it.
0

Share this post


Link to post
Share on other sites

There's no problems with the way you're deleting the buffer objects. I'm questioning where and when you're doing it.

0

Share this post


Link to post
Share on other sites

There's no problems with the way you're deleting the buffer objects. I'm questioning where and when you're doing it.


Likewise I would ask this question. I don't mean to sound insulting, and I may be very wrong here, but you may be someone who has previously only ever used immediate mode, has received advice to use buffer objects instead, but is trying to use buffer objects in the same way as you used to use immediate mode - i.e. specify vertex data on the fly and on a fairly ad-hoc basis. If that's the case then you've got a deeper design problem that you also need to resolve, as well as a requirement to better understand how buffer objects are supposed to be used. Edited by mhagain
0

Share this post


Link to post
Share on other sites

My apologies, I find pasting code here very painful, I guess I tried cutting corners in my explanation but my code
looks more like this:
 
void OpenGL::SetVertexBuffer(VertexBuffer *in_buffer)

{

    UInt &l_id = in_buffer->GetArrayId();


    if (l_id == 0)

    {

        glGenBuffers(1, &l_id);

    }

    glBindBuffer(GL_ARRAY_BUFFER, l_id);


    if (in_buffer->IsUpdated())

    {

        glBufferData(GL_ARRAY_BUFFER, in_buffer->GetArraySize(), NULL, gl_BufferTypes[in_buffer->GetType()]);

    }

}


template <class T> void OpenGL::SetVertexData(ArrayBuffer<T> &in_array)

{

    if (in_array.IsValid())

    {

        glBufferSubData(GL_ARRAY_BUFFER, in_array.GetOffset(), in_array.GetSize(), in_array.GetData());

    }

}


template <class T> void OpenGL::SetVertexAttribute(ArrayBuffer<T> &in_array)

{

    if (in_array.IsValid())

    {

        e_VertexAttributes &l_index = in_array.GetIndex();

        glVertexAttribPointer(l_index, gl_AttributeSizes[l_index], gl_AttributeTypes[l_index], gl_AttributeNormalized[l_index], gl_AttributeStrides[l_index], (void*) in_array.GetOffset());


        glEnableVertexAttribArray(l_index);

    }

    else

        glDisableVertexAttribArray(in_array.GetIndex());

}


template <class T> void OpenGL::Draw(VertexBuffer *in_buffer, ArrayBuffer<T> &in_indices, UInt in_offset, const e_RenderTypes &in_type)

{

    UInt &l_id = in_buffer->GetElementId();


    if (l_id == 0)

    {

        glGenBuffers(1, &l_id);

    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, l_id);


    if (in_buffer->IsUpdated())

    {

        in_buffer->SetUpdated(false);

        glBufferData(GL_ELEMENT_ARRAY_BUFFER, in_indices.GetSize(), in_indices.GetData(), gl_BufferTypes[in_buffer->GetType()]); /// Only if reseted.

    }

    glDrawRangeElements(gl_RenderTypes[in_type], in_offset, in_offset + in_indices.GetSize(), in_indices.GetSize(), GL_UNSIGNED_INT, (void*) in_indices.GetOffset());   

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);



If my understanding is correct, unbinding any subData attached to the buffers was my missing link before deletion at run time.

 

void OpenGL::DeleteVertexBuffer(UInt &in_id)
{
if (in_id != 0)
{
  glBindBuffer(GL_ARRAY_BUFFER, in_id);

  for (UInt i = 0; i < 16; ++i)
  {
   glDisableVertexAttribArray(i);
  }
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  glDeleteBuffers(1, &in_id);
  in_id = 0;
}
}

0

Share this post


Link to post
Share on other sites

Your code looks very suspicions. Why are you checking the validity of the object and uploading data almost everywhere in the code? I don't see why, for example, the draw function should have to be bothered in the first place with allocating buffer object names or uploading data anywhere. Shouldn't the draw function just be responsible for drawing a buffer, and nothing else?
 
With name allocation and buffer data uploads in almost every single function, it's going to be very difficult to track down incorrect usage. It sounds like the fundamental design itself is wrong somewhere, and that requires a fundamental design change to the code as well.

0

Share this post


Link to post
Share on other sites

Why are you checking the validity of the object and uploading data almost everywhere in the code?

 

The validity check comes from:

 

- In the old days, resizing a window was emptying the video memory. (Not a valid argument anymore)

- I'm using a mixture of SFML and QT and for some reason, it does prevent me from creating buffer at initialization of my API as there is a switch GL context or some funny stuff similar to this. (I will start by investigate this.)

- I have the option of resetting programs at run time. (I'll make re-initialization on reset() instead.)

 

The uploading data is rather tricky, as my approach supports multi-materials, I have 2 different techniques that I would like to debate:

 

- Geometries hold vertex attributes and meshes.

- Meshes hold face ids.

 

For each geometry:

1 - One VBO for the vertex attributes and one VBO for each mesh(i).

2 - One VBO for the vertex attributes and one VBO for all mesh(i) using buffer offset.

 

Surprisingly, number 2 is giving better performance even if it has to call subData every draw.

 

To resume, You are right, I'm in the process of redesign and I'd love some insights.

Edited by Neosettler
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0