Пример #1
0
 public static void uploadBitmapData(bc.flash.display3D.textures.AsTexture nativeTexture, AsBitmapData data, bool generateMipmaps)
 {
     nativeTexture.uploadFromBitmapData(data);
     if (generateMipmaps && data.getWidth() > 1 && data.getHeight() > 1)
     {
         int          currentWidth  = data.getWidth() >> 1;
         int          currentHeight = data.getHeight() >> 1;
         int          level         = 1;
         AsBitmapData canvas        = new AsBitmapData(currentWidth, currentHeight, true, 0);
         AsMatrix     transform     = new AsMatrix(.5f, 0, 0, .5f);
         AsRectangle  bounds        = new AsRectangle();
         while (currentWidth >= 1 || currentHeight >= 1)
         {
             bounds.width  = currentWidth;
             bounds.height = currentHeight;
             canvas.fillRect(bounds, (uint)(0));
             canvas.draw(data, transform, null, null, null, true);
             nativeTexture.uploadFromBitmapData(canvas, (uint)(level++));
             transform.scale(0.5f, 0.5f);
             currentWidth  = currentWidth >> 1;
             currentHeight = currentHeight >> 1;
         }
         canvas.dispose();
     }
 }
Пример #2
0
        public static AsTexture empty(int width, int height, bool premultipliedAlpha, bool optimizeForRenderTexture, float scale)
        {
            if (scale <= 0)
            {
                scale = AsStarling.getContentScaleFactor();
            }
            int         origWidth   = (int)(width * scale);
            int         origHeight  = (int)(height * scale);
            int         legalWidth  = AsGlobal.getNextPowerOfTwo(origWidth);
            int         legalHeight = AsGlobal.getNextPowerOfTwo(origHeight);
            String      format      = AsContext3DTextureFormat.BGRA;
            AsContext3D context     = AsStarling.getContext();

            if (context == null)
            {
                throw new AsMissingContextError();
            }
            bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture);
            AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, format, legalWidth, legalHeight, false, premultipliedAlpha, optimizeForRenderTexture, scale);

            if (origWidth == legalWidth && origHeight == legalHeight)
            {
                return(concreteTexture);
            }
            else
            {
                return(new AsSubTexture(concreteTexture, new AsRectangle(0, 0, width, height), true));
            }
        }
Пример #3
0
        public static AsTexture fromBitmapData(AsBitmapData data, bool generateMipMaps, bool optimizeForRenderTexture, float scale)
        {
            int          origWidth   = data.getWidth();
            int          origHeight  = data.getHeight();
            int          legalWidth  = AsGlobal.getNextPowerOfTwo(origWidth);
            int          legalHeight = AsGlobal.getNextPowerOfTwo(origHeight);
            AsContext3D  context     = AsStarling.getContext();
            AsBitmapData potData     = null;

            if (context == null)
            {
                throw new AsMissingContextError();
            }
            bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture);
            if (legalWidth > origWidth || legalHeight > origHeight)
            {
                potData = new AsBitmapData(legalWidth, legalHeight, true, 0);
                potData.copyPixels(data, data.getRect(), sOrigin);
                data = potData;
            }
            uploadBitmapData(nativeTexture, data, generateMipMaps);
            AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, AsContext3DTextureFormat.BGRA, legalWidth, legalHeight, generateMipMaps, true, optimizeForRenderTexture, scale);

            if (AsStarling.getHandleLostContext())
            {
                concreteTexture.restoreOnLostContext(data);
            }
            else
            {
                if (potData != null)
                {
                    potData.dispose();
                }
            }
            if (origWidth == legalWidth && origHeight == legalHeight)
            {
                return(concreteTexture);
            }
            else
            {
                return(new AsSubTexture(concreteTexture, new AsRectangle(0, 0, origWidth / scale, origHeight / scale), true));
            }
        }
Пример #4
0
        public static AsTexture fromAtfData(AsByteArray data, float scale)
        {
            AsContext3D context = AsStarling.getContext();

            if (context == null)
            {
                throw new AsMissingContextError();
            }
            AsAtfData atfData = new AsAtfData(data);

            bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(atfData.getWidth(), atfData.getHeight(), atfData.getFormat(), false);
            uploadAtfData(nativeTexture, data);
            AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, atfData.getFormat(), atfData.getWidth(), atfData.getHeight(), atfData.getNumTextures() > 1, false, false, scale);

            if (AsStarling.getHandleLostContext())
            {
                concreteTexture.restoreOnLostContext(atfData);
            }
            return(concreteTexture);
        }
        private void onContextCreated(AsEvent _event)
        {
            AsContext3D  context    = AsStarling.getContext();
            AsBitmapData bitmapData = mData as AsBitmapData;
            AsAtfData    atfData    = mData as AsAtfData;

            bc.flash.display3D.textures.AsTexture nativeTexture = null;
            if (bitmapData != null)
            {
                nativeTexture = context.createTexture(mWidth, mHeight, AsContext3DTextureFormat.BGRA, mOptimizedForRenderTexture);
                AsTexture.uploadBitmapData(nativeTexture, bitmapData, mMipMapping);
            }
            else
            {
                if (atfData != null)
                {
                    nativeTexture = context.createTexture(atfData.getWidth(), atfData.getHeight(), atfData.getFormat(), mOptimizedForRenderTexture);
                    AsTexture.uploadAtfData(nativeTexture, atfData.getData());
                }
            }
            mBase = nativeTexture;
        }
Пример #6
0
 public static void uploadAtfData(bc.flash.display3D.textures.AsTexture nativeTexture, AsByteArray data)
 {
     uploadAtfData(nativeTexture, data, 0);
 }
Пример #7
0
 public static void uploadAtfData(bc.flash.display3D.textures.AsTexture nativeTexture, AsByteArray data, int offset)
 {
     nativeTexture.uploadCompressedTextureFromByteArray(data, (uint)(offset));
 }