class Vissen::Output::VixelStack
Stack
TODO: Document this class.
Attributes
@return [Context] the context in which the stack exist.
@return [Array<VixelBuffer>] the layers that make up the stack.
Public Class Methods
TODO: Make palettes a keyword argument in the next minor version.
@raise [RangeError] if layer_count <= 0.
@param context [Context] the context in which the stack exist. @param layer_count [Integer] the number of layers in the stack.
# File lib/vissen/output/vixel_stack.rb, line 31 def initialize(context, layer_count) raise RangeError if layer_count <= 0 @context = context @layers = Array.new(layer_count) { VixelBuffer.new context } freeze end
Public Instance Methods
Accesses a vixel in one of the vixelbuffers stored in the stack.
@param layer [Integer] the index of the layer that is accessed. @param args (see VixelBuffer#[]
) @return [Vixel,nil] the vixel at the given layer.
# File lib/vissen/output/vixel_stack.rb, line 53 def [](layer, *args) @layers[layer][*args] end
Prevents more layers and palettes from being added.
@return [self]
# File lib/vissen/output/vixel_stack.rb, line 43 def freeze @layers.freeze super end
@return [PixelBuffer] a new, uninitialized pixel buffer.
# File lib/vissen/output/vixel_stack.rb, line 58 def pixel_buffer PixelBuffer.new context end
Renders each layer and combines the result in the given buffer.
TODO: Could we cache the result of this operation at time t to an
internal PixelGrid and copy the stored information for subsequent requests at or around the same time?
@raise [ContextError] if the pixel buffer does not share the same
context.
@param pixel_buffer
[PixelBuffer] the buffer to store the resulting
colors of each point in.
@param intensity [Numeric] the intensity to scale the vixels intensity
with.
@return [PixelBuffer] the same buffer that was given as a parameter.
# File lib/vissen/output/vixel_stack.rb, line 76 def render(pixel_buffer, intensity: 1.0) raise ContextError unless context == pixel_buffer.context pixel_buffer.clear! @layers.reduce(pixel_buffer) do |a, e| e.render a, intensity: intensity end pixel_buffer.finalize! end