Implemented KRBundle's

Implementation of logic to allow dynamic loading and unloading of meshes and models for scenes larger than RAM in progress

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4090
This commit is contained in:
kearwood
2012-09-11 03:06:35 +00:00
parent c7b7c20310
commit 34c7dc7b53
57 changed files with 1841 additions and 1089 deletions

View File

@@ -23,6 +23,8 @@
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = E42CB1EB158446940066E0D8 /* KRQuaternion.h */; };
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
E430D08115F8882F0010558D /* occlusion_test.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08015F8882F0010558D /* occlusion_test.fsh */; };
E430D08915F88AD10010558D /* occlusion_test.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08815F88AD10010558D /* occlusion_test.vsh */; };
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; };
@@ -67,7 +69,7 @@
E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; };
E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; };
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; };
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; settings = {ATTRIBUTES = (Public, ); }; };
E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; };
E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; };
E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -75,7 +77,15 @@
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; };
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; };
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A813F4F6DD00FF4370 /* KRShader.cpp */; };
E48278B115F03028001C9431 /* visualize_overlay.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E48278B015F03028001C9431 /* visualize_overlay.fsh */; };
E488399415F928CA00BD66D5 /* KRBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E488399215F928CA00BD66D5 /* KRBundle.cpp */; };
E488399515F928CA00BD66D5 /* KRBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E488399215F928CA00BD66D5 /* KRBundle.cpp */; };
E488399615F928CA00BD66D5 /* KRBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = E488399315F928CA00BD66D5 /* KRBundle.h */; };
E488399715F928CA00BD66D5 /* KRBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = E488399315F928CA00BD66D5 /* KRBundle.h */; settings = {ATTRIBUTES = (Public, ); }; };
E488399C15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E488399A15F92BE000BD66D5 /* KRBundleManager.cpp */; };
E488399D15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E488399A15F92BE000BD66D5 /* KRBundleManager.cpp */; };
E488399E15F92BE000BD66D5 /* KRBundleManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E488399B15F92BE000BD66D5 /* KRBundleManager.h */; };
E488399F15F92BE000BD66D5 /* KRBundleManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E488399B15F92BE000BD66D5 /* KRBundleManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E48839A115F92C2800BD66D5 /* visualize_overlay.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */; };
E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B3CBC14393DF5000C50E2 /* KRCamera.h */; };
E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */; };
E48C696F15374F5B00232E28 /* KRContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E48C696E15374F5A00232E28 /* KRContext.h */; };
@@ -189,6 +199,8 @@
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRBoundingVolume.cpp; path = Classes/KRBoundingVolume.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E42CB1EB158446940066E0D8 /* KRQuaternion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRQuaternion.h; path = Classes/KRQuaternion.h; sourceTree = "<group>"; };
E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRQuaternion.cpp; path = Classes/KRQuaternion.cpp; sourceTree = "<group>"; };
E430D08015F8882F0010558D /* occlusion_test.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.fsh; path = Shaders/occlusion_test.fsh; sourceTree = "<group>"; };
E430D08815F88AD10010558D /* occlusion_test.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.vsh; path = Shaders/occlusion_test.vsh; sourceTree = "<group>"; };
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRNotified.cpp; path = Classes/KRNotified.cpp; sourceTree = "<group>"; };
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRNotified.h; path = Classes/KRNotified.h; sourceTree = "<group>"; };
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = "<group>"; };
@@ -227,7 +239,11 @@
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShader.cpp; path = Classes/KRShader.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E48278AE15F03010001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.vsh; path = Shaders/visualize_overlay.vsh; sourceTree = "<group>"; };
E48278B015F03028001C9431 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = visualize_overlay.fsh; sourceTree = "<group>"; };
E488399215F928CA00BD66D5 /* KRBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRBundle.cpp; path = Classes/KRBundle.cpp; sourceTree = "<group>"; };
E488399315F928CA00BD66D5 /* KRBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRBundle.h; path = Classes/KRBundle.h; sourceTree = "<group>"; };
E488399A15F92BE000BD66D5 /* KRBundleManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRBundleManager.cpp; path = Classes/KRBundleManager.cpp; sourceTree = "<group>"; };
E488399B15F92BE000BD66D5 /* KRBundleManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRBundleManager.h; path = Classes/KRBundleManager.h; sourceTree = "<group>"; };
E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.fsh; path = Shaders/visualize_overlay.fsh; sourceTree = "<group>"; };
E48B3CBC14393DF5000C50E2 /* KRCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRCamera.h; path = Classes/KRCamera.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRCamera.cpp; path = Classes/KRCamera.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E48C696E15374F5A00232E28 /* KRContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContext.h; path = Classes/KRContext.h; sourceTree = "<group>"; };
@@ -331,7 +347,9 @@
E4769DEC158A78B6004B83AC /* flare.fsh */,
E4769DEF158A78C6004B83AC /* flare.vsh */,
E48278AE15F03010001C9431 /* visualize_overlay.vsh */,
E48278B015F03028001C9431 /* visualize_overlay.fsh */,
E430D08015F8882F0010558D /* occlusion_test.fsh */,
E430D08815F88AD10010558D /* occlusion_test.vsh */,
E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */,
);
name = Shaders;
sourceTree = "<group>";
@@ -339,9 +357,7 @@
E461A170152E598200F2044A /* Resources */ = {
isa = PBXGroup;
children = (
E48C696C15374A1500232E28 /* Scene Graph */,
E461A174152E5A1300F2044A /* Meshes */,
E461A172152E59BC00F2044A /* Materials */,
E497B949151BCEE900D3DC67 /* KRResource.h */,
E497B94C151BCF2500D3DC67 /* KRResource.cpp */,
E497B94F151BD2CE00D3DC67 /* KRResource+obj.cpp */,
@@ -367,15 +383,6 @@
name = Lights;
sourceTree = "<group>";
};
E461A172152E59BC00F2044A /* Materials */ = {
isa = PBXGroup;
children = (
E491017C13C99BDC0098455B /* KRMaterial.cpp */,
E491017D13C99BDC0098455B /* KRMaterial.h */,
);
name = Materials;
sourceTree = "<group>";
};
E461A173152E59DF00F2044A /* Math */ = {
isa = PBXGroup;
children = (
@@ -414,7 +421,87 @@
name = tinyxml2;
sourceTree = "<group>";
};
E48C696C15374A1500232E28 /* Scene Graph */ = {
E488399915F92BA300BD66D5 /* Managers */ = {
isa = PBXGroup;
children = (
E48839AB15F930E200BD66D5 /* Bundle */,
E48839AA15F9309E00BD66D5 /* Material */,
E48839A915F9307E00BD66D5 /* Model */,
E48839A815F9304C00BD66D5 /* Texture */,
E48839A715F9302E00BD66D5 /* Shader */,
E48839A615F92FC300BD66D5 /* Scene */,
);
name = Managers;
sourceTree = "<group>";
};
E48839A615F92FC300BD66D5 /* Scene */ = {
isa = PBXGroup;
children = (
E46C214915364DDB009CABF3 /* KRSceneManager.h */,
E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */,
E414BAE6143557D200A668C4 /* KRScene.h */,
E414BAE81435585A00A668C4 /* KRScene.cpp */,
E48C696C15374A1500232E28 /* Scene Graph Nodes */,
);
name = Scene;
sourceTree = "<group>";
};
E48839A715F9302E00BD66D5 /* Shader */ = {
isa = PBXGroup;
children = (
E47C25A113F4F65A00FF4370 /* KRShaderManager.h */,
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */,
E47C25A413F4F66F00FF4370 /* KRShader.h */,
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */,
);
name = Shader;
sourceTree = "<group>";
};
E48839A815F9304C00BD66D5 /* Texture */ = {
isa = PBXGroup;
children = (
E491018513C99BDC0098455B /* KRTextureManager.h */,
E491018013C99BDC0098455B /* KRTextureManager.cpp */,
E491018613C99BDC0098455B /* KRTexture.h */,
E491018113C99BDC0098455B /* KRTexture.cpp */,
);
name = Texture;
sourceTree = "<group>";
};
E48839A915F9307E00BD66D5 /* Model */ = {
isa = PBXGroup;
children = (
E491018313C99BDC0098455B /* KRModelManager.h */,
E491018213C99BDC0098455B /* KRModelManager.cpp */,
E491017A13C99BDC0098455B /* KRModel.h */,
E491017913C99BDC0098455B /* KRModel.cpp */,
);
name = Model;
sourceTree = "<group>";
};
E48839AA15F9309E00BD66D5 /* Material */ = {
isa = PBXGroup;
children = (
E491018413C99BDC0098455B /* KRMaterialManager.h */,
E491017B13C99BDC0098455B /* KRMaterialManager.cpp */,
E491017D13C99BDC0098455B /* KRMaterial.h */,
E491017C13C99BDC0098455B /* KRMaterial.cpp */,
);
name = Material;
sourceTree = "<group>";
};
E48839AB15F930E200BD66D5 /* Bundle */ = {
isa = PBXGroup;
children = (
E488399B15F92BE000BD66D5 /* KRBundleManager.h */,
E488399A15F92BE000BD66D5 /* KRBundleManager.cpp */,
E488399315F928CA00BD66D5 /* KRBundle.h */,
E488399215F928CA00BD66D5 /* KRBundle.cpp */,
);
name = Bundle;
sourceTree = "<group>";
};
E48C696C15374A1500232E28 /* Scene Graph Nodes */ = {
isa = PBXGroup;
children = (
E414BAE11435557300A668C4 /* KRInstance.h */,
@@ -422,12 +509,10 @@
E461A171152E599E00F2044A /* Lights */,
E4F975311536220900FD60B2 /* KRNode.h */,
E4F975351536221C00FD60B2 /* KRNode.cpp */,
E414BAE6143557D200A668C4 /* KRScene.h */,
E414BAE81435585A00A668C4 /* KRScene.cpp */,
1000469C15E6EF550053B072 /* KRSkyBox.h */,
1000469B15E6EF550053B072 /* KRSkyBox.cpp */,
);
name = "Scene Graph";
name = "Scene Graph Nodes";
sourceTree = "<group>";
};
E491015613C99B9D0098455B = {
@@ -484,40 +569,25 @@
E491016E13C99BAE0098455B /* Classes */ = {
isa = PBXGroup;
children = (
E4F9753815362A5200FD60B2 /* 3rdparty */,
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
E48C697115374F7E00232E28 /* KRContext.cpp */,
E48C696E15374F5A00232E28 /* KRContext.h */,
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */,
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */,
E4F9753815362A5200FD60B2 /* 3rdparty */,
E461A173152E59DF00F2044A /* Math */,
E461A170152E598200F2044A /* Resources */,
E491016F13C99BDC0098455B /* KREngine.mm */,
E491017213C99BDC0098455B /* KREngine.h */,
E491017913C99BDC0098455B /* KRModel.cpp */,
E491017A13C99BDC0098455B /* KRModel.h */,
E491018413C99BDC0098455B /* KRMaterialManager.h */,
E491017B13C99BDC0098455B /* KRMaterialManager.cpp */,
E491018213C99BDC0098455B /* KRModelManager.cpp */,
E491018313C99BDC0098455B /* KRModelManager.h */,
E491018513C99BDC0098455B /* KRTextureManager.h */,
E491018013C99BDC0098455B /* KRTextureManager.cpp */,
E491018613C99BDC0098455B /* KRTexture.h */,
E491018113C99BDC0098455B /* KRTexture.cpp */,
E47C25A113F4F65A00FF4370 /* KRShaderManager.h */,
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */,
E47C25A413F4F66F00FF4370 /* KRShader.h */,
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */,
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */,
E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */,
E46DBE841512B9E200D59F86 /* KREngine-common.h */,
E46C214915364DDB009CABF3 /* KRSceneManager.h */,
E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */,
E48C696E15374F5A00232E28 /* KRContext.h */,
E48C697115374F7E00232E28 /* KRContext.cpp */,
E491017213C99BDC0098455B /* KREngine.h */,
E491016F13C99BDC0098455B /* KREngine.mm */,
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */,
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */,
E46F49FF155DF46700CCF8B8 /* KRWorld.h */,
E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */,
E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */,
E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */,
E46F49FF155DF46700CCF8B8 /* KRWorld.h */,
E488399915F92BA300BD66D5 /* Managers */,
E461A173152E59DF00F2044A /* Math */,
E461A170152E598200F2044A /* Resources */,
);
name = Classes;
sourceTree = "<group>";
@@ -604,6 +674,8 @@
E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */,
1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */,
E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */,
E488399615F928CA00BD66D5 /* KRBundle.h in Headers */,
E488399E15F92BE000BD66D5 /* KRBundleManager.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -620,14 +692,17 @@
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
E4F975331536220900FD60B2 /* KRNode.h in Headers */,
E4B2A4391523B027004CB0EC /* KRMaterial.h in Headers */,
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */,
E46DBE811512AFE600D59F86 /* KRMesh.h in Headers */,
E4F9754115362CD900FD60B2 /* KRScene.h in Headers */,
E4F9754A153632AA00FD60B2 /* KRModelManager.cpp in Headers */,
E4F9754215362D0D00FD60B2 /* KRInstance.h in Headers */,
E4F975491536329E00FD60B2 /* KRTextureManager.h in Headers */,
E46DBE851512B9FA00D59F86 /* KREngine-common.h in Headers */,
E488399715F928CA00BD66D5 /* KRBundle.h in Headers */,
E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */,
E4F975501536333500FD60B2 /* KRModel.h in Headers */,
E488399F15F92BE000BD66D5 /* KRBundleManager.h in Headers */,
E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */,
E4D133661537685A0070068C /* KRShader.h in Headers */,
E461A153152E54B500F2044A /* KRLight.h in Headers */,
@@ -648,7 +723,6 @@
E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */,
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */,
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -771,7 +845,11 @@
E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */,
1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */,
E40BA45415EFF79500D7C3DD /* KRAABB.cpp in Sources */,
E48278B115F03028001C9431 /* visualize_overlay.fsh in Sources */,
E430D08115F8882F0010558D /* occlusion_test.fsh in Sources */,
E430D08915F88AD10010558D /* occlusion_test.vsh in Sources */,
E488399415F928CA00BD66D5 /* KRBundle.cpp in Sources */,
E488399C15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */,
E48839A115F92C2800BD66D5 /* visualize_overlay.fsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -816,6 +894,8 @@
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */,
E488399515F928CA00BD66D5 /* KRBundle.cpp in Sources */,
E488399D15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -7,6 +7,7 @@
//
#include "KRAABB.h"
#include "KRMat4.h"
KRAABB::KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint)
{
@@ -78,4 +79,68 @@ bool KRAABB::intersects(const KRAABB& b) const
{
// Return true if the two volumes intersect
return min.x <= b.max.x && min.y <= b.max.y && min.z <= b.max.z && max.x >= b.min.x && max.y >= b.min.y && max.z >= b.max.z;
}
}
bool KRAABB::contains(const KRAABB &b) const
{
// Return true if the passed KRAABB is entirely contained within this KRAABB
return b.min.x >= min.x && b.min.y >= min.y && b.min.z >= min.z && b.max.x <= max.x && b.max.y <= max.y && b.max.z <= max.z;
}
KRAABB KRAABB::Infinite()
{
return KRAABB(KRVector3::Min(), KRVector3::Max());
}
bool KRAABB::visible(const KRMat4 &matViewProjection) const
{
// test if bounding box would be within the visible range of the clip space transformed by matViewProjection
// This is used for view frustrum culling
KRVector3 minCorner, maxCorner;
int outside_count[6] = {0, 0, 0, 0, 0, 0};
for(int iCorner=0; iCorner<8; iCorner++) {
KRVector3 cornerVertex = KRVector3(
(iCorner & 1) == 0 ? min.x : max.x,
(iCorner & 2) == 0 ? min.y : max.y,
(iCorner & 4) == 0 ? min.z : max.z);
cornerVertex = KRMat4::Dot(matViewProjection, cornerVertex);
float cornerVertexW = KRMat4::DotW(matViewProjection, cornerVertex);
if(cornerVertex.x < -cornerVertexW) {
outside_count[0]++;
}
if(cornerVertex.y < -cornerVertexW) {
outside_count[1]++;
}
if(cornerVertex.z < -cornerVertexW) {
outside_count[2]++;
}
if(cornerVertex.x > cornerVertexW) {
outside_count[3]++;
}
if(cornerVertex.y > cornerVertexW) {
outside_count[4]++;
}
if(cornerVertex.z > cornerVertexW) {
outside_count[5]++;
}
}
bool is_visible = true;
for(int iFace=0; iFace < 6; iFace++) {
if(outside_count[iFace] == 8) {
is_visible = false;
}
}
if(!is_visible) {
fprintf(stderr, "AABB culled: %i%i%i%i%i%i out, (%f, %f, %f) - (%f, %f, %f)\n", outside_count[0], outside_count[1], outside_count[2], outside_count[3], outside_count[4], outside_count[5], min.x, min.y, min.z, max.x, max.y, max.z);
} else {
fprintf(stderr, "AABB visible: %i%i%i%i%i%i out, (%f, %f, %f) - (%f, %f, %f)\n", outside_count[0], outside_count[1], outside_count[2], outside_count[3], outside_count[4], outside_count[5], min.x, min.y, min.z, max.x, max.y, max.z);
}
return is_visible;
}

View File

@@ -13,6 +13,8 @@
#include "KRVector3.h"
class KRMat4;
class KRAABB {
public:
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint);
@@ -21,6 +23,8 @@ public:
KRVector3 center() const;
KRVector3 size() const;
bool intersects(const KRAABB& b) const;
bool contains(const KRAABB &b) const;
bool visible(const KRMat4 &matViewProjection) const;
KRAABB& operator =(const KRAABB& b);
bool operator ==(const KRAABB& b) const;
@@ -32,6 +36,8 @@ public:
KRVector3 min;
KRVector3 max;
static KRAABB Infinite();
};

View File

@@ -194,7 +194,7 @@ bool KRBoundingVolume::test_intersect(const KRBoundingVolume &p) const {
}
bool KRBoundingVolume::test_intersect(const KRAABB &p) const {
// Simple, non-aligned bounding box intersection test
// Axis aligned bounding box intersection test
KRVector3 minPoint = m_vertices[0], maxPoint = m_vertices[0], minPoint2 = p.min, maxPoint2 = p.max;
for(int iVertex=1; iVertex < 8; iVertex++) {

View File

@@ -0,0 +1,86 @@
//
// KRBundle.cpp
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KRBundle.h"
#include "KRContext.h"
#include <assert.h>
typedef struct _tar_header
{
char file_name[100];
char file_mode[8];
char owner_id[8]; // Owner's numeric user ID (OCTAL!)
char group_id[8]; // Group's numeric user ID (OCTAL!)
char file_size[12]; // File size in bytes (OCTAL!)
char mod_time[12]; // Last modification time in numeric Unix time format
char checksum[8]; // Checksum for header block
char file_type[1]; // Link indicator (file type)
char linked_file[100]; // Name of linked file
} tar_header_type;
KRBundle::KRBundle(KRContext &context, std::string name, KRDataBlock *pData) : KRContextObject(context)
{
m_pData = pData;
unsigned char *pFile = (unsigned char *)m_pData->getStart();
while(pFile < m_pData->getEnd() ) {
tar_header_type *file_header = (tar_header_type *)pFile;
size_t file_size = strtol(file_header->file_size, NULL, 8);
pFile += 512; // Skip past the header to the file contents
if(file_header->file_name[0] != '\0' && file_header->file_name[0] != '.') {
// We ignore the last two records in the tar file, which are zero'ed out tar_header structures
KRDataBlock *pFileData = new KRDataBlock();
if(pFileData->load(pFile, file_size)) {
context.loadResource(file_header->file_name, pFileData);
} else {
delete pFileData;
assert(false);
}
}
// Advance past the end of the file
if((file_size & 0x01ff) == 0) {
// file size is a multiple of 512 bytes, we can just add it
pFile += file_size;
} else {
// We would not be on a 512 byte boundary, round up to the next one
pFile += (file_size + 0x0200) - (file_size & 0x1ff);
}
}
}
KRBundle::~KRBundle()
{
delete m_pData;
}

View File

@@ -0,0 +1,47 @@
//
// KRBundle.h
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRBUNDLE_H
#define KRBUNDLE_H
#import "KREngine-common.h"
#import "KRResource.h"
#import "KRDataBlock.h"
class KRBundle : public KRContextObject {
public:
KRBundle(KRContext &context, std::string name, KRDataBlock *pData);
virtual ~KRBundle();
private:
KRDataBlock *m_pData;
};
#endif /* defined(KRBUNDLE_H) */

View File

@@ -0,0 +1,60 @@
//
// KRBundleManager.cpp
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include "KRBundleManager.h"
#import "KRBundle.h"
KRBundleManager::KRBundleManager(KRContext &context) : KRContextObject(context) {
}
KRBundleManager::~KRBundleManager() {
for(map<std::string, KRBundle *>::iterator itr = m_bundles.begin(); itr != m_bundles.end(); ++itr){
delete (*itr).second;
}
m_bundles.empty();
}
KRBundle *KRBundleManager::loadBundle(const char *szName, KRDataBlock *pData)
{
KRBundle *pBundle = new KRBundle(*m_pContext, szName, pData);
m_bundles[szName] = pBundle;
return pBundle;
}
KRBundle *KRBundleManager::getBundle(const char *szName) {
return m_bundles[szName];
}
std::map<std::string, KRBundle *> KRBundleManager::getBundles() {
return m_bundles;
}

View File

@@ -0,0 +1,62 @@
//
// KRBundleManager.h
// KREngine
//
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRBUNDLEMANAGER_H
#define KRBUNDLEMANAGER_H
#import "KREngine-common.h"
#import "KRContextObject.h"
#import "KRDataBlock.h"
class KRContext;
class KRBundle;
#include <map>
#import <string>
using std::map;
class KRBundleManager : public KRContextObject {
public:
KRBundleManager(KRContext &context);
~KRBundleManager();
KRBundle *loadBundle(const char *szName, KRDataBlock *pData);
KRBundle *getBundle(const char *szName);
std::vector<std::string> getBundleNames();
std::map<std::string, KRBundle *> getBundles();
private:
std::map<std::string, KRBundle *> m_bundles;
};
#endif /* defined(KRBUNDLEMANAGER_H) */

View File

@@ -47,6 +47,7 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(c
double const D2R = PI * 2 / 360;
bShowShadowBuffer = false;
bShowOctree = false;
bEnablePerPixel = true;
bEnableDiffuseMap = true;
bEnableNormalMap = true;
@@ -230,8 +231,10 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
glDepthMask(GL_FALSE);
// Set source to buffers from pass 1
m_pContext->getTextureManager()->selectTexture(6, NULL);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
m_pContext->getTextureManager()->selectTexture(7, NULL);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
@@ -251,6 +254,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
glClear(GL_COLOR_BUFFER_BIT);
// Set source to buffers from pass 2
m_pContext->getTextureManager()->selectTexture(6, NULL);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
@@ -270,8 +274,10 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
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
m_pContext->getTextureManager()->selectTexture(6, NULL);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, 0);
m_pContext->getTextureManager()->selectTexture(7, NULL);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, 0);
} else {
@@ -355,38 +361,36 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
// ----====---- Debug Overlay ----====----
bool bVisualize = false; // MIKE EDIT: True->false
if(bVisualize) {
if(bShowOctree) {
// Enable z-buffer test
glEnable(GL_DEPTH_TEST);
glDepthRangef(0.0, 1.0);
// Enable backface culling
glCullFace(GL_BACK);
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);
KRMat4 projectionMatrix = getProjectionMatrix();
static const GLfloat cubeVertices[] = {
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
1.0,-1.0, 1.0,
-1.0,-1.0, 1.0,
-1.0,-1.0,-1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0,-1.0,
1.0, 1.0, 1.0,
1.0, 1.0,-1.0,
1.0,-1.0, 1.0,
1.0,-1.0,-1.0,
-1.0,-1.0,-1.0,
1.0, 1.0,-1.0,
-1.0, 1.0,-1.0
};
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -400,16 +404,17 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 17);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 14);
}
}
scene.getOcclusionQueryResults(m_visibleBounds);
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
glDepthMask(GL_TRUE);
}
@@ -664,10 +669,12 @@ void KRCamera::renderPost()
glDisable(GL_DEPTH_TEST);
bindPostShader();
m_pContext->getTextureManager()->selectTexture(0, NULL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
m_pContext->getTextureManager()->selectTexture(1, NULL);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
//glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
@@ -682,9 +689,11 @@ void KRCamera::renderPost()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_pContext->getTextureManager()->selectTexture(0, NULL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
m_pContext->getTextureManager()->selectTexture(1, NULL);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
@@ -693,6 +702,7 @@ void KRCamera::renderPost()
glDisable(GL_DEPTH_TEST);
glUseProgram(m_postShaderProgram);
m_pContext->getTextureManager()->selectTexture(0, NULL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
@@ -706,6 +716,7 @@ void KRCamera::renderPost()
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVA);
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
m_pContext->getTextureManager()->selectTexture(1, NULL);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVerticesShadow[iShadow]);
@@ -713,9 +724,11 @@ void KRCamera::renderPost()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
m_pContext->getTextureManager()->selectTexture(0, NULL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
m_pContext->getTextureManager()->selectTexture(1, NULL);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
}
@@ -729,11 +742,11 @@ void KRCamera::renderPost()
glDisable(GL_DEPTH_TEST);
glUseProgram(m_postShaderProgram);
m_pContext->getTextureManager()->selectTexture(0, NULL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, pFontTexture->getName());
m_pContext->getTextureManager()->selectTexture(1, pFontTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);
@@ -774,8 +787,7 @@ void KRCamera::renderPost()
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
m_pContext->getTextureManager()->selectTexture(1, NULL);
}
}

