Browse Source

updated readme, added RI_tick

IverMartinson 5 months ago
parent
commit
e591ec1688
6 changed files with 47 additions and 10 deletions
  1. BIN
      build/librasteriver.so
  2. BIN
      build/main.bin
  3. 33 2
      readme.md
  4. 1 0
      src/headers/functions.h
  5. 2 0
      src/launch_program/main.c
  6. 11 8
      src/library/rasteriver.c

BIN
build/librasteriver.so


BIN
build/main.bin


+ 33 - 2
readme.md

@@ -1,7 +1,38 @@
-### How to Run?
+
+# RasterIver
+
+World's Best Renderer, 2025
+
+## How Does it Work?
+
+### Building Blocks
+
+- There are a couple fundimental elements of RasterIver: `actors`, `textures`, `materials`, `meshes`, and `scenes` (this isnt including internal ones like `vectors` and `faces`)
+- They all use `pointers` to reference objects
+- This allows multiple `actors`, for instance, to reference the same `material` or `mesh`
+- Because most things' attributes are a reference, a `material` can have a `texture reference` to the `window`! (it's `frame buffer` is an `RI_texture`)
+
+### Functions
+
+- There are functions such as `RI_request_actors` which creates new `actors` and returns a `pointer` to the list of total `actors` that exist in the `RI context`
+- Every function intended for the user will be prefixed with `RI_`
+
+### Rasterizer Pipeline
+
+- `RI_render` is called
+- RasterIver checks if the `faces_to_render` array is allocated (this is an array that stores every valid, renderable `face` in the `scene` and is specific to each `scene`) and if it isn't, it loops through every `actor` in the `scene` and checks the total number of `faces`, then allocates 2x the needed memory (this is because sometimes `faces` need to be split into 2, meaning that you need another slot where you previously only needed one)
+- `faces_to_render` is cleared
+- RasterIver loops through every `actor` and calculates the transforms of positions, normals, and uvs for `face` in the `mesh` (it also performs shrinking and splitting culling here), checks if it's going to be in view, is a valid `face`, or has `should_render` set to `true`. If it is a valid `face`, it is added to the `faces_to_render` at the first open slot as a `RI_renderable_face` struct. The `AABB` of the `face` is also calculated here
+- The `target texture`'s `image buffer` and the `z buffer` are cleared
+- RasterIver loops through `faces_to_render` and then check every pixel in it's `AABB` and sees if it is inside the `face`. If it is, figure out what the color should be (does it have a `material`? A `texture`? Is it `wireframe`?)
+- When `RI_tick` is called, it copies the `RI context`'s `image buffer` into the `SDL texture` and renders the frame onto the `window` (it also handles `SDL events`)
+
+## How to Run?
+
 To run the binary, it needs to be in the same folder as librasteriver.so (if you just cloned the repo then they both should be in the build folder). You also need SDL2 installed (libsdl2-dev)
 To run the binary, it needs to be in the same folder as librasteriver.so (if you just cloned the repo then they both should be in the build folder). You also need SDL2 installed (libsdl2-dev)
 
 
-### Todo
+## Todo List
+
 - [ ] checks for missing references
 - [ ] checks for missing references
 - [ ] checks for missing files
 - [ ] checks for missing files
 - [ ] debugging
 - [ ] debugging

+ 1 - 0
src/headers/functions.h

@@ -13,5 +13,6 @@ int RI_stop(int result); // Stop RasterIver safely and free memory
 int RI_render(RI_scene *scene, RI_texture *target_texture); // Render a scene to a texture
 int RI_render(RI_scene *scene, RI_texture *target_texture); // Render a scene to a texture
 int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor *actors, RI_scene *scene);
 int RI_add_actors_to_scene(int RI_number_of_actors_to_add_to_scene, RI_actor *actors, RI_scene *scene);
 void RI_euler_rotation_to_quaternion(RI_vector_4f* quaternion, RI_vector_3f euler_rotation);
 void RI_euler_rotation_to_quaternion(RI_vector_4f* quaternion, RI_vector_3f euler_rotation);
+void RI_tick();
 
 
 #endif
 #endif

+ 2 - 0
src/launch_program/main.c

@@ -101,5 +101,7 @@ int main(){
         y_rotation += 0.1;
         y_rotation += 0.1;
 
 
         RI_render(scene, ri->frame_buffer);
         RI_render(scene, ri->frame_buffer);
+
+        RI_tick();
     }
     }
 }
 }

+ 11 - 8
src/library/rasteriver.c

@@ -751,17 +751,22 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
             }
             }
         }
         }
 
 
-        SDL_UpdateTexture(ri.texture, NULL, ri.frame_buffer->image_buffer, ri.window_width * sizeof(uint32_t));
-
-        SDL_RenderClear(ri.renderer);
-        SDL_RenderCopyEx(ri.renderer, ri.texture, NULL, NULL, 0, NULL, SDL_FLIP_VERTICAL);
-    
-        SDL_RenderPresent(ri.renderer);
     }
     }
     else{
     else{
         RI_stop(0);
         RI_stop(0);
     }
     }
 
 
+    return 0;
+}
+
+void RI_tick(){
+    SDL_UpdateTexture(ri.texture, NULL, ri.frame_buffer->image_buffer, ri.window_width * sizeof(uint32_t));
+
+    SDL_RenderClear(ri.renderer);
+    SDL_RenderCopyEx(ri.renderer, ri.texture, NULL, NULL, 0, NULL, SDL_FLIP_VERTICAL);
+
+    SDL_RenderPresent(ri.renderer);
+
     // handle SDL events
     // handle SDL events
     while (SDL_PollEvent(&ri.event)){
     while (SDL_PollEvent(&ri.event)){
         switch (ri.event.type){
         switch (ri.event.type){
@@ -771,8 +776,6 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
     }
     }
 
 
     ++ri.frame;
     ++ri.frame;
-
-    return 0;
 }
 }
 
 
 int opencl_init(){
 int opencl_init(){