public static void Start(uint width, uint height, Type rootType) { GPUInfo.PrintGPUInfo(); #if DEBUG OpenGLDebugCallback.Init(); #endif if (rootType == null) { throw new InvalidOperationException("Root cannot be null!"); } if (Root != null) { throw new InvalidOperationException("App already initialized!"); } RenderSupport.HasOpenGLError = false; Stage = new Stage(width, height); DefaultJuggler = new Juggler(); Context = new Context(); renderSupport = new RenderSupport(); Root = (DisplayObject)Activator.CreateInstance(rootType); Stage.AddChild(Root); }
private void CalcBounds(DisplayObject obj, Stage stage, float scale, bool intersectWithStage, out Rectangle bounds, out Rectangle boundsPOT) { float marginX; float marginY; // optimize for full-screen effects if (obj == stage || obj == SparrowSharpApp.Root) { marginX = marginY = 0; bounds = new Rectangle(0, 0, stage.Width, stage.Height); } else { marginX = MarginX; marginY = MarginY; bounds = obj.BoundsInSpace(stage); } if (intersectWithStage) bounds = bounds.Intersection(stage.Bounds); boundsPOT = null; Rectangle result = bounds; if (!result.IsEmpty()) { // the bounds are a rectangle around the object, in stage coordinates, // and with an optional margin. bounds.Inflate(marginX, marginY); // To fit into a POT-texture, we extend it towards the right and bottom. int minSize = (int)(MIN_TEXTURE_SIZE / scale); float minWidth = result.Width > minSize ? result.Width : minSize; float minHeight = result.Height > minSize ? result.Height : minSize; boundsPOT = new Rectangle(result.X, result.Top, NumberUtil.NextPowerOfTwo(minWidth * scale) / scale, NumberUtil.NextPowerOfTwo(minHeight * scale) / scale); } }