View File

@@ -78,6 +78,7 @@ public:
bool bDebugPSSM;
bool bDebugSuperShiny;
bool bShowShadowBuffer;
bool bShowOctree;
bool bEnableAmbient;
bool bEnableDiffuse;
bool bEnableSpecular;

View File

@@ -12,14 +12,16 @@
#include "KRCamera.h"
KRContext::KRContext() {
m_pShaderManager = new KRShaderManager(*this);
m_pTextureManager = new KRTextureManager(*this);
m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pShaderManager);
m_pModelManager = new KRModelManager(*this);
m_pSceneManager = new KRSceneManager(*this);
m_pBundleManager = new KRBundleManager(*this);
m_pShaderManager = new KRShaderManager(*this);
m_pTextureManager = new KRTextureManager(*this);
m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pShaderManager);
m_pModelManager = new KRModelManager(*this);
m_pSceneManager = new KRSceneManager(*this);
}
KRContext::~KRContext() {
if(m_pSceneManager) {
delete m_pSceneManager;
m_pSceneManager = NULL;
@@ -44,9 +46,17 @@ KRContext::~KRContext() {
delete m_pShaderManager;
m_pShaderManager = NULL;
}
// The bundles must be destroyed last, as the other objects may be using mmap'ed data from bundles
if(m_pBundleManager) {
delete m_pBundleManager;
m_pBundleManager = NULL;
}
}
KRBundleManager *KRContext::getBundleManager() {
return m_pBundleManager;
}
KRSceneManager *KRContext::getSceneManager() {
return m_pSceneManager;
}
@@ -63,24 +73,41 @@ KRModelManager *KRContext::getModelManager() {
return m_pModelManager;
}
void KRContext::loadResource(std::string path) {
std::string name = KRResource::GetFileBase(path);
std::string extension = KRResource::GetFileExtension(path);
if(extension.compare("krobject") == 0) {
m_pModelManager->loadModel(name.c_str(), path.c_str());
void KRContext::loadResource(const std::string &file_name, KRDataBlock *data) {
std::string name = KRResource::GetFileBase(file_name);
std::string extension = KRResource::GetFileExtension(file_name);
fprintf(stderr, "KRContext::loadResource - Loading: %s\n", file_name.c_str());
if(extension.compare("krbundle") == 0) {
m_pBundleManager->loadBundle(name.c_str(), data);
} else if(extension.compare("krobject") == 0) {
m_pModelManager->loadModel(name.c_str(), data);
} else if(extension.compare("krscene") == 0) {
m_pSceneManager->loadScene(name.c_str(), path.c_str());
m_pSceneManager->loadScene(name.c_str(), data);
#if TARGET_OS_IPHONE
} else if(extension.compare("pvr") == 0) {
m_pTextureManager->loadTexture(name.c_str(), path.c_str());
m_pTextureManager->loadTexture(name.c_str(), data);
#endif
} else if(extension.compare("vsh") == 0) {
m_pShaderManager->loadVertexShader(name.c_str(), path.c_str());
m_pShaderManager->loadVertexShader(name.c_str(), data);
} else if(extension.compare("fsh") == 0) {
m_pShaderManager->loadFragmentShader(name.c_str(), path.c_str());
m_pShaderManager->loadFragmentShader(name.c_str(), data);
} else if(extension.compare("mtl") == 0) {
m_pMaterialManager->loadFile(path.c_str());
m_pMaterialManager->load(name.c_str(), data);
} else {
fprintf(stderr, "KRContext::loadResource - Unknown resource file type: %s\n", path.c_str());
fprintf(stderr, "KRContext::loadResource - Unknown resource file type: %s\n", file_name.c_str());
delete data;
}
}
void KRContext::loadResource(std::string path) {
KRDataBlock *data = new KRDataBlock();
if(data->load(path)) {
loadResource(path, data);
} else {
delete data;
}
}

View File

@@ -9,6 +9,7 @@
#ifndef KREngine_KRContext_h
#define KREngine_KRContext_h
#import "KRBundleManager.h"
#import "KRSceneManager.h"
#import "KRTextureManager.h"
#import "KRMaterialManager.h"
@@ -21,8 +22,10 @@ public:
KRContext();
~KRContext();
void loadResource(const std::string &file_name, KRDataBlock *data);
void loadResource(std::string path);
KRBundleManager *getBundleManager();
KRSceneManager *getSceneManager();
KRTextureManager *getTextureManager();
KRMaterialManager *getMaterialManager();
@@ -32,6 +35,7 @@ public:
KRCamera *createCamera(int width, int height);
private:
KRBundleManager *m_pBundleManager;
KRSceneManager *m_pSceneManager;
KRTextureManager *m_pTextureManager;
KRMaterialManager *m_pMaterialManager;

View File

@@ -2,41 +2,188 @@
// KRDataBlock.cpp
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include <iostream>
#include "KRDataBlock.h"
#include <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
KRDataBlock::KRDataBlock() {
m_data = NULL;
m_data_size = 0;
m_fdPackFile = 0;
m_bMalloced = false;
}
KRDataBlock::~KRDataBlock() {
if(m_data) {
free(m_data);
}
unload();
}
void *KRDataBlock::getData() {
// Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use
void KRDataBlock::unload()
{
if(m_fdPackFile) {
// Memory mapped file
if(m_bMalloced) {
munmap(m_data, m_data_size);
}
close(m_fdPackFile);
} else if(m_data != NULL && m_bMalloced) {
// Malloc'ed data
free(m_data);
}
m_bMalloced = false;
m_data = NULL;
m_data_size = 0;
m_fdPackFile = 0;
}
// Encapsulate a pointer. Note - The pointer will not be free'ed
bool KRDataBlock::load(void *data, size_t size)
{
unload();
m_data = data;
m_data_size = size;
return true;
}
// Load a file into memory using mmap. The data pointer will be protected as read-only until append() or expand() is called
bool KRDataBlock::load(const std::string &path)
{
bool success = false;
unload();
struct stat statbuf;
m_fdPackFile = open(path.c_str(), O_RDONLY);
if(m_fdPackFile >= 0) {
if(fstat(m_fdPackFile, &statbuf) >= 0) {
if ((m_data = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, m_fdPackFile, 0)) == (caddr_t) -1) {
} else {
m_data_size = statbuf.st_size;
success = true;
}
}
}
if(!success) {
// If anything failed, don't leave the object in an invalid state
unload();
}
return success;
}
// Return a pointer to the start of the data block
void *KRDataBlock::getStart() {
return m_data;
}
int KRDataBlock::getSize() {
// Return a pointer to the byte after the end of the data block
void *KRDataBlock::getEnd() {
return (unsigned char *)m_data + m_data_size;
}
// Return the size of the data block. Use append() or expand() to make the data block larger
size_t KRDataBlock::getSize() const {
return m_data_size;
}
void KRDataBlock::append(void *data, int size) {
// Expand the data block, and switch it to read-write mode. Note - this may result in a mmap'ed file being copied to malloc'ed ram and then closed
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);
memcpy(m_data, data, size);
m_data_size = size;
} else {
m_bMalloced = true;
} else if(m_bMalloced) {
// Starting with a malloc'ed data block; realloc it expand
m_data = realloc(m_data, m_data_size + size);
memcpy((unsigned char *)m_data + size, data, size);
m_data_size += size;
} else {
// 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);
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
unload();
m_bMalloced = true;
m_data = pNewData;
m_data_size = new_size;
}
}
}
// Append data to the end of the block, increasing the size of the block and making it read-write.
void KRDataBlock::append(void *data, size_t size) {
// Expand the data block
expand(size);
// Fill the new space with the data to append
memcpy((unsigned char *)m_data + m_data_size - size, data, size);
}
// Save the data to a file, and switch to read-only mode. The data pointer will be replaced with a mmap'ed address of the file; the malloc'ed data will be freed
bool KRDataBlock::save(const std::string& path) {
int fdNewFile = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
if(fdNewFile == -1) {
return false;
} else {
// Seek to end of file and write a byte to enlarge it
lseek(fdNewFile, m_data_size-1, SEEK_SET);
write(fdNewFile, "", 1);
// Now map it...
void *pNewData = mmap(0, m_data_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdNewFile, 0);
if(pNewData == (caddr_t) -1) {
close(fdNewFile);
return false;
} else if(m_data != NULL) {
// Copy data to new file
memcpy(pNewData, m_data, m_data_size);
// Unload existing data allocation, which is now redundant
size_t new_size = m_data_size; // We need to store this, as unload() will reset it
unload();
// Protect new mmap'ed memory
mprotect(pNewData, m_data_size, PROT_READ);
// Switch pointer to use new mmap'ed memory
m_data_size = new_size;
m_fdPackFile = fdNewFile;
m_data = pNewData;
}
return true;
}
}

View File

@@ -2,8 +2,31 @@
// KRDataBlock.h
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KREngine_KRDataBlock_h
@@ -14,13 +37,41 @@ public:
KRDataBlock();
~KRDataBlock();
void append(void *data, int size);
// Encapsulate a pointer. Note - The pointer will not be free'ed
bool load(void *data, size_t size);
void *getData();
int getSize();
// Load a file into memory using mmap. The data pointer will be protected as read-only until append() or expand() is called
bool load(const std::string &path);
// Save the data to a file, and switch to read-only mode. The data pointer will be replaced with a mmap'ed address of the file; the malloc'ed data will be freed
bool save(const std::string& path);
// Append data to the end of the block, increasing the size of the block and making it read-write.
void append(void *data, size_t size);
// Expand the data block, and switch it to read-write mode. Note - this may result in a mmap'ed file being copied to malloc'ed ram and then closed
void expand(size_t size);
// Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use
void unload();
// Return a pointer to the start of the data block
void *getStart();
// Return a pointer to the one byte after the end of the data block
void *getEnd();
// Return the size of the data block. Use append() or expand() to make the data block larger
size_t getSize() const;
private:
void *m_data;
int m_data_size;
size_t m_data_size;
// For memory mapped objects:
int m_fdPackFile;
// For malloc'ed objects:
bool m_bMalloced;
};
#endif

