2022-03-21 21:52:44 -04:00
|
|
|
#ifndef GFX_RENDERING_API_H
|
|
|
|
#define GFX_RENDERING_API_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2022-04-18 05:37:47 -04:00
|
|
|
#include <map>
|
2022-07-05 19:29:57 -04:00
|
|
|
#include <unordered_map>
|
2022-04-18 05:37:47 -04:00
|
|
|
#include <set>
|
|
|
|
|
2022-03-21 21:52:44 -04:00
|
|
|
struct ShaderProgram;
|
|
|
|
|
2022-04-18 05:37:47 -04:00
|
|
|
struct GfxClipParameters {
|
|
|
|
bool z_is_from_0_to_1;
|
|
|
|
bool invert_y;
|
|
|
|
};
|
|
|
|
|
2022-05-11 10:59:56 -04:00
|
|
|
enum FilteringMode {
|
|
|
|
THREE_POINT,
|
|
|
|
LINEAR,
|
|
|
|
NONE
|
|
|
|
};
|
|
|
|
|
2022-07-05 19:29:57 -04:00
|
|
|
// A hash function used to hash a: pair<float, float>
|
|
|
|
struct hash_pair_ff {
|
|
|
|
size_t operator()(const std::pair<float, float> &p ) const {
|
|
|
|
auto hash1 = std::hash<float>{}(p.first);
|
|
|
|
auto hash2 = std::hash<float>{}(p.second);
|
|
|
|
|
|
|
|
// If hash1 == hash2, their XOR is zero.
|
|
|
|
return (hash1 != hash2) ? hash1 ^ hash2 : hash1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-21 21:52:44 -04:00
|
|
|
struct GfxRenderingAPI {
|
2022-04-18 05:37:47 -04:00
|
|
|
struct GfxClipParameters (*get_clip_parameters)(void);
|
2022-03-21 21:52:44 -04:00
|
|
|
void (*unload_shader)(struct ShaderProgram *old_prg);
|
|
|
|
void (*load_shader)(struct ShaderProgram *new_prg);
|
|
|
|
struct ShaderProgram *(*create_and_load_new_shader)(uint64_t shader_id0, uint32_t shader_id1);
|
|
|
|
struct ShaderProgram *(*lookup_shader)(uint64_t shader_id0, uint32_t shader_id1);
|
|
|
|
void (*shader_get_info)(struct ShaderProgram *prg, uint8_t *num_inputs, bool used_textures[2]);
|
|
|
|
uint32_t (*new_texture)(void);
|
|
|
|
void (*select_texture)(int tile, uint32_t texture_id);
|
|
|
|
void (*upload_texture)(const uint8_t *rgba32_buf, uint32_t width, uint32_t height);
|
|
|
|
void (*set_sampler_parameters)(int sampler, bool linear_filter, uint32_t cms, uint32_t cmt);
|
|
|
|
void (*set_depth_test_and_mask)(bool depth_test, bool z_upd);
|
|
|
|
void (*set_zmode_decal)(bool zmode_decal);
|
|
|
|
void (*set_viewport)(int x, int y, int width, int height);
|
|
|
|
void (*set_scissor)(int x, int y, int width, int height);
|
|
|
|
void (*set_use_alpha)(bool use_alpha);
|
|
|
|
void (*draw_triangles)(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris);
|
|
|
|
void (*init)(void);
|
|
|
|
void (*on_resize)(void);
|
|
|
|
void (*start_frame)(void);
|
|
|
|
void (*end_frame)(void);
|
|
|
|
void (*finish_render)(void);
|
2022-04-18 05:37:47 -04:00
|
|
|
int (*create_framebuffer)();
|
|
|
|
void (*update_framebuffer_parameters)(int fb_id, uint32_t width, uint32_t height, uint32_t msaa_level, bool opengl_invert_y, bool render_target, bool has_depth_buffer, bool can_extract_depth);
|
|
|
|
void (*start_draw_to_framebuffer)(int fb_id, float noise_scale);
|
|
|
|
void (*clear_framebuffer)(void);
|
|
|
|
void (*resolve_msaa_color_buffer)(int fb_id_target, int fb_id_source);
|
2022-07-05 19:29:57 -04:00
|
|
|
std::unordered_map<std::pair<float, float>, uint16_t, hash_pair_ff> (*get_pixel_depth)(int fb_id, const std::set<std::pair<float, float>>& coordinates);
|
2022-04-18 05:37:47 -04:00
|
|
|
void *(*get_framebuffer_texture_id)(int fb_id);
|
|
|
|
void (*select_texture_fb)(int fb_id);
|
2022-03-21 21:52:44 -04:00
|
|
|
void (*delete_texture)(uint32_t texID);
|
2022-05-11 10:59:56 -04:00
|
|
|
void (*set_texture_filter)(FilteringMode mode);
|
|
|
|
FilteringMode(*get_texture_filter)(void);
|
2022-03-21 21:52:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|