Optimized to reduce redundant GL state changes
Updated header copyright dates Further refactoring to prepare for FBX file compatibility --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4010
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// KRBoundingVolume.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRBoundingVolume.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRSettings.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRSettings.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KREngine.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KREngine.mm
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRInstance.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRInstance.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRMat4.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRMat4.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRMaterial.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -102,69 +102,90 @@ bool KRMaterial::isTransparent() {
|
||||
return m_tr != 0.0;
|
||||
}
|
||||
|
||||
void KRMaterial::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
||||
void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
||||
bool bSameMaterial = *prevBoundMaterial == this;
|
||||
|
||||
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
|
||||
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
||||
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
||||
|
||||
KRShader *pShader = m_pShaderManager->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers);
|
||||
pShader->bind(pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT],
|
||||
m_ka_r + pCamera->dAmbientR,
|
||||
m_ka_g + pCamera->dAmbientG,
|
||||
m_ka_b + pCamera->dAmbientB
|
||||
);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||
m_kd_r * pCamera->dSunR,
|
||||
m_kd_g * pCamera->dSunG,
|
||||
m_kd_b * pCamera->dSunB
|
||||
);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||
m_ks_r * pCamera->dSunR,
|
||||
m_ks_g * pCamera->dSunG,
|
||||
m_ks_b * pCamera->dSunB
|
||||
);
|
||||
|
||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
|
||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns);
|
||||
if(!bSameMaterial) {
|
||||
KRShader *pShader = m_pShaderManager->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers);
|
||||
|
||||
int iTextureName = 0;
|
||||
if(bDiffuseMap) {
|
||||
iTextureName = m_pDiffuseMap->getName();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
iTextureName = 0;
|
||||
if(bSpecMap) {
|
||||
iTextureName = m_pSpecularMap->getName();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||
if(!bSameShader) {
|
||||
pShader->bind(pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns);
|
||||
strcpy(szPrevShaderKey, pShader->getKey());
|
||||
}
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT],
|
||||
m_ka_r + pCamera->dAmbientR,
|
||||
m_ka_g + pCamera->dAmbientG,
|
||||
m_ka_b + pCamera->dAmbientB
|
||||
);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||
m_kd_r * pCamera->dSunR,
|
||||
m_kd_g * pCamera->dSunG,
|
||||
m_kd_b * pCamera->dSunB
|
||||
);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||
m_ks_r * pCamera->dSunR,
|
||||
m_ks_g * pCamera->dSunG,
|
||||
m_ks_b * pCamera->dSunB
|
||||
);
|
||||
|
||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
|
||||
|
||||
|
||||
iTextureName = 0;
|
||||
if(bNormalMap) {
|
||||
iTextureName = m_pNormalMap->getName();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
bool bSameDiffuseMap = false;
|
||||
bool bSameSpecMap = false;
|
||||
bool bSameNormalMap = false;
|
||||
if(*prevBoundMaterial) {
|
||||
if((*prevBoundMaterial)->m_pDiffuseMap == m_pDiffuseMap) {
|
||||
bSameDiffuseMap = true;
|
||||
}
|
||||
if((*prevBoundMaterial)->m_pSpecularMap == m_pSpecularMap) {
|
||||
bSameSpecMap = true;
|
||||
}
|
||||
if((*prevBoundMaterial)->m_pNormalMap == m_pNormalMap) {
|
||||
bSameNormalMap = true;
|
||||
}
|
||||
}
|
||||
if(bDiffuseMap && !bSameDiffuseMap) {
|
||||
int iTextureName = m_pDiffuseMap->getName();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
if(bSpecMap && !bSameSpecMap) {
|
||||
int iTextureName = m_pSpecularMap->getName();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
if(bNormalMap && !bSameNormalMap) {
|
||||
int iTextureName = m_pNormalMap->getName();
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
*prevBoundMaterial = this;
|
||||
} // if(!bSameMaterial)
|
||||
}
|
||||
|
||||
char *KRMaterial::getName() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRMaterial.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
void setTransparency(GLfloat a);
|
||||
void setShininess(GLfloat s);
|
||||
|
||||
void bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
||||
void bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
||||
bool isTransparent();
|
||||
char *getName();
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRMaterialManager.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRMaterialManager.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,8 +2,31 @@
|
||||
// KRMesh.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-03-15.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
// 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 "KRMesh.h"
|
||||
@@ -160,4 +183,5 @@ void KRMesh::renderSubmesh(int iSubmesh) {
|
||||
cVertexes = 0;
|
||||
}
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,31 @@
|
||||
// KRMesh.h
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-03-15.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
// 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.
|
||||
//
|
||||
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRModel.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -55,7 +55,9 @@ void KRModel::loadPack(std::string path, KRMaterialManager *pMaterialManager) {
|
||||
vector<KRMesh::Submesh *> submeshes = m_mesh.getSubmeshes();
|
||||
|
||||
for(std::vector<KRMesh::Submesh *>::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) {
|
||||
m_materials.push_back(pMaterialManager->getMaterial((*itr)->szMaterialName));
|
||||
KRMaterial *pMaterial = pMaterialManager->getMaterial((*itr)->szMaterialName);
|
||||
m_materials.push_back(pMaterial);
|
||||
m_uniqueMaterials.insert(pMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,21 +66,35 @@ KRModel::~KRModel() {
|
||||
}
|
||||
|
||||
void KRModel::render(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
||||
KRMaterial *pPrevBoundMaterial = NULL;
|
||||
char szPrevShaderKey[128];
|
||||
szPrevShaderKey[0] = '\0';
|
||||
int cSubmeshes = m_mesh.getSubmeshes().size();
|
||||
for(int iSubmesh=0; iSubmesh<cSubmeshes; iSubmesh++) {
|
||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||
|
||||
if(pMaterial != NULL) {
|
||||
if(!bRenderShadowMap) {
|
||||
pMaterial->bind(pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
||||
}
|
||||
if(bRenderShadowMap) {
|
||||
for(int iSubmesh=0; iSubmesh<cSubmeshes; iSubmesh++) {
|
||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||
|
||||
if(pMaterial != NULL) {
|
||||
|
||||
if(!bRenderShadowMap || !pMaterial->isTransparent()) {
|
||||
// Exclude transparent and semi-transparent meshes from shadow maps
|
||||
m_mesh.renderSubmesh(iSubmesh);
|
||||
if(pMaterial->isTransparent()) {
|
||||
// Exclude transparent and semi-transparent meshes from shadow maps
|
||||
m_mesh.renderSubmesh(iSubmesh);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// Apply submeshes in per-material batches to reduce number of state changes
|
||||
for(std::set<KRMaterial *>::iterator mat_itr = m_uniqueMaterials.begin(); mat_itr != m_uniqueMaterials.end(); mat_itr++) {
|
||||
for(int iSubmesh=0; iSubmesh<cSubmeshes; iSubmesh++) {
|
||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||
|
||||
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
||||
pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
||||
m_mesh.renderSubmesh(iSubmesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRModel.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -33,10 +33,12 @@
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <stdint.h>
|
||||
#import <vector>
|
||||
#import <set>
|
||||
#import <string>
|
||||
#import "KRMesh.h"
|
||||
|
||||
using std::vector;
|
||||
using std::set;
|
||||
|
||||
#ifndef KRMODEL_I
|
||||
#define KRMODEL_I
|
||||
@@ -58,6 +60,7 @@ private:
|
||||
void loadPack(std::string path, KRMaterialManager *pMaterialManager);
|
||||
|
||||
vector<KRMaterial *> m_materials;
|
||||
set<KRMaterial *> m_uniqueMaterials;
|
||||
KRMesh m_mesh;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//
|
||||
// KRModelManager.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRModelManager.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRScene.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRScene.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRShader.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -31,7 +31,8 @@
|
||||
|
||||
#include "KRShader.h"
|
||||
|
||||
KRShader::KRShader(std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource) {
|
||||
KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource) {
|
||||
strcpy(m_szKey, szKey);
|
||||
m_iProgram = 0;
|
||||
GLuint vertexShader = 0, fragShader = 0;
|
||||
try {
|
||||
@@ -185,3 +186,7 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPositio
|
||||
GLuint KRShader::getProgram() {
|
||||
return m_iProgram;
|
||||
}
|
||||
|
||||
char *KRShader::getKey() {
|
||||
return m_szKey;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRShader.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -46,9 +46,10 @@ using std::vector;
|
||||
|
||||
class KRShader {
|
||||
public:
|
||||
KRShader(std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
||||
KRShader(char *szKey, std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
||||
~KRShader();
|
||||
GLuint getProgram();
|
||||
char *getKey();
|
||||
|
||||
void bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
||||
|
||||
@@ -82,6 +83,7 @@ public:
|
||||
KRENGINE_NUM_UNIFORMS
|
||||
};
|
||||
GLint m_uniforms[KRENGINE_NUM_UNIFORMS];
|
||||
char m_szKey[128];
|
||||
|
||||
private:
|
||||
GLuint m_iProgram;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRShaderManager.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
@@ -83,7 +83,7 @@ KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool b
|
||||
stream << "\n";
|
||||
std::string options = stream.str();
|
||||
|
||||
pShader = new KRShader(options, m_szVertShaderSource, m_szFragShaderSource);
|
||||
pShader = new KRShader(szKey, options, m_szVertShaderSource, m_szFragShaderSource);
|
||||
|
||||
m_shaders[szKey] = pShader;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// KRShaderManager.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRTexture.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRTexture.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRTextureManager.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRTextureManager.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRVector3.cpp
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// KRVector3.h
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,8 +1,8 @@
|
||||
//
|
||||
// Shader.vsh
|
||||
// gldemo
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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,4 +1,4 @@
|
||||
// Copyright 2011 Kearwood Gilbert. All rights reserved.
|
||||
// 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:
|
||||
|
||||
Reference in New Issue
Block a user