caramia-0.7.2.2: High-level OpenGL bindings

Safe HaskellNone
LanguageHaskell2010

Graphics.Caramia.Texture

Contents

Description

Textures.

Synopsis

Creating textures

newTexture :: MonadIO m => TextureSpecification -> m Texture Source

Creates a new texture.

Initially the contents of the texture are undefined.

Texture dimensions must be positive.

data Texture Source

Instances

Eq Texture Source 
Ord Texture Source 
OpenGLResource GLuint Texture Source

If you use finalize, be careful of any resource that might refer to the texture.

data TextureSpecification Source

Specification on what the texture should be like.

Use textureSpecification and set at least topology and imageFormat. Future minor versions remain compatible if you use textureSpecification instead of the constructor directly.

Constructors

TextureSpecification 

Fields

topology :: Topology
 
imageFormat :: ImageFormat
 
mipmapLevels :: Int

How many mipmap levels including the base level? Must be at least 1.

Ignored and not evaluated for multisampling textures.

data Topology Source

Specifies a topology of a texture.

Constructors

Tex1D 

Fields

width1D :: !Int
 
Tex2D 

Fields

width2D :: !Int
 
height2D :: !Int
 
Tex3D 

Fields

width3D :: !Int
 
height3D :: !Int
 
depth3D :: !Int
 
Tex1DArray 

Fields

width1DArray :: !Int
 
layers1D :: !Int
 
Tex2DArray 
Tex2DMultisample

Multisampling is available if OpenGL version >= 3.2 or GL_ARB_texture_multisample is available.

Tex2DMultisampleArray 
TexCube 

Fields

widthCube :: Int
 
TexBuffer

Buffer textures, see https://www.opengl.org/wiki/Buffer_Texture

Available if OpenGL version >= 3.1 or GL_ARB_texture_buffer_object is available.

Fields

texBuffer :: !Buffer
 

Uploading to textures

uploadToTexture :: MonadIO m => Uploading -> Texture -> m () Source

Uploads an image to a texture.

data Uploading Source

Used to specify how to move the data from a Buffer to a Texture in uploadToTexture.

This is common for all texture topologies. However, some fields are ignored depending on the topology.

For example, if you upload into a 1D texture, then all fields that deal with higher dimensions (yOffset, zOffset, uHeight etc.) are ignored.

It is recommended that you use one of the smart constructors as they implement the common use cases so you don't have to fill all these fields by yourself.

Constructors

Uploading 

Fields

fromBuffer :: !Buffer

From which buffer to upload.

bufferOffset :: !Int

Offset in the buffer, in bytes, from where to start uploading.

toMipmapLevel :: !Int

To which mipmap level to upload. (0 = base level).

specificationType :: !SpecificationType

What data type is used for each component value in a pixel.

uploadFormat :: !UploadFormat

What format is the source data in.

xOffset :: !Int

X offset where to put the data.

yOffset :: !Int

Y offset where to put the data.

zOffset :: !Int

Z offset where to put the data.

uWidth :: !Int

Width of the data to put.

uHeight :: !Int

Height of the data to put.

uDepth :: !Int

Number of 2D images to put.

cubeSide :: CubeSide

Only used for cube map textures. Specifies which side of the cube to upload. Not evaluated if the texture is not a cube texture.

numColumns :: !Int

Number of columns in the image in the source buffer. This value is also sometimes known as 'pitch'. It is the same as uWidth except in cases where the next row in source data does not come immediately after the current row but after numColumns from the first pixel in the row.

numRows :: !Int

Same as numColumns but for images in 3D uploading.

pixelAlignment :: !Int

Alignment in which the source texture data is. Every row is aligned to this value. Allowed values are 1, 2, 4 and 8. The default value in smart constructors is 1.

Instances

uploading1D Source

Arguments

:: Buffer 
-> Int

How many pixels to upload.

-> SpecificationType 
-> UploadFormat 
-> Uploading 

Constructs a common 1D uploading.

uploading2D Source

Arguments

:: Buffer 
-> Int

Width of the image to upload.

-> Int

Height of the image to upload.

-> SpecificationType 
-> UploadFormat 
-> Uploading 

Constructs a common 2D uploading.

This can also be used for uploading into 1D texture arrays.

uploading3D Source

Arguments

:: Buffer 
-> Int

Width of the image to upload.

-> Int

Height of the image to upload.

-> Int

Number of images to upload.

-> SpecificationType 
-> UploadFormat 
-> Uploading 

Constructs a common 3D uploading.

This can also be used for uploading into 2D texture arrays.

data UploadFormat Source

Specifies the format in which buffer data is for the purposes of uploading said data to a texture.

Constructors

UR

Just red.

URG

Red and green.

URGB

You know the drill.

URGBA 
UBGR 
UBGRA 
UDEPTH_COMPONENT

Depth values.

USTENCIL_INDEX

Stencil values.

Texture units

type TextureUnit = Int Source

The type of a texture unit.

The minimum valid value is 0 and maximum is implementation dependant but in OpenGL at least 48 units will work at the same time in shaders.

Mipmapping

generateMipmaps :: (MonadIO m, MonadMask m) => Texture -> m () Source

Generate all mipmaps for a texture. If mipmap levels were specified, that is.

Texture parameters

Views

viewWidth :: Texture -> Int Source

Returns the width of a texture.

viewHeight :: Texture -> Int Source

Returns the height of a texture.

This is 1 for one-dimensional textures.

viewDepth :: Texture -> Int Source

Returns the depth of a 3D texture or number of layers in array textures.

This is 1 for any other type of texture.

viewSize2D :: Texture -> V2 Int Source

Returns the size of a texture, as a V2. Width and height.

viewSize2D tex = V2 (viewWidth tex) (viewHeight tex)

viewSize3D :: Texture -> V3 Int Source

Returns the size of a texture, as a V3. Width, height and depth.

viewSize3D tex = V3 (viewWidth tex) (viewHeight tex) (viewDepth tex)

Utilities

maxMipmapLevels :: Int -> Int Source

Returns the maximal number of mipmap levels when given a side length.