Stage3d 中的DeviceLost(设备丢失)处理方案

/* @author Jave.Lin
    @date 2016-09-10
*/

IDeviceRes
{
  function onRestore(newDevice:Context3D):void;
}

GameVertexBufferRes : IDeviceRes
{
  perVertexNum:int;
  rawData:Vector.<Number>;
  vertexBuff:VertexBuffer3D;
  function onRestore(newDevice:Context3D):void
  {
    vertexBuff.dispose();
    vertexBuff = newDevice.createVertexBuffer(rawData.length, perVertexNum);
    vertexBuff.upload(rawData);
  }
}

GameIndexBufferRes : IDeviceRes
{
  rawData:Vector.<int>;
  indexBuff:IndexBuffer3D;
  function onRestore(newDevice:Context3D):void
  {
    indexBuffer.dispose();
    indexBuffer = newDevice.createIndexBuffer(rawData.length);
    indexBuffer.upload(rawData);
  }
}

GameTextureRes : IDeviceRes
{
  width:Number, height:Number,
  format:String, optmizForRT:Boolean;
  tex:TextureBase;
  texType:EnumTexture; // @see EnumTexType
  rawData:Object;
  function onRestore(newDevice:Context3D):void
  {
    tex.dispose();
    tex = newDevice.createTexture(width, height, format, optmizForRT);
    switch (texType)
    {
      case EnumTexType.ATF:
      tex.uploadByATF(rawData as ByteArray);
      break;
      case EnumTexType.URL_PICS:
      ResMgr.getRes(rawData as String, function(bmd:BitmapData):void
      {
        tex.uploadByBmd(bmd);
      });
      break;
      case EnumTexType.TEMP:
      text.uploadByBmd(rawData as BitmapData);
      break;
    }
  }
}

EnumTexType
{
  ATF, // Adobe texture format
  URL_PICS, // url pics : jpg/png/bmp/dds/wds, etc.
  TEMP // new BitmapData upload
}

Game
{
 renderRes:Dictionary = new Dictionary();

 function addRenderRes(dr:IDeviceRes):void
 {
   renderRes[dr] = true;
 }

 functin onDeviceLostEvent(e:Event):void
 {
   var newDevice:Context3D = ...;
   for (var dr:IDeviceRes in renderRes)
   {
     dr.onRestore(newDevice);
   }
 }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值