临时可运行版本。已将SceneWorld改名为Scene,下一步改文件名。并将default_scene,default_renderer放在RenderFramework中

This commit is contained in:
hyzboy 2025-06-04 00:04:46 +08:00
parent 5c186fdb95
commit 839e187cb2
9 changed files with 49 additions and 34 deletions

View File

@ -26,18 +26,15 @@ namespace hgl
graph::RenderPass *render_pass=nullptr; graph::RenderPass *render_pass=nullptr;
bool destroy_flag=false; bool destroy_flag=false;
bool render_dirty=true;
protected: protected:
//以下数据均取自RenderFramework
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代 graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
/** graph::Scene * scene=nullptr; //场景
* WorkObject中SceneWorld以及一个Renderer即可
* WorldWorkObject上
*/
graph::SceneWorld * world =nullptr; //世界
graph::Renderer * renderer=nullptr; //渲染器 graph::Renderer * renderer=nullptr; //渲染器
public: public:
@ -54,6 +51,9 @@ namespace hgl
const bool IsDestroy ()const{return destroy_flag;} const bool IsDestroy ()const{return destroy_flag;}
void MarkDestory(){destroy_flag=true;} void MarkDestory(){destroy_flag=true;}
const bool IsRenderDirty ()const{return render_dirty;}
void MarkRenderDirty(){render_dirty=true;}
public: public:
WorkObject(graph::RenderFramework *,graph::IRenderTarget *rt=nullptr); WorkObject(graph::RenderFramework *,graph::IRenderTarget *rt=nullptr);

View File

@ -17,6 +17,9 @@ class RenderTargetManager;
class RenderModule; class RenderModule;
class Scene;
class Renderer;
class CameraComponentManager{/*现阶段测试使用*/}; class CameraComponentManager{/*现阶段测试使用*/};
class LightComponentManager{/*现阶段测试使用*/}; class LightComponentManager{/*现阶段测试使用*/};
@ -47,6 +50,11 @@ protected:
CameraComponentManager *camera_component_manager=nullptr; CameraComponentManager *camera_component_manager=nullptr;
LightComponentManager *light_component_manager =nullptr; LightComponentManager *light_component_manager =nullptr;
protected:
Scene * default_scene =nullptr;
Renderer * default_renderer=nullptr;
public: public:
Window * GetWindow ()const{return win;} Window * GetWindow ()const{return win;}
@ -68,6 +76,11 @@ public:
SwapchainModule * GetSwapchainModule (){return sc_module;} SwapchainModule * GetSwapchainModule (){return sc_module;}
SwapchainRenderTarget * GetSwapchainRenderTarget(){return sc_module?sc_module->GetRenderTarget():nullptr;} SwapchainRenderTarget * GetSwapchainRenderTarget(){return sc_module?sc_module->GetRenderTarget():nullptr;}
public:
Scene * GetDefaultScene (){return default_scene;}
Renderer * GetDefaultRenderer (){return default_renderer;}
public: public:
RenderFramework(const OSString &); RenderFramework(const OSString &);

View File

