zgpu

git clone git://git.electrosoup.com/zgpu
Log | Files | Refs | Submodules | README

render_pass.zig (3111B)


      1 const c = @import("c.zig").c;
      2 const ChainedStruct = @import("common.zig").ChainedStruct;
      3 const Color = @import("common.zig").Color;
      4 const BindGroup = @import("bind_group.zig").BindGroup;
      5 const LoadOp = @import("common.zig").LoadOp;
      6 const RenderPipeline = @import("render_pipeline.zig").RenderPipeline;
      7 const StoreOp = @import("common.zig").StoreOp;
      8 const StringView = @import("common.zig").StringView;
      9 const TextureView = @import("texture_view.zig").TextureView;
     10 
     11 pub const depth_slice_undefined = 0xFFFFFFFF;
     12 
     13 pub const QuerySet = opaque {};
     14 
     15 pub const RenderPass = opaque {
     16     pub const Descriptor = extern struct {
     17         next: ?*ChainedStruct = null,
     18         label: StringView,
     19         color_attachment_count: usize,
     20         color_attachments: ?[*]const ColorAttachment,
     21         depth_stencil_attachment: ?*const DepthStencilAttachment,
     22         occlusion_query_set: ?*const QuerySet,
     23         timestamp_writes: ?*const TimestampWrites,
     24     };
     25 
     26     pub const ColorAttachment = extern struct {
     27         next: ?*ChainedStruct = null,
     28         view: ?*TextureView,
     29         // no other value is supported yet
     30         depth_slice: u32 = depth_slice_undefined,
     31         resolve_target: ?*TextureView,
     32         load_op: LoadOp,
     33         store_op: StoreOp,
     34         clear_value: Color,
     35     };
     36 
     37     pub const DepthStencilAttachment = extern struct {
     38         view: *TextureView,
     39         depth_load_op: LoadOp,
     40         depth_store_op: StoreOp,
     41         depth_clear_value: f32,
     42         depth_read_only: bool,
     43         stencil_load_op: LoadOp,
     44         stencil_store_op: StoreOp,
     45         stencil_clear_value: u32,
     46         stencil_read_only: bool,
     47     };
     48 
     49     pub const TimestampWrites = extern struct {
     50         query_set: ?*QuerySet,
     51         beginning_of_pass_write_index: u32,
     52         end_of_pass_write_index: u32,
     53     };
     54 };
     55 
     56 pub const RenderPassEncoder = opaque {
     57     pub fn release(encoder: *RenderPassEncoder) void {
     58         c.wgpuRenderPassEncoderRelease(@ptrCast(encoder));
     59     }
     60 
     61     pub fn end(encoder: *RenderPassEncoder) void {
     62         c.wgpuRenderPassEncoderEnd(@ptrCast(encoder));
     63     }
     64 
     65     pub fn setPipeline(
     66         encoder: *RenderPassEncoder,
     67         pipeline: *RenderPipeline,
     68     ) void {
     69         c.wgpuRenderPassEncoderSetPipeline(
     70             @ptrCast(encoder),
     71             @ptrCast(pipeline),
     72         );
     73     }
     74 
     75     pub fn setBindGroup(
     76         encoder: *RenderPassEncoder,
     77         group_index: u32,
     78         bind_group: *BindGroup,
     79         dynamic_offset_count: usize,
     80         dynamic_offsets: ?[*]u32,
     81     ) void {
     82         c.wgpuRenderPassEncoderSetBindGroup(
     83             @ptrCast(encoder),
     84             group_index,
     85             @ptrCast(bind_group),
     86             dynamic_offset_count,
     87             dynamic_offsets,
     88         );
     89     }
     90 
     91     pub fn draw(
     92         encoder: *RenderPassEncoder,
     93         vertex_count: u32,
     94         instance_count: u32,
     95         first_vertex: u32,
     96         first_instance: u32,
     97     ) void {
     98         c.wgpuRenderPassEncoderDraw(
     99             @ptrCast(encoder),
    100             vertex_count,
    101             instance_count,
    102             first_vertex,
    103             first_instance,
    104         );
    105     }
    106 };