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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临漳县| 垫江县| 如东县| 维西| 呼和浩特市| 西和县| 紫阳县| 磐安县| 石景山区| 察哈| 黄浦区| 禹城市| 独山县| 航空| 大同市| 天镇县| 交城县| 安国市| 施秉县| 武冈市| 全州县| 黄山市| 康定县| 金门县| 砀山县| 福泉市| 吴忠市| 新安县| 双柏县| 文化| 都匀市| 江永县| 桂东县| 黄浦区| 勃利县| 涞水县| 澄迈县| 翁牛特旗| 寿光市| 开阳县| 杭锦后旗|