View File

@@ -48,9 +48,9 @@ KRVector3 KRDirectionalLight::getLocalLightDirection() {
#if TARGET_OS_IPHONE
bool KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
bool bRendered = KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
@@ -109,8 +109,6 @@ bool KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
return bRendered;
}
#endif

View File

@@ -25,7 +25,7 @@ public:
#if TARGET_OS_IPHONE
virtual bool render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
#endif
private:

View File

@@ -89,7 +89,8 @@ double const PI = 3.141592653589793f;
@"debug_enable_diffuse" : @27,
@"debug_enable_specular" : @28,
@"debug_super_shiny" : @29,
@"enable_deferred_lighting" : @30
@"debug_octree" : @30,
@"enable_deferred_lighting" : @31
} copy];
[self loadShaders];
@@ -151,7 +152,7 @@ double const PI = 3.141592653589793f;
-(int)getParameterCount
{
return 31;
return 32;
}
-(NSString *)getParameterNameWithIndex: (int)i
@@ -161,7 +162,7 @@ double const PI = 3.141592653589793f;
-(NSString *)getParameterLabelWithIndex: (int)i
{
NSString *parameter_labels[31] = {
NSString *parameter_labels[32] = {
@"Camera FOV",
@"Shadow Quality (0 - 2)",
@"Enable per-pixel lighting",
@@ -192,13 +193,14 @@ double const PI = 3.141592653589793f;
@"Debug - Enable Diffuse",
@"Debug - Enable Specular",
@"Debug - Super Shiny",
@"Debug - Octree Visualize",
@"Enable Deferred Lighting"
};
return parameter_labels[i];
}
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
{
KREngineParameterType types[31] = {
KREngineParameterType types[32] = {
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_INT,
@@ -230,13 +232,14 @@ double const PI = 3.141592653589793f;
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL
};
return types[i];
}
-(double)getParameterValueWithIndex: (int)i
{
double values[31] = {
double values[32] = {
_camera->perspective_fov,
(double)_camera->m_cShadowBuffers,
_camera->bEnablePerPixel ? 1.0f : 0.0f,
@@ -267,6 +270,7 @@ double const PI = 3.141592653589793f;
_camera->bEnableDiffuse ? 1.0f : 0.0f,
_camera->bEnableSpecular ? 1.0f : 0.0f,
_camera->bDebugSuperShiny ? 1.0f : 0.0f,
_camera->bShowOctree ? 1.0f : 0.0f,
_camera->bEnableDeferredLighting ? 1.0f : 0.0f
};
return values[i];
@@ -409,21 +413,38 @@ double const PI = 3.141592653589793f;
}
break;
case 30:
if(_camera->bShowOctree != bNewBoolVal) {
_camera->bShowOctree = bNewBoolVal;
}
break;
case 31:
if(_camera->bEnableDeferredLighting != bNewBoolVal) {
_camera->bEnableDeferredLighting = bNewBoolVal;
}
break;
}
}
-(double)getParameterMinWithIndex: (int)i
{
double minValues[31] = {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};
double minValues[32] = {
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
};
return minValues[i];
}
-(double)getParameterMaxWithIndex: (int)i
{
double maxValues[31] = {PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.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};
double maxValues[32] = {
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 3.0f, 3.0f,
3.0f, 3.0f, 3.0f, 3.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
};
return maxValues[i];
}

View File

@@ -74,34 +74,31 @@ void KRInstance::loadModel() {
#if TARGET_OS_IPHONE
bool 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) {
bool bRendered = 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) {
// Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied
loadModel();
KRMat4 projectionMatrix;
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
projectionMatrix = pCamera->getProjectionMatrix();
}
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || renderPass == RENDER_PASS_SHADOWMAP)) {
//if(m_pModel != NULL && (getBounds().visible(viewMatrix * projectionMatrix) || renderPass == RENDER_PASS_SHADOWMAP)) {
if(m_pLightMap == NULL && m_lightMap.size()) {
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
}
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP) {
int iTextureName = m_pLightMap->getName();
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
m_pContext->getTextureManager()->selectTexture(3, m_pLightMap);
}
KRMat4 projectionMatrix;
if(renderPass != RENDER_PASS_SHADOWMAP) {
projectionMatrix = pCamera->getProjectionMatrix();
}
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
@@ -113,30 +110,15 @@ bool KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
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);
/*
glGetQueryObjectuivEXT(occlusionTest, GL_QUERY_RESULT_AVAILABLE_EXT, &hasBeenTested);
if (hasBeenTested) glGetQueryObjectuivEXT(occlusionTest, GL_QUERY_RESULT_EXT, &theParams);
if (theParams) {
bRendered = true;
}
*/
bRendered = true;
glDeleteQueriesEXT(1, &occlusionTest);
}
}
return bRendered;
}
#endif
void KRInstance::calcExtents(KRContext *pContext) {
void KRInstance::calcExtents(KRContext *pContext)
{
KRNode::calcExtents(pContext);
loadModel();
KRMesh *pMesh = m_pModel->getMesh();
@@ -156,12 +138,47 @@ bool KRInstance::hasTransparency() {
}
}
KRVector3 KRInstance::getMinPoint() {
KRAABB KRInstance::getBounds() {
loadModel();
return KRMat4::Dot(m_modelMatrix, m_pModel->getMesh()->getMinPoint());
KRMesh *pMesh = m_pModel->getMesh();
KRVector3 meshMin = pMesh->getMinPoint();
KRVector3 meshMax = pMesh->getMaxPoint();
KRVector3 min, max;
for(int iCorner=0; iCorner < 8; iCorner++) {
KRVector3 cornerVertex = KRVector3(
(iCorner & 1) == 0 ? meshMin.x : meshMax.x,
(iCorner & 2) == 0 ? meshMin.y : meshMax.y,
(iCorner & 4) == 0 ? meshMin.z : meshMax.z);
cornerVertex = KRMat4::Dot(m_modelMatrix, cornerVertex);
if(iCorner == 0) {
// Prime with first point
min = cornerVertex;
max = cornerVertex;
} else {
if(cornerVertex.x < min.x) {
min.x = cornerVertex.x;
}
if(cornerVertex.y < min.y) {
min.y = cornerVertex.y;
}
if(cornerVertex.z < min.z) {
min.z = cornerVertex.z;
}
if(cornerVertex.x > max.x) {
max.x = cornerVertex.x;
}
if(cornerVertex.y > max.y) {
max.y = cornerVertex.y;
}
if(cornerVertex.z > max.z) {
max.z = cornerVertex.z;
}
}
}
return KRAABB(min, max);
}
KRVector3 KRInstance::getMaxPoint() {
loadModel();
return KRMat4::Dot(m_modelMatrix, m_pModel->getMesh()->getMaxPoint());
}

View File

@@ -61,7 +61,7 @@ public:
#if TARGET_OS_IPHONE
virtual bool render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
#endif
virtual void calcExtents(KRContext *pContext);
@@ -71,8 +71,7 @@ public:
bool hasTransparency();
virtual KRVector3 getMinPoint();
virtual KRVector3 getMaxPoint();
virtual KRAABB getBounds();
private:
KRModel *m_pModel;

View File

@@ -117,9 +117,9 @@ float KRLight::getDecayStart() {
#if TARGET_OS_IPHONE
bool KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
bool bRendered = 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_FLARES) {
if(m_flareTexture.size() && m_flareSize > 0.0f) {
@@ -146,8 +146,7 @@ bool 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);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_pFlareTexture->getName());
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
static const GLfloat squareVertices[] = {
0.0f, 0.0f,
@@ -169,8 +168,6 @@ bool KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
}
}
return bRendered || true;
}
#endif

