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

重庆百度网站快速排名烟台公司网站建设

重庆百度网站快速排名,烟台公司网站建设,网页制作软件下载教程,20条优化防疫措施方案WebGPU(七):C头部封装 在前面的学习中,我们使用的都是原生态的WebGPU API,那是基于C语言的API,但是为了更高效的开发,我们可以使用一个基于C的库。 根据参考的教程,这个github库提供更加纤细的描述。它提…

WebGPU(七):C++头部封装

在前面的学习中,我们使用的都是原生态的WebGPU API,那是基于C语言的API,但是为了更高效的开发,我们可以使用一个基于C++的库。

根据参考的教程,这个github库提供更加纤细的描述。它提供了一个webgpu.hpp的C++封装头文件,但是在Dawn的代码实现中,本身包含一个C++头封装文件,本例程主要使用Dawn自带的C++封装头文件。

#define WEBGPU_CPP_IMPLEMENTATION
#include <webgpu/webgpu.hpp>#include <glfw3webgpu.h>
#include <GLFW/glfw3.h>#include <iostream>
#include <cassert>#define UNUSED(x) (void)x;using namespace wgpu;int main (int, char**) {Instance instance = createInstance(InstanceDescriptor{});if (!instance) {std::cerr << "Could not initialize WebGPU!" << std::endl;return 1;}if (!glfwInit()) {std::cerr << "Could not initialize GLFW!" << std::endl;return 1;}glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);GLFWwindow* window = glfwCreateWindow(640, 480, "Learn WebGPU", NULL, NULL);if (!window) {std::cerr << "Could not open window!" << std::endl;return 1;}std::cout << "Requesting adapter..." << std::endl;Surface surface = glfwGetWGPUSurface(instance, window);RequestAdapterOptions adapterOpts{};adapterOpts.compatibleSurface = surface;Adapter adapter = instance.requestAdapter(adapterOpts);std::cout << "Got adapter: " << adapter << std::endl;std::cout << "Requesting device..." << std::endl;DeviceDescriptor deviceDesc{};deviceDesc.label = "My Device";deviceDesc.requiredFeaturesCount = 0;deviceDesc.requiredLimits = nullptr;deviceDesc.defaultQueue.label = "The default queue";Device device = adapter.requestDevice(deviceDesc);std::cout << "Got device: " << device << std::endl;Queue queue = device.getQueue();auto onDeviceError = [](WGPUErrorType type, char const* message, void* /* pUserData */) {std::cout << "Uncaptured device error: type " << type;if (message) std::cout << " (" << message << ")";std::cout << std::endl;};wgpuDeviceSetUncapturedErrorCallback(device, onDeviceError, nullptr /* pUserData */);std::cout << "Creating swapchain device..." << std::endl;
#ifdef WEBGPU_BACKEND_WGPUTextureFormat swapChainFormat = surface.getPreferredFormat(adapter);
#elseTextureFormat swapChainFormat = TextureFormat::BGRA8Unorm;
#endifSwapChainDescriptor swapChainDesc = {};swapChainDesc.width = 640;swapChainDesc.height = 480;swapChainDesc.usage = TextureUsage::RenderAttachment;swapChainDesc.format = swapChainFormat;swapChainDesc.presentMode = PresentMode::Fifo;SwapChain swapChain = device.createSwapChain(surface, swapChainDesc);std::cout << "Swapchain: " << swapChain << std::endl;while (!glfwWindowShouldClose(window)) {glfwPollEvents();TextureView nextTexture = swapChain.getCurrentTextureView();if (!nextTexture) {std::cerr << "Cannot acquire next swap chain texture" << std::endl;return 1;}CommandEncoderDescriptor commandEncoderDesc{};commandEncoderDesc.label = "Command Encoder";CommandEncoder encoder = device.createCommandEncoder(commandEncoderDesc);RenderPassDescriptor renderPassDesc{};WGPURenderPassColorAttachment renderPassColorAttachment = {};renderPassColorAttachment.view = nextTexture;renderPassColorAttachment.resolveTarget = nullptr;renderPassColorAttachment.loadOp = LoadOp::Clear;renderPassColorAttachment.storeOp = StoreOp::Store;renderPassColorAttachment.clearValue = Color{ 0.9, 0.1, 0.2, 1.0 };renderPassDesc.colorAttachmentCount = 1;renderPassDesc.colorAttachments = &renderPassColorAttachment;renderPassDesc.depthStencilAttachment = nullptr;renderPassDesc.timestampWriteCount = 0;renderPassDesc.timestampWrites = nullptr;RenderPassEncoder renderPass = encoder.beginRenderPass(renderPassDesc);renderPass.end();nextTexture.release();CommandBufferDescriptor cmdBufferDescriptor{};cmdBufferDescriptor.label = "Command buffer";CommandBuffer command = encoder.finish(cmdBufferDescriptor);queue.submit(command);swapChain.present();}glfwDestroyWindow(window);glfwTerminate();return 0;
}

因为在测试的时候发现,有很多函数都没有相对应的封装,所以这一步的代码修改的内容相对而言很少。

http://www.yayakq.cn/news/180324/

相关文章:

  • asp网站ftp入侵最好玩的网页游戏
  • 三合一静态网站个人网站制作手绘
  • 手机网页前端开发江苏网站建设 seo
  • 郴州做网站的公司wordpress调用api接口
  • 无忧传媒在短视频领域的成就网站权重优化
  • 乐之网站制作网站开发哪便宜
  • 网站怎样做seo推广学习php网站开发
  • 有源代码怎么制作网站请问下网站开发怎么弄
  • php 个人网站电商插件 wordpress
  • 平台营销型网站建设餐饮业网站建设
  • 西宁网站seo公司做直播的小视频在线观看网站
  • 怎么用腾讯云服务器做网站网页设计个人主页模板
  • 南通医院网站建设方案百度最新版本2022
  • win2008r做网站做哪个网站的推广最好
  • 自己建的网站打开的特别慢注册网站域名需要什么资料医疗器械
  • 设计师做兼职的网站国际新闻界期刊
  • 网站链接导出深入网站开发和运维
  • 网站的表现形式研究院网站建设
  • 网页设计工作岗位及薪资阳江市企业网站优化
  • 用windows搭建手机网站ppt网站模板
  • 做.net网站流程网站建设开发人员须知
  • 微信号注册官方网站商洛市商南县城乡建设局网站
  • 在服务器网站上做跳转河北建筑工程网
  • wordpress软件站西部数码网站管理助手4.0
  • 手工艺品网站建设侧胡顺短视频运营计划书
  • 新乡百度网站推广工具如何建设好企业的网站维护
  • 是不是做网站就能赚钱科技网站设计欣赏
  • 展示用网站模板产品推广哪个平台好
  • 嘉兴快速建站合作wordpress中文语言包
  • 百度推广公司电话google推广seo