diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index d44fbbe..eef1240 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -16,6 +16,14 @@ E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; }; E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; settings = {ATTRIBUTES = (); }; }; E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E40F982C184A7A2700CFA4D8 /* KRMeshQuad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40F982A184A7A2700CFA4D8 /* KRMeshQuad.cpp */; }; + E40F982D184A7A2700CFA4D8 /* KRMeshQuad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40F982A184A7A2700CFA4D8 /* KRMeshQuad.cpp */; }; + E40F982E184A7A2700CFA4D8 /* KRMeshQuad.h in Headers */ = {isa = PBXBuildFile; fileRef = E40F982B184A7A2700CFA4D8 /* KRMeshQuad.h */; }; + E40F982F184A7A2700CFA4D8 /* KRMeshQuad.h in Headers */ = {isa = PBXBuildFile; fileRef = E40F982B184A7A2700CFA4D8 /* KRMeshQuad.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E40F9832184A7BAC00CFA4D8 /* KRSprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40F9830184A7BAC00CFA4D8 /* KRSprite.cpp */; }; + E40F9833184A7BAC00CFA4D8 /* KRSprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40F9830184A7BAC00CFA4D8 /* KRSprite.cpp */; }; + E40F9834184A7BAC00CFA4D8 /* KRSprite.h in Headers */ = {isa = PBXBuildFile; fileRef = E40F9831184A7BAC00CFA4D8 /* KRSprite.h */; }; + E40F9835184A7BAC00CFA4D8 /* KRSprite.h in Headers */ = {isa = PBXBuildFile; fileRef = E40F9831184A7BAC00CFA4D8 /* KRSprite.h */; settings = {ATTRIBUTES = (Public, ); }; }; E414BAE21435557300A668C4 /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRModel.h */; settings = {ATTRIBUTES = (); }; }; E414BAE51435558900A668C4 /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRModel.cpp */; }; E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; settings = {ATTRIBUTES = (); }; }; @@ -73,6 +81,18 @@ E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; }; E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; settings = {ATTRIBUTES = (); }; }; E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E43F70DC181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; + E43F70DD181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; + E43F70DE181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; }; + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E43F70E51824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; + E43F70E61824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; + E43F70E71824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; }; + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E43F70FF1824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; + E43F71001824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; + E43F71011824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; }; + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4409D2916FA748700310F76 /* font.tga in Resources */ = {isa = PBXBuildFile; fileRef = E41AE1DD16B124CA00980428 /* font.tga */; }; E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (); }; }; E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -90,7 +110,7 @@ E459040616C30CD9002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040516C30CD9002B00A0 /* AudioUnit.framework */; }; E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; settings = {ATTRIBUTES = (); }; }; E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; }; + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk.a */; }; E460292C166834AB00261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (); }; }; E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -109,6 +129,10 @@ E461A176152E5C5600F2044A /* KRPointLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A157152E555400F2044A /* KRPointLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; E461A177152E5C6600F2044A /* KRMat4.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017613C99BDC0098455B /* KRMat4.h */; settings = {ATTRIBUTES = (Public, ); }; }; E461A17A152E5C9100F2044A /* KRMat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017713C99BDC0098455B /* KRMat4.cpp */; }; + E468447F17FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; + E468448017FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; + E468448117FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; }; + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */; }; E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; }; @@ -267,8 +291,8 @@ E4E6F68716BA5DF700E410F8 /* debug_font.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */; }; E4E6F68816BA5DF700E410F8 /* dust_particle.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */; }; E4E6F68916BA5DF700E410F8 /* dust_particle.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */; }; - E4E6F68A16BA5DF700E410F8 /* flare.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64E16BA5D9400E410F8 /* flare.fsh */; }; - E4E6F68B16BA5DF700E410F8 /* flare.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64F16BA5D9400E410F8 /* flare.vsh */; }; + E4E6F68A16BA5DF700E410F8 /* sprite.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64E16BA5D9400E410F8 /* sprite.fsh */; }; + E4E6F68B16BA5DF700E410F8 /* sprite.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64F16BA5D9400E410F8 /* sprite.vsh */; }; E4E6F68C16BA5DF700E410F8 /* light_directional.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65016BA5D9400E410F8 /* light_directional.fsh */; }; E4E6F68D16BA5DF700E410F8 /* light_directional.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65116BA5D9400E410F8 /* light_directional.vsh */; }; E4E6F68E16BA5DF700E410F8 /* light_point_inside.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */; }; @@ -299,8 +323,8 @@ E4E6F6A716BA5E0A00E410F8 /* debug_font_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */; }; E4E6F6A816BA5E0A00E410F8 /* dust_particle_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */; }; E4E6F6A916BA5E0A00E410F8 /* dust_particle_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */; }; - E4E6F6AA16BA5E0A00E410F8 /* flare_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */; }; - E4E6F6AB16BA5E0A00E410F8 /* flare_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */; }; + E4E6F6AA16BA5E0A00E410F8 /* sprite_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */; }; + E4E6F6AB16BA5E0A00E410F8 /* sprite_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */; }; E4E6F6AC16BA5E0A00E410F8 /* light_directional_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */; }; E4E6F6AD16BA5E0A00E410F8 /* light_directional_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */; }; E4E6F6AE16BA5E0A00E410F8 /* light_point_inside_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */; }; @@ -387,6 +411,10 @@ E4030E4B160A3CF000592648 /* KRStockGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRStockGeometry.h; sourceTree = ""; }; E40BA45215EFF79500D7C3DD /* KRAABB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRAABB.cpp; sourceTree = ""; }; E40BA45315EFF79500D7C3DD /* KRAABB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRAABB.h; sourceTree = ""; }; + E40F982A184A7A2700CFA4D8 /* KRMeshQuad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRMeshQuad.cpp; sourceTree = ""; }; + E40F982B184A7A2700CFA4D8 /* KRMeshQuad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRMeshQuad.h; sourceTree = ""; }; + E40F9830184A7BAC00CFA4D8 /* KRSprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRSprite.cpp; sourceTree = ""; }; + E40F9831184A7BAC00CFA4D8 /* KRSprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRSprite.h; sourceTree = ""; }; E414BAE11435557300A668C4 /* KRModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRModel.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E414BAE41435558800A668C4 /* KRModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRModel.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E414BAE6143557D200A668C4 /* KRScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRScene.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -400,6 +428,10 @@ E41AE1DD16B124CA00980428 /* font.tga */ = {isa = PBXFileReference; lastKnownFileType = file; path = font.tga; sourceTree = ""; }; E41B6BA716BE436100B510EB /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; E41B6BA916BE437800B510EB /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/CoreAudio.framework; sourceTree = DEVELOPER_DIR; }; + E42559AA184DD4490081BB20 /* flare.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.fsh; sourceTree = ""; }; + E42559AC184DD45A0081BB20 /* flare.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.vsh; sourceTree = ""; }; + E42559AE184DD4730081BB20 /* flare_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.fsh; sourceTree = ""; }; + E42559B0184DD48B0081BB20 /* flare_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.vsh; sourceTree = ""; }; E428C2F11669610500A16EDF /* KRAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRAnimationManager.h; sourceTree = ""; }; E428C2F41669611600A16EDF /* KRAnimationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRAnimationManager.cpp; sourceTree = ""; }; E428C2F71669612500A16EDF /* KRAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRAnimation.h; sourceTree = ""; }; @@ -419,6 +451,12 @@ E437849716C488360037FD43 /* hrtf_kemar.krbundle */ = {isa = PBXFileReference; lastKnownFileType = file; path = hrtf_kemar.krbundle; sourceTree = ""; }; E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRContextObject.cpp; sourceTree = ""; }; E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRContextObject.h; sourceTree = ""; }; + E43F70DA181B20E300136169 /* KRLODSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRLODSet.cpp; sourceTree = ""; }; + E43F70DB181B20E400136169 /* KRLODSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRLODSet.h; sourceTree = ""; }; + E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KRTextureStreamer.mm; sourceTree = ""; }; + E43F70E41824D9AB00136169 /* KRTextureStreamer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureStreamer.h; sourceTree = ""; }; + E43F70FD1824E73100136169 /* KRMeshStreamer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KRMeshStreamer.mm; sourceTree = ""; }; + E43F70FE1824E73100136169 /* KRMeshStreamer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRMeshStreamer.h; sourceTree = ""; }; E44F38231683B22C00399B5D /* KRRenderSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRRenderSettings.h; sourceTree = ""; }; E44F38271683B24400399B5D /* KRRenderSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRRenderSettings.cpp; sourceTree = ""; }; E450273716E0491D00FDEC5C /* KRReverbZone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRReverbZone.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; @@ -429,7 +467,7 @@ E459040516C30CD9002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; E460292516681CFE00261BB9 /* KRTextureAnimated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureAnimated.h; sourceTree = ""; }; E460292716681D1000261BB9 /* KRTextureAnimated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRTextureAnimated.cpp; sourceTree = ""; }; - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2013.3-static.a"; path = "lib/gcc4/ub/libfbxsdk-2013.3-static.a"; sourceTree = FBXSDK; }; + E460292916682BD900261BB9 /* libfbxsdk.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfbxsdk.a; path = "../../FBX SDK/2014.2/lib/ios-i386/release/libfbxsdk.a"; sourceTree = FBXSDK; }; E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRLight.h; sourceTree = ""; }; E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRLight.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRPointLight.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -438,6 +476,8 @@ E461A15E152E565700F2044A /* KRDirectionalLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRDirectionalLight.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A164152E56C000F2044A /* KRSpotLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRSpotLight.cpp; sourceTree = ""; }; E461A167152E570500F2044A /* KRSpotLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRSpotLight.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + E468447D17FFDF51001F1FA1 /* KRLocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRLocator.cpp; sourceTree = ""; }; + E468447E17FFDF51001F1FA1 /* KRLocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRLocator.h; sourceTree = ""; }; E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "KRResource+blend.cpp"; sourceTree = ""; }; E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KRResource+blend.h"; sourceTree = ""; }; E46C214115364BC8009CABF3 /* tinyxml2_readme.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = tinyxml2_readme.txt; sourceTree = ""; }; @@ -545,8 +585,8 @@ E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = debug_font_osx.vsh; sourceTree = ""; }; E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle_osx.fsh; sourceTree = ""; }; E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle_osx.vsh; sourceTree = ""; }; - E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.fsh; sourceTree = ""; }; - E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.vsh; sourceTree = ""; }; + E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite_osx.fsh; sourceTree = ""; }; + E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite_osx.vsh; sourceTree = ""; }; E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional_osx.fsh; sourceTree = ""; }; E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional_osx.vsh; sourceTree = ""; }; E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_point_inside_osx.fsh; sourceTree = ""; }; @@ -573,8 +613,8 @@ E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = debug_font.vsh; sourceTree = ""; }; E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle.fsh; sourceTree = ""; }; E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle.vsh; sourceTree = ""; }; - E4E6F64E16BA5D9400E410F8 /* flare.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.fsh; sourceTree = ""; }; - E4E6F64F16BA5D9400E410F8 /* flare.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.vsh; sourceTree = ""; }; + E4E6F64E16BA5D9400E410F8 /* sprite.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.fsh; sourceTree = ""; }; + E4E6F64F16BA5D9400E410F8 /* sprite.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.vsh; sourceTree = ""; }; E4E6F65016BA5D9400E410F8 /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional.fsh; sourceTree = ""; }; E4E6F65116BA5D9400E410F8 /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional.vsh; sourceTree = ""; }; E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_point_inside.fsh; sourceTree = ""; }; @@ -647,7 +687,7 @@ E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */, E497B95D151BF05F00D3DC67 /* CoreServices.framework in Frameworks */, E497B95F151BF09600D3DC67 /* SystemConfiguration.framework in Frameworks */, - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */, + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -698,8 +738,8 @@ E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */, E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */, E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */, - E4E6F64E16BA5D9400E410F8 /* flare.fsh */, - E4E6F64F16BA5D9400E410F8 /* flare.vsh */, + E4E6F64E16BA5D9400E410F8 /* sprite.fsh */, + E4E6F64F16BA5D9400E410F8 /* sprite.vsh */, E4E6F65016BA5D9400E410F8 /* light_directional.fsh */, E4E6F65116BA5D9400E410F8 /* light_directional.vsh */, E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */, @@ -723,6 +763,8 @@ E4E6F66416BA5D9400E410F8 /* volumetric_fog_downsampled.vsh */, E4E6F66516BA5D9400E410F8 /* volumetric_fog.fsh */, E4E6F66616BA5D9400E410F8 /* volumetric_fog.vsh */, + E42559AA184DD4490081BB20 /* flare.fsh */, + E42559AC184DD45A0081BB20 /* flare.vsh */, ); path = Shaders; sourceTree = ""; @@ -878,6 +920,8 @@ E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */, E460292516681CFE00261BB9 /* KRTextureAnimated.h */, E460292716681D1000261BB9 /* KRTextureAnimated.cpp */, + E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */, + E43F70E41824D9AB00136169 /* KRTextureStreamer.h */, ); name = Texture; sourceTree = ""; @@ -893,6 +937,10 @@ E4C454AE167BB8FC003586CD /* KRMeshCube.cpp */, E4C454B1167BC04B003586CD /* KRMeshSphere.h */, E4C454B4167BC05C003586CD /* KRMeshSphere.cpp */, + E43F70FD1824E73100136169 /* KRMeshStreamer.mm */, + E43F70FE1824E73100136169 /* KRMeshStreamer.h */, + E40F982A184A7A2700CFA4D8 /* KRMeshQuad.cpp */, + E40F982B184A7A2700CFA4D8 /* KRMeshQuad.h */, ); name = Mesh; sourceTree = ""; @@ -971,6 +1019,12 @@ E480BE6B1671C653004EC8AD /* KRBone.cpp */, E4AE635B1704FB0A00B460CD /* KRLODGroup.cpp */, E4AE635C1704FB0A00B460CD /* KRLODGroup.h */, + E468447D17FFDF51001F1FA1 /* KRLocator.cpp */, + E468447E17FFDF51001F1FA1 /* KRLocator.h */, + E43F70DA181B20E300136169 /* KRLODSet.cpp */, + E43F70DB181B20E400136169 /* KRLODSet.h */, + E40F9830184A7BAC00CFA4D8 /* KRSprite.cpp */, + E40F9831184A7BAC00CFA4D8 /* KRSprite.h */, ); name = "Scene Graph Nodes"; sourceTree = ""; @@ -1059,7 +1113,7 @@ E459040316C30CC5002B00A0 /* AudioUnit.framework */, E41B6BA916BE437800B510EB /* CoreAudio.framework */, 10CC33A3168530A300BB9846 /* libPVRTexLib.a */, - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */, + E460292916682BD900261BB9 /* libfbxsdk.a */, E4BBBB9A1512A48200F43B5B /* Foundation.framework */, E46DBE7D1512AD4900D59F86 /* OpenGL.framework */, E4F027D41697A02D00D4427D /* OpenAL.framework */, @@ -1105,8 +1159,8 @@ E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */, E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */, E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */, - E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */, - E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */, + E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */, + E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */, E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */, E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */, E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */, @@ -1128,6 +1182,8 @@ E4E6F62816BA5D8300E410F8 /* volumetric_fog_downsampled_osx.vsh */, E4E6F62916BA5D8300E410F8 /* volumetric_fog_osx.fsh */, E4E6F62A16BA5D8300E410F8 /* volumetric_fog_osx.vsh */, + E42559AE184DD4730081BB20 /* flare_osx.fsh */, + E42559B0184DD48B0081BB20 /* flare_osx.vsh */, ); path = Shaders; sourceTree = ""; @@ -1180,6 +1236,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + E43F70DE181B20E400136169 /* KRLODSet.h in Headers */, E491019513C99BDC0098455B /* KRMaterial.h in Headers */, E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */, E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */, @@ -1194,10 +1251,13 @@ E414BAE21435557300A668C4 /* KRModel.h in Headers */, E414BAE7143557D200A668C4 /* KRScene.h in Headers */, E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */, + E40F982E184A7A2700CFA4D8 /* KRMeshQuad.h in Headers */, E497B94A151BCEE900D3DC67 /* KRResource.h in Headers */, E461A152152E54B500F2044A /* KRLight.h in Headers */, E461A15C152E563100F2044A /* KRDirectionalLight.h in Headers */, E461A168152E570700F2044A /* KRSpotLight.h in Headers */, + E468448117FFDF51001F1FA1 /* KRLocator.h in Headers */, + E43F70E71824D9AB00136169 /* KRTextureStreamer.h in Headers */, E4F975321536220900FD60B2 /* KRNode.h in Headers */, E46C214715364BC8009CABF3 /* tinyxml2.h in Headers */, E48C696F15374F5B00232E28 /* KRContext.h in Headers */, @@ -1207,6 +1267,7 @@ E4924C2715EE95E800B965C6 /* KROctree.h in Headers */, E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */, E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */, + E40F9834184A7BAC00CFA4D8 /* KRSprite.h in Headers */, E488399615F928CA00BD66D5 /* KRBundle.h in Headers */, E488399E15F92BE000BD66D5 /* KRBundleManager.h in Headers */, E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */, @@ -1246,6 +1307,7 @@ E4AE635F1704FB0A00B460CD /* KRLODGroup.h in Headers */, E4EC73C31720B1FF0065299F /* KRVector4.h in Headers */, E48CF944173453990005EBBB /* KRFloat.h in Headers */, + E43F71011824E73100136169 /* KRMeshStreamer.h in Headers */, E45134B81746A4A300443C21 /* KRBehavior.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1321,8 +1383,14 @@ E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */, E499BF1D16AE74FF007FCDBE /* KRTextureAnimated.h in Headers */, E4EC73C41720B1FF0065299F /* KRVector4.h in Headers */, + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */, + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */, E4AE63601704FB0A00B460CD /* KRLODGroup.h in Headers */, E45134B91746A4A300443C21 /* KRBehavior.h in Headers */, + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */, + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */, + E40F982F184A7A2700CFA4D8 /* KRMeshQuad.h in Headers */, + E40F9835184A7BAC00CFA4D8 /* KRSprite.h in Headers */, E48CF945173453990005EBBB /* KRFloat.h in Headers */, E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */, E499BF2316AE7636007FCDBE /* kraken-prefix.pch in Headers */, @@ -1451,8 +1519,8 @@ E4E6F68716BA5DF700E410F8 /* debug_font.vsh in Resources */, E4E6F68816BA5DF700E410F8 /* dust_particle.fsh in Resources */, E4E6F68916BA5DF700E410F8 /* dust_particle.vsh in Resources */, - E4E6F68A16BA5DF700E410F8 /* flare.fsh in Resources */, - E4E6F68B16BA5DF700E410F8 /* flare.vsh in Resources */, + E4E6F68A16BA5DF700E410F8 /* sprite.fsh in Resources */, + E4E6F68B16BA5DF700E410F8 /* sprite.vsh in Resources */, E4E6F68C16BA5DF700E410F8 /* light_directional.fsh in Resources */, E4E6F68D16BA5DF700E410F8 /* light_directional.vsh in Resources */, E4E6F68E16BA5DF700E410F8 /* light_point_inside.fsh in Resources */, @@ -1491,8 +1559,8 @@ E4E6F6A716BA5E0A00E410F8 /* debug_font_osx.vsh in Resources */, E4E6F6A816BA5E0A00E410F8 /* dust_particle_osx.fsh in Resources */, E4E6F6A916BA5E0A00E410F8 /* dust_particle_osx.vsh in Resources */, - E4E6F6AA16BA5E0A00E410F8 /* flare_osx.fsh in Resources */, - E4E6F6AB16BA5E0A00E410F8 /* flare_osx.vsh in Resources */, + E4E6F6AA16BA5E0A00E410F8 /* sprite_osx.fsh in Resources */, + E4E6F6AB16BA5E0A00E410F8 /* sprite_osx.vsh in Resources */, E4E6F6AC16BA5E0A00E410F8 /* light_directional_osx.fsh in Resources */, E4E6F6AD16BA5E0A00E410F8 /* light_directional_osx.vsh in Resources */, E4E6F6AE16BA5E0A00E410F8 /* light_point_inside_osx.fsh in Resources */, @@ -1536,14 +1604,17 @@ E491019A13C99BDC0098455B /* KRMeshManager.cpp in Sources */, E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */, E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */, + E43F70DC181B20E400136169 /* KRLODSet.cpp in Sources */, E414BAE51435558900A668C4 /* KRModel.cpp in Sources */, E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */, E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */, E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */, E497B94D151BCF2500D3DC67 /* KRResource.cpp in Sources */, E497B950151BD2CE00D3DC67 /* KRResource+obj.cpp in Sources */, + E43F70FF1824E73100136169 /* KRMeshStreamer.mm in Sources */, E461A156152E54F800F2044A /* KRLight.cpp in Sources */, E461A159152E557E00F2044A /* KRPointLight.cpp in Sources */, + E468447F17FFDF51001F1FA1 /* KRLocator.cpp in Sources */, E461A15F152E565700F2044A /* KRDirectionalLight.cpp in Sources */, E461A165152E56C000F2044A /* KRSpotLight.cpp in Sources */, E4F975361536221C00FD60B2 /* KRNode.cpp in Sources */, @@ -1566,6 +1637,7 @@ E4324BA816444C230043185B /* KRParticleSystem.cpp in Sources */, E4324BAE16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */, E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */, + E43F70E51824D9AB00136169 /* KRTextureStreamer.mm in Sources */, E428C2F51669611600A16EDF /* KRAnimationManager.cpp in Sources */, E428C2FB1669613200A16EDF /* KRAnimation.cpp in Sources */, E428C3071669628A00A16EDF /* KRAnimationCurve.cpp in Sources */, @@ -1577,11 +1649,13 @@ E4C454AF167BB8FC003586CD /* KRMeshCube.cpp in Sources */, E4C454B5167BC05C003586CD /* KRMeshSphere.cpp in Sources */, E4C454BB167BD248003586CD /* KRHitInfo.cpp in Sources */, + E40F9832184A7BAC00CFA4D8 /* KRSprite.cpp in Sources */, E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */, E414F9A61694D977000B3D58 /* KRUnknownManager.cpp in Sources */, E414F9AC1694DA37000B3D58 /* KRUnknown.cpp in Sources */, E48B68151697794F00D99917 /* KRAudioSource.cpp in Sources */, E4F027C716979CCD00D4427D /* KRAudioManager.cpp in Sources */, + E40F982C184A7A2700CFA4D8 /* KRMeshQuad.cpp in Sources */, E4F027CE16979CE200D4427D /* KRAudioSample.cpp in Sources */, E4F027DE1697BFFF00D4427D /* KRAudioBuffer.cpp in Sources */, E4943231169E08D200BCB891 /* KRAmbientZone.cpp in Sources */, @@ -1607,6 +1681,7 @@ E4BBBBA71512A6DC00F43B5B /* KRVector3.cpp in Sources */, E4B2A43B1523B02E004CB0EC /* KRMaterial.cpp in Sources */, E4BBBB8E1512A40300F43B5B /* krengine_osx.mm in Sources */, + E468448017FFDF51001F1FA1 /* KRLocator.cpp in Sources */, E497B947151BA99500D3DC67 /* KRVector2.cpp in Sources */, E497B94E151BCF2500D3DC67 /* KRResource.cpp in Sources */, E497B951151BD2CE00D3DC67 /* KRResource+obj.cpp in Sources */, @@ -1629,6 +1704,7 @@ E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */, E48C697315374F7E00232E28 /* KRContext.cpp in Sources */, E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */, + E40F982D184A7A2700CFA4D8 /* KRMeshQuad.cpp in Sources */, E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */, E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */, E4AFC6BB15F7C7D600DDB4C8 /* KROctreeNode.cpp in Sources */, @@ -1636,8 +1712,11 @@ E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */, E488399515F928CA00BD66D5 /* KRBundle.cpp in Sources */, E488399D15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */, + E43F70DD181B20E400136169 /* KRLODSet.cpp in Sources */, + E43F71001824E73100136169 /* KRMeshStreamer.mm in Sources */, E4B175AD161F5A1000B8FB80 /* KRTexture.cpp in Sources */, E4B175B3161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */, + E40F9833184A7BAC00CFA4D8 /* KRSprite.cpp in Sources */, E4CA10EA1637BD2B005D9400 /* KRTexturePVR.cpp in Sources */, E4CA10F01637BD58005D9400 /* KRTextureTGA.cpp in Sources */, E4CA11791639CC90005D9400 /* KRViewport.cpp in Sources */, @@ -1651,6 +1730,7 @@ E428C31A1669A25D00A16EDF /* KRAnimationAttribute.cpp in Sources */, E416AA9D1671375C000F6786 /* KRAnimationCurveManager.cpp in Sources */, E480BE6D1671C653004EC8AD /* KRBone.cpp in Sources */, + E43F70E61824D9AB00136169 /* KRTextureStreamer.mm in Sources */, E4C454B0167BB8FC003586CD /* KRMeshCube.cpp in Sources */, E4C454B6167BC05C003586CD /* KRMeshSphere.cpp in Sources */, E4C454BC167BD248003586CD /* KRHitInfo.cpp in Sources */, @@ -1701,21 +1781,22 @@ E491016913C99B9E0098455B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"; - GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_C_LANGUAGE_STANDARD = c11; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1"; GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_UNROLL_LOOPS = YES; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( /usr/local/include, "$(SRCROOT)/3rdparty/**", ); - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -1725,18 +1806,20 @@ E491016A13C99B9E0098455B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_C_LANGUAGE_STANDARD = c11; + GCC_OPTIMIZATION_LEVEL = fast; + GCC_UNROLL_LOOPS = YES; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( /usr/local/include, "$(SRCROOT)/3rdparty/**", ); - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + LLVM_VECTORIZE_LOOPS = YES; MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -1747,6 +1830,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; DSTROOT = /tmp/KREngine.dst; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1754,7 +1838,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "kraken_ios/Kraken-Prefix.pch"; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", @@ -1762,7 +1846,6 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = kraken; SHARED_PRECOMPS_DIR = "$(CACHE_ROOT)/SharedPrecompiledHeaders"; - SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1771,6 +1854,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; DSTROOT = /tmp/KREngine.dst; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1778,7 +1862,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "kraken_ios/Kraken-Prefix.pch"; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", @@ -1786,7 +1870,6 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = kraken; SHARED_PRECOMPS_DIR = "$(CACHE_ROOT)/SharedPrecompiledHeaders"; - SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -1796,7 +1879,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1815,14 +1897,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; @@ -1840,7 +1922,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -1859,14 +1940,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; diff --git a/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - ios.xcscheme b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - ios.xcscheme new file mode 100644 index 0000000..832c872 --- /dev/null +++ b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - ios.xcscheme @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - osx.xcscheme b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - osx.xcscheme new file mode 100644 index 0000000..03db38e --- /dev/null +++ b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken - osx.xcscheme @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - OSX.xcscheme b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - OSX.xcscheme new file mode 100644 index 0000000..a5f6a90 --- /dev/null +++ b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - OSX.xcscheme @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - iOS.xcscheme b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - iOS.xcscheme new file mode 100644 index 0000000..b95caa0 --- /dev/null +++ b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/Kraken Standard Assets - iOS.xcscheme @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/xcschememanagement.plist b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..46ad7fe --- /dev/null +++ b/KREngine/Kraken.xcodeproj/xcuserdata/admin8onf.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,60 @@ + + + + + SchemeUserState + + Kraken - ios.xcscheme + + isShown + + orderHint + 30 + + Kraken - osx.xcscheme + + isShown + + orderHint + 31 + + Kraken Standard Assets - OSX.xcscheme + + isShown + + orderHint + 33 + + Kraken Standard Assets - iOS.xcscheme + + isShown + + orderHint + 32 + + + SuppressBuildableAutocreation + + E491016013C99B9E0098455B + + primary + + + E4BBBB7D1512A40300F43B5B + + primary + + + E4C8E4E316B9B2D50031DDCB + + primary + + + E4C8E4F316B9B2E20031DDCB + + primary + + + + + diff --git a/KREngine/kraken/KRAmbientZone.cpp b/KREngine/kraken/KRAmbientZone.cpp index 5770fe0..fac94fb 100644 --- a/KREngine/kraken/KRAmbientZone.cpp +++ b/KREngine/kraken/KRAmbientZone.cpp @@ -97,7 +97,8 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector &point KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/KREngine/kraken/KRAnimation.cpp b/KREngine/kraken/KRAnimation.cpp index 02b99a8..7db4273 100644 --- a/KREngine/kraken/KRAnimation.cpp +++ b/KREngine/kraken/KRAnimation.cpp @@ -85,9 +85,10 @@ bool KRAnimation::save(KRDataBlock &data) { KRAnimation *KRAnimation::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 + std::string xml_string = data->getString(); + tinyxml2::XMLDocument doc; - doc.Parse((char *)data->getStart()); + doc.Parse(xml_string.c_str()); KRAnimation *new_animation = new KRAnimation(context, name); tinyxml2::XMLElement *animation_node = doc.RootElement(); @@ -172,7 +173,6 @@ void KRAnimation::update(float deltaTime) void KRAnimation::Play() { - m_local_time = 0.0f; m_playing = true; getContext().getAnimationManager()->updateActiveAnimations(this); } @@ -296,3 +296,31 @@ void KRAnimation::deleteCurves() } } +void KRAnimation::_lockData() +{ + for(unordered_map::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) { + KRAnimationLayer *layer = (*layer_itr).second; + for(std::vector::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) { + KRAnimationAttribute *attribute = *attribute_itr; + KRAnimationCurve *curve = attribute->getCurve(); + if(curve) { + curve->_lockData(); + } + } + } +} + +void KRAnimation::_unlockData() +{ + for(unordered_map::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) { + KRAnimationLayer *layer = (*layer_itr).second; + for(std::vector::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) { + KRAnimationAttribute *attribute = *attribute_itr; + KRAnimationCurve *curve = attribute->getCurve(); + if(curve) { + curve->_unlockData(); + } + } + } +} + diff --git a/KREngine/kraken/KRAnimation.h b/KREngine/kraken/KRAnimation.h index a052177..2c731ea 100644 --- a/KREngine/kraken/KRAnimation.h +++ b/KREngine/kraken/KRAnimation.h @@ -71,6 +71,9 @@ public: KRAnimation *split(const std::string &name, float start_time, float duration, bool strip_unchanging_attributes = true, bool clone_curves = true); void deleteCurves(); + void _lockData(); + void _unlockData(); + private: unordered_map m_layers; bool m_auto_play; diff --git a/KREngine/kraken/KRAnimationCurve.cpp b/KREngine/kraken/KRAnimationCurve.cpp index 48077e9..366ae26 100644 --- a/KREngine/kraken/KRAnimationCurve.cpp +++ b/KREngine/kraken/KRAnimationCurve.cpp @@ -37,11 +37,13 @@ KRAnimationCurve::KRAnimationCurve(KRContext &context, const std::string &name) { m_pData = new KRDataBlock(); m_pData->expand(sizeof(animation_curve_header)); + m_pData->lock(); animation_curve_header *header = (animation_curve_header *)m_pData->getStart(); strcpy(header->szTag, "KRCURVE1.0 "); header->frame_rate = 30.0f; header->frame_start = 0; header->frame_count = 0; + m_pData->unlock(); } KRAnimationCurve::~KRAnimationCurve() @@ -84,11 +86,16 @@ KRAnimationCurve *KRAnimationCurve::Load(KRContext &context, const std::string & int KRAnimationCurve::getFrameCount() { - return ((animation_curve_header *)m_pData->getStart())->frame_count; + m_pData->lock(); + int frame_count = ((animation_curve_header *)m_pData->getStart())->frame_count; + m_pData->unlock(); + + return frame_count; } void KRAnimationCurve::setFrameCount(int frame_count) { + m_pData->lock(); int prev_frame_count = getFrameCount(); if(frame_count != prev_frame_count) { float fill_value = 0.0f; @@ -102,30 +109,42 @@ void KRAnimationCurve::setFrameCount(int frame_count) } ((animation_curve_header *)m_pData->getStart())->frame_count = frame_count; } + m_pData->unlock(); } float KRAnimationCurve::getFrameRate() { - return ((animation_curve_header *)m_pData->getStart())->frame_rate; + m_pData->lock(); + float frame_rate =((animation_curve_header *)m_pData->getStart())->frame_rate; + m_pData->unlock(); + return frame_rate; } void KRAnimationCurve::setFrameRate(float frame_rate) { + m_pData->lock(); ((animation_curve_header *)m_pData->getStart())->frame_rate = frame_rate; + m_pData->unlock(); } int KRAnimationCurve::getFrameStart() { - return ((animation_curve_header *)m_pData->getStart())->frame_start; + m_pData->lock(); + int frame_start = ((animation_curve_header *)m_pData->getStart())->frame_start; + m_pData->unlock(); + return frame_start; } void KRAnimationCurve::setFrameStart(int frame_number) { + m_pData->lock(); ((animation_curve_header *)m_pData->getStart())->frame_start = frame_number; + m_pData->unlock(); } float KRAnimationCurve::getValue(int frame_number) { + m_pData->lock(); //printf("frame_number: %i\n", frame_number); int clamped_frame = frame_number - getFrameStart(); if(clamped_frame < 0) { @@ -134,43 +153,56 @@ float KRAnimationCurve::getValue(int frame_number) clamped_frame = getFrameCount()-1; } float *frame_data = (float *)((char *)m_pData->getStart() + sizeof(animation_curve_header)); - return frame_data[clamped_frame]; + float v = frame_data[clamped_frame]; + m_pData->unlock(); + return v; } void KRAnimationCurve::setValue(int frame_number, float value) { + m_pData->lock(); int clamped_frame = frame_number - getFrameStart(); if(clamped_frame >= 0 && clamped_frame < getFrameCount()) { float *frame_data = (float *)((char *)m_pData->getStart() + sizeof(animation_curve_header)); frame_data[clamped_frame] = value; } + m_pData->unlock(); } float KRAnimationCurve::getValue(float local_time) { // TODO - Need to add interpolation for time values between frames. // Must consider looping animations when determining which two frames to interpolate between. - return getValue((int)(local_time * getFrameRate())); + m_pData->lock(); + float v = getValue((int)(local_time * getFrameRate())); + m_pData->unlock(); + return v; } bool KRAnimationCurve::valueChanges(float start_time, float duration) { - return valueChanges((int)(start_time * getFrameRate()), (int)(duration * getFrameRate())); + m_pData->lock(); + bool c = valueChanges((int)(start_time * getFrameRate()), (int)(duration * getFrameRate())); + m_pData->unlock(); + return c; } bool KRAnimationCurve::valueChanges(int start_frame, int frame_count) { - + m_pData->lock(); float first_value = getValue(start_frame); + bool change_found = false; + // Range of frames is not inclusive of last frame - for(int frame_number = start_frame + 1; frame_number < start_frame + frame_count; frame_number++) { + for(int frame_number = start_frame + 1; frame_number < start_frame + frame_count && !change_found; frame_number++) { if(getValue(frame_number) != first_value) { - return true; + change_found = true; } } - return false; + m_pData->unlock(); + return change_found; } KRAnimationCurve *KRAnimationCurve::split(const std::string &name, float start_time, float duration) @@ -185,12 +217,24 @@ KRAnimationCurve *KRAnimationCurve::split(const std::string &name, int start_fra new_curve->setFrameRate(getFrameRate()); new_curve->setFrameStart(start_frame); new_curve->setFrameCount(frame_count); + new_curve->m_pData->lock(); // Range of frames is not inclusive of last frame for(int frame_number = start_frame; frame_number < start_frame + frame_count; frame_number++) { new_curve->setValue(frame_number, getValue(frame_number)); // TODO - MEMCPY here? } + new_curve->m_pData->unlock(); getContext().getAnimationCurveManager()->addAnimationCurve(new_curve); return new_curve; } + +void KRAnimationCurve::_lockData() +{ + m_pData->lock(); +} + +void KRAnimationCurve::_unlockData() +{ + m_pData->unlock(); +} diff --git a/KREngine/kraken/KRAnimationCurve.h b/KREngine/kraken/KRAnimationCurve.h index ff5309c..2a2beda 100644 --- a/KREngine/kraken/KRAnimationCurve.h +++ b/KREngine/kraken/KRAnimationCurve.h @@ -67,6 +67,9 @@ public: KRAnimationCurve *split(const std::string &name, float start_time, float duration); KRAnimationCurve *split(const std::string &name, int start_frame, int frame_count); + void _lockData(); + void _unlockData(); + private: KRDataBlock *m_pData; diff --git a/KREngine/kraken/KRAnimationCurveManager.cpp b/KREngine/kraken/KRAnimationCurveManager.cpp index 548d378..08c6cbe 100644 --- a/KREngine/kraken/KRAnimationCurveManager.cpp +++ b/KREngine/kraken/KRAnimationCurveManager.cpp @@ -50,12 +50,19 @@ void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve *curve) { KRAnimationCurve *KRAnimationCurveManager::loadAnimationCurve(const std::string &name, KRDataBlock *data) { KRAnimationCurve *pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data); - m_animationCurves[name] = pAnimationCurve; + if(pAnimationCurve) { + m_animationCurves[name] = pAnimationCurve; + } return pAnimationCurve; } KRAnimationCurve *KRAnimationCurveManager::getAnimationCurve(const std::string &name) { - return m_animationCurves[name]; + unordered_map::iterator itr = m_animationCurves.find(name); + if(itr == m_animationCurves.end()) { + return NULL; // Not found + } else { + return (*itr).second; + } } unordered_map &KRAnimationCurveManager::getAnimationCurves() { @@ -64,6 +71,7 @@ unordered_map &KRAnimationCurveManager::getAnim void KRAnimationCurveManager::addAnimationCurve(KRAnimationCurve *new_animation_curve) { + assert(new_animation_curve != NULL); m_animationCurves[new_animation_curve->getName()] = new_animation_curve; } diff --git a/KREngine/kraken/KRAnimationManager.cpp b/KREngine/kraken/KRAnimationManager.cpp index 76224e7..40e3667 100644 --- a/KREngine/kraken/KRAnimationManager.cpp +++ b/KREngine/kraken/KRAnimationManager.cpp @@ -38,6 +38,11 @@ KRAnimationManager::KRAnimationManager(KRContext &context) : KRContextObject(con } KRAnimationManager::~KRAnimationManager() { + for(std::set::iterator itr = m_activeAnimations.begin(); itr != m_activeAnimations.end(); itr++) { + KRAnimation *animation = *itr; + animation->_unlockData(); + } + for(unordered_map::iterator itr = m_animations.begin(); itr != m_animations.end(); ++itr){ delete (*itr).second; } @@ -52,11 +57,13 @@ void KRAnimationManager::startFrame(float deltaTime) // Add playing animations to the active animations list if(active_animations_itr == m_activeAnimations.end()) { m_activeAnimations.insert(animation); + animation->_lockData(); } } else { // Remove stopped animations from the active animations list if(active_animations_itr != m_activeAnimations.end()) { m_activeAnimations.erase(active_animations_itr); + animation->_unlockData(); } } } diff --git a/KREngine/kraken/KRAudioManager.cpp b/KREngine/kraken/KRAudioManager.cpp index 428cb2b..4d8158f 100644 --- a/KREngine/kraken/KRAudioManager.cpp +++ b/KREngine/kraken/KRAudioManager.cpp @@ -214,8 +214,8 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData) uint64_t end_time = mach_absolute_time(); - uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds - uint64_t max_duration = (uint64_t)inNumberFrames * 1000000000 / 44100; +// uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds +// uint64_t max_duration = (uint64_t)inNumberFrames * 1000000000 / 44100; // fprintf(stderr, "audio load: %5.1f%% hrtf channels: %li\n", (float)(duration * 1000 / max_duration) / 10.0f, m_mapped_sources.size()); } @@ -1364,14 +1364,14 @@ KRDataBlock *KRAudioManager::getBufferData(int size) data = new KRDataBlock(); data->expand(size); } - + data->lock(); return data; - } void KRAudioManager::recycleBufferData(KRDataBlock *data) { if(data != NULL) { + data->unlock(); if(data->getSize() == KRENGINE_AUDIO_MAX_BUFFER_SIZE && m_bufferPoolIdle.size() < KRENGINE_AUDIO_MAX_POOL_SIZE) { m_bufferPoolIdle.push_back(data); } else { diff --git a/KREngine/kraken/KRAudioSample.cpp b/KREngine/kraken/KRAudioSample.cpp index 793729f..b115711 100644 --- a/KREngine/kraken/KRAudioSample.cpp +++ b/KREngine/kraken/KRAudioSample.cpp @@ -198,7 +198,7 @@ OSStatus KRAudioSample::ReadProc( // AudioFile_ReadProc KRAudioSample *sound = (KRAudioSample *)inClientData; UInt32 max_count = sound->m_pData->getSize() - inPosition; *actualCount = requestCount < max_count ? requestCount : max_count; - memcpy(buffer, (unsigned char *)sound->m_pData->getStart() + inPosition, *actualCount); + sound->m_pData->copy(buffer, inPosition, *actualCount); return noErr; } @@ -231,6 +231,7 @@ void KRAudioSample::openFile() { // AudioFileInitializeWithCallbacks if(m_fileRef == NULL) { + // Temp variables UInt32 propertySize; diff --git a/KREngine/kraken/KRAudioSource.cpp b/KREngine/kraken/KRAudioSource.cpp index afef53d..dd1668a 100644 --- a/KREngine/kraken/KRAudioSource.cpp +++ b/KREngine/kraken/KRAudioSource.cpp @@ -56,6 +56,7 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n m_enable_obstruction = true; m_start_audio_frame = -1; + m_paused_audio_frame = 0; } KRAudioSource::~KRAudioSource() @@ -208,7 +209,8 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector &point KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_light; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, rim_light, 0.0f)) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); @@ -314,12 +316,13 @@ void KRAudioSource::setRolloffFactor(float rolloff_factor) void KRAudioSource::setLooping(bool looping) { + // Enable or disable looping playback; Audio source must be stopped and re-started for loop mode changes to take effect m_looping = looping; - // Audio source must be stopped and re-started for loop mode changes to take effect } bool KRAudioSource::getLooping() { + // Returns true if the playback will automatically loop return m_looping; } @@ -400,38 +403,54 @@ void KRAudioSource::physicsUpdate(float deltaTime) void KRAudioSource::play() { - KRAudioManager *audioManager = getContext().getAudioManager(); - m_start_audio_frame = audioManager->getAudioFrame(); - audioManager->activateAudioSource(this); - if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) { - getContext().getAudioManager()->makeCurrentContext(); - prime(); - updatePosition(); + // Start playback of audio at the current audio sample position. If audio is already playing, this has no effect. + // play() does not automatically seek to the beginning of the sample. Call setAudioFrame( 0 ) first if you wish the playback to begin at the start of the audio sample. + // If not set to looping, audio playback ends automatically at the end of the sample + + if(!m_playing) { + KRAudioManager *audioManager = getContext().getAudioManager(); + assert(m_start_audio_frame == -1); + m_start_audio_frame = audioManager->getAudioFrame() - m_paused_audio_frame; + m_paused_audio_frame = -1; + audioManager->activateAudioSource(this); + if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) { + getContext().getAudioManager()->makeCurrentContext(); + prime(); + updatePosition(); - if(m_is3d) { - ALDEBUG(alSource3f(m_sourceID, AL_VELOCITY, 0.0f, 0.0f, 0.0f)); - ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance)); - ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor)); - ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb))); - ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE)); - } else { - ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE)); - ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0)); + if(m_is3d) { + ALDEBUG(alSource3f(m_sourceID, AL_VELOCITY, 0.0f, 0.0f, 0.0f)); + ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance)); + ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor)); + ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb))); + ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE)); + } else { + ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE)); + ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0)); + } + ALDEBUG(alSourcePlay(m_sourceID)); } - ALDEBUG(alSourcePlay(m_sourceID)); } m_playing = true; } void KRAudioSource::stop() { - m_start_audio_frame = -1; - m_playing = false; - getContext().getAudioManager()->deactivateAudioSource(this); + // Stop playback of audio. If audio is already stopped, this has no effect. + // If play() is called afterwards, playback will continue at the current audio sample position. + + if(m_playing) { + m_paused_audio_frame = getAudioFrame(); + m_start_audio_frame = -1; + m_playing = false; + getContext().getAudioManager()->deactivateAudioSource(this); + } } bool KRAudioSource::isPlaying() { + // Returns true if audio is playing. Will return false if a non-looped playback has reached the end of the audio sample. + return m_playing; } @@ -504,16 +523,46 @@ int KRAudioSource::getBufferFrame() return m_currentBufferFrame; } -__int64_t KRAudioSource::getStartAudioFrame() +__int64_t KRAudioSource::getAudioFrame() { - return m_start_audio_frame; + // Returns the audio playback position in units of integer audio frames. + + if(m_playing) { + return getContext().getAudioManager()->getAudioFrame() - m_start_audio_frame; + } else { + return m_paused_audio_frame; + } +} + +void KRAudioSource::setAudioFrame(__int64_t next_frame) +{ + // Sets the audio playback position with units of integer audio frames. + if(m_playing) { + m_start_audio_frame = getContext().getAudioManager()->getAudioFrame() - next_frame; + } else { + m_paused_audio_frame = next_frame; + } +} + + +float KRAudioSource::getAudioTime() +{ + // Gets the audio playback position with units of floating point seconds. + + return getAudioFrame() / 44100.0f; +} + +void KRAudioSource::setAudioTime(float new_position) +{ + // Sets the audio playback position with units of floating point seconds. + setAudioFrame(new_position * 44100.0f); } void KRAudioSource::sample(int frame_count, int channel, float *buffer, float gain) { KRAudioSample *source_sample = getAudioSample(); if(source_sample && m_playing) { - __int64_t next_frame = getContext().getAudioManager()->getAudioFrame() - getStartAudioFrame(); + __int64_t next_frame = getAudioFrame(); source_sample->sample(next_frame, frame_count, channel, buffer, gain, m_looping); if(!m_looping && next_frame > source_sample->getFrameCount()) { stop(); diff --git a/KREngine/kraken/KRAudioSource.h b/KREngine/kraken/KRAudioSource.h index 8472f36..a82343e 100644 --- a/KREngine/kraken/KRAudioSource.h +++ b/KREngine/kraken/KRAudioSource.h @@ -51,10 +51,41 @@ public: virtual void physicsUpdate(float deltaTime); void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); + + // ---- Audio Playback Controls ---- + + // Start playback of audio at the current audio sample position. If audio is already playing, this has no effect. + // play() does not automatically seek to the beginning of the sample. Call setAudioFrame( 0 ) first if you wish the playback to begin at the start of the audio sample. + // If not set to looping, audio playback ends automatically at the end of the sample void play(); + + // Stop playback of audio. If audio is already stopped, this has no effect. + // If play() is called afterwards, playback will continue at the current audio sample position. void stop(); + + // Returns true if audio is playing. Will return false if a non-looped playback has reached the end of the audio sample. bool isPlaying(); + // Returns the audio playback position in units of integer audio frames. + __int64_t getAudioFrame(); + + // Sets the audio playback position with units of integer audio frames. + void setAudioFrame(__int64_t next_frame); + + // Gets the audio playback position with units of floating point seconds. + float getAudioTime(); + + // Sets the audio playback position with units of floating point seconds. + void setAudioTime(float new_position); + + // Returns true if the playback will automatically loop + bool getLooping(); + + // Enable or disable looping playback; Audio source must be stopped and re-started for loop mode changes to take effect + void setLooping(bool looping); + + // ---- End: Audio Playback Controls ---- + void setSample(const std::string &sound_name); std::string getSample(); @@ -66,8 +97,7 @@ public: float getPitch(); void setPitch(float pitch); - bool getLooping(); - void setLooping(bool looping); + bool getIs3D(); void setIs3D(bool is3D); @@ -94,12 +124,11 @@ public: KRAudioBuffer *getBuffer(); int getBufferFrame(); - - __int64_t getStartAudioFrame(); void sample(int frame_count, int channel, float *buffer, float gain); private: - __int64_t m_start_audio_frame; // Global audio frame that matches the start of the audio sample playback + __int64_t m_start_audio_frame; // Global audio frame that matches the start of the audio sample playback; when paused or not playing, this contains a value of -1 + __int64_t m_paused_audio_frame; // When paused or not playing, this contains the local audio frame number. When playing, this contains a value of -1 int m_currentBufferFrame; // Siren Audio Engine frame number within current buffer void advanceBuffer(); diff --git a/KREngine/kraken/KRBone.cpp b/KREngine/kraken/KRBone.cpp index 1b32c27..18b4a87 100644 --- a/KREngine/kraken/KRBone.cpp +++ b/KREngine/kraken/KRBone.cpp @@ -62,7 +62,8 @@ void KRBone::render(KRCamera *pCamera, std::vector &point_lights KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { std::vector sphereModels = getContext().getModelManager()->getModel("__sphere"); if(sphereModels.size()) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { diff --git a/KREngine/kraken/KRBundle.cpp b/KREngine/kraken/KRBundle.cpp index 5173695..d152d77 100644 --- a/KREngine/kraken/KRBundle.cpp +++ b/KREngine/kraken/KRBundle.cpp @@ -53,35 +53,18 @@ KRBundle::KRBundle(KRContext &context, std::string name, KRDataBlock *pData) : K { 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] != '.') { + __int64_t file_pos = 0; + while(file_pos < m_pData->getSize()) { + tar_header_type file_header; + m_pData->copy(&file_header, file_pos, sizeof(file_header)); + size_t file_size = strtol(file_header.file_size, NULL, 8); + file_pos += 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); - } + KRDataBlock *pFileData = pData->getSubBlock(file_pos, file_size); + context.loadResource(file_header.file_name, pFileData); } - - // 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); - } - */ - pFile += RoundUpSize(file_size); - + file_pos += RoundUpSize(file_size); } } @@ -90,7 +73,9 @@ KRBundle::KRBundle(KRContext &context, std::string name) : KRResource(context, n // Create an empty krbundle (tar) file, initialized with two zero-ed out file headers, which terminate it. m_pData = new KRDataBlock(); m_pData->expand(KRENGINE_KRBUNDLE_HEADER_SIZE * 2); + m_pData->lock(); memset(m_pData->getStart(), 0, m_pData->getSize()); + m_pData->unlock(); } size_t KRBundle::RoundUpSize(size_t s) @@ -142,6 +127,8 @@ void KRBundle::append(KRResource &resource) m_pData->expand(KRENGINE_KRBUNDLE_HEADER_SIZE + resource_data.getSize() + padding_size - KRENGINE_KRBUNDLE_HEADER_SIZE * 2); // We will overwrite the existing zero-ed out file headers that marked the end of the archive, so we don't have to include their size here + m_pData->lock(); + // Get location of file header tar_header_type *file_header = (tar_header_type *)((unsigned char *)m_pData->getEnd() - padding_size - resource_data.getSize() - KRENGINE_KRBUNDLE_HEADER_SIZE); @@ -149,7 +136,9 @@ void KRBundle::append(KRResource &resource) memset(file_header, 0, KRENGINE_KRBUNDLE_HEADER_SIZE); // Copy resource data + resource_data.lock(); memcpy((unsigned char *)m_pData->getEnd() - padding_size - resource_data.getSize(), resource_data.getStart(), resource_data.getSize()); + resource_data.unlock(); // Zero out alignment padding and terminating set of file header blocks memset((unsigned char *)m_pData->getEnd() - padding_size, 0, padding_size); @@ -172,4 +161,6 @@ void KRBundle::append(KRResource &resource) check_sum += byte_ptr[i]; } sprintf(file_header->checksum, "%07o", check_sum); + + m_pData->unlock(); } diff --git a/KREngine/kraken/KRCamera.cpp b/KREngine/kraken/KRCamera.cpp index fb67f83..fb205a6 100644 --- a/KREngine/kraken/KRCamera.cpp +++ b/KREngine/kraken/KRCamera.cpp @@ -54,14 +54,9 @@ KRCamera::KRCamera(KRScene &scene, std::string name) : KRNode(scene, name) { volumetricLightAccumulationBuffer = 0; volumetricLightAccumulationTexture = 0; m_frame_times_filled = 0; - - m_debug_text_vertices = NULL; } KRCamera::~KRCamera() { - if(m_debug_text_vertices) { - delete m_debug_text_vertices; - } destroyBuffers(); } @@ -310,12 +305,13 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende } if(m_pSkyBoxTexture) { - getContext().getShaderManager()->selectShader("sky_box", *this, std::vector(), std::vector(), std::vector(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE); + KRVector3 rim_color; + getContext().getShaderManager()->selectShader("sky_box", *this, std::vector(), std::vector(), std::vector(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, rim_color, 0.0f); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture); // Render a full screen quad - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } @@ -472,13 +468,13 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, KRENGINE_VBO_3D_CUBE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_ATTRIBS, true); for(unordered_map::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { KRMat4 matModel = KRMat4(); matModel.scale((*itr).first.size() * 0.5f); matModel.translate((*itr).first.center()); - - if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f)) { GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); } } @@ -687,7 +683,9 @@ void KRCamera::renderPost() GLDEBUG(glDisable(GL_DEPTH_TEST)); KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); + + KRVector3 rim_color; + getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f); m_pContext->getTextureManager()->selectTexture(0, NULL); m_pContext->getTextureManager()->_setActiveTexture(0); @@ -704,7 +702,7 @@ void KRCamera::renderPost() } // Update attribute values. - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); @@ -726,7 +724,7 @@ void KRCamera::renderPost() // viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0); // getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); // m_pContext->getTextureManager()->selectTexture(1, NULL); -// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); +// m_pContext->getModelManager()->bindVBO(KRENGINE_VBO_2D_SQUARE_INDICES, KRENGINE_VBO_2D_SQUARE_VERTEXES, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); // m_pContext->getTextureManager()->_setActiveTexture(0); // GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow])); //#if GL_EXT_shadow_samplers @@ -745,7 +743,7 @@ void KRCamera::renderPost() - if(m_debug_text_vertices) { + if(m_debug_text_vertices.getSize()) { m_pContext->getModelManager()->releaseVBO(m_debug_text_vertices); } @@ -791,12 +789,13 @@ void KRCamera::renderPost() const int DEBUG_TEXT_COLUMNS = 256; const int DEBUG_TEXT_ROWS = 128; - if(m_debug_text_vertices == NULL) { - m_debug_text_vertices = new DebugTextVertexData[DEBUG_TEXT_COLUMNS * DEBUG_TEXT_ROWS * 6]; + if(m_debug_text_vertices.getSize() == 0) { + m_debug_text_vertices.expand(sizeof(DebugTextVertexData) * DEBUG_TEXT_COLUMNS * DEBUG_TEXT_ROWS * 6); } int vertex_count = 0; - + m_debug_text_vertices.lock(); + DebugTextVertexData *vertex_data = (DebugTextVertexData *)m_debug_text_vertices.getStart(); pChar = szText; float dScaleX = 2.0 / (1024 / 16); @@ -824,47 +823,47 @@ void KRCamera::renderPost() KRVector2 top_left_uv = KRVector2(dTexScale * iTexCol, dTexScale * iTexRow); KRVector2 bottom_right_uv = KRVector2(dTexScale * iTexCol + dTexScale, dTexScale * iTexRow + dTexScale); - m_debug_text_vertices[vertex_count].x = top_left_pos.x; - m_debug_text_vertices[vertex_count].y = top_left_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = top_left_uv.x; - m_debug_text_vertices[vertex_count].v = top_left_uv.y; + vertex_data[vertex_count].x = top_left_pos.x; + vertex_data[vertex_count].y = top_left_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = top_left_uv.x; + vertex_data[vertex_count].v = top_left_uv.y; vertex_count++; - m_debug_text_vertices[vertex_count].x = bottom_right_pos.x; - m_debug_text_vertices[vertex_count].y = bottom_right_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = bottom_right_uv.x; - m_debug_text_vertices[vertex_count].v = bottom_right_uv.y; + vertex_data[vertex_count].x = bottom_right_pos.x; + vertex_data[vertex_count].y = bottom_right_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = bottom_right_uv.x; + vertex_data[vertex_count].v = bottom_right_uv.y; vertex_count++; - m_debug_text_vertices[vertex_count].x = top_left_pos.x; - m_debug_text_vertices[vertex_count].y = bottom_right_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = top_left_uv.x; - m_debug_text_vertices[vertex_count].v = bottom_right_uv.y; + vertex_data[vertex_count].x = top_left_pos.x; + vertex_data[vertex_count].y = bottom_right_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = top_left_uv.x; + vertex_data[vertex_count].v = bottom_right_uv.y; vertex_count++; - m_debug_text_vertices[vertex_count].x = top_left_pos.x; - m_debug_text_vertices[vertex_count].y = top_left_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = top_left_uv.x; - m_debug_text_vertices[vertex_count].v = top_left_uv.y; + vertex_data[vertex_count].x = top_left_pos.x; + vertex_data[vertex_count].y = top_left_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = top_left_uv.x; + vertex_data[vertex_count].v = top_left_uv.y; vertex_count++; - m_debug_text_vertices[vertex_count].x = bottom_right_pos.x; - m_debug_text_vertices[vertex_count].y = top_left_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = bottom_right_uv.x; - m_debug_text_vertices[vertex_count].v = top_left_uv.y; + vertex_data[vertex_count].x = bottom_right_pos.x; + vertex_data[vertex_count].y = top_left_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = bottom_right_uv.x; + vertex_data[vertex_count].v = top_left_uv.y; vertex_count++; - m_debug_text_vertices[vertex_count].x = bottom_right_pos.x; - m_debug_text_vertices[vertex_count].y = bottom_right_pos.y; - m_debug_text_vertices[vertex_count].z = 0.0f; - m_debug_text_vertices[vertex_count].u = bottom_right_uv.x; - m_debug_text_vertices[vertex_count].v = bottom_right_uv.y; + vertex_data[vertex_count].x = bottom_right_pos.x; + vertex_data[vertex_count].y = bottom_right_pos.y; + vertex_data[vertex_count].z = 0.0f; + vertex_data[vertex_count].u = bottom_right_uv.x; + vertex_data[vertex_count].v = bottom_right_uv.y; vertex_count++; } @@ -888,22 +887,25 @@ void KRCamera::renderPost() GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); + KRVector3 rim_color; + getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f); m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font")); - - m_pContext->getModelManager()->bindVBO((void *)m_debug_text_vertices, vertex_count * sizeof(DebugTextVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true); + KRDataBlock index_data; + //m_pContext->getModelManager()->bindVBO((void *)m_debug_text_vertices, vertex_count * sizeof(DebugTextVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true); + m_pContext->getModelManager()->bindVBO(m_debug_text_vertices, index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, vertex_count)); // Re-enable z-buffer write GLDEBUG(glDepthMask(GL_TRUE)); + + m_debug_text_vertices.unlock(); } else { - if(m_debug_text_vertices) { - delete m_debug_text_vertices; - m_debug_text_vertices = NULL; + if(m_debug_text_vertices.getSize() > 0) { + m_debug_text_vertices = KRDataBlock(); } } } diff --git a/KREngine/kraken/KRCamera.h b/KREngine/kraken/KRCamera.h index 03d518a..560dd4e 100644 --- a/KREngine/kraken/KRCamera.h +++ b/KREngine/kraken/KRCamera.h @@ -99,7 +99,7 @@ private: GLfloat v; } DebugTextVertexData; - DebugTextVertexData *m_debug_text_vertices; + KRDataBlock m_debug_text_vertices; // std::string getDebugText(); diff --git a/KREngine/kraken/KRCollider.cpp b/KREngine/kraken/KRCollider.cpp index b7dc674..ad7eba5 100644 --- a/KREngine/kraken/KRCollider.cpp +++ b/KREngine/kraken/KRCollider.cpp @@ -171,7 +171,8 @@ void KRCollider::render(KRCamera *pCamera, std::vector &point_li KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/KREngine/kraken/KRContext.cpp b/KREngine/kraken/KRContext.cpp index 6c1145d..a26e398 100644 --- a/KREngine/kraken/KRContext.cpp +++ b/KREngine/kraken/KRContext.cpp @@ -17,7 +17,6 @@ int KRContext::KRENGINE_MAX_SHADER_HANDLES; int KRContext::KRENGINE_MAX_TEXTURE_HANDLES; int KRContext::KRENGINE_MAX_TEXTURE_MEM; int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX; -int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN; int KRContext::KRENGINE_MAX_TEXTURE_DIM; int KRContext::KRENGINE_MIN_TEXTURE_DIM; int KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT; @@ -27,6 +26,7 @@ const char *KRContext::extension_names[KRENGINE_NUM_EXTENSIONS] = { }; KRContext::KRContext() { + m_streamingEnabled = false; mach_timebase_info(&m_timebase_info); m_bDetectedExtensions = false; @@ -43,7 +43,7 @@ KRContext::KRContext() { m_pAnimationCurveManager = new KRAnimationCurveManager(*this); m_pSoundManager = new KRAudioManager(*this); m_pUnknownManager = new KRUnknownManager(*this); - + m_streamingEnabled = true; } KRContext::~KRContext() { @@ -271,3 +271,35 @@ long KRContext::getAbsoluteTimeMilliseconds() return (long)(mach_absolute_time() / 1000 * m_timebase_info.numer / m_timebase_info.denom); // Division done first to avoid potential overflow } +bool KRContext::getStreamingEnabled() +{ + return m_streamingEnabled; +} + +void KRContext::setStreamingEnabled(bool enable) +{ + m_streamingEnabled = enable; +} + +void KRContext::getMemoryStats(long &free_memory) +{ + free_memory = 0; +#if TARGET_OS_IPHONE || TARGET_OS_MAC + mach_port_t host_port = mach_host_self(); + mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); + vm_size_t pagesize = 0; + vm_statistics_data_t vm_stat; + int total_ram = 256 * 1024 * 1024; + if(host_page_size(host_port, &pagesize) != KERN_SUCCESS) { + fprintf(stderr, "ERROR: Could not get VM page size.\n"); + } else if(host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) { + fprintf(stderr, "ERROR: Could not get VM stats.\n"); + } else { + total_ram = (vm_stat.wire_count + vm_stat.active_count + vm_stat.inactive_count + vm_stat.free_count) * pagesize; + + free_memory = vm_stat.free_count * pagesize; + } +#else +#error Unsupported Platform +#endif +} diff --git a/KREngine/kraken/KRContext.h b/KREngine/kraken/KRContext.h index 47a0b34..c75f846 100644 --- a/KREngine/kraken/KRContext.h +++ b/KREngine/kraken/KRContext.h @@ -29,7 +29,6 @@ public: static int KRENGINE_MAX_TEXTURE_HANDLES; static int KRENGINE_MAX_TEXTURE_MEM; static int KRENGINE_TARGET_TEXTURE_MEM_MAX; - static int KRENGINE_TARGET_TEXTURE_MEM_MIN; static int KRENGINE_MAX_TEXTURE_DIM; static int KRENGINE_MIN_TEXTURE_DIM; static int KRENGINE_MAX_TEXTURE_THROUGHPUT; @@ -73,6 +72,10 @@ public: long getAbsoluteTimeMilliseconds(); std::vector getResources(); + bool getStreamingEnabled(); + void setStreamingEnabled(bool enable); + + void getMemoryStats(long &free_memory); private: KRBundleManager *m_pBundleManager; @@ -93,6 +96,8 @@ private: float m_absolute_time; mach_timebase_info_data_t m_timebase_info; + + std::atomic m_streamingEnabled; }; #endif diff --git a/KREngine/kraken/KRDataBlock.cpp b/KREngine/kraken/KRDataBlock.cpp index b60ad37..cfc2421 100644 --- a/KREngine/kraken/KRDataBlock.cpp +++ b/KREngine/kraken/KRDataBlock.cpp @@ -30,12 +30,44 @@ // #include "KRDataBlock.h" +#include "KREngine-common.h" +#include "KRResource.h" + +#include + +int KRAKEN_MEM_PAGE_SIZE = getpagesize(); +#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) +#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE) + +int m_mapCount = 0; +size_t m_mapSize = 0; +size_t m_mapOverhead = 0; KRDataBlock::KRDataBlock() { m_data = NULL; m_data_size = 0; + m_data_offset = 0; m_fdPackFile = 0; + m_fileName = ""; + m_mmapData = NULL; + m_fileOwnerDataBlock = NULL; m_bMalloced = false; + m_lockCount = 0; + m_bReadOnly = false; +} + +KRDataBlock::KRDataBlock(void *data, size_t size) { + m_data = NULL; + m_data_size = 0; + m_data_offset = 0; + m_fdPackFile = 0; + m_fileName = ""; + m_mmapData = NULL; + m_fileOwnerDataBlock = NULL; + m_bMalloced = false; + m_lockCount = 0; + m_bReadOnly = false; + load(data, size); } KRDataBlock::~KRDataBlock() { @@ -45,10 +77,13 @@ KRDataBlock::~KRDataBlock() { // Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use void KRDataBlock::unload() { + assert(m_lockCount == 0); + if(m_fdPackFile) { // Memory mapped file - munmap(m_data, m_data_size); - close(m_fdPackFile); + if(m_fileOwnerDataBlock == this) { + close(m_fdPackFile); + } } else if(m_data != NULL && m_bMalloced) { // Malloc'ed data free(m_data); @@ -57,7 +92,12 @@ void KRDataBlock::unload() m_bMalloced = false; m_data = NULL; m_data_size = 0; + m_data_offset = 0; m_fdPackFile = 0; + m_fileName = ""; + m_mmapData = NULL; + m_fileOwnerDataBlock = NULL; + m_bReadOnly = false; } // Encapsulate a pointer. Note - The pointer will not be free'ed @@ -66,6 +106,8 @@ bool KRDataBlock::load(void *data, size_t size) unload(); m_data = data; m_data_size = size; + m_data_offset = 0; + m_bReadOnly = false; return true; } @@ -76,14 +118,15 @@ bool KRDataBlock::load(const std::string &path) unload(); struct stat statbuf; + m_bReadOnly = true; m_fdPackFile = open(path.c_str(), O_RDONLY); if(m_fdPackFile >= 0) { + m_fileOwnerDataBlock = this; + m_fileName = KRResource::GetFileBase(path); 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; - } + m_data_size = statbuf.st_size; + m_data_offset = 0; + success = true; } } if(!success) { @@ -93,13 +136,33 @@ bool KRDataBlock::load(const std::string &path) return success; } +// Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object. +KRDataBlock *KRDataBlock::getSubBlock(int start, int length) +{ + KRDataBlock *new_block = new KRDataBlock(); + + new_block->m_data_size = length; + if(m_fdPackFile) { + new_block->m_fdPackFile = m_fdPackFile; + new_block->m_fileOwnerDataBlock = m_fileOwnerDataBlock; + new_block->m_data_offset = start + m_data_offset; + } else if(m_bMalloced) { + new_block->m_data = (unsigned char *)m_data + start + m_data_offset; + } + new_block->m_bReadOnly = true; + + return new_block; +} + // Return a pointer to the start of the data block void *KRDataBlock::getStart() { + assertLocked(); return m_data; } // Return a pointer to the byte after the end of the data block void *KRDataBlock::getEnd() { + assertLocked(); return (unsigned char *)m_data + m_data_size; } @@ -111,28 +174,33 @@ size_t KRDataBlock::getSize() const { // 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) { + if(m_data == NULL && m_fdPackFile == 0) { // Starting with an empty data block; allocate memory on the heap m_data = malloc(size); assert(m_data != NULL); m_data_size = size; + m_data_offset = 0; 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); 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 + // Starting with a mmap'ed data block, an encapsulated pointer, or a sub-block; copy it to ram before expanding to avoid updating the original file until save() is called // ... Or starting with a pointer reference, we must make our own copy and must not free the pointer void *pNewData = malloc(m_data_size + size); assert(pNewData != NULL); - memcpy((unsigned char *)pNewData, m_data, m_data_size); // Copy exising data + + // Copy exising data + copy(pNewData); + // 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; + m_data_offset = 0; } } @@ -142,12 +210,35 @@ void KRDataBlock::append(void *data, size_t size) { expand(size); // Fill the new space with the data to append + lock(); memcpy((unsigned char *)m_data + m_data_size - size, data, size); + unlock(); +} + + +// Copy the entire data block to the destination pointer +void KRDataBlock::copy(void *dest) { + copy(dest, 0, m_data_size); +} + +// Copy a range of data to the destination pointer +void KRDataBlock::copy(void *dest, int start, int count) { + if(m_lockCount == 0 && m_fdPackFile != 0) { + // Optimization: If we haven't mmap'ed or malloced the data already, pread() it directly from the file into the buffer + ssize_t r = pread(m_fdPackFile, dest, count, start + m_data_offset); + assert(r != -1); + } else { + lock(); + memcpy((unsigned char *)dest, (unsigned char *)m_data + start, count); + unlock(); + } } // Append data to the end of the block, increasing the size of the block and making it read-write. void KRDataBlock::append(KRDataBlock &data) { + data.lock(); append(data.getStart(), data.getSize()); + data.unlock(); } // Append string to the end of the block, increasing the size of the block and making it read-write. The null terminating character is included @@ -157,7 +248,7 @@ void KRDataBlock::append(const std::string &s) append((void *)szText, strlen(szText)+1); } -// 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 +// Save the data to a file. 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) { @@ -173,20 +264,16 @@ bool KRDataBlock::save(const std::string& path) { close(fdNewFile); return false; } else if(m_data != NULL) { + + // Copy data to new file - memcpy(pNewData, m_data, m_data_size); + copy(pNewData); - // 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); + // Unmap the new file + munmap(pNewData, m_data_size); - // Switch pointer to use new mmap'ed memory - m_data_size = new_size; - m_fdPackFile = fdNewFile; - m_data = pNewData; + // Close the new file + close(fdNewFile); } return true; } @@ -198,5 +285,102 @@ std::string KRDataBlock::getString() KRDataBlock b; b.append(*this); b.append((void *)"\0", 1); // Ensure data is null terminated, to read as a string safely - return std::string((char *)b.getStart()); + b.lock(); + std::string ret = std::string((char *)b.getStart()); + b.unlock(); + return ret; +} + +// Lock the memory, forcing it to be loaded into a contiguous block of address space +void KRDataBlock::lock() +{ + if(m_lockCount == 0) { + + // Memory mapped file; ensure data is mapped to ram + if(m_fdPackFile) { + if(m_data_size < KRENGINE_MIN_MMAP) { + m_data = malloc(m_data_size); + assert(m_data != NULL); + copy(m_data); + } else { + //fprintf(stderr, "KRDataBlock::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount); + + // Round m_data_offset down to the next memory page, as required by mmap + size_t alignment_offset = m_data_offset & (KRAKEN_MEM_PAGE_SIZE - 1); + if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (caddr_t) -1) { + int iError = errno; + switch(iError) { + case EACCES: + fprintf(stderr, "mmap failed with EACCES\n"); + break; + case EBADF: + fprintf(stderr, "mmap failed with EBADF\n"); + break; + case EMFILE: + fprintf(stderr, "mmap failed with EMFILE\n"); + break; + case EINVAL: + fprintf(stderr, "mmap failed with EINVAL\n"); + break; + case ENOMEM: + fprintf(stderr, "mmap failed with ENOMEM\n"); + break; + case ENXIO: + fprintf(stderr, "mmap failed with ENXIO\n"); + break; + case EOVERFLOW: + fprintf(stderr, "mmap failed with EOVERFLOW\n"); + break; + default: + fprintf(stderr, "mmap failed with errno: %i\n", iError); + break; + } + assert(false); // mmap() failed. + } + m_mapCount++; + m_mapSize += m_data_size; + m_mapOverhead += alignment_offset + KRAKEN_MEM_ROUND_UP_PAGE(m_data_size + alignment_offset) - m_data_size + alignment_offset; + // fprintf(stderr, "Mapped: %i Size: %d Overhead: %d\n", m_mapCount, m_mapSize, m_mapOverhead); + m_data = (unsigned char *)m_mmapData + alignment_offset; + } + } + } + m_lockCount++; +} + +// Unlock the memory, releasing the address space for use by other allocations +void KRDataBlock::unlock() +{ + // We expect that the data block was previously locked + assertLocked(); + + + if(m_lockCount == 1) { + + // Memory mapped file; ensure data is unmapped from ram + if(m_fdPackFile) { + if(m_data_size < KRENGINE_MIN_MMAP) { + free(m_data); + m_data = NULL; + } else { + //fprintf(stderr, "KRDataBlock::unlock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount); + + munmap(m_mmapData, m_data_size); + m_data = NULL; + m_mmapData = NULL; + m_mapCount--; + m_mapSize -= m_data_size; + size_t alignment_offset = m_data_offset & (KRAKEN_MEM_PAGE_SIZE - 1); + m_mapOverhead -= alignment_offset + KRAKEN_MEM_ROUND_UP_PAGE(m_data_size + alignment_offset) - m_data_size + alignment_offset; + // fprintf(stderr, "Mapped: %i Size: %d Overhead: %d\n", m_mapCount, m_mapSize, m_mapOverhead); + } + } + } + m_lockCount--; +} + +// Assert if not locked +void KRDataBlock::assertLocked() +{ + assert(m_lockCount > 0); } diff --git a/KREngine/kraken/KRDataBlock.h b/KREngine/kraken/KRDataBlock.h index b67dba8..fc001cf 100644 --- a/KREngine/kraken/KRDataBlock.h +++ b/KREngine/kraken/KRDataBlock.h @@ -34,9 +34,12 @@ #include "KREngine-common.h" +#define KRENGINE_MIN_MMAP 32768 + class KRDataBlock { public: KRDataBlock(); + KRDataBlock(void *data, size_t size); ~KRDataBlock(); // Encapsulate a pointer. Note - The pointer will not be free'ed @@ -45,9 +48,12 @@ public: // 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 + // Save the data to a file. bool save(const std::string& path); + // Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object. + KRDataBlock *getSubBlock(int start, int length); + // 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); @@ -74,15 +80,42 @@ public: // Get the contents as a string std::string getString(); + + // Copy the entire data block to the destination pointer + void copy(void *dest); + + // Copy a range of data to the destination pointer + void copy(void *dest, int start, int count); + + // Lock the memory, forcing it to be loaded into a contiguous block of address space + void lock(); + + // Unlock the memory, releasing the address space for use by other allocations + void unlock(); + private: void *m_data; size_t m_data_size; + size_t m_data_offset; // For memory mapped objects: int m_fdPackFile; + std::string m_fileName; + KRDataBlock *m_fileOwnerDataBlock; + void *m_mmapData; // For malloc'ed objects: bool m_bMalloced; + + // Lock refcount + int m_lockCount; + + // Read-only allocation + bool m_bReadOnly; + + // Assert if not locked + void assertLocked(); + }; #endif diff --git a/KREngine/kraken/KRDirectionalLight.cpp b/KREngine/kraken/KRDirectionalLight.cpp index 2335b95..8e2e01b 100644 --- a/KREngine/kraken/KRDirectionalLight.cpp +++ b/KREngine/kraken/KRDirectionalLight.cpp @@ -105,8 +105,10 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector & light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space); light_direction_view_space.normalize(); + KRVector3 rim_color; + KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector(), this_light, std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector(), this_light, std::vector(), 0, renderPass)) { + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector(), this_light, std::vector(), 0, renderPass, rim_color, 0.0f)) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space); pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); @@ -119,7 +121,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector & GLDEBUG(glDisable(GL_DEPTH_TEST)); // Render a full screen quad - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } } diff --git a/KREngine/kraken/KREngine-common.h b/KREngine/kraken/KREngine-common.h index d80a414..1b60047 100644 --- a/KREngine/kraken/KREngine-common.h +++ b/KREngine/kraken/KREngine-common.h @@ -11,11 +11,10 @@ #ifndef KRENGINE_COMMON_H #define KRENGINE_COMMON_H -#define KRENGINE_MAX_TEXTURE_UNITS 8 - float const PI = 3.141592653589793f; float const D2R = PI * 2 / 360; + #include #include #include @@ -47,6 +46,9 @@ float const D2R = PI * 2 / 360; #include #include +#include +#include + #include "tinyxml2.h" @@ -69,29 +71,19 @@ using std::queue; #define KRAKEN_HAVE_BLAS 1 #endif +#define KRENGINE_MAX_TEXTURE_UNITS 8 + #if !defined(__i386__) && defined(__arm__) #define KRAKEN_USE_ARM_NEON #endif -#if TARGET_OS_IPHONE - #include using std::unordered_map; using std::unordered_multimap; using std::hash; -#else - -#include -using std::tr1::unordered_map; -using std::tr1::unordered_multimap; -using std::tr1::hash; - -#endif - - #if TARGET_OS_IPHONE #include @@ -129,9 +121,6 @@ using std::tr1::hash; #include #endif -#endif - - #if DEBUG #define GLDEBUG(x) \ @@ -197,3 +186,5 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n" #include "KRVector3.h" #include "KRVector2.h" #include "KRBehavior.h" + +#endif diff --git a/KREngine/kraken/KREngine.mm b/KREngine/kraken/KREngine.mm index cb64a3f..e1c8eb6 100644 --- a/KREngine/kraken/KREngine.mm +++ b/KREngine/kraken/KREngine.mm @@ -101,7 +101,6 @@ void kraken::set_debug_text(const std::string &print_text) KRContext::KRENGINE_MAX_VBO_MEM = total_ram * 2 / 4; KRContext::KRENGINE_MAX_TEXTURE_MEM = total_ram * 1 / 8; KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = KRContext::KRENGINE_MAX_TEXTURE_MEM * 3 / 4; - KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = KRContext::KRENGINE_MAX_TEXTURE_MEM / 2; @@ -115,7 +114,6 @@ void kraken::set_debug_text(const std::string &print_text) KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000; KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000 * 2; KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000 * 2; - KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000 * 2; KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048; KRContext::KRENGINE_MIN_TEXTURE_DIM = 64; KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000; @@ -126,7 +124,6 @@ void kraken::set_debug_text(const std::string &print_text) KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000; KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000; KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000; - KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000; KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048; KRContext::KRENGINE_MIN_TEXTURE_DIM = 64; KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000; @@ -139,7 +136,6 @@ void kraken::set_debug_text(const std::string &print_text) KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000; KRContext::KRENGINE_MAX_TEXTURE_MEM = 512000000; KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 384000000; - KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 256000000; KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048; KRContext::KRENGINE_MIN_TEXTURE_DIM = 64; KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 128000000; @@ -425,7 +421,7 @@ void kraken::set_debug_text(const std::string &print_text) [self getAmbientIntensity], [self getSunTemperature], [self getSunIntensity], - _settings.dof_quality, + static_cast(_settings.dof_quality), _settings.dof_depth, _settings.dof_falloff, _settings.bEnableFlash ? 1.0f : 0.0f, @@ -445,26 +441,26 @@ void kraken::set_debug_text(const std::string &print_text) _settings.bEnableDeferredLighting ? 1.0f : 0.0f, _settings.getPerspectiveNearZ(), _settings.getPerspectiveFarZ(), - _settings.volumetric_environment_enable, - 5 - _settings.volumetric_environment_downsample, + static_cast(_settings.volumetric_environment_enable), + static_cast(5 - _settings.volumetric_environment_downsample), _settings.volumetric_environment_max_distance, _settings.volumetric_environment_quality, _settings.volumetric_environment_intensity, - _settings.fog_type, + static_cast(_settings.fog_type), _settings.fog_near, _settings.fog_far, _settings.fog_density, _settings.fog_color.x, _settings.fog_color.y, _settings.fog_color.z, - _settings.dust_particle_enable, + static_cast(_settings.dust_particle_enable), _settings.dust_particle_intensity, _settings.getLODBias(), - _settings.getEnableRealtimeOcclusion(), + static_cast(_settings.getEnableRealtimeOcclusion()), _settings.debug_display, - _settings.siren_enable, - _settings.siren_enable_reverb, - _settings.siren_enable_hrtf, + static_cast(_settings.siren_enable), + static_cast(_settings.siren_enable_reverb), + static_cast(_settings.siren_enable_hrtf), _settings.siren_reverb_max_length, _settings.max_anisotropy }; diff --git a/KREngine/kraken/KRLODGroup.h b/KREngine/kraken/KRLODGroup.h index a35daea..c394fb4 100644 --- a/KREngine/kraken/KRLODGroup.h +++ b/KREngine/kraken/KRLODGroup.h @@ -11,7 +11,6 @@ #include "KRResource.h" #include "KRNode.h" -#include "KRTexture.h" class KRLODGroup : public KRNode { public: diff --git a/KREngine/kraken/KRLODSet.cpp b/KREngine/kraken/KRLODSet.cpp new file mode 100644 index 0000000..93fe90d --- /dev/null +++ b/KREngine/kraken/KRLODSet.cpp @@ -0,0 +1,35 @@ +// +// KRLODSet.cpp +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include "KRLODSet.h" +#include "KRContext.h" + +KRLODSet::KRLODSet(KRScene &scene, std::string name) : KRNode(scene, name) +{ + +} + +KRLODSet::~KRLODSet() +{ +} + +std::string KRLODSet::getElementName() { + return "lod_set"; +} + +tinyxml2::XMLElement *KRLODSet::saveXML( tinyxml2::XMLNode *parent) +{ + tinyxml2::XMLElement *e = KRNode::saveXML(parent); + + return e; +} + +void KRLODSet::loadXML(tinyxml2::XMLElement *e) +{ + KRNode::loadXML(e); +} diff --git a/KREngine/kraken/KRLODSet.h b/KREngine/kraken/KRLODSet.h new file mode 100644 index 0000000..cbb5337 --- /dev/null +++ b/KREngine/kraken/KRLODSet.h @@ -0,0 +1,26 @@ +// +// KRLODSet +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRLODSET_H +#define KRLODSET_H + +#include "KRResource.h" +#include "KRNode.h" + +class KRLODSet : public KRNode { +public: + KRLODSet(KRScene &scene, std::string name); + virtual ~KRLODSet(); + virtual std::string getElementName(); + virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + virtual void loadXML(tinyxml2::XMLElement *e); + +}; + + +#endif diff --git a/KREngine/kraken/KRLight.cpp b/KREngine/kraken/KRLight.cpp index c5337a6..79a303e 100644 --- a/KREngine/kraken/KRLight.cpp +++ b/KREngine/kraken/KRLight.cpp @@ -220,13 +220,15 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, rim_color, 0.0f)) { pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), KRVector3::Zero())); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true); + KRDataBlock particle_index_data; + m_pContext->getModelManager()->bindVBO(m_pContext->getModelManager()->getRandomParticles(), particle_index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } @@ -255,8 +257,8 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES); - - if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, rim_color, 0.0f)) { int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5; float slice_near = -pCamera->settings.getPerspectiveNearZ(); @@ -266,7 +268,8 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, KRVector2(slice_near, slice_spacing)); pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f)); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRMeshManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRMeshManager::VolumetricLightingVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), true); + KRDataBlock index_data; + m_pContext->getModelManager()->bindVBO(m_pContext->getModelManager()->getVolumetricLightingVertexes(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), true); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6)); } @@ -283,7 +286,8 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix(); } - if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, rim_color, 0.0f)) { GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery)); #if TARGET_OS_IPHONE @@ -330,10 +334,12 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light // Render light flare on transparency pass KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_light; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, rim_light, 0.0f)) { + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture); - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } } @@ -446,7 +452,8 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera) // Use shader program KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector(), std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); - getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP); + KRVector3 rim_light; + getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP, rim_light, 0.0f); getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true); diff --git a/KREngine/kraken/KRLocator.cpp b/KREngine/kraken/KRLocator.cpp new file mode 100644 index 0000000..694cbe2 --- /dev/null +++ b/KREngine/kraken/KRLocator.cpp @@ -0,0 +1,40 @@ +// +// KRLocator.cpp +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include "KRLocator.h" +#include "KRContext.h" + +KRLocator::KRLocator(KRScene &scene, std::string name) : KRNode(scene, name) +{ + +} + +KRLocator::~KRLocator() +{ +} + +std::string KRLocator::getElementName() { + return "locator"; +} + +tinyxml2::XMLElement *KRLocator::saveXML( tinyxml2::XMLNode *parent) +{ + tinyxml2::XMLElement *e = KRNode::saveXML(parent); + + return e; +} + +void KRLocator::loadXML(tinyxml2::XMLElement *e) +{ + KRNode::loadXML(e); +} + +unordered_map > &KRLocator::getUserAttributes() +{ + return m_userAttributes; +} \ No newline at end of file diff --git a/KREngine/kraken/KRLocator.h b/KREngine/kraken/KRLocator.h new file mode 100644 index 0000000..b2c0a64 --- /dev/null +++ b/KREngine/kraken/KRLocator.h @@ -0,0 +1,32 @@ +// +// KRLocator +// KREngine +// +// Created by Kearwood Gilbert on 2012-12-06. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRLOCATOR_H +#define KRLOCATOR_H + +#include "KRResource.h" +#include "KRNode.h" +#include "KRTexture.h" + +#include "boost/variant.hpp" + +class KRLocator : public KRNode { +public: + KRLocator(KRScene &scene, std::string name); + virtual ~KRLocator(); + virtual std::string getElementName(); + virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + virtual void loadXML(tinyxml2::XMLElement *e); + unordered_map > &getUserAttributes(); + +private: + unordered_map > m_userAttributes; +}; + + +#endif diff --git a/KREngine/kraken/KRMat4.cpp b/KREngine/kraken/KRMat4.cpp index 1441e55..6e686c0 100644 --- a/KREngine/kraken/KRMat4.cpp +++ b/KREngine/kraken/KRMat4.cpp @@ -87,7 +87,7 @@ float KRMat4::operator[](unsigned i) const { } // Overload comparison operator -bool KRMat4::operator==(const KRMat4 &m) { +bool KRMat4::operator==(const KRMat4 &m) const { return memcmp(c, m.c, sizeof(float) * 16) == 0; } diff --git a/KREngine/kraken/KRMat4.h b/KREngine/kraken/KRMat4.h index c8ac508..8e7340e 100644 --- a/KREngine/kraken/KRMat4.h +++ b/KREngine/kraken/KRMat4.h @@ -83,7 +83,7 @@ class KRMat4 { KRMat4& operator=(const KRMat4 &m); // Overload comparison operator - bool operator==(const KRMat4 &m); + bool operator==(const KRMat4 &m) const; // Overload compound multiply operator KRMat4& operator*=(const KRMat4 &m); diff --git a/KREngine/kraken/KRMaterial.cpp b/KREngine/kraken/KRMaterial.cpp index 3a29612..141f648 100644 --- a/KREngine/kraken/KRMaterial.cpp +++ b/KREngine/kraken/KRMaterial.cpp @@ -217,7 +217,7 @@ bool KRMaterial::isTransparent() { return m_tr < 1.0 || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE; } -bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass) { +bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power) { bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap; if(!m_pAmbientMap && m_ambientMap.size()) { @@ -251,10 +251,9 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap; bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE); - - KRShader *pShader = getContext().getShaderManager()->getShader("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_reflectionMapScale != default_scale && bReflectionMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, m_reflectionMapOffset != default_offset && bReflectionMap, bAlphaTest, bAlphaBlend, renderPass); + KRShader *pShader = getContext().getShaderManager()->getShader("ObjectShader", pCamera, point_lights, directional_lights, spot_lights, bones.size(), bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_reflectionMapScale != default_scale && bReflectionMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, m_reflectionMapOffset != default_offset && bReflectionMap, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f); - if(!getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass)) { + if(!getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, rim_power)) { return false; } diff --git a/KREngine/kraken/KRMaterial.h b/KREngine/kraken/KRMaterial.h index 7b88eb8..ef6d9ee 100644 --- a/KREngine/kraken/KRMaterial.h +++ b/KREngine/kraken/KRMaterial.h @@ -37,6 +37,7 @@ #include "KRCamera.h" #include "KRResource.h" #include "KRVector2.h" +#include "KRVector3.h" #include "KRScene.h" #include "KRBone.h" @@ -83,7 +84,7 @@ public: bool isTransparent(); const std::string &getName() const; - bool bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass); + bool bind(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const std::vector &bones, const std::vector &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power); bool needsVertexTangents(); diff --git a/KREngine/kraken/KRMaterialManager.cpp b/KREngine/kraken/KRMaterialManager.cpp index 5f9d568..8b7deaa 100644 --- a/KREngine/kraken/KRMaterialManager.cpp +++ b/KREngine/kraken/KRMaterialManager.cpp @@ -100,7 +100,7 @@ void KRMaterialManager::add(KRMaterial *new_material) { bool KRMaterialManager::load(const char *szName, KRDataBlock *data) { KRMaterial *pMaterial = NULL; char szSymbol[16][256]; - + data->lock(); char *pScan = (char *)data->getStart(); char *pEnd = (char *)data->getEnd(); @@ -282,7 +282,7 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) { } } - + data->unlock(); delete data; return true; } diff --git a/KREngine/kraken/KRMesh.cpp b/KREngine/kraken/KRMesh.cpp index 1afe334..2cf0c2f 100644 --- a/KREngine/kraken/KRMesh.cpp +++ b/KREngine/kraken/KRMesh.cpp @@ -42,20 +42,23 @@ KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) { - m_hasTransparency = false; - m_materials.clear(); - m_uniqueMaterials.clear(); - m_pData = new KRDataBlock(); setName(name); + + m_hasTransparency = false; + m_pData = NULL; + m_pMetaData = NULL; + m_pIndexBaseData = NULL; + } KRMesh::KRMesh(KRContext &context, std::string name, KRDataBlock *data) : KRResource(context, name) { - m_hasTransparency = false; - m_materials.clear(); - m_uniqueMaterials.clear(); - m_pData = new KRDataBlock(); setName(name); + m_hasTransparency = false; + m_pData = NULL; + m_pMetaData = NULL; + m_pIndexBaseData = NULL; + loadPack(data); } @@ -103,8 +106,26 @@ int KRMesh::GetLODCoverage(const std::string &name) KRMesh::~KRMesh() { - clearData(); - if(m_pData) delete m_pData; + releaseData(); +} + +void KRMesh::releaseData() { + m_hasTransparency = false; + m_submeshes.clear(); + if(m_pIndexBaseData) { + m_pIndexBaseData->unlock(); + delete m_pIndexBaseData; + m_pIndexBaseData = NULL; + } + if(m_pMetaData) { + m_pMetaData->unlock(); + delete m_pMetaData; + m_pMetaData = NULL; + } + if(m_pData) { + delete m_pData; + m_pData = NULL; + } } std::string KRMesh::getExtension() { @@ -112,28 +133,36 @@ std::string KRMesh::getExtension() { } bool KRMesh::save(const std::string& path) { - clearBuffers(); return m_pData->save(path); } bool KRMesh::save(KRDataBlock &data) { - clearBuffers(); data.append(*m_pData); return true; } void KRMesh::loadPack(KRDataBlock *data) { - clearData(); - delete m_pData; + releaseData(); + m_pData = data; + + pack_header ph; + m_pData->copy((void *)&ph, 0, sizeof(ph)); + m_pMetaData = m_pData->getSubBlock(0, sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count); + m_pMetaData->lock(); + + m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8); + m_pIndexBaseData->lock(); + + m_minPoint = KRVector3(ph.minx, ph.miny, ph.minz); + m_maxPoint = KRVector3(ph.maxx, ph.maxy, ph.maxz); + updateAttributeOffsets(); - pack_header *pHeader = getHeader(); - m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz); - m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz); } -void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones) { +void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const KRVector3 &rim_color, float rim_power) { + //fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { getSubmeshes(); @@ -185,7 +214,7 @@ void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vect for(int i=0; i < bones.size(); i++) { bone_bind_poses.push_back(getBoneBindPose(i)); } - if(pMaterial->bind(pCamera, point_lights, directional_lights, spot_lights, bones, bone_bind_poses, viewport, matModel, pLightMap, renderPass)) { + if(pMaterial->bind(pCamera, point_lights, directional_lights, spot_lights, bones, bone_bind_poses, viewport, matModel, pLightMap, renderPass, rim_color, rim_power)) { switch(pMaterial->getAlphaMode()) { case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials @@ -250,21 +279,21 @@ void KRMesh::getSubmeshes() { } void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const std::string &object_name, const std::string &material_name) { + //m_pData->lock(); getSubmeshes(); Submesh *pSubmesh = m_submeshes[iSubmesh]; int cVertexes = pSubmesh->vertex_count; // fprintf(stderr, "start - object: %s material: %s vertices: %i\n", object_name.c_str(), material_name.c_str(), cVertexes); - unsigned char *pVertexData = getVertexData(); + int vertex_data_offset = getVertexDataOffset(); + int index_data_offset = getIndexDataOffset(); pack_header *pHeader = getHeader(); - + int32_t vertex_attrib_flags = pHeader->vertex_attrib_flags; + int32_t vertex_count = pHeader->vertex_count; + int vbo_index=0; if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) { - - - - __uint16_t *index_data = getIndexData(); int index_group = getSubmesh(iSubmesh)->index_group; int index_group_offset = getSubmesh(iSubmesh)->index_group_offset; while(cVertexes > 0) { @@ -272,7 +301,22 @@ void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const st int start_index_offset, start_vertex_offset, index_count, vertex_count; getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count); - m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size, index_data + start_index_offset, index_count * 2, pHeader->vertex_attrib_flags, true); + KRDataBlock *vertex_data_block = NULL; + KRDataBlock *index_data_block = NULL; + if(m_submeshes[iSubmesh]->vertex_data_blocks.size() <= vbo_index) { + vertex_data_block = m_pData->getSubBlock(vertex_data_offset + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size); + index_data_block = m_pData->getSubBlock(index_data_offset + start_index_offset * 2, index_count * 2); + m_submeshes[iSubmesh]->vertex_data_blocks.push_back(vertex_data_block); + m_submeshes[iSubmesh]->index_data_blocks.push_back(index_data_block); + } else { + vertex_data_block = m_submeshes[iSubmesh]->vertex_data_blocks[vbo_index]; + index_data_block = m_submeshes[iSubmesh]->index_data_blocks[vbo_index]; + } + vbo_index++; + + //m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size, index_data + start_index_offset, index_count * 2, vertex_attrib_flags, true); + m_pContext->getModelManager()->bindVBO(*vertex_data_block, *index_data_block, vertex_attrib_flags, true); + int vertex_draw_count = cVertexes; if(vertex_draw_count > index_count - index_group_offset) vertex_draw_count = index_count - index_group_offset; @@ -284,21 +328,27 @@ void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const st } } else { - int cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE; + int cBuffers = (vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE; int iVertex = pSubmesh->start_vertex; int iBuffer = iVertex / MAX_VBO_SIZE; iVertex = iVertex % MAX_VBO_SIZE; while(cVertexes > 0) { - GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE; + GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : vertex_count % MAX_VBO_SIZE; int vertex_size = m_vertex_size; - void *vbo_end = (unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size + vertex_size * cBufferVertexes; - void *buffer_end = m_pData->getEnd(); - assert(vbo_end <= buffer_end); - assert(cBufferVertexes <= 65535); + KRDataBlock *vertex_data_block = NULL; + KRDataBlock *index_data_block = NULL; + if(m_submeshes[iSubmesh]->vertex_data_blocks.size() <= vbo_index) { + vertex_data_block = m_pData->getSubBlock(vertex_data_offset + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes); + + m_submeshes[iSubmesh]->vertex_data_blocks.push_back(vertex_data_block); + } else { + vertex_data_block = m_submeshes[iSubmesh]->vertex_data_blocks[vbo_index]; + } + vbo_index++; - - m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, NULL, 0, pHeader->vertex_attrib_flags, true); + //m_pContext->getModelManager()->bindVBO((unsigned char *)pVertexData + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes, NULL, 0, vertex_attrib_flags, true); + m_pContext->getModelManager()->bindVBO(*vertex_data_block, *index_data_block, vertex_attrib_flags, true); if(iVertex + cVertexes >= MAX_VBO_SIZE) { @@ -344,13 +394,12 @@ void KRMesh::renderSubmesh(int iSubmesh, KRNode::RenderPass renderPass, const st } } - // fprintf(stderr, "end object\n"); - + //m_pData->unlock(); } -void KRMesh::LoadData(/*std::vector<__uint16_t> vertex_indexes, std::vector > vertex_index_bases, std::vector vertices, std::vector uva, std::vector uvb, std::vector normals, std::vector tangents, std::vector submesh_starts, std::vector submesh_lengths, std::vector material_names, std::vector bone_names, std::vector bone_bind_poses, std::vector > bone_indexes, std::vector > bone_weights, model_format_t model_format, */const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) { +void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) { - clearData(); + releaseData(); // TODO, FINDME - These values should be passed as a parameter and set by GUI flags bool use_short_vertexes = false; @@ -429,9 +478,10 @@ void KRMesh::LoadData(/*std::vector<__uint16_t> vertex_indexes, std::vectorexpand(new_file_size); - + m_pData->lock(); pack_header *pHeader = getHeader(); memset(pHeader, 0, sizeof(pack_header)); pHeader->vertex_attrib_flags = vertex_attrib_flags; @@ -573,6 +623,18 @@ void KRMesh::LoadData(/*std::vector<__uint16_t> vertex_indexes, std::vectorunlock(); + + // ---- + + pack_header ph; + m_pData->copy((void *)&ph, 0, sizeof(ph)); + m_pMetaData = m_pData->getSubBlock(0, sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count); + m_pMetaData->lock(); + m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8); + m_pIndexBaseData->lock(); + + // ---- optimize(); } @@ -585,14 +647,6 @@ KRVector3 KRMesh::getMaxPoint() const { return m_maxPoint; } -void KRMesh::clearData() { - m_pData->unload(); -} - -void KRMesh::clearBuffers() { - m_submeshes.clear(); -} - int KRMesh::getLODCoverage() const { return m_lodCoverage; } @@ -620,34 +674,47 @@ bool KRMesh::has_vertex_attribute(int vertex_attrib_flags, vertex_attrib_t attri KRMesh::pack_header *KRMesh::getHeader() const { - return (pack_header *)m_pData->getStart(); + return (pack_header *)m_pMetaData->getStart(); } KRMesh::pack_bone *KRMesh::getBone(int index) { pack_header *header = getHeader(); - return (pack_bone *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index); + return (pack_bone *)((unsigned char *)m_pMetaData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index); } unsigned char *KRMesh::getVertexData() const { + return ((unsigned char *)m_pData->getStart()) + getVertexDataOffset(); +} + +size_t KRMesh::getVertexDataOffset() const { pack_header *pHeader = getHeader(); - return ((unsigned char *)m_pData->getStart()) + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count) + KRALIGN(8 * pHeader->index_base_count); + return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count) + KRALIGN(8 * pHeader->index_base_count); } __uint16_t *KRMesh::getIndexData() const { + + return (__uint16_t *)((unsigned char *)m_pData->getStart() + getIndexDataOffset()); +} + +size_t KRMesh::getIndexDataOffset() const { pack_header *pHeader = getHeader(); - return (__uint16_t *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count); + return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count; } __uint32_t *KRMesh::getIndexBaseData() const { - pack_header *pHeader = getHeader(); - return (__uint32_t *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count)); + if(m_pIndexBaseData == NULL) { + pack_header *pHeader = getHeader(); + return (__uint32_t *)((unsigned char *)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count)); + } else { + return (__uint32_t *)m_pIndexBaseData->getStart(); + } } KRMesh::pack_material *KRMesh::getSubmesh(int mesh_index) const { - return (pack_material *)((unsigned char *)m_pData->getStart() + sizeof(pack_header)) + mesh_index; + return (pack_material *)((unsigned char *)m_pMetaData->getStart() + sizeof(pack_header)) + mesh_index; } unsigned char *KRMesh::getVertexData(int index) const @@ -658,7 +725,8 @@ unsigned char *KRMesh::getVertexData(int index) const int KRMesh::getSubmeshCount() const { pack_header *header = getHeader(); - return header->submesh_count; + int submesh_count = header->submesh_count; + return submesh_count; } int KRMesh::getVertexCount(int submesh) const @@ -893,7 +961,8 @@ size_t KRMesh::AttributeOffset(__int32_t vertex_attrib, __int32_t vertex_attrib_ int KRMesh::getBoneCount() { pack_header *header = getHeader(); - return header->bone_count; + int bone_count = header->bone_count; + return bone_count; } char *KRMesh::getBoneName(int bone_index) @@ -908,7 +977,8 @@ KRMat4 KRMesh::getBoneBindPose(int bone_index) KRMesh::model_format_t KRMesh::getModelFormat() const { - return (model_format_t)getHeader()->model_format; + model_format_t f = (model_format_t)getHeader()->model_format; + return f; } bool KRMesh::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, const KRVector3 &tri_v0, const KRVector3 &tri_v1, const KRVector3 &tri_v2, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo) @@ -1000,6 +1070,7 @@ bool KRMesh::rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_ind bool KRMesh::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const { + m_pData->lock(); bool hit_found = false; for(int submesh_index=0; submesh_index < getSubmeshCount(); submesh_index++) { // int vertex_start = getSubmesh(submesh_index)->start_vertex; @@ -1036,26 +1107,30 @@ bool KRMesh::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitin break; } } + m_pData->unlock(); return hit_found; } bool KRMesh::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const { + m_pData->lock(); KRHitInfo new_hitinfo; KRVector3 dir = KRVector3::Normalize(v1 - v0); if(rayCast(v0, dir, new_hitinfo)) { if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) { // The hit was between v1 and v2 hitinfo = new_hitinfo; + m_pData->unlock(); return true; } } + m_pData->unlock(); return false; // Either no hit, or the hit was beyond v1 } void KRMesh::convertToIndexed() { - + m_pData->lock(); char *szKey = new char[m_vertex_size * 2 + 1]; // Convert model to indexed vertices, identying vertexes with identical attributes and optimizing order of trianges for best usage post-vertex-transform cache on GPU @@ -1230,6 +1305,8 @@ void KRMesh::convertToIndexed() mi.format = KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES; + + m_pData->unlock(); LoadData(mi, false, false); } @@ -1264,6 +1341,9 @@ int KRMesh::getTriangleVertexIndex(int submesh, int index) const switch(getModelFormat()) { case KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES: { + __uint16_t *index_data = getIndexData(); + + int start_index_offset, start_vertex_offset, index_count, vertex_count; int index_group = getSubmesh(submesh)->index_group; int index_group_offset = getSubmesh(submesh)->index_group_offset; @@ -1273,7 +1353,7 @@ int KRMesh::getTriangleVertexIndex(int submesh, int index) const remaining_vertices -= index_count; getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count); } - return getIndexData()[start_index_offset + remaining_vertices] + start_vertex_offset; + return index_data[start_index_offset + remaining_vertices] + start_vertex_offset; } break; default: @@ -1284,85 +1364,89 @@ int KRMesh::getTriangleVertexIndex(int submesh, int index) const void KRMesh::optimizeIndexes() { - if(getModelFormat() != KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) return; - - __uint16_t *new_indices = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t)); - __uint16_t *vertex_mapping = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t)); - unsigned char *new_vertex_data = (unsigned char *)malloc(m_vertex_size * 0x10000); - - // FINDME, TODO, HACK - This will segfault if the KRData object is still mmap'ed to a read-only file. Need to detach from the file before calling this function. Currently, this function is only being used during the import process, so it isn't going to cause any problems for now. - - pack_header *header = getHeader(); - - __uint16_t *index_data = getIndexData(); - unsigned char *vertex_data = getVertexData(); - - for(int submesh_index=0; submesh_index < header->submesh_count; submesh_index++) { - pack_material *submesh = getSubmesh(submesh_index); - int vertexes_remaining = submesh->vertex_count; - int index_group = getSubmesh(submesh_index)->index_group; - int index_group_offset = getSubmesh(submesh_index)->index_group_offset; - while(vertexes_remaining > 0) { - int start_index_offset, start_vertex_offset, index_count, vertex_count; - getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count); - - int vertexes_to_process = vertexes_remaining; - if(vertexes_to_process + index_group_offset > 0xffff) { - vertexes_to_process = 0xffff - index_group_offset; - } - - __uint16_t *index_data_start = index_data + start_index_offset + index_group_offset; - - - // ----====---- Step 1: Optimize triangle drawing order to maximize use of the GPU's post-transform vertex cache ----====---- - Forsyth::OptimizeFaces(index_data_start, vertexes_to_process, vertex_count, new_indices, 16); // FINDME, TODO - GPU post-transform vertex cache size of 16 should be configureable - memcpy(index_data_start, new_indices, vertexes_to_process * sizeof(__uint16_t)); - vertexes_remaining -= vertexes_to_process; - - /* - - unsigned char * vertex_data_start = vertex_data + start_vertex_offset; - - // ----====---- Step 2: Re-order the vertex data to maintain cache coherency ----====---- - for(int i=0; i < vertex_count; i++) { - vertex_mapping[i] = i; - } - int new_vertex_index=0; - for(int index_number=0; index_number new_vertex_index) { - // Swap prev_vertex_index and new_vertex_index - - for(int i=0; i < index_count; i++) { - if(index_data_start[i] == prev_vertex_index) { - index_data_start[i] = new_vertex_index; - } else if(index_data_start[i] == new_vertex_index) { - index_data_start[i] = prev_vertex_index; - } - } - - int tmp = vertex_mapping[prev_vertex_index]; - vertex_mapping[prev_vertex_index] = vertex_mapping[new_vertex_index]; - vertex_mapping[new_vertex_index] = tmp; - - - new_vertex_index++; + m_pData->lock(); + if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) { + + __uint16_t *new_indices = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t)); + __uint16_t *vertex_mapping = (__uint16_t *)malloc(0x10000 * sizeof(__uint16_t)); + unsigned char *new_vertex_data = (unsigned char *)malloc(m_vertex_size * 0x10000); + + // FINDME, TODO, HACK - This will segfault if the KRData object is still mmap'ed to a read-only file. Need to detach from the file before calling this function. Currently, this function is only being used during the import process, so it isn't going to cause any problems for now. + + pack_header *header = getHeader(); + + __uint16_t *index_data = getIndexData(); + unsigned char *vertex_data = getVertexData(); + + for(int submesh_index=0; submesh_index < header->submesh_count; submesh_index++) { + pack_material *submesh = getSubmesh(submesh_index); + int vertexes_remaining = submesh->vertex_count; + int index_group = getSubmesh(submesh_index)->index_group; + int index_group_offset = getSubmesh(submesh_index)->index_group_offset; + while(vertexes_remaining > 0) { + int start_index_offset, start_vertex_offset, index_count, vertex_count; + getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count); + + int vertexes_to_process = vertexes_remaining; + if(vertexes_to_process + index_group_offset > 0xffff) { + vertexes_to_process = 0xffff - index_group_offset; } + + __uint16_t *index_data_start = index_data + start_index_offset + index_group_offset; + + + // ----====---- Step 1: Optimize triangle drawing order to maximize use of the GPU's post-transform vertex cache ----====---- + Forsyth::OptimizeFaces(index_data_start, vertexes_to_process, vertex_count, new_indices, 16); // FINDME, TODO - GPU post-transform vertex cache size of 16 should be configureable + memcpy(index_data_start, new_indices, vertexes_to_process * sizeof(__uint16_t)); + vertexes_remaining -= vertexes_to_process; + + /* + + unsigned char * vertex_data_start = vertex_data + start_vertex_offset; + + // ----====---- Step 2: Re-order the vertex data to maintain cache coherency ----====---- + for(int i=0; i < vertex_count; i++) { + vertex_mapping[i] = i; + } + int new_vertex_index=0; + for(int index_number=0; index_number new_vertex_index) { + // Swap prev_vertex_index and new_vertex_index + + for(int i=0; i < index_count; i++) { + if(index_data_start[i] == prev_vertex_index) { + index_data_start[i] = new_vertex_index; + } else if(index_data_start[i] == new_vertex_index) { + index_data_start[i] = prev_vertex_index; + } + } + + int tmp = vertex_mapping[prev_vertex_index]; + vertex_mapping[prev_vertex_index] = vertex_mapping[new_vertex_index]; + vertex_mapping[new_vertex_index] = tmp; + + + new_vertex_index++; + } + } + + for(int i=0; i < vertex_count; i++) { + memcpy(new_vertex_data + vertex_mapping[i] * m_vertex_size, vertex_data_start + i * m_vertex_size, m_vertex_size); + } + memcpy(vertex_data_start, new_vertex_data, vertex_count * m_vertex_size); + */ + + + + index_group_offset = 0; } - - for(int i=0; i < vertex_count; i++) { - memcpy(new_vertex_data + vertex_mapping[i] * m_vertex_size, vertex_data_start + i * m_vertex_size, m_vertex_size); - } - memcpy(vertex_data_start, new_vertex_data, vertex_count * m_vertex_size); - */ - - - - index_group_offset = 0; } - } + + free(new_indices); + free(vertex_mapping); + free(new_vertex_data); + } // if(getModelFormat() == KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES) - free(new_indices); - free(vertex_mapping); - free(new_vertex_data); + m_pData->unlock(); } diff --git a/KREngine/kraken/KRMesh.h b/KREngine/kraken/KRMesh.h index abc03d7..92e2162 100644 --- a/KREngine/kraken/KRMesh.h +++ b/KREngine/kraken/KRMesh.h @@ -109,7 +109,7 @@ public: std::vector > bone_weights; } mesh_info; - void render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones); + void render(const std::string &object_name, KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector &bones, const KRVector3 &rim_color, float rim_power); std::string m_lodBaseName; @@ -133,11 +133,24 @@ public: - typedef struct { + class Submesh { + public: + Submesh() {}; + ~Submesh() { + for(std::vector::iterator itr = vertex_data_blocks.begin(); itr != vertex_data_blocks.end(); itr++) { + delete (*itr); + } + for(std::vector::iterator itr = index_data_blocks.begin(); itr != index_data_blocks.end(); itr++) { + delete (*itr); + } + }; + GLint start_vertex; GLsizei vertex_count; char szMaterialName[KRENGINE_MAX_NAME_LENGTH]; - } Submesh; + vector vertex_data_blocks; + vector index_data_blocks; + }; typedef struct { union { @@ -198,6 +211,10 @@ public: static int GetLODCoverage(const std::string &name); private: + KRDataBlock *m_pData; + KRDataBlock *m_pMetaData; + KRDataBlock *m_pIndexBaseData; + void getSubmeshes(); // bool rayCast(const KRVector3 &line_v0, const KRVector3 &dir, int tri_index0, int tri_index1, int tri_index2, KRHitInfo &hitinfo) const; @@ -212,8 +229,7 @@ private: KRVector3 m_minPoint, m_maxPoint; - KRDataBlock *m_pData; - + typedef struct { @@ -234,24 +250,25 @@ private: int m_vertex_size; void updateAttributeOffsets(); - - void clearData(); - void clearBuffers(); - void setName(const std::string name); pack_material *getSubmesh(int mesh_index) const; unsigned char *getVertexData() const; + size_t getVertexDataOffset() const; unsigned char *getVertexData(int index) const; __uint16_t *getIndexData() const; + size_t getIndexDataOffset() const; __uint32_t *getIndexBaseData() const; pack_header *getHeader() const; pack_bone *getBone(int index); void getIndexedRange(int index_group, int &start_index_offset, int &start_vertex_offset, int &index_count, int &vertex_count) const; + + void releaseData(); + }; diff --git a/KREngine/kraken/KRMeshManager.cpp b/KREngine/kraken/KRMeshManager.cpp index 7f9b607..65c7985 100644 --- a/KREngine/kraken/KRMeshManager.cpp +++ b/KREngine/kraken/KRMeshManager.cpp @@ -35,23 +35,61 @@ #include "KRMesh.h" #include "KRMeshCube.h" +#include "KRMeshQuad.h" #include "KRMeshSphere.h" -KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) { +KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context), m_streamer(context) { m_currentVBO.vbo_handle = -1; m_currentVBO.vbo_handle_indexes = -1; m_currentVBO.vao_handle = -1; m_currentVBO.data = NULL; m_vboMemUsed = 0; - m_randomParticleVertexData = NULL; - m_volumetricLightingVertexData = NULL; m_memoryTransferredThisFrame = 0; -// addModel(new KRMeshCube(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults - + addModel(new KRMeshCube(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults + addModel(new KRMeshQuad(context)); // FINDME - HACK! This needs to be fixed, as it currently segfaults addModel(new KRMeshSphere(context)); m_draw_call_logging_enabled = false; m_draw_call_log_used = false; + + + + // ---- Initialize stock models ---- + + static const GLfloat _KRENGINE_VBO_3D_CUBE_VERTEX_DATA[] = { + 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 + }; + + KRENGINE_VBO_3D_CUBE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX); + KRENGINE_VBO_3D_CUBE_VERTICES.expand(sizeof(GLfloat) * 3 * 14); + KRENGINE_VBO_3D_CUBE_VERTICES.lock(); + memcpy(KRENGINE_VBO_3D_CUBE_VERTICES.getStart(), _KRENGINE_VBO_3D_CUBE_VERTEX_DATA, sizeof(GLfloat) * 3 * 14); + KRENGINE_VBO_3D_CUBE_VERTICES.unlock(); + + static const GLfloat _KRENGINE_VBO_2D_SQUARE_VERTEX_DATA[] = { + -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, + 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, + -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 0.0f, 1.0f, 1.0f + }; + KRENGINE_VBO_2D_SQUARE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA); + KRENGINE_VBO_2D_SQUARE_VERTICES.expand(sizeof(GLfloat) * 5 * 4); + KRENGINE_VBO_2D_SQUARE_VERTICES.lock(); + memcpy(KRENGINE_VBO_2D_SQUARE_VERTICES.getStart(), _KRENGINE_VBO_2D_SQUARE_VERTEX_DATA, sizeof(GLfloat) * 5 * 4); + KRENGINE_VBO_2D_SQUARE_VERTICES.unlock(); } KRMeshManager::~KRMeshManager() { @@ -59,8 +97,6 @@ KRMeshManager::~KRMeshManager() { delete (*itr).second; } m_models.empty(); - if(m_randomParticleVertexData != NULL) delete m_randomParticleVertexData; - if(m_volumetricLightingVertexData != NULL) delete m_volumetricLightingVertexData; } KRMesh *KRMeshManager::loadModel(const char *szName, KRDataBlock *pData) { @@ -115,24 +151,24 @@ void KRMeshManager::unbindVBO() { } } -void KRMeshManager::releaseVBO(GLvoid *data) +void KRMeshManager::releaseVBO(KRDataBlock &data) { - if(m_currentVBO.data == data) { + if(m_currentVBO.data == &data) { unbindVBO(); } vbo_info_type vbo_to_release; - if(m_vbosActive.find(data) != m_vbosActive.end()) { + if(m_vbosActive.find(&data) != m_vbosActive.end()) { fprintf(stderr, "glFinish called due to releasing a VBO that is active in the current frame.\n"); GLDEBUG(glFinish()); // The VBO is active - vbo_to_release = m_vbosActive[data]; - m_vbosActive.erase(data); + vbo_to_release = m_vbosActive[&data]; + m_vbosActive.erase(&data); } else { // The VBO is inactive - vbo_to_release = m_vbosPool[data]; - m_vbosPool.erase(data); + vbo_to_release = m_vbosPool[&data]; + m_vbosPool.erase(&data); } m_vboMemUsed -= vbo_to_release.size; @@ -146,12 +182,12 @@ void KRMeshManager::releaseVBO(GLvoid *data) } } -void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, int vertex_attrib_flags, bool static_vbo) { +void KRMeshManager::bindVBO(KRDataBlock &data, KRDataBlock &index_data, int vertex_attrib_flags, bool static_vbo) { - if(m_currentVBO.data != data || m_currentVBO.size != size + index_data_size) { + if(m_currentVBO.data != &data) { - if(m_vbosActive.find(data) != m_vbosActive.end()) { - m_currentVBO = m_vbosActive[data]; + if(m_vbosActive.find(&data) != m_vbosActive.end()) { + m_currentVBO = m_vbosActive[&data]; #if GL_OES_vertex_array_object GLDEBUG(glBindVertexArrayOES(m_currentVBO.vao_handle)); #else @@ -163,10 +199,10 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, G GLDEBUG(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_currentVBO.vbo_handle_indexes)); } #endif - } else if(m_vbosPool.find(data) != m_vbosPool.end()) { - m_currentVBO = m_vbosPool[data]; - m_vbosPool.erase(data); - m_vbosActive[data] = m_currentVBO; + } else if(m_vbosPool.find(&data) != m_vbosPool.end()) { + m_currentVBO = m_vbosPool[&data]; + m_vbosPool.erase(&data); + m_vbosActive[&data] = m_currentVBO; #if GL_OES_vertex_array_object GLDEBUG(glBindVertexArrayOES(m_currentVBO.vao_handle)); #else @@ -181,12 +217,12 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, G } else { - while(m_vbosPool.size() + m_vbosActive.size() + 1 >= KRContext::KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed + size + index_data_size >= KRContext::KRENGINE_MAX_VBO_MEM) { + while(m_vbosPool.size() + m_vbosActive.size() + 1 >= KRContext::KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed + data.getSize() + index_data.getSize() >= KRContext::KRENGINE_MAX_VBO_MEM) { if(m_vbosPool.empty()) { fprintf(stderr, "flushBuffers due to VBO exhaustion...\n"); m_pContext->rotateBuffers(false); } - unordered_map::iterator first_itr = m_vbosPool.begin(); + unordered_map::iterator first_itr = m_vbosPool.begin(); vbo_info_type firstVBO = first_itr->second; #if GL_OES_vertex_array_object GLDEBUG(glDeleteVertexArraysOES(1, &firstVBO.vao_handle)); @@ -204,7 +240,7 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, G m_currentVBO.vbo_handle = -1; m_currentVBO.vbo_handle_indexes = -1; GLDEBUG(glGenBuffers(1, &m_currentVBO.vbo_handle)); - if(index_data != NULL) { + if(index_data.getSize() > 0) { GLDEBUG(glGenBuffers(1, &m_currentVBO.vbo_handle_indexes)); } @@ -214,25 +250,49 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, G #endif GLDEBUG(glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.vbo_handle)); - GLDEBUG(glBufferData(GL_ARRAY_BUFFER, size, data, static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); - m_memoryTransferredThisFrame += size; - m_vboMemUsed += size; +#if GL_OES_mapbuffer + + GLDEBUG(glBufferData(GL_ARRAY_BUFFER, data.getSize(), NULL, static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); + GLDEBUG(void *map_ptr = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES)); + data.copy(map_ptr); + //memcpy(map_ptr, data, size); + GLDEBUG(glUnmapBufferOES(GL_ARRAY_BUFFER)); +#else + data.lock(); + GLDEBUG(glBufferData(GL_ARRAY_BUFFER, data.getSize(), data.getStart(), static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); + data.unlock(); +#endif + m_memoryTransferredThisFrame += data.getSize(); + m_vboMemUsed += data.getSize(); configureAttribs(vertex_attrib_flags); - m_currentVBO.size = size; - m_currentVBO.data = data; + m_currentVBO.size = data.getSize(); + m_currentVBO.data = &data; - if(index_data == NULL) { + if(index_data.getSize() == 0) { GLDEBUG(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } else { GLDEBUG(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_currentVBO.vbo_handle_indexes)); - GLDEBUG(glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_data_size, index_data, static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); - m_memoryTransferredThisFrame += index_data_size; - m_vboMemUsed += index_data_size; - m_currentVBO.size += index_data_size; + +#if GL_OES_mapbuffer + + GLDEBUG(glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_data.getSize(), NULL, static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); + GLDEBUG(void *map_ptr = glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES)); + index_data.copy(map_ptr); + //memcpy(map_ptr, index_data, index_data.getSize()); + GLDEBUG(glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER)); +#else + index_data.lock(); + GLDEBUG(glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_data.getSize(), index_data.getStart(), static_vbo ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW)); + index_data.unlock(); +#endif + + m_memoryTransferredThisFrame += index_data.getSize(); + m_vboMemUsed += index_data.getSize(); + m_currentVBO.size += index_data.getSize(); } - m_vbosActive[data] = m_currentVBO; + m_vbosActive[&data] = m_currentVBO; } } } @@ -314,7 +374,7 @@ long KRMeshManager::getMemUsed() long KRMeshManager::getMemActive() { long mem_active = 0; - for(unordered_map::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) { + for(unordered_map::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) { mem_active += (*itr).second.size; } return mem_active; @@ -332,56 +392,56 @@ void KRMeshManager::rotateBuffers(bool new_frame) } -KRMeshManager::VolumetricLightingVertexData *KRMeshManager::getVolumetricLightingVertexes() +KRDataBlock &KRMeshManager::getVolumetricLightingVertexes() { - if(m_volumetricLightingVertexData == NULL) { - m_volumetricLightingVertexData = (VolumetricLightingVertexData *)malloc(sizeof(VolumetricLightingVertexData) * KRENGINE_MAX_VOLUMETRIC_PLANES * 6); + if(m_volumetricLightingVertexData.getSize() == 0) { + m_volumetricLightingVertexData.expand(sizeof(VolumetricLightingVertexData) * KRENGINE_MAX_VOLUMETRIC_PLANES * 6); + m_volumetricLightingVertexData.lock(); + VolumetricLightingVertexData * vertex_data = (VolumetricLightingVertexData *)m_volumetricLightingVertexData.getStart(); int iVertex=0; for(int iPlane=0; iPlane < KRENGINE_MAX_VOLUMETRIC_PLANES; iPlane++) { - m_volumetricLightingVertexData[iVertex].vertex.x = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.x = -1.0f; + vertex_data[iVertex].vertex.y = -1.0f; + vertex_data[iVertex].vertex.z = iPlane; iVertex++; - m_volumetricLightingVertexData[iVertex].vertex.x = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.x = 1.0f; + vertex_data[iVertex].vertex.y = -1.0f; + vertex_data[iVertex].vertex.z = iPlane; iVertex++; - m_volumetricLightingVertexData[iVertex].vertex.x = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.x = -1.0f; + vertex_data[iVertex].vertex.y = 1.0f; + vertex_data[iVertex].vertex.z = iPlane; iVertex++; - m_volumetricLightingVertexData[iVertex].vertex.x = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.x = -1.0f; + vertex_data[iVertex].vertex.y = 1.0f; + vertex_data[iVertex].vertex.z = iPlane; iVertex++; - m_volumetricLightingVertexData[iVertex].vertex.x = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = -1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; + vertex_data[iVertex].vertex.x = 1.0f; + vertex_data[iVertex].vertex.y = -1.0f; + vertex_data[iVertex].vertex.z = iPlane; iVertex++; + vertex_data[iVertex].vertex.x = 1.0f; + vertex_data[iVertex].vertex.y = 1.0f; + vertex_data[iVertex].vertex.z = iPlane; + iVertex++; - m_volumetricLightingVertexData[iVertex].vertex.x = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.y = 1.0f; - m_volumetricLightingVertexData[iVertex].vertex.z = iPlane; - iVertex++; - -// -1.0f, -1.0f, -// 1.0f, -1.0f, -// -1.0f, 1.0f, -// 1.0f, 1.0f, } + m_volumetricLightingVertexData.unlock(); } return m_volumetricLightingVertexData; } -KRMeshManager::RandomParticleVertexData *KRMeshManager::getRandomParticles() +KRDataBlock &KRMeshManager::getRandomParticles() { - if(m_randomParticleVertexData == NULL) { - m_randomParticleVertexData = (RandomParticleVertexData *)malloc(sizeof(RandomParticleVertexData) * KRENGINE_MAX_RANDOM_PARTICLES * 3); + if(m_randomParticleVertexData.getSize() == 0) { + m_randomParticleVertexData.expand(sizeof(RandomParticleVertexData) * KRENGINE_MAX_RANDOM_PARTICLES * 3); + m_randomParticleVertexData.lock(); + RandomParticleVertexData *vertex_data = (RandomParticleVertexData *)m_randomParticleVertexData.getStart(); // Generate vertices for randomly placed equilateral triangles with a side length of 1 and an origin point centered so that an inscribed circle can be efficiently rendered without wasting fill @@ -390,27 +450,28 @@ KRMeshManager::RandomParticleVertexData *KRMeshManager::getRandomParticles() int iVertex=0; for(int iParticle=0; iParticle < KRENGINE_MAX_RANDOM_PARTICLES; iParticle++) { - m_randomParticleVertexData[iVertex].vertex.x = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; - m_randomParticleVertexData[iVertex].vertex.y = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; - m_randomParticleVertexData[iVertex].vertex.z = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; - m_randomParticleVertexData[iVertex].uva.u = -0.5f; - m_randomParticleVertexData[iVertex].uva.v = -inscribed_circle_radius; + vertex_data[iVertex].vertex.x = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; + vertex_data[iVertex].vertex.y = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; + vertex_data[iVertex].vertex.z = (float)(arc4random() % 2000) / 1000.0f - 1000.0f; + vertex_data[iVertex].uva.u = -0.5f; + vertex_data[iVertex].uva.v = -inscribed_circle_radius; iVertex++; - m_randomParticleVertexData[iVertex].vertex.x = m_randomParticleVertexData[iVertex-1].vertex.x; - m_randomParticleVertexData[iVertex].vertex.y = m_randomParticleVertexData[iVertex-1].vertex.y; - m_randomParticleVertexData[iVertex].vertex.z = m_randomParticleVertexData[iVertex-1].vertex.z; - m_randomParticleVertexData[iVertex].uva.u = 0.5f; - m_randomParticleVertexData[iVertex].uva.v = -inscribed_circle_radius; + vertex_data[iVertex].vertex.x = vertex_data[iVertex-1].vertex.x; + vertex_data[iVertex].vertex.y = vertex_data[iVertex-1].vertex.y; + vertex_data[iVertex].vertex.z = vertex_data[iVertex-1].vertex.z; + vertex_data[iVertex].uva.u = 0.5f; + vertex_data[iVertex].uva.v = -inscribed_circle_radius; iVertex++; - m_randomParticleVertexData[iVertex].vertex.x = m_randomParticleVertexData[iVertex-1].vertex.x; - m_randomParticleVertexData[iVertex].vertex.y = m_randomParticleVertexData[iVertex-1].vertex.y; - m_randomParticleVertexData[iVertex].vertex.z = m_randomParticleVertexData[iVertex-1].vertex.z; - m_randomParticleVertexData[iVertex].uva.u = 0.0f; - m_randomParticleVertexData[iVertex].uva.v = -inscribed_circle_radius + equilateral_triangle_height; + vertex_data[iVertex].vertex.x = vertex_data[iVertex-1].vertex.x; + vertex_data[iVertex].vertex.y = vertex_data[iVertex-1].vertex.y; + vertex_data[iVertex].vertex.z = vertex_data[iVertex-1].vertex.z; + vertex_data[iVertex].uva.u = 0.0f; + vertex_data[iVertex].uva.v = -inscribed_circle_radius + equilateral_triangle_height; iVertex++; } + m_randomParticleVertexData.unlock(); } return m_randomParticleVertexData; } diff --git a/KREngine/kraken/KRMeshManager.h b/KREngine/kraken/KRMeshManager.h index 6e17df4..2783617 100644 --- a/KREngine/kraken/KRMeshManager.h +++ b/KREngine/kraken/KRMeshManager.h @@ -37,6 +37,8 @@ #include "KRDataBlock.h" #include "KRNode.h" +#include "KRMeshStreamer.h" + class KRContext; class KRMesh; @@ -59,8 +61,8 @@ public: std::vector getModelNames(); unordered_multimap &getModels(); - void bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, int vertex_attrib_flags, bool static_vbo); - void releaseVBO(GLvoid *data); + void bindVBO(KRDataBlock &data, KRDataBlock &index_data, int vertex_attrib_flags, bool static_vbo); + void releaseVBO(KRDataBlock &data); void unbindVBO(); long getMemUsed(); long getMemActive(); @@ -88,10 +90,8 @@ public: } VolumetricLightingVertexData; - - - RandomParticleVertexData *getRandomParticles(); - VolumetricLightingVertexData *getVolumetricLightingVertexes(); + KRDataBlock &getRandomParticles(); + KRDataBlock &getVolumetricLightingVertexes(); long getMemoryTransferedThisFrame(); @@ -108,7 +108,13 @@ public: void log_draw_call(KRNode::RenderPass pass, const std::string &object_name, const std::string &material_name, int vertex_count); std::vector getDrawCalls(); - + + + KRDataBlock KRENGINE_VBO_3D_CUBE_VERTICES, KRENGINE_VBO_3D_CUBE_INDEXES; + __int32_t KRENGINE_VBO_3D_CUBE_ATTRIBS; + + KRDataBlock KRENGINE_VBO_2D_SQUARE_VERTICES, KRENGINE_VBO_2D_SQUARE_INDEXES; + __int32_t KRENGINE_VBO_2D_SQUARE_ATTRIBS; private: unordered_multimap m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model @@ -118,23 +124,25 @@ private: GLuint vbo_handle_indexes; GLuint vao_handle; GLsizeiptr size; - GLvoid *data; + KRDataBlock *data; } vbo_info_type; long m_vboMemUsed; vbo_info_type m_currentVBO; - unordered_map m_vbosActive; - unordered_map m_vbosPool; + unordered_map m_vbosActive; + unordered_map m_vbosPool; - RandomParticleVertexData *m_randomParticleVertexData; - VolumetricLightingVertexData *m_volumetricLightingVertexData; + KRDataBlock m_randomParticleVertexData; + KRDataBlock m_volumetricLightingVertexData; long m_memoryTransferredThisFrame; std::vector m_draw_calls; bool m_draw_call_logging_enabled; bool m_draw_call_log_used; + + KRMeshStreamer m_streamer; }; diff --git a/KREngine/kraken/KRMeshQuad.cpp b/KREngine/kraken/KRMeshQuad.cpp new file mode 100644 index 0000000..875f8a7 --- /dev/null +++ b/KREngine/kraken/KRMeshQuad.cpp @@ -0,0 +1,62 @@ +// +// KRMeshQuad.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 "KRMeshQuad.h" + + +KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad") +{ + KRMesh::mesh_info mi; + + mi.vertices.push_back(KRVector3(-1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(-1.0f, 1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(1.0f, 1.0f, 0.0f)); + + mi.uva.push_back(KRVector2(0.0f, 0.0f)); + mi.uva.push_back(KRVector2(1.0f, 0.0f)); + mi.uva.push_back(KRVector2(0.0f, 1.0f)); + mi.uva.push_back(KRVector2(1.0f, 1.0f)); + + + mi.submesh_starts.push_back(0); + mi.submesh_lengths.push_back(mi.vertices.size()); + mi.material_names.push_back(""); + mi.format = KRENGINE_MODEL_FORMAT_STRIP; + + + LoadData(mi, true, true); +} + +KRMeshQuad::~KRMeshQuad() +{ + +} diff --git a/KREngine/kraken/KRMeshQuad.h b/KREngine/kraken/KRMeshQuad.h new file mode 100644 index 0000000..5fa5de2 --- /dev/null +++ b/KREngine/kraken/KRMeshQuad.h @@ -0,0 +1,44 @@ +// +// KRMeshQuad.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 KRMESHQUAD_H +#define KRMESHQUAD_H + +#include "KRMesh.h" + +class KRMeshQuad : public KRMesh { +public: + KRMeshQuad(KRContext &context); + virtual ~KRMeshQuad(); +private: +}; + +#endif diff --git a/KREngine/kraken/KRMeshStreamer.h b/KREngine/kraken/KRMeshStreamer.h new file mode 100644 index 0000000..beb3666 --- /dev/null +++ b/KREngine/kraken/KRMeshStreamer.h @@ -0,0 +1,60 @@ +// +// KRMeshManager.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 KRMESHSTREAMER_H +#define KRMESHSTREAMER_H + +#include "KREngine-common.h" + +#include +#include + +class KRContext; + +class KRMeshStreamer +{ +public: + KRMeshStreamer(KRContext &context); + ~KRMeshStreamer(); + + void startStreamer(); + +private: + KRContext &m_context; + + std::thread m_thread; + std::atomic m_stop; + std::atomic m_running; + + void run(); +}; + +#endif /* defined(KRMESHSTREAMER_H) */ diff --git a/KREngine/kraken/KRMeshStreamer.mm b/KREngine/kraken/KRMeshStreamer.mm new file mode 100644 index 0000000..1fd6560 --- /dev/null +++ b/KREngine/kraken/KRMeshStreamer.mm @@ -0,0 +1,91 @@ +// +// KRMeshStreamer.cpp +// Kraken +// +// Created by Kearwood Gilbert on 11/1/2013. +// Copyright (c) 2013 Kearwood Software. All rights reserved. +// + +#include "KRMeshStreamer.h" + +#include "KREngine-common.h" +#include "KRContext.h" + +#include + +#if TARGET_OS_IPHONE + +EAGLContext *gMeshStreamerContext = nil; + +#elif TARGET_OS_MAC + +NSOpenGLContext *gMeshStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif + +KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context) +{ + m_running = false; + m_stop = false; +} + +void KRMeshStreamer::startStreamer() +{ + if(!m_running) { + m_running = true; + +#if TARGET_OS_IPHONE + gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; +#elif TARGET_OS_MAC + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; +#else + #error Unsupported Platform +#endif + + m_thread = std::thread(&KRMeshStreamer::run, this); + } +} + +KRMeshStreamer::~KRMeshStreamer() +{ + if(m_running) { + m_stop = true; + m_thread.join(); + m_running = false; + } + + [gMeshStreamerContext release]; +} + +void KRMeshStreamer::run() +{ + pthread_setname_np("Kraken - Mesh Streamer"); + + std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE + [EAGLContext setCurrentContext: gMeshStreamerContext]; +#elif TARGET_OS_MAC + [gMeshStreamerContext makeCurrentContext]; +#else + #error Unsupported Platform +#endif + + + while(!m_stop) + { + if(m_context.getStreamingEnabled()) { + + } + std::this_thread::sleep_for( sleep_duration ); + } +} diff --git a/KREngine/kraken/KRModel.cpp b/KREngine/kraken/KRModel.cpp index 1f1be11..a7bd54e 100644 --- a/KREngine/kraken/KRModel.cpp +++ b/KREngine/kraken/KRModel.cpp @@ -36,13 +36,32 @@ #include "KRMesh.h" #include "KRQuaternion.h" -KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera) : KRNode(scene, instance_name) { +KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, KRVector3 rim_color, float rim_power) : KRNode(scene, instance_name) { m_lightMap = light_map; m_pLightMap = NULL; m_model_name = model_name; m_min_lod_coverage = lod_min_coverage; m_receivesShadow = receives_shadow; m_faces_camera = faces_camera; + m_rim_color = rim_color; + m_rim_power = rim_power; + + m_boundsCachedMat.c[0] = -1.0f; + m_boundsCachedMat.c[1] = -1.0f; + m_boundsCachedMat.c[2] = -1.0f; + m_boundsCachedMat.c[3] = -1.0f; + m_boundsCachedMat.c[4] = -1.0f; + m_boundsCachedMat.c[5] = -1.0f; + m_boundsCachedMat.c[6] = -1.0f; + m_boundsCachedMat.c[7] = -1.0f; + m_boundsCachedMat.c[8] = -1.0f; + m_boundsCachedMat.c[9] = -1.0f; + m_boundsCachedMat.c[10] = -1.0f; + m_boundsCachedMat.c[11] = -1.0f; + m_boundsCachedMat.c[12] = -1.0f; + m_boundsCachedMat.c[13] = -1.0f; + m_boundsCachedMat.c[14] = -1.0f; + m_boundsCachedMat.c[15] = -1.0f; } KRModel::~KRModel() { @@ -61,9 +80,31 @@ tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent) e->SetAttribute("lod_min_coverage", m_min_lod_coverage); e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); + m_rim_color.setXMLAttribute("rim_color", e); + e->SetAttribute("rim_power", m_rim_power); return e; } +void KRModel::setRimColor(const const KRVector3 &rim_color) +{ + m_rim_color = rim_color; +} + +void KRModel::setRimPower(float rim_power) +{ + m_rim_power = rim_power; +} + +KRVector3 KRModel::getRimColor() +{ + return m_rim_color; +} + +float KRModel::getRimPower() +{ + return m_rim_power; +} + void KRModel::loadModel() { if(m_models.size() == 0) { std::vector models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first @@ -141,7 +182,7 @@ void KRModel::render(KRCamera *pCamera, std::vector &point_light matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; } - pModel->render(getName(), pCamera, point_lights, directional_lights, spot_lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel]); + pModel->render(getName(), pCamera, point_lights, directional_lights, spot_lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel], m_rim_color, m_rim_power); } } } @@ -155,7 +196,12 @@ KRAABB KRModel::getBounds() { float max_dimension = normal_bounds.longest_radius(); return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); } else { - return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + + if(!(m_boundsCachedMat == getModelMatrix())) { + m_boundsCachedMat = getModelMatrix(); + m_boundsCached = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + } + return m_boundsCached; } } else { return KRAABB::Infinite(); diff --git a/KREngine/kraken/KRModel.h b/KREngine/kraken/KRModel.h index 80e145c..25f46e0 100644 --- a/KREngine/kraken/KRModel.h +++ b/KREngine/kraken/KRModel.h @@ -51,7 +51,7 @@ class KRModel : public KRNode { public: - KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera); + KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, KRVector3 rim_color = KRVector3::Zero(), float rim_power = 0.0f); virtual ~KRModel(); virtual std::string getElementName(); @@ -61,6 +61,11 @@ public: virtual KRAABB getBounds(); + void setRimColor(const const KRVector3 &rim_color); + void setRimPower(float rim_power); + KRVector3 getRimColor(); + float getRimPower(); + private: std::vector m_models; unordered_map > m_bones; // Outer std::map connects model to set of bones @@ -74,6 +79,14 @@ private: bool m_receivesShadow; bool m_faces_camera; + + + KRMat4 m_boundsCachedMat; + KRAABB m_boundsCached; + + + KRVector3 m_rim_color; + float m_rim_power; }; diff --git a/KREngine/kraken/KRNode.cpp b/KREngine/kraken/KRNode.cpp index 56d8093..ebbbeb2 100644 --- a/KREngine/kraken/KRNode.cpp +++ b/KREngine/kraken/KRNode.cpp @@ -20,9 +20,11 @@ #include "KRAABB.h" #include "KRQuaternion.h" #include "KRBone.h" +#include "KRLocator.h" #include "KRAudioSource.h" #include "KRAmbientZone.h" #include "KRReverbZone.h" +#include "KRSprite.h" KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext()) { @@ -403,6 +405,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { new_node = new KRSpotLight(scene, szName); } else if(strcmp(szElementName, "particles_newtonian") == 0) { new_node = new KRParticleSystemNewtonian(scene, szName); + } else if(strcmp(szElementName, "sprite") == 0) { + new_node = new KRSprite(scene, szName); } else if(strcmp(szElementName, "model") == 0) { float lod_min_coverage = 0.0f; if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) { @@ -416,11 +420,19 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { if(e->QueryBoolAttribute("faces_camera", &faces_camera) != tinyxml2::XML_SUCCESS) { faces_camera = false; } - new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera); + float rim_power = 0.0f; + if(e->QueryFloatAttribute("rim_power", &rim_power) != tinyxml2::XML_SUCCESS) { + rim_power = 0.0f; + } + KRVector3 rim_color = KRVector3::Zero(); + rim_color.getXMLAttribute("rim_color", e, KRVector3::Zero()); + new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera, rim_color, rim_power); } else if(strcmp(szElementName, "collider") == 0) { new_node = new KRCollider(scene, szName, e->Attribute("mesh"), 65535, 1.0f); } else if(strcmp(szElementName, "bone") == 0) { new_node = new KRBone(scene, szName); + } else if(strcmp(szElementName, "locator") == 0) { + new_node = new KRLocator(scene, szName); } else if(strcmp(szElementName, "audio_source") == 0) { new_node = new KRAudioSource(scene, szName); } else if(strcmp(szElementName, "ambient_zone") == 0) { @@ -447,6 +459,10 @@ const std::set &KRNode::getChildren() { return m_childNodes; } +KRNode *KRNode::getParent() { + return m_parentNode; +} + const std::string &KRNode::getName() const { return m_name; } @@ -910,4 +926,9 @@ void KRNode::addBehavior(KRBehavior *behavior) m_behaviors.insert(behavior); behavior->__setNode(this); getScene().notify_sceneGraphModify(this); -} \ No newline at end of file +} + +std::set &KRNode::getBehaviors() +{ + return m_behaviors; +} diff --git a/KREngine/kraken/KRNode.h b/KREngine/kraken/KRNode.h index 61cea10..eb074fa 100644 --- a/KREngine/kraken/KRNode.h +++ b/KREngine/kraken/KRNode.h @@ -58,6 +58,7 @@ public: void addChild(KRNode *child); const std::set &getChildren(); + KRNode *getParent(); void setLocalTranslation(const KRVector3 &v, bool set_original = false); void setLocalScale(const KRVector3 &v, bool set_original = false); @@ -226,6 +227,17 @@ private: public: void addBehavior(KRBehavior *behavior); + std::set &getBehaviors(); + template T *getBehavior() + { + for(std::set::iterator itr=m_behaviors.begin(); itr != m_behaviors.end(); itr++) { + T *behavior = dynamic_cast(*itr); + if(behavior) { + return behavior; + } + } + return NULL; + } void removeFromOctreeNodes(); void addToOctreeNode(KROctreeNode *octree_node); void childDeleted(KRNode *child_node); diff --git a/KREngine/kraken/KRParticleSystemNewtonian.cpp b/KREngine/kraken/KRParticleSystemNewtonian.cpp index 81324cd..89e9dc5 100644 --- a/KREngine/kraken/KRParticleSystemNewtonian.cpp +++ b/KREngine/kraken/KRParticleSystemNewtonian.cpp @@ -74,10 +74,13 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vectorgetShaderManager()->getShader("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f); - m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false); + //m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false); + KRDataBlock index_data; + m_pContext->getModelManager()->bindVBO(m_pContext->getModelManager()->getRandomParticles(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false); GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3)); } } diff --git a/KREngine/kraken/KRPointLight.cpp b/KREngine/kraken/KRPointLight.cpp index d18ddcb..fd7cbce 100644 --- a/KREngine/kraken/KRPointLight.cpp +++ b/KREngine/kraken/KRPointLight.cpp @@ -69,8 +69,8 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &point_ bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ()); KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector(), std::vector(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector(), std::vector(), 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector(), std::vector(), 0, renderPass, rim_color, 0.0f)) { pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); @@ -96,7 +96,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector &point_ GLDEBUG(glDisable(GL_DEPTH_TEST)); // Render a full screen quad - m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); } else { #if GL_OES_vertex_array_object diff --git a/KREngine/kraken/KRResource+fbx.cpp b/KREngine/kraken/KRResource+fbx.cpp index 360f002..e2fb402 100644 --- a/KREngine/kraken/KRResource+fbx.cpp +++ b/KREngine/kraken/KRResource+fbx.cpp @@ -9,6 +9,7 @@ #include "KREngine-common.h" #include #include +#include #include @@ -23,6 +24,7 @@ #include "KRScene.h" #include "KRQuaternion.h" #include "KRBone.h" +#include "KRLocator.h" #include "KRBundle.h" #include "KRModel.h" #include "KRLODGroup.h" @@ -33,20 +35,21 @@ #define IOS_REF (*(pSdkManager->GetIOSettings())) #endif -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene); -void DestroySdkObjects(KFbxSdkManager* pSdkManager); -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename); +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene); +void DestroySdkObjects(FbxManager* pSdkManager); +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename); KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack); KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurve); KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer); -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); //void BakeNode(KFbxNode* pNode); void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial); -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh); -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode); -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, KFbxNode* pNode); -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh); +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode); +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode); std::string GetFbxObjectName(FbxObject *obj); const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable @@ -54,9 +57,28 @@ const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be c std::string GetFbxObjectName(FbxObject *obj) { + bool is_locator = false; + FbxNode *node = FbxCast(obj); + if(node) { + FbxNodeAttribute::EType attribute_type = (node->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) node->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { + is_locator = true; + } + } + } + + // Object names from FBX files are now concatenated with the FBX numerical ID to ensure that they are unique // TODO - This should be updated to only add a prefix or suffix if needed to make the name unique - if(strcmp(obj->GetName(), "default_camera") == 0) { + if(is_locator) { + // We do not rename locators + return std::string(obj->GetName()); + } else if(strncmp(obj->GetName(), "so_", 3) == 0) { + // An so_ prefix indicates that this is a "Scriptable Object" that should not have the name decorated; + return obj->GetName(); + } else if(strcmp(obj->GetName(), "default_camera") == 0) { // There is currently support for rendering from only one camera, "default_camera". We don't translate this node's name, so that animations can drive the camera return "default_camera"; } else { @@ -76,8 +98,8 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path)); context.getSceneManager()->add(pScene); - KFbxSdkManager* lSdkManager = NULL; - KFbxScene* pFbxScene = NULL; + FbxManager* lSdkManager = NULL; + FbxScene* pFbxScene = NULL; bool lResult; FbxGeometryConverter *pGeometryConverter = NULL; @@ -90,7 +112,7 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) // Load the scene. lResult = LoadScene(lSdkManager, pFbxScene, path.c_str()); - KFbxNode* pNode = pFbxScene->GetRootNode(); + FbxNode* pNode = pFbxScene->GetRootNode(); // ----====---- Bake pivots into transforms, as Kraken doesn't support them directly ----====---- /* @@ -120,7 +142,9 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) FbxAnimCurve *curve = pFbxScene->GetSrcObject(i); printf(" Animation Curve %i of %i: %s\n", i+1, curve_count, curve->GetName()); KRAnimationCurve *new_curve = LoadAnimationCurve(context, curve); + if(new_curve) { + printf("Adding a curve\n"); context.getAnimationCurveManager()->addAnimationCurve(new_curve); } } @@ -171,11 +195,11 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) DestroySdkObjects(lSdkManager); } -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene) { // The first thing to do is to create the FBX SDK manager which is the // object allocator for almost all the classes in the SDK. - pSdkManager = KFbxSdkManager::Create(); + pSdkManager = FbxManager::Create(); if (!pSdkManager) { @@ -184,25 +208,27 @@ void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) } // create an IOSettings object - KFbxIOSettings * ios = KFbxIOSettings::Create(pSdkManager, IOSROOT ); + FbxIOSettings * ios = FbxIOSettings::Create(pSdkManager, IOSROOT ); pSdkManager->SetIOSettings(ios); // Load plugins from the executable directory - KString lPath = FbxGetApplicationDirectory(); -#if defined(KARCH_ENV_WIN) - KString lExtension = "dll"; -#elif defined(KARCH_ENV_MACOSX) - KString lExtension = "dylib"; -#elif defined(KARCH_ENV_LINUX) - KString lExtension = "so"; + FbxString lPath = FbxGetApplicationDirectory(); +#if TARGET_OS_WIN32 + FbxString lExtension = "dll"; +#elif TARGET_OS_MAC + FbxString lExtension = "dylib"; +#elif TARGET_OS_UNIX + FbxString lExtension = "so"; +#elif + #error Unsupported Platform #endif pSdkManager->LoadPluginsDirectory(lPath.Buffer(), lExtension.Buffer()); // Create the entity that will hold the scene. - pScene = KFbxScene::Create(pSdkManager,""); + pScene = FbxScene::Create(pSdkManager,""); } -void DestroySdkObjects(KFbxSdkManager* pSdkManager) +void DestroySdkObjects(FbxManager* pSdkManager) { // Delete the FBX SDK manager. All the objects that have been allocated // using the FBX SDK manager and that haven't been explicitly destroyed @@ -212,7 +238,7 @@ void DestroySdkObjects(KFbxSdkManager* pSdkManager) } -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename) +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename) { int lFileMajor, lFileMinor, lFileRevision; int lSDKMajor, lSDKMinor, lSDKRevision; @@ -222,10 +248,10 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF char lPassword[1024]; // Get the file version number generate by the FBX SDK. - KFbxSdkManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); + FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); // Create an importer. - KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager,""); + FbxImporter* lImporter = FbxImporter::Create(pSdkManager,""); // Initialize the importer by providing a filename. const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings()); @@ -233,11 +259,14 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF if( !lImportStatus ) { - printf("Call to KFbxImporter::Initialize() failed.\n"); - printf("Error returned: %s\n\n", lImporter->GetLastErrorString()); + FbxStatus &status = lImporter->GetStatus(); - if (lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedYet || - lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedAnymore) + printf("Call to KFbxImporter::Initialize() failed.\n"); + printf("Error returned: %s\n\n", status.GetErrorString()); + + + + if (status.GetCode() == FbxStatus::EStatusCode::eInvalidFileVersion) { printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision); printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision); @@ -281,21 +310,21 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF // Import the scene. lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("Please enter password: "); lPassword[0] = '\0'; scanf("%s", lPassword); - KString lString(lPassword); + FbxString lString(lPassword); IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString); IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true); lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("\nPassword is wrong, import aborted.\n"); } @@ -543,8 +572,8 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye // } //} -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { - KFbxVector4 lTmpVector; +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { + FbxVector4 lTmpVector; pNode->UpdatePropertiesFromPivotsAndLimits(); @@ -813,27 +842,27 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } } } - - fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); - fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); - fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); + + FbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); + FbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); + FbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); bool rotation_active = pNode->RotationActive.Get(); - fbxDouble3 post_rotation = pNode->PostRotation.Get(); - fbxDouble3 pre_rotation = pNode->PreRotation.Get(); - fbxDouble3 rotation_offset = pNode->RotationOffset.Get(); - fbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); - fbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); - fbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); - fbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); - fbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); - fbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); - ERotationOrder rotation_order = pNode->RotationOrder.Get(); + FbxDouble3 post_rotation = pNode->PostRotation.Get(); + FbxDouble3 pre_rotation = pNode->PreRotation.Get(); + FbxDouble3 rotation_offset = pNode->RotationOffset.Get(); + FbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); + FbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); + FbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); + FbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); + FbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); + FbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); + EFbxRotationOrder rotation_order = pNode->RotationOrder.Get(); - KFbxVector4 lZero(0.0, 0.0, 0.0); - KFbxVector4 lOne(1.0, 1.0, 1.0); + FbxVector4 lZero(0.0, 0.0, 0.0); + FbxVector4 lOne(1.0, 1.0, 1.0); assert(geometric_rotation == lZero); assert(geometric_translation == lZero); @@ -861,8 +890,8 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p // printf(" Local Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]); // printf(" Local Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]); - KFbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); - if(attribute_type == KFbxNodeAttribute::eLODGroup) { + FbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eLODGroup) { std::string name = GetFbxObjectName(pNode); FbxLODGroup *fbx_lod_group = (FbxLODGroup*) pNode->GetNodeAttribute(); // FbxCast(pNode); bool use_world_space_units = fbx_lod_group->WorldSpace.Get(); @@ -946,69 +975,55 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } else { KRNode *new_node = NULL; switch(attribute_type) { - case KFbxNodeAttribute::eMesh: + case FbxNodeAttribute::eMesh: new_node = LoadMesh(parent_node, pFbxScene, pGeometryConverter, pNode); break; - case KFbxNodeAttribute::eLight: + case FbxNodeAttribute::eLight: new_node = LoadLight(parent_node, pNode); break; - case KFbxNodeAttribute::eSkeleton: + case FbxNodeAttribute::eSkeleton: new_node = LoadSkeleton(parent_node, pFbxScene, pNode); break; - case KFbxNodeAttribute::eCamera: + + case FbxNodeAttribute::eCamera: new_node = LoadCamera(parent_node, pNode); break; default: { - if(pNode->GetChildCount() > 0) { - // Create an empty node, for inheritence of transforms - std::string name = GetFbxObjectName(pNode); - - float min_distance = 0.0f; - float max_distance = 0.0f; - - typedef boost::tokenizer > char_tokenizer; - - int step = 0; - - char_tokenizer name_components(name, boost::char_separator("_")); - for(char_tokenizer::iterator itr=name_components.begin(); itr != name_components.end(); itr++) { - std::string component = *itr; - std::transform(component.begin(), component.end(), - component.begin(), ::tolower); - if(component.compare("lod") == 0) { - step = 1; - } else if(step == 1) { - min_distance = boost::lexical_cast(component); - step++; - } else if(step == 2) { - max_distance = boost::lexical_cast(component); - step++; - } + bool is_locator = false; + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) pNode->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { + is_locator = true; } - - /* - if(min_distance == 0.0f && max_distance == 0.0f) { - // Regular node for grouping children together under one transform - new_node = new KRNode(parent_node->getScene(), name); - } else { - */ - // LOD Enabled group node - KRLODGroup *lod_group = new KRLODGroup(parent_node->getScene(), name); - lod_group->setMinDistance(min_distance); - lod_group->setMaxDistance(max_distance); - new_node = lod_group; - /* + } + + if(is_locator) { + new_node = LoadLocator(parent_node, pFbxScene, pNode); + } else { + if(pNode->GetChildCount() > 0) { + // Create an empty node, for inheritence of transforms + std::string name = GetFbxObjectName(pNode); + + + /* + if(min_distance == 0.0f && max_distance == 0.0f) { + // Regular node for grouping children together under one transform + new_node = new KRNode(parent_node->getScene(), name); + } else { + */ + // LOD Enabled group node + KRLODGroup *lod_group = new KRLODGroup(parent_node->getScene(), name); + lod_group->setMinDistance(0.0f); + lod_group->setMaxDistance(0.0f); + new_node = lod_group; } - */ - - } } break; } - + // this is a KRNode if(new_node != NULL) { new_node->setLocalRotation(node_rotation); new_node->setLocalTranslation(node_translation); @@ -1020,7 +1035,7 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p new_node->setPreRotation(node_pre_rotation); new_node->setPostRotation(node_post_rotation); parent_node->addChild(new_node); - + // Load child nodes for(int i = 0; i < pNode->GetChildCount(); i++) { @@ -1055,7 +1070,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { FbxPropertyT lKFbxDouble3; FbxPropertyT lKFbxDouble1; - if (pMaterial->GetClassId().Is(KFbxSurfacePhong::ClassId)) { + if (pMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { // We found a Phong material. // Ambient Color @@ -1063,11 +1078,11 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Specular Color (unique to Phong materials) - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Specular; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular; new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive Color @@ -1080,7 +1095,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Shininess - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->Shininess; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->Shininess; new_material->setShininess(lKFbxDouble1.Get()); /* @@ -1090,27 +1105,27 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->TransparentColor; new_material->setTransparency( 1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); // Reflection factor - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->ReflectionFactor; // Reflection color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Reflection; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection; // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken new_material->setReflection(KRVector3(lKFbxDouble3.Get()[0] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[1] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[2] * lKFbxDouble1.Get())); - } else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) { + } else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) { // We found a Lambert material. // Ambient Color - lKFbxDouble3=((KFbxSurfaceLambert *)pMaterial)->Ambient; + lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient; new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive @@ -1122,7 +1137,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfaceLambert *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfaceLambert *) pMaterial)->TransparentColor; new_material->setTransparency(1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); } else { @@ -1131,31 +1146,31 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { - KFbxProperty pProperty; + FbxProperty pProperty; // Diffuse Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sDiffuse); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + int texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple diffuse textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); assert(!pTexture->GetSwapUV()); assert(pTexture->GetCroppingTop() == 0); assert(pTexture->GetCroppingLeft() == 0); assert(pTexture->GetCroppingRight() == 0); assert(pTexture->GetCroppingBottom() == 0); - assert(pTexture->GetWrapModeU() == KFbxTexture::eRepeat); - assert(pTexture->GetWrapModeV() == KFbxTexture::eRepeat); + assert(pTexture->GetWrapModeU() == FbxTexture::eRepeat); + assert(pTexture->GetWrapModeV() == FbxTexture::eRepeat); assert(pTexture->GetRotationU() == 0.0f); assert(pTexture->GetRotationV() == 0.0f); assert(pTexture->GetRotationW() == 0.0f); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1163,24 +1178,24 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { // Specular Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sSpecular); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sSpecular); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple specular textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } } // Normal Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sNormalMap); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sNormalMap); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } @@ -1189,8 +1204,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { if(texture_count > 1) { printf("Error! Multiple normal map textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = pProperty.GetSrcObject(0); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = pProperty.GetSrcObject(0); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1207,8 +1222,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh) { - KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh) { + FbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); KRMesh::mesh_info mi; mi.format = KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES; @@ -1219,7 +1234,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG } control_point_weight_info_t; int control_point_count = pMesh->GetControlPointsCount(); - KFbxVector4* control_points = pMesh->GetControlPoints(); + FbxVector4* control_points = pMesh->GetControlPoints(); control_point_weight_info_t *control_point_weights = new control_point_weight_info_t[control_point_count]; for(int control_point=0; control_point < control_point_count; control_point++) { @@ -1342,7 +1357,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG bool need_tangents = false; for(int iMaterial=0; iMaterial < material_count; iMaterial++) { - KFbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); + FbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); KRMaterial *material = context.getMaterialManager()->getMaterial(pMaterial->GetName()); if(material) { @@ -1380,7 +1395,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG for(int iVertex=0; iVertex<3; iVertex++) { // ----====---- Read Vertex Position ----====---- int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex); - KFbxVector4 v = control_points[lControlPointIndex]; + FbxVector4 v = control_points[lControlPointIndex]; mi.vertices.push_back(KRVector3(v[0], v[1], v[2])); if(mi.bone_names.size() > 0) { @@ -1401,29 +1416,35 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read UVs ----====---- - KStringList uvNames; + FbxStringList uvNames; pMesh->GetUVSetNames(uvNames); if(uv_count >= 1) { const char *setName = uvNames[0].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { - new_uva = KRVector2(uv[0], uv[1]); + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + if(!unmapped) { + new_uva = KRVector2(uv[0], uv[1]); + } } mi.uva.push_back(new_uva); } if(uv_count >= 2) { const char *setName = uvNames[1].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { - new_uvb = KRVector2(uv[0], uv[1]); + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + if(!unmapped) { + new_uvb = KRVector2(uv[0], uv[1]); + } } mi.uvb.push_back(new_uvb); } // ----====---- Read Normals ----====---- - KFbxVector4 new_normal; + FbxVector4 new_normal; if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) { mi.normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2])); } @@ -1432,7 +1453,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read Tangents ----====---- for(int l = 0; l < tangent_count; ++l) { - KFbxVector4 new_tangent; + FbxVector4 new_tangent; FbxGeometryElementTangent* leTangent = pMesh->GetElementTangent(l); if(leTangent->GetMappingMode() == FbxGeometryElement::eByPolygonVertex) { @@ -1484,10 +1505,10 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG context.getModelManager()->addModel(new_mesh); } -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); - KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute(); + FbxMesh* pSourceMesh = (FbxMesh*) pNode->GetNodeAttribute(); if(KRMesh::GetLODCoverage(pNode->GetName()) == 100) { // If this is the full detail model, add an instance of it to the scene file @@ -1500,9 +1521,23 @@ KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_PHYSICS, 0.0f); } else if(strncmp(node_name, "audio_collider_", strlen("audio_collider_")) == 0) { return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_AUDIO, 1.0f); - } else if(strncmp(node_name, "collider_", strlen("collider_")) == 0) { + } else if(strncmp(node_name, "collider_", 9) == 0) { // 9 == strlen("collider_") + // Colliders can have a prefix of collider_##_, where ## indicates the layer mask + // Colliders with a prefix of only collider_ will have a default layer mask of KRAKEN_COLLIDER_PHYSICS | KRAKEN_COLLIDER_AUDIO - return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), KRAKEN_COLLIDER_PHYSICS | KRAKEN_COLLIDER_AUDIO, 1.0f); + // Scan through the characters of the name until we no longer see digit characters (or see a '\0' indicating the end of the string) + unsigned int layer = 0; + const char *szNodeName = node_name + 9; // 9 == strlen("collider_") + const char *source_char = szNodeName; + while(*source_char >= '0' && *source_char <= '9') { + layer = layer * 10 + (*source_char++ - '0'); + } + + if(layer == 0) { + // No layer mask number was found, use the default + layer = KRAKEN_COLLIDER_PHYSICS | KRAKEN_COLLIDER_AUDIO; + } + return new KRCollider(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), layer, 1.0f); } else { return new KRModel(parent_node->getScene(), GetFbxObjectName(pNode), pSourceMesh->GetNode()->GetName(), light_map, 0.0f, true, false); } @@ -1512,7 +1547,7 @@ KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter } -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); KRBone *new_bone = new KRBone(parent_node->getScene(), name.c_str()); @@ -1526,7 +1561,56 @@ KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) return new_bone; } -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { + std::string name = GetFbxObjectName(pNode); + + KRLocator *new_locator = new KRLocator(parent_node->getScene(), name.c_str()); + + // Enumerate fbx properties so client code can convert locators into application-specific objects + FbxProperty fbx_property = pNode->GetFirstProperty(); + while(fbx_property.IsValid()) { + std::string property_name = fbx_property.GetNameAsCStr(); + std::transform(property_name.begin(), property_name.end(), property_name.begin(), ::tolower); + + boost::variant property_value = ""; + switch(fbx_property.GetPropertyDataType().GetType()) { + case eFbxInt: + new_locator->getUserAttributes()[property_name] = fbx_property.Get(); + break; + case eFbxDouble: + new_locator->getUserAttributes()[property_name] = fbx_property.Get(); + break; + case eFbxBool: + new_locator->getUserAttributes()[property_name] = fbx_property.Get(); + break; + case eFbxFloat: + new_locator->getUserAttributes()[property_name] = fbx_property.Get(); + break; + case eFbxString: + new_locator->getUserAttributes()[property_name] = std::string(fbx_property.Get().Buffer()); + break; + default: + { + fprintf(stderr, "FBX property not imported due to unsupported data type: %s.%s\n", name.c_str(), property_name.c_str()); + } + break; + } + + fbx_property = pNode->GetNextProperty(fbx_property); + } + + + //static bool GetBindPoseContaining(FbxScene* pScene, FbxNode* pNode, PoseList& pPoseList, FbxArray& pIndex); + // PoseList pose_list; + // FbxArray pose_indices; + // if(FbxPose::GetBindPoseContaining(pFbxScene, pNode, pose_list, pose_indices)) { + // fprintf(stderr, "Found bind pose(s)!\n"); + // } + + return new_locator; +} + +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode) { FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute(); const char *szName = pNode->GetName(); @@ -1534,7 +1618,7 @@ KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { return new_camera; } -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) { const GLfloat PI = 3.14159265; const GLfloat d2r = PI * 2 / 360; @@ -1545,7 +1629,7 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { FbxDouble light_intensity = pLight->Intensity.Get(); FbxDouble light_hotspot = pLight->InnerAngle.Get(); // light inner cone angle (in degrees). Also know as the HotSpot FbxDouble light_coneangle = pLight->OuterAngle.Get(); // light outer cone angle (in degrees). Also known as the Falloff - KFbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type + FbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type FbxDouble light_decaystart = pLight->DecayStart.Get(); // decay start distance @@ -1557,20 +1641,20 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { KRLight *new_light = NULL; switch(pLight->LightType.Get()) { - case KFbxLight::ePoint: + case FbxLight::ePoint: { KRPointLight *l = new KRPointLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eDirectional: + case FbxLight::eDirectional: { KRDirectionalLight *l = new KRDirectionalLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eSpot: + case FbxLight::eSpot: { KRSpotLight *l = new KRSpotLight(parent_node->getScene(), szName); l->setInnerAngle(light_hotspot * d2r); @@ -1578,8 +1662,8 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { new_light = l; } break; - case KFbxLight::eVolume: - case KFbxLight::eArea: + case FbxLight::eVolume: + case FbxLight::eArea: // Not supported yet break; } diff --git a/KREngine/kraken/KRReverbZone.cpp b/KREngine/kraken/KRReverbZone.cpp index a9f1ab5..95a4e95 100644 --- a/KREngine/kraken/KRReverbZone.cpp +++ b/KREngine/kraken/KRReverbZone.cpp @@ -96,7 +96,8 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector &point_ KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); - if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass)) { + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/KREngine/kraken/KRScene.cpp b/KREngine/kraken/KRScene.cpp index 2a1f2f5..5e31dce 100644 --- a/KREngine/kraken/KRScene.cpp +++ b/KREngine/kraken/KRScene.cpp @@ -93,6 +93,11 @@ std::set &KRScene::getReverbZones() return m_reverbZoneNodes; } +std::set &KRScene::getLocators() +{ + return m_locatorNodes; +} + void KRScene::render(KRCamera *pCamera, unordered_map &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) { if(new_frame) { // Expire cached occlusion test results. @@ -272,7 +277,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi KRMat4 mvpmatrix = matModel * viewport.getViewProjectionMatrix(); - getContext().getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, KRENGINE_VBO_3D_CUBE_ATTRIBS, true); + getContext().getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_3D_CUBE_ATTRIBS, true); // Enable additive blending if(renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { @@ -290,7 +295,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map &visi GLDEBUG(glDepthMask(GL_FALSE)); } - if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { + if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f)) { GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); m_pContext->getModelManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14); } @@ -404,9 +409,10 @@ bool KRScene::save(KRDataBlock &data) { 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 + std::string xml_string = data->getString(); + delete data; tinyxml2::XMLDocument doc; - doc.Parse((char *)data->getStart()); + doc.Parse(xml_string.c_str()); KRScene *new_scene = new KRScene(context, name); tinyxml2::XMLElement *scene_element = doc.RootElement(); @@ -418,7 +424,7 @@ KRScene *KRScene::Load(KRContext &context, const std::string &name, KRDataBlock new_scene->getRootNode()->addChild(n); } - delete data; + return new_scene; } @@ -459,6 +465,10 @@ void KRScene::notify_sceneGraphDelete(KRNode *pNode) if(ReverbZoneNode) { m_reverbZoneNodes.erase(ReverbZoneNode); } + KRLocator *locator = dynamic_cast(pNode); + if(locator) { + m_locatorNodes.erase(locator); + } m_modifiedNodes.erase(pNode); if(!m_newNodes.erase(pNode)) { m_nodeTree.remove(pNode); @@ -480,20 +490,30 @@ void KRScene::updateOctree(const KRViewport &viewport) if(node->hasPhysics()) { m_physicsNodes.insert(node); } - KRAmbientZone *AmbientZoneNode = dynamic_cast(node); - if(dynamic_cast(node)) { - m_ambientZoneNodes.insert(AmbientZoneNode); + KRAmbientZone *ambientZoneNode = dynamic_cast(node); + if(ambientZoneNode) { + m_ambientZoneNodes.insert(ambientZoneNode); } - KRReverbZone *ReverbZoneNode = dynamic_cast(node); - if(dynamic_cast(node)) { - m_reverbZoneNodes.insert(ReverbZoneNode); + KRReverbZone *reverbZoneNode = dynamic_cast(node); + if(reverbZoneNode) { + m_reverbZoneNodes.insert(reverbZoneNode); } + KRLocator *locatorNode = dynamic_cast(node); + if(locatorNode) { + m_locatorNodes.insert(locatorNode); + } + } for(std::set::iterator itr=modifiedNodes.begin(); itr != modifiedNodes.end(); itr++) { KRNode *node = *itr; if(node->lodIsVisible()) { m_nodeTree.update(node); } + if(node->hasPhysics()) { + m_physicsNodes.insert(node); + } else if(!node->hasPhysics()) { + m_physicsNodes.erase(node); + } } } diff --git a/KREngine/kraken/KRScene.h b/KREngine/kraken/KRScene.h index b8f5cab..9242a03 100644 --- a/KREngine/kraken/KRScene.h +++ b/KREngine/kraken/KRScene.h @@ -40,6 +40,7 @@ #include "KRCamera.h" #include "KRMeshManager.h" #include "KRNode.h" +#include "KRLocator.h" #include "KRAmbientZone.h" #include "KRReverbZone.h" #include "KROctree.h" @@ -84,6 +85,7 @@ public: std::set &getAmbientZones(); std::set &getReverbZones(); + std::set &getLocators(); private: @@ -98,6 +100,7 @@ private: std::set m_physicsNodes; std::set m_ambientZoneNodes; std::set m_reverbZoneNodes; + std::set m_locatorNodes; KROctree m_nodeTree; diff --git a/KREngine/kraken/KRShader.cpp b/KREngine/kraken/KRShader.cpp index 210aae4..bdb2cef 100644 --- a/KREngine/kraken/KRShader.cpp +++ b/KREngine/kraken/KRShader.cpp @@ -101,7 +101,9 @@ const char *KRShader::KRENGINE_UNIFORM_NAMES[] = { "fog_density_premultiplied_squared", // KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_SQUARED "slice_depth_scale", // KRENGINE_UNIFORM_SLICE_DEPTH_SCALE "particle_origin", // KRENGINE_UNIFORM_PARTICLE_ORIGIN - "bone_transforms" // KRENGINE_UNIFORM_BONE_TRANSFORMS + "bone_transforms", // KRENGINE_UNIFORM_BONE_TRANSFORMS + "rim_color", // KRENGINE_UNIFORM_RIM_COLOR + "rim_power" // KRENGINE_UNIFORM_RIM_POWER }; KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource) : KRContextObject(context) @@ -340,7 +342,7 @@ void KRShader::setUniform(int location, const KRMat4 &value) } } -bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass) { +bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power) { if(m_iProgram == 0) { return false; } @@ -505,11 +507,15 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 & ); } + // Rim highlighting parameters + setUniform(KRENGINE_UNIFORM_RIM_COLOR, rim_color); + setUniform(KRENGINE_UNIFORM_RIM_POWER, rim_power); + // Fog parameters setUniform(KRENGINE_UNIFORM_FOG_NEAR, camera.settings.fog_near); setUniform(KRENGINE_UNIFORM_FOG_FAR, camera.settings.fog_far); setUniform(KRENGINE_UNIFORM_FOG_DENSITY, camera.settings.fog_density); - setUniform(KRENGINE_UNIFORM_FOG_COLOR, camera.settings.fog_color); + setUniform(KRENGINE_UNIFORM_FOG_COLOR, camera.settings.fog_color); if(m_uniforms[KRENGINE_UNIFORM_FOG_SCALE] != -1) { setUniform(KRENGINE_UNIFORM_FOG_SCALE, 1.0f / (camera.settings.fog_far - camera.settings.fog_near)); diff --git a/KREngine/kraken/KRShader.h b/KREngine/kraken/KRShader.h index 06e4fe2..f0cdccc 100644 --- a/KREngine/kraken/KRShader.h +++ b/KREngine/kraken/KRShader.h @@ -47,7 +47,7 @@ public: virtual ~KRShader(); const char *getKey() const; - bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass); + bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power); enum { KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0, @@ -114,6 +114,8 @@ public: KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRENGINE_UNIFORM_BONE_TRANSFORMS, + KRENGINE_UNIFORM_RIM_COLOR, + KRENGINE_UNIFORM_RIM_POWER, KRENGINE_NUM_UNIFORMS }; /* diff --git a/KREngine/kraken/KRShaderManager.cpp b/KREngine/kraken/KRShaderManager.cpp index a591ea8..0cbe5d2 100644 --- a/KREngine/kraken/KRShaderManager.cpp +++ b/KREngine/kraken/KRShaderManager.cpp @@ -48,7 +48,7 @@ KRShaderManager::~KRShaderManager() { } -KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass) { +KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor) { int iShadowQuality = 0; // FINDME - HACK - Placeholder code, need to iterate through lights and dynamically build shader @@ -114,6 +114,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p key.second.push_back(pCamera->settings.flash_intensity * 1000.0f); key.second.push_back(pCamera->settings.vignette_radius * 1000.0f); key.second.push_back(pCamera->settings.vignette_falloff * 1000.0f); + key.second.push_back(bRimColor); KRShader *pShader = m_shaders[key]; @@ -180,6 +181,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p stream << "\n#define ENABLE_AMBIENT " << (pCamera->settings.bEnableAmbient ? "1" : "0"); stream << "\n#define ENABLE_DIFFUSE " << (pCamera->settings.bEnableDiffuse ? "1" : "0"); stream << "\n#define ENABLE_SPECULAR " << (pCamera->settings.bEnableSpecular ? "1" : "0"); + stream << "\n#define ENABLE_RIM_COLOR " << (bRimColor ? "1" : "0"); stream << "\n#define FOG_TYPE " << pCamera->settings.fog_type; switch(renderPass) { case KRNode::RENDER_PASS_DEFERRED_GBUFFER: @@ -238,28 +240,28 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p return pShader; } -bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass) +bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power) { - KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass); - return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass); + KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f); + return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power); } -bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass) +bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power) { if(pShader) { - return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass); + return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power); } else { return false; } } void KRShaderManager::loadFragmentShader(const std::string &name, KRDataBlock *data) { - m_fragShaderSource[name] = string((char *)data->getStart(), data->getSize()); + m_fragShaderSource[name] = data->getString(); delete data; } void KRShaderManager::loadVertexShader(const std::string &name, KRDataBlock *data) { - m_vertShaderSource[name] = string((char *)data->getStart(), data->getSize()); + m_vertShaderSource[name] = data->getString(); delete data; } diff --git a/KREngine/kraken/KRShaderManager.h b/KREngine/kraken/KRShaderManager.h index 1de85da..2615ecb 100644 --- a/KREngine/kraken/KRShaderManager.h +++ b/KREngine/kraken/KRShaderManager.h @@ -58,11 +58,11 @@ public: const std::string &getVertShaderSource(const std::string &name); - KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass); + KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); - bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass); + bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power); - bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass); + bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power); long getShaderHandlesUsed(); diff --git a/KREngine/kraken/KRSprite.cpp b/KREngine/kraken/KRSprite.cpp new file mode 100644 index 0000000..3ee9d93 --- /dev/null +++ b/KREngine/kraken/KRSprite.cpp @@ -0,0 +1,140 @@ +// +// KRSprite.cpp +// KREngine +// +// Created by Kearwood Gilbert on 12-04-05. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + + +#include "KREngine-common.h" +#include "KRSprite.h" + +#include "KRNode.h" +#include "KRMat4.h" +#include "KRVector3.h" +#include "KRCamera.h" +#include "KRContext.h" + +#include "KRShaderManager.h" +#include "KRShader.h" +#include "KRStockGeometry.h" +#include "KRDirectionalLight.h" +#include "KRSpotLight.h" +#include "KRPointLight.h" + + +KRSprite::KRSprite(KRScene &scene, std::string name) : KRNode(scene, name) +{ + m_spriteTexture = ""; + m_pSpriteTexture = NULL; + m_spriteSize = 0.0f; + m_spriteAlpha = 1.0f; +} + +KRSprite::~KRSprite() +{ +} + +std::string KRSprite::getElementName() { + return "sprite"; +} + +tinyxml2::XMLElement *KRSprite::saveXML( tinyxml2::XMLNode *parent) +{ + tinyxml2::XMLElement *e = KRNode::saveXML(parent); + e->SetAttribute("sprite_size", m_spriteSize); + e->SetAttribute("sprite_texture", m_spriteTexture.c_str()); + e->SetAttribute("sprite_alpha", m_spriteAlpha); + return e; +} + +void KRSprite::loadXML(tinyxml2::XMLElement *e) { + KRNode::loadXML(e); + + if(e->QueryFloatAttribute("sprite_size", &m_spriteSize) != tinyxml2::XML_SUCCESS) { + m_spriteSize = 0.0f; + } + if(e->QueryFloatAttribute("sprite_alpha", &m_spriteAlpha) != tinyxml2::XML_SUCCESS) { + m_spriteAlpha = 1.0f; + } + + const char *szSpriteTexture = e->Attribute("sprite_texture"); + if(szSpriteTexture) { + m_spriteTexture = szSpriteTexture; + } else { + m_spriteTexture = ""; + } + m_pSpriteTexture = NULL; +} + +void KRSprite::setSpriteTexture(std::string sprite_texture) { + m_spriteTexture = sprite_texture; + m_pSpriteTexture = NULL; +} + +void KRSprite::setSpriteSize(float sprite_size) { + // TODO - Deprecated - This should come from the localScale + m_spriteSize = sprite_size; +} + +void KRSprite::setSpriteAlpha(float alpha) +{ + m_spriteAlpha = alpha; +} + +float KRSprite::getSpriteAlpha() const +{ + return m_spriteAlpha; +} + +KRAABB KRSprite::getBounds() { + return KRAABB(KRVector3(-m_spriteSize), KRVector3(m_spriteSize), getModelMatrix()); +} + + +void KRSprite::render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) { + + KRNode::render(pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass); + + + if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) { + if(m_spriteTexture.size() && m_spriteSize > 0.0f && m_spriteAlpha > 0.0f) { + + + if(!m_pSpriteTexture && m_spriteTexture.size()) { + m_pSpriteTexture = getContext().getTextureManager()->getTexture(m_spriteTexture); + } + + if(m_pSpriteTexture) { + /* + // Enable additive blending + GLDEBUG(glEnable(GL_BLEND)); + GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); + + // Disable z-buffer write + GLDEBUG(glDepthMask(GL_FALSE)); + */ + + // TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes + + // Enable z-buffer test + GLDEBUG(glEnable(GL_DEPTH_TEST)); + GLDEBUG(glDepthFunc(GL_LEQUAL)); + GLDEBUG(glDepthRangef(0.0, 1.0)); + + // Render light sprite on transparency pass + KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); + KRVector3 rim_color; + if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, 0.0f)) { + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha); + pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_spriteSize); + m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture); + m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); + GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); + } + } + } + + } +} diff --git a/KREngine/kraken/KRSprite.h b/KREngine/kraken/KRSprite.h new file mode 100644 index 0000000..e64be0f --- /dev/null +++ b/KREngine/kraken/KRSprite.h @@ -0,0 +1,42 @@ +// +// KRSprite.h +// KREngine +// +// Created by Kearwood Gilbert on 12-04-05. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRSPRITE_H +#define KRSPRITE_H + +#include "KRResource.h" +#include "KRNode.h" +#include "KRTexture.h" + +class KRSprite : public KRNode { +public: + KRSprite(KRScene &scene, std::string name); + + virtual ~KRSprite(); + virtual std::string getElementName(); + virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); + virtual void loadXML(tinyxml2::XMLElement *e); + + void setSpriteTexture(std::string sprite_texture); + void setSpriteSize(float sprite_size); + void setSpriteAlpha(float alpha); + float getSpriteAlpha() const; + + virtual void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); + + virtual KRAABB getBounds(); + +protected: + + std::string m_spriteTexture; + KRTexture *m_pSpriteTexture; + float m_spriteSize; + float m_spriteAlpha; +}; + +#endif diff --git a/KREngine/kraken/KRStockGeometry.h b/KREngine/kraken/KRStockGeometry.h index 4dc7e18..37297c2 100644 --- a/KREngine/kraken/KRStockGeometry.h +++ b/KREngine/kraken/KRStockGeometry.h @@ -10,8 +10,9 @@ #define KRSTOCKGEOMETRY_H #include "KRMesh.h" - -static const GLfloat KRENGINE_VBO_3D_CUBE[] = { +#include "KRDataBlock.h" +/* +static const GLfloat _KRENGINE_VBO_3D_CUBE_VERTEX_DATA[] = { 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0,-1.0, 1.0, @@ -28,32 +29,20 @@ static const GLfloat KRENGINE_VBO_3D_CUBE[] = { -1.0, 1.0,-1.0 }; -static int KRENGINE_VBO_3D_CUBE_SIZE = sizeof(GLfloat) * 3 * 14; +static KRDataBlock KRENGINE_VBO_3D_CUBE_VERTICES, KRENGINE_VBO_3D_CUBE_INDEXES; +KRENGINE_VBO_3D_CUBE_VERTICES.load((void *)_KRENGINE_VBO_3D_CUBE_VERTEX_DATA, sizeof(GLfloat) * 3 * 14); + static const __int32_t KRENGINE_VBO_3D_CUBE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX); -static const GLfloat KRENGINE_VERTICES_2D_SQUARE[] = { - -1.0f, -1.0f, - 1.0f, -1.0f, - -1.0f, 1.0f, - 1.0f, 1.0f, -}; - -static const GLfloat KRENGINE_VERTICES_2D_SQUARE_UV[] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, -}; - -static const GLfloat KRENGINE_VBO_2D_SQUARE[] = { +static const GLfloat _KRENGINE_VBO_2D_SQUARE_VERTEX_DATA[] = { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; -static const int KRENGINE_VBO_2D_SQUARE_SIZE = sizeof(GLfloat) * 5 * 4; +static KRDataBlock KRENGINE_VBO_2D_SQUARE_VERTICES, KRENGINE_VBO_2D_SQUARE_INDEXES; +KRENGINE_VBO_2D_SQUARE_VERTICES.load((void *)_KRENGINE_VBO_2D_SQUARE_VERTEX_DATA, sizeof(GLfloat) * 5 * 4); static const __int32_t KRENGINE_VBO_2D_SQUARE_ATTRIBS = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA); - - +*/ #endif diff --git a/KREngine/kraken/KRTexture.cpp b/KREngine/kraken/KRTexture.cpp index 24aee65..af9f351 100644 --- a/KREngine/kraken/KRTexture.cpp +++ b/KREngine/kraken/KRTexture.cpp @@ -15,26 +15,42 @@ KRTexture::KRTexture(KRContext &context, std::string name) : KRResource(context, name) { m_iHandle = 0; + m_iNewHandle = 0; m_textureMemUsed = 0; + m_newTextureMemUsed = 0; m_last_frame_used = 0; + m_last_frame_bound = 0; + m_handle_lock.clear(); } KRTexture::~KRTexture() { - releaseHandle(); + releaseHandles(); } -void KRTexture::releaseHandle() { +void KRTexture::releaseHandles() { + long mem_size = getMemSize(); + + while(m_handle_lock.test_and_set()); // Spin lock + + if(m_iNewHandle != 0) { + GLDEBUG(glDeleteTextures(1, &m_iNewHandle)); + m_iNewHandle = 0; + m_newTextureMemUsed = 0; + } if(m_iHandle != 0) { GLDEBUG(glDeleteTextures(1, &m_iHandle)); - getContext().getTextureManager()->memoryChanged(-getMemSize()); m_iHandle = 0; m_textureMemUsed = 0; } + + m_handle_lock.clear(); + + getContext().getTextureManager()->memoryChanged(-mem_size); } long KRTexture::getMemSize() { - return m_textureMemUsed; // TODO - This is not 100% accurate, as loaded format may differ in size while in GPU memory + return m_textureMemUsed + m_newTextureMemUsed; // TODO - This is not 100% accurate, as loaded format may differ in size while in GPU memory } long KRTexture::getReferencedMemSize() { @@ -44,42 +60,36 @@ long KRTexture::getReferencedMemSize() { void KRTexture::resize(int max_dim) { - if(max_dim == 0) { - releaseHandle(); - } else { - int target_dim = max_dim; - if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; - int requiredMemoryTransfer = getThroughputRequiredForResize(target_dim); - int requiredMemoryDelta = getMemRequiredForSize(target_dim) - getMemSize() - getReferencedMemSize(); - - if(requiredMemoryDelta) { - // Only resize / regenerate the texture if it actually changes the size of the texture (Assumption: textures of different sizes will always consume different amounts of memory) - - if(getContext().getTextureManager()->getMemoryTransferedThisFrame() + requiredMemoryTransfer > getContext().KRENGINE_MAX_TEXTURE_THROUGHPUT) { - // Exceeding per-frame transfer throughput; can't resize now - return; - } - - if(getContext().getTextureManager()->getMemUsed() + requiredMemoryDelta > getContext().KRENGINE_MAX_TEXTURE_MEM) { - // Exceeding total memory allocated to textures; can't resize now - return; - } - - if(m_current_lod_max_dim != target_dim || m_iHandle == 0) { - if(!createGLTexture(target_dim)) { - assert(false); + if(!m_handle_lock.test_and_set()) + { + if(m_iHandle == m_iNewHandle) { + if(max_dim == 0) { + m_iNewHandle = 0; + } else { + int target_dim = max_dim; + if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; + + if(m_current_lod_max_dim != target_dim || (m_iHandle == 0 && m_iNewHandle == 0)) { + assert(m_newTextureMemUsed == 0); + m_newTextureMemUsed = getMemRequiredForSize(target_dim); + + getContext().getTextureManager()->memoryChanged(m_newTextureMemUsed); + getContext().getTextureManager()->addMemoryTransferredThisFrame(m_newTextureMemUsed); + + if(!createGLTexture(target_dim)) { + getContext().getTextureManager()->memoryChanged(-m_newTextureMemUsed); + m_newTextureMemUsed = 0; + assert(false); + } } } } + + m_handle_lock.clear(); } } - GLuint KRTexture::getHandle() { - if(m_iHandle == 0) { - //resize(getContext().KRENGINE_MIN_TEXTURE_DIM); - resize(m_min_lod_max_dim); - } resetPoolExpiry(); return m_iHandle; } @@ -89,34 +99,6 @@ void KRTexture::resetPoolExpiry() m_last_frame_used = getContext().getCurrentFrame(); } -long KRTexture::getThroughputRequiredForResize(int max_dim) -{ - // Calculate the throughput required for GPU texture upload if the texture is resized to max_dim. - // This default behaviour assumes that the texture will need to be deleted and regenerated to change the maximum mip-map level. - // If an OpenGL extension is present that allows a texture to be resized incrementally, then this method should be overridden - - if(max_dim == 0) { - return 0; - } else { - int target_dim = max_dim; - if(target_dim < m_min_lod_max_dim) target_dim = target_dim; - - - if(target_dim != m_current_lod_max_dim) { - int requiredMemory = getMemRequiredForSize(target_dim); - int requiredMemoryDelta = requiredMemory - getMemSize() - getReferencedMemSize(); - - if(requiredMemoryDelta == 0) { - // Only resize / regenerate the texture if it actually changes the size of the texture (Assumption: textures of different sizes will always consume different amounts of memory) - return 0; - } - return requiredMemory; - } else { - return 0; - } - } -} - long KRTexture::getLastFrameUsed() { return m_last_frame_used; @@ -147,3 +129,28 @@ int KRTexture::getMinMipMap() { bool KRTexture::hasMipmaps() { return m_max_lod_max_dim != m_min_lod_max_dim; } + +void KRTexture::bind(GLuint texture_unit) { + m_last_frame_bound = getContext().getCurrentFrame(); +} + +bool KRTexture::canStreamOut() const { + return (m_last_frame_bound + 2 > getContext().getCurrentFrame()); +} + +void KRTexture::_swapHandles() +{ + if(!m_handle_lock.test_and_set()) { + if(m_iHandle != m_iNewHandle) { + if(m_iHandle != 0) { + GLDEBUG(glDeleteTextures(1, &m_iHandle)); + getContext().getTextureManager()->memoryChanged(-m_textureMemUsed); + } + m_textureMemUsed = (long)m_newTextureMemUsed; + m_newTextureMemUsed = 0; + m_iHandle = m_iNewHandle; + } + m_handle_lock.clear(); + } +} + diff --git a/KREngine/kraken/KRTexture.h b/KREngine/kraken/KRTexture.h index 1a38e4f..592ac14 100644 --- a/KREngine/kraken/KRTexture.h +++ b/KREngine/kraken/KRTexture.h @@ -46,13 +46,12 @@ public: KRTexture(KRContext &context, std::string name); virtual ~KRTexture(); - virtual void bind(GLuint texture_unit) = 0; - void releaseHandle(); + virtual void bind(GLuint texture_unit); + void releaseHandles(); long getMemSize(); virtual long getReferencedMemSize(); virtual long getMemRequiredForSize(int max_dim) = 0; - virtual long getThroughputRequiredForResize(int max_dim); virtual void resize(int max_dim); long getLastFrameUsed(); @@ -66,13 +65,17 @@ public: int getMinMipMap(); bool hasMipmaps(); + bool canStreamOut() const; + + void _swapHandles(); protected: virtual bool createGLTexture(int lod_max_dim) = 0; GLuint getHandle(); - GLuint m_iHandle; - long m_textureMemUsed; + GLuint m_iHandle; + GLuint m_iNewHandle; + std::atomic_flag m_handle_lock; int m_current_lod_max_dim; @@ -80,6 +83,11 @@ protected: uint32_t m_min_lod_max_dim; long m_last_frame_used; + long m_last_frame_bound; + +private: + std::atomic m_textureMemUsed; + std::atomic m_newTextureMemUsed; }; diff --git a/KREngine/kraken/KRTexture2D.cpp b/KREngine/kraken/KRTexture2D.cpp index da79d62..11918d9 100644 --- a/KREngine/kraken/KRTexture2D.cpp +++ b/KREngine/kraken/KRTexture2D.cpp @@ -43,54 +43,47 @@ KRTexture2D::~KRTexture2D() { } bool KRTexture2D::createGLTexture(int lod_max_dim) { + if(m_iHandle != m_iNewHandle) { + return true; + } + bool success = true; - GLuint prev_handle = 0; int prev_lod_max_dim = 0; - long prev_mem_size = 0; #if GL_APPLE_copy_texture_levels && GL_EXT_texture_storage if(m_iHandle != 0) { - prev_handle = m_iHandle; - prev_mem_size = getMemSize(); - m_iHandle = 0; - m_textureMemUsed = 0; prev_lod_max_dim = m_current_lod_max_dim; } -#else - releaseHandle(); #endif + m_iNewHandle = 0; m_current_lod_max_dim = 0; - GLDEBUG(glGenTextures(1, &m_iHandle)); + GLDEBUG(glGenTextures(1, &m_iNewHandle)); - if(m_iHandle == 0) { + if(m_iNewHandle == 0) { success = false; } else { - GLDEBUG(glBindTexture(GL_TEXTURE_2D, m_iHandle)); + GLDEBUG(glBindTexture(GL_TEXTURE_2D, m_iNewHandle)); if (hasMipmaps()) { GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); } else { GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); } - if(!uploadTexture(GL_TEXTURE_2D, lod_max_dim, m_current_lod_max_dim, m_textureMemUsed, prev_lod_max_dim, prev_handle)) { - GLDEBUG(glDeleteTextures(1, &m_iHandle)); - m_iHandle = 0; - m_current_lod_max_dim = 0; + if(!uploadTexture(GL_TEXTURE_2D, lod_max_dim, m_current_lod_max_dim, prev_lod_max_dim)) { + GLDEBUG(glDeleteTextures(1, &m_iNewHandle)); + m_iNewHandle = m_iHandle; + m_current_lod_max_dim = prev_lod_max_dim; success = false; } } - if(prev_handle != 0) { - getContext().getTextureManager()->memoryChanged(-prev_mem_size); - GLDEBUG(glDeleteTextures(1, &prev_handle)); - } - return success; } void KRTexture2D::bind(GLuint texture_unit) { + KRTexture::bind(texture_unit); GLuint handle = getHandle(); GLDEBUG(glBindTexture(GL_TEXTURE_2D, handle)); @@ -101,7 +94,6 @@ void KRTexture2D::bind(GLuint texture_unit) { } } - bool KRTexture2D::save(const std::string& path) { if(m_pData) { diff --git a/KREngine/kraken/KRTexture2D.h b/KREngine/kraken/KRTexture2D.h index f3e8684..139e5d5 100644 --- a/KREngine/kraken/KRTexture2D.h +++ b/KREngine/kraken/KRTexture2D.h @@ -46,7 +46,7 @@ public: virtual bool save(const std::string& path); virtual bool save(KRDataBlock &data); - virtual bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed, int prev_lod_max_dim, GLuint prev_handle) = 0; + virtual bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim) = 0; virtual void bind(GLuint texture_unit); protected: diff --git a/KREngine/kraken/KRTextureAnimated.cpp b/KREngine/kraken/KRTextureAnimated.cpp index c3b5669..c25028a 100644 --- a/KREngine/kraken/KRTextureAnimated.cpp +++ b/KREngine/kraken/KRTextureAnimated.cpp @@ -47,7 +47,7 @@ KRTextureAnimated::KRTextureAnimated(KRContext &context, std::string name) : KRT int second_comma_pos = name.find(",", first_comma_pos + 1); - m_texture_base_name = name.substr(8, first_comma_pos - 9); + m_texture_base_name = name.substr(8, first_comma_pos - 8); m_frame_count = atoi(name.substr(first_comma_pos+1, second_comma_pos - first_comma_pos -1).c_str()); m_frame_rate = atof(name.substr(second_comma_pos+1).c_str()); @@ -87,17 +87,7 @@ bool KRTextureAnimated::createGLTexture(int lod_max_dim) long KRTextureAnimated::getMemRequiredForSize(int max_dim) { - int target_dim = max_dim; - if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; - - long memoryRequired = 0; - for(int i=0; igetMemRequiredForSize(target_dim); - } - } - return memoryRequired; + return 0; // Memory is allocated by individual frame textures } @@ -108,12 +98,15 @@ void KRTextureAnimated::resetPoolExpiry() KRTexture2D *frame_texture = textureForFrame(i); if(frame_texture) { frame_texture->resetPoolExpiry(); // Ensure that frames of animated textures do not expire from the texture pool prematurely, as they are referenced indirectly + getContext().getTextureManager()->primeTexture(frame_texture); } } } void KRTextureAnimated::bind(GLuint texture_unit) { + resetPoolExpiry(); + KRTexture::bind(texture_unit); int frame_number = (int)floor(fmodf(getContext().getAbsoluteTime() * m_frame_rate,m_frame_count)); KRTexture2D *frame_texture = textureForFrame(frame_number); if(frame_texture) { @@ -153,3 +146,7 @@ bool KRTextureAnimated::save(KRDataBlock &data) return true; // Animated textures are just references; there are no files to output } +void KRTextureAnimated::resize(int max_dim) +{ + // Purposely not calling the superclass method +} \ No newline at end of file diff --git a/KREngine/kraken/KRTextureAnimated.h b/KREngine/kraken/KRTextureAnimated.h index 8e458b9..9e685b6 100644 --- a/KREngine/kraken/KRTextureAnimated.h +++ b/KREngine/kraken/KRTextureAnimated.h @@ -50,6 +50,7 @@ public: virtual long getReferencedMemSize(); virtual bool isAnimated(); + virtual void resize(int max_dim); private: virtual bool createGLTexture(int lod_max_dim); diff --git a/KREngine/kraken/KRTextureCube.cpp b/KREngine/kraken/KRTextureCube.cpp index a9e532d..dcf8e0f 100644 --- a/KREngine/kraken/KRTextureCube.cpp +++ b/KREngine/kraken/KRTextureCube.cpp @@ -55,57 +55,45 @@ KRTextureCube::~KRTextureCube() bool KRTextureCube::createGLTexture(int lod_max_dim) { + assert(m_iNewHandle == m_iHandle); // Only allow one resize per frame + bool success = true; - GLuint prev_handle = 0; int prev_lod_max_dim = 0; - long prev_mem_size = 0; #if GL_APPLE_copy_texture_levels && GL_EXT_texture_storage if(m_iHandle != 0) { - prev_handle = m_iHandle; - prev_mem_size = getMemSize(); - m_iHandle = 0; - m_textureMemUsed = 0; prev_lod_max_dim = m_current_lod_max_dim; } -#else - releaseHandle(); #endif + m_iNewHandle = 0; + GLDEBUG(glGenTextures(1, &m_iNewHandle)); + assert(m_iNewHandle != 0); + m_current_lod_max_dim = 0; - GLDEBUG(glGenTextures(1, &m_iHandle)); - if(m_iHandle == 0) { - success = false; - } else { - - GLDEBUG(glBindTexture(GL_TEXTURE_CUBE_MAP, m_iHandle)); - - bool bMipMaps = false; + GLDEBUG(glBindTexture(GL_TEXTURE_CUBE_MAP, m_iNewHandle)); + + bool bMipMaps = false; - for(int i=0; i<6; i++) { - std::string faceName = getName() + SUFFIXES[i]; - KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); - if(faceTexture) { - if(faceTexture->hasMipmaps()) bMipMaps = true; - faceTexture->uploadTexture(TARGETS[i], lod_max_dim, m_current_lod_max_dim, m_textureMemUsed, prev_lod_max_dim, prev_handle); - } - } - - if(bMipMaps) { - GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); - } else { - // GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); - GLDEBUG(glGenerateMipmap(GL_TEXTURE_CUBE_MAP)); + for(int i=0; i<6; i++) { + std::string faceName = getName() + SUFFIXES[i]; + KRTexture2D *faceTexture = (KRTexture2D *)getContext().getTextureManager()->getTexture(faceName); + if(faceTexture) { + if(faceTexture->hasMipmaps()) bMipMaps = true; + faceTexture->uploadTexture(TARGETS[i], lod_max_dim, m_current_lod_max_dim, prev_lod_max_dim); } } - if(prev_handle != 0) { - getContext().getTextureManager()->memoryChanged(-prev_mem_size); - GLDEBUG(glDeleteTextures(1, &prev_handle)); + if(bMipMaps) { + GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); + } else { + // GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); + GLDEBUG(glGenerateMipmap(GL_TEXTURE_CUBE_MAP)); } + return success; } @@ -141,6 +129,7 @@ void KRTextureCube::resetPoolExpiry() void KRTextureCube::bind(GLuint texture_unit) { + KRTexture::bind(texture_unit); GLuint handle = getHandle(); GLDEBUG(glBindTexture(GL_TEXTURE_CUBE_MAP, handle)); if(handle) { diff --git a/KREngine/kraken/KRTextureManager.cpp b/KREngine/kraken/KRTextureManager.cpp index c81d104..74b718f 100644 --- a/KREngine/kraken/KRTextureManager.cpp +++ b/KREngine/kraken/KRTextureManager.cpp @@ -39,7 +39,7 @@ #include "KRTextureAnimated.h" #include "KRContext.h" -KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) { +KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context), m_streamer(context) { m_textureMemUsed = 0; for(int iTexture=0; iTexturebind(iTextureUnit); } else { @@ -199,6 +197,14 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) { } +void KRTextureManager::primeTexture(KRTexture *pTexture) +{ + m_poolTextures.erase(pTexture); + if(m_activeTextures.find(pTexture) == m_activeTextures.end()) { + m_activeTextures.insert(pTexture); + } +} + long KRTextureManager::getMemUsed() { return m_textureMemUsed; } @@ -215,9 +221,20 @@ long KRTextureManager::getMemActive() { void KRTextureManager::startFrame(float deltaTime) { + m_streamer.startStreamer(); _clearGLState(); + for(std::set::iterator itr=m_activeTextures.begin(); itr != m_activeTextures.end(); itr++) { + KRTexture *activeTexture = *itr; + activeTexture->_swapHandles(); + } + + // TODO - Implement proper double-buffering to reduce copy operations + m_streamerFenceMutex.lock(); + m_activeTextures_streamer_copy = m_activeTextures; + m_poolTextures_streamer_copy = m_poolTextures; + m_streamerFenceMutex.unlock(); + m_memoryTransferredThisFrame = 0; - balanceTextureMemory(); rotateBuffers(); } @@ -230,6 +247,17 @@ void KRTextureManager::endFrame(float deltaTime) } } +void KRTextureManager::doStreaming() +{ + // TODO - Implement proper double-buffering to reduce copy operations + m_streamerFenceMutex.lock(); + m_activeTextures_streamer = m_activeTextures_streamer_copy; + m_poolTextures_streamer = m_poolTextures_streamer_copy; + m_streamerFenceMutex.unlock(); + + balanceTextureMemory(); +} + void KRTextureManager::balanceTextureMemory() { // Balance texture memory by reducing and increasing the maximum mip-map level of both active and inactive textures @@ -237,14 +265,14 @@ void KRTextureManager::balanceTextureMemory() // Determine the additional amount of memory required in order to resize all active textures to the maximum size long wantedTextureMem = 0; - for(std::set::iterator itr=m_activeTextures.begin(); itr != m_activeTextures.end(); itr++) { + for(std::set::iterator itr=m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end(); itr++) { KRTexture *activeTexture = *itr; wantedTextureMem = activeTexture->getMemRequiredForSize(getContext().KRENGINE_MAX_TEXTURE_DIM) - activeTexture->getMemSize(); } // Determine how much memory we need to free up - long memoryDeficit = wantedTextureMem - (getContext().KRENGINE_MAX_TEXTURE_MEM - getMemUsed()); + long memoryDeficit = wantedTextureMem - (getContext().KRENGINE_TARGET_TEXTURE_MEM_MAX - getMemUsed()); // Determine how many mip map levels we need to strip off of inactive textures to free the memory we need @@ -254,7 +282,7 @@ void KRTextureManager::balanceTextureMemory() maxDimInactive = maxDimInactive >> 1; potentialMemorySaving = 0; - for(std::set::iterator itr=m_poolTextures.begin(); itr != m_poolTextures.end(); itr++) { + for(std::set::iterator itr=m_poolTextures_streamer.begin(); itr != m_poolTextures_streamer.end(); itr++) { KRTexture *poolTexture = *itr; long potentialMemoryDelta = poolTexture->getMemRequiredForSize(maxDimInactive) - poolTexture->getMemSize(); if(potentialMemoryDelta < 0) { @@ -265,12 +293,19 @@ void KRTextureManager::balanceTextureMemory() // Strip off mipmap levels of inactive textures to free up memory long inactive_texture_mem_used_target = 0; - for(std::set::iterator itr=m_poolTextures.begin(); itr != m_poolTextures.end(); itr++) { + for(std::set::iterator itr=m_poolTextures_streamer.begin(); itr != m_poolTextures_streamer.end(); itr++) { KRTexture *poolTexture = *itr; - long potentialMemoryDelta = poolTexture->getMemRequiredForSize(maxDimInactive) - poolTexture->getMemSize(); + long mem_required = poolTexture->getMemRequiredForSize(maxDimInactive); + long potentialMemoryDelta = mem_required - poolTexture->getMemSize(); if(potentialMemoryDelta < 0) { - poolTexture->resize(maxDimInactive); - inactive_texture_mem_used_target += poolTexture->getMemRequiredForSize(maxDimInactive); + if(mem_required * 2 + getMemUsed() < KRContext::KRENGINE_MAX_TEXTURE_MEM) { + long mem_free; + m_pContext->getMemoryStats(mem_free); + if(mem_required * 2 < mem_free - 10000000) { + poolTexture->resize(maxDimInactive); + } + } + inactive_texture_mem_used_target += mem_required; } else { inactive_texture_mem_used_target += poolTexture->getMemSize(); } @@ -280,8 +315,8 @@ void KRTextureManager::balanceTextureMemory() long memory_available = 0; long maxDimActive = getContext().KRENGINE_MAX_TEXTURE_DIM; while(memory_available <= 0 && maxDimActive >= getContext().KRENGINE_MIN_TEXTURE_DIM) { - memory_available = getContext().KRENGINE_MAX_TEXTURE_MEM - inactive_texture_mem_used_target; - for(std::set::iterator itr=m_activeTextures.begin(); itr != m_activeTextures.end() && memory_available > 0; itr++) { + memory_available = getContext().KRENGINE_TARGET_TEXTURE_MEM_MAX - inactive_texture_mem_used_target; + for(std::set::iterator itr=m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end() && memory_available > 0; itr++) { KRTexture *activeTexture = *itr; memory_available -= activeTexture->getMemRequiredForSize(maxDimActive); } @@ -292,9 +327,16 @@ void KRTextureManager::balanceTextureMemory() } // Resize active textures to balance the memory usage and mipmap levels - for(std::set::iterator itr=m_activeTextures.begin(); itr != m_activeTextures.end() && memory_available > 0; itr++) { + for(std::set::iterator itr=m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end() && memory_available > 0; itr++) { KRTexture *activeTexture = *itr; - activeTexture->resize(maxDimActive); + long mem_required = activeTexture->getMemRequiredForSize(maxDimActive); + if(mem_required * 2 + getMemUsed() < KRContext::KRENGINE_MAX_TEXTURE_MEM) { + long mem_free; + m_pContext->getMemoryStats(mem_free); + if(mem_required * 2 < mem_free - 10000000) { + activeTexture->resize(maxDimActive); + } + } } //fprintf(stderr, "Active mipmap size: %i Inactive mapmap size: %i\n", (int)maxDimActive, (int)maxDimInactive); @@ -310,7 +352,7 @@ void KRTextureManager::rotateBuffers() KRTexture *poolTexture = *itr; if(poolTexture->getLastFrameUsed() + KRENGINE_TEXTURE_EXPIRY_FRAMES < getContext().getCurrentFrame()) { expiredTextures.insert(poolTexture); - poolTexture->releaseHandle(); + poolTexture->releaseHandles(); } } for(std::set::iterator itr=expiredTextures.begin(); itr != expiredTextures.end(); itr++) { @@ -318,6 +360,7 @@ void KRTextureManager::rotateBuffers() } // ----====---- Swap the buffers ----====---- + m_poolTextures.insert(m_activeTextures.begin(), m_activeTextures.end()); m_activeTextures.clear(); } @@ -335,6 +378,7 @@ void KRTextureManager::addMemoryTransferredThisFrame(long memoryTransferred) void KRTextureManager::memoryChanged(long memoryDelta) { m_textureMemUsed += memoryDelta; + //fprintf(stderr, "Texture Memory: %ld / %i\n", (long)m_textureMemUsed, KRContext::KRENGINE_MAX_TEXTURE_MEM); } unordered_map &KRTextureManager::getTextures() diff --git a/KREngine/kraken/KRTextureManager.h b/KREngine/kraken/KRTextureManager.h index 7c71129..cdf8b99 100644 --- a/KREngine/kraken/KRTextureManager.h +++ b/KREngine/kraken/KRTextureManager.h @@ -39,12 +39,14 @@ #include "KREngine-common.h" #include "KRDataBlock.h" #include "KRContext.h" +#include "KRTextureStreamer.h" class KRTextureManager : public KRContextObject { public: KRTextureManager(KRContext &context); virtual ~KRTextureManager(); + void primeTexture(KRTexture *pTexture); void selectTexture(int iTextureUnit, KRTexture *pTexture); KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data); @@ -77,6 +79,8 @@ public: void _clearGLState(); void setMaxAnisotropy(float max_anisotropy); + void doStreaming(); + private: int m_iActiveTexture; @@ -88,13 +92,24 @@ private: GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS]; GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS]; float m_maxAnisotropy[KRENGINE_MAX_TEXTURE_UNITS]; + + std::set m_activeTextures; std::set m_poolTextures; - long m_textureMemUsed; + std::set m_activeTextures_streamer; + std::set m_poolTextures_streamer; + std::set m_activeTextures_streamer_copy; + std::set m_poolTextures_streamer_copy; + + std::atomic m_textureMemUsed; void rotateBuffers(); void balanceTextureMemory(); + + KRTextureStreamer m_streamer; + + std::mutex m_streamerFenceMutex; }; #endif diff --git a/KREngine/kraken/KRTexturePVR.cpp b/KREngine/kraken/KRTexturePVR.cpp index 97addbf..6ce9a65 100644 --- a/KREngine/kraken/KRTexturePVR.cpp +++ b/KREngine/kraken/KRTexturePVR.cpp @@ -64,8 +64,11 @@ typedef struct _PVRTexHeader KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data, std::string name) : KRTexture2D(context, data, name) { #if TARGET_OS_IPHONE - PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart(); - uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK; + + PVRTexHeader header; + m_pData->copy(&header, 0, sizeof(PVRTexHeader)); + + 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) { @@ -74,7 +77,7 @@ KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data, std::string na assert(false); } - uint32_t pvrTag = header->pvrTag; + uint32_t pvrTag = header.pvrTag; if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) || gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) || gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) || @@ -82,12 +85,12 @@ KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data, std::string na assert(false); } - m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness - m_iHeight = header->height; - m_bHasAlpha = header->bitmaskAlpha; + 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 dataStart = 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; @@ -114,11 +117,7 @@ KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data, std::string na } dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); - dataBlockStruct newBlock; - newBlock.start = bytes+dataOffset; - newBlock.length = dataSize; - - m_blocks.push_back(newBlock); + m_blocks.push_back(m_pData->getSubBlock(dataStart + dataOffset, dataSize)); dataOffset += dataSize; @@ -134,12 +133,15 @@ KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data, std::string na m_max_lod_max_dim = m_iWidth > m_iHeight ? m_iWidth : m_iHeight; m_min_lod_max_dim = width > height ? width : height; - #endif } KRTexturePVR::~KRTexturePVR() { - + for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { + KRDataBlock *block = *itr; + delete block; + } + m_blocks.clear(); } long KRTexturePVR::getMemRequiredForSize(int max_dim) @@ -152,10 +154,10 @@ long KRTexturePVR::getMemRequiredForSize(int max_dim) int height = m_iHeight; long memoryRequired = 0; - for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { - dataBlockStruct block = *itr; + for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { + KRDataBlock *block = *itr; if(width <= target_dim && height <= target_dim) { - memoryRequired += block.length; + memoryRequired += block->getSize(); } width = width >> 1; @@ -171,13 +173,11 @@ long KRTexturePVR::getMemRequiredForSize(int max_dim) return memoryRequired; } -bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed, int prev_lod_max_dim, GLuint prev_handle) +bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim) { int target_dim = lod_max_dim; if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim; - GLenum err; - if(m_blocks.size() == 0) { return false; } @@ -196,7 +196,7 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo int level_count=0; int max_lod_width=0; int max_lod_height=0; - for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { + for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { if(width <= target_dim && height <= target_dim) { if(max_lod_width == 0) { max_lod_width = width; @@ -229,8 +229,8 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo // Upload texture data int destination_level=0; int source_level = 0; - for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { - dataBlockStruct block = *itr; + for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { + KRDataBlock *block = *itr; if(width <= target_dim && height <= target_dim) { if(width > current_lod_max_dim) { @@ -243,22 +243,25 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo if(target == GL_TEXTURE_2D && width <= prev_lod_max_dim && height <= prev_lod_max_dim) { //GLDEBUG(glCompressedTexImage2D(target, i, m_internalFormat, width, height, 0, block.length, NULL)); // Allocate, but don't copy // GLDEBUG(glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL)); - GLDEBUG(glCopyTextureLevelsAPPLE(m_iHandle, prev_handle, source_level, 1)); + GLDEBUG(glCopyTextureLevelsAPPLE(m_iNewHandle, m_iHandle, source_level, 1)); } else { - // glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); - GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, block.length, block.start)); -// GLDEBUG(glCompressedTexImage2D(target, destination_level, m_internalFormat, width, height, 0, block.length, block.start)); - memoryTransferred += block.length; // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE + block->lock(); + GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, (GLsizei)block->getSize(), block->getStart())); + block->unlock(); + + memoryTransferred += block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE } #else + block->lock(); #if GL_EXT_texture_storage - GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, block.length, block.start)); + GLDEBUG(glCompressedTexSubImage2D(target, destination_level, 0, 0, width, height, m_internalFormat, block->getSize(), block->getStart())); #else - GLDEBUG(glCompressedTexImage2D(target, destination_level, m_internalFormat, width, height, 0, block.length, block.start)); + GLDEBUG(glCompressedTexImage2D(target, destination_level, m_internalFormat, width, height, 0, block->getSize(), block->getStart())); #endif - memoryTransferred += block.length; // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE + block->unlock(); + memoryTransferred += block->getSize(); // memoryTransferred does not include throughput of mipmap levels copied through glCopyTextureLevelsAPPLE #endif - memoryRequired += block.length; + memoryRequired += block->getSize(); // // err = glGetError(); // if (err != GL_NO_ERROR) { @@ -284,10 +287,6 @@ bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo } } - textureMemUsed += memoryRequired; - getContext().getTextureManager()->memoryChanged(memoryTransferred); - getContext().getTextureManager()->addMemoryTransferredThisFrame(memoryTransferred); - return true; } diff --git a/KREngine/kraken/KRTexturePVR.h b/KREngine/kraken/KRTexturePVR.h index db7f9c7..974619e 100644 --- a/KREngine/kraken/KRTexturePVR.h +++ b/KREngine/kraken/KRTexturePVR.h @@ -18,7 +18,7 @@ public: virtual ~KRTexturePVR(); virtual std::string getExtension(); - bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed, int prev_lod_max_dim, GLuint prev_handle); + bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim); virtual long getMemRequiredForSize(int max_dim); @@ -29,12 +29,7 @@ protected: GLenum m_internalFormat; bool m_bHasAlpha; - struct dataBlockStruct { - void *start; - uint32_t length; - }; - - std::list m_blocks; + std::list m_blocks; }; #endif diff --git a/KREngine/kraken/KRTextureStreamer.h b/KREngine/kraken/KRTextureStreamer.h new file mode 100644 index 0000000..39f3705 --- /dev/null +++ b/KREngine/kraken/KRTextureStreamer.h @@ -0,0 +1,60 @@ +// +// KRTextureManager.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 KRTEXTURESTREAMER_H +#define KRTEXTURESTREAMER_H + +#include "KREngine-common.h" + +#include +#include + +class KRContext; + +class KRTextureStreamer +{ +public: + KRTextureStreamer(KRContext &context); + ~KRTextureStreamer(); + + void startStreamer(); + +private: + KRContext &m_context; + + std::thread m_thread; + std::atomic m_stop; + std::atomic m_running; + + void run(); +}; + +#endif /* defined(KRTEXTURESTREAMER_H) */ diff --git a/KREngine/kraken/KRTextureStreamer.mm b/KREngine/kraken/KRTextureStreamer.mm new file mode 100644 index 0000000..5185c22 --- /dev/null +++ b/KREngine/kraken/KRTextureStreamer.mm @@ -0,0 +1,97 @@ +// +// KRTextureStreamer.cpp +// Kraken +// +// Created by Kearwood Gilbert on 11/1/2013. +// Copyright (c) 2013 Kearwood Software. All rights reserved. +// + +#include "KREngine-common.h" + +#include "KRTextureStreamer.h" +#include "KRContext.h" + +#include + + +#if TARGET_OS_IPHONE + +EAGLContext *gTextureStreamerContext = nil; + +#elif TARGET_OS_MAC + +NSOpenGLContext *gTextureStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif + +KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) +{ + m_running = false; + m_stop = false; +} + +void KRTextureStreamer::startStreamer() +{ + if(!m_running) { + m_running = true; + +#if TARGET_OS_IPHONE + + gTextureStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; + + +#elif TARGET_OS_MAC + + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gTextureStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; + +#else + + #error Unsupported Platform +#endif + + m_thread = std::thread(&KRTextureStreamer::run, this); + } +} + +KRTextureStreamer::~KRTextureStreamer() +{ + if(m_running) { + m_stop = true; + m_thread.join(); + m_running = false; + } + + [gTextureStreamerContext release]; +} + +void KRTextureStreamer::run() +{ + pthread_setname_np("Kraken - Texture Streamer"); + + std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE + [EAGLContext setCurrentContext: gTextureStreamerContext]; +#elif TARGET_OS_MAC + [gTextureStreamerContext makeCurrentContext]; +#else +#error Unsupported Platform +#endif + + while(!m_stop) + { + if(m_context.getStreamingEnabled()) { + m_context.getTextureManager()->doStreaming(); + } + std::this_thread::sleep_for( sleep_duration ); + } +} diff --git a/KREngine/kraken/KRTextureTGA.cpp b/KREngine/kraken/KRTextureTGA.cpp index 5c6bb71..373385b 100644 --- a/KREngine/kraken/KRTextureTGA.cpp +++ b/KREngine/kraken/KRTextureTGA.cpp @@ -28,10 +28,40 @@ typedef struct { KRTextureTGA::KRTextureTGA(KRContext &context, KRDataBlock *data, std::string name) : KRTexture2D(context, data, name) { + data->lock(); TGA_HEADER *pHeader = (TGA_HEADER *)data->getStart(); m_max_lod_max_dim = pHeader->width > pHeader->height ? pHeader->width : pHeader->height; m_min_lod_max_dim = m_max_lod_max_dim; // Mipmaps not yet supported for TGA images + switch(pHeader->imagetype) { + case 2: // rgb + switch(pHeader->bitsperpixel) { + case 24: + { + m_imageSize = pHeader->width * pHeader->height * 4; + } + break; + case 32: + { + m_imageSize = pHeader->width * pHeader->height * 4; + } + break; + + default: + { + assert(false); + } + break; + } + break; + default: + { + assert(false); + break; + } + } + + data->unlock(); } KRTextureTGA::~KRTextureTGA() @@ -39,12 +69,14 @@ KRTextureTGA::~KRTextureTGA() } -bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed, int prev_lod_max_dim, GLuint prev_handle) -{ +bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim) +{ + m_pData->lock(); TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart(); unsigned char *pData = (unsigned char *)pHeader + (long)pHeader->idlength + (long)pHeader->colourmaplength * (long)pHeader->colourmaptype + sizeof(TGA_HEADER); if(pHeader->colourmaptype != 0) { + m_pData->unlock(); return false; // Mapped colors not supported } @@ -73,15 +105,12 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo } //#endif glTexImage2D(target, 0, GL_RGBA, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image); - delete converted_image; + free(converted_image); err = glGetError(); if (err != GL_NO_ERROR) { + m_pData->unlock(); return false; } - int memAllocated = pHeader->width * pHeader->height * 4; - textureMemUsed += memAllocated; - getContext().getTextureManager()->memoryChanged(memAllocated); - getContext().getTextureManager()->addMemoryTransferredThisFrame(memAllocated); current_lod_max_dim = m_max_lod_max_dim; } break; @@ -90,47 +119,29 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo glTexImage2D(target, 0, GL_RGBA, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pData); err = glGetError(); if (err != GL_NO_ERROR) { + m_pData->unlock(); return false; } - int memAllocated = pHeader->width * pHeader->height * 4; - textureMemUsed += memAllocated; - getContext().getTextureManager()->memoryChanged(memAllocated); - getContext().getTextureManager()->addMemoryTransferredThisFrame(memAllocated); current_lod_max_dim = m_max_lod_max_dim; } break; default: + m_pData->unlock(); return false; // 16-bit images not yet supported } break; default: + m_pData->unlock(); return false; // Image type not yet supported } + m_pData->unlock(); return true; } long KRTextureTGA::getMemRequiredForSize(int max_dim) { - TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart(); - switch(pHeader->imagetype) { - case 2: // rgb - switch(pHeader->bitsperpixel) { - case 24: - { - return pHeader->width * pHeader->height * 4; - } - break; - case 32: - { - return pHeader->width * pHeader->height * 4; - } - break; - } - break; - } - - return 0; + return m_imageSize; } std::string KRTextureTGA::getExtension() diff --git a/KREngine/kraken/KRTextureTGA.h b/KREngine/kraken/KRTextureTGA.h index 458ca3a..82826d7 100644 --- a/KREngine/kraken/KRTextureTGA.h +++ b/KREngine/kraken/KRTextureTGA.h @@ -18,9 +18,11 @@ public: virtual ~KRTextureTGA(); virtual std::string getExtension(); - bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed, int prev_lod_max_dim, GLuint prev_handle); + bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim); virtual long getMemRequiredForSize(int max_dim); +private: + long m_imageSize; }; #endif diff --git a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.fsh b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.fsh index 71acfbc..625f602 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.fsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.fsh @@ -27,6 +27,11 @@ #extension GL_EXT_shadow_samplers : require +#if ENABLE_RIM_COLOR == 1 + uniform lowp vec3 rim_color; + uniform mediump float rim_power; +#endif + #if FOG_TYPE > 0 // FOG_TYPE 1 - Linear // FOG_TYPE 2 - Exponential @@ -111,18 +116,27 @@ uniform sampler2D reflectionTexture; #endif + #if ENABLE_RIM_COLOR == 1 + #define NEED_EYEVEC + #endif + #if HAS_REFLECTION_CUBE_MAP == 1 uniform lowp vec3 material_reflection; uniform samplerCube reflectionCubeTexture; #if HAS_NORMAL_MAP == 1 varying highp mat3 tangent_to_world_matrix; - varying mediump vec3 eyeVec; + #define NEED_EYEVEC + uniform highp mat4 model_matrix; #else varying mediump vec3 reflectionVec; #endif #endif + #ifdef NEED_EYEVEC + varying mediump vec3 eyeVec; + #endif + #if SHADOW_QUALITY >= 1 #ifdef GL_EXT_shadow_samplers @@ -394,6 +408,12 @@ void main() #endif + #if ENABLE_RIM_COLOR == 1 + lowp float rim = 1.0 - clamp(dot(normalize(eyeVec), normal), 0.0, 1.0); + + gl_FragColor += vec4(rim_color, 1.0) * pow(rim, rim_power); + #endif + #if BONE_COUNT > 0 gl_FragColor.b = 1.0; #endif diff --git a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh index 6d2b3fe..904a3a4 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/ObjectShader.vsh @@ -138,11 +138,14 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t varying mediump float specularFactor; #endif + #if ENABLE_RIM_COLOR == 1 + #define NEED_EYEVEC + #endif #if HAS_REFLECTION_CUBE_MAP == 1 #if HAS_NORMAL_MAP == 1 + #define NEED_EYEVEC uniform highp mat4 model_inverse_transpose_matrix; - varying mediump vec3 eyeVec; varying highp mat3 tangent_to_world_matrix; #else uniform highp mat4 model_matrix; @@ -150,6 +153,10 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t #endif #endif + #ifdef NEED_EYEVEC + varying mediump vec3 eyeVec; + #endif + #if HAS_DIFFUSE_MAP_SCALE == 1 uniform highp vec2 diffuseTexture_Scale; #endif @@ -246,7 +253,7 @@ void main() #if HAS_REFLECTION_CUBE_MAP == 1 #if HAS_NORMAL_MAP == 1 - eyeVec = normalize(camera_position_model_space - vertex_position_skinned); + #else // Calculate reflection vector as I - 2.0 * dot(N, I) * N mediump vec3 eyeVec = normalize(camera_position_model_space - vertex_position_skinned); @@ -255,6 +262,9 @@ void main() #endif #endif + #ifdef NEED_EYEVEC + eyeVec = normalize(camera_position_model_space - vertex_position_skinned); + #endif #if HAS_LIGHT_MAP == 1 // Pass shadow UV co-ordinates diff --git a/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh b/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh index aa8d43b..7fce713 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh @@ -3,17 +3,17 @@ // 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 @@ -23,7 +23,7 @@ // 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. @@ -31,7 +31,8 @@ varying mediump vec2 texCoord; uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; void main() { - gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0); + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; } \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh b/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh index 785bf5e..fc0c4d4 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh @@ -3,17 +3,17 @@ // 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 @@ -23,7 +23,7 @@ // 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. diff --git a/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh b/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh new file mode 100644 index 0000000..4519d5d --- /dev/null +++ b/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh @@ -0,0 +1,38 @@ +// +// sprite.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. +// + +varying mediump vec2 texCoord; +uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; + +void main() { + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; +} \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh b/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh new file mode 100644 index 0000000..347191e --- /dev/null +++ b/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh @@ -0,0 +1,42 @@ +// +// sprite.vsh +// 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. +// + +attribute mediump vec2 vertex_uv; +uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices +uniform mediump vec4 viewport; +uniform mediump float flare_size; + +varying mediump vec2 texCoord; + +void main() { + texCoord = vertex_uv; + gl_Position = mvp_matrix * vec4(0.0, 0.0, 0.0, 1.0) + vec4(vertex_uv.x * viewport.w / viewport.z * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 0.0) * flare_size; +} diff --git a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh index bf70c98..25972be 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/ObjectShader_osx.fsh @@ -27,6 +27,11 @@ // #extension GL_EXT_shadow_samplers : require +#if ENABLE_RIM_COLOR == 1 +uniform lowp vec3 rim_color; +uniform mediump float rim_power; +#endif + #if FOG_TYPE > 0 // FOG_TYPE 1 - Linear // FOG_TYPE 2 - Exponential diff --git a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh index aa8d43b..7fce713 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh @@ -3,17 +3,17 @@ // 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 @@ -23,7 +23,7 @@ // 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. @@ -31,7 +31,8 @@ varying mediump vec2 texCoord; uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; void main() { - gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0); + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; } \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh index 785bf5e..fc0c4d4 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh @@ -3,17 +3,17 @@ // 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 @@ -23,7 +23,7 @@ // 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. diff --git a/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh new file mode 100644 index 0000000..4519d5d --- /dev/null +++ b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh @@ -0,0 +1,38 @@ +// +// sprite.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. +// + +varying mediump vec2 texCoord; +uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; + +void main() { + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; +} \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh new file mode 100644 index 0000000..347191e --- /dev/null +++ b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh @@ -0,0 +1,42 @@ +// +// sprite.vsh +// 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. +// + +attribute mediump vec2 vertex_uv; +uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices +uniform mediump vec4 viewport; +uniform mediump float flare_size; + +varying mediump vec2 texCoord; + +void main() { + texCoord = vertex_uv; + gl_Position = mvp_matrix * vec4(0.0, 0.0, 0.0, 1.0) + vec4(vertex_uv.x * viewport.w / viewport.z * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 0.0) * flare_size; +}