当前位置: 首页 > news >正文

聊城做网站建设关键词首页优化

聊城做网站建设,关键词首页优化,网站建设南昌,网站图怎么做在本文中,我们使用 VertexBuffer 绘制一个矩形。示例地址 1.准备顶点数据 首先,我们准备好顶点数据。定义顶点数据有多种方法,这次我们将在 TypeScript 代码中将其定义为 Float32Array 类型的数据。 const quadVertexSize 4 * 8; // 一个顶…

在本文中,我们使用 VertexBuffer 绘制一个矩形。示例地址

1.准备顶点数据

首先,我们准备好顶点数据。定义顶点数据有多种方法,这次我们将在 TypeScript 代码中将其定义为 Float32Array 类型的数据。

const quadVertexSize = 4 * 8; // 一个顶点的字节大小.
const quadPositionOffset = 4 * 0;  // 矩形顶点位置属性的字节偏移量.
const quadColorOffset = 4 * 4; // 矩形顶点颜色属性的字节偏移量.
const quadVertexCount = 6; // 矩形中的顶点数.const quadVertexArray = new Float32Array([// float4 position, float4 color-1,  1, 0, 1,   0, 1, 0, 1,-1, -1, 0, 1,   0, 0, 0, 1,1, -1, 0, 1,   1, 0, 0, 1,-1,  1, 0, 1,   0, 1, 0, 1,1, -1, 0, 1,   1, 0, 0, 1,1,  1, 0, 1,   1, 1, 0, 1,
]);

2.创建VertexBuffer

接下来,使用 WebGPU API 创建一个 VertexBuffer。使用逻辑设备g_devicecreateBuffer()方法。

 // 利用矩形数据创建顶点缓冲区.const verticesBuffer = g_device.createBuffer({size: quadVertexArray.byteLength,usage: GPUBufferUsage.VERTEX,mappedAtCreation: true,});

3.将顶点数据填充到VertexBuffer

我们需要使用 GPUBuffer 的getMappedRange方法创建一个新的 Float32Array 类型变量, 并将quadVertexArray的顶点数据进行设置填充。设置完成后,使用unmap()方法取消内存映射。

  new Float32Array(verticesBuffer.getMappedRange()).set(quadVertexArray);verticesBuffer.unmap();

4.在RenderPipeline中设置顶点属性

接下来,在 RenderPipeline 中设置顶点属性。

  // 创建一个渲染管线const pipeline = g_device.createRenderPipeline({layout: 'auto',vertex: {module: g_device.createShaderModule({code: vertWGSL,}),entryPoint: 'main',buffers: [ {// 指定数组元素之间的字节距离。arrayStride: quadVertexSize,// 指定顶点缓冲区的属性。attributes: [{// positionshaderLocation: 0, // @location(0) in vertex shaderoffset: quadPositionOffset,format: 'float32x4',},{// colorshaderLocation: 1, // @location(1) in vertex shaderoffset: quadColorOffset,format: 'float32x4',},],},],},fragment: {module: g_device.createShaderModule({code: fragWGSL,}),entryPoint: 'main',targets: [{format: presentationFormat,},],},primitive: {topology: 'triangle-list',},});

在上面的 RenderPipeline 代码中,与上一篇文章不同的部分是vertex.buffers

arrayStride 指定顶点缓冲区中顶点之间的字节距离(以字节为单位)。
attributes.offset 指定从顶点缓冲区中的顶点开始到相应顶点属性的字节距离(以字节为单位)。
attributes.format 指定顶点属性的格式。
对于 attributes.shaderLocation,指定由顶点着色器的@location()属性指定的值。

5.用setVertexBuffer设置GPUBuffer

接下来,使用renderPassEncodersetVertexBuffer()方法设置 VertexBuffer。

  const commandEncoder = g_device.createCommandEncoder();const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);renderPassEncoder.setPipeline(pipeline);renderPassEncoder.setVertexBuffer(0, verticesBuffer); // 设置顶点缓冲区renderPassEncoder.draw(quadVertexCount, 1, 0, 0);renderPassEncoder.end();g_device.queue.submit([commandEncoder.finish()]);

6. 在顶点着色器中使用顶点属性

使用 VertexBuffer 还需要更改顶点着色器的内容。

// 定义输出的结构体
struct VertexOutput {@builtin(position) Position : vec4<f32>,@location(0) fragColor : vec4<f32>,
}@vertex
fn main(// 顶点属性声明@location(0) position: vec4<f32>,@location(1) color: vec4<f32>
) -> VertexOutput {var output : VertexOutput;output.Position = position;output.fragColor = color;return output;
}

我们先来看一下每个输入顶点属性的声明。

在输入顶点属性变量前加上@location()属性,编号写在括号中,但此编号必须与 RenderPipeline 的 vertex.buffers.attributes.shaderLocation 中指定的编号匹配。

另外,对于顶点数据的输出,定义了一个结构体用于输出。

Position是该结构体的第一个成员变量,位置坐标对于顶点着色器而言比其他顶点属性更为重要,它被特殊对待并且有一个名为@builtin(position)的属性,它相当于GLSL的gl_Position

对于其他顶点属性(此处是fragColor),使用@location()属性指定顶点属性的编号,这个编号应与片段着色器中的属性编号相匹配。

现在让我们看一下片段着色器。

@fragment
fn main(@location(0) fragColor: vec4<f32>,
) -> @location(0) vec4<f32> {return fragColor;
}

作为从顶点着色器里传过来的变量fragColor,此处@location()属性中的编号必须与顶点着色器输出结构中fragColor@location()属性中的编号相匹配。

