abstract class Eagle::GPU::Device

Overview

The interface every graphics backend implements. Custom rendering code can call it through GPU.device, but prefer Graphics, Shader, Texture and Mesh, which handle state and batching for you.

Defined in:

eagle/gpu/device.cr

Instance Method Summary

Instance Method Detail

abstract def bind_render_target(target : RenderTargetHandle | Nil) : Nil #

Draws into target, or the screen with nil.


abstract def bind_texture(unit : Int32, id : UInt32) : Nil #

Binds a texture to a sampler unit.


abstract def blend_mode(mode : BlendMode) : Nil #

Sets the blend mode.


abstract def check_errors(where : String = "") : Nil #

Logs any pending GPU errors, tagged with where. Enable with EAGLE_GL_DEBUG=1.


abstract def clear(color : Color | Nil = nil, depth : Bool = false, stencil : Bool = false) : Nil #

--- frame state --- Clears the current target's color, depth and stencil as requested.


abstract def create_depth_target(w : Int32, h : Int32) : RenderTargetHandle #

Creates a depth-only target whose depth can be sampled, for shadow maps.


abstract def create_geometry(layout : VertexLayout) : UInt32 #

--- geometry (vertex + index buffers with a layout) --- Creates vertex and index buffers for a layout.


abstract def create_program(vertex : String, fragment : String, attribs : Array(String)) : UInt32 #

--- programs --- Compiles and links a shader program. Raises ShaderError on failure.


abstract def create_render_target(w : Int32, h : Int32, depth : Bool, filter : Filter) : RenderTargetHandle #

--- render targets --- Creates an off-screen color target, optionally with depth.


abstract def create_texture(w : Int32, h : Int32, format : PixelFormat, data : Bytes | Nil, filter : Filter, wrap : Wrap, mipmaps : Bool) : UInt32 #

--- textures --- Creates a texture, optionally with initial pixels.


abstract def cull(mode : CullMode) : Nil #

Sets which faces are culled.


abstract def current_target : RenderTargetHandle | Nil #

The target being drawn into, or nil for the screen.


abstract def delete_geometry(geom : UInt32) : Nil #

Frees geometry buffers.


abstract def delete_program(id : UInt32) : Nil #

Frees a shader program.


abstract def delete_render_target(target : RenderTargetHandle) : Nil #

Frees a render target.


abstract def delete_texture(id : UInt32) : Nil #

Frees a texture.


abstract def depth_test(enabled : Bool, write : Bool = true, func : DepthFunc = DepthFunc::Less) : Nil #

Configures depth testing and depth writes.


abstract def draw(geom : UInt32, primitive : Primitive, count : Int32, offset : Int32 = 0, indexed : Bool = false, instances : Int32 = 1) : Nil #

Draws geometry.


def emulate_wireframe? : Bool #

True on backends without wireframe fill modes, such as WebGL. Meshes then draw their edges as lines.


abstract def front_face_ccw(ccw : Bool) : Nil #

Sets whether counter-clockwise triangles face forward.


abstract def max_texture_size : Int32 #

Largest texture width or height the GPU supports.


abstract def name : String #

Human-readable backend and driver name, as logged at startup.


abstract def read_pixels(x : Int32, y : Int32, w : Int32, h : Int32) : Bytes #

Reads RGBA pixels back from the current target.


abstract def scissor(rect : Rect | Nil, framebuffer_height : Int32) : Nil #

Clips drawing to rect, or turns clipping off with nil.


abstract def set_uniform(location : Int32, value : UniformValue) : Nil #

Sets a uniform on the current program.


abstract def shader_prelude(stage : Symbol) : String #

The #version line and precision statements added to shaders for stage.


abstract def texture_params(id : UInt32, filter : Filter, wrap : Wrap, mipmaps : Bool) : Nil #

Changes filtering, wrapping and mipmaps.


abstract def uniform_location(program : UInt32, name : String) : Int32 #

Looks up a uniform, returning -1 when the program doesn't use it.


abstract def update_texture(id : UInt32, x : Int32, y : Int32, w : Int32, h : Int32, format : PixelFormat, data : Bytes) : Nil #

Replaces part of a texture.


abstract def upload_indices(geom : UInt32, data : Slice(UInt32), usage : Usage) : Nil #

Uploads triangle indices.


abstract def upload_vertices(geom : UInt32, data : Slice(Float32), usage : Usage) : Nil #

Uploads vertex data as floats.


abstract def upload_vertices(geom : UInt32, data : Bytes, usage : Usage) : Nil #

Uploads vertex data as raw bytes.


abstract def use_program(id : UInt32) : Nil #

Makes a program current.


abstract def viewport(x : Int32, y : Int32, w : Int32, h : Int32) : Nil #

Sets the drawing area in pixels.


abstract def wireframe(enabled : Bool) : Nil #

Turns wireframe rendering on or off where supported.


def wireframe? : Bool #

True while wireframe rendering is on.