@ -6,7 +6,7 @@
namespace hgl::graph namespace hgl::graph
{ {
class SceneNode; class SceneNode;
class SceneWorld; class Scene;
class Camera; class Camera;
class IRenderTarget; class IRenderTarget;
class RenderList; class RenderList;

View File

@ -5,7 +5,7 @@
namespace hgl::graph namespace hgl::graph
{ {
class SceneWorld; class Scene;
using RenderTaskNameMap=Map<RenderTaskName,RenderTask *>; using RenderTaskNameMap=Map<RenderTaskName,RenderTask *>;
@ -15,7 +15,7 @@ namespace hgl::graph
class Renderer class Renderer
{ {
IRenderTarget *render_target; IRenderTarget *render_target;
SceneWorld *world; Scene *world;
Camera *camera; Camera *camera;
@ -30,7 +30,7 @@ namespace hgl::graph
public: public:
SceneWorld *GetSceneWorld () const { return world; } ///<获取场景世界 Scene *GetScene () const { return world; } ///<获取场景世界
Camera * GetCurCamera () const { return camera; } ///<获取当前相机 Camera * GetCurCamera () const { return camera; } ///<获取当前相机
public: public:
@ -38,7 +38,7 @@ namespace hgl::graph
Renderer(IRenderTarget *); Renderer(IRenderTarget *);
virtual ~Renderer(); virtual ~Renderer();
void SetCurWorld(SceneWorld *); void SetCurWorld(Scene *);
void SetCurCamera(Camera *); void SetCurCamera(Camera *);
bool RenderFrame(RenderCmdBuffer *); bool RenderFrame(RenderCmdBuffer *);

View File

@ -6,45 +6,45 @@
namespace hgl::graph namespace hgl::graph
{ {
/** /**
* <Br> * <Br>
* *
*/ */
class SceneWorld class Scene
{ {
U8String WorldName; ///<世界名称 U8String SceneName; ///<场景名称
ObjectList<SceneNode> SceneNodePool; ///<场景节点池 ObjectList<SceneNode> SceneNodePool; ///<场景节点池
SceneNode *root_node; ///<世界根节点 SceneNode *root_node; ///<场景根节点
public: public:
const U8String & GetWorldName()const{return WorldName;} ///<获取世界名称 const U8String & GetSceneName()const{return SceneName;} ///<获取场景名称
SceneNode * GetRootNode (){return root_node;} ///<获取世界根节点 SceneNode * GetRootNode (){return root_node;} ///<获取场景根节点
public: public:
SceneWorld() Scene()
{ {
root_node=new SceneNode; root_node=new SceneNode;
} }
virtual ~SceneWorld() virtual ~Scene()
{ {
SAFE_CLEAR(root_node); SAFE_CLEAR(root_node);
} }
};//class SceneWorld };//class Scene
bool RegistrySceneWorld(SceneWorld *sw); ///<注册场景世界 bool RegistryScene(Scene *sw); ///<注册场景
bool UnregistrySceneWorld(const U8String &world_name); ///<注销场景世界 bool UnregistryScene(const U8String &world_name); ///<注销场景
inline bool UnregistrySceneWorld(SceneWorld *sw) ///<注销场景世界 inline bool UnregistryScene(Scene *sw) ///<注销场景
{ {
if(!sw)return(false); if(!sw)return(false);
return UnregistrySceneWorld(sw->GetWorldName()); return UnregistryScene(sw->GetSceneName());
} }
SceneWorld *GetSceneWorld(const U8String &world_name); ///<获取指定名称的场景世界 Scene *GetScene(const U8String &world_name); ///<获取指定名称的场景
}//namespace hgl::graph }//namespace hgl::graph

View File

@ -17,7 +17,7 @@ namespace hgl::graph
delete world; delete world;
} }
void Renderer::SetCurWorld(SceneWorld *sw) void Renderer::SetCurWorld(Scene *sw)
{ {
if(world==sw) if(world==sw)
return; return;

View File

@ -5,14 +5,14 @@ namespace hgl::graph
{ {
namespace namespace
{ {
Map<U8String,SceneWorld *> scene_world_map;///<场景世界列表 Map<U8String,Scene *> scene_world_map;///<场景世界列表
}//namespace }//namespace
bool RegistrySceneWorld(SceneWorld *sw) bool RegistryScene(Scene *sw)
{ {
if(!sw)return(false); if(!sw)return(false);
const U8String &world_name=sw->GetWorldName(); const U8String &world_name=sw->GetSceneName();
if(scene_world_map.Find(world_name)) if(scene_world_map.Find(world_name))
return false;///<已经注册过了 return false;///<已经注册过了
@ -21,7 +21,7 @@ namespace hgl::graph
return true; return true;
} }
SceneWorld *GetSceneWorld(const U8String &world_name) Scene *GetScene(const U8String &world_name)
{ {
if(world_name.IsEmpty()) if(world_name.IsEmpty())
return(nullptr); return(nullptr);
@ -29,7 +29,7 @@ namespace hgl::graph
return GetObjectFromMap(scene_world_map,world_name); return GetObjectFromMap(scene_world_map,world_name);
} }
bool UnregistrySceneWorld(const U8String &world_name) bool UnregistryScene(const U8String &world_name)
{ {
if(world_name.IsEmpty()) if(world_name.IsEmpty())
return(false); return(false);

View File

@ -75,7 +75,7 @@ namespace hgl
if(cur_work_object->IsTickable()) if(cur_work_object->IsTickable())
Tick(cur_work_object); Tick(cur_work_object);
if(win->IsVisible()&&cur_work_object->IsRenderable()) if(win->IsVisible())//&&cur_work_object->IsRenderable())
{ {
Render(cur_work_object); Render(cur_work_object);
dev->WaitIdle(); dev->WaitIdle();

View File

@ -43,6 +43,8 @@ namespace hgl
render_pass=rt->GetRenderPass(); render_pass=rt->GetRenderPass();
db=rf->GetRenderResource(); db=rf->GetRenderResource();
scene=rf->GetDefaultScene();
renderer=rf->GetDefaultRenderer();
} }
void WorkObject::Render(double delta_time) void WorkObject::Render(double delta_time)