001/* 002 * Renderer 4. The MIT License. 003 * Copyright (c) 2022 rlkraft@pnw.edu 004 * See LICENSE for details. 005*/ 006 007package renderer.pipeline; 008 009import renderer.scene.*; 010import renderer.scene.primitives.*; 011import renderer.framebuffer.*; 012import static renderer.pipeline.PipelineLogger.*; 013 014/** 015 Rasterize a projected geometric {@link Primitive} 016 into shaded pixels in a {{@link FrameBuffer.Viewport}. 017*/ 018public class Rasterize 019{ 020 public static boolean debug = false; 021 public static boolean doClipping = true; 022 public static boolean doAntiAliasing = false; 023 public static boolean doGamma = true; 024 public static final double GAMMA = 2.2; 025 026 /** 027 Rasterize every projected, visible {@link Primitive} 028 into shaded pixels in a {@link FrameBuffer.Viewport}. 029 030 @param model {@link Model} that contains clipped {@link Primitive}s 031 @param vp {@link FrameBuffer.Viewport} to hold rasterized, shaded pixels 032 */ 033 public static void rasterize(final Model model, 034 final FrameBuffer.Viewport vp) 035 { 036 // Rasterize each visible primitive into shaded pixels. 037 for (final Primitive p : model.primitiveList) 038 { 039 logPrimitive("4. Rasterize", model, p); 040 041 if (p instanceof LineSegment) 042 { 043 Rasterize_Clip_AntiAlias_Line.rasterize(model, (LineSegment)p, vp); 044 } 045 else if (p instanceof Point) 046 { 047 Rasterize_Clip_Point.rasterize(model, (Point)p, vp); 048 } 049 else // should never get here 050 { 051 System.err.println("Incorrect primitive: " + p); 052 } 053 } 054 } 055 056 057 058 // Private default constructor to enforce noninstantiable class. 059 // See Item 4 in "Effective Java", 3rd Ed, Joshua Bloch. 060 private Rasterize() { 061 throw new AssertionError(); 062 } 063}