Skip to content

Commit

Permalink
Merge 932e203 into 305fa30
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Sep 12, 2019
2 parents 305fa30 + 932e203 commit 82ad1b5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/api-reference/webgl/context/has-features.md
Expand Up @@ -75,7 +75,7 @@ Note that luma has a few WebGL2 classes that **can** be instantiated under WebGL
A list of luma classes that can only be instantiated under WebGL2:
* `Texture3D` - e.g for volumetric rendering
* `Texture2DArray` - an array of textures, e.g. a texture atlas
* `Sampler` - holds a separate set of texture sampler paramters
* `Sampler` - holds a separate set of texture sampler parameters
* `TransformFeedback` - holds a list of output buffers for shaders to write to.
* `Sync` -

Expand Down
10 changes: 6 additions & 4 deletions modules/core/src/lib/transform/texture-transform.js
Expand Up @@ -51,7 +51,7 @@ export default class TextureTransform {

const attributes = Object.assign({}, opts.attributes);
const uniforms = Object.assign({}, opts.uniforms);
const parameters = Object.assign({}, opts.paramters);
const parameters = Object.assign({}, opts.parameters);
let discard = opts.discard;

if (this.hasSourceTextures || this.hasTargetTexture) {
Expand Down Expand Up @@ -127,9 +127,11 @@ export default class TextureTransform {

// Delete owned resources.
delete() {
const ownResources = [this.ownTexture, this.elementIDBuffer];
for (const name in ownResources) {
ownResources[name].delete();
if (this.ownTexture) {
this.ownTexture.delete();
}
if (this.elementIDBuffer) {
this.elementIDBuffer.delete();
}
}

Expand Down
15 changes: 10 additions & 5 deletions modules/core/src/lib/transform/transform.js
Expand Up @@ -27,11 +27,16 @@ export default class Transform {

// Delete owned resources.
delete() {
this.model.delete();
/* eslint-disable no-unused-expressions */
this.bufferTransform && this.bufferTransform.delete();
this.textureTransform && this.textureTransform.delete();
/* eslint-enable no-unused-expressions */
const {model, bufferTransform, textureTransform} = this;
if (model) {
model.delete();
}
if (bufferTransform) {
bufferTransform.delete();
}
if (textureTransform) {
textureTransform.delete();
}
}

// Run one transform loop.
Expand Down
54 changes: 54 additions & 0 deletions modules/core/test/lib/transform.spec.js
Expand Up @@ -2,6 +2,7 @@ import {Buffer, Transform, Texture2D} from '@luma.gl/core';
import test from 'tape-catch';
import {fixture} from 'test/setup';
import GL from '@luma.gl/constants';
import {setParameters, getParameter} from '@luma.gl/webgl-state-tracker';

const VS = `\
#version 300 es
Expand Down Expand Up @@ -1060,6 +1061,8 @@ test('WebGL#Transform run (offline rendering)', t => {
return item === expected;
});
t.ok(testPassed, `${name} Transform should write correct data into Texture`);

transform.delete();
});

t.end();
Expand Down Expand Up @@ -1272,3 +1275,54 @@ void main()
validateResourceCounts(t, startCounts, endCounts);
t.end();
});

test('WebGL#Transform run (custom parameters)', t => {
const {gl2} = fixture;

if (!gl2) {
t.comment('WebGL2 not available, skipping tests');
t.end();
return;
}

const {sourceData, format, dataFormat, type, width, height, name, vs} = TEXTURE_TEST_CASES[0];
const sourceTexture = new Texture2D(gl2, {
data: sourceData,
format,
dataFormat,
type,
mipmaps: false,
width,
height,
pixelStore: {
[GL.UNPACK_FLIP_Y_WEBGL]: false
}
});

// enable blending
setParameters(gl2, {blend: true, blendEquation: GL.MIN});

const transform = new Transform(gl2, {
_sourceTextures: {
inTexture: sourceTexture
},
_targetTexture: 'inTexture',
_targetTextureVarying: 'outTexture',
_swapTexture: 'inTexture',
vs,
elementCount: sourceData.length
});

// disable blending through parameters
transform.run({parameters: {blend: false}});

const expectedData = sourceData.map(x => x * 2);
const outTexData = transform.getData({packed: true});
t.deepEqual(outTexData, expectedData, `${name} Transform should write correct data into Texture`);

t.ok(getParameter(gl2, GL.BLEND) === true, 'Parameters are properly set');

setParameters(gl2, {blend: false});

t.end();
});

0 comments on commit 82ad1b5

Please sign in to comment.