Corrected shader link status validation
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40103
This commit is contained in:
@@ -389,8 +389,9 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
matModel.translate((*itr).center());
|
||||
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
||||
|
||||
pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
if(pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ void KRDataBlock::expand(size_t size)
|
||||
if(m_data == NULL) {
|
||||
// Starting with an empty data block; allocate memory on the heap
|
||||
m_data = malloc(size);
|
||||
assert(m_data != NULL);
|
||||
m_data_size = size;
|
||||
m_bMalloced = true;
|
||||
} else if(m_bMalloced) {
|
||||
@@ -132,6 +133,7 @@ void KRDataBlock::expand(size_t size)
|
||||
// Starting with a mmap'ed data block; copy it to ram before expanding to avoid updating the original file until save() is called
|
||||
// ... Or starting with a pointer reference, we must make our own copy and must not free the pointer
|
||||
void *pNewData = malloc(m_data_size + size);
|
||||
assert(pNewData != NULL);
|
||||
memcpy((unsigned char *)pNewData, m_data, m_data_size); // Copy exising data
|
||||
// Unload existing data allocation, which is now redundant
|
||||
size_t new_size = m_data_size + size; // We need to store this before unload() as unload() will reset it
|
||||
|
||||
@@ -69,37 +69,38 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
light_direction_view_space.normalize();
|
||||
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE],
|
||||
light_direction_view_space.x,
|
||||
light_direction_view_space.y,
|
||||
light_direction_view_space.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x,
|
||||
m_color.y,
|
||||
m_color.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE],
|
||||
light_direction_view_space.x,
|
||||
light_direction_view_space.y,
|
||||
light_direction_view_space.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x,
|
||||
m_color.y,
|
||||
m_color.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,14 +146,15 @@ void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
||||
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("flare", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ bool KRMaterial::isTransparent() {
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
bool bSameMaterial = *prevBoundMaterial == this;
|
||||
bool bLightMap = pLightMap && pCamera->bEnableLightMap;
|
||||
|
||||
@@ -233,7 +233,9 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
|
||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||
if(!bSameShader) {
|
||||
pShader->bind(pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
if(!pShader->bind(pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
strcpy(szPrevShaderKey, pShader->getKey());
|
||||
}
|
||||
@@ -413,6 +415,8 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
|
||||
*prevBoundMaterial = this;
|
||||
} // if(!bSameMaterial)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
char *getName();
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
void bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
bool bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ void KRMesh::renderSubmesh(int iSubmesh) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, cVertexes));
|
||||
cVertexes = 0;
|
||||
}
|
||||
m_pContext->getModelManager()->unbindVBO();
|
||||
//m_pContext->getModelManager()->unbindVBO();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,25 +117,26 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
||||
|
||||
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
||||
if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass);
|
||||
if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass)) {
|
||||
|
||||
switch(pMaterial->getAlphaMode()) {
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||
// Render back faces first
|
||||
GLDEBUG(glCullFace(GL_BACK));
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
|
||||
// Render front faces second
|
||||
GLDEBUG(glCullFace(GL_BACK));
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
switch(pMaterial->getAlphaMode()) {
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||
// Render back faces first
|
||||
GLDEBUG(glCullFace(GL_BACK));
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
|
||||
// Render front faces second
|
||||
GLDEBUG(glCullFace(GL_BACK));
|
||||
m_pMesh->renderSubmesh(iSubmesh);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -83,89 +83,89 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
|
||||
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x,
|
||||
m_color.y,
|
||||
m_color.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
||||
getDecayStart()
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
||||
KRLIGHT_MIN_INFLUENCE
|
||||
));
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION],
|
||||
light_position.x,
|
||||
light_position.y,
|
||||
light_position.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
|
||||
view_space_light_position.x,
|
||||
view_space_light_position.y,
|
||||
view_space_light_position.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer()));
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer()));
|
||||
|
||||
|
||||
KRMat4 matInvProjection;
|
||||
matInvProjection = pCamera->getProjectionMatrix();
|
||||
matInvProjection.invert();
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer()));
|
||||
|
||||
|
||||
if(bVisualize) {
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x,
|
||||
m_color.y,
|
||||
m_color.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
||||
getDecayStart()
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
||||
KRLIGHT_MIN_INFLUENCE
|
||||
));
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION],
|
||||
light_position.x,
|
||||
light_position.y,
|
||||
light_position.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
|
||||
view_space_light_position.x,
|
||||
view_space_light_position.y,
|
||||
view_space_light_position.z
|
||||
));
|
||||
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer()));
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer()));
|
||||
|
||||
|
||||
KRMat4 matInvProjection;
|
||||
matInvProjection = pCamera->getProjectionMatrix();
|
||||
matInvProjection.invert();
|
||||
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer()));
|
||||
|
||||
|
||||
if(bVisualize) {
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
}
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
|
||||
|
||||
if(bInsideLight) {
|
||||
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
} else {
|
||||
m_pContext->getModelManager()->configureAttribs(true, false, false, false, false);
|
||||
// Render sphere of light's influence
|
||||
generateMesh();
|
||||
|
||||
// Enable z-buffer test
|
||||
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices));
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, m_cVertices));
|
||||
}
|
||||
}
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
|
||||
|
||||
if(bInsideLight) {
|
||||
|
||||
// Disable z-buffer test
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
} else {
|
||||
m_pContext->getModelManager()->configureAttribs(true, false, false, false, false);
|
||||
// Render sphere of light's influence
|
||||
generateMesh();
|
||||
|
||||
// Enable z-buffer test
|
||||
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
|
||||
GLDEBUG(glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices));
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, m_cVertices));
|
||||
}
|
||||
|
||||
if(bVisualize) {
|
||||
// Enable alpha blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -262,6 +262,7 @@ void KRPointLight::generateMesh() {
|
||||
}
|
||||
|
||||
m_sphereVertices = (GLfloat *)malloc(sizeof(GLfloat) * m_cVertices * 3);
|
||||
assert(m_sphereVertices != NULL);
|
||||
GLfloat *pDest = m_sphereVertices;
|
||||
for(int facet_index=0; facet_index < facet_count; facet_index++) {
|
||||
*pDest++ = f[facet_index].p1.x;
|
||||
|
||||
@@ -113,7 +113,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
||||
// -----=====----- Populate vertexes and faces -----=====-----
|
||||
|
||||
int *pFaces = (int *)malloc(sizeof(int *) * (cFaces + 1));
|
||||
|
||||
assert(pFaces != NULL);
|
||||
|
||||
std::vector<KRVector3> indexed_vertices;
|
||||
std::vector<KRVector2> indexed_uva;
|
||||
|
||||
@@ -182,8 +182,9 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
|
||||
pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
if(pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
||||
GLDEBUG(glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
assert(log != NULL);
|
||||
GLDEBUG(glGetShaderInfoLog(vertexShader, logLength, &logLength, log));
|
||||
fprintf(stderr, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
free(log);
|
||||
@@ -67,6 +68,7 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
||||
GLDEBUG(glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
assert(log != NULL);
|
||||
GLDEBUG(glGetShaderInfoLog(fragShader, logLength, &logLength, log));
|
||||
fprintf(stderr, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
free(log);
|
||||
@@ -90,64 +92,75 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
||||
// Link program.
|
||||
GLDEBUG(glLinkProgram(m_iProgram));
|
||||
|
||||
// Report any linking issues to stderr
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
fprintf(stderr, "KREngine - Failed to link shader program: %s\nProgram link log:\n%s", szKey, log);
|
||||
free(log);
|
||||
}
|
||||
GLint link_success = GL_FALSE;
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_LINK_STATUS, &link_success));
|
||||
|
||||
// Get uniform locations
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTION] = glGetUniformLocation(m_iProgram, "material_reflection"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY] = glGetUniformLocation(m_iProgram, "material_reflectivity"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION] = glGetUniformLocation(m_iProgram, "light_position"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "view_space_light_position"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_COLOR] = glGetUniformLocation(m_iProgram, "light_color"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_INTENSITY] = glGetUniformLocation(m_iProgram, "light_intensity"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DECAY_START] = glGetUniformLocation(m_iProgram, "light_decay_start"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_CUTOFF] = glGetUniformLocation(m_iProgram, "light_cutoff"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_FLARE_SIZE] = glGetUniformLocation(m_iProgram, "flare_size"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "mvp_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVP] = glGetUniformLocation(m_iProgram, "inv_projection_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MN2V] = glGetUniformLocation(m_iProgram, "model_normal_to_view_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_to_view_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_V2M] = glGetUniformLocation(m_iProgram, "view_to_model_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION] = glGetUniformLocation(m_iProgram, "light_direction"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "light_direction_view_space"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS] = glGetUniformLocation(m_iProgram, "cameraPosition"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_VIEWPORT] = glGetUniformLocation(m_iProgram, "viewport"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE] = glGetUniformLocation(m_iProgram, "reflectionTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "diffuseTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "specularTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "reflectionTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "normalTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "ambientTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "diffuseTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "specularTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "reflectionTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "normalTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "ambientTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] = glGetUniformLocation(m_iProgram, "shadowTexture1"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] = glGetUniformLocation(m_iProgram, "shadowTexture2"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME] = glGetUniformLocation(m_iProgram, "gbuffer_frame"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH] = glGetUniformLocation(m_iProgram, "gbuffer_depth"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME] = glGetUniformLocation(m_iProgram, "depthFrame"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME] = glGetUniformLocation(m_iProgram, "renderFrame"));
|
||||
if(link_success != GL_TRUE) {
|
||||
// Report any linking issues to stderr
|
||||
fprintf(stderr, "KREngine - Failed to link shader program: %s\n", szKey);
|
||||
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
assert(log != NULL);
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
fprintf(stderr, "Program link log:\n%s", log);
|
||||
free(log);
|
||||
}
|
||||
GLDEBUG(glDeleteProgram(m_iProgram));
|
||||
m_iProgram = 0;
|
||||
} else {
|
||||
|
||||
// Get uniform locations
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTION] = glGetUniformLocation(m_iProgram, "material_reflection"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY] = glGetUniformLocation(m_iProgram, "material_reflectivity"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION] = glGetUniformLocation(m_iProgram, "light_position"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "view_space_light_position"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_COLOR] = glGetUniformLocation(m_iProgram, "light_color"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_INTENSITY] = glGetUniformLocation(m_iProgram, "light_intensity"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DECAY_START] = glGetUniformLocation(m_iProgram, "light_decay_start"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_CUTOFF] = glGetUniformLocation(m_iProgram, "light_cutoff"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_FLARE_SIZE] = glGetUniformLocation(m_iProgram, "flare_size"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "mvp_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVP] = glGetUniformLocation(m_iProgram, "inv_projection_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MN2V] = glGetUniformLocation(m_iProgram, "model_normal_to_view_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_to_view_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_V2M] = glGetUniformLocation(m_iProgram, "view_to_model_matrix"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION] = glGetUniformLocation(m_iProgram, "light_direction"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "light_direction_view_space"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS] = glGetUniformLocation(m_iProgram, "cameraPosition"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_VIEWPORT] = glGetUniformLocation(m_iProgram, "viewport"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE] = glGetUniformLocation(m_iProgram, "reflectionTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "diffuseTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "specularTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "reflectionTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "normalTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "ambientTexture_Scale"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "diffuseTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "specularTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "reflectionTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "normalTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_AMBIENTTEXTURE_OFFSET] = glGetUniformLocation(m_iProgram, "ambientTexture_Offset"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] = glGetUniformLocation(m_iProgram, "shadowTexture1"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] = glGetUniformLocation(m_iProgram, "shadowTexture2"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME] = glGetUniformLocation(m_iProgram, "gbuffer_frame"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH] = glGetUniformLocation(m_iProgram, "gbuffer_depth"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME] = glGetUniformLocation(m_iProgram, "depthFrame"));
|
||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME] = glGetUniformLocation(m_iProgram, "renderFrame"));
|
||||
}
|
||||
|
||||
} catch(...) {
|
||||
if(vertexShader) {
|
||||
@@ -181,7 +194,12 @@ KRShader::~KRShader() {
|
||||
|
||||
#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) {
|
||||
bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
if(m_iProgram == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
GLDEBUG(glUseProgram(m_iProgram));
|
||||
|
||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||
@@ -251,12 +269,15 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength);
|
||||
assert(log != NULL);
|
||||
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);
|
||||
free(log);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
bool bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -40,12 +40,14 @@
|
||||
/* The pixel dimensions of the backbuffer */
|
||||
GLint backingWidth, backingHeight;
|
||||
|
||||
EAGLContext *context;
|
||||
|
||||
|
||||
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
|
||||
GLuint viewFramebuffer, viewRenderbuffer;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) EAGLContext *context;
|
||||
|
||||
// OpenGL drawing
|
||||
- (BOOL)createFramebuffers;
|
||||
- (void)destroyFramebuffer;
|
||||
|
||||
@@ -57,15 +57,15 @@
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
|
||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
|
||||
if (!context)
|
||||
if (!_context)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (![EAGLContext setCurrentContext:context])
|
||||
if (![EAGLContext setCurrentContext:_context])
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
@@ -86,6 +86,7 @@
|
||||
|
||||
- (void)dealloc {
|
||||
[_engine release]; _engine = nil;
|
||||
[_context release]; _context = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -123,7 +124,7 @@
|
||||
// ----- Create color buffer for viewFramebuffer -----
|
||||
GLDEBUG(glGenRenderbuffers(1, &viewRenderbuffer));
|
||||
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth));
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight));
|
||||
NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);
|
||||
@@ -166,7 +167,7 @@
|
||||
|
||||
- (void)setDisplayFramebuffer;
|
||||
{
|
||||
if (context)
|
||||
if (_context)
|
||||
{
|
||||
if (!viewFramebuffer)
|
||||
{
|
||||
@@ -183,11 +184,11 @@
|
||||
{
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (context)
|
||||
if (_context)
|
||||
{
|
||||
//GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||
|
||||
success = [context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
success = [_context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
@@ -163,11 +163,13 @@
|
||||
cParamDisplayFrames = 0;
|
||||
|
||||
camera_position = KRVector3(-85, -1, -70);
|
||||
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView:)];
|
||||
[displayLink setFrameInterval:2]; // Maximum 30fps
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
|
||||
_lastTime= [displayLink timestamp];
|
||||
}
|
||||
|
||||
@@ -181,93 +183,97 @@
|
||||
|
||||
- (void)drawView:(id)sender
|
||||
{
|
||||
glGetError(); // Clear any prior errors...
|
||||
|
||||
|
||||
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
||||
|
||||
NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
CFTimeInterval time = [displayLink timestamp];
|
||||
float deltaTime = (time - _lastTime);
|
||||
_lastTime = time;
|
||||
|
||||
const GLfloat PI = 3.14159265;
|
||||
const GLfloat d2r = PI * 2 / 360;
|
||||
|
||||
|
||||
KREngine *engine = glView.engine;
|
||||
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
|
||||
if(iParam > [engine getParameterCount]) {
|
||||
iParam = [engine getParameterCount];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
|
||||
cParamDisplayFrames--;
|
||||
char szText[256];
|
||||
const char *szName = [[engine getParameterLabelWithIndex: iParam] UTF8String];
|
||||
double dValue = [engine getParameterValueWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
sprintf(szText, "%s: %i", szName, (int)dValue);
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
sprintf(szText, "%s: %s", szName, dValue == 0.0 ? "false" : "true");
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
sprintf(szText, "%s: %f", szName, dValue);
|
||||
break;
|
||||
}
|
||||
NSString *debug_text = [[NSString alloc] initWithUTF8String:szText];
|
||||
engine.debug_text = debug_text;
|
||||
[debug_text release];
|
||||
} else {
|
||||
engine.debug_text = @"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bUpdateParam) {
|
||||
bUpdateParam = false;
|
||||
if(glView.context && glView.engine) {
|
||||
//glGetError(); // Clear any prior errors...
|
||||
|
||||
double dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] + 0.5 - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
[engine setParameterValueWithIndex: iParam Value: 1.0 - dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
|
||||
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
||||
|
||||
//NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
CFTimeInterval time = [displayLink timestamp];
|
||||
float deltaTime = (time - _lastTime);
|
||||
_lastTime = time;
|
||||
|
||||
const GLfloat PI = 3.14159265;
|
||||
const GLfloat d2r = PI * 2 / 360;
|
||||
|
||||
|
||||
KREngine *engine = glView.engine;
|
||||
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
|
||||
if(iParam > [engine getParameterCount]) {
|
||||
iParam = [engine getParameterCount];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
|
||||
cParamDisplayFrames--;
|
||||
char szText[256];
|
||||
const char *szName = [[engine getParameterLabelWithIndex: iParam] UTF8String];
|
||||
double dValue = [engine getParameterValueWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
sprintf(szText, "%s: %i", szName, (int)dValue);
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
sprintf(szText, "%s: %s", szName, dValue == 0.0 ? "false" : "true");
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
sprintf(szText, "%s: %f", szName, dValue);
|
||||
break;
|
||||
}
|
||||
NSString *debug_text = [[NSString alloc] initWithUTF8String:szText];
|
||||
engine.debug_text = debug_text;
|
||||
[debug_text release];
|
||||
} else {
|
||||
engine.debug_text = @"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bUpdateParam) {
|
||||
bUpdateParam = false;
|
||||
|
||||
double dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] + 0.5 - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
[engine setParameterValueWithIndex: iParam Value: 1.0 - dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double dScaleFactor = 200.0f * deltaTime;
|
||||
|
||||
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.x += (cos(camera_pitch) * sin(camera_yaw) * leftStickDeltaX + cos(camera_pitch) * sin(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.y += sin(camera_pitch) * leftStickDeltaX * dScaleFactor;
|
||||
camera_yaw += rightStickDeltaY * 180.0 * d2r * deltaTime;
|
||||
camera_pitch += rightStickDeltaX * 180.0 * d2r * deltaTime;
|
||||
|
||||
|
||||
|
||||
assert([EAGLContext setCurrentContext:glView.context]);
|
||||
[glView setDisplayFramebuffer];
|
||||
KRScene *scene = [glView getScene];
|
||||
[engine renderScene: scene WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
|
||||
[glView presentFramebuffer];
|
||||
|
||||
//[framePool release];
|
||||
|
||||
double frameTime = CACurrentMediaTime() - frame_start_time;
|
||||
|
||||
//NSLog(@"frameTime = %.1f ms (%.2f fps / %.2f fps) - %.2f%%", frameTime * 1000.0f, 1.0f / frameTime, 1.0f / deltaTime, frameTime / deltaTime * 100.0f);
|
||||
}
|
||||
|
||||
double dScaleFactor = 200.0f * deltaTime;
|
||||
|
||||
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.x += (cos(camera_pitch) * sin(camera_yaw) * leftStickDeltaX + cos(camera_pitch) * sin(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.y += sin(camera_pitch) * leftStickDeltaX * dScaleFactor;
|
||||
camera_yaw += rightStickDeltaY * 180.0 * d2r * deltaTime;
|
||||
camera_pitch += rightStickDeltaX * 180.0 * d2r * deltaTime;
|
||||
|
||||
|
||||
[glView setDisplayFramebuffer];
|
||||
KRScene *scene = [glView getScene];
|
||||
[engine renderScene: scene WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
|
||||
[glView presentFramebuffer];
|
||||
|
||||
[framePool release];
|
||||
|
||||
double frameTime = CACurrentMediaTime() - frame_start_time;
|
||||
|
||||
//NSLog(@"frameTime = %.1f ms (%.2f fps / %.2f fps) - %.2f%%", frameTime * 1000.0f, 1.0f / frameTime, 1.0f / deltaTime, frameTime / deltaTime * 100.0f);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user