Example #1
0
 // Assign this data to an orthographic camera.
 public void AssignTo(Camera cam)
 {
     // Move the camera to the new 2D position without modifying the camera z position.
     cam.transform.position = Swizzle.Vec3(position, "xy_", cam.transform.position);
     cam.orthographicSize   = orthographicSize;
     cam.aspect             = aspect;
 }
        public static void Initialize()
        {
            var args = NSProcessInfo.ProcessInfo.Arguments;

            if (args.Contains("-doNotThrowOnInitFailure"))
            {
                ObjCRuntime.Class.ThrowOnInitFailure = false;
            }

            // Troubleshooting NSUrl crashes
            if (args.Contains("-wrapNSUrlInitWithString"))
            {
                urlSwizzle = new Swizzle <InitWithStringDelegate>(new Class("NSURL"), Selector.GetHandle("initWithString:"), NSUrlInitWithString);
            }
            //urlSwizzle = new Swizzle<InitWithStringDelegate>(typeof(NSUrl), "initWithString:", NSUrlInitWithString);

            if (args.Contains("-wrapNSDictionaryInitWithObjectsForKeysCount"))
            {
                initDictSwizzle = new Swizzle <InitDictWithObjectsForKeysCountDelegate>(typeof(NSDictionary), "dictionaryWithObjects:forKeys:count:", InitDictWithObjectsForKeysCount, true);
            }

            //-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:] + 53
            if (args.Contains("-wrapConnectionWillSendRequestRedirectResponse"))
            {
                connectionSwizzle = new Swizzle <ConnectionWillSendRequestRedirectResponseDelegate>(new Class("WebCoreResourceHandleAsOperationQueueDelegate"), Selector.GetHandle("connection:willSendRequest:redirectResponse:"), ConnectionWillSendRequestRedirectResponse);
            }
        }
Example #3
0
        private static string MaskVector(Swizzle[] swizzle, string[] mask)
        {
            Contract.Requires <ArgumentNullException>(swizzle != null);
            Contract.Requires <ArgumentException>(swizzle.Length > 0);
            Contract.Requires <ArgumentNullException>(mask != null);
            string s = string.Empty;

            for (int i = 0; i < swizzle.Length; i++)
            {
                Swizzle component = swizzle[i];
                if (component != Swizzle.Null)
                {
                    s += component.ToString().ToLowerInvariant();
                    if (i + 1 < swizzle.Length - 2 && swizzle[i + 1] == Swizzle.Null)
                    {
                        s += ", ";
                    }
                }
                else
                {
                    if (i > 0)
                    {
                        s += ", ";
                    }
                    s += mask[i];
                }
            }

            return(s);
        }
Example #4
0
        public static dynamic Swizzle(this Vect2f v)
        {
            var s = new Swizzle <float>();

            s.Add('X', v.X);
            s.Add('Y', v.Y);
            return(s);
        }
Example #5
0
        public static dynamic Swizzle(this Vect3 v)
        {
            var s = new Swizzle <double>();

            s.Add('X', v.X);
            s.Add('Y', v.Y);
            s.Add('Z', v.Z);
            return(s);
        }
Example #6
0
        public virtual void WriteSwizzle(Swizzle s, ExpressionUsage u)
        {
            WriteMemberBase(s.Object);

            foreach (var f in s.Fields)
            {
                WriteName(f);
            }
        }
 public static NSApplication CreateShared()
 {
     if (instance == null)
     {
         instance = CreateFromInfoPlist() ?? new MonoApplication(New(typeof(MonoApplication)));
         shared   = new Swizzle <CreateSharedApplicationDelegate>(typeof(NSApplication), "sharedApplication", GetSharedApplication, true);
     }
     return(instance);
 }
Example #8
0
        void SwizzleDict()
        {
            var selName = "initWithObjects:forKeys:";

            using (swizzle = new Swizzle <NativeEventHandler>(typeof(NSDictionary), selName, HijackedInitWithObjectsForKeys))
            {
                var type = typeof(NSDictionary);
                var d    = new NSDictionary((NSString)"key1", (NSString)"obj1", (NSString)"key2", (NSString)"obj2");
            }
        }
