Skip to content

Commit 6ef9729

Browse files
committed
feat: support latest sokol
1 parent fac5d08 commit 6ef9729

File tree

79 files changed

+768
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+768
-706
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ To enable web builds you need to setup the [emscripten](https://emscripten.org/i
4747

4848
#### Todo
4949

50-
- [ ] [4-5-4-sharpen](src/4-5-framebuffers/4-sharpen.c)
51-
- [ ] [4-5-5-blur](src/4-5-framebuffers/5-blur.c)
52-
- [ ] [4-10-1-instancing](src/4-10-instancing/1-instancing.c)
50+
- [ ] [4-1-4](src\4-1-depth-testing\4-linear-depth-buffer.c) 颜色偏黑了
51+
- [ ] [4-2-1](src\4-2-stencil-testing\1-object-outlining.c) 直接就绿色正方体了,纹理没有
52+
- [ ] [4-8-1](src\4-8-advanced-glsl\1-point-size.c) dx 下点比 gl 的小
53+
- [ ] 5-3 dx 光源不对
54+
- [x] 4-5 gl 与 dx 的 plane.model 坐标不相同

generate_properites.lua

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function main()
2+
local package_file = '.xmake/'..os.host()..'/'..os.arch()..'/cache/package'
3+
local packages = io.load(package_file)
4+
local all_sysincludedirs = {}
5+
for name, package in pairs(packages) do
6+
local sysincludedirs = package.sysincludedirs
7+
if sysincludedirs == nil then
8+
goto continue
9+
end
10+
if type(sysincludedirs) == 'table' then
11+
for _, sysincludedir in ipairs(sysincludedirs) do
12+
table.insert(all_sysincludedirs, sysincludedir)
13+
end
14+
else
15+
table.insert(all_sysincludedirs, sysincludedirs)
16+
end
17+
::continue::
18+
end
19+
for _, sysincludedir in ipairs(all_sysincludedirs) do
20+
print(string.format('"%s",', sysincludedir:gsub('\\', '/')))
21+
end
22+
end

src/1-6-textures/1-texture.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void init(void) {
4848
Any draw calls containing such an "incomplete" image handle
4949
will be silently dropped.
5050
*/
51-
sg_alloc_image_smp(state.bind.fs, SLOT__ourTexture, SLOT_ourTexture_smp);
51+
sg_alloc_image_smp(state.bind, IMG__ourTexture, SMP_ourTexture_smp);
5252

5353
float vertices[] = {
5454
// positions // colors // texture coords
@@ -85,9 +85,9 @@ static void init(void) {
8585
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
8686
.layout = {
8787
.attrs = {
88-
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
89-
[ATTR_vs_aColor].format = SG_VERTEXFORMAT_FLOAT3,
90-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
88+
[ATTR_simple_position].format = SG_VERTEXFORMAT_FLOAT3,
89+
[ATTR_simple_aColor].format = SG_VERTEXFORMAT_FLOAT3,
90+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
9191
}
9292
},
9393
.label = "triangle-pipeline"
@@ -123,7 +123,7 @@ static void fetch_callback(const sfetch_response_t* response) {
123123
&num_channels, desired_channels);
124124
if (pixels) {
125125
/* initialize the sokol-gfx texture */
126-
sg_init_image(state.bind.fs.images[SLOT__ourTexture], &(sg_image_desc){
126+
sg_init_image(state.bind.images[IMG__ourTexture], &(sg_image_desc){
127127
.width = img_width,
128128
.height = img_height,
129129
/* set pixel_format to RGBA8 for WebGL */

src/1-6-textures/2-texture-blend.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void init(void) {
4040
Any draw calls containing such an "incomplete" image handle
4141
will be silently dropped.
4242
*/
43-
sg_alloc_image_smp(state.bind.fs, SLOT__ourTexture, SLOT_ourTexture_smp);
43+
sg_alloc_image_smp(state.bind, IMG__ourTexture, SMP_ourTexture_smp);
4444

4545
float vertices[] = {
4646
// positions // colors // texture coords
@@ -77,9 +77,9 @@ static void init(void) {
7777
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
7878
.layout = {
7979
.attrs = {
80-
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
81-
[ATTR_vs_aColor].format = SG_VERTEXFORMAT_FLOAT3,
82-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
80+
[ATTR_simple_position].format = SG_VERTEXFORMAT_FLOAT3,
81+
[ATTR_simple_aColor].format = SG_VERTEXFORMAT_FLOAT3,
82+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
8383
}
8484
},
8585
.label = "triangle-pipeline"
@@ -115,7 +115,7 @@ static void fetch_callback(const sfetch_response_t* response) {
115115
&num_channels, desired_channels);
116116
if (pixels) {
117117
/* initialize the sokol-gfx texture */
118-
sg_init_image(state.bind.fs.images[SLOT__ourTexture], &(sg_image_desc){
118+
sg_init_image(state.bind.images[IMG__ourTexture], &(sg_image_desc){
119119
.width = img_width,
120120
.height = img_height,
121121
/* set pixel_format to RGBA8 for WebGL */

src/1-6-textures/3-multiple-textures.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ static void init(void) {
5050
Any draw calls containing such an "incomplete" image handle
5151
will be silently dropped.
5252
*/
53-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
54-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
53+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
54+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
5555

5656
/* flip images vertically after loading */
5757
stbi_set_flip_vertically_on_load(true);
@@ -91,9 +91,9 @@ static void init(void) {
9191
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
9292
.layout = {
9393
.attrs = {
94-
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
95-
[ATTR_vs_aColor].format = SG_VERTEXFORMAT_FLOAT3,
96-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
94+
[ATTR_simple_position].format = SG_VERTEXFORMAT_FLOAT3,
95+
[ATTR_simple_aColor].format = SG_VERTEXFORMAT_FLOAT3,
96+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
9797
}
9898
},
9999
.label = "triangle-pipeline"
@@ -108,7 +108,7 @@ static void init(void) {
108108
.path = "container.jpg",
109109
.callback = fetch_callback,
110110
.buffer = SFETCH_RANGE(state.file_buffer),
111-
.user_data = SFETCH_RANGE(state.bind.fs.images[0]),
111+
.user_data = SFETCH_RANGE(state.bind.images[IMG__texture1]),
112112
});
113113

114114
/* start loading the PNG file
@@ -117,7 +117,7 @@ static void init(void) {
117117
.path = "awesomeface.png",
118118
.callback = fetch_callback,
119119
.buffer = SFETCH_RANGE(state.file_buffer),
120-
.user_data = SFETCH_RANGE(state.bind.fs.images[1]),
120+
.user_data = SFETCH_RANGE(state.bind.images[IMG__texture2]),
121121
});
122122
}
123123

src/1-7-transformations/1-scale-rotate.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ static void init(void) {
4040
Any draw calls containing such an "incomplete" image handle
4141
will be silently dropped.
4242
*/
43-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
44-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
43+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
44+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
4545

4646
/* flip images vertically after loading */
4747
stbi_set_flip_vertically_on_load(true);
@@ -81,8 +81,8 @@ static void init(void) {
8181
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
8282
.layout = {
8383
.attrs = {
84-
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
85-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
84+
[ATTR_simple_position].format = SG_VERTEXFORMAT_FLOAT3,
85+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
8686
}
8787
},
8888
.label = "triangle-pipeline"
@@ -93,8 +93,8 @@ static void init(void) {
9393
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
9494
};
9595

96-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
97-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
96+
sg_image image1 = state.bind.images[IMG__texture1];
97+
sg_image image2 = state.bind.images[IMG__texture2];
9898

9999
/* start loading the JPG file */
100100
sfetch_send(&(sfetch_request_t){
@@ -166,7 +166,7 @@ void frame(void) {
166166
vs_params_t vs_params = {
167167
.transform = trans
168168
};
169-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
169+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
170170

171171
sg_draw(0, 6, 1);
172172
sg_end_pass();

src/1-7-transformations/2-rotate-translate.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static void init(void) {
4444
Any draw calls containing such an "incomplete" image handle
4545
will be silently dropped.
4646
*/
47-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
48-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
47+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
48+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
4949

5050
/* flip images vertically after loading */
5151
stbi_set_flip_vertically_on_load(true);
@@ -85,8 +85,8 @@ static void init(void) {
8585
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
8686
.layout = {
8787
.attrs = {
88-
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
89-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
88+
[ATTR_simple_position].format = SG_VERTEXFORMAT_FLOAT3,
89+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
9090
}
9191
},
9292
.label = "triangle-pipeline"
@@ -97,8 +97,8 @@ static void init(void) {
9797
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
9898
};
9999

100-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
101-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
100+
sg_image image1 = state.bind.images[IMG__texture1];
101+
sg_image image2 = state.bind.images[IMG__texture2];
102102

103103
/* start loading the JPG file */
104104
sfetch_send(&(sfetch_request_t){
@@ -171,7 +171,7 @@ void frame(void) {
171171
vs_params_t vs_params = {
172172
.transform = trans
173173
};
174-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
174+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
175175

176176
sg_draw(0, 6, 1);
177177
sg_end_pass();

src/1-8-coordinate-systems/1-plane.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ static void init(void) {
4040
Any draw calls containing such an "incomplete" image handle
4141
will be silently dropped.
4242
*/
43-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
44-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
43+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
44+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
4545

4646
/* flip images vertically after loading */
4747
stbi_set_flip_vertically_on_load(true);
@@ -81,8 +81,8 @@ static void init(void) {
8181
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
8282
.layout = {
8383
.attrs = {
84-
[ATTR_vs_aPos].format = SG_VERTEXFORMAT_FLOAT3,
85-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
84+
[ATTR_simple_aPos].format = SG_VERTEXFORMAT_FLOAT3,
85+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
8686
}
8787
},
8888
.label = "triangle-pipeline"
@@ -93,8 +93,8 @@ static void init(void) {
9393
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
9494
};
9595

96-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
97-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
96+
sg_image image1 = state.bind.images[IMG__texture1];
97+
sg_image image2 = state.bind.images[IMG__texture2];
9898

9999
/* start loading the JPG file */
100100
sfetch_send(&(sfetch_request_t){
@@ -171,7 +171,7 @@ void frame(void) {
171171
.view = view,
172172
.projection = projection
173173
};
174-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
174+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
175175

176176
sg_draw(0, 6, 1);
177177
sg_end_pass();

src/1-8-coordinate-systems/2-cube.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static void init(void) {
4444
Any draw calls containing such an "incomplete" image handle
4545
will be silently dropped.
4646
*/
47-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
48-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
47+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
48+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
4949

5050
/* flip images vertically after loading */
5151
stbi_set_flip_vertically_on_load(true);
@@ -109,8 +109,8 @@ static void init(void) {
109109
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
110110
.layout = {
111111
.attrs = {
112-
[ATTR_vs_aPos].format = SG_VERTEXFORMAT_FLOAT3,
113-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
112+
[ATTR_simple_aPos].format = SG_VERTEXFORMAT_FLOAT3,
113+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
114114
}
115115
},
116116
.depth = {
@@ -125,8 +125,8 @@ static void init(void) {
125125
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
126126
};
127127

128-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
129-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
128+
sg_image image1 = state.bind.images[IMG__texture1];
129+
sg_image image2 = state.bind.images[IMG__texture2];
130130

131131
/* start loading the JPG file */
132132
sfetch_send(&(sfetch_request_t){
@@ -203,7 +203,7 @@ void frame(void) {
203203
.view = view,
204204
.projection = projection
205205
};
206-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
206+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
207207

208208
sg_draw(0, 36, 1);
209209
sg_end_pass();

src/1-8-coordinate-systems/3-more-cubes.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ static void init(void) {
4141
Any draw calls containing such an "incomplete" image handle
4242
will be silently dropped.
4343
*/
44-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
45-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
44+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
45+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
4646

4747
/* flip images vertically after loading */
4848
stbi_set_flip_vertically_on_load(true);
@@ -117,8 +117,8 @@ static void init(void) {
117117
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
118118
.layout = {
119119
.attrs = {
120-
[ATTR_vs_aPos].format = SG_VERTEXFORMAT_FLOAT3,
121-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
120+
[ATTR_simple_aPos].format = SG_VERTEXFORMAT_FLOAT3,
121+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
122122
}
123123
},
124124
.depth = {
@@ -133,8 +133,8 @@ static void init(void) {
133133
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
134134
};
135135

136-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
137-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
136+
sg_image image1 = state.bind.images[IMG__texture1];
137+
sg_image image2 = state.bind.images[IMG__texture2];
138138

139139
/* start loading the JPG file */
140140
sfetch_send(&(sfetch_request_t){
@@ -214,7 +214,7 @@ void frame(void) {
214214
float angle = 20.0f * i;
215215
model = HMM_MulM4(model, HMM_Rotate_RH(HMM_AngleDeg(angle), HMM_V3(1.0f, 0.3f, 0.5f)));
216216
vs_params.model = model;
217-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
217+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
218218

219219
sg_draw(0, 36, 1);
220220
}

src/1-9-camera/1-lookat.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static void init(void) {
4545
Any draw calls containing such an "incomplete" image handle
4646
will be silently dropped.
4747
*/
48-
sg_alloc_image_smp(state.bind.fs, SLOT__texture1, SLOT_texture1_smp);
49-
sg_alloc_image_smp(state.bind.fs, SLOT__texture2, SLOT_texture2_smp);
48+
sg_alloc_image_smp(state.bind, IMG__texture1, SMP_texture1_smp);
49+
sg_alloc_image_smp(state.bind, IMG__texture2, SMP_texture2_smp);
5050

5151
/* flip images vertically after loading */
5252
stbi_set_flip_vertically_on_load(true);
@@ -121,8 +121,8 @@ static void init(void) {
121121
/* if the vertex layout doesn't have gaps, don't need to provide strides and offsets */
122122
.layout = {
123123
.attrs = {
124-
[ATTR_vs_aPos].format = SG_VERTEXFORMAT_FLOAT3,
125-
[ATTR_vs_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
124+
[ATTR_simple_aPos].format = SG_VERTEXFORMAT_FLOAT3,
125+
[ATTR_simple_aTexCoord].format = SG_VERTEXFORMAT_FLOAT2
126126
}
127127
},
128128
.depth = {
@@ -137,8 +137,8 @@ static void init(void) {
137137
.colors[0] = { .load_action=SG_LOADACTION_CLEAR, .clear_value={0.2f, 0.3f, 0.3f, 1.0f} }
138138
};
139139

140-
sg_image image1 = state.bind.fs.images[SLOT__texture1];
141-
sg_image image2 = state.bind.fs.images[SLOT__texture2];
140+
sg_image image1 = state.bind.images[IMG__texture1];
141+
sg_image image2 = state.bind.images[IMG__texture2];
142142

143143
/* start loading the JPG file */
144144
sfetch_send(&(sfetch_request_t){
@@ -223,7 +223,7 @@ void frame(void) {
223223
float angle = 20.0f * i;
224224
model = HMM_MulM4(model, HMM_Rotate_RH(HMM_AngleDeg(angle), HMM_V3(1.0f, 0.3f, 0.5f)));
225225
vs_params.model = model;
226-
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
226+
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
227227

228228
sg_draw(0, 36, 1);
229229
}

0 commit comments

Comments
 (0)