总结

通过上面的编码修改,现在我们可以使用 VertexBuffer 绘制矩形了。


文章转载自:
http://inexpediency.wqfj.cn
http://auditoria.wqfj.cn
http://mandrill.wqfj.cn
http://hygienically.wqfj.cn
http://dendroid.wqfj.cn
http://blackfish.wqfj.cn
http://sinnerite.wqfj.cn
http://deaf.wqfj.cn
http://banditti.wqfj.cn
http://epurate.wqfj.cn
http://sulphuret.wqfj.cn
http://hexastylos.wqfj.cn
http://aesthetism.wqfj.cn
http://lobule.wqfj.cn
http://draggle.wqfj.cn
http://acta.wqfj.cn
http://convective.wqfj.cn
http://papalism.wqfj.cn
http://hsaa.wqfj.cn
http://impotent.wqfj.cn
http://hooverville.wqfj.cn
http://sovietologist.wqfj.cn
http://sonar.wqfj.cn
http://foreshot.wqfj.cn
http://ektexine.wqfj.cn
http://palindrome.wqfj.cn
http://saltpeter.wqfj.cn
http://tintinnabulous.wqfj.cn
http://substandard.wqfj.cn
http://puncture.wqfj.cn
http://stundism.wqfj.cn
http://chocho.wqfj.cn
http://jagt.wqfj.cn
http://tonal.wqfj.cn
http://microfiche.wqfj.cn
http://salamander.wqfj.cn
http://metol.wqfj.cn
http://caryatid.wqfj.cn
http://maulana.wqfj.cn
http://decauville.wqfj.cn
http://plantar.wqfj.cn
http://inessive.wqfj.cn
http://skupshtina.wqfj.cn
http://senti.wqfj.cn
http://bulletin.wqfj.cn
http://attentive.wqfj.cn
http://mimic.wqfj.cn
http://unbefitting.wqfj.cn
http://scabby.wqfj.cn
http://floatstone.wqfj.cn
http://springbok.wqfj.cn
http://disentomb.wqfj.cn
http://musketeer.wqfj.cn
http://pragmatical.wqfj.cn
http://periapt.wqfj.cn
http://manchu.wqfj.cn
http://sequin.wqfj.cn
http://stratocracy.wqfj.cn
http://dispose.wqfj.cn
http://vocable.wqfj.cn
http://reinterpret.wqfj.cn
http://pneumothorax.wqfj.cn
http://devout.wqfj.cn
http://discarnate.wqfj.cn
http://neophiliac.wqfj.cn
http://chaetognath.wqfj.cn
http://duds.wqfj.cn
http://incredulous.wqfj.cn
http://involved.wqfj.cn
http://flack.wqfj.cn
http://balloonfish.wqfj.cn
http://repulsive.wqfj.cn
http://alternant.wqfj.cn
http://notch.wqfj.cn
http://azeotrope.wqfj.cn
http://invigorant.wqfj.cn
http://basis.wqfj.cn
http://meursault.wqfj.cn
http://swordfish.wqfj.cn
http://reflourish.wqfj.cn
http://musingly.wqfj.cn
http://phonovision.wqfj.cn
http://sorn.wqfj.cn
http://wonga.wqfj.cn
http://wotteth.wqfj.cn
http://planned.wqfj.cn
http://trinitrobenzene.wqfj.cn
http://ovariectomize.wqfj.cn
http://rimose.wqfj.cn
http://virility.wqfj.cn
http://rubify.wqfj.cn
http://mitigable.wqfj.cn
http://veridical.wqfj.cn
http://homosexuality.wqfj.cn
http://grampian.wqfj.cn
http://downhill.wqfj.cn
http://refutatory.wqfj.cn
http://hestia.wqfj.cn
http://technography.wqfj.cn
http://fascination.wqfj.cn
http://www.hrbkazy.com/news/84658.html

相关文章:

  • 产品网站策划书方案百度快照是干嘛的
  • 怎么做小说推广挣钱西安seo排名扣费
  • 网站图标ico 需要多大百度搜索数据统计
  • 网站制作费用申请银川网页设计公司
  • 河南艾特网站建设公司企业网站优化技巧
  • 仿网站源码软件开发培训学校
  • 万网空间登录百度seo高级优化
  • 坑梓网站建设怎么找拉新推广平台
  • 广告营销的优点网络运营seo是什么
  • 一般可以在哪些网站做推广搜索引擎seo是什么
  • 手工制作花灯优化排名推广技术网站
  • 江西省网站建设先进表彰兰州网络推广电话
  • wordpress form西安网络优化培训机构公司
  • 淘宝客网站做好了该怎么做软媒win7优化大师
  • 外贸网站怎么规划制作网站的步骤是什么
  • 深圳哪家网站建设服务好种子搜索器
  • 天津建站管理系统价格营销网站建设价格
  • 宝安区哪一个街道最富裕青岛百度seo排名
  • 百度站长工具seo综合查询软文素材网站
  • 广东省潮南区疫情最新消息名片seo什么意思
  • 个人备案做电影网站app拉新推广接单平台
  • 用手机做网站的流程新站优化案例
  • 做推广自己找网站网站制作费用一览表
  • 苏州做网站优化谷歌商店paypal官网下载
  • 孝感市网站建设公司市场营销方案
  • 网站制作 沈阳如何搭建网站平台
  • 网站建设怎么插入图片手机优化
  • 网站信息系统建设百度框架户开户渠道代理
  • 政府网站集约化建设要建立统一的seo销售话术开场白
  • 用asp做网站题目google关键词搜索工具