ShaderManager now uses SourceManager

This commit is contained in:
Kearwood Kip Gilbert
2019-08-18 18:03:44 -07:00
parent cbbbe41cb0
commit aca476afa9
2 changed files with 7 additions and 33 deletions

View File

@@ -222,14 +222,15 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
stream << "\n"; stream << "\n";
std::string options = stream.str(); std::string options = stream.str();
KRSourceManager *sourceManager = m_pContext->getSourceManager();
KRSource *vertSource = sourceManager->get(platform_shader_name.c_str(), "vsh");
KRSource *fragSource = sourceManager->get(platform_shader_name.c_str(), "fsh");
std::string vertShaderSource = m_vertShaderSource[platform_shader_name]; if(vertSource == nullptr) {
std::string fragShaderSource = m_fragShaderSource[platform_shader_name];
if(vertShaderSource.length() == 0) {
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Vertex Shader Missing: %s", platform_shader_name.c_str()); KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Vertex Shader Missing: %s", platform_shader_name.c_str());
} }
if(fragShaderSource.length() == 0) { if(fragSource == nullptr) {
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Fragment Shader Missing: %s", platform_shader_name.c_str()); KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Fragment Shader Missing: %s", platform_shader_name.c_str());
} }
@@ -238,7 +239,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
char szKey[256]; char szKey[256];
sprintf(szKey, "%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", light_directional_count, light_point_count, light_spot_count, bone_count, pCamera->settings.fog_type, pCamera->settings.bEnablePerPixel,bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->settings.bDebugPSSM, iShadowQuality, pCamera->settings.bEnableAmbient, pCamera->settings.bEnableDiffuse, pCamera->settings.bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->settings.volumetric_environment_enable && pCamera->settings.volumetric_environment_downsample != 0, renderPass, shader_name.c_str(),pCamera->settings.dof_quality,pCamera->settings.bEnableFlash,pCamera->settings.bEnableVignette,pCamera->settings.dof_depth,pCamera->settings.dof_falloff,pCamera->settings.flash_depth,pCamera->settings.flash_falloff,pCamera->settings.flash_intensity,pCamera->settings.vignette_radius,pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w); sprintf(szKey, "%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", light_directional_count, light_point_count, light_spot_count, bone_count, pCamera->settings.fog_type, pCamera->settings.bEnablePerPixel,bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->settings.bDebugPSSM, iShadowQuality, pCamera->settings.bEnableAmbient, pCamera->settings.bEnableDiffuse, pCamera->settings.bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->settings.volumetric_environment_enable && pCamera->settings.volumetric_environment_downsample != 0, renderPass, shader_name.c_str(),pCamera->settings.dof_quality,pCamera->settings.bEnableFlash,pCamera->settings.bEnableVignette,pCamera->settings.dof_depth,pCamera->settings.dof_falloff,pCamera->settings.flash_depth,pCamera->settings.flash_falloff,pCamera->settings.flash_intensity,pCamera->settings.vignette_radius,pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w);
pShader = new KRShader(getContext(), szKey, options, vertShaderSource, fragShaderSource); pShader = new KRShader(getContext(), szKey, options, vertSource->getData()->getString(), fragSource->getData()->getString());
m_shaders[key] = pShader; m_shaders[key] = pShader;
} }
@@ -260,24 +261,6 @@ bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KR
} }
} }
void KRShaderManager::loadFragmentShader(const std::string &name, KRDataBlock *data) {
m_fragShaderSource[name] = data->getString();
delete data;
}
void KRShaderManager::loadVertexShader(const std::string &name, KRDataBlock *data) {
m_vertShaderSource[name] = data->getString();
delete data;
}
const std::string &KRShaderManager::getFragShaderSource(const std::string &name) {
return m_fragShaderSource[name];
}
const std::string &KRShaderManager::getVertShaderSource(const std::string &name) {
return m_vertShaderSource[name];
}
size_t KRShaderManager::getShaderHandlesUsed() { size_t KRShaderManager::getShaderHandlesUsed() {
return m_shaders.size(); return m_shaders.size();
} }

View File

@@ -52,12 +52,6 @@ public:
KRShaderManager(KRContext &context); KRShaderManager(KRContext &context);
virtual ~KRShaderManager(); virtual ~KRShaderManager();
void loadFragmentShader(const std::string &name, KRDataBlock *data);
void loadVertexShader(const std::string &name, KRDataBlock *data);
const std::string &getFragShaderSource(const std::string &name);
const std::string &getVertShaderSource(const std::string &name);
KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
@@ -71,9 +65,6 @@ public:
private: private:
//unordered_map<std::string, KRShader *> m_shaders; //unordered_map<std::string, KRShader *> m_shaders;
std::map<std::pair<std::string, std::vector<int> >, KRShader *> m_shaders; std::map<std::pair<std::string, std::vector<int> >, KRShader *> m_shaders;
unordered_map<std::string, std::string> m_fragShaderSource;
unordered_map<std::string, std::string> m_vertShaderSource;
}; };
#endif #endif