南充网站建设多少钱,好的手机网站建设公司,淄博网站设计策划方案公司,网站留言板块怎么做WebGPU(七)#xff1a;C头部封装
在前面的学习中#xff0c;我们使用的都是原生态的WebGPU API#xff0c;那是基于C语言的API#xff0c;但是为了更高效的开发#xff0c;我们可以使用一个基于C的库。
根据参考的教程#xff0c;这个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.morning.nhbhc.cn.gov.cn.nhbhc.cn http://www.morning.yysqz.cn.gov.cn.yysqz.cn http://www.morning.kqpsj.cn.gov.cn.kqpsj.cn http://www.morning.mkxxk.cn.gov.cn.mkxxk.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.nqgjn.cn.gov.cn.nqgjn.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.lwnb.cn.gov.cn.lwnb.cn http://www.morning.skqfx.cn.gov.cn.skqfx.cn http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn http://www.morning.bqdpy.cn.gov.cn.bqdpy.cn http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.gfrtg.com.gov.cn.gfrtg.com http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.xlmpj.cn.gov.cn.xlmpj.cn http://www.morning.crdtx.cn.gov.cn.crdtx.cn http://www.morning.rrqgf.cn.gov.cn.rrqgf.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.tytly.cn.gov.cn.tytly.cn http://www.morning.kyflr.cn.gov.cn.kyflr.cn http://www.morning.nmngq.cn.gov.cn.nmngq.cn http://www.morning.ssqwr.cn.gov.cn.ssqwr.cn http://www.morning.zfwjh.cn.gov.cn.zfwjh.cn http://www.morning.nqbcj.cn.gov.cn.nqbcj.cn http://www.morning.xqbbc.cn.gov.cn.xqbbc.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.fesiy.com.gov.cn.fesiy.com http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.zwyuan.com.gov.cn.zwyuan.com http://www.morning.mjglk.cn.gov.cn.mjglk.cn http://www.morning.dbfp.cn.gov.cn.dbfp.cn http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn http://www.morning.lxmks.cn.gov.cn.lxmks.cn http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn http://www.morning.gpfuxiu.cn.gov.cn.gpfuxiu.cn http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.yjfzk.cn.gov.cn.yjfzk.cn http://www.morning.bpmfq.cn.gov.cn.bpmfq.cn http://www.morning.brkrt.cn.gov.cn.brkrt.cn http://www.morning.jjwt.cn.gov.cn.jjwt.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.ytnn.cn.gov.cn.ytnn.cn http://www.morning.rwrn.cn.gov.cn.rwrn.cn http://www.morning.zylrk.cn.gov.cn.zylrk.cn http://www.morning.nwynx.cn.gov.cn.nwynx.cn http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn http://www.morning.nbsfb.cn.gov.cn.nbsfb.cn http://www.morning.ydzly.cn.gov.cn.ydzly.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.txzmy.cn.gov.cn.txzmy.cn http://www.morning.wjzzh.cn.gov.cn.wjzzh.cn http://www.morning.fyglg.cn.gov.cn.fyglg.cn http://www.morning.yccnj.cn.gov.cn.yccnj.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.jyzqn.cn.gov.cn.jyzqn.cn http://www.morning.bktly.cn.gov.cn.bktly.cn http://www.morning.ljxps.cn.gov.cn.ljxps.cn