UNPKG

shadow-function

Version:

ioing lib - shadow Function, worker Function

1,442 lines (1,289 loc) 330 kB
(function(window,document,Laya){ var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec; var Arith=window.laya.maths.Arith,Bezier=window.laya.maths.Bezier,Bitmap=window.laya.resource.Bitmap,Browser=window.laya.utils.Browser; var Byte=window.laya.utils.Byte,Color=window.laya.utils.Color,ColorFilter=window.laya.filters.ColorFilter,Config=window.Laya.Config,Context=window.laya.resource.Context; var Event=window.laya.events.Event,Filter=window.laya.filters.Filter,Graphics=window.laya.display.Graphics,HTMLCanvas=window.laya.resource.HTMLCanvas; var HTMLChar=window.laya.utils.HTMLChar,HTMLImage=window.laya.resource.HTMLImage,HTMLSubImage=window.laya.resource.HTMLSubImage; var Handler=window.laya.utils.Handler,Loader=window.laya.net.Loader,Matrix=window.laya.maths.Matrix,Point=window.laya.maths.Point,Rectangle=window.laya.maths.Rectangle; var Render=window.laya.renders.Render,RenderContext=window.laya.renders.RenderContext,RenderSprite=window.laya.renders.RenderSprite; var Resource=window.laya.resource.Resource,ResourceManager=window.laya.resource.ResourceManager,RunDriver=window.laya.utils.RunDriver; var Sprite=window.laya.display.Sprite,Stage=window.laya.display.Stage,Stat=window.laya.utils.Stat,StringKey=window.laya.utils.StringKey; var Style=window.laya.display.css.Style,System=window.laya.system.System,Text=window.laya.display.Text,Texture=window.laya.resource.Texture; var TransformInfo=window.laya.display.css.TransformInfo,URL=window.laya.net.URL,Utils=window.laya.utils.Utils,VectorGraphManager=window.laya.utils.VectorGraphManager; var WordText=window.laya.utils.WordText; Laya.interface('laya.webgl.shapes.IShape'); Laya.interface('laya.webgl.submit.ISubmit'); Laya.interface('laya.webgl.text.ICharSegment'); Laya.interface('laya.webgl.canvas.save.ISaveData'); Laya.interface('laya.webgl.resource.IMergeAtlasBitmap'); Laya.interface('laya.filters.IFilterActionGL','laya.filters.IFilterAction'); //class laya.filters.webgl.FilterActionGL var FilterActionGL=(function(){ function FilterActionGL(){} __class(FilterActionGL,'laya.filters.webgl.FilterActionGL'); var __proto=FilterActionGL.prototype; Laya.imps(__proto,{"laya.filters.IFilterActionGL":true}) __proto.setValue=function(shader){} __proto.setValueMix=function(shader){} __proto.apply3d=function(scope,sprite,context,x,y){return null;} __proto.apply=function(srcCanvas){return null;} __getset(0,__proto,'typeMix',function(){ return 0; }); return FilterActionGL; })() //class laya.webgl.shader.ShaderValue var ShaderValue=(function(){ function ShaderValue(){} __class(ShaderValue,'laya.webgl.shader.ShaderValue'); return ShaderValue; })() //class laya.webgl.atlas.AtlasGrid var AtlasGrid=(function(){ var TexRowInfo,TexMergeTexSize; function AtlasGrid(width,height,atlasID){ this._atlasID=0; this._width=0; this._height=0; this._texCount=0; this._rowInfo=null; this._cells=null; this._failSize=new TexMergeTexSize(); (width===void 0)&& (width=0); (height===void 0)&& (height=0); (atlasID===void 0)&& (atlasID=0); this._cells=null; this._rowInfo=null; this._init(width,height); this._atlasID=atlasID; } __class(AtlasGrid,'laya.webgl.atlas.AtlasGrid'); var __proto=AtlasGrid.prototype; //------------------------------------------------------------------------------ __proto.getAltasID=function(){ return this._atlasID; } //------------------------------------------------------------------------------ __proto.setAltasID=function(atlasID){ if (atlasID >=0){ this._atlasID=atlasID; } } //------------------------------------------------------------------ __proto.addTex=function(type,width,height){ var result=this._get(width,height); if (result.ret==false){ return result; } this._fill(result.x,result.y,width,height,type); this._texCount++; return result; } //------------------------------------------------------------------------------ __proto._release=function(){ if (this._cells !=null){ this._cells.length=0; this._cells=null; } if (this._rowInfo){ this._rowInfo.length=0; this._rowInfo=null; } } //------------------------------------------------------------------------------ __proto._init=function(width,height){ this._width=width; this._height=height; this._release(); if (this._width==0)return false; this._cells=new Uint8Array(this._width *this._height*3); this._rowInfo=__newvec(this._height); for (var i=0;i < this._height;i++){ this._rowInfo[i]=new TexRowInfo(); } this._clear(); return true; } //------------------------------------------------------------------ __proto._get=function(width,height){ var pFillInfo=new MergeFillInfo(); if (width >=this._failSize.width && height >=this._failSize.height){ return pFillInfo; }; var rx=-1; var ry=-1; var nWidth=this._width; var nHeight=this._height; var pCellBox=this._cells; for (var y=0;y < nHeight;y++){ if (this._rowInfo[y].spaceCount < width)continue ; for (var x=0;x < nWidth;){ var tm=(y *nWidth+x)*3; if (pCellBox[tm] !=0 || pCellBox[tm+1] < width || pCellBox[tm+2] < height){ x+=pCellBox[tm+1]; continue ; } rx=x; ry=y; for (var xx=0;xx < width;xx++){ if (pCellBox[3*xx+tm+2] < height){ rx=-1; break ; } } if (rx < 0){ x+=pCellBox[tm+1]; continue ; } pFillInfo.ret=true; pFillInfo.x=rx; pFillInfo.y=ry; return pFillInfo; } } return pFillInfo; } //------------------------------------------------------------------ __proto._fill=function(x,y,w,h,type){ var nWidth=this._width; var nHeghit=this._height; this._check((x+w)<=nWidth && (y+h)<=nHeghit); for (var yy=y;yy < (h+y);++yy){ this._check(this._rowInfo[yy].spaceCount >=w); this._rowInfo[yy].spaceCount-=w; for (var xx=0;xx < w;xx++){ var tm=(x+yy *nWidth+xx)*3; this._check(this._cells[tm]==0); this._cells[tm]=type; this._cells[tm+1]=w; this._cells[tm+2]=h; } } if (x > 0){ for (yy=0;yy < h;++yy){ var s=0; for (xx=x-1;xx >=0;--xx,++s){ if (this._cells[((y+yy)*nWidth+xx)*3] !=0)break ; } for (xx=s;xx > 0;--xx){ this._cells[((y+yy)*nWidth+x-xx)*3+1]=xx; this._check(xx > 0); } } } if (y > 0){ for (xx=x;xx < (x+w);++xx){ s=0; for (yy=y-1;yy >=0;--yy,s++){ if (this._cells[(xx+yy *nWidth)*3] !=0)break ; } for (yy=s;yy > 0;--yy){ this._cells[(xx+(y-yy)*nWidth)*3+2]=yy; this._check(yy > 0); } } } } __proto._check=function(ret){ if (ret==false){ console.log("xtexMerger 错误啦"); } } //------------------------------------------------------------------ __proto._clear=function(){ this._texCount=0; for (var y=0;y < this._height;y++){ this._rowInfo[y].spaceCount=this._width; } for (var i=0;i < this._height;i++){ for (var j=0;j < this._width;j++){ var tm=(i *this._width+j)*3; this._cells[tm]=0; this._cells[tm+1]=this._width-j; this._cells[tm+2]=this._width-i; } } this._failSize.width=this._width+1; this._failSize.height=this._height+1; } AtlasGrid.__init$=function(){ //------------------------------------------------------------------------------ //class TexRowInfo TexRowInfo=(function(){ function TexRowInfo(){ this.spaceCount=0; } __class(TexRowInfo,''); return TexRowInfo; })() //------------------------------------------------------------------------------ //class TexMergeTexSize TexMergeTexSize=(function(){ function TexMergeTexSize(){ this.width=0; this.height=0; } __class(TexMergeTexSize,''); return TexMergeTexSize; })() } return AtlasGrid; })() //class laya.webgl.atlas.AtlasResourceManager var AtlasResourceManager=(function(){ function AtlasResourceManager(width,height,gridSize,maxTexNum){ this._currentAtlasCount=0; this._maxAtlaserCount=0; this._width=0; this._height=0; this._gridSize=0; this._gridNumX=0; this._gridNumY=0; this._init=false; this._curAtlasIndex=0; this._setAtlasParam=false; this._atlaserArray=null; this._needGC=false; this._setAtlasParam=true; this._width=width; this._height=height; this._gridSize=gridSize; this._maxAtlaserCount=maxTexNum; this._gridNumX=width / gridSize; this._gridNumY=height / gridSize; this._curAtlasIndex=0; this._atlaserArray=[]; } __class(AtlasResourceManager,'laya.webgl.atlas.AtlasResourceManager'); var __proto=AtlasResourceManager.prototype; __proto.setAtlasParam=function(width,height,gridSize,maxTexNum){ if (this._setAtlasParam==true){ AtlasResourceManager._sid_=0; this._width=width; this._height=height; this._gridSize=gridSize; this._maxAtlaserCount=maxTexNum; this._gridNumX=width / gridSize; this._gridNumY=height / gridSize; this._curAtlasIndex=0; this.freeAll(); return true; }else { console.log("设置大图合集参数错误,只能在开始页面设置各种参数"); throw-1; return false; } return false; } //添加 图片到大图集 __proto.pushData=function(texture){ var bitmap=texture.bitmap; var nWebGLImageIndex=-1; var curAtlas=null; var i=0,n=0,altasIndex=0; for (i=0,n=this._atlaserArray.length;i < n;i++){ altasIndex=(this._curAtlasIndex+i)% n; curAtlas=this._atlaserArray[altasIndex]; nWebGLImageIndex=curAtlas.findBitmapIsExist(bitmap); if (nWebGLImageIndex !=-1){ break ; } } if (nWebGLImageIndex !=-1){ var offset=curAtlas.InAtlasWebGLImagesOffsetValue[nWebGLImageIndex]; offsetX=offset[0]; offsetY=offset[1]; curAtlas.addToAtlas(texture,offsetX,offsetY); return true; }else { var tex=texture; this._setAtlasParam=false; var bFound=false; var nImageGridX=(Math.ceil((texture.bitmap.width+2)/ this._gridSize)); var nImageGridY=(Math.ceil((texture.bitmap.height+2)/ this._gridSize)); var bSuccess=false; for (var k=0;k < 2;k++){ var maxAtlaserCount=this._maxAtlaserCount; for (i=0;i < maxAtlaserCount;i++){ altasIndex=(this._curAtlasIndex+i)% maxAtlaserCount; (this._atlaserArray.length-1 >=altasIndex)|| (this._atlaserArray.push(new Atlaser(this._gridNumX,this._gridNumY,this._width,this._height,AtlasResourceManager._sid_++))); var atlas=this._atlaserArray[altasIndex]; var offsetX=0,offsetY=0; var fillInfo=atlas.addTex(1,nImageGridX,nImageGridY); if (fillInfo.ret){ offsetX=fillInfo.x *this._gridSize+1; offsetY=fillInfo.y *this._gridSize+1; bitmap.lock=true; atlas.addToAtlasTexture((bitmap),offsetX,offsetY); atlas.addToAtlas(texture,offsetX,offsetY); bSuccess=true; this._curAtlasIndex=altasIndex; break ; } } if (bSuccess) break ; this._atlaserArray.push(new Atlaser(this._gridNumX,this._gridNumY,this._width,this._height,AtlasResourceManager._sid_++)); this._needGC=true; this.garbageCollection(); this._curAtlasIndex=this._atlaserArray.length-1; } if (!bSuccess){ console.log(">>>AtlasManager pushData error"); } return bSuccess; } } __proto.addToAtlas=function(tex){ laya.webgl.atlas.AtlasResourceManager.instance.pushData(tex); } /** *回收大图合集,不建议手动调用 *@return */ __proto.garbageCollection=function(){ if (this._needGC===true){ var n=this._atlaserArray.length-this._maxAtlaserCount; for (var i=0;i < n;i++){ this._atlaserArray[i].dispose(); console.log("AtlasResourceManager:Dispose the inner Atlas。"); } console.log(">>>>altas garbageCollection ="+n); this._atlaserArray.splice(0,n); this._needGC=false; } return true; } __proto.freeAll=function(){ for (var i=0,n=this._atlaserArray.length;i < n;i++){ this._atlaserArray[i].dispose(); } this._atlaserArray.length=0; this._curAtlasIndex=0; } __proto.getAtlaserCount=function(){ return this._atlaserArray.length; } __proto.getAtlaserByIndex=function(index){ return this._atlaserArray[index]; } __getset(1,AtlasResourceManager,'instance',function(){ if (!AtlasResourceManager._Instance){ AtlasResourceManager._Instance=new AtlasResourceManager(laya.webgl.atlas.AtlasResourceManager.atlasTextureWidth,laya.webgl.atlas.AtlasResourceManager.atlasTextureHeight,/*CLASS CONST:laya.webgl.atlas.AtlasResourceManager.gridSize*/16,laya.webgl.atlas.AtlasResourceManager.maxTextureCount); } return AtlasResourceManager._Instance; }); __getset(1,AtlasResourceManager,'enabled',function(){ return Config.atlasEnable; }); __getset(1,AtlasResourceManager,'atlasLimitWidth',function(){ return AtlasResourceManager._atlasLimitWidth; },function(value){ AtlasResourceManager._atlasLimitWidth=value; }); __getset(1,AtlasResourceManager,'atlasLimitHeight',function(){ return AtlasResourceManager._atlasLimitHeight; },function(value){ AtlasResourceManager._atlasLimitHeight=value; }); AtlasResourceManager._enable=function(){ Config.atlasEnable=true; } AtlasResourceManager._disable=function(){ Config.atlasEnable=false; } AtlasResourceManager.__init__=function(){ AtlasResourceManager.atlasTextureWidth=2048; AtlasResourceManager.atlasTextureHeight=2048; AtlasResourceManager.maxTextureCount=6; AtlasResourceManager.atlasLimitWidth=512; AtlasResourceManager.atlasLimitHeight=512; } AtlasResourceManager._atlasLimitWidth=0; AtlasResourceManager._atlasLimitHeight=0; AtlasResourceManager.gridSize=16; AtlasResourceManager.atlasTextureWidth=0; AtlasResourceManager.atlasTextureHeight=0; AtlasResourceManager.maxTextureCount=0; AtlasResourceManager._atlasRestore=0; AtlasResourceManager.BOARDER_TYPE_NO=0; AtlasResourceManager.BOARDER_TYPE_RIGHT=1; AtlasResourceManager.BOARDER_TYPE_LEFT=2; AtlasResourceManager.BOARDER_TYPE_BOTTOM=4; AtlasResourceManager.BOARDER_TYPE_TOP=8; AtlasResourceManager.BOARDER_TYPE_ALL=15; AtlasResourceManager._sid_=0; AtlasResourceManager._Instance=null; return AtlasResourceManager; })() //class laya.webgl.atlas.MergeFillInfo var MergeFillInfo=(function(){ function MergeFillInfo(){ this.x=0; this.y=0; this.ret=false; this.ret=false; this.x=0; this.y=0; } __class(MergeFillInfo,'laya.webgl.atlas.MergeFillInfo'); return MergeFillInfo; })() ; //class laya.webgl.canvas.BlendMode var BlendMode=(function(){ function BlendMode(){} __class(BlendMode,'laya.webgl.canvas.BlendMode'); BlendMode._init_=function(gl){ BlendMode.fns=[BlendMode.BlendNormal,BlendMode.BlendAdd,BlendMode.BlendMultiply,BlendMode.BlendScreen,BlendMode.BlendOverlay,BlendMode.BlendLight,BlendMode.BlendMask,BlendMode.BlendDestinationOut]; BlendMode.targetFns=[BlendMode.BlendNormalTarget,BlendMode.BlendAddTarget,BlendMode.BlendMultiplyTarget,BlendMode.BlendScreenTarget,BlendMode.BlendOverlayTarget,BlendMode.BlendLightTarget,BlendMode.BlendMask,BlendMode.BlendDestinationOut]; } BlendMode.BlendNormal=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303); } BlendMode.BlendAdd=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304); } BlendMode.BlendMultiply=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303); } BlendMode.BlendScreen=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1); } BlendMode.BlendOverlay=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301); } BlendMode.BlendLight=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1); } BlendMode.BlendNormalTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303); } BlendMode.BlendAddTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.DST_ALPHA*/0x0304); } BlendMode.BlendMultiplyTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.DST_COLOR*/0x0306,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_ALPHA*/0x0303); } BlendMode.BlendScreenTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1); } BlendMode.BlendOverlayTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE_MINUS_SRC_COLOR*/0x0301); } BlendMode.BlendLightTarget=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ONE*/1,/*laya.webgl.WebGLContext.ONE*/1); } BlendMode.BlendMask=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.SRC_ALPHA*/0x0302); } BlendMode.BlendDestinationOut=function(gl){ gl.blendFunc(/*laya.webgl.WebGLContext.ZERO*/0,/*laya.webgl.WebGLContext.ZERO*/0); } BlendMode.activeBlendFunction=null; BlendMode.NAMES=["normal","add","multiply","screen","overlay","light","mask","destination-out"]; BlendMode.TOINT={"normal":0,"add":1,"multiply":2,"screen":3 ,"lighter":1,"overlay":4,"light":5,"mask":6,"destination-out":7}; BlendMode.NORMAL="normal"; BlendMode.ADD="add"; BlendMode.MULTIPLY="multiply"; BlendMode.SCREEN="screen"; BlendMode.LIGHT="light"; BlendMode.OVERLAY="overlay"; BlendMode.DESTINATIONOUT="destination-out"; BlendMode.fns=[]; BlendMode.targetFns=[]; return BlendMode; })() //class laya.webgl.canvas.DrawStyle var DrawStyle=(function(){ function DrawStyle(value){ this._color=Color.create("black"); this.setValue(value); } __class(DrawStyle,'laya.webgl.canvas.DrawStyle'); var __proto=DrawStyle.prototype; __proto.setValue=function(value){ if (value){ if ((typeof value=='string')){ this._color=Color.create(value); return; } if ((value instanceof laya.utils.Color )){ this._color=value; return; } } } __proto.reset=function(){ this._color=Color.create("black"); } __proto.equal=function(value){ if ((typeof value=='string'))return this._color.strColor===value; if ((value instanceof laya.utils.Color ))return this._color.numColor===(value).numColor; return false; } __proto.toColorStr=function(){ return this._color.strColor; } DrawStyle.create=function(value){ if (value){ var color; if ((typeof value=='string'))color=Color.create(value); else if ((value instanceof laya.utils.Color ))color=value; if (color){ return color._drawStyle || (color._drawStyle=new DrawStyle(value)); } } return laya.webgl.canvas.DrawStyle.DEFAULT; } __static(DrawStyle, ['DEFAULT',function(){return this.DEFAULT=new DrawStyle("#000000");} ]); return DrawStyle; })() //class laya.webgl.canvas.Path var Path=(function(){ function Path(){ this._x=0; this._y=0; //this._rect=null; //this.ib=null; //this.vb=null; this.dirty=false; //this.geomatrys=null; //this._curGeomatry=null; this.offset=0; this.count=0; this.geoStart=0; this.tempArray=[]; this.closePath=false; this.geomatrys=[]; var gl=WebGL.mainContext; this.ib=IndexBuffer2D.create(/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8); this.vb=VertexBuffer2D.create(5); } __class(Path,'laya.webgl.canvas.Path'); var __proto=Path.prototype; __proto.addPoint=function(pointX,pointY){ this.tempArray.push(pointX,pointY); } __proto.getEndPointX=function(){ return this.tempArray[this.tempArray.length-2]; } __proto.getEndPointY=function(){ return this.tempArray[this.tempArray.length-1]; } __proto.polygon=function(x,y,points,color,borderWidth,borderColor){ var geo; this.geomatrys.push(this._curGeomatry=geo=new Polygon(x,y,points,color,borderWidth,borderColor)); if (!color)geo.fill=false; if (borderColor==undefined)geo.borderWidth=0; return geo; } __proto.setGeomtry=function(shape){ this.geomatrys.push(this._curGeomatry=shape); } __proto.drawLine=function(x,y,points,width,color){ var geo; if (this.closePath){ this.geomatrys.push(this._curGeomatry=geo=new LoopLine(x,y,points,width,color)); }else { this.geomatrys.push(this._curGeomatry=geo=new Line(x,y,points,width,color)); } geo.fill=false; return geo; } __proto.update=function(){ var si=this.ib._byteLength; var len=this.geomatrys.length; this.offset=si; for (var i=this.geoStart;i < len;i++){ this.geomatrys[i].getData(this.ib,this.vb,this.vb._byteLength / 20); } this.geoStart=len; this.count=(this.ib._byteLength-si)/ CONST3D2D.BYTES_PIDX; } __proto.reset=function(){ this.vb.clear(); this.ib.clear(); this.offset=this.count=this.geoStart=0; this.geomatrys.length=0; } __proto.recover=function(){ this._curGeomatry=null; this.vb.destory(); this.vb=null; this.ib.destory(); this.ib=null; } return Path; })() //class laya.webgl.canvas.save.SaveBase var SaveBase=(function(){ function SaveBase(){ //this._valueName=null; //this._value=null; //this._dataObj=null; //this._newSubmit=false; } __class(SaveBase,'laya.webgl.canvas.save.SaveBase'); var __proto=SaveBase.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){return false;} __proto.restore=function(context){ this._dataObj[this._valueName]=this._value; SaveBase._cache[SaveBase._cache._length++]=this; this._newSubmit && (context._curSubmit=Submit.RENDERBASE,context._renderKey=0); } SaveBase._createArray=function(){ var value=[]; value._length=0; return value; } SaveBase._init=function(){ var namemap=SaveBase._namemap={}; namemap[0x1]="ALPHA"; namemap[0x2]="fillStyle"; namemap[0x8]="font"; namemap[0x100]="lineWidth"; namemap[0x200]="strokeStyle"; namemap[0x2000]="_mergeID"; namemap[0x400]=namemap[0x800]=namemap[0x1000]=[]; namemap[0x4000]="textBaseline"; namemap[0x8000]="textAlign"; namemap[0x10000]="_nBlendType"; namemap[0x100000]="shader"; namemap[0x200000]="filters"; return namemap; } SaveBase.save=function(context,type,dataObj,newSubmit){ if ((context._saveMark._saveuse & type)!==type){ context._saveMark._saveuse |=type; var cache=SaveBase._cache; var o=cache._length > 0 ? cache[--cache._length] :(new SaveBase()); o._value=dataObj[o._valueName=SaveBase._namemap[type]]; o._dataObj=dataObj; o._newSubmit=newSubmit; var _save=context._save; _save[_save._length++]=o; } } SaveBase._cache=window.laya.webgl.canvas.save.SaveBase._createArray(); SaveBase._namemap=SaveBase._init(); return SaveBase; })() //class laya.webgl.canvas.save.SaveClipRect var SaveClipRect=(function(){ function SaveClipRect(){ //this._clipSaveRect=null; //this._submitScissor=null; this._clipRect=new Rectangle(); } __class(SaveClipRect,'laya.webgl.canvas.save.SaveClipRect'); var __proto=SaveClipRect.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){return false;} __proto.restore=function(context){ context._clipRect=this._clipSaveRect; SaveClipRect._cache[SaveClipRect._cache._length++]=this; this._submitScissor.submitLength=context._submits._length-this._submitScissor.submitIndex; context._curSubmit=Submit.RENDERBASE; context._renderKey=0; } SaveClipRect.save=function(context,submitScissor){ if ((context._saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)==/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000)return; context._saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT*/0x20000; var cache=SaveClipRect._cache; var o=cache._length > 0 ? cache[--cache._length] :(new SaveClipRect()); o._clipSaveRect=context._clipRect; context._clipRect=o._clipRect.copyFrom(context._clipRect); o._submitScissor=submitScissor; var _save=context._save; _save[_save._length++]=o; } __static(SaveClipRect, ['_cache',function(){return this._cache=SaveBase._createArray();} ]); return SaveClipRect; })() //class laya.webgl.canvas.save.SaveClipRectStencil var SaveClipRectStencil=(function(){ function SaveClipRectStencil(){ //this._clipSaveRect=null; //this._saveMatrix=null; this._contextX=0; this._contextY=0; //this._submitStencil=null; this._clipRect=new Rectangle(); this._rect=new Rectangle(); this._matrix=new Matrix(); } __class(SaveClipRectStencil,'laya.webgl.canvas.save.SaveClipRectStencil'); var __proto=SaveClipRectStencil.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){return false;} __proto.restore=function(context){ SubmitStencil.restore(context,this._rect,this._saveMatrix,this._contextX,this._contextY); context._clipRect=this._clipSaveRect; context._curMat=this._saveMatrix; context._x=this._contextX; context._y=this._contextY; SaveClipRectStencil._cache[SaveClipRectStencil._cache._length++]=this; context._curSubmit=Submit.RENDERBASE; } SaveClipRectStencil.save=function(context,submitStencil,x,y,width,height,clipX,clipY,clipWidth,clipHeight){ if ((context._saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT_STENCIL*/0x40000)==/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT_STENCIL*/0x40000)return; context._saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_CLIPRECT_STENCIL*/0x40000; var cache=SaveClipRectStencil._cache; var o=cache._length > 0 ? cache[--cache._length] :(new SaveClipRectStencil()); o._clipSaveRect=context._clipRect; o._clipRect.setTo(clipX,clipY,clipWidth,clipHeight); context._clipRect=o._clipRect; o._rect.x=x; o._rect.y=y; o._rect.width=width; o._rect.height=height; o._contextX=context._x; o._contextY=context._y; o._saveMatrix=context._curMat; context._curMat.copyTo(o._matrix); context._curMat=o._matrix; o._submitStencil=submitStencil; var _save=context._save; _save[_save._length++]=o; } __static(SaveClipRectStencil, ['_cache',function(){return this._cache=SaveBase._createArray();} ]); return SaveClipRectStencil; })() //class laya.webgl.canvas.save.SaveMark var SaveMark=(function(){ function SaveMark(){ this._saveuse=0; //this._preSaveMark=null; ; } __class(SaveMark,'laya.webgl.canvas.save.SaveMark'); var __proto=SaveMark.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){ return true; } __proto.restore=function(context){ context._saveMark=this._preSaveMark; SaveMark._no[SaveMark._no._length++]=this; } SaveMark.Create=function(context){ var no=SaveMark._no; var o=no._length > 0 ? no[--no._length] :(new SaveMark()); o._saveuse=0; o._preSaveMark=context._saveMark; context._saveMark=o; return o; } __static(SaveMark, ['_no',function(){return this._no=SaveBase._createArray();} ]); return SaveMark; })() //class laya.webgl.canvas.save.SaveTransform var SaveTransform=(function(){ function SaveTransform(){ //this._savematrix=null; this._matrix=new Matrix(); } __class(SaveTransform,'laya.webgl.canvas.save.SaveTransform'); var __proto=SaveTransform.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){return false;} __proto.restore=function(context){ context._curMat=this._savematrix; SaveTransform._no[SaveTransform._no._length++]=this; } SaveTransform.save=function(context){ var _saveMark=context._saveMark; if ((_saveMark._saveuse & /*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)===/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800)return; _saveMark._saveuse |=/*laya.webgl.canvas.save.SaveBase.TYPE_TRANSFORM*/0x800; var no=SaveTransform._no; var o=no._length > 0 ? no[--no._length] :(new SaveTransform()); o._savematrix=context._curMat; context._curMat=context._curMat.copyTo(o._matrix); var _save=context._save; _save[_save._length++]=o; } __static(SaveTransform, ['_no',function(){return this._no=SaveBase._createArray();} ]); return SaveTransform; })() //class laya.webgl.canvas.save.SaveTranslate var SaveTranslate=(function(){ function SaveTranslate(){ //this._x=NaN; //this._y=NaN; } __class(SaveTranslate,'laya.webgl.canvas.save.SaveTranslate'); var __proto=SaveTranslate.prototype; Laya.imps(__proto,{"laya.webgl.canvas.save.ISaveData":true}) __proto.isSaveMark=function(){return false;} __proto.restore=function(context){ var mat=context._curMat; context._x=this._x; context._y=this._y; SaveTranslate._no[SaveTranslate._no._length++]=this; } SaveTranslate.save=function(context){ var no=SaveTranslate._no; var o=no._length > 0 ? no[--no._length] :(new SaveTranslate()); o._x=context._x; o._y=context._y; var _save=context._save; _save[_save._length++]=o; } __static(SaveTranslate, ['_no',function(){return this._no=SaveBase._createArray();} ]); return SaveTranslate; })() //class laya.webgl.resource.RenderTargetMAX var RenderTargetMAX=(function(){ function RenderTargetMAX(){ //public var targets:Vector.<OneTarget>;//没用到 this.target=null; this.repaint=false; this._width=NaN; this._height=NaN; this._sp=null; this._clipRect=new Rectangle(); } __class(RenderTargetMAX,'laya.webgl.resource.RenderTargetMAX'); var __proto=RenderTargetMAX.prototype; __proto.setSP=function(sp){ this._sp=sp; } __proto.size=function(w,h){ var _$this=this; if (this._width===w && this._height===h){ this.target.size(w,h); return; } this.repaint=true; this._width=w; this._height=h; if (!this.target) this.target=RenderTarget2D.create(w,h); else this.target.size(w,h); if (!this.target.hasListener(/*laya.events.Event.RECOVERED*/"recovered")){ this.target.on(/*laya.events.Event.RECOVERED*/"recovered",this,function(e){ Laya.timer.callLater(_$this._sp,_$this._sp.repaint); }); } } __proto._flushToTarget=function(context,target){ if (target._destroy)return; var worldScissorTest=RenderState2D.worldScissorTest; var preworldClipRect=RenderState2D.worldClipRect; RenderState2D.worldClipRect=this._clipRect; this._clipRect.x=this._clipRect.y=0; this._clipRect.width=this._width; this._clipRect.height=this._height; RenderState2D.worldScissorTest=false; WebGL.mainContext.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11); var preAlpha=RenderState2D.worldAlpha; var preMatrix4=RenderState2D.worldMatrix4; var preMatrix=RenderState2D.worldMatrix; var preFilters=RenderState2D.worldFilters; var preShaderDefines=RenderState2D.worldShaderDefines; RenderState2D.worldMatrix=Matrix.EMPTY; RenderState2D.restoreTempArray(); RenderState2D.worldMatrix4=RenderState2D.TEMPMAT4_ARRAY; RenderState2D.worldAlpha=1; RenderState2D.worldFilters=null; RenderState2D.worldShaderDefines=null; BaseShader.activeShader=null; target.start(); Config.showCanvasMark ? target.clear(0,1,0,0.3):target.clear(0,0,0,0); context.flush(); target.end(); BaseShader.activeShader=null; RenderState2D.worldAlpha=preAlpha; RenderState2D.worldMatrix4=preMatrix4; RenderState2D.worldMatrix=preMatrix; RenderState2D.worldFilters=preFilters; RenderState2D.worldShaderDefines=preShaderDefines; RenderState2D.worldScissorTest=worldScissorTest if (worldScissorTest){ var y=RenderState2D.height-preworldClipRect.y-preworldClipRect.height; WebGL.mainContext.scissor(preworldClipRect.x,y,preworldClipRect.width,preworldClipRect.height); WebGL.mainContext.enable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11); } RenderState2D.worldClipRect=preworldClipRect; } __proto.flush=function(context){ if (this.repaint){ this._flushToTarget(context,this.target); this.repaint=false; } } __proto.drawTo=function(context,x,y,width,height){ context.drawTexture(this.target.getTexture(),x,y,width,height,0,0); } __proto.destroy=function(){ if (this.target){ this.target.destroy(); this.target=null; this._sp=null; } } return RenderTargetMAX; })() //class laya.webgl.shader.d2.Shader2D var Shader2D=(function(){ function Shader2D(){ this.ALPHA=1; //this.glTexture=null; //this.shader=null; //this.filters=null; this.shaderType=0; //this.colorAdd=null; //this.strokeStyle=null; //this.fillStyle=null; this.defines=new ShaderDefines2D(); } __class(Shader2D,'laya.webgl.shader.d2.Shader2D'); var __proto=Shader2D.prototype; __proto.destroy=function(){ this.defines=null; this.filters=null; this.glTexture=null; this.strokeStyle=null; this.fillStyle=null; } Shader2D.__init__=function(){ Shader.addInclude("parts/ColorFilter_ps_uniform.glsl","uniform vec4 colorAlpha;\nuniform mat4 colorMat;"); Shader.addInclude("parts/ColorFilter_ps_logic.glsl","mat4 alphaMat =colorMat;\n\nalphaMat[0][3] *= gl_FragColor.a;\nalphaMat[1][3] *= gl_FragColor.a;\nalphaMat[2][3] *= gl_FragColor.a;\n\ngl_FragColor = gl_FragColor * alphaMat;\ngl_FragColor += colorAlpha/255.0*gl_FragColor.a;\n"); Shader.addInclude("parts/GlowFilter_ps_uniform.glsl","uniform vec4 u_color;\nuniform float u_strength;\nuniform float u_blurX;\nuniform float u_blurY;\nuniform float u_offsetX;\nuniform float u_offsetY;\nuniform float u_textW;\nuniform float u_textH;"); Shader.addInclude("parts/GlowFilter_ps_logic.glsl","const float c_IterationTime = 10.0;\nfloat floatIterationTotalTime = c_IterationTime * c_IterationTime;\nvec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\nvec2 vec2FilterDir = vec2(-(u_offsetX)/u_textW,-(u_offsetY)/u_textH);\nvec2 vec2FilterOff = vec2(u_blurX/u_textW/c_IterationTime * 2.0,u_blurY/u_textH/c_IterationTime * 2.0);\nfloat maxNum = u_blurX * u_blurY;\nvec2 vec2Off = vec2(0.0,0.0);\nfloat floatOff = c_IterationTime/2.0;\nfor(float i = 0.0;i<=c_IterationTime; ++i){\n for(float j = 0.0;j<=c_IterationTime; ++j){\n vec2Off = vec2(vec2FilterOff.x * (i - floatOff),vec2FilterOff.y * (j - floatOff));\n vec4Color += texture2D(texture, v_texcoord + vec2FilterDir + vec2Off)/floatIterationTotalTime;\n }\n}\ngl_FragColor = vec4(u_color.rgb,vec4Color.a * u_strength);\ngl_FragColor.rgb *= gl_FragColor.a;"); Shader.addInclude("parts/BlurFilter_ps_logic.glsl","gl_FragColor = blur();\ngl_FragColor.w*=alpha;"); Shader.addInclude("parts/BlurFilter_ps_uniform.glsl","uniform vec4 strength_sig2_2sig2_gauss1;\nuniform vec2 blurInfo;\n\n#define PI 3.141593\n\n//float sigma=strength/3.0;//3σ以外影响很小。即当σ=1的时候,半径为3\n//float sig2 = sigma*sigma;\n//float _2sig2 = 2.0*sig2;\n//return 1.0/(2*PI*sig2)*exp(-(x*x+y*y)/_2sig2)\n//float gauss1 = 1.0/(2.0*PI*sig2);\n\nfloat getGaussian(float x, float y){\n return strength_sig2_2sig2_gauss1.w*exp(-(x*x+y*y)/strength_sig2_2sig2_gauss1.z);\n}\n\nvec4 blur(){\n const float blurw = 9.0;\n vec4 vec4Color = vec4(0.0,0.0,0.0,0.0);\n vec2 halfsz=vec2(blurw,blurw)/2.0/blurInfo; \n vec2 startpos=v_texcoord-halfsz;\n vec2 ctexcoord = startpos;\n vec2 step = 1.0/blurInfo; //每个像素 \n \n for(float y = 0.0;y<=blurw; ++y){\n ctexcoord.x=startpos.x;\n for(float x = 0.0;x<=blurw; ++x){\n //TODO 纹理坐标的固定偏移应该在vs中处理\n vec4Color += texture2D(texture, ctexcoord)*getGaussian(x-blurw/2.0,y-blurw/2.0);\n ctexcoord.x+=step.x;\n }\n ctexcoord.y+=step.y;\n }\n return vec4Color;\n}"); Shader.addInclude("parts/ColorAdd_ps_uniform.glsl","uniform vec4 colorAdd;\n"); Shader.addInclude("parts/ColorAdd_ps_logic.glsl","gl_FragColor = vec4(colorAdd.rgb,colorAdd.a*gl_FragColor.a);\ngl_FragColor.xyz *= colorAdd.a;"); var vs,ps; vs="attribute vec4 position;\nattribute vec2 texcoord;\nuniform vec2 size;\n\n#ifdef WORLDMAT\nuniform mat4 mmat;\n#endif\nvarying vec2 v_texcoord;\nvoid main() {\n #ifdef WORLDMAT\n vec4 pos=mmat*position;\n gl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n #else\n gl_Position =vec4((position.x/size.x-0.5)*2.0,(0.5-position.y/size.y)*2.0,position.z,1.0);\n #endif\n \n v_texcoord = texcoord;\n}"; ps="precision mediump float;\n//precision highp float;\nvarying vec2 v_texcoord;\nuniform sampler2D texture;\nuniform float alpha;\n#include?BLUR_FILTER \"parts/BlurFilter_ps_uniform.glsl\";\n#include?COLOR_FILTER \"parts/ColorFilter_ps_uniform.glsl\";\n#include?GLOW_FILTER \"parts/GlowFilter_ps_uniform.glsl\";\n#include?COLOR_ADD \"parts/ColorAdd_ps_uniform.glsl\";\n\nvoid main() {\n vec4 color= texture2D(texture, v_texcoord);\n color.a*=alpha;\n color.rgb*=alpha;\n gl_FragColor=color;\n #include?COLOR_ADD \"parts/ColorAdd_ps_logic.glsl\"; \n #include?BLUR_FILTER \"parts/BlurFilter_ps_logic.glsl\";\n #include?COLOR_FILTER \"parts/ColorFilter_ps_logic.glsl\";\n #include?GLOW_FILTER \"parts/GlowFilter_ps_logic.glsl\";\n}"; Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.TEXTURE2D*/0x01,vs,ps,null); vs="attribute vec4 position;\nuniform vec2 size;\nuniform mat4 mmat;\nvoid main() {\n vec4 pos=mmat*position;\n gl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n}"; ps="precision mediump float;\nuniform vec4 color;\nuniform float alpha;\n#include?COLOR_FILTER \"parts/ColorFilter_ps_uniform.glsl\";\nvoid main() {\n vec4 a = vec4(color.r, color.g, color.b, color.a);\n a.w = alpha;\n a.xyz *= alpha;\n gl_FragColor = a;\n #include?COLOR_FILTER \"parts/ColorFilter_ps_logic.glsl\";\n}"; Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.COLOR2D*/0x02,vs,ps,null); vs="attribute vec4 position;\nattribute vec3 a_color;\nuniform mat4 mmat;\nuniform mat4 u_mmat2;\nuniform vec2 u_pos;\nuniform vec2 size;\nvarying vec3 color;\nvoid main(){\n vec4 tPos = vec4(position.x + u_pos.x,position.y + u_pos.y,position.z,position.w);\n vec4 pos=mmat*u_mmat2*tPos;\n gl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n color=a_color;\n}"; ps="precision mediump float;\n//precision mediump float;\nvarying vec3 color;\nuniform float alpha;\nvoid main(){\n //vec4 a=vec4(color.r, color.g, color.b, 1);\n //a.a*=alpha;\n gl_FragColor=vec4(color.r, color.g, color.b, alpha);\n gl_FragColor.rgb*=alpha;\n}"; Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.PRIMITIVE*/0x04,vs,ps,null); vs="attribute vec4 position;\nattribute vec2 texcoord;\nuniform vec2 size;\n\n#ifdef WORLDMAT\nuniform mat4 mmat;\n#endif\nvarying vec2 v_texcoord;\nvoid main() {\n #ifdef WORLDMAT\n vec4 pos=mmat*position;\n gl_Position =vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n #else\n gl_Position =vec4((position.x/size.x-0.5)*2.0,(0.5-position.y/size.y)*2.0,position.z,1.0);\n #endif\n \n v_texcoord = texcoord;\n}"; ps="#ifdef FSHIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n//precision highp float;\nvarying vec2 v_texcoord;\nuniform sampler2D texture;\nuniform float alpha;\nuniform vec4 u_TexRange;\nuniform vec2 u_offset;\n#include?BLUR_FILTER \"parts/BlurFilter_ps_uniform.glsl\";\n#include?COLOR_FILTER \"parts/ColorFilter_ps_uniform.glsl\";\n#include?GLOW_FILTER \"parts/GlowFilter_ps_uniform.glsl\";\n#include?COLOR_ADD \"parts/ColorAdd_ps_uniform.glsl\";\n\nvoid main() {\n vec2 newTexCoord;\n newTexCoord.x = mod(u_offset.x + v_texcoord.x,u_TexRange.y) + u_TexRange.x;\n newTexCoord.y = mod(u_offset.y + v_texcoord.y,u_TexRange.w) + u_TexRange.z;\n vec4 color= texture2D(texture, newTexCoord);\n color.a*=alpha;\n gl_FragColor=color;\n #include?COLOR_ADD \"parts/ColorAdd_ps_logic.glsl\"; \n #include?BLUR_FILTER \"parts/BlurFilter_ps_logic.glsl\";\n #include?COLOR_FILTER \"parts/ColorFilter_ps_logic.glsl\";\n #include?GLOW_FILTER \"parts/GlowFilter_ps_logic.glsl\";\n}"; Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.FILLTEXTURE*/0x100,vs,ps,null); vs="attribute vec2 position;\nattribute vec2 texcoord;\nattribute vec4 color;\nuniform vec2 size;\nuniform float offsetX;\nuniform float offsetY;\nuniform mat4 mmat;\nuniform mat4 u_mmat2;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\nvoid main() {\n vec4 pos=mmat*u_mmat2*vec4(offsetX+position.x,offsetY+position.y,0,1 );\n gl_Position = vec4((pos.x/size.x-0.5)*2.0,(0.5-pos.y/size.y)*2.0,pos.z,1.0);\n v_color = color;\n v_color.rgb *= v_color.a;\n v_texcoord = texcoord; \n}"; ps="precision mediump float;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\nuniform sampler2D texture;\nuniform float alpha;\nvoid main() {\n vec4 t_color = texture2D(texture, v_texcoord);\n gl_FragColor = t_color.rgba * v_color;\n gl_FragColor *= alpha;\n}"; Shader.preCompile2D(0,/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,vs,ps,null); } return Shader2D; })() //class laya.webgl.shader.ShaderDefines var ShaderDefines=(function(){ function ShaderDefines(name2int,int2name,int2nameMap){ this._value=0; //this._name2int=null; //this._int2name=null; //this._int2nameMap=null; this._name2int=name2int; this._int2name=int2name; this._int2nameMap=int2nameMap; } __class(ShaderDefines,'laya.webgl.shader.ShaderDefines'); var __proto=ShaderDefines.prototype; __proto.add=function(value){ if ((typeof value=='string'))value=this._name2int[value]; this._value |=value; return this._value; } __proto.addInt=function(value){ this._value |=value; return this._value; } __proto.remove=function(value){ if ((typeof value=='string'))value=this._name2int[value]; this._value &=(~value); return this._value; } __proto.isDefine=function(def){ return (this._value & def)===def; } __proto.getValue=function(){ return this._value; } __proto.setValue=function(value){ this._value=value; } __proto.toNameDic=function(){ var r=this._int2nameMap[this._value]; return r ? r :ShaderDefines._toText(this._value,this._int2name,this._int2nameMap); } ShaderDefines._reg=function(name,value,_name2int,_int2name){ _name2int[name]=value; _int2name[value]=name; } ShaderDefines._toText=function(value,_int2name,_int2nameMap){ var r=_int2nameMap[value]; if (r)return r; var o={}; var d=1; for (var i=0;i < 32;i++){ d=1 << i; if (d > value)break ; if (value & d){ var name=_int2name[d]; name && (o[name]=""); } } _int2nameMap[value]=o; return o; } ShaderDefines._toInt=function(names,_name2int){ var words=names.split('.'); var num=0; for (var i=0,n=words.length;i < n;i++){ var value=_name2int[words[i]]; if (!value)throw new Error("Defines to int err:"+names+"/"+words[i]); num |=value; } return num; } return ShaderDefines; })() /** *这里销毁的问题,后面待确认 */ //class laya.webgl.shader.d2.skinAnishader.SkinMesh var SkinMesh=(function(){ function SkinMesh(){ this.mVBBuffer=null; this.mIBBuffer=null; this.mVBData=null; this.mIBData=null; this.mEleNum=0; this.mTexture=null; this.transform=null; this._vs=null; this._ps=null; this._indexStart=-1; this._verticles=null; this._uvs=null; this._tempMatrix=new Matrix(); } __class(SkinMesh,'laya.webgl.shader.d2.skinAnishader.SkinMesh'); var __proto=SkinMesh.prototype; __proto.init=function(texture,vs,ps){ if (vs){ this._vs=vs; }else { this._vs=[]; var tWidth=texture.width; var tHeight=texture.height; var tRed=1; var tGreed=1; var tBlue=1; var tAlpha=1; this._vs.push(0,0,0,0,tRed,tGreed,tBlue,tAlpha); this._vs.push(tWidth,0,1,0,tRed,tGreed,tBlue,tAlpha); this._vs.push(tWidth,tHeight,1,1,tRed,tGreed,tBlue,tAlpha); this._vs.push(0,tHeight,0,1,tRed,tGreed,tBlue,tAlpha); } if (ps){ this._ps=ps; }else { if (!SkinMesh._defaultPS){ SkinMesh._defaultPS=[]; SkinMesh._defaultPS.push(0,1,3,3,1,2); } this._ps=SkinMesh._defaultPS; } this.mVBData=new Float32Array(this._vs); this.mIBData=new Uint16Array(this._ps.length); this.mIBData["start"]=-1; this.mEleNum=this._ps.length; this.mTexture=texture; } __proto.init2=function(texture,vs,ps,verticles,uvs){ if (this.transform)this.transform=null; if (ps){ this._ps=ps; }else { this._ps=[]; this._ps.push(0,1,3,3,1,2); } this._verticles=verticles; this._uvs=uvs; this.mEleNum=this._ps.length; this.mTexture=texture; if (Render.isConchNode || Render.isConchApp){ this._initMyData(); this.mVBData=new Float32Array(this._vs); } } __proto._initMyData=function(){ var vsI=0; var vI=0; var vLen=this._verticles.length; var tempVLen=vLen *4; this._vs=SkinMesh._tempVS; var insertNew=false; if (Render.isConchNode || Render.isConchApp){ this._vs.length=tempVLen; insertNew=true; }else{ if (this._vs.length < tempVLen){ this._vs.length=tempVLen; insertNew=true; } } SkinMesh._tVSLen=tempVLen; if (insertNew){ while (vsI < tempVLen){ this._vs[vsI]=this._verticles[vI]; this._vs[vsI+1]=this._verticles[vI+1]; this._vs[vsI+2]=this._uvs[vI]; this._vs[vsI+3]=this._uvs[vI+1]; this._vs[vsI+4]=1; this._vs[vsI+5]=1; this._vs[vsI+6]=1; this._vs[vsI+7]=1; vsI+=8; vI+=2; } }else{ while (vsI < tempVLen){ this._vs[vsI]=this._verticles[vI]; this._vs[vsI+1]=this._verticles[vI+1]; this._vs[vsI+2]=this._uvs[vI]; this._vs[vsI+3]=this._uvs[vI+1]; vsI+=8; vI+=2; } } } __proto.getData2=function(vb,ib,start){ this.mVBBuffer=vb; this.mIBBuffer=ib; this._initMyData(); vb.appendEx2(this._vs,Float32Array,SkinMesh._tVSLen,4); this._indexStart=ib._byteLength; var tIB; tIB=SkinMesh._tempIB; if (tIB.length < this._ps.length){ tIB.length=this._ps.length; } for (var i=0,n=this._ps.length;i < n;i++){ tIB[i]=this._ps[i]+start; } ib.appendEx2(tIB,Uint16Array,this._ps.length,2); } __proto.getData=function(vb,ib,start){ this.mVBBuffer=vb; this.mIBBuffer=ib; vb.append(this.mVBData); this._indexStart=ib._byteLength; if (this.mIBData["start"] !=start){ for (var i=0,n=this._ps.length;i < n;i++){ this.mIBData[i]=this._ps[i]+start; } this.mIBData["start"]=start; } ib.append(this.mIBData); } __proto.render=function(context,x,y){ if (Render.isWebGL && this.mTexture){ context._renderKey=0; context._shader2D.glTexture=null; SkinMeshBuffer.getInstance().addSkinMesh(this); var tempSubmit=Submit.createShape(context,this.mIBBuffer,this.mVBBuffer,this.mEleNum,this._indexStart,Value2D.create(/*laya.webgl.shader.d2.ShaderDefines2D.SKINMESH*/0x200,0)); this.transform || (this.transform=Matrix.EMPTY); this.transform.translate(x,y); Matrix.mul(this.transform,context._curMat,this._tempMatrix); this.transform.translate(-x,-y); var tShaderValue=tempSubmit.shaderValue; var tArray=tShaderValue.u_mmat2||RenderState2D.getMatrArray(); RenderState2D.mat2MatArray(this._tempMatrix,tArray); tShaderValue.textureHost=this.mTexture; tShaderValue.offsetX=0; tShaderValue.offsetY=0; tShaderValue.u_mmat2=tArray; tShaderValue.ALPHA=context._shader2D.ALPHA; context._submits[context._submits._length++]=tempSubmit; } else if (Render.isConchApp&&this.mTexture){ this.transform || (this.transform=Matrix.EMPTY); context.setSkinMesh&&context.setSkinMesh(x,y,this._ps,this.mVBData,this.mEleNum,0,this.mTexture,this.transform); } } SkinMesh._tempVS=[]; SkinMesh._tempIB=[]; SkinMesh._defaultPS=null; SkinMesh._tVSLen=0; return SkinMesh; })() //class laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer var SkinMeshBuffer=(function(){ function SkinMeshBuffer(){ this.ib=null; this.vb=null; var gl=WebGL.mainContext; this.ib=IndexBuffer2D.create(/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8); this.vb=VertexBuffer2D.create(8); } __class(SkinMeshBuffer,'laya.webgl.shader.d2.skinAnishader.SkinMeshBuffer'); var __proto=SkinMeshBuffer.prototype; __proto.addSkinMesh=function(skinMesh){ skinMesh.getData2(this.vb,this.ib,this.vb._byteLength / 32); } __proto.reset=function(){ this.vb.clear(); this.ib.clear(); } SkinMeshBuffer.getInstance=function(){ return SkinMeshBuffer.instance=SkinMeshBuffer.instance|| new SkinMeshBuffer(); } SkinMeshBuffer.instance=null; return SkinMeshBuffer; })() //此类可以减少代码 //class laya.webgl.shapes.BasePoly var BasePoly=(function(){ function BasePoly(x,y,width,height,edges,color,borderWidth,borderColor,round){ //this.x=NaN; //this.y=NaN; //this.r=NaN; //this.width=NaN; //this.height=NaN; //this.edges=NaN; this.r0=0 //this.color=0; //this.borderColor=NaN; //this.borderWidth=NaN; //this.round=0; this.fill=true; //this.mUint16Array=null; //this.mFloat32Array=null; this.r1=Math.PI / 2; (round===void 0)&& (round=0); this.x=x; this.y=y; this.width=width; this.height=height; this.edges=edges; this.color=color; this.borderWidth=borderWidth; this.borderColor=borderColor; } __class(BasePoly,'laya.webgl.shapes.BasePoly'); var __proto=BasePoly.