对于其他缓冲区,有以下功能:
glVertexArrayVertexAttribOffsetEXT(
this->handle, // vao handle
vbo.getHandle(), // vbo handle
index, // specifies the index of the generic vertex attribute to be modified.
size, // number of components per generic vertex attribute
vbo.getType(), // specifies the data type of each component in the array
normalized, // specifies whether fixed-point data values should be normalized
stride, // specifies the byte offset between consecutive generic vertex attributes
offset // specifies a pointer to the first component of the first generic vertex attribute …Run Code Online (Sandbox Code Playgroud) 编辑II:
当前代码效果很好!感谢大家.我继续把我的着色器代码包含在底部以供参考,尽管它们在这一点上确实没有做任何事情.
我正在尝试使用OpenGL 4.1并且仍处于开发阶段.目前我在这个项目中还没有真正使用4.0功能,所以这也是一个OpenGL 3问题.
我首先要完成的目标只是编写两个类来处理VAO和VBO.我有一些误解,但终于通过了空白屏幕.
/* THIS CODE IS NOW FULLY FUNCTIONAL */
/* well, fully is questionable lol, should work out of the box with glew and glfw */
/* A simple function that will read a file into an allocated char pointer buffer */
/* Borrowed from OpenGL.org tutorial */
char* filePull(char *file)
{
FILE *fptr;
long length;
char *buf;
fptr = fopen(file, "r"); /* Open file for reading */
if (!fptr) /* Return NULL on failure …Run Code Online (Sandbox Code Playgroud) 我已经初始化了 glewInit( ) 和任何其他 openGL 东西。所有这些都是在我拨打这些电话之前进行的。
glGenBuffers( 1, &m_uiVertBufferHandle );
glBindBuffer( GL_ARRAY_BUFFER, m_uiVertBufferHandle );
glBufferData( GL_ARRAY_BUFFER, 0, 0, GL_READ_WRITE );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
Run Code Online (Sandbox Code Playgroud)
这就是我创建缓冲区对象的方式,ii 执行了 glBufferData,因为我在 openGL 文章中读到,如果您不至少调用一次它,则根本没有任何存储空间,这将使 glMapBuffer 总是给您 0x00000000。
稍后我调用 glMapBuffer 来获取我的存储位置以开始保存数据,当我使用 glMapBuffer 时我这样称呼它
void* buffer1;
glBindBuffer( GL_ARRAY_BUFFER, m_uiVertBufferHandle );
//make sure our buffer excists
buffer1 = glMapBuffer( GL_ARRAY_BUFFER, GL_READ_WRITE );
Run Code Online (Sandbox Code Playgroud)
我的 buffer1 中总是得到 0x00000000。为什么是这样?我发现的唯一两个原因是我没有正确初始化 glewInit (我已经完成了)并且我没有至少调用一次 glBindBufferData 。
我面临着许多开发人员可能找到解决方案的问题.我有一个小项目,地板设计有小立方体(100X100).如果我超过这个限制,我的游戏遭遇重大减速和联赛!
这是我如何画地板的:
//Function to draw my ground ( 100 X 100 X 1)
public void DrawGround(GameTime gameTime)
{
// Copy any parent transforms.
Matrix[] transforms = new Matrix[this.model.Bones.Count];
this.model.CopyAbsoluteBoneTransformsTo(transforms);
//loop 1 cube high
for (int a = 0; a < 1; a++)
{
//loop 100 along cube
for (int b = 0; b < 100; b++)
{
//loop 100 cubic wide
for (int c = 0; c < 100; c++)
{
// Draw the model. A model can have multiple …Run Code Online (Sandbox Code Playgroud) 对于每个属性,使用跨步顶点缓冲区与紧密打包缓冲区有什么优缺点?我的意思是例如:
步幅: xyzrgb xyzrgb xyzrgb
紧: xyzxyzxyz rgbrgbrgb
乍一看,您看起来很容易在使用跨步时更改大小,但是当您使用进行重新分配时,顶点缓冲区的内容将被删除glBufferData()。
对我来说,最好使用紧密模型,因为位置,颜色和texcoords可能来自本地内存中的不同数组,并且因为没有跨步缓冲区数据函数;您必须在上传之前将所有数组复制到交错缓冲区中,或者glBufferSubData()每个属性每个顶点使用一个(我猜这是一个糟糕的主意)。
似乎通常使用交错缓冲区(步幅)。这是为什么?我在这里想念什么吗?
如果我的顶点位置是共享的,但是我的法线和UV不是(为了保留硬边等),是否可以在DirectX11中使用非交错缓冲区来解决这个内存表示,这样我就可以使用indice缓冲区了?或者我应该在交错缓冲区中坚持重复的顶点位置?
交错和非交错顶点缓冲区之间是否有任何性能问题?谢谢!
所以我正在寻找关于命令glVertexAttribPointer的另一个SO问题,我遇到了一些轻微的混乱.这个问题的接受答案解释了,
但是当你进行调用时,还会有一个额外的隐含状态,它也会被存储为属性0:从当前绑定到GL_ARRAY_BUFFER的缓冲区中读取数据
这对我来说很有意义,但如果我有多个绑定的缓冲区GL_ARRAY_BUFFER呢?该glVertexAttribPointer()方法如何知道设置属性的方法?
例如,在我的代码中,我正在绘制一个渐变三角形.为此,我创建了2个VBO,一个是数组中的颜色数据,另一个是顶点位置.
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
static const GLfloat points[] = {
//data here
};
static const GLfloat colors[] = {
//data here
};
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
vs = glCreateShader(GL_VERTEX_SHADER);
fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vs, 1, &vertexShaderData, NULL);
glShaderSource(fs, 1, &fragShaderData, NULL);
glCompileShader(vs);
glCompileShader(fs);
sp=glCreateProgram();
glBindFragDataLocation(sp, 0, "outColor");
glAttachShader(sp, vs);
glAttachShader(sp, fs);
glLinkProgram(sp);
glUseProgram(sp);
glGenBuffers(1, &colorBuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); …Run Code Online (Sandbox Code Playgroud) c++ opengl vertex-buffer vertex-attributes vertex-array-object
我知道如何创建MTLBuffer和/或MTLTexture但是如何在不再需要这些资源时释放GPU内存?
我读过,VBO(顶点缓冲区对象)本质上保留了一个引用计数,因此,如果将 VBO 的名称指定给 ,那么glDeleteBuffers()如果活动的 VAO(顶点数组对象)仍然引用它,它就不会真正被忽略。这种行为类似于越来越多的新语言采用的“智能指针”。但在多大程度上这是正确的并且可以围绕它进行设计,以及它是否也适用于 IBO(索引缓冲区对象),我还没有找到任何相关信息。
如果一个 VBO 被引用它的 VAO 保持存活,并且我不打算在 VAO 死亡后更新它或使用它,我认为最好的做法是销毁我对它的引用。这样做合适吗?我可以对 IBO 做同样的事情吗?
假设我有一个顶点数组和一个VBO指针:
std::vector<Vertex> vertices;
GLuint vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
Run Code Online (Sandbox Code Playgroud)
现在我缓冲数据:
glBufferData(
GL_ARRAY_BUFFER,
vertices.size()*sizeof(Vertex),
&vertices[0],
GL_STATIC_DRAW
);
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,我仍然需要保持顶点数组GL_STATIC_DRAW.但是,如果我将其更改为GL_STATIC_COPY然后所有数据都将被复制到GPU的内存中,这样我就可以释放所使用的内存vertices.那是对的吗?如果是这样的话我们为什么需要*_DRAW?由于GPU的内存限制,这有用吗?加上GL_STATIC_READ真的有用吗?
vertex-buffer ×10
opengl ×7
c++ ×5
vbo ×2
3d ×1
class ×1
directx ×1
graphics ×1
index-buffer ×1
metal ×1
opengl-3 ×1
performance ×1
textures ×1
vertex ×1
vertexdata ×1
xna ×1