Copyright | (c) 2018 Schell Scivally |
---|---|
License | MIT |
Maintainer | Schell Scivally <schell@takt.com> |
Safe Haskell | None |
Language | Haskell2010 |
This module provides a method of caching rendererd text, making it suitable for interactive rendering. You can use the defaultCache or provide your own.
Synopsis
- class Layout t where
- data AllocatedRendering t = AllocatedRendering {}
- newtype WordCache t = WordCache {
- unWordCache :: Map String (AllocatedRendering t)
- loadWords :: (MonadIO m, MonadError TypograffitiError m) => (Atlas -> String -> m (AllocatedRendering t)) -> Atlas -> WordCache t -> String -> m (WordCache t)
- unloadMissingWords :: MonadIO m => WordCache t -> String -> m (WordCache t)
- loadText :: forall m t. (MonadIO m, MonadError TypograffitiError m, Layout t) => (Atlas -> String -> m (AllocatedRendering t)) -> Atlas -> WordCache t -> String -> m (t -> IO (), V2 Int, WordCache t)
- data SpatialTransform
- data TextTransform
- move :: Float -> Float -> TextTransform
- scale :: Float -> Float -> TextTransform
- rotate :: Float -> TextTransform
- color :: Float -> Float -> Float -> Float -> TextTransform
- alpha :: Float -> TextTransform
- transformToUniforms :: [TextTransform] -> (M44 Float, V4 Float)
- vertexShader :: ByteString
- fragmentShader :: ByteString
- makeDefaultAllocateWord :: (MonadIO m, MonadError TypograffitiError m, Integral i) => IO (V2 i) -> m (Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering [TextTransform])))
Documentation
Generic operations for text layout.
Instances
Layout [TextTransform] Source # | |
Defined in Typograffiti.Cache translate :: [TextTransform] -> V2 Float -> [TextTransform] Source # |
data AllocatedRendering t Source #
Holds an allocated draw function for some amount of text. The function takes one parameter that can be used to transform the text in various ways. This type is generic and can be used to take advantage of your own font rendering shaders.
:: (MonadIO m, MonadError TypograffitiError m) | |
=> (Atlas -> String -> m (AllocatedRendering t)) | Operation used to allocate a word. |
-> Atlas | The character atlas that holds our letters, which is used to generate the word geometry. |
-> WordCache t | The atlas to load the words into. |
-> String | The string of words to load, with each word separated by spaces. |
-> m (WordCache t) |
Load a string of words into the WordCache.
:: MonadIO m | |
=> WordCache t | The WordCache to unload words from. |
-> String | The source string. |
-> m (WordCache t) |
Unload any words from the cache that are not contained in the source string.
:: (MonadIO m, MonadError TypograffitiError m, Layout t) | |
=> (Atlas -> String -> m (AllocatedRendering t)) | Operation used to allocate a word. |
-> Atlas | The character atlas that holds our letters. |
-> WordCache t | The WordCache to load AllocatedRenderings into. |
-> String | The string to render. This string may contain newlines, which will be respected. |
-> m (t -> IO (), V2 Int, WordCache t) | Returns a function for rendering the text, the size of the text and the new WordCache with the allocated renderings of the text. |
Constructs a Renderer2
from the given color and string. The WordMap
record of the given Atlas
is used to construct the string geometry, greatly
improving performance and allowing longer strings to be compiled and renderered
in real time. To create a new Atlas
see allocAtlas
.
Note that since word geometries are stored in the Atlas
WordMap
and multiple
renderers can reference the same Atlas
, the returned Renderer2
contains a
clean up operation that does nothing. It is expected that the programmer
will call freeAtlas
manually when the Atlas
is no longer needed.
data SpatialTransform Source #
data TextTransform Source #
Instances
Layout [TextTransform] Source # | |
Defined in Typograffiti.Cache translate :: [TextTransform] -> V2 Float -> [TextTransform] Source # |
rotate :: Float -> TextTransform Source #
alpha :: Float -> TextTransform Source #
transformToUniforms :: [TextTransform] -> (M44 Float, V4 Float) Source #
makeDefaultAllocateWord Source #
:: (MonadIO m, MonadError TypograffitiError m, Integral i) | |
=> IO (V2 i) | A monadic operation that returns the current context's dimentions. This is used to set the orthographic projection for rendering text. |
-> m (Atlas -> String -> IO (Either TypograffitiError (AllocatedRendering [TextTransform]))) |