View File

@@ -36,7 +36,7 @@ public:
#if TARGET_OS_IPHONE
virtual bool render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
#endif

View File

@@ -278,7 +278,7 @@ void KRMat4::transpose() {
memcpy(m_mat, trans, sizeof(GLfloat) * 16);
}
/* Dot Product */
/* Dot Product, returning KRVector3 */
KRVector3 KRMat4::Dot(const KRMat4 &m, const KRVector3 &v) {
return KRVector3(
v.x * (float)m[0*4 + 0] + v.y * (float)m[1*4 + 0] + v.z * (float)m[2*4 + 0] + (float)m[3*4 + 0],
@@ -286,3 +286,20 @@ KRVector3 KRMat4::Dot(const KRMat4 &m, const KRVector3 &v) {
v.x * (float)m[0*4 + 2] + v.y * (float)m[1*4 + 2] + v.z * (float)m[2*4 + 2] + (float)m[3*4 + 2]
);
}
/* Dot Product, returning w component as if it were a KRVector4 (This will be deprecated once KRVector4 is implemented instead*/
float KRMat4::DotW(const KRMat4 &m, const KRVector3 &v) {
return v.x * (float)m[0*4 + 3] + v.y * (float)m[1*4 + 3] + v.z * (float)m[2*4 + 3] + (float)m[3*4 + 3];
}
/* Dot Product followed by W-divide */
KRVector3 KRMat4::DotWDiv(const KRMat4 &m, const KRVector3 &v) {
KRVector3 r = KRVector3(
v.x * (float)m[0*4 + 0] + v.y * (float)m[1*4 + 0] + v.z * (float)m[2*4 + 0] + (float)m[3*4 + 0],
v.x * (float)m[0*4 + 1] + v.y * (float)m[1*4 + 1] + v.z * (float)m[2*4 + 1] + (float)m[3*4 + 1],
v.x * (float)m[0*4 + 2] + v.y * (float)m[1*4 + 2] + v.z * (float)m[2*4 + 2] + (float)m[3*4 + 2]
);
// Get W component, then divide x, y, and z by w.
r /= DotW(m, v);
return r;
}

View File

@@ -103,6 +103,8 @@ public:
void transpose();
static KRVector3 Dot(const KRMat4 &m, const KRVector3 &v);
static float DotW(const KRMat4 &m, const KRVector3 &v);
static KRVector3 DotWDiv(const KRMat4 &m, const KRVector3 &v);
};
#endif // KRMAT4_I

View File

@@ -390,65 +390,27 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY], m_reflectionFactor);
bool bSameDiffuseMap = false;
bool bSameSpecMap = false;
bool bSameNormalMap = false;
bool bSameReflectionMap = false;
if(*prevBoundMaterial) {
if((*prevBoundMaterial)->m_pDiffuseMap == m_pDiffuseMap) {
bSameDiffuseMap = true;
}
if((*prevBoundMaterial)->m_pSpecularMap == m_pSpecularMap) {
bSameSpecMap = true;
}
if((*prevBoundMaterial)->m_pReflectionMap == m_pReflectionMap) {
bSameReflectionMap = true;
}
if((*prevBoundMaterial)->m_pNormalMap == m_pNormalMap) {
bSameNormalMap = true;
}
if(bDiffuseMap) {
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap);
}
if(bDiffuseMap && !bSameDiffuseMap) {
int iTextureName = m_pDiffuseMap->getName();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
if(bSpecMap && !bSameSpecMap) {
int iTextureName = m_pSpecularMap->getName();
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if(bSpecMap) {
m_pContext->getTextureManager()->selectTexture(1, m_pSpecularMap);
}
if(bNormalMap && !bSameNormalMap) {
int iTextureName = m_pNormalMap->getName();
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if(bNormalMap) {
m_pContext->getTextureManager()->selectTexture(2, m_pNormalMap);
}
if(bReflectionMap && !bSameReflectionMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
if(bReflectionMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
// GL_TEXTURE7 is used for reading the depth buffer in gBuffer pass 2 and re-used for the reflection map in gBuffer Pass 3 and in forward rendering
int iTextureName = m_pReflectionMap->getName();
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
m_pContext->getTextureManager()->selectTexture(7, m_pReflectionMap);
}
*prevBoundMaterial = this;
} // if(!bSameMaterial)
}
#endif
char *KRMaterial::getName() {

View File

@@ -46,7 +46,7 @@ KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pText
}
KRMaterialManager::~KRMaterialManager() {
}
@@ -59,212 +59,187 @@ KRMaterial *KRMaterialManager::getMaterial(const char *szName) {
return (*itr).second;
}
}
bool KRMaterialManager::loadFile(const char *szPath) {
bool bSuccess = false;
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
KRMaterial *pMaterial = NULL;
char szSymbol[16][64];
struct stat statbuf;
fdFile = open(szPath, O_RDONLY);
if(fdFile >= 0) {
if(fstat(fdFile, &statbuf) >= 0) {
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
} else {
fileSize = statbuf.st_size;
char *pScan = (char *)data->getStart();
char *pEnd = (char *)data->getEnd();
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pScan = (char *)pFile;
char *pEnd = (char *)pFile + fileSize;
while(pScan < pEnd) {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(cSymbols > 0) {
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
pMaterial = new KRMaterial(*m_pContext, szSymbol[1]);
m_materials[szSymbol[1]] = pMaterial;
}
if(pMaterial != NULL) {
if(strcmp(szSymbol[0], "alpha_mode") == 0) {
if(cSymbols == 2) {
if(strcmp(szSymbol[1], "test") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_TEST);
} else if(strcmp(szSymbol[1], "blendoneside") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
} else if(strcmp(szSymbol[1], "blendtwoside") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
} else {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE);
}
}
if(cSymbols > 0) {
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
pMaterial = new KRMaterial(*m_pContext, szSymbol[1]);
m_materials[szSymbol[1]] = pMaterial;
} else if(strcmp(szSymbol[0], "Ka") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setAmbient(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setAmbient(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Kd") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setDiffuse(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setDiffuse(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Ks") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setSpecular(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setSpecular(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Kr") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setReflection(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setReflection(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Tr") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setTransparency(a);
} else if(strcmp(szSymbol[0], "Ns") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setShininess(a);
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
// Truncate file extension
char *pScan2 = szSymbol[1];
char *pLastPeriod = NULL;
while(*pScan2 != '\0') {
if(*pScan2 == '.') {
pLastPeriod = pScan2;
}
if(pMaterial != NULL) {
if(strcmp(szSymbol[0], "alpha_mode") == 0) {
if(cSymbols == 2) {
if(strcmp(szSymbol[1], "test") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_TEST);
} else if(strcmp(szSymbol[1], "blendoneside") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
} else if(strcmp(szSymbol[1], "blendtwoside") == 0) {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
} else {
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE);
}
}
} else if(strcmp(szSymbol[0], "Ka") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setAmbient(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setAmbient(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Kd") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setDiffuse(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setDiffuse(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Ks") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setSpecular(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setSpecular(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Kr") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setReflection(KRVector3(r, r, r));
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setReflection(KRVector3(r, g, b));
}
} else if(strcmp(szSymbol[0], "Tr") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setTransparency(a);
} else if(strcmp(szSymbol[0], "Ns") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setShininess(a);
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
// Truncate file extension
char *pScan2 = szSymbol[1];
char *pLastPeriod = NULL;
while(*pScan2 != '\0') {
if(*pScan2 == '.') {
pLastPeriod = pScan2;
}
pScan2++;
}
if(pLastPeriod) {
*pLastPeriod = '\0';
}
KRVector2 texture_scale = KRVector2(1.0f, 1.0f);
KRVector2 texture_offset = KRVector2(0.0f, 0.0f);
int iScanSymbol = 2;
int iScaleParam = -1;
int iOffsetParam = -1;
while(iScanSymbol < cSymbols) {
if(strcmp(szSymbol[iScanSymbol], "-s") == 0) {
// Scale
iScaleParam = 0;
iOffsetParam = -1;
} else if(strcmp(szSymbol[iScanSymbol], "-o") == 0) {
// Offset
iOffsetParam = 0;
iScaleParam = -1;
} else {
char *pScan3 = szSymbol[iScanSymbol];
double v = strtof(pScan3, &pScan3);
if(iScaleParam == 0) {
texture_scale.x = v;
iScaleParam++;
} else if(iScaleParam == 1) {
texture_scale.y = v;
iScaleParam++;
} else if(iOffsetParam == 0) {
texture_offset.x = v;
iOffsetParam++;
} else if(iOffsetParam == 1) {
texture_offset.y = v;
iOffsetParam++;
}
}
iScanSymbol++;
}
if(strcmp(szSymbol[0], "map_Ka") == 0) {
pMaterial->setAmbientMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Kd") == 0) {
pMaterial->setDiffuseMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Ks") == 0) {
pMaterial->setSpecularMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Normal") == 0) {
pMaterial->setNormalMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Reflection") == 0) {
pMaterial->setReflectionMap(szSymbol[1], texture_scale, texture_offset);
}
pScan2++;
}
if(pLastPeriod) {
*pLastPeriod = '\0';
}
KRVector2 texture_scale = KRVector2(1.0f, 1.0f);
KRVector2 texture_offset = KRVector2(0.0f, 0.0f);
int iScanSymbol = 2;
int iScaleParam = -1;
int iOffsetParam = -1;
while(iScanSymbol < cSymbols) {
if(strcmp(szSymbol[iScanSymbol], "-s") == 0) {
// Scale
iScaleParam = 0;
iOffsetParam = -1;
} else if(strcmp(szSymbol[iScanSymbol], "-o") == 0) {
// Offset
iOffsetParam = 0;
iScaleParam = -1;
} else {
char *pScan3 = szSymbol[iScanSymbol];
double v = strtof(pScan3, &pScan3);
if(iScaleParam == 0) {
texture_scale.x = v;
iScaleParam++;
} else if(iScaleParam == 1) {
texture_scale.y = v;
iScaleParam++;
} else if(iOffsetParam == 0) {
texture_offset.x = v;
iOffsetParam++;
} else if(iOffsetParam == 1) {
texture_offset.y = v;
iOffsetParam++;
}
}
iScanSymbol++;
}
}
if(strcmp(szSymbol[0], "map_Ka") == 0) {
pMaterial->setAmbientMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Kd") == 0) {
pMaterial->setDiffuseMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Ks") == 0) {
pMaterial->setSpecularMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Normal") == 0) {
pMaterial->setNormalMap(szSymbol[1], texture_scale, texture_offset);
} else if(strcmp(szSymbol[0], "map_Reflection") == 0) {
pMaterial->setReflectionMap(szSymbol[1], texture_scale, texture_offset);
}
}
}
bSuccess = true;
}
}
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
}
return bSuccess;
delete data;
return true;
}

View File

@@ -33,6 +33,8 @@
#define KRMATERIALMANAGER_H
#import "KREngine-common.h"
#include "KRMaterial.h"
@@ -50,13 +52,16 @@ public:
KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRShaderManager *pShaderManager);
virtual ~KRMaterialManager();
bool loadFile(const char *szPath);
bool load(const char *szName, KRDataBlock *data);
KRMaterial *getMaterial(const char *szName);
private:
map<std::string, KRMaterial *> m_materials;
KRTextureManager *m_pTextureManager;
KRShaderManager *m_pShaderManager;
};
#endif

View File

@@ -31,6 +31,7 @@
#include "KRMesh.h"
#import "KRShader.h"
#import "KRContext.h"
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
@@ -41,15 +42,12 @@
#include <assert.h>
KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) {
m_fdPackFile = 0;
m_pPackData = NULL;
m_iPackFileSize = 0;
m_cBuffers = 0;
m_pBuffers = NULL;
m_pData = new KRDataBlock();
}
KRMesh::~KRMesh() {
clearData();
if(m_pData) delete m_pData;
}
std::string KRMesh::getExtension() {
@@ -57,96 +55,25 @@ std::string KRMesh::getExtension() {
}
void KRMesh::clearData() {
clearBuffers();
if(m_fdPackFile) {
if(m_pPackData != NULL) {
munmap(m_pPackData, m_iPackFileSize);
m_pPackData = NULL;
}
close(m_fdPackFile);
m_fdPackFile = 0;
} else {
// If we didn't load a packed file, then the data was calculated at run time and malloc'ed
if(m_pPackData != NULL) {
free(m_pPackData);
m_pPackData = NULL;
}
}
m_pData->unload();
}
void KRMesh::clearBuffers() {
m_submeshes.clear();
if(m_pBuffers != NULL) {
glDeleteBuffers(m_cBuffers, m_pBuffers);
delete m_pBuffers;
m_pBuffers = NULL;
}
}
void KRMesh::loadPack(std::string path) {
void KRMesh::loadPack(KRDataBlock *data) {
clearData();
struct stat statbuf;
m_fdPackFile = open(path.c_str(), O_RDONLY);
if(m_fdPackFile >= 0) {
if(fstat(m_fdPackFile, &statbuf) >= 0) {
if ((m_pPackData = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, m_fdPackFile, 0)) == (caddr_t) -1) {
} else {
m_iPackFileSize = statbuf.st_size;
pack_header *pHeader = (pack_header *)m_pPackData;
m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz);
m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz);
}
}
}
delete m_pData;
m_pData = data;
pack_header *pHeader = (pack_header *)m_pData->getStart();
m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz);
m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz);
}
bool KRMesh::save(const std::string& path) {
clearBuffers();
int fdNewFile = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
if(fdNewFile == -1) {
return false;
} else {
// Seek to end of file and write a byte to enlarge it
lseek(fdNewFile, m_iPackFileSize-1, SEEK_SET);
write(fdNewFile, "", 1);
// Now map it...
void *pNewData = mmap(0, m_iPackFileSize, PROT_READ | PROT_WRITE, MAP_SHARED, fdNewFile, 0);
if(pNewData == (caddr_t) -1) {
close(fdNewFile);
return false;
} else {
memcpy(pNewData, m_pPackData, m_iPackFileSize);
mprotect(pNewData, m_iPackFileSize, PROT_READ);
if(m_fdPackFile) {
if(m_pPackData != NULL) {
void *malloc_data = malloc(m_iPackFileSize);
memcpy(malloc_data, m_pPackData, m_iPackFileSize);
munmap(m_pPackData, m_iPackFileSize);
}
close(m_fdPackFile);
}
m_fdPackFile = fdNewFile;
m_pPackData = pNewData;
return true;
}
}
}
void KRMesh::unmap() {
clearBuffers();
if(m_fdPackFile) {
if(m_pPackData != NULL) {
void *malloc_data = malloc(m_iPackFileSize);
memcpy(malloc_data, m_pPackData, m_iPackFileSize);
munmap(m_pPackData, m_iPackFileSize);
m_pPackData = malloc_data;
}
close(m_fdPackFile);
}
return m_pData->save(path);
}
GLfloat KRMesh::getMaxDimension() {
@@ -159,7 +86,7 @@ GLfloat KRMesh::getMaxDimension() {
vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
if(m_submeshes.size() == 0) {
pack_header *pHeader = (pack_header *)m_pPackData;
pack_header *pHeader = (pack_header *)m_pData->getStart();
pack_material *pPackMaterials = (pack_material *)(pHeader+1);
m_submeshes.clear();
for(int iMaterial=0; iMaterial < pHeader->submesh_count; iMaterial++) {
@@ -177,20 +104,23 @@ vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
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);
//
// }
// }
if(m_cBuffers == 0) {
pack_header *pHeader = (pack_header *)m_pPackData;
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();
int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
vector<KRMesh::Submesh *> submeshes = getSubmeshes();
Submesh *pSubmesh = submeshes[iSubmesh];
@@ -200,8 +130,9 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
iVertex = iVertex % MAX_VBO_SIZE;
int cVertexes = pSubmesh->vertex_count;
while(cVertexes > 0) {
if(*iPrevBuffer != iBuffer) {
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
//if(*iPrevBuffer != iBuffer) {
GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
m_pContext->getModelManager()->bindVBO(pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes);
if(*iPrevBuffer == -1) {
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
@@ -211,6 +142,7 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUVB);
}
int data_size = sizeof(VertexData);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(0));
@@ -218,10 +150,9 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
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));
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) {
glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex));
cVertexes -= (MAX_VBO_SIZE - iVertex);
@@ -235,7 +166,7 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
}
KRMesh::VertexData *KRMesh::getVertexData() {
pack_header *pHeader = (pack_header *)m_pPackData;
pack_header *pHeader = (pack_header *)m_pData->getStart();
pack_material *pPackMaterials = (pack_material *)(pHeader+1);
return (VertexData *)(pPackMaterials + pHeader->submesh_count);
}
@@ -246,10 +177,10 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
int submesh_count = submesh_lengths.size();
int vertex_count = vertices.size();
m_iPackFileSize = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(VertexData) * vertex_count;
m_pPackData = malloc(m_iPackFileSize);
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(VertexData) * vertex_count;
m_pData->expand(new_file_size);
pack_header *pHeader = (pack_header *)m_pPackData;
pack_header *pHeader = (pack_header *)m_pData->getStart();
memset(pHeader, 0, sizeof(pack_header));
pHeader->submesh_count = submesh_lengths.size();

