Skip to content

Commit

Permalink
Merge pull request #57 from Interrupt/features/images-as-values
Browse files Browse the repository at this point in the history
During texture creation, images are now passed as values and not pointers
  • Loading branch information
Interrupt authored Sep 24, 2024
2 parents d5cd402 + 6239a79 commit 543dc7b
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/examples/debugdraw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn on_init() !void {
debug.log("Could not load test texture", .{});
return;
};
texture = graphics.Texture.init(&test_image);
texture = graphics.Texture.init(test_image);

graphics.setClearColor(colors.examples_bg_dark);
}
Expand Down
2 changes: 1 addition & 1 deletion src/examples/easing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn on_init() !void {
debug.log("Could not load test texture", .{});
return;
};
texture = graphics.Texture.init(&test_image);
texture = graphics.Texture.init(test_image);
}

fn on_tick(delta: f32) void {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/forest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn on_init() !void {
return;
};

tex_treesheet = graphics.Texture.init(&treesheet_img);
tex_treesheet = graphics.Texture.init(treesheet_img);

// make our default shader
shader_blend = try graphics.Shader.initDefault(.{ .blend_mode = .NONE, .cull_mode = .NONE });
Expand Down
2 changes: 1 addition & 1 deletion src/examples/framepacing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn on_init() !void {
debug.log("Could not load test texture", .{});
return;
};
texture = graphics.Texture.init(&test_image);
texture = graphics.Texture.init(test_image);
}

fn on_tick(delta: f32) void {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/lighting.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn on_init() !void {

var base_img: images.Image = try images.loadFile(mesh_texture_file);
defer base_img.deinit();
const tex_base = graphics.Texture.init(&base_img);
const tex_base = graphics.Texture.init(base_img);

// Create a material out of our shader and textures
skinned_mesh_material = try delve.platform.graphics.Material.init(.{
Expand Down
2 changes: 1 addition & 1 deletion src/examples/meshbuilder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn on_init() !void {
return;
};
defer img.deinit();
const tex = graphics.Texture.init(&img);
const tex = graphics.Texture.init(img);

const shader = try graphics.Shader.initFromBuiltin(.{ .vertex_attributes = delve.graphics.mesh.getShaderAttributes() }, delve.shaders.default_mesh);

Expand Down
4 changes: 2 additions & 2 deletions src/examples/meshes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn on_init() !void {
return;
};
defer base_img.deinit();
const tex_base = graphics.Texture.init(&base_img);
const tex_base = graphics.Texture.init(base_img);

// Load the emissive texture for the mesh
const emissive_texture_file = "assets/meshes/SciFiHelmet_Emissive_512.png";
Expand All @@ -87,7 +87,7 @@ fn on_init() !void {
return;
};
defer emissive_img.deinit();
const tex_emissive = graphics.Texture.init(&emissive_img);
const tex_emissive = graphics.Texture.init(emissive_img);

// Make our emissive shader from one that is pre-compiled
shader = try graphics.Shader.initFromBuiltin(.{ .vertex_attributes = mesh.getShaderAttributes() }, emissive_shader_builtin);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/passes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ pub fn on_init() !void {
return;
};
defer img.deinit();
const tex = graphics.Texture.init(&img);
const tex = graphics.Texture.init(img);

// Create our offscreen passes
offscreen_pass = graphics.RenderPass.init(.{ .width = 1024, .height = 768 });
offscreen_pass_2 = graphics.RenderPass.init(.{ .width = 640, .height = 480 });

shader = delve.platform.graphics.Shader.initFromBuiltin(.{ .vertex_attributes = delve.graphics.mesh.getShaderAttributes() }, delve.shaders.default_mesh).?;
shader = try delve.platform.graphics.Shader.initFromBuiltin(.{ .vertex_attributes = delve.graphics.mesh.getShaderAttributes() }, delve.shaders.default_mesh);

// Create a material out of the texture
material1 = try graphics.Material.init(.{
Expand Down
2 changes: 1 addition & 1 deletion src/examples/quakemap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn on_init() !void {
continue;
};
defer tex_img.deinit();
const tex = graphics.Texture.init(&tex_img);
const tex = graphics.Texture.init(tex_img);

const mat = try graphics.Material.init(.{
.shader = shader,
Expand Down
2 changes: 1 addition & 1 deletion src/examples/skinned-meshes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn on_init() !void {
};
defer base_img.deinit();

const tex_base = graphics.Texture.init(&base_img);
const tex_base = graphics.Texture.init(base_img);

// Create a material out of our shader and textures
material = try delve.platform.graphics.Material.init(.{
Expand Down
2 changes: 1 addition & 1 deletion src/examples/sprite-animation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn on_init() !void {
defer spritesheet_image.deinit();

// make the texture to draw
sprite_texture = graphics.Texture.init(&spritesheet_image);
sprite_texture = graphics.Texture.init(spritesheet_image);

// Load the default shader, but from a Yaml description file!
const loaded_shader = try delve.graphics.shaders.loadFromYaml(.{}, "assets/shaders/built/default/default_reflection.yaml");
Expand Down
4 changes: 2 additions & 2 deletions src/examples/sprites.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ fn on_init() !void {
defer test_image_2.deinit();

// make some textures from our images
texture_1 = graphics.Texture.init(&test_image_1);
texture_2 = graphics.Texture.init(&test_image_2);
texture_1 = graphics.Texture.init(test_image_1);
texture_2 = graphics.Texture.init(test_image_2);

// make some shaders for testing
shader_opaque = try graphics.Shader.initDefault(.{});
Expand Down
4 changes: 2 additions & 2 deletions src/framework/api/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn get_texture(filename: [*:0]const u8) i64 {
const filename_len = filename_idx;

debug.log("Assets: Loading Image: {s}...", .{filename});
var new_img: images.Image = images.loadFile(filename[0..filename_len :0]) catch {
const new_img: images.Image = images.loadFile(filename[0..filename_len :0]) catch {
debug.log("Assets: Error loading image asset: {s}", .{filename});
return -1;
};
Expand All @@ -55,7 +55,7 @@ pub fn get_texture(filename: [*:0]const u8) i64 {
return -1;
};

const texture = graphics.Texture.init(&new_img);
const texture = graphics.Texture.init(new_img);
texture_handles.put(new_handle, texture) catch {
debug.log("Assets: Error caching loaded texture!", .{});
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/framework/platform/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub const Texture = struct {
sokol_image: ?sg.Image,

/// Creates a new texture from an Image
pub fn init(image: *images.Image) Texture {
pub fn init(image: images.Image) Texture {
defer next_texture_handle += 1;

var img_desc: sg.ImageDesc = .{
Expand Down

0 comments on commit 543dc7b

Please sign in to comment.