kvark / vange-rs

Rusty Vangers clone
https://vange.rs
Apache License 2.0
420 stars 21 forks source link

lib: move compositor to rust #240

Open caiiiycuk opened 5 months ago

caiiiycuk commented 5 months ago

Hi, here is my proposal for how we can transfer all graphics-related tasks to the render-ng library.

  1. We need to change rv_init to accept a window context handle (provided by SDL; we can provide something from SDL_SysWMinfo). Like this:
struct rv_init_descriptor {
    uint32_t width;
    uint32_t height;
    const char* render_config;
    void* handle; // <----- native window handle
};

rv_context rv_init(rv_init_descriptor desc);
  1. The function to render RGBA data in window coordinates (using the same coordinates as those used for rv_resize):
rv_render_rgba(const rv_rect& dest, uint32_t width, uint32_t height, uint8_t *rgba);

We also use 'texture coloring' (as in FragColor = texture(tex, uv) * color). While it's not mandatory, please add color as the last optional parameter if possible.

rv_render_rgba(const rv_rect& dest, uint32_t width, uint32_t height, uint8_t *rgba, uint32_t *color = nullptr);

The blend function is always the same: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  1. lifecycle function:
enum Stage {
   LAYER_3D,
   LAYER_2D,
   PRESENT
}

rv_stage(Stage stage);
  1. Optiononal function that sets clear color (we want to change bg of the game window):
void rv_clear_color(uint32_t color)

P.S. Feel free to change the naming/declarations as you see fit.

caiiiycuk commented 5 months ago

It is very important to not break android version. Not sure if rust can create context on android device, so if possible let's keep fallback path of rv_init using glfunctor.