Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays opengl映射的数组缓冲区总是太小_Arrays_Opengl - Fatal编程技术网

Arrays opengl映射的数组缓冲区总是太小

Arrays opengl映射的数组缓冲区总是太小,arrays,opengl,Arrays,Opengl,我正在opengl应用程序中使用顶点数组对象。当我测试少量顶点时,映射数组缓冲区没有问题。然后我尝试分配一个更大的缓冲区,因此: unsigned int vaoToStore, vboToStore[2]; glGenVertexArrays ( 1, &vaoToStore ); glBindVertexArray ( vaoToStore ); glGenBuffers ( 2, vboToStore ); glBindBuffer ( G

我正在opengl应用程序中使用顶点数组对象。当我测试少量顶点时,映射数组缓冲区没有问题。然后我尝试分配一个更大的缓冲区,因此:

    unsigned int vaoToStore, vboToStore[2];
    glGenVertexArrays ( 1, &vaoToStore );
    glBindVertexArray ( vaoToStore );

    glGenBuffers ( 2, vboToStore );
    glBindBuffer ( GL_ARRAY_BUFFER, vboToStore[0] );

    glBufferData ( GL_ARRAY_BUFFER,
                   30000,
                   NULL,
                   GL_DYNAMIC_DRAW );

    glEnableVertexAttribArray ( kAttribPositionLoc );
    glEnableVertexAttribArray ( kAttribColorLoc );
    glEnableVertexAttribArray ( kAttribTexcoordLoc );
    glEnableVertexAttribArray ( kAttribMaskIndex );

    glVertexAttribPointer ( kAttribPositionLoc, 3, GL_FLOAT, GL_FALSE, 10 * sizeof ( float ), 0 );
    glVertexAttribPointer ( kAttribColorLoc, 4, GL_FLOAT, GL_FALSE, 10 * sizeof ( float ), ( void* ) ( 3*sizeof ( float ) ) );
    glVertexAttribPointer ( kAttribTexcoordLoc, 2, GL_FLOAT, GL_FALSE, 10 * sizeof ( float ), ( void* ) ( 7*sizeof ( float ) ) );
    glVertexAttribPointer ( kAttribMaskIndex, 1, GL_FLOAT, GL_FALSE, 10 * sizeof ( float ), ( void* ) ( 9*sizeof ( float ) ) );

    glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, vboToStore[1] );

    glBufferData ( GL_ELEMENT_ARRAY_BUFFER,
                   1000 * sizeof ( unsigned int ),
                   NULL,
                   GL_DYNAMIC_DRAW );
然后,当使用glMapBufferRange进行映射时,元素数组可以正常工作,但是属性数组将始终返回null,除非我只映射100或更小的大小。。。 这是正常的行为吗?我浏览了谷歌和opengl的参考资料,但他们似乎都认为这是可能的

按要求映射代码

float *vertAttribs = reinterpret_cast<float*> ( glMapBufferRange( GL_ARRAY_BUFFER, 0, 30000, GL_MAP_WRITE_BIT ) );

    unsigned int *elements = reinterpret_cast<unsigned int*> ( glMapBufferRange ( GL_ELEMENT_ARRAY_BUFFER, 0, 1000 * sizeof ( unsigned int ), GL_MAP_WRITE_BIT ) );
float*vertttribs=reinterpret_cast(glMapBufferRange(GL_数组_缓冲区,0,30000,GL_映射_写入位));
unsigned int*elements=reinterpret_cast(glMapBufferRange(GL_ELEMENT_数组_BUFFER,0,1000*sizeof(unsigned int),GL_MAP_WRITE_位));

现在,正如我所说的,像这样映射元素缓冲区是可行的,但是即使我将大小从30000更改为(sizeof(float)*1000),属性数组在映射时抛出无效的值…

OK!!我发现:我不知道GL_ARRAY_BUFFER绑定不是VAO状态的一部分……所以我绑定了VAO,并认为这意味着也绑定了数组缓冲区。我认为没有错误,这解释了为什么另一个VAO的显示都被搞砸了,它也变小了,这解释了有限的映射范围。

请同时显示映射代码。现在完全不清楚你在映射什么,以及如何映射。