package { import flash.events.ErrorEvent; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.TimerEvent; import flash.utils.ByteArray; import flash.utils.Timer; [Event(name = "complete", type = "flash.events.Event")] [Event(name = "cancel", type = "flash.events.Event")] [Event(name = "error", type = "flash.events.ErrorEvent")] /** * PBJDecoder * @author Yukiya Okuda * * @example * var loader:URLLoader = new URLLoader(); * loader.dataFormat = URLLoaderDataFormat.BINARY; * loader.addEventListener(Event.COMPLETE, onLoadComplete); * loader.load( new URLRequest("example.pbj") ); * * var decoder:PBJDecoder = new PBJDecoder(); * decoder.addEventListener(Event.COMPLETE, onDecodeComplete); * decoder.addEventListener(Event.CANCEL, onDecodeCancel); * decoder.addEventListener(ErrorEvent.ERROR, onDecodeError); * * function onLoadComplete(e:Event):void * { * //Synchronous * //decoder.decode(loader.data, 0); * * //Asynchronous * decoder.decode(loader.data, 1); * } * * function onDecodeError(e:ErrorEvent):void * { * trace("ERROR\n-----"); * trace(decoder.log); * trace("-----"); * } * * function onDecodeCancel(e:Event):void * { * trace("CANCEL\n-----"); * trace(decoder.log); * trace("-----"); * } * * function onDecodeComplete(e:Event):void * { * trace("COMPLETE\n-----"); * trace(decoder.log); * trace("-----"); * } * //END * * C++ version * @see http://www.kaourantin.net/2008/09/pixel-bender-pbj-files.html */ public class PBJDecoder extends EventDispatcher { public function PBJDecoder():void { _isRunning = false; _isCompleted = false; } public function get log():String { return _log; } private var _log:String; public function get isRunning():Boolean { return _isRunning; } private var _isRunning:Boolean; public function get isCompleted():Boolean { return _isCompleted; } private var _isCompleted:Boolean; private var _bytes:ByteArray; private var _firstins:Boolean; private var _interval:int; private var _timer:Timer; public function decode(bytes:ByteArray, interval:int = 0):void { cancel(); _isRunning = true; _isCompleted = false; _bytes = bytes; _log = ""; _firstins = false; _interval = interval; if (_interval > 0) { _timer = new Timer(_interval); _timer.addEventListener(TimerEvent.TIMER, _timerHandler); _timer.start(); } else { while (!_isCompleted) { _timerHandler(null); } } } public function cancel():void { if (!_isRunning) return; _isRunning = false; if (_timer) { _timer.stop(); _timer.removeEventListener(TimerEvent.TIMER, _timerHandler); _timer = null; } dispatchEvent( new Event(Event.CANCEL) ); } private function _timerHandler(e:TimerEvent):void { switch (step()) { case 0: break; case 1: _isRunning = false; _isCompleted = true; if (_timer) { _timer.stop(); _timer.removeEventListener(TimerEvent.TIMER, _timerHandler); _timer = null; } dispatchEvent( new Event(Event.COMPLETE) ); break; case 2: _isRunning = false; if (_timer) { _timer.stop(); _timer.removeEventListener(TimerEvent.TIMER, _timerHandler); _timer = null; } dispatchEvent( new ErrorEvent(ErrorEvent.ERROR) ); break; } } private function _logging(m:*):void { _log += m; } private function step():int { if (!available()) return 1; //while (available()) //{ var op0:uint = readUint32(); var op1:uint = readUint32(); var op:int = (op0 >>> 24) ; var dst:int = (op0 >>> 8) & 0xffff; var writeMask:int = (op0 >>> 4) & 0xf; var matrixSize:int = (op0 >>> 2) & 0x3; var readSize:int = (op0 & 3) + 1; var src:int = (op1 >>> 16) & 0xffff; var readSwizzle:int = (op1 >>> 8) & 0xff; dst = littleToBig16(dst); src = littleToBig16(src); // /* if (op <= pbjSelect) { if (matrixSize == 0) { if (op == pbjLoadConstant) { } else if (op == pbjLength) { if (BitCount(writeMask) != pbjSampleSizeScalar) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( dst ) != 1\n"); return 2; } } else if (op == pbjSampleNearest || op == pbjSampleBilinear) { if (readSize != pbjSampleSizeVector2) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( src ) != 2\n"); return 2; } } else if (op == pbjSelect) { if ( readSize != 1 ) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( src ) != 1\n"); return 2; } } else { if (BitCount(writeMask) != readSize) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( dst ) != sizeof( src )\n"); return 2; } } } else { if (isIntReg(src) || isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation not allowed on integer types\n"); return 2; } } } // */ switch (op) { case pbjNop: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } _logging("\t" + opNamesLo[op] + "\n"); break; case pbjAdd: case pbjSubtract: case pbjMultiply: case pbjDivide: case pbjMatrixMatrixMultiply: case pbjAtan2: case pbjPow: case pbjMod: case pbjMin: case pbjMax: case pbjStep: case pbjCopy: case pbjFloatToInt: case pbjIntToFloat: case pbjReciprocal: case pbjSin: case pbjCos: case pbjTan: case pbjASin: case pbjACos: case pbjATan: case pbjExp: case pbjExp2: case pbjLog: case pbjLog2: case pbjSqrt: case pbjRSqrt: case pbjAbs: case pbjSign: case pbjFloor: case pbjCeil: case pbjFract: case pbjFloatToBool: case pbjIntToBool: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { if (writeMask != 0) { _logging("(" + opNamesLo[op & 0x7f] + ") (write mask:" + writeMask + ") write mask not allowed\n"); return 2; } switch (op) { case pbjCopy: case pbjAdd: case pbjSubtract: case pbjMultiply: case pbjReciprocal: case pbjMatrixMatrixMultiply: _logging("\t" + opNamesLo[op] + matrixNames[matrixSize] + "\t\t" + dst + ", " + src + "\n"); break; default: _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } } else { var dstInt:Boolean = false; var srcInt:Boolean = false; switch (op) { case pbjAdd: if (isIntReg(dst)) { dstInt = true; srcInt = true; } break; case pbjSubtract: if (isIntReg(dst)) { dstInt = true; srcInt = true; } break; case pbjMultiply: if (isIntReg(dst)) { dstInt = true; srcInt = true; } break; case pbjDivide: if (isIntReg(dst)) { dstInt = true; srcInt = true; } break; } if (op == pbjCopy) { if (isIntReg(dst) != isIntReg(src)) { _logging("(" + opNamesLo[op & 0x7f] + ") source and destination register type mismatch\n"); return 2; } } else { if (isIntReg(dst) != dstInt) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid destination register type\n"); return 2; } if (isIntReg(src) != srcInt) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid source register type\n"); return 2; } } _logging("\t"); _logging(opNamesLo[op]); if (String(opNamesLo[op]).length < 4) { _logging("\t\t"); } else { _logging("\t"); } printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging( "\n"); } break; case pbjBoolToInt: case pbjBoolToFloat: if (_firstins) { _firstins = false; _logging( "\n;----------------------------------------------------------\n\n"); } if (!isIntReg(src)) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid source register type\n"); return 2; } if (isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid destination register type\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjAny: case pbjAll: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (!isIntReg(src)) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid source register type\n"); return 2; } if (!isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") invalid destination register type\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjVectorMatrixMultiply: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (BitCount(writeMask) != (matrixSize + 1)) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( dst ) != sizeof( src )\n"); return 2; } _logging("\t" + opNamesLo[op] + matrixNames[matrixSize] + "\t"); printDstReg(dst, writeMask, readSize); _logging(", f" + src + "\n"); break; case pbjMatrixVectorMultiply: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (BitCount(writeMask) != (matrixSize + 1)) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof( dst ) != sizeof( src )\n"); return 2; } _logging("\t" + opNamesLo[op] + matrixNames[matrixSize] + "\t"); printDstReg(dst, writeMask, readSize); _logging(", f" + src + "\n"); break; case pbjNormalize: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (isIntReg(src) || isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on integer types\n"); return 2; } if (readSize == pbjSampleSizeScalar) { _logging("(" + opNamesLo[op & 0x7f] + ") trying to normalize a scalar\n"); return 2; } else { _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); } break; case pbjDistance: case pbjLength: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } if (isIntReg(src) || isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on integer values\n"); return 2; } if (readSize == pbjSampleSizeScalar) { _logging("(" + opNamesLo[op & 0x7f] + ") trying to get the length of a scalar\n"); return 2; } else { _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, 1); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); } break; case pbjDotProduct: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } if (isIntReg(src) || isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on integer values\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjCrossProduct: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } if (isIntReg(src) || isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on integer values\n"); return 2; } if (readSize != 3) { _logging("(" + opNamesLo[op & 0x7f] + ") vector type not supported\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjEqual: case pbjNotEqual: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("\t" + opNamesLo[op] + matrixNames[matrixSize] + "\t\t" + dst + ", " + src + "\n"); } else { _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); } break; case pbjVectorEqual: case pbjVectorNotEqual: case pbjLessThan: case pbjLessThanEqual: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } if (isIntReg(src) != isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") register type mismatch\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t"); if (String(opNamesLo[op]).length < 4) { _logging("\t"); } printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjLogicalOr: case pbjLogicalXor: case pbjLogicalAnd: case pbjLogicalNot: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (matrixSize) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on matrices\n"); return 2; } if (!isIntReg(src) || !isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") operation now allowed on float values\n"); return 2; } if (readSize != pbjSampleSizeScalar) { _logging("(" + opNamesLo[op & 0x7f] + ") ( sizeof( dst ) = sizeof( src ) ) != 1\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging("\n"); break; case pbjSampleBilinear: case pbjSampleNearest: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (isIntReg(dst)) { _logging("(" + opNamesLo[op & 0x7f] + ") Can't sample into integer registers\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); var txtId:int = (op1) & 0xff; _logging(", t" + txtId + "\n"); break; case pbjLoadConstant: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } //union共用体で定義される変数はメモリを共有する //union { var valuec:Array = [0, 0, 0, 0]; var valuef:Number; var valuei:uint; //}; valuei = op1; if (isIntReg(dst)) { _logging("\tset\t\t"); printDstReg(dst, writeMask, readSize); _logging(", " + valuei + "\n"); } else { var ba:ByteArray = new ByteArray(); ba.writeUnsignedInt(valuei); /* ba.position = 0; valuec[0] = ba.readUnsignedByte(); valuec[1] = ba.readUnsignedByte(); valuec[2] = ba.readUnsignedByte(); valuec[3] = ba.readUnsignedByte(); valuei = (uint(valuec[3]) << 24) | (uint(valuec[2]) << 16) | (uint(valuec[1]) << 8 ) | (uint(valuec[0]) << 0 ) ; */ ba.position = 0; ba.writeUnsignedInt(valuei); ba.position = 0; valuef = ba.readFloat(); //TODO 有効桁数 _logging("\tset\t\t"); printDstReg(dst, writeMask, readSize); _logging(", " + valuef + "\n"); } break; case pbjSelect: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } var op2:uint = readUint32(); var op3:uint = readUint32(); var src0:uint = op2 >> 16; var src1:uint = op3 >> 16; var readSize0:int = ((op2 >> 6) & 0x3 ) + 1; var readSwizzle0:int = ( op2 >> 8) & 0xff; var readSize1:int = ((op3 >> 6) & 0x3 ) + 1; var readSwizzle1:int = ( op3 >> 8) & 0xff; src0 = littleToBig16(src0); src1 = littleToBig16(src1); if (!isIntReg(src)) { _logging("(" + opNamesLo[op & 0x7f] + ") source needs to be of type int\n"); return 2; } if (readSize0 != readSize1) { _logging("(" + opNamesLo[op & 0x7f] + ") sizeof(src1) != sizeof(src2)\n"); return 2; } if (matrixSize) { if (!isIntReg(src0) || !isIntReg(src1)) { _logging("(" + opNamesLo[op & 0x7f] + ") source needs to be of type int\n"); return 2; } _logging("\t" + opNamesLo[op] + matrixNames[matrixSize] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging(", f" + src0 + ", f" + src1 + "\n"); } else { if (isIntReg(src0) != isIntReg(src1) || isIntReg(src0) != isIntReg(dst) ) { _logging("(" + opNamesLo[op & 0x7f] + ") source register type mismatch\n"); return 2; } _logging("\t" + opNamesLo[op] + "\t\t"); printDstReg(dst, writeMask, readSize); _logging(", "); printSrcReg(src, readSwizzle, readSize); _logging(", "); printSrcReg(src0, readSwizzle0, readSize); _logging(", "); printSrcReg(src1, readSwizzle1, readSize); _logging("\n"); } break; case pbjIf: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } if (!isIntReg(src)) { _logging("(" + opNamesLo[op & 0x7f] + ") source needs to be of type int\n"); return 2; } _logging("\n\t" + opNamesLo[op] + "\t\t"); printSrcReg(src, readSwizzle, readSize); _logging("\n\n"); break; case pbjElse: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } _logging("\n\t" + opNamesLo[op] + "\t\t\n\n"); break; case pbjEndif: if (_firstins) { _firstins = false; _logging("\n;----------------------------------------------------------\n\n"); } _logging("\n\t" + opNamesLo[op] + "\t\t\n\n"); break; case pbjParameterMetaData: case pbjKernelMetaData: seek(-7); var type:uint = readUint8(); if (type == pbjTypeString) { var name:String = readStr(); var meta:String = readStr(); if (op == pbjParameterMetaData) { _logging("\tmeta\t\t\"" + name + "\", \"" + meta + "\""); } else { _logging("\tkernel\t\t\"" + name + "\", \"" + meta + "\""); } } else { var name:String = readStr(); if (op == pbjParameterMetaData) { _logging("\tmeta\t\t\"" + name + "\""); var numElem:int = 0; switch (type) { case pbjTypeFloat4x4: numElem += 7; case pbjTypeFloat3x3: numElem += 5; case pbjTypeFloat2x2: case pbjTypeFloat4: numElem++; case pbjTypeFloat3: numElem++; case pbjTypeFloat2: numElem++; case pbjTypeFloat: numElem++; for (var c:int = 0; c < numElem; ++c) { _logging(", " + readFloat()); } break; case pbjTypeBool4: case pbjTypeInt4: numElem++; case pbjTypeBool3: case pbjTypeInt3: numElem++; case pbjTypeBool2: case pbjTypeInt2: numElem++; case pbjTypeBool: case pbjTypeInt: numElem++; for (var c:int = 0; c < numElem; ++c) { var i:int = (littleToBig16(readUint16()) << 15) >> 15; _logging(", " + i); } break; } } else { //_logging("\tkernel\t\t\"" + name + "\""); switch (type) { case pbjTypeInt: var i:int = (littleToBig16(readUint16()) << 15) >> 15; //_logging(", " + i); _logging("\tkernel\t\t\"" + name + "\", " + i); break; default: return 2; } } } _logging("\n"); break; case pbjParameterData: seek(-7); var qualifier:uint = readUint8(); var type:uint = readUint8(); if (type == pbjTypeString || qualifier > 2 || qualifier < 1) { return 2; } else { dst = littleToBig16(readUint16()); writeMask = readUint8(); var paramName:String = readStr(); _logging("\n\tparameter\t\"" + paramName + "\", " + typeNames[type] + ", "); printDstReg(dst, writeMask, typeSizes[type]); _logging(", " + qualifierName[qualifier]); _logging("\n"); } break; case pbjTextureData: seek(-7); var index:int = readUint8(); var channels:int = readUint8(); _logging("\n\ttexture\t\t\"" + readStr() + "\", t" + index); var cnam:Array = ["r", "g", "b", "a"]; if (channels != 4) { _logging("."); for (var c:int = 0; c < channels; ++c) { _logging(cnam[c]); } } _logging("\n"); break; case pbjKernelName: seek(-7); var name:String = readStrN(littleToBig16(readUint16())); _logging("\tname\t\t\"" + name + "\"\n"); break; case pbjVersionData: seek(-7); var a0:uint = readUint8(); var a1:uint = readUint8(); var a2:uint = readUint8(); var a3:uint = readUint8(); var version:uint = (a0) | (a1 << 8) | (a2 << 16) | (a3 << 24); if (version != 1) { _logging("(?) unsupported pbj byte code version " + version + "\n"); return 2; } _logging("\tversion\t\t" + version + "\n"); break; default: if (available()) { _logging("(?) unknown opcode " + op + "\n"); return 2; } //return 0; } //} // //return 1; return 0; } private function available():Boolean { return _bytes.bytesAvailable; } private function seek(n:int):void { _bytes.position += n; } private function readUint8():uint { return _bytes.readUnsignedByte(); } private function readUint16():uint { return _bytes.readUnsignedShort(); } private function readUint32():uint { return _bytes.readUnsignedInt(); } private function readFloat():Number { return _bytes.readFloat(); } private function isIntReg(reg:int):Boolean { return (reg & 0x8000) ? true : false; } private function Swizzle(index:int, swizzle:int):int { return (swizzle >>> (6 - index * 2)) & 3; } private function BitCount(n:uint):int { return n.toString(2).match(/1/g).length; //2進数表記の1を数えるロジックだと思う //var tmp:uint = n - ((n >>> 1) & 033333333333) - ((n >>> 2) & 011111111111); //return ((tmp + (tmp >>> 3)) & 030707070707) % 63; } private function littleToBig16(v:uint):uint { return ((v >>> 8) & 0xff) | ((v << 8) & 0xff00); } private function readStrN(n:int):String { var s:String = ""; for (var i:int = 0; i < n; ++i) { s += String.fromCharCode(readUint8()); } return s; } private function readStr():String { var s:String = ""; var c:uint; while ((c = readUint8()) != 0) { s += String.fromCharCode(c); } return s; } private function IndexToDstWithMask(index:int, mask:int):int { return dstMap[(mask << 2 | index)]; } private function printDstReg(index:int, writeMask:int, readSize:int):void { if (index >= 32768) { _logging("i" + (index - 32768)); } else { _logging("f" + index); } if (writeMask != 0xf) { _logging("."); var cnam:Array = ["r", "g", "b", "a"]; for (var c:int = 0; c < readSize; ++c) { _logging(cnam[IndexToDstWithMask(c, writeMask)]); } } } private function printSrcReg(index:int, readSwizzle:int, readSize:int):void { if (index >= 32768) { _logging("i" + (index - 32768)); } else { _logging("f" + index); } if (readSwizzle != 0x1b) { _logging("."); var cnam:Array = ["r", "g", "b", "a"]; for (var c:int = 0; c < readSize; ++c) { _logging(cnam[Swizzle(c, readSwizzle)]); } } } private const pbjNop = 0x00; private const pbjAdd = 0x01; private const pbjSubtract = 0x02; private const pbjMultiply = 0x03; private const pbjReciprocal = 0x04; private const pbjDivide = 0x05; private const pbjAtan2 = 0x06; private const pbjPow = 0x07; private const pbjMod = 0x08; private const pbjMin = 0x09; private const pbjMax = 0x0A; private const pbjStep = 0x0B; private const pbjSin = 0x0C; private const pbjCos = 0x0D; private const pbjTan = 0x0E; private const pbjASin = 0x0F; private const pbjACos = 0x10; private const pbjATan = 0x11; private const pbjExp = 0x12; private const pbjExp2 = 0x13; private const pbjLog = 0x14; private const pbjLog2 = 0x15; private const pbjSqrt = 0x16; private const pbjRSqrt = 0x17; private const pbjAbs = 0x18; private const pbjSign = 0x19; private const pbjFloor = 0x1A; private const pbjCeil = 0x1B; private const pbjFract = 0x1C; private const pbjCopy = 0x1D; private const pbjFloatToInt = 0x1E; private const pbjIntToFloat = 0x1F; private const pbjMatrixMatrixMultiply = 0x20; private const pbjVectorMatrixMultiply = 0x21; private const pbjMatrixVectorMultiply = 0x22; private const pbjNormalize = 0x23; private const pbjLength = 0x24; private const pbjDistance = 0x25; private const pbjDotProduct = 0x26; private const pbjCrossProduct = 0x27; private const pbjEqual = 0x28; private const pbjNotEqual = 0x29; private const pbjLessThan = 0x2A; private const pbjLessThanEqual = 0x2B; private const pbjLogicalNot = 0x2C; private const pbjLogicalAnd = 0x2D; private const pbjLogicalOr = 0x2E; private const pbjLogicalXor = 0x2F; private const pbjSampleNearest = 0x30; private const pbjSampleBilinear = 0x31; private const pbjLoadConstant = 0x32; private const pbjSelect = 0x33; private const pbjIf = 0x34; private const pbjElse = 0x35; private const pbjEndif = 0x36; private const pbjFloatToBool = 0x37; private const pbjBoolToFloat = 0x38; private const pbjIntToBool = 0x39; private const pbjBoolToInt = 0x3A; private const pbjVectorEqual = 0x3B; private const pbjVectorNotEqual = 0x3C; private const pbjAny = 0x3D; private const pbjAll = 0x3E; private const pbjKernelMetaData = 0xa0; private const pbjParameterData = 0xa1; private const pbjParameterMetaData = 0xa2; private const pbjTextureData = 0xa3; private const pbjKernelName = 0xa4; private const pbjVersionData = 0xa5; private const pbjTypeFloat = 0x01; private const pbjTypeFloat2 = 0x02; private const pbjTypeFloat3 = 0x03; private const pbjTypeFloat4 = 0x04; private const pbjTypeFloat2x2 = 0x05; private const pbjTypeFloat3x3 = 0x06; private const pbjTypeFloat4x4 = 0x07; private const pbjTypeInt = 0x08; private const pbjTypeInt2 = 0x09; private const pbjTypeInt3 = 0x0A; private const pbjTypeInt4 = 0x0B; private const pbjTypeString = 0x0C; private const pbjTypeBool = 0x0D; private const pbjTypeBool2 = 0x0E; private const pbjTypeBool3 = 0x0F; private const pbjTypeBool4 = 0x10; private const pbjSampleSizeScalar = 0x01; private const pbjSampleSizeVector2 = 0x02; private const pbjSampleSizeVector3 = 0x03; private const pbjSampleSizeVector4 = 0x04; private const opNamesLo:Array = [ "nop", "add", "sub", "mul", "rcp", "div", "atan2", "pow", "mod", "min", "max", "step", "sin", "cos", "tan", "asin", "acos", "atan", "exp", "exp2", "log", "log2", "sqr", "rsqr", "abs", "sign", "floor", "ceil", "fract", "mov", "ftoi", "itof", "mmmul", "vmmul", "mvmul", "norm", "len", "dist", "dot", "cross", "equ", "neq", "ltn", "lte", "not", "and", "or", "xor", "texn", "texb", "set", "sel", "if", "else", "end", "ftob", "btof", "itob", "btoi", "vequ", "vneq", "any", "all" ]; private const opNamesHi:Array = [ "kernel", "parameter", "meta", "texture", "name", "version" ]; private const matrixNames:Array = [ "", "2x2", "3x3", "4x4" ]; private const typeSizes:Array = [ 0, 1, 2, 3, 4, 4, 9, 16, 1, 2, 3, 4, 0, 1, 2, 3, 4 ]; private const typeNames:Array = [ "", "float", "float2", "float3", "float4", "matrix2x2", "matrix3x3", "matrix4x4", "int", "int2", "int3", "int4", "bool", "bool2", "bool3", "bool4" ]; private const qualifierName:Array = [ "", "in", "out" ]; private const dstMap:Array = [ 0x00,0x00,0x00,0x00, 0x03,0x00,0x00,0x00, 0x02,0x00,0x00,0x00, 0x02,0x03,0x00,0x00, 0x01,0x00,0x00,0x00, 0x01,0x03,0x00,0x00, 0x01,0x02,0x00,0x00, 0x01,0x02,0x03,0x00, 0x00,0x00,0x00,0x00, 0x00,0x03,0x00,0x00, 0x00,0x02,0x00,0x00, 0x00,0x02,0x03,0x00, 0x00,0x01,0x00,0x00, 0x00,0x01,0x03,0x00, 0x00,0x01,0x02,0x00, 0x00,0x01,0x02,0x03 ]; } }