Class SoftwareRenderer

java.lang.Object
technology.sola.engine.graphics.Canvas
technology.sola.engine.graphics.renderer.SoftwareRenderer
All Implemented Interfaces:
Renderer

@NullMarked public class SoftwareRenderer extends Canvas implements Renderer
SoftwareRenderer is a Renderer implementation that draws on an in memory array of pixels using the CPU. This is portable across SolaPlatforms but will be less performant than a GPU based implementation.
  • Constructor Details

    • SoftwareRenderer

      public SoftwareRenderer(int width, int height)
      Creates a SoftwareRenderer with width and height.
      Parameters:
      width - width of the renderer
      height - height of the renderer
  • Method Details

    • setBlendFunction

      public void setBlendFunction(BlendFunction blendFunction)
      Description copied from interface: Renderer
      Sets the BlendFunction that should be used.
      Specified by:
      setBlendFunction in interface Renderer
      Parameters:
      blendFunction - the new BlendMode to use
    • getBlendFunction

      public BlendFunction getBlendFunction()
      Specified by:
      getBlendFunction in interface Renderer
      Returns:
      the current BlendFunction being used when drawing
    • createRendererForImage

      public Renderer createRendererForImage(SolaImage solaImage)
      Description copied from interface: Renderer
      Creates a new Renderer instance that draws to a SolaImage instead of the screen.
      Specified by:
      createRendererForImage in interface Renderer
      Parameters:
      solaImage - the image to draw to
      Returns:
      a new renderer instance drawing to an image
    • getFont

      public Font getFont()
      Specified by:
      getFont in interface Renderer
      Returns:
      the current Font being used for drawing text
    • setFont

      public void setFont(Font font)
      Description copied from interface: Renderer
      Sets the Font to use when drawing text.
      Specified by:
      setFont in interface Renderer
      Parameters:
      font - the new Font to use
    • setClamp

      public void setClamp(int x, int y, int width, int height)
      Description copied from interface: Renderer
      Restricts rendering of pixels within a rectangle. Any setPixel call outside of this rectangle will be ignored.
      Specified by:
      setClamp in interface Renderer
      Parameters:
      x - top left coordinate x
      y - top left coordinate y
      width - width of the rectangle
      height - height of the rectangle
    • clear

      public void clear(Color color)
      Description copied from interface: Renderer
      Sets all pixels to desired Color.
      Specified by:
      clear in interface Renderer
      Parameters:
      color - the Color to set all pixels to
    • setPixel

      public void setPixel(int x, int y, Color color)
      Description copied from interface: Renderer
      Sets the Color of a pixel at coordinate.
      Specified by:
      setPixel in interface Renderer
      Parameters:
      x - the x coordinate of the pixel
      y - the y coordinate of the pixel
      color - the new Color
    • drawLine

      public void drawLine(float x1, float y1, float x2, float y2, Color color)
      Description copied from interface: Renderer
      Draws a line.
      Specified by:
      drawLine in interface Renderer
      Parameters:
      x1 - the x coordinate of the first point
      y1 - the y coordinate of the first point
      x2 - the x coordinate of the second point
      y2 - the y coordinate of the second point
      color - the Color of the line
    • drawRect

      public void drawRect(float x, float y, float width, float height, Color color)
      Description copied from interface: Renderer
      Draws an unfilled rectangle.
      Specified by:
      drawRect in interface Renderer
      Parameters:
      x - top left coordinate x
      y - top left coordinate y
      width - width of the rectangle
      height - height of the rectangle
      color - Color of the rectangle
    • fillRect

      public void fillRect(float x, float y, float width, float height, Color color)
      Description copied from interface: Renderer
      Draws a filled rectangle.
      Specified by:
      fillRect in interface Renderer
      Parameters:
      x - top left coordinate x
      y - top left coordinate y
      width - width of the rectangle
      height - height of the rectangle
      color - Color of the rectangle
    • drawCircle

      public void drawCircle(float x, float y, float radius, Color color)
      Description copied from interface: Renderer
      Draws an unfilled circle. Uses Bresenham's circle drawing algorithm.
      Specified by:
      drawCircle in interface Renderer
      Parameters:
      x - top left coordinate x
      y - top left coordinate y
      radius - radius of the circle
      color - Color of the circle
    • fillCircle

      public void fillCircle(float x, float y, float radius, Color color)
      Description copied from interface: Renderer
      Draws a filled circle.
      Specified by:
      fillCircle in interface Renderer
      Parameters:
      x - top left coordinate x
      y - top left coordinate y
      radius - radius of the circle
      color - Color of the circle
    • fillTriangle

      public void fillTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Color color)
      Description copied from interface: Renderer
      Draws a filled triangle.
      Specified by:
      fillTriangle in interface Renderer
      Parameters:
      x1 - x coordinate for the first point
      y1 - y coordinate for the first point
      x2 - x coordinate for the second point
      y2 - y coordinate for the second point
      x3 - x coordinate for the third point
      y3 - y coordinate for the third point
      color - Color of the triangle
    • drawImage

      public void drawImage(SolaImage solaImage, float x, float y)
      Description copied from interface: Renderer
      Draws a SolaImage at desired coordinate. The coordinate will be the top-left of the image drawn.
      Specified by:
      drawImage in interface Renderer
      Parameters:
      solaImage - the SolaImage to draw
      x - top left coordinate x
      y - top left coordinate y
    • drawImage

      public void drawImage(SolaImage solaImage, AffineTransform affineTransform)
      Description copied from interface: Renderer
      Draws a SolaImage with AffineTransform applied.
      Specified by:
      drawImage in interface Renderer
      Parameters:
      solaImage - the SolaImage to draw
      affineTransform - the transform to apply
    • drawImage

      public void drawImage(SolaImage solaImage, float x, float y, float width, float height)
      Description copied from interface: Renderer
      Draws a SolaImage scaled to fit within a rectangle specified by x,y, width and height.
      Specified by:
      drawImage in interface Renderer
      Parameters:
      solaImage - the SolaImage to draw
      x - top left coordinate x of the scaling rectangle
      y - top left coordinate y of the scaling rectangle
      width - the width of the scaling rectangle
      height - the height of the scaling rectangle
    • getLayers

      public List<Layer> getLayers()
      Specified by:
      getLayers in interface Renderer
      Returns:
      the List of Layers this Renderer has