Fix cross-platform rendering and optimize frame performance
Correct selection orientation, game-entry lifecycle, mounted NPCs, labels and skill panels. Add the native GPU scene path, resident geometry, bounded texture and Python caches, and collision broad phase. Pin the independently maintained Metin2 SDK through a submodule and document reproducible setup. Include rendering regressions and macOS packaging improvements. Validation: client Debug build and 12 targeted client tests passed; SDK build and all 14 SDK tests passed.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "RenderCommands3D.h"
|
||||
namespace ava2 {
|
||||
struct HardwareVertex {
|
||||
float position[4], color[4], uv[2];
|
||||
float normal[4]{};
|
||||
uint32_t bones[4]{};
|
||||
float weights[4]{};
|
||||
};
|
||||
struct HardwareTransform {
|
||||
float world[16]{}, mvp[16]{};
|
||||
float diffuse[4]{}, ambient[4]{}, emissive[4]{};
|
||||
float lightDirection[4]{}, lightAmbient[4]{}, lightDiffuse[4]{};
|
||||
float fogColor[4]{}, fogParams[4]{};
|
||||
float modes[4]{}; // raw vertices, lighting, fog type, disable depth
|
||||
float skin[4]{}; // palette count
|
||||
};
|
||||
static_assert(sizeof(HardwareTransform)==288);
|
||||
HardwareVertex MakeHardwareVertex(const Render3DDraw& mesh, size_t index);
|
||||
struct HardwareBatch {
|
||||
uint32_t firstIndex, indexCount;
|
||||
SDL_GPUTexture* texture;
|
||||
uint32_t cull;
|
||||
bool depth, depthWrite, blend, additive;
|
||||
float alphaRef;
|
||||
HardwareTransform transform{};
|
||||
std::shared_ptr<const Render3DDraw> geometry;
|
||||
std::vector<float> palette;
|
||||
|
||||
};
|
||||
class HardwareScene {
|
||||
public:
|
||||
explicit HardwareScene(SDL_GPUDevice* device): device_(device) {}
|
||||
~HardwareScene();
|
||||
SDL_GPUTexture* FindTexture(const std::string& key);
|
||||
void SetTextureBudget(size_t bytes) { textureBudget_=bytes; }
|
||||
size_t GetTextureBytes() const { return textureBytes_; }
|
||||
size_t GetTextureUploadCount() const { return textureUploads_; }
|
||||
SDL_GPUTexture* Texture(const std::string& key, int width, int height, const void* rgba);
|
||||
bool Render(SDL_Renderer* renderer, int width, int height,
|
||||
const std::vector<HardwareVertex>& vertices,
|
||||
const std::vector<uint32_t>& indices,
|
||||
const std::vector<HardwareBatch>& batches);
|
||||
size_t GetResidentUploadCount() const { return residentUploads_; }
|
||||
size_t GetLastDrawCallCount() const { return lastDrawCalls_; }
|
||||
size_t GetLastDynamicUploadBytes() const { return lastDynamicBytes_; }
|
||||
private:
|
||||
struct ResidentMesh {
|
||||
std::shared_ptr<const Render3DDraw> source;
|
||||
SDL_GPUBuffer *vertices=nullptr, *indices=nullptr;
|
||||
uint32_t count=0, bytes=0;
|
||||
uint64_t lastUsed=0;
|
||||
};
|
||||
ResidentMesh* Resident(const std::shared_ptr<const Render3DDraw>& geometry);
|
||||
std::unordered_map<const Render3DDraw*,ResidentMesh> resident_;
|
||||
uint64_t frame_=0;
|
||||
size_t residentBytes_=0, residentUploads_=0, lastDrawCalls_=0, lastDynamicBytes_=0;
|
||||
SDL_GPUBuffer* instances_=nullptr;
|
||||
SDL_GPUTransferBuffer* instanceTransfer_=nullptr;
|
||||
uint32_t instanceBytes_=0;
|
||||
bool Initialize(SDL_Renderer* renderer, int width, int height);
|
||||
SDL_GPUGraphicsPipeline* Pipeline(const HardwareBatch& batch);
|
||||
SDL_GPUDevice* device_;
|
||||
SDL_GPUShader *vertex_=nullptr, *fragment_=nullptr;
|
||||
SDL_GPUSampler* sampler_=nullptr;
|
||||
SDL_GPUTexture *color_=nullptr, *depth_=nullptr;
|
||||
SDL_Texture* output_=nullptr;
|
||||
SDL_GPUTexture* white_=nullptr;
|
||||
struct TextureEntry {SDL_GPUTexture* texture;size_t bytes;uint64_t lastUsed;};
|
||||
std::unordered_map<std::string,TextureEntry> textures_;
|
||||
size_t textureBytes_=0,textureUploads_=0,textureBudget_=256u*1024u*1024u;
|
||||
SDL_GPUBuffer *vertices_=nullptr, *indices_=nullptr;
|
||||
SDL_GPUTransferBuffer* transfer_=nullptr;
|
||||
uint32_t vertexBytes_=0, indexBytes_=0;
|
||||
int width_=0,height_=0;
|
||||
std::unordered_map<unsigned,SDL_GPUGraphicsPipeline*> pipelines_;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user