openrndr / org.openrndr.draw / ColorBuffer

ColorBuffer

interface ColorBuffer (source)

representation for simple images stored on GPU memory

ColorBuffer is a unmanaged GPU resource, the user is responsible for destroying a ColorBuffer once it is no longer used.

Properties

anisotropy

the (unitless?) degree of anisotropy to be used in filtering

abstract var anisotropy: Double

bounds

open val bounds: Rectangle

contentScale

the content scale of the ColorBuffer

abstract val contentScale: Double

effectiveHeight

the height of the ColorBuffer in pixels

open val effectiveHeight: Int

effectiveWidth

the width of the ColorBuffer in pixels

open val effectiveWidth: Int

filterMag

the filter to use when display at sizes larger than the original

abstract var filterMag: MagnifyingFilter

filterMin

the filter to use when displaying at sizes smaller than the original

abstract var filterMin: MinifyingFilter

flipV

should the v coordinate be flipped because the ColorBuffer contents are stored upside-down?

abstract var flipV: Boolean

format

the ColorFormat of the image stored in the ColorBuffer

abstract val format: ColorFormat

height

the height of the ColorBuffer in device units

abstract val height: Int

levels

the number of mipmap levels

abstract val levels: Int

multisample

the multisampling method used for this ColorBuffer

abstract val multisample: BufferMultisample

session

abstract val session: Session?

shadow

abstract val shadow: ColorBufferShadow

type

the ColorType of the image stored in the ColorBuffer

abstract val type: ColorType

width

the width of the ColorBuffer in device units

abstract val width: Int

wrapU

the wrapping mode to use in the horizontal direction

abstract var wrapU: WrapMode

wrapV

the wrapping mode to use in the vertical direction

abstract var wrapV: WrapMode

Functions

bind

bind the colorbuffer to a texture unit, internal API

abstract fun bind(unit: Int): Unit

copyTo

copies contents to a target color buffer

abstract fun copyTo(target: ColorBuffer, fromLevel: Int = 0, toLevel: Int = 0, sourceRectangle: IntRectangle = IntRectangle( 0, 0, this.effectiveWidth / (1 shl fromLevel), this.effectiveHeight / (1 shl fromLevel) ), targetRectangle: IntRectangle = IntRectangle( 0, 0, sourceRectangle.width, sourceRectangle.height ), filter: MagnifyingFilter = MagnifyingFilter.NEAREST): Unit

copies contents to a target array texture

abstract fun copyTo(target: ArrayTexture, layer: Int, fromLevel: Int = 0, toLevel: Int = 0): Unit

createEquivalent

create an equivalent ColorBuffer, with the option to override attributes

open fun createEquivalent(width: Int = this.width, height: Int = this.height, contentScale: Double = this.contentScale, format: ColorFormat = this.format, type: ColorType = this.type, multisample: BufferMultisample = this.multisample, levels: Int = this.levels): ColorBuffer

crop

create a cropped copy of the ColorBuffer

open fun crop(sourceRectangle: IntRectangle): ColorBuffer

destroy

permanently destroy the underlying ColorBuffer resources, ColorBuffer can not be used after it is destroyed

abstract fun destroy(): Unit

fill

sets all pixels in the color buffer to color

abstract fun fill(color: ColorRGBa): Unit

filter

sets the ColorBuffer filter for minifying and magnification

open fun filter(filterMin: MinifyingFilter, filterMag: MagnifyingFilter): Unit

generateMipmaps

generates mipmaps from the top-level mipmap

abstract fun generateMipmaps(): Unit

isEquivalentTo

check if this ColorBuffer is equivalent to other

open fun isEquivalentTo(other: ColorBuffer, ignoreWidth: Boolean = false, ignoreHeight: Boolean = false, ignoreContentScale: Boolean = false, ignoreFormat: Boolean = false, ignoreType: Boolean = false, ignoreMultisample: Boolean = false, ignoreLevels: Boolean = false): Boolean

read

read the contents of the ColorBuffer and write to targetBuffer, potentially with format and type conversions

abstract fun read(targetBuffer: ByteBuffer, targetFormat: ColorFormat = format, targetType: ColorType = type, level: Int = 0): Unit

saveToFile

save the ColorBuffer to File

abstract fun saveToFile(file: File, imageFileFormat: ImageFileFormat = ImageFileFormat.guessFromExtension(file), async: Boolean = true): Unit

toDataUrl

return a base64 data url representation

abstract fun toDataUrl(imageFileFormat: ImageFileFormat = ImageFileFormat.JPG): String

write

write the contents from sourceBuffer to the ColorBuffer, potentially with format and type conversions

abstract fun write(sourceBuffer: ByteBuffer, sourceFormat: ColorFormat = format, sourceType: ColorType = type, level: Int = 0): Unit

Companion Object Functions

fromArray

create a ColorBuffer from a ByteArray containing a formatted image (meaning any of the formats in ImageFileFormat)

fun fromArray(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size, formatHint: ImageFileFormat?, session: Session? = Session.active): ColorBuffer

fromBuffer

create a ColorBuffer from a ByteBuffer holding a formatted image (meaning any of the formats in ImageFileFormat

fun fromBuffer(bytes: ByteBuffer, formatHint: ImageFileFormat?, session: Session? = Session.active): ColorBuffer

fromFile

create a ColorBuffer from a File containing a formatted image

fun fromFile(file: File, formatHint: ImageFileFormat? = null, session: Session? = Session.active): ColorBuffer

create a ColorBuffer from a file indicated by filename containing a formatted image

fun fromFile(filename: String, formatHint: ImageFileFormat?, session: Session? = Session.active): ColorBuffer

fromStream

create a ColorBuffer from an InputStream containing a formatted image

fun fromStream(stream: InputStream, formatHint: ImageFileFormat? = null, session: Session? = Session.active): ColorBuffer

fromUrl

create a ColorBuffer from a File containing a formatted image

fun fromUrl(url: String, formatHint: ImageFileFormat? = null, session: Session? = Session.active): ColorBuffer

Extension Functions

imageBinding

fun ColorBuffer.imageBinding(level: Int = 0, imageAccess: ImageAccess): ColorBufferImageBinding