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

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

vulkan中vertex buffer的用法

2019-11-09 17:48:46
字體:
來源:轉載
供稿:網友
-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()


上一篇:啟動圖片的設置

下一篇:Masonry

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 搜索| 宁南县| 辽宁省| 什邡市| 通化市| 上饶市| 龙江县| 仁布县| 丰镇市| 澄江县| 谢通门县| 武宣县| 乐清市| 河北省| 兴宁市| 苍山县| 库伦旗| 峡江县| 屏东市| 辉县市| 武清区| 隆尧县| 罗田县| 定结县| 青浦区| 泰顺县| 库尔勒市| 阜新市| 乐清市| 清徐县| 锦州市| 达州市| 淄博市| 苏尼特左旗| 闽清县| 盈江县| 临海市| 浦东新区| 永新县| 二手房| 应用必备|