Skip to content

Commit

Permalink
wgpu updates wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Jul 30, 2023
1 parent 36873a4 commit 8d74220
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
25 changes: 22 additions & 3 deletions wgpu/clear-wgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@
// clear-wgpu.c
// Simple draw loop, clear default framebuffer.
//------------------------------------------------------------------------------
#define SOKOL_IMPL
#define SOKOL_WGPU
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "wgpu_entry.h"

static sg_pass_action pass_action;

static void init(void) {
// FIXME
sg_setup(&(sg_desc){
.context = wgpu_get_context(),
.logger.func = slog_func,
});
pass_action = (sg_pass_action) {
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR,
.clear_value = { 1.0f, 0.0f, 0.0f, 1.0f }
}
};
}

static void frame(void) {
// FIXME
float g = pass_action.colors[0].clear_value.g + 0.01f;
pass_action.colors[0].clear_value.g = (g > 1.0f) ? 0.0f : g;
sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
sg_end_pass();
sg_commit();
}

static void shutdown(void) {
// FIXME
sg_shutdown();
}

int main() {
Expand Down
7 changes: 4 additions & 3 deletions wgpu/wgpu_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,16 @@ static const void* wgpu_get_depth_stencil_view(void* user_data) {

static sg_pixel_format wgpu_get_color_format(void) {
switch (state.render_format) {
case WGPUTextureFormat_RGBA8Unorm: return SG_PIXELFORMAT_RGBA8;
case WGPUTextureFormat_BGRA8Unorm: return SG_PIXELFORMAT_BGRA8;
default: return SG_PIXELFORMAT_NONE;
case WGPUTextureFormat_RGBA8Unorm: return SG_PIXELFORMAT_RGBA8;
case WGPUTextureFormat_BGRA8Unorm: return SG_PIXELFORMAT_BGRA8;
default: return SG_PIXELFORMAT_NONE;
}
}

sg_context_desc wgpu_get_context(void) {
return (sg_context_desc) {
.color_format = wgpu_get_color_format(),
.depth_format = SG_PIXELFORMAT_DEPTH_STENCIL,
.sample_count = state.desc.sample_count,
.wgpu = {
.device = (const void*) state.device,
Expand Down

0 comments on commit 8d74220

Please sign in to comment.