public styles_gouraud(mesh_ctrl mesh, GammaLookUpTable gamma) { int i; for (i = 0; i < mesh.num_triangles(); i++) { mesh_triangle t = mesh.triangle(i); mesh_point p1 = mesh.vertex(t.p1); mesh_point p2 = mesh.vertex(t.p2); mesh_point p3 = mesh.vertex(t.p3); RGBA_Bytes c1 = p1.color; RGBA_Bytes c2 = p2.color; RGBA_Bytes c3 = p3.color; c1.apply_gamma_dir(gamma); c2.apply_gamma_dir(gamma); c3.apply_gamma_dir(gamma); span_gouraud_rgba gouraud = new span_gouraud_rgba(c1, c2, c3, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); gouraud.prepare(); m_triangles.Add(gouraud); } }
public override void OnDraw() { #if SourceDepth24 pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr()); #else FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pf); clippingProxy.Clear(new RGBA_Doubles(0, 0, 0)); RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); ScanlineBin sl_bin = new ScanlineBin(); RasterizerCompoundAA <T> rasc = new RasterizerCompoundAA <T>(); SpanAllocator alloc = new SpanAllocator(); uint i; styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma); start_timer(); rasc.Reset(); //rasc.clip_box(40, 40, width() - 40, height() - 40); for (i = 0; i < m_mesh.num_edges(); i++) { mesh_edge e = m_mesh.edge(i); mesh_point p1 = m_mesh.vertex(e.p1); mesh_point p2 = m_mesh.vertex(e.p2); rasc.Styles(e.tl, e.tr); rasc.MoveToDbl(p1.x, p1.y); rasc.LineToDbl(p2.x, p2.y); } Renderer <T> .RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles); double tm = elapsed_time(); GsvText <T> t = new GsvText <T>(); t.SetFontSize(10.0); ConvStroke <T> pt = new ConvStroke <T>(t); pt.Width = M.New <T>(1.5); pt.LineCap = LineCap.Round; pt.LineJoin = LineJoin.RoundJoin; string buf = string.Format("{0:F2} ms, {1} triangles, {2:F0} tri/sec", tm, m_mesh.num_triangles(), m_mesh.num_triangles() / tm * 1000.0); t.StartPoint(10.0, 10.0); t.Text = buf; ras.AddPath(pt); Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(1, 1, 1).GetAsRGBA_Bytes()); if (m_gamma.Gamma() != 1.0) { pf.ApplyGammaInv(m_gamma); } }
public styles_gouraud(mesh_ctrl mesh, GammaLut gamma) { uint i; for (i = 0; i < mesh.num_triangles(); i++) { mesh_triangle t = mesh.triangle(i); mesh_point p1 = mesh.vertex(t.p1); mesh_point p2 = mesh.vertex(t.p2); mesh_point p3 = mesh.vertex(t.p3); RGBA_Bytes c1 = p1.color; RGBA_Bytes c2 = p2.color; RGBA_Bytes c3 = p3.color; c1.ApplyGammaDir(gamma); c2.ApplyGammaDir(gamma); c3.ApplyGammaDir(gamma); SpanGouraudRgba <T> gouraud = new SpanGouraudRgba <T>(c1, c2, c3, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); gouraud.Prepare(); m_triangles.Add(gouraud); } }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); IImageByte backBuffer = widgetsSubImage; IImageByte destImage = backBuffer; ImageClippingProxy clippingProxy = new ImageClippingProxy(destImage); clippingProxy.clear(new RGBA_Floats(0, 0, 0)); ScanlineRasterizer ras = new ScanlineRasterizer(); scanline_unpacked_8 sl = new scanline_unpacked_8(); scanline_bin sl_bin = new scanline_bin(); rasterizer_compound_aa rasc = new rasterizer_compound_aa(); span_allocator alloc = new span_allocator(); int i; styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma); stopwatch.Restart(); rasc.reset(); //rasc.clip_box(40, 40, width() - 40, height() - 40); for (i = 0; i < m_mesh.num_edges(); i++) { mesh_edge e = m_mesh.edge(i); mesh_point p1 = m_mesh.vertex(e.p1); mesh_point p2 = m_mesh.vertex(e.p2); rasc.styles(e.tl, e.tr); rasc.move_to_d(p1.x, p1.y); rasc.line_to_d(p2.x, p2.y); } ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); scanlineRenderer.RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles); double tm = stopwatch.ElapsedMilliseconds; gsv_text t = new gsv_text(); t.SetFontSize(10.0); Stroke pt = new Stroke(t); pt.width(1.5); pt.line_cap(LineCap.Round); pt.line_join(LineJoin.Round); string buf = string.Format("{0:F2} ms, {1} triangles, {2:F0} tri/sec", tm, m_mesh.num_triangles(), m_mesh.num_triangles() / tm * 1000.0); t.start_point(10.0, 10.0); t.text(buf); ras.add_path(pt); scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(255, 255, 255)); if (m_gamma.GetGamma() != 1.0) { ((ImageBuffer)destImage).apply_gamma_inv(m_gamma); } base.OnDraw(graphics2D); }