Added KRShader and KRShaderManager for spir-v binaries

This commit is contained in:
2019-12-01 16:20:55 -08:00
parent 9f71c278ea
commit 1c5520fa3a
9 changed files with 308 additions and 3 deletions

View File

@@ -67,6 +67,8 @@ add_sources(KRResource.cpp)
add_sources(KRReverbZone.cpp) add_sources(KRReverbZone.cpp)
add_sources(KRScene.cpp) add_sources(KRScene.cpp)
add_sources(KRSceneManager.cpp) add_sources(KRSceneManager.cpp)
add_sources(KRShader.cpp)
add_sources(KRShaderManager.cpp)
add_sources(KRSource.cpp) add_sources(KRSource.cpp)
add_sources(KRSourceManager.cpp) add_sources(KRSourceManager.cpp)
add_sources(KRPipeline.cpp) add_sources(KRPipeline.cpp)

View File

@@ -83,6 +83,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
m_pAnimationCurveManager = new KRAnimationCurveManager(*this); m_pAnimationCurveManager = new KRAnimationCurveManager(*this);
m_pSoundManager = new KRAudioManager(*this); m_pSoundManager = new KRAudioManager(*this);
m_pUnknownManager = new KRUnknownManager(*this); m_pUnknownManager = new KRUnknownManager(*this);
m_pShaderManager = new KRShaderManager(*this);
m_pSourceManager = new KRSourceManager(*this); m_pSourceManager = new KRSourceManager(*this);
m_streamingEnabled = true; m_streamingEnabled = true;
@@ -224,6 +225,9 @@ KRAnimationCurveManager *KRContext::getAnimationCurveManager() {
KRAudioManager *KRContext::getAudioManager() { KRAudioManager *KRContext::getAudioManager() {
return m_pSoundManager; return m_pSoundManager;
} }
KRShaderManager *KRContext::getShaderManager() {
return m_pShaderManager;
}
KRSourceManager *KRContext::getSourceManager() { KRSourceManager *KRContext::getSourceManager() {
return m_pSourceManager; return m_pSourceManager;
} }
@@ -262,6 +266,13 @@ std::vector<KRResource *> KRContext::getResources()
resources.push_back((*itr2).second); resources.push_back((*itr2).second);
} }
} }
unordered_map<std::string, unordered_map<std::string, KRShader *> > shaders = m_pShaderManager->getShaders();
for(unordered_map<std::string, unordered_map<std::string, KRShader *> >::iterator itr = shaders.begin(); itr != shaders.end(); itr++) {
for(unordered_map<std::string, KRShader *>::iterator itr2 = (*itr).second.begin(); itr2 != (*itr).second.end(); itr2++) {
resources.push_back((*itr2).second);
}
}
unordered_map<std::string, unordered_map<std::string, KRUnknown *> > unknowns = m_pUnknownManager->getUnknowns(); unordered_map<std::string, unordered_map<std::string, KRUnknown *> > unknowns = m_pUnknownManager->getUnknowns();
for(unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator itr = unknowns.begin(); itr != unknowns.end(); itr++) { for(unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator itr = unknowns.begin(); itr != unknowns.end(); itr++) {
@@ -297,6 +308,9 @@ KRResource* KRContext::loadResource(const std::string &file_name, KRDataBlock *d
resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data); resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
} else if(extension.compare("tga") == 0) { } else if(extension.compare("tga") == 0) {
resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data); resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
} else if(extension.compare("spv") == 0) {
// SPIR-V shader binary
resource = m_pShaderManager->load(name, extension, data);
} else if(extension.compare("vert") == 0) { } else if(extension.compare("vert") == 0) {
// vertex shader // vertex shader
resource = m_pSourceManager->load(name, extension, data); resource = m_pSourceManager->load(name, extension, data);

View File

@@ -19,6 +19,7 @@
#include "KRAnimationManager.h" #include "KRAnimationManager.h"
#include "KRAnimationCurveManager.h" #include "KRAnimationCurveManager.h"
#include "KRUnknownManager.h" #include "KRUnknownManager.h"
#include "KRShaderManager.h"
#include "KRSourceManager.h" #include "KRSourceManager.h"
#include "KRStreamer.h" #include "KRStreamer.h"
@@ -58,6 +59,7 @@ public:
KRAnimationCurveManager *getAnimationCurveManager(); KRAnimationCurveManager *getAnimationCurveManager();
KRAudioManager *getAudioManager(); KRAudioManager *getAudioManager();
KRUnknownManager *getUnknownManager(); KRUnknownManager *getUnknownManager();
KRShaderManager *getShaderManager();
KRSourceManager *getSourceManager(); KRSourceManager *getSourceManager();
KRCamera *createCamera(int width, int height); KRCamera *createCamera(int width, int height);
@@ -120,6 +122,7 @@ private:
KRAnimationCurveManager *m_pAnimationCurveManager; KRAnimationCurveManager *m_pAnimationCurveManager;
KRAudioManager *m_pSoundManager; KRAudioManager *m_pSoundManager;
KRUnknownManager *m_pUnknownManager; KRUnknownManager *m_pUnknownManager;
KRShaderManager *m_pShaderManager;
KRSourceManager *m_pSourceManager; KRSourceManager *m_pSourceManager;
KRResource** m_resourceMap; KRResource** m_resourceMap;

65
kraken/KRShader.cpp Normal file
View File

@@ -0,0 +1,65 @@
//
// KRShader.cpp
// KREngine
//
// Copyright 2019 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KRShader.h"
KRShader::KRShader(KRContext &context, std::string name, std::string extension) : KRResource(context, name)
{
m_pData = new KRDataBlock();
m_extension = extension;
}
KRShader::KRShader(KRContext &context, std::string name, std::string extension, KRDataBlock *data) : KRResource(context, name)
{
m_pData = data;
m_extension = extension;
}
KRShader::~KRShader()
{
delete m_pData;
}
std::string KRShader::getExtension()
{
return m_extension;
}
bool KRShader::save(KRDataBlock &data)
{
data.append(*m_pData);
return true;
}
KRDataBlock *KRShader::getData()
{
return m_pData;
}

59
kraken/KRShader.h Normal file
View File

@@ -0,0 +1,59 @@
//
// KRShader.h
// KREngine
//
// Copyright 2019 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRSHADER_H
#define KRSHADER_H
#include "KREngine-common.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "KRResource.h"
class KRShader : public KRResource {
public:
KRShader(KRContext &context, std::string name, std::string extension);
KRShader(KRContext &context, std::string name, std::string extension, KRDataBlock *data);
virtual ~KRShader();
virtual std::string getExtension();
virtual bool save(KRDataBlock &data);
KRDataBlock *getData();
private:
std::string m_extension;
KRDataBlock *m_pData;
};
#endif /* defined(KRSHADER_H) */

102
kraken/KRShaderManager.cpp Normal file
View File

@@ -0,0 +1,102 @@
//
// ShaderManager.cpp
// KREngine
//
// Copyright 2019 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KRShaderManager.h"
#include "KREngine-common.h"
KRShaderManager::KRShaderManager(KRContext &context) : KRContextObject(context)
{
}
KRShaderManager::~KRShaderManager()
{
for(unordered_map<std::string, unordered_map<std::string, KRShader *> >::iterator extension_itr = m_shaders.begin(); extension_itr != m_shaders.end(); extension_itr++) {
for(unordered_map<std::string, KRShader *>::iterator name_itr=(*extension_itr).second.begin(); name_itr != (*extension_itr).second.end(); name_itr++) {
delete (*name_itr).second;
}
}
}
unordered_map<std::string, unordered_map<std::string, KRShader *> > &KRShaderManager::getShaders()
{
return m_shaders;
}
void KRShaderManager::add(KRShader *shader)
{
std::string lower_name = shader->getName();
std::string lower_extension = shader->getExtension();
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
unordered_map<std::string, unordered_map<std::string, KRShader *> >::iterator extension_itr = m_shaders.find(lower_extension);
if(extension_itr == m_shaders.end()) {
m_shaders[lower_extension] = unordered_map<std::string, KRShader *>();
extension_itr = m_shaders.find(lower_extension);
}
unordered_map<std::string, KRShader *>::iterator name_itr = (*extension_itr).second.find(lower_name);
if(name_itr != (*extension_itr).second.end()) {
delete (*name_itr).second;
(*name_itr).second = shader;
} else {
(*extension_itr).second[lower_name] = shader;
}
}
KRShader *KRShaderManager::load(const std::string &name, const std::string &extension, KRDataBlock *data)
{
KRShader *shader = new KRShader(getContext(), name, extension, data);
if(shader) add(shader);
return shader;
}
KRShader *KRShaderManager::get(const std::string &name, const std::string &extension)
{
std::string lower_name = name;
std::string lower_extension = extension;
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
return m_shaders[lower_extension][lower_name];
}
const unordered_map<std::string, KRShader *> &KRShaderManager::get(const std::string &extension)
{
std::string lower_extension = extension;
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
return m_shaders[lower_extension];
}

60
kraken/KRShaderManager.h Normal file
View File

@@ -0,0 +1,60 @@
//
// ShaderManager.h
// KREngine
//
// Copyright 2019 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRSHADER_MANAGER_H
#define KRSHADER_MANAGER_H
#include "KREngine-common.h"
#include "KRShader.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
class KRShaderManager : public KRContextObject {
public:
KRShaderManager(KRContext &context);
virtual ~KRShaderManager();
void add(KRShader *shader);
KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data);
KRShader *get(const std::string &name, const std::string &extension);
const unordered_map<std::string, KRShader *> &get(const std::string &extension);
unordered_map<std::string, unordered_map<std::string, KRShader *> > &getShaders();
private:
unordered_map<std::string, unordered_map<std::string, KRShader *> > m_shaders;
};
#endif /* defined(KRUNKNOWN_MANAGER_H) */

View File

@@ -2,7 +2,7 @@
// SourceManager.cpp // SourceManager.cpp
// KREngine // KREngine
// //
// Copyright 2012 Kearwood Gilbert. All rights reserved. // Copyright 2019 Kearwood Gilbert. All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met:

View File

@@ -1,8 +1,8 @@
// //
// FileManager.h // SourceManager.h
// KREngine // KREngine
// //
// Copyright 2012 Kearwood Gilbert. All rights reserved. // Copyright 2019 Kearwood Gilbert. All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, are // Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met: // permitted provided that the following conditions are met: