abstract class Tessell::Render::Backend

Direct Known Subclasses

Defined in:

tessell/render/backend.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.text_batch_end(size : Int32, batch_count : Int32, from_batch : Int32) : Int32 #

文本批区间语义(issue #50/#52):draw_text 的 batch_count 是"本次提交的 批数量",不是排他结束索引——实际绘制区间是 [from_batch, min(from_batch + batch_count, size))。from_batch=0 时与旧实现 相同,交错提交(issue #15)时才算得对。负的 count 夹成空区间。 加法先加宽到 Int64:Int32 溢出检查(Crystal 1.22)会让 from_batch=1 + batch_count=Int32::MAX 在钳制前抛 OverflowError。


[View source]

Instance Method Detail

abstract def begin_frame(dirty : Array(Tessell::Rect) | Nil = nil, theme : Tessell::Render::Theme = Tessell::Render::Theme.light) : Nil #

[View source]
abstract def close : Nil #

[View source]
def create_texture(width : Int32, height : Int32, pixels : Bytes) : Int32 #

创建外部纹理;返回 handle(≥1,独立命名空间)。基类返回 0 = 不支持 (仿 draw_polygon 先例),实现方必须返回非 0。


[View source]
def destroy_texture(handle : Int32) : Nil #

销毁外部纹理;handle 失效后再绘制 Image 命令属应用层错误。


[View source]
def draw_draw_list(list : Tessell::Render::DrawList, from : Int32 = 0, count : Int32 = -1) : Int32 #

Draw a command list. Backends that support 2D primitives implement this; base returns 0 = unsupported rather than silently claiming success. Text commands are skipped here (rendered via draw_text) so a host can interleave shape/text segments in command order. from/count select a sub-range of the list (count < 0 = to the end). Returns number of non-text commands actually submitted.


[View source]
def draw_polygon(points : Array(Tessell::Point), color : UInt32, even_odd : Bool = true) : Bool #

Fill a polygon using stencil/cover when supported (e.g. GLBackend). points are in screen space, color is premultiplied RGBA8, and even_odd selects fill rule (true = even-odd). Base returns false = unsupported; backends that perform the fill must return true and account stencil_fills in stats.


[View source]
abstract def draw_text(vertices : Array(Vertex), batches : Array(TextBatch), batch_count : Int32 = batches.size, from_batch : Int32 = 0, clip : Tessell::Rect | Nil = nil) : Int32 #

Issue #15 contract: text is part of the command order — a host may draw text segments interleaved with draw_draw_list segments. from_batch selects the unsubmitted suffix of batches; clip restricts the text segment to a scissor rect (nil = unclipped). Return value = quads submitted by THIS call (delta, issue #46); stats.submitted_quads is the FRAME cumulative total (reset only in begin_frame) — interleaved submissions accumulate, never reset.


[View source]
abstract def end_frame : Nil #

[View source]
abstract def init(width : Int32, height : Int32) : Nil #

[View source]
abstract def resize(width : Int32, height : Int32) : Nil #

[View source]
def resolved_texture(page : Int32, color : Bool) : Int32 #

Color-page resolution: batches carrying color=true read RGBA atlas pages. Backends without RGBA pages fall back to the R8 resolution (gray semantics).


[View source]
abstract def resolved_texture(page : Int32) : Int32 #

[View source]
def resolved_texture_external(handle : Int32) : Int32 #

外部纹理 handle 解析(独立命名空间,不与 glyph atlas 页号混用)。 基类返回 0 = 不支持;软件后端返回内部引用键。


[View source]
abstract def stats : FrameStats #

[View source]
abstract def sync_atlas(atlas : Text::GlyphAtlas) : Nil #

全量重传 glyph atlas 所有页(冷启动/整体重建用)。动态文本场景禁止 每帧调用——增量路径走 sync_atlas_dirty(issue #22)。


[View source]
def sync_atlas_dirty(atlas : Text::GlyphAtlas) : Nil #

增量 glyph atlas 同步(issue #22):只上传内容 revision 变化的页。 宿主按 Backend 抽象编程即可每帧调用——有增量实现的后端(GL)在 atlas 未变化时是 no-op;基类默认退化为全量 sync_atlas,第三方后端 不必强制实现。禁止用 page_count 比较自行判断是否同步(issue #1 口径)。


[View source]
def update_texture(handle : Int32, x : Int32, y : Int32, width : Int32, height : Int32, pixels : Bytes) : Nil #

增量区域上传(GL 走 glTexSubImage2D 同型链路)。基类 no-op。


[View source]