View File

@@ -38,6 +38,7 @@
#import "KRVector2.h"
#import "KRVector3.h"
#import "KRResource.h"
#import "KRDataBlock.h"
#import "KREngine-common.h"
@@ -65,7 +66,7 @@ public:
virtual bool save(const std::string& path);
void LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uva, std::vector<KRVector2> uvb, std::vector<KRVector3> normals, std::vector<KRVector3> tangents, std::vector<int> submesh_starts, std::vector<int> submesh_lengths, std::vector<std::string> material_names);
void loadPack(std::string path);
void loadPack(KRDataBlock *data);
void renderSubmesh(int iSubmesh, int *iPrevBuffer);
@@ -113,9 +114,7 @@ public:
protected:
KRVector3 m_minPoint, m_maxPoint;
int m_fdPackFile;
void *m_pPackData;
int m_iPackFileSize;
KRDataBlock *m_pData;
typedef struct {
char szTag[16];
@@ -124,15 +123,8 @@ protected:
int32_t submesh_count;
} pack_header;
GLsizei m_cBuffers;
GLuint *m_pBuffers;
vector<Submesh *> m_submeshes;
void unmap();
void clearData();
void clearBuffers();
};

View File

@@ -46,17 +46,13 @@
#import "KRShaderManager.h"
#import "KRContext.h"
KRModel::KRModel(KRContext &context, std::string name, std::string path) : KRContextObject(context) {
KRModel::KRModel(KRContext &context, std::string name, KRDataBlock *data) : KRContextObject(context) {
m_name = name;
loadPack(path);
}
void KRModel::loadPack(std::string path) {
m_hasTransparency = false;
m_materials.clear();
m_uniqueMaterials.clear();
m_pMesh = new KRMesh(*m_pContext, KRResource::GetFileBase(path));
m_pMesh->loadPack(path);
m_pMesh = new KRMesh(*m_pContext, name);
m_pMesh->loadPack(data);
}
std::string KRModel::getName() {
@@ -70,6 +66,8 @@ 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) {
// fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
if(renderPass != KRNode::RENDER_PASS_FLARES) {
if(m_materials.size() == 0) {
@@ -78,7 +76,9 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
for(std::vector<KRMesh::Submesh *>::iterator itr = submeshes.begin(); itr != submeshes.end(); itr++) {
KRMaterial *pMaterial = pContext->getMaterialManager()->getMaterial((*itr)->szMaterialName);
m_materials.push_back(pMaterial);
m_uniqueMaterials.insert(pMaterial);
if(pMaterial) {
m_uniqueMaterials.insert(pMaterial);
}
}
m_hasTransparency = false;

View File

@@ -52,7 +52,7 @@ class KRMaterial;
class KRModel : public KRContextObject {
public:
KRModel(KRContext &context, std::string name, std::string path);
KRModel(KRContext &context, std::string name, KRDataBlock *data);
virtual ~KRModel();
bool hasTransparency();
@@ -66,9 +66,7 @@ public:
KRMesh *getMesh();
std::string getName();
private:
void loadPack(std::string path);
private:
vector<KRMaterial *> m_materials;
set<KRMaterial *> m_uniqueMaterials;
KRMesh *m_pMesh;

View File

@@ -34,7 +34,8 @@
#import "KRModel.h"
KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
m_currentVBO.handle = 0;
m_currentVBO.data = NULL;
}
KRModelManager::~KRModelManager() {
@@ -44,8 +45,8 @@ KRModelManager::~KRModelManager() {
m_models.empty();
}
KRModel *KRModelManager::loadModel(const char *szName, const char *szPath) {
KRModel *pModel = new KRModel(*m_pContext, szName, szPath);
KRModel *KRModelManager::loadModel(const char *szName, KRDataBlock *pData) {
KRModel *pModel = new KRModel(*m_pContext, szName, pData);
m_models[szName] = pModel;
return pModel;
}
@@ -63,3 +64,35 @@ std::map<std::string, KRModel *> KRModelManager::getModels() {
return m_models;
}
void KRModelManager::bindVBO(const GLvoid *data, GLsizeiptr size) {
assert(size > 0);
if(m_currentVBO.data != data || m_currentVBO.size != size) {
if(m_vbos.find(data) != m_vbos.end()) {
m_currentVBO = m_vbos[data];
assert(m_currentVBO.size == size);
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
} else {
while(m_vbos.size() >= KRENGINE_MAX_VBO_HANDLES) {
// 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.
std::map<const GLvoid *, vbo_info_type>::iterator first_itr = m_vbos.begin();
vbo_info_type firstVBO = first_itr->second;
glDeleteBuffers(1, &firstVBO.handle);
m_vbos.erase(first_itr);
fprintf(stderr, "VBO Swapping...");
}
m_currentVBO.handle = -1;
glGenBuffers(1, &m_currentVBO.handle);
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
m_currentVBO.size = size;
m_currentVBO.data = data;
m_vbos[data] = m_currentVBO;
}
}
}

View File

@@ -32,8 +32,11 @@
#ifndef KRMODELMANAGER_H
#define KRMODELMANAGER_H
#define KRENGINE_MAX_VBO_HANDLES 50
#import "KREngine-common.h"
#import "KRContextObject.h"
#import "KRDataBlock.h"
class KRContext;
class KRModel;
@@ -47,15 +50,30 @@ public:
KRModelManager(KRContext &context);
virtual ~KRModelManager();
KRModel *loadModel(const char *szName, const char *szPath);
KRModel *loadModel(const char *szName, KRDataBlock *pData);
KRModel *getModel(const char *szName);
KRModel *getFirstModel();
std::vector<std::string> getModelNames();
std::map<std::string, KRModel *> getModels();
void bindVBO(const GLvoid *data, GLsizeiptr size);
private:
std::map<std::string, KRModel *> m_models;
typedef struct vbo_info {
GLuint handle;
GLsizeiptr size;
const GLvoid *data;
} vbo_info_type;
vbo_info_type m_currentVBO;
std::map<const GLvoid *, vbo_info_type> m_vbos;
};
#endif

View File

@@ -16,6 +16,7 @@
#import "KRDirectionalLight.h"
#import "KRInstance.h"
#import "KRSkyBox.h"
#import "KRAABB.h"
KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext())
@@ -158,16 +159,7 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
#if TARGET_OS_IPHONE
bool KRNode::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
/*
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
KRNode *child = (*itr);
child->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
*/
return false;
void KRNode::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
}
#endif
@@ -191,6 +183,7 @@ KRBoundingVolume KRNode::getExtents(KRContext *pContext) {
void KRNode::calcExtents(KRContext *pContext) {
clearExtents();
/*
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
KRNode *child = (*itr);
if(m_pExtents) {
@@ -199,6 +192,7 @@ void KRNode::calcExtents(KRContext *pContext) {
m_pExtents = new KRBoundingVolume(child->getExtents(pContext));
}
}
*/
}
const std::vector<KRNode *> &KRNode::getChildren() {
@@ -213,11 +207,6 @@ KRScene &KRNode::getScene() {
return *m_pScene;
}
KRVector3 KRNode::getMinPoint() {
return KRVector3::Min();
KRAABB KRNode::getBounds() {
return KRAABB::Infinite();
}
KRVector3 KRNode::getMaxPoint() {
return KRVector3::Max();
}

View File

@@ -22,6 +22,7 @@ class KRMat4;
class KRTextureManager;
class KRContext;
class KRScene;
class KRAABB;
class KRNode : public KRContextObject
{
@@ -66,13 +67,12 @@ public:
virtual void calcExtents(KRContext *Context);
KRBoundingVolume getExtents(KRContext *pContext);
virtual KRVector3 getMinPoint();
virtual KRVector3 getMaxPoint();
virtual KRAABB getBounds();
KRScene &getScene();
#if TARGET_OS_IPHONE
virtual bool render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
#endif

View File

@@ -23,15 +23,14 @@ KROctree::~KROctree()
void KROctree::add(KRNode *pNode)
{
KRVector3 minPoint = pNode->getMinPoint();
KRVector3 maxPoint = pNode->getMaxPoint();
if(pNode->getMinPoint() == KRVector3::Min() && pNode->getMaxPoint() == KRVector3::Max()) {
KRAABB nodeBounds = pNode->getBounds();
if(nodeBounds == KRAABB::Infinite()) {
// This item is infinitely large; we track it separately
m_outerSceneNodes.insert(pNode);
} else {
if(m_pRootNode == NULL) {
// First item inserted, create a node large enough to fit it
m_pRootNode = new KROctreeNode(KRAABB(pNode->getMinPoint(), pNode->getMaxPoint()));
m_pRootNode = new KROctreeNode(nodeBounds);
m_pRootNode->add(pNode);
} else {
// Keep encapsulating the root node until the new root contains the inserted node
@@ -39,9 +38,9 @@ void KROctree::add(KRNode *pNode)
while(!bInsideRoot) {
KRAABB rootBounds = m_pRootNode->getBounds();
KRVector3 rootSize = rootBounds.size();
if(minPoint.x < rootBounds.min.x || minPoint.y < rootBounds.min.y || minPoint.z < rootBounds.min.z) {
if(nodeBounds.min.x < rootBounds.min.x || nodeBounds.min.y < rootBounds.min.y || nodeBounds.min.z < rootBounds.min.z) {
m_pRootNode = new KROctreeNode(KRAABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode);
} else if(maxPoint.x > rootBounds.max.x || maxPoint.y > rootBounds.max.y || maxPoint.z > rootBounds.max.z) {
} else if(nodeBounds.max.x > rootBounds.max.x || nodeBounds.max.y > rootBounds.max.y || nodeBounds.max.z > rootBounds.max.z) {
m_pRootNode = new KROctreeNode(KRAABB(rootBounds.max, rootBounds.max + rootSize), 0, m_pRootNode);
} else {
bInsideRoot = true;

View File

@@ -100,8 +100,8 @@ bool KROctreeNode::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
}
// FINDME - Test Code:
bGoDeeper = true;
bRendered = true;
//bGoDeeper = true;
//bRendered = true;
if(bGoDeeper) { // Only recurse deeper if we reached this level in the previous pass
for(int i=0; i<8; i++) {
@@ -129,33 +129,40 @@ KRAABB KROctreeNode::getBounds()
void KROctreeNode::add(KRNode *pNode)
{
KRVector3 center = m_bounds.center();
int iChild = getChildIndex(pNode);
if(iChild == -1) {
m_sceneNodes.insert(pNode);
} else {
if(m_children[iChild] == NULL) {
m_children[iChild] = new KROctreeNode(KRAABB(
KRVector3(
(iChild & 1) == 0 ? m_bounds.min.x : center.x,
(iChild & 2) == 0 ? m_bounds.min.y : center.y,
(iChild & 4) == 0 ? m_bounds.min.z : center.z),
KRVector3(
(iChild & 1) == 0 ? center.x : m_bounds.max.x,
(iChild & 2) == 0 ? center.y : m_bounds.max.y,
(iChild & 4) == 0 ? center.z : m_bounds.max.z)
)
);
m_children[iChild] = new KROctreeNode(getChildBounds(iChild));
}
m_children[iChild]->add(pNode);
}
}
KRAABB KROctreeNode::getChildBounds(int iChild)
{
KRVector3 center = m_bounds.center();
return KRAABB(
KRVector3(
(iChild & 1) == 0 ? m_bounds.min.x : center.x,
(iChild & 2) == 0 ? m_bounds.min.y : center.y,
(iChild & 4) == 0 ? m_bounds.min.z : center.z),
KRVector3(
(iChild & 1) == 0 ? center.x : m_bounds.max.x,
(iChild & 2) == 0 ? center.y : m_bounds.max.y,
(iChild & 4) == 0 ? center.z : m_bounds.max.z)
);
}
int KROctreeNode::getChildIndex(KRNode *pNode)
{
KRVector3 min = pNode->getMinPoint();
KRVector3 max = pNode->getMaxPoint();
/*
KRVector3 min = pNode->getMinPoint();
KRVector3 max = pNode->getMaxPoint();
// 0: max.x < center.x && max.y < center.y && max.z < center.z
// 1: min.x > center.x && max.y < center.y && max.z < center.z
// 2: max.x < center.x && min.y > center.y && max.z < center.z
@@ -197,6 +204,14 @@ int KROctreeNode::getChildIndex(KRNode *pNode)
}
}
return iChild;
*/
for(int iChild=0; iChild < 8; iChild++) {
if(getChildBounds(iChild).contains(pNode->getBounds())) {
return iChild;
}
}
return -1;
}
void KROctreeNode::remove(KRNode *pNode)

View File

@@ -32,6 +32,7 @@ public:
void setChildNode(int iChild, KROctreeNode *pChild);
int getChildIndex(KRNode *pNode);
KRAABB getChildBounds(int iChild);
bool isEmpty() const;
bool canShrinkRoot() const;

View File

@@ -36,9 +36,9 @@ std::string KRPointLight::getElementName() {
#if TARGET_OS_IPHONE
bool KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
bool bRendered = KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
@@ -140,8 +140,6 @@ bool KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
}
}
return bRendered;
}
void KRPointLight::generateMesh() {

View File

@@ -23,7 +23,7 @@ public:
#if TARGET_OS_IPHONE
virtual bool render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
#endif
private:

View File

@@ -17,7 +17,6 @@
#include <assert.h>
#include "KRResource.h"
#include "KRMesh.h"
#include "KRScene.h"
#include "KRResource+blend.h"
@@ -27,33 +26,12 @@ std::vector<KRResource *> KRResource::LoadBlenderScene(KRContext &context, const
KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path));
resources.push_back(pScene);
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
KRDataBlock data;
struct stat statbuf;
fdFile = open(path.c_str(), O_RDONLY);
if(fdFile >= 0) {
if(fstat(fdFile, &statbuf) >= 0) {
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
} else {
fileSize = statbuf.st_size;
KRBlendFile blend_file = KRBlendFile(pFile);
}
}
if(data.load(path)) {
KRBlendFile blend_file = KRBlendFile(pFile);
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
}
return resources;
}

View File

@@ -36,322 +36,304 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
std::vector<std::string> material_names_t;
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
KRDataBlock data;
char szSymbol[500][64];
int *pFaces = NULL;
vector<KRMesh::pack_material *> m_materials;
struct stat statbuf;
fdFile = open(path.c_str(), O_RDONLY);
if(fdFile >= 0) {
if(fstat(fdFile, &statbuf) >= 0) {
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
if(data.load(path)) {
// -----=====----- Get counts -----=====-----
int cVertexData = 0;
int cFaces = 1;
int cMaterialFaceStart = 1;
char *pScan = (char *)data.getStart();
char *pEnd = (char *)data.getEnd();
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
fileSize = statbuf.st_size;
// -----=====----- Get counts -----=====-----
int cVertexData = 0;
int cFaces = 1;
int cMaterialFaceStart = 1;
char *pScan = (char *)pFile;
char *pEnd = (char *)pFile + fileSize;
while(pScan < pEnd) {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
int cFaceVertexes = (cSymbols - 3) * 3; // 3 vertexes per triangle. Triangles have 4 symbols. Quads have 5 symbols and generate two triangles.
cVertexData += cFaceVertexes;
cFaces += cFaceVertexes * 3 + 1; // Allocate space for count of vertices, Vertex Index, Texture Coordinate Index, and Normal Index
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(cMaterialFaceStart - cFaces > 0) {
cFaces++;
}
material_names_t.push_back(std::string(szSymbol[1]));
}
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
// -----=====----- Populate vertexes and faces -----=====-----
int *pFaces = (int *)malloc(sizeof(int *) * (cFaces + 1));
std::vector<KRVector3> indexed_vertices;
std::vector<KRVector2> indexed_uva;
std::vector<KRVector3> indexed_normals;
int *pFace = pFaces;
int *pMaterialFaces = pFace++;
*pMaterialFaces = 0;
// --------
pScan = (char *)pFile;
while(pScan < pEnd) {
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
int cFaceVertexes = (cSymbols - 3) * 3; // 3 vertexes per triangle. Triangles have 4 symbols. Quads have 5 symbols and generate two triangles.
cVertexData += cFaceVertexes;
cFaces += cFaceVertexes * 3 + 1; // Allocate space for count of vertices, Vertex Index, Texture Coordinate Index, and Normal Index
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(cMaterialFaceStart - cFaces > 0) {
cFaces++;
}
material_names_t.push_back(std::string(szSymbol[1]));
}
}
}
// -----=====----- Populate vertexes and faces -----=====-----
int *pFaces = (int *)malloc(sizeof(int *) * (cFaces + 1));
std::vector<KRVector3> indexed_vertices;
std::vector<KRVector2> indexed_uva;
std::vector<KRVector3> indexed_normals;
int *pFace = pFaces;
int *pMaterialFaces = pFace++;
*pMaterialFaces = 0;
// --------
pScan = (char *)data.getStart();
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
float x, y, z;
char *pChar = szSymbol[1];
x = strtof(pChar, &pChar);
pChar = szSymbol[2];
y = strtof(pChar, &pChar);
pChar = szSymbol[3];
z = strtof(pChar, &pChar);
indexed_vertices.push_back(KRVector3(x,y,z));
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
char *pChar = szSymbol[1];
float u,v;
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
u = strtof(pChar, &pChar);
pChar = szSymbol[2];
v = strtof(pChar, &pChar);
indexed_uva.push_back(KRVector2(u,v));
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
float x,y,z;
char *pChar = szSymbol[1];
x = strtof(pChar, &pChar);
pChar = szSymbol[2];
y = strtof(pChar, &pChar);
pChar = szSymbol[3];
z = strtof(pChar, &pChar);
indexed_normals.push_back(KRVector3(x,y,z));
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
int cFaceVertices = cSymbols - 1;
*pFace++ = cFaceVertices;
for(int iSymbol=1; iSymbol < cSymbols; iSymbol++) {
char *pChar = szSymbol[iSymbol];
if(*pChar == '.' || (*pChar >= '0' && *pChar <= '9')) {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Vertex Index
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
float x, y, z;
char *pChar = szSymbol[1];
x = strtof(pChar, &pChar);
pChar = szSymbol[2];
y = strtof(pChar, &pChar);
pChar = szSymbol[3];
z = strtof(pChar, &pChar);
indexed_vertices.push_back(KRVector3(x,y,z));
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
char *pChar = szSymbol[1];
float u,v;
u = strtof(pChar, &pChar);
pChar = szSymbol[2];
v = strtof(pChar, &pChar);
indexed_uva.push_back(KRVector2(u,v));
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
float x,y,z;
char *pChar = szSymbol[1];
x = strtof(pChar, &pChar);
pChar = szSymbol[2];
y = strtof(pChar, &pChar);
pChar = szSymbol[3];
z = strtof(pChar, &pChar);
indexed_normals.push_back(KRVector3(x,y,z));
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
int cFaceVertices = cSymbols - 1;
*pFace++ = cFaceVertices;
for(int iSymbol=1; iSymbol < cSymbols; iSymbol++) {
char *pChar = szSymbol[iSymbol];
if(*pChar == '.' || (*pChar >= '0' && *pChar <= '9')) {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Vertex Index
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Texture Coordinate Index
}
} else {
*pFace++ = -1;
}
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Normal Index
}
} else {
*pFace++ = -1;
}
while(*pChar == '/') {
pChar++;
strtol(pChar, &pChar, 10);
}
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Texture Coordinate Index
}
} else {
*pFace++ = -1;
}
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(pFace - pMaterialFaces > 1) {
*pMaterialFaces = pFace - pMaterialFaces - 1;
pMaterialFaces = pFace++;
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Normal Index
}
} else {
*pFace++ = -1;
}
while(*pChar == '/') {
pChar++;
strtol(pChar, &pChar, 10);
}
}
}
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(pFace - pMaterialFaces > 1) {
*pMaterialFaces = pFace - pMaterialFaces - 1;
pMaterialFaces = pFace++;
}
}
*pMaterialFaces = pFace - pMaterialFaces - 1;
*pFace++ = 0;
int iVertex = 0;
std::vector<std::string>::iterator material_itr = material_names_t.begin();
KRMesh::pack_material *pMaterial = new KRMesh::pack_material();
}
}
*pMaterialFaces = pFace - pMaterialFaces - 1;
*pFace++ = 0;
int iVertex = 0;
std::vector<std::string>::iterator material_itr = material_names_t.begin();
KRMesh::pack_material *pMaterial = new KRMesh::pack_material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
memset(pMaterial->szName, 64, 0);
if(material_itr < material_names_t.end()) {
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
}
m_materials.push_back(pMaterial);
pFace = pFaces;
while(*pFace != 0 && iVertex < cVertexData) {
pMaterial->start_vertex = iVertex;
int *pMaterialEndFace = pFace + *pFace++;
while(pFace < pMaterialEndFace && iVertex < cVertexData) {
int cFaceVertexes = *pFace;
KRVector3 firstFaceVertex;
KRVector3 prevFaceVertex;
KRVector3 firstFaceNormal;
KRVector3 prevFaceNormal;
KRVector2 firstFaceUva;
KRVector2 prevFaceUva;
for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) {
if(iFaceVertex > 2) {
// There have already been 3 vertices. Now we need to split the quad into a second triangle composed of the 1st, 3rd, and 4th vertices
iVertex+=2;
vertices.push_back(firstFaceVertex);
uva.push_back(firstFaceUva);
normals.push_back(firstFaceNormal);
vertices.push_back(prevFaceVertex);
uva.push_back(prevFaceUva);
normals.push_back(prevFaceNormal);
}
KRVector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]];
KRVector2 new_uva;
if(pFace[iFaceVertex*3+2] >= 0) {
new_uva = indexed_uva[pFace[iFaceVertex*3+2]];
}
KRVector3 normal;
if(pFace[iFaceVertex*3+3] >= 0){
KRVector3 normal = indexed_normals[pFace[iFaceVertex*3+3]];
}
vertices.push_back(vertex);
uva.push_back(new_uva);
normals.push_back(normal);
if(iFaceVertex==0) {
firstFaceVertex = vertex;
firstFaceUva = new_uva;
firstFaceNormal = normal;
}
prevFaceVertex = vertex;
prevFaceUva = new_uva;
prevFaceNormal = normal;
iVertex++;
}
pFace += cFaceVertexes * 3 + 1;
}
pMaterial->vertex_count = iVertex - pMaterial->start_vertex;
if(*pFace != 0) {
pMaterial = new KRMesh::pack_material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
memset(pMaterial->szName, 64, 0);
if(material_itr < material_names_t.end()) {
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
}
m_materials.push_back(pMaterial);
pFace = pFaces;
while(*pFace != 0 && iVertex < cVertexData) {
pMaterial->start_vertex = iVertex;
int *pMaterialEndFace = pFace + *pFace++;
while(pFace < pMaterialEndFace && iVertex < cVertexData) {
int cFaceVertexes = *pFace;
KRVector3 firstFaceVertex;
KRVector3 prevFaceVertex;
KRVector3 firstFaceNormal;
KRVector3 prevFaceNormal;
KRVector2 firstFaceUva;
KRVector2 prevFaceUva;
for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) {
if(iFaceVertex > 2) {
// There have already been 3 vertices. Now we need to split the quad into a second triangle composed of the 1st, 3rd, and 4th vertices
iVertex+=2;
vertices.push_back(firstFaceVertex);
uva.push_back(firstFaceUva);
normals.push_back(firstFaceNormal);
vertices.push_back(prevFaceVertex);
uva.push_back(prevFaceUva);
normals.push_back(prevFaceNormal);
}
KRVector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]];
KRVector2 new_uva;
if(pFace[iFaceVertex*3+2] >= 0) {
new_uva = indexed_uva[pFace[iFaceVertex*3+2]];
}
KRVector3 normal;
if(pFace[iFaceVertex*3+3] >= 0){
KRVector3 normal = indexed_normals[pFace[iFaceVertex*3+3]];
}
vertices.push_back(vertex);
uva.push_back(new_uva);
normals.push_back(normal);
if(iFaceVertex==0) {
firstFaceVertex = vertex;
firstFaceUva = new_uva;
firstFaceNormal = normal;
}
prevFaceVertex = vertex;
prevFaceUva = new_uva;
prevFaceNormal = normal;
iVertex++;
}
pFace += cFaceVertexes * 3 + 1;
}
pMaterial->vertex_count = iVertex - pMaterial->start_vertex;
if(*pFace != 0) {
pMaterial = new KRMesh::pack_material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
memset(pMaterial->szName, 64, 0);
if(material_itr < material_names_t.end()) {
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
}
m_materials.push_back(pMaterial);
}
}
for(int iMaterial=0; iMaterial < m_materials.size(); iMaterial++) {
KRMesh::pack_material *pNewMaterial = m_materials[iMaterial];
if(pNewMaterial->vertex_count > 0) {
material_names.push_back(std::string(pNewMaterial->szName));
submesh_starts.push_back(pNewMaterial->start_vertex);
submesh_lengths.push_back(pNewMaterial->vertex_count);
}
delete pNewMaterial;
}
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names);
}
}
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
for(int iMaterial=0; iMaterial < m_materials.size(); iMaterial++) {
KRMesh::pack_material *pNewMaterial = m_materials[iMaterial];
if(pNewMaterial->vertex_count > 0) {
material_names.push_back(std::string(pNewMaterial->szName));
submesh_starts.push_back(pNewMaterial->start_vertex);
submesh_lengths.push_back(pNewMaterial->vertex_count);
}
delete pNewMaterial;
}
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names);
}
if(pFaces) {

View File

@@ -38,6 +38,7 @@
#import "KRDirectionalLight.h"
#import "KRScene.h"
#import "KRNode.h"
KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) {
m_pContext = &context;
@@ -61,6 +62,7 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
if(cShadowBuffers > 0) {
m_pContext->getTextureManager()->selectTexture(3, NULL);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -70,6 +72,7 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
}
if(cShadowBuffers > 1) {
m_pContext->getTextureManager()->selectTexture(4, NULL);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -79,6 +82,7 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
}
if(cShadowBuffers > 2) {
m_pContext->getTextureManager()->selectTexture(5, NULL);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[2]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -135,17 +139,93 @@ 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)
{
if(pOctreeNode) {
if(frustrumVolume.test_intersect(pOctreeNode->getBounds())) { // Only recurse deeper if within the view frustrum
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
pOctreeNode->endOcclusionQuery();
for(int i=0; i<8; i++) {
render(pOctreeNode->getChildren()[i], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
KRMat4 projectionMatrix;
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
projectionMatrix = pCamera->getProjectionMatrix();
}
KRAABB octreeBounds = pOctreeNode->getBounds();
if(true) {
//if(pOctreeNode->getBounds().visible(viewMatrix * projectionMatrix)) { // Only recurse deeper if within the view frustrum
//if(frustrumVolume.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_OPAQUE || renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
if(true) {
//if(visibleBounds.find(octreeBounds) != visibleBounds.end()) {
if(can_occlusion_test) {
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
}
// Occlusion test indicates that this bounding box was visible in the last frame
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
//assert(pOctreeNode->getBounds().contains((*itr)->getBounds())); // Sanity check
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
if(can_occlusion_test) {
pOctreeNode->endOcclusionQuery();
}
for(int i=0; i<8; i++) {
render(pOctreeNode->getChildren()[i], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
} else if(KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE) {
if(pOctreeNode->getSceneNodes().empty()) {
for(int i=0; i<8; i++) {
render(pOctreeNode->getChildren()[i], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
} else {
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("occlusion_test", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
static const GLfloat cubeVertices[] = {
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
1.0,-1.0, 1.0,
-1.0,-1.0, 1.0,
-1.0,-1.0,-1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0,-1.0,
1.0, 1.0, 1.0,
1.0, 1.0,-1.0,
1.0,-1.0, 1.0,
1.0,-1.0,-1.0,
-1.0,-1.0,-1.0,
1.0, 1.0,-1.0,
-1.0, 1.0,-1.0
};
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices);
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
KRMat4 matModel = KRMat4();
matModel.scale(octreeBounds.size() / 2.0f);
matModel.translate(octreeBounds.center());
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
// Enable additive blending
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 14);
glDisable(GL_BLEND);
pOctreeNode->endOcclusionQuery();
}
}
} else {
fprintf(stderr, "Octree culled: (%f, %f, %f) - (%f, %f, %f)\n", pOctreeNode->getBounds().min.x, pOctreeNode->getBounds().min.y, pOctreeNode->getBounds().min.z, pOctreeNode->getBounds().max.x, pOctreeNode->getBounds().max.y, pOctreeNode->getBounds().max.z);
//fprintf(stderr, "Octree culled: (%f, %f, %f) - (%f, %f, %f)\n", pOctreeNode->getBounds().min.x, pOctreeNode->getBounds().min.y, pOctreeNode->getBounds().min.z, pOctreeNode->getBounds().max.x, pOctreeNode->getBounds().max.y, pOctreeNode->getBounds().max.z);
}
}
}
@@ -190,16 +270,20 @@ KRDirectionalLight *KRScene::findFirstDirectionalLight(KRNode &node) {
return NULL;
}
KRScene *KRScene::LoadXML(KRContext &context, const std::string& path)
KRScene *KRScene::Load(KRContext &context, const std::string &name, KRDataBlock *data)
{
data->append((void *)"\0", 1); // Ensure data is null terminated, to read as a string safely
tinyxml2::XMLDocument doc;
doc.LoadFile(path.c_str());
KRScene *new_scene = new KRScene(context, KRResource::GetFileBase(path));
fprintf(stderr, "Scene Content: %s\n", data->getStart());
doc.Parse((char *)data->getStart());
KRScene *new_scene = new KRScene(context, name);
KRNode *n = KRNode::LoadXML(*new_scene, doc.RootElement()->FirstChildElement());
if(n) {
new_scene->getRootNode()->addChild(n);
}
delete data;
return new_scene;
}

View File

@@ -57,7 +57,7 @@ public:
virtual std::string getExtension();
virtual bool save(const std::string& path);
static KRScene *LoadXML(KRContext &context, const std::string& path);
static KRScene *Load(KRContext &context, const std::string &name, KRDataBlock *data);
KRNode *getRootNode();
KRDirectionalLight *getFirstDirectionalLight();

View File

@@ -42,8 +42,8 @@ KRSceneManager::~KRSceneManager() {
m_scenes.empty();
}
KRScene *KRSceneManager::loadScene(const char *szName, const char *szPath) {
KRScene *pScene = KRScene::LoadXML(*m_pContext, szPath);
KRScene *KRSceneManager::loadScene(const char *szName, KRDataBlock *data) {
KRScene *pScene = KRScene::Load(*m_pContext, szName, data);
m_scenes[szName] = pScene;
return pScene;
}

View File

@@ -34,6 +34,7 @@
#import "KREngine-common.h"
#import "KRContextObject.h"
#import "KRDataBlock.h"
class KRScene;
@@ -47,7 +48,7 @@ public:
KRSceneManager(KRContext &context);
virtual ~KRSceneManager();
KRScene *loadScene(const char *szName, const char *szPath);
KRScene *loadScene(const char *szName, KRDataBlock *data);
KRScene *getScene(const char *szName);
KRScene *getFirstScene();

View File

@@ -113,28 +113,14 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
return pShader;
}
void KRShaderManager::loadFragmentShader(const std::string &name, const std::string &path) {
ifstream ifs(path.c_str(), ios::in | ios::binary | ios::ate);
ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
vector<char> bytes(fileSize);
ifs.read(&bytes[0], fileSize);
m_fragShaderSource[name] = string(&bytes[0], fileSize);
void KRShaderManager::loadFragmentShader(const std::string &name, KRDataBlock *data) {
m_fragShaderSource[name] = string((char *)data->getStart(), data->getSize());
delete data;
}
void KRShaderManager::loadVertexShader(const std::string &name, const std::string &path) {
ifstream ifs(path.c_str(), ios::in | ios::binary | ios::ate);
ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
vector<char> bytes(fileSize);
ifs.read(&bytes[0], fileSize);
m_vertShaderSource[name] = string(&bytes[0], fileSize);
void KRShaderManager::loadVertexShader(const std::string &name, KRDataBlock *data) {
m_vertShaderSource[name] = string((char *)data->getStart(), data->getSize());
delete data;
}
const std::string &KRShaderManager::getFragShaderSource(const std::string &name) {

View File

@@ -34,6 +34,7 @@
#import <map>
#import <string>
#import "KRCamera.h"
#import "KRDataBlock.h"
using std::map;
using std::vector;
@@ -50,8 +51,8 @@ public:
KRShaderManager(KRContext &context);
virtual ~KRShaderManager();
void loadFragmentShader(const std::string &name, const std::string &path);
void loadVertexShader(const std::string &name, const std::string &path);
void loadFragmentShader(const std::string &name, KRDataBlock *data);
void loadVertexShader(const std::string &name, KRDataBlock *data);
const std::string &getFragShaderSource(const std::string &name);
const std::string &getVertShaderSource(const std::string &name);

View File

@@ -13,6 +13,7 @@
#import "KRContext.h"
#import "KRMat4.h"
#import "KRResource.h"
#import "KRContext.h"
KRSkyBox::KRSkyBox(KRScene &scene, std::string name) : KRNode(scene, name)
{
@@ -138,14 +139,13 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &
// KRShader *pShader = pContext->getShaderManager()->getShader("sky_box", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, renderPass);
// pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, NULL, NULL, NULL, 0, renderPass);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_pFrontTexture->getName());
glBindTexture(GL_TEXTURE_2D, m_pBackTexture->getName());
glBindTexture(GL_TEXTURE_2D, m_pTopTexture->getName());
glBindTexture(GL_TEXTURE_2D, m_pBottomTexture->getName());
glBindTexture(GL_TEXTURE_2D, m_pLeftTexture->getName());
glBindTexture(GL_TEXTURE_2D, m_pRightTexture->getName());
m_pContext->getTextureManager()->selectTexture(0, m_pFrontTexture);
m_pContext->getTextureManager()->selectTexture(1, m_pBackTexture);
m_pContext->getTextureManager()->selectTexture(2, m_pTopTexture);
m_pContext->getTextureManager()->selectTexture(3, m_pBottomTexture);
m_pContext->getTextureManager()->selectTexture(4, m_pLeftTexture);
m_pContext->getTextureManager()->selectTexture(5, m_pRightTexture);
// Disable z-buffer write
glDepthMask(GL_FALSE);

View File

@@ -30,6 +30,7 @@
//
#include "KRTexture.h"
#include "KRTextureManager.h"
#import <stdint.h>
#include <sys/mman.h>
@@ -68,117 +69,93 @@ typedef struct _PVRTexHeader
uint32_t numSurfs;
} PVRTexHeader;
KRTexture::KRTexture() {
KRTexture::KRTexture(KRDataBlock *data, KRTextureManager *manager) {
m_pData = data;
m_iName = 0;
m_fdFile = 0;
m_pFile = NULL;
m_fileSize = 0;
m_pManager = manager;
load();
}
KRTexture::~KRTexture() {
if(m_iName != 0) {
glDeleteTextures(1, &m_iName);
}
if(m_pFile != NULL) {
munmap(m_pFile, m_fileSize);
}
if(m_fdFile != 0) {
close(m_fdFile);
}
releaseHandle();
delete m_pData;
}
#if TARGET_OS_IPHONE
bool KRTexture::loadFromFile(const char *szFile) {
struct stat statbuf;
m_fdFile = open(szFile, O_RDONLY);
if(m_fdFile < 0) {
return false;
bool KRTexture::load() {
PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart();
uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK;
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
} else if(formatFlags == kPVRTextureFlagTypePVRTC_2) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
} else {
if(fstat(m_fdFile,&statbuf) < 0) {
return false;
assert(false);
}
uint32_t pvrTag = header->pvrTag;
if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) ||
gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) ||
gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) ||
gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff))
{
return false;
}
m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness
m_iHeight = header->height;
m_bHasAlpha = header->bitmaskAlpha;
uint8_t *bytes = ((uint8_t *)m_pData->getStart()) + sizeof(PVRTexHeader);
uint32_t dataLength = header->dataLength, dataOffset = 0, dataSize = 0;
uint32_t width = m_iWidth, height = m_iHeight, bpp = 4;
uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0;
// Calculate the data size for each texture level and respect the minimum number of blocks
while(dataOffset < dataLength) {
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
widthBlocks = width / 4;
heightBlocks = height / 4;
bpp = 4;
} else {
void *pFile;
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, m_fdFile, 0))
== (caddr_t) -1) {
return false;
} else {
m_fileSize = statbuf.st_size;
m_pFile = pFile;
PVRTexHeader *header = (PVRTexHeader *)pFile;
uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK;
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
} else if(formatFlags == kPVRTextureFlagTypePVRTC_2) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
} else {
assert(false);
}
uint32_t pvrTag = header->pvrTag;
if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) ||
gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) ||
gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) ||
gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff))
{
return false;
}
m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness
m_iHeight = header->height;
m_bHasAlpha = header->bitmaskAlpha;
uint8_t *bytes = ((uint8_t *)pFile) + sizeof(PVRTexHeader);
uint32_t dataLength = header->dataLength, dataOffset = 0, dataSize = 0;
uint32_t width = m_iWidth, height = m_iHeight, bpp = 4;
uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0;
// Calculate the data size for each texture level and respect the minimum number of blocks
while(dataOffset < dataLength) {
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
widthBlocks = width / 4;
heightBlocks = height / 4;
bpp = 4;
} else {
blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
widthBlocks = width / 8;
heightBlocks = height / 4;
bpp = 2;
}
// Clamp to minimum number of blocks
if (widthBlocks < 2) {
widthBlocks = 2;
}
if (heightBlocks < 2) {
heightBlocks = 2;
}
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
dataBlockStruct newBlock;
newBlock.start = bytes+dataOffset;
newBlock.length = dataSize;
m_blocks.push_back(newBlock);
dataOffset += dataSize;
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
}
return true;
}
blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
widthBlocks = width / 8;
heightBlocks = height / 4;
bpp = 2;
}
// Clamp to minimum number of blocks
if (widthBlocks < 2) {
widthBlocks = 2;
}
if (heightBlocks < 2) {
heightBlocks = 2;
}
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
dataBlockStruct newBlock;
newBlock.start = bytes+dataOffset;
newBlock.length = dataSize;
m_blocks.push_back(newBlock);
dataOffset += dataSize;
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
}
return true;
}
#endif
@@ -228,9 +205,20 @@ bool KRTexture::createGLTexture() {
return true;
}
GLuint KRTexture::getName() {
GLuint KRTexture::getHandle() {
if(m_iName == 0) {
if(!createGLTexture()) {
createGLTexture(); // FINDME - HACK! The first texture fails with 0x501 return code but loads on second try
}
createGLTexture();
}
return m_iName;
}
}
void KRTexture::releaseHandle() {
if(m_iName != 0) {
glDeleteTextures(1, &m_iName);
m_iName = 0;
}
}

