Переход к RenderEngine

This commit is contained in:
2025-12-21 17:26:19 +03:00
parent 6f58967049
commit 3ac35a5046
11 changed files with 138 additions and 33 deletions

View File

@@ -0,0 +1,46 @@
const std = @import("std");
const builtin = @import("builtin");
const dvui = @import("dvui");
const RenderEngine = @import("RenderEngine.zig").RenderEngine;
const rast_models = @import("../models/rasterization_models.zig");
const ImageSize = rast_models.ImageSize;
const ImageRect = rast_models.ImageRect;
const Allocator = std.mem.Allocator;
const Color = dvui.Color;
const CpuRenderEngine = @This();
const Type = enum {
Gradient,
Squares,
};
type: Type,
_allocator: Allocator,
gradient_start: Color.PMA = .{ .r = 0, .g = 0, .b = 0, .a = 255 },
gradient_end: Color.PMA = .{ .r = 255, .g = 255, .b = 255, .a = 255 },
pub fn init(allocator: Allocator, render_type: Type) CpuRenderEngine {
return .{
._allocator = allocator,
.type = render_type,
};
}
pub fn exampleReset(self: *CpuRenderEngine) void {
// Сгенерировать случайные цвета градиента
var prng = std.Random.DefaultPrng.init(@intCast(std.time.microTimestamp()));
const random = prng.random();
self.gradient_start = Color.PMA{ .r = random.int(u8), .g = random.int(u8), .b = random.int(u8), .a = 255 };
self.gradient_end = Color.PMA{ .r = random.int(u8), .g = random.int(u8), .b = random.int(u8), .a = 255 };
}
pub fn example(self: CpuRenderEngine, canvas_size: ImageSize, visible_rect: ImageRect) !?dvui.Texture {
_ = self;
_ = canvas_size;
_ = visible_rect;
return null;
}
pub fn renderEngine(self: *CpuRenderEngine) RenderEngine {
return .{ .cpu = self };
}