CSEngine
Loading...
Searching...
No Matches
CSE::SShaderGroup Class Reference
Inheritance diagram for CSE::SShaderGroup:
CSE::SResource CSE::SObject

Public Member Functions

void Exterminate () override
 
const GLProgramHandleGetHandle (const std::string &pass) const
 
const GLProgramHandleGetHandleByMode (int mode) const
 
const GLProgramHandleGetGeometryHandle () const
 
const GLProgramHandleGetForwardHandle () const
 
const GLProgramHandleGetDepthOnlyHandle () const
 
- Public Member Functions inherited from CSE::SResource
 SResource (bool isRegister)
 
 SResource (const SResource *resource, bool isRegister)
 
void SetName (std::string name)
 
void SetAbsoluteID (std::string id)
 
std::string GetName () const
 
std::string GetAbsoluteID () const
 
AssetMgr::AssetReferenceGetAssetReference (std::string hash="") const
 
void LinkResource (AssetMgr::AssetReference *asset)
 
void LinkResource (std::string name)
 
void SetHash (std::string &hash) override
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 

Additional Inherited Members

- Static Public Member Functions inherited from CSE::SResource
template<class T >
static T * Create (const std::string &name)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
template<class T >
static T * Get (std::string name)
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 10 of file SShaderGroup.h.

Constructor & Destructor Documentation

◆ SShaderGroup()

SShaderGroup::SShaderGroup ( )

Definition at line 12 of file SShaderGroup.cpp.

12 {
13}

◆ ~SShaderGroup()

SShaderGroup::~SShaderGroup ( )
override

Definition at line 15 of file SShaderGroup.cpp.

15 {
16}

Member Function Documentation

◆ Exterminate()

void SShaderGroup::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 18 of file SShaderGroup.cpp.

18 {
19}

◆ GetDepthOnlyHandle()

const GLProgramHandle * CSE::SShaderGroup::GetDepthOnlyHandle ( ) const
inline

Definition at line 26 of file SShaderGroup.h.

26 {
27 return m_depthOnlyHandle;
28 }

◆ GetForwardHandle()

const GLProgramHandle * CSE::SShaderGroup::GetForwardHandle ( ) const
inline

Definition at line 23 of file SShaderGroup.h.

23 {
24 return m_forwardHandle;
25 }

◆ GetGeometryHandle()

const GLProgramHandle * CSE::SShaderGroup::GetGeometryHandle ( ) const
inline

Definition at line 20 of file SShaderGroup.h.

20 {
21 return m_geometryHandle;
22 }

◆ GetHandle()

const GLProgramHandle * SShaderGroup::GetHandle ( const std::string &  pass) const

Definition at line 84 of file SShaderGroup.cpp.

84 {
85 return m_handles.at(pass);
86}

◆ GetHandleByMode()

const GLProgramHandle * SShaderGroup::GetHandleByMode ( int  mode) const

Definition at line 88 of file SShaderGroup.cpp.

88 {
89 const std::unordered_map<SMaterial::SMaterialMode, std::string> pass_map = {
90 {SMaterial::NORMAL, "forward"},
91 {SMaterial::DEFERRED, "geometry"},
92 {SMaterial::DEPTH_ONLY, "depthOnly"}
93 };
94
95 return m_handles.at(pass_map.at(static_cast<SMaterial::SMaterialMode>(mode)));
96}

◆ Init()

void SShaderGroup::Init ( const AssetMgr::AssetReference asset)
overrideprotectedvirtual

Implements CSE::SResource.

Definition at line 21 of file SShaderGroup.cpp.

21 {
22 const XNode* root;
23
24 try {
25 root = XFILE(asset->name_path.c_str()).getRoot();
26 }
27 catch (int e) {
28// SAFE_DELETE(root);
29 return;
30 }
31
32 const auto& cse_mat = root->getChild("CSESHADER");
33 const auto& cse_shaders = cse_mat.children;
34 for (const auto& shader : cse_shaders) {
35 const auto& pass = shader.getAttribute("pass").value;
36 const auto& vert_path = shader.getAttribute("v").value;
37 const auto& frag_path = shader.getAttribute("f").value;
38
39 std::string&& vert = "";
40 std::string&& frag = "";
41
42 std::string hashes = "";
43
44 if (shader.hasAttribute("localPath")
45 && shader.getAttribute("localPath").value == "1") {
46 const auto vert_asset_path = asset->path + vert_path;
47 const auto frag_asset_path = asset->path + frag_path;
48 vert = AssetMgr::LoadAssetFile(vert_asset_path);
49 frag = AssetMgr::LoadAssetFile(frag_asset_path);
50 hashes = GetShaderHash(vert_asset_path, frag_asset_path);
51 } else {
52 const auto& resMgr = CORE->GetCore(ResMgr);
53 const auto& vert_asset = resMgr->GetAssetReference(vert_path);
54 const auto& frag_asset = resMgr->GetAssetReference(frag_path);
55
56 vert = AssetMgr::LoadAssetFile(vert_asset->name_path);
57 frag = AssetMgr::LoadAssetFile(frag_asset->name_path);
58 hashes = vert_asset->hash + frag_asset->hash;
59 }
60
61 if (vert.empty() || frag.empty() || hashes.empty()) continue;
62
63 const auto& existHandle = SResource::Get<GLProgramHandle>(hashes);
64 GLProgramHandle* handle = nullptr;
65 if (existHandle == nullptr) {
66 handle = ShaderUtil::CreateProgramHandle(vert.c_str(), frag.c_str());
67 handle->SetName(hashes);
68 } else {
69 handle = existHandle;
70 }
71 m_handles.insert(std::pair<std::string, GLProgramHandle*>(pass, handle));
72 if(pass == "geometry") m_geometryHandle = handle;
73 if(pass == "forward") m_forwardHandle = handle;
74 if(pass == "depthOnly") m_depthOnlyHandle = handle;
75 }
76
77 SAFE_DELETE(root);
78}
static GLProgramHandle * CreateProgramHandle(const GLchar *vertexSource, const GLchar *fragmentSource, GLProgramHandle *handle=nullptr)
Creates a program handle.
Definition XML.h:77
Definition XML.h:43

The documentation for this class was generated from the following files: