From 256d2bb7f4e549c947bd578b7701bff3f89fa2f0 Mon Sep 17 00:00:00 2001 From: Abhishek Soni Date: Wed, 19 Jul 2017 01:11:11 +0530 Subject: [PATCH] reuse kernel inside Texture.toArray --- src/core/texture.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/texture.js b/src/core/texture.js index 93fe9a24..7362b882 100644 --- a/src/core/texture.js +++ b/src/core/texture.js @@ -17,6 +17,7 @@ module.exports = class Texture { this.size = size; this.dimensions = dimensions; this.webGl = webGl; + this.kernel = null; } /** @@ -31,11 +32,13 @@ module.exports = class Texture { */ toArray(gpu) { if (!gpu) throw new Error('You need to pass the GPU object for toArray to work.'); - const copy = gpu.createKernel(function(x) { + if(this.kernel) return this.kernel(this); + + this.kernel = gpu.createKernel(function(x) { return x[this.thread.z][this.thread.y][this.thread.x]; }).setDimensions(this.dimensions); - return copy(this); + return this.kernel(this); } /**