Posts: 11
Joined: Wed Aug 15, 2018 9:15 pm
Location: India

boost::circular_buffer and openGL glBufferData not getting along.

Fri Dec 21, 2018 11:08 pm


I'm storing some vertex data in:

boost::circular_buffer<int> bufferData(200);

My class has a function to return a pointer to the address of bufferData.front():

int *getBufferData() {return &bufferData.front();}

Then i send this pointer to glBufferData:

glBufferData(GL_ARRAY_BUFFER, 200*sizeof(int), MyClass.getBufferData(), GL_STATIC_DRAW);

The screen renders, however i don't get the right coordinates to show almost looks as if openGL is plotting the addresses instead of the actual data in my circular buffer.

Can anyone confirm if this is the right way to send the data?

Posts: 105
Joined: Sun Jan 07, 2018 3:44 pm

Re: boost::circular_buffer and openGL glBufferData not getting along.

Tue Jan 29, 2019 8:22 am

I know this is an old thread but it bears mention. The OP's interpretation of how to use a ring buffer is faulty.

Although, it's not his fault, since boost libraries have some of the least comprehensive and most useless documentation of any internet collaborative project in existence.

circular_buffer::front() probably returns a reference to the data item stored at the head of the buffer. Its address should NOT be used as pointer to a contiguous data structure such as openGL will want! there is no quarantee the front() points to the lowest memory address occupied by the structure, so using it as a beginning pointer/reference is incorrect.

do NOT use a ring buffer for this. allocate a std::vector instead. Then you can easily retrieve the startins address of the vector as

Code: Select all

std::vector<uchar> vec(2000);			// create a vector of 2000 characters
uchar* p(&vec[0]);						// get a pointer to its first entry

Return to “Graphics programming”