monaco-editor-core
Version:
A browser based code editor
91 lines (78 loc) • 3.15 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TextureAtlas } from '../atlas/textureAtlas.js';
import { TextureAtlasPage } from '../atlas/textureAtlasPage.js';
export const fullFileRenderStrategyWgsl = /*wgsl*/ `
struct GlyphInfo {
position: vec2f,
size: vec2f,
origin: vec2f,
};
struct Vertex {
position: vec2f,
};
struct Cell {
position: vec2f,
unused1: vec2f,
glyphIndex: f32,
textureIndex: f32
};
struct LayoutInfo {
canvasDims: vec2f,
viewportOffset: vec2f,
viewportDims: vec2f,
}
struct ScrollOffset {
offset: vec2f
}
struct VSOutput {
position: vec4f,
layerIndex: f32,
texcoord: vec2f,
};
// Uniforms
var<uniform> layoutInfo: LayoutInfo;
var<uniform> atlasDims: vec2f;
var<uniform> scrollOffset: ScrollOffset;
// Storage buffers
var<storage, read> glyphInfo: array<array<GlyphInfo, ${TextureAtlasPage.maximumGlyphCount}>, ${TextureAtlas.maximumPageCount}>;
var<storage, read> cells: array<Cell>;
fn vs(
vert: Vertex,
instanceIndex: u32,
vertexIndex : u32
) -> VSOutput {
let cell = cells[instanceIndex];
var glyph = glyphInfo[u32(cell.textureIndex)][u32(cell.glyphIndex)];
var vsOut: VSOutput;
// Multiple vert.position by 2,-2 to get it into clipspace which ranged from -1 to 1
vsOut.position = vec4f(
// Make everything relative to top left instead of center
vec2f(-1, 1) +
((vert.position * vec2f(2, -2)) / layoutInfo.canvasDims) * glyph.size +
((cell.position * vec2f(2, -2)) / layoutInfo.canvasDims) +
((glyph.origin * vec2f(2, -2)) / layoutInfo.canvasDims) +
(((layoutInfo.viewportOffset - scrollOffset.offset * vec2(1, -1)) * 2) / layoutInfo.canvasDims),
0.0,
1.0
);
vsOut.layerIndex = cell.textureIndex;
// Textures are flipped from natural direction on the y-axis, so flip it back
vsOut.texcoord = vert.position;
vsOut.texcoord = (
// Glyph offset (0-1)
(glyph.position / atlasDims) +
// Glyph coordinate (0-1)
(vsOut.texcoord * (glyph.size / atlasDims))
);
return vsOut;
}
var ourSampler: sampler;
var ourTexture: texture_2d_array<f32>;
fn fs(vsOut: VSOutput) -> vec4f {
return textureSample(ourTexture, ourSampler, vsOut.texcoord, u32(vsOut.layerIndex));
}
`;
//# sourceMappingURL=fullFileRenderStrategy.wgsl.js.map