在使用64位操作系统glMultiDrawElements [英] Using glMultiDrawElements in 64bit OS

查看:159
本文介绍了在使用64位操作系统glMultiDrawElements的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从32位环境迁移到64位1迁移,它已顺利除了一个问题: glMultiDrawElements 使用某些阵列不无一些调整工作下一个64位操作系统。

I have recently migrated from a 32bit environment to a 64bit one, and it has gone smoothly apart from one problem: glMultiDrawElements uses some arrays that do not work without some tweaking under a 64bit OS.

glMultiDrawElements( GL_LINE_LOOP, fCount_, GL_UNSIGNED_INT,
                     reinterpret_cast< const GLvoid** >( iOffset_ ),
                     mesh().faces().size() );

我使用维也纳各组织为顶点和顶点索引。 FCOUNT _ 为offset _ GLsizei 的阵列。由于缓冲势必 GL_ELEMENT_ARRAY_BUFFER 为offset _ 的元素被用作从VBO开始字节偏移。这工作完全在32位操作系统下。

I am using VBOs for both the vertices and vertex indices. fCount_ and iOffset_ are arrays of GLsizei. Since a buffer is bound to GL_ELEMENT_ARRAY_BUFFER, iOffset_'s elements are used as byte offsets from the VBO beginning. This works perfectly under a 32bit OS.

如果我修改 glMultiDrawElements 与glDrawElements ,并把它变成一个循环,它工作正常,在两个平台上:

If I change glMultiDrawElements to glDrawElements and put it into a loop, it works fine on both platforms:

int offset = 0;
for ( Sy_meshData::Faces::ConstIterator i  = mesh().faces().constBegin();
                                        i != mesh().faces().constEnd(); ++i ) {
    glDrawElements( GL_LINE_LOOP, i->vertexIndices.size(), GL_UNSIGNED_INT,
                    reinterpret_cast< const GLvoid* >( sizeof( GLsizei ) * offset ) );
    offset += i->vertexIndices.size();
 }

我觉得我所看到的是OpenGL的读为offset _ 64块,导致庞大的数字,但 glMultiDrawElements 做不支持任何类型的不是32位( GL_UNSIGNED_INT )较宽,所以我不知道如何纠正它。

I think what I am seeing is OpenGL reading 64bit chunks of iOffset_ leading to massive numbers, but glMultiDrawElements does not support any type wider than 32bit (GL_UNSIGNED_INT), so I'm not sure how to correct it.

任何人都有这种情况下,解决了呢?还是我处理这个完全错误的,是一个32位操作系统只是运气好?

Has anyone else had this situation and solved it? Or am I handling this entirely wrong and was just lucky on a 32bit OS?

交换了我现有的code为:

Swapping out my existing code for:

typedef void ( *testPtr )( GLenum mode, const GLsizei* count, GLenum type,
                           const GLuint* indices, GLsizei primcount );
testPtr ptr = (testPtr)glMultiDrawElements;
ptr( GL_LINE_LOOP, fCount_, GL_UNSIGNED_INT, iOffset_, mesh().faces().size() );

结果中得到完全相同的结果。

Results in exactly the same result.

推荐答案

简单的原因是,<一个href="http://www.opengl.org/sdk/docs/man/xhtml/glMultiDrawElements.xml"><$c$c>glMultiDrawElements不期望整数偏移量(32位平台)的数组,但是指针(你的平台上64位)阵列,PTED缓冲偏移跨$ P $。

The simple reason is, that glMultiDrawElements doesn't expect an array of integer offsets (32bit on your platform), but an array of pointers (64bit on your platform), interpreted as buffer offsets.

但你只是铸造的数组(或指针)整数数组(或指针)的指针,这是行不通的,因为该功能现在只需reinter $ P $其中pts的n个连续的32位值n个连续的64位值。当然,它适用于与glDrawElements 因为你只是铸造一个整数到一个单一的指针,它基本上是将您的32位值转换为64位值。

But you are just casting the array of (or pointer to) integers to an array of (or pointer to) pointers, which won't work, as the function now just reinterprets your n consecutive 32bit values as n consecutive 64bit values. Of course it works for glDrawElements because you're just casting a single integer into a single pointer, which essentially converts your 32bit value into a 64bit value.

您需要做的是不投你的指针/阵列,但在这个偏移数组中的每个单独的值:

What you need to do is not cast your pointer/array, but each individual value in this offset array:

std::vector<void*> pointers(mesh().faces().size());
for(size_t i=0; i<pointers.size(); ++i)
    pointers[i] = static_cast<void*>(iOffset_[i]);
glMultiDrawElements( GL_LINE_LOOP, fCount_, GL_UNSIGNED_INT, 
                     &pointers.front(), mesh().faces().size() );

或者更好的,只是你的偏移量存储为指针,而不是从一开始的整数。

Or better, just store your offsets as pointers instead of integers right from the start.

这篇关于在使用64位操作系统glMultiDrawElements的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