- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在为显示旋转立方体的 iphone 编写一个简单的应用程序。我正在使用 glDrawElements (openGl es) 绘制立方体的三角形并旋转它。我注意到当我将立方体的大小增加到 100*100*100 体素时,显示性能会变差(澄清:我不画整个立方体,我只画它的轮廓(网格)。我通过在立方体上应用行进立方体算法得到网格的所有三角形......最终我得到像 120k 三角形的东西来绘制它们是由 40k 个顶点表示)...
为了绘制立方体,我保存了一个顶点数组、颜色数组和一个顶点索引数组。 indices 数组定义要绘制的顶点的三角形。它作为参数传递给 glDrawElements。
最近我发现了一种使用顶点缓冲区对象 (VBO) 绘制立方体的不同技术。我已经实现了它,但性能比以前的技术更差
这是我的代码,也许我犯了一个愚蠢的错误,任何改进建议都会受到欢迎:)
顺便说一句,我使用了以下文章作为引用:
http://playcontrol.net/ewing/jibberjabber/opengl_vertex_buffer_object.html http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html
//all the 7 variables down are initialized by other function at the beginning
GLushort* meshIndices; //array of indices (ushort)
MeshVertex* meshVertices; //array of vertices (floats)
Color3D* meshColors; //array of colors (floats)
int numberOfTriangles; //number of Triangle to draw the cube
int numberOfVertices; //number of all Vertices to draw the cube
int numberOfIndices; //number of all Indices to draw the cube, each 3 indices define 3 vertices which define 1 triangle
int numberOfColors; //number of colors used to draw the cube. each color is of tip Color3D
//in this function i initializing the VBOs
- (void) setupMeshVBOs {
glGenBuffers(1, &triangleVBO);
glBindBuffer(GL_ARRAY_BUFFER, triangleVBO);
const GLsizeiptr vertex_size = numberOfVertices * sizeof(MeshVertex);
const GLsizeiptr color_size = numberOfColors * sizeof(Color3D);
glBufferData(GL_ARRAY_BUFFER, vertex_size + color_size, 0, GL_STATIC_DRAW);
GLvoid* vbo_buffer = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
memcpy(vbo_buffer, meshVertices, vertex_size);
GLbyte* temp = (GLbyte*)vbo_buffer;
temp += vertex_size;
memcpy((GLvoid*)temp, meshColors, color_size);
glUnmapBufferOES(GL_ARRAY_BUFFER);
glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)((char*)NULL));
glColorPointer(4, GL_FLOAT, 0, (GLvoid*)((char*)NULL+vertex_size));
glGenBuffers(1, &triangleIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numberOfIndices * sizeof(GLushort), meshIndices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
//this function is the one which draws the VBOs
- (void)drawView:(GLView*)view;
{
static GLfloat rot = 0.0;
glLoadIdentity();
glTranslatef(-1.0f,-2.0f,-20.0f);
glRotatef(rot,1.0f,1.0f,1.0f);
glClearColor(0.7, 0.7, 0.7, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, triangleVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIBO);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_STRIP, numberOfIndices, GL_UNSIGNED_SHORT, (GLvoid*)((char*)NULL));
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
static NSTimeInterval lastDrawTime;
if (lastDrawTime)
{
NSTimeInterval timeSinceLastDraw = [NSDate timeIntervalSinceReferenceDate] - lastDrawTime;
rot+=50 * timeSinceLastDraw;
}
lastDrawTime = [NSDate timeIntervalSinceReferenceDate];
}
最佳答案
首先,要绘制 100x100x100 的立方体 map ,您不应单独绘制每个立方体。如果有,比如说,连续六个盒子,那么你应该把它们画成一个长方体,总共有十二个三角形。任何被六边包围的立方体肯定不需要考虑。您应该应用类似的策略来显着减少几何数。
Apple 关于 GL 优化的建议是 here .摘要版本是您应该旨在使用具有对齐的交错数据的 VBO,使用最小的可接受类型。因此,隐含地,读取数据是一个瓶颈。使用两个单独的列表可能会使您的几何输入速率减半,而使用 float 可能会进一步减慢速度。
关于objective-c - 在 OpenGL es (Iphone) 中使用 Vertex Buffer Objects (VBO) 来提高性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7215309/
我在使用 dijkstra 时遇到了这个错误:TypeError:不可排序的类型:Vertex() dijkstra(g, g.get_vertex('a')) File "C:/Use
我对为自定义类实现迭代器感到困惑。我正在尝试为 std::set 实现一个迭代器,其中我的 Vertex 类声明为: class Vertex{
我正在尝试学习和实现有向图,但在执行程序时遇到了一些困难。 // ADD Function public boolean addVertex(Vertex v) { boolean added
我是 OpenGL 的初学者,我试图每 5 秒将大量“对象”从一个位置移动到另一个位置。如果我在顶点着色器中计算位置,fps 急剧下降,难道不应该在 GPU 上完成这些类型的计算吗? 这是顶点着色器代
我正在学习使用 Boost 图形库。我已经按照此处的说明定义了一个自定义结构来存储有关顶点的信息:Modifying vertex properties in a Boost::Graph . str
我正在尝试使用 boost::adjacency list 和捆绑属性创建一个 TreeMap 来存储每个顶点的父级,我想以一种它们不会失效的方式存储顶点描述符以防万一我删除了一个顶点,所以我使用了
要定义一个从 int 到 struct vertex 的映射,我应该定义 map[int]vertex 还是 map[int]*vertex?首选哪一个? 我扩展了 Chickencha 的代码: p
我创建了一个 VBO(顶点缓冲区对象)和 VAO(顶点数组对象)并执行了以下操作: glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo)
我用 HBase 设置了 Titan。 我删除图中的所有顶点 全部删除后显示为空。 gremlin> g.V.count() ==>0 但是如果我重新登录泰坦,那么图中会有一堆空顶点 gremlin>
我正在探索使用计算着色器将骨骼变形应用于网格顶点,而不是使用流输出的顶点着色器。我发现计算着色器的执行速度比顶点着色器慢得多,但在我把它写下来之前,我想确定我没有做错什么。 使用我的 100,000
这里我有一个有向图G,我需要判断是否存在一组顶点不相交的循环,以便每个顶点都属于一个循环。 我不确定这是否可以在多项式时间内完成或者它是否是 NP-Complete?谁能至少指出我正确的方向? 最佳答
要检测一个点是否在多边形中,您可以从该点到无穷远投影一条线,然后查看它与多少个多边形顶点相交......足够简单。我的问题是,如果射线在其中一个点上与多边形相交,则将其视为与两个线段相交,并被视为在多
我在 VehicleHistoryGraph 数据库中创建了一个 Message 类型的顶点,并向其中加载了 50,000 个该类型的顶点。 当我尝试使用此 SQL 语句一次删除所有顶点时 - DEL
所以我正在尝试将 Graph 类作为另一个项目的一部分。顶点存储在由 unordered_map 定义的邻接表中。我正在尝试创建一个散列函数以允许我的 Vertex 类存储在此 map 中,但我不知道
我正在尝试使用 Parma Polyhedra 库 [1]枚举(凸)多面体的顶点,例如,我有一个由四个约束指定的矩形: Constraint_System cs; cs.insert(x >= 0);
我开始了解 Visual Studio 2017 中的 OpenGL。按照 www.learnopengl.com 教程并通过了纹理检查点,转换是目前的主要问题。 我使用预先获取的统一位置 ID 将我
有一个预定的笔记本,它使用 BigQuery 客户端和具有所有者权限的服务帐户。当我手动运行单元格时,它会更新 BQ 表。 BQ 和 Vertex AI 都有一个项目。 我发现了一个类似的问题,但是
我在 R 中使用 Igraph 包,当我通过 V(graph) 访问顶点名称列表时,我得到以下结果: Vertex sequence: [1] "d66cp96igcdnt25brjeics9d11
我有一个 U-SQL 脚本,它在数据湖中存储的多个 JSON 文件上运行,当我针对单个文件运行该脚本时,一切正常,但是打开它以针对我的所有文件运行每次都会出现以下错误,并且作业永远不会超过“准备”阶段
我正在尝试实现 phong 阴影,但无济于事。我正在一点一点地构建着色器(这本身可能是一个问题),但这就是我目前所处的位置。我希望它将我的结果(犹他茶壶)输出为黑色背景上的白色图像。当我从顶点着色器中
我是一名优秀的程序员,十分优秀!