国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

vulkan中vertex buffer的用法

2019-11-09 16:47:53
字體:
來源:轉載
供稿:網友
-Vulkan的資源(buffer或者image)都用descriptor表示,vertex buffer也是以descriptor的形式來分配和使用的下面講的是如果使用vertex buffer來向shader傳遞頂點數據1.準備vertex數據    const float vb[3][5] = {        /*      position             texcoord */        { -1.0f, -1.0f,  0.25f,     0.0f, 0.0f },        {  1.0f, -1.0f,  0.25f,     1.0f, 0.0f },        {  0.0f,  1.0f,  1.0f,      0.5f, 1.0f },    };2.調用vkCreateBuffer創建VkBuffer(buf),然后用vkAllocateMemory來分配device內存(men)3.vkMapMemory將device內存map到cpu端(data)4.memcpy(data, vb, sizeof(vb));5.調用vkBindBufferMemory(device,buf,mem)將device內存和vkbuffer綁定6.創建vi,VkPipelineVertexInputStateCreateInfo vi    demo->vertices.vi.vertexAttributeDescriptionCount = 2;

    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()


上一篇:Smaller apk

下一篇:JSonKit支持 ARC

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东宁县| 桂东县| 雅安市| 大同县| 临颍县| 江孜县| 涟源市| 大化| 林口县| 登封市| 开封市| 鸡东县| 龙井市| 东台市| 新闻| 汕尾市| 江安县| 呼和浩特市| 建始县| 竹山县| 鄯善县| 吉林省| 乐业县| 营山县| 抚松县| 滦平县| 二连浩特市| 崇仁县| 德庆县| 新化县| 公主岭市| 灯塔市| 龙胜| 阳西县| 宽城| 龙岩市| 九龙县| 武冈市| 江安县| 翁源县| 广水市|