Guest User

Untitled

a guest
Jul 26th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #ifndef RASTERIZATION_HPP
  2. #define RASTERIZATION_HPP
  3.  
  4. #include <cstdint>
  5. #include <raylib.h>
  6. #include <renderkid/vertex_stage.hpp>
  7. #include <vector>
  8. #include <array>
  9. #include <map>
  10.  
  11. namespace _raster {
  12. struct UserTexture {
  13. uint8_t *data;
  14. int channels;
  15. int width;
  16. int height;
  17. };
  18.  
  19.  
  20. class Rasterizer {
  21. public:
  22. Rasterizer(int width, int height);
  23. void draw_primitives(uint8_t primitive_type, std::vector<_vertex::Primitive> &primitives);
  24. uint8_t create_texture(int width, int height, int n_channels);
  25.  
  26. void use_texture(uint8_t id) {
  27. current_texture = id;
  28. }
  29.  
  30. void load_data_to_texture(uint8_t *data);
  31. void destroy_texture(uint8_t texture);
  32. private:
  33. void raster_triangle(const _vertex::Primitive &triangle);
  34. glm::vec4 gen_frag_color_from_attributes(const glm::vec4 &frag_coord, const _vertex::Vertex &a, const _vertex::Vertex &b,
  35. const _vertex::Vertex &c);
  36. glm::vec4 gen_frag_color_from_texture(const glm::vec4 &frag_coord, const glm::vec4 &a_coord,
  37. const glm::vec4 &b_coord, const glm::vec4 &c_coord);
  38. void draw_framebuffer();
  39. void clear_framebuffer();
  40. float *depth_buffer;
  41. std::map<uint8_t, UserTexture> textures;
  42. uint8_t current_texture;
  43. uint8_t next_texture_id;
  44. Image framebuffer;
  45. Texture framebuffer_texture;
  46. int width;
  47. int height;
  48. };
  49. }
  50.  
  51. #endif
Advertisement
Add Comment
Please, Sign In to add comment