flaw-graphics-0.1.0.0

LicenseMIT
Safe HaskellNone
LanguageHaskell2010

Flaw.Graphics

Description

Graphics system is mostly abstracted from backend. Almost everything from uploading textures to writing shader programs can be done with zero amount of backend-dependent code.

Initialization of graphics subsystem is still backend-dependent though. Initialization includes creating instances of System, Device and Presenter classes.

  • System instance allows to enumerate graphics hardware supported by backend, get information about displays and display modes.
  • Device instance creates graphics resources such as render targets, textures, shader programs, etc.
  • Context instance performs actual drawing. Draw operations run in Render monad.
  • Presenter instance shows rendering results onto screen or window.

Abstraction is mostly follows DirectX 11 / OpenGL 3 model. In a few places the lowest common denominator was choosen for certain features, to allow one-to-one mapping from abstraction to implementation. Examples:

  • Textures accept default sampling parameters, used when no sampler is bound;
  • Program objects are created explicitly;
  • There's no separate texture and sampler slots. Both a texture and a sampler are bound into combined slot indexed by numeric index;
  • Default framebuffer is bound automatically as part of initial state inside present.
Synopsis

Documentation

class System s where Source #

Class of graphics system.

Associated Types

data DeviceId s :: * Source #

Type for id of graphics device.

data DisplayId s :: * Source #

Type for id of display.

data DisplayModeId s :: * Source #

Type for id of display mode.

Methods

getInstalledDevices :: s -> IO ([(DeviceId s, DeviceInfo s)], IO ()) Source #

Get list of graphics devices installed in system.

createDisplayMode Source #

Arguments

:: s 
-> DisplayId s

Display id.

-> Int

Width.

-> Int

Height.

-> IO ((DisplayModeId s, DisplayModeInfo), IO ()) 

Create custom display mode (with specified width and height) for specified display.

class Device d where Source #

Class of graphics device. Graphics device performs managing of resources. Also it works as a primary context for the device.

Associated Types

type DeferredContext d :: * Source #

Type for deferred contexts.

data TextureId d :: * Source #

Type for texture id.

data SamplerStateId d :: * Source #

Type for sampler state id.

data BlendStateId d :: * Source #

Type for blend state id.

data RenderTargetId d :: * Source #

Type for render target id.

data DepthStencilTargetId d :: * Source #

Type for depth stencil target id.

data FrameBufferId d :: * Source #

Type for framebuffer id.

data VertexBufferId d :: * Source #

Type for vertex buffer id.

data IndexBufferId d :: * Source #

Type for index buffer id.

data ProgramId d :: * Source #

Type for program id.

data UniformBufferId d :: * Source #

Type for uniform buffer id.

Methods

nullTexture :: TextureId d Source #

Null texture.

nullSamplerState :: SamplerStateId d Source #

Null sampler state.

nullBlendState :: BlendStateId d Source #

Null blend state.

nullDepthStencilTarget :: DepthStencilTargetId d Source #

Null depth stencil target.

nullVertexBuffer :: VertexBufferId d Source #

Null vertex buffer.

nullIndexBuffer :: IndexBufferId d Source #

Null index buffer.

nullUniformBuffer :: UniformBufferId d Source #

Null uniform buffer.

createDeferredContext :: d -> IO (DeferredContext d, IO ()) Source #

Create deferred context.

createStaticTexture :: d -> TextureInfo -> SamplerStateInfo -> ByteString -> IO (TextureId d, IO ()) Source #

Create static texture.

createNativeTexture :: d -> SamplerStateInfo -> ByteString -> IO (TextureId d, IO ()) Source #

Create texture from image packed in any format natively supported by device.

createSamplerState :: d -> SamplerStateInfo -> IO (SamplerStateId d, IO ()) Source #

Create sampler state.

createBlendState :: d -> BlendStateInfo -> IO (BlendStateId d, IO ()) Source #

Create blend state.

createReadableRenderTarget :: d -> Int -> Int -> TextureFormat -> SamplerStateInfo -> IO ((RenderTargetId d, TextureId d), IO ()) Source #

Create readable render target.

createDepthStencilTarget :: d -> Int -> Int -> IO (DepthStencilTargetId d, IO ()) Source #

Create depth stencil target.

createReadableDepthStencilTarget :: d -> Int -> Int -> SamplerStateInfo -> IO ((DepthStencilTargetId d, TextureId d), IO ()) Source #

Create readable depth stencil target.

