Skip to content

Commit 03e2791

Browse files
committed
Update tests, examples and add browser pseudofullscreen example
1 parent af0cba6 commit 03e2791

21 files changed

+301
-404
lines changed

examples/CMakeLists.txt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ endfunction()
5151

5252
add_example(core_window)
5353
add_example(core_resizable)
54+
add_example(core_browser_extent)
55+
if(EMSCRIPTEN)
56+
set_target_properties(core_browser_extent PROPERTIES LINK_FLAGS
57+
"--shell-file ${CMAKE_SOURCE_DIR}/resources/shell_browser_extent.html")
58+
endif()
5459
add_example(core_shapes)
5560
add_example(rlfunctions)
5661
add_example(shaders_basic)
@@ -64,51 +69,41 @@ add_example(textures_generate)
6469
add_example(core_camera2d)
6570
add_example(core_camera3d)
6671
add_example(core_rendertexture)
67-
#add_example(pipeline_basic)
72+
add_example(pipeline_basic)
6873
add_example(pipeline_settings)
6974
add_example(input_keys)
7075
add_example(input_gamepad)
7176
add_example(input_multitouch_gesture)
7277
add_example(input_text)
73-
#add_example(models_cube)
78+
add_example(models_cube)
7479
add_example(split_screen_camera3d)
75-
#add_example(core_fonts)
80+
add_example(core_fonts)
7681
add_example(core_headless)
7782
add_example(core_cursor)
78-
#add_example(textures_array)
83+
add_example(textures_array)
7984
add_example(core_multiwindow)
80-
#add_example(memory_vma_allocator)
81-
#add_cpp_example(vao_multibuffer)
82-
#add_cpp_example(shader_inspection)
85+
#add_example(memory_vma_allocator) # Requires VMA library to be linked
86+
add_cpp_example(vao_multibuffer)
8387
add_cpp_example(compute)
84-
#add_cpp_example(shaders_glsl)
85-
#add_cpp_example(pipeline_instancing)
86-
if(SUPPORT_VULKAN_BACKEND)
87-
#add_cpp_example(models_raytracing)
88-
endif()
89-
#add_cpp_example(pipeline_uniforms)
88+
add_cpp_example(shaders_glsl)
89+
add_cpp_example(pipeline_instancing)
90+
#if(SUPPORT_VULKAN_BACKEND)
91+
# add_cpp_example(models_raytracing) # Requires vulkan_internals.hpp (not yet available)
92+
#endif()
93+
add_cpp_example(pipeline_uniforms)
9094
add_cpp_example(models_obj)
9195
add_cpp_example(models_lights)
9296
add_cpp_example(models_glb)
93-
#add_cpp_example(models_forwardkinematics)
94-
#add_cpp_example(pipeline_constants)
97+
add_cpp_example(models_forwardkinematics)
98+
add_cpp_example(pipeline_constants)
9599
add_example(benchmark_cubes)
96-
#add_cpp_example(benchmark_tilemap)
100+
add_cpp_example(benchmark_tilemap)
97101
add_cpp_example(core_screenrecord)
98-
#add_cpp_example(textures_formats)
102+
add_cpp_example(textures_formats)
99103
add_cpp_example(textures_mipmap)
100104
add_cpp_example(models_gpu_skinning)
101-
#add_cpp_example(textures_bloom)
102-
#if(SUPPORT_GLSL_PARSER)
103-
# add_cpp_example(glsl_to_wgsl)
104-
#endif()
105-
#add_cpp_example(textures_storage)
106-
if(SUPPORT_VULKAN_BACKEND)
107-
#add_executable(plain_wgvk "plain_wgvk.c")
108-
#target_link_libraries(plain_wgvk PUBLIC wgvk)
109-
#target_compile_features(plain_wgvk PUBLIC c_std_23)
110-
111-
#add_executable(surface_wgvk "surface_wgvk.c")
112-
#target_link_libraries (surface_wgvk PUBLIC wgvk glfw)
113-
#target_compile_features(surface_wgvk PUBLIC c_std_23)
105+
add_cpp_example(textures_bloom)
106+
if(SUPPORT_GLSL_PARSER AND SUPPORT_WGSL_PARSER)
107+
add_cpp_example(glsl_to_wgsl)
114108
endif()
109+
add_cpp_example(textures_storage)

