Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/gpu/rectangleRenderer.wgsl.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export const enum RectangleRendererBindingId {
7
Shapes,
8
LayoutInfoUniform,
9
ScrollOffset,
10
}
11
12
export const rectangleRendererWgsl = /*wgsl*/ `
13
14
struct Vertex {
15
@location(0) position: vec2f,
16
};
17
18
struct LayoutInfo {
19
canvasDims: vec2f,
20
viewportOffset: vec2f,
21
viewportDims: vec2f,
22
}
23
24
struct ScrollOffset {
25
offset: vec2f,
26
}
27
28
struct Shape {
29
position: vec2f,
30
size: vec2f,
31
color: vec4f,
32
};
33
34
struct VSOutput {
35
@builtin(position) position: vec4f,
36
@location(1) color: vec4f,
37
};
38
39
// Uniforms
40
@group(0) @binding(${RectangleRendererBindingId.LayoutInfoUniform}) var<uniform> layoutInfo: LayoutInfo;
41
42
// Storage buffers
43
@group(0) @binding(${RectangleRendererBindingId.Shapes}) var<storage, read> shapes: array<Shape>;
44
@group(0) @binding(${RectangleRendererBindingId.ScrollOffset}) var<uniform> scrollOffset: ScrollOffset;
45
46
@vertex fn vs(
47
vert: Vertex,
48
@builtin(instance_index) instanceIndex: u32,
49
@builtin(vertex_index) vertexIndex : u32
50
) -> VSOutput {
51
let shape = shapes[instanceIndex];
52
53
var vsOut: VSOutput;
54
vsOut.position = vec4f(
55
(
56
// Top left corner
57
vec2f(-1, 1) +
58
// Convert pixel position to clipspace
59
vec2f( 2, -2) / layoutInfo.canvasDims *
60
// Shape position and size
61
(layoutInfo.viewportOffset - scrollOffset.offset + shape.position + vert.position * shape.size)
62
),
63
0.0,
64
1.0
65
);
66
vsOut.color = shape.color;
67
return vsOut;
68
}
69
70
@fragment fn fs(vsOut: VSOutput) -> @location(0) vec4f {
71
return vsOut.color;
72
}
73
`;
74
75