From 790397ae0f05a8dfc8694c4d99197d5be2ccbce9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Feb 2015 16:07:05 -0800 Subject: [PATCH 1/2] [Plot] Add test for buffer size Add test case for usage of drawing buffer size as reported by WebGL (instead of assuming we always got the full size we requested.) WTD-852. --- platform/features/plot/test/GLChartSpec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platform/features/plot/test/GLChartSpec.js b/platform/features/plot/test/GLChartSpec.js index cfd38d0638..67ec83aa73 100644 --- a/platform/features/plot/test/GLChartSpec.js +++ b/platform/features/plot/test/GLChartSpec.js @@ -106,6 +106,19 @@ define( expect(mockGL.drawArrays) .toHaveBeenCalledWith("TRIANGLE_FAN", 0, 4); }); + + it("uses buffer sizes reported by WebGL", function () { + // Make sure that GLChart uses the GL buffer size, which may + // differ from what canvas requested. WTD-852 + mockCanvas.width = 300; + mockCanvas.height = 150; + mockGL.drawingBufferWidth = 200; + mockGL.drawingBufferHeight = 175; + + glChart.clear(); + + expect(mockGL.viewport).toHaveBeenCalledWith(0, 0, 200, 175); + }); }); } ); \ No newline at end of file From 7c5c96ff1ded33201a251e4666ec4597cb2bc63c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Feb 2015 16:10:20 -0800 Subject: [PATCH 2/2] [Plot] Use GL-reported buffer size Use the buffer width/height reported by WebGL when configuring the viewport to ensure that data aligns correctly to canvas size when drawn. WTD-852. --- platform/features/plot/src/GLChart.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/features/plot/src/GLChart.js b/platform/features/plot/src/GLChart.js index 284333beaf..7dcda27a70 100644 --- a/platform/features/plot/src/GLChart.js +++ b/platform/features/plot/src/GLChart.js @@ -96,7 +96,15 @@ define( * Clear the chart. */ clear: function () { - gl.viewport(0, 0, canvas.width, canvas.height); + // Set the viewport size; note that we use the width/height + // that our WebGL context reports, which may be lower + // resolution than the canvas we requested. + gl.viewport( + 0, + 0, + gl.drawingBufferWidth, + gl.drawingBufferHeight + ); gl.clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT); }, /** @@ -107,8 +115,11 @@ define( * origin of the chart */ setDimensions: function (dimensions, origin) { - gl.uniform2fv(uDimensions, dimensions); - gl.uniform2fv(uOrigin, origin); + if (dimensions && dimensions.length > 0 && + origin && origin.length > 0) { + gl.uniform2fv(uDimensions, dimensions); + gl.uniform2fv(uOrigin, origin); + } }, /** * Draw the supplied buffer as a line strip (a sequence