Example #9
0
        private IImageSwizzle GetSwizzle()
        {
            if (Swizzle == null)
            {
                return(null);
            }

            var props       = Swizzle.GetType().GetProperties();
            var swizzleProp = props.FirstOrDefault(x => x.PropertyType == typeof(IImageSwizzle));

            return((IImageSwizzle)swizzleProp?.GetValue(Swizzle));
        }
Example #10
0
        public void InPlaceConstruction <T, TProperty>(T t1, T t2, Expression <Func <T, TProperty> > getXExpr, Expression <Func <T, TProperty> > getYExpr, TProperty x, TProperty y)
        {
            var t2_xy = new Swizzle <T, TProperty>(t2, getXExpr, getYExpr);
            var t1_yx = new Swizzle <T, TProperty>(t1, getYExpr, getXExpr);

            t2 = t2_xy.Set(t1_yx);

            Func <T, TProperty> getX = getXExpr.Compile();
            Func <T, TProperty> getY = getYExpr.Compile();

            AssertHelper(getX(t1), getY(t1), getX(t2), getY(t2), x, y);
        }
Example #11
0
        void SwizzleCls()
        {
            var selName = "dictionaryWithObjects:forKeys:count:";

            using (swizzleCls = new Swizzle <NativeEventHandlerCls>(typeof(NSDictionary), selName, HijackedDictionaryWithObjectsForKeysCount, true))
            {
                var classHandle    = Class.GetHandle(typeof(NSDictionary));
                var keys           = IntPtr.Zero;
                var objects        = IntPtr.Zero;
                var sel            = new Selector(selName);
                var instanceHandle = MacApi.LibObjc.IntPtr_objc_msgSend_IntPtr_IntPtr_Int32(classHandle, sel.Handle, IntPtr.Zero, IntPtr.Zero, 0);
            }
        }
Example #12
0
        public static byte[] DecodeTexture(this ITexture texture)
        {
            byte[] decoded = null;

            switch (texture.Format)
            {
            case TextureFormat.BC1 when texture is Xbx.Textures.MtxtTexture tex:
                Xbx.Textures.Swizzle.Deswizzle(tex, 6);
                decoded = Dxt.DecompressDxt1(texture);
                break;

            case TextureFormat.BC1:
                Swizzle.Deswizzle(texture, 3);
                decoded = Dxt.DecompressDxt1(texture);
                break;

            case TextureFormat.BC3 when texture is Xbx.Textures.MtxtTexture tex:
                Xbx.Textures.Swizzle.Deswizzle(tex, 7);
                decoded = Dxt.DecompressDxt5(texture);
                break;

            case TextureFormat.BC3:
                Swizzle.Deswizzle(texture, 4);
                decoded = Dxt.DecompressDxt5(texture);
                break;

            case TextureFormat.BC4:
                Swizzle.Deswizzle(texture, 3);
                decoded = Dxt.DecompressDxt4(texture);
                break;

            case TextureFormat.BC6H_UF16:
                Swizzle.Deswizzle(texture, 4);
                decoded = Dxt.DecompressBc6(texture);
                break;

            case TextureFormat.BC7:
                Swizzle.Deswizzle(texture, 4);
                decoded = Dxt.DecompressBc7(texture);
                break;

            case TextureFormat.R8G8B8A8_UNORM:
                Swizzle.Deswizzle(texture, 4, 1);
                decoded = texture.Data;
                break;
            }

            return(decoded);
        }
        public static DDSEncoderResult EncodeTex(DDSLoadResult img)
        {
            var numMips   = 1;
            var alignment = 512;

            var fmt = EncoderTable[img.Format];

            var blockHeight         = Utils.getBlockHeight(Utils.DIV_ROUND_UP(img.height, fmt.blkHeight));
            var blockHeightLog2     = Utils.Log2(blockHeight);
            var linesPerBlockHeight = blockHeight * 8;

            var surfSize         = 0;
            var blockHeightShift = 0;

            List <int>  mipOfsets = new List <int>();
            List <byte> res       = new List <byte>();

            for (int mipLevel = 0; mipLevel < numMips; mipLevel++)
            {
                var    offSize = getCurrentMipOffset_Size(img.width, img.height, fmt.blkWidth, fmt.blkHeight, fmt.bpp, mipLevel);
                byte[] data    = new byte[offSize.Item2];
                Array.Copy(img.data, offSize.Item1, data, 0, offSize.Item2);
                var width_         = Math.Max(1, img.width >> mipLevel);
                var height_        = Math.Max(1, img.height >> mipLevel);
                var width__        = Utils.DIV_ROUND_UP(width_, fmt.blkWidth);
                var height__       = Utils.DIV_ROUND_UP(height_, fmt.blkHeight);
                int dataAlignBytes = Utils.round_up(surfSize, alignment) - surfSize;
                surfSize += dataAlignBytes;
                mipOfsets.Add(surfSize);
                if (Utils.pow2_round_up(height__) < linesPerBlockHeight)
                {
                    blockHeightShift += 1;
                }
                var pitch = Utils.round_up(width__ * fmt.bpp, 64);
                surfSize += pitch * Utils.round_up(height__, Math.Max(1, blockHeight >> blockHeightShift) * 8);

                if (dataAlignBytes != 0)
                {
                    res.AddRange(new byte[dataAlignBytes]);
                }
                res.AddRange(Swizzle.swizzle(width_, height_, fmt.blkWidth, fmt.blkHeight, true, fmt.bpp, 0, Math.Max(0, blockHeightLog2 - blockHeightShift), data, true));
            }

            return(new DDSEncoderResult {
                Data = res.ToArray(), blockHeightLog2 = blockHeightLog2, format = fmt
            });
        }
