diff --git a/build/pomdog.xcodeproj/project.pbxproj b/build/pomdog.xcodeproj/project.pbxproj index bc80b36d0..46c29f6dd 100644 --- a/build/pomdog.xcodeproj/project.pbxproj +++ b/build/pomdog.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 0997B2307F87B872762B0A2B /* AudioClipAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F15A5217D38E950360A6A5 /* AudioClipAL.cpp */; }; 0A291D8212398840CBEB9A5D /* FloatingPointVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01B9F8CE68C05D1EF64A4711 /* FloatingPointVector3.cpp */; }; 0AECD9F61617195B0205EFEF /* GameHostCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = D9C3D114115E6C3A619E8CF9 /* GameHostCocoa.mm */; }; - 0B000E134EE1FB9B23D549AA /* PNGTextureReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7855CAE795F3A9F1B3F59EC5 /* PNGTextureReader.cpp */; }; 0B0F472CF35B5E06E17342B1 /* PipelineStateBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A8619258242CAE058476558 /* PipelineStateBuilder.cpp */; }; 0B2A073EC556AE4DF301E6DA /* SamplerStateGL4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DC908E294094E4F0DBC625D1 /* SamplerStateGL4.cpp */; }; 0B4B6C232BC86463B6B58E08 /* PomdogOpenGLView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95A9AA9F5E520A294039FF38 /* PomdogOpenGLView.mm */; }; @@ -59,7 +58,6 @@ 3F941E8F3AB564A6641C4B0E /* StringHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D07BE9AF32EED1D5F74BE69A /* StringHelper.cpp */; }; 4282457DCED6C0F50EC6CE7E /* SamplerStateGL4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DC908E294094E4F0DBC625D1 /* SamplerStateGL4.cpp */; }; 460526B2F0D0E531DBE74416 /* BoundingCircle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B85BC78383398FBF4414326 /* BoundingCircle.cpp */; }; - 46937FE2B1FC98BBA39A1C3D /* PNGTextureReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7855CAE795F3A9F1B3F59EC5 /* PNGTextureReader.cpp */; }; 48657AD97E278FA04C4994B4 /* ConnectionList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2AEB843C0EAE82FED23106B /* ConnectionList.cpp */; }; 4B6482395A34745225470B08 /* ErrorCheckerAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 66802D7806B0E296795BD9D4 /* ErrorCheckerAL.cpp */; }; 4D3F6C1E105B1A1149475635 /* libzlib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 63DEC4E495A2A3E49BFD61E5 /* libzlib.a */; }; @@ -73,7 +71,6 @@ 566D366B6621FECC73232526 /* PathHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5DAB111727E9143A507A0C10 /* PathHelper.cpp */; }; 56943E805DA5A66B2B412B6E /* ConstantBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C7B6B9ADFEE35269D5B261C8 /* ConstantBuffer.cpp */; }; 57F63AE13143A86E9FB8C7B4 /* FileSystemApple.mm in Sources */ = {isa = PBXBuildFile; fileRef = A02355510B5738D6BF9B3877 /* FileSystemApple.mm */; }; - 5A778C274019DF20B4A89035 /* DDSTextureReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F99F8A89DE73BF98171E2441 /* DDSTextureReader.cpp */; }; 5B1D2792F76709A593451042 /* MathHelper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D3FB9357487DBB6F9C5AAC0 /* MathHelper.cpp */; }; 5B2A7872A04E4938E7E62058 /* FloatingPointVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01B9F8CE68C05D1EF64A4711 /* FloatingPointVector3.cpp */; }; 5D45742CD0787C6A52ED8F29 /* AudioClipAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F15A5217D38E950360A6A5 /* AudioClipAL.cpp */; }; @@ -91,7 +88,6 @@ 66DF4B1D8D85D2B963D5A0D5 /* Color.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C4D55AF0FA9C943AFEB7E91 /* Color.cpp */; }; 68C77475A849DB821AEC1312 /* Texture2DGL4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 61C56C956CFAFF61E6576773 /* Texture2DGL4.cpp */; }; 6AC6140DEE87DAE2DC52FFE7 /* KeyboardState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D7D5A98E477FB0CDE2089FBD /* KeyboardState.cpp */; }; - 6AF7B562E9CA059894EB5359 /* MSWaveAudioLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6CF76618636C36F96145C2A9 /* MSWaveAudioLoader.cpp */; }; 6CAD968D14E4A83B87CE38BD /* GraphicsDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0732B0AF8F54DAE712BFE595 /* GraphicsDevice.cpp */; }; 6DED53A00BC530C5F59A2547 /* AudioEngineAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E6B1323537C7C990BE1436C /* AudioEngineAL.cpp */; }; 6FA8A4ED33396758E9052EAD /* GraphicsCommandQueueImmediate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CA6CF7478713A3FBFCCEA57D /* GraphicsCommandQueueImmediate.cpp */; }; @@ -110,7 +106,6 @@ 7A376FB1B427C73FA45B705F /* BufferGL4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C80CF7400944C955DC0F99EA /* BufferGL4.cpp */; }; 7A500C8DE0D6DC20D936D25D /* ErrorCheckerAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 66802D7806B0E296795BD9D4 /* ErrorCheckerAL.cpp */; }; 7BFC36E8777C887934E3F02B /* FloatingPointMatrix4x4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D2A9D82D0E533AAF3A8D57AC /* FloatingPointMatrix4x4.cpp */; }; - 7EA811ADD537C1D53C100DDC /* MSWaveAudioLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6CF76618636C36F96145C2A9 /* MSWaveAudioLoader.cpp */; }; 8187A830E800AA46A814B09C /* GLSLCompiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF6B97894802CD7445E0EC10 /* GLSLCompiler.cpp */; }; 8455FDB1EFE2A4DC02D36A09 /* VertexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F97885F56CF10EA62B2375A /* VertexBuffer.cpp */; }; 845CA542456D4E309BFCFD1B /* MouseCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 80B5948D01FB98ADEA01D578 /* MouseCocoa.cpp */; }; @@ -125,7 +120,6 @@ 94FC0ADEB7D7E0AE9084A692 /* KeyboardCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 678BDC1DC932B3C09FAEFEC2 /* KeyboardCocoa.cpp */; }; 96250C0AF1475E290503FBF7 /* HLSLCompiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F976B8B50141FE39C87B699D /* HLSLCompiler.cpp */; }; 972D8345F3491175B7E8411B /* BoundingSphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AD66A6372EA23853297EBF /* BoundingSphere.cpp */; }; - 97D9BB458E1CCD768983FA5F /* DDSTextureReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F99F8A89DE73BF98171E2441 /* DDSTextureReader.cpp */; }; 99DE12DBE8D4B0D14FDACD5F /* Bootstrap.mm in Sources */ = {isa = PBXBuildFile; fileRef = F0C11BC845983DFAFDEC6756 /* Bootstrap.mm */; }; 9BD2B7E492D96A784F54C910 /* ErrorChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 74C791C392D2DF46A553FC0F /* ErrorChecker.cpp */; }; 9EA7C97EE18F199AE5272E24 /* AssetLoaderContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DC27D48A6B2A63C9F1A650A9 /* AssetLoaderContext.cpp */; }; @@ -290,6 +284,12 @@ D702F1F722FD914000886A78 /* libmbedtls-crypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D702F1E622FD8F2C00886A78 /* libmbedtls-crypto.a */; }; D702F1F822FD914900886A78 /* libmbedtls.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D702F1E022FD8F2800886A78 /* libmbedtls.a */; }; D702F1F922FD914900886A78 /* libmbedtls-crypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D702F1E622FD8F2C00886A78 /* libmbedtls-crypto.a */; }; + D719A53323497EA600C1868B /* WAV.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53123497EA600C1868B /* WAV.cpp */; }; + D719A53423497EA600C1868B /* WAV.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53123497EA600C1868B /* WAV.cpp */; }; + D719A53A23497EB600C1868B /* DDS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53723497EB600C1868B /* DDS.cpp */; }; + D719A53B23497EB600C1868B /* DDS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53723497EB600C1868B /* DDS.cpp */; }; + D719A53C23497EB600C1868B /* PNG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53823497EB600C1868B /* PNG.cpp */; }; + D719A53D23497EB600C1868B /* PNG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D719A53823497EB600C1868B /* PNG.cpp */; }; D7334DC8228AC80200232225 /* PolylineBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D7334DC6228AC80200232225 /* PolylineBatch.cpp */; }; D7334DC9228AC80200232225 /* PolylineBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D7334DC6228AC80200232225 /* PolylineBatch.cpp */; }; D7334DCA228AC80200232225 /* PrimitiveBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D7334DC7228AC80200232225 /* PrimitiveBatch.cpp */; }; @@ -494,7 +494,6 @@ 170661792862A0323C40CDC3 /* SurfaceFormatHelper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SurfaceFormatHelper.cpp; sourceTree = ""; }; 1892782F88759D12052FFC2B /* InputElement.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = InputElement.hpp; sourceTree = ""; }; 1AEA83A100F195FE0816B39C /* PlayerIndex.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = PlayerIndex.hpp; sourceTree = ""; }; - 1BED371B011B6BD6EDF26BB8 /* Texture2DLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Texture2DLoader.hpp; sourceTree = ""; }; 1D9DD11937173B699F763FAA /* AudioClip.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = AudioClip.hpp; sourceTree = ""; }; 1EC5597A41696495C978EDC9 /* MakeFourCC.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = MakeFourCC.hpp; sourceTree = ""; }; 1F2D3469F0692959C9DCC878 /* FloatingPointMatrix3x2.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = FloatingPointMatrix3x2.hpp; sourceTree = ""; }; @@ -529,7 +528,6 @@ 37D0464D1E5DE9AC99F9A5E4 /* GraphicsCommandQueue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsCommandQueue.cpp; sourceTree = ""; }; 38BA5CD8EB4B484A9B64DA14 /* LogChannel.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = LogChannel.hpp; sourceTree = ""; }; 3A437299F451BC61297C9523 /* TextureHelper.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = TextureHelper.hpp; sourceTree = ""; }; - 3C1B099829F46A7B8F103748 /* DDSTextureReader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = DDSTextureReader.hpp; sourceTree = ""; }; 3C99D84B84F43D1176C600FC /* FloatingPointVector2.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FloatingPointVector2.cpp; sourceTree = ""; }; 3CD68D9350D98D440EC18B73 /* Bootstrap.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Bootstrap.hpp; sourceTree = ""; }; 3E06DBEDBF924D9DF2561581 /* ScopedConnection.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = ScopedConnection.hpp; sourceTree = ""; }; @@ -587,7 +585,6 @@ 6A02F7A644AFC4F395058D95 /* EffectVariableType.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = EffectVariableType.hpp; sourceTree = ""; }; 6AAB8065B15E3C906F2BE8A1 /* FloatingPointQuaternion.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FloatingPointQuaternion.cpp; sourceTree = ""; }; 6AB8FF0EE7B469693B84F20E /* RasterizerStateGL4.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RasterizerStateGL4.cpp; sourceTree = ""; }; - 6CF76618636C36F96145C2A9 /* MSWaveAudioLoader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MSWaveAudioLoader.cpp; sourceTree = ""; }; 6D4384BEFB623F2EF79A82ED /* ShaderBytecode.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = ShaderBytecode.hpp; sourceTree = ""; }; 6E17FE9C0283543D400814CE /* EffectReflectionGL4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = EffectReflectionGL4.hpp; sourceTree = ""; }; 6E7F6810795FF035ED3D761A /* Gamepad.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gamepad.hpp; sourceTree = ""; }; @@ -602,7 +599,6 @@ 75AEFC7E8D7B40E0A34D8A4B /* RenderTarget2DGL4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = RenderTarget2DGL4.hpp; sourceTree = ""; }; 75C24C7B061BE820623F0633 /* TypesafeHelperGL4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = TypesafeHelperGL4.hpp; sourceTree = ""; }; 7820046A70F49F98D15B5608 /* SignalBody.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = SignalBody.hpp; sourceTree = ""; }; - 7855CAE795F3A9F1B3F59EC5 /* PNGTextureReader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PNGTextureReader.cpp; sourceTree = ""; }; 78E0F1EFDF25209303CBEA26 /* GamepadThumbSticks.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = GamepadThumbSticks.hpp; sourceTree = ""; }; 7A9BE55BBDA2D47FF3E4D7CF /* FloatingPointVector4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = FloatingPointVector4.hpp; sourceTree = ""; }; 7AD01E19E140ED2A9FE21D6E /* Radian.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Radian.hpp; sourceTree = ""; }; @@ -644,10 +640,7 @@ 94B88FDB085BF0802CB94273 /* FloatingPointVector2.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = FloatingPointVector2.hpp; sourceTree = ""; }; 9524A580BCEF4C5E9F56EB43 /* AudioClipLoader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AudioClipLoader.cpp; sourceTree = ""; }; 95A9AA9F5E520A294039FF38 /* PomdogOpenGLView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PomdogOpenGLView.mm; sourceTree = ""; }; - 977A7E4CC6D97A9AC8F23EF7 /* AudioClipLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = AudioClipLoader.hpp; sourceTree = ""; }; 97BB80D15705D98F76D28396 /* Any.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Any.hpp; sourceTree = ""; }; - 98A81F2185C556564B6A977D /* PNGTextureReader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = PNGTextureReader.hpp; sourceTree = ""; }; - 9935A1508262CB524DADF1CF /* MSWaveAudioLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = MSWaveAudioLoader.hpp; sourceTree = ""; }; 996E32EF3AA885F9BB9412A2 /* GraphicsDeviceGL4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = GraphicsDeviceGL4.hpp; sourceTree = ""; }; 9AB649441250ACD876E6EFA4 /* ConstantBuffer.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = ConstantBuffer.hpp; sourceTree = ""; }; 9C362E5974D2BDFA88D4823E /* libpomdog.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpomdog.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -822,7 +815,6 @@ CB812182FDF6BA677492B4D3 /* RasterizerStateGL4.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = RasterizerStateGL4.hpp; sourceTree = ""; }; CD99DA1957060FD9ABEDE985 /* LogEntry.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = LogEntry.hpp; sourceTree = ""; }; CFB01062DBC62463D243E231 /* NativeBuffer.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = NativeBuffer.hpp; sourceTree = ""; }; - CFB5F934ACE826A22A466032 /* AssetLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = AssetLoader.hpp; sourceTree = ""; }; D07BE9AF32EED1D5F74BE69A /* StringHelper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringHelper.cpp; sourceTree = ""; }; D2A9D82D0E533AAF3A8D57AC /* FloatingPointMatrix4x4.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FloatingPointMatrix4x4.cpp; sourceTree = ""; }; D323D517D4577AC539963B21 /* ShaderPipelineStage.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = ShaderPipelineStage.hpp; sourceTree = ""; }; @@ -866,6 +858,16 @@ D702F06822FD8B1B00886A78 /* SocketHelperPOSIX.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SocketHelperPOSIX.hpp; sourceTree = ""; }; D702F1DB22FD8F2800886A78 /* mbedtls.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = mbedtls.xcodeproj; path = dependencies/mbedtls.xcodeproj; sourceTree = ""; }; D702F1E122FD8F2C00886A78 /* mbedtls-crypto.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "mbedtls-crypto.xcodeproj"; path = "dependencies/mbedtls-crypto.xcodeproj"; sourceTree = ""; }; + D719A52623497E4200C1868B /* PNG.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = PNG.hpp; sourceTree = ""; }; + D719A52723497E4200C1868B /* DDS.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = DDS.hpp; sourceTree = ""; }; + D719A52923497E4200C1868B /* ImageBuffer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ImageBuffer.hpp; sourceTree = ""; }; + D719A52A23497E4F00C1868B /* WAV.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = WAV.hpp; sourceTree = ""; }; + D719A52C23497E5900C1868B /* Texture2DLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Texture2DLoader.hpp; sourceTree = ""; }; + D719A52D23497E5900C1868B /* AudioClipLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = AudioClipLoader.hpp; sourceTree = ""; }; + D719A52E23497E5900C1868B /* AssetLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = AssetLoader.hpp; sourceTree = ""; }; + D719A53123497EA600C1868B /* WAV.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WAV.cpp; sourceTree = ""; }; + D719A53723497EB600C1868B /* DDS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DDS.cpp; sourceTree = ""; }; + D719A53823497EB600C1868B /* PNG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PNG.cpp; sourceTree = ""; }; D7334DC6228AC80200232225 /* PolylineBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolylineBatch.cpp; sourceTree = ""; }; D7334DC7228AC80200232225 /* PrimitiveBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrimitiveBatch.cpp; sourceTree = ""; }; D7334DCC228AC81F00232225 /* SpriteLine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpriteLine.cpp; sourceTree = ""; }; @@ -980,7 +982,6 @@ F90935EA6FC9155800EE40A7 /* SystemEvents.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = SystemEvents.hpp; sourceTree = ""; }; F9577C4F0F2F45BC080E9625 /* EffectReflectionGL4.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EffectReflectionGL4.cpp; sourceTree = ""; }; F976B8B50141FE39C87B699D /* HLSLCompiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HLSLCompiler.cpp; sourceTree = ""; }; - F99F8A89DE73BF98171E2441 /* DDSTextureReader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DDSTextureReader.cpp; sourceTree = ""; }; FA837DAFD014705086479CB4 /* Log.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Log.cpp; sourceTree = ""; }; FAD0748160DFD77FCBD9729C /* GamepadCapabilities.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = GamepadCapabilities.hpp; sourceTree = ""; }; FBB43FBECEC56612A3BDC867 /* Coordinate2D.hpp */ = {isa = PBXFileReference; lastKnownFileType = text; path = Coordinate2D.hpp; sourceTree = ""; }; @@ -1058,6 +1059,8 @@ FF2F2E326C2A608073CE06E4 /* Utility */, 862A27768A8B2F02F49D6548 /* AssetDictionary.cpp */, DC27D48A6B2A63C9F1A650A9 /* AssetLoaderContext.cpp */, + D719A52F23497E8400C1868B /* Audio */, + D719A53023497E9100C1868B /* Image */, 2279CD1BE0F50CD696851DA5 /* AssetManager.cpp */, ); path = Content; @@ -1210,15 +1213,6 @@ path = Audio; sourceTree = ""; }; - 389BDE517B65A596BC888FE8 /* AssetLoaders */ = { - isa = PBXGroup; - children = ( - 977A7E4CC6D97A9AC8F23EF7 /* AudioClipLoader.hpp */, - 1BED371B011B6BD6EDF26BB8 /* Texture2DLoader.hpp */, - ); - path = AssetLoaders; - sourceTree = ""; - }; 3A13052CEB15935EDEC4001E /* detail */ = { isa = PBXGroup; children = ( @@ -1301,9 +1295,7 @@ 4C4968B652E4E2098D58F226 /* detail */ = { isa = PBXGroup; children = ( - 389BDE517B65A596BC888FE8 /* AssetLoaders */, 3E987C97619CC5BE2D001D55 /* AssetDictionary.hpp */, - CFB5F934ACE826A22A466032 /* AssetLoader.hpp */, 44634A8A9CF085678362093D /* AssetLoaderContext.hpp */, ); path = detail; @@ -1330,6 +1322,9 @@ isa = PBXGroup; children = ( 44CC2B4ACCB66AB60745F7E1 /* AssetBuilders */, + D719A52323497DD100C1868B /* AssetLoaders */, + D719A52423497E0100C1868B /* Audio */, + D719A52523497E1600C1868B /* Image */, 76B9D602F2B636F094143F65 /* Utility */, 4C4968B652E4E2098D58F226 /* detail */, E15589E67EB6BFF7D9957346 /* AssetManager.hpp */, @@ -1947,6 +1942,51 @@ name = Products; sourceTree = ""; }; + D719A52323497DD100C1868B /* AssetLoaders */ = { + isa = PBXGroup; + children = ( + D719A52E23497E5900C1868B /* AssetLoader.hpp */, + D719A52D23497E5900C1868B /* AudioClipLoader.hpp */, + D719A52C23497E5900C1868B /* Texture2DLoader.hpp */, + ); + path = AssetLoaders; + sourceTree = ""; + }; + D719A52423497E0100C1868B /* Audio */ = { + isa = PBXGroup; + children = ( + D719A52A23497E4F00C1868B /* WAV.hpp */, + ); + path = Audio; + sourceTree = ""; + }; + D719A52523497E1600C1868B /* Image */ = { + isa = PBXGroup; + children = ( + D719A52723497E4200C1868B /* DDS.hpp */, + D719A52923497E4200C1868B /* ImageBuffer.hpp */, + D719A52623497E4200C1868B /* PNG.hpp */, + ); + path = Image; + sourceTree = ""; + }; + D719A52F23497E8400C1868B /* Audio */ = { + isa = PBXGroup; + children = ( + D719A53123497EA600C1868B /* WAV.cpp */, + ); + path = Audio; + sourceTree = ""; + }; + D719A53023497E9100C1868B /* Image */ = { + isa = PBXGroup; + children = ( + D719A53723497EB600C1868B /* DDS.cpp */, + D719A53823497EB600C1868B /* PNG.cpp */, + ); + path = Image; + sourceTree = ""; + }; D7334E02228AEB6A00232225 /* ImageEffects */ = { isa = PBXGroup; children = ( @@ -2206,19 +2246,6 @@ path = Platform.Cocoa; sourceTree = ""; }; - FF2F2E326C2A608073CE06E4 /* Utility */ = { - isa = PBXGroup; - children = ( - F99F8A89DE73BF98171E2441 /* DDSTextureReader.cpp */, - 3C1B099829F46A7B8F103748 /* DDSTextureReader.hpp */, - 6CF76618636C36F96145C2A9 /* MSWaveAudioLoader.cpp */, - 9935A1508262CB524DADF1CF /* MSWaveAudioLoader.hpp */, - 7855CAE795F3A9F1B3F59EC5 /* PNGTextureReader.cpp */, - 98A81F2185C556564B6A977D /* PNGTextureReader.hpp */, - ); - path = Utility; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -2381,10 +2408,7 @@ 07B330A5B3BE47D6311109E8 /* ShaderBuilder.cpp in Sources */, EE3B49ABE19A8826A0299A21 /* AudioClipLoader.cpp in Sources */, EC2E27BB5CDE6B796CFD767F /* Texture2DLoader.cpp in Sources */, - 5A778C274019DF20B4A89035 /* DDSTextureReader.cpp in Sources */, - 6AF7B562E9CA059894EB5359 /* MSWaveAudioLoader.cpp in Sources */, D7334E23228AEC1300232225 /* RetroCrtEffect.cpp in Sources */, - 0B000E134EE1FB9B23D549AA /* PNGTextureReader.cpp in Sources */, 56943E805DA5A66B2B412B6E /* ConstantBuffer.cpp in Sources */, 30E3441F3697C393B219D621 /* EffectBinaryParameter.cpp in Sources */, B6BD5FE552C47288CCEB50D4 /* EffectReflection.cpp in Sources */, @@ -2431,6 +2455,7 @@ C3A63B50AA37BB77F4224857 /* FloatingPointMatrix2x2.cpp in Sources */, FFDFEBC545EB6A4B2D810F99 /* FloatingPointMatrix3x2.cpp in Sources */, 51184430EB95428FD308DC8F /* FloatingPointMatrix3x3.cpp in Sources */, + D719A53A23497EB600C1868B /* DDS.cpp in Sources */, A997F7021CAEFC4800926392 /* RenderTarget2DMetal.mm in Sources */, D7334E25228AEC1300232225 /* ChromaticAberration.cpp in Sources */, A9854B9E1DC115D400650729 /* BufferHelper.cpp in Sources */, @@ -2439,6 +2464,7 @@ 1A671762A001893355AC4247 /* FloatingPointQuaternion.cpp in Sources */, 722648A22471D9FC50128061 /* FloatingPointVector2.cpp in Sources */, D702F05622FD8AC700886A78 /* TLSStream.cpp in Sources */, + D719A53323497EA600C1868B /* WAV.cpp in Sources */, 5B2A7872A04E4938E7E62058 /* FloatingPointVector3.cpp in Sources */, D702F05222FD8AC700886A78 /* EndPoint.cpp in Sources */, 0497572B05C5E009716C044A /* FloatingPointVector4.cpp in Sources */, @@ -2456,6 +2482,7 @@ D7334E1F228AEC1300232225 /* SepiaToneEffect.cpp in Sources */, A9E4B86A210CD9C1003F87DC /* GamepadMappings.cpp in Sources */, A9A822931DAB7FBE0091497F /* TextureAtlasGenerator.cpp in Sources */, + D719A53C23497EB600C1868B /* PNG.cpp in Sources */, D702F04422FD8AC700886A78 /* HTTPResponse.cpp in Sources */, A9FC99051DC3D87F00C78D63 /* SpriteBatch.cpp in Sources */, D740A54F231010A00077D040 /* ErrorHelper.cpp in Sources */, @@ -2550,10 +2577,7 @@ F8CEA52C304DD8A4BBEAA042 /* ShaderBuilder.cpp in Sources */, DC83323F55585B855108ED51 /* AudioClipLoader.cpp in Sources */, BD62DB67E515FA42A9D8F788 /* Texture2DLoader.cpp in Sources */, - 97D9BB458E1CCD768983FA5F /* DDSTextureReader.cpp in Sources */, - 7EA811ADD537C1D53C100DDC /* MSWaveAudioLoader.cpp in Sources */, D7334E24228AEC1300232225 /* RetroCrtEffect.cpp in Sources */, - 46937FE2B1FC98BBA39A1C3D /* PNGTextureReader.cpp in Sources */, 712667FE9F33A8F7581022FC /* ConstantBuffer.cpp in Sources */, FB449C29F6AE9D0C12E0B224 /* EffectBinaryParameter.cpp in Sources */, 054132B7E4436F540059F098 /* EffectReflection.cpp in Sources */, @@ -2600,6 +2624,7 @@ E971CF40D05A93F09E489D10 /* FloatingPointMatrix2x2.cpp in Sources */, 2A792456A91A1FCD600F40C7 /* FloatingPointMatrix3x2.cpp in Sources */, D8E9871132965BADBA4BE734 /* FloatingPointMatrix3x3.cpp in Sources */, + D719A53B23497EB600C1868B /* DDS.cpp in Sources */, A997F7031CAEFC4900926392 /* RenderTarget2DMetal.mm in Sources */, D7334E26228AEC1300232225 /* ChromaticAberration.cpp in Sources */, A9854B9F1DC115D400650729 /* BufferHelper.cpp in Sources */, @@ -2608,6 +2633,7 @@ 043C1238BFC3C906AEAEEA09 /* FloatingPointQuaternion.cpp in Sources */, D147245447821976039CCCC2 /* FloatingPointVector2.cpp in Sources */, D702F05722FD8AC700886A78 /* TLSStream.cpp in Sources */, + D719A53423497EA600C1868B /* WAV.cpp in Sources */, 0A291D8212398840CBEB9A5D /* FloatingPointVector3.cpp in Sources */, D702F05322FD8AC700886A78 /* EndPoint.cpp in Sources */, F03B5A2733D5B0585DFBBB89 /* FloatingPointVector4.cpp in Sources */, @@ -2625,6 +2651,7 @@ D7334E20228AEC1300232225 /* SepiaToneEffect.cpp in Sources */, A9E4B86B210CD9C1003F87DC /* GamepadMappings.cpp in Sources */, A9A822941DAB7FBE0091497F /* TextureAtlasGenerator.cpp in Sources */, + D719A53D23497EB600C1868B /* PNG.cpp in Sources */, D702F04522FD8AC700886A78 /* HTTPResponse.cpp in Sources */, A9FC99061DC3D87F00C78D63 /* SpriteBatch.cpp in Sources */, D740A550231010A00077D040 /* ErrorHelper.cpp in Sources */, diff --git a/build/pomdog/CMakeLists.txt b/build/pomdog/CMakeLists.txt index a086bcb67..0d8930ccf 100644 --- a/build/pomdog/CMakeLists.txt +++ b/build/pomdog/CMakeLists.txt @@ -16,6 +16,9 @@ source_group(Audio REGULAR_EXPRESSION "(include/Pomdog|sr source_group(Basic REGULAR_EXPRESSION "(include/Pomdog|src)/Basic/*") source_group(Content REGULAR_EXPRESSION "(include/Pomdog|src)/Content/*") source_group(Content\\AssetBuilders REGULAR_EXPRESSION "(include/Pomdog|src)/Content/AssetBuilders/*") +source_group(Content\\AssetLoaders REGULAR_EXPRESSION "(include/Pomdog|src)/Content/AssetLoaders/*") +source_group(Content\\Audio REGULAR_EXPRESSION "(include/Pomdog|src)/Content/Audio/*") +source_group(Content\\Image REGULAR_EXPRESSION "(include/Pomdog|src)/Content/Image/*") source_group(Content\\Utility REGULAR_EXPRESSION "(include/Pomdog|src)/Content/Utility/*") source_group(Graphics REGULAR_EXPRESSION "(include/Pomdog|src)/Graphics/*") source_group(Graphics\\ShaderCompilers REGULAR_EXPRESSION "(include/Pomdog|src)/Graphics/ShaderCompilers/*") @@ -85,13 +88,17 @@ set(POMDOG_SOURCES_CORE ${POMDOG_DIR}/include/Pomdog/Content/AssetBuilders/PipelineStateBuilder.hpp ${POMDOG_DIR}/include/Pomdog/Content/AssetBuilders/ShaderBuilder.hpp ${POMDOG_DIR}/include/Pomdog/Content/Utility/BinaryFileStream.hpp + ${POMDOG_DIR}/include/Pomdog/Content/Audio/WAV.hpp + ${POMDOG_DIR}/include/Pomdog/Content/Image/ImageBuffer.hpp + ${POMDOG_DIR}/include/Pomdog/Content/Image/DDS.hpp + ${POMDOG_DIR}/include/Pomdog/Content/Image/PNG.hpp ${POMDOG_DIR}/include/Pomdog/Content/Utility/BinaryReader.hpp ${POMDOG_DIR}/include/Pomdog/Content/Utility/MakeFourCC.hpp ${POMDOG_DIR}/include/Pomdog/Content/detail/AssetDictionary.hpp ${POMDOG_DIR}/include/Pomdog/Content/detail/AssetLoaderContext.hpp - ${POMDOG_DIR}/include/Pomdog/Content/detail/AssetLoader.hpp - ${POMDOG_DIR}/include/Pomdog/Content/detail/AssetLoaders/AudioClipLoader.hpp - ${POMDOG_DIR}/include/Pomdog/Content/detail/AssetLoaders/Texture2DLoader.hpp + ${POMDOG_DIR}/include/Pomdog/Content/AssetLoaders/AssetLoader.hpp + ${POMDOG_DIR}/include/Pomdog/Content/AssetLoaders/AudioClipLoader.hpp + ${POMDOG_DIR}/include/Pomdog/Content/AssetLoaders/Texture2DLoader.hpp ${POMDOG_DIR}/include/Pomdog/Graphics/Blend.hpp ${POMDOG_DIR}/include/Pomdog/Graphics/BlendDescription.hpp ${POMDOG_DIR}/include/Pomdog/Graphics/BlendOperation.hpp @@ -255,12 +262,9 @@ set(POMDOG_SOURCES_CORE ${POMDOG_DIR}/src/Content/AssetBuilders/ShaderBuilder.cpp ${POMDOG_DIR}/src/Content/AssetLoaders/AudioClipLoader.cpp ${POMDOG_DIR}/src/Content/AssetLoaders/Texture2DLoader.cpp - ${POMDOG_DIR}/src/Content/Utility/DDSTextureReader.cpp - ${POMDOG_DIR}/src/Content/Utility/DDSTextureReader.hpp - ${POMDOG_DIR}/src/Content/Utility/MSWaveAudioLoader.cpp - ${POMDOG_DIR}/src/Content/Utility/MSWaveAudioLoader.hpp - ${POMDOG_DIR}/src/Content/Utility/PNGTextureReader.cpp - ${POMDOG_DIR}/src/Content/Utility/PNGTextureReader.hpp + ${POMDOG_DIR}/src/Content/Audio/WAV.cpp + ${POMDOG_DIR}/src/Content/Image/DDS.cpp + ${POMDOG_DIR}/src/Content/Image/PNG.cpp ${POMDOG_DIR}/src/Graphics/ConstantBuffer.cpp ${POMDOG_DIR}/src/Graphics/EffectBinaryParameter.cpp ${POMDOG_DIR}/src/Graphics/EffectReflection.cpp diff --git a/include/Pomdog/Content/detail/AssetLoader.hpp b/include/Pomdog/Content/AssetLoaders/AssetLoader.hpp similarity index 100% rename from include/Pomdog/Content/detail/AssetLoader.hpp rename to include/Pomdog/Content/AssetLoaders/AssetLoader.hpp diff --git a/include/Pomdog/Content/detail/AssetLoaders/AudioClipLoader.hpp b/include/Pomdog/Content/AssetLoaders/AudioClipLoader.hpp similarity index 55% rename from include/Pomdog/Content/detail/AssetLoaders/AudioClipLoader.hpp rename to include/Pomdog/Content/AssetLoaders/AudioClipLoader.hpp index 7512c7793..e2514a323 100644 --- a/include/Pomdog/Content/detail/AssetLoaders/AudioClipLoader.hpp +++ b/include/Pomdog/Content/AssetLoaders/AudioClipLoader.hpp @@ -3,23 +3,23 @@ #pragma once #include "Pomdog/Basic/Export.hpp" -#include "Pomdog/Content/detail/AssetLoader.hpp" +#include "Pomdog/Content/AssetLoaders/AssetLoader.hpp" +#include "Pomdog/Utility/Errors.hpp" #include #include +#include namespace Pomdog { +class AssetManager; class AudioClip; } // namespace Pomdog namespace Pomdog::Detail { -class AssetLoaderContext; - template <> struct POMDOG_EXPORT AssetLoader final { - std::shared_ptr operator()( - const AssetLoaderContext& loaderContext, - const std::string& assetName); + [[nodiscard]] std::tuple, std::shared_ptr> + operator()(AssetManager& assets, const std::string& filePath); }; } // namespace Pomdog::Detail diff --git a/include/Pomdog/Content/detail/AssetLoaders/Texture2DLoader.hpp b/include/Pomdog/Content/AssetLoaders/Texture2DLoader.hpp similarity index 55% rename from include/Pomdog/Content/detail/AssetLoaders/Texture2DLoader.hpp rename to include/Pomdog/Content/AssetLoaders/Texture2DLoader.hpp index a6fc308aa..288ce0058 100644 --- a/include/Pomdog/Content/detail/AssetLoaders/Texture2DLoader.hpp +++ b/include/Pomdog/Content/AssetLoaders/Texture2DLoader.hpp @@ -3,23 +3,23 @@ #pragma once #include "Pomdog/Basic/Export.hpp" -#include "Pomdog/Content/detail/AssetLoader.hpp" +#include "Pomdog/Content/AssetLoaders/AssetLoader.hpp" +#include "Pomdog/Utility/Errors.hpp" #include #include +#include namespace Pomdog { +class AssetManager; class Texture2D; } // namespace Pomdog namespace Pomdog::Detail { -class AssetLoaderContext; - template <> struct POMDOG_EXPORT AssetLoader final { - std::shared_ptr operator()( - const AssetLoaderContext& loaderContext, - const std::string& assetName); + [[nodiscard]] std::tuple, std::shared_ptr> + operator()(AssetManager& assets, const std::string& filePath); }; } // namespace Pomdog::Detail diff --git a/include/Pomdog/Content/Audio/WAV.hpp b/include/Pomdog/Content/Audio/WAV.hpp new file mode 100644 index 000000000..50fc41d21 --- /dev/null +++ b/include/Pomdog/Content/Audio/WAV.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. + +#pragma once + +#include "Pomdog/Audio/detail/ForwardDeclarations.hpp" +#include "Pomdog/Basic/Export.hpp" +#include "Pomdog/Utility/Errors.hpp" +#include +#include +#include +#include +#include + +namespace Pomdog::WAV { + +/// Reads an audio data from Waveform Audio File (.wav) format data. +[[nodiscard]] POMDOG_EXPORT +std::tuple, std::shared_ptr> +Load(std::ifstream&& stream, std::size_t byteLength); + +} // namespace Pomdog::WAV diff --git a/include/Pomdog/Content/Image/DDS.hpp b/include/Pomdog/Content/Image/DDS.hpp new file mode 100644 index 000000000..2b2f3fded --- /dev/null +++ b/include/Pomdog/Content/Image/DDS.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. + +#pragma once + +#include "Pomdog/Basic/Export.hpp" +#include "Pomdog/Content/Image/ImageBuffer.hpp" +#include "Pomdog/Utility/Errors.hpp" +#include +#include +#include +#include + +namespace Pomdog::DDS { + +/// Reads a DDS image from data (.dds). +[[nodiscard]] POMDOG_EXPORT +std::tuple> +Decode(const std::uint8_t* data, std::size_t size); + +} // namespace Pomdog::DDS diff --git a/include/Pomdog/Content/Image/ImageBuffer.hpp b/include/Pomdog/Content/Image/ImageBuffer.hpp new file mode 100644 index 000000000..7993780f9 --- /dev/null +++ b/include/Pomdog/Content/Image/ImageBuffer.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. + +#pragma once + +#include "Pomdog/Basic/Export.hpp" +#include "Pomdog/Graphics/SurfaceFormat.hpp" +#include +#include +#include + +namespace Pomdog { + +struct POMDOG_EXPORT ImageBuffer final { + /// Raw pixel data. + std::vector RawData; + + /// Pointer to pixel data array. + const std::uint8_t* PixelData = nullptr; + + /// Size of byte array of pixel data. + std::size_t ByteLength = 0; + + /// Width of the image in pixels. + std::int32_t Width = 1; + + /// Height of the image in pixels. + std::int32_t Height = 1; + + /// The number of mipmap levels in a multilevel texture. + std::int32_t MipmapCount = 0; + + /// Surface format of the image. + SurfaceFormat Format = SurfaceFormat::R8_UNorm; +}; + +} // namespace Pomdog diff --git a/include/Pomdog/Content/Image/PNG.hpp b/include/Pomdog/Content/Image/PNG.hpp new file mode 100644 index 000000000..24b5cd406 --- /dev/null +++ b/include/Pomdog/Content/Image/PNG.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. + +#pragma once + +#include "Pomdog/Basic/Export.hpp" +#include "Pomdog/Content/Image/ImageBuffer.hpp" +#include "Pomdog/Utility/Errors.hpp" +#include +#include +#include +#include + +namespace Pomdog::PNG { + +/// Reads a PNG image from data (.png). +[[nodiscard]] POMDOG_EXPORT +std::tuple> +Decode(const std::uint8_t* data, std::size_t size); + +} // namespace Pomdog::PNG diff --git a/src/Content/AssetLoaders/AudioClipLoader.cpp b/src/Content/AssetLoaders/AudioClipLoader.cpp index f704ba00a..60183f9e0 100644 --- a/src/Content/AssetLoaders/AudioClipLoader.cpp +++ b/src/Content/AssetLoaders/AudioClipLoader.cpp @@ -1,13 +1,14 @@ // Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. -#include "Pomdog/Content/detail/AssetLoaders/AudioClipLoader.hpp" -#include "../Utility/MSWaveAudioLoader.hpp" +#include "Pomdog/Content/AssetLoaders/AudioClipLoader.hpp" #include "Pomdog/Audio/AudioClip.hpp" +#include "Pomdog/Content/Audio/WAV.hpp" #include "Pomdog/Content/Utility/BinaryReader.hpp" #include "Pomdog/Content/Utility/MakeFourCC.hpp" -#include "Pomdog/Content/detail/AssetLoaderContext.hpp" +#include "Pomdog/Content/AssetManager.hpp" #include "Pomdog/Utility/Assert.hpp" #include "Pomdog/Utility/Exception.hpp" +#include "Pomdog/Utility/FileSystem.hpp" #include #include #include @@ -16,37 +17,51 @@ namespace Pomdog::Detail { -std::shared_ptr AssetLoader::operator()( - const AssetLoaderContext& loaderContext, const std::string& assetName) +std::tuple, std::shared_ptr> +AssetLoader::operator()([[maybe_unused]] AssetManager& assets, const std::string& filePath) { - auto binaryStream = loaderContext.OpenStream(assetName); + std::ifstream stream{filePath, std::ifstream::binary}; - if (!binaryStream.Stream) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot open the wave file: " + assetName); + if (!stream) { + auto err = Errors::New("cannot open the file, " + filePath); + return std::make_tuple(nullptr, std::move(err)); } - if (binaryStream.SizeInBytes < (sizeof(std::uint8_t) * 12)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "The audio file is too small: " + assetName); + auto[byteLength, sizeErr] = FileSystem::GetFileSize(filePath); + if (sizeErr != nullptr) { + auto err = Errors::Wrap(std::move(sizeErr), "failed to get file size, " + filePath); + return std::make_tuple(nullptr, std::move(err)); } - auto & stream = binaryStream.Stream; + POMDOG_ASSERT(stream); + + if (byteLength < (sizeof(std::uint8_t) * 12)) { + auto err = Errors::New("The audio file is too small " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } auto signature = BinaryReader::ReadArray(stream); if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read the audio file."); + auto err = Errors::New("failed to read signature in the file " + filePath); + return std::make_tuple(nullptr, std::move(err)); } + stream.clear(); + stream.seekg(0, std::ios_base::beg); + const auto fourCC = MakeFourCC(signature[0], signature[1], signature[2], signature[3]); if (fourCC == MakeFourCC('R', 'I', 'F', 'F')) { const auto fccType = MakeFourCC(signature[8], signature[9], signature[10], signature[11]); if (fccType == MakeFourCC('W', 'A', 'V', 'E')) { - // This file format is RIFF waveform audio. - auto audioClip = MSWaveAudioLoader::Load(std::move(binaryStream)); - return std::move(audioClip); + // NOTE: This file format is RIFF waveform audio. + auto[audioClip, loadErr] = WAV::Load(std::move(stream), byteLength); + + if (loadErr != nullptr) { + auto err = Errors::Wrap(std::move(loadErr), "Cannot load the wave file " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } + return std::make_tuple(std::move(audioClip), nullptr); } } else if (fourCC == MakeFourCC('O', 'g', 'g', 'S')) { @@ -55,7 +70,8 @@ std::shared_ptr AssetLoader::operator()( "Pomdog does not yet supported Ogg Vorbis format."); } - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); + auto err = Errors::New("This audio file format is not supported " + filePath); + return std::make_tuple(nullptr, std::move(err)); } } // namespace Pomdog::Detail diff --git a/src/Content/AssetLoaders/Texture2DLoader.cpp b/src/Content/AssetLoaders/Texture2DLoader.cpp index e61543d3e..838b96d9d 100644 --- a/src/Content/AssetLoaders/Texture2DLoader.cpp +++ b/src/Content/AssetLoaders/Texture2DLoader.cpp @@ -1,89 +1,147 @@ // Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. -#include "Pomdog/Content/detail/AssetLoaders/Texture2DLoader.hpp" -#include "../Utility/DDSTextureReader.hpp" -#include "../Utility/PNGTextureReader.hpp" +#include "Pomdog/Content/AssetLoaders/Texture2DLoader.hpp" +#include "Pomdog/Content/Image/DDS.hpp" +#include "Pomdog/Content/Image/PNG.hpp" #include "Pomdog/Content/Utility/BinaryReader.hpp" #include "Pomdog/Content/Utility/MakeFourCC.hpp" -#include "Pomdog/Content/detail/AssetLoaderContext.hpp" +#include "Pomdog/Content/AssetManager.hpp" +#include "Pomdog/Graphics/SurfaceFormat.hpp" +#include "Pomdog/Graphics/Texture2D.hpp" #include "Pomdog/Utility/Assert.hpp" -#include "Pomdog/Utility/Exception.hpp" +#include "Pomdog/Utility/FileSystem.hpp" #include #include #include #include #include +#include #include #include namespace Pomdog::Detail { namespace { -bool IsPNGFormat(const std::array& signature) +bool IsPNGFormat(const std::array& signature) noexcept { std::array const pngSignature {{ 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}}; - return std::equal(std::begin(signature), std::end(signature), - std::begin(pngSignature)); + return std::equal(std::begin(signature), std::end(signature), std::begin(pngSignature)); } -bool IsDDSFormat(const std::array& signature) +bool IsDDSFormat(const std::array& signature) noexcept { constexpr auto fourCC = MakeFourCC('D', 'D', 'S', ' '); static_assert(fourCC == 0x20534444, "The four character code value is 'DDS '"); return (MakeFourCC(signature[0], signature[1], signature[2], signature[3]) == fourCC); } -} // unnamed namespace +} // namespace -std::shared_ptr AssetLoader::operator()( - const AssetLoaderContext& loaderContext, const std::string& assetName) +std::tuple, std::shared_ptr> +AssetLoader::operator()(AssetManager& assets, const std::string& filePath) { - auto binaryFile = loaderContext.OpenStream(assetName); - auto & stream = binaryFile.Stream; + std::ifstream stream{filePath, std::ifstream::binary}; - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::invalid_argument, "Cannot open file: " + assetName); + if (!stream) { + auto err = Errors::New("cannot open the file, " + filePath); + return std::make_tuple(nullptr, std::move(err)); } - if (binaryFile.SizeInBytes < (sizeof(std::uint8_t) * 8)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); + auto[byteLength, sizeErr] = FileSystem::GetFileSize(filePath); + if (sizeErr != nullptr) { + auto err = Errors::Wrap(std::move(sizeErr), "failed to get file size, " + filePath); + return std::make_tuple(nullptr, std::move(err)); } - auto signature = BinaryReader::ReadArray(stream); - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); - } + POMDOG_ASSERT(stream); - if (IsPNGFormat(signature)) { - constexpr auto SignatureLength = sizeof(std::uint8_t) * 8; + constexpr std::size_t signatureArraySize = 8; + if (byteLength < (sizeof(std::uint8_t) * signatureArraySize)) { + auto err = Errors::New("The texture file is too small " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } - POMDOG_ASSERT(stream.tellg() == std::streampos(SignatureLength)); + auto signature = BinaryReader::ReadArray(stream); + if (stream.fail()) { + auto err = Errors::New("failed to read signature in the file " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } - std::vector binaryWithoutSignature(binaryFile.SizeInBytes - SignatureLength); - stream.read(reinterpret_cast(binaryWithoutSignature.data()), binaryWithoutSignature.size()); + stream.clear(); + stream.seekg(0, stream.beg); - auto graphicsDevice = loaderContext.GraphicsDevice.lock(); - POMDOG_ASSERT(graphicsDevice); + auto graphicsDevice = assets.GetGraphicsDevice(); + POMDOG_ASSERT(graphicsDevice); - return PNGTextureReader::Read(graphicsDevice, binaryWithoutSignature.data(), binaryWithoutSignature.size()); + if (IsPNGFormat(signature)) { + std::vector binary; + binary.resize(byteLength); + stream.read(reinterpret_cast(binary.data()), binary.size()); + if (!stream) { + auto err = Errors::New("failed to read the file " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } + + auto[image, decodeErr] = PNG::Decode(binary.data(), binary.size()); + if (decodeErr != nullptr) { + auto err = Errors::Wrap(std::move(decodeErr), "cannot load the PNG texture " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } + + constexpr bool generateMipmap = false; + + auto texture = std::make_shared( + graphicsDevice, + image.Width, + image.Height, + generateMipmap, + image.Format); + + POMDOG_ASSERT(!image.RawData.empty()); + POMDOG_ASSERT(image.PixelData != nullptr); + POMDOG_ASSERT(image.ByteLength > 0); + + texture->SetData(image.PixelData); + + return std::make_tuple(std::move(texture), nullptr); } else if (IsDDSFormat(signature)) { - constexpr auto FourCCLength = sizeof(std::uint8_t) * 4; - - stream.seekg(FourCCLength, stream.beg); - - std::vector binaryWithoutFourCC(binaryFile.SizeInBytes - FourCCLength); - stream.read(reinterpret_cast(binaryWithoutFourCC.data()), binaryWithoutFourCC.size()); - - auto graphicsDevice = loaderContext.GraphicsDevice.lock(); - POMDOG_ASSERT(graphicsDevice); - - return DDSTextureReader::Read(graphicsDevice, binaryWithoutFourCC.data(), binaryWithoutFourCC.size()); + std::vector binary; + binary.resize(byteLength); + stream.read(reinterpret_cast(binary.data()), binary.size()); + if (!stream) { + auto err = Errors::New("failed to read the file " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } + + auto[image, decodeErr] = DDS::Decode(binary.data(), binary.size()); + if (decodeErr != nullptr) { + auto err = Errors::Wrap(std::move(decodeErr), "cannot load the DDS texture " + filePath); + return std::make_tuple(nullptr, std::move(err)); + } + + // FIXME: Add support multi-level texture (mipmap) + constexpr bool generateMipmap = false; + + auto texture = std::make_shared( + graphicsDevice, + image.Width, + image.Height, + generateMipmap, + image.Format); + + POMDOG_ASSERT(image.PixelData != nullptr); + POMDOG_ASSERT(image.ByteLength > 0); + + texture->SetData(image.PixelData); + + return std::make_tuple(std::move(texture), nullptr); } - POMDOG_THROW_EXCEPTION(std::runtime_error, "Invalid/unsupported texture format."); + auto err = Errors::New("This texture file format is not supported " + filePath); + return std::make_tuple(nullptr, std::move(err)); } } // namespace Pomdog::Detail diff --git a/src/Content/Audio/WAV.cpp b/src/Content/Audio/WAV.cpp new file mode 100644 index 000000000..5a337b54d --- /dev/null +++ b/src/Content/Audio/WAV.cpp @@ -0,0 +1,273 @@ +// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. + +#include "Pomdog/Content/Audio/WAV.hpp" + +#include "Pomdog/Basic/Platform.hpp" +#if defined(POMDOG_PLATFORM_MACOSX) \ + || defined(POMDOG_PLATFORM_APPLE_IOS) \ + || defined(POMDOG_PLATFORM_LINUX) +#include "../../SoundSystem.OpenAL/AudioClipAL.hpp" +#elif defined(POMDOG_PLATFORM_WIN32) \ + || defined(POMDOG_PLATFORM_XBOX_ONE) +#include "../../SoundSystem.XAudio2/AudioClipXAudio2.hpp" +#endif + +#include "../../Basic/ConditionalCompilation.hpp" +#include "Pomdog/Audio/AudioClip.hpp" +#include "Pomdog/Content/Utility/BinaryReader.hpp" +#include "Pomdog/Content/Utility/MakeFourCC.hpp" +#include "Pomdog/Utility/Assert.hpp" +#include +#include +#include + +using Pomdog::Detail::BinaryReader; +using Pomdog::Detail::MakeFourCC; + +namespace Pomdog::WAV { +namespace { + +#if defined(POMDOG_COMPILER_MSVC) +#pragma pack(push, 1) +#endif + +#if defined(POMDOG_DETAIL_PACKED) +# error "'POMDOG_DETAIL_PACKED' already defined." +#endif + +#if defined(POMDOG_COMPILER_CLANG) || defined(POMDOG_COMPILER_GNUC) +# define POMDOG_DETAIL_PACKED __attribute__((packed)) +#elif defined(POMDOG_COMPILER_MSVC) +# define POMDOG_DETAIL_PACKED +#else +# error "'POMDOG_DETAIL_PACKED' is not supported in this compiler." +#endif + +struct RIFFChunk final { + std::uint32_t ChunkID; + std::uint32_t ChunkSize; + std::uint32_t FourCCType; +} POMDOG_DETAIL_PACKED; + +struct SubChunkHeader final { + std::uint32_t ChunkID; + std::uint32_t ChunkSize; +} POMDOG_DETAIL_PACKED; + +struct PCMWaveFormat final { + std::uint16_t FormatTag; + std::uint16_t Channels; + std::uint32_t SamplesPerSec; + std::uint32_t AvgBytesPerSec; + std::uint16_t BlockAlign; + std::uint16_t BitsPerSample; +} POMDOG_DETAIL_PACKED; + +#if defined(POMDOG_DETAIL_PACKED) +# undef POMDOG_DETAIL_PACKED +#endif + +#if defined(POMDOG_COMPILER_MSVC) +#pragma pack(pop) +#endif + +struct WaveFormat final { + PCMWaveFormat PCMFormat; + std::uint16_t ExtraBytes = 0; + std::vector ExtraData; +}; + +[[nodiscard]] std::shared_ptr +ReadRIFFChunk(std::ifstream& stream) +{ + const auto riffChunk = BinaryReader::Read(stream); + + if (stream.fail()) { + return Errors::New("failed to read read RiffChunk"); + } + + if (riffChunk.ChunkID != MakeFourCC('R', 'I', 'F', 'F')) { + return Errors::New("missing RIFF chunk"); + } + if (riffChunk.FourCCType != MakeFourCC('W', 'A', 'V', 'E')) { + return Errors::New("FourCCType is not 'WAVE'"); + } + + return nullptr; +} + +[[nodiscard]] std::tuple> +ReadWaveFormat(std::ifstream& stream) +{ + const auto fmtChunkHeader = BinaryReader::Read(stream); + + if (stream.fail()) { + auto err = Errors::New("failed to read SubChunkHeader"); + return std::make_tuple(WaveFormat{}, std::move(err)); + } + + if (fmtChunkHeader.ChunkID != MakeFourCC('f', 'm', 't', ' ')) { + auto err = Errors::New("cannot find the 'fmt ' chunk"); + return std::make_tuple(WaveFormat{}, std::move(err)); + } + if (fmtChunkHeader.ChunkSize < sizeof(PCMWaveFormat)) { + auto err = Errors::New("The 'fmt ' chunk size is too small: " + std::to_string(fmtChunkHeader.ChunkSize)); + return std::make_tuple(WaveFormat{}, std::move(err)); + } + + WaveFormat waveFormat; + waveFormat.PCMFormat = BinaryReader::Read(stream); + waveFormat.ExtraBytes = 0; + + if (stream.fail()) { + auto err = Errors::New("failed to read the 'fmt ' chunk into PCMWaveFormat"); + return std::make_tuple(std::move(waveFormat), std::move(err)); + } + + // NOTE: WAVE_FORMAT_PCM + constexpr std::uint16_t WaveFormatTagPCM = 0x0001; + + if (waveFormat.PCMFormat.FormatTag == WaveFormatTagPCM) { + waveFormat.ExtraBytes = 0; + waveFormat.ExtraData.clear(); + } + else { + waveFormat.ExtraBytes = BinaryReader::Read(stream); + if (stream.fail()) { + auto err = Errors::New("failed to read read the extra bytes"); + return std::make_tuple(std::move(waveFormat), std::move(err)); + } + + waveFormat.ExtraData.resize(waveFormat.ExtraBytes); + stream.read(reinterpret_cast(waveFormat.ExtraData.data()), waveFormat.ExtraBytes); + + if (stream.fail()) { + auto err = Errors::New("failed to read read the extra data"); + return std::make_tuple(std::move(waveFormat), std::move(err)); + } + } + + return std::make_tuple(std::move(waveFormat), nullptr); +} + +[[nodiscard]] std::tuple, std::shared_ptr> +ReadWaveAudioData(std::ifstream& stream) +{ + POMDOG_ASSERT(stream); + + const auto chunkHeader = BinaryReader::Read(stream); + + if (stream.fail()) { + auto err = Errors::New("failed to read 'data' chunk header"); + return std::make_tuple(std::vector{}, std::move(err)); + } + if (chunkHeader.ChunkID != MakeFourCC('d', 'a', 't', 'a')) { + auto err = Errors::New("cannot find the 'data' chunk"); + return std::make_tuple(std::vector{}, std::move(err)); + } + if (chunkHeader.ChunkSize <= 0) { + auto err = Errors::New("data chunk is empty"); + return std::make_tuple(std::vector{}, std::move(err)); + } + + std::vector audioData; + audioData.resize(chunkHeader.ChunkSize); + + for (auto& dest : audioData) { + dest = BinaryReader::Read(stream); + if (stream.fail()) { + auto err = Errors::New("failed to read wave data"); + return std::make_tuple(std::move(audioData), std::move(err)); + } + } + + return std::make_tuple(std::move(audioData), nullptr); +} + +[[nodiscard]] AudioChannels ToAudioChannels(std::uint32_t channels) noexcept +{ + POMDOG_ASSERT(channels > 0); + POMDOG_ASSERT(channels <= 2); + + switch (channels) { + case 1: return AudioChannels::Mono; + case 2: return AudioChannels::Stereo; + default: + break; + } + return AudioChannels::Mono; +} + +} // namespace + +[[nodiscard]] std::tuple, std::shared_ptr> +Load(std::ifstream&& stream, std::size_t byteLength) +{ + constexpr auto MinimumWaveFormatSizeInBytes = 4 * 11; + if (byteLength < MinimumWaveFormatSizeInBytes) { + return std::make_tuple(nullptr, Errors::New("the wave file is too small")); + } + + if (!stream) { + return std::make_tuple(nullptr, Errors::New("invalid file stream")); + } + + if (auto readErr = ReadRIFFChunk(stream); readErr != nullptr) { + auto err = Errors::Wrap(std::move(readErr), "cannot read the wave file"); + return std::make_tuple(nullptr, std::move(err)); + } + + auto[waveFormat, waveFormatErr] = ReadWaveFormat(stream); + if (waveFormatErr != nullptr) { + auto err = Errors::Wrap(std::move(waveFormatErr), "cannot read the wave format"); + return std::make_tuple(nullptr, std::move(err)); + } + + auto[audioData, audioDataErr] = ReadWaveAudioData(stream); + if (audioDataErr != nullptr) { + auto err = Errors::Wrap(std::move(audioDataErr), "cannot read the wave audio data"); + return std::make_tuple(nullptr, std::move(err)); + } + + auto channels = ToAudioChannels(waveFormat.PCMFormat.Channels); + +#if defined(POMDOG_PLATFORM_MACOSX) \ + || defined(POMDOG_PLATFORM_APPLE_IOS) \ + || defined(POMDOG_PLATFORM_LINUX) + // NOTE: OpenAL + using Detail::SoundSystem::OpenAL::AudioClipAL; + auto nativeAudioClip = std::make_unique( + audioData.data(), + audioData.size(), + static_cast(waveFormat.PCMFormat.SamplesPerSec), + static_cast(waveFormat.PCMFormat.BitsPerSample), + channels); + +#elif defined(POMDOG_PLATFORM_WIN32) \ + || defined(POMDOG_PLATFORM_XBOX_ONE) + // NOTE: XAudio2 + std::vector waveFormatData; + waveFormatData.resize(sizeof(waveFormat.PCMFormat) + + sizeof(waveFormat.ExtraBytes) + + waveFormat.ExtraBytes); + + auto offset = sizeof(waveFormat.PCMFormat) + sizeof(waveFormat.ExtraBytes); + std::memcpy(waveFormatData.data(), &waveFormat, offset); + std::memcpy(waveFormatData.data() + offset, waveFormat.ExtraData.data(), waveFormat.ExtraBytes); + + using Detail::SoundSystem::XAudio2::AudioClipXAudio2; + auto nativeAudioClip = std::make_unique( + std::move(audioData), + std::move(waveFormatData)); +#endif + + auto audioClip = std::make_shared( + std::move(nativeAudioClip), + static_cast(waveFormat.PCMFormat.SamplesPerSec), + static_cast(waveFormat.PCMFormat.BitsPerSample), + channels); + + return std::make_tuple(std::move(audioClip), nullptr); +} + +} // namespace Pomdog::WAV diff --git a/src/Content/Utility/DDSTextureReader.cpp b/src/Content/Image/DDS.cpp similarity index 62% rename from src/Content/Utility/DDSTextureReader.cpp rename to src/Content/Image/DDS.cpp index 61f473df5..ae85b686b 100644 --- a/src/Content/Utility/DDSTextureReader.cpp +++ b/src/Content/Image/DDS.cpp @@ -1,15 +1,17 @@ // Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. -#include "DDSTextureReader.hpp" +#include "Pomdog/Content/Image/DDS.hpp" #include "../../Basic/ConditionalCompilation.hpp" #include "Pomdog/Content/Utility/BinaryReader.hpp" #include "Pomdog/Content/Utility/MakeFourCC.hpp" #include "Pomdog/Graphics/SurfaceFormat.hpp" -#include "Pomdog/Graphics/Texture2D.hpp" #include "Pomdog/Utility/Assert.hpp" -#include "Pomdog/Utility/Exception.hpp" +#include -namespace Pomdog::Detail { +using Pomdog::Detail::MakeFourCC; +using Pomdog::Detail::BinaryReader; + +namespace Pomdog::DDS { namespace { #if defined(POMDOG_COMPILER_MSVC) @@ -28,18 +30,18 @@ namespace { # error "'POMDOG_DETAIL_PACKED' is not supported in this compiler." #endif -struct DDSPixelFormat { +struct DDSPixelFormat final { std::uint32_t ByteSize; std::uint32_t Flags; std::uint32_t FourCC; - std::uint32_t RgbBitCount; + std::uint32_t RGBBitCount; std::uint32_t RedBitMask; std::uint32_t GreenBitMask; std::uint32_t BlueBitMask; std::uint32_t AlphaBitMask; } POMDOG_DETAIL_PACKED; -struct DDSHeader { +struct DDSHeader final { std::uint32_t ByteSize; std::uint32_t Flags; std::uint32_t PixelHeight; @@ -56,7 +58,7 @@ struct DDSHeader { std::uint32_t Reserved2; } POMDOG_DETAIL_PACKED; -struct DDSHeaderDXT10 { +struct DDSHeaderDXT10 final { std::uint32_t DxgiFormat; // Note: enum DXGI_FORMAT std::uint32_t ResourceDimension; // Note: enum D3D10_RESOURCE_DIMENSION std::uint32_t MiscFlag; @@ -82,7 +84,16 @@ static constexpr std::uint32_t Luminance = 0x00020000; // DDPF_LUMINANCE } // namespace DirectDrawPixelFormat -SurfaceFormat ToSurfaceFormatFromDDSPixelFormat(const DDSPixelFormat& pixelFormat) +[[nodiscard]] bool +IsDDSFormat(std::uint32_t signature) noexcept +{ + constexpr auto fourCC = MakeFourCC('D', 'D', 'S', ' '); + static_assert(fourCC == 0x20534444, "The four character code value is 'DDS '"); + return (signature == fourCC); +} + +[[nodiscard]] std::optional +ToSurfaceFormat(const DDSPixelFormat& pixelFormat) { constexpr std::uint32_t FourCC_A32B32G32R32_Float = 0x00000074; @@ -107,7 +118,7 @@ SurfaceFormat ToSurfaceFormatFromDDSPixelFormat(const DDSPixelFormat& pixelForma } } else if (pixelFormat.Flags & DirectDrawPixelFormat::RGB) { - switch (pixelFormat.RgbBitCount) { + switch (pixelFormat.RGBBitCount) { case 32: if ( (0x000000ff == pixelFormat.RedBitMask) && @@ -137,12 +148,12 @@ SurfaceFormat ToSurfaceFormatFromDDSPixelFormat(const DDSPixelFormat& pixelForma } } else if (pixelFormat.Flags & DirectDrawPixelFormat::Alpha) { - if (8 == pixelFormat.RgbBitCount) { + if (8 == pixelFormat.RGBBitCount) { return SurfaceFormat::A8_UNorm; } } else if (pixelFormat.Flags & DirectDrawPixelFormat::Luminance) { - switch (pixelFormat.RgbBitCount) { + switch (pixelFormat.RGBBitCount) { case 8: if ( (0x000000ff == pixelFormat.RedBitMask) && @@ -167,54 +178,78 @@ SurfaceFormat ToSurfaceFormatFromDDSPixelFormat(const DDSPixelFormat& pixelForma } } - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot find the surface format. Undefined or not supported"); + return std::nullopt; } -std::size_t ComputePixelDataByteLength(const DDSHeader& ddsHeader) +[[nodiscard]] std::size_t +ComputePixelDataByteLength(const DDSHeader& ddsHeader, SurfaceFormat format) { - auto const bytesPerBlock = ddsHeader.PixelFormat.RgbBitCount; - auto const levelCount = (ddsHeader.MipMapCount > 0) ? ddsHeader.MipMapCount: 1; + const auto levelCount = (ddsHeader.MipMapCount > 0) ? ddsHeader.MipMapCount: 1; + + const auto bytesPerBlock = [&format]() -> int { + switch (format) { + case SurfaceFormat::BlockComp1_UNorm: + return 8; + case SurfaceFormat::BlockComp2_UNorm: + return 16; + case SurfaceFormat::BlockComp3_UNorm: + return 16; + default: + break; + } + return 16; + }(); std::size_t result = 0; - std::size_t mipMapPixelWidth = ddsHeader.PixelWidth; - std::size_t mipMapPixelHeight = ddsHeader.PixelHeight; + std::size_t mipmapPixelWidth = ddsHeader.PixelWidth; + std::size_t mipmapPixelHeight = ddsHeader.PixelHeight; for (std::uint32_t mipmapLevel = 0; mipmapLevel < levelCount; ++mipmapLevel) { - std::size_t const strideBytesPerMipMap = ((mipMapPixelWidth + 3)/4) * ((mipMapPixelHeight + 3)/4) * bytesPerBlock; + std::size_t const strideBytesPerMipMap = ((mipmapPixelWidth + 3)/4) * ((mipmapPixelHeight + 3)/4) * bytesPerBlock; result += strideBytesPerMipMap; - mipMapPixelWidth = (mipMapPixelWidth >> 1) ? (mipMapPixelWidth >> 1): 1; - mipMapPixelHeight = (mipMapPixelHeight >> 1) ? (mipMapPixelHeight >> 1): 1; + mipmapPixelWidth = (mipmapPixelWidth >> 1) ? (mipmapPixelWidth >> 1): 1; + mipmapPixelHeight = (mipmapPixelHeight >> 1) ? (mipmapPixelHeight >> 1): 1; } return result; } -} // unnamed namespace +} // namespace -std::shared_ptr DDSTextureReader::Read( - const std::shared_ptr& graphicsDevice, - const std::uint8_t* data, - std::size_t byteLength) +std::tuple> +Decode(const std::uint8_t* data, std::size_t size) { - POMDOG_ASSERT(graphicsDevice); POMDOG_ASSERT(data != nullptr); - POMDOG_ASSERT(byteLength > 0); + POMDOG_ASSERT(size > 0); + + ImageBuffer image; + image.PixelData = nullptr; + image.ByteLength = 0; std::size_t offsetBytes = 0; - if (!BinaryReader::CanRead(byteLength - offsetBytes)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); + if (!BinaryReader::CanRead(size - offsetBytes)) { + return std::make_tuple(std::move(image), Errors::New("cannot find dds signature")); } - auto const ddsHeader = BinaryReader::Read(data); + const auto ddsSignature = BinaryReader::Read(data + offsetBytes); + offsetBytes += sizeof(ddsSignature); + + if (!IsDDSFormat(ddsSignature)) { + return std::make_tuple(std::move(image), Errors::New("invalid format")); + } + + if (!BinaryReader::CanRead(size - offsetBytes)) { + return std::make_tuple(std::move(image), Errors::New("dds header has an invalid format")); + } + const auto ddsHeader = BinaryReader::Read(data + offsetBytes); offsetBytes += sizeof(ddsHeader); if (ddsHeader.ByteSize != sizeof(DDSHeader)) { - POMDOG_THROW_EXCEPTION(std::domain_error, "DDSHeader has invalid format."); + return std::make_tuple(std::move(image), Errors::New("dds header has an invalid format")); } if (ddsHeader.PixelFormat.ByteSize != sizeof(DDSPixelFormat)) { - POMDOG_THROW_EXCEPTION(std::domain_error, "DDSHeader has invalid format."); + return std::make_tuple(std::move(image), Errors::New("dds header has an invalid format")); } bool hasDXT10Header = false; @@ -225,27 +260,30 @@ std::shared_ptr DDSTextureReader::Read( } if (hasDXT10Header) { - ///@todo Not implemented. - POMDOG_THROW_EXCEPTION(std::runtime_error, "Sorry, DXT10 header is not supported."); + // FIXME: Not implemented yet. + return std::make_tuple(std::move(image), Errors::New("Sorry, DXT10 header is not supported yet.")); } - std::uint32_t pixelWidth = ddsHeader.PixelWidth; - std::uint32_t pixelHeight = ddsHeader.PixelHeight; - SurfaceFormat surfaceFormat = ToSurfaceFormatFromDDSPixelFormat(ddsHeader.PixelFormat); - bool const generateMipmap = (ddsHeader.MipMapCount > 0); + image.Width = ddsHeader.PixelWidth; + image.Height = ddsHeader.PixelHeight; + image.MipmapCount = ddsHeader.MipMapCount; - if ((byteLength - offsetBytes) < ComputePixelDataByteLength(ddsHeader)) { - POMDOG_THROW_EXCEPTION(std::domain_error, "DDSHeader has invalid format."); + if (auto format = ToSurfaceFormat(ddsHeader.PixelFormat); format != std::nullopt) { + image.Format = *format; } + else { + return std::make_tuple(std::move(image), Errors::New("cannot find the surface format. Undefined or not supported")); + } + image.ByteLength = ComputePixelDataByteLength(ddsHeader, image.Format); - auto texture = std::make_shared(graphicsDevice, - pixelWidth, pixelHeight, generateMipmap, surfaceFormat); - - if (texture) { - texture->SetData(data + offsetBytes); + if ((size - offsetBytes) < image.ByteLength) { + return std::make_tuple(std::move(image), Errors::New("dds header has an invalid format")); } + image.PixelData = data + offsetBytes; + + POMDOG_ASSERT(image.RawData.empty()); - return texture; + return std::make_tuple(std::move(image), nullptr); } -} // namespace Pomdog::Detail +} // namespace Pomdog::DDS diff --git a/src/Content/Utility/PNGTextureReader.cpp b/src/Content/Image/PNG.cpp similarity index 69% rename from src/Content/Utility/PNGTextureReader.cpp rename to src/Content/Image/PNG.cpp index 17c521aa9..a32cd1e25 100644 --- a/src/Content/Utility/PNGTextureReader.cpp +++ b/src/Content/Image/PNG.cpp @@ -1,33 +1,23 @@ // Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. -#include "PNGTextureReader.hpp" +#include "Pomdog/Content/Image/PNG.hpp" #include "../../Utility/ScopeGuard.hpp" -#include "Pomdog/Graphics/SurfaceFormat.hpp" -#include "Pomdog/Graphics/Texture2D.hpp" #include "Pomdog/Utility/Assert.hpp" -#include "Pomdog/Utility/Exception.hpp" extern "C" { #include } #include #include -namespace Pomdog::Detail { +namespace Pomdog::PNG { namespace { -struct PNGBinaryContext { +struct PNGBinaryContext final { const std::uint8_t* Data; std::size_t ByteLength; std::size_t Offset; }; -struct Texture2DParsingData { - std::vector Binary; - std::uint32_t Height; - std::uint32_t Width; - SurfaceFormat Format; -}; - void ReadPNGDataCallback(::png_structp png_ptr, ::png_bytep data, ::png_size_t length) { auto context = static_cast(::png_get_io_ptr(png_ptr)); @@ -41,16 +31,24 @@ void ReadPNGDataCallback(::png_structp png_ptr, ::png_bytep data, ::png_size_t l } } -Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) +} // namespace + +std::tuple> +Decode(const std::uint8_t* data, std::size_t byteLength) { + ImageBuffer image; + image.PixelData = nullptr; + image.ByteLength = 0; + image.MipmapCount = 0; + auto pngPtr = ::png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (nullptr == pngPtr) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); + return std::make_tuple(std::move(image), Errors::New("png_create_read_struct() failed")); } auto infoPtr = ::png_create_info_struct(pngPtr); - ScopeGuard scopedDestroyReadStruct([&] { + Detail::ScopeGuard scopedDestroyReadStruct([&] { if (nullptr != pngPtr) { if (nullptr != infoPtr) { ::png_destroy_read_struct(&pngPtr, &infoPtr, nullptr); @@ -62,7 +60,7 @@ Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) }); if (nullptr == infoPtr) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented."); + return std::make_tuple(std::move(image), Errors::New("infoPtr is null")); } PNGBinaryContext context; @@ -71,15 +69,16 @@ Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) context.Offset = 0; ::png_set_read_fn(pngPtr, &context, ReadPNGDataCallback); - constexpr auto pngSignatureByteLength = sizeof(std::uint8_t) * 8; + // NOTE: If we have already read some of the signature. + constexpr auto pngSignatureByteLength = 0; ::png_set_sig_bytes(pngPtr, pngSignatureByteLength); - // Read PNG Header + // NOTE: Read PNG header. ::png_read_info(pngPtr, infoPtr); auto const originalColorType = ::png_get_color_type(pngPtr, infoPtr); auto const originalBitDepth = ::png_get_bit_depth(pngPtr, infoPtr); - // Settings + // NOTE: Settings if (originalColorType == PNG_COLOR_TYPE_PALETTE) { // NOTE: PALETTE => RGB (24 bit) ::png_set_palette_to_rgb(pngPtr); @@ -121,7 +120,7 @@ Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) POMDOG_ASSERT(pixelWidth > 0); POMDOG_ASSERT(pixelHeight > 0); - // Read PNG Image Data + // NOTE: Read PNG image data auto const rowBytes = ::png_get_rowbytes(pngPtr, infoPtr); std::vector rowData(rowBytes * pixelHeight * sizeof(png_byte)); @@ -135,10 +134,9 @@ Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) ::png_read_image(pngPtr, bytePointers.data()); ::png_read_end(pngPtr, nullptr); - Texture2DParsingData parsingData; - parsingData.Width = pixelWidth; - parsingData.Height = pixelHeight; - parsingData.Format = ([](::png_byte colorTypeIn) -> SurfaceFormat { + image.Width = pixelWidth; + image.Height = pixelHeight; + image.Format = ([](::png_byte colorTypeIn) -> SurfaceFormat { POMDOG_ASSERT(colorTypeIn != PNG_COLOR_TYPE_RGB); switch (colorTypeIn) { case PNG_COLOR_TYPE_GRAY: @@ -154,33 +152,11 @@ Texture2DParsingData ReadPNG(const std::uint8_t* data, std::size_t byteLength) return SurfaceFormat::A8_UNorm; })(colorType); - parsingData.Binary = std::move(rowData); - - return parsingData; -} - -} // unnamed namespace - -std::shared_ptr PNGTextureReader::Read( - const std::shared_ptr& graphicsDevice, - const std::uint8_t* data, - std::size_t byteLength) -{ - POMDOG_ASSERT(graphicsDevice); - POMDOG_ASSERT(data != nullptr); - POMDOG_ASSERT(byteLength > 0); - - auto parsingData = ReadPNG(data, byteLength); - - constexpr bool generateMipmap = false; - - auto texture = std::make_shared(graphicsDevice, - parsingData.Width, parsingData.Height, - generateMipmap, parsingData.Format); + image.RawData = std::move(rowData); + image.PixelData = image.RawData.data(); + image.ByteLength = image.RawData.size(); - POMDOG_ASSERT(!parsingData.Binary.empty()); - texture->SetData(parsingData.Binary.data()); - return texture; + return std::make_tuple(std::move(image), nullptr); } -} // namespace Pomdog::Detail +} // namespace Pomdog::PNG diff --git a/src/Content/Utility/DDSTextureReader.hpp b/src/Content/Utility/DDSTextureReader.hpp deleted file mode 100644 index 5e046af4f..000000000 --- a/src/Content/Utility/DDSTextureReader.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. - -#pragma once - -#include "Pomdog/Graphics/detail/ForwardDeclarations.hpp" -#include -#include -#include - -namespace Pomdog::Detail::DDSTextureReader { - -std::shared_ptr Read( - const std::shared_ptr& graphicsDevice, - const std::uint8_t* data, - std::size_t byteLength); - -} // namespace Pomdog::Detail::DDSTextureReader diff --git a/src/Content/Utility/MSWaveAudioLoader.cpp b/src/Content/Utility/MSWaveAudioLoader.cpp deleted file mode 100644 index b51216510..000000000 --- a/src/Content/Utility/MSWaveAudioLoader.cpp +++ /dev/null @@ -1,596 +0,0 @@ -// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. - -#include "MSWaveAudioLoader.hpp" - -#include "Pomdog/Basic/Platform.hpp" -#if defined(POMDOG_PLATFORM_MACOSX) \ - || defined(POMDOG_PLATFORM_APPLE_IOS) \ - || defined(POMDOG_PLATFORM_LINUX) -#include "../../SoundSystem.OpenAL/AudioClipAL.hpp" -#elif defined(POMDOG_PLATFORM_WIN32) \ - || defined(POMDOG_PLATFORM_XBOX_ONE) -#include "../../SoundSystem.XAudio2/AudioClipXAudio2.hpp" -#endif - -#include "Pomdog/Audio/AudioClip.hpp" -#include "Pomdog/Content/Utility/BinaryReader.hpp" -#include "Pomdog/Content/Utility/MakeFourCC.hpp" -#include "Pomdog/Logging/Log.hpp" -#include "Pomdog/Utility/Assert.hpp" -#include "Pomdog/Utility/Exception.hpp" - -#if 0 -#if defined(POMDOG_PLATFORM_MACOSX) || defined(POMDOG_PLATFORM_APPLE_IOS) -#include -#include -#elif defined(POMDOG_PLATFORM_WIN32) || defined(POMDOG_PLATFORM_XBOX_ONE) -#include "Pomdog/Content/Utility/MakeFourCC.hpp" -#include "Pomdog/Platform/Win32/PrerequisitesWin32.hpp" -#include -#endif -#endif - -#include -#include -#include - -namespace Pomdog::Detail { -namespace { - -AudioChannels ToAudioChannels(std::uint32_t channels) noexcept -{ - POMDOG_ASSERT(channels > 0); - POMDOG_ASSERT(channels <= 2); - - switch (channels) { - case 1: return AudioChannels::Mono; - case 2: return AudioChannels::Stereo; - default: - break; - } - return AudioChannels::Mono; -} -#if 0 -#if defined(POMDOG_PLATFORM_MACOSX) || defined(POMDOG_PLATFORM_APPLE_IOS) - -std::unique_ptr LoadMSWave_Apple(const std::string& filePath) -{ - CFStringRef filename = CFStringCreateWithCString(nullptr, filePath.c_str(), kCFStringEncodingUTF8); - CFURLRef url = CFURLCreateWithFileSystemPath(nullptr, filename, kCFURLPOSIXPathStyle, false); - CFRelease(filename); - - AudioFileID audioFile; - auto errorCode = AudioFileOpenURL(url, kAudioFileReadPermission, kAudioFileWAVEType, &audioFile); - CFRelease(url); - - if (errorCode != noErr) - { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot open audio file"); - } - - AudioStreamBasicDescription basicDescription; - UInt32 propertySize = sizeof(basicDescription); - errorCode = AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &propertySize, &basicDescription); - - if (errorCode != noErr) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to get audio file propety"); - } - - if (basicDescription.mFormatID != kAudioFormatLinearPCM) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "This audio file is not linear PCM format"); - } - - UInt64 audioDataByteCount = 0; - propertySize = sizeof(audioDataByteCount); - errorCode = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataByteCount, &propertySize, &audioDataByteCount); - - if (errorCode != noErr) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot get the byte count of the audio data"); - } - - Float64 estimatedDuration = 0; - propertySize = sizeof(estimatedDuration); - errorCode = AudioFileGetProperty(audioFile, kAudioFilePropertyEstimatedDuration, &propertySize, &estimatedDuration); - - if (errorCode != noErr) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot get the estimated duration of the audio data"); - } - - if (basicDescription.mChannelsPerFrame < 1 - && basicDescription.mChannelsPerFrame > 2) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "4, 5.1, 6.1 and 7.1 channel audio are not supported. You can use mono and stereo."); - } - - if (basicDescription.mBitsPerChannel < 8 - && basicDescription.mBitsPerChannel > 32 - && (basicDescription.mBitsPerChannel % 8 != 0)) - { - AudioFileClose(audioFile); - POMDOG_THROW_EXCEPTION(std::runtime_error, - "4, 5.1, 6.1 and 7.1 channel audio are not supported. You can use mono and stereo."); - } - - POMDOG_ASSERT(basicDescription.mBitsPerChannel == 8 - || basicDescription.mBitsPerChannel == 16 - || basicDescription.mBitsPerChannel == 24 - || basicDescription.mBitsPerChannel == 32); - - std::vector audioData; - audioData.resize(audioDataByteCount); - - UInt32 byteCountToRead = static_cast(audioData.size()); - errorCode = AudioFileReadBytes(audioFile, false, 0, &byteCountToRead, audioData.data()); - AudioFileClose(audioFile); - - if (errorCode != noErr) - { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read audio data"); - } - - if (byteCountToRead != audioDataByteCount) - { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read audio data"); - } - - using Detail::SoundSystem::OpenAL::AudioClipAL; - - auto channels = ToAudioChannels(basicDescription.mChannelsPerFrame); - - auto nativeAudioClip = std::make_unique( - audioData.data(), audioData.size(), - basicDescription.mSampleRate, - basicDescription.mBitsPerChannel, - channels); - - auto audioClip = std::make_unique( - std::move(nativeAudioClip), - basicDescription.mSampleRate, - basicDescription.mBitsPerChannel, - channels); - - return std::move(audioClip); -} - -#elif defined(POMDOG_PLATFORM_WIN32) || defined(POMDOG_PLATFORM_XBOX_ONE) - -MMCKINFO ReadRiffChunk(HMMIO ioHandle) -{ - POMDOG_ASSERT(ioHandle); - - MMCKINFO riffChunk; - - auto mmResult = ::mmioDescend(ioHandle, &riffChunk, nullptr, 0); - if (MMSYSERR_NOERROR != mmResult) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read Multi-Media I/O wave file, mmResult=" + std::to_string(mmResult)); - } - - if (MakeFourCC('R', 'I', 'F', 'F') != riffChunk.ckid) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read wave file. this file is a invalid wave file"); - } - - if (MakeFourCC('W', 'A', 'V', 'E') != riffChunk.fccType) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read wave file. this file is a invalid wave file"); - } - - return std::move(riffChunk); -} - -std::vector ReadWaveFormat(HMMIO ioHandle, const MMCKINFO& riffChunk) -{ - POMDOG_ASSERT(ioHandle); - - MMCKINFO chunkInfo; - chunkInfo.ckid = MakeFourCC('f', 'm', 't', ' '); - - auto mmResult = ::mmioDescend(ioHandle, &chunkInfo, &riffChunk, MMIO_FINDCHUNK); - if (MMSYSERR_NOERROR != mmResult) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to search the input file for the 'fmt ' chunk, mmResult=" + std::to_string(mmResult)); - } - - if (chunkInfo.cksize < sizeof(PCMWAVEFORMAT)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "chunkInfo.cksize=" + std::to_string(chunkInfo.cksize)); - } - - PCMWAVEFORMAT pcmWaveFormat; - - auto byteSize = ::mmioRead(ioHandle, reinterpret_cast(&pcmWaveFormat), sizeof(pcmWaveFormat)); - if (byteSize != sizeof(pcmWaveFormat)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to Read the 'fmt ' chunk into "); - } - - std::vector waveFormat; - - if (WAVE_FORMAT_PCM == pcmWaveFormat.wf.wFormatTag) - { - waveFormat.resize(sizeof(WAVEFORMATEX)); - - static_assert(sizeof(WAVEFORMATEX) >= sizeof(pcmWaveFormat), ""); - POMDOG_ASSERT(waveFormat.size() >= sizeof(pcmWaveFormat)); - std::memcpy(waveFormat.data(), &pcmWaveFormat, sizeof(pcmWaveFormat)); - - reinterpret_cast(waveFormat.data())->cbSize = 0; - } - else - { - WORD extraBytes = 0; - byteSize = ::mmioRead(ioHandle, reinterpret_cast(&extraBytes), sizeof(WORD)); - if (byteSize != sizeof(WORD)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to Read the extraBytes"); - } - - waveFormat.resize(sizeof(WAVEFORMATEX) + extraBytes); - - static_assert(sizeof(WAVEFORMATEX) >= sizeof(pcmWaveFormat), ""); - POMDOG_ASSERT(waveFormat.size() >= sizeof(pcmWaveFormat)); - std::memcpy(waveFormat.data(), &pcmWaveFormat, sizeof(pcmWaveFormat)); - - reinterpret_cast(waveFormat.data())->cbSize = extraBytes; - - byteSize = ::mmioRead(ioHandle, reinterpret_cast(waveFormat.data() + sizeof(WAVEFORMATEX)), extraBytes); - if (byteSize != extraBytes) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read the extra data"); - } - } - - mmResult = ::mmioAscend(ioHandle, &chunkInfo, 0); - if (MMSYSERR_NOERROR != mmResult) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to ascend the input file out of the 'fmt ' chunk, mmResult=" + std::to_string(mmResult)); - } - - return std::move(waveFormat); -} - -MMCKINFO SeekDataChunk(HMMIO ioHandle, const MMCKINFO& riffChunk) -{ - POMDOG_ASSERT(ioHandle); - - constexpr LONG seekErrorCode = -1; - if (seekErrorCode == ::mmioSeek(ioHandle, riffChunk.dwDataOffset + sizeof(FOURCC), SEEK_SET)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Failed to call mmioSeek"); - } - - MMCKINFO dataChunk; - dataChunk.ckid = MakeFourCC('d', 'a', 't', 'a'); - - auto mmResult = ::mmioDescend(ioHandle, &dataChunk, &riffChunk, MMIO_FINDCHUNK); - if (MMSYSERR_NOERROR != mmResult) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to call mmioDescend, mmResult=" + std::to_string(mmResult)); - } - return std::move(dataChunk); -} - -std::vector ReadWaveAudioData(HMMIO ioHandle, const MMCKINFO& dataChunk) -{ - POMDOG_ASSERT(ioHandle); - - MMIOINFO mmioInfoIn; - if (0 != ::mmioGetInfo(ioHandle, &mmioInfoIn, 0)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Buffer size is zero"); - } - - if (dataChunk.cksize <= 0) { - POMDOG_THROW_EXCEPTION(std::runtime_error, "Data chunk is empty"); - } - - std::vector result; - result.resize(dataChunk.cksize); - - for (DWORD index = 0; index < dataChunk.cksize; ++index) - { - if (mmioInfoIn.pchNext == mmioInfoIn.pchEndRead) - { - auto mmResult = ::mmioAdvance(ioHandle, &mmioInfoIn, MMIO_READ); - if (MMSYSERR_NOERROR != mmResult) { - ///@todo Not implemeneted - // error: FUS RO DAH! - break; - } - - if (mmioInfoIn.pchNext == mmioInfoIn.pchEndRead) { - ///@todo Not implemeneted - // error: FUS RO DAH! - break; - } - } - - *(result.data() + index) = *(reinterpret_cast<::BYTE*>(mmioInfoIn.pchNext)); - ++mmioInfoIn.pchNext; - } - - if (0 != ::mmioSetInfo(ioHandle, &mmioInfoIn, 0)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to call mmioSetInfo"); - } - - return std::move(result); -} - -std::unique_ptr LoadMSWave_Win32(const std::string& filePath) -{ - HMMIO ioHandle = ::mmioOpen(const_cast(filePath.c_str()), nullptr, MMIO_ALLOCBUF | MMIO_READ); - - if (!ioHandle) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot open Multi-Media I/O wave file"); - } - - try { - auto riffChunk = ReadRiffChunk(ioHandle); - auto waveFormat = ReadWaveFormat(ioHandle, riffChunk); - auto dataChunk = SeekDataChunk(ioHandle, riffChunk); - auto audioData = ReadWaveAudioData(ioHandle, dataChunk); - - ::mmioClose(ioHandle, 0); - ioHandle = nullptr; - - using Detail::SoundSystem::XAudio2::AudioClipXAudio2; - auto nativeAudioClip = std::make_unique( - std::move(audioData), std::move(waveFormat)); - - auto format = nativeAudioClip->WaveFormat(); - POMDOG_ASSERT(format); - - auto audioClip = std::make_unique(std::move(nativeAudioClip), - format->nSamplesPerSec, format->wBitsPerSample, ToAudioChannels(format->nChannels)); - - return std::move(audioClip); - } - catch (const std::exception& e) { - if (ioHandle) { - ::mmioClose(ioHandle, 0); - ioHandle = nullptr; - } - throw e; - } -} -#endif -#endif - -struct RiffChunk { - std::uint32_t ChunkId; - std::uint32_t ChunkSize; - std::uint32_t FourCCType; -}; - -struct SubChunkHeader { - std::uint32_t ChunkId; - std::uint32_t ChunkSize; -}; - -struct PcmWaveFormat { - std::uint16_t FormatTag; - std::uint16_t Channels; - std::uint32_t SamplesPerSec; - std::uint32_t AvgBytesPerSec; - std::uint16_t BlockAlign; - std::uint16_t BitsPerSample; -}; - -struct WaveFormat { - Pomdog::Detail::PcmWaveFormat PcmWaveFormat; - std::uint16_t ExtraBytes; - std::vector ExtraData; -}; - -namespace WaveFormatTags { - // WAVE_FORMAT_PCM - static constexpr std::uint16_t PCM = 0x0001; -} - -RiffChunk ReadRiffChunk(std::ifstream & stream) -{ - POMDOG_ASSERT(stream); - auto riffChunk = BinaryReader::Read(stream); - - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read 'RIFF' chunk descriptor form wave file"); - } - if (MakeFourCC('R', 'I', 'F', 'F') != riffChunk.ChunkId) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read wave file. this file is a invalid wave file"); - } - if (MakeFourCC('W', 'A', 'V', 'E') != riffChunk.FourCCType) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read wave file. this file is a invalid wave file"); - } - return riffChunk; -} - -WaveFormat ReadWaveFormat(std::ifstream & stream) -{ - POMDOG_ASSERT(stream); - - const auto fmtChunkHeader = BinaryReader::Read(stream); - - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read 'fmt ' chunk header form wave file"); - } - if (MakeFourCC('f', 'm', 't', ' ') != fmtChunkHeader.ChunkId) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to search the wave file for the 'fmt ' chunk"); - } - if (fmtChunkHeader.ChunkSize < sizeof(PcmWaveFormat)) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "The 'fmt ' chunk size is too small: " + std::to_string(fmtChunkHeader.ChunkSize)); - } - - WaveFormat waveFormat; - waveFormat.PcmWaveFormat = BinaryReader::Read(stream); - - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to Read the 'fmt ' chunk into pcmWaveFormat"); - } - - if (WaveFormatTags::PCM == waveFormat.PcmWaveFormat.FormatTag) { - waveFormat.ExtraBytes = 0; - waveFormat.ExtraData.clear(); - } - else { - waveFormat.ExtraBytes = BinaryReader::Read(stream); - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to Read the extraBytes"); - } - - waveFormat.ExtraData.resize(waveFormat.ExtraBytes); - stream.read(reinterpret_cast(waveFormat.ExtraData.data()), waveFormat.ExtraBytes); - - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read the extra data"); - } - } - - return waveFormat; -} - -std::vector ReadWaveAudioData(std::ifstream & stream) -{ - POMDOG_ASSERT(stream); - - const auto chunkHeader = BinaryReader::Read(stream); - - if (stream.fail()) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Cannot read 'data' chunk header form wave file"); - } - if (MakeFourCC('d', 'a', 't', 'a') != chunkHeader.ChunkId) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to search the wave file for the 'data' chunk"); - } - if (chunkHeader.ChunkSize <= 0) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Data chunk is empty"); - } - - std::vector audioData; - audioData.resize(chunkHeader.ChunkSize); - - for (auto & dest : audioData) { - dest = BinaryReader::Read(stream); - if (stream.fail()) { - break; - } - } - - if (!stream) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "Failed to read wave data"); - } - return audioData; -} - -} // unnamed namespace - -std::unique_ptr MSWaveAudioLoader::Load(BinaryFileStream && binaryFile) -{ - POMDOG_ASSERT(binaryFile.Stream); - POMDOG_ASSERT(binaryFile.SizeInBytes > 8); - - constexpr auto MinimumWaveFormatSizeInBytes = 4 * 11; - if (binaryFile.SizeInBytes < MinimumWaveFormatSizeInBytes) { - POMDOG_THROW_EXCEPTION(std::runtime_error, - "This wave file is too small."); - } - - auto & stream = binaryFile.Stream; - - stream.clear(); - stream.seekg(0, std::ios_base::beg); - - POMDOG_ASSERT(stream); - - try { - ReadRiffChunk(stream); - auto waveFormat = ReadWaveFormat(stream); - auto audioData = ReadWaveAudioData(stream); - - auto channels = ToAudioChannels(waveFormat.PcmWaveFormat.Channels); - -#if defined(POMDOG_PLATFORM_MACOSX) \ - || defined(POMDOG_PLATFORM_APPLE_IOS) \ - || defined(POMDOG_PLATFORM_LINUX) - using Detail::SoundSystem::OpenAL::AudioClipAL; - auto nativeAudioClip = std::make_unique( - audioData.data(), - audioData.size(), - waveFormat.PcmWaveFormat.SamplesPerSec, - waveFormat.PcmWaveFormat.BitsPerSample, - channels); - - auto audioClip = std::make_unique( - std::move(nativeAudioClip), - waveFormat.PcmWaveFormat.SamplesPerSec, - waveFormat.PcmWaveFormat.BitsPerSample, - channels); - - return audioClip; - -#elif defined(POMDOG_PLATFORM_WIN32) \ - || defined(POMDOG_PLATFORM_XBOX_ONE) - std::vector waveFormatData; - waveFormatData.resize(sizeof(waveFormat.PcmWaveFormat) - + sizeof(waveFormat.ExtraBytes) - + waveFormat.ExtraBytes); - - auto offset = sizeof(waveFormat.PcmWaveFormat) + sizeof(waveFormat.ExtraBytes); - std::memcpy(waveFormatData.data(), &waveFormat, offset); - std::memcpy(waveFormatData.data() + offset, waveFormat.ExtraData.data(), waveFormat.ExtraBytes); - - using Detail::SoundSystem::XAudio2::AudioClipXAudio2; - auto nativeAudioClip = std::make_unique( - std::move(audioData), - std::move(waveFormatData)); - - auto audioClip = std::make_unique( - std::move(nativeAudioClip), - waveFormat.PcmWaveFormat.SamplesPerSec, - waveFormat.PcmWaveFormat.BitsPerSample, - channels); - - return std::move(audioClip); -#endif - } - catch (const std::exception& e) { - if (stream.is_open()) { - stream.close(); - } -#if defined(DEBUG) && !defined(NDEBUG) - Log::Warning("Failed to read audio file.\n", e.what()); -#endif - throw e; - } -} - -} // namespace Pomdog::Detail diff --git a/src/Content/Utility/MSWaveAudioLoader.hpp b/src/Content/Utility/MSWaveAudioLoader.hpp deleted file mode 100644 index 426f6b804..000000000 --- a/src/Content/Utility/MSWaveAudioLoader.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. - -#pragma once - -#include "Pomdog/Audio/detail/ForwardDeclarations.hpp" -#include "Pomdog/Content/Utility/BinaryFileStream.hpp" -#include - -namespace Pomdog::Detail { - -struct MSWaveAudioLoader { - static std::unique_ptr Load(BinaryFileStream && binaryFile); -}; - -} // namespace Pomdog::Detail diff --git a/src/Content/Utility/PNGTextureReader.hpp b/src/Content/Utility/PNGTextureReader.hpp deleted file mode 100644 index 86096aa7e..000000000 --- a/src/Content/Utility/PNGTextureReader.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. - -#pragma once - -#include "Pomdog/Graphics/detail/ForwardDeclarations.hpp" -#include -#include -#include - -namespace Pomdog::Detail { - -struct PNGTextureReader { - static std::shared_ptr Read( - const std::shared_ptr& graphicsDevice, - const std::uint8_t* data, - std::size_t byteLength); -}; - -} // namespace Pomdog::Detail