Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
azeem committed Mar 5, 2018
1 parent 0ee7608 commit 3d61251
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 53 deletions.
4 changes: 1 addition & 3 deletions index.ts
Expand Up @@ -3,12 +3,10 @@ import Component from './src/Component';
import WebAudioAnalyser from './src/analyser/WebAudioAnalyser';
import AnalyserAdapter from './src/analyser/AnalyserAdapter';
import ShaderProgram from './src/webgl/ShaderProgram';
import QuadBoxProgram from './src/webgl/QuadBoxProgram';

const Webvs = {
Main, Component,
Main, Component, ShaderProgram,
WebAudioAnalyser, AnalyserAdapter,
ShaderProgram, QuadBoxProgram
};

export default Webvs;
3 changes: 2 additions & 1 deletion karma.conf.js
@@ -1,5 +1,6 @@
var webpack = require('webpack');
var webpackConfig = require('./webpack.config')({TARGET: 'web'});
process.env.TARGET = 'web';
var webpackConfig = require('./webpack.config');
var packageJson = require('./package.json');

module.exports = function(config) {
Expand Down
2 changes: 1 addition & 1 deletion src/Main.ts
Expand Up @@ -148,7 +148,7 @@ export default class Main extends Model implements IMain {
private _initGl() {
try {
this.rctx = new RenderingContext(this.canvas.getContext("webgl", {alpha: false}));
this.copier = new CopyProgram(this.rctx, {dynamicBlend: true});
this.copier = new CopyProgram(this.rctx, true);
this.tempBuffers = new FrameBufferManager(this.rctx, this.copier, true, 0);
} catch(e) {
throw new Error("Couldnt get webgl context" + e);
Expand Down
2 changes: 1 addition & 1 deletion src/render/Picture.ts
Expand Up @@ -75,7 +75,7 @@ export default class Picture extends Component {
this.program.run(
this.parent.fm,
{
position: [this.opts.x, this.opts.y],
position: [this.opts.x, -this.opts.y],
imageRes: [this.width, this.height],
image: this.texture,
points: squareGeometry(this.main.rctx, true)
Expand Down
5 changes: 3 additions & 2 deletions src/render/Texer.ts
Expand Up @@ -97,7 +97,7 @@ export default class Texer extends Component {
attribs: {
vertices: { name: 'a_vertex' },
texVertices: { name: 'a_texVertex' },
colors: { name: 'a_color' },
colors: { name: 'a_color', size: 3 },
},
index: {
valueName: 'indices',
Expand Down Expand Up @@ -329,7 +329,8 @@ export default class Texer extends Component {
colorFilter: colorData ? 1 : 0,
vertices: this.vertexBuffer,
texVertices: this.texVertexBuffer,
colors: colorData ? this.colorBuffer : null
indices: this.indexBuffer,
colors: colorData ? this.colorBuffer : null,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/trans/Mirror.ts
Expand Up @@ -74,7 +74,7 @@ export default class Mirror extends Component {
#define mirrorPos(pos,qa,qb) ((pos-vec2(0.5,0.5))*vec2(xFlip(qa,qb),yFlip(qa,qb))+vec2(0.5,0.5))
#define getMirrorColor(pos,qa,qb) (getSrcColorAtPos(mirrorPos(pos,qa,qb)))
void main() {",
void main() {
int quadrant = getQuadrant(v_position);
vec4 mix;
if(quadrant == 0) { mix = u_mix0; }
Expand Down
3 changes: 2 additions & 1 deletion src/webgl/CopyProgram.ts
Expand Up @@ -9,8 +9,9 @@ export interface CopyProgramValues {

// A Shader that copies given texture onto current buffer
export default class CopyProgram extends ShaderProgram<CopyProgramValues> {
constructor(rctx: RenderingContext) {
constructor(rctx: RenderingContext, dynamicBlend: boolean = false) {
super(rctx, {
dynamicBlend,
bindings: {
uniforms: {
srcTexture: { name: 'u_copySource', valueType: WebGLVarType.TEXTURE2D }
Expand Down
27 changes: 10 additions & 17 deletions test/func/funcTestUtils.ts
Expand Up @@ -3,8 +3,8 @@ import { clamp, glslFloatRepr, noop } from "../../src/utils";
import * as _ from "lodash";
import Main from "../../src/Main";
import Component from "../../src/Component";
import QuadBoxProgram from "../../src/webgl/QuadBoxProgram";
import IMain from "../../src/IMain";
import ShaderProgram from "../../src/webgl/ShaderProgram";

class MockAnalyser extends AnalyserAdapter {
private sineData: Float32Array;
Expand All @@ -28,19 +28,6 @@ class MockAnalyser extends AnalyserAdapter {
}
}

class GradientProgram extends QuadBoxProgram {
constructor(rctx, blue) {
super(rctx, {
fragmentShader: [
"void main() {",
" setFragColor(vec4(v_position, "+glslFloatRepr(blue)+", 1));",
"}"
]

});
}
}

interface TestPatternOpts {
blue: number;
};
Expand All @@ -55,18 +42,24 @@ class TestPattern extends Component {
blue: 0.5
};
protected opts: TestPatternOpts;
private program: GradientProgram;
private program: ShaderProgram;

init() {
this.updateProgram();
}

draw() {
this.program.run(this.parent.fm, null);
this.program.run(this.parent.fm, {});
}

private updateProgram() {
const program = new GradientProgram(this.main.rctx, this.opts.blue);
const program = new ShaderProgram(this.main.rctx, {
fragmentShader: `
void main() {
setFragColor(vec4(v_position, ${glslFloatRepr(this.opts.blue)}, 1));
}
`
});
if(this.program) {
this.program.destroy();
}
Expand Down
47 changes: 21 additions & 26 deletions test/func/trans/Mirror.test.ts
@@ -1,42 +1,37 @@
import * as seedrandom from 'seedrandom';
import QuadBoxProgram from "../../../src/webgl/QuadBoxProgram";
import Component from "../../../src/Component";
import { mainTest } from "../funcTestUtils";
import IMain from "../../../src/IMain";
import ShaderProgram from '../../../src/webgl/ShaderProgram';

class QuadrantColorProgram extends QuadBoxProgram {
constructor(rctx) {
super(rctx, {
fragmentShader: [
"void main() {",
" if(v_position.x < 0.5 && v_position.y < 0.5) {",
" setFragColor(vec4(1.0,0.0,0.0,1.0));",
" }",
" if(v_position.x < 0.5 && v_position.y > 0.5) {",
" setFragColor(vec4(0.0,1.0,0.0,1.0));",
" }",
" if(v_position.x > 0.5 && v_position.y > 0.5) {",
" setFragColor(vec4(0.0,0.0,1.0,1.0));",
" }",
" if(v_position.x > 0.5 && v_position.y < 0.5) {",
" setFragColor(vec4(1.0,1.0,0.0,1.0));",
" }",
"}"
]
})
}
};
class QuadrantColorComponent extends Component {
public static componentName: string = "QuadrantColor";
public static componentTag: string = "render";
private program: QuadrantColorProgram;
private program: ShaderProgram;

init() {
this.program = new QuadrantColorProgram(this.main.rctx);
this.program = new ShaderProgram(this.main.rctx, {
fragmentShader: `
void main() {
if(v_position.x < 0.5 && v_position.y < 0.5) {
setFragColor(vec4(1.0,0.0,0.0,1.0));
}
if(v_position.x < 0.5 && v_position.y > 0.5) {
setFragColor(vec4(0.0,1.0,0.0,1.0));
}
if(v_position.x > 0.5 && v_position.y > 0.5) {
setFragColor(vec4(0.0,0.0,1.0,1.0));
}
if(v_position.x > 0.5 && v_position.y < 0.5) {
setFragColor(vec4(1.0,1.0,0.0,1.0));
}
}
`
});
}

draw() {
this.program.run(this.parent.fm, null);
this.program.run(this.parent.fm, {});
}
}

Expand Down

0 comments on commit 3d61251

Please sign in to comment.