Skip to content

Commit

Permalink
Remove use of gl.lineWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Jun 5, 2018
1 parent 560ca15 commit d067936
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 43 deletions.
6 changes: 1 addition & 5 deletions src/gl/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DepthMode from './depth_mode';
import StencilMode from './stencil_mode';
import ColorMode from './color_mode';
import { deepEqual } from '../util/util';
import { ClearColor, ClearDepth, ClearStencil, ColorMask, DepthMask, StencilMask, StencilFunc, StencilOp, StencilTest, DepthRange, DepthTest, DepthFunc, Blend, BlendFunc, BlendColor, Program, LineWidth, ActiveTextureUnit, Viewport, BindFramebuffer, BindRenderbuffer, BindTexture, BindVertexBuffer, BindElementBuffer, BindVertexArrayOES, PixelStoreUnpack, PixelStoreUnpackPremultiplyAlpha } from './value';
import { ClearColor, ClearDepth, ClearStencil, ColorMask, DepthMask, StencilMask, StencilFunc, StencilOp, StencilTest, DepthRange, DepthTest, DepthFunc, Blend, BlendFunc, BlendColor, Program, ActiveTextureUnit, Viewport, BindFramebuffer, BindRenderbuffer, BindTexture, BindVertexBuffer, BindElementBuffer, BindVertexArrayOES, PixelStoreUnpack, PixelStoreUnpackPremultiplyAlpha } from './value';


import type {TriangleIndexArray, LineIndexArray} from '../data/index_array_type';
Expand All @@ -28,7 +28,6 @@ class Context {
gl: WebGLRenderingContext;
extVertexArrayObject: any;
currentNumAttributes: ?number;
lineWidthRange: [number, number];

clearColor: ClearColor;
clearDepth: ClearDepth;
Expand All @@ -46,7 +45,6 @@ class Context {
blendFunc: BlendFunc;
blendColor: BlendColor;
program: Program;
lineWidth: LineWidth;
activeTexture: ActiveTextureUnit;
viewport: Viewport;
bindFramebuffer: BindFramebuffer;
Expand All @@ -65,7 +63,6 @@ class Context {
constructor(gl: WebGLRenderingContext) {
this.gl = gl;
this.extVertexArrayObject = this.gl.getExtension('OES_vertex_array_object');
this.lineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE);

this.clearColor = new ClearColor(this);
this.clearDepth = new ClearDepth(this);
Expand All @@ -83,7 +80,6 @@ class Context {
this.blendFunc = new BlendFunc(this);
this.blendColor = new BlendColor(this);
this.program = new Program(this);
this.lineWidth = new LineWidth(this);
this.activeTexture = new ActiveTextureUnit(this);
this.viewport = new Viewport(this);
this.bindFramebuffer = new BindFramebuffer(this);
Expand Down
23 changes: 0 additions & 23 deletions src/gl/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import Color from '../style-spec/util/color';

import { clamp } from '../util/util';

import type Context from './context';
import type {
BlendFuncType,
Expand Down Expand Up @@ -356,27 +354,6 @@ export class Program implements Value<?WebGLProgram> {
}
}

export class LineWidth implements Value<number> {
context: Context;
current: number;

constructor(context: Context) {
this.context = context;
this.current = 1;
}

get(): number { return this.current; }

set(v: number): void {
const range = this.context.lineWidthRange;
const clamped = clamp(v, range[0], range[1]);
if (this.current !== clamped) {
this.context.gl.lineWidth(clamped);
this.current = v;
}
}
}

export class ActiveTextureUnit implements Value<TextureUnitType> {
context: Context;
current: TextureUnitType;
Expand Down
4 changes: 0 additions & 4 deletions src/render/draw_collision_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ function drawCollisionDebugGeometry(painter: Painter, sourceCache: SourceCache,

gl.uniformMatrix4fv(program.uniforms.u_matrix, false, coord.posMatrix);

if (!drawCircles) {
context.lineWidth.set(1);
}

gl.uniform1f(program.uniforms.u_camera_to_center_distance, painter.transform.cameraToCenterDistance);
const pixelRatio = pixelsToTileUnits(tile, 1, painter.transform.zoom);
const scale = Math.pow(2, painter.transform.zoom - tile.tileID.overscaledZ);
Expand Down
4 changes: 0 additions & 4 deletions src/render/draw_debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @flow

import browser from '../util/browser';

import { mat4 } from 'gl-matrix';
import EXTENT from '../data/extent';
import VertexArrayObject from './vertex_array_object';
Expand All @@ -26,8 +24,6 @@ function drawDebugTile(painter, sourceCache, coord) {
const context = painter.context;
const gl = context.gl;

context.lineWidth.set(1 * browser.devicePixelRatio);

const posMatrix = coord.posMatrix;
const program = painter.useProgram('debug');

Expand Down
1 change: 0 additions & 1 deletion src/render/draw_fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function drawFill(painter: Painter, sourceCache: SourceCache, layer: FillStyleLa

// Draw stroke
if (painter.renderPass === 'translucent' && layer.paint.get('fill-antialias')) {
context.lineWidth.set(2);

// If we defined a different color for the fill outline, we are
// going to ignore the bits in 0x07 and just care about the global
Expand Down
7 changes: 1 addition & 6 deletions test/unit/gl/state.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { test } from 'mapbox-gl-js-test';
import { ClearColor, ClearDepth, ClearStencil, ColorMask, DepthMask, StencilMask, StencilFunc, StencilOp, StencilTest, DepthRange, DepthTest, DepthFunc, Blend, BlendFunc, BlendColor, Program, LineWidth, ActiveTextureUnit, Viewport, BindFramebuffer, BindRenderbuffer, BindTexture, BindVertexBuffer, BindElementBuffer, BindVertexArrayOES, PixelStoreUnpack, PixelStoreUnpackPremultiplyAlpha } from '../../../src/gl/value';
import { ClearColor, ClearDepth, ClearStencil, ColorMask, DepthMask, StencilMask, StencilFunc, StencilOp, StencilTest, DepthRange, DepthTest, DepthFunc, Blend, BlendFunc, BlendColor, Program, ActiveTextureUnit, Viewport, BindFramebuffer, BindRenderbuffer, BindTexture, BindVertexBuffer, BindElementBuffer, BindVertexArrayOES, PixelStoreUnpack, PixelStoreUnpackPremultiplyAlpha } from '../../../src/gl/value';
import Context from '../../../src/gl/context';
import Color from '../../../src/style-spec/util/color';
import { deepEqual } from '../../../src/util/util';

const context = new Context(require('gl')(10, 10));
context.lineWidthRange = [0, 1];

function ValueTest(Constructor, options, t) {
t.test('#constructor', (t) => {
Expand Down Expand Up @@ -97,10 +96,6 @@ test('Program', ValueTest.bind(ValueTest, Program, {
setValue: context.gl.createProgram()
}));

test('LineWidth', ValueTest.bind(ValueTest, LineWidth, {
setValue: 0.5
}));

test('ActiveTextureUnit', ValueTest.bind(ValueTest, ActiveTextureUnit, {
setValue: context.gl.TEXTURE1
}));
Expand Down

0 comments on commit d067936

Please sign in to comment.