更新时间:2023-09-20 09:50:28
在进行低级编程时,您有时会不得不执行C ++核心准则中不应执行的操作.因此,只需执行这些操作,要么接受警告",要么关闭该特定准则(可能基于每个文件).
When you're doing low-level programming, you will occasionally have to do things that the C++ core guidelines say you shouldn't do. So just do them and either live with the "warning" or turn off that specific guideline (possibly on a per-file basis).
话虽如此,对这种特殊的低级软硬件的需求仅仅是因为OpenGL在其顶点规范API中的愚蠢性.该值应该是某种形式的整数字节偏移量,而不是转换为指针的偏移量,而指针将被另一侧转换回该偏移量.
That having been said, the need for this particular bit of low-level fudgery is solely because of OpenGL's stupidity in its vertex specification API. That value ought to be an integer byte offset of some sort, not an offset cast to a pointer which the other side will cast back to an offset.
因此***完全避免使用错误的API.使用单独的属性格式规范,而不要使用旧式glVertexAttribPointer
.在几乎所有方面它都是优越的.它将使您的代码来自:
So it would be better to just avoid the bad API altogether. Use separate attribute format specification rather than the old-style glVertexAttribPointer
. It's superior in pretty much every way. It will turn your code from:
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 8,
reinterpret_cast<void*>(sizeof(GLfloat) * 3));
到
glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3); //Offset specified as integer.
glVertexAttribBinding(1, 0); //You seem to be using multiple attributes with a stride, so they should use the same buffer binding.
//Some later point when you're ready to provide a buffer.
glBindVertexBuffer(0, buffer_obj, 0, sizeof(GLfloat) * 8); //Stride goes into the buffer binding.
看,根本没有演员.
不幸的是,glDrawElements
系列功能没有其他选择,因此您仍然会收到此警告.
Unfortunately, there are no alternatives for the glDrawElements
family of functions, so you're still going to get this warning.