Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8ff27c

Browse files
authored
Merge pull request#2552 from Tyriar/webgl_compat_attr
True color support in WebGL renderer
2 parentsadc631d +e89d79b commita8ff27c

File tree

16 files changed

+610
-269
lines changed

16 files changed

+610
-269
lines changed

‎addons/xterm-addon-webgl/src/CharDataCompat.ts‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎addons/xterm-addon-webgl/src/ColorUtils.ts‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎addons/xterm-addon-webgl/src/Constants.ts‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎addons/xterm-addon-webgl/src/GlyphRenderer.ts‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import{createProgram,PROJECTION_MATRIX,throwIfFalsy}from'./WebglUtils';
77
import{WebglCharAtlas}from'./atlas/WebglCharAtlas';
88
import{IWebGL2RenderingContext,IWebGLVertexArrayObject,IRenderModel,IRasterizedGlyph}from'./Types';
9-
import{INDICIES_PER_CELL}from'./WebglRenderer';
10-
import{COMBINED_CHAR_BIT_MASK}from'./RenderModel';
9+
import{COMBINED_CHAR_BIT_MASK,RENDER_MODEL_INDICIES_PER_CELL,RENDER_MODEL_FG_OFFSET}from'./RenderModel';
1110
import{fill}from'common/TypedArrayUtils';
1211
import{slice}from'./TypedArray';
13-
import{NULL_CELL_CODE,WHITESPACE_CELL_CODE}from'common/buffer/Constants';
14-
import{getLuminance}from'./ColorUtils';
12+
import{NULL_CELL_CODE,WHITESPACE_CELL_CODE,Attributes}from'common/buffer/Constants';
1513
import{Terminal,IBufferLine}from'xterm';
1614
import{IColorSet}from'browser/Types';
1715
import{IRenderDimensions}from'browser/renderer/Types';
@@ -169,11 +167,11 @@ export class GlyphRenderer {
169167
returnthis._atlas ?this._atlas.beginFrame() :true;
170168
}
171169

