Skip to content

Commit

Permalink
make dx11 backend compile
Browse files Browse the repository at this point in the history
Also add some extra debugging code to the sdl backend, because I'm
getting the wrong color order out on Windows.  Trying to figure it out.
  • Loading branch information
david-vanderson committed Dec 5, 2024
1 parent 22ab82f commit 3be6dc4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ fn addDvuiModule(
if (target.result.os.tag == .windows) {
// tinyfiledialogs needs this
dvui_mod.linkSystemLibrary("comdlg32", .{});
dvui_mod.linkSystemLibrary("ole32", .{});
}

const options = b.addOptions();
Expand Down
10 changes: 10 additions & 0 deletions src/backends/dx11_backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,16 @@ pub fn textureCreateTarget(self: *Dx11Backend, width: u32, height: u32, interpol
return error.TextureCreate;
}

pub fn textureRead(self: *Dx11Backend, texture: *anyopaque, pixels_out: [*]u8, width: u32, height: u32) error{TextureRead}!void {
_ = self;
_ = texture;
_ = pixels_out;
_ = width;
_ = height;
dvui.log.debug("dx11 textureRead unimplemented", .{});
return error.TextureRead;
}

pub fn textureDestroy(self: *Dx11Backend, texture: *anyopaque) void {
_ = self;
const tex: *dx.ID3D11Texture2D = @ptrCast(@alignCast(texture));
Expand Down
22 changes: 20 additions & 2 deletions src/backends/sdl_backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,30 @@ pub fn textureCreateTarget(self: *SDLBackend, width: u32, height: u32, interpola
return texture;
}

pub fn textureRead(self: *SDLBackend, texture: *anyopaque, pixels_out: [*]u8, width: u32, _: u32) error{TextureRead}!void {
pub fn textureRead(self: *SDLBackend, texture: *anyopaque, pixels_out: [*]u8, width: u32, height: u32) error{TextureRead}!void {
const orig_target = c.SDL_GetRenderTarget(self.renderer);
defer _ = c.SDL_SetRenderTarget(self.renderer, orig_target);

_ = c.SDL_SetRenderTarget(self.renderer, @ptrCast(texture));
var format: u32 = undefined;
var access: c_int = undefined;
var w: c_int = undefined;
var h: c_int = undefined;
_ = c.SDL_QueryTexture(@ptrCast(texture), &format, &access, &w, &h);
//std.debug.print("query texture: {s} {d} {d} {d} width {d}\n", .{c.SDL_GetPixelFormatName(format), access, w, h, width});
_ = c.SDL_RenderReadPixels(self.renderer, null, 0, pixels_out, @intCast(width * 4));

//for (0..width * height) |i| {
// const r = pixels_out[i * 4 + 0];
// const g = pixels_out[i * 4 + 1];
// const b = pixels_out[i * 4 + 2];
// pixels_out[i * 4 + 0] = b;
// pixels_out[i * 4 + 1] = g;
// pixels_out[i * 4 + 2] = r;
//}

//_ = c.SDL_ConvertPixels(@intCast(width), @intCast(height), format, pixels_out, @intCast(width * 4), c.SDL_PIXELFORMAT_ARGB8888, pixels_out, @intCast(width * 4));

_ = c.SDL_SetRenderTarget(self.renderer, orig_target);
}

pub fn textureDestroy(_: *SDLBackend, texture: *anyopaque) void {
Expand Down

0 comments on commit 3be6dc4

Please sign in to comment.