init method
dynamic
init()
Implementation
init() {
var parameters = this._parameters;
var adapterOptions = GPURequestAdapterOptions(
powerPreference: parameters["powerPreference"]);
var adapter = requestAdapter(adapterOptions);
if (adapter == null) {
throw ('WebGPURenderer: Unable to create WebGPU adapter.');
}
var deviceDescriptor = GPUDeviceDescriptor(maxBindGroups: 1);
// "requiredFeatures": parameters["requiredFeatures"],
// "requiredLimits": parameters["requiredLimits"]
var device = adapter.requestDevice(deviceDescriptor);
// var context = ( parameters["context"] != undefined ) ? parameters["context"] : this.domElement.getContext( 'webgpu' );
// context.configure( {
// "device": device,
// "format": GPUTextureFormat.BGRA8Unorm // this is the only valid context format right now (r121)
// } );
this._adapter = adapter;
this._device = device;
// this._context = context;
this._info = new WebGPUInfo();
this._properties = new WebGPUProperties();
this._attributes = new WebGPUAttributes(device);
this._geometries = new WebGPUGeometries(this._attributes, this._info);
this._textures = new WebGPUTextures(device, this._properties, this._info);
this._objects = new WebGPUObjects(this._geometries, this._info);
this._nodes = new WebGPUNodes(this);
this._computePipelines = new WebGPUComputePipelines(device);
this._renderPipelines = new WebGPURenderPipelines(
this, device, parameters["sampleCount"], this._nodes);
this._renderPipelines.bindings = new WebGPUBindings(
device,
this._info,
this._properties,
this._textures,
this._renderPipelines,
this._computePipelines,
this._attributes,
this._nodes);
this._bindings = this._renderPipelines.bindings;
this._renderLists = new WebGPURenderLists();
this._background = new WebGPUBackground(this);
//
// TODO 每次都创建新对象 优化??
this._renderPassDescriptor = GPURenderPassDescriptor(
colorAttachments: GPURenderPassColorAttachment(
clearColor: GPUColor(r: 0.0, g: 0.0, b: 0.0, a: 1.0),
loadOp: GPULoadOp.Clear,
storeOp: GPUStoreOp.Store
),
depthStencilAttachment: GPURenderPassDepthStencilAttachment(
depthStoreOp: GPUStoreOp.Store,
depthLoadOp: GPULoadOp.Clear,
stencilStoreOp: GPUStoreOp.Store,
stencilLoadOp: GPULoadOp.Clear,
)
);
this._setupColorBuffer();
this._setupDepthBuffer();
}