每个图元的顶点属性数组

每个图元的顶点属性数组

本文介绍了OpenGL:每个图元的顶点属性数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在OpenGL中是否有可能通过glVertexAttribPointer type函数指定一个属性数组,该数组由glVertexAttribPointer type函数指定,该数组对每个基元(或N个顶点)前进一个,而不是对每个顶点前进一个?

I'm wondering if it's possible in OpenGL (via extensions or otherwise) to have an attribute array specified by the glVertexAttribPointertype functions that advances by one for every primitive (or N vertices) instead of one for every vertex?

例如,如果我有一个三角形的数组,这些三角形具有单色,则我必须为每个顶点重复相同的颜色数据,而我想要的是沿着这些方向的东西:

For example, if I have an array of triangles which have a solid color currently I'm having to repeat the same color data for every vertex, what I would like instead is something along these lines:

struct pos {
    uint8_t x, y;
} positions[NUM_VERTICES];

struct col {
    uint8_t r, g, b;
} colors[NUM_VERTICES / 3];

当两个数组都使用glVertexAttribPointer提交给OpenGL并使用单个glDrawArrays(GL_TRIANGLES, ...);

Where one element of the colors array is reused for every 3 consecutive positions elements when both arrays are submitted to OpenGL with glVertexAttribPointer and renderered with a single glDrawArrays(GL_TRIANGLES, ...);

我发现了ARB_instanced_arrays扩展名,它提供了glVertexAttribDivisorARB函数,乍一看似乎很有前途,但是我认为它不能像我所描述的那样起作用.

I found the ARB_instanced_arrays extension, which provides the glVertexAttribDivisorARB function which seemed promising at first, but I don't think it works the way I've described.

推荐答案

这实际上是(不同,这就是为什么我不称其为重复的原因).简单回答是不.不太简单的答案是自己进行访问和建立索引.

This is essentially an alternate form of this question about multi-indexed rendering (it's different, which is why I'm not calling it a duplicate). The simple answer is no. The less simple answer is to do the accessing and indexing yourself.

这篇关于OpenGL:每个图元的顶点属性数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:06