createFrameBuffer :: d -> [RenderTargetId d] -> DepthStencilTargetId d -> IO (FrameBufferId d, IO ()) Source #

Create framebuffer.

createStaticVertexBuffer Source #

Arguments

:: d

Device.

-> ByteString

Buffer.

-> Int

Stride in bytes.

-> IO (VertexBufferId d, IO ()) 

Create static vertex buffer.

createDynamicVertexBuffer Source #

Arguments

:: d

Device.

-> Int

Size in bytes.

-> Int

Stride in bytes.

-> IO (VertexBufferId d, IO ()) 

Create dynamic vertex buffer.

createStaticIndexBuffer :: d -> ByteString -> IndexTopology -> IndexStride -> IO (IndexBufferId d, IO ()) Source #

Create index buffer.

createProgram Source #

Arguments

:: d

Device.

-> Program ()

Program contents.

-> IO (ProgramId d, IO ()) 

Create program.

createUniformBuffer :: d -> Int -> IO (UniformBufferId d, IO ()) Source #

Create uniform buffer.

class Device d => Context c d | c -> d where Source #

Class of graphics context. Performs actual render operations.

Methods

contextClearColor :: c -> Int -> Float4 -> IO () Source #

Clear render target.

contextClearDepth :: c -> Float -> IO () Source #

Clear depth.

contextClearStencil :: c -> Int -> IO () Source #

Clear stencil.

contextClearDepthStencil :: c -> Float -> Int -> IO () Source #

Clear depth and stencil.

contextUploadUniformBuffer :: c -> UniformBufferId d -> ByteString -> IO () Source #

Upload data to uniform buffer.

contextUploadVertexBuffer :: c -> VertexBufferId d -> ByteString -> IO () Source #

Upload data to dynamic vertex buffer.

contextDraw Source #

Arguments

:: c 
-> Int

Instances count (1 for non-instanced).

-> Int

Indices count.

-> IO () 

Draw (instanced).

contextPlay :: Context dc d => c -> dc -> IO () Source #

Replay deferred context on immediate context.

contextRender :: c -> IO a -> IO a Source #

Perform rendering. Initial state is context's default state.

contextSetFrameBuffer :: c -> FrameBufferId d -> IO a -> IO a Source #

Set framebuffer.

contextSetViewport :: c -> Int4 -> IO a -> IO a Source #

Set viewport (left, top, right, bottom).

contextGetViewport :: c -> IO Int4 Source #

Get current viewport.

contextSetScissor :: c -> Maybe Int4 -> IO a -> IO a Source #

Set scissor (left, top, right, bottom).

contextGetScissor :: c -> IO (Maybe Int4) Source #

Get current scissor.

contextSetVertexBuffer :: c -> Int -> VertexBufferId d -> IO a -> IO a Source #

Set vertex buffer.

contextSetIndexBuffer :: c -> IndexBufferId d -> IO a -> IO a Source #

Set index buffer.

contextSetUniformBuffer :: c -> Int -> UniformBufferId d -> IO a -> IO a Source #

Set uniform buffer.

contextSetSampler :: c -> Int -> TextureId d -> SamplerStateId d -> IO a -> IO a Source #

Set sampler.

contextSetBlendState :: c -> BlendStateId d -> IO a -> IO a Source #

Set blend state.

contextSetDepthTestFunc :: c -> DepthTestFunc -> IO a -> IO a Source #

Set depth-test function.

contextSetDepthWrite :: c -> Bool -> IO a -> IO a Source #

Set depth write flag.

contextSetProgram :: c -> ProgramId d -> IO a -> IO a Source #

Set program.

class (System s, Context c d) => Presenter p s c d | p -> s c d where Source #

Presenter class.

Methods

setPresenterMode :: p -> Maybe (DisplayModeId s) -> IO () Source #

presenterRender :: p -> c -> IO a -> IO a Source #

Perform rendering on presenter's surface. Presenter's framebuffer, viewport, etc will be automatically set as an initial state.

data DeviceInfo device Source #

Device information structure.

Constructors

DeviceInfo 

Fields

data DisplayInfo device Source #

Display information structure.

Constructors

DisplayInfo 

data DisplayModeInfo Source #

Display mode information structure.

data IndexTopology Source #

Index topology.

Instances
Eq IndexTopology Source # 
Instance details

Defined in Flaw.Graphics

Generic IndexTopology Source # 
Instance details

Defined in Flaw.Graphics

Associated Types

