MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / createAreaRenderer

Function createAreaRenderer

src/renderers/createAreaRenderer.ts:131–300  ·  view source on GitHub ↗
(device: GPUDevice, options?: AreaRendererOptions)

Source from the content-addressed store, hash-verified

129};
130
131export function createAreaRenderer(device: GPUDevice, options?: AreaRendererOptions): AreaRenderer {
132 let disposed = false;
133 const targetFormat = options?.targetFormat ?? DEFAULT_TARGET_FORMAT;
134
135 const bindGroupLayout = device.createBindGroupLayout({
136 entries: [
137 { binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } },
138 { binding: 1, visibility: GPUShaderStage.FRAGMENT, buffer: { type: 'uniform' } },
139 ],
140 });
141
142 const vsUniformBuffer = createUniformBuffer(device, 96, { label: 'areaRenderer/vsUniforms' });
143 const fsUniformBuffer = createUniformBuffer(device, 16, { label: 'areaRenderer/fsUniforms' });
144
145 // Reused CPU-side staging for uniform writes (avoid per-frame allocations).
146 const vsUniformScratchBuffer = new ArrayBuffer(96);
147 const vsUniformScratchF32 = new Float32Array(vsUniformScratchBuffer);
148 const fsUniformScratchF32 = new Float32Array(4);
149
150 const bindGroup = device.createBindGroup({
151 layout: bindGroupLayout,
152 entries: [
153 { binding: 0, resource: { buffer: vsUniformBuffer } },
154 { binding: 1, resource: { buffer: fsUniformBuffer } },
155 ],
156 });
157
158 const pipeline = createRenderPipeline(device, {
159 label: 'areaRenderer/pipeline',
160 bindGroupLayouts: [bindGroupLayout],
161 vertex: {
162 code: areaWgsl,
163 label: 'area.wgsl',
164 buffers: [
165 {
166 arrayStride: 8,
167 stepMode: 'vertex',
168 attributes: [{ shaderLocation: 0, format: 'float32x2', offset: 0 }],
169 },
170 ],
171 },
172 fragment: {
173 code: areaWgsl,
174 label: 'area.wgsl',
175 formats: targetFormat,
176 // Enable standard alpha blending so `areaStyle.opacity` behaves correctly.
177 blend: {
178 color: { operation: 'add', srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha' },
179 alpha: { operation: 'add', srcFactor: 'one', dstFactor: 'one-minus-src-alpha' },
180 },
181 },
182 primitive: { topology: 'triangle-strip', cullMode: 'none' },
183 multisample: { count: 1 },
184 });
185
186 let vertexBuffer: GPUBuffer | null = null;
187 let vertexCount = 0;
188

Callers 1

ensureAreaRendererCountFunction · 0.90

Calls 2

createUniformBufferFunction · 0.90
createRenderPipelineFunction · 0.90

Tested by

no test coverage detected