demo->vertices.vi.pVertexAttributeDescriptions = demo->vertices.vi_attrs;//vi_attrs是关键
demo->vertices.vi_attrs[0].binding = VERTEX_BUFFER_BIND_ID; demo->vertices.vi_attrs[0].location = 0; demo->vertices.vi_attrs[0].format = VK_FORMAT_R32G32B32_SFLOAT; demo->vertices.vi_attrs[0].offset = 0; demo->vertices.vi_attrs[1].binding = VERTEX_BUFFER_BIND_ID; demo->vertices.vi_attrs[1].location = 1; demo->vertices.vi_attrs[1].format = VK_FORMAT_R32G32_SFLOAT; demo->vertices.vi_attrs[1].offset = sizeof(float) * 3;7.在create pipeline的时候传入刚创建的vi:pipeline.pVertexInputState = &vi;8.build cmd的时候,bind之前创建的vertex buffer vkCmdBindVertexBuffers(demo->draw_cmd, VERTEX_BUFFER_BIND_ID, 1,&demo->vertices.buf, offsets); vkCmdDraw(demo->draw_cmd, 3, 1, 0, 0); vkCmdEndRenderPass(demo->draw_cmd);9.在shader中使用vertex buffer vs #version 400 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable layout (location = 0) in vec4 pos; layout (location = 1) in vec2 attr; layout (location = 0) out vec2 texcoord; void main() { texcoord = attr; gl_Position = pos; } fs #version 400 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable layout (binding = 0) uniform sampler2D tex; layout (location = 0) in vec2 texcoord; layout (location = 0) out vec4 uFragColor; void main() { uFragColor = texture(tex, texcoord); } comment:layout(location = attribute index) in vec3 position;跟glBindAttribLocation的功能类似,设置position使用哪个属性:
static const GLfloat verts[3][2] = { { -0.5, -0.5 }, { 0.5, -0.5 }, { 0, 0.5 } };"attribute vec4 pos;/n"//in shaderglBindAttribLocation(PRogram, window->gl.pos, "pos");glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);glEnableVertexAttribArray(window->gl.pos);glDrawArrays()
新闻热点
疑难解答