TextureProtocol
public protocol TextureProtocol
The TextureProtocol
protocol exposes the methods and properties of an underlying CoglTexture
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Texture
.
Alternatively, use TextureRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
CoglTexture
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
texture_ptr
Default implementationTyped pointer to the underlying
CoglTexture
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
CoglTexture
instance.Declaration
Swift
var texture_ptr: UnsafeMutablePointer<CoglTexture>! { get }
-
Required Initialiser for types conforming to
TextureProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
allocate()
Extension methodExplicitly allocates the storage for the given
texture
which allows you to be sure that there is enough memory for the texture and if not then the error can be handled gracefully.<note>Normally applications don’t need to use this api directly since the texture will be implicitly allocated when data is set on the texture, or if the texture is attached to a
CoglOffscreen
framebuffer and rendered too.</note>Declaration
Swift
@inlinable func allocate() throws -> CoglBool
-
getComponents()
Extension methodQueries what components the given
texture
stores internally as set viacogl_texture_set_components()
.For textures created by the ‘_with_size’ constructors the default is
COGL_TEXTURE_COMPONENTS_RGBA
. The other constructors which take aCoglBitmap
or a data pointer default to the same components as the pixel format of the data.Declaration
Swift
@inlinable func getComponents() -> CoglTextureComponents
-
getData(format:
Extension methodrowstride: data: ) Copies the pixel data from a cogl texture to system memory.
<note>Don’t pass the value of
cogl_texture_get_rowstride()
as therowstride
argument, the rowstride should be the rowstride you want for the destinationdata
buffer not the rowstride of the source texture</note>Declaration
Swift
@inlinable func getData(format: CoglPixelFormat, rowstride: Int, data: UnsafeMutablePointer<UInt8>!) -> Int
-
getGlTexture(outGlHandle:
Extension methodoutGlTarget: ) Queries the GL handles for a GPU side texture through its
CoglTexture
.If the texture is spliced the data for the first sub texture will be queried.
Declaration
Swift
@inlinable func getGlTexture(outGlHandle: UnsafeMutablePointer<guint>! = nil, outGlTarget: UnsafeMutablePointer<guint>! = nil) -> CoglBool
-
getHeight()
Extension methodQueries the height of a cogl texture.
Declaration
Swift
@inlinable func getHeight() -> Int
-
getMaxWaste()
Extension methodQueries the maximum wasted (unused) pixels in one dimension of a GPU side texture.
Declaration
Swift
@inlinable func getMaxWaste() -> Int
-
getPremultiplied()
Extension methodQueries the pre-multiplied alpha status for internally stored red, green and blue components for the given
texture
as set bycogl_texture_set_premultiplied()
.By default the pre-multipled state is
TRUE
.Declaration
Swift
@inlinable func getPremultiplied() -> CoglBool
-
getWidth()
Extension methodQueries the width of a cogl texture.
Declaration
Swift
@inlinable func getWidth() -> Int
-
set(components:
Extension method) Affects the internal storage format for this texture by specifying what components will be required for sampling later.
This api affects how data is uploaded to the GPU since unused components can potentially be discarded from source data.
For textures created by the ‘_with_size’ constructors the default is
COGL_TEXTURE_COMPONENTS_RGBA
. The other constructors which take aCoglBitmap
or a data pointer default to the same components as the pixel format of the data.Note that the
COGL_TEXTURE_COMPONENTS_RG
format is not available on all drivers. The availability can be determined by checking for theCOGL_FEATURE_ID_TEXTURE_RG
feature. If this format is used on a driver where it is not available thenCOGL_TEXTURE_ERROR_FORMAT
will be raised when the texture is allocated. Even if the feature is not available thenCOGL_PIXEL_FORMAT_RG_88
can still be used as an image format as long asCOGL_TEXTURE_COMPONENTS_RG
isn’t used as the texture’s components.Declaration
Swift
@inlinable func set(components: CoglTextureComponents)
-
set(premultiplied:
Extension method) Affects the internal storage format for this texture by specifying whether red, green and blue color components should be stored as pre-multiplied alpha values.
This api affects how data is uploaded to the GPU since Cogl will convert source data to have premultiplied or unpremultiplied components according to this state.
For example if you create a texture via
cogl_texture_2d_new_with_size()
and then upload data viacogl_texture_set_data()
passing a source format ofCOGL_PIXEL_FORMAT_RGBA_8888
then Cogl will internally multiply the red, green and blue components of the source data by the alpha component, for each pixel so that the internally stored data has pre-multiplied alpha components. If you instead upload data that already has pre-multiplied components by passingCOGL_PIXEL_FORMAT_RGBA_8888_PRE
as the source format tocogl_texture_set_data()
then the data can be uploaded without being converted.By default the
premultipled
state isTRUE
.Declaration
Swift
@inlinable func set(premultiplied: CoglBool)
-
setRegion(srcX:
Extension methodsrcY: dstX: dstY: dstWidth: dstHeight: width: height: format: rowstride: data: ) Sets the pixels in a rectangular subregion of
texture
from an in-memory buffer containing pixel data.<note>The region set can’t be larger than the source
data
</note>Declaration
Swift
@inlinable func setRegion(srcX: Int, srcY: Int, dstX: Int, dstY: Int, dstWidth: Int, dstHeight: Int, width: Int, height: Int, format: CoglPixelFormat, rowstride: Int, data: UnsafePointer<UInt8>!) -> CoglBool
-
setSourceTexture()
Extension methodThis is a convenience function for creating a material with the first layer set to
texture
and setting that material as the source with cogl_set_source.Note: There is no interaction between calls to cogl_set_source_color and cogl_set_source_texture. If you need to blend a texture with a color then you can create a simple material like this: <programlisting> material = cogl_material_new (); cogl_material_set_color4ub (material, 0xff, 0x00, 0x00, 0x80); cogl_material_set_layer (material, 0, tex_handle); cogl_set_source (material); </programlisting>
set_source_texture is deprecated: Latest drawing apis all take an explicit #CoglPipeline argument so this stack of #CoglMaterial<!– –>s shouldn’t be used.
Declaration
Swift
@available(*, deprecated) @inlinable func setSourceTexture()
-
components
Extension methodQueries what components the given
texture
stores internally as set viacogl_texture_set_components()
.For textures created by the ‘_with_size’ constructors the default is
COGL_TEXTURE_COMPONENTS_RGBA
. The other constructors which take aCoglBitmap
or a data pointer default to the same components as the pixel format of the data.Declaration
Swift
@inlinable var components: CoglTextureComponents { get nonmutating set }
-
height
Extension methodQueries the height of a cogl texture.
Declaration
Swift
@inlinable var height: Int { get }
-
isSliced
Extension methodQueries if a texture is sliced (stored as multiple GPU side tecture objects).
Declaration
Swift
@inlinable var isSliced: CoglBool { get }
-
maxWaste
Extension methodQueries the maximum wasted (unused) pixels in one dimension of a GPU side texture.
Declaration
Swift
@inlinable var maxWaste: Int { get }
-
premultiplied
Extension methodQueries the pre-multiplied alpha status for internally stored red, green and blue components for the given
texture
as set bycogl_texture_set_premultiplied()
.By default the pre-multipled state is
TRUE
.Declaration
Swift
@inlinable var premultiplied: CoglBool { get nonmutating set }
-
width
Extension methodQueries the width of a cogl texture.
Declaration
Swift
@inlinable var width: Int { get }