Imported glslang library. Refactoring shader manager.
This commit is contained in:
@@ -69,8 +69,8 @@ add_sources(KRScene.cpp)
|
||||
add_sources(KRSceneManager.cpp)
|
||||
add_sources(KRSource.cpp)
|
||||
add_sources(KRSourceManager.cpp)
|
||||
add_sources(KRShader.cpp)
|
||||
add_sources(KRShaderManager.cpp)
|
||||
add_sources(KRPipeline.cpp)
|
||||
add_sources(KRPipelineManager.cpp)
|
||||
add_sources(KRSpotLight.cpp)
|
||||
add_sources(KRSprite.cpp)
|
||||
add_sources(KRTexture.cpp)
|
||||
|
||||
@@ -96,9 +96,9 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pPipeline, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -180,9 +180,9 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -61,9 +61,9 @@ void KRBone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
|
||||
@@ -312,7 +312,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
}
|
||||
|
||||
if(m_pSkyBoxTexture) {
|
||||
getContext().getShaderManager()->selectShader("sky_box", *this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, m_viewport, Matrix4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline("sky_box", *this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, m_viewport, Matrix4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
|
||||
|
||||
@@ -473,14 +473,14 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
|
||||
KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline("visualize_overlay", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
|
||||
for(unordered_map<AABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
|
||||
Matrix4 matModel = Matrix4();
|
||||
matModel.scale((*itr).first.size() * 0.5f);
|
||||
matModel.translate((*itr).first.center());
|
||||
if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
}
|
||||
@@ -492,7 +492,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
GL_POP_GROUP_MARKER;
|
||||
|
||||
|
||||
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getShaderManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
|
||||
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getPipelineManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
|
||||
GL_PUSH_GROUP_MARKER("Post Processing");
|
||||
|
||||
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO));
|
||||
@@ -692,10 +692,10 @@ void KRCamera::renderPost()
|
||||
|
||||
GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y));
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline("PostShader", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
Vector3 rim_color;
|
||||
getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture);
|
||||
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture);
|
||||
@@ -714,13 +714,13 @@ void KRCamera::renderPost()
|
||||
|
||||
|
||||
// if(bShowShadowBuffer) {
|
||||
// KRShader *blitShader = m_pContext->getShaderManager()->getShader("simple_blit", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// KRPipeline *blitShader = m_pContext->getPipelineManager()->getShader("simple_blit", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
//
|
||||
// for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
||||
// Matrix4 viewMatrix = Matrix4();
|
||||
// viewMatrix.scale(0.20, 0.20, 0.20);
|
||||
// viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0);
|
||||
// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, Matrix4()), shadowViewports, Matrix4(), Vector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// getContext().getPipelineManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, Matrix4()), shadowViewports, Matrix4(), Vector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
// m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES);
|
||||
// m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
@@ -878,8 +878,8 @@ void KRCamera::renderPost()
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRShader.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRContextObject.h"
|
||||
#include "KRTexture.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
@@ -196,9 +196,9 @@ void KRCollider::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_li
|
||||
|
||||
GL_PUSH_GROUP_MARKER("Debug Overlays");
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
|
||||
int KRContext::KRENGINE_MAX_PIPELINE_HANDLES;
|
||||
int KRContext::KRENGINE_GPU_MEM_MAX;
|
||||
int KRContext::KRENGINE_GPU_MEM_TARGET;
|
||||
int KRContext::KRENGINE_MAX_TEXTURE_DIM;
|
||||
@@ -74,9 +74,9 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
|
||||
m_absolute_time = 0.0f;
|
||||
|
||||
m_pBundleManager = new KRBundleManager(*this);
|
||||
m_pShaderManager = new KRShaderManager(*this);
|
||||
m_pPipelineManager = new KRPipelineManager(*this);
|
||||
m_pTextureManager = new KRTextureManager(*this);
|
||||
m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pShaderManager);
|
||||
m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pPipelineManager);
|
||||
m_pMeshManager = new KRMeshManager(*this);
|
||||
m_pSceneManager = new KRSceneManager(*this);
|
||||
m_pAnimationManager = new KRAnimationManager(*this);
|
||||
@@ -128,9 +128,9 @@ KRContext::~KRContext() {
|
||||
m_pMaterialManager = NULL;
|
||||
}
|
||||
|
||||
if(m_pShaderManager) {
|
||||
delete m_pShaderManager;
|
||||
m_pShaderManager = NULL;
|
||||
if(m_pPipelineManager) {
|
||||
delete m_pPipelineManager;
|
||||
m_pPipelineManager = NULL;
|
||||
}
|
||||
|
||||
if(m_pAnimationManager) {
|
||||
@@ -209,8 +209,8 @@ KRTextureManager *KRContext::getTextureManager() {
|
||||
KRMaterialManager *KRContext::getMaterialManager() {
|
||||
return m_pMaterialManager;
|
||||
}
|
||||
KRShaderManager *KRContext::getShaderManager() {
|
||||
return m_pShaderManager;
|
||||
KRPipelineManager *KRContext::getPipelineManager() {
|
||||
return m_pPipelineManager;
|
||||
}
|
||||
KRMeshManager *KRContext::getMeshManager() {
|
||||
return m_pMeshManager;
|
||||
@@ -297,9 +297,53 @@ KRResource* KRContext::loadResource(const std::string &file_name, KRDataBlock *d
|
||||
resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
|
||||
} else if(extension.compare("tga") == 0) {
|
||||
resource = m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
|
||||
} else if(extension.compare("vsh") == 0) {
|
||||
} else if(extension.compare("vert") == 0) {
|
||||
// vertex shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("fsh") == 0) {
|
||||
} else if(extension.compare("frag") == 0) {
|
||||
// fragment shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("tesc") == 0) {
|
||||
// tessellation control shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("tese") == 0) {
|
||||
// tessellation evaluation shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("geom") == 0) {
|
||||
// geometry shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("comp") == 0) {
|
||||
// compute shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("mesh") == 0) {
|
||||
// mesh shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("task") == 0) {
|
||||
// task shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rgen") == 0) {
|
||||
// ray generation shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rint") == 0) {
|
||||
// ray intersection shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rahit") == 0) {
|
||||
// ray any hit shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rchit") == 0) {
|
||||
// ray closest hit shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rmiss") == 0) {
|
||||
// ray miss shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("rcall") == 0) {
|
||||
// ray callable shader
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("glsl") == 0) {
|
||||
// glsl included by other shaders
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("options") == 0) {
|
||||
// shader pre-processor options definition file
|
||||
resource = m_pSourceManager->load(name, extension, data);
|
||||
} else if(extension.compare("mtl") == 0) {
|
||||
resource = m_pMaterialManager->load(name.c_str(), data);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "KRSceneManager.h"
|
||||
#include "KRTextureManager.h"
|
||||
#include "KRMaterialManager.h"
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRMeshManager.h"
|
||||
#include "KRAnimationManager.h"
|
||||
#include "KRAnimationCurveManager.h"
|
||||
@@ -26,7 +26,7 @@ class KRAudioManager;
|
||||
|
||||
class KRContext {
|
||||
public:
|
||||
static int KRENGINE_MAX_SHADER_HANDLES;
|
||||
static int KRENGINE_MAX_PIPELINE_HANDLES;
|
||||
static int KRENGINE_GPU_MEM_MAX;
|
||||
static int KRENGINE_GPU_MEM_TARGET;
|
||||
static int KRENGINE_MAX_TEXTURE_DIM;
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
KRSceneManager *getSceneManager();
|
||||
KRTextureManager *getTextureManager();
|
||||
KRMaterialManager *getMaterialManager();
|
||||
KRShaderManager *getShaderManager();
|
||||
KRPipelineManager *getPipelineManager();
|
||||
KRMeshManager *getMeshManager();
|
||||
KRAnimationManager *getAnimationManager();
|
||||
KRAnimationCurveManager *getAnimationCurveManager();
|
||||
@@ -114,7 +114,7 @@ private:
|
||||
KRSceneManager *m_pSceneManager;
|
||||
KRTextureManager *m_pTextureManager;
|
||||
KRMaterialManager *m_pMaterialManager;
|
||||
KRShaderManager *m_pShaderManager;
|
||||
KRPipelineManager *m_pPipelineManager;
|
||||
KRMeshManager *m_pMeshManager;
|
||||
KRAnimationManager *m_pAnimationManager;
|
||||
KRAnimationCurveManager *m_pAnimationCurveManager;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRDirectionalLight.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRContext.h"
|
||||
#include "assert.h"
|
||||
#include "KRStockGeometry.h"
|
||||
@@ -109,12 +109,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &
|
||||
light_direction_view_space = Matrix4::Dot(matModelViewInverseTranspose, light_direction_view_space);
|
||||
light_direction_view_space.normalize();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY, m_intensity * 0.01f);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_INTENSITY, m_intensity * 0.01f);
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include "KRCamera.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRStockGeometry.h"
|
||||
#include "KRDirectionalLight.h"
|
||||
#include "KRSpotLight.h"
|
||||
@@ -218,13 +218,13 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
this_point_light.push_back(point_light);
|
||||
}
|
||||
|
||||
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
|
||||
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
|
||||
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size);
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size);
|
||||
|
||||
KRDataBlock particle_index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(m_pContext->getMeshManager()->getRandomParticles(), particle_index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true, 1.0f);
|
||||
@@ -254,17 +254,17 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
this_point_light.push_back(point_light);
|
||||
}
|
||||
|
||||
KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
|
||||
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, Matrix4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pFogShader, viewport, Matrix4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
|
||||
|
||||
float slice_near = -pCamera->settings.getPerspectiveNearZ();
|
||||
float slice_far = -pCamera->settings.volumetric_environment_max_distance;
|
||||
float slice_spacing = (slice_far - slice_near) / slice_count;
|
||||
|
||||
pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, Vector2::Create(slice_near, slice_spacing));
|
||||
pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||
pFogShader->setUniform(KRPipeline::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, Vector2::Create(slice_near, slice_spacing));
|
||||
pFogShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||
|
||||
KRDataBlock index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(m_pContext->getMeshManager()->getVolumetricLightingVertexes(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), true, 1.0f);
|
||||
@@ -284,7 +284,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix();
|
||||
}
|
||||
|
||||
if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
|
||||
#if TARGET_OS_IPHONE || defined(ANDROID)
|
||||
@@ -330,11 +330,11 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
|
||||
m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
@@ -447,9 +447,9 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera)
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
// Use shader program
|
||||
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
|
||||
getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);
|
||||
|
||||
@@ -319,16 +319,16 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap;
|
||||
bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE);
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, (int)bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_reflectionMapScale != default_scale && bReflectionMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, m_reflectionMapOffset != default_offset && bReflectionMap, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, (int)bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_reflectionMapScale != default_scale && bReflectionMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, m_reflectionMapOffset != default_offset && bReflectionMap, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f);
|
||||
|
||||
|
||||
Vector4 fade_color;
|
||||
if(!getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) {
|
||||
if(!getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bind bones
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
if(pShader->m_uniforms[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
GLfloat bone_mats[256 * 16];
|
||||
GLfloat *bone_mat_component = bone_mats;
|
||||
for(int bone_index=0; bone_index < bones.size(); bone_index++) {
|
||||
@@ -355,40 +355,40 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
*bone_mat_component++ = t[i];
|
||||
}
|
||||
}
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS], (GLsizei)bones.size(), GL_FALSE, bone_mats);
|
||||
if(pShader->m_uniforms[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
glUniformMatrix4fv(pShader->m_uniforms[KRPipeline::KRENGINE_UNIFORM_BONE_TRANSFORMS], (GLsizei)bones.size(), GL_FALSE, bone_mats);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT, m_ambientColor + pCamera->settings.ambient_intensity);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_AMBIENT, m_ambientColor + pCamera->settings.ambient_intensity);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3::Create(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3::Create(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor);
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3::Create(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3::Create(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor);
|
||||
}
|
||||
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS, m_ns);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTION, m_reflectionColor);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE, m_diffuseMapScale);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE, m_specularMapScale);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE, m_reflectionMapScale);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_SCALE, m_normalMapScale);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET, m_diffuseMapOffset);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET, m_specularMapOffset);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET, m_reflectionMapOffset);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET, m_normalMapOffset);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SHININESS, m_ns);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_REFLECTION, m_reflectionColor);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE, m_diffuseMapScale);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE, m_specularMapScale);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE, m_reflectionMapScale);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_NORMALTEXTURE_SCALE, m_normalMapScale);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET, m_diffuseMapOffset);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET, m_specularMapOffset);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET, m_reflectionMapOffset);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET, m_normalMapOffset);
|
||||
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_tr);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_tr);
|
||||
|
||||
if(bDiffuseMap) {
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap, lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRTexture.h"
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRCamera.h"
|
||||
#include "KRResource.h"
|
||||
#include "KRScene.h"
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
#include "KRMaterialManager.h"
|
||||
|
||||
|
||||
KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRShaderManager *pShaderManager) : KRContextObject(context)
|
||||
KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRPipelineManager *pPipelineManager) : KRContextObject(context)
|
||||
{
|
||||
m_pTextureManager = pTextureManager;
|
||||
m_pShaderManager = pShaderManager;
|
||||
m_pPipelineManager = pPipelineManager;
|
||||
}
|
||||
|
||||
KRMaterialManager::~KRMaterialManager() {
|
||||
|
||||
@@ -46,7 +46,7 @@ using std::map;
|
||||
|
||||
class KRMaterialManager : public KRContextObject {
|
||||
public:
|
||||
KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRShaderManager *pShaderManager);
|
||||
KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRPipelineManager *pPipelineManager);
|
||||
virtual ~KRMaterialManager();
|
||||
|
||||
KRMaterial* load(const char *szName, KRDataBlock *data);
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
private:
|
||||
unordered_map<std::string, KRMaterial *> m_materials;
|
||||
KRTextureManager *m_pTextureManager;
|
||||
KRShaderManager *m_pShaderManager;
|
||||
KRPipelineManager *m_pPipelineManager;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
#include "KRMesh.h"
|
||||
|
||||
#include "KRShader.h"
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRContext.h"
|
||||
#include "../3rdparty/forsyth/forsyth.h"
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class Matrix4;
|
||||
class AABB;
|
||||
} // namespace kraken
|
||||
class KRCamera;
|
||||
class KRShaderManager;
|
||||
class KRPipelineManager;
|
||||
class KRMeshManager;
|
||||
class KRMaterialManager;
|
||||
class KRTextureManager;
|
||||
|
||||
@@ -74,11 +74,11 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector<KRPointLig
|
||||
|
||||
int particle_count = 10000;
|
||||
|
||||
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
// Vector3 rim_color; Vector4 fade_color;
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);
|
||||
|
||||
KRDataBlock index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(m_pContext->getMeshManager()->getRandomParticles(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false, 1.0f);
|
||||
|
||||
50
kraken/KRShader.cpp → kraken/KRPipeline.cpp
Executable file → Normal file
50
kraken/KRShader.cpp → kraken/KRPipeline.cpp
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRShader.cpp
|
||||
// KRPipeline.cpp
|
||||
// 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
|
||||
// permitted provided that the following conditions are met:
|
||||
@@ -29,7 +29,7 @@
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include "KRShader.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "assert.h"
|
||||
#include "KRLight.h"
|
||||
#include "KRDirectionalLight.h"
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "KRPointLight.h"
|
||||
|
||||
|
||||
const char *KRShader::KRENGINE_UNIFORM_NAMES[] = {
|
||||
const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
|
||||
"material_ambient", // KRENGINE_UNIFORM_MATERIAL_AMBIENT
|
||||
"material_diffuse", // KRENGINE_UNIFORM_MATERIAL_DIFFUSE
|
||||
"material_specular", // KRENGINE_UNIFORM_MATERIAL_SPECULAR
|
||||
@@ -108,7 +108,7 @@ const char *KRShader::KRENGINE_UNIFORM_NAMES[] = {
|
||||
"fade_color", // KRENGINE_UNIFORM_FADE_COLOR
|
||||
};
|
||||
|
||||
KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource) : KRContextObject(context)
|
||||
KRPipeline::KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource) : KRContextObject(context)
|
||||
{
|
||||
strcpy(m_szKey, szKey);
|
||||
m_iProgram = 0;
|
||||
@@ -216,16 +216,16 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
}
|
||||
}
|
||||
|
||||
KRShader::~KRShader() {
|
||||
KRPipeline::~KRPipeline() {
|
||||
if(m_iProgram) {
|
||||
GLDEBUG(glDeleteProgram(m_iProgram));
|
||||
if(getContext().getShaderManager()->m_active_shader == this) {
|
||||
getContext().getShaderManager()->m_active_shader = NULL;
|
||||
if(getContext().getPipelineManager()->m_active_pipeline == this) {
|
||||
getContext().getPipelineManager()->m_active_pipeline = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRShader::setUniform(int location, float value)
|
||||
void KRPipeline::setUniform(int location, float value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -243,7 +243,7 @@ void KRShader::setUniform(int location, float value)
|
||||
}
|
||||
}
|
||||
}
|
||||
void KRShader::setUniform(int location, int value)
|
||||
void KRPipeline::setUniform(int location, int value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -262,7 +262,7 @@ void KRShader::setUniform(int location, int value)
|
||||
}
|
||||
}
|
||||
|
||||
void KRShader::setUniform(int location, const Vector2 &value)
|
||||
void KRPipeline::setUniform(int location, const Vector2 &value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -280,7 +280,7 @@ void KRShader::setUniform(int location, const Vector2 &value)
|
||||
}
|
||||
}
|
||||
}
|
||||
void KRShader::setUniform(int location, const Vector3 &value)
|
||||
void KRPipeline::setUniform(int location, const Vector3 &value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -298,7 +298,7 @@ void KRShader::setUniform(int location, const Vector3 &value)
|
||||
}
|
||||
}
|
||||
}
|
||||
void KRShader::setUniform(int location, const Vector4 &value)
|
||||
void KRPipeline::setUniform(int location, const Vector4 &value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -317,7 +317,7 @@ void KRShader::setUniform(int location, const Vector4 &value)
|
||||
}
|
||||
}
|
||||
|
||||
void KRShader::setUniform(int location, const Matrix4 &value)
|
||||
void KRPipeline::setUniform(int location, const Matrix4 &value)
|
||||
{
|
||||
if(m_uniforms[location] != -1) {
|
||||
int value_index = m_uniform_value_index[location];
|
||||
@@ -336,14 +336,14 @@ void KRShader::setUniform(int location, const Matrix4 &value)
|
||||
}
|
||||
}
|
||||
|
||||
bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) {
|
||||
bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) {
|
||||
if(m_iProgram == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool shander_changed = false;
|
||||
if(getContext().getShaderManager()->m_active_shader != this) {
|
||||
getContext().getShaderManager()->m_active_shader = this;
|
||||
if(getContext().getPipelineManager()->m_active_pipeline != this) {
|
||||
getContext().getPipelineManager()->m_active_pipeline = this;
|
||||
GLDEBUG(glUseProgram(m_iProgram));
|
||||
shander_changed = true;
|
||||
}
|
||||
@@ -428,22 +428,22 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4
|
||||
}
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_MVP] != -1 || m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) {
|
||||
if(m_uniforms[KRENGINE_UNIFORM_MVP] != -1 || m_uniforms[KRPipeline::KRENGINE_UNIFORM_INVMVP] != -1) {
|
||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||
Matrix4 mvpMatrix = matModel * viewport.getViewProjectionMatrix();
|
||||
setUniform(KRENGINE_UNIFORM_MVP, mvpMatrix);
|
||||
|
||||
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) {
|
||||
setUniform(KRShader::KRENGINE_UNIFORM_INVMVP, Matrix4::Invert(mvpMatrix));
|
||||
if(m_uniforms[KRPipeline::KRENGINE_UNIFORM_INVMVP] != -1) {
|
||||
setUniform(KRPipeline::KRENGINE_UNIFORM_INVMVP, Matrix4::Invert(mvpMatrix));
|
||||
}
|
||||
}
|
||||
|
||||
if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1 || m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1 || m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_VIEW] != -1) {
|
||||
if(m_uniforms[KRPipeline::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1 || m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1 || m_uniforms[KRPipeline::KRENGINE_UNIFORM_MODEL_VIEW] != -1) {
|
||||
Matrix4 matModelView = matModel * viewport.getViewMatrix();
|
||||
setUniform(KRENGINE_UNIFORM_MODEL_VIEW, matModelView);
|
||||
|
||||
|
||||
if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) {
|
||||
if(m_uniforms[KRPipeline::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) {
|
||||
Vector3 view_space_model_origin = Matrix4::Dot(matModelView, Vector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
|
||||
setUniform(KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN, view_space_model_origin);
|
||||
}
|
||||
@@ -463,11 +463,11 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4
|
||||
setUniform(KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE, matModelInverseTranspose);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVP] != -1) {
|
||||
if(m_uniforms[KRPipeline::KRENGINE_UNIFORM_INVP] != -1) {
|
||||
setUniform(KRENGINE_UNIFORM_INVP, viewport.getInverseProjectionMatrix());
|
||||
}
|
||||
|
||||
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] != -1) {
|
||||
if(m_uniforms[KRPipeline::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] != -1) {
|
||||
Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();;
|
||||
// Remove the translation
|
||||
matInvMVPNoTranslate.getPointer()[3] = 0;
|
||||
@@ -576,6 +576,6 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *KRShader::getKey() const {
|
||||
const char *KRPipeline::getKey() const {
|
||||
return m_szKey;
|
||||
}
|
||||
16
kraken/KRShader.h → kraken/KRPipeline.h
Executable file → Normal file
16
kraken/KRShader.h → kraken/KRPipeline.h
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRShader.h
|
||||
// KRPipeline.h
|
||||
// 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
|
||||
// permitted provided that the following conditions are met:
|
||||
@@ -31,19 +31,19 @@
|
||||
|
||||
|
||||
|
||||
#ifndef KRSHADER_H
|
||||
#define KRSHADER_H
|
||||
#ifndef KRPIPELINE_H
|
||||
#define KRPIPELINE_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRCamera.h"
|
||||
#include "KRNode.h"
|
||||
#include "KRViewport.h"
|
||||
|
||||
class KRShader : public KRContextObject {
|
||||
class KRPipeline : public KRContextObject {
|
||||
public:
|
||||
KRShader(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRShader();
|
||||
KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRPipeline();
|
||||
const char *getKey() const;
|
||||
|
||||
bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
89
kraken/KRShaderManager.cpp → kraken/KRPipelineManager.cpp
Executable file → Normal file
89
kraken/KRShaderManager.cpp → kraken/KRPipelineManager.cpp
Executable file → Normal file
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRShaderManager.cpp
|
||||
// KRPipelineManager.cpp
|
||||
// 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
|
||||
// permitted provided that the following conditions are met:
|
||||
@@ -31,28 +31,43 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRLight.h"
|
||||
#include "KRDirectionalLight.h"
|
||||
#include "KRSpotLight.h"
|
||||
#include "KRPointLight.h"
|
||||
|
||||
#ifndef ANDROID
|
||||
#include "glslang/Public/ShaderLang.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
KRShaderManager::KRShaderManager(KRContext &context) : KRContextObject(context) {
|
||||
m_active_shader = NULL;
|
||||
KRPipelineManager::KRPipelineManager(KRContext &context) : KRContextObject(context) {
|
||||
m_active_pipeline = NULL;
|
||||
#ifndef ANDROID
|
||||
bool success = glslang::InitializeProcess();
|
||||
if (success) {
|
||||
printf("GLSLang Initialized.\n");
|
||||
}
|
||||
else {
|
||||
printf("Failed to initialize GLSLang.\n");
|
||||
}
|
||||
#endif // ANDROID
|
||||
}
|
||||
|
||||
KRShaderManager::~KRShaderManager() {
|
||||
|
||||
KRPipelineManager::~KRPipelineManager() {
|
||||
#ifndef ANDROID
|
||||
glslang::FinalizeProcess();
|
||||
#endif // ANDROID
|
||||
}
|
||||
|
||||
|
||||
KRShader *KRShaderManager::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) {
|
||||
KRPipeline *KRPipelineManager::getPipeline(const std::string &pipeline_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) {
|
||||
|
||||
int iShadowQuality = 0; // FINDME - HACK - Placeholder code, need to iterate through lights and dynamically build shader
|
||||
|
||||
|
||||
|
||||
int light_directional_count = 0;
|
||||
int light_point_count = 0;
|
||||
int light_spot_count = 0;
|
||||
@@ -73,7 +88,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
|
||||
bool bFadeColorEnabled = pCamera->getFadeColor().w >= 0.0f;
|
||||
|
||||
std::pair<std::string, std::vector<int> > key;
|
||||
key.first = shader_name;
|
||||
key.first = pipeline_name;
|
||||
key.second.push_back(light_directional_count);
|
||||
key.second.push_back(light_point_count);
|
||||
key.second.push_back(light_spot_count);
|
||||
@@ -120,26 +135,18 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
|
||||
key.second.push_back(bFadeColorEnabled);
|
||||
|
||||
|
||||
KRShader *pShader = m_shaders[key];
|
||||
KRPipeline *pPipeline = m_pipelines[key];
|
||||
|
||||
|
||||
if(pShader == NULL) {
|
||||
if(m_shaders.size() > KRContext::KRENGINE_MAX_SHADER_HANDLES) {
|
||||
// Keep the size of the shader cache reasonable
|
||||
std::map<std::pair<std::string, std::vector<int> > , KRShader *>::iterator itr = m_shaders.begin();
|
||||
if(pPipeline == NULL) {
|
||||
if(m_pipelines.size() > KRContext::KRENGINE_MAX_PIPELINE_HANDLES) {
|
||||
// Keep the size of the pipeline cache reasonable
|
||||
std::map<std::pair<std::string, std::vector<int> > , KRPipeline *>::iterator itr = m_pipelines.begin();
|
||||
delete (*itr).second;
|
||||
m_shaders.erase(itr);
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Swapping shaders...\n");
|
||||
m_pipelines.erase(itr);
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Swapping pipelines...\n");
|
||||
}
|
||||
|
||||
|
||||
std::string platform_shader_name = shader_name;
|
||||
#if TARGET_OS_IPHONE
|
||||
platform_shader_name = shader_name;
|
||||
#else
|
||||
platform_shader_name = shader_name + "_osx";
|
||||
#endif
|
||||
|
||||
stringstream stream;
|
||||
stream.precision(std::numeric_limits<long double>::digits10);
|
||||
|
||||
@@ -224,43 +231,43 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
|
||||
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");
|
||||
KRSource *vertSource = sourceManager->get(pipeline_name.c_str(), "vert");
|
||||
KRSource *fragSource = sourceManager->get(pipeline_name.c_str(), "frag");
|
||||
|
||||
if(vertSource == nullptr) {
|
||||
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", pipeline_name.c_str());
|
||||
}
|
||||
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", pipeline_name.c_str());
|
||||
}
|
||||
|
||||
Vector4 fade_color = pCamera->getFadeColor();
|
||||
|
||||
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, pipeline_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, vertSource->getData()->getString(), fragSource->getData()->getString());
|
||||
pPipeline = new KRPipeline(getContext(), szKey, options, vertSource->getData()->getString(), fragSource->getData()->getString());
|
||||
|
||||
m_shaders[key] = pShader;
|
||||
m_pipelines[key] = pPipeline;
|
||||
}
|
||||
return pShader;
|
||||
return pPipeline;
|
||||
}
|
||||
|
||||
bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, 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, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color)
|
||||
bool KRPipelineManager::selectPipeline(const std::string &pipeline_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, 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, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color)
|
||||
{
|
||||
KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f);
|
||||
return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power, fade_color);
|
||||
KRPipeline *pPipeline = getPipeline(pipeline_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f);
|
||||
return selectPipeline(camera, pPipeline, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power, fade_color);
|
||||
}
|
||||
|
||||
bool KRShaderManager::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 KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline, 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)
|
||||
{
|
||||
if(pShader) {
|
||||
return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color);
|
||||
if(pPipeline) {
|
||||
return pPipeline->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t KRShaderManager::getShaderHandlesUsed() {
|
||||
return m_shaders.size();
|
||||
size_t KRPipelineManager::getPipelineHandlesUsed() {
|
||||
return m_pipelines.size();
|
||||
}
|
||||
69
kraken/KRPipelineManager.h
Normal file
69
kraken/KRPipelineManager.h
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// KRPipelineManager.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.
|
||||
//
|
||||
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "KRCamera.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
|
||||
#include "KRPipeline.h"
|
||||
|
||||
#ifndef KRPIPELINEMANAGER_H
|
||||
#define KRPIPELINEMANAGER_H
|
||||
|
||||
class KRPipeline;
|
||||
class KRCamera;
|
||||
|
||||
class KRPipelineManager : public KRContextObject {
|
||||
public:
|
||||
KRPipelineManager(KRContext &context);
|
||||
virtual ~KRPipelineManager();
|
||||
|
||||
KRPipeline *getPipeline(const std::string &pipeline_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 selectPipeline(KRCamera &camera, KRPipeline *pPipeline, 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 selectPipeline(const std::string &pipeline_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, 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, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
|
||||
size_t getPipelineHandlesUsed();
|
||||
|
||||
KRPipeline *m_active_pipeline;
|
||||
|
||||
private:
|
||||
std::map<std::pair<std::string, std::vector<int> >, KRPipeline *> m_pipelines;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -67,15 +67,15 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
|
||||
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY, m_intensity * 0.01f);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START, getDecayStart());
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF, KRLIGHT_MIN_INFLUENCE);
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_POSITION, light_position);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_INTENSITY, m_intensity * 0.01f);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_DECAY_START, getDecayStart());
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_CUTOFF, KRLIGHT_MIN_INFLUENCE);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_POSITION, light_position);
|
||||
|
||||
|
||||
if(bVisualize) {
|
||||
|
||||
@@ -95,9 +95,9 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -298,7 +298,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibl
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
}
|
||||
|
||||
if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
m_pContext->getMeshManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14);
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// KRShaderManager.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 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 "KREngine-common.h"
|
||||
|
||||
#include "KRCamera.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
|
||||
#include "KRShader.h"
|
||||
|
||||
#ifndef KRSHADERMANAGER_H
|
||||
#define KRSHADERMANAGER_H
|
||||
|
||||
class KRShader;
|
||||
class KRCamera;
|
||||
|
||||
class KRShaderManager : public KRContextObject {
|
||||
public:
|
||||
KRShaderManager(KRContext &context);
|
||||
virtual ~KRShaderManager();
|
||||
|
||||
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(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const Matrix4 &matModel, 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, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
|
||||
size_t getShaderHandlesUsed();
|
||||
|
||||
KRShader *m_active_shader;
|
||||
|
||||
private:
|
||||
//unordered_map<std::string, KRShader *> m_shaders;
|
||||
std::map<std::pair<std::string, std::vector<int> >, KRShader *> m_shaders;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,8 +14,8 @@
|
||||
#include "KRCamera.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
#include "KRShaderManager.h"
|
||||
#include "KRShader.h"
|
||||
#include "KRPipelineManager.h"
|
||||
#include "KRPipeline.h"
|
||||
#include "KRStockGeometry.h"
|
||||
#include "KRDirectionalLight.h"
|
||||
#include "KRSpotLight.h"
|
||||
@@ -127,9 +127,9 @@ void KRSprite::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
// Render light sprite on transparency pass
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
|
||||
m_pContext->getMeshManager()->bindVBO(&m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
|
||||
Reference in New Issue
Block a user