Optimize rendering: frame pacing, UI culling, render scale and GPU scratch buffers

This commit is contained in:
shen
2026-10-08 17:06:17 -07:00
parent d7adbb3014
commit 08cc8865be
5 changed files with 180 additions and 72 deletions
+24
View File
@@ -105,6 +105,10 @@ public:
bool IsFogEnabled() const { return m_fog_enabled; }
uint32_t GetFogColor() const { return m_fog_color; }
void SetLogicalSize(int width, int height) { m_logicalWidth = width; m_logicalHeight = height; }
int GetLogicalWidth() const { return m_logicalWidth > 0 ? m_logicalWidth : m_viewport[2]; }
int GetLogicalHeight() const { return m_logicalHeight > 0 ? m_logicalHeight : m_viewport[3]; }
const float* GetViewMatrix() const { return m_view; }
const float* GetProjMatrix() const { return m_proj; }
const int* GetViewport() const { return m_viewport; }
@@ -130,14 +134,34 @@ private:
};
const TextureData* GetTexture(const std::string& texturePath);
struct GpuTransformedVertex {
float x_clip, y_clip, z_clip, w_clip;
float x_screen, y_screen;
float u, v;
float r, g, b, a;
};
struct DrawOrder {
int priority = 1;
float depth = 0.0f;
const Render3DDraw* draw = nullptr;
};
float m_eye[3] = {0.0f, 0.0f, 0.0f};
float m_view[16];
float m_proj[16];
int m_viewport[4];
int m_logicalWidth = 0;
int m_logicalHeight = 0;
std::vector<float> m_depthBuffer;
std::unordered_map<std::string, TextureData> m_textureCache;
std::unordered_map<std::string, SDL_Texture*> m_gpuTextureCache;
// Persistent scratch buffers to eliminate per-draw heap allocation churn in RenderSceneGPU
std::vector<DrawOrder> m_scratchSortedDraws;
std::vector<GpuTransformedVertex> m_scratchGpuXverts;
std::vector<SDL_Vertex> m_scratchSdlVertices;
std::vector<int> m_scratchSdlIndices;
bool m_fog_enabled = false;
uint32_t m_fog_color = 0xFFCCDDEE;
float m_fog_density = 0.0003f;