PDA

View Full Version : openGL buffer for vector of struct



rafal
04-23-2012, 03:12 PM
the same i think but result no the same. what is wrong ?

first draw withou using budffer works good :


QVector<SamplePointer> samples = curve->samples();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_DOUBLE, sizeof(SamplePointer), samples.data() + curve->firstSample());
glDrawArrays(curve->style(), 0, samples.size() - curve->firstSample());


srcond one uses buffer and result is not the same and it is bad :


QVector<SamplePointer> samples = curve->samples();
glEnableClientState(GL_VERTEX_ARRAY);
m_buffers[curve]->bind();
glVertexPointer(2, GL_DOUBLE, sizeof(SamplePointer), reinterpret_cast<void*>(curve->firstSample()) );
m_buffers[curve]->release();
glDrawArrays(curve->style(), 0, samples.size() - curve->firstSample());


buffer m_buffers[curve] done by :


QVector<SamplePointer> samples = curve->samples();
QGLBuffer *buffer = new QGLBuffer(QGLBuffer::VertexBuffer);
buffer->setUsagePattern(QGLBuffer::DynamicDraw);
if (!buffer->create())
{
qFatal("cant create buffer");
delete buffer;
return;
}

buffer->bind();
buffer->allocate(sizeof(SamplePointer) * curve->samples().size());
SamplePointer* vector2D = (SamplePointer*)(buffer->map(QGLBuffer::WriteOnly));
if (!vector2D)
{
qFatal("cant map buffer");
buffer->unmap();
buffer->release();
delete buffer;
return;
}
m_buffers[curve] = buffer;

for (int i = 0; i < samples.size();i++)
{
vector2D[i].sx = samples[i].sx;
vector2D[i].sy = samples[i].sy;
}

buffer->unmap();
buffer->release();


PLEASE HELP. what is wrong ?