examples/benchmark_tilemap.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <filesystem>
2+
#include <vector>
23
#include <raygpu.h>
34
#ifdef __EMSCRIPTEN__
45
#include <emscripten.h>
@@ -41,7 +42,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4f {
4142
)";
4243
Texture tilemap;
4344
Camera2D cam;
44-
DescribedPipeline* shader;
45+
Shader shader;
4546
VertexArray* tileVAO;
4647
DescribedBuffer* tileVBO;
4748
DescribedBuffer* tileIBO;
@@ -51,14 +52,12 @@ int tileCount;
5152

5253
void mainloop(){
5354
BeginDrawing();
54-
//ClearBackground(BLACK);
55-
BeginPipelineMode(shader);
55+
BeginShaderMode(shader);
5656
BeginMode2D(cam);
57-
BindPipelineVertexArray(shader, tileVAO);
58-
DrawArraysIndexedInstanced(WGPUPrimitiveTopology_TriangleList, *tileIBO, 6, tileCount);
59-
//DrawTexturePro(tilemap, Rectangle{0,0,(float)tilemap.width, (float)tilemap.height}, Rectangle{0,0,1000,1000}, Vector2{0,0}, 0.0f, WHITE);
57+
BindShaderVertexArray(shader, tileVAO);
58+
DrawArraysIndexedInstanced(RL_TRIANGLES, *tileIBO, 6, tileCount);
6059
EndMode2D();
61-
EndPipelineMode();
60+
EndShaderMode();
6261
DrawFPS(10,10);
6362
cam.zoom *= std::exp(GetMouseWheelMove() / 30.0f);
6463
const float speed = 200.0f;
@@ -77,25 +76,23 @@ void mainloop(){
7776
EndDrawing();
7877
}
7978
int main(){
80-
//SetConfigFlags(FLAG_MSAA_4X_HINT);
8179
SetConfigFlags(FLAG_VSYNC_HINT);
8280
std::filesystem::path p(".");
8381
std::cout << std::filesystem::absolute(p) << "\n";
8482
InitWindow(640, 480, "Tilemap Benchmark");
8583
SetTargetFPS(0);
8684
Image img = LoadImage("../resources/tileset.png");
87-
//Image img = GenImageColor(RED, 100, 100);
8885
tilemap = LoadTextureFromImage(img);
8986
cam = Camera2D{
90-
.offset = Vector2{GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f},
87+
.offset = Vector2{GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f},
9188
.target = Vector2{0,0},
92-
.rotation = 0.0f,
89+
.rotation = 0.0f,
9390
.zoom = 100.0f
9491
};
9592
shader = LoadPipeline(wgsl);
9693

97-
SetPipelineTexture(shader, 1, tilemap);
98-
SetPipelineSampler(shader, 2, LoadSampler(repeat, nearest));
94+
SetShaderTexture(shader, 1, tilemap);
95+
SetShaderSampler(shader, 2, LoadSampler(TEXTURE_WRAP_REPEAT, TEXTURE_FILTER_POINT));
9996
tileVAO = LoadVertexArray();
10097
float tileVertices [8] = {
10198
0, 0,
@@ -107,7 +104,7 @@ int main(){
107104
0,1,2,0,2,3
108105
};
109106
tileIBO = GenIndexBuffer(tileIndices, sizeof(tileIndices));
110-
tileVBO = GenBuffer(tileVertices, sizeof(tileVertices));
107+
tileVBO = GenVertexBuffer(tileVertices, sizeof(tileVertices));
111108
std::vector<Vector2> offsets;
112109
std::vector<uint32_t> tt;
113110
int w = 1000;
@@ -120,17 +117,16 @@ int main(){
120117
++tileCount;
121118
}
122119
}
123-
//std::cout << tileCount << "\n";
124-
tileOffsets = GenBuffer(offsets.data(), offsets.size() * sizeof(Vector2));
120+
tileOffsets = GenVertexBuffer(offsets.data(), offsets.size() * sizeof(Vector2));
125121
tileTypes = GenStorageBuffer(tt.data(), tt.size() * sizeof(uint32_t));
126-
VertexAttribPointer(tileVAO, tileVBO, 0, WGPUVertexFormat_Float32x2, 0, WGPUVertexStepMode_Vertex);
127-
VertexAttribPointer(tileVAO, tileOffsets, 1, WGPUVertexFormat_Float32x2, 0, WGPUVertexStepMode_Instance);
128-
SetPipelineStorageBuffer(shader, 3, tileTypes);
122+
VertexAttribPointer(tileVAO, tileVBO, 0, RGVertexFormat_Float32x2, 0, RGVertexStepMode_Vertex);
123+
VertexAttribPointer(tileVAO, tileOffsets, 1, RGVertexFormat_Float32x2, 0, RGVertexStepMode_Instance);
124+
SetShaderStorageBuffer(shader, 3, tileTypes);
129125
#ifdef __EMSCRIPTEN__
130126
emscripten_set_main_loop(mainloop, 0, 0);
131127
#else
132128
while(!WindowShouldClose()){
133129
mainloop();
134130
}
135131
#endif
136-
}
132+
}

