Files
jak-project/game/graphics/opengl_renderer/background/Shrub.h
T
water111 5b04be2fa0 Add hfrag, clean up some background renderer stuff (#3509)
This adds hfrag, but with a few remaining issues:
- The textures aren't animated. Instead, it just uses one texture.
- The texture filtering isn't as good as at it could be.

I also cleaned up a few issues with the background renderers:
- Cleaned up some stuff that is common to hfrag, tie, tfrag, shrub
- Moved time-of-day color packing stuff to FR3 creation, rather than at
level load. This appears to reduce the frame time spikes when a level is
first drawn by about 5 or 6 ms in big levels.
- Cleaned up the x86 specific stuff used in time of day. Now there's
only one place where we have an `ifdef`, rather than spreading it all
over the rendering code.
2024-05-09 20:11:43 -04:00

84 lines
2.5 KiB
C++

#pragma once
#include <optional>
#include "common/util/FilteredValue.h"
#include "game/graphics/gfx.h"
#include "game/graphics/opengl_renderer/BucketRenderer.h"
#include "game/graphics/opengl_renderer/background/background_common.h"
#include "game/graphics/pipelines/opengl.h"
class Shrub : public BucketRenderer {
public:
Shrub(const std::string& name, int my_id);
~Shrub();
void init_shaders(ShaderLibrary& shaders) override;
bool setup_for_level(const std::string& level, SharedRenderState* render_state);
void render_all_trees(const TfragRenderSettings& settings,
SharedRenderState* render_state,
ScopedProfilerNode& prof);
void render_tree(int idx,
const TfragRenderSettings& settings,
SharedRenderState* render_state,
ScopedProfilerNode& prof);
void render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) override;
void draw_debug_window() override;
private:
void update_load(const LevelData* loader_data);
void discard_tree_cache();
struct Tree {
GLuint vertex_buffer;
GLuint index_buffer;
GLuint single_draw_index_buffer;
GLuint time_of_day_texture;
GLuint vao;
u32 vert_count;
const std::vector<tfrag3::ShrubDraw>* draws = nullptr;
const std::vector<tfrag3::TieWindInstance>* instance_info = nullptr;
const tfrag3::PackedTimeOfDay* colors = nullptr;
const u32* index_data = nullptr;
std::vector<bool> proto_vis_mask;
std::unordered_map<std::string, std::vector<u32>> proto_name_to_idx;
struct {
u32 draws = 0;
u32 wind_draws = 0;
Filtered<float> cull_time;
Filtered<float> index_time;
Filtered<float> tod_time;
Filtered<float> setup_time;
Filtered<float> draw_time;
Filtered<float> tree_time;
} perf;
};
struct {
GLuint decal;
} m_uniforms;
std::vector<Tree> m_trees;
std::string m_level_name;
const std::vector<GLuint>* m_textures;
u64 m_load_id = -1;
std::vector<math::Vector<u8, 4>> m_color_result;
static constexpr int TIME_OF_DAY_COLOR_COUNT = 8192;
bool m_has_level = false;
struct Cache {
std::vector<std::pair<int, int>> draw_idx_temp;
std::vector<u32> index_temp;
std::vector<std::pair<int, int>> multidraw_offset_per_stripdraw;
std::vector<GLsizei> multidraw_count_buffer;
std::vector<void*> multidraw_index_offset_buffer;
} m_cache;
TfragPcPortData m_pc_port_data;
const u8* m_proto_vis_data = nullptr;
int m_proto_vis_data_size = 0;
};