public override Figure GetScene(Figure Foreground, Camera Camera, View View) { double zoom = Camera.Zoom; double wash = Math.Min(1.0, Math.Max(0.0, (zoom + 2.0) / 10.0)); Color topcol = Color.Mix(Color.RGB(0.3, 0.6, 0.7), Color.RGB(0.3, 0.5, 0.8), wash); Color botcol = Color.Mix(Color.RGB(0.1, 0.4, 0.6), Color.RGB(0.1, 0.3, 0.7), wash); Figure fig = MeshFigure.CreateQuad( new MeshVertex(View.TopLeft, topcol), new MeshVertex(View.TopRight, topcol), new MeshVertex(View.BottomLeft, botcol), new MeshVertex(View.BottomRight, botcol)); foreach (Layer l in this._Layers) { double pg = (zoom - l.MinZoom) / (l.MaxZoom - l.MinZoom); if (pg > 0.0 && pg < 1.0) { double op = pg * (1.0 - pg) * 4.0; fig += new ModulatedFigure(Color.RGBA(1.0, 1.0, 1.0, op), l.Figure); } } fig += Foreground; return fig; }
public ShapeFigure(Shape Shape, Figure Source) { this.Shape = Shape; this.Source = Source; }
/// <summary> /// Gets the final scene to display when given the foreground scene, camera parameters and the view. /// </summary> public abstract Figure GetScene(Figure Foreground, Camera Camera, View View);
public PersistenceHintFigure(int NumberRenders, Figure Source) : base(Source) { this.NumberRenders = NumberRenders; }
public HintFigure(Figure Source) { this.Source = Source; }
public CacheHintFigure(string Name, Figure Source) : base(Source) { this.Name = Name; }
public ProjectedFigure(View Projection, Figure Source) { this.Source = Source; this.Projection = Projection; }
/// <summary> /// Sets up the view on the current graphics context and renders a figure. /// </summary> public void Render(View View, int Width, int Height, bool InvertY, Figure Figure) { GL.Viewport(0, 0, Width, Height); View iview = View.Inverse; GL.MatrixMode(MatrixMode.Projection); UpdateProjection(InvertY, iview); GL.CullFace(InvertY ? CullFaceMode.Front : CullFaceMode.Back); this.GetProcedure(Figure, new Environment { }).Execute(new Context { InvertY = InvertY, InverseView = iview, Resolution = Width / View.Area * Height, Renderer = this, Modulation = Color.White }); }
/// <summary> /// Creates a rotated form of a figure. /// </summary> public static RotatedFigure Rotate(Figure Figure, double Angle) { if (Figure == null) return null; return new RotatedFigure(Angle, Figure); }
/// <summary> /// Creates a projected form of a figure. /// </summary> public static ProjectedFigure Project(Figure Figure, View Projection) { if (Figure == null) return null; return new ProjectedFigure(Projection, Figure); }
/// <summary> /// Creates a modulated form of a figure. /// </summary> public static ModulatedFigure Modulate(Figure Figure, Color Modulation) { if (Figure == null) return null; return new ModulatedFigure(Modulation, Figure); }
public TranslatedFigure(Point Offset, Figure Source) { this.Source = Source; this.Offset = Offset; }
public SuperimposedFigure(Figure Under, Figure Over) { this.Under = Under; this.Over = Over; }
public ScaledFigure(double Factor, Figure Source) { this.Factor = Factor; this.Source = Source; }
public RotatedFigure(double Angle, Figure Source) { this.Angle = Angle; this.Source = Source; }
/// <summary> /// Gets a procedure that renders the given figure with the given color modulation. /// </summary> public Procedure GetProcedure(Figure Figure, Environment Environment) { // See if there is a stored procedure for it Procedure res; if(this._Procedures.TryGetValue(Figure, out res)) { return res; } // Hint figure HintFigure hint = Figure as HintFigure; if (hint != null) { CacheHintFigure cachehint = hint as CacheHintFigure; if (cachehint != null) { IRenderCache cache = this._Cache; Disposable<InStream> cacheread = cache.Read(cachehint.Name); if (!cacheread.IsNull) { Environment.CacheRead = cacheread; Procedure result = this.GetProcedure(hint.Source, Environment); Environment.CacheRead = null; cacheread.Dispose(); return result; } Disposable<OutStream> cachewrite = cache.Update(cachehint.Name); if (!cachewrite.IsNull) { Environment.CacheWrite = cachewrite; Procedure result = this.GetProcedure(hint.Source, Environment); Environment.CacheWrite = null; cachewrite.Dispose(); return result; } } return this.GetProcedure(hint.Source, Environment); } // Translated figure TranslatedFigure translated = Figure as TranslatedFigure; if (translated != null) { return new ProjectionProcedure(View.Translation(translated.Offset), this.GetProcedure(translated.Source, Environment)); } // Scaled figure ScaledFigure scaled = Figure as ScaledFigure; if (scaled != null) { return new ProjectionProcedure(View.Scale(scaled.Factor), this.GetProcedure(scaled.Source, Environment)); } // Rotated figure RotatedFigure rotated = Figure as RotatedFigure; if (rotated != null) { return new ProjectionProcedure(View.Rotation(rotated.Angle), this.GetProcedure(rotated.Source, Environment)); } // Projected figure ProjectedFigure projected = Figure as ProjectedFigure; if (projected != null) { return new ProjectionProcedure(projected.Projection, this.GetProcedure(projected.Source, Environment)); } // Modulated figure ModulatedFigure modulated = Figure as ModulatedFigure; if (modulated != null) { return new ModulateProcedure(modulated.Modulation, this.GetProcedure(modulated.Source, Environment)); } // Superimposed figure SuperimposedFigure superimposed = Figure as SuperimposedFigure; if (superimposed != null) { return this.GetProcedure(superimposed.Under, Environment) + this.GetProcedure(superimposed.Over, Environment); } // Compound figure CompoundFigure compound = Figure as CompoundFigure; if (compound != null) { Procedure[] components = new Procedure[compound.Components.Count()]; int i = 0; foreach (Figure component in compound.Components) { components[i++] = this.GetProcedure(component, Environment); } return new CompoundProcedure(components); } // Shape figure ShapeFigure shape = Figure as ShapeFigure; if (shape != null) { return this.GetShapeProcedure(shape.Shape, shape.Source, Environment); } // Mesh figure MeshFigure mesh = Figure as MeshFigure; if (mesh != null) { return BindTextureProcedure.Null + SetColorProcedure.White + new RenderGeometryProcedure(BeginMode.Triangles, new MeshGeometry(mesh)); } // System font glyph SystemFontGlyph sfg = Figure as SystemFontGlyph; if (sfg != null) { SystemFont font = sfg.Font; BitmapTypeface typeface = font.Typeface as BitmapTypeface; if (typeface != null) { Texture tex; Rectangle src; Rectangle dst; typeface.GetGlyph(sfg.Character).GetRenderInfo(font.Size, out tex, out src, out dst); return new BindTextureProcedure(tex) + new SetColorProcedure(font.Color) + new RenderGeometryProcedure(BeginMode.Quads, new BufferGeometry( new Point[] { dst.TopLeft, dst.TopRight, dst.BottomRight, dst.BottomLeft }, null, new Point[] { src.TopLeft, src.TopRight, src.BottomRight, src.BottomLeft })); } } // Sampled figure SampledFigure sampled = Figure as SampledFigure; if(sampled != null) { if(sampled.Tiled) { int size = 256; byte[] data = new byte[size * size * 4]; Texture tex; unsafe { fixed (byte* ptr = data) { if (Environment.CacheRead != null) { Environment.CacheRead.Read(data, 0, data.Length); } else { Texture.WriteImageARGB(sampled, new View(Rectangle.UnitSquare), size, size, ptr); if (Environment.CacheWrite != null) { Environment.CacheWrite.Write(data, 0, data.Length); } } tex = Texture.Create(); Texture.SetImage(Texture.Format.BGRA32, 0, size, size, ptr); Texture.GenerateMipmap(); Texture.SetFilterMode(TextureMinFilter.LinearMipmapLinear, TextureMagFilter.Linear); } } Procedure proc = new BindTextureProcedure(tex) + SetColorProcedure.White + RenderViewProcedure.Singleton; this._Procedures[sampled] = proc; return proc; } } // No rendering method available throw new NotImplementedException(); }
/// <summary> /// Gets a procedure that renders a figure confined to a certain shape. /// </summary> public Procedure GetShapeProcedure(Shape Shape, Figure Source, Environment Environment) { SolidFigure solidsource = Source as SolidFigure; if (solidsource != null) { Color fillcol = solidsource.Color; RectangleShape rectangle = Shape as RectangleShape; if (rectangle != null) { Rectangle rect = rectangle.Rectangle; return BindTextureProcedure.Null + new SetColorProcedure(fillcol) + new RenderGeometryProcedure(BeginMode.Quads, new BufferGeometry(new Point[] { rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft }, null, null)); } PathShape pathshape = Shape as PathShape; if (pathshape != null) { return BindTextureProcedure.Null + new SetColorProcedure(fillcol) + this.GetPathProcedure(pathshape.Thickness, pathshape.Path, Environment); } } throw new NotImplementedException(); }
/// <summary> /// Creates a scaled form of a figure. /// </summary> public static ScaledFigure Scale(Figure Figure, double Factor) { if (Figure == null) return null; return new ScaledFigure(Factor, Figure); }
/// <summary> /// Creates a translated form of a figure. /// </summary> public static TranslatedFigure Translate(Figure Figure, Point Offset) { if (Figure == null) return null; return new TranslatedFigure(Offset, Figure); }
public ModulatedFigure(Color Modulation, Figure Source) { this.Modulation = Modulation; this.Source = Source; }