Skip to content

Commit

Permalink
Calculate WGSL coordinates inside shader
Browse files Browse the repository at this point in the history
Fixes #233787
  • Loading branch information
Tyriar committed Nov 13, 2024
1 parent db865c3 commit 4a5844e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
43 changes: 6 additions & 37 deletions src/vs/editor/browser/gpu/fullFileRenderStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,8 @@ export class FullFileRenderStrategy extends Disposable implements IGpuRenderStra
let chars = '';
let y = 0;
let x = 0;
let screenAbsoluteX = 0;
let screenAbsoluteY = 0;
let zeroToOneX = 0;
let zeroToOneY = 0;
let wgslX = 0;
let wgslY = 0;
let absoluteOffsetX = 0;
let absoluteOffsetY = 0;
let xOffset = 0;
let glyph: Readonly<ITextureAtlasPageGlyph>;
let cellIndex = 0;
Expand Down Expand Up @@ -200,29 +196,6 @@ export class FullFileRenderStrategy extends Disposable implements IGpuRenderStra
content = lineData.content;
xOffset = 0;

// See ViewLine#renderLine
// const renderLineInput = new RenderLineInput(
// options.useMonospaceOptimizations,
// options.canUseHalfwidthRightwardsArrow,
// lineData.content,
// lineData.continuesWithWrappedLine,
// lineData.isBasicASCII,
// lineData.containsRTL,
// lineData.minColumn - 1,
// lineData.tokens,
// actualInlineDecorations,
// lineData.tabSize,
// lineData.startVisibleColumn,
// options.spaceWidth,
// options.middotWidth,
// options.wsmiddotWidth,
// options.stopRenderingLineAfter,
// options.renderWhitespace,
// options.renderControlCharacters,
// options.fontLigatures !== EditorFontLigatures.OFF,
// selectionsOnLine
// );

tokens = lineData.tokens;
tokenStartIndex = lineData.minColumn - 1;
tokenEndIndex = 0;
Expand Down Expand Up @@ -255,23 +228,19 @@ export class FullFileRenderStrategy extends Disposable implements IGpuRenderStra
glyph = this._viewGpuContext.atlas.getGlyph(this._glyphRasterizer, chars, tokenMetadata);

// TODO: Support non-standard character widths
screenAbsoluteX = Math.round((x + xOffset) * viewLineOptions.spaceWidth * dpr);
screenAbsoluteY = (
absoluteOffsetX = Math.round((x + xOffset) * viewLineOptions.spaceWidth * dpr);
absoluteOffsetY = (
Math.ceil((
// Top of line including line height
viewportData.relativeVerticalOffset[y - viewportData.startLineNumber] +
// Delta to top of line after line height
Math.floor((viewportData.lineHeight - this._context.configuration.options.get(EditorOption.fontSize)) / 2)
) * dpr)
);
zeroToOneX = screenAbsoluteX / this._viewGpuContext.canvas.domNode.width;
zeroToOneY = screenAbsoluteY / this._viewGpuContext.canvas.domNode.height;
wgslX = zeroToOneX * 2 - 1;
wgslY = zeroToOneY * 2 - 1;

cellIndex = ((y - 1) * this._viewGpuContext.maxGpuCols + x) * Constants.IndicesPerCell;
cellBuffer[cellIndex + CellBufferInfo.Offset_X] = wgslX;
cellBuffer[cellIndex + CellBufferInfo.Offset_Y] = -wgslY;
cellBuffer[cellIndex + CellBufferInfo.Offset_X] = absoluteOffsetX;
cellBuffer[cellIndex + CellBufferInfo.Offset_Y] = absoluteOffsetY;
cellBuffer[cellIndex + CellBufferInfo.GlyphIndex] = glyph.glyphIndex;
cellBuffer[cellIndex + CellBufferInfo.TextureIndex] = glyph.pageIndex;
}
Expand Down
7 changes: 6 additions & 1 deletion src/vs/editor/browser/gpu/fullFileRenderStrategy.wgsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ struct VSOutput {
var vsOut: VSOutput;
// Multiple vert.position by 2,-2 to get it into clipspace which ranged from -1 to 1
vsOut.position = vec4f(
(((vert.position * vec2f(2, -2)) / layoutInfo.canvasDims)) * glyph.size + cell.position + ((glyph.origin * vec2f(2, -2)) / layoutInfo.canvasDims) + (((layoutInfo.viewportOffset - scrollOffset.offset * vec2(1, -1)) * 2) / layoutInfo.canvasDims),
// 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
);
Expand Down

0 comments on commit 4a5844e

Please sign in to comment.