问题描述
我很难从数据结构之类的数组结构中绘制顶点。我认为这可能是我在glVertexAttribPointer
调用中使用跨步和指针参数的方式。我有这样的结构:
struct RadarReturn_t
{
float32_t x;
float32_t y;
float32_t z;
float32_t prob;
}
我正在像这样的另一种结构中使用RadarReturn_t
:
struct Detections_t
{
uint32_t currentScanNum;
std::array<RadarReturn_t,64> detections;
}
让我们假设我要画100张Detections_t
。我创建了一个VBO来打包所有这些信息,如下所示:
glGenBuffers(1,&mRadarVbo);
for (uint32_t iScan = 0; iScan < mMaxNumScans; ++iScan)
{
// Set the timestamp to 0U
mPersistentDetections.at(iScan).currentScanNum = 0U;
for (uint32_t iDet = 0; iDet < 64; ++iDet)
{
RadarReturn_t& detection = mPersistentDetections.at(iScan).detections.at(iDet);
detection.x = 0.0F;
detection.y = 0.0F;
detection.z = 0.0F;
detection.probability = 0.0F;
}
}
// Bind the VBO and copy the initial data to the graphics card
glBindBuffer(GL_ARRAY_BUFFER,mRadarVbo);
glBufferData(GL_ARRAY_BUFFER,mMaxNumScans * sizeof(DetectionData_t),&mPersistentDetections,GL_DYNAMIC_DRAW);
mPersistentDetections
在哪里:
std::array<DetectionData_t,mMaxNumScans> mPersistentDetections;
稍后,在代码中,我使用currentScanNum
的新传入数据更新缓冲区:
// Offset is: 64 Radar returns plus one scanNumber
uint32_t offset = scanNum* ((64*sizeof(RadarReturn_t)) + 1*sizeof(GLuint));
glBufferSubData(GL_ARRAY_BUFFER,offset,sizeof(GLuint),&mPersistentDetections.at(scanNum).currentScanNum)
,对于detections
,如下所示:
uint32_t dataSize = 64 * sizeof(RadarReturn_t);
glBufferSubData(GL_ARRAY_BUFFER,offset + sizeof(GLuint),dataSize,&mPersistentDetections.at(scanNum).detections);
这就是我代表VAO的方式:
// Bind the VAO
glBindVertexArray(mRadarVao);
// Specify the layout of timestamp data
glVertexAttribIPointer(0,1,GL_UNSIGNED_INT,sizeof(DetectionData_t),(GLvoid*) 0);
// Specify the layout of the radar return data
glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,(GLvoid*) (sizeof(GLuint)));
最后是平局:
glDrawArrays(GL_POINTS,mMaxNumScans* 64);
如果我为mMaxNumScans = 100
绘制此图形,则由于某种原因将无法在此处绘制100x64顶点。您能指出我哪里出问题了吗?
编辑:
根据@ Rabbid76的建议,我对Detections_t
结构进行了如下修改:
struct Detections_t
{
std::array<RadarReturn_t,64> detections;
std::array<uint32_t,64> scanNumbers;
}
我还适当修改了glBufferData
和glBufferSubData
的电话。这是我仍然遇到问题的地方。我无法获得正确的步幅参数。
glVertexAttribPointer(0,mDetectionAttributeSize,sizeof(RadarReturn_t),reinterpret_cast<void*>offsetof(DetectionData_t,detectionData_t::detections)));
glVertexAttribIPointer(1,mTimestampAttributeSize,GL_INT,reinterpret_cast<void*>(offsetof(DetectionData_t,DetectionData_t::scanCounter)));
如果将属性0的跨度设置为sizeof(Detection_t)
,则不会绘制所有点。只有sizeof(RadarReturn_t)
绘制所有点。
如果我将属性1的跨度设置为sizeof(Detection_t)
,则只需几次扫描,检测的颜色(我正在使用scanNumber来更改alpha值)就会变得透明。
如果有人能告诉我属性0和属性1的步幅值是多少,我将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)