Skip to main content
removing blackliste engine tag; grammar and punctiation; removed forumesque commentary
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

Best What is the best way for storing VBOto store Vertex Buffer Object data?

TillUntil now I´ve, I have been using this way of storinga vertexData structure to store data for VBOa Vertex Buffer Object :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uvVBO)

This structure; vertexData holds a static array of 6 vertices (2 triangles). Then I´m savingI then save them to a vectorvector of these structuresthe vertexData type, before finally using this vertexData in the buffering method:

struct vertexData {

    Vertex vertices[6]; // position, color, UVs
};

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

 
void SpriteBatch::createVBO() {

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}
 

This works good, as everything in my vector is contiguous contiguous. However, iI want to work also with other vertex sizes (for, for different shapes - such as polygons,lines..). I tried vectora vector of vectors (to get an opportunityvector types, in oder to work work with dynamically allocated "arrays" )arrays, but it didn´tdid not work, as it wasn´twas not contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.

Edit1: At At first i, I thought about using somea polymorphic class to be stored in vector andas a vector, where every child would have a different size of array, size; but then iI recognized that this vertex buffer doesn´tdoes not work with pointers

The second idea was to create a generic SpriteBatch (forSpriteBatch. For example, a batch for 6 vertices, and then a batch for 2 vertices, etc.) etc.

What is the best way to store Vertex Buffer Object data?

Best way for storing VBO data?

Till now I´ve been using this way of storing data for VBO :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uv)

This structure holds a static array of 6 vertices (2 triangles). Then I´m saving them to a vector of these structures:

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

void SpriteBatch::createVBO(){

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}

This works good, as everything in my vector is contiguous . However, i want to work also with other vertex sizes (for different shapes - such as polygons,lines..). I tried vector of vectors (to get an opportunity to work with dynamically allocated "arrays" ) but it didn´t work as it wasn´t contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.

Edit1: At first i thought about using some polymorphic class to be stored in vector and every child would have different size of array, but then i recognized that this vertex buffer doesn´t work with pointers

The second idea was to create a generic SpriteBatch (for example batch for 6 vertices, and then batch for 2 vertices etc.)

What is the best way to store Vertex Buffer Object data?

Until now, I have been using a vertexData structure to store data for a Vertex Buffer Object (VBO); vertexData holds a static array of 6 vertices (2 triangles). I then save them to a vector of the vertexData type, before finally using this vertexData in the buffering method:

struct vertexData {

    Vertex vertices[6]; // position, color, UVs
};

std::vector<vertexData> _DATA;
 
void SpriteBatch::createVBO() {

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}
 

This works good, as everything in my vector is contiguous. However, I want to work with other vertex sizes, for different shapes. I tried a vector of vector types, in oder to work with dynamically allocated arrays, but it did not work, as it was not contiguous.

At first, I thought about using a polymorphic class to be stored as a vector, where every child would have a different array size; but then I recognized that this vertex buffer does not work with pointers

The second idea was to create a generic SpriteBatch. For example, a batch for 6 vertices, and then a batch for 2 vertices, etc. etc.

What is the best way to store Vertex Buffer Object data?

added some of my opinions as im trying to solve it in some "creative" way :D
Source Link
Pins
  • 589
  • 6
  • 25

Till now I´ve been using this way of storing data for VBO :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uv)

This structure holds a static array of 6 vertices (2 triangles). Then I´m saving them to a vector of these structures:

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

void SpriteBatch::createVBO(){

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}

This works good, as everything in my vector is contiguous . However, i want to work also with other vertex sizes (for different shapes - such as polygons,lines..). I tried vector of vectors (to get an opportunity to work with dynamically allocated "arrays" ) but it didn´t work as it wasn´t contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.

Edit1: At first i thought about using some polymorphic class to be stored in vector and every child would have different size of array, but then i recognized that this vertex buffer doesn´t work with pointers

The second idea was to create a generic SpriteBatch (for example batch for 6 vertices, and then batch for 2 vertices etc.)

Till now I´ve been using this way of storing data for VBO :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uv)

This structure holds a static array of 6 vertices (2 triangles). Then I´m saving them to a vector of these structures:

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

void SpriteBatch::createVBO(){

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}

This works good, as everything in my vector is contiguous . However, i want to work also with other vertex sizes (for different shapes - such as polygons,lines..). I tried vector of vectors (to get an opportunity to work with dynamically allocated "arrays" ) but it didn´t work as it wasn´t contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.

Till now I´ve been using this way of storing data for VBO :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uv)

This structure holds a static array of 6 vertices (2 triangles). Then I´m saving them to a vector of these structures:

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

void SpriteBatch::createVBO(){

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}

This works good, as everything in my vector is contiguous . However, i want to work also with other vertex sizes (for different shapes - such as polygons,lines..). I tried vector of vectors (to get an opportunity to work with dynamically allocated "arrays" ) but it didn´t work as it wasn´t contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.

Edit1: At first i thought about using some polymorphic class to be stored in vector and every child would have different size of array, but then i recognized that this vertex buffer doesn´t work with pointers

The second idea was to create a generic SpriteBatch (for example batch for 6 vertices, and then batch for 2 vertices etc.)

Source Link
Pins
  • 589
  • 6
  • 25

Best way for storing VBO data?

Till now I´ve been using this way of storing data for VBO :

struct vertexData{

    Vertex vertices[6];
};

(Vertex - position,color,uv)

This structure holds a static array of 6 vertices (2 triangles). Then I´m saving them to a vector of these structures:

std::vector<vertexData> _DATA;

And finally, the buffering function looks like this:

void SpriteBatch::createVBO(){

    glBindBuffer(GL_ARRAY_BUFFER,_VBO);

    glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
    glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());

    glBindBuffer(GL_ARRAY_BUFFER,0);
}

This works good, as everything in my vector is contiguous . However, i want to work also with other vertex sizes (for different shapes - such as polygons,lines..). I tried vector of vectors (to get an opportunity to work with dynamically allocated "arrays" ) but it didn´t work as it wasn´t contiguous. Can you give me some tips? I´ve got an idea to code own container but wanted to know how does the big engines deal with this before.