examples/compute.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ constexpr bool headless = false;
103103

104104
constexpr size_t parts = (1 << 16);
105105
void mainloop(void){
106-
BeginDrawing();
107106
BeginComputepass();
108107
BindComputePipeline(firstPassPipeline);
109108
DispatchCompute(parts / 64, 64, 1);
110109
EndComputepass();
110+
111+
BeginDrawing();
111112
ClearBackground(BLACK);
112113

113114
BeginShaderMode(rpl);

examples/core_browser_extent.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <raygpu.h>
2+
3+
void setup(void){
4+
}
5+
6+
void render(void){
7+
BeginDrawing();
8+
ClearBackground((Color){40, 44, 52, 255});
9+
10+
const char* title = "Browser Extent Example";
11+
int fontSize = 40;
12+
DrawText(title, GetScreenWidth() / 2 - MeasureText(title, fontSize) / 2, 40, fontSize, WHITE);
13+
14+
const char* sizeText = TextFormat("Canvas: %d x %d", GetScreenWidth(), GetScreenHeight());
15+
DrawText(sizeText, GetScreenWidth() / 2 - MeasureText(sizeText, 20) / 2, 100, 20, (Color){150, 150, 150, 255});
16+
17+
DrawText(
18+
"Resize your browser window - the canvas follows",
19+
GetScreenWidth() / 2 - MeasureText("Resize your browser window - the canvas follows", 20) / 2,
20+
140, 20, (Color){100, 200, 100, 255}
21+
);
22+
23+
DrawRectangleLinesEx((Rectangle){2, 2, (float)GetScreenWidth() - 4, (float)GetScreenHeight() - 4}, 2.0f, (Color){80, 80, 80, 255});
24+
25+
DrawCircleSector(GetMousePosition(), 30.0f, 0.0f, 360.0f, 64, (Color){100, 149, 237, 200});
26+
DrawFPS(10, 10);
27+
if(IsKeyPressed(KEY_F)){
28+
ToggleFullscreen();
29+
}
30+
EndDrawing();
31+
}
32+
33+
int main(void){
34+
SetConfigFlags(FLAG_WINDOW_RESIZE_TO_BROWSER_EXTENT | FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
35+
ProgramInfo progInfo = {
36+
.windowTitle = "Browser Extent",
37+
.windowWidth = 800,
38+
.windowHeight = 600,
39+
.setupFunction = setup,
40+
.renderFunction = render
41+
};
42+
InitProgram(progInfo);
43+
}

examples/models_cube.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <raygpu.h>
22
#include <stdio.h>
3+
#include <string.h>
34
#include <assert.h>
45
#ifdef __EMSCRIPTEN__
56
#include <emscripten.h>
67
#endif
78

89
Camera3D cam;
910
Mesh cube;
10-
DescribedPipeline* pl;
11+
Shader pl;
1112
Texture checkers;
1213
Texture checkersHDR;
1314
float angle;
@@ -70,15 +71,13 @@ void mainloop(void){
7071
angle += GetFrameTime();
7172
cam.position = (Vector3){sinf(angle) * 10.f, 5.0f, cosf(angle) * 10.f};
7273
ClearBackground(BLACK);
73-
//TODO: Swapping the next two causes a problem since the BindGroup is lazily updated only at BindPipeline
74-
//EDIT: It's not due to lazy update; DrawArrays and DrawArraysIndexed did not check for a pending Bindgroup Update
75-
BeginPipelineMode(pl);
74+
BeginShaderMode(pl);
7675
UseTexture(checkersHDR);
7776
BeginMode3D(cam);
7877
BindVertexArray(cube.vao);
7978
DrawArraysIndexed(RL_TRIANGLES, *cube.ibo, 36);
8079
EndMode3D();
81-
EndPipelineMode();
80+
EndShaderMode();
8281
DrawFPS(0, 0);
8382
if(IsKeyPressed(KEY_U)){
8483
ToggleFullscreen();
@@ -87,18 +86,16 @@ void mainloop(void){
8786
}
8887
int main(cwoid){
8988
SetConfigFlags(FLAG_VSYNC_HINT);
90-
//SetConfigFlags(FLAG_MSAA_4X_HINT);
9189
InitWindow(1200, 800, "VAO");
92-
//SetTargetFPS(300);
9390
cam = CLITERAL(Camera3D){
9491
.position = CLITERAL(Vector3){0,0,10},
9592
.target = CLITERAL(Vector3){0,0,0},
9693
.up = CLITERAL(Vector3){0,1,0},
9794
.fovy = 45.0f
9895
};
9996
cube = GenMeshCube(3.f,3.f,3.f);
100-
//assert(cube.ibo.buffer == 0);
101-
pl = Relayout(DefaultPipeline(), cube.vao);
97+
pl = DefaultShader();
98+
PrepareShader(pl, cube.vao);
10299
checkersHDR = LoadTextureEx(9, 9, PIXELFORMAT_UNCOMPRESSED_R16G16B16A16, false);
103100

104101
checkers = LoadTextureFromImage(GenImageChecker(RED, DARKBLUE, 9, 9, 4));
@@ -116,7 +113,7 @@ int main(cwoid){
116113
checkersData[4 * i + 2] = (i & 1) ? 255 : 0;
117114
checkersData[4 * i + 3] = 255;
118115
}
119-
116+
120117
UpdateTexture(checkersHDR, checkersHDRData);
121118
UpdateTexture(checkers, checkersData);
122119
angle = 0.0f;

examples/models_forwardkinematics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void calculate_tx2_90_fk_mu(const float q[6], Matrix T_out[7]) {
5656
const float d[] = {0.478f, 0.0f, 0.0f, 0.425f, 0.0f, 0.100f};
5757
// theta_i uses q[i]
5858

59-
Matrix T_prev_curr zeroinit; // Transform {i-1} to {i}
59+
Matrix T_prev_curr = {}; // Transform {i-1} to {i}
6060

6161
// T_out[0] is Base Frame relative to Base (Identity)
6262
T_out[0] = MatrixIdentity();

examples/pipeline_basic.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,35 @@
44
#endif
55
VertexArray* vao;
66
DescribedBuffer* vbo;
7-
DescribedPipeline* pipeline;
7+
Shader pipeline;
88
void mainloop(cwoid){
99
BeginDrawing();
1010
ClearBackground(BLACK);
11-
BeginPipelineMode(pipeline);
11+
BeginShaderMode(pipeline);
1212
BindShaderVertexArray(pipeline, vao);
1313
DrawArrays(RL_TRIANGLES, 3);
14-
EndPipelineMode();
14+
EndShaderMode();
1515
DrawFPS(0,0);
1616
EndDrawing();
1717
}
1818
int main(void){
1919
InitWindow(800, 600, "The Render Pipeline");
2020
const char* resourceDirectoryPath = FindDirectory("resources", 3);
2121
char* shaderSource = LoadFileText(TextFormat("%s/simple_shader.wgsl", resourceDirectoryPath));
22-
22+
2323
float vertices[6] = {
2424
0,0,
2525
1,0,
2626
0,1
2727
};
28-
vbo = GenVertexBuffer(vertices, sizeof(vertices));
28+
vbo = GenVertexBuffer(vertices, sizeof(vertices));
2929
vao = LoadVertexArray();
30-
VertexAttribPointer(vao, vbo, 0, WGPUVertexFormat_Float32x2, 0, WGPUVertexStepMode_Vertex);
30+
VertexAttribPointer(vao, vbo, 0, RGVertexFormat_Float32x2, 0, RGVertexStepMode_Vertex);
3131
EnableVertexAttribArray(vao, 0);
3232
pipeline = LoadPipeline(shaderSource);
3333

34-
float uniformData[4] = {0,0,0,0};
3534
SetTargetFPS(0);
36-
35+
3736
#ifndef __EMSCRIPTEN__
3837
while(!WindowShouldClose()){
3938
mainloop();

0 commit comments

Comments
 (0)