Skip to content

Commit

Permalink
fix quad-wgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 13, 2023
1 parent 0b6faca commit 80e970e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 43 deletions.
11 changes: 5 additions & 6 deletions wgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ fips_begin_app(triangle-wgpu windowed)
fips_deps(wgpu_entry)
fips_end_app()

#fips_begin_app(quad-wgpu windowed)
# fips_files(quad-wgpu.c)
# sokol_shader(quad-wgpu.glsl wgpu)
# fips_deps(wgpu_entry)
#fips_end_app()
#
fips_begin_app(quad-wgpu windowed)
fips_files(quad-wgpu.c)
fips_deps(wgpu_entry)
fips_end_app()

#fips_begin_app(bufferoffsets-wgpu windowed)
# fips_files(bufferoffsets-wgpu.c)
# sokol_shader(bufferoffsets-wgpu.glsl wgpu)
Expand Down
39 changes: 27 additions & 12 deletions wgpu/quad-wgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
// quad-wgpu.c
// Simple 2D rendering with vertex- and index-buffer.
//------------------------------------------------------------------------------
#include "wgpu_entry.h"
#define SOKOL_IMPL
#define SOKOL_WGPU
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "wgpu_entry.h"
#include "quad-wgpu.glsl.h"

static struct {
sg_pass_action pass_action;
sg_pipeline pip;
sg_bindings bind;
} state = {
.pass_action = {
.colors[0] = { .action=SG_ACTION_CLEAR, .value={0.0f, 0.0f, 0.0f, 1.0f } }
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.0f, 0.0f, 0.0f, 1.0f } }
}
};

Expand All @@ -25,8 +24,8 @@ void init(void) {
.logger.func = slog_func,
});

/* a vertex buffer */
float vertices[] = {
// a vertex buffer
const float vertices[] = {
// positions colors
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f,
Expand All @@ -38,25 +37,41 @@ void init(void) {
.label = "quad-vertices"
});

/* an index buffer with 2 triangles */
uint16_t indices[] = { 0, 1, 2, 0, 2, 3 };
// an index buffer with 2 triangles
const uint16_t indices[] = { 0, 1, 2, 0, 2, 3 };
state.bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){
.type = SG_BUFFERTYPE_INDEXBUFFER,
.data = SG_RANGE(indices),
.label = "quad-indices"
});

/* a shader (use separate shader sources here */
sg_shader shd = sg_make_shader(quad_shader_desc(sg_query_backend()));
// a shader object with wgsl shader code
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",
});

/* a pipeline state object */
// a pipeline state object
state.pip = sg_make_pipeline(&(sg_pipeline_desc){
.shader = shd,
.index_type = SG_INDEXTYPE_UINT16,
.layout = {
.attrs = {
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4
[0].format = SG_VERTEXFORMAT_FLOAT3,
[1].format = SG_VERTEXFORMAT_FLOAT4
}
},
.label = "quad-pipeline"
Expand Down
25 changes: 0 additions & 25 deletions wgpu/quad-wgpu.glsl

This file was deleted.

1 change: 1 addition & 0 deletions wgpu/triangle-wgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static void init(void) {
.data = SG_RANGE(vertices)
});

// a shader object with wgsl shader code
sg_shader shd = sg_make_shader(&(sg_shader_desc){
.vs.source =
"struct vs_out {\n"
Expand Down

0 comments on commit 80e970e

Please sign in to comment.