Added debugging macro for GL calls
Activated octree culling logic as a default Wide spread bug fixes related to occlusion culling and GPU resource management Implemented logic to automatically enable alpha blending for materials that do not contain an alpha blending statement but have a material-level opacity value set less than 1.0 Extended the krobject file format to 256 characters for material names. Added logic to prevent exported krobject files from being corrupted when long material names are used. --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4096
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#import <assert.h>
|
||||||
|
|
||||||
#import "KRVector2.h"
|
#import "KRVector2.h"
|
||||||
#import "KRCamera.h"
|
#import "KRCamera.h"
|
||||||
@@ -57,15 +58,15 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(c
|
|||||||
bDebugPSSM = false;
|
bDebugPSSM = false;
|
||||||
bEnableAmbient = true;
|
bEnableAmbient = true;
|
||||||
bEnableDiffuse = true;
|
bEnableDiffuse = true;
|
||||||
bEnableSpecular = true;
|
bEnableSpecular = false; // FINDME - Should be "true"
|
||||||
bEnableLightMap = true;
|
bEnableLightMap = true;
|
||||||
bDebugSuperShiny = false;
|
bDebugSuperShiny = false;
|
||||||
bEnableDeferredLighting = true;
|
bEnableDeferredLighting = true; // FINDME - should be "true"
|
||||||
|
|
||||||
|
|
||||||
dAmbientR = 0.0f;
|
dAmbientR = 0.25f; // FINDME - should be "0.0f"
|
||||||
dAmbientG = 0.0f;
|
dAmbientG = 0.25f; // FINDME - should be "0.0f"
|
||||||
dAmbientB = 0.0f;
|
dAmbientB = 0.25f; // FINDME - should be "0.0f"
|
||||||
|
|
||||||
dSunR = 1.0f;
|
dSunR = 1.0f;
|
||||||
dSunG = 1.0f;
|
dSunG = 1.0f;
|
||||||
@@ -130,6 +131,7 @@ void KRCamera::setPosition(const KRVector3 &position) {
|
|||||||
|
|
||||||
void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix)
|
void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix)
|
||||||
{
|
{
|
||||||
|
m_pContext->rotateBuffers();
|
||||||
KRMat4 invViewMatrix = viewMatrix;
|
KRMat4 invViewMatrix = viewMatrix;
|
||||||
invViewMatrix.invert();
|
invViewMatrix.invert();
|
||||||
|
|
||||||
@@ -195,49 +197,49 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
glEnable(GL_CULL_FACE);
|
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Enable z-buffer write
|
// Enable z-buffer write
|
||||||
glDepthMask(GL_TRUE);
|
GLDEBUG(glDepthMask(GL_TRUE));
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LEQUAL);
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
// Disable alpha blending
|
// Disable alpha blending
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
// Render the geometry
|
// Render the geometry
|
||||||
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_GBUFFER);
|
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_GBUFFER);
|
||||||
|
|
||||||
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT));
|
||||||
|
|
||||||
// Enable additive blending
|
// Enable additive blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
// Set source to buffers from pass 1
|
// Set source to buffers from pass 1
|
||||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||||
glActiveTexture(GL_TEXTURE6);
|
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||||
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
||||||
glActiveTexture(GL_TEXTURE7);
|
GLDEBUG(glActiveTexture(GL_TEXTURE7));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||||
|
|
||||||
|
|
||||||
// Render the geometry
|
// Render the geometry
|
||||||
@@ -247,66 +249,66 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
|
|
||||||
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
|
|
||||||
// Disable alpha blending
|
// Disable alpha blending
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT));
|
||||||
|
|
||||||
// Set source to buffers from pass 2
|
// Set source to buffers from pass 2
|
||||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||||
glActiveTexture(GL_TEXTURE6);
|
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||||
glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture));
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
glEnable(GL_CULL_FACE);
|
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LEQUAL);
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
// Enable z-buffer write
|
// Enable z-buffer write
|
||||||
glDepthMask(GL_TRUE);
|
GLDEBUG(glDepthMask(GL_TRUE));
|
||||||
|
|
||||||
// Render the geometry
|
// Render the geometry
|
||||||
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_OPAQUE);
|
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_OPAQUE);
|
||||||
|
|
||||||
// Deactivate source buffer texture units
|
// Deactivate source buffer texture units
|
||||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||||
glActiveTexture(GL_TEXTURE6);
|
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
||||||
glActiveTexture(GL_TEXTURE7);
|
GLDEBUG(glActiveTexture(GL_TEXTURE7));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
} else {
|
} else {
|
||||||
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
|
|
||||||
// Disable alpha blending
|
// Disable alpha blending
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
glEnable(GL_CULL_FACE);
|
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Enable z-buffer write
|
// Enable z-buffer write
|
||||||
glDepthMask(GL_TRUE);
|
GLDEBUG(glDepthMask(GL_TRUE));
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LEQUAL);
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -319,23 +321,23 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
|
|
||||||
// Disable backface culling
|
// Disable backface culling
|
||||||
glDisable(GL_CULL_FACE);
|
GLDEBUG(glDisable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LEQUAL);
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
// Enable alpha blending
|
// Enable alpha blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
GLDEBUG(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||||
|
|
||||||
// Render all transparent geometry
|
// Render all transparent geometry
|
||||||
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||||
@@ -344,22 +346,22 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
// ----====---- Flares ----====----
|
// ----====---- Flares ----====----
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
|
|
||||||
// Disable backface culling
|
// Disable backface culling
|
||||||
glDisable(GL_CULL_FACE);
|
GLDEBUG(glDisable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
// Disable z-buffer test
|
// Disable z-buffer test
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
// Enable additive blending
|
// Enable additive blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
|
|
||||||
// Render all flares
|
// Render all flares
|
||||||
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FLARES);
|
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FLARES);
|
||||||
@@ -368,13 +370,13 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
|
|
||||||
if(bShowOctree) {
|
if(bShowOctree) {
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
glEnable(GL_CULL_FACE);
|
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||||
|
|
||||||
|
|
||||||
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("visualize_overlay", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("visualize_overlay", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||||
@@ -398,9 +400,8 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
-1.0, 1.0,-1.0
|
-1.0, 1.0,-1.0
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
|
||||||
|
|
||||||
for(std::set<KRAABB>::iterator itr=m_visibleBounds.begin(); itr != m_visibleBounds.end(); itr++) {
|
for(std::set<KRAABB>::iterator itr=m_visibleBounds.begin(); itr != m_visibleBounds.end(); itr++) {
|
||||||
KRMat4 matModel = KRMat4();
|
KRMat4 matModel = KRMat4();
|
||||||
@@ -409,7 +410,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
||||||
|
|
||||||
pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 14);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,53 +419,53 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
// fprintf(stderr, "visible bounds: %i\n", (int)m_visibleBounds.size());
|
// fprintf(stderr, "visible bounds: %i\n", (int)m_visibleBounds.size());
|
||||||
|
|
||||||
// Re-enable z-buffer write
|
// Re-enable z-buffer write
|
||||||
glDepthMask(GL_TRUE);
|
GLDEBUG(glDepthMask(GL_TRUE));
|
||||||
|
|
||||||
|
|
||||||
//fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRCamera::createBuffers() {
|
void KRCamera::createBuffers() {
|
||||||
// ===== Create offscreen compositing framebuffer object =====
|
// ===== Create offscreen compositing framebuffer object =====
|
||||||
glGenFramebuffers(1, &compositeFramebuffer);
|
GLDEBUG(glGenFramebuffers(1, &compositeFramebuffer));
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
|
||||||
|
|
||||||
// ----- Create texture color buffer for compositeFramebuffer -----
|
// ----- Create texture color buffer for compositeFramebuffer -----
|
||||||
glGenTextures(1, &compositeColorTexture);
|
GLDEBUG(glGenTextures(1, &compositeColorTexture));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, compositeColorTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, compositeColorTexture, 0));
|
||||||
|
|
||||||
// ----- Create Depth Texture for compositeFramebuffer -----
|
// ----- Create Depth Texture for compositeFramebuffer -----
|
||||||
glGenTextures(1, &compositeDepthTexture);
|
GLDEBUG(glGenTextures(1, &compositeDepthTexture));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
//GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
|
||||||
//glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, backingWidth, backingHeight);
|
//GLDEBUG(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, backingWidth, backingHeight));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
|
||||||
|
|
||||||
// ===== Create offscreen compositing framebuffer object =====
|
// ===== Create offscreen compositing framebuffer object =====
|
||||||
glGenFramebuffers(1, &lightAccumulationBuffer);
|
GLDEBUG(glGenFramebuffers(1, &lightAccumulationBuffer));
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer));
|
||||||
|
|
||||||
// ----- Create texture color buffer for compositeFramebuffer -----
|
// ----- Create texture color buffer for compositeFramebuffer -----
|
||||||
glGenTextures(1, &lightAccumulationTexture);
|
GLDEBUG(glGenTextures(1, &lightAccumulationTexture));
|
||||||
glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lightAccumulationTexture, 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lightAccumulationTexture, 0));
|
||||||
|
|
||||||
allocateShadowBuffers();
|
allocateShadowBuffers();
|
||||||
loadShaders();
|
loadShaders();
|
||||||
@@ -474,12 +475,12 @@ void KRCamera::allocateShadowBuffers() {
|
|||||||
// First deallocate buffers no longer needed
|
// First deallocate buffers no longer needed
|
||||||
for(int iShadow = m_cShadowBuffers; iShadow < KRENGINE_MAX_SHADOW_BUFFERS; iShadow++) {
|
for(int iShadow = m_cShadowBuffers; iShadow < KRENGINE_MAX_SHADOW_BUFFERS; iShadow++) {
|
||||||
if (shadowDepthTexture[iShadow]) {
|
if (shadowDepthTexture[iShadow]) {
|
||||||
glDeleteTextures(1, shadowDepthTexture + iShadow);
|
GLDEBUG(glDeleteTextures(1, shadowDepthTexture + iShadow));
|
||||||
shadowDepthTexture[iShadow] = 0;
|
shadowDepthTexture[iShadow] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shadowFramebuffer[iShadow]) {
|
if (shadowFramebuffer[iShadow]) {
|
||||||
glDeleteFramebuffers(1, shadowFramebuffer + iShadow);
|
GLDEBUG(glDeleteFramebuffers(1, shadowFramebuffer + iShadow));
|
||||||
shadowFramebuffer[iShadow] = 0;
|
shadowFramebuffer[iShadow] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,21 +490,21 @@ void KRCamera::allocateShadowBuffers() {
|
|||||||
if(!shadowDepthTexture[iShadow]) {
|
if(!shadowDepthTexture[iShadow]) {
|
||||||
shadowValid[iShadow] = false;
|
shadowValid[iShadow] = false;
|
||||||
|
|
||||||
glGenFramebuffers(1, shadowFramebuffer + iShadow);
|
GLDEBUG(glGenFramebuffers(1, shadowFramebuffer + iShadow));
|
||||||
glGenTextures(1, shadowDepthTexture + iShadow);
|
GLDEBUG(glGenTextures(1, shadowDepthTexture + iShadow));
|
||||||
// ===== Create offscreen shadow framebuffer object =====
|
// ===== Create offscreen shadow framebuffer object =====
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer[iShadow]);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer[iShadow]));
|
||||||
|
|
||||||
// ----- Create Depth Texture for shadowFramebuffer -----
|
// ----- Create Depth Texture for shadowFramebuffer -----
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]);
|
GLDEBUG( glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowDepthTexture[iShadow], 0);
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowDepthTexture[iShadow], 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,27 +515,27 @@ void KRCamera::destroyBuffers()
|
|||||||
allocateShadowBuffers();
|
allocateShadowBuffers();
|
||||||
|
|
||||||
if (compositeDepthTexture) {
|
if (compositeDepthTexture) {
|
||||||
glDeleteTextures(1, &compositeDepthTexture);
|
GLDEBUG(glDeleteTextures(1, &compositeDepthTexture));
|
||||||
compositeDepthTexture = 0;
|
compositeDepthTexture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compositeColorTexture) {
|
if (compositeColorTexture) {
|
||||||
glDeleteTextures(1, &compositeColorTexture);
|
GLDEBUG(glDeleteTextures(1, &compositeColorTexture));
|
||||||
compositeColorTexture = 0;
|
compositeColorTexture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lightAccumulationTexture) {
|
if (lightAccumulationTexture) {
|
||||||
glDeleteTextures(1, &lightAccumulationTexture);
|
GLDEBUG(glDeleteTextures(1, &lightAccumulationTexture));
|
||||||
lightAccumulationTexture = 0;
|
lightAccumulationTexture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compositeFramebuffer) {
|
if (compositeFramebuffer) {
|
||||||
glDeleteFramebuffers(1, &compositeFramebuffer);
|
GLDEBUG(glDeleteFramebuffers(1, &compositeFramebuffer));
|
||||||
compositeFramebuffer = 0;
|
compositeFramebuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lightAccumulationBuffer) {
|
if (lightAccumulationBuffer) {
|
||||||
glDeleteFramebuffers(1, &lightAccumulationBuffer);
|
GLDEBUG(glDeleteFramebuffers(1, &lightAccumulationBuffer));
|
||||||
lightAccumulationBuffer = 0;
|
lightAccumulationBuffer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,27 +544,27 @@ void KRCamera::destroyBuffers()
|
|||||||
void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
||||||
{
|
{
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer[iShadow]);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer[iShadow]));
|
||||||
glClearDepthf(1.0f);
|
GLDEBUG(glClearDepthf(1.0f));
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
GLDEBUG(glClear(GL_DEPTH_BUFFER_BIT));
|
||||||
|
|
||||||
//glViewport(1, 1, 2046, 2046);
|
//glViewport(1, 1, 2046, 2046);
|
||||||
|
|
||||||
glDisable(GL_DITHER);
|
GLDEBUG(glDisable(GL_DITHER));
|
||||||
|
|
||||||
glCullFace(GL_BACK); // Enable frontface culling, which eliminates some self-cast shadow artifacts
|
GLDEBUG(glCullFace(GL_BACK)); // Enable frontface culling, which eliminates some self-cast shadow artifacts
|
||||||
glEnable(GL_CULL_FACE);
|
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LESS);
|
GLDEBUG(glDepthFunc(GL_LESS));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
// Disable alpha blending as we are using alpha channel for packed depth info
|
// Disable alpha blending as we are using alpha channel for packed depth info
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
// Use shader program
|
// Use shader program
|
||||||
glUseProgram(m_shadowShaderProgram);
|
GLDEBUG(glUseProgram(m_shadowShaderProgram));
|
||||||
|
|
||||||
// Sets the diffuseTexture variable to the first texture unit
|
// Sets the diffuseTexture variable to the first texture unit
|
||||||
/*
|
/*
|
||||||
@@ -582,7 +583,7 @@ void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
|||||||
|
|
||||||
|
|
||||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||||
glUniformMatrix4fv(m_shadowUniforms[KRENGINE_UNIFORM_SHADOWMVP1], 1, GL_FALSE, shadowmvpmatrix[iShadow].getPointer());
|
GLDEBUG(glUniformMatrix4fv(m_shadowUniforms[KRENGINE_UNIFORM_SHADOWMVP1], 1, GL_FALSE, shadowmvpmatrix[iShadow].getPointer()));
|
||||||
|
|
||||||
|
|
||||||
// Calculate the bounding volume of the light map
|
// Calculate the bounding volume of the light map
|
||||||
@@ -608,7 +609,7 @@ void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
|||||||
KRBoundingVolume shadowVolume = KRBoundingVolume(vertices);
|
KRBoundingVolume shadowVolume = KRBoundingVolume(vertices);
|
||||||
scene.render(this, m_shadowVisibleBounds[iShadow], m_pContext, shadowVolume, shadowmvpmatrix[iShadow], cameraPosition, lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers, KRNode::RENDER_PASS_SHADOWMAP);
|
scene.render(this, m_shadowVisibleBounds[iShadow], m_pContext, shadowVolume, shadowmvpmatrix[iShadow], cameraPosition, lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers, KRNode::RENDER_PASS_SHADOWMAP);
|
||||||
scene.getOcclusionQueryResults(m_shadowVisibleBounds[iShadow]);
|
scene.getOcclusionQueryResults(m_shadowVisibleBounds[iShadow]);
|
||||||
glViewport(0, 0, backingWidth, backingHeight);
|
GLDEBUG(glViewport(0, 0, backingWidth, backingHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -616,17 +617,17 @@ bool KRCamera::ValidateProgram(GLuint prog)
|
|||||||
{
|
{
|
||||||
GLint logLength, status;
|
GLint logLength, status;
|
||||||
|
|
||||||
glValidateProgram(prog);
|
GLDEBUG(glValidateProgram(prog));
|
||||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(prog, logLength, &logLength, log);
|
GLDEBUG(glGetProgramInfoLog(prog, logLength, &logLength, log));
|
||||||
fprintf(stderr, "Program validate log:\n%s", log);
|
fprintf(stderr, "Program validate log:\n%s", log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
|
GLDEBUG(glGetProgramiv(prog, GL_VALIDATE_STATUS, &status));
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -636,10 +637,10 @@ bool KRCamera::ValidateProgram(GLuint prog)
|
|||||||
void KRCamera::renderPost()
|
void KRCamera::renderPost()
|
||||||
{
|
{
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 1); // renderFramebuffer
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, 1)); // renderFramebuffer
|
||||||
|
|
||||||
// Disable alpha blending
|
// Disable alpha blending
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
static const GLfloat squareVertices[] = {
|
static const GLfloat squareVertices[] = {
|
||||||
-1.0f, -1.0f,
|
-1.0f, -1.0f,
|
||||||
@@ -672,71 +673,71 @@ void KRCamera::renderPost()
|
|||||||
1.0f, 1.0f,
|
1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
bindPostShader();
|
bindPostShader();
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||||
//glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
|
//GLDEBUG(glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture));
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||||
|
|
||||||
// Update attribute values.
|
// Update attribute values.
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
|
|
||||||
|
|
||||||
if(bShowShadowBuffer) {
|
if(bShowShadowBuffer) {
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
glUseProgram(m_postShaderProgram);
|
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||||
|
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||||
|
|
||||||
// Update attribute values.
|
// Update attribute values.
|
||||||
|
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, textureVertices));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||||
|
|
||||||
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
||||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVerticesShadow[iShadow]);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVerticesShadow[iShadow]));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -745,17 +746,17 @@ void KRCamera::renderPost()
|
|||||||
if(*szText) {
|
if(*szText) {
|
||||||
KRTexture *pFontTexture = m_pContext->getTextureManager()->getTexture("font");
|
KRTexture *pFontTexture = m_pContext->getTextureManager()->getTexture("font");
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
glUseProgram(m_postShaderProgram);
|
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(1, pFontTexture);
|
m_pContext->getTextureManager()->selectTexture(1, pFontTexture);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0));
|
||||||
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);
|
GLDEBUG(glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1));
|
||||||
|
|
||||||
const char *pChar = szText;
|
const char *pChar = szText;
|
||||||
int iPos=0;
|
int iPos=0;
|
||||||
@@ -780,18 +781,18 @@ void KRCamera::renderPost()
|
|||||||
dTexScale * iCol + dTexScale, dTexScale * iRow
|
dTexScale * iCol + dTexScale, dTexScale * iRow
|
||||||
};
|
};
|
||||||
|
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, charTexCoords);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, charTexCoords));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||||
|
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, charVertices);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, charVertices));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
|
|
||||||
iPos++;
|
iPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||||
}
|
}
|
||||||
@@ -820,13 +821,13 @@ void KRCamera::bindPostShader()
|
|||||||
stream << "\n";
|
stream << "\n";
|
||||||
LoadShader(*m_pContext, "PostShader", &m_postShaderProgram, stream.str());
|
LoadShader(*m_pContext, "PostShader", &m_postShaderProgram, stream.str());
|
||||||
}
|
}
|
||||||
glUseProgram(m_postShaderProgram);
|
GLDEBUG(glUseProgram(m_postShaderProgram));
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRCamera::invalidatePostShader()
|
void KRCamera::invalidatePostShader()
|
||||||
{
|
{
|
||||||
if(m_postShaderProgram) {
|
if(m_postShaderProgram) {
|
||||||
glDeleteProgram(m_postShaderProgram);
|
GLDEBUG(glDeleteProgram(m_postShaderProgram));
|
||||||
m_postShaderProgram = 0;
|
m_postShaderProgram = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -843,7 +844,7 @@ bool KRCamera::LoadShader(KRContext &context, const std::string &name, GLuint *p
|
|||||||
GLuint vertexShader, fragShader;
|
GLuint vertexShader, fragShader;
|
||||||
|
|
||||||
// Create shader program.
|
// Create shader program.
|
||||||
*programPointer = glCreateProgram();
|
GLDEBUG(*programPointer = glCreateProgram());
|
||||||
|
|
||||||
// Create and compile vertex shader.
|
// Create and compile vertex shader.
|
||||||
|
|
||||||
@@ -859,33 +860,33 @@ bool KRCamera::LoadShader(KRContext &context, const std::string &name, GLuint *p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attach vertex shader to program.
|
// Attach vertex shader to program.
|
||||||
glAttachShader(*programPointer, vertexShader);
|
GLDEBUG(glAttachShader(*programPointer, vertexShader));
|
||||||
|
|
||||||
// Attach fragment shader to program.
|
// Attach fragment shader to program.
|
||||||
glAttachShader(*programPointer, fragShader);
|
GLDEBUG(glAttachShader(*programPointer, fragShader));
|
||||||
|
|
||||||
// Bind attribute locations.
|
// Bind attribute locations.
|
||||||
// This needs to be done prior to linking.
|
// This needs to be done prior to linking.
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
|
GLDEBUG(glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv"));
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "vertex_position");
|
GLDEBUG(glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "vertex_position"));
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_NORMAL, "vertex_normal");
|
GLDEBUG(glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_NORMAL, "vertex_normal"));
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TANGENT, "vertex_tangent");
|
GLDEBUG(glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TANGENT, "vertex_tangent"));
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "vertex_uv");
|
GLDEBUG(glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "vertex_uv"));
|
||||||
|
|
||||||
// Link program.
|
// Link program.
|
||||||
if(!LinkProgram(*programPointer)) {
|
if(!LinkProgram(*programPointer)) {
|
||||||
fprintf(stderr, "Failed to link program: %d", *programPointer);
|
fprintf(stderr, "Failed to link program: %d", *programPointer);
|
||||||
|
|
||||||
if (vertexShader) {
|
if (vertexShader) {
|
||||||
glDeleteShader(vertexShader);
|
GLDEBUG(glDeleteShader(vertexShader));
|
||||||
vertexShader = 0;
|
vertexShader = 0;
|
||||||
}
|
}
|
||||||
if (fragShader) {
|
if (fragShader) {
|
||||||
glDeleteShader(fragShader);
|
GLDEBUG(glDeleteShader(fragShader));
|
||||||
fragShader = 0;
|
fragShader = 0;
|
||||||
}
|
}
|
||||||
if (*programPointer) {
|
if (*programPointer) {
|
||||||
glDeleteProgram(*programPointer);
|
GLDEBUG(glDeleteProgram(*programPointer));
|
||||||
*programPointer = 0;
|
*programPointer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,11 +896,11 @@ bool KRCamera::LoadShader(KRContext &context, const std::string &name, GLuint *p
|
|||||||
// Release vertex and fragment shaders.
|
// Release vertex and fragment shaders.
|
||||||
if (vertexShader)
|
if (vertexShader)
|
||||||
{
|
{
|
||||||
glDeleteShader(vertexShader);
|
GLDEBUG(glDeleteShader(vertexShader));
|
||||||
}
|
}
|
||||||
if (fragShader)
|
if (fragShader)
|
||||||
{
|
{
|
||||||
glDeleteShader(fragShader);
|
GLDEBUG(glDeleteShader(fragShader));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -922,25 +923,25 @@ bool KRCamera::CompileShader(GLuint *shader, GLenum type, const std::string &sha
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*shader = glCreateShader(type);
|
GLDEBUG(*shader = glCreateShader(type));
|
||||||
glShaderSource(*shader, options.length() ? 2 : 1, source, NULL);
|
GLDEBUG(glShaderSource(*shader, options.length() ? 2 : 1, source, NULL));
|
||||||
glCompileShader(*shader);
|
GLDEBUG(glCompileShader(*shader));
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetShaderInfoLog(*shader, logLength, &logLength, log);
|
GLDEBUG(glGetShaderInfoLog(*shader, logLength, &logLength, log));
|
||||||
fprintf(stderr, "Shader compile log:\n%s", log);
|
fprintf(stderr, "Shader compile log:\n%s", log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
|
GLDEBUG(glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
glDeleteShader(*shader);
|
GLDEBUG(glDeleteShader(*shader));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -951,21 +952,21 @@ bool KRCamera::LinkProgram(GLuint prog)
|
|||||||
{
|
{
|
||||||
GLint status;
|
GLint status;
|
||||||
|
|
||||||
glLinkProgram(prog);
|
GLDEBUG(glLinkProgram(prog));
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(prog, logLength, &logLength, log);
|
GLDEBUG(glGetProgramInfoLog(prog, logLength, &logLength, log));
|
||||||
fprintf(stderr, "Program link log:\n%s", log);
|
fprintf(stderr, "Program link log:\n%s", log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glGetProgramiv(prog, GL_LINK_STATUS, &status);
|
GLDEBUG(glGetProgramiv(prog, GL_LINK_STATUS, &status));
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -110,4 +110,12 @@ void KRContext::loadResource(std::string path) {
|
|||||||
} else {
|
} else {
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRContext::rotateBuffers() {
|
||||||
|
//fprintf(stderr, "Rotating Buffers...\n");
|
||||||
|
GLDEBUG(glFinish());
|
||||||
|
|
||||||
|
m_pModelManager->rotateBuffers();
|
||||||
|
m_pTextureManager->rotateBuffers();
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,8 @@ public:
|
|||||||
|
|
||||||
KRCamera *createCamera(int width, int height);
|
KRCamera *createCamera(int width, int height);
|
||||||
|
|
||||||
|
void rotateBuffers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRBundleManager *m_pBundleManager;
|
KRBundleManager *m_pBundleManager;
|
||||||
KRSceneManager *m_pSceneManager;
|
KRSceneManager *m_pSceneManager;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#import "KRShader.h"
|
#import "KRShader.h"
|
||||||
#import "KRContext.h"
|
#import "KRContext.h"
|
||||||
#import "KRMat4.h"
|
#import "KRMat4.h"
|
||||||
|
#import "assert.h"
|
||||||
|
|
||||||
KRDirectionalLight::KRDirectionalLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
KRDirectionalLight::KRDirectionalLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
||||||
{
|
{
|
||||||
@@ -70,30 +71,30 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
|||||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||||
|
|
||||||
|
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE],
|
||||||
light_direction_view_space.x,
|
light_direction_view_space.x,
|
||||||
light_direction_view_space.y,
|
light_direction_view_space.y,
|
||||||
light_direction_view_space.z
|
light_direction_view_space.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||||
m_color.x,
|
m_color.x,
|
||||||
m_color.y,
|
m_color.y,
|
||||||
m_color.z
|
m_color.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform1f(
|
GLDEBUG(glUniform1f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||||
m_intensity / 100.0f
|
m_intensity / 100.0f
|
||||||
);
|
));
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
// Disable z-buffer test
|
// Disable z-buffer test
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
|
|
||||||
// Render a full screen quad
|
// Render a full screen quad
|
||||||
static const GLfloat squareVertices[] = {
|
static const GLfloat squareVertices[] = {
|
||||||
@@ -103,10 +104,9 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
|||||||
1.0f, 1.0f,
|
1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,3 +35,14 @@
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define GLDEBUG(x) \
|
||||||
|
x; \
|
||||||
|
{ \
|
||||||
|
GLenum e; \
|
||||||
|
while( (e=glGetError()) != GL_NO_ERROR) \
|
||||||
|
{ \
|
||||||
|
fprintf(stderr, "Error at line number %d, in file %s. glGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
@@ -35,8 +35,7 @@
|
|||||||
#import "KRMesh.h"
|
#import "KRMesh.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map) : KRNode(scene, instance_name) {
|
KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map) : KRNode(scene, instance_name) {
|
||||||
m_modelMatrix = modelMatrix;
|
|
||||||
m_lightMap = light_map;
|
m_lightMap = light_map;
|
||||||
m_pLightMap = NULL;
|
m_pLightMap = NULL;
|
||||||
m_pModel = NULL;
|
m_pModel = NULL;
|
||||||
@@ -61,6 +60,7 @@ tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent)
|
|||||||
|
|
||||||
|
|
||||||
KRMat4 &KRInstance::getModelMatrix() {
|
KRMat4 &KRInstance::getModelMatrix() {
|
||||||
|
calcModelMatrix();
|
||||||
return m_modelMatrix;
|
return m_modelMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +76,8 @@ void KRInstance::loadModel() {
|
|||||||
|
|
||||||
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||||
|
|
||||||
|
calcModelMatrix();
|
||||||
|
|
||||||
KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||||
|
|
||||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && (renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT || this->hasTransparency()) && renderPass != KRNode::RENDER_PASS_FLARES) {
|
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && (renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT || this->hasTransparency()) && renderPass != KRNode::RENDER_PASS_FLARES) {
|
||||||
@@ -119,6 +121,8 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
|
|||||||
|
|
||||||
void KRInstance::calcExtents(KRContext *pContext)
|
void KRInstance::calcExtents(KRContext *pContext)
|
||||||
{
|
{
|
||||||
|
calcModelMatrix();
|
||||||
|
|
||||||
KRNode::calcExtents(pContext);
|
KRNode::calcExtents(pContext);
|
||||||
loadModel();
|
loadModel();
|
||||||
KRMesh *pMesh = m_pModel->getMesh();
|
KRMesh *pMesh = m_pModel->getMesh();
|
||||||
@@ -139,6 +143,7 @@ bool KRInstance::hasTransparency() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRAABB KRInstance::getBounds() {
|
KRAABB KRInstance::getBounds() {
|
||||||
|
calcModelMatrix();
|
||||||
loadModel();
|
loadModel();
|
||||||
|
|
||||||
KRMesh *pMesh = m_pModel->getMesh();
|
KRMesh *pMesh = m_pModel->getMesh();
|
||||||
@@ -182,3 +187,13 @@ KRAABB KRInstance::getBounds() {
|
|||||||
|
|
||||||
return KRAABB(min, max);
|
return KRAABB(min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRInstance::calcModelMatrix()
|
||||||
|
{
|
||||||
|
m_modelMatrix = KRMat4();
|
||||||
|
// m_modelMatrix.scale(m_localScale);
|
||||||
|
// m_modelMatrix.rotate(m_localRotation.x, X_AXIS);
|
||||||
|
// m_modelMatrix.rotate(m_localRotation.y, Y_AXIS);
|
||||||
|
// m_modelMatrix.rotate(m_localRotation.z, Z_AXIS);
|
||||||
|
// m_modelMatrix.translate(m_localTranslation);
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class KRBoundingVolume;
|
|||||||
class KRInstance : public KRNode {
|
class KRInstance : public KRNode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KRInstance(KRScene &scene, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map);
|
KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map);
|
||||||
virtual ~KRInstance();
|
virtual ~KRInstance();
|
||||||
|
|
||||||
virtual std::string getElementName();
|
virtual std::string getElementName();
|
||||||
@@ -72,6 +72,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
virtual KRAABB getBounds();
|
virtual KRAABB getBounds();
|
||||||
|
void calcModelMatrix();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRModel *m_pModel;
|
KRModel *m_pModel;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#import "KRBoundingVolume.h"
|
#import "KRBoundingVolume.h"
|
||||||
#import "KRShaderManager.h"
|
#import "KRShaderManager.h"
|
||||||
#import "KRShader.h"
|
#import "KRShader.h"
|
||||||
|
#import "assert.h"
|
||||||
|
|
||||||
KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
|
KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||||
{
|
{
|
||||||
@@ -155,15 +156,14 @@ void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
|||||||
1.0f, 1.0f,
|
1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, 0, squareVertices);
|
|
||||||
|
|
||||||
glUniform1f(
|
GLDEBUG(glUniform1f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||||
m_flareSize
|
m_flareSize
|
||||||
);
|
));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -179,6 +179,9 @@ void KRMaterial::setReflection(const KRVector3 &c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setTransparency(GLfloat a) {
|
void KRMaterial::setTransparency(GLfloat a) {
|
||||||
|
if(a != 1.0f && m_alpha_mode == KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE) {
|
||||||
|
setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
|
||||||
|
}
|
||||||
m_tr = a;
|
m_tr = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +237,7 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
|
|
||||||
strcpy(szPrevShaderKey, pShader->getKey());
|
strcpy(szPrevShaderKey, pShader->getKey());
|
||||||
}
|
}
|
||||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns );
|
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns ));
|
||||||
|
|
||||||
bool bSameAmbient = false;
|
bool bSameAmbient = false;
|
||||||
bool bSameDiffuse = false;
|
bool bSameDiffuse = false;
|
||||||
@@ -269,127 +272,127 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!bSameAmbient) {
|
if(!bSameAmbient) {
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT],
|
||||||
m_ambientColor.x + pCamera->dAmbientR,
|
m_ambientColor.x + pCamera->dAmbientR,
|
||||||
m_ambientColor.y + pCamera->dAmbientG,
|
m_ambientColor.y + pCamera->dAmbientG,
|
||||||
m_ambientColor.z + pCamera->dAmbientB
|
m_ambientColor.z + pCamera->dAmbientB
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bSameDiffuse) {
|
if(!bSameDiffuse) {
|
||||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||||
// We pre-multiply the light color with the material color in the forward renderer
|
// We pre-multiply the light color with the material color in the forward renderer
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||||
m_diffuseColor.x * pCamera->dSunR,
|
m_diffuseColor.x * pCamera->dSunR,
|
||||||
m_diffuseColor.y * pCamera->dSunG,
|
m_diffuseColor.y * pCamera->dSunG,
|
||||||
m_diffuseColor.z * pCamera->dSunB
|
m_diffuseColor.z * pCamera->dSunB
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
|
||||||
m_diffuseColor.x,
|
m_diffuseColor.x,
|
||||||
m_diffuseColor.y,
|
m_diffuseColor.y,
|
||||||
m_diffuseColor.z
|
m_diffuseColor.z
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bSameSpecular) {
|
if(!bSameSpecular) {
|
||||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||||
// We pre-multiply the light color with the material color in the forward renderer
|
// We pre-multiply the light color with the material color in the forward renderer
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||||
m_specularColor.x * pCamera->dSunR,
|
m_specularColor.x * pCamera->dSunR,
|
||||||
m_specularColor.y * pCamera->dSunG,
|
m_specularColor.y * pCamera->dSunG,
|
||||||
m_specularColor.z * pCamera->dSunB
|
m_specularColor.z * pCamera->dSunB
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
|
||||||
m_specularColor.x,
|
m_specularColor.x,
|
||||||
m_specularColor.y,
|
m_specularColor.y,
|
||||||
m_specularColor.z
|
m_specularColor.z
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bSameReflection) {
|
if(!bSameReflection) {
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTION],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTION],
|
||||||
m_reflectionColor.x,
|
m_reflectionColor.x,
|
||||||
m_reflectionColor.y,
|
m_reflectionColor.y,
|
||||||
m_reflectionColor.z
|
m_reflectionColor.z
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bDiffuseMap && !bSameDiffuseScale && m_diffuseMapScale != default_scale) {
|
if(bDiffuseMap && !bSameDiffuseScale && m_diffuseMapScale != default_scale) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE],
|
||||||
m_diffuseMapScale.x,
|
m_diffuseMapScale.x,
|
||||||
m_diffuseMapScale.y
|
m_diffuseMapScale.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bSpecMap && !bSameSpecularScale && m_specularMapScale != default_scale) {
|
if(bSpecMap && !bSameSpecularScale && m_specularMapScale != default_scale) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE],
|
||||||
m_specularMapScale.x,
|
m_specularMapScale.x,
|
||||||
m_specularMapScale.y
|
m_specularMapScale.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bReflectionMap && !bSameReflectionScale && m_reflectionMapScale != default_scale) {
|
if(bReflectionMap && !bSameReflectionScale && m_reflectionMapScale != default_scale) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE],
|
||||||
m_reflectionMapScale.x,
|
m_reflectionMapScale.x,
|
||||||
m_reflectionMapScale.y
|
m_reflectionMapScale.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bNormalMap && !bSameNormalScale && m_normalMapScale != default_scale) {
|
if(bNormalMap && !bSameNormalScale && m_normalMapScale != default_scale) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_SCALE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_SCALE],
|
||||||
m_normalMapScale.x,
|
m_normalMapScale.x,
|
||||||
m_normalMapScale.y
|
m_normalMapScale.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bDiffuseMap && !bSameDiffuseOffset && m_diffuseMapOffset != default_offset) {
|
if(bDiffuseMap && !bSameDiffuseOffset && m_diffuseMapOffset != default_offset) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET],
|
||||||
m_diffuseMapOffset.x,
|
m_diffuseMapOffset.x,
|
||||||
m_diffuseMapOffset.y
|
m_diffuseMapOffset.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bSpecMap && !bSameSpecularOffset && m_specularMapOffset != default_offset) {
|
if(bSpecMap && !bSameSpecularOffset && m_specularMapOffset != default_offset) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET],
|
||||||
m_specularMapOffset.x,
|
m_specularMapOffset.x,
|
||||||
m_specularMapOffset.y
|
m_specularMapOffset.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bReflectionMap && !bSameReflectionOffset && m_reflectionMapOffset != default_offset) {
|
if(bReflectionMap && !bSameReflectionOffset && m_reflectionMapOffset != default_offset) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET],
|
||||||
m_reflectionMapOffset.x,
|
m_reflectionMapOffset.x,
|
||||||
m_reflectionMapOffset.y
|
m_reflectionMapOffset.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bNormalMap && !bSameNormalOffset && m_normalMapOffset != default_offset) {
|
if(bNormalMap && !bSameNormalOffset && m_normalMapOffset != default_offset) {
|
||||||
glUniform2f(
|
GLDEBUG(glUniform2f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET],
|
||||||
m_normalMapOffset.x,
|
m_normalMapOffset.x,
|
||||||
m_normalMapOffset.y
|
m_normalMapOffset.y
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
|
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr));
|
||||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY], m_reflectionFactor);
|
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY], m_reflectionFactor));
|
||||||
|
|
||||||
if(bDiffuseMap) {
|
if(bDiffuseMap) {
|
||||||
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap);
|
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char m_szName[64];
|
char m_szName[256];
|
||||||
|
|
||||||
KRTexture *m_pAmbientMap; // mtl map_Ka value
|
KRTexture *m_pAmbientMap; // mtl map_Ka value
|
||||||
KRTexture *m_pDiffuseMap; // mtl map_Kd value
|
KRTexture *m_pDiffuseMap; // mtl map_Kd value
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ KRMaterial *KRMaterialManager::getMaterial(const char *szName) {
|
|||||||
}
|
}
|
||||||
bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
||||||
KRMaterial *pMaterial = NULL;
|
KRMaterial *pMaterial = NULL;
|
||||||
char szSymbol[16][64];
|
char szSymbol[16][256];
|
||||||
|
|
||||||
|
|
||||||
char *pScan = (char *)data->getStart();
|
char *pScan = (char *)data->getStart();
|
||||||
|
|||||||
@@ -95,7 +95,10 @@ vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
|
|||||||
Submesh *pSubmesh = new Submesh();
|
Submesh *pSubmesh = new Submesh();
|
||||||
pSubmesh->start_vertex = pPackMaterial->start_vertex;
|
pSubmesh->start_vertex = pPackMaterial->start_vertex;
|
||||||
pSubmesh->vertex_count = pPackMaterial->vertex_count;
|
pSubmesh->vertex_count = pPackMaterial->vertex_count;
|
||||||
strcpy(pSubmesh->szMaterialName, pPackMaterial->szName);
|
|
||||||
|
strncpy(pSubmesh->szMaterialName, pPackMaterial->szName, 256);
|
||||||
|
pSubmesh->szMaterialName[63] = '\0';
|
||||||
|
//fprintf(stderr, "Submesh material: \"%s\"\n", pSubmesh->szMaterialName);
|
||||||
m_submeshes.push_back(pSubmesh);
|
m_submeshes.push_back(pSubmesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,20 +107,6 @@ vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
|
|||||||
|
|
||||||
void KRMesh::renderSubmesh(int iSubmesh, int &iPrevBuffer) {
|
void KRMesh::renderSubmesh(int iSubmesh, int &iPrevBuffer) {
|
||||||
VertexData *pVertexData = getVertexData();
|
VertexData *pVertexData = getVertexData();
|
||||||
//
|
|
||||||
// if(m_cBuffers == 0) {
|
|
||||||
// pack_header *pHeader = (pack_header *)m_pData->getStart();
|
|
||||||
// m_cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
|
|
||||||
// m_pBuffers = new GLuint[m_cBuffers];
|
|
||||||
// glGenBuffers(m_cBuffers, m_pBuffers);
|
|
||||||
// for(GLsizei iBuffer=0; iBuffer < m_cBuffers; iBuffer++) {
|
|
||||||
// GLsizei cVertexes = iBuffer < m_cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
|
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * cVertexes, pVertexData + iBuffer * MAX_VBO_SIZE, GL_STATIC_DRAW);
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
pack_header *pHeader = (pack_header *)m_pData->getStart();
|
pack_header *pHeader = (pack_header *)m_pData->getStart();
|
||||||
int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
|
int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
|
||||||
@@ -130,38 +119,47 @@ void KRMesh::renderSubmesh(int iSubmesh, int &iPrevBuffer) {
|
|||||||
iVertex = iVertex % MAX_VBO_SIZE;
|
iVertex = iVertex % MAX_VBO_SIZE;
|
||||||
int cVertexes = pSubmesh->vertex_count;
|
int cVertexes = pSubmesh->vertex_count;
|
||||||
while(cVertexes > 0) {
|
while(cVertexes > 0) {
|
||||||
|
GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
||||||
if(iPrevBuffer != iBuffer) {
|
if(iPrevBuffer != iBuffer) {
|
||||||
GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
assert(pVertexData + iBuffer * MAX_VBO_SIZE >= m_pData->getStart());
|
||||||
m_pContext->getModelManager()->bindVBO(pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes);
|
int vertex_size = sizeof(VertexData) ;
|
||||||
|
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) {
|
if(iPrevBuffer == -1) {
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int data_size = sizeof(VertexData);
|
int data_size = sizeof(VertexData);
|
||||||
|
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(0));
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(0)));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D)));
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D))));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 2));
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 2)));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3));
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3)));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3 + sizeof(TexCoord)));
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3 + sizeof(TexCoord))));
|
||||||
}
|
}
|
||||||
iPrevBuffer = iBuffer;
|
iPrevBuffer = iBuffer;
|
||||||
|
|
||||||
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
|
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
|
||||||
glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex));
|
assert(iVertex + (MAX_VBO_SIZE - iVertex) <= cBufferVertexes);
|
||||||
|
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex)));
|
||||||
|
|
||||||
cVertexes -= (MAX_VBO_SIZE - iVertex);
|
cVertexes -= (MAX_VBO_SIZE - iVertex);
|
||||||
iVertex = 0;
|
iVertex = 0;
|
||||||
iBuffer++;
|
iBuffer++;
|
||||||
} else {
|
} else {
|
||||||
glDrawArrays(GL_TRIANGLES, iVertex, cVertexes);
|
assert(iVertex + cVertexes <= cBufferVertexes);
|
||||||
|
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, cVertexes));
|
||||||
cVertexes = 0;
|
cVertexes = 0;
|
||||||
}
|
}
|
||||||
|
m_pContext->getModelManager()->unbindVBO();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +191,7 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
|
|||||||
pack_material *pPackMaterial = pPackMaterials + iMaterial;
|
pack_material *pPackMaterial = pPackMaterials + iMaterial;
|
||||||
pPackMaterial->start_vertex = submesh_starts[iMaterial];
|
pPackMaterial->start_vertex = submesh_starts[iMaterial];
|
||||||
pPackMaterial->vertex_count = submesh_lengths[iMaterial];
|
pPackMaterial->vertex_count = submesh_lengths[iMaterial];
|
||||||
strcpy(pPackMaterial->szName, material_names[iMaterial].c_str());
|
strncpy(pPackMaterial->szName, material_names[iMaterial].c_str(), 63);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bFirstVertex = true;
|
bool bFirstVertex = true;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
GLint start_vertex;
|
GLint start_vertex;
|
||||||
GLsizei vertex_count;
|
GLsizei vertex_count;
|
||||||
char szMaterialName[64];
|
char szMaterialName[256];
|
||||||
} Submesh;
|
} Submesh;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -108,7 +108,7 @@ public:
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t start_vertex;
|
int32_t start_vertex;
|
||||||
int32_t vertex_count;
|
int32_t vertex_count;
|
||||||
char szName[64];
|
char szName[256];
|
||||||
} pack_material;
|
} pack_material;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ KRModel::~KRModel() {
|
|||||||
|
|
||||||
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||||
|
|
||||||
// fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
||||||
|
|
||||||
if(renderPass != KRNode::RENDER_PASS_FLARES) {
|
if(renderPass != KRNode::RENDER_PASS_FLARES) {
|
||||||
|
|
||||||
@@ -74,7 +74,8 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
|||||||
vector<KRMesh::Submesh *> submeshes = m_pMesh->getSubmeshes();
|
vector<KRMesh::Submesh *> submeshes = m_pMesh->getSubmeshes();
|
||||||
|
|
||||||
for(std::vector<KRMesh::Submesh *>::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) {
|
for(std::vector<KRMesh::Submesh *>::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) {
|
||||||
KRMaterial *pMaterial = pContext->getMaterialManager()->getMaterial((*itr)->szMaterialName);
|
const char *szMaterialName = (*itr)->szMaterialName;
|
||||||
|
KRMaterial *pMaterial = pContext->getMaterialManager()->getMaterial(szMaterialName);
|
||||||
m_materials.push_back(pMaterial);
|
m_materials.push_back(pMaterial);
|
||||||
if(pMaterial) {
|
if(pMaterial) {
|
||||||
m_uniqueMaterials.insert(pMaterial);
|
m_uniqueMaterials.insert(pMaterial);
|
||||||
@@ -128,11 +129,11 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
|||||||
break;
|
break;
|
||||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||||
// Render back faces first
|
// Render back faces first
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
|
|
||||||
// Render front faces second
|
// Render front faces second
|
||||||
glCullFace(GL_BACK);
|
GLDEBUG(glCullFace(GL_BACK));
|
||||||
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -143,7 +144,6 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "KRModelManager.h"
|
#include "KRModelManager.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#import "KRModel.h"
|
#import "KRModel.h"
|
||||||
|
|
||||||
@@ -53,7 +54,13 @@ KRModel *KRModelManager::loadModel(const char *szName, KRDataBlock *pData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRModel *KRModelManager::getModel(const char *szName) {
|
KRModel *KRModelManager::getModel(const char *szName) {
|
||||||
return m_models[szName];
|
std::map<std::string, KRModel *>::iterator itr_match = m_models.find(szName);
|
||||||
|
if(itr_match == m_models.end()) {
|
||||||
|
fprintf(stderr, "ERROR: Model not found: %s\n", szName);
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return itr_match->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRModel *KRModelManager::getFirstModel() {
|
KRModel *KRModelManager::getFirstModel() {
|
||||||
@@ -65,40 +72,71 @@ std::map<std::string, KRModel *> KRModelManager::getModels() {
|
|||||||
return m_models;
|
return m_models;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRModelManager::bindVBO(const GLvoid *data, GLsizeiptr size) {
|
void KRModelManager::unbindVBO() {
|
||||||
|
if(m_currentVBO.data != NULL) {
|
||||||
|
GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||||
|
m_currentVBO.size = 0;
|
||||||
|
m_currentVBO.data = NULL;
|
||||||
|
m_currentVBO.handle = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size) {
|
||||||
|
|
||||||
if(m_currentVBO.data != data || m_currentVBO.size != size) {
|
if(m_currentVBO.data != data || m_currentVBO.size != size) {
|
||||||
|
|
||||||
if(m_vbos.find(data) != m_vbos.end()) {
|
if(m_vbosActive.find(data) != m_vbosActive.end()) {
|
||||||
m_currentVBO = m_vbos[data];
|
m_currentVBO = m_vbosActive[data];
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
|
GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle));
|
||||||
|
} else if(m_vbosPool.find(data) != m_vbosPool.end()) {
|
||||||
|
m_currentVBO = m_vbosPool[data];
|
||||||
|
m_vbosPool.erase(data);
|
||||||
|
m_vbosActive[data] = m_currentVBO;
|
||||||
|
GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle));
|
||||||
} else {
|
} else {
|
||||||
m_vboMemUsed += size;
|
m_vboMemUsed += size;
|
||||||
|
|
||||||
while(m_vbos.size() >= KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRENGINE_MAX_VBO_MEM) {
|
while(m_vbosPool.size() + m_vbosActive.size() >= KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRENGINE_MAX_VBO_MEM) {
|
||||||
// TODO - This should maintain a max size limit for VBO's rather than a limit on the number of VBO's. As meshes are split to multiple small VBO's, this is not too bad, but still not optimial.
|
if(m_vbosPool.empty()) {
|
||||||
std::map<const GLvoid *, vbo_info_type>::iterator first_itr = m_vbos.begin();
|
m_pContext->rotateBuffers();
|
||||||
|
}
|
||||||
|
std::map<GLvoid *, vbo_info_type>::iterator first_itr = m_vbosPool.begin();
|
||||||
vbo_info_type firstVBO = first_itr->second;
|
vbo_info_type firstVBO = first_itr->second;
|
||||||
glDeleteBuffers(1, &firstVBO.handle);
|
GLDEBUG(glDeleteBuffers(1, &firstVBO.handle));
|
||||||
m_vboMemUsed -= firstVBO.size;
|
m_vboMemUsed -= firstVBO.size;
|
||||||
m_vbos.erase(first_itr);
|
m_vbosPool.erase(first_itr);
|
||||||
fprintf(stderr, "VBO Swapping...\n");
|
//fprintf(stderr, "VBO Swapping...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentVBO.handle = -1;
|
m_currentVBO.handle = -1;
|
||||||
glGenBuffers(1, &m_currentVBO.handle);
|
GLDEBUG(glGenBuffers(1, &m_currentVBO.handle));
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
|
||||||
|
GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle));
|
||||||
|
GLDEBUG(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
|
||||||
|
|
||||||
m_currentVBO.size = size;
|
m_currentVBO.size = size;
|
||||||
m_currentVBO.data = data;
|
m_currentVBO.data = data;
|
||||||
|
|
||||||
m_vbos[data] = m_currentVBO;
|
m_vbosActive[data] = m_currentVBO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
long KRModelManager::getMemUsed()
|
long KRModelManager::getMemUsed()
|
||||||
{
|
{
|
||||||
return m_vboMemUsed;
|
return m_vboMemUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRModelManager::rotateBuffers()
|
||||||
|
{
|
||||||
|
m_vbosPool.insert(m_vbosActive.begin(), m_vbosActive.end());
|
||||||
|
m_vbosActive.clear();
|
||||||
|
if(m_currentVBO.data != NULL) {
|
||||||
|
// Ensure that the currently active VBO does not get flushed to free memory
|
||||||
|
m_vbosPool.erase(m_currentVBO.data);
|
||||||
|
m_vbosActive[m_currentVBO.data] = m_currentVBO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#define KRMODELMANAGER_H
|
#define KRMODELMANAGER_H
|
||||||
|
|
||||||
#define KRENGINE_MAX_VBO_HANDLES 1000
|
#define KRENGINE_MAX_VBO_HANDLES 1000
|
||||||
#define KRENGINE_MAX_VBO_MEM 100000000
|
#define KRENGINE_MAX_VBO_MEM 50000000
|
||||||
|
|
||||||
#import "KREngine-common.h"
|
#import "KREngine-common.h"
|
||||||
#import "KRContextObject.h"
|
#import "KRContextObject.h"
|
||||||
@@ -51,6 +51,8 @@ public:
|
|||||||
KRModelManager(KRContext &context);
|
KRModelManager(KRContext &context);
|
||||||
virtual ~KRModelManager();
|
virtual ~KRModelManager();
|
||||||
|
|
||||||
|
void rotateBuffers();
|
||||||
|
|
||||||
KRModel *loadModel(const char *szName, KRDataBlock *pData);
|
KRModel *loadModel(const char *szName, KRDataBlock *pData);
|
||||||
KRModel *getModel(const char *szName);
|
KRModel *getModel(const char *szName);
|
||||||
KRModel *getFirstModel();
|
KRModel *getFirstModel();
|
||||||
@@ -59,7 +61,8 @@ public:
|
|||||||
std::map<std::string, KRModel *> getModels();
|
std::map<std::string, KRModel *> getModels();
|
||||||
|
|
||||||
|
|
||||||
void bindVBO(const GLvoid *data, GLsizeiptr size);
|
void bindVBO(GLvoid *data, GLsizeiptr size);
|
||||||
|
void unbindVBO();
|
||||||
long getMemUsed();
|
long getMemUsed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -68,14 +71,14 @@ private:
|
|||||||
typedef struct vbo_info {
|
typedef struct vbo_info {
|
||||||
GLuint handle;
|
GLuint handle;
|
||||||
GLsizeiptr size;
|
GLsizeiptr size;
|
||||||
const GLvoid *data;
|
GLvoid *data;
|
||||||
} vbo_info_type;
|
} vbo_info_type;
|
||||||
|
|
||||||
long m_vboMemUsed;
|
long m_vboMemUsed;
|
||||||
vbo_info_type m_currentVBO;
|
vbo_info_type m_currentVBO;
|
||||||
|
|
||||||
std::map<const GLvoid *, vbo_info_type> m_vbos;
|
std::map<GLvoid *, vbo_info_type> m_vbosActive;
|
||||||
|
std::map<GLvoid *, vbo_info_type> m_vbosPool;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
|||||||
} else if(strcmp(szElementName, "spot_light") == 0) {
|
} else if(strcmp(szElementName, "spot_light") == 0) {
|
||||||
new_node = new KRSpotLight(scene, szName);
|
new_node = new KRSpotLight(scene, szName);
|
||||||
} else if(strcmp(szElementName, "mesh") == 0) {
|
} else if(strcmp(szElementName, "mesh") == 0) {
|
||||||
new_node = new KRInstance(scene, szName, szName, KRMat4(), e->Attribute("light_map"));
|
new_node = new KRInstance(scene, szName, szName, e->Attribute("light_map"));
|
||||||
} else if(strcmp(szElementName, "sky_box") == 0) {
|
} else if(strcmp(szElementName, "sky_box") == 0) {
|
||||||
new_node = new KRSkyBox(scene, szName);
|
new_node = new KRSkyBox(scene, szName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,11 +79,12 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
KRBoundingVolume *m_pExtents;
|
KRBoundingVolume *m_pExtents;
|
||||||
|
|
||||||
private:
|
|
||||||
KRVector3 m_localTranslation;
|
KRVector3 m_localTranslation;
|
||||||
KRVector3 m_localScale;
|
KRVector3 m_localScale;
|
||||||
KRVector3 m_localRotation;
|
KRVector3 m_localRotation;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
std::vector<KRNode *> m_childNodes;
|
std::vector<KRNode *> m_childNodes;
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ KROctreeNode::~KROctreeNode()
|
|||||||
}
|
}
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
if(m_occlusionTested) {
|
if(m_occlusionTested) {
|
||||||
glDeleteQueriesEXT(1, &m_occlusionQuery);
|
GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQuery));
|
||||||
}
|
}
|
||||||
if(m_occlusionTestedTransparent) {
|
if(m_occlusionTestedTransparent) {
|
||||||
glDeleteQueriesEXT(1, &m_occlusionQueryTransparent);
|
GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQueryTransparent));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -54,13 +54,13 @@ KROctreeNode::~KROctreeNode()
|
|||||||
void KROctreeNode::beginOcclusionQuery(bool bTransparentPass)
|
void KROctreeNode::beginOcclusionQuery(bool bTransparentPass)
|
||||||
{
|
{
|
||||||
if(bTransparentPass && !m_occlusionTestedTransparent) {
|
if(bTransparentPass && !m_occlusionTestedTransparent) {
|
||||||
glGenQueriesEXT(1, &m_occlusionQueryTransparent);
|
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQueryTransparent));
|
||||||
glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQueryTransparent);
|
GLDEBUG(glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQueryTransparent));
|
||||||
m_occlusionTestedTransparent = true;
|
m_occlusionTestedTransparent = true;
|
||||||
m_activeQuery = true;
|
m_activeQuery = true;
|
||||||
} else if(!bTransparentPass && !m_occlusionTested){
|
} else if(!bTransparentPass && !m_occlusionTested){
|
||||||
glGenQueriesEXT(1, &m_occlusionQuery);
|
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
|
||||||
glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQuery);
|
GLDEBUG(glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQuery));
|
||||||
m_occlusionTested = true;
|
m_occlusionTested = true;
|
||||||
m_activeQuery = true;
|
m_activeQuery = true;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ void KROctreeNode::endOcclusionQuery()
|
|||||||
{
|
{
|
||||||
if(m_activeQuery) {
|
if(m_activeQuery) {
|
||||||
// Only end a query if we started one
|
// Only end a query if we started one
|
||||||
glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
|
GLDEBUG(glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,19 +81,19 @@ bool KROctreeNode::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
|
|||||||
|
|
||||||
if(m_occlusionTested) {
|
if(m_occlusionTested) {
|
||||||
GLuint params = 0;
|
GLuint params = 0;
|
||||||
glGetQueryObjectuivEXT(m_occlusionQuery, GL_QUERY_RESULT_EXT, ¶ms);
|
GLDEBUG(glGetQueryObjectuivEXT(m_occlusionQuery, GL_QUERY_RESULT_EXT, ¶ms));
|
||||||
if(params) bRendered = true; // At least one opaque fragment processed
|
if(params) bRendered = true; // At least one opaque fragment processed
|
||||||
|
|
||||||
glDeleteQueriesEXT(1, &m_occlusionQuery);
|
GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQuery));
|
||||||
m_occlusionTested = false;
|
m_occlusionTested = false;
|
||||||
bGoDeeper = true;
|
bGoDeeper = true;
|
||||||
}
|
}
|
||||||
if(m_occlusionTestedTransparent) {
|
if(m_occlusionTestedTransparent) {
|
||||||
GLuint params = 0;
|
GLuint params = 0;
|
||||||
glGetQueryObjectuivEXT(m_occlusionQueryTransparent, GL_QUERY_RESULT_EXT, ¶ms);
|
GLDEBUG(glGetQueryObjectuivEXT(m_occlusionQueryTransparent, GL_QUERY_RESULT_EXT, ¶ms));
|
||||||
if(params) bRendered = true; // At least one transparent fragment processed
|
if(params) bRendered = true; // At least one transparent fragment processed
|
||||||
|
|
||||||
glDeleteQueriesEXT(1, &m_occlusionQueryTransparent);
|
GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQueryTransparent));
|
||||||
m_occlusionTestedTransparent = false;
|
m_occlusionTestedTransparent = false;
|
||||||
|
|
||||||
bGoDeeper = true;
|
bGoDeeper = true;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#import "KRCamera.h"
|
#import "KRCamera.h"
|
||||||
#import "KRContext.h"
|
#import "KRContext.h"
|
||||||
#import "KRBoundingVolume.h"
|
#import "KRBoundingVolume.h"
|
||||||
|
#import "assert.h"
|
||||||
|
|
||||||
KRPointLight::KRPointLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
KRPointLight::KRPointLight(KRScene &scene, std::string name) : KRLight(scene, name)
|
||||||
{
|
{
|
||||||
@@ -84,66 +85,66 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||||
|
|
||||||
|
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||||
m_color.x,
|
m_color.x,
|
||||||
m_color.y,
|
m_color.y,
|
||||||
m_color.z
|
m_color.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform1f(
|
GLDEBUG(glUniform1f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||||
m_intensity / 100.0f
|
m_intensity / 100.0f
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform1f(
|
GLDEBUG(glUniform1f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
||||||
getDecayStart()
|
getDecayStart()
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform1f(
|
GLDEBUG(glUniform1f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
||||||
KRLIGHT_MIN_INFLUENCE
|
KRLIGHT_MIN_INFLUENCE
|
||||||
);
|
));
|
||||||
|
|
||||||
|
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION],
|
||||||
light_position.x,
|
light_position.x,
|
||||||
light_position.y,
|
light_position.y,
|
||||||
light_position.z
|
light_position.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
|
||||||
view_space_light_position.x,
|
view_space_light_position.x,
|
||||||
view_space_light_position.y,
|
view_space_light_position.y,
|
||||||
view_space_light_position.z
|
view_space_light_position.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer());
|
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer()));
|
||||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer());
|
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer()));
|
||||||
|
|
||||||
|
|
||||||
KRMat4 matInvProjection;
|
KRMat4 matInvProjection;
|
||||||
matInvProjection = pCamera->getProjectionMatrix();
|
matInvProjection = pCamera->getProjectionMatrix();
|
||||||
matInvProjection.invert();
|
matInvProjection.invert();
|
||||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer());
|
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer()));
|
||||||
|
|
||||||
|
|
||||||
if(bVisualize) {
|
if(bVisualize) {
|
||||||
// Enable additive blending
|
// Enable additive blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
if(bInsideLight) {
|
if(bInsideLight) {
|
||||||
|
|
||||||
// Disable z-buffer test
|
// Disable z-buffer test
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
|
|
||||||
// Render a full screen quad
|
// Render a full screen quad
|
||||||
static const GLfloat squareVertices[] = {
|
static const GLfloat squareVertices[] = {
|
||||||
@@ -153,29 +154,27 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
1.0f, 1.0f,
|
1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
} else {
|
} else {
|
||||||
// Render sphere of light's influence
|
// Render sphere of light's influence
|
||||||
generateMesh();
|
generateMesh();
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
glDepthFunc(GL_LEQUAL);
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
glDepthRangef(0.0, 1.0);
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, m_cVertices));
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bVisualize) {
|
if(bVisualize) {
|
||||||
// Enable alpha blending
|
// Enable alpha blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
GLDEBUG(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ std::vector<KRResource *> KRResource::LoadBlenderScene(KRContext &context, const
|
|||||||
KRDataBlock data;
|
KRDataBlock data;
|
||||||
|
|
||||||
if(data.load(path)) {
|
if(data.load(path)) {
|
||||||
KRBlendFile blend_file = KRBlendFile(pFile);
|
//KRBlendFile blend_file = KRBlendFile(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resources;
|
return resources;
|
||||||
|
|||||||
@@ -240,14 +240,14 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF
|
|||||||
void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
void LoadNode(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
||||||
KFbxVector4 lTmpVector;
|
KFbxVector4 lTmpVector;
|
||||||
|
|
||||||
/*
|
|
||||||
lTmpVector = pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
|
fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
|
||||||
printf(" Translation: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
|
||||||
lTmpVector = pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
|
fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
|
||||||
printf(" Rotation: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
|
||||||
lTmpVector = pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
|
printf(" Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]);
|
||||||
printf(" Scaling: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
printf(" Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]);
|
||||||
*/
|
printf(" Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]);
|
||||||
|
|
||||||
KFbxNodeAttribute::EAttributeType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType());
|
KFbxNodeAttribute::EAttributeType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType());
|
||||||
switch(attribute_type) {
|
switch(attribute_type) {
|
||||||
@@ -271,10 +271,15 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
|
|||||||
std::string light_map = pNode->GetName();
|
std::string light_map = pNode->GetName();
|
||||||
light_map.append("_lightmap");
|
light_map.append("_lightmap");
|
||||||
|
|
||||||
KRInstance *new_instance = new KRInstance(parent_node->getScene(), pNode->GetName(), pNode->GetName(), KRMat4(), light_map);
|
KRInstance *new_instance = new KRInstance(parent_node->getScene(), pNode->GetName(), pNode->GetName(), light_map);
|
||||||
fbxDouble3 local_rotation = pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
|
fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
|
||||||
fbxDouble3 local_translation = pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
|
fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
|
||||||
fbxDouble3 local_scale = pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
|
fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
|
||||||
|
/*
|
||||||
|
fbxDouble3 local_rotation = pNode->GetGeometricRotation(KFbxNode::eDESTINATION_SET);
|
||||||
|
fbxDouble3 local_translation = pNode->GetGeometricTranslation(KFbxNode::eDESTINATION_SET);
|
||||||
|
fbxDouble3 local_scale = pNode->GetGeometricScaling(KFbxNode::eDESTINATION_SET);
|
||||||
|
*/
|
||||||
new_instance->setLocalRotation(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]));
|
new_instance->setLocalRotation(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]));
|
||||||
new_instance->setLocalTranslation(KRVector3(local_translation[0], local_translation[1], local_translation[2]));
|
new_instance->setLocalTranslation(KRVector3(local_translation[0], local_translation[1], local_translation[2]));
|
||||||
new_instance->setLocalScale(KRVector3(local_scale[0], local_scale[1], local_scale[2]));
|
new_instance->setLocalScale(KRVector3(local_scale[0], local_scale[1], local_scale[2]));
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
|||||||
|
|
||||||
KRDataBlock data;
|
KRDataBlock data;
|
||||||
|
|
||||||
char szSymbol[500][64];
|
char szSymbol[500][256];
|
||||||
|
|
||||||
int *pFaces = NULL;
|
int *pFaces = NULL;
|
||||||
|
|
||||||
@@ -249,9 +249,9 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
|||||||
KRMesh::pack_material *pMaterial = new KRMesh::pack_material();
|
KRMesh::pack_material *pMaterial = new KRMesh::pack_material();
|
||||||
pMaterial->start_vertex = iVertex;
|
pMaterial->start_vertex = iVertex;
|
||||||
pMaterial->vertex_count = 0;
|
pMaterial->vertex_count = 0;
|
||||||
memset(pMaterial->szName, 64, 0);
|
memset(pMaterial->szName, 256, 0);
|
||||||
if(material_itr < material_names_t.end()) {
|
if(material_itr < material_names_t.end()) {
|
||||||
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
|
strncpy(pMaterial->szName, (*material_itr++).c_str(), 256);
|
||||||
}
|
}
|
||||||
m_materials.push_back(pMaterial);
|
m_materials.push_back(pMaterial);
|
||||||
|
|
||||||
@@ -314,10 +314,10 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
|||||||
pMaterial = new KRMesh::pack_material();
|
pMaterial = new KRMesh::pack_material();
|
||||||
pMaterial->start_vertex = iVertex;
|
pMaterial->start_vertex = iVertex;
|
||||||
pMaterial->vertex_count = 0;
|
pMaterial->vertex_count = 0;
|
||||||
memset(pMaterial->szName, 64, 0);
|
memset(pMaterial->szName, 256, 0);
|
||||||
|
|
||||||
if(material_itr < material_names_t.end()) {
|
if(material_itr < material_names_t.end()) {
|
||||||
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
|
strncpy(pMaterial->szName, (*material_itr++).c_str(), 256);
|
||||||
}
|
}
|
||||||
m_materials.push_back(pMaterial);
|
m_materials.push_back(pMaterial);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,32 +63,32 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
|
|||||||
|
|
||||||
if(cShadowBuffers > 0) {
|
if(cShadowBuffers > 0) {
|
||||||
m_pContext->getTextureManager()->selectTexture(3, NULL);
|
m_pContext->getTextureManager()->selectTexture(3, NULL);
|
||||||
glActiveTexture(GL_TEXTURE3);
|
GLDEBUG(glActiveTexture(GL_TEXTURE3));
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[0]);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[0]));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cShadowBuffers > 1) {
|
if(cShadowBuffers > 1) {
|
||||||
m_pContext->getTextureManager()->selectTexture(4, NULL);
|
m_pContext->getTextureManager()->selectTexture(4, NULL);
|
||||||
glActiveTexture(GL_TEXTURE4);
|
GLDEBUG(glActiveTexture(GL_TEXTURE4));
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[1]);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[1]));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cShadowBuffers > 2) {
|
if(cShadowBuffers > 2) {
|
||||||
m_pContext->getTextureManager()->selectTexture(5, NULL);
|
m_pContext->getTextureManager()->selectTexture(5, NULL);
|
||||||
glActiveTexture(GL_TEXTURE5);
|
GLDEBUG(glActiveTexture(GL_TEXTURE5));
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[2]);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[2]));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,32 +102,6 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
|
|||||||
pCamera->dSunB = sun_color.z;
|
pCamera->dSunB = sun_color.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLuint occlusionTest,hasBeenTested,theParams = 0;
|
|
||||||
glGenQueriesEXT(1, &occlusionTest);
|
|
||||||
glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, occlusionTest);
|
|
||||||
m_pModel->render(pCamera, pContext, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
|
|
||||||
glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----
|
|
||||||
|
|
||||||
|
|
||||||
if (hasBeenTested) glGetQueryObjectuivEXT(occlusionTest, GL_QUERY_RESULT_EXT, &theParams);
|
|
||||||
if (!theParams) {
|
|
||||||
fprintf(stderr, "Occluded: %s\n", getName().c_str());
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, " Visible: %s\n", getName().c_str());
|
|
||||||
}
|
|
||||||
glDeleteQueriesEXT(1, &occlusionTest);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//m_pRootNode->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
|
||||||
render(m_nodeTree.getRootNode(), visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
render(m_nodeTree.getRootNode(), visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||||
|
|
||||||
|
|
||||||
@@ -137,7 +111,7 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds, KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass)
|
void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds, KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass)
|
||||||
{
|
{
|
||||||
if(pOctreeNode) {
|
if(pOctreeNode) {
|
||||||
KRMat4 projectionMatrix;
|
KRMat4 projectionMatrix;
|
||||||
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
|
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
|
||||||
@@ -148,13 +122,13 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
|||||||
|
|
||||||
KRBoundingVolume frustrumVolumeNoNearClip = KRBoundingVolume(viewMatrix, pCamera->perspective_fov, pCamera->m_viewportSize.x / pCamera->m_viewportSize.y, 0.0, pCamera->perspective_farz);
|
KRBoundingVolume frustrumVolumeNoNearClip = KRBoundingVolume(viewMatrix, pCamera->perspective_fov, pCamera->m_viewportSize.x / pCamera->m_viewportSize.y, 0.0, pCamera->perspective_farz);
|
||||||
|
|
||||||
if(true) {
|
//if(true) {
|
||||||
//if(pOctreeNode->getBounds().visible(viewMatrix * projectionMatrix)) { // Only recurse deeper if within the view frustrum
|
//if(pOctreeNode->getBounds().visible(viewMatrix * projectionMatrix)) { // Only recurse deeper if within the view frustrum
|
||||||
//if(frustrumVolumeNoNearClip.test_intersect(pOctreeNode->getBounds())) { // Only recurse deeper if within the view frustrum
|
if(frustrumVolumeNoNearClip.test_intersect(pOctreeNode->getBounds())) { // Only recurse deeper if within the view frustrum
|
||||||
|
|
||||||
bool can_occlusion_test = renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER/* || renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT*/;
|
bool can_occlusion_test = renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER/* || renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT*/;
|
||||||
|
|
||||||
|
// can_occlusion_test = false;
|
||||||
bool bVisible = true;
|
bool bVisible = true;
|
||||||
//bool bVisible = visibleBounds.find(octreeBounds) != visibleBounds.end();
|
//bool bVisible = visibleBounds.find(octreeBounds) != visibleBounds.end();
|
||||||
|
|
||||||
@@ -213,9 +187,8 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
|||||||
-1.0, 1.0,-1.0
|
-1.0, 1.0,-1.0
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
|
||||||
|
|
||||||
KRMat4 matModel = KRMat4();
|
KRMat4 matModel = KRMat4();
|
||||||
matModel.scale(octreeBounds.size() / 2.0f);
|
matModel.scale(octreeBounds.size() / 2.0f);
|
||||||
@@ -223,14 +196,14 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
|||||||
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
||||||
|
|
||||||
// Enable additive blending
|
// Enable additive blending
|
||||||
glEnable(GL_BLEND);
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
|
|
||||||
|
|
||||||
pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 14);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
GLDEBUG(glDisable(GL_BLEND));
|
||||||
|
|
||||||
pOctreeNode->endOcclusionQuery();
|
pOctreeNode->endOcclusionQuery();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,62 +40,62 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
|||||||
const GLchar *fragSource[2] = {options.c_str(), fragShaderSource.c_str()};
|
const GLchar *fragSource[2] = {options.c_str(), fragShaderSource.c_str()};
|
||||||
|
|
||||||
// Create shader program.
|
// Create shader program.
|
||||||
m_iProgram = glCreateProgram();
|
GLDEBUG(m_iProgram = glCreateProgram());
|
||||||
|
|
||||||
// Create and compile vertex shader.
|
// Create and compile vertex shader.
|
||||||
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
GLDEBUG(vertexShader = glCreateShader(GL_VERTEX_SHADER));
|
||||||
glShaderSource(vertexShader, 2, vertSource, NULL);
|
GLDEBUG(glShaderSource(vertexShader, 2, vertSource, NULL));
|
||||||
glCompileShader(vertexShader);
|
GLDEBUG(glCompileShader(vertexShader));
|
||||||
|
|
||||||
// Report any compile issues to stderr
|
// Report any compile issues to stderr
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0) {
|
if (logLength > 0) {
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
|
GLDEBUG(glGetShaderInfoLog(vertexShader, logLength, &logLength, log));
|
||||||
fprintf(stderr, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
fprintf(stderr, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create and compile vertex shader.
|
// Create and compile vertex shader.
|
||||||
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
GLDEBUG(fragShader = glCreateShader(GL_FRAGMENT_SHADER));
|
||||||
glShaderSource(fragShader, 2, fragSource, NULL);
|
GLDEBUG(glShaderSource(fragShader, 2, fragSource, NULL));
|
||||||
glCompileShader(fragShader);
|
GLDEBUG(glCompileShader(fragShader));
|
||||||
|
|
||||||
// Report any compile issues to stderr
|
// Report any compile issues to stderr
|
||||||
glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0) {
|
if (logLength > 0) {
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetShaderInfoLog(fragShader, logLength, &logLength, log);
|
GLDEBUG(glGetShaderInfoLog(fragShader, logLength, &logLength, log));
|
||||||
fprintf(stderr, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
fprintf(stderr, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach vertex shader to program.
|
// Attach vertex shader to program.
|
||||||
glAttachShader(m_iProgram, vertexShader);
|
GLDEBUG(glAttachShader(m_iProgram, vertexShader));
|
||||||
|
|
||||||
// Attach fragment shader to program.
|
// Attach fragment shader to program.
|
||||||
glAttachShader(m_iProgram, fragShader);
|
GLDEBUG(glAttachShader(m_iProgram, fragShader));
|
||||||
|
|
||||||
// Bind attribute locations.
|
// Bind attribute locations.
|
||||||
// This needs to be done prior to linking.
|
// This needs to be done prior to linking.
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "vertex_position");
|
GLDEBUG(glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "vertex_position"));
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "vertex_normal");
|
GLDEBUG(glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "vertex_normal"));
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "vertex_tangent");
|
GLDEBUG(glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "vertex_tangent"));
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "vertex_uv");
|
GLDEBUG(glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "vertex_uv"));
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
|
GLDEBUG(glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv"));
|
||||||
|
|
||||||
|
|
||||||
// Link program.
|
// Link program.
|
||||||
glLinkProgram(m_iProgram);
|
GLDEBUG(glLinkProgram(m_iProgram));
|
||||||
|
|
||||||
// Report any linking issues to stderr
|
// Report any linking issues to stderr
|
||||||
glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
|
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||||
fprintf(stderr, "KREngine - Failed to link shader program: %s\nProgram link log:\n%s", szKey, log);
|
fprintf(stderr, "KREngine - Failed to link shader program: %s\nProgram link log:\n%s", szKey, log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
@@ -161,104 +161,104 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
|||||||
|
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
if(vertexShader) {
|
if(vertexShader) {
|
||||||
glDeleteShader(vertexShader);
|
GLDEBUG(glDeleteShader(vertexShader));
|
||||||
vertexShader = 0;
|
vertexShader = 0;
|
||||||
}
|
}
|
||||||
if(fragShader) {
|
if(fragShader) {
|
||||||
glDeleteShader(fragShader);
|
GLDEBUG(glDeleteShader(fragShader));
|
||||||
fragShader = 0;
|
fragShader = 0;
|
||||||
}
|
}
|
||||||
if(m_iProgram) {
|
if(m_iProgram) {
|
||||||
glDeleteProgram(m_iProgram);
|
GLDEBUG(glDeleteProgram(m_iProgram));
|
||||||
m_iProgram = 0;
|
m_iProgram = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release vertex and fragment shaders.
|
// Release vertex and fragment shaders.
|
||||||
if (vertexShader) {
|
if (vertexShader) {
|
||||||
glDeleteShader(vertexShader);
|
GLDEBUG(glDeleteShader(vertexShader));
|
||||||
}
|
}
|
||||||
if (fragShader) {
|
if (fragShader) {
|
||||||
glDeleteShader(fragShader);
|
GLDEBUG(glDeleteShader(fragShader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRShader::~KRShader() {
|
KRShader::~KRShader() {
|
||||||
if(m_iProgram) {
|
if(m_iProgram) {
|
||||||
glDeleteProgram(m_iProgram);
|
GLDEBUG(glDeleteProgram(m_iProgram));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||||
glUseProgram(m_iProgram);
|
GLDEBUG(glUseProgram(m_iProgram));
|
||||||
|
|
||||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||||
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpMatrix.getPointer());
|
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpMatrix.getPointer()));
|
||||||
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MN2V], 1, GL_FALSE, matModelToView.getPointer());
|
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MN2V], 1, GL_FALSE, matModelToView.getPointer()));
|
||||||
|
|
||||||
|
|
||||||
KRVector3 nLightDir = lightDirection;
|
KRVector3 nLightDir = lightDirection;
|
||||||
nLightDir.normalize();
|
nLightDir.normalize();
|
||||||
|
|
||||||
// Bind the light direction vector
|
// Bind the light direction vector
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION],
|
m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION],
|
||||||
(GLfloat)nLightDir.x,
|
(GLfloat)nLightDir.x,
|
||||||
(GLfloat)nLightDir.y,
|
(GLfloat)nLightDir.y,
|
||||||
(GLfloat)nLightDir.z
|
(GLfloat)nLightDir.z
|
||||||
);
|
));
|
||||||
|
|
||||||
// Bind the camera position, in model space
|
// Bind the camera position, in model space
|
||||||
glUniform3f(
|
GLDEBUG(glUniform3f(
|
||||||
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS],
|
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS],
|
||||||
(GLfloat)cameraPosition.x,
|
(GLfloat)cameraPosition.x,
|
||||||
(GLfloat)cameraPosition.y,
|
(GLfloat)cameraPosition.y,
|
||||||
(GLfloat)cameraPosition.z
|
(GLfloat)cameraPosition.z
|
||||||
);
|
));
|
||||||
|
|
||||||
glUniform4f(
|
GLDEBUG(glUniform4f(
|
||||||
m_uniforms[KRENGINE_UNIFORM_VIEWPORT],
|
m_uniforms[KRENGINE_UNIFORM_VIEWPORT],
|
||||||
(GLfloat)0.0,
|
(GLfloat)0.0,
|
||||||
(GLfloat)0.0,
|
(GLfloat)0.0,
|
||||||
(GLfloat)pCamera->getViewportSize().x,
|
(GLfloat)pCamera->getViewportSize().x,
|
||||||
(GLfloat)pCamera->getViewportSize().y
|
(GLfloat)pCamera->getViewportSize().y
|
||||||
);
|
));
|
||||||
|
|
||||||
// Bind the shadowmap space matrices
|
// Bind the shadowmap space matrices
|
||||||
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
|
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
|
||||||
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1 + iShadow], 1, GL_FALSE, pShadowMatrices[iShadow].getPointer());
|
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1 + iShadow], 1, GL_FALSE, pShadowMatrices[iShadow].getPointer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the diffuseTexture variable to the first texture unit
|
// Sets the diffuseTexture variable to the first texture unit
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE], 0);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE], 0));
|
||||||
|
|
||||||
// Sets the specularTexture variable to the second texture unit
|
// Sets the specularTexture variable to the second texture unit
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE], 1);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE], 1));
|
||||||
|
|
||||||
// Sets the normalTexture variable to the third texture unit
|
// Sets the normalTexture variable to the third texture unit
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE], 2);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE], 2));
|
||||||
|
|
||||||
// Sets the shadowTexture variable to the fourth texture unit
|
// Sets the shadowTexture variable to the fourth texture unit
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1], 3);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1], 3));
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4));
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5));
|
||||||
|
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6);
|
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6));
|
||||||
|
|
||||||
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_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
|
||||||
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_REFLECTIONTEXTURE], 7)); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
|
|
||||||
glValidateProgram(m_iProgram);
|
GLDEBUG(glValidateProgram(m_iProgram));
|
||||||
glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength);
|
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
|
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||||
fprintf(stderr, "KREngine - Failed to validate shader program: %s\n Program validate log:\n%s", m_szKey, log);
|
fprintf(stderr, "KREngine - Failed to validate shader program: %s\n Program validate log:\n%s", m_szKey, log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ using std::vector;
|
|||||||
#ifndef KRSHADERMANAGER_H
|
#ifndef KRSHADERMANAGER_H
|
||||||
#define KRSHADERMANAGER_H
|
#define KRSHADERMANAGER_H
|
||||||
|
|
||||||
#define KRENGINE_MAX_SHADER_HANDLES 100
|
#define KRENGINE_MAX_SHADER_HANDLES 1000
|
||||||
|
|
||||||
class KRShaderManager : public KRContextObject {
|
class KRShaderManager : public KRContextObject {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -147,10 +147,10 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &
|
|||||||
m_pContext->getTextureManager()->selectTexture(5, m_pRightTexture);
|
m_pContext->getTextureManager()->selectTexture(5, m_pRightTexture);
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
GLDEBUG(glDepthMask(GL_FALSE));
|
||||||
|
|
||||||
// Disable z-buffer test
|
// Disable z-buffer test
|
||||||
glDisable(GL_DEPTH_TEST);
|
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||||
|
|
||||||
// Render a full screen quad
|
// Render a full screen quad
|
||||||
static const GLfloat squareVertices[] = {
|
static const GLfloat squareVertices[] = {
|
||||||
@@ -160,10 +160,9 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &
|
|||||||
1.0f, 1.0f,
|
1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
GLDEBUG(glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX));
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ KRTexture::~KRTexture() {
|
|||||||
delete m_pData;
|
delete m_pData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
|
||||||
|
|
||||||
bool KRTexture::load() {
|
bool KRTexture::load() {
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart();
|
PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart();
|
||||||
uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK;
|
uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK;
|
||||||
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
|
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
|
||||||
@@ -154,12 +154,12 @@ bool KRTexture::load() {
|
|||||||
height = 1;
|
height = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool KRTexture::createGLTexture() {
|
bool KRTexture::createGLTexture() {
|
||||||
int width = m_iWidth;
|
int width = m_iWidth;
|
||||||
@@ -170,25 +170,25 @@ bool KRTexture::createGLTexture() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_iName);
|
GLDEBUG(glGenTextures(1, &m_iName));
|
||||||
if(m_iName == 0) {
|
if(m_iName == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, m_iName);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, m_iName));
|
||||||
|
|
||||||
if (m_blocks.size() > 1) {
|
if (m_blocks.size() > 1) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
|
||||||
} else {
|
} else {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
for(std::list<dataBlockStruct>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for(std::list<dataBlockStruct>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
dataBlockStruct block = *itr;
|
dataBlockStruct block = *itr;
|
||||||
glCompressedTexImage2D(GL_TEXTURE_2D, i, m_internalFormat, width, height, 0, block.length, block.start);
|
GLDEBUG(glCompressedTexImage2D(GL_TEXTURE_2D, i, m_internalFormat, width, height, 0, block.length, block.start));
|
||||||
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
if (err != GL_NO_ERROR) {
|
if (err != GL_NO_ERROR) {
|
||||||
glDeleteTextures(1, &m_iName);
|
GLDEBUG(glDeleteTextures(1, &m_iName));
|
||||||
m_iName = 0;
|
m_iName = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -210,12 +210,10 @@ bool KRTexture::createGLTexture() {
|
|||||||
|
|
||||||
GLuint KRTexture::getHandle(long &textureMemUsed) {
|
GLuint KRTexture::getHandle(long &textureMemUsed) {
|
||||||
if(m_iName == 0) {
|
if(m_iName == 0) {
|
||||||
if(!createGLTexture()) {
|
if(createGLTexture()) {
|
||||||
if(createGLTexture()) { // FINDME - HACK! The first texture fails with 0x501 return code but loads on second try
|
|
||||||
textureMemUsed += getMemSize();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
textureMemUsed += getMemSize();
|
textureMemUsed += getMemSize();
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//createGLTexture();
|
//createGLTexture();
|
||||||
@@ -226,7 +224,7 @@ GLuint KRTexture::getHandle(long &textureMemUsed) {
|
|||||||
void KRTexture::releaseHandle(long &textureMemUsed) {
|
void KRTexture::releaseHandle(long &textureMemUsed) {
|
||||||
if(m_iName != 0) {
|
if(m_iName != 0) {
|
||||||
textureMemUsed -= getMemSize();
|
textureMemUsed -= getMemSize();
|
||||||
glDeleteTextures(1, &m_iName);
|
GLDEBUG(glDeleteTextures(1, &m_iName));
|
||||||
m_iName = 0;
|
m_iName = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
||||||
m_textureMemUsed = 0;
|
m_textureMemUsed = 0;
|
||||||
for(int iTexture=0; iTexture<KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
for(int iTexture=0; iTexture<KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
||||||
m_activeTextures[iTexture] = NULL;
|
m_boundTextures[iTexture] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ KRTexture *KRTextureManager::getTexture(const char *szName) {
|
|||||||
map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName);
|
map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName);
|
||||||
if(itr == m_textures.end()) {
|
if(itr == m_textures.end()) {
|
||||||
// Not found
|
// Not found
|
||||||
|
//fprintf(stderr, "ERROR: Texture not found: %s\n", szName);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
return (*itr).second;
|
return (*itr).second;
|
||||||
@@ -79,46 +80,55 @@ KRTexture *KRTextureManager::getTexture(const char *szName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) {
|
void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) {
|
||||||
if(m_activeTextures[iTextureUnit] != pTexture) {
|
|
||||||
glActiveTexture(GL_TEXTURE0 + iTextureUnit);
|
if(m_boundTextures[iTextureUnit] != pTexture) {
|
||||||
|
GLDEBUG(glActiveTexture(GL_TEXTURE0 + iTextureUnit));
|
||||||
if(pTexture != NULL) {
|
if(pTexture != NULL) {
|
||||||
m_textureCache.erase(pTexture); // Ensure that the texture will not be deleted while it is bound to a texture unit, and return it to the top of the texture cache when it is released
|
m_poolTextures.erase(pTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, pTexture->getHandle(m_textureMemUsed));
|
if(m_activeTextures.find(pTexture) == m_activeTextures.end()) {
|
||||||
|
m_activeTextures.insert(pTexture);
|
||||||
|
}
|
||||||
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, pTexture->getHandle(m_textureMemUsed)));
|
||||||
// TODO - These texture parameters should be assigned by the material or texture parameters
|
// TODO - These texture parameters should be assigned by the material or texture parameters
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
GLDEBUG(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||||
}
|
}
|
||||||
if(m_activeTextures[iTextureUnit] != NULL) {
|
m_boundTextures[iTextureUnit] = pTexture;
|
||||||
KRTexture *unloadedTexture = m_activeTextures[iTextureUnit];
|
while(m_activeTextures.size() + m_poolTextures.size() > KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRENGINE_MAX_TEXTURE_MEM) {
|
||||||
m_activeTextures[iTextureUnit] = NULL;
|
if(m_poolTextures.empty()) {
|
||||||
bool bActive = false;
|
m_pContext->rotateBuffers();
|
||||||
for(int iTexture=0; iTexture < KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
|
||||||
if(m_activeTextures[iTexture] == unloadedTexture) {
|
|
||||||
bActive = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!bActive) {
|
// Keep texture size within limits
|
||||||
// Only return a texture to the cache when the last texture unit referencing it is re-assigned to a different texture
|
KRTexture *droppedTexture = (*m_poolTextures.begin());
|
||||||
if(m_textureCache.find(unloadedTexture) == m_textureCache.end()) {
|
droppedTexture->releaseHandle(m_textureMemUsed);
|
||||||
m_textureCache.insert(unloadedTexture);
|
m_poolTextures.erase(droppedTexture);
|
||||||
while(m_textureCache.size() > KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRENGINE_MAX_TEXTURE_MEM) {
|
//fprintf(stderr, "Texture Swapping...\n");
|
||||||
// Keep texture size within limits
|
}
|
||||||
KRTexture *droppedTexture = (*m_textureCache.begin());
|
|
||||||
droppedTexture->releaseHandle(m_textureMemUsed);
|
|
||||||
m_textureCache.erase(droppedTexture);
|
|
||||||
fprintf(stderr, "Texture Swapping...\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_activeTextures[iTextureUnit] = pTexture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
long KRTextureManager::getMemUsed() {
|
long KRTextureManager::getMemUsed() {
|
||||||
return m_textureMemUsed;
|
return m_textureMemUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KRTextureManager::rotateBuffers()
|
||||||
|
{
|
||||||
|
m_poolTextures.insert(m_activeTextures.begin(), m_activeTextures.end());
|
||||||
|
m_activeTextures.clear();
|
||||||
|
|
||||||
|
for(int iTexture=0; iTexture < KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
|
||||||
|
KRTexture *pBoundTexture = m_boundTextures[iTexture];
|
||||||
|
if(pBoundTexture != NULL) {
|
||||||
|
m_poolTextures.erase(pBoundTexture);
|
||||||
|
if(m_activeTextures.find(pBoundTexture) == m_activeTextures.end()) {
|
||||||
|
m_activeTextures.insert(pBoundTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#define KRENGINE_MAX_TEXTURE_UNITS 8
|
#define KRENGINE_MAX_TEXTURE_UNITS 8
|
||||||
#define KRENGINE_MAX_TEXTURE_HANDLES 1000
|
#define KRENGINE_MAX_TEXTURE_HANDLES 10000
|
||||||
#define KRENGINE_MAX_TEXTURE_MEM 100000000
|
#define KRENGINE_MAX_TEXTURE_MEM 100000000
|
||||||
|
|
||||||
#ifndef KRTEXTUREMANAGER_H
|
#ifndef KRTEXTUREMANAGER_H
|
||||||
@@ -49,6 +49,8 @@ public:
|
|||||||
KRTextureManager(KRContext &context);
|
KRTextureManager(KRContext &context);
|
||||||
virtual ~KRTextureManager();
|
virtual ~KRTextureManager();
|
||||||
|
|
||||||
|
void rotateBuffers();
|
||||||
|
|
||||||
void selectTexture(int iTextureUnit, KRTexture *pTexture);
|
void selectTexture(int iTextureUnit, KRTexture *pTexture);
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
@@ -64,8 +66,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::map<std::string, KRTexture *> m_textures;
|
std::map<std::string, KRTexture *> m_textures;
|
||||||
|
|
||||||
KRTexture *m_activeTextures[KRENGINE_MAX_TEXTURE_UNITS];
|
KRTexture *m_boundTextures[KRENGINE_MAX_TEXTURE_UNITS];
|
||||||
std::set<KRTexture *> m_textureCache;
|
std::set<KRTexture *> m_activeTextures;
|
||||||
|
std::set<KRTexture *> m_poolTextures;
|
||||||
|
|
||||||
long m_textureMemUsed;
|
long m_textureMemUsed;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -105,7 +105,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[self.engine setNearZ: 5.0];
|
[self.engine setNearZ: 5.0];
|
||||||
[self.engine setFarZ: 500.0];
|
[self.engine setFarZ: 1000.0];
|
||||||
//[renderEngine setNearZ: 1.0];
|
//[renderEngine setNearZ: 1.0];
|
||||||
//[renderEngine setFarZ: 3000.0];
|
//[renderEngine setFarZ: 3000.0];
|
||||||
|
|
||||||
@@ -117,31 +117,34 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
// ===== Create onscreen framebuffer object =====
|
// ===== Create onscreen framebuffer object =====
|
||||||
glGenFramebuffers(1, &viewFramebuffer);
|
GLDEBUG(glGenFramebuffers(1, &viewFramebuffer));
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer));
|
||||||
|
|
||||||
// ----- Create color buffer for viewFramebuffer -----
|
// ----- Create color buffer for viewFramebuffer -----
|
||||||
glGenRenderbuffers(1, &viewRenderbuffer);
|
GLDEBUG(glGenRenderbuffers(1, &viewRenderbuffer));
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
|
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||||
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
||||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
|
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth));
|
||||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
|
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight));
|
||||||
NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);
|
NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
|
GLDEBUG(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
GLDEBUG(
|
||||||
NSLog(@"Failure with depth buffer generation");
|
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
return NO;
|
NSLog(@"Failure with depth buffer generation");
|
||||||
}
|
return NO;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
GLDEBUG(
|
||||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
NSLog(@"Incomplete FBO: %d", status);
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
exit(1);
|
NSLog(@"Incomplete FBO: %d", status);
|
||||||
}
|
exit(1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -150,13 +153,13 @@
|
|||||||
{
|
{
|
||||||
if (viewFramebuffer)
|
if (viewFramebuffer)
|
||||||
{
|
{
|
||||||
glDeleteFramebuffers(1, &viewFramebuffer);
|
GLDEBUG(glDeleteFramebuffers(1, &viewFramebuffer));
|
||||||
viewFramebuffer = 0;
|
viewFramebuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewRenderbuffer)
|
if (viewRenderbuffer)
|
||||||
{
|
{
|
||||||
glDeleteRenderbuffers(1, &viewRenderbuffer);
|
GLDEBUG(glDeleteRenderbuffers(1, &viewRenderbuffer));
|
||||||
viewRenderbuffer = 0;
|
viewRenderbuffer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,9 +173,9 @@
|
|||||||
[self createFramebuffers];
|
[self createFramebuffers];
|
||||||
}
|
}
|
||||||
|
|
||||||
//glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
|
//GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer));
|
||||||
|
|
||||||
glViewport(0, 0, backingWidth, backingHeight);
|
GLDEBUG(glViewport(0, 0, backingWidth, backingHeight));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +185,7 @@
|
|||||||
|
|
||||||
if (context)
|
if (context)
|
||||||
{
|
{
|
||||||
//glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
|
//GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||||
|
|
||||||
success = [context presentRenderbuffer:GL_RENDERBUFFER];
|
success = [context presentRenderbuffer:GL_RENDERBUFFER];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,9 @@
|
|||||||
|
|
||||||
- (void)drawView:(id)sender
|
- (void)drawView:(id)sender
|
||||||
{
|
{
|
||||||
|
glGetError(); // Clear any prior errors...
|
||||||
|
|
||||||
|
|
||||||
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
||||||
|
|
||||||
NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||||
1D3623240D0F684500981E51 /* KRObjViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRObjViewAppDelegate.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
1D3623240D0F684500981E51 /* KRObjViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRObjViewAppDelegate.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||||
1D3623250D0F684500981E51 /* KRObjViewAppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = KRObjViewAppDelegate.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
1D3623250D0F684500981E51 /* KRObjViewAppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = KRObjViewAppDelegate.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||||
1D6058910D05DD3D006BFB54 /* KRObjView2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KRObjView2.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
1D6058910D05DD3D006BFB54 /* KRObjView3.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KRObjView3.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||||
288765A40DF7441C002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
|
288765A40DF7441C002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
|
||||||
28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
|
28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
19C28FACFE9D520D11CA2CBB /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
1D6058910D05DD3D006BFB54 /* KRObjView2.app */,
|
1D6058910D05DD3D006BFB54 /* KRObjView3.app */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -263,7 +263,7 @@
|
|||||||
);
|
);
|
||||||
name = KRObjView;
|
name = KRObjView;
|
||||||
productName = AVCapTest;
|
productName = AVCapTest;
|
||||||
productReference = 1D6058910D05DD3D006BFB54 /* KRObjView2.app */;
|
productReference = 1D6058910D05DD3D006BFB54 /* KRObjView3.app */;
|
||||||
productType = "com.apple.product-type.application";
|
productType = "com.apple.product-type.application";
|
||||||
};
|
};
|
||||||
/* End PBXNativeTarget section */
|
/* End PBXNativeTarget section */
|
||||||
@@ -368,7 +368,7 @@
|
|||||||
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
||||||
"\"$(SRCROOT)/testflight\"",
|
"\"$(SRCROOT)/testflight\"",
|
||||||
);
|
);
|
||||||
PRODUCT_NAME = KRObjView2;
|
PRODUCT_NAME = KRObjView3;
|
||||||
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
@@ -394,7 +394,7 @@
|
|||||||
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
||||||
"\"$(SRCROOT)/testflight\"",
|
"\"$(SRCROOT)/testflight\"",
|
||||||
);
|
);
|
||||||
PRODUCT_NAME = KRObjView2;
|
PRODUCT_NAME = KRObjView3;
|
||||||
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
@@ -460,7 +460,7 @@
|
|||||||
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
"\"$(SRCROOT)/TestFlightSDK0.8\"",
|
||||||
"\"$(SRCROOT)/testflight\"",
|
"\"$(SRCROOT)/testflight\"",
|
||||||
);
|
);
|
||||||
PRODUCT_NAME = KRObjView2;
|
PRODUCT_NAME = KRObjView3;
|
||||||
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
PROVISIONING_PROFILE = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "833D5E39-C2AD-4221-9136-B9DCF6FF81A1";
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
|
|||||||
Reference in New Issue
Block a user