Example #14
0
        public static Expression TransformSwizzleToNewObject(this Swizzle s, Namescope scope)
        {
            // a.XYZ -> (temp = a, new T(temp.X, temp.Y, temp.Z))
            //   OR     new T(a.X, a.Y, a.Z)

            var obj = s.Object;
            var ind = TryCreateIndirection(scope, ref obj);

            var args = new Expression[s.Fields.Length];

            for (int i = 0; i < s.Fields.Length; i++)
            {
                args[i] = new LoadField(s.Source, obj, s.Fields[i]);
            }

            var result = new NewObject(s.Source, s.Constructor, args);

            return(ind != null
                ? (Expression) new SequenceOp(ind, result)
                :              result);
        }
Example #15
0
 public static Vector2 Swizzle2(this Vector4 input, Swizzle swizzle) {
     float[] data = Swizzle(new float[] { input.x, input.y, input.z, input.w }, TranslateCommonSwizzle(swizzle));
     return new Vector2(data[0], data[1]);
 }
Example #16
0
 public static Vector3 Swizzle3(this Vector2 input, Swizzle swizzle) {
     float[] data = Swizzle(new float[] { input.x, input.y }, TranslateCommonSwizzle(swizzle));
     return new Vector3(data[0], data[1], data[2]);
 }
Example #17
0
 public void             Read(BinaryReader _R)
 {
     m_layout  = (Layout)_R.ReadUInt32();
     m_type    = (Type)_R.ReadUInt32();
     m_swizzle = (Swizzle)_R.ReadUInt32();
 }
Example #18
0
 public static Vector4 Swizzle4(this Vector3 input, Swizzle swizzle) {
     float[] data = Swizzle(new float[] { input.x, input.y, input.z }, TranslateCommonSwizzle(swizzle));
     return new Vector4(data[0], data[1], data[2], data[3]);
 }
Example #19
0
 private static string TranslateCommonSwizzle(Swizzle swizzle) {
     return _commonSwizzles[(int)swizzle];
 }
Example #20
0
 /// <inheritdoc cref="IImageSwizzle.Get(Point)"/>
 public Point Get(Point point) => Swizzle.Get(point.Y * Width + point.X);
Example #21
0
 public void Read( BinaryReader _R )
 {
     m_layout = (Layout) _R.ReadUInt32();
     m_type = (Type) _R.ReadUInt32();
     m_swizzle = (Swizzle) _R.ReadUInt32();
 }
Example #22
0
 /// <inheritdoc />
 public Point Transform(Point point) => Swizzle.Get(point.Y * Width + point.X);