private void ApplyBlendMode() { string blendMode = _state.BlendMode; if (blendMode != _actualBlendMode) { BlendMode.Get(_state.BlendMode).Activate(); _actualBlendMode = blendMode; } }
/// <summary> /// Start your app. /// </summary> /// <param name="width">Stage width</param> /// <param name="height">Stage height</param> /// <param name="viewportHeight"></param> /// <param name="viewportWidth"></param> /// <param name="rootType">The root class of your app</param> /// <exception cref="InvalidOperationException">When rootType is null or this function is called twice</exception> /// <exception cref="NotSupportedException">When the OpenGL framebuffer creation fails.</exception> /// <exception cref="ArgumentException">When width or height are less than 32.</exception> public static void Start(uint width, uint height, uint viewportWidth, uint viewportHeight, Type rootType) { Debug.WriteLine("Sparrow starting"); if (width < 32 || height < 32 || viewportWidth < 32 || viewportHeight < 32) { throw new ArgumentException($"Invalid dimensions: {width}x{height}"); } var ver = Gl.CurrentVersion; if (ver.Api == "gl") { if (ver.Major < 4) { throw new NotSupportedException("You need at least OpenGL 4.0 to run Sparrow!"); } } else { if (ver.Major < 3) { throw new NotSupportedException("You need at least OpenGL ES 3.0 to run Sparrow!"); } IsRunningOpenGLES = true; } Gl.Disable(EnableCap.CullFace); Gl.Disable(EnableCap.Dither); Gl.Enable(EnableCap.DepthTest); Gl.DepthFunc(DepthFunction.Always); BlendMode.Get(BlendMode.NORMAL).Activate(); FramebufferStatus status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if (status != FramebufferStatus.FramebufferComplete) { throw new NotSupportedException("GL Framebuffer creation error. Status: " + status); } _viewPort = Rectangle.Create(0, 0, viewportWidth, viewportHeight); _previousViewPort = Rectangle.Create(); GPUInfo.PrintGPUInfo(); // Desktop GL core profile needs a VAO for vertex attrib pointers to work. uint vao = Gl.GenVertexArray(); Gl.BindVertexArray(vao); if (rootType == null) { throw new InvalidOperationException("Root cannot be null!"); } if (Root != null) { throw new InvalidOperationException("App already initialized!"); } _painter = new Painter(width, height); Stage = new Stage(width, height); DefaultJuggler = new Juggler(); UpdateViewPort(true); Root = (DisplayObject)Activator.CreateInstance(rootType); Stage.AddChild(Root); _frameId = 1; // starts with 1, so things on the first frame are cached }