Moved the post processing shader to KRShaderManager / KRShader
Changed many vertex buffers to VBO's --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40100
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1000469B15E6EF550053B072 /* KRSkyBox.cpp */; };
|
||||
1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 1000469C15E6EF550053B072 /* KRSkyBox.h */; };
|
||||
E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; };
|
||||
E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; };
|
||||
E40BA45415EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; };
|
||||
E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; };
|
||||
E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; };
|
||||
@@ -191,6 +193,7 @@
|
||||
/* Begin PBXFileReference section */
|
||||
1000469B15E6EF550053B072 /* KRSkyBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRSkyBox.cpp; path = Classes/KRSkyBox.cpp; sourceTree = "<group>"; };
|
||||
1000469C15E6EF550053B072 /* KRSkyBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRSkyBox.h; path = Classes/KRSkyBox.h; sourceTree = "<group>"; };
|
||||
E4030E4B160A3CF000592648 /* KRStockGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRStockGeometry.h; path = Classes/KRStockGeometry.h; sourceTree = "<group>"; };
|
||||
E40BA45215EFF79500D7C3DD /* KRAABB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRAABB.cpp; path = Classes/KRAABB.cpp; sourceTree = "<group>"; };
|
||||
E40BA45315EFF79500D7C3DD /* KRAABB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRAABB.h; path = Classes/KRAABB.h; sourceTree = "<group>"; };
|
||||
E414BAE11435557300A668C4 /* KRInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRInstance.h; path = Classes/KRInstance.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
@@ -556,10 +559,6 @@
|
||||
children = (
|
||||
E4CE184615FEED6800F80870 /* Standard Assets */,
|
||||
E491016E13C99BAE0098455B /* Classes */,
|
||||
E4924C2415EE95E700B965C6 /* KROctree.cpp */,
|
||||
E4924C2515EE95E800B965C6 /* KROctree.h */,
|
||||
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */,
|
||||
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */,
|
||||
E491016713C99B9E0098455B /* Supporting Files */,
|
||||
);
|
||||
path = KREngine;
|
||||
@@ -576,6 +575,10 @@
|
||||
E491016E13C99BAE0098455B /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E4924C2415EE95E700B965C6 /* KROctree.cpp */,
|
||||
E4924C2515EE95E800B965C6 /* KROctree.h */,
|
||||
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */,
|
||||
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */,
|
||||
E4F9753815362A5200FD60B2 /* 3rdparty */,
|
||||
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
|
||||
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
|
||||
@@ -595,6 +598,7 @@
|
||||
E488399915F92BA300BD66D5 /* Managers */,
|
||||
E461A173152E59DF00F2044A /* Math */,
|
||||
E461A170152E598200F2044A /* Resources */,
|
||||
E4030E4B160A3CF000592648 /* KRStockGeometry.h */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
@@ -692,6 +696,7 @@
|
||||
E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */,
|
||||
E488399615F928CA00BD66D5 /* KRBundle.h in Headers */,
|
||||
E488399E15F92BE000BD66D5 /* KRBundleManager.h in Headers */,
|
||||
E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -740,6 +745,7 @@
|
||||
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
|
||||
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
|
||||
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */,
|
||||
E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#import "KRVector2.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRStockGeometry.h"
|
||||
|
||||
KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(context) {
|
||||
backingWidth = width;
|
||||
@@ -61,7 +62,7 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(c
|
||||
bEnableSpecular = false; // FINDME - Should be "true"
|
||||
bEnableLightMap = true;
|
||||
bDebugSuperShiny = false;
|
||||
bEnableDeferredLighting = true; // FINDME - should be "true"
|
||||
bEnableDeferredLighting = false; // FINDME - should be "true"
|
||||
|
||||
|
||||
dAmbientR = 0.25f; // FINDME - should be "0.0f"
|
||||
@@ -96,14 +97,12 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(c
|
||||
memset(shadowFramebuffer, sizeof(GLuint) * 3, 0);
|
||||
memset(shadowDepthTexture, sizeof(GLuint) * 3, 0);
|
||||
|
||||
m_postShaderProgram = 0;
|
||||
m_iFrame = 0;
|
||||
|
||||
createBuffers();
|
||||
}
|
||||
|
||||
KRCamera::~KRCamera() {
|
||||
invalidatePostShader();
|
||||
destroyBuffers();
|
||||
}
|
||||
|
||||
@@ -383,26 +382,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
|
||||
KRMat4 projectionMatrix = getProjectionMatrix();
|
||||
|
||||
static const GLfloat cubeVertices[] = {
|
||||
1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
-1.0,-1.0, 1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
-1.0, 1.0,-1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
1.0,-1.0,-1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
-1.0, 1.0,-1.0
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false);
|
||||
for(std::set<KRAABB>::iterator itr=m_visibleBounds.begin(); itr != m_visibleBounds.end(); itr++) {
|
||||
KRMat4 matModel = KRMat4();
|
||||
matModel.scale((*itr).size() / 2.0f);
|
||||
@@ -642,12 +622,7 @@ void KRCamera::renderPost()
|
||||
// Disable alpha blending
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
|
||||
static const GLfloat squareVerticesShadow[3][8] = {{
|
||||
-1.0f, -1.0f,
|
||||
@@ -666,33 +641,24 @@ void KRCamera::renderPost()
|
||||
0.40f, -0.60f,
|
||||
}};
|
||||
|
||||
static const GLfloat textureVertices[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
bindPostShader();
|
||||
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRMat4 matIdentity; // Value not used by postshader
|
||||
KRVector3 vec4Temp; // Value not used by postshader
|
||||
postShader->bind(this, matIdentity, matIdentity, m_position, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||
//GLDEBUG(glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture));
|
||||
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||
|
||||
// Update attribute values.
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
|
||||
@@ -707,27 +673,22 @@ void KRCamera::renderPost()
|
||||
|
||||
if(bShowShadowBuffer) {
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||
|
||||
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||
|
||||
// Update attribute values.
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
m_pContext->getModelManager()->configureAttribs(true, false, false, true, false);
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, KRENGINE_VERTICES_2D_SQUARE_UV));
|
||||
|
||||
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVerticesShadow[iShadow]));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
||||
@@ -747,7 +708,6 @@ void KRCamera::renderPost()
|
||||
KRTexture *pFontTexture = m_pContext->getTextureManager()->getTexture("font");
|
||||
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
@@ -755,9 +715,6 @@ void KRCamera::renderPost()
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(1, pFontTexture);
|
||||
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||
|
||||
const char *pChar = szText;
|
||||
int iPos=0;
|
||||
double dScale = 1.0 / 24.0;
|
||||
@@ -781,11 +738,9 @@ void KRCamera::renderPost()
|
||||
dTexScale * iCol + dTexScale, dTexScale * iRow
|
||||
};
|
||||
|
||||
m_pContext->getModelManager()->configureAttribs(true, false, false, true, false);
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, charTexCoords));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, charVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
|
||||
iPos++;
|
||||
@@ -799,39 +754,6 @@ void KRCamera::renderPost()
|
||||
|
||||
}
|
||||
|
||||
|
||||
void KRCamera::bindPostShader()
|
||||
{
|
||||
if(!m_postShaderProgram) {
|
||||
std::stringstream stream;
|
||||
stream.precision(std::numeric_limits<long double>::digits10);
|
||||
|
||||
stream << "#define DOF_QUALITY " << dof_quality;
|
||||
stream << "\n#define ENABLE_FLASH " << (bEnableFlash ? "1" : "0");
|
||||
stream << "\n#define ENABLE_VIGNETTE " << (bEnableVignette ? "1" : "0");
|
||||
stream.setf(std::ios::fixed,std::ios::floatfield);
|
||||
stream << "\n#define DOF_DEPTH " << dof_depth;
|
||||
stream << "\n#define DOF_FALLOFF " << dof_falloff;
|
||||
stream << "\n#define FLASH_DEPTH " << flash_depth;
|
||||
stream << "\n#define FLASH_FALLOFF " << flash_falloff;
|
||||
stream << "\n#define FLASH_INTENSITY " << flash_intensity;
|
||||
stream << "\n#define VIGNETTE_RADIUS " << vignette_radius;
|
||||
stream << "\n#define VIGNETTE_FALLOFF " << vignette_falloff;
|
||||
|
||||
stream << "\n";
|
||||
LoadShader(*m_pContext, "PostShader", &m_postShaderProgram, stream.str());
|
||||
}
|
||||
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||
}
|
||||
|
||||
void KRCamera::invalidatePostShader()
|
||||
{
|
||||
if(m_postShaderProgram) {
|
||||
GLDEBUG(glDeleteProgram(m_postShaderProgram));
|
||||
m_postShaderProgram = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void KRCamera::invalidateShadowBuffers() {
|
||||
for(int i=0; i < m_cShadowBuffers; i++) {
|
||||
shadowValid[i] = false;
|
||||
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
|
||||
void renderFrame(KRScene &scene, KRMat4 &viewMatrix);
|
||||
void renderShadowBuffer(KRScene &scene, int iShadow);
|
||||
void invalidatePostShader();
|
||||
void invalidateShadowBuffers();
|
||||
void allocateShadowBuffers();
|
||||
void createBuffers();
|
||||
@@ -158,11 +157,9 @@ private:
|
||||
};
|
||||
GLint m_shadowUniforms[KRENGINE_NUM_UNIFORMS];
|
||||
|
||||
GLuint m_postShaderProgram;
|
||||
GLuint m_shadowShaderProgram;
|
||||
|
||||
void renderPost();
|
||||
void bindPostShader();
|
||||
|
||||
void destroyBuffers();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#import "KRContext.h"
|
||||
#import "KRMat4.h"
|
||||
#import "assert.h"
|
||||
#import "KRStockGeometry.h"
|
||||
|
||||
KRDirectionalLight::KRDirectionalLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
||||
{
|
||||
@@ -97,15 +98,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,61 +329,51 @@ double const PI = 3.141592653589793f;
|
||||
case 14:
|
||||
if(_camera->dof_quality != (int)v) {
|
||||
_camera->dof_quality = (int)v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
if(_camera->dof_depth != v) {
|
||||
_camera->dof_depth = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
if(_camera->dof_falloff != v) {
|
||||
_camera->dof_falloff = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
if(_camera->bEnableFlash != bNewBoolVal) {
|
||||
_camera->bEnableFlash = bNewBoolVal;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
if(_camera->flash_intensity != v) {
|
||||
_camera->flash_intensity = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
if(_camera->flash_depth != v) {
|
||||
_camera->flash_depth = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
if(_camera->flash_falloff != v) {
|
||||
_camera->flash_falloff = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
if(_camera->bEnableVignette != bNewBoolVal) {
|
||||
_camera->bEnableVignette = bNewBoolVal;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
if(_camera->vignette_radius != v) {
|
||||
_camera->vignette_radius = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 23:
|
||||
if(_camera->vignette_falloff != v) {
|
||||
_camera->vignette_falloff = v;
|
||||
_camera->invalidatePostShader();
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRShaderManager.h"
|
||||
#import "KRShader.h"
|
||||
#import "KRStockGeometry.h"
|
||||
#import "assert.h"
|
||||
|
||||
KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
@@ -142,27 +143,16 @@ void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
|
||||
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("flare", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
|
||||
|
||||
static const GLfloat squareVertices[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) {
|
||||
m_pData = new KRDataBlock();
|
||||
}
|
||||
@@ -126,24 +128,7 @@ void KRMesh::renderSubmesh(int iSubmesh, int &iPrevBuffer) {
|
||||
void *vbo_end = (unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE + vertex_size * cBufferVertexes;
|
||||
void *buffer_end = m_pData->getEnd();
|
||||
assert(vbo_end <= buffer_end);
|
||||
m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes);
|
||||
|
||||
if(iPrevBuffer == -1) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB));
|
||||
}
|
||||
|
||||
|
||||
int data_size = sizeof(VertexData);
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(0)));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D))));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 2)));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3)));
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3 + sizeof(TexCoord))));
|
||||
m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes, true, true, true, true, true);
|
||||
}
|
||||
iPrevBuffer = iBuffer;
|
||||
|
||||
|
||||
@@ -78,6 +78,8 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
||||
m_materials.push_back(pMaterial);
|
||||
if(pMaterial) {
|
||||
m_uniqueMaterials.insert(pMaterial);
|
||||
} else {
|
||||
fprintf(stderr, "Missing material: %s\n", szMaterialName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,11 @@ KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
|
||||
m_currentVBO.handle = 0;
|
||||
m_currentVBO.data = NULL;
|
||||
m_vboMemUsed = 0;
|
||||
m_bVBOAttribEnabled_Vertex = false;
|
||||
m_bVBOAttribEnabled_Normal = false;
|
||||
m_bVBOAttribEnabled_Tangent = false;
|
||||
m_bVBOAttribEnabled_UVA = false;
|
||||
m_bVBOAttribEnabled_UVB = false;
|
||||
}
|
||||
|
||||
KRModelManager::~KRModelManager() {
|
||||
@@ -81,7 +86,7 @@ void KRModelManager::unbindVBO() {
|
||||
}
|
||||
}
|
||||
|
||||
void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size) {
|
||||
void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb) {
|
||||
|
||||
if(m_currentVBO.data != data || m_currentVBO.size != size) {
|
||||
|
||||
@@ -120,11 +125,106 @@ void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size) {
|
||||
|
||||
m_vbosActive[data] = m_currentVBO;
|
||||
}
|
||||
|
||||
configureAttribs(enable_vertex, enable_normal, enable_tangent, enable_uva, enable_uvb);
|
||||
|
||||
}
|
||||
|
||||
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
||||
}
|
||||
|
||||
void KRModelManager::configureAttribs(bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb)
|
||||
{
|
||||
bool reconfigured = false;
|
||||
|
||||
if(m_bVBOAttribEnabled_Vertex != enable_vertex) {
|
||||
if(enable_vertex) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
} else {
|
||||
GLDEBUG(glDisableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
}
|
||||
m_bVBOAttribEnabled_Vertex = enable_vertex;
|
||||
reconfigured = true;
|
||||
}
|
||||
if(m_bVBOAttribEnabled_Normal != enable_normal) {
|
||||
if(enable_normal) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL));
|
||||
} else {
|
||||
GLDEBUG(glDisableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL));
|
||||
}
|
||||
m_bVBOAttribEnabled_Normal = enable_normal;
|
||||
reconfigured = true;
|
||||
}
|
||||
if(m_bVBOAttribEnabled_Tangent != enable_tangent) {
|
||||
if(enable_tangent) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT));
|
||||
} else {
|
||||
GLDEBUG(glDisableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT));
|
||||
}
|
||||
m_bVBOAttribEnabled_Tangent = enable_tangent;
|
||||
reconfigured = true;
|
||||
}
|
||||
if(m_bVBOAttribEnabled_UVA != enable_uva) {
|
||||
if(enable_uva) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
} else {
|
||||
GLDEBUG(glDisableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||
}
|
||||
m_bVBOAttribEnabled_UVA = enable_uva;
|
||||
reconfigured = true;
|
||||
}
|
||||
if(m_bVBOAttribEnabled_UVB != enable_uvb) {
|
||||
if(enable_uvb) {
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB));
|
||||
} else {
|
||||
GLDEBUG(glDisableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB));
|
||||
}
|
||||
m_bVBOAttribEnabled_UVB = enable_uvb;
|
||||
reconfigured = true;
|
||||
}
|
||||
|
||||
if(reconfigured || true) {
|
||||
int data_size = 0;
|
||||
if(enable_vertex) {
|
||||
data_size += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_normal) {
|
||||
data_size += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_tangent) {
|
||||
data_size += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_uva) {
|
||||
data_size += sizeof(KRMesh::TexCoord);
|
||||
}
|
||||
if(enable_uvb) {
|
||||
data_size += sizeof(KRMesh::TexCoord);
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
if(enable_vertex) {
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(offset)));
|
||||
offset += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_normal) {
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(offset)));
|
||||
offset += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_tangent) {
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(offset)));
|
||||
offset += sizeof(KRMesh::KRVector3D);
|
||||
}
|
||||
if(enable_uva) {
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(offset)));
|
||||
offset += sizeof(KRMesh::TexCoord);
|
||||
}
|
||||
if(enable_uvb) {
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(offset)));
|
||||
offset += sizeof(KRMesh::TexCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long KRModelManager::getMemUsed()
|
||||
{
|
||||
return m_vboMemUsed;
|
||||
@@ -139,4 +239,5 @@ void KRModelManager::rotateBuffers()
|
||||
m_vbosPool.erase(m_currentVBO.data);
|
||||
m_vbosActive[m_currentVBO.data] = m_currentVBO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,10 +61,12 @@ public:
|
||||
std::map<std::string, KRModel *> getModels();
|
||||
|
||||
|
||||
void bindVBO(GLvoid *data, GLsizeiptr size);
|
||||
void bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb);
|
||||
void unbindVBO();
|
||||
long getMemUsed();
|
||||
|
||||
void configureAttribs(bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb);
|
||||
|
||||
private:
|
||||
std::map<std::string, KRModel *> m_models;
|
||||
|
||||
@@ -80,6 +82,13 @@ private:
|
||||
std::map<GLvoid *, vbo_info_type> m_vbosActive;
|
||||
std::map<GLvoid *, vbo_info_type> m_vbosPool;
|
||||
|
||||
bool m_bVBOAttribEnabled_Vertex;
|
||||
bool m_bVBOAttribEnabled_Normal;
|
||||
bool m_bVBOAttribEnabled_Tangent;
|
||||
bool m_bVBOAttribEnabled_UVA;
|
||||
bool m_bVBOAttribEnabled_UVB;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#import "KRCamera.h"
|
||||
#import "KRContext.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRStockGeometry.h"
|
||||
#import "assert.h"
|
||||
|
||||
KRPointLight::KRPointLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
||||
@@ -141,23 +142,18 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
|
||||
|
||||
if(bInsideLight) {
|
||||
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
} else {
|
||||
m_pContext->getModelManager()->configureAttribs(true, false, false, false, false);
|
||||
// Render sphere of light's influence
|
||||
generateMesh();
|
||||
|
||||
@@ -167,7 +163,6 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, m_cVertices));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#import "KRScene.h"
|
||||
#import "KRNode.h"
|
||||
#import "KRStockGeometry.h"
|
||||
|
||||
KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) {
|
||||
m_pContext = &context;
|
||||
@@ -170,26 +171,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
||||
|
||||
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
|
||||
|
||||
static const GLfloat cubeVertices[] = {
|
||||
1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
-1.0,-1.0, 1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
-1.0, 1.0,-1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
1.0,-1.0,-1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
-1.0, 1.0,-1.0
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false);
|
||||
KRMat4 matModel = KRMat4();
|
||||
matModel.scale(octreeBounds.size() / 2.0f);
|
||||
matModel.translate(octreeBounds.center());
|
||||
|
||||
@@ -159,6 +159,9 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
||||
m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME] = glGetUniformLocation(m_iProgram, "gbuffer_frame");
|
||||
m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH] = glGetUniformLocation(m_iProgram, "gbuffer_depth");
|
||||
|
||||
m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME] = glGetUniformLocation(m_iProgram, "depthFrame");
|
||||
m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME] = glGetUniformLocation(m_iProgram, "renderFrame");
|
||||
|
||||
} catch(...) {
|
||||
if(vertexShader) {
|
||||
GLDEBUG(glDeleteShader(vertexShader));
|
||||
@@ -250,6 +253,9 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE], 7)); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
|
||||
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME], 0));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME], 1));
|
||||
|
||||
#if defined(DEBUG)
|
||||
GLint logLength;
|
||||
|
||||
|
||||
@@ -117,6 +117,8 @@ public:
|
||||
KRENGINE_UNIFORM_SHADOWTEXTURE3,
|
||||
KRENGINE_UNIFORM_GBUFFER_FRAME,
|
||||
KRENGINE_UNIFORM_GBUFFER_DEPTH,
|
||||
KRENGINE_UNIFORM_DEPTH_FRAME,
|
||||
KRENGINE_UNIFORM_RENDER_FRAME,
|
||||
|
||||
KRENGINE_NUM_UNIFORMS
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ KRShaderManager::~KRShaderManager() {
|
||||
KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass) {
|
||||
|
||||
char szKey[256];
|
||||
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s", pCamera->bEnablePerPixel, bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, renderPass, shader_name.c_str());
|
||||
sprintf(szKey, "%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", pCamera->bEnablePerPixel, bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, renderPass, shader_name.c_str(),pCamera->dof_quality,pCamera->bEnableFlash,pCamera->bEnableVignette,pCamera->dof_depth,pCamera->dof_falloff,pCamera->flash_depth,pCamera->flash_falloff,pCamera->flash_intensity,pCamera->vignette_radius,pCamera->vignette_falloff);
|
||||
|
||||
|
||||
/*
|
||||
@@ -62,6 +62,7 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
|
||||
std::map<std::string, KRShader *>::iterator itr = m_shaders.begin();
|
||||
delete (*itr).second;
|
||||
m_shaders.erase(itr);
|
||||
fprintf(stderr, "Swapping shaders...\n");
|
||||
}
|
||||
|
||||
stringstream stream;
|
||||
@@ -99,12 +100,29 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
|
||||
stream << "\n#define GBUFFER_PASS " << 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
stream << "\n#define DOF_QUALITY " << pCamera->dof_quality;
|
||||
stream << "\n#define ENABLE_FLASH " << (pCamera->bEnableFlash ? "1" : "0");
|
||||
stream << "\n#define ENABLE_VIGNETTE " << (pCamera->bEnableVignette ? "1" : "0");
|
||||
|
||||
|
||||
|
||||
stream.setf(ios::fixed,ios::floatfield);
|
||||
|
||||
stream.precision(std::numeric_limits<long double>::digits10);
|
||||
|
||||
stream << "\n#define DOF_DEPTH " << pCamera->dof_depth;
|
||||
stream << "\n#define DOF_FALLOFF " << pCamera->dof_falloff;
|
||||
stream << "\n#define FLASH_DEPTH " << pCamera->flash_depth;
|
||||
stream << "\n#define FLASH_FALLOFF " << pCamera->flash_falloff;
|
||||
stream << "\n#define FLASH_INTENSITY " << pCamera->flash_intensity;
|
||||
stream << "\n#define VIGNETTE_RADIUS " << pCamera->vignette_radius;
|
||||
stream << "\n#define VIGNETTE_FALLOFF " << pCamera->vignette_falloff;
|
||||
|
||||
stream << "\n";
|
||||
std::string options = stream.str();
|
||||
fprintf(stderr, "Shader Options:\n%s\n\n", options.c_str());
|
||||
|
||||
pShader = new KRShader(szKey, options, m_vertShaderSource[shader_name], m_fragShaderSource[shader_name]);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#import "KRMat4.h"
|
||||
#import "KRResource.h"
|
||||
#import "KRContext.h"
|
||||
#import "KRStockGeometry.h"
|
||||
|
||||
KRSkyBox::KRSkyBox(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
@@ -153,15 +154,7 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
|
||||
55
KREngine/KREngine/Classes/KRStockGeometry.h
Normal file
55
KREngine/KREngine/Classes/KRStockGeometry.h
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// KRStockGeometry.h
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2012-09-19.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef KRSTOCKGEOMETRY_H
|
||||
#define KRSTOCKGEOMETRY_H
|
||||
|
||||
static const GLfloat KRENGINE_VBO_3D_CUBE[] = {
|
||||
1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
-1.0,-1.0, 1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
-1.0, 1.0,-1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
1.0,-1.0, 1.0,
|
||||
1.0,-1.0,-1.0,
|
||||
-1.0,-1.0,-1.0,
|
||||
1.0, 1.0,-1.0,
|
||||
-1.0, 1.0,-1.0
|
||||
};
|
||||
|
||||
static int KRENGINE_VBO_3D_CUBE_SIZE = sizeof(GLfloat) * 3 * 14;
|
||||
|
||||
static const GLfloat KRENGINE_VERTICES_2D_SQUARE[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
static const GLfloat KRENGINE_VERTICES_2D_SQUARE_UV[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
static const GLfloat KRENGINE_VBO_2D_SQUARE[] = {
|
||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
static const int KRENGINE_VBO_2D_SQUARE_SIZE = sizeof(GLfloat) * 5 * 4;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#define KRENGINE_MAX_TEXTURE_UNITS 8
|
||||
#define KRENGINE_MAX_TEXTURE_HANDLES 10000
|
||||
#define KRENGINE_MAX_TEXTURE_MEM 100000000
|
||||
#define KRENGINE_MAX_TEXTURE_MEM 200000000
|
||||
|
||||
#ifndef KRTEXTUREMANAGER_H
|
||||
#define KRTEXTUREMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user