Permalink
Browse files

More refactoring, pulled shaders out of .html files and into JavaScri…

…pt code.
  • Loading branch information...
1 parent 0096390 commit 84db00f4fc532013a15653d90186003839e061ac Michael Bebenita committed Nov 11, 2011
Showing with 1,082 additions and 257 deletions.
  1. +6 −53 Demo/benchmarks.html
  2. +9 −46 Demo/broadway.html
  3. +248 −155 Demo/canvas.js
  4. +791 −0 Demo/jquery/jquery-ui.min.js
  5. +18 −0 Demo/jquery/jquery.min.js
  6. +10 −3 Demo/util.js
View
@@ -121,20 +121,22 @@
function run() {
var size = new Size(512, 512);
- var c1 = new WebGLCanvas(document.getElementById('canvas-1'), size, "shader-fs", "shader-vs");
+ var c1 = new WebGLCanvas(document.getElementById('canvas-1'), size);
var buffer = new Uint8Array(size.w * size.h);
for (var i = 0; i < buffer.length; i++) {
buffer[i] = i;
}
- c1.drawTexture(buffer);
+ c1.texture.fill(buffer);
c1.drawScene();
- var c2 = new YUVWebGLCanvas(document.getElementById('canvas-2'), size, "yuv-shader-fs", "shader-vs");
+ var c2 = new YUVWebGLCanvas(document.getElementById('canvas-2'), size);
var chroma = new Uint8Array((size.w >>> 1) * (size.h >>> 1));
for (var i = 0; i < chroma.length; i++) {
chroma[i] = i;
}
- c2.drawYUVTextures(buffer, chroma, chroma);
+ c2.YTexture.fill(buffer);
+ c2.UTexture.fill(chroma);
+ c2.VTexture.fill(chroma);
c2.drawScene();
/* for (var i = 0; i < 100; i++) {
@@ -161,55 +163,6 @@
}
</script>
- <script id="yuv-shader-fs" type="x-shader/x-fragment">
- precision highp float;
-
- varying highp vec2 vTextureCoord;
-
- uniform sampler2D YTexture;
- uniform sampler2D CbTexture;
- uniform sampler2D CrTexture;
-
- void main(void) {
- vec3 YCbCr = vec3
- (
- texture2D(YTexture, vTextureCoord).x * 1.1643828125, // premultiply Y
- texture2D(CbTexture, vTextureCoord).x,
- texture2D(CrTexture, vTextureCoord).x
- );
-
- gl_FragColor = vec4
- (
- YCbCr.x + 1.59602734375 * YCbCr.z - 0.87078515625,
- YCbCr.x - 0.39176171875 * YCbCr.y - 0.81296875 * YCbCr.z + 0.52959375,
- YCbCr.x + 2.017234375 * YCbCr.y - 1.081390625,
- 1
- );
- }
- </script>
-
- <script id="shader-fs" type="x-shader/x-fragment">
- precision highp float;
- varying highp vec2 vTextureCoord;
- uniform sampler2D texture;
-
- void main(void) {
- gl_FragColor = texture2D(texture, vTextureCoord);
- }
-
- </script>
- <script id="shader-vs" type="x-shader/x-vertex">
- attribute vec3 aVertexPosition;
- attribute vec2 aTextureCoord;
- uniform mat4 uMVMatrix;
- uniform mat4 uPMatrix;
- varying highp vec2 vTextureCoord;
- void main(void) {
- gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
- vTextureCoord = aTextureCoord;
- }
- </script>
-
<div id="doc">
<header>
<h1 id="site-title"><b>Broadway.js</b></h1>
View
@@ -82,12 +82,10 @@
}
</style>
-
+
<link type="text/css" href="jquery/theme/jquery-ui.css" rel="stylesheet" />
- <script type="text/javascript"
- src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
- <script type="text/javascript"
- src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="jquery/jquery.min.js"></script>
+ <script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
<script type='text/javascript'>
var Module = {
@@ -221,55 +219,20 @@
function paint($luma, $cb, $cr, height, width) {
if (!webGLCanvas) {
- webGLCanvas = new YUVWebGLCanvas(Module.canvas, new Size(width, height), "shader-fs", "shader-vs");
+ webGLCanvas = new YUVWebGLCanvas(Module.canvas, new Size(width, height));
}
var luma = HEAPU8.subarray($luma);
var cb = HEAPU8.subarray($cb);
var cr = HEAPU8.subarray($cr);
- webGLCanvas.drawYUVTextures(luma, cb, cr);
+
+ webGLCanvas.YTexture.fill(luma);
+ webGLCanvas.UTexture.fill(cb);
+ webGLCanvas.VTexture.fill(cr);
webGLCanvas.drawScene();
}
</script>
- <script id="shader-fs" type="x-shader/x-fragment">
- precision highp float;
-
- varying highp vec2 vTextureCoord;
-
- uniform sampler2D YTexture;
- uniform sampler2D CbTexture;
- uniform sampler2D CrTexture;
-
- void main(void) {
- vec3 YCbCr = vec3
- (
- texture2D(YTexture, vTextureCoord).x * 1.1643828125, // premultiply Y
- texture2D(CbTexture, vTextureCoord).x,
- texture2D(CrTexture, vTextureCoord).x
- );
-
- gl_FragColor = vec4
- (
- YCbCr.x + 1.59602734375 * YCbCr.z - 0.87078515625,
- YCbCr.x - 0.39176171875 * YCbCr.y - 0.81296875 * YCbCr.z + 0.52959375,
- YCbCr.x + 2.017234375 * YCbCr.y - 1.081390625,
- 1
- );
- }
-
-
- </script>
- <script id="shader-vs" type="x-shader/x-vertex">
- attribute vec3 aVertexPosition;
- attribute vec2 aTextureCoord;
- uniform mat4 uMVMatrix;
- uniform mat4 uPMatrix;
- varying highp vec2 vTextureCoord;
- void main(void) {
- gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
- vTextureCoord = aTextureCoord;
- }
- </script>
+
<div id="doc">
<header>
Oops, something went wrong.

0 comments on commit 84db00f

Please sign in to comment.