View File

@@ -34,24 +34,23 @@
#import <string>
#import "KREngine-common.h"
#import "KRDataBlock.h"
using std::list;
#ifndef KRTEXTURE_H
#define KRTEXTURE_H
class KRTextureManager;
class KRTexture {
public:
KRTexture();
KRTexture(KRDataBlock *data, KRTextureManager *manager);
~KRTexture();
#if TARGET_OS_IPHONE
bool loadFromFile(const char *szFile);
#endif
bool createGLTexture();
GLuint getName();
GLuint getHandle();
void releaseHandle();
private:
@@ -68,9 +67,11 @@ private:
std::list<dataBlockStruct> m_blocks;
int m_fdFile;
int m_fileSize;
void *m_pFile;
KRDataBlock *m_pData;
bool load();
KRTextureManager *m_pManager;
};
#endif

View File

@@ -33,7 +33,9 @@
#include <string.h>
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
for(int iTexture=0; iTexture<KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
m_activeTextures[iTexture] = NULL;
}
}
KRTextureManager::~KRTextureManager() {
@@ -44,19 +46,8 @@ KRTextureManager::~KRTextureManager() {
#if TARGET_OS_IPHONE
KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szPath) {
KRTexture *pTexture = new KRTexture();
if(!pTexture->loadFromFile(szPath)) {
delete pTexture;
return NULL;
}
if(!pTexture->createGLTexture()) {
if(!pTexture->createGLTexture()) { // FINDME - HACK! The first texture fails with 0x501 return code but loads on second try
delete pTexture;
return NULL;
}
}
KRTexture *KRTextureManager::loadTexture(const char *szName, KRDataBlock *data) {
KRTexture *pTexture = new KRTexture(data, this);
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
@@ -70,15 +61,6 @@ KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szPath)
#endif
GLuint KRTextureManager::getTextureName(const char *szName) {
KRTexture *pTexture = getTexture(szName);
if(pTexture) {
return pTexture->getName();
} else {
return NULL;
}
}
KRTexture *KRTextureManager::getTexture(const char *szName) {
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
@@ -92,4 +74,44 @@ KRTexture *KRTextureManager::getTexture(const char *szName) {
return (*itr).second;
}
}
}
void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) {
if(m_activeTextures[iTextureUnit] != pTexture) {
glActiveTexture(GL_TEXTURE0 + iTextureUnit);
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
glBindTexture(GL_TEXTURE_2D, pTexture->getHandle());
// TODO - These texture parameters should be assigned by the material or texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} else {
glBindTexture(GL_TEXTURE_2D, 0);
}
if(m_activeTextures[iTextureUnit] != NULL) {
KRTexture *unloadedTexture = m_activeTextures[iTextureUnit];
bool bActive = false;
for(int iTexture=0; iTexture < KRENGINE_MAX_TEXTURE_UNITS; iTexture++) {
if(m_activeTextures[iTexture] == unloadedTexture) {
bActive = true;
}
}
if(!bActive) {
// Only return a texture to the cache when the last texture unit referencing it is re-assigned to a different texture
if(m_textureCache.find(unloadedTexture) == m_textureCache.end()) {
m_textureCache.insert(unloadedTexture);
while(m_textureCache.size() > KRENGINE_MAX_TEXTURE_HANDLES) {
// Keep texture size within limits
KRTexture *droppedTexture = (*m_textureCache.begin());
droppedTexture->releaseHandle();
m_textureCache.erase(droppedTexture);
fprintf(stderr, "Texture Swapping...\n");
}
}
}
}
m_activeTextures[iTextureUnit] = pTexture;
}
}

