This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Soo long story short I am following the cherno's tutorials in the game engine series and I have reached the batched renderer part.
On short, again, the batch renderer uploads the data of all the vertices to a huge vertex buffer object that was initially created without any data. The data should be uploaded by a function that implements glBufferSubData that takes the pointer to the data and a size that should represent the size of the data in bytes.
The problem arose after I made this change from the normal quad renderer to the batch renderer and now nothing renders. I don't know if it's anything complicated or not in the middle of all of this but I have spent like 2 days and I can't get it to work. I have pinned down two OpenGl errors though, those being a 1281 error after the glbuffersubdata function and a 1285 error after the glDrawElements function.
Now I have checked everything I think, from the context and shader code and all it's uniforms and variable names to the OpenGl code. And I also can say that during debugging I have seen that no, the data and size parameters uploaded to glbuffersubdata are valid. The vertex buffer object is being bound with the ID it was created with and the index buffer is also bound at the time of glDrawElements with the ID it was created with and the layout is correct.
I can't figure out what is the problem so I hope maybe someone here knows what to do.
I will provide some code as a point of reference but if anyones wants to help me and needs more code please feel free to dm me or ask me in the comments to upload more. I will respond pretty quick i think since i want to get this sorted out cause it is already a pain in the ass.
batch renderer flush :
"void Renderer2D::end_scene()
{
SAI\_PROFILE\_FUNCTION();
uint32\_t data\_size = (uint8\_t\*)s\_data.quad\_vertex\_buffer\_ptr - (uint8\_t\*)s\_data.quad\_vertex\_buffer\_base;
s\_data.quad\_vertex\_buffer->set\_data((float\*)s\_data.quad\_vertex\_buffer\_base, data\_size);
for (uint32\_t i = 0; s\_data.quad\_vertex\_array->get\_index\_buffer()->get\_indices()\[i\]; i )
{
std::cout << s\_data.quad\_vertex\_array->get\_index\_buffer()->get\_indices()\[i\] << " ";
}
flush();
}
void Renderer2D::flush()
{
SAI\_PROFILE\_FUNCTION();
if (s\_data.quad\_index\_count)
{
s\_data.full\_shader->bind();
for (uint32\_t i = 0; i < s\_data.texture\_slot\_index; i )
{
s_data.texture_slots[i]->bind(i);
}
s\_data.quad\_vertex\_array->get\_index\_buffer()->bind();
Render\_Command::draw\_indexed(s\_data.quad\_vertex\_array, s\_data.quad\_index\_count);
s\_data.stats.draw\_calls ;
}
}"
what det_data does:
"
void OpenGL_Vertex_Buffer::set_data(const void* data, uint32_t size)
{
glEnable(GL\_DEBUG\_OUTPUT);
glEnable(GL\_DEBUG\_OUTPUT\_SYNCHRONOUS);
// Set the debug message callback function
glDebugMessageCallback(\[\](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar\* message, const void\* userParam)
{
// Output the debug message to the console or log file
std::cout << "OpenGL Debug Message: " << message << std::endl;
},
nullptr);
glBindBuffer(GL\_ARRAY\_BUFFER, m\_renderer\_id);
glBufferSubData(GL\_ARRAY\_BUFFER, 0, size, data);
GLenum error = glGetError();
while (error != GL\_NO\_ERROR)
{
SAI\_CORE\_ERROR("Set data error {0}", error);
error = glGetError();
}
}
"
what draw_indexed does:
"
void OpenGL_Renderer_API::draw_indexed(const Ref<Vertex\_Array>& vertex_array, uint32_t index_count)
{
SAI\_PROFILE\_FUNCTION();
vertex\_array->bind();
uint32\_t count = index\_count ? index\_count : vertex\_array->get\_index\_buffer()->get\_count();
glDrawElements(GL\_TRIANGLES, count, GL\_UNSIGNED\_INT, nullptr);
GLenum error = glGetError();
while (error)
{
SAI\_CORE\_ERROR("OpenGL draw indexed error {0}", error);
error = glGetError();
}
}
"
as i mentioned in the description at the beggining i am getting errors 1281 and 1285. here is some advanced query on the errors with additional explanation:
"OpenGL Debug Message: GL_INVALID_VALUE error generated. Invalid offset and/or size.
[21:33:15] SAI: Set data error 1281
23 OpenGL Debug Message: GL_OUT_OF_MEMORY error generated. Failed to allocate memory for buffer object.
OpenGL Debug Message: GL_OUT_OF_MEMORY error generated. Failed to map memory for buffer.
[21:33:15] SAI: OpenGL draw indexed error 1285"
I am also getting some weird debug messages at the beggining(first few run loops) that are these
"
OpenGL Debug Message: Buffer detailed info: Buffer object 3 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (2), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
OpenGL Debug Message: Buffer detailed info: Buffer object 4 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
OpenGL Debug Message: GL_INVALID_VALUE error generated. Invalid offset and/or size.
"
Also note that in the whole code, there is only one vertex buffer object and index buffer object as well as only one vertex array.
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/opengl/comm...