From 04b77cadf9f631fa25940f29b787bb9f12fb0daa Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 26 Jun 2024 01:51:13 +0800 Subject: [PATCH] Added GizmoResource.cpp --- example/Gizmo/Gizmo.cpp | 0 example/Gizmo/Gizmo.h | 18 +-- example/Gizmo/GizmoResource.cpp | 140 ++++++++++++++++++ .../LightBasic/BlinnPhongDirectionLight.cpp | 2 +- 4 files changed, 147 insertions(+), 13 deletions(-) delete mode 100644 example/Gizmo/Gizmo.cpp create mode 100644 example/Gizmo/GizmoResource.cpp diff --git a/example/Gizmo/Gizmo.cpp b/example/Gizmo/Gizmo.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/example/Gizmo/Gizmo.h b/example/Gizmo/Gizmo.h index 4d92d5b1..5b4d0252 100644 --- a/example/Gizmo/Gizmo.h +++ b/example/Gizmo/Gizmo.h @@ -4,22 +4,16 @@ VK_NAMESPACE_BEGIN -class Gizmo +class PrimitiveCreater; + +class GizmoResource { protected: - Material * material; - MaterialInstance * mtl_inst; - Pipeline * pipeline; - VertexDataManager * vdm; - Primitive * prim_cylinder; ///<圆柱 - Primitive * prim_cone; ///<圆锥 - Primitive * prim_sphere; ///<球体 - Primitive * prim_cube; ///<立方体 - Primitive * prim_plane; ///<平面 +public: - -};//class Gizmo + +};//class GizmoResource VK_NAMESPACE_END diff --git a/example/Gizmo/GizmoResource.cpp b/example/Gizmo/GizmoResource.cpp new file mode 100644 index 00000000..667fffd4 --- /dev/null +++ b/example/Gizmo/GizmoResource.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +VK_NAMESPACE_BEGIN + +namespace +{ + enum class GizmoColor:uint + { + Black=0, + White, + + Red, + Green, + Blue, + + Yellow, + + ENUM_CLASS_RANGE(Black,Yellow) + }; + + static Color4f GizmoColorRGB[size_t(GizmoColor::RANGE_SIZE)]; + + enum class GizmoShape:uint + { + Plane=0, //平面 + Cube, //立方体 + Sphere, //球 + Cone, //圆锥 + Cylinder, //圆柱 + + ENUM_CLASS_RANGE(Plane,Cylinder) + }; + + static Material * material =nullptr; + static MaterialInstance * mtl_inst[size_t(GizmoColor::RANGE_SIZE)]{}; + static Pipeline * pipeline =nullptr; + static VertexDataManager * vdm =nullptr; + + static PrimitiveCreater * prim_creater=nullptr; + + static Primitive * prim[size_t(GizmoShape::RANGE_SIZE)]{}; + + bool InitGizmoMI(RenderResource *rr) + { + constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]= + { + COLOR::MozillaCharcoal, + COLOR::BlanchedAlmond, + + COLOR::BlenderAxisRed, + COLOR::BlenderAxisGreen, + COLOR::BlenderAxisBlue, + + COLOR::BlenderYellow, + }; + + if(!rr||!material) + return(false); + + Color4f color; + + for(uint i=0;iCreateMaterialInstance(material,nullptr,&color); + if(!mtl_inst[i]) + return(false); + } + + return(true); + } +}//namespace + +bool InitGizmoResource(RenderResource *rr) +{ + if(!rr) + return(false); + + GPUDevice *device=rr->GetDevice(); + RenderPass *render_pass=device->GetRenderPass(); + + { + mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"Gizmo3D",Prim::Triangles); + + cfg.local_to_world=true; + cfg.material_instance=true; + + mtl::MaterialCreateInfo *mci=CreateMaterialGizmo3D(&cfg); + + if(!mci) + return(false); + + material=rr->CreateMaterial(mci); + if(!material) + return(false); + } + + if(!InitGizmoMI(rr)) + return(false); + + { + pipeline=render_pass->CreatePipeline(material,InlinePipeline::Solid3D,Prim::Triangles); + if(!pipeline) + return(false); + } + + { + vdm=new VertexDataManager(device,material->GetDefaultVIL()); + + if(!vdm) + return(false); + + if(!vdm->Init( HGL_SIZE_1MB, //最大顶点数量 + HGL_SIZE_1MB, //最大索引数量 + IndexType::U16)) //索引类型 + return(false); + } + + { + prim_creater=new PrimitiveCreater(vdm); + + if(!prim_creater) + return(false); + + + } + + return(true); +} + +VK_NAMESPACE_END \ No newline at end of file diff --git a/example/LightBasic/BlinnPhongDirectionLight.cpp b/example/LightBasic/BlinnPhongDirectionLight.cpp index e3253983..69b191e1 100644 --- a/example/LightBasic/BlinnPhongDirectionLight.cpp +++ b/example/LightBasic/BlinnPhongDirectionLight.cpp @@ -87,7 +87,7 @@ private: TexCount, ///<纹理层数 PF_BC1_RGBUN, ///<纹理格式 false); ///<是否自动产生mipmaps - + if(!texture)return(false); OSString filename;