View File

@@ -29,6 +29,9 @@
// or implied, of Kearwood Gilbert.
//
#define KRENGINE_MAX_TEXTURE_UNITS 8
#define KRENGINE_MAX_TEXTURE_HANDLES 20
#ifndef KRTEXTUREMANAGER_H
#define KRTEXTUREMANAGER_H
@@ -45,17 +48,21 @@ public:
KRTextureManager(KRContext &context);
virtual ~KRTextureManager();
void selectTexture(int iTextureUnit, KRTexture *pTexture);
#if TARGET_OS_IPHONE
KRTexture *loadTexture(const char *szName, const char *szPath);
KRTexture *loadTexture(const char *szName, KRDataBlock *data);
#endif
GLuint getTextureName(const char *szName);
KRTexture *getTexture(const char *szFile);
private:
std::map<std::string, KRTexture *> m_textures;
KRTexture *m_activeTextures[KRENGINE_MAX_TEXTURE_UNITS];
std::set<KRTexture *> m_textureCache;
};
#endif

View File

@@ -0,0 +1,34 @@
//
// flare.fsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
void main() {
gl_FragColor = vec4(0.00, 0.00, 0.00, 0.00);
}

View File

@@ -0,0 +1,34 @@
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
attribute vec4 vertex_position;
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
void main()
{
gl_Position = mvp_matrix * vertex_position;
}

