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)" ;
4243Texture tilemap;
4344Camera2D cam;
44- DescribedPipeline* shader;
45+ Shader shader;
4546VertexArray* tileVAO;
4647DescribedBuffer* tileVBO;
4748DescribedBuffer* tileIBO;
@@ -51,14 +52,12 @@ int tileCount;
5152
5253void 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}
7978int 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+ }
0 commit comments