172-
publicupdateCell(x:number,y:number,code:number,attr:number,bg:number,fg:number,chars:string):void{
173-
this._updateCell(this._vertices.attributes,x,y,code,attr,bg,fg,chars);
170+
publicupdateCell(x:number,y:number,code:number,bg:number,fg:number,chars:string):void{
171+
this._updateCell(this._vertices.attributes,x,y,code,bg,fg,chars);
174172
}
175173

176-
private_updateCell(array:Float32Array,x:number,y:number,code:number|undefined,attr:number,bg:number,fg:number,chars?:string):void{
174+
private_updateCell(array:Float32Array,x:number,y:number,code:number|undefined,bg:number,fg:number,chars?:string):void{
177175
constterminal=this._terminal;
178176

179177
consti=(y*terminal.cols+x)*INDICES_PER_CELL;
@@ -189,9 +187,9 @@ export class GlyphRenderer {
189187
thrownewError('atlas must be set before updating cell');
190188
}
191189
if(chars&&chars.length>1){
192-
rasterizedGlyph=this._atlas.getRasterizedGlyphCombinedChar(chars,attr,bg,fg);
190+
rasterizedGlyph=this._atlas.getRasterizedGlyphCombinedChar(chars,bg,fg);
193191
}else{
194-
rasterizedGlyph=this._atlas.getRasterizedGlyph(code,attr,bg,fg);
192+
rasterizedGlyph=this._atlas.getRasterizedGlyph(code,bg,fg);
195193
}
196194

197195
// Fill empty if no glyph was found
@@ -220,58 +218,51 @@ export class GlyphRenderer {
220218

221219
this._vertices.selectionAttributes=slice(this._vertices.attributes,0);
222220

223-
// TODO: Make fg and bg configurable, currently since the buffer doesn't
224-
// support truecolor the char atlas cannot store it.
225-
constlumi=getLuminance(this._colors.background);
226-
constfg=lumi>0.5 ?7 :0;
227-
constbg=lumi>0.5 ?0 :7;
221+
constbg=(this._colors.selectionOpaque.rgba>>>8)|Attributes.CM_RGB;
228222

229223
if(columnSelectMode){
230224
conststartCol=model.selection.startCol;
231225
constwidth=model.selection.endCol-startCol;
232226
constheight=model.selection.viewportCappedEndRow-model.selection.viewportCappedStartRow+1;
233227
for(lety=model.selection.viewportCappedStartRow;y<model.selection.viewportCappedStartRow+height;y++){
234-
this._updateSelectionRange(startCol,startCol+width,y,model,bg,fg);
228+
this._updateSelectionRange(startCol,startCol+width,y,model,bg);
235229
}
236230
}else{
237231
// Draw first row
238232
conststartCol=model.selection.viewportStartRow===model.selection.viewportCappedStartRow ?model.selection.startCol :0;
239233
conststartRowEndCol=model.selection.viewportCappedStartRow===model.selection.viewportCappedEndRow ?model.selection.endCol :terminal.cols;
240-
this._updateSelectionRange(startCol,startRowEndCol,model.selection.viewportCappedStartRow,model,bg,fg);
234+
this._updateSelectionRange(startCol,startRowEndCol,model.selection.viewportCappedStartRow,model,bg);
241235

242236
// Draw middle rows
243237
constmiddleRowsCount=Math.max(model.selection.viewportCappedEndRow-model.selection.viewportCappedStartRow-1,0);
244238
for(lety=model.selection.viewportCappedStartRow+1;y<=model.selection.viewportCappedStartRow+middleRowsCount;y++){
245-
this._updateSelectionRange(0,startRowEndCol,y,model,bg,fg);
239+
this._updateSelectionRange(0,startRowEndCol,y,model,bg);
246240
}
247241

248242
// Draw final row
249243
if(model.selection.viewportCappedStartRow!==model.selection.viewportCappedEndRow){
250244
// Only draw viewportEndRow if it's not the same as viewportStartRow
251245
constendCol=model.selection.viewportEndRow===model.selection.viewportCappedEndRow ?model.selection.endCol :terminal.cols;
252-
this._updateSelectionRange(0,endCol,model.selection.viewportCappedEndRow,model,bg,fg);
246+
this._updateSelectionRange(0,endCol,model.selection.viewportCappedEndRow,model,bg);
253247
}
254248
}
255249
}
256250

257-
private_updateSelectionRange(startCol:number,endCol:number,y:number,model:IRenderModel,bg:number,fg:number):void{
251+
private_updateSelectionRange(startCol:number,endCol:number,y:number,model:IRenderModel,bg:number):void{
258252
constterminal=this._terminal;
259253
constrow=y+terminal.buffer.viewportY;
260254
letline:IBufferLine|undefined;
261255
for(letx=startCol;x<endCol;x++){
262-
constoffset=(y*this._terminal.cols+x)*INDICIES_PER_CELL;
263-
// Because the cache uses attr as a lookup key it needs to contain the selection colors as well
264-
letattr=model.cells[offset+1];
265-
attr=attr&~0x3ffff|bg<<9|fg;
256+
constoffset=(y*this._terminal.cols+x)*RENDER_MODEL_INDICIES_PER_CELL;
266257
constcode=model.cells[offset];
267258
if(code&COMBINED_CHAR_BIT_MASK){
268259
if(!line){
269260
line=terminal.buffer.getLine(row);
270261
}
271262
constchars=line!.getCell(x)!.char;
272-
this._updateCell(this._vertices.selectionAttributes,x,y,model.cells[offset],attr,bg,fg,chars);
263+
this._updateCell(this._vertices.selectionAttributes,x,y,model.cells[offset],bg,model.cells[offset+RENDER_MODEL_FG_OFFSET],chars);
273264
}else{
274-
this._updateCell(this._vertices.selectionAttributes,x,y,model.cells[offset],attr,bg,fg);
265+
this._updateCell(this._vertices.selectionAttributes,x,y,model.cells[offset],bg,model.cells[offset+RENDER_MODEL_FG_OFFSET]);
275266
}
276267
}
277268
}

‎addons/xterm-addon-webgl/src/RectangleRenderer.ts‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
import{createProgram,expandFloat32Array,PROJECTION_MATRIX,throwIfFalsy}from'./WebglUtils';
77
import{IRenderModel,IWebGLVertexArrayObject,IWebGL2RenderingContext,ISelectionRenderModel}from'./Types';
88
import{fill}from'common/TypedArrayUtils';
9-
import{INVERTED_DEFAULT_COLOR}from'browser/renderer/atlas/Constants';
10-
import{is256Color}from'./atlas/CharAtlasUtils';
11-
import{DEFAULT_COLOR}from'common/buffer/Constants';
9+
import{Attributes,FgFlags}from'common/buffer/Constants';
1210
import{Terminal}from'xterm';
1311
import{IColorSet,IColor}from'browser/Types';
1412
import{IRenderDimensions}from'browser/renderer/Types';
13+
import{RENDER_MODEL_BG_OFFSET,RENDER_MODEL_FG_OFFSET,RENDER_MODEL_INDICIES_PER_CELL}from'./RenderModel';
1514

1615
constenumVertexAttribLocations{
1716
POSITION=0,
@@ -156,7 +155,7 @@ export class RectangleRenderer {
156155

157156
private_updateCachedColors():void{
158157
this._bgFloat=this._colorToFloat32Array(this._colors.background);
159-
this._selectionFloat=this._colorToFloat32Array(this._colors.selection);
158+
this._selectionFloat=this._colorToFloat32Array(this._colors.selectionOpaque);
160159
}
161160

162161
private_updateViewportRectangle():void{
@@ -247,47 +246,61 @@ export class RectangleRenderer {
247246

248247
for(lety=0;y<terminal.rows;y++){
249248
letcurrentStartX=-1;
250-
letcurrentBg=DEFAULT_COLOR;
249+
letcurrentBg=0;
250+
letcurrentFg=0;
251251
for(letx=0;x<terminal.cols;x++){
252-
constmodelIndex=((y*terminal.cols)+x)*4;
253-
constbg=model.cells[modelIndex+2];
252+
constmodelIndex=((y*terminal.cols)+x)*RENDER_MODEL_INDICIES_PER_CELL;
253+
constbg=model.cells[modelIndex+RENDER_MODEL_BG_OFFSET];
254+
constfg=model.cells[modelIndex+RENDER_MODEL_FG_OFFSET];
254255
if(bg!==currentBg){
255256
// A rectangle needs to be drawn if going from non-default to another color
256-
if(currentBg!==DEFAULT_COLOR){
257+
if(currentBg!==0){
257258
constoffset=rectangleCount++*INDICES_PER_RECTANGLE;
258-
this._updateRectangle(vertices,offset,currentBg,currentStartX,x,y);
259+
this._updateRectangle(vertices,offset,currentFg,currentBg,currentStartX,x,y);
259260
}
260261
currentStartX=x;
261262
currentBg=bg;
263+
currentFg=fg;
262264
}
263265
}
264266
// Finish rectangle if it's still going
265-
if(currentBg!==DEFAULT_COLOR){
267+
if(currentBg!==0){
266268
constoffset=rectangleCount++*INDICES_PER_RECTANGLE;
267-
this._updateRectangle(vertices,offset,currentBg,currentStartX,terminal.cols,y);
269+
this._updateRectangle(vertices,offset,currentFg,currentBg,currentStartX,terminal.cols,y);
268270
}
269271
}
270272
vertices.count=rectangleCount;
271273
}
272274

273-
private_updateRectangle(vertices:IVertices,offset:number,bg:number,startX:number,endX:number,y:number):void{
274-
letcolor:IColor|null=null;
275-
if(bg===INVERTED_DEFAULT_COLOR){
276-
color=this._colors.foreground;
277-
}elseif(is256Color(bg)){
278-
color=this._colors.ansi[bg];
275+
private_updateRectangle(vertices:IVertices,offset:number,fg:number,bg:number,startX:number,endX:number,y:number):void{
276+
letrgba:number|undefined;
277+
constcolorMode=bg&Attributes.CM_MASK;
278+
if(fg&FgFlags.INVERSE){
279+
// Inverted color
280+
rgba=this._colors.foreground.rgba;
279281
}else{
280-
// TODO: Add support for true color
281-
color=this._colors.foreground;
282+
switch(colorMode){
283+
caseAttributes.CM_P16:
284+
caseAttributes.CM_P256:
285+
rgba=this._colors.ansi[bg&Attributes.PCOLOR_MASK].rgba;
286+
break;
287+
caseAttributes.CM_RGB:
288+
rgba=(bg&Attributes.RGB_MASK)<<8;
289+
break;
290+
caseAttributes.CM_DEFAULT:
291+
default:
292+
rgba=this._colors.background.rgba;
293+
}
282294
}
295+
283296
if(vertices.attributes.length<offset+4){
284297
vertices.attributes=expandFloat32Array(vertices.attributes,this._terminal.rows*this._terminal.cols*INDICES_PER_RECTANGLE);
285298
}
286299
constx1=startX*this._dimensions.scaledCellWidth;
287300
consty1=y*this._dimensions.scaledCellHeight;
288-
constr=((color.rgba>>24)&0xFF)/255;
289-
constg=((color.rgba>>16)&0xFF)/255;
290-
constb=((color.rgba>>8)&0xFF)/255;
301+
constr=((rgba>>24)&0xFF)/255;
302+
constg=((rgba>>16)&0xFF)/255;
303+
constb=((rgba>>8)&0xFF)/255;
291304

292305
this._addRectangle(vertices.attributes,offset,x1,y1,(endX-startX)*this._dimensions.scaledCellWidth,this._dimensions.scaledCellHeight,r,g,b,1);
293306
}

‎addons/xterm-addon-webgl/src/RenderModel.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import{IRenderModel,ISelectionRenderModel}from'./Types';
77
import{fill}from'common/TypedArrayUtils';
88

9-
exportconstRENDER_MODEL_INDICIES_PER_CELL=4;
9+
exportconstRENDER_MODEL_INDICIES_PER_CELL=3;
10+
exportconstRENDER_MODEL_BG_OFFSET=1;
11+
exportconstRENDER_MODEL_FG_OFFSET=2;
1012

1113
exportconstCOMBINED_CHAR_BIT_MASK=0x80000000;
1214

‎addons/xterm-addon-webgl/src/Types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
exportinterfaceIRasterizedGlyphSet{
7-
[flags:number]:IRasterizedGlyph;
7+
[bg:number]:{[fg:number]:IRasterizedGlyph}|undefined;
88
}
99

1010
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp