diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index 8a22b35..423deb2 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -275,6 +275,9 @@ E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture2D.cpp */; }; E4F975541536340400FD60B2 /* KRTexture2D.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture2D.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E4FE6AA816B21D660058B8CE /* forsyth.h in Headers */ = {isa = PBXBuildFile; fileRef = E4FE6AA716B21D660058B8CE /* forsyth.h */; }; + E4FE6AA916B21D660058B8CE /* forsyth.h in Headers */ = {isa = PBXBuildFile; fileRef = E4FE6AA716B21D660058B8CE /* forsyth.h */; }; + E4FE6AAB16B21D7E0058B8CE /* forsyth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4FE6AAA16B21D7E0058B8CE /* forsyth.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXBuildRule section */ @@ -502,6 +505,8 @@ E4F027F91698116000D4427D /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; E4F975311536220900FD60B2 /* KRNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRNode.h; path = Classes/KRNode.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E4F975351536221C00FD60B2 /* KRNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRNode.cpp; path = Classes/KRNode.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E4FE6AA716B21D660058B8CE /* forsyth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = forsyth.h; path = KREngine/Classes/forsyth.h; sourceTree = ""; }; + E4FE6AAA16B21D7E0058B8CE /* forsyth.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = forsyth.cpp; path = KREngine/Classes/forsyth.cpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1016,12 +1021,22 @@ E4F9753815362A5200FD60B2 /* 3rdparty */ = { isa = PBXGroup; children = ( + E4FE6AA516B21D330058B8CE /* forsyth */, E46C214015364BB8009CABF3 /* tinyxml2 */, ); name = 3rdparty; path = ..; sourceTree = ""; }; + E4FE6AA516B21D330058B8CE /* forsyth */ = { + isa = PBXGroup; + children = ( + E4FE6AA716B21D660058B8CE /* forsyth.h */, + E4FE6AAA16B21D7E0058B8CE /* forsyth.cpp */, + ); + name = forsyth; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1090,6 +1105,7 @@ E499BF1E16AE751E007FCDBE /* KRSceneManager.h in Headers */, E499BF2016AE755B007FCDBE /* KRPointLight.h in Headers */, E499BF2116AE75A7007FCDBE /* KREngine-common.h in Headers */, + E4FE6AA816B21D660058B8CE /* forsyth.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1163,6 +1179,7 @@ E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */, E499BF2216AE760F007FCDBE /* krengine_osx.h in Headers */, E499BF2316AE7636007FCDBE /* krengine_osx-Prefix.pch in Headers */, + E4FE6AA916B21D660058B8CE /* forsyth.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1308,6 +1325,7 @@ E4F027CE16979CE200D4427D /* KRAudioSample.cpp in Sources */, E4F027DE1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */, E4943231169E08D200BCB891 /* KRReverbZone.cpp in Sources */, + E4FE6AAB16B21D7E0058B8CE /* forsyth.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/KREngine/Classes/KRCamera.cpp b/KREngine/KREngine/Classes/KRCamera.cpp index 39d8ee4..d153471 100644 --- a/KREngine/KREngine/Classes/KRCamera.cpp +++ b/KREngine/KREngine/Classes/KRCamera.cpp @@ -235,7 +235,7 @@ void KRCamera::renderFrame(float deltaTime) getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture); // Render a full screen quad - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } @@ -371,7 +371,7 @@ void KRCamera::renderFrame(float deltaTime) KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, true, false, false, false, false, false, false); for(std::map::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { KRMat4 matModel = KRMat4(); matModel.scale((*itr).first.size() / 2.0f); @@ -599,7 +599,7 @@ void KRCamera::renderPost() } // Update attribute values. - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); @@ -621,7 +621,7 @@ void KRCamera::renderPost() // viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0); // getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); // m_pContext->getTextureManager()->selectTexture(1, NULL); -// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false); +// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false); // GLDEBUG(glActiveTexture(GL_TEXTURE0)); // GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow])); //#if GL_EXT_shadow_samplers diff --git a/KREngine/KREngine/Classes/KRDirectionalLight.cpp b/KREngine/KREngine/Classes/KRDirectionalLight.cpp index 5e575c0..bb75635 100644 --- a/KREngine/KREngine/Classes/KRDirectionalLight.cpp +++ b/KREngine/KREngine/Classes/KRDirectionalLight.cpp @@ -133,7 +133,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector &light 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, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } } diff --git a/KREngine/KREngine/Classes/KREngine.mm b/KREngine/KREngine/Classes/KREngine.mm index 047658f..0d83a92 100644 --- a/KREngine/KREngine/Classes/KREngine.mm +++ b/KREngine/KREngine/Classes/KREngine.mm @@ -563,12 +563,11 @@ using namespace std; -(float)getParameterMinWithIndex: (int)i { float minValues[48] = { - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.01f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; return minValues[i]; @@ -577,13 +576,11 @@ using namespace std; -(float)getParameterMaxWithIndex: (int)i { float maxValues[48] = { - PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, - 1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, - 0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 1000.0f, 10000.0f, - 1.0f, 5.0f, 10000.0f, 1.0f, 5.0f, - 3.0f, 10000.0f, 10000.0f, 0.01f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f + PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, + 1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, 0.5f, 1.0f, + 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 10.0f, 1000.0f, 1.0f, 5.0f, 1000.0f, 1.0f, 5.0f, 3.0f, + 1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; return maxValues[i]; diff --git a/KREngine/KREngine/Classes/KRLight.cpp b/KREngine/KREngine/Classes/KRLight.cpp index d53f639..ca3b7f4 100644 --- a/KREngine/KREngine/Classes/KRLight.cpp +++ b/KREngine/KREngine/Classes/KRLight.cpp @@ -212,7 +212,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR GLDEBUG(glUniform1f(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE], m_dust_particle_size)); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } @@ -239,7 +239,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR KRVector2(slice_near, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]); (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRMeshManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRMeshManager::VolumetricLightingVertexData), true, false, false, false, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRMeshManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRMeshManager::VolumetricLightingVertexData), NULL, 0, true, false, false, false, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6)); } @@ -301,7 +301,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR 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, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } } diff --git a/KREngine/KREngine/Classes/KRMesh.cpp b/KREngine/KREngine/Classes/KRMesh.cpp index b447af4..c234511 100644 --- a/KREngine/KREngine/Classes/KRMesh.cpp +++ b/KREngine/KREngine/Classes/KRMesh.cpp @@ -272,7 +272,7 @@ void KRMesh::renderSubmesh(int iSubmesh) { assert(cBufferVertexes <= 65535); - m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, has_vertex_attribute(KRENGINE_ATTRIB_VERTEX), has_vertex_attribute(KRENGINE_ATTRIB_NORMAL), has_vertex_attribute(KRENGINE_ATTRIB_TANGENT), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB), has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES), + m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, NULL, 0, has_vertex_attribute(KRENGINE_ATTRIB_VERTEX), has_vertex_attribute(KRENGINE_ATTRIB_NORMAL), has_vertex_attribute(KRENGINE_ATTRIB_TANGENT), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA), has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB), has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES), has_vertex_attribute(KRENGINE_ATTRIB_BONEWEIGHTS)); @@ -285,6 +285,12 @@ void KRMesh::renderSubmesh(int iSubmesh) { case KRENGINE_MODEL_FORMAT_STRIP: GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, iVertex, (MAX_VBO_SIZE - iVertex))); break; + case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES: + GLDEBUG(glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex))); + break; + case KRENGINE_MODEL_FORMAT_INDEXED_STRIP: + GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, iVertex, (MAX_VBO_SIZE - iVertex))); + break; default: break; } diff --git a/KREngine/KREngine/Classes/KRMeshManager.cpp b/KREngine/KREngine/Classes/KRMeshManager.cpp index 5cdb619..4715e1f 100644 --- a/KREngine/KREngine/Classes/KRMeshManager.cpp +++ b/KREngine/KREngine/Classes/KRMeshManager.cpp @@ -38,8 +38,9 @@ #include "KRMeshSphere.h" KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) { - m_currentVBO.vbo_handle = 0; - m_currentVBO.vao_handle = 0; + m_currentVBO.vbo_handle = -1; + m_currentVBO.vbo_handle_indexes = -1; + m_currentVBO.vao_handle = -1; m_currentVBO.data = NULL; m_vboMemUsed = 0; m_randomParticleVertexData = NULL; @@ -103,14 +104,16 @@ std::multimap KRMeshManager::getModels() { void KRMeshManager::unbindVBO() { if(m_currentVBO.data != NULL) { GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, 0)); + GLDEBUG(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); m_currentVBO.size = 0; m_currentVBO.data = NULL; m_currentVBO.vbo_handle = -1; + m_currentVBO.vbo_handle_indexes = -1; m_currentVBO.vao_handle = -1; } } -void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) { +void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights) { if(m_currentVBO.data != data || m_currentVBO.size != size) { @@ -146,6 +149,9 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, b GLDEBUG(glDeleteVertexArraysOES(1, &firstVBO.vao_handle)); #endif GLDEBUG(glDeleteBuffers(1, &firstVBO.vbo_handle)); + if(firstVBO.vbo_handle_indexes != -1) { + GLDEBUG(glDeleteBuffers(1, &firstVBO.vbo_handle_indexes)); + } m_vboMemUsed -= firstVBO.size; m_vbosPool.erase(first_itr); fprintf(stderr, "VBO Swapping...\n"); @@ -153,6 +159,7 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, b m_currentVBO.vao_handle = -1; m_currentVBO.vbo_handle = -1; + m_currentVBO.vbo_handle_indexes = -1; GLDEBUG(glGenBuffers(1, &m_currentVBO.vbo_handle)); #if GL_OES_vertex_array_object GLDEBUG(glGenVertexArraysOES(1, &m_currentVBO.vao_handle)); diff --git a/KREngine/KREngine/Classes/KRMeshManager.h b/KREngine/KREngine/Classes/KRMeshManager.h index 9004a19..50b3ce2 100644 --- a/KREngine/KREngine/Classes/KRMeshManager.h +++ b/KREngine/KREngine/Classes/KRMeshManager.h @@ -57,7 +57,7 @@ public: std::multimap getModels(); - void bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights); + void bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights); void unbindVBO(); long getMemUsed(); @@ -92,6 +92,7 @@ private: typedef struct vbo_info { GLuint vbo_handle; + GLuint vbo_handle_indexes; GLuint vao_handle; GLsizeiptr size; GLvoid *data; diff --git a/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp index 7f069db..22f49e8 100644 --- a/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp +++ b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp @@ -81,7 +81,7 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector 1.0f )); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false, false, false); + m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } @@ -109,7 +109,7 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector // 1.0f // )); // -// m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), true, false, false, true, false); +// m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, true, false, false, true, false); // GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); // } //// } diff --git a/KREngine/KREngine/Classes/KRPointLight.cpp b/KREngine/KREngine/Classes/KRPointLight.cpp index cf7f1be..2584b0b 100644 --- a/KREngine/KREngine/Classes/KRPointLight.cpp +++ b/KREngine/KREngine/Classes/KRPointLight.cpp @@ -108,7 +108,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &lights, con 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, false, false); + m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } else { #if GL_OES_vertex_array_object diff --git a/KREngine/KREngine/Classes/KRRenderSettings.cpp b/KREngine/KREngine/Classes/KRRenderSettings.cpp index 05e49cc..ca1441c 100644 --- a/KREngine/KREngine/Classes/KRRenderSettings.cpp +++ b/KREngine/KREngine/Classes/KRRenderSettings.cpp @@ -32,8 +32,8 @@ KRRenderSettings::KRRenderSettings() light_intensity = KRVector3::One(); perspective_fov = 45.0 * D2R; - perspective_nearz = 5.0f; - perspective_farz = 100.0f; + perspective_nearz = 0.05f; + perspective_farz = 1000.0f; dof_quality = 0; dof_depth = 0.05f; @@ -59,13 +59,13 @@ KRRenderSettings::KRRenderSettings() volumetric_environment_enable = false; volumetric_environment_downsample = 2; - volumetric_environment_max_distance = 1000.0f; + volumetric_environment_max_distance = 100.0f; volumetric_environment_quality = (50 - 5.0) / 495.0f; volumetric_environment_intensity = 0.9f; - fog_near = 500.0f; - fog_far = 5000.0f; + fog_near = 50.0f; + fog_far = 500.0f; fog_density = 0.0005f; fog_color = KRVector3(0.45, 0.45, 0.5); fog_type = 0; diff --git a/KREngine/KREngine/Classes/KRScene.cpp b/KREngine/KREngine/Classes/KRScene.cpp index d6ca80f..a53a9f0 100644 --- a/KREngine/KREngine/Classes/KRScene.cpp +++ b/KREngine/KREngine/Classes/KRScene.cpp @@ -240,7 +240,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::map &visibleBo KRMat4 mvpmatrix = matModel * viewport.getViewProjectionMatrix(); - getContext().getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false, false, false); + getContext().getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, true, false, false, false, false, false, false); // Enable additive blending if(renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { diff --git a/KREngine/KREngine/Classes/KRShaderManager.cpp b/KREngine/KREngine/Classes/KRShaderManager.cpp index e56cdff..399ef63 100644 --- a/KREngine/KREngine/Classes/KRShaderManager.cpp +++ b/KREngine/KREngine/Classes/KRShaderManager.cpp @@ -51,10 +51,10 @@ KRShaderManager::~KRShaderManager() { KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass) { std::string platform_shader_name = shader_name; -#if TARGET_OS_MAC - platform_shader_name = shader_name + "_osx"; -#else +#if TARGET_OS_IPHONE platform_shader_name = shader_name; +#else + platform_shader_name = shader_name + "_osx"; #endif int iShadowQuality = 0; // FINDME - HACK - Placeholder code, need to iterate through lights and dynamically build shader @@ -99,7 +99,8 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p stringstream stream; stream.precision(std::numeric_limits::digits10); -#if TARGET_OS_MAC +#if TARGET_OS_IPHONE +#else stream << "\n#version 120"; stream << "\n#define lowp"; stream << "\n#define mediump"; diff --git a/KREngine/KREngine/Classes/forsyth.cpp b/KREngine/KREngine/Classes/forsyth.cpp new file mode 100644 index 0000000..a92e09e --- /dev/null +++ b/KREngine/KREngine/Classes/forsyth.cpp @@ -0,0 +1,351 @@ +//----------------------------------------------------------------------------- +// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache +// Optimization" algorithm as described here: +// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html +// +// This code was authored and released into the public domain by +// Adrian Stone (stone@gameangst.com). +// +// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER +// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#include "forsyth.h" +#include +#include +#include +#include +#include + +namespace Forsyth +{ + typedef unsigned int uint; + typedef unsigned short uint16; + typedef unsigned char byte; + + //----------------------------------------------------------------------------- + // OptimizeFaces + //----------------------------------------------------------------------------- + // Parameters: + // indexList + // input index list + // indexCount + // the number of indices in the list + // vertexCount + // the largest index value in indexList + // newIndexList + // a pointer to a preallocated buffer the same size as indexList to + // hold the optimized index list + // lruCacheSize + // the size of the simulated post-transform cache (max:64) + //----------------------------------------------------------------------------- + void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize); + + namespace + { + // code for computing vertex score was taken, as much as possible + // directly from the original publication. + float ComputeVertexCacheScore(int cachePosition, uint vertexCacheSize) + { + const float FindVertexScore_CacheDecayPower = 1.5f; + const float FindVertexScore_LastTriScore = 0.75f; + + float score = 0.0f; + if ( cachePosition < 0 ) + { + // Vertex is not in FIFO cache - no score. + } + else + { + if ( cachePosition < 3 ) + { + // This vertex was used in the last triangle, + // so it has a fixed score, whichever of the three + // it's in. Otherwise, you can get very different + // answers depending on whether you add + // the triangle 1,2,3 or 3,1,2 - which is silly. + score = FindVertexScore_LastTriScore; + } + else + { + assert ( cachePosition < vertexCacheSize ); + // Points for being high in the cache. + const float scaler = 1.0f / ( vertexCacheSize - 3 ); + score = 1.0f - ( cachePosition - 3 ) * scaler; + score = powf ( score, FindVertexScore_CacheDecayPower ); + } + } + + return score; + } + + float ComputeVertexValenceScore(uint numActiveFaces) + { + const float FindVertexScore_ValenceBoostScale = 2.0f; + const float FindVertexScore_ValenceBoostPower = 0.5f; + + float score = 0.f; + + // Bonus points for having a low number of tris still to + // use the vert, so we get rid of lone verts quickly. + float valenceBoost = powf ( static_cast(numActiveFaces), + -FindVertexScore_ValenceBoostPower ); + score += FindVertexScore_ValenceBoostScale * valenceBoost; + + return score; + } + + + const uint kMaxVertexCacheSize = 64; + const uint kMaxPrecomputedVertexValenceScores = 64; + float s_vertexCacheScores[kMaxVertexCacheSize+1][kMaxVertexCacheSize]; + float s_vertexValenceScores[kMaxPrecomputedVertexValenceScores]; + + bool ComputeVertexScores() + { + for (uint cacheSize=0; cacheSize<=kMaxVertexCacheSize; ++cacheSize) + { + for (uint cachePos=0; cachePos vertexDataList; + vertexDataList.resize(vertexCount); + + // compute face count per vertex + for (uint i=0; i activeFaceList; + + const uint16 kEvictedCacheIndex = std::numeric_limits::max(); + + { + // allocate face list per vertex + uint curActiveFaceListPos = 0; + for (uint i=0; i processedFaceList; + processedFaceList.resize(indexCount); + + uint16 vertexCacheBuffer[(kMaxVertexCacheSize+3)*2]; + uint16* cache0 = vertexCacheBuffer; + uint16* cache1 = vertexCacheBuffer+(kMaxVertexCacheSize+3); + uint16 entriesInCache0 = 0; + + uint bestFace = 0; + float bestScore = -1.f; + + const float maxValenceScore = FindVertexScore(1, kEvictedCacheIndex, lruCacheSize) * 3.f; + + for (uint i = 0; i < indexCount; i += 3) + { + if (bestScore < 0.f) + { + // no verts in the cache are used by any unprocessed faces so + // search all unprocessed faces for a new starting point + for (uint j = 0; j < indexCount; j += 3) + { + if (processedFaceList[j] == 0) + { + uint face = j; + float faceScore = 0.f; + for (uint k=0; k<3; ++k) + { + uint16 index = indexList[face+k]; + OptimizeVertexData& vertexData = vertexDataList[index]; + assert(vertexData.activeFaceListSize > 0); + assert(vertexData.cachePos0 >= lruCacheSize); + faceScore += vertexData.score; + } + + if (faceScore > bestScore) + { + bestScore = faceScore; + bestFace = face; + + assert(bestScore <= maxValenceScore); + if (bestScore >= maxValenceScore) + { + break; + } + } + } + } + assert(bestScore >= 0.f); + } + + processedFaceList[bestFace] = 1; + uint16 entriesInCache1 = 0; + + // add bestFace to LRU cache and to newIndexList + for (uint v = 0; v < 3; ++v) + { + uint16 index = indexList[bestFace+v]; + newIndexList[i+v] = index; + + OptimizeVertexData& vertexData = vertexDataList[index]; + + if (vertexData.cachePos1 >= entriesInCache1) + { + vertexData.cachePos1 = entriesInCache1; + cache1[entriesInCache1++] = index; + + if (vertexData.activeFaceListSize == 1) + { + --vertexData.activeFaceListSize; + continue; + } + } + + assert(vertexData.activeFaceListSize > 0); + uint* begin = &activeFaceList[vertexData.activeFaceListStart]; + uint* end = &activeFaceList[vertexData.activeFaceListStart + vertexData.activeFaceListSize]; + uint* it = std::find(begin, end, bestFace); + assert(it != end); + std::swap(*it, *(end-1)); + --vertexData.activeFaceListSize; + vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize); + + } + + // move the rest of the old verts in the cache down and compute their new scores + for (uint c0 = 0; c0 < entriesInCache0; ++c0) + { + uint16 index = cache0[c0]; + OptimizeVertexData& vertexData = vertexDataList[index]; + + if (vertexData.cachePos1 >= entriesInCache1) + { + vertexData.cachePos1 = entriesInCache1; + cache1[entriesInCache1++] = index; + vertexData.score = FindVertexScore(vertexData.activeFaceListSize, vertexData.cachePos1, lruCacheSize); + } + } + + // find the best scoring triangle in the current cache (including up to 3 that were just evicted) + bestScore = -1.f; + for (uint c1 = 0; c1 < entriesInCache1; ++c1) + { + uint16 index = cache1[c1]; + OptimizeVertexData& vertexData = vertexDataList[index]; + vertexData.cachePos0 = vertexData.cachePos1; + vertexData.cachePos1 = kEvictedCacheIndex; + for (uint j=0; j bestScore) + { + bestScore = faceScore; + bestFace = face; + } + } + } + + std::swap(cache0, cache1); + entriesInCache0 = std::min(entriesInCache1, lruCacheSize); + } + } + +} // namespace Forsyth \ No newline at end of file diff --git a/KREngine/KREngine/Classes/forsyth.h b/KREngine/KREngine/Classes/forsyth.h new file mode 100644 index 0000000..9834554 --- /dev/null +++ b/KREngine/KREngine/Classes/forsyth.h @@ -0,0 +1,44 @@ +//----------------------------------------------------------------------------- +// This is an implementation of Tom Forsyth's "Linear-Speed Vertex Cache +// Optimization" algorithm as described here: +// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html +// +// This code was authored and released into the public domain by +// Adrian Stone (stone@gameangst.com). +// +// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +// SHALL ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER +// LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef KRENGINE_FORSYTH_H +#define KRENGINE_FORSYTH_H + +namespace Forsyth { + typedef unsigned int uint; + typedef unsigned short uint16; + typedef unsigned char byte; + + //----------------------------------------------------------------------------- + // OptimizeFaces + //----------------------------------------------------------------------------- + // Parameters: + // indexList + // input index list + // indexCount + // the number of indices in the list + // vertexCount + // the largest index value in indexList + // newIndexList + // a pointer to a preallocated buffer the same size as indexList to + // hold the optimized index list + // lruCacheSize + // the size of the simulated post-transform cache (max:64) + //----------------------------------------------------------------------------- + void OptimizeFaces(const uint16* indexList, uint indexCount, uint vertexCount, uint16* newIndexList, uint16 lruCacheSize); +}; + +#endif