vange-rs
vange-rs copied to clipboard
lib: move compositor to rust
Hi, here is my proposal for how we can transfer all graphics-related tasks to the render-ng library.
- 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);
- 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);
- lifecycle function:
enum Stage {
LAYER_3D,
LAYER_2D,
PRESENT
}
rv_stage(Stage stage);
- LAYER_2D is called just before we start using rv_render_rgba. Here, you can set the blend function, viewport, etc.
- PRESENT marks the end of a frame, where we actually render to the frame.
- LAYER_3D is called immediately after PRESENT. Here you can reset the color buffer, etc.
- 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.
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.