/// <summary> /// Applies the filter on a certain display object, rendering the output into the current render /// target. This method is called automatically by Sparrow's rendering system for the object the /// filter is attached to. /// </summary> public void RenderObject(DisplayObject obj, RenderSupport support) { // bottom layer if (Mode == FragmentFilterMode.Above) { obj.Render(support); } // center layer if (_cacheRequested) { _cacheRequested = false; _cache = RenderPasses(obj, support, true); DisposePassTextures(); } if (_cache != null) { _cache.Render(support); } else { RenderPasses(obj, support, false); } // top layer if (Mode == FragmentFilterMode.Below) { obj.Render(support); } }
override public void Render(RenderSupport support) { support.Clear(Color, 1.0f); support.SetupOrthographicProjection(0, Width, 0, Height); base.Render(support); }
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); }
override public void Render(RenderSupport support) { if (_requiresRedraw) { Redraw(); } base.Render(support); }
override public void Render(RenderSupport support) { if (_numQuads != 0) { support.FinishQuadBatch(); support.AddDrawCalls(1); Render(support.MvpMatrix, support.Alpha, support.BlendMode); } }
override public void Render(RenderSupport support) { if (ClipRect != null) { Rectangle stageClipRect = support.PushClipRect(ClipRectInSpace(Stage)); if (stageClipRect != null || stageClipRect.IsEmpty()) { // empty clipping bounds - no need to render children support.PopClipRect(); return; } } if (_flattenRequested) { _flattenedContents = QuadBatch.Compile(this, _flattenedContents); _flattenRequested = false; } if (_flattenedContents.Count > 0) { support.FinishQuadBatch(); support.AddDrawCalls(_flattenedContents.Count); Matrix mvpMatrix = support.MvpMatrix; float alpha = support.Alpha; uint supportBlendMode = support.BlendMode; foreach (QuadBatch quadBatch in _flattenedContents) { uint blendMode = quadBatch.BlendMode; if (blendMode == Sparrow.Display.BlendMode.AUTO) { blendMode = supportBlendMode; } quadBatch.Render(mvpMatrix, alpha, blendMode); } } else { base.Render(support); } if (ClipRect != null) { support.PopClipRect(); } }
override public void Render(RenderSupport support) { foreach (DisplayObject child in _children) { if (child.HasVisibleArea) { support.PushState(child.TransformationMatrix, child.Alpha, child.BlendMode); if (child.Filter != null) { child.Filter.RenderObject(child, support); } else { child.Render(support); } support.PopState(); } } }
/// <summary> /// Initializes a render texture with a certain ARGB color (0xAARRGGBB) and a scale factor. /// </summary> public RenderTexture(float width, float height, uint argbFillColor = 0x0, float scale = 1.0f) { int legalWidth = NumberUtil.NextPowerOfTwo(width * scale); int legalHeight = NumberUtil.NextPowerOfTwo(height * scale); TextureProperties properties = new TextureProperties { TextureFormat = Sparrow.Textures.TextureFormat.Rgba8888, Scale = scale, Width = legalWidth, Height = legalHeight, NumMipmaps = 0, PremultipliedAlpha = true }; Rectangle region = new Rectangle(0, 0, width, height); GLTexture glTexture = new GLTexture(IntPtr.Zero, properties); Init(glTexture, region); _renderSupport = new RenderSupport(); Clear(argbFillColor, ColorUtil.GetA(argbFillColor) / 255.0f); }
public static void Step(double time) { long elapsed = watch.ElapsedMilliseconds; watch.Restart(); renderSupport.NextFrame(); Stage.Render(renderSupport); renderSupport.FinishQuadBatch(); if (stats != null) { stats.NumDrawCalls = renderSupport.NumDrawCalls - 2; // stats display requires 2 itself } #if DEBUG RenderSupport.CheckForOpenGLError(); #endif Stage.AdvanceTime(elapsed); DefaultJuggler.AdvanceTime(elapsed / 1000.0f); }
override public void Render(RenderSupport support) { support.BatchQuad(this); }
/// <summary> /// Renders the display object with the help of a support object. /// </summary> public abstract void Render(RenderSupport support);
private QuadBatch RenderPasses(DisplayObject obj, RenderSupport support, bool intoCache) { Texture cacheTexture = null; Stage stage = obj.Stage; float scale = Resolution; if (stage == null) { throw new InvalidOperationException("Filtered object must be on the stage."); } // the bounds of the object in stage coordinates Rectangle boundsPOT; Rectangle bounds; CalcBounds(obj, stage, scale, !intoCache, out bounds, out boundsPOT); if (bounds.IsEmpty()) { DisposePassTextures(); return(intoCache ? new QuadBatch() : null); } UpdateBuffers(boundsPOT); UpdatePassTextures((int)boundsPOT.Width, (int)boundsPOT.Height, scale); support.FinishQuadBatch(); support.AddDrawCalls(NumPasses); support.PushState(Matrix.Create(), 1.0f, BlendMode.AUTO); // save original projection matrix and render target _projMatrix.CopyFromMatrix(support.ProjectionMatrix); Texture previousRenderTarget = support.RenderTarget; // use cache? if (intoCache) { cacheTexture = CreateTexture((int)boundsPOT.Width, (int)boundsPOT.Height, scale); } // draw the original object into a texture support.RenderTarget = _passTextures[0]; SparrowSharpApp.Context.ScissorBox = null; // we want the entire texture cleared support.Clear(); support.BlendMode = BlendMode.NORMAL; support.SetupOrthographicProjection(boundsPOT.Left, boundsPOT.Right, boundsPOT.Bottom, boundsPOT.Top); obj.Render(support); support.FinishQuadBatch(); // prepare drawing of actual filter passes support.ApplyBlendMode(true); support.ModelViewMatrix.Identity(); support.PushClipRect(bounds); GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBufferName); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBufferName); GL.EnableVertexAttribArray(VertexPosID); GL.VertexAttribPointer(VertexPosID, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.POSITION_OFFSET); GL.EnableVertexAttribArray(TexCoordsID); GL.VertexAttribPointer(TexCoordsID, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.TEXTURE_OFFSET); // draw all passes for (int i = 0; i < NumPasses; ++i) { if (i < NumPasses - 1) { // intermediate pass // draw into pass texture support.RenderTarget = PassTextureForPass(i + 1); support.Clear(); } else { // final pass if (intoCache) { // draw into cache texture support.RenderTarget = cacheTexture; support.Clear(); } else { // draw into back buffer, at original (stage) coordinates support.RenderTarget = previousRenderTarget; support.ProjectionMatrix = _projMatrix; support.ModelViewMatrix.Translate(OffsetX, OffsetY); support.BlendMode = obj.BlendMode; support.ApplyBlendMode(true); } } Texture passTexture = PassTextureForPass(i); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, passTexture.Name); ActivateWithPass(i, passTexture, support.MvpMatrix); GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, IntPtr.Zero); DeactivateWithPass(i, passTexture); } GL.DisableVertexAttribArray(VertexPosID); GL.DisableVertexAttribArray(TexCoordsID); support.PopState(); support.PopClipRect(); QuadBatch cache = null; if (intoCache) { // restore support settings support.RenderTarget = previousRenderTarget; support.ProjectionMatrix = _projMatrix; // Create an image containing the cache. To have a display object that contains // the filter output in object coordinates, we wrap it in a QuadBatch: that way, // we can modify it with a transformation matrix. cache = new QuadBatch(); Image image = new Image(cacheTexture); Matrix matrix = stage.TransformationMatrixToSpace(obj); // Note: the next line was originally: // matrix.Translate (bounds.X + OffsetX, bounds.Y + OffsetY); // this seems like a sparrow-s bug; fix is from Starling matrix.PrependTranslation(bounds.X + OffsetX, bounds.Top + OffsetY); cache.AddQuad(image, 1.0f, BlendMode.AUTO, matrix); } return(cache); }
public override void Render(RenderSupport support) { base.Render(support); support.ProjectionMatrix = support.ProjectionMatrix; }