Compare commits
7
Commits
b5a15871f4
...
71f393bbd1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71f393bbd1 | ||
|
|
b2c7c6ce7d | ||
|
|
696f4f62e6 | ||
|
|
dcd301a080 | ||
|
|
df87bc64eb | ||
|
|
b57f2fba99 | ||
|
|
46880be537 |
@@ -1044,3 +1044,40 @@ Outstanding: no Vulkan/Android device run or frame-time capture for this pass;
|
||||
`frames*0.033f` / `frames/60` animation clocks are frame-based rather than real
|
||||
time; translucent depth sorting uses each draw's first vertex. Original AVA2
|
||||
data and the server are unchanged.
|
||||
|
||||
### 2026-10-12 FPS pass 2 (SpeedTree untouched)
|
||||
|
||||
SpeedTree (forest culling, SpeedTreeRT texture-path cache) is left alone while
|
||||
the SDK side is still being optimized. Client commits 46880be5..b2c7c6ce, one per
|
||||
item:
|
||||
|
||||
- Cached map-object and terrain-patch draws are submitted by pointer
|
||||
(`Render3DDrawRef` + `FlattenDraws`); no per-frame copies of cached commands.
|
||||
- Map objects beyond the AVA2 loading distance are skipped, 1:1 with
|
||||
`ENABLE_MAP_OBJECT_OPTIMIZATION` (`CArea::__UpdateLoadedObjectInstances`):
|
||||
2D distance from the main actor > max(`OBJECT_DIST`, 5000). The background
|
||||
update now receives the player position instead of the camera eye, as
|
||||
`CPythonApplication` does. Fog-far culling was rejected (it changes
|
||||
silhouettes against the sky).
|
||||
- Render scale < 1 no longer copies the scene through an extra full-screen
|
||||
texture when the SDL_GPU pipeline is active; the scene target is composited
|
||||
with linear filtering.
|
||||
- HardwareScene skips redundant vertex/index/pipeline/sampler binds; the
|
||||
opaque sort groups depth-writing opaque and alpha-tested draws by cull mode,
|
||||
texture and geometry (blended and non-depth-writing draws stay back to front).
|
||||
- Distant actors animate at the original reduced FPS
|
||||
(`CGrannyLODController::UpdateLODLevel` + `CGrannyModelInstance::Update`):
|
||||
only models with a `_lod_01.gr2` sibling, more than 500 units from the camera
|
||||
target, 30-120 FPS by camera distance over 5000 (25000 for models of 500+
|
||||
units). The `_lod_` meshes are still not swapped in.
|
||||
|
||||
GPU skinning limit reviewed, not changed: 36 of 3755 skinned models in pc*,
|
||||
monster*, npc*, npc_mount and npc_pet exceed 128 bones (bosses, metin stones,
|
||||
doors; max 314, no PC models) and fall back to CPU skinning. Raising the limit
|
||||
needs shader rebuilds, exceeds Vulkan's 16 KB minimum uniform range and the
|
||||
UBYTE4 bone index range.
|
||||
|
||||
Verified: Debug macOS/Metal build, 50/50 CTests (new regressions for
|
||||
`FlattenDraws`, scaled-scene compositing and LOD animation rate). Not verified:
|
||||
in-game frame-time capture and 3D screenshots (no server in this session), and
|
||||
any Vulkan/Android device run.
|
||||
|
||||
+24
-21
@@ -1965,6 +1965,10 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
// Draw count is stable frame to frame; reserve last frame's peak up front.
|
||||
static size_t draw_reserve = 0;
|
||||
draws.reserve(draw_reserve);
|
||||
// Cached map-object commands go by pointer; flattened in order right before rendering.
|
||||
static std::vector<ava2::Render3DDrawRef> draw_refs;
|
||||
static std::vector<const ava2::Render3DDraw*> draw_list;
|
||||
draw_refs.clear();
|
||||
const auto profileBuildStart = std::chrono::steady_clock::now();
|
||||
if (last_phase == "game") {
|
||||
// Update outdoor SkyBox, Clouds UV scrolling & dynamic environment
|
||||
@@ -2019,9 +2023,9 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
#ifdef AVA2_HAS_PYTHON
|
||||
bool bg_rendered = false;
|
||||
if (ava2::CPythonBackground::Instance().IsMapReady()) {
|
||||
ava2::CPythonBackground::Instance().Update(eyeX, eyeY, eyeZ);
|
||||
ava2::CPythonBackground::Instance().Update(player_world_x, player_world_y, player_world_z);
|
||||
float camPos[3] = {eyeX, eyeY, eyeZ};
|
||||
ava2::CPythonBackground::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), camPos, draws);
|
||||
ava2::CPythonBackground::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), camPos, draws, &draw_refs);
|
||||
bg_rendered = true;
|
||||
}
|
||||
if (!bg_rendered)
|
||||
@@ -2034,8 +2038,13 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
// 2. Game phase: render outdoor terrain with quadtree culling & multi-texture patches
|
||||
auto terrain_draws = outdoor_terrain.BuildCulledDraws(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), 8000.0f);
|
||||
if (terrain_draws.empty()) {
|
||||
const float terrain_light_dir[3] = {current_env.dir_light.direction[0], current_env.dir_light.direction[1], current_env.dir_light.direction[2]};
|
||||
const float terrain_light_ambient[3] = {std::max(0.35f, current_env.dir_light.bg_ambient[0]),
|
||||
std::max(0.35f, current_env.dir_light.bg_ambient[1]), std::max(0.38f, current_env.dir_light.bg_ambient[2])};
|
||||
const size_t terrain_ref_count = draw_refs.size();
|
||||
outdoor_terrain.AppendCulledDrawRefs(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), 8000.0f, draws.size(), draw_refs,
|
||||
terrain_light_dir, terrain_light_ambient);
|
||||
if (draw_refs.size() == terrain_ref_count) {
|
||||
auto td = outdoor_terrain.BuildDrawCommand(nullptr, 2);
|
||||
td.light_direction[0] = current_env.dir_light.direction[0];
|
||||
td.light_direction[1] = current_env.dir_light.direction[1];
|
||||
@@ -2044,16 +2053,6 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
td.light_ambient[1] = std::max(0.35f, current_env.dir_light.bg_ambient[1]);
|
||||
td.light_ambient[2] = std::max(0.38f, current_env.dir_light.bg_ambient[2]);
|
||||
draws.push_back(std::move(td));
|
||||
} else {
|
||||
for (auto& td : terrain_draws) {
|
||||
td.light_direction[0] = current_env.dir_light.direction[0];
|
||||
td.light_direction[1] = current_env.dir_light.direction[1];
|
||||
td.light_direction[2] = current_env.dir_light.direction[2];
|
||||
td.light_ambient[0] = std::max(0.35f, current_env.dir_light.bg_ambient[0]);
|
||||
td.light_ambient[1] = std::max(0.35f, current_env.dir_light.bg_ambient[1]);
|
||||
td.light_ambient[2] = std::max(0.38f, current_env.dir_light.bg_ambient[2]);
|
||||
draws.push_back(std::move(td));
|
||||
}
|
||||
}
|
||||
|
||||
// Add water surface (translucent, animated)
|
||||
@@ -2063,8 +2062,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
draws.push_back(std::move(water_draw));
|
||||
}
|
||||
|
||||
auto bldg_draws = map_objects.BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix());
|
||||
for (auto& bd : bldg_draws) draws.push_back(std::move(bd));
|
||||
map_objects.AppendDrawRefs(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), draws.size(), draw_refs);
|
||||
|
||||
// Add outdoor forest trees, pines, and vegetation (SpeedTree Engine)
|
||||
auto tree_draws = outdoor_forest.BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), eyeX, eyeY, eyeZ, 6000.0f);
|
||||
@@ -2114,6 +2112,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
auto char_draws = preview_data ? player_actor.BuildDrawCommands() : std::vector<ava2::Render3DDraw>{};
|
||||
auto dog_draws = preview_data ? mob_dog.BuildDrawCommands() : std::vector<ava2::Render3DDraw>{};
|
||||
auto metin_draws = preview_data ? mob_metin.BuildDrawCommands() : std::vector<ava2::Render3DDraw>{};
|
||||
ava2::NetworkActorManager::Instance().UpdateLODLevel(eyeX, eyeY, eyeZ, player_world_x, player_world_z);
|
||||
auto net_draws = ava2::NetworkActorManager::Instance().BuildDrawCommands(static_cast<float>(frames) * 0.033f, renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix());
|
||||
if (until_game && rendered_game_frames == 20) {
|
||||
for (const auto& entry : ava2::NetworkActorManager::Instance().GetActorDict()) {
|
||||
@@ -2184,20 +2183,24 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
|
||||
profileBuildMs = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now()-profileBuildStart).count();
|
||||
draw_reserve = std::max(draw_reserve, draws.size());
|
||||
if (!draws.empty()) {
|
||||
ava2::FlattenDraws(draws, draw_refs, draw_list);
|
||||
if (!draw_list.empty()) {
|
||||
const auto profileRasterStart = std::chrono::steady_clock::now();
|
||||
uint32_t clear_col = (last_phase == "game") ? current_env.fog.GetColorUint() : 0x00000000;
|
||||
if (use_gpu_raster) {
|
||||
// High Performance Hardware-Accelerated GPU Pipeline (Metal / Vulkan via SDL_RenderGeometry)
|
||||
if (gpu_scene_texture) {
|
||||
// Only the SDL geometry fallback rasterizes at screen coordinates and needs the
|
||||
// scaled intermediate; the hardware pipeline upscales its colour target in one blit.
|
||||
const bool scaled_target = gpu_scene_texture && !renderer3d->HasHardwarePipeline();
|
||||
if (scaled_target) {
|
||||
SDL_SetRenderTarget(renderer.get(), gpu_scene_texture.get());
|
||||
SDL_SetRenderDrawColor(renderer.get(), (clear_col >> 16) & 0xFF, (clear_col >> 8) & 0xFF, clear_col & 0xFF, (clear_col >> 24) & 0xFF);
|
||||
SDL_RenderClear(renderer.get());
|
||||
}
|
||||
|
||||
renderer3d->RenderSceneGPU(renderer.get(), draws);
|
||||
renderer3d->RenderSceneGPU(renderer.get(), draw_list);
|
||||
|
||||
if (gpu_scene_texture) {
|
||||
if (scaled_target) {
|
||||
SDL_SetRenderTarget(renderer.get(), nullptr);
|
||||
SDL_FRect dst = { 0.0f, 0.0f, static_cast<float>(screen_width), static_cast<float>(screen_height) };
|
||||
SDL_RenderTexture(renderer.get(), gpu_scene_texture.get(), nullptr, &dst);
|
||||
@@ -2206,7 +2209,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
// CPU Software Rasterizer (Fallback & Headless verification)
|
||||
SDL_FillSurfaceRect(surface3d.get(), nullptr, clear_col);
|
||||
renderer3d->Clear(clear_col, 1.0f);
|
||||
renderer3d->RenderScene(surface3d.get(), draws);
|
||||
renderer3d->RenderScene(surface3d.get(), draw_list);
|
||||
|
||||
SDL_UpdateTexture(texture3d.get(), nullptr, surface3d->pixels, surface3d->pitch);
|
||||
SDL_FRect dst = { 0.0f, 0.0f, static_cast<float>(screen_width), static_cast<float>(screen_height) };
|
||||
|
||||
@@ -893,6 +893,14 @@ std::shared_ptr<ActorInstance> NetworkActorManager::GetActorInstance(uint32_t vi
|
||||
return (it != m_actors.end()) ? it->second.m_pActorInstance : nullptr;
|
||||
}
|
||||
|
||||
void NetworkActorManager::UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ) {
|
||||
for (auto& [vid, actorData] : m_actors) {
|
||||
(void)vid;
|
||||
if (actorData.m_pActorInstance) actorData.m_pActorInstance->UpdateLODLevel(eyeX, eyeY, eyeZ, targetX, targetZ);
|
||||
if (actorData.m_pMountInstance) actorData.m_pMountInstance->UpdateLODLevel(eyeX, eyeY, eyeZ, targetX, targetZ);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> NetworkActorManager::BuildDrawCommands(float animTime, const float* view, const float* proj) {
|
||||
(void)animTime;
|
||||
std::vector<Render3DDraw> allDraws;
|
||||
|
||||
@@ -284,6 +284,8 @@ public:
|
||||
|
||||
// Helpers to build 3D rendering draw calls for all visible network actors
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animTime, const float* view = nullptr, const float* proj = nullptr);
|
||||
// CArea/CInstanceBase -> CGraphicThingInstance::UpdateLODLevel for every actor and mount.
|
||||
void UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ);
|
||||
|
||||
private:
|
||||
uint32_t m_mainVID = 0;
|
||||
|
||||
@@ -45,6 +45,7 @@ void ActorInstance::SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const
|
||||
m_boundsModel = nullptr;
|
||||
m_model = std::move(model);
|
||||
m_modelPath = m_model ? path : std::string();
|
||||
ResetLodModel();
|
||||
RebindParts();
|
||||
// A new PART_MAIN instance restarts the current motion on it.
|
||||
if (m_model) {
|
||||
@@ -204,6 +205,24 @@ void ActorInstance::SetSashScale(float sx, float sy, float sz) {
|
||||
RebindParts();
|
||||
}
|
||||
|
||||
void ActorInstance::ResetLodModel() {
|
||||
// CActorInstance registers NoExtension(model) + "_lod_01.gr2" when it exists; only then does
|
||||
// CGrannyLODController::UpdateLODLevel lower the animation FPS (m_que_pkModelInst.size() > 1).
|
||||
m_hasLodModel = false;
|
||||
m_lodAniFps = 120;
|
||||
m_poseTimeValid = false;
|
||||
if (!m_model) return;
|
||||
const size_t dot = m_modelPath.find_last_of('.');
|
||||
const bool hasExtension = dot != std::string::npos && m_modelPath.find_first_of("/\\", dot) == std::string::npos;
|
||||
std::error_code error;
|
||||
m_hasLodModel = std::filesystem::is_regular_file(ResolvePath((hasExtension ? m_modelPath.substr(0, dot) : m_modelPath) + "_lod_01.gr2"), error);
|
||||
// CGrannyLODController::AddModel: models of 500 units or more use the building LOD distance.
|
||||
float loX, loY, loZ, hiX, hiY, hiZ;
|
||||
m_lodDistance = 5000.0f; // LODDISTANCE_ACTOR
|
||||
if (m_model->GetLocalBounds(loX, loY, loZ, hiX, hiY, hiZ) && std::max({hiX - loX, hiY - loY, hiZ - loZ}) >= 500.0f)
|
||||
m_lodDistance = 25000.0f; // LODDISTANCE_BUILDING
|
||||
}
|
||||
|
||||
bool ActorInstance::SetModel(const std::string& modelPath) {
|
||||
std::string resolved = ResolvePath(modelPath);
|
||||
if (!std::filesystem::exists(resolved)) {
|
||||
@@ -214,6 +233,7 @@ bool ActorInstance::SetModel(const std::string& modelPath) {
|
||||
m_model = Gr2ModelInstance::Load(resolved);
|
||||
if (!m_model) return false;
|
||||
m_modelPath = modelPath;
|
||||
ResetLodModel();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -457,6 +477,7 @@ void ActorInstance::Update(float dt, const TerrainHeightSource* terrain, const M
|
||||
|
||||
// Advance animation time
|
||||
m_animTime += dt;
|
||||
m_lodLocalTime += dt; // CGrannyModelInstance::UpdateLocalTime
|
||||
if (!m_motionQueue.empty() && m_animTime >= m_motionDuration) {
|
||||
// ReservingMotionProcess: the next pushed motion takes over when the current one ends.
|
||||
const auto next = m_motionQueue.front();
|
||||
@@ -587,7 +608,7 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOve
|
||||
if (!m_model) return {};
|
||||
float world[16];
|
||||
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
|
||||
auto draws = m_model->BuildDrawCommands(m_animTime, worldOverride ? worldOverride : world);
|
||||
auto draws = m_model->BuildDrawCommands(PoseTime(), worldOverride ? worldOverride : world);
|
||||
|
||||
// Shining system (ENABLE_SHINING_SYSTEM): weapon aura / glow
|
||||
if (m_weaponShining > 0) {
|
||||
@@ -662,6 +683,30 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOve
|
||||
return draws;
|
||||
}
|
||||
|
||||
void ActorInstance::UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ) {
|
||||
// CGrannyLODController::UpdateLODLevel; the distance from the camera target ignores height.
|
||||
m_lodAniFps = 120;
|
||||
if (m_hasLodModel) {
|
||||
const float centerX = targetX - m_posX, centerZ = targetZ - m_posZ;
|
||||
if (std::sqrt(centerX * centerX + centerZ * centerZ) > 500.0f) { // LOD_APPLY_MIN
|
||||
const float dx = eyeX - m_posX, dy = eyeY - m_posY, dz = eyeZ - m_posZ;
|
||||
const float factor = std::clamp(m_lodDistance - std::sqrt(dx * dx + dy * dy + dz * dz), 0.0f, m_lodDistance);
|
||||
m_lodAniFps = static_cast<uint32_t>((120 - 30) * factor / m_lodDistance + 30) / 10 * 10; // ANIFPS_MAX/MIN
|
||||
}
|
||||
}
|
||||
// CGrannyModelInstance::Update: hold the pose until the next ANIFPS_STEP frame. A restarted or
|
||||
// switched motion (time going back, new model) re-samples at once instead of mixing clips.
|
||||
const uint32_t frame = static_cast<uint32_t>(m_lodLocalTime * 120.0f);
|
||||
const uint32_t step = 120 / m_lodAniFps;
|
||||
if (m_poseTimeValid && m_poseModel == m_model.get() && m_animTime >= m_poseAnimTime
|
||||
&& frame > step && frame / step == m_oldUpdateFrame / step)
|
||||
return;
|
||||
m_oldUpdateFrame = frame;
|
||||
m_poseAnimTime = m_animTime;
|
||||
m_poseModel = m_model.get();
|
||||
m_poseTimeValid = step > 1; // full rate: always draw the current time
|
||||
}
|
||||
|
||||
bool ActorInstance::IsVisible(const float* view, const float* proj) const {
|
||||
if (!view || !proj || !m_model) return true;
|
||||
if (m_boundsModel != m_model.get()) {
|
||||
@@ -705,7 +750,7 @@ bool ActorInstance::HitTestScreen(float clickX, float clickY, const Gr2SceneRend
|
||||
bool ActorInstance::GetBoneWorldTransform(const std::string& boneName, float* outWorld16) const {
|
||||
if (!m_model || !outWorld16) return false;
|
||||
float localBone[16];
|
||||
if (!m_model->GetBoneWorldTransform(boneName, localBone, m_animTime)) {
|
||||
if (!m_model->GetBoneWorldTransform(boneName, localBone, PoseTime())) {
|
||||
return false;
|
||||
}
|
||||
// Bone poses are still Granny Z-up, just like the mesh vertices. Convert
|
||||
|
||||
@@ -210,6 +210,10 @@ public:
|
||||
|
||||
// Generate 3D draw commands
|
||||
std::vector<Render3DDraw> BuildDrawCommands(const float* worldOverride = nullptr);
|
||||
// CGraphicThingInstance::UpdateLODLevel + CGrannyModelInstance::Update(dwAniFPS): actors with
|
||||
// _lod_ models far from the camera sample their pose at a reduced animation FPS (Y-up world).
|
||||
void UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ);
|
||||
uint32_t GetLODAniFPS() const { return m_lodAniFps; }
|
||||
|
||||
Gr2ModelInstance* GetModel() { return m_model.get(); }
|
||||
const std::string& GetModelPath() const { return m_modelPath; }
|
||||
@@ -218,6 +222,7 @@ private:
|
||||
std::string ResolvePath(const std::string& path) const;
|
||||
std::shared_ptr<Gr2ModelInstance> LoadPartModel(const std::string& path) const;
|
||||
void SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const std::string& path);
|
||||
void ResetLodModel();
|
||||
void AttachWeaponPart(uint32_t part, const SPartItem& item);
|
||||
void RebindParts();
|
||||
|
||||
@@ -241,6 +246,16 @@ private:
|
||||
mutable const Gr2ModelInstance* m_boundsModel = nullptr;
|
||||
mutable float m_boundsRadius = 500.f;
|
||||
std::string m_modelPath;
|
||||
// LOD animation rate (CGrannyLODController); the meshes of _lod_01.._03 are still not ported.
|
||||
float PoseTime() const { return m_poseTimeValid ? m_poseAnimTime : m_animTime; }
|
||||
bool m_hasLodModel = false;
|
||||
float m_lodDistance = 5000.0f; // LODDISTANCE_ACTOR, LODDISTANCE_BUILDING for size >= 500
|
||||
float m_lodLocalTime = 0.0f;
|
||||
uint32_t m_lodAniFps = 120; // CGrannyModelInstance::ANIFPS_MAX
|
||||
uint32_t m_oldUpdateFrame = 0;
|
||||
float m_poseAnimTime = 0.0f;
|
||||
bool m_poseTimeValid = false;
|
||||
const Gr2ModelInstance* m_poseModel = nullptr;
|
||||
|
||||
std::unordered_map<MotionType, std::string> m_motionPaths;
|
||||
MotionType m_currentMotion = MotionType::Wait;
|
||||
|
||||
@@ -733,6 +733,14 @@ void Gr2SceneRenderer::RenderScene(SDL_Surface* targetSurface, const std::vector
|
||||
TrimTextureCaches(true);
|
||||
}
|
||||
|
||||
void Gr2SceneRenderer::RenderScene(SDL_Surface* targetSurface, const std::vector<const Render3DDraw*>& draws) {
|
||||
++m_textureFrame;
|
||||
for (const auto* draw : draws) {
|
||||
RenderDraw(targetSurface, *draw);
|
||||
}
|
||||
TrimTextureCaches(true);
|
||||
}
|
||||
|
||||
void Gr2SceneRenderer::DestroyGPUTextures() {
|
||||
for (auto& pair : m_gpuTextureCache) {
|
||||
if (pair.second.texture) {
|
||||
@@ -805,6 +813,13 @@ void Gr2SceneRenderer::SetGPUDevice(SDL_GPUDevice* device) {
|
||||
}
|
||||
|
||||
void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<Render3DDraw>& draws) {
|
||||
m_scratchDrawPtrs.clear();
|
||||
m_scratchDrawPtrs.reserve(draws.size());
|
||||
for (const auto& d : draws) m_scratchDrawPtrs.push_back(&d);
|
||||
RenderSceneGPU(renderer, m_scratchDrawPtrs);
|
||||
}
|
||||
|
||||
void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<const Render3DDraw*>& draws) {
|
||||
if (!renderer || draws.empty()) return;
|
||||
++m_textureFrame;
|
||||
|
||||
@@ -825,7 +840,8 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
|
||||
m_scratchSortedDraws.clear();
|
||||
m_scratchSortedDraws.reserve(draws.size());
|
||||
|
||||
for (const auto& d : draws) {
|
||||
for (const auto* drawPtr : draws) {
|
||||
const auto& d = *drawPtr;
|
||||
DrawOrder ord;
|
||||
ord.draw = &d;
|
||||
const auto& sortedMesh = d.Mesh();
|
||||
@@ -864,9 +880,14 @@ void Gr2SceneRenderer::RenderSceneGPU(SDL_Renderer* renderer, const std::vector<
|
||||
|
||||
std::stable_sort(m_scratchSortedDraws.begin(),m_scratchSortedDraws.end(),[this](const DrawOrder& a,const DrawOrder& b){
|
||||
if(a.priority!=b.priority)return a.priority<b.priority;
|
||||
if(m_hardware && a.priority==1) {
|
||||
if(a.draw->alpha_blend!=b.draw->alpha_blend)return !a.draw->alpha_blend;
|
||||
if(!a.draw->alpha_blend) {
|
||||
if(m_hardware && (a.priority==1 || a.priority==3)) {
|
||||
// Opaque and alpha-tested draws that write depth do not depend on submission order:
|
||||
// group them by pipeline state (cull/depth write), then texture and geometry, so
|
||||
// HardwareScene can skip redundant binds and instance runs. Everything else stays back to front.
|
||||
const bool aState=!a.draw->alpha_blend&&a.draw->z_write,bState=!b.draw->alpha_blend&&b.draw->z_write;
|
||||
if(aState!=bState)return aState;
|
||||
if(aState) {
|
||||
if(a.draw->cull_mode!=b.draw->cull_mode)return a.draw->cull_mode<b.draw->cull_mode;
|
||||
if(a.texture!=b.texture)return std::less<SDL_GPUTexture*>{}(a.texture,b.texture);
|
||||
if(a.draw->geometry.get()!=b.draw->geometry.get())return std::less<const Render3DDraw*>{}(a.draw->geometry.get(),b.draw->geometry.get());
|
||||
return a.depth<b.depth;
|
||||
|
||||
@@ -90,10 +90,14 @@ public:
|
||||
|
||||
// Rasterize a list of draw commands (CPU software rasterizer)
|
||||
void RenderScene(SDL_Surface* targetSurface, const std::vector<Render3DDraw>& draws);
|
||||
void RenderScene(SDL_Surface* targetSurface, const std::vector<const Render3DDraw*>& draws);
|
||||
|
||||
// Native SDL_GPU depth/perspective pipeline; SDL geometry fallback for software renderers.
|
||||
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<Render3DDraw>& draws);
|
||||
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<const Render3DDraw*>& draws);
|
||||
void SetGPUDevice(SDL_GPUDevice* device);
|
||||
// The SDL_GPU pipeline composites its own (smaller) colour target to the full render target.
|
||||
bool HasHardwarePipeline() const { return m_hardware != nullptr; }
|
||||
void DestroyGPUTextures();
|
||||
SDL_Texture* GetGPUTexture(SDL_Renderer* renderer, const std::string& texturePath);
|
||||
|
||||
@@ -166,6 +170,7 @@ private:
|
||||
|
||||
// Persistent scratch buffers to eliminate per-draw heap allocation churn in RenderSceneGPU
|
||||
std::vector<DrawOrder> m_scratchSortedDraws;
|
||||
std::vector<const Render3DDraw*> m_scratchDrawPtrs;
|
||||
std::vector<GpuTransformedVertex> m_scratchGpuXverts;
|
||||
std::vector<SDL_Vertex> m_scratchSdlVertices;
|
||||
std::vector<int> m_scratchSdlIndices;
|
||||
|
||||
@@ -127,12 +127,13 @@ bool HardwareScene::Initialize(SDL_Renderer* renderer,int width,int height) {
|
||||
// The target accumulates premultiplied colors. Transparent pixels keep
|
||||
// the Python selection background and other existing 2D layers intact.
|
||||
SDL_SetTextureBlendMode(output_,SDL_BLENDMODE_BLEND_PREMULTIPLIED);
|
||||
SDL_SetTextureScaleMode(output_,SDL_SCALEMODE_LINEAR); // render-scale < 1 upscales in the composite
|
||||
width_=width;height_=height;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SDL_GPUGraphicsPipeline* HardwareScene::Pipeline(const HardwareBatch& b) {
|
||||
unsigned key=b.cull|(b.depth<<3)|(b.depthWrite<<4)|(b.blend<<5)|(b.additive<<6);
|
||||
const unsigned key=PipelineKey(b);
|
||||
auto it=pipelines_.find(key);if(it!=pipelines_.end())return it->second;
|
||||
SDL_GPUGraphicsPipelineCreateInfo info{};
|
||||
info.vertex_shader=vertex_;info.fragment_shader=fragment_;info.primitive_type=SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
||||
@@ -299,6 +300,10 @@ bool HardwareScene::Render(SDL_Renderer* renderer,int width,int height,const std
|
||||
HardwareTransform header{};header.modes[0]=2;SDL_PushGPUVertexUniformData(cmd,0,&header,sizeof(header));
|
||||
float pushedParams[4]={-2,-1,0,0}; // never a real alphaRef/opaque pair
|
||||
const std::vector<float>* pushedPalette=nullptr; // draws of one instance share a palette; push once
|
||||
// Bindings persist within the pass (SDL re-applies them after a pipeline change); skip redundant ones,
|
||||
// each sampler rebind costs a fresh descriptor set on Vulkan.
|
||||
SDL_GPUBuffer* boundVertices=nullptr;SDL_GPUBuffer* boundIndices=nullptr;SDL_GPUTexture* boundTexture=nullptr;
|
||||
unsigned boundPipeline=~0u;
|
||||
for(size_t i=0;i<batches.size();) {
|
||||
const auto& batch=batches[i];auto* mesh=meshes[i];
|
||||
size_t count=1;
|
||||
@@ -309,10 +314,12 @@ bool HardwareScene::Render(SDL_Renderer* renderer,int width,int height,const std
|
||||
if(meshes[i+count]!=mesh || next.firstIndex!=batch.firstIndex || next.indexCount!=batch.indexCount || next.texture!=batch.texture || next.cull!=batch.cull || next.depth!=batch.depth || next.depthWrite!=batch.depthWrite || next.blend || next.additive || next.alphaRef!=batch.alphaRef || next.transform.skin[0]!=0 || next.transform.modes[0]<.5f)break;
|
||||
++count;
|
||||
}
|
||||
SDL_GPUBufferBinding binding{mesh ? mesh->vertices : vertices_,0};SDL_BindGPUVertexBuffers(pass,0,&binding,1);
|
||||
binding.buffer=mesh ? mesh->indices : indices_;SDL_BindGPUIndexBuffer(pass,&binding,SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||
SDL_BindGPUGraphicsPipeline(pass,Pipeline(batch));
|
||||
SDL_GPUTextureSamplerBinding texture{batch.texture ? batch.texture : white_,sampler_};SDL_BindGPUFragmentSamplers(pass,0,&texture,1);
|
||||
SDL_GPUBuffer* vertexBuffer=mesh ? mesh->vertices : vertices_;SDL_GPUBuffer* indexBuffer=mesh ? mesh->indices : indices_;
|
||||
if(vertexBuffer!=boundVertices){boundVertices=vertexBuffer;SDL_GPUBufferBinding binding{vertexBuffer,0};SDL_BindGPUVertexBuffers(pass,0,&binding,1);}
|
||||
if(indexBuffer!=boundIndices){boundIndices=indexBuffer;SDL_GPUBufferBinding binding{indexBuffer,0};SDL_BindGPUIndexBuffer(pass,&binding,SDL_GPU_INDEXELEMENTSIZE_32BIT);}
|
||||
if(PipelineKey(batch)!=boundPipeline){boundPipeline=PipelineKey(batch);SDL_BindGPUGraphicsPipeline(pass,Pipeline(batch));}
|
||||
SDL_GPUTexture* batchTexture=batch.texture ? batch.texture : white_;
|
||||
if(batchTexture!=boundTexture){boundTexture=batchTexture;SDL_GPUTextureSamplerBinding texture{batchTexture,sampler_};SDL_BindGPUFragmentSamplers(pass,0,&texture,1);}
|
||||
float params[4]={batch.alphaRef,(!batch.blend&&!batch.additive)?1.f:0.f,0,0};
|
||||
if(std::memcmp(params,pushedParams,sizeof(params))!=0){std::memcpy(pushedParams,params,sizeof(params));SDL_PushGPUFragmentUniformData(cmd,0,params,sizeof(params));}
|
||||
const auto& transform=batch.transform;
|
||||
|
||||
@@ -36,8 +36,10 @@ struct HardwareBatch {
|
||||
HardwareTransform transform{};
|
||||
std::shared_ptr<const Render3DDraw> geometry;
|
||||
std::shared_ptr<const std::vector<float>> palette;
|
||||
|
||||
};
|
||||
inline unsigned PipelineKey(const HardwareBatch& b) {
|
||||
return b.cull|(unsigned(b.depth)<<3)|(unsigned(b.depthWrite)<<4)|(unsigned(b.blend)<<5)|(unsigned(b.additive)<<6);
|
||||
}
|
||||
class HardwareScene {
|
||||
public:
|
||||
explicit HardwareScene(SDL_GPUDevice* device): device_(device) {}
|
||||
|
||||
@@ -374,9 +374,22 @@ bool MapObjectManager::CheckCollisionNormal(float worldX, float worldZ, float ac
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands(const float* view, const float* proj) const {
|
||||
std::vector<Render3DDrawRef> refs;
|
||||
AppendDrawRefs(view, proj, 0, refs);
|
||||
std::vector<Render3DDraw> all_draws;
|
||||
all_draws.reserve(refs.size());
|
||||
for (const auto& ref : refs) all_draws.push_back(*ref.draw);
|
||||
return all_draws;
|
||||
}
|
||||
|
||||
void MapObjectManager::AppendDrawRefs(const float* view, const float* proj, std::size_t before, std::vector<Render3DDrawRef>& out,
|
||||
const float* light_direction, const float* light_ambient) const {
|
||||
for (const auto& obj : m_objects) {
|
||||
if (!obj.model) continue;
|
||||
if (m_maxDistanceSq > 0.0f) {
|
||||
const float dx = obj.x - m_centerX, dz = obj.z - m_centerZ;
|
||||
if (dx * dx + dz * dz >= m_maxDistanceSq) continue;
|
||||
}
|
||||
|
||||
float world[16];
|
||||
MakeFullTransformMatrix(obj.yaw, obj.pitch, obj.roll, obj.x, obj.y, obj.z, obj.scale, world);
|
||||
@@ -404,9 +417,12 @@ std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands(const float* view,
|
||||
obj.draws_cached = true;
|
||||
}
|
||||
if (!IsBoundsVisible(obj.bounds_min, obj.bounds_max, view, proj)) continue;
|
||||
all_draws.insert(all_draws.end(), obj.cached_draws.begin(), obj.cached_draws.end());
|
||||
for (auto& draw : obj.cached_draws) {
|
||||
if (light_direction) std::copy_n(light_direction, 3, draw.light_direction);
|
||||
if (light_ambient) std::copy_n(light_ambient, 3, draw.light_ambient);
|
||||
out.push_back({before, &draw});
|
||||
}
|
||||
}
|
||||
return all_draws;
|
||||
}
|
||||
|
||||
void MapObjectManager::ClearObjects() {
|
||||
|
||||
@@ -134,6 +134,10 @@ public:
|
||||
|
||||
// Build 3D draw commands for all instantiated objects
|
||||
std::vector<Render3DDraw> BuildDrawCommands(const float* view = nullptr, const float* proj = nullptr) const;
|
||||
// Same visible set without copying: the cached commands are referenced, spliced before owned[before].
|
||||
// Valid until the objects are cleared or added to. light_* (optional) are written into the cache.
|
||||
void AppendDrawRefs(const float* view, const float* proj, std::size_t before, std::vector<Render3DDrawRef>& out,
|
||||
const float* light_direction = nullptr, const float* light_ambient = nullptr) const;
|
||||
|
||||
// Clear all instantiated objects (retaining loaded model cache)
|
||||
void ClearObjects();
|
||||
@@ -145,6 +149,9 @@ public:
|
||||
size_t GetCachedModelCount() const { return m_model_cache.size(); }
|
||||
|
||||
const std::vector<MapObjectInstance>& GetObjects() const { return m_objects; }
|
||||
// CArea::__UpdateLoadedObjectInstances (ENABLE_MAP_OBJECT_OPTIMIZATION): objects farther than
|
||||
// maxDistance (2D, from the main actor) are not drawn. maxDistance <= 0 draws everything.
|
||||
void SetLoadingCenter(float x, float z, float maxDistance) { m_centerX = x; m_centerZ = z; m_maxDistanceSq = maxDistance > 0.0f ? maxDistance * maxDistance : 0.0f; }
|
||||
|
||||
private:
|
||||
const std::vector<size_t>& CollisionCandidates(float x,float z,float radius) const;
|
||||
@@ -158,6 +165,7 @@ private:
|
||||
std::unordered_map<std::string, std::shared_ptr<Gr2ModelInstance>> m_model_cache;
|
||||
mutable std::unordered_map<const Gr2ModelInstance*,std::vector<std::shared_ptr<const Render3DDraw>>> m_meshStreams;
|
||||
std::vector<MapObjectInstance> m_objects;
|
||||
float m_centerX = 0.0f, m_centerZ = 0.0f, m_maxDistanceSq = 0.0f;
|
||||
};
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -115,4 +115,22 @@ struct Render3DDraw {
|
||||
float light_ambient[4] = {0.55f, 0.55f, 0.55f, 1.0f};
|
||||
};
|
||||
|
||||
// A cached command submitted by pointer instead of copied into the frame's list; it is
|
||||
// drawn just before owned[before], so the flattened order equals a single flat list.
|
||||
struct Render3DDrawRef {
|
||||
std::size_t before = 0;
|
||||
const Render3DDraw* draw = nullptr;
|
||||
};
|
||||
|
||||
inline void FlattenDraws(const std::vector<Render3DDraw>& owned, const std::vector<Render3DDrawRef>& refs,
|
||||
std::vector<const Render3DDraw*>& out) {
|
||||
out.clear();
|
||||
out.reserve(owned.size() + refs.size());
|
||||
std::size_t r = 0;
|
||||
for (std::size_t i = 0; i <= owned.size(); ++i) {
|
||||
for (; r < refs.size() && refs[r].before <= i; ++r) out.push_back(refs[r].draw);
|
||||
if (i < owned.size()) out.push_back(&owned[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -600,8 +600,18 @@ void TerrainHeightmap::QueryQuadtree(const TerrainQuadNode* node, const float pl
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> TerrainHeightmap::BuildCulledDraws(const float view[16], const float proj[16], float max_distance) const {
|
||||
std::vector<Render3DDrawRef> refs;
|
||||
AppendCulledDrawRefs(view, proj, max_distance, 0, refs);
|
||||
std::vector<Render3DDraw> draws;
|
||||
if (m_heights.empty() || m_patches.empty() || !m_quadtreeRoot) return draws;
|
||||
draws.reserve(refs.size());
|
||||
for (const auto& ref : refs) draws.push_back(*ref.draw);
|
||||
return draws;
|
||||
}
|
||||
|
||||
void TerrainHeightmap::AppendCulledDrawRefs(const float view[16], const float proj[16], float max_distance, std::size_t before,
|
||||
std::vector<Render3DDrawRef>& out,
|
||||
const float* light_direction, const float* light_ambient) const {
|
||||
if (m_heights.empty() || m_patches.empty() || !m_quadtreeRoot) return;
|
||||
|
||||
float planes[6][4];
|
||||
ExtractFrustumPlanes(view, proj, planes);
|
||||
@@ -634,10 +644,12 @@ std::vector<Render3DDraw> TerrainHeightmap::BuildCulledDraws(const float view[16
|
||||
for (auto& draw : patchDraws) draw = Render3DDraw::ShareGeometry(std::move(draw));
|
||||
it = m_patchDrawCache.emplace(key, std::move(patchDraws)).first;
|
||||
}
|
||||
draws.insert(draws.end(), it->second.begin(), it->second.end());
|
||||
for (auto& draw : it->second) {
|
||||
if (light_direction) std::copy_n(light_direction, 3, draw.light_direction);
|
||||
if (light_ambient) std::copy_n(light_ambient, 3, draw.light_ambient);
|
||||
out.push_back({before, &draw});
|
||||
}
|
||||
}
|
||||
|
||||
return draws;
|
||||
}
|
||||
|
||||
Render3DDraw TerrainHeightmap::BuildPatchDraw(int patch_x, int patch_y, int step) const {
|
||||
|
||||
@@ -122,6 +122,11 @@ public:
|
||||
|
||||
// Build multi-texture, patch-subdivided 3D draw commands with QuadTree frustum culling
|
||||
std::vector<Render3DDraw> BuildCulledDraws(const float view[16], const float proj[16], float max_distance = 4000.0f) const;
|
||||
// Same visible patches without copying: cached patch commands are referenced, spliced before owned[before].
|
||||
// Valid until the heightmap is reloaded/edited. light_* (optional) are written into the cache.
|
||||
void AppendCulledDrawRefs(const float view[16], const float proj[16], float max_distance, std::size_t before,
|
||||
std::vector<Render3DDrawRef>& out,
|
||||
const float* light_direction = nullptr, const float* light_ambient = nullptr) const;
|
||||
|
||||
// Build patch draw command for a single patch
|
||||
Render3DDraw BuildPatchDraw(int patch_x, int patch_y, int step = 1) const;
|
||||
|
||||
@@ -589,8 +589,12 @@ void CPythonBackground::DeleteSpecialEffect(uint32_t dwID) {
|
||||
(void)dwID;
|
||||
}
|
||||
|
||||
void CPythonBackground::Update(float fCameraX, float fCameraY, float fCameraZ) {
|
||||
(void)fCameraX; (void)fCameraY; (void)fCameraZ;
|
||||
void CPythonBackground::Update(float fCenterX, float fCenterY, float fCenterZ) {
|
||||
(void)fCenterY;
|
||||
if (m_mapObjects) {
|
||||
// CArea::GetMaxLoadingDistanceSqr: OBJECT_DIST, never under 5000.
|
||||
m_mapObjects->SetLoadingCenter(fCenterX, fCenterZ, std::max(5000.0f, CPythonSystem::Instance().GetObjectDistance()));
|
||||
}
|
||||
if (m_skybox) {
|
||||
m_skybox->Update(0.033f);
|
||||
}
|
||||
@@ -632,9 +636,21 @@ void CPythonBackground::RenderCharacterShadowToTexture() {
|
||||
void CPythonBackground::RenderSnow() {
|
||||
}
|
||||
|
||||
void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws) {
|
||||
void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws,
|
||||
std::vector<Render3DDrawRef>* outRefs) {
|
||||
if (!IsMapReady()) return;
|
||||
|
||||
// Background light written into the referenced (cached) terrain and map-object commands.
|
||||
float lightDir[3], lightAmbient[3];
|
||||
if (m_pCurrentEnvironment) {
|
||||
std::copy_n(m_pCurrentEnvironment->dir_light.direction, 3, lightDir);
|
||||
lightAmbient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
|
||||
lightAmbient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
|
||||
lightAmbient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
|
||||
}
|
||||
const float* refLightDir = m_pCurrentEnvironment ? lightDir : nullptr;
|
||||
const float* refLightAmbient = m_pCurrentEnvironment ? lightAmbient : nullptr;
|
||||
|
||||
if (m_bVisiblePart[PART_SKY] && m_skybox && viewMatrix && projMatrix && camPos) {
|
||||
auto sdraws = m_skybox->BuildDrawCommands(viewMatrix, projMatrix, camPos[0], camPos[1], camPos[2]);
|
||||
for (auto& sd : sdraws) outDraws.push_back(std::move(sd));
|
||||
@@ -642,10 +658,15 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
|
||||
|
||||
if (m_bVisiblePart[PART_TERRAIN] && m_terrain) {
|
||||
std::vector<Render3DDraw> tdraws;
|
||||
if (viewMatrix && projMatrix) {
|
||||
bool referenced = false;
|
||||
if (viewMatrix && projMatrix && outRefs) {
|
||||
const size_t refCount = outRefs->size();
|
||||
m_terrain->AppendCulledDrawRefs(viewMatrix, projMatrix, GetFarClip(), outDraws.size(), *outRefs, refLightDir, refLightAmbient);
|
||||
referenced = outRefs->size() != refCount;
|
||||
} else if (viewMatrix && projMatrix) {
|
||||
tdraws = m_terrain->BuildCulledDraws(viewMatrix, projMatrix, GetFarClip());
|
||||
}
|
||||
if (tdraws.empty()) {
|
||||
if (!referenced && tdraws.empty()) {
|
||||
auto td = m_terrain->BuildDrawCommand(nullptr, 2);
|
||||
if (!td.positions.empty()) tdraws.push_back(std::move(td));
|
||||
}
|
||||
@@ -675,7 +696,9 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
|
||||
outDraws.push_back(std::move(wd));
|
||||
}
|
||||
|
||||
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
|
||||
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects && outRefs) {
|
||||
m_mapObjects->AppendDrawRefs(viewMatrix, projMatrix, outDraws.size(), *outRefs, refLightDir, refLightAmbient);
|
||||
} else if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
|
||||
auto bdraws = m_mapObjects->BuildDrawCommands(viewMatrix, projMatrix);
|
||||
for (auto& bd : bdraws) {
|
||||
if (m_pCurrentEnvironment) {
|
||||
|
||||
@@ -184,7 +184,8 @@ public:
|
||||
void CreateSpecialEffect(uint32_t dwID, float fx, float fy, float fz, const char* szFileName);
|
||||
void DeleteSpecialEffect(uint32_t dwID);
|
||||
|
||||
void Update(float fCameraX, float fCameraY, float fCameraZ);
|
||||
// Original CPythonApplication passes the main actor position (map-object loading center).
|
||||
void Update(float fCenterX, float fCenterY, float fCenterZ);
|
||||
|
||||
void Render();
|
||||
void RenderSky();
|
||||
@@ -205,7 +206,9 @@ public:
|
||||
SpeedTreeForest* GetForest() { return m_forest.get(); }
|
||||
const OutdoorMapInfo* GetOutdoorMap() const { return m_strMapName.empty() ? nullptr : &m_outdoorMap; }
|
||||
|
||||
void BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws);
|
||||
// outRefs (optional) receives the cached map-object commands by pointer instead of copies in outDraws.
|
||||
void BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws,
|
||||
std::vector<Render3DDrawRef>* outRefs = nullptr);
|
||||
|
||||
private:
|
||||
void LoadAtlas();
|
||||
|
||||
@@ -828,6 +828,30 @@ int main(int argc, char** argv) {
|
||||
const auto poseBeforeCull = actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
|
||||
assert(!actor.IsVisible(cullCamera.GetViewMatrix(),cullCamera.GetProjMatrix()));
|
||||
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()==poseBeforeCull);
|
||||
|
||||
// CGrannyLODController: warrior_assasin1 has _lod_ models, so far from the camera it animates at
|
||||
// ANIFPS_MIN (pose re-sampled every 4/120 s) and near the camera target at full rate.
|
||||
actor.SetPosition(0,0,0);
|
||||
actor.UpdateLODLevel(0,200,-300,0,0);
|
||||
assert(actor.GetLODAniFPS()==120);
|
||||
actor.UpdateLODLevel(0,200,-4900,2000,0);
|
||||
assert(actor.GetLODAniFPS()==30);
|
||||
float lodBone[16];
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
const auto poseBeforeLod=actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
|
||||
for(int frame=0;frame<24;++frame){
|
||||
actor.Update(1.0f/60.0f,&terrain);
|
||||
actor.UpdateLODLevel(0,200,-4900,2000,0);
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
}
|
||||
const auto farEvaluations=actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod;
|
||||
assert(farEvaluations>=10 && farEvaluations<=14 && "30 FPS animation over 0.4 s");
|
||||
for(int frame=0;frame<24;++frame){
|
||||
actor.Update(1.0f/60.0f,&terrain);
|
||||
actor.UpdateLODLevel(0,200,-300,0,0);
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
}
|
||||
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod-farEvaluations==24);
|
||||
assert(actor.IsVisible(nullptr,nullptr));
|
||||
|
||||
// Test movement driving
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
int main() {
|
||||
{ // Referenced (cached) commands splice in before owned[before], in submission order.
|
||||
std::vector<ava2::Render3DDraw> owned(3);ava2::Render3DDraw cachedA,cachedB,cachedC;
|
||||
std::vector<ava2::Render3DDrawRef> refs{{1,&cachedA},{1,&cachedB},{3,&cachedC}};
|
||||
std::vector<const ava2::Render3DDraw*> list;ava2::FlattenDraws(owned,refs,list);
|
||||
const std::vector<const ava2::Render3DDraw*> expect{&owned[0],&cachedA,&cachedB,&owned[1],&owned[2],&cachedC};
|
||||
assert(list==expect);
|
||||
}
|
||||
if(!SDL_Init(SDL_INIT_VIDEO))return 77;
|
||||
auto* device=SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_MSL|SDL_GPU_SHADERFORMAT_SPIRV,true,nullptr);
|
||||
if(!device){SDL_Quit();return 77;}
|
||||
@@ -73,6 +80,19 @@ int main() {
|
||||
for(int i=0;i<100;++i)UI::DrawText(renderer,"NPC label",12,0,0,i%2 ? 0xffff0000 : 0xff00ff00);
|
||||
assert(SDL_RenderPresent(renderer));
|
||||
}
|
||||
{ // Render scale < 1: a smaller colour target is upscaled over the whole render target in the composite.
|
||||
ava2::HardwareScene scaled(device);
|
||||
std::vector<ava2::HardwareVertex> quad;
|
||||
for(auto p: {std::pair{-1.f,-1.f},std::pair{1.f,-1.f},std::pair{1.f,1.f},std::pair{-1.f,1.f}})
|
||||
quad.push_back({{p.first,p.second,.5f,1},{255,0,0,255},{0,0}});
|
||||
SDL_SetRenderDrawColor(renderer,0,255,0,255);SDL_RenderClear(renderer);
|
||||
assert(scaled.Render(renderer,32,32,quad,{0,1,2,0,2,3},{{0,6,nullptr,1,true,true,false,false,-1}}));
|
||||
auto* pixels=SDL_RenderReadPixels(renderer,nullptr);assert(pixels);
|
||||
auto redAt=[&](int x,int y){Uint32 v=0;std::memcpy(&v,static_cast<Uint8*>(pixels->pixels)+y*pixels->pitch+x*SDL_BYTESPERPIXEL(pixels->format),SDL_BYTESPERPIXEL(pixels->format));
|
||||
Uint8 r,g,b,a;SDL_GetRGBA(v,SDL_GetPixelFormatDetails(pixels->format),nullptr,&r,&g,&b,&a);return r>245&&g<5;};
|
||||
assert(redAt(1,1)&&redAt(62,62)&&redAt(62,1)&&redAt(1,62)&&redAt(32,32));
|
||||
SDL_DestroySurface(pixels);SDL_RenderPresent(renderer);
|
||||
}
|
||||
{
|
||||
ava2::Gr2SceneRenderer raster(64,64);
|
||||
raster.SetGPUDevice(device);
|
||||
|
||||
Reference in New Issue
Block a user