type Rep IndexTopology :: Type -> Type #

Serialize IndexTopology Source # 
Instance details

Defined in Flaw.Graphics

type Rep IndexTopology Source # 
Instance details

Defined in Flaw.Graphics

type Rep IndexTopology = D1 (MetaData "IndexTopology" "Flaw.Graphics" "flaw-graphics-0.1.0.0-G4aqR0nuB7u1vHlmL38e2" False) ((C1 (MetaCons "IndexTopologyPoints" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "IndexTopologyLines" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "IndexTopologyLineStrip" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "IndexTopologyTriangles" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "IndexTopologyTriangleStrip" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "IndexTopologyPatches" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) SourceUnpack SourceStrict DecidedStrict) (Rec0 Int)))))

data IndexStride Source #

Index stride.

Instances
Eq IndexStride Source # 
Instance details

Defined in Flaw.Graphics

Generic IndexStride Source # 
Instance details

Defined in Flaw.Graphics

Associated Types

type Rep IndexStride :: Type -> Type #

Serialize IndexStride Source # 
Instance details

Defined in Flaw.Graphics

type Rep IndexStride Source # 
Instance details

Defined in Flaw.Graphics

type Rep IndexStride = D1 (MetaData "IndexStride" "Flaw.Graphics" "flaw-graphics-0.1.0.0-G4aqR0nuB7u1vHlmL38e2" False) (C1 (MetaCons "IndexStride32Bit" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "IndexStride16Bit" PrefixI False) (U1 :: Type -> Type))

type Render c = StackT (ReaderT c IO) Source #

Rendering monad.

renderScope :: Render c a -> Render c a Source #

Scope for rendering state. Context state will be restored after the scope.

renderFrameBuffer :: Context c d => FrameBufferId d -> Render c () Source #

Set current framebuffer.

renderViewport :: Context c d => Int4 -> Render c () Source #

Set current viewport (vector with left, top, right, bottom).

renderGetViewport :: Context c d => Render c Int4 Source #

Get current viewport.

renderScissor :: Context c d => Maybe Int4 -> Render c () Source #

Set current scissor (vector with left, top, right, bottom).

renderGetScissor :: Context c d => Render c (Maybe Int4) Source #

Get current scissor.

renderIntersectScissor :: Context c d => Int4 -> Render c () Source #

Set intersection between specified and current scissor as scissor.

renderVertexBuffer :: Context c d => Int -> VertexBufferId d -> Render c () Source #

Set vertex buffer.

renderIndexBuffer :: Context c d => IndexBufferId d -> Render c () Source #

Set current index buffer.

renderUniformBuffer :: Context c d => Int -> UniformBufferId d -> Render c () Source #

Set uniform buffer.

renderSampler :: Context c d => Int -> TextureId d -> SamplerStateId d -> Render c () Source #

Set sampler.

renderBlendState :: Context c d => BlendStateId d -> Render c () Source #

Set blend state.

renderDepthTestFunc :: Context c d => DepthTestFunc -> Render c () Source #

Set depth test function.

renderDepthWrite :: Context c d => Bool -> Render c () Source #

Set depth write flag.

renderProgram :: Context c d => ProgramId d -> Render c () Source #

Set current program.

renderClearColor :: Context c d => Int -> Float4 -> Render c () Source #

Clear render target.

renderClearDepth :: Context c d => Float -> Render c () Source #

Clear depth.

renderClearStencil :: Context c d => Int -> Render c () Source #

Clear stencil.

renderClearDepthStencil :: Context c d => Float -> Int -> Render c () Source #

Clear depth and stencil.

renderUploadUniformBuffer :: Context c d => UniformBufferId d -> ByteString -> Render c () Source #

Upload data to uniform buffer.

renderUploadVertexBuffer :: Context c d => VertexBufferId d -> ByteString -> Render c () Source #

Upload data to dynamic vertex buffer.

renderDraw Source #

Arguments

:: Context c d 
=> Int

Indices count.

-> Render c () 

Draw.

renderDrawInstanced Source #

Arguments

:: Context c d 
=> Int

Instances count.

-> Int

Indices count.

-> Render c () 

Draw instanced.

renderPlay :: (Context c d, Context dc d) => dc -> Render c () Source #

Play deferred context on immediate context.

render :: Context c d => c -> Render c a -> IO a Source #

Perform offscreen rendering.

present :: Presenter p s c d => p -> Render c a -> Render c a Source #

Perform rendering on presenter.