国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绿春县| 万州区| 开阳县| 南昌市| 台南市| 黔西| 南川市| 东阿县| 宁化县| 宾川县| 芜湖县| 邻水| 天水市| 绍兴市| 昌图县| 鹤峰县| 洛川县| 屏边| 水城县| 东源县| 根河市| 湟源县| 中阳县| 惠水县| 睢宁县| 苏尼特左旗| 安吉县| 霞浦县| 抚顺市| 文水县| 柯坪县| 施甸县| 尤溪县| 博湖县| 麻城市| 清新县| 舞阳县| 宜兴市| 彭州市| 南澳县| 南城县|