PortalGame/src/gfx/renderer.hpp
2025-08-09 18:01:53 +02:00

54 lines
1.1 KiB
C++

#pragma once
#include <memory>
#include "gfx/shader.hpp"
#include "game/world.hpp"
#include "game/sector.hpp"
namespace gfx
{
struct DrawSectorParams
{
const game::Sector* sector;
const game::Portal* entry_portal;
glm::vec4 clip_plane;
collision::AABB2 screen_aabb;
size_t recursion;
glm::mat4 view;
glm::mat4 view_proj;
glm::vec3 eye;
};
class Renderer
{
public:
Renderer();
void Begin(size_t width, size_t height);
void DrawWorld(
const game::World& world,
size_t sector_idx,
const glm::vec3& eye,
const glm::vec3& dir,
const glm::vec3& up,
float aspect,
float fov);
private:
std::unique_ptr<Shader> sector_shader_;
std::unique_ptr<Shader> portal_shader_;
std::shared_ptr<VertexArray> portal_vao_;
void SetupPortalVAO();
glm::mat4 proj_;
void DrawSector(const DrawSectorParams& params);
void DrawPortal(const DrawSectorParams& params, const game::Portal& portal);
static bool ComputePortalScreenAABB(const game::Portal& portal, const glm::mat4 view_proj, collision::AABB2& aabb);
void DrawPortalPlane(const DrawSectorParams& params, const game::Portal& portal, bool clear_depth);
};
}