【发布时间】:2016-10-26 08:49:32
【问题描述】:
在 OpenGL ES (3.0) 和 Objective-C 中使用缓冲区和顶点属性时,我使用
glBufferData(GL_ARRAY_BUFFER, sizeof(attributes), attributes, GL_DYNAMIC_DRAW);
将一些顶点数据(属性)加载到缓冲区中,然后
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, sizeof(VertexCoordinatesStruct) / sizeof(GLfloat), GL_FLOAT, GL_FALSE, sizeof(VertexAttributesStruct), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, sizeof(TextureCoordinatesStruct) / sizeof(GLfloat), GL_FLOAT, GL_FALSE, sizeof(VertexAttributesStruct), (void *)sizeof(VertexCoordinatesStruct));
为顶点着色器指定缓冲区中的顶点数据内存布局。请注意我如何在第二个 glVertexAttribPointer 调用中将 sizeof(OGLVertexCoordinates) 转换为 Void*。如果 GL_ARRAY_BUFFER 中的偏移量位于 TextureCoordinatesStruct 数据所在的位置。
然后我尝试在 Swift 3 中实现相同类型的代码。但是 glVertexAttribPointer 函数将 UnsafeRawPointer 作为最后一个参数,而不是 void*。
这是我无法解决的问题:我无法像在 Objc 中那样创建具有特定值(内存偏移)的 UnsafeRawPointer。
我研究了我能找到的所有 Q/A,但它们都不适合我的情况,或者根本不适用于 Swift 3。
【问题讨论】: