|
@@ -1,5 +1,6 @@
|
|
|
/**
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
+ * @author mraleph / http://mrale.ph/
|
|
|
*/
|
|
|
|
|
|
THREE.SoftwareRenderer = function () {
|
|
@@ -9,17 +10,27 @@ THREE.SoftwareRenderer = function () {
|
|
|
var canvas = document.createElement( 'canvas' );
|
|
|
var context = canvas.getContext( '2d' );
|
|
|
|
|
|
- var imagedata = context.getImageData( 0, 0, canvas.width, canvas.height );
|
|
|
- var data = imagedata.data;
|
|
|
-
|
|
|
var canvasWidth = canvas.width;
|
|
|
var canvasHeight = canvas.height;
|
|
|
|
|
|
var canvasWidthHalf = canvasWidth / 2;
|
|
|
var canvasHeightHalf = canvasHeight / 2;
|
|
|
|
|
|
- var edges = [ new Edge(), new Edge(), new Edge() ];
|
|
|
- var span = new Span();
|
|
|
+ var imagedata = context.getImageData( 0, 0, canvas.width, canvas.height );
|
|
|
+ var data = imagedata.data;
|
|
|
+
|
|
|
+ var blocksize = 8;
|
|
|
+
|
|
|
+ var canvasWBlocks = Math.floor( ( canvasWidth + blocksize - 1 ) / blocksize );
|
|
|
+ var canvasHBlocks = Math.floor( ( canvasHeight + blocksize - 1 ) / blocksize );
|
|
|
+
|
|
|
+ var block_full = new Uint8Array( canvasWBlocks * canvasHBlocks );
|
|
|
+
|
|
|
+ var rectx1 = Infinity, recty1 = Infinity;
|
|
|
+ var rectx2 = 0, recty2 = 0;
|
|
|
+
|
|
|
+ var prevrectx1 = Infinity, prevrecty1 = Infinity;
|
|
|
+ var prevrectx2 = 0, prevrecty2 = 0;
|
|
|
|
|
|
var projector = new THREE.Projector();
|
|
|
|
|
@@ -41,13 +52,22 @@ THREE.SoftwareRenderer = function () {
|
|
|
imagedata = context.getImageData( 0, 0, width, height );
|
|
|
data = imagedata.data;
|
|
|
|
|
|
+ canvasWBlocks = Math.floor( ( canvasWidth + blocksize - 1 ) / blocksize );
|
|
|
+ canvasHBlocks = Math.floor( ( canvasHeight + blocksize - 1 ) / blocksize );
|
|
|
+
|
|
|
+ console.log( canvasWBlocks, canvasHBlocks );
|
|
|
+
|
|
|
+ block_full = new Uint8Array( canvasWBlocks * canvasHBlocks )
|
|
|
+
|
|
|
};
|
|
|
|
|
|
this.clear = function () {
|
|
|
|
|
|
- for ( var i = 3, l = data.length; i < l; i += 4 ) {
|
|
|
+ clearRectangle( prevrectx1, prevrecty1, prevrectx2, prevrecty2 );
|
|
|
+
|
|
|
+ for ( var i = 0, l = block_full.length; i < l; i ++ ) {
|
|
|
|
|
|
- data[ i ] = 0;
|
|
|
+ block_full[ i ] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -55,14 +75,17 @@ THREE.SoftwareRenderer = function () {
|
|
|
|
|
|
this.render = function ( scene, camera ) {
|
|
|
|
|
|
- var m, ml, element, material, dom, v1x, v1y;
|
|
|
+ rectx1 = Infinity;
|
|
|
+ recty1 = Infinity;
|
|
|
+ rectx2 = 0;
|
|
|
+ recty2 = 0;
|
|
|
|
|
|
if ( this.autoClear ) this.clear();
|
|
|
|
|
|
var renderData = projector.projectScene( scene, camera );
|
|
|
var elements = renderData.elements;
|
|
|
|
|
|
- elements.sort( function painterSort( a, b ) { return a.z - b.z; } );
|
|
|
+ elements.sort( numericalSort );
|
|
|
|
|
|
for ( var e = 0, el = elements.length; e < el; e ++ ) {
|
|
|
|
|
@@ -77,13 +100,13 @@ THREE.SoftwareRenderer = function () {
|
|
|
drawTriangle(
|
|
|
v1.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v1.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0xff0000,
|
|
|
v2.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v2.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0x00ff00,
|
|
|
v3.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v3.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0x0000ff
|
|
|
+ 0.5 * element.normalModelView.x + 0.5,
|
|
|
+ 0.5 * element.normalModelView.y + 0.5,
|
|
|
+ 0.5 * element.normalModelView.z + 0.5
|
|
|
)
|
|
|
|
|
|
} else if ( element instanceof THREE.RenderableFace4 ) {
|
|
@@ -96,42 +119,53 @@ THREE.SoftwareRenderer = function () {
|
|
|
drawTriangle(
|
|
|
v1.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v1.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0xff0000,
|
|
|
v2.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v2.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0x00ff00,
|
|
|
v3.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v3.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0x0000ff
|
|
|
+ 0.5 * element.normalModelView.x + 0.5,
|
|
|
+ 0.5 * element.normalModelView.y + 0.5,
|
|
|
+ 0.5 * element.normalModelView.z + 0.5
|
|
|
);
|
|
|
|
|
|
drawTriangle(
|
|
|
v3.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v3.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0x0000ff,
|
|
|
v4.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v4.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0xff00ff,
|
|
|
v1.x * canvasWidthHalf + canvasWidthHalf,
|
|
|
- v1.y * canvasHeightHalf + canvasHeightHalf,
|
|
|
- 0xff0000
|
|
|
+ 0.5 * element.normalModelView.x + 0.5,
|
|
|
+ 0.5 * element.normalModelView.y + 0.5,
|
|
|
+ 0.5 * element.normalModelView.z + 0.5
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- context.putImageData( imagedata, 0, 0 );
|
|
|
+ var x = Math.min( rectx1, prevrectx1 );
|
|
|
+ var y = Math.min( recty1, prevrecty1 );
|
|
|
+ var width = Math.max( rectx2, prevrectx2 ) - x;
|
|
|
+ var height = Math.max( recty2, prevrecty2 ) - y;
|
|
|
+
|
|
|
+ context.putImageData( imagedata, 0, 0, x, y, width, height );
|
|
|
+
|
|
|
+ prevrectx1 = rectx1; prevrecty1 = recty1;
|
|
|
+ prevrectx2 = rectx2; prevrecty2 = recty2;
|
|
|
|
|
|
};
|
|
|
|
|
|
+ function numericalSort( a, b ) {
|
|
|
+
|
|
|
+ return a.z - b.z;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function drawPixel( x, y, r, g, b ) {
|
|
|
|
|
|
var offset = ( x + y * canvasWidth ) * 4;
|
|
|
|
|
|
- if ( x < 0 || y < 0 ) return;
|
|
|
- if ( x > canvasWidth || y > canvasHeight ) return;
|
|
|
-
|
|
|
if ( data[ offset + 3 ] ) return;
|
|
|
|
|
|
data[ offset ] = r;
|
|
@@ -141,232 +175,244 @@ THREE.SoftwareRenderer = function () {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- function drawRectangle( x1, y1, x2, y2, color ) {
|
|
|
+ function clearRectangle( x1, y1, x2, y2 ) {
|
|
|
|
|
|
- var r = color >> 16 & 255;
|
|
|
- var g = color >> 8 & 255;
|
|
|
- var b = color & 255;
|
|
|
+ var xmin = Math.max( Math.min( x1, x2 ), 0 );
|
|
|
+ var xmax = Math.min( Math.max( x1, x2 ), canvasWidth );
|
|
|
+ var ymin = Math.max( Math.min( y1, y2 ), 0 );
|
|
|
+ var ymax = Math.min( Math.max( y1, y2 ), canvasHeight );
|
|
|
|
|
|
- var xmin = Math.min( x1, x2 ) >> 0;
|
|
|
- var xmax = Math.max( x1, x2 ) >> 0;
|
|
|
- var ymin = Math.min( y1, y2 ) >> 0;
|
|
|
- var ymax = Math.max( y1, y2 ) >> 0;
|
|
|
+ var offset = ( xmin + ymin * canvasWidth - 1 ) * 4 + 3;
|
|
|
+ var linestep = ( canvasWidth - ( xmax - xmin ) ) * 4;
|
|
|
|
|
|
for ( var y = ymin; y < ymax; y ++ ) {
|
|
|
|
|
|
for ( var x = xmin; x < xmax; x ++ ) {
|
|
|
|
|
|
- drawPixel( x, y, r, g, b );
|
|
|
+ data[ offset += 4 ] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ offset += linestep;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- */
|
|
|
-
|
|
|
- function drawTriangle( x1, y1, color1, x2, y2, color2, x3, y3, color3 ) {
|
|
|
-
|
|
|
- // http://joshbeam.com/articles/triangle_rasterization/
|
|
|
|
|
|
- edges[ 0 ].set( x1, y1, color1, x2, y2, color2 );
|
|
|
- edges[ 1 ].set( x2, y2, color2, x3, y3, color3 );
|
|
|
- edges[ 2 ].set( x3, y3, color3, x1, y1, color1 );
|
|
|
+ function drawTriangle( x1, y1, x2, y2, x3, y3, r, g, b ) {
|
|
|
|
|
|
- var maxLength = 0;
|
|
|
- var longEdge = 0;
|
|
|
+ // https://gist.github.com/2486101
|
|
|
+ // explanation: ttp://pouet.net/topic.php?which=8760&page=1
|
|
|
|
|
|
- // find edge with the greatest length in the y axis
|
|
|
+ // 28.4 fixed-point coordinates
|
|
|
|
|
|
- for ( var i = 0; i < 3; i ++ ) {
|
|
|
+ var x1 = (16 * x1) | 0;
|
|
|
+ var x2 = (16 * x2) | 0;
|
|
|
+ var x3 = (16 * x3) | 0;
|
|
|
|
|
|
- var length = ( edges[ i ].y2 - edges[ i ].y1 );
|
|
|
+ var y1 = (16 * y1) | 0;
|
|
|
+ var y2 = (16 * y2) | 0;
|
|
|
+ var y3 = (16 * y3) | 0;
|
|
|
|
|
|
- if ( length > maxLength ) {
|
|
|
+ // Deltas
|
|
|
|
|
|
- maxLength = length;
|
|
|
- longEdge = i;
|
|
|
+ var dx12 = x1 - x2, dy12 = y2 - y1;
|
|
|
+ var dx23 = x2 - x3, dy23 = y3 - y2;
|
|
|
+ var dx31 = x3 - x1, dy31 = y1 - y3;
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ // Bounding rectangle
|
|
|
|
|
|
- var shortEdge1 = ( longEdge + 1 ) % 3;
|
|
|
- var shortEdge2 = ( longEdge + 2 ) % 3;
|
|
|
+ var minx = Math.max( ( Math.min( x1, x2, x3 ) + 0xf ) >> 4, 0 );
|
|
|
+ var maxx = Math.min( ( Math.max( x1, x2, x3 ) + 0xf ) >> 4, canvasWidth );
|
|
|
+ var miny = Math.max( ( Math.min( y1, y2, y3 ) + 0xf ) >> 4, 0 );
|
|
|
+ var maxy = Math.min( ( Math.max( y1, y2, y3 ) + 0xf ) >> 4, canvasHeight );
|
|
|
|
|
|
- drawSpans( edges[ longEdge ], edges[ shortEdge1 ] );
|
|
|
- drawSpans( edges[ longEdge ], edges[ shortEdge2 ] );
|
|
|
+ rectx1 = Math.min( minx, rectx1 );
|
|
|
+ rectx2 = Math.max( maxx, rectx2 );
|
|
|
+ recty1 = Math.min( miny, recty1 );
|
|
|
+ recty2 = Math.max( maxy, recty2 );
|
|
|
|
|
|
- }
|
|
|
+ // Block size, standard 8x8 (must be power of two)
|
|
|
|
|
|
- function drawSpans( e1, e2 ) {
|
|
|
+ var q = blocksize;
|
|
|
|
|
|
- var e1ydiff = e1.y2 - e1.y1;
|
|
|
- if ( e1ydiff === 0 ) return;
|
|
|
+ // Start in corner of 8x8 block
|
|
|
|
|
|
- var e2ydiff = e2.y2 - e2.y1;
|
|
|
- if ( e2ydiff === 0 ) return;
|
|
|
+ minx &= ~(q - 1);
|
|
|
+ miny &= ~(q - 1);
|
|
|
|
|
|
- var e1xdiff = e1.x2 - e1.x1;
|
|
|
- var e2xdiff = e2.x2 - e2.x1;
|
|
|
+ // Constant part of half-edge functions
|
|
|
|
|
|
- var e1colordiffr = e1.r2 - e1.r1;
|
|
|
- var e1colordiffg = e1.g2 - e1.g1;
|
|
|
- var e1colordiffb = e1.b2 - e1.b1;
|
|
|
+ var c1 = dy12 * ((minx << 4) - x1) + dx12 * ((miny << 4) - y1);
|
|
|
+ var c2 = dy23 * ((minx << 4) - x2) + dx23 * ((miny << 4) - y2);
|
|
|
+ var c3 = dy31 * ((minx << 4) - x3) + dx31 * ((miny << 4) - y3);
|
|
|
|
|
|
- var e2colordiffr = e2.r2 - e2.r1;
|
|
|
- var e2colordiffg = e2.g2 - e2.g1;
|
|
|
- var e2colordiffb = e2.b2 - e2.b1;
|
|
|
+ // Correct for fill convention
|
|
|
|
|
|
- var factor1 = ( e2.y1 - e1.y1 ) / e1ydiff;
|
|
|
- var factorStep1 = 1 / e1ydiff;
|
|
|
- var factor2 = 0;
|
|
|
- var factorStep2 = 1 / e2ydiff;
|
|
|
+ if ( dy12 > 0 || ( dy12 == 0 && dx12 > 0 ) ) c1 ++;
|
|
|
+ if ( dy23 > 0 || ( dy23 == 0 && dx23 > 0 ) ) c2 ++;
|
|
|
+ if ( dy31 > 0 || ( dy31 == 0 && dx31 > 0 ) ) c3 ++;
|
|
|
|
|
|
+ // Note this doesn't kill subpixel precision, but only because we test for >=0 (not >0).
|
|
|
+ // It's a bit subtle. :)
|
|
|
+ c1 = (c1 - 1) >> 4;
|
|
|
+ c2 = (c2 - 1) >> 4;
|
|
|
+ c3 = (c3 - 1) >> 4;
|
|
|
|
|
|
- for ( var y = e2.y1; y < e2.y2; y ++ ) {
|
|
|
+ // Set up min/max corners
|
|
|
+ var qm1 = q - 1; // for convenience
|
|
|
+ var nmin1 = 0, nmax1 = 0;
|
|
|
+ var nmin2 = 0, nmax2 = 0;
|
|
|
+ var nmin3 = 0, nmax3 = 0;
|
|
|
+ if (dx12 >= 0) nmax1 -= qm1*dx12; else nmin1 -= qm1*dx12;
|
|
|
+ if (dy12 >= 0) nmax1 -= qm1*dy12; else nmin1 -= qm1*dy12;
|
|
|
+ if (dx23 >= 0) nmax2 -= qm1*dx23; else nmin2 -= qm1*dx23;
|
|
|
+ if (dy23 >= 0) nmax2 -= qm1*dy23; else nmin2 -= qm1*dy23;
|
|
|
+ if (dx31 >= 0) nmax3 -= qm1*dx31; else nmin3 -= qm1*dx31;
|
|
|
+ if (dy31 >= 0) nmax3 -= qm1*dy31; else nmin3 -= qm1*dy31;
|
|
|
|
|
|
- span.set(
|
|
|
- e1.x1 + ( e1xdiff * factor1 ),
|
|
|
- e1.r1 + e1colordiffr * factor1,
|
|
|
- e1.g1 + e1colordiffg * factor1,
|
|
|
- e1.b1 + e1colordiffb * factor1,
|
|
|
+ // Loop through blocks
|
|
|
+ var linestep = (canvasWidth - q) * 4;
|
|
|
+ var scale = 255.0 / (c1 + c2 + c3);
|
|
|
|
|
|
- e2.x1 + ( e2xdiff * factor2 ),
|
|
|
- e2.r1 + e2colordiffr * factor2,
|
|
|
- e2.g1 + e2colordiffg * factor2,
|
|
|
- e2.b1 + e2colordiffb * factor2
|
|
|
- );
|
|
|
+ var cb1 = c1;
|
|
|
+ var cb2 = c2;
|
|
|
+ var cb3 = c3;
|
|
|
+ var qstep = -q;
|
|
|
+ var e1x = qstep * dy12;
|
|
|
+ var e2x = qstep * dy23;
|
|
|
+ var e3x = qstep * dy31;
|
|
|
+ var x0 = minx;
|
|
|
|
|
|
- var xdiff = span.x2 - span.x1;
|
|
|
- if ( xdiff > 0 ) {
|
|
|
+ for (var y0 = miny; y0 < maxy; y0 += q) {
|
|
|
|
|
|
- var colordiffr = span.r2 - span.r1;
|
|
|
- var colordiffg = span.g2 - span.g1;
|
|
|
- var colordiffb = span.b2 - span.b1;
|
|
|
+ // New block line - keep hunting for tri outer edge in old block line dir
|
|
|
+ while (x0 >= minx && x0 < maxx && cb1 >= nmax1 && cb2 >= nmax2 && cb3 >= nmax3) {
|
|
|
|
|
|
- var factor = 0;
|
|
|
- var factorStep = 1 / xdiff;
|
|
|
-
|
|
|
- for ( var x = span.x1; x < span.x2; x ++ ) {
|
|
|
-
|
|
|
- var r = span.r1 + colordiffr * factor;
|
|
|
- var g = span.g1 + colordiffg * factor;
|
|
|
- var b = span.b1 + colordiffb * factor;
|
|
|
-
|
|
|
- drawPixel( x, y, r, g, b );
|
|
|
- factor += factorStep;
|
|
|
-
|
|
|
- }
|
|
|
+ x0 += qstep;
|
|
|
+ cb1 += e1x;
|
|
|
+ cb2 += e2x;
|
|
|
+ cb3 += e3x;
|
|
|
|
|
|
}
|
|
|
|
|
|
- factor1 += factorStep1;
|
|
|
- factor2 += factorStep2;
|
|
|
+ // Okay, we're now in a block we know is outside. Reverse direction and go into main loop.
|
|
|
+ qstep = -qstep;
|
|
|
+ e1x = -e1x;
|
|
|
+ e2x = -e2x;
|
|
|
+ e3x = -e3x;
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function Edge() {
|
|
|
-
|
|
|
- this.x1 = 0;
|
|
|
- this.y1 = 0;
|
|
|
+ while (1) {
|
|
|
|
|
|
- this.x2 = 0;
|
|
|
- this.y2 = 0;
|
|
|
+ // Step everything
|
|
|
+ x0 += qstep;
|
|
|
+ cb1 += e1x;
|
|
|
+ cb2 += e2x;
|
|
|
+ cb3 += e3x;
|
|
|
|
|
|
- this.r1 = 0;
|
|
|
- this.g1 = 0;
|
|
|
- this.b1 = 0;
|
|
|
+ // We're done with this block line when at least one edge completely out
|
|
|
+ // If an edge function is too small and decreasing in the current traversal
|
|
|
+ // dir, we're done with this line.
|
|
|
+ if (x0 < minx || x0 >= maxx) break;
|
|
|
+ if (cb1 < nmax1) if (e1x < 0) break; else continue;
|
|
|
+ if (cb2 < nmax2) if (e2x < 0) break; else continue;
|
|
|
+ if (cb3 < nmax3) if (e3x < 0) break; else continue;
|
|
|
|
|
|
- this.r2 = 0;
|
|
|
- this.g2 = 0;
|
|
|
- this.b2 = 0;
|
|
|
+ // We can skip this block if it's already fully covered
|
|
|
+ var blockX = (x0 / q) | 0;
|
|
|
+ var blockY = (y0 / q) | 0;
|
|
|
+ var blockInd = blockX + blockY * canvasWBlocks;
|
|
|
+ if (block_full[blockInd]) continue;
|
|
|
|
|
|
- this.set = function ( x1, y1, color1, x2, y2, color2 ) {
|
|
|
+ // Offset at top-left corner
|
|
|
+ var offset = (x0 + y0 * canvasWidth) * 4;
|
|
|
|
|
|
- if ( y1 < y2 ) {
|
|
|
+ // Accept whole block when fully covered
|
|
|
+ if (cb1 >= nmin1 && cb2 >= nmin2 && cb3 >= nmin3) {
|
|
|
|
|
|
- this.x1 = x1 >> 0;
|
|
|
- this.y1 = y1 >> 0;
|
|
|
+ var cy1 = cb1;
|
|
|
+ var cy2 = cb2;
|
|
|
|
|
|
- this.x2 = x2 >> 0;
|
|
|
- this.y2 = y2 >> 0;
|
|
|
+ for ( var iy = 0; iy < q; iy ++ ) {
|
|
|
|
|
|
- this.r1 = color1 >> 16 & 255;
|
|
|
- this.g1 = color1 >> 8 & 255;
|
|
|
- this.b1 = color1 & 255;
|
|
|
+ var cx1 = cy1;
|
|
|
+ var cx2 = cy2;
|
|
|
|
|
|
- this.r2 = color2 >> 16 & 255;
|
|
|
- this.g2 = color2 >> 8 & 255;
|
|
|
- this.b2 = color2 & 255;
|
|
|
+ for ( var ix = 0; ix < q; ix ++ ) {
|
|
|
|
|
|
- } else {
|
|
|
+ if (!data[offset + 3]) {
|
|
|
|
|
|
- this.x1 = x2 >> 0;
|
|
|
- this.y1 = y2 >> 0;
|
|
|
+ var u = cx1 * scale; // 0-255!
|
|
|
+ var v = cx2 * scale; // 0-255!
|
|
|
+ data[offset] = u;
|
|
|
+ data[offset + 1] = v;
|
|
|
+ data[offset + 2] = 0;
|
|
|
+ data[offset + 3] = 255;
|
|
|
|
|
|
- this.x2 = x1 >> 0;
|
|
|
- this.y2 = y1 >> 0;
|
|
|
+ }
|
|
|
|
|
|
- this.r1 = color2 >> 16 & 255;
|
|
|
- this.g1 = color2 >> 8 & 255;
|
|
|
- this.b1 = color2 & 255;
|
|
|
+ cx1 += dy12;
|
|
|
+ cx2 += dy23;
|
|
|
+ offset += 4;
|
|
|
|
|
|
- this.r2 = color1 >> 16 & 255;
|
|
|
- this.g2 = color1 >> 8 & 255;
|
|
|
- this.b2 = color1 & 255;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ cy1 += dx12;
|
|
|
+ cy2 += dx23;
|
|
|
+ offset += linestep;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ block_full[blockInd] = 1;
|
|
|
|
|
|
- function Span() {
|
|
|
+ } else { // Partially covered block
|
|
|
|
|
|
- this.x1 = 0;
|
|
|
- this.x2 = 0;
|
|
|
+ var cy1 = cb1;
|
|
|
+ var cy2 = cb2;
|
|
|
+ var cy3 = cb3;
|
|
|
|
|
|
- this.r1 = 0;
|
|
|
- this.g1 = 0;
|
|
|
- this.b1 = 0;
|
|
|
+ for ( var iy = 0; iy < q; iy ++ ) {
|
|
|
|
|
|
- this.r2 = 0;
|
|
|
- this.g2 = 0;
|
|
|
- this.b2 = 0;
|
|
|
+ var cx1 = cy1;
|
|
|
+ var cx2 = cy2;
|
|
|
+ var cx3 = cy3;
|
|
|
|
|
|
- this.set = function ( x1, r1, g1, b1, x2, r2, g2, b2 ) {
|
|
|
+ for ( var ix = 0; ix < q; ix ++ ) {
|
|
|
|
|
|
- if ( x1 < x2 ) {
|
|
|
+ if ( (cx1 | cx2 | cx3) >= 0 && !data[offset+3]) {
|
|
|
|
|
|
- this.x1 = x1 >> 0;
|
|
|
- this.x2 = x2 >> 0;
|
|
|
+ var u = cx1 * scale; // 0-255!
|
|
|
+ var v = cx2 * scale; // 0-255!
|
|
|
+ data[offset] = u;
|
|
|
+ data[offset + 1] = v;
|
|
|
+ data[offset + 2] = 0;
|
|
|
+ data[offset + 3] = 255;
|
|
|
|
|
|
- this.r1 = r1;
|
|
|
- this.g1 = g1;
|
|
|
- this.b1 = b1;
|
|
|
+ }
|
|
|
|
|
|
- this.r2 = r2;
|
|
|
- this.g2 = g2;
|
|
|
- this.b2 = b2;
|
|
|
+ cx1 += dy12;
|
|
|
+ cx2 += dy23;
|
|
|
+ cx3 += dy31;
|
|
|
+ offset += 4;
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- this.x1 = x2 >> 0;
|
|
|
- this.x2 = x1 >> 0;
|
|
|
+ cy1 += dx12;
|
|
|
+ cy2 += dx23;
|
|
|
+ cy3 += dx31;
|
|
|
+ offset += linestep;
|
|
|
|
|
|
- this.r1 = r2;
|
|
|
- this.g1 = g2;
|
|
|
- this.b1 = b2;
|
|
|
+ }
|
|
|
|
|
|
- this.r2 = r1;
|
|
|
- this.g2 = g1;
|
|
|
- this.b2 = b1;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // Advance to next row of blocks
|
|
|
+ cb1 += q*dx12;
|
|
|
+ cb2 += q*dx23;
|
|
|
+ cb3 += q*dx31;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|