View File

@@ -1,5 +1,5 @@
//
// flare.fsh
// visualize_overlay.fsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
@@ -32,3 +32,4 @@
void main() {
gl_FragColor = vec4(0.0, 0.05, 0.05, 0.0);
}

View File

@@ -1,3 +1,7 @@
//
// visualize_overlay.vsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are

View File

@@ -21,6 +21,10 @@
28D7ACF80DDB3853001CB0EB /* KRObjViewViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* KRObjViewViewController.mm */; };
E40611D714E4E98B0065996A /* README.txt in Resources */ = {isa = PBXBuildFile; fileRef = E40611D314E4E98B0065996A /* README.txt */; };
E40611D814E4E98B0065996A /* release_notes.txt in Resources */ = {isa = PBXBuildFile; fileRef = E40611D414E4E98B0065996A /* release_notes.txt */; };
E430D08615F88A9F0010558D /* occlusion_test.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08515F88A9F0010558D /* occlusion_test.fsh */; };
E430D08B15F88B950010558D /* occlusion_test.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08A15F88B950010558D /* occlusion_test.vsh */; };
E430D08C15F88BC50010558D /* occlusion_test.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E430D08A15F88B950010558D /* occlusion_test.vsh */; };
E430D08D15F88BC70010558D /* occlusion_test.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E430D08515F88A9F0010558D /* occlusion_test.fsh */; };
E43A7A6E13CA2BA2000A565E /* libKREngine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E43A7A6D13CA2BA2000A565E /* libKREngine.a */; };
E46DBE831512B7C300D59F86 /* libTestFlight.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E40611D214E4E98B0065996A /* libTestFlight.a */; };
E46FED2D13C9A49F009F5814 /* ShadowShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2113C9A488009F5814 /* ShadowShader.vsh */; };
@@ -32,7 +36,8 @@
E4769DF3158A7915004B83AC /* flare.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4769DF1158A7915004B83AC /* flare.fsh */; };
E4769DF4158A7915004B83AC /* flare.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4769DF2158A7915004B83AC /* flare.vsh */; };
E48278B415F037B9001C9431 /* visualize_overlay.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E48278B215F037B9001C9431 /* visualize_overlay.vsh */; };
E48278B515F037B9001C9431 /* visualize_overlay.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E48278B315F037B9001C9431 /* visualize_overlay.fsh */; };
E48839A415F92C6900BD66D5 /* visualize_overlay.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */; };
E48839A515F92C8D00BD66D5 /* visualize_overlay.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */; };
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */; };
E4A9DEC715412923009DF363 /* light_point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC2154128F0009DF363 /* light_point.fsh */; };
E4A9DEC815412923009DF363 /* light_point.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC515412906009DF363 /* light_point.vsh */; };
@@ -63,6 +68,8 @@
E40611D314E4E98B0065996A /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
E40611D414E4E98B0065996A /* release_notes.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = release_notes.txt; sourceTree = "<group>"; };
E40611D514E4E98B0065996A /* TestFlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = TestFlight.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E430D08515F88A9F0010558D /* occlusion_test.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.fsh; path = ../KREngine/KREngine/Shaders/occlusion_test.fsh; sourceTree = "<group>"; };
E430D08A15F88B950010558D /* occlusion_test.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.vsh; path = ../KREngine/KREngine/Shaders/occlusion_test.vsh; sourceTree = "<group>"; };
E43A7A6D13CA2BA2000A565E /* libKREngine.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libKREngine.a; sourceTree = BUILT_PRODUCTS_DIR; };
E46FED2113C9A488009F5814 /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = ../KREngine/KREngine/Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E46FED2213C9A488009F5814 /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = ../KREngine/KREngine/Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
@@ -72,8 +79,8 @@
E46FED2613C9A488009F5814 /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = ../KREngine/KREngine/Shaders/PostShader.vsh; sourceTree = "<group>"; };
E4769DF1158A7915004B83AC /* flare.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = flare.fsh; path = ../KREngine/KREngine/Shaders/flare.fsh; sourceTree = "<group>"; };
E4769DF2158A7915004B83AC /* flare.vsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = flare.vsh; path = ../KREngine/KREngine/Shaders/flare.vsh; sourceTree = "<group>"; };
E48278B215F037B9001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; name = visualize_overlay.vsh; path = ../KREngine/KREngine/Shaders/visualize_overlay.vsh; sourceTree = "<group>"; };
E48278B315F037B9001C9431 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; name = visualize_overlay.fsh; path = ../KREngine/KREngine/visualize_overlay.fsh; sourceTree = "<group>"; };
E48278B215F037B9001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.vsh; path = ../KREngine/KREngine/Shaders/visualize_overlay.vsh; sourceTree = "<group>"; };
E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.fsh; path = ../KREngine/KREngine/Shaders/visualize_overlay.fsh; sourceTree = "<group>"; };
E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
E4A9DEC2154128F0009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = ../KREngine/KREngine/Shaders/light_point.fsh; sourceTree = "<group>"; };
E4A9DEC515412906009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = ../KREngine/KREngine/Shaders/light_point.vsh; sourceTree = "<group>"; };
@@ -192,8 +199,10 @@
E46FED2013C9A472009F5814 /* Shaders */ = {
isa = PBXGroup;
children = (
E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */,
E430D08A15F88B950010558D /* occlusion_test.vsh */,
E430D08515F88A9F0010558D /* occlusion_test.fsh */,
E48278B215F037B9001C9431 /* visualize_overlay.vsh */,
E48278B315F037B9001C9431 /* visualize_overlay.fsh */,
E4769DF1158A7915004B83AC /* flare.fsh */,
E4769DF2158A7915004B83AC /* flare.vsh */,
E4A9DEC2154128F0009DF363 /* light_point.fsh */,
@@ -279,6 +288,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E48839A515F92C8D00BD66D5 /* visualize_overlay.fsh in Resources */,
E4769DF3158A7915004B83AC /* flare.fsh in Resources */,
E4769DF4158A7915004B83AC /* flare.vsh in Resources */,
E4A9DEC715412923009DF363 /* light_point.fsh in Resources */,
@@ -292,7 +302,8 @@
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */,
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */,
E48278B415F037B9001C9431 /* visualize_overlay.vsh in Resources */,
E48278B515F037B9001C9431 /* visualize_overlay.fsh in Resources */,
E430D08C15F88BC50010558D /* occlusion_test.vsh in Resources */,
E430D08D15F88BC70010558D /* occlusion_test.fsh in Resources */,
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */,
E40611D714E4E98B0065996A /* README.txt in Resources */,
@@ -311,6 +322,9 @@
1D3623260D0F684500981E51 /* KRObjViewAppDelegate.mm in Sources */,
28D7ACF80DDB3853001CB0EB /* KRObjViewViewController.mm in Sources */,
1063FC77136D6A1B00EE555B /* KRObjViewGLView.mm in Sources */,
E430D08615F88A9F0010558D /* occlusion_test.fsh in Sources */,
E430D08B15F88B950010558D /* occlusion_test.vsh in Sources */,
E48839A415F92C6900BD66D5 /* visualize_overlay.fsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};