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

Public Member Functions

 RESOURCE_DEFINE_CONSTRUCTOR (SShaderGroup)
 
void Exterminate () override
 
const GLProgramHandleGetHandle (const std::string &pass) const
 
const GLProgramHandleGetHandleByMode (int mode) const
 
const GLProgramHandleGetGeometryHandle () const
 
const GLProgramHandleGetForwardHandle () const
 
const GLProgramHandleGetDepthOnlyHandle () const
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
- Public Member Functions inherited from CSE::SResource
 SResource (std::string classType)
 
 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 ()
 
std::string GetHash () const
 
- Public Member Functions inherited from CSE::VariableBinder
- Public Member Functions inherited from CSE::ReflectionObject
 ReflectionObject (std::string type)
 
void SetClassType (std::string type)
 
const char * GetClassType () const
 
bool IsSameClass (const char *classType) const
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 
- Protected Member Functions inherited from CSE::SResource
- Protected Member Functions inherited from CSE::VariableBinder

Additional Inherited Members

- Static Public Member Functions inherited from CSE::SResource
template<class T >
static T * Create (const std::string &name)
 
static SResourceCreate (const std::string &name, const std::string &classType)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
static SResourceCreate (const AssetMgr::AssetReference *asset, const std::string &classType)
 
template<class T >
static T * Get (std::string name)
 
static SResourceGet (std::string &name)
 
- Static Public Member Functions inherited from CSE::ReflectionObject
static ReflectionObjectNewObject (const std::string &name)
 
- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 
- Protected Attributes inherited from CSE::ReflectionObject
std::string m_class
 

Detailed Description

Definition at line 10 of file SShaderGroup.h.

Constructor & Destructor Documentation

◆ ~SShaderGroup()

SShaderGroup::~SShaderGroup ( )
override

Definition at line 14 of file SShaderGroup.cpp.

14 {
15}

Member Function Documentation

◆ Exterminate()

void SShaderGroup::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 17 of file SShaderGroup.cpp.

17 {
18}

◆ 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 97 of file SShaderGroup.cpp.

97 {
98 return m_handles.at(pass);
99}

◆ GetHandleByMode()

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

Definition at line 101 of file SShaderGroup.cpp.

101 {
102 const std::unordered_map<SMaterial::SMaterialMode, std::string> pass_map = {
103 {SMaterial::FORWARD, "forward"},
104 {SMaterial::DEFERRED, "geometry"},
105 {SMaterial::DEPTH_ONLY, "depthOnly"}
106 };
107
108 return m_handles.at(pass_map.at(static_cast<SMaterial::SMaterialMode>(mode)));
109}

◆ Init()

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

Implements CSE::SResource.

Definition at line 20 of file SShaderGroup.cpp.

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

◆ PrintValue()

std::string SShaderGroup::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 114 of file SShaderGroup.cpp.

114 {
115 return {};
116}

◆ SetValue()

void SShaderGroup::SetValue ( std::string name_str,
Arguments value )
overridevirtual

Used to get serialized values. All classes that inherit from VariableBinder will unconditionally call this function first during initialization.

Parameters
name_strName of values
valueSerialized values

Implements CSE::VariableBinder.

Definition at line 111 of file SShaderGroup.cpp.

111 {
112}

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