Skip to content

Commit

Permalink
triangle-wgpu: embed shader code into sample
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 3, 2023
1 parent 5599ddc commit 333b251
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
1 change: 0 additions & 1 deletion wgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fips_end_app()

fips_begin_app(triangle-wgpu windowed)
fips_files(triangle-wgpu.c)
sokol_shader(triangle-wgpu.glsl wgsl)
fips_deps(wgpu_entry)
fips_end_app()

Expand Down
22 changes: 18 additions & 4 deletions wgpu/triangle-wgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define SOKOL_WGPU
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "triangle-wgpu.glsl.h"

static struct {
sg_pipeline pip;
Expand Down Expand Up @@ -36,8 +35,23 @@ static void init(void) {
.data = SG_RANGE(vertices)
});

// FIXME: use WGSL directly here, not sokol-shdc
sg_shader shd = sg_make_shader(triangle_shader_desc(sg_query_backend()));
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.vs.source =
"struct vs_out {\n"
" @builtin(position) pos: vec4f,\n"
" @location(0) color: vec4f,\n"
"}\n"
"@vertex fn main(@location(0) pos: vec4f, @location(1) color: vec4f) -> vs_out {\n"
" var out: vs_out;\n"
" out.pos = pos;\n"
" out.color = color;\n"
" return out;\n"
"}\n",
.fs.source =
"@fragment fn main(@location(0) color: vec4f) -> @location(0) vec4f {\n"
" return color;\n"
"}\n",
});

// create a pipeline object (default render states are fine for triangle)
state.pip = sg_make_pipeline(&(sg_pipeline_desc){
Expand All @@ -46,7 +60,7 @@ static void init(void) {
.attrs = {
[0].format=SG_VERTEXFORMAT_FLOAT3,
[1].format=SG_VERTEXFORMAT_FLOAT4
}
},
},
});
}
Expand Down
22 changes: 0 additions & 22 deletions wgpu/triangle-wgpu.glsl

This file was deleted.

0 comments on commit 333b251

Please sign in to comment.