From d7a88d240e66ff907ee384dd51fadca97d3158ca Mon Sep 17 00:00:00 2001 From: owen <1053210246@qq.com> Date: Thu, 16 May 2019 19:33:23 +0800 Subject: [PATCH 01/77] Sync native renderer to v2.3 --- .../cocos2d_libs.xcodeproj/project.pbxproj | 191 +- native/cocos/Android.mk | 12 +- native/cocos/base/ccConfig.h | 18 +- native/cocos/editor-support/MeshBuffer.cpp | 43 +- native/cocos/editor-support/MeshBuffer.h | 10 +- native/cocos/editor-support/MiddlewareMacro.h | 3 +- .../editor-support/MiddlewareManager.cpp | 4 - ...erInfoMgr.h => MiddlewareRenderHandle.cpp} | 89 +- ...erInfoMgr.cpp => MiddlewareRenderHandle.h} | 53 +- .../CCArmatureDisplay.cpp | 156 +- .../CCArmatureDisplay.h | 36 +- .../editor-support/middleware-adapter.cpp | 19 +- .../cocos/editor-support/middleware-adapter.h | 31 +- .../particle/ParticleSimulator.cpp | 462 +++ .../particle/ParticleSimulator.h | 280 ++ .../spine-creator-support/SpineAnimation.cpp | 768 ++--- .../spine-creator-support/SpineRenderer.cpp | 199 +- .../spine-creator-support/SpineRenderer.h | 371 +-- native/cocos/math/Vec3.cpp | 31 + native/cocos/math/Vec3.h | 23 + native/cocos/renderer/gfx/DeviceGraphics.cpp | 31 +- native/cocos/renderer/gfx/DeviceGraphics.h | 197 +- native/cocos/renderer/gfx/FrameBuffer.h | 61 +- native/cocos/renderer/gfx/GFX.cpp | 6 +- native/cocos/renderer/gfx/GFX.h | 6 +- native/cocos/renderer/gfx/GFXUtils.cpp | 6 +- native/cocos/renderer/gfx/GFXUtils.h | 6 +- native/cocos/renderer/gfx/GraphicsHandle.cpp | 6 +- native/cocos/renderer/gfx/GraphicsHandle.h | 21 +- native/cocos/renderer/gfx/IndexBuffer.cpp | 6 +- native/cocos/renderer/gfx/IndexBuffer.h | 78 +- native/cocos/renderer/gfx/Program.cpp | 6 +- native/cocos/renderer/gfx/Program.h | 79 +- native/cocos/renderer/gfx/RenderBuffer.cpp | 6 +- native/cocos/renderer/gfx/RenderBuffer.h | 28 +- native/cocos/renderer/gfx/RenderTarget.cpp | 6 +- native/cocos/renderer/gfx/RenderTarget.h | 17 +- native/cocos/renderer/gfx/State.cpp | 8 +- native/cocos/renderer/gfx/State.h | 182 +- native/cocos/renderer/gfx/Texture.cpp | 10 +- native/cocos/renderer/gfx/Texture.h | 105 +- native/cocos/renderer/gfx/Texture2D.cpp | 6 +- native/cocos/renderer/gfx/Texture2D.h | 45 +- native/cocos/renderer/gfx/VertexBuffer.cpp | 6 +- native/cocos/renderer/gfx/VertexBuffer.h | 71 +- native/cocos/renderer/gfx/VertexFormat.cpp | 26 +- native/cocos/renderer/gfx/VertexFormat.h | 98 +- .../cocos/renderer/renderer/BaseRenderer.cpp | 157 +- native/cocos/renderer/renderer/BaseRenderer.h | 45 +- native/cocos/renderer/renderer/Camera.cpp | 43 +- native/cocos/renderer/renderer/Camera.h | 150 +- native/cocos/renderer/renderer/Config.h | 25 + native/cocos/renderer/renderer/Effect.cpp | 67 +- native/cocos/renderer/renderer/Effect.h | 117 +- .../renderer/renderer/ForwardRenderer.cpp | 29 +- .../cocos/renderer/renderer/ForwardRenderer.h | 36 +- .../renderer/renderer/InputAssembler.cpp | 12 + .../cocos/renderer/renderer/InputAssembler.h | 52 +- native/cocos/renderer/renderer/Light.h | 158 +- native/cocos/renderer/renderer/Model.h | 68 +- native/cocos/renderer/renderer/Pass.cpp | 43 + native/cocos/renderer/renderer/Pass.h | 68 + native/cocos/renderer/renderer/ProgramLib.cpp | 28 +- native/cocos/renderer/renderer/ProgramLib.h | 41 +- native/cocos/renderer/renderer/Renderer.h | 6 +- .../cocos/renderer/renderer/RendererUtils.cpp | 6 +- .../cocos/renderer/renderer/RendererUtils.h | 6 +- native/cocos/renderer/renderer/Scene.cpp | 13 +- native/cocos/renderer/renderer/Scene.h | 107 +- native/cocos/renderer/renderer/Technique.cpp | 29 +- native/cocos/renderer/renderer/Technique.h | 105 +- native/cocos/renderer/renderer/View.h | 22 +- .../renderer/scene/CustomRenderHandle.cpp | 98 + .../renderer/scene/CustomRenderHandle.hpp | 141 + .../renderer/scene/GraphicsRenderHandle.cpp | 167 ++ .../renderer/scene/GraphicsRenderHandle.hpp | 83 + .../cocos/renderer/scene/MaskRenderHandle.cpp | 75 + .../cocos/renderer/scene/MaskRenderHandle.hpp | 63 + native/cocos/renderer/scene/MeshBuffer.cpp | 184 ++ native/cocos/renderer/scene/MeshBuffer.hpp | 181 ++ native/cocos/renderer/scene/ModelBatcher.cpp | 308 ++ native/cocos/renderer/scene/ModelBatcher.hpp | 138 + native/cocos/renderer/scene/NodeProxy.cpp | 429 +++ native/cocos/renderer/scene/NodeProxy.hpp | 281 ++ native/cocos/renderer/scene/RenderFlow.cpp | 54 + native/cocos/renderer/scene/RenderFlow.hpp | 89 + native/cocos/renderer/scene/RenderHandle.cpp | 248 ++ native/cocos/renderer/scene/RenderHandle.hpp | 176 ++ .../cocos/renderer/scene/StencilManager.cpp | 175 ++ .../cocos/renderer/scene/StencilManager.hpp | 113 + native/cocos/renderer/scene/SystemHandle.cpp | 25 + native/cocos/renderer/scene/SystemHandle.hpp | 89 + native/cocos/renderer/scene/scene-bindings.h | 33 + .../api/jsb_cocos2dx_dragonbones_auto_api.js | 38 +- .../jsb_cocos2dx_editor_support_auto_api.js | 66 +- .../api/jsb_cocos2dx_particle_auto_api.js | 248 ++ .../auto/api/jsb_cocos2dx_spine_auto_api.js | 58 +- .../js-bindings/auto/api/jsb_gfx_auto_api.js | 38 + .../auto/api/jsb_renderer_auto_api.js | 1268 +++++++- .../auto/jsb_cocos2dx_dragonbones_auto.cpp | 75 +- .../auto/jsb_cocos2dx_dragonbones_auto.hpp | 5 +- .../auto/jsb_cocos2dx_editor_support_auto.cpp | 173 +- .../auto/jsb_cocos2dx_editor_support_auto.hpp | 14 +- .../auto/jsb_cocos2dx_particle_auto.cpp | 1412 +++++++++ .../auto/jsb_cocos2dx_particle_auto.hpp | 34 + .../auto/jsb_cocos2dx_spine_auto.cpp | 123 +- .../auto/jsb_cocos2dx_spine_auto.hpp | 9 +- .../js-bindings/auto/jsb_gfx_auto.cpp | 73 + .../js-bindings/auto/jsb_gfx_auto.hpp | 4 + .../js-bindings/auto/jsb_renderer_auto.cpp | 2555 ++++++++++++++++- .../js-bindings/auto/jsb_renderer_auto.hpp | 176 +- .../js-bindings/event/EventDispatcher.cpp | 3 +- .../js-bindings/manual/jsb_conversions.cpp | 254 +- .../js-bindings/manual/jsb_conversions.hpp | 3 + .../manual/jsb_module_register.cpp | 8 + .../manual/jsb_renderer_manual.cpp | 269 +- native/templates/cocos2dx_files.json | 30 +- native/tools/tojs/cocos2dx_editor_support.ini | 8 +- native/tools/tojs/cocos2dx_particle.ini | 46 + native/tools/tojs/cocos2dx_spine.ini | 2 +- native/tools/tojs/genbindings.py | 1 + native/tools/tojs/renderer.ini | 15 +- 122 files changed, 13609 insertions(+), 1904 deletions(-) rename native/cocos/editor-support/{RenderInfoMgr.h => MiddlewareRenderHandle.cpp} (53%) rename native/cocos/editor-support/{RenderInfoMgr.cpp => MiddlewareRenderHandle.h} (58%) create mode 100644 native/cocos/editor-support/particle/ParticleSimulator.cpp create mode 100644 native/cocos/editor-support/particle/ParticleSimulator.h create mode 100644 native/cocos/renderer/scene/CustomRenderHandle.cpp create mode 100644 native/cocos/renderer/scene/CustomRenderHandle.hpp create mode 100644 native/cocos/renderer/scene/GraphicsRenderHandle.cpp create mode 100644 native/cocos/renderer/scene/GraphicsRenderHandle.hpp create mode 100644 native/cocos/renderer/scene/MaskRenderHandle.cpp create mode 100644 native/cocos/renderer/scene/MaskRenderHandle.hpp create mode 100644 native/cocos/renderer/scene/MeshBuffer.cpp create mode 100644 native/cocos/renderer/scene/MeshBuffer.hpp create mode 100644 native/cocos/renderer/scene/ModelBatcher.cpp create mode 100644 native/cocos/renderer/scene/ModelBatcher.hpp create mode 100644 native/cocos/renderer/scene/NodeProxy.cpp create mode 100644 native/cocos/renderer/scene/NodeProxy.hpp create mode 100644 native/cocos/renderer/scene/RenderFlow.cpp create mode 100644 native/cocos/renderer/scene/RenderFlow.hpp create mode 100644 native/cocos/renderer/scene/RenderHandle.cpp create mode 100644 native/cocos/renderer/scene/RenderHandle.hpp create mode 100644 native/cocos/renderer/scene/StencilManager.cpp create mode 100644 native/cocos/renderer/scene/StencilManager.hpp create mode 100644 native/cocos/renderer/scene/SystemHandle.cpp create mode 100644 native/cocos/renderer/scene/SystemHandle.hpp create mode 100644 native/cocos/renderer/scene/scene-bindings.h create mode 100644 native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_particle_auto_api.js create mode 100644 native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_particle_auto.cpp create mode 100644 native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_particle_auto.hpp create mode 100644 native/tools/tojs/cocos2dx_particle.ini diff --git a/native/build/cocos2d_libs.xcodeproj/project.pbxproj b/native/build/cocos2d_libs.xcodeproj/project.pbxproj index 84e2a70bd1..4cfd89458e 100644 --- a/native/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/native/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -7,6 +7,60 @@ objects = { /* Begin PBXBuildFile section */ + 04185457228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185455228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp */; }; + 04185458228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185455228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp */; }; + 04185459228D79BF00F8DF31 /* MiddlewareRenderHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 04185456228D79BF00F8DF31 /* MiddlewareRenderHandle.h */; }; + 0418545A228D79BF00F8DF31 /* MiddlewareRenderHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 04185456228D79BF00F8DF31 /* MiddlewareRenderHandle.h */; }; + 04185471228D7A0700F8DF31 /* ModelBatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545C228D7A0500F8DF31 /* ModelBatcher.cpp */; }; + 04185472228D7A0700F8DF31 /* ModelBatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545C228D7A0500F8DF31 /* ModelBatcher.cpp */; }; + 04185473228D7A0700F8DF31 /* GraphicsRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418545D228D7A0500F8DF31 /* GraphicsRenderHandle.hpp */; }; + 04185474228D7A0700F8DF31 /* GraphicsRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418545D228D7A0500F8DF31 /* GraphicsRenderHandle.hpp */; }; + 04185475228D7A0700F8DF31 /* NodeProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545E228D7A0500F8DF31 /* NodeProxy.cpp */; }; + 04185476228D7A0700F8DF31 /* NodeProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545E228D7A0500F8DF31 /* NodeProxy.cpp */; }; + 04185477228D7A0700F8DF31 /* StencilManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545F228D7A0500F8DF31 /* StencilManager.cpp */; }; + 04185478228D7A0700F8DF31 /* StencilManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418545F228D7A0500F8DF31 /* StencilManager.cpp */; }; + 04185479228D7A0700F8DF31 /* ModelBatcher.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185460228D7A0500F8DF31 /* ModelBatcher.hpp */; }; + 0418547A228D7A0700F8DF31 /* ModelBatcher.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185460228D7A0500F8DF31 /* ModelBatcher.hpp */; }; + 0418547B228D7A0700F8DF31 /* RenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185461228D7A0500F8DF31 /* RenderHandle.cpp */; }; + 0418547C228D7A0700F8DF31 /* RenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185461228D7A0500F8DF31 /* RenderHandle.cpp */; }; + 0418547D228D7A0700F8DF31 /* RenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185462228D7A0500F8DF31 /* RenderHandle.hpp */; }; + 0418547E228D7A0700F8DF31 /* RenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185462228D7A0500F8DF31 /* RenderHandle.hpp */; }; + 0418547F228D7A0700F8DF31 /* CustomRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185463228D7A0500F8DF31 /* CustomRenderHandle.cpp */; }; + 04185480228D7A0700F8DF31 /* CustomRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185463228D7A0500F8DF31 /* CustomRenderHandle.cpp */; }; + 04185481228D7A0700F8DF31 /* scene-bindings.h in Headers */ = {isa = PBXBuildFile; fileRef = 04185464228D7A0500F8DF31 /* scene-bindings.h */; }; + 04185482228D7A0700F8DF31 /* scene-bindings.h in Headers */ = {isa = PBXBuildFile; fileRef = 04185464228D7A0500F8DF31 /* scene-bindings.h */; }; + 04185483228D7A0700F8DF31 /* NodeProxy.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185465228D7A0600F8DF31 /* NodeProxy.hpp */; }; + 04185484228D7A0700F8DF31 /* NodeProxy.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185465228D7A0600F8DF31 /* NodeProxy.hpp */; }; + 04185485228D7A0700F8DF31 /* MeshBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185466228D7A0600F8DF31 /* MeshBuffer.cpp */; }; + 04185486228D7A0700F8DF31 /* MeshBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185466228D7A0600F8DF31 /* MeshBuffer.cpp */; }; + 04185487228D7A0700F8DF31 /* CustomRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185467228D7A0600F8DF31 /* CustomRenderHandle.hpp */; }; + 04185488228D7A0700F8DF31 /* CustomRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185467228D7A0600F8DF31 /* CustomRenderHandle.hpp */; }; + 04185489228D7A0700F8DF31 /* MaskRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185468228D7A0600F8DF31 /* MaskRenderHandle.hpp */; }; + 0418548A228D7A0700F8DF31 /* MaskRenderHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185468228D7A0600F8DF31 /* MaskRenderHandle.hpp */; }; + 0418548B228D7A0700F8DF31 /* MaskRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185469228D7A0600F8DF31 /* MaskRenderHandle.cpp */; }; + 0418548C228D7A0700F8DF31 /* MaskRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04185469228D7A0600F8DF31 /* MaskRenderHandle.cpp */; }; + 0418548D228D7A0700F8DF31 /* MeshBuffer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546A228D7A0600F8DF31 /* MeshBuffer.hpp */; }; + 0418548E228D7A0700F8DF31 /* MeshBuffer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546A228D7A0600F8DF31 /* MeshBuffer.hpp */; }; + 0418548F228D7A0700F8DF31 /* RenderFlow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546B228D7A0600F8DF31 /* RenderFlow.cpp */; }; + 04185490228D7A0700F8DF31 /* RenderFlow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546B228D7A0600F8DF31 /* RenderFlow.cpp */; }; + 04185491228D7A0700F8DF31 /* RenderFlow.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546C228D7A0600F8DF31 /* RenderFlow.hpp */; }; + 04185492228D7A0700F8DF31 /* RenderFlow.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546C228D7A0600F8DF31 /* RenderFlow.hpp */; }; + 04185493228D7A0700F8DF31 /* GraphicsRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546D228D7A0600F8DF31 /* GraphicsRenderHandle.cpp */; }; + 04185494228D7A0700F8DF31 /* GraphicsRenderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546D228D7A0600F8DF31 /* GraphicsRenderHandle.cpp */; }; + 04185495228D7A0700F8DF31 /* StencilManager.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546E228D7A0600F8DF31 /* StencilManager.hpp */; }; + 04185496228D7A0700F8DF31 /* StencilManager.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 0418546E228D7A0600F8DF31 /* StencilManager.hpp */; }; + 04185497228D7A0700F8DF31 /* SystemHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546F228D7A0700F8DF31 /* SystemHandle.cpp */; }; + 04185498228D7A0700F8DF31 /* SystemHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418546F228D7A0700F8DF31 /* SystemHandle.cpp */; }; + 04185499228D7A0700F8DF31 /* SystemHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185470228D7A0700F8DF31 /* SystemHandle.hpp */; }; + 0418549A228D7A0700F8DF31 /* SystemHandle.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 04185470228D7A0700F8DF31 /* SystemHandle.hpp */; }; + 0418549F228D7E5700F8DF31 /* ParticleSimulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418549D228D7E5700F8DF31 /* ParticleSimulator.cpp */; }; + 041854A0228D7E5700F8DF31 /* ParticleSimulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0418549D228D7E5700F8DF31 /* ParticleSimulator.cpp */; }; + 041854A1228D7E5700F8DF31 /* ParticleSimulator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0418549E228D7E5700F8DF31 /* ParticleSimulator.h */; }; + 041854A2228D7E5700F8DF31 /* ParticleSimulator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0418549E228D7E5700F8DF31 /* ParticleSimulator.h */; }; + 041854A5228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 041854A3228D7E7200F8DF31 /* jsb_cocos2dx_particle_auto.hpp */; }; + 041854A6228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 041854A3228D7E7200F8DF31 /* jsb_cocos2dx_particle_auto.hpp */; }; + 041854A7228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 041854A4228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp */; }; + 041854A8228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 041854A4228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp */; }; 0430122121DCF2B80007084D /* Atlas.c in Sources */ = {isa = PBXBuildFile; fileRef = 043011D021DCF2A70007084D /* Atlas.c */; }; 0430122221DCF2B80007084D /* Atlas.c in Sources */ = {isa = PBXBuildFile; fileRef = 043011D021DCF2A70007084D /* Atlas.c */; }; 0430122321DCF2B80007084D /* Attachment.h in Headers */ = {isa = PBXBuildFile; fileRef = 043011D121DCF2A70007084D /* Attachment.h */; }; @@ -395,10 +449,6 @@ 04F49F42222A777C00E5CAF1 /* SkeletonDataMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04F49F3F222A777C00E5CAF1 /* SkeletonDataMgr.cpp */; }; 04F49F43222A777C00E5CAF1 /* SkeletonDataMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F49F40222A777C00E5CAF1 /* SkeletonDataMgr.h */; }; 04F49F44222A777C00E5CAF1 /* SkeletonDataMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F49F40222A777C00E5CAF1 /* SkeletonDataMgr.h */; }; - 04F49F4D222B80C500E5CAF1 /* RenderInfoMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04F49F4B222B80C400E5CAF1 /* RenderInfoMgr.cpp */; }; - 04F49F4E222B80C500E5CAF1 /* RenderInfoMgr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04F49F4B222B80C400E5CAF1 /* RenderInfoMgr.cpp */; }; - 04F49F4F222B80C500E5CAF1 /* RenderInfoMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F49F4C222B80C400E5CAF1 /* RenderInfoMgr.h */; }; - 04F49F50222B80C500E5CAF1 /* RenderInfoMgr.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F49F4C222B80C400E5CAF1 /* RenderInfoMgr.h */; }; 1A14FD912080B4E300E10ABE /* CCGLUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A14FD8F2080B4E300E10ABE /* CCGLUtils.cpp */; }; 1A14FD922080B4E300E10ABE /* CCGLUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A14FD8F2080B4E300E10ABE /* CCGLUtils.cpp */; }; 1A14FD932080B4E300E10ABE /* CCGLUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A14FD902080B4E300E10ABE /* CCGLUtils.h */; }; @@ -1191,6 +1241,33 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 04185455228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MiddlewareRenderHandle.cpp; path = "../cocos/editor-support/MiddlewareRenderHandle.cpp"; sourceTree = ""; }; + 04185456228D79BF00F8DF31 /* MiddlewareRenderHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MiddlewareRenderHandle.h; path = "../cocos/editor-support/MiddlewareRenderHandle.h"; sourceTree = ""; }; + 0418545C228D7A0500F8DF31 /* ModelBatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ModelBatcher.cpp; path = ../scene/ModelBatcher.cpp; sourceTree = ""; }; + 0418545D228D7A0500F8DF31 /* GraphicsRenderHandle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = GraphicsRenderHandle.hpp; path = ../scene/GraphicsRenderHandle.hpp; sourceTree = ""; }; + 0418545E228D7A0500F8DF31 /* NodeProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NodeProxy.cpp; path = ../scene/NodeProxy.cpp; sourceTree = ""; }; + 0418545F228D7A0500F8DF31 /* StencilManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StencilManager.cpp; path = ../scene/StencilManager.cpp; sourceTree = ""; }; + 04185460228D7A0500F8DF31 /* ModelBatcher.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ModelBatcher.hpp; path = ../scene/ModelBatcher.hpp; sourceTree = ""; }; + 04185461228D7A0500F8DF31 /* RenderHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderHandle.cpp; path = ../scene/RenderHandle.cpp; sourceTree = ""; }; + 04185462228D7A0500F8DF31 /* RenderHandle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderHandle.hpp; path = ../scene/RenderHandle.hpp; sourceTree = ""; }; + 04185463228D7A0500F8DF31 /* CustomRenderHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomRenderHandle.cpp; path = ../scene/CustomRenderHandle.cpp; sourceTree = ""; }; + 04185464228D7A0500F8DF31 /* scene-bindings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "scene-bindings.h"; path = "../scene/scene-bindings.h"; sourceTree = ""; }; + 04185465228D7A0600F8DF31 /* NodeProxy.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = NodeProxy.hpp; path = ../scene/NodeProxy.hpp; sourceTree = ""; }; + 04185466228D7A0600F8DF31 /* MeshBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MeshBuffer.cpp; path = ../scene/MeshBuffer.cpp; sourceTree = ""; }; + 04185467228D7A0600F8DF31 /* CustomRenderHandle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = CustomRenderHandle.hpp; path = ../scene/CustomRenderHandle.hpp; sourceTree = ""; }; + 04185468228D7A0600F8DF31 /* MaskRenderHandle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MaskRenderHandle.hpp; path = ../scene/MaskRenderHandle.hpp; sourceTree = ""; }; + 04185469228D7A0600F8DF31 /* MaskRenderHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MaskRenderHandle.cpp; path = ../scene/MaskRenderHandle.cpp; sourceTree = ""; }; + 0418546A228D7A0600F8DF31 /* MeshBuffer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MeshBuffer.hpp; path = ../scene/MeshBuffer.hpp; sourceTree = ""; }; + 0418546B228D7A0600F8DF31 /* RenderFlow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderFlow.cpp; path = ../scene/RenderFlow.cpp; sourceTree = ""; }; + 0418546C228D7A0600F8DF31 /* RenderFlow.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderFlow.hpp; path = ../scene/RenderFlow.hpp; sourceTree = ""; }; + 0418546D228D7A0600F8DF31 /* GraphicsRenderHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GraphicsRenderHandle.cpp; path = ../scene/GraphicsRenderHandle.cpp; sourceTree = ""; }; + 0418546E228D7A0600F8DF31 /* StencilManager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = StencilManager.hpp; path = ../scene/StencilManager.hpp; sourceTree = ""; }; + 0418546F228D7A0700F8DF31 /* SystemHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SystemHandle.cpp; path = ../scene/SystemHandle.cpp; sourceTree = ""; }; + 04185470228D7A0700F8DF31 /* SystemHandle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SystemHandle.hpp; path = ../scene/SystemHandle.hpp; sourceTree = ""; }; + 0418549D228D7E5700F8DF31 /* ParticleSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ParticleSimulator.cpp; path = "../cocos/editor-support/particle/ParticleSimulator.cpp"; sourceTree = ""; }; + 0418549E228D7E5700F8DF31 /* ParticleSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticleSimulator.h; path = "../cocos/editor-support/particle/ParticleSimulator.h"; sourceTree = ""; }; + 041854A3228D7E7200F8DF31 /* jsb_cocos2dx_particle_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_cocos2dx_particle_auto.hpp; sourceTree = ""; }; + 041854A4228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsb_cocos2dx_particle_auto.cpp; sourceTree = ""; }; 043011D021DCF2A70007084D /* Atlas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Atlas.c; path = "../cocos/editor-support/spine/Atlas.c"; sourceTree = ""; }; 043011D121DCF2A70007084D /* Attachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Attachment.h; path = "../cocos/editor-support/spine/Attachment.h"; sourceTree = ""; }; 043011D221DCF2A70007084D /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BoundingBoxAttachment.h; path = "../cocos/editor-support/spine/BoundingBoxAttachment.h"; sourceTree = ""; }; @@ -1385,8 +1462,6 @@ 04ED68D721F8188F006E82F8 /* MeshBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MeshBuffer.h; path = "../cocos/editor-support/MeshBuffer.h"; sourceTree = ""; }; 04F49F3F222A777C00E5CAF1 /* SkeletonDataMgr.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = SkeletonDataMgr.cpp; path = "../cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp"; sourceTree = ""; }; 04F49F40222A777C00E5CAF1 /* SkeletonDataMgr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SkeletonDataMgr.h; path = "../cocos/editor-support/spine-creator-support/SkeletonDataMgr.h"; sourceTree = ""; }; - 04F49F4B222B80C400E5CAF1 /* RenderInfoMgr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderInfoMgr.cpp; path = "../cocos/editor-support/RenderInfoMgr.cpp"; sourceTree = ""; }; - 04F49F4C222B80C400E5CAF1 /* RenderInfoMgr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RenderInfoMgr.h; path = "../cocos/editor-support/RenderInfoMgr.h"; sourceTree = ""; }; 051C016F21E2F85C00D4A347 /* CCModuleConfigIOS.debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.debug.xcconfig; sourceTree = ""; }; 051C017021E2F85C00D4A347 /* CCModuleConfigIOS.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.release.xcconfig; sourceTree = ""; }; 051C017121E2F86900D4A347 /* CCModuleConfigMac.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigMac.release.xcconfig; sourceTree = ""; }; @@ -1906,9 +1981,48 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0418545B228D79E100F8DF31 /* scene */ = { + isa = PBXGroup; + children = ( + 04185463228D7A0500F8DF31 /* CustomRenderHandle.cpp */, + 04185467228D7A0600F8DF31 /* CustomRenderHandle.hpp */, + 0418546D228D7A0600F8DF31 /* GraphicsRenderHandle.cpp */, + 0418545D228D7A0500F8DF31 /* GraphicsRenderHandle.hpp */, + 04185469228D7A0600F8DF31 /* MaskRenderHandle.cpp */, + 04185468228D7A0600F8DF31 /* MaskRenderHandle.hpp */, + 04185466228D7A0600F8DF31 /* MeshBuffer.cpp */, + 0418546A228D7A0600F8DF31 /* MeshBuffer.hpp */, + 0418545C228D7A0500F8DF31 /* ModelBatcher.cpp */, + 04185460228D7A0500F8DF31 /* ModelBatcher.hpp */, + 0418545E228D7A0500F8DF31 /* NodeProxy.cpp */, + 04185465228D7A0600F8DF31 /* NodeProxy.hpp */, + 0418546B228D7A0600F8DF31 /* RenderFlow.cpp */, + 0418546C228D7A0600F8DF31 /* RenderFlow.hpp */, + 04185461228D7A0500F8DF31 /* RenderHandle.cpp */, + 04185462228D7A0500F8DF31 /* RenderHandle.hpp */, + 04185464228D7A0500F8DF31 /* scene-bindings.h */, + 0418545F228D7A0500F8DF31 /* StencilManager.cpp */, + 0418546E228D7A0600F8DF31 /* StencilManager.hpp */, + 0418546F228D7A0700F8DF31 /* SystemHandle.cpp */, + 04185470228D7A0700F8DF31 /* SystemHandle.hpp */, + ); + name = scene; + path = "New Group"; + sourceTree = ""; + }; + 0418549C228D7E4500F8DF31 /* particle */ = { + isa = PBXGroup; + children = ( + 0418549D228D7E5700F8DF31 /* ParticleSimulator.cpp */, + 0418549E228D7E5700F8DF31 /* ParticleSimulator.h */, + ); + name = particle; + sourceTree = ""; + }; 04355811217EADAC00B9C056 /* editor-support */ = { isa = PBXGroup; children = ( + 0418549C228D7E4500F8DF31 /* particle */, 046E040B2181A9BE00B24E2D /* dragonbones-creator-support */, 046E040321806AD400B24E2D /* dragonbones */, 046E03DE2180456A00B24E2D /* spine-creator-support */, @@ -1918,6 +2032,8 @@ 046E06F62189990700B24E2D /* middleware-adapter.h */, 04355812217EADB900B9C056 /* spine */, 04AF62FD219190ED00AED9DE /* TypedArrayPool.cpp */, + 04185455228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp */, + 04185456228D79BF00F8DF31 /* MiddlewareRenderHandle.h */, 04AF62FE219190ED00AED9DE /* TypedArrayPool.h */, 046B6888219FA61200B33469 /* MiddlewareManager.cpp */, 046B6889219FA61200B33469 /* MiddlewareManager.h */, @@ -1926,8 +2042,6 @@ 046B689421A10D5800B33469 /* MiddlewareMacro.h */, 04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */, 04ED68D721F8188F006E82F8 /* MeshBuffer.h */, - 04F49F4B222B80C400E5CAF1 /* RenderInfoMgr.cpp */, - 04F49F4C222B80C400E5CAF1 /* RenderInfoMgr.h */, ); name = "editor-support"; sourceTree = ""; @@ -2628,6 +2742,8 @@ 469302512046AE05004A3D6C /* auto */ = { isa = PBXGroup; children = ( + 041854A4228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp */, + 041854A3228D7E7200F8DF31 /* jsb_cocos2dx_particle_auto.hpp */, 046E06FB2189999500B24E2D /* jsb_cocos2dx_editor_support_auto.cpp */, 046E06FC2189999600B24E2D /* jsb_cocos2dx_editor_support_auto.hpp */, 046E0707218B015000B24E2D /* jsb_cocos2dx_dragonbones_auto.cpp */, @@ -2776,6 +2892,7 @@ 46FDDA2C202ACC6A00931238 /* renderer */ = { isa = PBXGroup; children = ( + 0418545B228D79E100F8DF31 /* scene */, 46FDDA2D202ACC6A00931238 /* renderer */, 46FDDA4C202ACC6A00931238 /* Types.cpp */, 46FDDA4E202ACC6A00931238 /* Types.h */, @@ -3141,6 +3258,7 @@ 46AE3FDD2092F3A600F3A228 /* inspector_socket_server.h in Headers */, 0430126721DCF2B80007084D /* Triangulator.h in Headers */, 4008729620CE20C2002EB77B /* jsb_cocos2dx_network_manual.h in Headers */, + 04185473228D7A0700F8DF31 /* GraphicsRenderHandle.hpp in Headers */, 469303EE2046AE05004A3D6C /* jsb_renderer_auto.hpp in Headers */, 4617863720522469008256E1 /* HttpClient.h in Headers */, 50ABBD461925AB0000A911A9 /* CCVertex.h in Headers */, @@ -3152,10 +3270,12 @@ 40CEAEB820CFDC47007A3281 /* CCReachability.h in Headers */, ED30579B1BEC77B70083C3ED /* ConvertUTF.h in Headers */, 46FDDA75202ACC6A00931238 /* Config.h in Headers */, + 0418548D228D7A0700F8DF31 /* MeshBuffer.hpp in Headers */, 0430127F21DCF2B80007084D /* TransformConstraintData.h in Headers */, 469303822046AE05004A3D6C /* Value.hpp in Headers */, 046B689521A10D5800B33469 /* MiddlewareMacro.h in Headers */, 46FDDAC3202ACC6A00931238 /* FrameBuffer.h in Headers */, + 04185483228D7A0700F8DF31 /* NodeProxy.hpp in Headers */, 4617863D20522469008256E1 /* HttpResponse.h in Headers */, 1A29D7A320566CAC00168D9A /* CCCanvasRenderingContext2D.h in Headers */, 1A29D77D2056667800168D9A /* csscolorparser.hpp in Headers */, @@ -3183,11 +3303,13 @@ 043012AB21DCF2B80007084D /* AnimationStateData.h in Headers */, 0430124721DCF2B80007084D /* Skin.h in Headers */, 0430123521DCF2B80007084D /* extension.h in Headers */, + 041854A5228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.hpp in Headers */, 4648882520AC2BC900CD1E4A /* CCRenderTexture.h in Headers */, 46FDDA97202ACC6A00931238 /* Model.h in Headers */, 046E06332185B41100B24E2D /* Animation.h in Headers */, 043012A121DCF2B80007084D /* VertexAttachment.h in Headers */, 50ABBD4A1925AB0000A911A9 /* Mat4.h in Headers */, + 04185491228D7A0700F8DF31 /* RenderFlow.hpp in Headers */, 0430128721DCF2B80007084D /* PathConstraintData.h in Headers */, 046E063F2185B41100B24E2D /* AnimationState.h in Headers */, 1A52DB38205BCD9200350EE3 /* ScriptEngine.hpp in Headers */, @@ -3208,6 +3330,7 @@ 46FDDB4D202ADDCE00931238 /* pvr.h in Headers */, 4617863920522469008256E1 /* CCDownloaderImpl-apple.h in Headers */, 1A52DB73205BCDC700350EE3 /* Base.h in Headers */, + 04185481228D7A0700F8DF31 /* scene-bindings.h in Headers */, 1A28FF551F20AFAB007A1D9D /* SRIOConsumerPool.h in Headers */, 461786632052607E008256E1 /* jsb_socketio.hpp in Headers */, 046E06BD2185B49F00B24E2D /* UserData.h in Headers */, @@ -3233,6 +3356,7 @@ 0430125D21DCF2B80007084D /* BoneData.h in Headers */, 50643BDB19BFAF4400EF68ED /* CCStdC.h in Headers */, 1A28FF591F20AFAB007A1D9D /* NSRunLoop+SRWebSocketPrivate.h in Headers */, + 04185489228D7A0700F8DF31 /* MaskRenderHandle.hpp in Headers */, 1A29D79A205666F500168D9A /* jsb_opengl_utils.hpp in Headers */, 0430123D21DCF2B80007084D /* spine.h in Headers */, 46FDDB5B202ADDCE00931238 /* CCData.h in Headers */, @@ -3262,7 +3386,7 @@ 46FDDA91202ACC6A00931238 /* Pass.h in Headers */, 046E069F2185B45300B24E2D /* Point.h in Headers */, 0430125F21DCF2B80007084D /* Atlas.h in Headers */, - 04F49F4F222B80C500E5CAF1 /* RenderInfoMgr.h in Headers */, + 04185459228D79BF00F8DF31 /* MiddlewareRenderHandle.h in Headers */, 46FDDAC7202ACC6A00931238 /* GFX.h in Headers */, 46FDDC63202D502F00931238 /* CCApplication.h in Headers */, 469303A42046AE05004A3D6C /* ScriptEngine.hpp in Headers */, @@ -3285,6 +3409,8 @@ 1A52DB5E205BCDC700350EE3 /* Class.hpp in Headers */, 4693039C2046AE05004A3D6C /* PlatformUtils.h in Headers */, 046E06C12185B49F00B24E2D /* TextureAtlasData.h in Headers */, + 041854A1228D7E5700F8DF31 /* ParticleSimulator.h in Headers */, + 04185479228D7A0700F8DF31 /* ModelBatcher.hpp in Headers */, 1AAAC8E5205CB6E9005321B9 /* AudioPlayer.h in Headers */, 1AAAC8ED205CB6E9005321B9 /* AudioCache.h in Headers */, 046E063D2185B41100B24E2D /* TimelineState.h in Headers */, @@ -3293,6 +3419,7 @@ 046E067B2185B42F00B24E2D /* DragonBonesHeaders.h in Headers */, 046E06C72185B49F00B24E2D /* DisplayData.h in Headers */, 46FDDADB202ACC6A00931238 /* State.h in Headers */, + 0418547D228D7A0700F8DF31 /* RenderHandle.hpp in Headers */, 1A29D771205665D200168D9A /* jsb_cocos2dx_manual.hpp in Headers */, 46AE3FFF2092F3A600F3A228 /* v8_inspector_protocol_json.h in Headers */, 046E03F121804E6B00B24E2D /* SpineAnimation.h in Headers */, @@ -3306,6 +3433,7 @@ 469304142046AE06004A3D6C /* jsb_renderer_manual.hpp in Headers */, 46FDDAD1202ACC6A00931238 /* Texture.h in Headers */, 1A52DB72205BCDC700350EE3 /* Utils.hpp in Headers */, + 04185487228D7A0700F8DF31 /* CustomRenderHandle.hpp in Headers */, 1A52DB70205BCDC700350EE3 /* SeApi.h in Headers */, 046E06DB2185B49F00B24E2D /* ConstraintData.h in Headers */, 1A28FF971F20AFAB007A1D9D /* SRSecurityPolicy.h in Headers */, @@ -3316,6 +3444,7 @@ 04AF6301219190ED00AED9DE /* TypedArrayPool.h in Headers */, 46AE3FE52092F3A600F3A228 /* base64.h in Headers */, 046E061E2185B37100B24E2D /* CCDragonBonesHeaders.h in Headers */, + 04185495228D7A0700F8DF31 /* StencilManager.hpp in Headers */, 50ABBD421925AB0000A911A9 /* CCMathBase.h in Headers */, 469303862046AE05004A3D6C /* Object.hpp in Headers */, 1A29D788205666B200168D9A /* LocalStorage.h in Headers */, @@ -3416,6 +3545,7 @@ 46FDDBB5202ADDCE00931238 /* uthash.h in Headers */, 1AAAC8DF205CB6E9005321B9 /* AudioDecoder.h in Headers */, 4617862520522469008256E1 /* CCDownloader.h in Headers */, + 04185499228D7A0700F8DF31 /* SystemHandle.hpp in Headers */, 1A28FF7D1F20AFAB007A1D9D /* SRMutex.h in Headers */, 1A28FF711F20AFAB007A1D9D /* SRHash.h in Headers */, 469301CF203FC696004A3D6C /* CCConfiguration.h in Headers */, @@ -3476,6 +3606,7 @@ 46AE3FE62092F3A600F3A228 /* base64.h in Headers */, 1A586C4A2064C97800B47573 /* EJConvert.h in Headers */, 46AE3FE82092F3A600F3A228 /* inspector_io.h in Headers */, + 04185484228D7A0700F8DF31 /* NodeProxy.hpp in Headers */, 1AAAC8E0205CB6E9005321B9 /* AudioDecoder.h in Headers */, 046E06D02185B49F00B24E2D /* BoundingBoxData.h in Headers */, 0430128621DCF2B80007084D /* PathConstraint.h in Headers */, @@ -3492,7 +3623,6 @@ 046E06652185B41B00B24E2D /* Armature.h in Headers */, 046E06692185B41B00B24E2D /* Constraint.h in Headers */, 046B689621A10D5800B33469 /* MiddlewareMacro.h in Headers */, - 04F49F50222B80C500E5CAF1 /* RenderInfoMgr.h in Headers */, 46FDDA82202ACC6A00931238 /* RendererUtils.h in Headers */, 40AEF7B7216D982600729AA5 /* jsb_webview_auto.hpp in Headers */, 50ABC0101926664800A911A9 /* CCFileUtils.h in Headers */, @@ -3507,12 +3637,14 @@ 46FDDAC8202ACC6A00931238 /* GFX.h in Headers */, 469303972046AE05004A3D6C /* Class.hpp in Headers */, 046E06F22185B4A500B24E2D /* BinaryDataParser.h in Headers */, + 041854A6228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.hpp in Headers */, 46FDDA98202ACC6A00931238 /* Model.h in Headers */, 469304112046AE06004A3D6C /* jsb_helper.hpp in Headers */, 1A52DAF7205BB81400350EE3 /* CCThreadPool.h in Headers */, 046E06192185B37100B24E2D /* CCTextureAtlasData.h in Headers */, 50ABBD5B1925AB0000A911A9 /* Vec2.h in Headers */, 4008729720CE20C2002EB77B /* jsb_cocos2dx_network_manual.h in Headers */, + 04185474228D7A0700F8DF31 /* GraphicsRenderHandle.hpp in Headers */, 50ABBD411925AB0000A911A9 /* CCMath.h in Headers */, 04355819217EADF300B9C056 /* IOBuffer.h in Headers */, 046E06342185B41100B24E2D /* Animation.h in Headers */, @@ -3537,6 +3669,7 @@ 46FDDBEA202ADDCE00931238 /* CCAutoreleasePool.h in Headers */, 461786642052607E008256E1 /* jsb_socketio.hpp in Headers */, 40AEF7C1216DF22500729AA5 /* jsb_video_auto.hpp in Headers */, + 0418547E228D7A0700F8DF31 /* RenderHandle.hpp in Headers */, 46AE40002092F3A600F3A228 /* v8_inspector_protocol_json.h in Headers */, 0430125E21DCF2B80007084D /* BoneData.h in Headers */, 0430128821DCF2B80007084D /* PathConstraintData.h in Headers */, @@ -3575,6 +3708,7 @@ 46FDDAD0202ACC6A00931238 /* RenderBuffer.h in Headers */, 1A28FF7A1F20AFAB007A1D9D /* SRLog.h in Headers */, 46AE3FF42092F3A600F3A228 /* node.h in Headers */, + 0418548A228D7A0700F8DF31 /* MaskRenderHandle.hpp in Headers */, 46FDDC64202D502F00931238 /* CCApplication.h in Headers */, 0430126021DCF2B80007084D /* Atlas.h in Headers */, 046E06D82185B49F00B24E2D /* AnimationConfig.h in Headers */, @@ -3587,14 +3721,17 @@ 046E06632185B41B00B24E2D /* Slot.h in Headers */, 4693045B2046AE06004A3D6C /* EventDispatcher.h in Headers */, 046E06BE2185B49F00B24E2D /* UserData.h in Headers */, + 04185496228D7A0700F8DF31 /* StencilManager.hpp in Headers */, 46FDDAA2202ACC6A00931238 /* InputAssembler.h in Headers */, 046E06612185B41B00B24E2D /* DeformVertices.h in Headers */, 46FDDBCC202ADDCE00931238 /* ZipUtils.h in Headers */, + 04185492228D7A0700F8DF31 /* RenderFlow.hpp in Headers */, 046E06462185B41100B24E2D /* IAnimatable.h in Headers */, 046E06E02185B49F00B24E2D /* DragonBonesData.h in Headers */, 04AF6302219190ED00AED9DE /* TypedArrayPool.h in Headers */, 46FDDB50202ADDCE00931238 /* CCValue.h in Headers */, 46FDDADA202ACC6A00931238 /* Program.h in Headers */, + 0418547A228D7A0700F8DF31 /* ModelBatcher.hpp in Headers */, 0430122C21DCF2B80007084D /* ClippingAttachment.h in Headers */, 46FDDAC4202ACC6A00931238 /* FrameBuffer.h in Headers */, 46FDDAD2202ACC6A00931238 /* Texture.h in Headers */, @@ -3629,6 +3766,7 @@ 1AAAC8F4205CB6E9005321B9 /* AudioEngine.h in Headers */, 046B68A921A292D300B33469 /* jsb_spine_manual.hpp in Headers */, 46FDDA78202ACC6A00931238 /* Light.h in Headers */, + 0418548E228D7A0700F8DF31 /* MeshBuffer.hpp in Headers */, 0430125A21DCF2B80007084D /* AtlasAttachmentLoader.h in Headers */, 1A29D7A420566CAC00168D9A /* CCCanvasRenderingContext2D.h in Headers */, 0430122E21DCF2B80007084D /* Animation.h in Headers */, @@ -3657,6 +3795,7 @@ 043012AC21DCF2B80007084D /* AnimationStateData.h in Headers */, 046E069E2185B45300B24E2D /* Transform.h in Headers */, 046E070C218B015100B24E2D /* jsb_cocos2dx_dragonbones_auto.hpp in Headers */, + 0418545A228D79BF00F8DF31 /* MiddlewareRenderHandle.h in Headers */, 046E03F221804E6B00B24E2D /* SpineAnimation.h in Headers */, 046E06152185B37100B24E2D /* CCArmatureDisplay.h in Headers */, 0430127021DCF2B80007084D /* PathAttachment.h in Headers */, @@ -3684,7 +3823,9 @@ 1A29D789205666B200168D9A /* LocalStorage.h in Headers */, 046E0712218B01EF00B24E2D /* jsb_dragonbones_manual.hpp in Headers */, 46FDDC67202D504E00931238 /* CCApplication.h in Headers */, + 04185482228D7A0700F8DF31 /* scene-bindings.h in Headers */, 046E06772185B42500B24E2D /* DragonBones.h in Headers */, + 041854A2228D7E5700F8DF31 /* ParticleSimulator.h in Headers */, 46AE3FE42092F3A600F3A228 /* inspector_agent.h in Headers */, 046E06C82185B49F00B24E2D /* DisplayData.h in Headers */, 0430125821DCF2B80007084D /* Bone.h in Headers */, @@ -3705,6 +3846,7 @@ 1A14FD942080B4E300E10ABE /* CCGLUtils.h in Headers */, 50ABBD5F1925AB0000A911A9 /* Vec3.h in Headers */, 46FDDC02202ADDCE00931238 /* ccCArray.h in Headers */, + 04185488228D7A0700F8DF31 /* CustomRenderHandle.hpp in Headers */, 1A29D79F205666F500168D9A /* jsb_opengl_manual.hpp in Headers */, 46FDDAE0202ACC6A00931238 /* RenderTarget.h in Headers */, 046E06B82185B49F00B24E2D /* AnimationData.h in Headers */, @@ -3728,6 +3870,7 @@ 46178671205262BC008256E1 /* jsb_conversions.hpp in Headers */, 0430122621DCF2B80007084D /* BoundingBoxAttachment.h in Headers */, 469304212046AE06004A3D6C /* jsb_gfx_manual.hpp in Headers */, + 0418549A228D7A0700F8DF31 /* SystemHandle.hpp in Headers */, 04F49F44222A777C00E5CAF1 /* SkeletonDataMgr.h in Headers */, 50ABC01C1926664800A911A9 /* CCSAXParser.h in Headers */, 0430125C21DCF2B80007084D /* RegionAttachment.h in Headers */, @@ -3830,12 +3973,15 @@ 04355816217EADF300B9C056 /* IOBuffer.cpp in Sources */, 043012B721DCF2B80007084D /* VertexAttachment.c in Sources */, 1A52DAF8205BB81400350EE3 /* CCThreadPool.cpp in Sources */, + 04185497228D7A0700F8DF31 /* SystemHandle.cpp in Sources */, + 04185475228D7A0700F8DF31 /* NodeProxy.cpp in Sources */, 46AE3FFB2092F3A600F3A228 /* inspector_io.cc in Sources */, 0430129521DCF2B80007084D /* Event.c in Sources */, 4037F5CE2108751E001C205C /* CCAsyncTaskPool.cpp in Sources */, 46FDDB65202ADDCE00931238 /* ccRandom.cpp in Sources */, 46FDDAB9202ACC6A00931238 /* FrameBuffer.cpp in Sources */, 50ABBD581925AB0000A911A9 /* Vec2.cpp in Sources */, + 0418548F228D7A0700F8DF31 /* RenderFlow.cpp in Sources */, 043012A721DCF2B80007084D /* Array.c in Sources */, 0430124521DCF2B80007084D /* Json.c in Sources */, 4626B1FF202D9BD800BE30B9 /* CCApplication-mac.mm in Sources */, @@ -3846,9 +3992,11 @@ 0430128321DCF2B80007084D /* Skin.c in Sources */, 1AAAC8EB205CB6E9005321B9 /* AudioCache.mm in Sources */, 4648882720AC2BC900CD1E4A /* CCRenderTexture.cpp in Sources */, + 041854A7228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp in Sources */, 46AE3FF92092F3A600F3A228 /* inspector_socket.cc in Sources */, 1A52DB61205BCDC700350EE3 /* Object.cpp in Sources */, 50ABBD501925AB0000A911A9 /* Quaternion.cpp in Sources */, + 0418549F228D7E5700F8DF31 /* ParticleSimulator.cpp in Sources */, ED30579A1BEC77B70083C3ED /* ConvertUTF.c in Sources */, 046E06C92185B49F00B24E2D /* UserData.cpp in Sources */, 46FDDA79202ACC6A00931238 /* Camera.cpp in Sources */, @@ -3856,6 +4004,7 @@ 0430125121DCF2B80007084D /* TransformConstraintData.c in Sources */, 46FDDAC1202ACC6A00931238 /* Texture.cpp in Sources */, 1A28FF6B1F20AFAB007A1D9D /* SRConstants.m in Sources */, + 0418547B228D7A0700F8DF31 /* RenderHandle.cpp in Sources */, 294D7D9C1D0E93A2002CE7B7 /* CCDevice-apple.mm in Sources */, 0430127121DCF2B80007084D /* SkeletonBounds.c in Sources */, 043012A921DCF2B80007084D /* Animation.c in Sources */, @@ -3908,11 +4057,11 @@ 0430123121DCF2B80007084D /* VertexEffect.c in Sources */, 50ABBD4C1925AB0000A911A9 /* MathUtil.cpp in Sources */, 046E06C52185B49F00B24E2D /* AnimationConfig.cpp in Sources */, - 04F49F4D222B80C500E5CAF1 /* RenderInfoMgr.cpp in Sources */, 46FDDA99202ACC6A00931238 /* Model.cpp in Sources */, 4693038E2046AE05004A3D6C /* Value.cpp in Sources */, 46FDDA89202ACC6A00931238 /* Effect.cpp in Sources */, 1ABAD24E20C29F3800BC71C0 /* CCCanvasRenderingContext2D-apple.mm in Sources */, + 04185485228D7A0700F8DF31 /* MeshBuffer.cpp in Sources */, 043012AF21DCF2B80007084D /* SkeletonJson.c in Sources */, 046E06E12185B49F00B24E2D /* DragonBonesData.cpp in Sources */, ED30577E1BEC76C90083C3ED /* ioapi_mem.cpp in Sources */, @@ -3927,6 +4076,7 @@ 1A28FF5F1F20AFAB007A1D9D /* SRProxyConnect.m in Sources */, 46FDDB8B202ADDCE00931238 /* CCAutoreleasePool.cpp in Sources */, 046E03FD21804E6B00B24E2D /* AttachmentVertices.cpp in Sources */, + 04185477228D7A0700F8DF31 /* StencilManager.cpp in Sources */, 0430129F21DCF2B80007084D /* SkeletonBinary.c in Sources */, 046E06432185B41100B24E2D /* Animation.cpp in Sources */, 046E06312185B41100B24E2D /* BaseTimelineState.cpp in Sources */, @@ -3960,6 +4110,7 @@ 46FDDAA9202ACC6A00931238 /* Types.cpp in Sources */, 1A28FF4F1F20AFAB007A1D9D /* SRDelegateController.m in Sources */, 0430128121DCF2B80007084D /* AtlasAttachmentLoader.c in Sources */, + 0418547F228D7A0700F8DF31 /* CustomRenderHandle.cpp in Sources */, 46FDDBFB202ADDCE00931238 /* ccCArray.cpp in Sources */, 1AAAC8E1205CB6E9005321B9 /* AudioPlayer.mm in Sources */, 1A28FF631F20AFAB007A1D9D /* SRRunLoopThread.m in Sources */, @@ -3976,6 +4127,7 @@ 46FDDAC5202ACC6A00931238 /* RenderTarget.cpp in Sources */, 1A52DB6D205BCDC700350EE3 /* ScriptEngine.cpp in Sources */, 50ABBD3C1925AB0000A911A9 /* CCGeometry.cpp in Sources */, + 04185493228D7A0700F8DF31 /* GraphicsRenderHandle.cpp in Sources */, 1A28FF771F20AFAB007A1D9D /* SRHTTPConnectMessage.m in Sources */, 46FDDB99202ADDCE00931238 /* ccUTF8.cpp in Sources */, 4617862F20522469008256E1 /* HttpClient-apple.mm in Sources */, @@ -4059,6 +4211,7 @@ ED3057A11BEC77D50083C3ED /* xxhash.c in Sources */, 46FDDA6F202ACC6A00931238 /* Pass.cpp in Sources */, 4617863520522469008256E1 /* HttpAsynConnection-apple.m in Sources */, + 04185471228D7A0700F8DF31 /* ModelBatcher.cpp in Sources */, 043012B121DCF2B80007084D /* extension.c in Sources */, 461786612052607E008256E1 /* jsb_socketio.cpp in Sources */, 1A28FF8B1F20AFAB007A1D9D /* SRURLUtilities.m in Sources */, @@ -4068,6 +4221,7 @@ 46FDDB8F202ADDCE00931238 /* ccUtils.cpp in Sources */, 046E06FD2189999600B24E2D /* jsb_cocos2dx_editor_support_auto.cpp in Sources */, 046E065C2185B41B00B24E2D /* Constraint.cpp in Sources */, + 04185457228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp in Sources */, 0430124F21DCF2B80007084D /* Skeleton.c in Sources */, 1A29D796205666F500168D9A /* jsb_opengl_utils.cpp in Sources */, BA21055A21009A2600E19975 /* AssetsManagerEx.cpp in Sources */, @@ -4075,6 +4229,7 @@ BA21055B21009A2900E19975 /* CCEventAssetsManagerEx.cpp in Sources */, 046E06822185B43B00B24E2D /* EventObject.cpp in Sources */, 046B68A621A292D300B33469 /* jsb_spine_manual.cpp in Sources */, + 0418548B228D7A0700F8DF31 /* MaskRenderHandle.cpp in Sources */, BA21055C21009A2C00E19975 /* Manifest.cpp in Sources */, 046E06392185B41100B24E2D /* WorldClock.cpp in Sources */, 1A28FF931F20AFAB007A1D9D /* NSURLRequest+SRWebSocket.m in Sources */, @@ -4090,6 +4245,7 @@ 46FDDA9E202ACC6A00931238 /* BaseRenderer.cpp in Sources */, 1A586C462064C90500B47573 /* EJConvertTypedArray.m in Sources */, 46FDDAC6202ACC6A00931238 /* RenderTarget.cpp in Sources */, + 04185490228D7A0700F8DF31 /* RenderFlow.cpp in Sources */, 4617864820522469008256E1 /* CCDownloaderImpl-apple.mm in Sources */, 0430129021DCF2B80007084D /* PathAttachment.c in Sources */, 046E066D2185B41B00B24E2D /* Slot.cpp in Sources */, @@ -4118,6 +4274,7 @@ 046E06892185B44A00B24E2D /* BaseFactory.cpp in Sources */, 1A28FF801F20AFAB007A1D9D /* SRMutex.m in Sources */, 046E06FE2189999600B24E2D /* jsb_cocos2dx_editor_support_auto.cpp in Sources */, + 04185498228D7A0700F8DF31 /* SystemHandle.cpp in Sources */, 46AE400C2092F3A600F3A228 /* env.cc in Sources */, 46FDDC69202D733800931238 /* CCApplication-ios.mm in Sources */, ED3057C21BEC78A80083C3ED /* xxhash.c in Sources */, @@ -4192,7 +4349,6 @@ 1A52DAF9205BB81400350EE3 /* CCThreadPool.cpp in Sources */, 4617864A20522469008256E1 /* CCDownloader.cpp in Sources */, 46FDDAD6202ACC6A00931238 /* GraphicsHandle.cpp in Sources */, - 04F49F4E222B80C500E5CAF1 /* RenderInfoMgr.cpp in Sources */, 046E063A2185B41100B24E2D /* WorldClock.cpp in Sources */, 50ABBD611925AB0000A911A9 /* Vec4.cpp in Sources */, 46FDDB9A202ADDCE00931238 /* ccUTF8.cpp in Sources */, @@ -4202,6 +4358,7 @@ 1A52DB7A205BCDD000350EE3 /* ScriptEngine.cpp in Sources */, 1A14FD922080B4E300E10ABE /* CCGLUtils.cpp in Sources */, 1A28FF741F20AFAB007A1D9D /* SRHash.m in Sources */, + 04185480228D7A0700F8DF31 /* CustomRenderHandle.cpp in Sources */, 46FDDB70202ADDCE00931238 /* ZipUtils.cpp in Sources */, 50ABBD511925AB0000A911A9 /* Quaternion.cpp in Sources */, 46930469204FE20F004A3D6C /* CCLog.cpp in Sources */, @@ -4252,6 +4409,7 @@ 4617862220522469008256E1 /* HttpCookie.cpp in Sources */, 46FDDAE2202ACC6A00931238 /* GFXUtils.cpp in Sources */, 1A586C4C2064C97800B47573 /* EJConvert.m in Sources */, + 04185476228D7A0700F8DF31 /* NodeProxy.cpp in Sources */, 469304272046AE06004A3D6C /* jsb_conversions.cpp in Sources */, 046E03F021804E6B00B24E2D /* SpineAnimation.cpp in Sources */, 46AE40042092F3A600F3A228 /* http_parser.c in Sources */, @@ -4259,6 +4417,7 @@ 0430129821DCF2B80007084D /* Attachment.c in Sources */, 046E06EC2185B4A500B24E2D /* DataParser.cpp in Sources */, 46FDDA7A202ACC6A00931238 /* Camera.cpp in Sources */, + 04185458228D79BF00F8DF31 /* MiddlewareRenderHandle.cpp in Sources */, 461786602052607E008256E1 /* jsb_xmlhttprequest.cpp in Sources */, 46FDDAA0202ACC6A00931238 /* ProgramLib.cpp in Sources */, 4617863420522469008256E1 /* Uri.cpp in Sources */, @@ -4271,6 +4430,7 @@ 1A28FF541F20AFAB007A1D9D /* SRIOConsumer.m in Sources */, 046B68A721A292D300B33469 /* jsb_spine_manual.cpp in Sources */, 469303692046AE05004A3D6C /* State.cpp in Sources */, + 0418547C228D7A0700F8DF31 /* RenderHandle.cpp in Sources */, 46FDDAAA202ACC6A00931238 /* Types.cpp in Sources */, 1A29D797205666F500168D9A /* jsb_opengl_utils.cpp in Sources */, 046E06E22185B49F00B24E2D /* DragonBonesData.cpp in Sources */, @@ -4296,6 +4456,7 @@ 4617861A20522469008256E1 /* SocketIO.cpp in Sources */, 46FDDB72202ADDCE00931238 /* base64.cpp in Sources */, 46FDDA7E202ACC6A00931238 /* Light.cpp in Sources */, + 04185486228D7A0700F8DF31 /* MeshBuffer.cpp in Sources */, 469303AB2046AE05004A3D6C /* Class.cpp in Sources */, 046E065D2185B41B00B24E2D /* Constraint.cpp in Sources */, 046E06672185B41B00B24E2D /* Bone.cpp in Sources */, @@ -4305,6 +4466,8 @@ 1AAAC8EC205CB6E9005321B9 /* AudioCache.mm in Sources */, 46FDDBE4202ADDCE00931238 /* CCData.cpp in Sources */, 0430127421DCF2B80007084D /* SlotData.c in Sources */, + 04185494228D7A0700F8DF31 /* GraphicsRenderHandle.cpp in Sources */, + 0418548C228D7A0700F8DF31 /* MaskRenderHandle.cpp in Sources */, 0430129621DCF2B80007084D /* Event.c in Sources */, 469304592046AE06004A3D6C /* EventDispatcher.cpp in Sources */, 46FDDAB4202ACC6A00931238 /* VertexBuffer.cpp in Sources */, @@ -4330,15 +4493,18 @@ 0430129A21DCF2B80007084D /* AnimationStateData.c in Sources */, 461786662052607E008256E1 /* jsb_websocket.cpp in Sources */, 046E06172185B37100B24E2D /* CCSlot.cpp in Sources */, + 041854A8228D7E7300F8DF31 /* jsb_cocos2dx_particle_auto.cpp in Sources */, 50ABC0001926664800A911A9 /* CCFileUtils-apple.mm in Sources */, 0430128A21DCF2B80007084D /* IkConstraint.c in Sources */, 4DC57D331F7B840E005B6546 /* xxtea.cpp in Sources */, + 041854A0228D7E5700F8DF31 /* ParticleSimulator.cpp in Sources */, 1A29D77C2056667800168D9A /* csscolorparser.cpp in Sources */, 046E06D42185B49F00B24E2D /* SkinData.cpp in Sources */, 46FDDA8E202ACC6A00931238 /* Config.cpp in Sources */, 1A29D795205666F500168D9A /* jsb_opengl_manual.cpp in Sources */, 46AE3FFC2092F3A600F3A228 /* inspector_io.cc in Sources */, 4648882820AC2BC900CD1E4A /* CCRenderTexture.cpp in Sources */, + 04185478228D7A0700F8DF31 /* StencilManager.cpp in Sources */, 503DD8E31926736A00CD74DD /* CCDevice-ios.mm in Sources */, 1A28FF701F20AFAB007A1D9D /* SRError.m in Sources */, 1A28FF501F20AFAB007A1D9D /* SRDelegateController.m in Sources */, @@ -4347,6 +4513,7 @@ BA21055E21009A5700E19975 /* AssetsManagerEx.cpp in Sources */, BA21055F21009A5A00E19975 /* CCEventAssetsManagerEx.cpp in Sources */, BA21055D21009A5500E19975 /* Manifest.cpp in Sources */, + 04185472228D7A0700F8DF31 /* ModelBatcher.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/native/cocos/Android.mk b/native/cocos/Android.mk index 4d5514739d..ed9b4893f3 100644 --- a/native/cocos/Android.mk +++ b/native/cocos/Android.mk @@ -136,6 +136,16 @@ renderer/renderer/Scene.cpp \ renderer/renderer/Technique.cpp \ renderer/renderer/View.cpp \ renderer/renderer/ForwardRenderer.cpp \ +renderer/scene/CustomRenderHandle.cpp \ +renderer/scene/MeshBuffer.cpp \ +renderer/scene/ModelBatcher.cpp \ +renderer/scene/NodeProxy.cpp \ +renderer/scene/RenderFlow.cpp \ +renderer/scene/StencilManager.cpp \ +renderer/scene/RenderHandle.cpp \ +renderer/scene/SystemHandle.cpp \ +renderer/scene/GraphicsRenderHandle.cpp \ +renderer/scene/MaskRenderHandle.cpp \ scripting/js-bindings/auto/jsb_gfx_auto.cpp \ scripting/js-bindings/auto/jsb_renderer_auto.cpp \ scripting/js-bindings/manual/jsb_renderer_manual.cpp \ @@ -174,7 +184,7 @@ endif # USE_SOCKET ifneq ($(USE_MIDDLEWARE),0) LOCAL_STATIC_LIBRARIES += editor_support_static -endif # USE_SPINE or USE_DRAGONBONES +endif # USE_MIDDLEWARE LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/.. \ diff --git a/native/cocos/base/ccConfig.h b/native/cocos/base/ccConfig.h index 7351fc8f60..6570b56311 100644 --- a/native/cocos/base/ccConfig.h +++ b/native/cocos/base/ccConfig.h @@ -39,7 +39,7 @@ THE SOFTWARE. // disable module if you didn't need it, this will reduce package size #ifndef USE_GFX_RENDERER -#define USE_GFX_RENDERER 0 +#define USE_GFX_RENDERER 1 #endif #ifndef USE_VIDEO @@ -62,12 +62,18 @@ THE SOFTWARE. #define USE_MIDDLEWARE 1 #endif -#ifndef USE_SPINE -#define USE_SPINE 1 -#endif +#if USE_MIDDLEWARE > 0 + #ifndef USE_SPINE + #define USE_SPINE 1 + #endif -#ifndef USE_DRAGONBONES -#define USE_DRAGONBONES 1 + #ifndef USE_DRAGONBONES + #define USE_DRAGONBONES 1 + #endif + + #ifndef USE_PARTICLE + #define USE_PARTICLE 1 + #endif #endif /** @def CC_ENABLE_STACKABLE_ACTIONS diff --git a/native/cocos/editor-support/MeshBuffer.cpp b/native/cocos/editor-support/MeshBuffer.cpp index 5967c938b6..8713036878 100644 --- a/native/cocos/editor-support/MeshBuffer.cpp +++ b/native/cocos/editor-support/MeshBuffer.cpp @@ -24,6 +24,10 @@ #include "MeshBuffer.h" #include "base/CCGLUtils.h" +#include "renderer/gfx/DeviceGraphics.h" + +using namespace cocos2d; +using namespace cocos2d::renderer; MIDDLEWARE_BEGIN @@ -41,11 +45,13 @@ MeshBuffer::MeshBuffer(int vertexSize) next(); }); - _glIBArr.resize(1); - glGenBuffers(1, &_glIBArr[0]); + auto glIB = new IndexBuffer(); + glIB->init(DeviceGraphics::getInstance(), IndexFormat::UINT16, Usage::STATIC, nullptr, 0, (uint32_t)_ib.getCapacity() / sizeof(unsigned short)); + _glIBArr.push_back(glIB); - _glVBArr.resize(1); - glGenBuffers(1, &_glVBArr[0]); + auto glVB = new VertexBuffer(); + glVB->init(DeviceGraphics::getInstance(), VertexFormat::XY_UV_Color, Usage::DYNAMIC, nullptr, 0, (uint32_t)_vb.getCapacity() / VertexFormat::XY_UV_Color->getBytes()); + _glVBArr.push_back(glVB); } MeshBuffer::~MeshBuffer() @@ -53,8 +59,8 @@ MeshBuffer::~MeshBuffer() auto num = _glVBArr.size(); for (auto i = 0; i < num; i++) { - cocos2d::ccDeleteBuffers(1, &_glIBArr[i]); - cocos2d::ccDeleteBuffers(1, &_glVBArr[i]); + delete _glIBArr[i]; + delete _glVBArr[i]; } _glIBArr.clear(); _glVBArr.clear(); @@ -64,11 +70,10 @@ void MeshBuffer::uploadVB() { auto length = _vb.length(); if (length == 0) return; - + auto glVB = _glVBArr[_bufferPos]; - cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, glVB); - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)length, _vb.getBuffer(), GL_DYNAMIC_DRAW); - cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, 0); + glVB->setBytes((uint32_t)length); + glVB->update(0, _vb.getBuffer(), length); } void MeshBuffer::uploadIB() @@ -76,13 +81,9 @@ void MeshBuffer::uploadIB() auto length = _ib.length(); if (length == 0) return; - GLint _oldGLID = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &_oldGLID); - auto glIB = _glIBArr[_bufferPos]; - cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glIB); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)length, _ib.getBuffer(), GL_STATIC_DRAW); - cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _oldGLID); + glIB->setBytes((uint32_t)length); + glIB->update(0, _ib.getBuffer(), length); } void MeshBuffer::next() @@ -90,14 +91,16 @@ void MeshBuffer::next() _bufferPos++; if (_glIBArr.size() <= _bufferPos) { - _glIBArr.resize(_bufferPos + 1); - glGenBuffers(1, &_glIBArr[_bufferPos]); + auto glIB = new IndexBuffer(); + glIB->init(DeviceGraphics::getInstance(), IndexFormat::UINT16, Usage::STATIC, nullptr, 0, (uint32_t)_ib.getCapacity() / sizeof(unsigned short)); + _glIBArr.push_back(glIB); } if (_glVBArr.size() <= _bufferPos) { - _glVBArr.resize(_bufferPos + 1); - glGenBuffers(1, &_glVBArr[_bufferPos]); + auto glVB = new VertexBuffer(); + glVB->init(DeviceGraphics::getInstance(), VertexFormat::XY_UV_Color, Usage::DYNAMIC, nullptr, 0, (uint32_t)_vb.getCapacity() / VertexFormat::XY_UV_Color->getBytes()); + _glVBArr.push_back(glVB); } } diff --git a/native/cocos/editor-support/MeshBuffer.h b/native/cocos/editor-support/MeshBuffer.h index 7898e0a5e6..7fe802ef2a 100644 --- a/native/cocos/editor-support/MeshBuffer.h +++ b/native/cocos/editor-support/MeshBuffer.h @@ -25,6 +25,8 @@ #include "IOBuffer.h" #include +#include "renderer/gfx/VertexBuffer.h" +#include "renderer/gfx/IndexBuffer.h" MIDDLEWARE_BEGIN @@ -34,12 +36,12 @@ public: MeshBuffer(int vertexFormat); ~MeshBuffer(); - uint32_t getGLVB() + inline cocos2d::renderer::VertexBuffer* getGLVB() { return _glVBArr[_bufferPos]; } - uint32_t getGLIB() + inline cocos2d::renderer::IndexBuffer* getGLIB() { return _glIBArr[_bufferPos]; } @@ -60,8 +62,8 @@ public: private: void next(); private: - std::vector _glIBArr; - std::vector _glVBArr; + std::vector _glIBArr; + std::vector _glVBArr; std::size_t _bufferPos = 0; IOBuffer _vb; diff --git a/native/cocos/editor-support/MiddlewareMacro.h b/native/cocos/editor-support/MiddlewareMacro.h index 155b6abe71..14ed4b68f7 100644 --- a/native/cocos/editor-support/MiddlewareMacro.h +++ b/native/cocos/editor-support/MiddlewareMacro.h @@ -26,8 +26,7 @@ #define INIT_INDEX_BUFFER_SIZE 1024000 // max vertex buffer size #define MAX_VERTEX_BUFFER_SIZE 65535 -// render info int capacity -#define INIT_RENDER_INFO_BUFFER_SIZE 1024000 + // fill debug data max capacity #define MAX_DEBUG_BUFFER_SIZE 40960 // type array pool min size diff --git a/native/cocos/editor-support/MiddlewareManager.cpp b/native/cocos/editor-support/MiddlewareManager.cpp index 32b85ff399..053e48f579 100644 --- a/native/cocos/editor-support/MiddlewareManager.cpp +++ b/native/cocos/editor-support/MiddlewareManager.cpp @@ -24,7 +24,6 @@ #include "MiddlewareManager.h" #include "base/CCGLUtils.h" #include "scripting/js-bindings/jswrapper/SeApi.h" -#include "RenderInfoMgr.h" MIDDLEWARE_BEGIN @@ -69,9 +68,6 @@ void MiddlewareManager::update(float dt) buffer->reset(); } } - // reset render info - auto renderInfoMgr = RenderInfoMgr::getInstance(); - renderInfoMgr->reset(); isUpdating = true; diff --git a/native/cocos/editor-support/RenderInfoMgr.h b/native/cocos/editor-support/MiddlewareRenderHandle.cpp similarity index 53% rename from native/cocos/editor-support/RenderInfoMgr.h rename to native/cocos/editor-support/MiddlewareRenderHandle.cpp index 3933bf8def..859a2c461a 100644 --- a/native/cocos/editor-support/RenderInfoMgr.h +++ b/native/cocos/editor-support/MiddlewareRenderHandle.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - Copyright (c) 2019 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org @@ -22,63 +22,56 @@ THE SOFTWARE. ****************************************************************************/ -#pragma once +#include "MiddlewareRenderHandle.h" +#include "renderer/scene/ModelBatcher.hpp" -#include "IOTypedArray.h" -#include +using namespace cocos2d; +using namespace cocos2d::renderer; MIDDLEWARE_BEGIN - -class RenderInfoMgr { -public: - static RenderInfoMgr* getInstance () - { - if (_instance == nullptr) - { - _instance = new RenderInfoMgr(); - } - return _instance; - } - - static void destroyInstance () - { - if (_instance) - { - delete _instance; - _instance = nullptr; - } - } - - RenderInfoMgr (); - virtual ~RenderInfoMgr (); - void reset () - { - _buffer->reset(); - } +MiddlewareRenderHandle::MiddlewareRenderHandle() +{ + _useModel = true; +} - IOTypedArray* getBuffer() +MiddlewareRenderHandle::~MiddlewareRenderHandle() +{ + for (std::size_t i = 0, n = _iaPool.size(); i < n; i++) { - return _buffer; + auto ia = _iaPool[i]; + delete ia; } + _iaPool.clear(); +} - typedef std::function resizeCallback; - void setResizeCallback(resizeCallback callback) - { - _resizeCallback = callback; - } +void MiddlewareRenderHandle::updateIARange(std::size_t index, int start, int count) +{ + auto ia = adjustIA(index); + if (!ia) return; + + ia->setCount(count); + ia->setStart(start); +} - se_object_ptr getRenderInfo() +void MiddlewareRenderHandle::updateIABuffer(std::size_t index, VertexBuffer* vb, IndexBuffer* ib) +{ + auto ia = adjustIA(index); + if (!ia) return; + + ia->setVertexBuffer(vb); + ia->setIndexBuffer(ib); +} + +void MiddlewareRenderHandle::renderIA(std::size_t index, ModelBatcher* batcher, NodeProxy* node) +{ + if (index >= _iaCount) { - return _buffer->getTypeArray(); + cocos2d::log("MiddlewareRenderHandle:renderIA index:%lu out of range", index); + return; } -private: - void init(); - void afterCleanupHandle(); -private: - static RenderInfoMgr* _instance; - IOTypedArray* _buffer = nullptr; - resizeCallback _resizeCallback = nullptr; -}; + + batcher->flushIA(_iaPool[index]); +} MIDDLEWARE_END diff --git a/native/cocos/editor-support/RenderInfoMgr.cpp b/native/cocos/editor-support/MiddlewareRenderHandle.h similarity index 58% rename from native/cocos/editor-support/RenderInfoMgr.cpp rename to native/cocos/editor-support/MiddlewareRenderHandle.h index 6e82bf9c9d..f17020bb0e 100644 --- a/native/cocos/editor-support/RenderInfoMgr.cpp +++ b/native/cocos/editor-support/MiddlewareRenderHandle.h @@ -1,5 +1,5 @@ /**************************************************************************** - Copyright (c) 2019 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org @@ -21,45 +21,24 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#pragma once + +#include "renderer/scene/CustomRenderHandle.hpp" +#include "renderer/renderer/InputAssembler.h" +#include +#include "MiddlewareMacro.h" -#include "RenderInfoMgr.h" MIDDLEWARE_BEGIN -RenderInfoMgr* RenderInfoMgr::_instance = nullptr; -RenderInfoMgr::RenderInfoMgr () +class MiddlewareManager; +class MiddlewareRenderHandle : public cocos2d::renderer::CustomRenderHandle { - init(); -} - -RenderInfoMgr::~RenderInfoMgr () -{ - CC_SAFE_DELETE(_buffer); -} - -void RenderInfoMgr::afterCleanupHandle() -{ - if (_buffer) - { - delete _buffer; - _buffer = nullptr; - } - se::ScriptEngine::getInstance()->addAfterInitHook(std::bind(&RenderInfoMgr::init,this)); -} - -void RenderInfoMgr::init() -{ - if (!_buffer) - { - _buffer = new IOTypedArray(se::Object::TypedArrayType::UINT32, INIT_RENDER_INFO_BUFFER_SIZE); - _buffer->setResizeCallback([this] - { - if (_resizeCallback) - { - _resizeCallback(); - } - }); - } - se::ScriptEngine::getInstance()->addAfterCleanupHook(std::bind(&RenderInfoMgr::afterCleanupHandle,this)); -} +public: + MiddlewareRenderHandle(); + virtual ~MiddlewareRenderHandle(); + virtual void renderIA(std::size_t index, cocos2d::renderer::ModelBatcher* batcher, cocos2d::renderer::NodeProxy* node) override; + void updateIARange(std::size_t index, int start, int count); + void updateIABuffer(std::size_t index, cocos2d::renderer::VertexBuffer* vb, cocos2d::renderer::IndexBuffer* ib); +}; MIDDLEWARE_END diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp index c3fe8b2dcb..24b372a530 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp +++ b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp @@ -23,10 +23,15 @@ #include "dragonbones-creator-support/CCArmatureDisplay.h" #include "dragonbones-creator-support/CCSlot.h" #include "MiddlewareMacro.h" -#include "RenderInfoMgr.h" +#include "renderer/renderer/Pass.h" +#include "renderer/renderer/Technique.h" USING_NS_CC; USING_NS_MW; +using namespace cocos2d::renderer; + +static const std::string techStage = "transparent"; +static const std::string textureKey = "texture"; DRAGONBONES_NAMESPACE_BEGIN @@ -46,23 +51,21 @@ CCArmatureDisplay* CCArmatureDisplay::create() CCArmatureDisplay::CCArmatureDisplay() { - _renderInfoOffset = new IOTypedArray(se::Object::TypedArrayType::UINT32, sizeof(uint32_t)); + } CCArmatureDisplay::~CCArmatureDisplay() { dispose(); - if (_renderInfoOffset) - { - delete _renderInfoOffset; - _renderInfoOffset = nullptr; - } if (_debugBuffer) { delete _debugBuffer; _debugBuffer = nullptr; } + + CC_SAFE_RELEASE(_nodeProxy); + CC_SAFE_RELEASE(_effect); } void CCArmatureDisplay::dbInit(Armature* armature) @@ -92,40 +95,33 @@ void CCArmatureDisplay::dbUpdate() auto mgr = MiddlewareManager::getInstance(); if (!mgr->isUpdating) return; + + if (_nodeProxy == nullptr) + { + return; + } - auto renderMgr = RenderInfoMgr::getInstance(); - auto renderInfo = renderMgr->getBuffer(); - if (renderInfo == nullptr) return; - - _renderInfoOffset->reset(); - // store renderInfo offset - _renderInfoOffset->writeUint32((uint32_t)renderInfo->getCurPos() / sizeof(uint32_t)); + _renderHandle = (MiddlewareRenderHandle*)_nodeProxy->getHandle("render"); + if (_renderHandle == nullptr) + { + return; + } + _renderHandle->reset(); _preBlendMode = -1; _preTextureIndex = -1; _curTextureIndex = -1; - _curBlendSrc = -1; - _curBlendDst = -1; - - _preISegWritePos = -1; + _preISegWritePos = -1; _curISegLen = 0; _debugSlotsLen = 0; _materialLen = 0; - // check enough space - renderInfo->checkSpace(sizeof(uint32_t), true); - _materialLenOffset = renderInfo->getCurPos(); - // Reserved space to save material len - renderInfo->writeUint32(0); - // Traverse all aramture to fill vertex and index buffer. traverseArmature(_armature); - - renderInfo->writeUint32(_materialLenOffset, _materialLen); if (_preISegWritePos != -1) { - renderInfo->writeUint32(_preISegWritePos, _curISegLen); + _renderHandle->updateIARange(_materialLen - 1, _preISegWritePos, _curISegLen); } if (_debugDraw) @@ -166,7 +162,7 @@ void CCArmatureDisplay::dbUpdate() { _debugBuffer->writeFloat32(0, 0); cocos2d::log("Dragonbones debug data is too large,debug buffer has no space to put in it!!!!!!!!!!"); - cocos2d::log("You can adjust MAX_DEBUG_BUFFER_SIZE in Macro"); + cocos2d::log("You can adjust MAX_DEBUG_BUFFER_SIZE in MiddlewareMacro"); } } } @@ -207,16 +203,14 @@ void CCArmatureDisplay::traverseArmature(Armature* armature, float parentOpacity { auto& slots = armature->getSlots(); auto mgr = MiddlewareManager::getInstance(); - MeshBuffer* mb = mgr->getMeshBuffer(VF_XYUVC); + + middleware::MeshBuffer* mb = mgr->getMeshBuffer(VF_XYUVC); IOBuffer& vb = mb->getVB(); IOBuffer& ib = mb->getIB(); - auto renderMgr = RenderInfoMgr::getInstance(); - auto renderInfo = renderMgr->getBuffer(); - if (!renderInfo) return; - - float r, g, b, a; + float realOpacity = _nodeProxy->getRealOpacity() / 255.0f; + float r, g, b, a; CCSlot* slot = nullptr; - middleware::Texture2D* texture = nullptr; + middleware::Texture2D* texture = nullptr; int isFull = 0; auto flush = [&]() @@ -224,51 +218,85 @@ void CCArmatureDisplay::traverseArmature(Armature* armature, float parentOpacity // fill pre segment count field if (_preISegWritePos != -1) { - renderInfo->writeUint32(_preISegWritePos, _curISegLen); + _renderHandle->updateIARange(_materialLen - 1, _preISegWritePos, _curISegLen); } // prepare to fill new segment field switch (slot->_blendMode) { case BlendMode::Add: - _curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - _curBlendDst = GL_ONE; + _curBlendSrc = _premultipliedAlpha ? BlendFactor::ONE : BlendFactor::SRC_ALPHA; + _curBlendDst = BlendFactor::ONE; break; case BlendMode::Multiply: - _curBlendSrc = GL_DST_COLOR; - _curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + _curBlendSrc = BlendFactor::DST_COLOR; + _curBlendDst = BlendFactor::ONE_MINUS_SRC_ALPHA; break; case BlendMode::Screen: - _curBlendSrc = GL_ONE; - _curBlendDst = GL_ONE_MINUS_SRC_COLOR; + _curBlendSrc = BlendFactor::ONE; + _curBlendDst = BlendFactor::ONE_MINUS_SRC_COLOR; break; default: - _curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - _curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + _curBlendSrc = _premultipliedAlpha ? BlendFactor::ONE : BlendFactor::SRC_ALPHA; + _curBlendDst = BlendFactor::ONE_MINUS_SRC_ALPHA; break; } - // check enough space - renderInfo->checkSpace(sizeof(uint32_t) * 7, true); + double curHash = _curTextureIndex + (int)_curBlendSrc + (int)_curBlendDst; - // fill new texture index - renderInfo->writeUint32(_curTextureIndex); - // fill new blend src and dst - renderInfo->writeUint32(_curBlendSrc); - renderInfo->writeUint32(_curBlendDst); - // fill new index and vertex buffer id - auto glIB = mb->getGLIB(); - auto glVB = mb->getGLVB(); - renderInfo->writeUint32(glIB); - renderInfo->writeUint32(glVB); - // fill new index offset - renderInfo->writeUint32((uint32_t)ib.getCurPos() / sizeof(unsigned short)); - - // save new segment count pos field - _preISegWritePos = (int)renderInfo->getCurPos(); - // reserve indice segamentation count - renderInfo->writeUint32(0); + Effect* renderEffect = _renderHandle->getEffect(_materialLen); + Technique::Parameter* param = nullptr; + Pass* pass = nullptr; + + if (renderEffect) + { + double renderHash = renderEffect->getHash(); + if (abs(renderHash - curHash) >= 0.01) + { + param = (Technique::Parameter*)&(renderEffect->getProperty(textureKey)); + Technique* tech = renderEffect->getTechnique(techStage); + Vector& passes = (Vector&)tech->getPasses(); + pass = *(passes.begin()); + } + } + else + { + if (_effect == nullptr) + { + cocos2d::log("ArmatureDisplay:update get effect failed"); + _renderHandle->reset(); + return; + } + auto effect = new cocos2d::renderer::Effect(); + effect->autorelease(); + effect->copy(*_effect); + + Technique* tech = effect->getTechnique(techStage); + Vector& passes = (Vector&)tech->getPasses(); + pass = *(passes.begin()); + + _renderHandle->updateNativeEffect(_materialLen, effect); + renderEffect = effect; + param = (Technique::Parameter*)&(renderEffect->getProperty(textureKey)); + } + + if (param) + { + param->setTexture(texture->getNativeTexture()); + } + + if (pass) + { + pass->setBlend(BlendOp::ADD, _curBlendSrc, _curBlendDst, + BlendOp::ADD, _curBlendSrc, _curBlendDst); + } + + renderEffect->updateHash(curHash); + // save new segment count pos field + _preISegWritePos = (int)ib.getCurPos()/sizeof(unsigned short); + // save new segment vb and ib + _renderHandle->updateIABuffer(_materialLen, mb->getGLVB(), mb->getGLIB()); // reset pre blend mode to current _preBlendMode = (int)slot->_blendMode; // reset pre texture index to current @@ -313,7 +341,7 @@ void CCArmatureDisplay::traverseArmature(Armature* armature, float parentOpacity } // Calculation vertex color. - a = _nodeColor.a * slot->color.a * parentOpacity; + a = realOpacity * slot->color.a * parentOpacity; float multiplier = _premultipliedAlpha ? a / 255.0f : 1.0f; r = _nodeColor.r * slot->color.r * multiplier; g = _nodeColor.g * slot->color.g * multiplier; diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.h b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.h index 6b81780b5f..c88441352b 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.h +++ b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.h @@ -32,6 +32,11 @@ #include "dragonbones-creator-support/CCSlot.h" #include "IOTypedArray.h" #include "MiddlewareManager.h" +#include "renderer/scene/NodeProxy.hpp" +#include "base/CCMap.h" +#include "middleware-adapter.h" +#include "MiddlewareRenderHandle.h" +#include "renderer/Types.h" DRAGONBONES_NAMESPACE_BEGIN /** @@ -120,17 +125,19 @@ public: return nullptr; } - /** - * @return render info offset,it's a Uint32Array, - * format |render info offset| - */ - se_object_ptr getRenderInfoOffset() const + void bindNodeProxy(cocos2d::renderer::NodeProxy* node) { - if (_renderInfoOffset) - { - return _renderInfoOffset->getTypeArray(); - } - return nullptr; + CC_SAFE_RELEASE(_nodeProxy); + _nodeProxy = node; + CC_SAFE_RETAIN(_nodeProxy); + } + + void setNativeEffect(cocos2d::renderer::Effect* effect) + { + if (effect == _effect) return; + CC_SAFE_RELEASE(_effect); + _effect = effect; + CC_SAFE_RETAIN(_effect); } void setColor(cocos2d::Color4B& color) @@ -171,25 +178,26 @@ public: private: std::map _listenerIDMap; - cocos2d::middleware::IOTypedArray* _renderInfoOffset = nullptr; cocos2d::middleware::IOTypedArray* _debugBuffer = nullptr; cocos2d::Color4F _nodeColor = cocos2d::Color4F::WHITE; int _preBlendMode = -1; int _preTextureIndex = -1; int _curTextureIndex = -1; - int _curBlendSrc = -1; - int _curBlendDst = -1; + cocos2d::renderer::BlendFactor _curBlendSrc; + cocos2d::renderer::BlendFactor _curBlendDst; int _preISegWritePos = -1; int _curISegLen = 0; int _debugSlotsLen = 0; int _materialLen = 0; - std::size_t _materialLenOffset = -1; bool _premultipliedAlpha = false; dbEventCallback _dbEventCallback = nullptr; + cocos2d::renderer::NodeProxy* _nodeProxy = nullptr; + cocos2d::renderer::Effect* _effect = nullptr; + cocos2d::middleware::MiddlewareRenderHandle* _renderHandle = nullptr; }; DRAGONBONES_NAMESPACE_END diff --git a/native/cocos/editor-support/middleware-adapter.cpp b/native/cocos/editor-support/middleware-adapter.cpp index 9009ef0a7e..b7d68902d9 100644 --- a/native/cocos/editor-support/middleware-adapter.cpp +++ b/native/cocos/editor-support/middleware-adapter.cpp @@ -23,6 +23,10 @@ ****************************************************************************/ #include "middleware-adapter.h" #include "base/ccMacros.h" +#include "renderer/gfx/Texture.h" + +using namespace cocos2d; +using namespace cocos2d::renderer; MIDDLEWARE_BEGIN @@ -33,7 +37,8 @@ Texture2D::Texture2D() Texture2D::~Texture2D() { - + CC_SAFE_RELEASE(_texture); + _texParamCallback = nullptr; } int Texture2D::getPixelsWide() const @@ -79,6 +84,18 @@ void Texture2D::setTexParameters(const TexParams& texParams) } } +void Texture2D::setNativeTexture(Texture* texture) +{ + CC_SAFE_RELEASE(_texture); + _texture = texture; + CC_SAFE_RETAIN(_texture); +} + +Texture* Texture2D::getNativeTexture() const +{ + return _texture; +} + SpriteFrame* SpriteFrame::createWithTexture(Texture2D *texture, const cocos2d::Rect& rect) { SpriteFrame *spriteFrame = new (std::nothrow) SpriteFrame(); diff --git a/native/cocos/editor-support/middleware-adapter.h b/native/cocos/editor-support/middleware-adapter.h index dff3336d93..4be794b745 100644 --- a/native/cocos/editor-support/middleware-adapter.h +++ b/native/cocos/editor-support/middleware-adapter.h @@ -27,6 +27,7 @@ #include "base/ccTypes.h" #include #include "MiddlewareMacro.h" +#include "renderer/renderer/Effect.h" MIDDLEWARE_BEGIN /** @@ -105,7 +106,7 @@ public: virtual ~Texture2D(); /** Extension to set the Min / Mag filter - */ + */ typedef struct _TexParams { GLuint minFilter; @@ -121,16 +122,16 @@ public: /** Sets the min filter, mag filter, wrap s and wrap t texture parameters. If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}. - - @warning Calling this method could allocate additional texture memory. - - @since v0.8 - * @code - * When this function bound into js or lua,the input parameter will be changed - * In js: var setBlendFunc(var arg1, var arg2, var arg3, var arg4) - * In lua: local setBlendFunc(local arg1, local arg2, local arg3, local arg4) - * @endcode - */ + + @warning Calling this method could allocate additional texture memory. + + @since v0.8 + * @code + * When this function bound into js or lua,the input parameter will be changed + * In js: var setBlendFunc(var arg1, var arg2, var arg3, var arg4) + * In lua: local setBlendFunc(local arg1, local arg2, local arg3, local arg4) + * @endcode + */ void setTexParameters(const TexParams& texParams); /** Gets the width of the texture in pixels. */ @@ -153,6 +154,12 @@ public: /** Sets texture param callback*/ void setTexParamCallback(const texParamCallback& callback); + + /** Sets texture native ptr*/ + void setNativeTexture(cocos2d::renderer::Texture* texture); + + /** Gets texture native ptr*/ + cocos2d::renderer::Texture* getNativeTexture() const; private: /** width in pixels */ @@ -165,6 +172,8 @@ private: int _realTextureIndex = 0; texParamCallback _texParamCallback = nullptr; + + cocos2d::renderer::Texture* _texture = nullptr; }; /////////////////////////////////////////////////////////////////////// diff --git a/native/cocos/editor-support/particle/ParticleSimulator.cpp b/native/cocos/editor-support/particle/ParticleSimulator.cpp new file mode 100644 index 0000000000..9015315a83 --- /dev/null +++ b/native/cocos/editor-support/particle/ParticleSimulator.cpp @@ -0,0 +1,462 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "ParticleSimulator.h" +#include "base/ccRandom.h" +#include +#include "base/ccMacros.h" +#include "math/Mat4.h" +#include "MiddlewareManager.h" +#include "middleware-adapter.h" +#include "MiddlewareRenderHandle.h" +#include "math/Vec2.h" + +USING_NS_MW; + +NS_CC_BEGIN + +// global particle pool +static ParticlePool _pool; + +void Particle::reset() +{ + pos = cocos2d::Vec3::ZERO; + startPos = cocos2d::Vec3::ZERO; + color = cocos2d::Color4B::BLACK; + deltaColor = cocos2d::Color4B::BLACK; + size = 0; + deltaSize = 0; + rotation = 0; + deltaRotation = 0; + timeToLive = 0; + drawPos = cocos2d::Vec3::ZERO; + + // Mode A + dir = cocos2d::Vec3::ZERO; + radialAccel = 0; + tangentialAccel = 0; + + // Mode B + angle = 0; + degreesPerSecond = 0; + radius = 0; + deltaRadius = 0; +} + +ParticlePool::ParticlePool() +{ + +} + +ParticlePool::~ParticlePool() +{ + for (auto particle : _pool) + { + delete particle; + } + _pool.clear(); +} + +ParticleSimulator::ParticleSimulator() +{ + +} + +ParticleSimulator::~ParticleSimulator() +{ + onDisable(); + + CC_SAFE_RELEASE(_effect); + CC_SAFE_RELEASE(_nodeProxy); + + for (auto particle : _particles) + { + delete particle; + } + _particles.clear(); +} + +void ParticleSimulator::stop() +{ + _active = false; + _elapsed = duration; + _emitCounter = 0; +} + +void ParticleSimulator::reset() +{ + _active = true; + _elapsed = 0; + _emitCounter = 0; + _finished = false; + for (auto particle : _particles) + { + _pool.put(particle); + } + _particles.clear(); +} + +void ParticleSimulator::emitParticle(cocos2d::Vec3 &pos) +{ + auto& particle = *_pool.get(); + _particles.push_back(&particle); + + // Init particle + // timeToLive + // no negative life. prevent division by 0 + particle.timeToLive = life + lifeVar * random(-1.0f, 1.0f); + // avoid divide zero + float timeToLive = particle.timeToLive = std::max(0.001f, particle.timeToLive); + + // position + particle.pos.x = _sourcePos.x + _posVar.x * random(-1.0f, 1.0f); + particle.pos.y = _sourcePos.y + _posVar.y * random(-1.0f, 1.0f); + + // Color + GLubyte sr, sg, sb, sa; + particle.color.r = sr = clampf(_startColor.r + _startColorVar.r * random(-1.0f, 1.0f), 0, 255); + particle.color.g = sg = clampf(_startColor.g + _startColorVar.g * random(-1.0f, 1.0f), 0, 255); + particle.color.b = sb = clampf(_startColor.b + _startColorVar.b * random(-1.0f, 1.0f), 0, 255); + particle.color.a = sa = clampf(_startColor.a + _startColorVar.a * random(-1.0f, 1.0f), 0, 255); + particle.deltaColor.r = (clampf(_endColor.r + _endColorVar.r * random(-1.0f, 1.0f), 0, 255) - sr) / timeToLive; + particle.deltaColor.g = (clampf(_endColor.g + _endColorVar.g * random(-1.0f, 1.0f), 0, 255) - sg) / timeToLive; + particle.deltaColor.b = (clampf(_endColor.b + _endColorVar.b * random(-1.0f, 1.0f), 0, 255) - sb) / timeToLive; + particle.deltaColor.a = (clampf(_endColor.a + _endColorVar.a * random(-1.0f, 1.0f), 0, 255) - sa) / timeToLive; + + // size + float startS = startSize + startSizeVar * random(-1.0f, 1.0f); + startS = std::max(0.0f, startS); // No negative value + particle.size = startS; + if (endSize == START_SIZE_EQUAL_TO_END_SIZE) + { + particle.deltaSize = 0; + } + else + { + float endS = endSize + endSizeVar * random(-1.0f, 1.0f); + endS = std::max(0.0f, endS); // No negative values + particle.deltaSize = (endS - startS) / timeToLive; + } + + // rotation + float startA = startSpin + startSpinVar * random(-1.0f, 1.0f); + float endA = endSpin + endSpinVar * random(-1.0f, 1.0f); + particle.rotation = startA; + particle.deltaRotation = (endA - startA) / timeToLive; + + // position + particle.startPos.x = pos.x; + particle.startPos.y = pos.y; + + // direction + float a = CC_DEGREES_TO_RADIANS(angle + angleVar * random(-1.0f, 1.0f)); + // Mode Gravity: A + if (emitterMode == EmitterMode::GRAVITY) + { + float s = speed + speedVar * random(-1.0f, 1.0f); + // direction + particle.dir.x = cos(a); + particle.dir.y = sin(a); + particle.dir.scale(s); + // radial accel + particle.radialAccel = radialAccel + radialAccelVar * random(-1.0f, 1.0f); + // tangential accel + particle.tangentialAccel = tangentialAccel + tangentialAccelVar * random(-1.0f, 1.0f); + // rotation is dir + if (rotationIsDir) + { + particle.rotation = -CC_RADIANS_TO_DEGREES(atan2(particle.dir.y, particle.dir.x)); + } + } + // Mode Radius: B + else + { + // Set the default diameter of the particle from the source position + float tempStartRadius = startRadius + startRadiusVar * random(-1.0f, 1.0f); + float tempEndRadius = endRadius + endRadiusVar * random(-1.0f, 1.0f); + particle.radius = tempStartRadius; + particle.deltaRadius = (endRadius == START_RADIUS_EQUAL_TO_END_RADIUS) ? 0 : (tempEndRadius - tempStartRadius) / timeToLive; + particle.angle = a; + particle.degreesPerSecond = CC_DEGREES_TO_RADIANS(rotatePerS + rotatePerSVar * random(-1.0f, 1.0f)); + } +} + +void ParticleSimulator::onEnable() +{ + MiddlewareManager::getInstance()->addTimer(this); +} + +void ParticleSimulator::onDisable() +{ + MiddlewareManager::getInstance()->removeTimer(this); +} + +void ParticleSimulator::update(float dt) +{ + // uv size must equal 8,because per particle has 4 vertex. + if (_uv.size() != 8) + { + return; + } + + if (_nodeProxy == nullptr) + { + return; + } + + MiddlewareRenderHandle* renderHandle = (MiddlewareRenderHandle*)_nodeProxy->getHandle("render"); + if (renderHandle == nullptr) + { + return; + } + renderHandle->reset(); + renderHandle->updateNativeEffect(0, _effect); + + // avoid other place call update. + auto mgr = MiddlewareManager::getInstance(); + if (!mgr->isUpdating) return; + + middleware::MeshBuffer* mb = mgr->getMeshBuffer(VF_XYUVC); + middleware::IOBuffer& vb = mb->getVB(); + middleware::IOBuffer& ib = mb->getIB(); + + // Calculate pos + auto worldMatrix = _nodeProxy->getWorldMatrix(); + + cocos2d::Vec3 pos; + cocos2d::Vec3 tpa; + cocos2d::Vec3 tpb; + cocos2d::Vec3 tpc; + + if (positionType == PositionType::FREE) + { + worldMatrix.transformPoint(&pos); + } + else if (positionType == PositionType::RELATIVE) + { + _nodeProxy->getPosition(&pos); + } + + // Get world to node trans only once + worldMatrix.inverse(); + + // Emission + if (_active && emissionRate) + { + float rate = 1.0 / emissionRate; + //issue #1201, prevent bursts of particles, due to too high emitCounter + if (_particles.size() < totalParticles) + _emitCounter += dt; + + while ((_particles.size() < totalParticles) && (_emitCounter > rate)) + { + emitParticle(pos); + _emitCounter -= rate; + } + + _elapsed += dt; + if (duration != -1 && duration < _elapsed) + { + _stopCallback(); + } + } + + // Used to reduce memory allocation / creation within the loop + std::size_t particleIdx = 0; + std::size_t particleSize = _particles.size(); + vb.checkSpace(particleSize * 4 * sizeof (middleware::V2F_T2F_C4B)); + ib.checkSpace(particleSize * 6 * sizeof (unsigned short)); + std::size_t vbOffset = vb.getCurPos() / sizeof (middleware::V2F_T2F_C4B); + uint32_t indexStart = (uint32_t)ib.getCurPos()/sizeof(unsigned short); + uint32_t indexCount = 0; + + while (particleIdx < particleSize) + { + // Reset temporary vectors + tpa.x = tpa.y = tpb.x = tpb.y = tpc.x = tpc.y = 0; + + auto& particle = *_particles[particleIdx]; + + // life + particle.timeToLive -= dt; + if (particle.timeToLive > 0) + { + // Mode A: gravity, direction, tangential accel & radial accel + if (emitterMode == EmitterMode::GRAVITY) + { + auto& tmp = tpc; + auto& radial = tpa; + auto& tangential = tpb; + + // radial acceleration + if (particle.pos.x || particle.pos.y) + { + radial.set(particle.pos); + radial.normalize(); + } + tangential.set(radial); + radial.scale(particle.radialAccel); + + // tangential acceleration + auto newy = tangential.x; + tangential.x = -tangential.y; + tangential.y = newy; + + tangential.scale(particle.tangentialAccel); + + tmp.set(radial); + tmp.add(tangential); + tmp.add(_gravity.x, _gravity.y, _gravity.z); + tmp.scale(dt); + particle.dir.add(tmp); + + tmp.set(particle.dir); + tmp.scale(dt); + particle.pos.add(tmp); + } + // Mode B: radius movement + else + { + // Update the angle and radius of the particle. + particle.angle += particle.degreesPerSecond * dt; + particle.radius += particle.deltaRadius * dt; + + particle.pos.x = -cos(particle.angle) * particle.radius; + particle.pos.y = -sin(particle.angle) * particle.radius; + } + + // color + particle.color.r += particle.deltaColor.r * dt; + particle.color.g += particle.deltaColor.g * dt; + particle.color.b += particle.deltaColor.b * dt; + particle.color.a += particle.deltaColor.a * dt; + + // size + particle.size += particle.deltaSize * dt; + if (particle.size < 0) + { + particle.size = 0; + } + + // angle + particle.rotation += particle.deltaRotation * dt; + + // update values in quad buffer + auto& newPos = tpa; + if (positionType == PositionType::FREE || positionType == PositionType::RELATIVE) + { + auto& diff = tpb; + auto& startPos = tpc; + // current Position convert To Node Space + worldMatrix.transformPoint(pos, &diff); + // start Position convert To Node Space + worldMatrix.transformPoint(particle.startPos, &startPos); + diff.add(-startPos.x, -startPos.y, -startPos.z); + newPos.set(particle.pos); + newPos.add(-diff.x, -diff.y, -diff.z); + } + else + { + newPos.set(particle.pos); + } + + auto x = newPos.x, y = newPos.y; + auto size_2 = particle.size * 0.5; + auto x1 = -size_2, y1 = -size_2; + auto x2 = size_2, y2 = size_2; + + auto rad = -CC_DEGREES_TO_RADIANS(particle.rotation); + auto cr = cos(rad), sr = sin(rad); + uint32_t tempColor = ((particle.color.a << 24) & 0xff000000) + + ((particle.color.b << 16) & 0x00ff0000) + + ((particle.color.g << 8) & 0x0000ff00) + + ((particle.color.r) & 0x000000ff); + // bl + vb.writeFloat32(x1 * cr - y1 * sr + x); + vb.writeFloat32(x1 * sr + y1 * cr + y); + vb.writeFloat32(_uv[0]); + vb.writeFloat32(_uv[1]); + vb.writeUint32(tempColor); + + // br + vb.writeFloat32(x2 * cr - y1 * sr + x); + vb.writeFloat32(x2 * sr + y1 * cr + y); + vb.writeFloat32(_uv[2]); + vb.writeFloat32(_uv[3]); + vb.writeUint32(tempColor); + + // tl + vb.writeFloat32(x1 * cr - y2 * sr + x); + vb.writeFloat32(x1 * sr + y2 * cr + y); + vb.writeFloat32(_uv[4]); + vb.writeFloat32(_uv[5]); + vb.writeUint32(tempColor); + + // tr + vb.writeFloat32(x2 * cr - y2 * sr + x); + vb.writeFloat32(x2 * sr + y2 * cr + y); + vb.writeFloat32(_uv[6]); + vb.writeFloat32(_uv[7]); + vb.writeUint32(tempColor); + + ib.writeUint16(vbOffset); + ib.writeUint16(vbOffset + 1); + ib.writeUint16(vbOffset + 2); + ib.writeUint16(vbOffset + 1); + ib.writeUint16(vbOffset + 3); + ib.writeUint16(vbOffset + 2); + + vbOffset += 4; + indexCount += 6; + + // update particle counter + ++particleIdx; + } + else + { + // life < 0 + auto deadParticle = _particles[particleIdx]; + if (particleIdx != particleSize - 1) + { + _particles[particleIdx] = _particles[particleSize - 1]; + } + _pool.put(deadParticle); + particleSize--; + _particles.resize(particleSize); + } + } + + renderHandle->updateIABuffer(0, mb->getGLVB(), mb->getGLIB()); + renderHandle->updateIARange(0, indexStart, indexCount); + + if (_particles.size() == 0 && !_active) + { + _finished = true; + if (_finishedCallback) + { + _finishedCallback(); + } + } +} + +NS_CC_END diff --git a/native/cocos/editor-support/particle/ParticleSimulator.h b/native/cocos/editor-support/particle/ParticleSimulator.h new file mode 100644 index 0000000000..e1c9b2ebb5 --- /dev/null +++ b/native/cocos/editor-support/particle/ParticleSimulator.h @@ -0,0 +1,280 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#pragma once +#include "MiddlewareMacro.h" +#include "math/Vec3.h" +#include "base/ccTypes.h" +#include +#include "IOBuffer.h" +#include "renderer/scene/NodeProxy.hpp" +#include "renderer/renderer/Effect.h" +#include "MiddlewareManager.h" +#include "scripting/js-bindings/jswrapper/SeApi.h" + +NS_CC_BEGIN + +struct Particle { +public: + cocos2d::Vec3 pos; + cocos2d::Vec3 startPos; + cocos2d::Color4B color = cocos2d::Color4B::BLACK; + cocos2d::Color4B deltaColor = cocos2d::Color4B::BLACK; + float size = 0.0f; + float deltaSize = 0.0f; + float rotation = 0.0f; + float deltaRotation = 0.0f; + float timeToLive = 0.0f; + cocos2d::Vec3 drawPos; + + // Mode A + cocos2d::Vec3 dir; + float radialAccel = 0.0f; + float tangentialAccel = 0.0f; + + // Mode B + float angle = 0.0f; + float degreesPerSecond = 0.0f; + float radius = 0.0f; + float deltaRadius = 0.0f; + + bool inPool = false; + void reset(); +}; + +class ParticlePool { +public: + ParticlePool(); + ~ParticlePool(); + + void put(Particle* particle) + { + CCASSERT(!particle->inPool, "Particle is in pool already"); + _pool.push_back(particle); + particle->inPool = true; + particle->reset(); + } + + Particle* get() + { + Particle* obj = nullptr; + if (_pool.size() > 0) + { + obj = _pool.back(); + _pool.pop_back(); + obj->inPool = false; + } else { + obj = new Particle(); + } + return obj; + } + +private: + std::vector _pool; +}; + +enum PositionType +{ + FREE = 0, + RELATIVE = 1, + GROUPED = 2 +}; + +enum EmitterMode +{ + GRAVITY = 0, + RADIUS = 1 +}; + +class ParticleSimulator : public cocos2d::middleware::IMiddleware, public cocos2d::Ref { + + //* @enum + enum { + /** The Particle emitter lives forever. */ + DURATION_INFINITY = -1, + + /** The starting size of the particle is equal to the ending size. */ + START_SIZE_EQUAL_TO_END_SIZE = -1, + + /** The starting radius of the particle is equal to the ending radius. */ + START_RADIUS_EQUAL_TO_END_RADIUS = -1, + }; + +public: + ParticleSimulator(); + ~ParticleSimulator(); + void stop(); + void reset(); + void emitParticle(cocos2d::Vec3& pos); + void update(float dt); + void onEnable(); + void onDisable(); + + typedef std::function finishedCallback; + void setFinishedCallback(finishedCallback callback) + { + _finishedCallback = callback; + } + + typedef std::function stopCallback; + void setStopCallback(stopCallback callback) + { + _stopCallback = callback; + } + + void bindNodeProxy(cocos2d::renderer::NodeProxy* node) + { + CC_SAFE_RELEASE(_nodeProxy); + _nodeProxy = node; + CC_SAFE_RETAIN(_nodeProxy); + } + + void setNativeEffect(cocos2d::renderer::Effect* effect) + { + CC_SAFE_RELEASE(_effect); + _effect = effect; + CC_SAFE_RETAIN(_effect); + } + + void updateUVs(const std::vector& uv) + { + _uv = uv; + } + + std::size_t getParticleCount() + { + return _particles.size(); + } + + bool active() + { + return _active; + } + + void setGravity(float x, float y, float z) + { + _gravity.x = x; + _gravity.y = y; + _gravity.z = z; + } + + void setSourcePos(float x, float y, float z) + { + _sourcePos.x = x; + _sourcePos.y = y; + _sourcePos.z = z; + } + + void setPosVar(float x, float y, float z) + { + _posVar.x = x; + _posVar.y = y; + _posVar.z = z; + } + + void setStartColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + _startColor.r = r; + _startColor.g = g; + _startColor.b = b; + _startColor.a = a; + } + + void setStartColorVar(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + _startColorVar.r = r; + _startColorVar.g = g; + _startColorVar.b = b; + _startColorVar.a = a; + } + + void setEndColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + _endColor.r = r; + _endColor.g = g; + _endColor.b = b; + _endColor.a = a; + } + + void setEndColorVar(GLubyte r, GLubyte g, GLubyte b, GLubyte a) + { + _endColorVar.r = r; + _endColorVar.g = g; + _endColorVar.b = b; + _endColorVar.a = a; + } + +private: + std::vector _particles; + bool _active = false; + bool _finished = false; + float _elapsed = 0; + float _emitCounter = 0; + std::size_t _uvFilled = 0; + finishedCallback _finishedCallback = nullptr; + stopCallback _stopCallback = nullptr; + cocos2d::renderer::NodeProxy* _nodeProxy = nullptr; + cocos2d::renderer::Effect* _effect = nullptr; + std::vector _uv; + + cocos2d::Vec3 _gravity; + cocos2d::Vec3 _sourcePos; + cocos2d::Vec3 _posVar; + cocos2d::Color4B _startColor = cocos2d::Color4B::BLACK; + cocos2d::Color4B _startColorVar = cocos2d::Color4B::WHITE; + cocos2d::Color4B _endColor = cocos2d::Color4B::BLACK; + cocos2d::Color4B _endColorVar = cocos2d::Color4B::WHITE; +public: + int positionType = PositionType::FREE; + float emissionRate = 0.0f; + std::size_t totalParticles = 0; + float duration = -1.0f; + int emitterMode = EmitterMode::GRAVITY; + float life = 0.0f; + float lifeVar = 0.0f; + float startSize = 0.0f; + float startSizeVar = 0.0f; + float endSize = 0.0f; + float endSizeVar = 0.0f; + float startSpin = 0.0f; + float startSpinVar = 0.0f; + float endSpin = 0.0f; + float endSpinVar = 0.0f; + float angle = 0.0f; + float angleVar = 0.0f; + float speed = 0.0f; + float speedVar = 0.0f; + float radialAccel = 0.0f; + float radialAccelVar = 0.0f; + float tangentialAccel = 0.0f; + float tangentialAccelVar = 0.0f; + bool rotationIsDir = false; + float startRadius = 0.0f; + float startRadiusVar = 0.0f; + float endRadius = 0.0f; + float endRadiusVar = 0.0f; + float rotatePerS = 0.0f; + float rotatePerSVar = 0.0f; +}; + +NS_CC_END diff --git a/native/cocos/editor-support/spine-creator-support/SpineAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SpineAnimation.cpp index 6b5a61564f..42d7d0d2b3 100644 --- a/native/cocos/editor-support/spine-creator-support/SpineAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SpineAnimation.cpp @@ -1,384 +1,384 @@ -/****************************************************************************** - * Spine Runtimes Software License v2.5 - * - * Copyright (c) 2013-2016, Esoteric Software - * All rights reserved. - * - * You are granted a perpetual, non-exclusive, non-sublicensable, and - * non-transferable license to use, install, execute, and perform the Spine - * Runtimes software and derivative works solely for personal or internal - * use. Without the written permission of Esoteric Software (see Section 2 of - * the Spine Software License Agreement), you may not (a) modify, translate, - * adapt, or develop new applications using the Spine Runtimes or otherwise - * create derivative works or improvements of the Spine Runtimes or (b) remove, - * delete, alter, or obscure any trademarks or any copyright, trademark, patent, - * or other intellectual property or proprietary rights notices on or in the - * Software, including any copy thereof. Redistributions in binary or source - * form must include this license and terms. - * - * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF - * USE, DATA, OR PROFITS) 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. - *****************************************************************************/ - -#include "spine-creator-support/SpineAnimation.h" -#include "spine-creator-support/spine-cocos2dx.h" -#include "spine/extension.h" -#include - -USING_NS_CC; -using std::min; -using std::max; -using std::vector; - -namespace spine { - -typedef struct _TrackEntryListeners -{ - StartListener startListener; - InterruptListener interruptListener; - EndListener endListener; - DisposeListener disposeListener; - CompleteListener completeListener; - EventListener eventListener; -} _TrackEntryListeners; - -void animationCallback (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) -{ - ((SpineAnimation*)state->rendererObject)->onAnimationStateEvent(entry, type, event); -} - -void trackEntryCallback (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) -{ - ((SpineAnimation*)state->rendererObject)->onTrackEntryEvent(entry, type, event); - if (type == SP_ANIMATION_DISPOSE) - if (entry->rendererObject) delete (spine::_TrackEntryListeners*)entry->rendererObject; -} - -static _TrackEntryListeners* getListeners (spTrackEntry* entry) -{ - if (!entry->rendererObject) { - entry->rendererObject = new spine::_TrackEntryListeners(); - entry->listener = trackEntryCallback; - } - return (_TrackEntryListeners*)entry->rendererObject; -} - -static float globalTimeScale = 1.0f; -void SpineAnimation::setGlobalTimeScale(float timeScale) -{ - globalTimeScale = timeScale; -} - -SpineAnimation* SpineAnimation::create() -{ - SpineAnimation* skeleton = new SpineAnimation(); - skeleton->autorelease(); - return skeleton; -} - -SpineAnimation* SpineAnimation::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) -{ - SpineAnimation* node = new SpineAnimation(); - node->initWithData(skeletonData, ownsSkeletonData); - node->autorelease(); - return node; -} - -SpineAnimation* SpineAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) -{ - SpineAnimation* node = new SpineAnimation(); - node->initWithJsonFile(skeletonJsonFile, atlas, scale); - node->autorelease(); - return node; -} - -SpineAnimation* SpineAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) -{ - SpineAnimation* node = new SpineAnimation(); - spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); - node->initWithJsonFile(skeletonJsonFile, atlas, scale); - node->autorelease(); - return node; -} - -SpineAnimation* SpineAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) -{ - SpineAnimation* node = new SpineAnimation(); - node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); - node->autorelease(); - return node; -} - -SpineAnimation* SpineAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) -{ - SpineAnimation* node = new SpineAnimation(); - spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); - node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); - node->autorelease(); - return node; -} - -void SpineAnimation::initialize () -{ - super::initialize(); - - _ownsAnimationStateData = true; - _state = spAnimationState_create(spAnimationStateData_create(_skeleton->data)); - _state->rendererObject = this; - _state->listener = animationCallback; -} - -SpineAnimation::SpineAnimation () -: SpineRenderer() -{ -} - -SpineAnimation::SpineAnimation (spSkeletonData *skeletonData, bool ownsSkeletonData) -: SpineRenderer(skeletonData, ownsSkeletonData) -{ - initialize(); -} - -SpineAnimation::SpineAnimation (const std::string& skeletonDataFile, spAtlas* atlas, float scale) -: SpineRenderer(skeletonDataFile, atlas, scale) -{ - initialize(); -} - -SpineAnimation::SpineAnimation (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) -: SpineRenderer(skeletonDataFile, atlasFile, scale) -{ - initialize(); -} - -SpineAnimation::~SpineAnimation () -{ - _startListener = nullptr; - _interruptListener = nullptr; - _endListener = nullptr; - _disposeListener = nullptr; - _completeListener = nullptr; - _eventListener = nullptr; - - if (_state) - { - clearTracks(); - if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); - spAnimationState_dispose(_state); - } -} - -void SpineAnimation::update (float deltaTime) -{ - if (!_paused) - { - deltaTime *= _timeScale * globalTimeScale; - spSkeleton_update(_skeleton, deltaTime); - spAnimationState_update(_state, deltaTime); - spAnimationState_apply(_state, _skeleton); - spSkeleton_updateWorldTransform(_skeleton); - } - - super::update(deltaTime); -} - -void SpineAnimation::setAnimationStateData (spAnimationStateData* stateData) -{ - CCASSERT(stateData, "stateData cannot be null."); - - if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); - spAnimationState_dispose(_state); - - _ownsAnimationStateData = false; - _state = spAnimationState_create(stateData); - _state->rendererObject = this; - _state->listener = animationCallback; -} - -void SpineAnimation::setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration) -{ - spAnimationStateData_setMixByName(_state->data, fromAnimation.c_str(), toAnimation.c_str(), duration); -} - -spTrackEntry* SpineAnimation::setAnimation (int trackIndex, const std::string& name, bool loop) -{ - spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, name.c_str()); - if (!animation) { - log("Spine: Animation not found: %s", name.c_str()); - return 0; - } - return spAnimationState_setAnimation(_state, trackIndex, animation, loop); -} - -spTrackEntry* SpineAnimation::addAnimation (int trackIndex, const std::string& name, bool loop, float delay) -{ - spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, name.c_str()); - if (!animation) - { - log("Spine: Animation not found: %s", name.c_str()); - return 0; - } - return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay); -} - -spTrackEntry* SpineAnimation::setEmptyAnimation (int trackIndex, float mixDuration) -{ - return spAnimationState_setEmptyAnimation(_state, trackIndex, mixDuration); -} - -void SpineAnimation::setEmptyAnimations (float mixDuration) -{ - spAnimationState_setEmptyAnimations(_state, mixDuration); -} - -spTrackEntry* SpineAnimation::addEmptyAnimation (int trackIndex, float mixDuration, float delay) -{ - return spAnimationState_addEmptyAnimation(_state, trackIndex, mixDuration, delay); -} - -spAnimation* SpineAnimation::findAnimation(const std::string& name) const -{ - return spSkeletonData_findAnimation(_skeleton->data, name.c_str()); -} - -spTrackEntry* SpineAnimation::getCurrent (int trackIndex) -{ - return spAnimationState_getCurrent(_state, trackIndex); -} - -void SpineAnimation::clearTracks () -{ - spAnimationState_clearTracks(_state); -} - -void SpineAnimation::clearTrack (int trackIndex) -{ - spAnimationState_clearTrack(_state, trackIndex); -} - -void SpineAnimation::onAnimationStateEvent (spTrackEntry* entry, spEventType type, spEvent* event) -{ - switch (type) - { - case SP_ANIMATION_START: - if (_startListener) _startListener(entry); - break; - case SP_ANIMATION_INTERRUPT: - if (_interruptListener) _interruptListener(entry); - break; - case SP_ANIMATION_END: - if (_endListener) _endListener(entry); - break; - case SP_ANIMATION_DISPOSE: - if (_disposeListener) _disposeListener(entry); - break; - case SP_ANIMATION_COMPLETE: - if (_completeListener) _completeListener(entry); - break; - case SP_ANIMATION_EVENT: - if (_eventListener) _eventListener(entry, event); - break; - } -} - -void SpineAnimation::onTrackEntryEvent (spTrackEntry* entry, spEventType type, spEvent* event) -{ - if (!entry->rendererObject) return; - _TrackEntryListeners* listeners = (_TrackEntryListeners*)entry->rendererObject; - switch (type) - { - case SP_ANIMATION_START: - if (listeners->startListener) listeners->startListener(entry); - break; - case SP_ANIMATION_INTERRUPT: - if (listeners->interruptListener) listeners->interruptListener(entry); - break; - case SP_ANIMATION_END: - if (listeners->endListener) listeners->endListener(entry); - break; - case SP_ANIMATION_DISPOSE: - if (listeners->disposeListener) listeners->disposeListener(entry); - break; - case SP_ANIMATION_COMPLETE: - if (listeners->completeListener) listeners->completeListener(entry); - break; - case SP_ANIMATION_EVENT: - if (listeners->eventListener) listeners->eventListener(entry, event); - break; - } -} - -void SpineAnimation::setStartListener (const StartListener& listener) -{ - _startListener = listener; -} - -void SpineAnimation::setInterruptListener (const InterruptListener& listener) -{ - _interruptListener = listener; -} - -void SpineAnimation::setEndListener (const EndListener& listener) -{ - _endListener = listener; -} - -void SpineAnimation::setDisposeListener (const DisposeListener& listener) -{ - _disposeListener = listener; -} - -void SpineAnimation::setCompleteListener (const CompleteListener& listener) -{ - _completeListener = listener; -} - -void SpineAnimation::setEventListener (const EventListener& listener) -{ - _eventListener = listener; -} - -void SpineAnimation::setTrackStartListener (spTrackEntry* entry, const StartListener& listener) -{ - getListeners(entry)->startListener = listener; -} - -void SpineAnimation::setTrackInterruptListener (spTrackEntry* entry, const InterruptListener& listener) -{ - getListeners(entry)->interruptListener = listener; -} - -void SpineAnimation::setTrackEndListener (spTrackEntry* entry, const EndListener& listener) -{ - getListeners(entry)->endListener = listener; -} - -void SpineAnimation::setTrackDisposeListener (spTrackEntry* entry, const DisposeListener& listener) -{ - getListeners(entry)->disposeListener = listener; -} - -void SpineAnimation::setTrackCompleteListener (spTrackEntry* entry, const CompleteListener& listener) -{ - getListeners(entry)->completeListener = listener; -} - -void SpineAnimation::setTrackEventListener (spTrackEntry* entry, const EventListener& listener) -{ - getListeners(entry)->eventListener = listener; -} - -spAnimationState* SpineAnimation::getState() const -{ - return _state; -} - -} +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF + * USE, DATA, OR PROFITS) 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. + *****************************************************************************/ + +#include "spine-creator-support/SpineAnimation.h" +#include "spine-creator-support/spine-cocos2dx.h" +#include "spine/extension.h" +#include + +USING_NS_CC; +using std::min; +using std::max; +using std::vector; + +namespace spine { + +typedef struct _TrackEntryListeners +{ + StartListener startListener; + InterruptListener interruptListener; + EndListener endListener; + DisposeListener disposeListener; + CompleteListener completeListener; + EventListener eventListener; +} _TrackEntryListeners; + +void animationCallback (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) +{ + ((SpineAnimation*)state->rendererObject)->onAnimationStateEvent(entry, type, event); +} + +void trackEntryCallback (spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) +{ + ((SpineAnimation*)state->rendererObject)->onTrackEntryEvent(entry, type, event); + if (type == SP_ANIMATION_DISPOSE) + if (entry->rendererObject) delete (spine::_TrackEntryListeners*)entry->rendererObject; +} + +static _TrackEntryListeners* getListeners (spTrackEntry* entry) +{ + if (!entry->rendererObject) { + entry->rendererObject = new spine::_TrackEntryListeners(); + entry->listener = trackEntryCallback; + } + return (_TrackEntryListeners*)entry->rendererObject; +} + +static float globalTimeScale = 1.0f; +void SpineAnimation::setGlobalTimeScale(float timeScale) +{ + globalTimeScale = timeScale; +} + +SpineAnimation* SpineAnimation::create() +{ + SpineAnimation* skeleton = new SpineAnimation(); + skeleton->autorelease(); + return skeleton; +} + +SpineAnimation* SpineAnimation::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) +{ + SpineAnimation* node = new SpineAnimation(); + node->initWithData(skeletonData, ownsSkeletonData); + node->autorelease(); + return node; +} + +SpineAnimation* SpineAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) +{ + SpineAnimation* node = new SpineAnimation(); + node->initWithJsonFile(skeletonJsonFile, atlas, scale); + node->autorelease(); + return node; +} + +SpineAnimation* SpineAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) +{ + SpineAnimation* node = new SpineAnimation(); + spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); + node->initWithJsonFile(skeletonJsonFile, atlas, scale); + node->autorelease(); + return node; +} + +SpineAnimation* SpineAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) +{ + SpineAnimation* node = new SpineAnimation(); + node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); + node->autorelease(); + return node; +} + +SpineAnimation* SpineAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) +{ + SpineAnimation* node = new SpineAnimation(); + spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); + node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); + node->autorelease(); + return node; +} + +void SpineAnimation::initialize () +{ + super::initialize(); + + _ownsAnimationStateData = true; + _state = spAnimationState_create(spAnimationStateData_create(_skeleton->data)); + _state->rendererObject = this; + _state->listener = animationCallback; +} + +SpineAnimation::SpineAnimation () +: SpineRenderer() +{ +} + +SpineAnimation::SpineAnimation (spSkeletonData *skeletonData, bool ownsSkeletonData) +: SpineRenderer(skeletonData, ownsSkeletonData) +{ + initialize(); +} + +SpineAnimation::SpineAnimation (const std::string& skeletonDataFile, spAtlas* atlas, float scale) +: SpineRenderer(skeletonDataFile, atlas, scale) +{ + initialize(); +} + +SpineAnimation::SpineAnimation (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) +: SpineRenderer(skeletonDataFile, atlasFile, scale) +{ + initialize(); +} + +SpineAnimation::~SpineAnimation () +{ + _startListener = nullptr; + _interruptListener = nullptr; + _endListener = nullptr; + _disposeListener = nullptr; + _completeListener = nullptr; + _eventListener = nullptr; + + if (_state) + { + clearTracks(); + if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); + spAnimationState_dispose(_state); + } +} + +void SpineAnimation::update (float deltaTime) +{ + if (!_paused) + { + deltaTime *= _timeScale * globalTimeScale; + spSkeleton_update(_skeleton, deltaTime); + spAnimationState_update(_state, deltaTime); + spAnimationState_apply(_state, _skeleton); + spSkeleton_updateWorldTransform(_skeleton); + } + + super::update(deltaTime); +} + +void SpineAnimation::setAnimationStateData (spAnimationStateData* stateData) +{ + CCASSERT(stateData, "stateData cannot be null."); + + if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); + spAnimationState_dispose(_state); + + _ownsAnimationStateData = false; + _state = spAnimationState_create(stateData); + _state->rendererObject = this; + _state->listener = animationCallback; +} + +void SpineAnimation::setMix (const std::string& fromAnimation, const std::string& toAnimation, float duration) +{ + spAnimationStateData_setMixByName(_state->data, fromAnimation.c_str(), toAnimation.c_str(), duration); +} + +spTrackEntry* SpineAnimation::setAnimation (int trackIndex, const std::string& name, bool loop) +{ + spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, name.c_str()); + if (!animation) { + log("Spine: Animation not found: %s", name.c_str()); + return 0; + } + return spAnimationState_setAnimation(_state, trackIndex, animation, loop); +} + +spTrackEntry* SpineAnimation::addAnimation (int trackIndex, const std::string& name, bool loop, float delay) +{ + spAnimation* animation = spSkeletonData_findAnimation(_skeleton->data, name.c_str()); + if (!animation) + { + log("Spine: Animation not found: %s", name.c_str()); + return 0; + } + return spAnimationState_addAnimation(_state, trackIndex, animation, loop, delay); +} + +spTrackEntry* SpineAnimation::setEmptyAnimation (int trackIndex, float mixDuration) +{ + return spAnimationState_setEmptyAnimation(_state, trackIndex, mixDuration); +} + +void SpineAnimation::setEmptyAnimations (float mixDuration) +{ + spAnimationState_setEmptyAnimations(_state, mixDuration); +} + +spTrackEntry* SpineAnimation::addEmptyAnimation (int trackIndex, float mixDuration, float delay) +{ + return spAnimationState_addEmptyAnimation(_state, trackIndex, mixDuration, delay); +} + +spAnimation* SpineAnimation::findAnimation(const std::string& name) const +{ + return spSkeletonData_findAnimation(_skeleton->data, name.c_str()); +} + +spTrackEntry* SpineAnimation::getCurrent (int trackIndex) +{ + return spAnimationState_getCurrent(_state, trackIndex); +} + +void SpineAnimation::clearTracks () +{ + spAnimationState_clearTracks(_state); +} + +void SpineAnimation::clearTrack (int trackIndex) +{ + spAnimationState_clearTrack(_state, trackIndex); +} + +void SpineAnimation::onAnimationStateEvent (spTrackEntry* entry, spEventType type, spEvent* event) +{ + switch (type) + { + case SP_ANIMATION_START: + if (_startListener) _startListener(entry); + break; + case SP_ANIMATION_INTERRUPT: + if (_interruptListener) _interruptListener(entry); + break; + case SP_ANIMATION_END: + if (_endListener) _endListener(entry); + break; + case SP_ANIMATION_DISPOSE: + if (_disposeListener) _disposeListener(entry); + break; + case SP_ANIMATION_COMPLETE: + if (_completeListener) _completeListener(entry); + break; + case SP_ANIMATION_EVENT: + if (_eventListener) _eventListener(entry, event); + break; + } +} + +void SpineAnimation::onTrackEntryEvent (spTrackEntry* entry, spEventType type, spEvent* event) +{ + if (!entry->rendererObject) return; + _TrackEntryListeners* listeners = (_TrackEntryListeners*)entry->rendererObject; + switch (type) + { + case SP_ANIMATION_START: + if (listeners->startListener) listeners->startListener(entry); + break; + case SP_ANIMATION_INTERRUPT: + if (listeners->interruptListener) listeners->interruptListener(entry); + break; + case SP_ANIMATION_END: + if (listeners->endListener) listeners->endListener(entry); + break; + case SP_ANIMATION_DISPOSE: + if (listeners->disposeListener) listeners->disposeListener(entry); + break; + case SP_ANIMATION_COMPLETE: + if (listeners->completeListener) listeners->completeListener(entry); + break; + case SP_ANIMATION_EVENT: + if (listeners->eventListener) listeners->eventListener(entry, event); + break; + } +} + +void SpineAnimation::setStartListener (const StartListener& listener) +{ + _startListener = listener; +} + +void SpineAnimation::setInterruptListener (const InterruptListener& listener) +{ + _interruptListener = listener; +} + +void SpineAnimation::setEndListener (const EndListener& listener) +{ + _endListener = listener; +} + +void SpineAnimation::setDisposeListener (const DisposeListener& listener) +{ + _disposeListener = listener; +} + +void SpineAnimation::setCompleteListener (const CompleteListener& listener) +{ + _completeListener = listener; +} + +void SpineAnimation::setEventListener (const EventListener& listener) +{ + _eventListener = listener; +} + +void SpineAnimation::setTrackStartListener (spTrackEntry* entry, const StartListener& listener) +{ + getListeners(entry)->startListener = listener; +} + +void SpineAnimation::setTrackInterruptListener (spTrackEntry* entry, const InterruptListener& listener) +{ + getListeners(entry)->interruptListener = listener; +} + +void SpineAnimation::setTrackEndListener (spTrackEntry* entry, const EndListener& listener) +{ + getListeners(entry)->endListener = listener; +} + +void SpineAnimation::setTrackDisposeListener (spTrackEntry* entry, const DisposeListener& listener) +{ + getListeners(entry)->disposeListener = listener; +} + +void SpineAnimation::setTrackCompleteListener (spTrackEntry* entry, const CompleteListener& listener) +{ + getListeners(entry)->completeListener = listener; +} + +void SpineAnimation::setTrackEventListener (spTrackEntry* entry, const EventListener& listener) +{ + getListeners(entry)->eventListener = listener; +} + +spAnimationState* SpineAnimation::getState() const +{ + return _state; +} + +} diff --git a/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp index 402a7e73a4..82b7102540 100644 --- a/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp @@ -33,12 +33,12 @@ #include "spine-creator-support/AttachmentVertices.h" #include "spine-creator-support/CreatorAttachmentLoader.h" #include -#include "platform/CCApplication.h" #include "base/CCScheduler.h" #include "MiddlewareMacro.h" -#include "MeshBuffer.h" +#include "renderer/renderer/Pass.h" +#include "renderer/renderer/Technique.h" +#include "MiddlewareRenderHandle.h" #include "SkeletonDataMgr.h" -#include "RenderInfoMgr.h" USING_NS_CC; USING_NS_MW; @@ -46,6 +46,11 @@ USING_NS_MW; using std::min; using std::max; using namespace spine; +using namespace cocos2d; +using namespace cocos2d::renderer; + +static const std::string techStage = "transparent"; +static const std::string textureKey = "texture"; SpineRenderer* SpineRenderer::create () { @@ -88,13 +93,6 @@ void SpineRenderer::initialize () { _clipper = spSkeletonClipping_create(); } - - if (_renderInfoOffset == nullptr) - { - // store global TypedArray begin and end offset - _renderInfoOffset = new IOTypedArray(se::Object::TypedArrayType::UINT32, sizeof(uint32_t)); - } - beginSchedule(); } @@ -116,12 +114,6 @@ void SpineRenderer::onDisable() void SpineRenderer::stopSchedule() { MiddlewareManager::getInstance()->removeTimer(this); - if (_renderInfoOffset) - { - _renderInfoOffset->reset(); - _renderInfoOffset->clear(); - } - if (_debugBuffer) { _debugBuffer->reset(); @@ -168,18 +160,14 @@ SpineRenderer::~SpineRenderer () if (_uuid != "") SkeletonDataMgr::getInstance()->releaseByUUID(_uuid); if (_clipper) spSkeletonClipping_dispose(_clipper); - if (_renderInfoOffset) - { - delete _renderInfoOffset; - _renderInfoOffset = nullptr; - } - if (_debugBuffer) { delete _debugBuffer; _debugBuffer = nullptr; } + CC_SAFE_RELEASE(_nodeProxy); + CC_SAFE_RELEASE(_effect); stopSchedule(); } @@ -280,46 +268,50 @@ void SpineRenderer::update (float deltaTime) auto mgr = MiddlewareManager::getInstance(); if (!mgr->isUpdating) return; - auto renderMgr = RenderInfoMgr::getInstance(); - auto renderInfo = renderMgr->getBuffer(); - if (!renderInfo) return; - - _renderInfoOffset->reset(); - // store renderInfo offset - _renderInfoOffset->writeUint32((uint32_t)renderInfo->getCurPos() / sizeof(uint32_t)); - - // If opacity is 0,then return. - if (_skeleton->color.a == 0) + if (_nodeProxy == nullptr) { - renderInfo->checkSpace(sizeof(uint32_t), true); - renderInfo->writeUint32(0); return; } + MiddlewareRenderHandle* renderHandle = (MiddlewareRenderHandle*)_nodeProxy->getHandle("render"); + if (renderHandle == nullptr) + { + return; + } + renderHandle->reset(); + + _nodeColor.a = _nodeProxy->getRealOpacity() / (float)255; + + // If opacity is 0,then return. + if (_skeleton->color.a == 0) + { + return; + } + Color4F color; Color4F darkColor; AttachmentVertices* attachmentVertices = nullptr; bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true; auto vertexFormat = _useTint? VF_XYUVCC : VF_XYUVC; - MeshBuffer* mb = mgr->getMeshBuffer(vertexFormat); + middleware::MeshBuffer* mb = mgr->getMeshBuffer(vertexFormat); middleware::IOBuffer& vb = mb->getVB(); middleware::IOBuffer& ib = mb->getIB(); - // vertex size in floats with one color + // vertex size in floats with one color int vs1 = sizeof(V2F_T2F_C4B) / sizeof(float); // verex size in floats with two color int vs2 = sizeof(V2F_T2F_C4B_C4B) / sizeof(float); - - int vbSize = 0; + + int vbSize = 0; int ibSize = 0; - - int preTextureIndex = -1; + + BlendFactor curBlendSrc = BlendFactor::ONE; + BlendFactor curBlendDst = BlendFactor::ZERO; int preBlendMode = -1; - int curBlendSrc = -1; - int curBlendDst = -1; + int preTextureIndex = -1; int curTextureIndex = -1; - int preISegWritePos = -1; + int preISegWritePos = -1; int curISegLen = 0; int debugSlotsLen = 0; @@ -327,6 +319,8 @@ void SpineRenderer::update (float deltaTime) spSlot* slot = nullptr; int isFull = 0; + middleware::Texture2D* texture = nullptr; + if (_debugSlots || _debugBones) { // If enable debug draw,then init debug buffer. @@ -343,65 +337,93 @@ void SpineRenderer::update (float deltaTime) } } - // check enough space - renderInfo->checkSpace(sizeof(uint32_t), true); - std::size_t materialLenOffset = renderInfo->getCurPos(); - //reserved space to save material len - renderInfo->writeUint32(0); - - auto flush = [&]() + auto flush = [&]() { // fill pre segment count field if (preISegWritePos != -1) { - renderInfo->writeUint32(preISegWritePos, curISegLen); + renderHandle->updateIARange(materialLen - 1, preISegWritePos, curISegLen); } // prepare to fill new segment field switch (slot->data->blendMode) { case SP_BLEND_MODE_ADDITIVE: - curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - curBlendDst = GL_ONE; + curBlendSrc = _premultipliedAlpha ? BlendFactor::ONE : BlendFactor::SRC_ALPHA; + curBlendDst = BlendFactor::ONE; break; case SP_BLEND_MODE_MULTIPLY: - curBlendSrc = GL_DST_COLOR; - curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + curBlendSrc = BlendFactor::DST_COLOR; + curBlendDst = BlendFactor::ONE_MINUS_SRC_ALPHA; break; case SP_BLEND_MODE_SCREEN: - curBlendSrc = GL_ONE; - curBlendDst = GL_ONE_MINUS_SRC_COLOR; + curBlendSrc = BlendFactor::ONE; + curBlendDst = BlendFactor::ONE_MINUS_SRC_COLOR; break; default: - curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + curBlendSrc = _premultipliedAlpha ? BlendFactor::ONE : BlendFactor::SRC_ALPHA; + curBlendDst = BlendFactor::ONE_MINUS_SRC_ALPHA; } - // check enough space - renderInfo->checkSpace(sizeof(uint32_t) * 7, true); + double curHash = curTextureIndex + (int)curBlendSrc + (int)curBlendDst; + Effect* renderEffect = renderHandle->getEffect(materialLen); + Technique::Parameter* param = nullptr; + Pass* pass = nullptr; + + if (renderEffect) + { + double renderHash = renderEffect->getHash(); + if (abs(renderHash - curHash) >= 0.01) + { + param = (Technique::Parameter*)&(renderEffect->getProperty(textureKey)); + Technique* tech = renderEffect->getTechnique(techStage); + Vector& passes = (Vector&)tech->getPasses(); + pass = *(passes.begin()); + } + } + else + { + if (_effect == nullptr) + { + cocos2d::log("SpineRender:update get effect failed"); + renderHandle->reset(); + return; + } + auto effect = new cocos2d::renderer::Effect(); + effect->autorelease(); + effect->copy(*_effect); + + Technique* tech = effect->getTechnique(techStage); + Vector& passes = (Vector&)tech->getPasses(); + pass = *(passes.begin()); + + renderHandle->updateNativeEffect(materialLen, effect); + renderEffect = effect; + param = (Technique::Parameter*)&(renderEffect->getProperty(textureKey)); + } - // fill new texture index - renderInfo->writeUint32(curTextureIndex); - // fill new blend src and dst - renderInfo->writeUint32(curBlendSrc); - renderInfo->writeUint32(curBlendDst); - // fill new index and vertex buffer id - auto glIB = mb->getGLIB(); - auto glVB = mb->getGLVB(); - renderInfo->writeUint32(glIB); - renderInfo->writeUint32(glVB); - // fill new index offset - renderInfo->writeUint32((uint32_t)ib.getCurPos() / sizeof(unsigned short)); - + if (param) + { + param->setTexture(texture->getNativeTexture()); + } + + if (pass) + { + pass->setBlend(BlendOp::ADD, curBlendSrc, curBlendDst, + BlendOp::ADD, curBlendSrc, curBlendDst); + } + + renderEffect->updateHash(curHash); + // save new segment count pos field - preISegWritePos = (int)renderInfo->getCurPos(); - // reserve indice segamentation count - renderInfo->writeUint32(0); - + preISegWritePos = (int)ib.getCurPos() / sizeof(unsigned short); + // save new segment vb and ib + renderHandle->updateIABuffer(materialLen, mb->getGLVB(), mb->getGLIB()); // reset pre blend mode to current preBlendMode = (int)slot->data->blendMode; - // reset pre texture index to current + // reset pre texture index to current preTextureIndex = curTextureIndex; + // reset index segmentation count curISegLen = 0; // material length increased @@ -725,9 +747,11 @@ void SpineRenderer::update (float deltaTime) } } - curTextureIndex = attachmentVertices->_texture->getRealTextureIndex(); - // If texture or blendMode change,will change material. - if (preTextureIndex != curTextureIndex || preBlendMode != slot->data->blendMode || isFull) + texture = attachmentVertices->_texture; + curTextureIndex = texture->getRealTextureIndex(); + + // If texture or blendMode change or vertex is more than 65535, will change material. + if (preTextureIndex != curTextureIndex || preBlendMode != (int)slot->data->blendMode || isFull) { flush(); } @@ -756,7 +780,7 @@ void SpineRenderer::update (float deltaTime) } spSkeletonClipping_clipEnd(_clipper, slot); - } // End slot traverse + } spSkeletonClipping_clipEnd2(_clipper); @@ -765,12 +789,11 @@ void SpineRenderer::update (float deltaTime) _debugBuffer->writeFloat32(0, debugSlotsLen); } - renderInfo->writeUint32(materialLenOffset, materialLen); - if (preISegWritePos != -1) + if (preISegWritePos != -1) { - renderInfo->writeUint32(preISegWritePos, curISegLen); + renderHandle->updateIARange(materialLen - 1, preISegWritePos, curISegLen); } - + if (_debugBones) { _debugBuffer->writeFloat32(_skeleton->bonesCount*4); @@ -791,7 +814,7 @@ void SpineRenderer::update (float deltaTime) _debugBuffer->writeFloat32(0, 0); _debugBuffer->writeFloat32(sizeof(float), 0); cocos2d::log("Spine debug data is too large,debug buffer has no space to put in it!!!!!!!!!!"); - cocos2d::log("You can adjust MAX_DEBUG_BUFFER_SIZE in Macro"); + cocos2d::log("You can adjust MAX_DEBUG_BUFFER_SIZE in MiddlewareMacro"); } } diff --git a/native/cocos/editor-support/spine-creator-support/SpineRenderer.h b/native/cocos/editor-support/spine-creator-support/SpineRenderer.h index ea6f5ef0dc..1bfd88d9ec 100644 --- a/native/cocos/editor-support/spine-creator-support/SpineRenderer.h +++ b/native/cocos/editor-support/spine-creator-support/SpineRenderer.h @@ -1,181 +1,190 @@ -/****************************************************************************** - * Spine Runtimes Software License v2.5 - * - * Copyright (c) 2013-2016, Esoteric Software - * All rights reserved. - * - * You are granted a perpetual, non-exclusive, non-sublicensable, and - * non-transferable license to use, install, execute, and perform the Spine - * Runtimes software and derivative works solely for personal or internal - * use. Without the written permission of Esoteric Software (see Section 2 of - * the Spine Software License Agreement), you may not (a) modify, translate, - * adapt, or develop new applications using the Spine Runtimes or otherwise - * create derivative works or improvements of the Spine Runtimes or (b) remove, - * delete, alter, or obscure any trademarks or any copyright, trademark, patent, - * or other intellectual property or proprietary rights notices on or in the - * Software, including any copy thereof. Redistributions in binary or source - * form must include this license and terms. - * - * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF - * USE, DATA, OR PROFITS) 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. - *****************************************************************************/ - -#pragma once - -#include "spine/spine.h" -#include "base/CCRef.h" -#include "base/ccTypes.h" -#include -#include "scripting/js-bindings/jswrapper/Object.hpp" -#include "IOTypedArray.h" -#include "MiddlewareManager.h" - -namespace spine { - - class AttachmentVertices; - - /** Draws a skeleton. - */ - class SpineRenderer: public cocos2d::middleware::IMiddleware, public cocos2d::Ref - { - public: - static SpineRenderer* create (); - static SpineRenderer* createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); - static SpineRenderer* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); - static SpineRenderer* createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); - static SpineRenderer* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); - - virtual void update (float deltaTime); - - spSkeleton* getSkeleton() const; - - void setTimeScale (float scale); - float getTimeScale () const; - - void updateWorldTransform (); - - void setToSetupPose (); - void setBonesToSetupPose (); - void setSlotsToSetupPose (); - void paused (bool value); - - /* Returns 0 if the bone was not found. */ - spBone* findBone (const std::string& boneName) const; - /* Returns 0 if the slot was not found. */ - spSlot* findSlot (const std::string& slotName) const; - - /* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are - * attached if the corresponding attachment from the old skin was attached. Returns false if the skin was not found. - * @param skin May be empty string ("") for no skin.*/ - bool setSkin (const std::string& skinName); - /** @param skin May be 0 for no skin.*/ - bool setSkin (const char* skinName); - - /* Returns 0 if the slot or attachment was not found. */ - spAttachment* getAttachment (const std::string& slotName, const std::string& attachmentName) const; - /* Returns false if the slot or attachment was not found. - * @param attachmentName May be empty string ("") for no attachment. */ - bool setAttachment (const std::string& slotName, const std::string& attachmentName); - /* @param attachmentName May be 0 for no attachment. */ - bool setAttachment (const std::string& slotName, const char* attachmentName); - - /* Enables/disables two color tinting for this instance. May break batching */ - void setUseTint(bool enabled); - - /* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */ - void setSlotsRange(int startSlotIndex, int endSlotIndex); - - /** - * @return debug data,it's a Float32Array, - * format |debug bones length|[beginX|beginY|toX|toY|...loop...] - */ - se_object_ptr getDebugData() const - { - if (_debugBuffer) - { - return _debugBuffer->getTypeArray(); - } - return nullptr; - } - - /** - * @return render info offset,it's a Uint32Array, - * format |render info offset| - */ - se_object_ptr getRenderInfoOffset() const - { - if (_renderInfoOffset) - { - return _renderInfoOffset->getTypeArray(); - } - return nullptr; - } - - void setColor (cocos2d::Color4B& color); - void setDebugBonesEnabled (bool enabled); - void setDebugSlotsEnabled (bool enabled); - - void setOpacityModifyRGB (bool value); - bool isOpacityModifyRGB () const; - - void beginSchedule(); - void stopSchedule(); - void onEnable(); - void onDisable(); - - CC_CONSTRUCTOR_ACCESS: - SpineRenderer (); - SpineRenderer(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); - SpineRenderer (spSkeletonData* skeletonData, bool ownsSkeletonData = false); - SpineRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); - SpineRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); - - virtual ~SpineRenderer (); - - void initWithUUID(const std::string& uuid); - void initWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); - void initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); - void initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); - void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); - void initWithBinaryFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); - void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); - - virtual void initialize (); - - protected: - void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData); - virtual AttachmentVertices* getAttachmentVertices (spRegionAttachment* attachment) const; - virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const; - - bool _ownsSkeletonData = true; - bool _ownsSkeleton = true; - spAtlas* _atlas = nullptr; - spAttachmentLoader* _attachmentLoader = nullptr; - spSkeleton* _skeleton = nullptr; - float _timeScale = 1; - bool _paused = false; - - bool _debugSlots = false; - bool _debugBones = false; - cocos2d::Color4F _nodeColor = cocos2d::Color4F::WHITE; - bool _premultipliedAlpha = false; - spSkeletonClipping* _clipper = nullptr; - bool _useTint = false; - std::string _uuid = ""; - - int _startSlotIndex = -1; - int _endSlotIndex = -1; - - cocos2d::middleware::IOTypedArray* _renderInfoOffset = nullptr; - cocos2d::middleware::IOTypedArray* _debugBuffer = nullptr; - }; - -} +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF + * USE, DATA, OR PROFITS) 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. + *****************************************************************************/ + +#pragma once + +#include "spine/spine.h" +#include "base/CCRef.h" +#include "base/ccTypes.h" +#include +#include "scripting/js-bindings/jswrapper/Object.hpp" +#include "IOTypedArray.h" +#include "MiddlewareManager.h" +#include "renderer/scene/NodeProxy.hpp" +#include "base/CCMap.h" +#include "middleware-adapter.h" +#include "base/ccMacros.h" + +namespace spine { + + class NodeProxy; + class AttachmentVertices; + + /** Draws a skeleton. + */ + class SpineRenderer: public cocos2d::middleware::IMiddleware, public cocos2d::Ref + { + public: + static SpineRenderer* create (); + static SpineRenderer* createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); + static SpineRenderer* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); + static SpineRenderer* createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); + static SpineRenderer* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); + + virtual void update (float deltaTime); + + spSkeleton* getSkeleton() const; + + void setTimeScale (float scale); + float getTimeScale () const; + + void updateWorldTransform (); + + void setToSetupPose (); + void setBonesToSetupPose (); + void setSlotsToSetupPose (); + void paused (bool value); + + /* Returns 0 if the bone was not found. */ + spBone* findBone (const std::string& boneName) const; + /* Returns 0 if the slot was not found. */ + spSlot* findSlot (const std::string& slotName) const; + + /* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are + * attached if the corresponding attachment from the old skin was attached. Returns false if the skin was not found. + * @param skin May be empty string ("") for no skin.*/ + bool setSkin (const std::string& skinName); + /** @param skin May be 0 for no skin.*/ + bool setSkin (const char* skinName); + + /* Returns 0 if the slot or attachment was not found. */ + spAttachment* getAttachment (const std::string& slotName, const std::string& attachmentName) const; + /* Returns false if the slot or attachment was not found. + * @param attachmentName May be empty string ("") for no attachment. */ + bool setAttachment (const std::string& slotName, const std::string& attachmentName); + /* @param attachmentName May be 0 for no attachment. */ + bool setAttachment (const std::string& slotName, const char* attachmentName); + + /* Enables/disables two color tinting for this instance. May break batching */ + void setUseTint(bool enabled); + + /* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */ + void setSlotsRange(int startSlotIndex, int endSlotIndex); + + /** + * @return debug data,it's a Float32Array, + * format |debug bones length|[beginX|beginY|toX|toY|...loop...] + */ + se_object_ptr getDebugData() const + { + if (_debugBuffer) + { + return _debugBuffer->getTypeArray(); + } + return nullptr; + } + + void bindNodeProxy(cocos2d::renderer::NodeProxy* node) + { + if (node == _nodeProxy) return; + CC_SAFE_RELEASE(_nodeProxy); + _nodeProxy = node; + CC_SAFE_RETAIN(_nodeProxy); + } + + void setNativeEffect(cocos2d::renderer::Effect* effect) + { + if (effect == _effect) return; + CC_SAFE_RELEASE(_effect); + _effect = effect; + CC_SAFE_RETAIN(_effect); + } + + void setColor (cocos2d::Color4B& color); + void setDebugBonesEnabled (bool enabled); + void setDebugSlotsEnabled (bool enabled); + + void setOpacityModifyRGB (bool value); + bool isOpacityModifyRGB () const; + + void beginSchedule(); + void stopSchedule(); + void onEnable(); + void onDisable(); + + CC_CONSTRUCTOR_ACCESS: + SpineRenderer (); + SpineRenderer(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); + SpineRenderer (spSkeletonData* skeletonData, bool ownsSkeletonData = false); + SpineRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); + SpineRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); + + virtual ~SpineRenderer (); + + void initWithUUID(const std::string& uuid); + void initWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); + void initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); + void initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); + void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); + void initWithBinaryFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); + void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); + + virtual void initialize (); + + protected: + void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData); + virtual AttachmentVertices* getAttachmentVertices (spRegionAttachment* attachment) const; + virtual AttachmentVertices* getAttachmentVertices (spMeshAttachment* attachment) const; + + bool _ownsSkeletonData = true; + bool _ownsSkeleton = true; + spAtlas* _atlas = nullptr; + spAttachmentLoader* _attachmentLoader = nullptr; + spSkeleton* _skeleton = nullptr; + float _timeScale = 1; + bool _paused = false; + + bool _debugSlots = false; + bool _debugBones = false; + cocos2d::Color4F _nodeColor = cocos2d::Color4F::WHITE; + bool _premultipliedAlpha = false; + spSkeletonClipping* _clipper = nullptr; + bool _useTint = false; + std::string _uuid = ""; + + int _startSlotIndex = -1; + int _endSlotIndex = -1; + + cocos2d::middleware::IOTypedArray* _debugBuffer = nullptr; + cocos2d::renderer::NodeProxy* _nodeProxy = nullptr; + cocos2d::renderer::Effect* _effect = nullptr; + }; + +} diff --git a/native/cocos/math/Vec3.cpp b/native/cocos/math/Vec3.cpp index 04d387b858..79070375c1 100644 --- a/native/cocos/math/Vec3.cpp +++ b/native/cocos/math/Vec3.cpp @@ -23,6 +23,7 @@ #include "math/Vec3.h" #include "math/MathUtil.h" #include "base/ccMacros.h" +#include "math/Quaternion.h" NS_CC_MATH_BEGIN @@ -153,6 +154,36 @@ void Vec3::cross(const Vec3& v1, const Vec3& v2, Vec3* dst) MathUtil::crossVec3(&v1.x, &v2.x, &dst->x); } +void Vec3::multiply(const Vec3& v) +{ + x *= v.x; + y *= v.y; + z *= v.z; +} + +void Vec3::multiply(const Vec3& v1, const Vec3& v2, Vec3* dst) +{ + dst->x = v1.x * v2.x; + dst->y = v1.y * v2.y; + dst->z = v1.z * v2.z; +} + +void Vec3::transformQuat(const Quaternion& q) +{ + float qx = q.x, qy = q.y, qz = q.z, qw = q.w; + + // calculate quat * vec + float ix = qw * x + qy * z - qz * y; + float iy = qw * y + qz * x - qx * z; + float iz = qw * z + qx * y - qy * x; + float iw = -qx * x - qy * y - qz * z; + + // calculate result * inverse quat + x = ix * qw + iw * -qx + iy * -qz - iz * -qy; + y = iy * qw + iw * -qy + iz * -qx - ix * -qz; + z = iz * qw + iw * -qz + ix * -qy - iy * -qx; +} + float Vec3::distance(const Vec3& v) const { float dx = v.x - x; diff --git a/native/cocos/math/Vec3.h b/native/cocos/math/Vec3.h index b1fe923114..04c667bce4 100644 --- a/native/cocos/math/Vec3.h +++ b/native/cocos/math/Vec3.h @@ -199,6 +199,29 @@ public: * @param dst A vector to store the result in. */ static void cross(const Vec3& v1, const Vec3& v2, Vec3* dst); + + /** + * Multiply the elements of the specified vector to this one. + * + * @param v The vector to multiply. + */ + void multiply(const Vec3& v); + + /** + * Multiply the specified vectors and stores the result in dst. + * + * @param v1 The first vector. + * @param v2 The second vector. + * @param dst A vector to store the result in. + */ + static void multiply(const Vec3& v1, const Vec3& v2, Vec3* dst); + + /** + * Transforms this vector by the specified quaternion and stores the result in this vector. + * + * @param q The quaternion to multiply. + */ + void transformQuat(const Quaternion& q); /** * Returns the distance between this vector and v. diff --git a/native/cocos/renderer/gfx/DeviceGraphics.cpp b/native/cocos/renderer/gfx/DeviceGraphics.cpp index b646138a6d..93f0f33614 100644 --- a/native/cocos/renderer/gfx/DeviceGraphics.cpp +++ b/native/cocos/renderer/gfx/DeviceGraphics.cpp @@ -284,14 +284,14 @@ void DeviceGraphics::setBlendColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) void DeviceGraphics::setBlendFunc(BlendFactor src, BlendFactor dst) { - _nextState.blendSepartion = false; + _nextState.blendSeparation = false; _nextState.blendSrc = src; _nextState.blendDst = dst; } void DeviceGraphics::setBlendFuncSeparate(BlendFactor srcRGB, BlendFactor dstRGB, BlendFactor srcAlpha, BlendFactor dstAlpha) { - _nextState.blendSepartion = true; + _nextState.blendSeparation = true; _nextState.blendSrc = srcRGB; _nextState.blendDst = dstRGB; _nextState.blendSrcAlpha = srcAlpha; @@ -300,13 +300,13 @@ void DeviceGraphics::setBlendFuncSeparate(BlendFactor srcRGB, BlendFactor dstRGB void DeviceGraphics::setBlendEquation(BlendOp mode) { - _nextState.blendSepartion = false; + _nextState.blendSeparation = false; _nextState.blendEq = mode; } void DeviceGraphics::setBlendEquationSeparate(BlendOp modeRGB, BlendOp modeAlpha) { - _nextState.blendSepartion = true; + _nextState.blendSeparation = true; _nextState.blendEq = modeRGB; _nextState.blendAlphaEq = modeAlpha; } @@ -431,6 +431,7 @@ void DeviceGraphics::draw(size_t base, GLsizei count) GL_CHECK(glDrawArrays(ENUM_CLASS_TO_GLENUM(_nextState.primitiveType), (GLint)base, count)); } + _drawCalls++; _currentState = std::move(_nextState); } @@ -680,7 +681,7 @@ void DeviceGraphics::commitBlendStates() } - if (_nextState.blendSepartion) + if (_nextState.blendSeparation) { GL_CHECK(glBlendFuncSeparate(ENUM_CLASS_TO_GLENUM(_nextState.blendSrc), ENUM_CLASS_TO_GLENUM(_nextState.blendDst), @@ -708,9 +709,9 @@ void DeviceGraphics::commitBlendStates() (_nextState.blendColor >> 8 & 0xff) / 255.f, (_nextState.blendColor & 0xff) / 255.f); - if (_currentState.blendSepartion != _nextState.blendSepartion) + if (_currentState.blendSeparation != _nextState.blendSeparation) { - if (_nextState.blendSepartion) + if (_nextState.blendSeparation) { GL_CHECK(glBlendFuncSeparate(ENUM_CLASS_TO_GLENUM(_nextState.blendSrc), ENUM_CLASS_TO_GLENUM(_nextState.blendDst), @@ -729,7 +730,7 @@ void DeviceGraphics::commitBlendStates() return; } - if (_nextState.blendSepartion) + if (_nextState.blendSeparation) { if (_currentState.blendSrc != _nextState.blendSrc || _currentState.blendDst != _nextState.blendDst || @@ -1031,8 +1032,8 @@ void DeviceGraphics::commitVertexBuffer() for (int j = 0; j < usedAttriLen; ++j) { const auto& attr = attributes[j]; - const auto& el = vb->getFormat().getElement(attr.name); - if (!el.isValid()) + const auto* el = vb->getFormat().getElement(attr.name); + if (!el->isValid()) { RENDERER_LOGW("Can not find vertex attribute: %s", attr.name.c_str()); continue; @@ -1047,11 +1048,11 @@ void DeviceGraphics::commitVertexBuffer() // glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); GL_CHECK(ccVertexAttribPointer(attr.location, - el.num, - ENUM_CLASS_TO_GLENUM(el.type), - el.normalize, - el.stride, - (GLvoid*)(el.offset + vboffset * el.stride))); + el->num, + ENUM_CLASS_TO_GLENUM(el->type), + el->normalize, + el->stride, + (GLvoid*)(el->offset + vboffset * el->stride))); } } diff --git a/native/cocos/renderer/gfx/DeviceGraphics.h b/native/cocos/renderer/gfx/DeviceGraphics.h index d37a51aecd..cdd27c0776 100644 --- a/native/cocos/renderer/gfx/DeviceGraphics.h +++ b/native/cocos/renderer/gfx/DeviceGraphics.h @@ -38,7 +38,6 @@ #include "../Types.h" #include "State.h" - RENDERER_BEGIN class FrameBuffer; @@ -47,6 +46,15 @@ class IndexBuffer; class Program; class Texture; +/** + * @addtogroup gfx + * @{ + */ + +/** + * DeviceGraphics is a direct abstraction for OpenGL APIs. + * This fundamental class takes responsibility for all GL states management and GL call invocations. + */ class DeviceGraphics final : public Ref { public: @@ -60,69 +68,227 @@ public: int maxColorAttatchments; }; + /** + * Returns a shared instance of the director. + */ static DeviceGraphics* getInstance(); - - inline const Capacity& getCapacity() const { return _caps; } + + /** + * Checks whether a gl extension is supported + */ bool supportGLExtension(const std::string& extension) const; + /** + * Sets the target FrameBuffer + */ void setFrameBuffer(const FrameBuffer* fb); + /** + * Sets viewport with x, y, width and height + */ void setViewport(int x, int y, int w, int h); + /** + * Sets scissor clipping area + */ void setScissor(int x, int y, int w, int h); - + + /** + * Clear with flags, including color, depth and stencil, + * you should also specify the color, depth and stencil value to use. + */ void clear(uint8_t flags, Color4F *color, double depth, int32_t stencil); - + + /** + * Enables blend in GL state + */ void enableBlend(); + /** + * Enables depth test in GL state + */ void enableDepthTest(); + /** + * Enables depth write in GL state + */ void enableDepthWrite(); + /** + * Enables stencil test in GL state + */ void enableStencilTest(); - + + /** + * Sets both the front and back function and reference value for stencil testing + */ void setStencilFunc(StencilFunc func, int ref, unsigned int mask); + /** + * Sets the front function and reference value for stencil testing + */ void setStencilFuncFront(StencilFunc func, int ref, unsigned int mask); + /** + * Sets the back function and reference value for stencil testing + */ void setStencilFuncBack(StencilFunc func, int ref, unsigned int mask); - + + /** + * Sets both the front and back-facing stencil test actions + */ void setStencilOp(StencilOp failOp, StencilOp zFailOp, StencilOp zPassOp, unsigned int writeMask); + /** + * Sets the front stencil test actions + */ void setStencilOpFront(StencilOp failOp, StencilOp zFailOp, StencilOp zPassOp, unsigned int writeMask); + /** + * Sets the back stencil test actions + */ void setStencilOpBack(StencilOp failOp, StencilOp zFailOp, StencilOp zPassOp, unsigned int writeMask); - + + /** + * Specifies the depth comparison function, which sets the conditions under which the pixel will be drawn. + */ void setDepthFunc(DepthFunc func); - + + /** + * Sets the source and destination blending factors with all channel packed into a 32bit unsigned int + */ void setBlendColor(uint32_t rgba); + /** + * Sets the source and destination blending factors with separate color channel values + */ void setBlendColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + /** + * Sets which function is used for blending pixel arithmetic + */ void setBlendFunc(BlendFactor src, BlendFactor dst); + /** + * Sets which function is used for blending pixel arithmetic for RGB and alpha components separately + */ void setBlendFuncSeparate(BlendFactor srcRGB, BlendFactor dstRGB, BlendFactor srcAlpha, BlendFactor dstAlpha); + /** + * Sets both the RGB blend equation and alpha blend equation to a single equation. + */ void setBlendEquation(BlendOp mode); + /** + * Sets the RGB blend equation and alpha blend equation separately. + */ void setBlendEquationSeparate(BlendOp modeRGB, BlendOp modeAlpha); - + + /** + * Specifies whether or not front and/or back-facing polygons can be culled. + */ void setCullMode(CullMode mode); - + + /** + * Sets the vertex buffer + */ void setVertexBuffer(int stream, VertexBuffer* buffer, int start = 0); + /** + * Sets the index buffer + */ void setIndexBuffer(IndexBuffer *buffer); + /** + * Sets a linked program + */ void setProgram(Program *program); + /** + * Sets a texture into a GL texture slot then set to the specified uniform + */ void setTexture(const std::string& name, Texture* texture, int slot); + /** + * Sets textures array into GL texture slots then set to the specified uniform + */ void setTextureArray(const std::string& name, const std::vector& textures, const std::vector& slots); - + + /** + * Sets a integer to the specified uniform + */ void setUniformi(const std::string& name, int i1); + /** + * Sets two integers to the specified uniform + */ void setUniformi(const std::string& name, int i1, int i2); + /** + * Sets three integers to the specified uniform + */ void setUniformi(const std::string& name, int i1, int i2, int i3); + /** + * Sets four integers to the specified uniform + */ void setUniformi(const std::string& name, int i1, int i2, int i3, int i4); + /** + * Sets a vector of integers to the specified uniform + */ void setUniformiv(const std::string& name, size_t count, const int* value); + /** + * Sets a float to the specified uniform + */ void setUniformf(const std::string& name, float f1); + /** + * Sets two floats to the specified uniform + */ void setUniformf(const std::string& name, float f1, float f2); + /** + * Sets three floats to the specified uniform + */ void setUniformf(const std::string& name, float f1, float f2, float f3); + /** + * Sets four floats to the specified uniform + */ void setUniformf(const std::string& name, float f1, float f2, float f3, float f4); + /** + * Sets a vector of floats to the specified uniform + */ void setUniformfv(const std::string& name, size_t count, const float* value); + /** + * Sets a Vec2 to the specified uniform + */ void setUniformVec2(const std::string& name, const cocos2d::Vec2& value); + /** + * Sets a Vec3 to the specified uniform + */ void setUniformVec3(const std::string& name, const cocos2d::Vec3& value); + /** + * Sets a Vec4 to the specified uniform + */ void setUniformVec4(const std::string& name, const cocos2d::Vec4& value); + /** + * Sets a 2x2 matrix to the specified uniform + */ void setUniformMat2(const std::string& name, float* value); + /** + * Sets a 3x3 matrix to the specified uniform + */ void setUniformMat3(const std::string& name, float* value); + /** + * Sets a 4x4 matrix specified by float pointer to the given uniform + */ void setUniformMat4(const std::string& name, float* value); + /** + * Sets a Mat4 object to the given uniform + */ void setUniformMat4(const std::string& name, const cocos2d::Mat4& value); + /** + * Sets data specified by data pointer, type and bytes to the given uniform + */ void setUniform(const std::string& name, const void* v, size_t bytes, UniformElementType elementType); + /** + * Sets the primitive type for draw calls + */ void setPrimitiveType(PrimitiveType type); - + + /** + * Draw elements using the current gl states + */ void draw(size_t base, GLsizei count); + + /** + * Resets the draw call counter to 0 + */ + void resetDrawCalls() { _drawCalls = 0; }; + /** + * Gets current draw call counts + */ + uint32_t getDrawCalls() const { return _drawCalls; }; + + inline const Capacity& getCapacity() const { return _caps; } private: @@ -170,6 +336,8 @@ private: int _sy; int _sw; int _sh; + + uint32_t _drawCalls = 0; int _defaultFbo; @@ -188,4 +356,7 @@ private: friend class Texture2D; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/FrameBuffer.h b/native/cocos/renderer/gfx/FrameBuffer.h index 315cc3a3d5..4dd771cdfa 100644 --- a/native/cocos/renderer/gfx/FrameBuffer.h +++ b/native/cocos/renderer/gfx/FrameBuffer.h @@ -22,10 +22,8 @@ THE SOFTWARE. ****************************************************************************/ - #pragma once - #include #include "../Macro.h" #include "../Types.h" @@ -36,24 +34,80 @@ RENDERER_BEGIN class DeviceGraphics; class RenderTarget; +/** + * @addtogroup gfx + * @{ + */ + +/** + * The FrameBuffer class can store the render results of DeviceGraphics. + * It contains color buffers, depth buffers and stencil buffers, + * they are destinations for drawing, clearing and writing operations during the render process. + */ class FrameBuffer final : public GraphicsHandle { public: + /** + * Create a FrameBuffer object with device and size + */ RENDERER_DEFINE_CREATE_METHOD_3(FrameBuffer, init, DeviceGraphics*, uint16_t, uint16_t) FrameBuffer(); + /** + * Inits the frame buffer with device and size + */ bool init(DeviceGraphics* device, uint16_t width, uint16_t height); + /** + * Destroys the GL buffers created by this frame buffer object + */ void destroy(); + /** + * Sets the color buffers as drawing and clearing destinations + */ void setColorBuffers(const std::vector& renderTargets); + /** + * Sets a color buffer at specific index + */ void setColorBuffer(RenderTarget* rt, int index); + /** + * Sets the depth buffer as depth writing destination + */ void setDepthBuffer(RenderTarget* rt); + /** + * Sets the stencil buffer as stencil writing destination + */ void setStencilBuffer(RenderTarget* rt); + /** + * Sets the depth and stencil buffer at the same time. + * If you want to set both with the same RenderTarget, you should use this instead of setting them separatly. + */ void setDepthStencilBuffer(RenderTarget* rt); + /** + * Sets the width of frame buffer + */ + inline int getWidth() const { return _width; } + /** + * Sets the width of frame buffer + */ + inline int getHeight() const { return _height; } + + /** + * Gets the color buffers + */ const std::vector& getColorBuffers() const; + /** + * Gets the depth buffer + */ const RenderTarget* getDepthBuffer() const; + /** + * Gets the stencil buffer + */ const RenderTarget* getStencilBuffer() const; + /** + * Gets the depth and stencil buffer if they share the same one. + */ const RenderTarget* getDepthStencilBuffer() const; private: @@ -68,4 +122,7 @@ private: uint16_t _height; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/GFX.cpp b/native/cocos/renderer/gfx/GFX.cpp index e913f1f41c..2a3d8119e3 100644 --- a/native/cocos/renderer/gfx/GFX.cpp +++ b/native/cocos/renderer/gfx/GFX.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/GFX.h b/native/cocos/renderer/gfx/GFX.h index 7a7b2ad569..8caae6cf37 100644 --- a/native/cocos/renderer/gfx/GFX.h +++ b/native/cocos/renderer/gfx/GFX.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/GFXUtils.cpp b/native/cocos/renderer/gfx/GFXUtils.cpp index 5544d6d453..f511092226 100644 --- a/native/cocos/renderer/gfx/GFXUtils.cpp +++ b/native/cocos/renderer/gfx/GFXUtils.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/GFXUtils.h b/native/cocos/renderer/gfx/GFXUtils.h index c68160d730..c3ba547008 100644 --- a/native/cocos/renderer/gfx/GFXUtils.h +++ b/native/cocos/renderer/gfx/GFXUtils.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/GraphicsHandle.cpp b/native/cocos/renderer/gfx/GraphicsHandle.cpp index f3d18d724b..bd4db097b3 100644 --- a/native/cocos/renderer/gfx/GraphicsHandle.cpp +++ b/native/cocos/renderer/gfx/GraphicsHandle.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/GraphicsHandle.h b/native/cocos/renderer/gfx/GraphicsHandle.h index 3da43d380d..ed7b714818 100644 --- a/native/cocos/renderer/gfx/GraphicsHandle.h +++ b/native/cocos/renderer/gfx/GraphicsHandle.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,15 +31,30 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + +/** + * Abstract class for GL graphic classes that uses a GL handle id. + * Such as Texture, FrameBuffer, IndexBuffer, VertexBuffer, Program. + */ class GraphicsHandle : public Ref { public: GraphicsHandle(); virtual ~GraphicsHandle(); + /** + * Gets the GL handle + */ inline GLuint getHandle() const { return _glID; } protected: GLuint _glID; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/IndexBuffer.cpp b/native/cocos/renderer/gfx/IndexBuffer.cpp index 2db942a9ab..6e43109329 100644 --- a/native/cocos/renderer/gfx/IndexBuffer.cpp +++ b/native/cocos/renderer/gfx/IndexBuffer.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/IndexBuffer.h b/native/cocos/renderer/gfx/IndexBuffer.h index ff0aa118d2..78f3f96425 100644 --- a/native/cocos/renderer/gfx/IndexBuffer.h +++ b/native/cocos/renderer/gfx/IndexBuffer.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + #pragma once #include @@ -30,32 +31,95 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + class DeviceGraphics; +/** + * IndexBuffer manages the GL buffer for element indices. + * It creates, updates and destoies the GL buffer. + */ class IndexBuffer final : public GraphicsHandle { public: + /** + * Creates an IndexBuffer object + * @param[in] device DeviceGraphics pointer. + * @param[in] format Index element format. + * @param[in] usage The usage pattern of the index buffer. + * @param[in] data Data pointer, could be nullptr, then nothing is updated to the buffer. + * @param[in] dataByteLength Data's byte length. + * @param[in] numIndices Count of indices. + */ RENDERER_DEFINE_CREATE_METHOD_6(IndexBuffer, init, DeviceGraphics*, IndexFormat, Usage, const void*, size_t, uint32_t) IndexBuffer(); virtual ~IndexBuffer(); + /** + * Initializes the index buffer with necessary options. + * @param[in] device DeviceGraphics pointer. + * @param[in] format Index element format. + * @param[in] usage The usage pattern of the index buffer. + * @param[in] data Data pointer, could be nullptr, then nothing is updated to the buffer. + * @param[in] dataByteLength Data's byte length. + * @param[in] numIndices Count of indices. + */ bool init(DeviceGraphics* device, IndexFormat format, Usage usage, const void* data, size_t dataByteLength, uint32_t numIndices); + /** + * Update data to the GL index buffer + * @param[in] offset Destination offset for filling buffer data. + * @param[in] data Data to be updated. + * @param[in] dataByteLength Data byte length to be updated. + */ void update(uint32_t offset, const void* data, size_t dataByteLength); + /** + * Gets the count of indices. + */ inline uint32_t getCount() const { return _numIndices; } + /** + * Sets the count of indices. + */ inline void setCount(uint32_t numIndices) { _numIndices = numIndices; } + /** + * Gets the format of indices. + */ inline IndexFormat getFormat() const { return _format; } + /** + * Sets the format of indices. + */ inline void setFormat(IndexFormat format) { _format = format; } + /** + * Gets bytes occupied by each index. + */ inline uint32_t getBytesPerIndex() const { return _bytesPerIndex; } + /** + * Sets bytes occupied by each index. + */ inline void setBytesPerIndex(uint32_t bytesPerIndex) {_bytesPerIndex = bytesPerIndex; } + /** + * Gets usage pattern of the index buffer + */ inline Usage getUsage() const { return _usage; } + /** + * Sets usage pattern of the index buffer + */ inline void setUsage(Usage usage) { _usage = usage; } + /** + * Gets byte size of the index buffer + */ inline uint32_t getBytes() const { return _bytes; } + /** + * Sets byte size of the index buffer + */ inline void setBytes(uint32_t bytes) { _bytes = bytes; } using FetchDataCallback = std::function; @@ -68,7 +132,10 @@ public: } return _fetchDataCallback(bytes); } - + + /** + * Destroies the index buffer + */ void destroy(); private: @@ -84,4 +151,7 @@ private: CC_DISALLOW_COPY_ASSIGN_AND_MOVE(IndexBuffer) }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/Program.cpp b/native/cocos/renderer/gfx/Program.cpp index 6e2d83b0af..00819219e1 100644 --- a/native/cocos/renderer/gfx/Program.cpp +++ b/native/cocos/renderer/gfx/Program.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/Program.h b/native/cocos/renderer/gfx/Program.h index c98c07a72c..430bc43aa0 100644 --- a/native/cocos/renderer/gfx/Program.h +++ b/native/cocos/renderer/gfx/Program.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -34,41 +34,111 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + class DeviceGraphics; +/** + * Program class manages the internal GL shader program. + */ class Program final: public GraphicsHandle { public: + /** + * Describes vertex attribute informations used in the program + * @struct Attribute + */ struct Attribute { + /** + * Attribute name + */ std::string name; + /** + * Number of components per attribute + */ GLsizei size; + /** + * Attribute location + */ GLuint location; + /** + * Attribute type + */ GLenum type; }; + /** + * Describes uniform informations used in the program + * @struct Uniform + */ struct Uniform { + /** + * Uniform name + */ std::string name; + /** + * The length of the array for uniforms declared as arrays, default value is 1 + */ GLsizei size; + /** + * Uniform location + */ GLint location; + /** + * Uniform type + */ GLenum type; + /** + * Sets the uniform value + */ void setUniform(const void* value, UniformElementType elementType) const; + /** + * Sets the callback which will be called when uniform updated + */ using SetUniformCallback = void (*)(GLint, GLsizei, const void*, UniformElementType); // location, count, value, elementType private: SetUniformCallback _callback; friend class Program; }; + /** + * Creates a Program with device and shader sources + */ RENDERER_DEFINE_CREATE_METHOD_3(Program, init, DeviceGraphics*, const char*, const char*) Program(); virtual ~Program(); + /** + * Initializes a Program with device and program sources + * @param[in] device DeviceGraphics pointer + * @param[in] vertSource Vertex shader program + * @param[in] fragSource Fragment shader program + */ bool init(DeviceGraphics* device, const char* vertSource, const char* fragSource); + /** + * Gets the id of program + */ inline uint32_t getID() const { return _id; } + /** + * Gets the attibutes used in the program + */ inline const std::vector& getAttributes() const { return _attributes; } + /** + * Gets the uniforms used in the program + */ inline const std::vector& getUniforms() const { return _uniforms; } + /** + * Indicates whether the program is successfully linked + */ inline bool isLinked() const { return _linked; } + /** + * Link the program with its shader sources + */ void link(); private: DeviceGraphics* _device; @@ -80,4 +150,7 @@ private: bool _linked; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/RenderBuffer.cpp b/native/cocos/renderer/gfx/RenderBuffer.cpp index 591a2d25a3..717ecdcb27 100644 --- a/native/cocos/renderer/gfx/RenderBuffer.cpp +++ b/native/cocos/renderer/gfx/RenderBuffer.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/RenderBuffer.h b/native/cocos/renderer/gfx/RenderBuffer.h index 60f52b8236..147397a4a4 100644 --- a/native/cocos/renderer/gfx/RenderBuffer.h +++ b/native/cocos/renderer/gfx/RenderBuffer.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,12 +31,23 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + class DeviceGraphics; +/** + * RenderBuffer manages the GL render buffer. + * A render buffer stores data such as an image, or can be source or target of a rendering operation. + */ class RenderBuffer final : public RenderTarget { public: - // render-buffer format + /** + * RenderBuffer's pixel format + */ enum class Format : uint32_t { RGBA4 = GL_RGBA4, @@ -46,11 +57,17 @@ public: // D24S8 = GL_DEPTH_STENCIL }; + /** + * Creates a RenderBuffer with device, pixel format and size + */ RENDERER_DEFINE_CREATE_METHOD_4(RenderBuffer, init, DeviceGraphics*, Format, uint16_t, uint16_t) RenderBuffer(); virtual ~RenderBuffer(); + /** + * Initializes a RenderBuffer with device, pixel format and size + */ bool init(DeviceGraphics* device, Format format, uint16_t width, uint16_t height); private: @@ -60,4 +77,7 @@ private: uint16_t _height; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/RenderTarget.cpp b/native/cocos/renderer/gfx/RenderTarget.cpp index 13f5279b06..027d8b8ecd 100644 --- a/native/cocos/renderer/gfx/RenderTarget.cpp +++ b/native/cocos/renderer/gfx/RenderTarget.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/RenderTarget.h b/native/cocos/renderer/gfx/RenderTarget.h index 69b6b9c3a6..204529e67c 100644 --- a/native/cocos/renderer/gfx/RenderTarget.h +++ b/native/cocos/renderer/gfx/RenderTarget.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -33,10 +33,21 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + +/** + * Abstract class for all classes that could act as a render target + */ class RenderTarget : public GraphicsHandle { public: virtual ~RenderTarget() {} }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/State.cpp b/native/cocos/renderer/gfx/State.cpp index 7ba4d71206..273e16e034 100644 --- a/native/cocos/renderer/gfx/State.cpp +++ b/native/cocos/renderer/gfx/State.cpp @@ -38,7 +38,7 @@ namespace { State::State() // blend : blend(false) -, blendSepartion(false) +, blendSeparation(false) , blendColor(0xFFFFFFFF) , blendEq(BlendOp::ADD) , blendAlphaEq(BlendOp::ADD) @@ -115,7 +115,7 @@ State& State::operator=(const State& o) { // blend blend = o.blend; - blendSepartion = o.blendSepartion; + blendSeparation = o.blendSeparation; blendColor = o.blendColor; blendEq = o.blendEq; blendAlphaEq = o.blendAlphaEq; @@ -218,7 +218,7 @@ State& State::operator=(State&& o) { // blend blend = o.blend; - blendSepartion = o.blendSepartion; + blendSeparation = o.blendSeparation; blendColor = o.blendColor; blendEq = o.blendEq; blendAlphaEq = o.blendAlphaEq; @@ -280,7 +280,7 @@ State& State::operator=(State&& o) // reset o o.blend = false; - o.blendSepartion = false; + o.blendSeparation = false; o.blendColor = 0xFFFFFFFF; o.blendEq = BlendOp::ADD; o.blendAlphaEq = BlendOp::ADD; diff --git a/native/cocos/renderer/gfx/State.h b/native/cocos/renderer/gfx/State.h index f5313a59b2..6b3832e599 100644 --- a/native/cocos/renderer/gfx/State.h +++ b/native/cocos/renderer/gfx/State.h @@ -36,8 +36,22 @@ class IndexBuffer; class Program; class Texture; +/** + * @addtogroup gfx + * @{ + */ + +/** + * State class save the GL states used in one draw call. + * It will be used to compare between the previous states and the current states, so that we know which GL states should be updated. + * User shouldn't be using this Class directly. Instead, they should set the states in Pass of material system. + * @see `Pass` + */ struct State final -{ +{ + /** + * Constructor + */ State(); State(const State&); State(State &&); @@ -46,65 +60,214 @@ struct State final State& operator =(const State& rhs); State& operator =(State&& rhs); + /** + * Reset all states to default values + */ void reset(); - // blend + /** + @name Blend + @{ + */ + /** + * Indicates blending enabled or not + */ bool blend; - bool blendSepartion; + /** + * Indicates the RGB blend equation and alpha blend equation settings are separate or not + */ + bool blendSeparation; + /** + * The blending color + */ uint32_t blendColor; + /** + * The blending equation + */ BlendOp blendEq; + /** + * The blending equation for alpha channel + */ BlendOp blendAlphaEq; + /** + * The blending source factor + */ BlendFactor blendSrc; + /** + * The blending destination factor + */ BlendFactor blendDst; + /** + * The blending source factor for alpha + */ BlendFactor blendSrcAlpha; + /** + * The blending destination factor for alpha + */ BlendFactor blendDstAlpha; + /** + end of Blend + @} + */ - // depth + /** + @name Depth + @{ + */ + /** + * Indicates depth test enabled or not + */ bool depthTest; + /** + * Indicates depth writing enabled or not + */ bool depthWrite; + /** + * The depth comparison function + */ DepthFunc depthFunc; + /** + end of Depth + @} + */ - // stencil + /** + @name Stencil + @{ + */ + /** + * Indicates stencil test enabled or not + */ bool stencilTest; + /** + * Indicates stencil test function for front and back is set separatly or not + */ bool stencilSeparation; + /** + * The front face function for stencil test + */ StencilFunc stencilFuncFront; + /** + * The front reference value for stencil test + */ int32_t stencilRefFront; + /** + * The front mask value to AND with the reference value and store the result into stencil buffer when test is done + */ uint32_t stencilMaskFront; + /** + * The function to use when the stencil test fails for front face + */ StencilOp stencilFailOpFront; + /** + * The function to use when the stencil test passes but the depth test fails for front face + */ StencilOp stencilZFailOpFront; + /** + * The function to use when both the stencil and the depth test pass for front face. + * Or when the stencil test passes and there is no depth buffer or depth testing is disabled. + */ StencilOp stencilZPassOpFront; + /** + * The bit mask to enable or disable writing of individual bits in the front stencil planes + */ uint32_t stencilWriteMaskFront; + /** + * The back face function for stencil test + */ StencilFunc stencilFuncBack; + /** + * The back reference value for stencil test + */ int32_t stencilRefBack; + /** + * The back mask value to AND with the reference value and store the result into stencil buffer when test is done + */ uint32_t stencilMaskBack; + /** + * The function to use when the stencil test fails for back face + */ StencilOp stencilFailOpBack; + /** + * The function to use when the stencil test passes but the depth test fails for back face + */ StencilOp stencilZFailOpBack; + /** + * The function to use when both the stencil and the depth test pass for back face. + * Or when the stencil test passes and there is no depth buffer or depth testing is disabled. + */ StencilOp stencilZPassOpBack; + /** + * The bit mask to enable or disable writing of individual bits in the back stencil planes + */ uint32_t stencilWriteMaskBack; + /** + end of Stencil + @} + */ + /** + * Specifies whether front-facing or back-facing polygons are candidates for culling. + */ CullMode cullMode; + /** + * Specifies the primitive type for rendering + */ PrimitiveType primitiveType; int32_t maxStream; + /** + * Specifies the vertex buffer + */ void setVertexBuffer(size_t index, VertexBuffer* vertBuf); + /** + * Gets the vertex buffer + */ VertexBuffer* getVertexBuffer(size_t index) const; + /** + * Specifies the vertex buffer offset + */ void setVertexBufferOffset(size_t index, int32_t offset); + /** + * Gets the vertex buffer offset + */ int32_t getVertexBufferOffset(size_t index) const; + /** + * Specifies the index buffer + */ void setIndexBuffer(IndexBuffer* indexBuf); + /** + * Gets the index buffer + */ IndexBuffer* getIndexBuffer() const; + /** + * Sets the texture for specific texture unit + */ void setTexture(size_t index, Texture* texture); + /** + * Gets the specific texture unit + */ Texture* getTexture(size_t index) const; - - void setProgram(Program* program); - Program* getProgram() const; + /** + * Gets all texture units + */ const std::vector& getTextureUnits() const { return _textureUnits; } + /** + * Sets the program used for rendering + */ + void setProgram(Program* program); + /** + * Gets the program used for rendering + */ + Program* getProgram() const; + private: std::vector _vertexBuffers; std::vector _vertexBufferOffsets; @@ -113,4 +276,7 @@ private: Program *_program; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/Texture.cpp b/native/cocos/renderer/gfx/Texture.cpp index 594dee9647..daf193f9fe 100644 --- a/native/cocos/renderer/gfx/Texture.cpp +++ b/native/cocos/renderer/gfx/Texture.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -76,6 +76,10 @@ Texture::~Texture() bool Texture::init(DeviceGraphics* device) { + if (device == nullptr) + { + return false; + } _device = device; _width = 4; _height = 4; diff --git a/native/cocos/renderer/gfx/Texture.h b/native/cocos/renderer/gfx/Texture.h index f43ac400d6..d0ea6bbb0d 100644 --- a/native/cocos/renderer/gfx/Texture.h +++ b/native/cocos/renderer/gfx/Texture.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -37,10 +37,21 @@ RENDERER_BEGIN class DeviceGraphics; +/** + * @addtogroup gfx + * @{ + */ + +/** + * The base texture class + */ class Texture : public RenderTarget { public: - // texture filter + /** + * @enum Filter + * Texture filter modes + */ enum class Filter : int8_t { NONE = -1, @@ -48,7 +59,10 @@ public: LINEAR = 1 }; - // texture wrap mode + /** + * @enum Filter + * Texture wrap modes + */ enum class WrapMode : uint16_t { REPEAT = GL_REPEAT, @@ -56,7 +70,10 @@ public: MIRROR = GL_MIRRORED_REPEAT }; - // texture format + /** + * @enum Format + * Texture formats + */ enum class Format : uint8_t { BEGIN = 0, @@ -95,35 +112,95 @@ public: // }; + /** + * @struct Image + * Raw image data + */ struct Image { uint8_t* data = nullptr; size_t length = 0; }; + /** + * @struct Options + * Texture setting options including format, width, height, wrap mode, filter etc. + */ struct Options { + /** + * Image mipmaps + */ std::vector images; + /** + * The maximum anisotropy for the texture + */ int32_t anisotropy = 1; + /** + * The internal format specifying the color components in the texture + */ GLenum glInternalFormat = GL_RGBA; + /** + * The pixel format of the texel data + */ GLenum glFormat = GL_RGB; + /** + * The data type of the texel data + */ GLenum glType = GL_UNSIGNED_BYTE; + /** + * The width of the texture + */ uint16_t width = 4; + /** + * The height of the texture + */ uint16_t height = 4; uint8_t bpp = 0; + /** + * The wrapping function for texture coordinate s + */ WrapMode wrapS = WrapMode::REPEAT; + /** + * The wrapping function for texture coordinate t + */ WrapMode wrapT = WrapMode::REPEAT; + /** + * The texture minification filter + */ Filter minFilter = Filter::LINEAR; + /** + * The texture magnification filter + */ Filter magFilter = Filter::LINEAR; + /** + * The texture filter for mipmaps + */ Filter mipFilter = Filter::LINEAR; + /** + * Specifies whether the texture have mipmaps + */ bool hasMipmap = false; + /** + * Specifies whether the texture if flipped vertically + */ bool flipY = true; + /** + * Specifies whether the texture have alpha premultiplied + */ bool premultiplyAlpha = false; + /** + * Specifies whether the texture is compressed + */ bool compressed = false; }; + /** + * @struct ImageOption + * The informations of Image which indicates the mipmap level, width, height, filpY and premultiplyAlpha + */ struct ImageOption { Image image; @@ -135,6 +212,10 @@ public: bool premultiplyAlpha = false; }; + /** + * @struct SubImageOption + * The informations of sub image which indicates the area to update, mipmap level, filpY and premultiplyAlpha + */ struct SubImageOption { SubImageOption(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t level, bool flipY, bool premultiplyAlpha) @@ -160,8 +241,17 @@ public: bool premultiplyAlpha = false; }; + /** + * Gets the target gl location + */ inline GLuint getTarget() const { return _target; } + /** + * Gets the width of texture + */ inline uint16_t getWidth() const { return _width; } + /** + * Gets the height of texture + */ inline uint16_t getHeight() const { return _height; } protected: @@ -198,4 +288,7 @@ protected: bool _compressed; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/Texture2D.cpp b/native/cocos/renderer/gfx/Texture2D.cpp index 2345d4463f..812255310c 100644 --- a/native/cocos/renderer/gfx/Texture2D.cpp +++ b/native/cocos/renderer/gfx/Texture2D.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/Texture2D.h b/native/cocos/renderer/gfx/Texture2D.h index 843c5fb69a..de7084c636 100644 --- a/native/cocos/renderer/gfx/Texture2D.h +++ b/native/cocos/renderer/gfx/Texture2D.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,15 +31,51 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + +/** + * The 2d texture class\n + * JS API: gfx.Texture2D + @code + let texture = new gfx.Texture2D(cc.renderer.device, { + images: [], + width: 128, + height: 128, + wrapS: renderEngine.gfx.WRAP_REPEAT, + wrapT: renderEngine.gfx.WRAP_REPEAT, + format: renderEngine.gfx.TEXTURE_FMT_RGB8, + mipmap: false, + }); + @endcode + */ class Texture2D : public Texture { public: Texture2D(); ~Texture2D(); + /* + * Init the texture with device and options + * @see Texture::Options + */ bool init(DeviceGraphics* device, Options& options); + /** + * Update the texture with new options + * @see Texture::Options + */ void update(const Options& options); + /** + * Update a sub area of the texture with sub image option + * @see Texture::SubImageOption + */ void updateSubImage(const SubImageOption& option); + /** + * Update the image of a given level mipmap specified in image option + * @see Texture::ImageOption + */ void updateImage(const ImageOption& option); private: @@ -50,4 +86,7 @@ private: }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/VertexBuffer.cpp b/native/cocos/renderer/gfx/VertexBuffer.cpp index 9a492f18fc..f35020def3 100644 --- a/native/cocos/renderer/gfx/VertexBuffer.cpp +++ b/native/cocos/renderer/gfx/VertexBuffer.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/native/cocos/renderer/gfx/VertexBuffer.h b/native/cocos/renderer/gfx/VertexBuffer.h index 94cd2e6273..fea24d4146 100644 --- a/native/cocos/renderer/gfx/VertexBuffer.h +++ b/native/cocos/renderer/gfx/VertexBuffer.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -32,30 +32,87 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + class DeviceGraphics; +/** + * VertexBuffer manages the GL vertex attributes buffer. + * It creates, updates and destoies the GL vertex buffer. + */ class VertexBuffer final : public GraphicsHandle { public: + /** + * Creates a vertex buffer object + * @param[in] device DeviceGraphics pointer + * @param[in] format Specifies the vertex attributes layout + * @param[in] usage The usage pattern + * @param[in] data Data pointer, could be nullptr, then nothing is updated to the buffer. + * @param[in] dataByteLength Data's byte length. + * @param[in] numVertices Count of vertices. + */ RENDERER_DEFINE_CREATE_METHOD_6(VertexBuffer, init, DeviceGraphics*, VertexFormat*, Usage, const void*, size_t, uint32_t) VertexBuffer(); virtual ~VertexBuffer(); + /** + * Initializes a vertex buffer object + * @param[in] device DeviceGraphics pointer + * @param[in] format Specifies the vertex attributes layout + * @param[in] usage The usage pattern + * @param[in] data Data pointer, could be nullptr, then nothing is updated to the buffer. + * @param[in] dataByteLength Data's byte length. + * @param[in] numVertices Count of vertices. + */ bool init(DeviceGraphics* device, VertexFormat* format, Usage usage, const void* data, size_t dataByteLength, uint32_t numVertices); + /** + * Update data to the GL vertex buffer + * @param[in] offset Destination offset for filling buffer data. + * @param[in] data Data to be updated. + * @param[in] dataByteLength Data byte length to be updated. + */ void update(uint32_t offset, const void* data, size_t dataByteLength); + /** + * Gets the count of vertices + */ inline uint32_t getCount() const { return _numVertices; } + /** + * Sets the count of vertices + */ inline void setCount(uint32_t numVertices) { _numVertices = numVertices; } + /** + * Gets the attributes layout and format of vertices. + */ inline const VertexFormat& getFormat() const { return *_format; } // inline void setFormat(VertexFormat&& format) { _format = std::move(format); } + /** + * Sets the attributes layout and format of vertices. + */ void setFormat(VertexFormat* format); + /** + * Gets usage pattern of the vertex buffer + */ inline Usage getUsage() const { return _usage; } + /** + * Sets usage pattern of the vertex buffer + */ inline void setUsage(Usage usage) { _usage = usage; } + /** + * Gets byte size of the vertex buffer + */ inline uint32_t getBytes() const { return _bytes; } + /** + * Sets byte size of the vertex buffer + */ inline void setBytes(uint32_t bytes) { _bytes = bytes; } using FetchDataCallback = std::function; @@ -68,7 +125,10 @@ public: } return _fetchDataCallback(bytes); } - + + /** + * Destroies the vertex buffer + */ void destroy(); private: @@ -83,4 +143,7 @@ private: CC_DISALLOW_COPY_ASSIGN_AND_MOVE(VertexBuffer) }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/gfx/VertexFormat.cpp b/native/cocos/renderer/gfx/VertexFormat.cpp index a66462cae0..2e7458bfcc 100644 --- a/native/cocos/renderer/gfx/VertexFormat.cpp +++ b/native/cocos/renderer/gfx/VertexFormat.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -48,6 +48,17 @@ static uint32_t attrTypeBytes(AttribType attrType) return 0; } +VertexFormat* VertexFormat::XY_UV_Color = new VertexFormat(std::vector({ + Info(ATTRIB_NAME_POSITION, AttribType::FLOAT32, 2), + Info(ATTRIB_NAME_UV0, AttribType::FLOAT32, 2), + Info(ATTRIB_NAME_COLOR, AttribType::UINT8, 4, true) +})); + +VertexFormat* VertexFormat::XY_Color = new VertexFormat(std::vector({ + Info(ATTRIB_NAME_POSITION, AttribType::FLOAT32, 2), + Info(ATTRIB_NAME_COLOR, AttribType::UINT8, 4, true) +})); + VertexFormat::VertexFormat() { } @@ -76,6 +87,7 @@ VertexFormat::VertexFormat(const std::vector& infos) el.normalize = info._normalize; el.bytes = info._num * attrTypeBytes(info._type); + _names.push_back(el.name); _attr2el[el.name] = el; elements.push_back(&_attr2el[el.name]); @@ -106,6 +118,7 @@ VertexFormat& VertexFormat::operator=(const VertexFormat& o) { if (this != &o) { + _names = o._names; _attr2el = o._attr2el; #if GFX_DEBUG > 0 _elements = o._elements; @@ -119,6 +132,7 @@ VertexFormat& VertexFormat::operator=(VertexFormat&& o) { if (this != &o) { + _names = std::move(o._names); _attr2el = std::move(o._attr2el); #if GFX_DEBUG > 0 _elements = std::move(o._elements); @@ -129,13 +143,13 @@ VertexFormat& VertexFormat::operator=(VertexFormat&& o) return *this; } -const VertexFormat::Element& VertexFormat::getElement(const std::string& attrName) const +const VertexFormat::Element* VertexFormat::getElement(const std::string& attrName) const { - static const Element INVALID_ELEMENT_VALUE; + static const Element* INVALID_ELEMENT_VALUE = nullptr; const auto& iter = _attr2el.find(attrName); if (iter != _attr2el.end()) { - return iter->second; + return &iter->second; } return INVALID_ELEMENT_VALUE; } diff --git a/native/cocos/renderer/gfx/VertexFormat.h b/native/cocos/renderer/gfx/VertexFormat.h index a9f9df41aa..ed7fb61886 100644 --- a/native/cocos/renderer/gfx/VertexFormat.h +++ b/native/cocos/renderer/gfx/VertexFormat.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -33,11 +33,38 @@ RENDERER_BEGIN +/** + * @addtogroup gfx + * @{ + */ + +/** + * The vertex format defines the attributes and their data layout in the VertexBuffer\n + * JS API: gfx.VertexFormat + @code + let vertexFmt = new gfx.VertexFormat([ + { name: gfx.ATTR_POSITION, type: gfx.ATTR_TYPE_FLOAT32, num: 3 }, + { name: gfx.ATTR_UV0, type: gfx.ATTR_TYPE_FLOAT32, num: 2 }, + { name: gfx.ATTR_COLOR, type: gfx.ATTR_TYPE_FLOAT32, num: 4, normalize: true }, + ]); + @endcode + */ class VertexFormat : public Ref { public: + /* + * Informations used to define an attribute in vertex data layout. + * @struct Info + */ struct Info { + /* + * Constructor + * @param[in] name Attribute name + * @param[in] type Data type of each component + * @param[in] num Number of components per attribute + * @param[in] normalized Whether integer data values should be normalized into a certain range when being casted to a float + */ Info(const std::string& name, AttribType type, uint32_t num, bool normalize = false) : _name(name) , _num(num) @@ -53,6 +80,10 @@ public: static Info INFO_END; + /* + * Element describes informations of an attribute + * @struct Info + */ struct Element { Element() @@ -70,27 +101,83 @@ public: return type != AttribType::INVALID; } + /* + * Name of the attribute + */ std::string name; + /* + * Byte offset in each vertex data + */ size_t offset; + /* + * Specifies the offset in bytes between the beginning of consecutive vertex attributes + */ uint32_t stride; int32_t stream; + /* + * Number of components per attribute unit + */ uint32_t num; + /* + * Total bytes per attribute unit + */ uint32_t bytes; + /* + * Data type of each component + */ AttribType type; + /* + * Specifies whether integer data values should be normalized into a certain range when being casted to a float + */ bool normalize; }; + /* + * Default constructor + */ VertexFormat(); + /** + * Constructor with specific attribute informations + * @param[in] infos Array of all elements informations + */ VertexFormat(const std::vector& infos); + /* + * Copy constructor + */ VertexFormat(const VertexFormat& o); + /* + * Move constructor + */ VertexFormat(VertexFormat&& o); VertexFormat& operator=(const VertexFormat& o); VertexFormat& operator=(VertexFormat&& o); - const Element& getElement(const std::string& attrName) const; + /** + * Gets all attribute names + */ + const std::vector& getAttributeNames() const { return _names; }; + /** + * Getes an attribute element by name + */ + const Element* getElement(const std::string& attrName) const; + + /** + * Gets total byte size of a vertex + */ + uint32_t getBytes() const { return _bytes; }; + + /* + * Builtin VertexFormat with 2d position, uv, color attributes + */ + static VertexFormat* XY_UV_Color; + /* + * Builtin VertexFormat with 2d position, color attributes + */ + static VertexFormat* XY_Color; private: + std::vector _names; std::unordered_map _attr2el; #if GFX_DEBUG > 0 std::vector _elements; @@ -100,4 +187,7 @@ private: friend class VertexBuffer; }; +// end of gfx group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/BaseRenderer.cpp b/native/cocos/renderer/renderer/BaseRenderer.cpp index a9d4cc524d..67e73c742a 100644 --- a/native/cocos/renderer/renderer/BaseRenderer.cpp +++ b/native/cocos/renderer/renderer/BaseRenderer.cpp @@ -33,7 +33,6 @@ #include "InputAssembler.h" #include "Pass.h" #include "Camera.h" -#include "INode.h" #include "Model.h" RENDERER_BEGIN @@ -100,20 +99,20 @@ void BaseRenderer::render(const View& view, const Scene* scene) // get all draw items _drawItems.clear(); - int modelViewId = -1; + int modelMask = -1; uint32_t drawItemCount = 0; DrawItem drawItem; for (const auto& model : scene->getModels()) { - modelViewId = model->getViewId(); + modelMask = model->getCullingMask(); if (view.cullingByID) { - if (modelViewId != view.id) + if ((modelMask & view.cullingMask) == 0) continue; } else { - if (-1 != modelViewId) + if (-1 != modelMask) continue; } @@ -155,13 +154,13 @@ void BaseRenderer::render(const View& view, const Scene* scene) // render stages std::unordered_map::iterator foundIter; - for (const auto& stageInfo : _stageInfos) + for (const auto& stageInfoEntry : _stageInfos) { - foundIter = _stage2fn.find(stageInfo.stage); + foundIter = _stage2fn.find(stageInfoEntry.stage); if (_stage2fn.end() != foundIter) { auto& fn = foundIter->second; - fn(view, *stageInfo.items); + fn(view, *stageInfoEntry.items); } } } @@ -255,77 +254,83 @@ void BaseRenderer::draw(const StageItem& item) else _device->setUniformfv(param.getName(), bytes / sizeof(float), (const float*)prop->getValue()); } + } + + const int32_t& definesKey = item.effect->getDefinesKey(); + // for each pass + for (const auto& pass : item.technique->getPasses()) + { + // set vertex buffer + _device->setVertexBuffer(0, ia->getVertexBuffer()); - // for each pass - for (const auto& pass : item.technique->getPasses()) + // set index buffer + if (ia->_indexBuffer) + _device->setIndexBuffer(ia->_indexBuffer); + + // set primitive type + _device->setPrimitiveType(ia->_primitiveType); + + // set program + if(!_program || _programName != pass->_programName || _definesKey != definesKey) { - // set vertex buffer - _device->setVertexBuffer(0, ia->getVertexBuffer()); - - // set index buffer - if (ia->_indexBuffer) - _device->setIndexBuffer(ia->_indexBuffer); - - // set primitive type - _device->setPrimitiveType(ia->_primitiveType); - - // set program - auto program = _programLib->getProgram(pass->_programName, *(item.defines)); - _device->setProgram(program); - - // cull mode - _device->setCullMode(pass->_cullMode); - - // blend - if (pass->_blend) - { - _device->enableBlend(); - _device->setBlendFuncSeparate(pass->_blendSrc, - pass->_blendDst, - pass->_blendSrcAlpha, - pass->_blendDstAlpha); - _device->setBlendEquationSeparate(pass->_blendEq, pass->_blendAlphaEq); - _device->setBlendColor(pass->_blendColor); - } - - // depth test & write - if (pass->_depthTest) - { - _device->enableDepthTest(); - _device->setDepthFunc(pass->_depthFunc); - } - if (pass->_depthWrite) - _device->enableDepthWrite(); - - // setencil - if (pass->_stencilTest) - { - _device->enableStencilTest(); - - // front - _device->setStencilFuncFront(pass->_stencilFuncFront, - pass->_stencilRefFront, - pass->_stencilMaskFront); - _device->setStencilOpFront(pass->_stencilFailOpFront, - pass->_stencilZFailOpFront, - pass->_stencilZPassOpFront, - pass->_stencilWriteMaskFront); - - // back - _device->setStencilFuncBack(pass->_stencilFuncBack, - pass->_stencilRefBack, - pass->_stencilMaskBack); - _device->setStencilOpBack(pass->_stencilFailOpBack, - pass->_stencilZFailOpBack, - pass->_stencilZPassOpBack, - pass->_stencilWriteMaskBack); - } - - // draw pass - _device->draw(ia->_start, ia->getPrimitiveCount()); - - resetTextureUint(); + _programName = pass->_programName; + _definesKey = definesKey; + _program = _programLib->getProgram(pass->_programName, *(item.defines), _definesKey); } + _device->setProgram(_program); + + // cull mode + _device->setCullMode(pass->_cullMode); + + // blend + if (pass->_blend) + { + _device->enableBlend(); + _device->setBlendFuncSeparate(pass->_blendSrc, + pass->_blendDst, + pass->_blendSrcAlpha, + pass->_blendDstAlpha); + _device->setBlendEquationSeparate(pass->_blendEq, pass->_blendAlphaEq); + _device->setBlendColor(pass->_blendColor); + } + + // depth test & write + if (pass->_depthTest) + { + _device->enableDepthTest(); + _device->setDepthFunc(pass->_depthFunc); + } + if (pass->_depthWrite) + _device->enableDepthWrite(); + + // setencil + if (pass->_stencilTest) + { + _device->enableStencilTest(); + + // front + _device->setStencilFuncFront(pass->_stencilFuncFront, + pass->_stencilRefFront, + pass->_stencilMaskFront); + _device->setStencilOpFront(pass->_stencilFailOpFront, + pass->_stencilZFailOpFront, + pass->_stencilZPassOpFront, + pass->_stencilWriteMaskFront); + + // back + _device->setStencilFuncBack(pass->_stencilFuncBack, + pass->_stencilRefBack, + pass->_stencilMaskBack); + _device->setStencilOpBack(pass->_stencilFailOpBack, + pass->_stencilZFailOpBack, + pass->_stencilZPassOpBack, + pass->_stencilWriteMaskBack); + } + + // draw pass + _device->draw(ia->_start, ia->getPrimitiveCount()); + + resetTextureUint(); } } diff --git a/native/cocos/renderer/renderer/BaseRenderer.h b/native/cocos/renderer/renderer/BaseRenderer.h index 4dad284ff3..2ea738af8b 100644 --- a/native/cocos/renderer/renderer/BaseRenderer.h +++ b/native/cocos/renderer/renderer/BaseRenderer.h @@ -44,13 +44,20 @@ class Effect; class Technique; class Texture2D; +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Base renderer implements the basic render process. + */ class BaseRenderer : public Ref { public: struct StageItem { Model* model = nullptr; - INode* node = nullptr; InputAssembler *ia = nullptr; Effect* effect = nullptr; ValueMap* defines = nullptr; @@ -58,15 +65,40 @@ public: int sortKey = -1; }; typedef std::function&)> StageCallback; - + + /** + * @brief The default constructor. + */ BaseRenderer(); + /** + * @brief Initializes the base renderer. + * @param[in] device DeviceGraphics pointer. + * @param[in] programTemplates All linked programs. + */ bool init(DeviceGraphics* device, std::vector& programTemplates); + /** + * @brief Initializes the base renderer. + * @param[in] device DeviceGraphics pointer. + * @param[in] programTemplates All programs. + * @param[in] defaultTexture Default texture pointer. + */ bool init(DeviceGraphics* device, std::vector& programTemplates, Texture2D* defaultTexture); + /** + * @brief The default destructor. + */ virtual ~BaseRenderer(); - + /** + * @brief Register a new render stage. + * @param[in] name Stage name. + * @param[in] call Stage handle callback. + */ void registerStage(const std::string& name, const StageCallback& callback); - ProgramLib* getProgramLib() const { return _programLib; } + /** + * @brief Gets the program library pointer. + * @return Program library pointer. + */ + ProgramLib* getProgramLib() const { return _programLib; }; protected: void render(const View&, const Scene* scene); @@ -84,8 +116,11 @@ protected: View* requestView(); int _usedTextureUnits = 0; + std::string _programName; + int32_t _definesKey = 0; DeviceGraphics* _device = nullptr; ProgramLib* _programLib = nullptr; + Program* _program = nullptr; Texture2D* _defaultTexture = nullptr; std::unordered_map _stage2fn; std::vector _drawItems; @@ -94,4 +129,6 @@ protected: CC_DISALLOW_COPY_ASSIGN_AND_MOVE(BaseRenderer); }; +// end of renderer group +/// @} RENDERER_END diff --git a/native/cocos/renderer/renderer/Camera.cpp b/native/cocos/renderer/renderer/Camera.cpp index 24d6b38228..3e92db6c01 100644 --- a/native/cocos/renderer/renderer/Camera.cpp +++ b/native/cocos/renderer/renderer/Camera.cpp @@ -24,7 +24,7 @@ #include "Camera.h" #include "gfx/FrameBuffer.h" -#include "INode.h" +#include "math/MathUtil.h" RENDERER_BEGIN @@ -39,6 +39,7 @@ Camera::Camera() Camera::~Camera() { RENDERER_SAFE_RELEASE(_framebuffer); + RENDERER_SAFE_RELEASE(_node); } void Camera::setFrameBuffer(FrameBuffer* framebuffer) @@ -96,9 +97,17 @@ void Camera::setStages(const std::vector& stages) } -void Camera::setNode(INode* node) +void Camera::setNode(NodeProxy* node) { + if (_node != nullptr) + { + _node->release(); + } _node = node; + if (_node != nullptr) + { + _node->retain(); + } } const View& Camera::extractView( int width, int height) @@ -113,7 +122,7 @@ const View& Camera::extractView( int width, int height) // view matrix //REFINE: - _worldRTInv.set(_node->getWorldRT()); + _node->getWorldRT(&_worldRTInv); _cachedView.matView.set(_worldRTInv.getInversed()); // projecton matrix @@ -124,13 +133,17 @@ const View& Camera::extractView( int width, int height) { float x = _orthoHeight * aspect; float y = _orthoHeight; - Mat4::createOrthographic(-x, x, -y, y, &_cachedView.matProj); + Mat4::createOrthographicOffCenter(-x, x, -y, y, _near, _far, &_cachedView.matProj); } // view projection Mat4::multiply(_cachedView.matProj, _cachedView.matView, &_cachedView.matViewProj); _cachedView.matInvViewPorj.set(_cachedView.matViewProj.getInversed()); + // culling mask + _cachedView.cullingMask = _cullingMask; + _cachedView.cullingByID = true; + return _cachedView; } @@ -153,7 +166,7 @@ Vec3& Camera::screenToWorld(Vec3& out, const Vec3& screenPos, int width, int hei Mat4::createOrthographic(-x, x, -y, y, &matProj); } - const_cast(this)->_worldRTInv = _node->getWorldRT(); + _node->getWorldRT(&(const_cast(this)->_worldRTInv)); const_cast(this)->_worldRTInv.inverse(); // view projection @@ -172,16 +185,15 @@ Vec3& Camera::screenToWorld(Vec3& out, const Vec3& screenPos, int width, int hei // Transform to world position. matInvViewProj.transformPoint(&out); - const_cast(this)->_worldPos.set(_node->getWorldPos()); + _node->getWorldPosition(&(const_cast(this)->_worldPos)); Vec3 tmpVec3 = _worldPos; - out = tmpVec3.lerp(out, screenPos.z / _far); + out = tmpVec3.lerp(out, MathUtil::lerp(_near / _far, 1, screenPos.z)); } else { - float range = _far - _near; out.set((screenPos.x - cx) * 2.0f / cw - 1.0f, (screenPos.y - cy) * 2.0f / ch - 1.0f, - (_far - screenPos.z) / range * 2.0f - 1.0f); + screenPos.z * 2.0f - 1.0f); // Transform to world position. matInvViewProj.transformPoint(&out); @@ -209,21 +221,16 @@ Vec3& Camera::worldToScreen(Vec3& out, const Vec3& worldPos, int width, int heig Mat4::createOrthographic(-x, x, -y, y, &matProj); } - const_cast(this)->_worldRTInv = _node->getWorldRT(); + _node->getWorldRT(&(const_cast(this)->_worldRTInv)); const_cast(this)->_worldRTInv.inverse(); // view projection Mat4 matViewProj; Mat4::multiply(matProj, _worldRTInv, &matViewProj); - // caculate w - float w = worldPos.x * matViewProj.m[3] + - worldPos.y * matViewProj.m[7] + - worldPos.z * matViewProj.m[11] + - matViewProj.m[15]; - matViewProj.transformPoint(worldPos, &out); - out.x = cx + (out.x / w + 1) * 0.5f * cw; - out.y = cy + (out.y / w + 1) * 0.5f * ch; + out.x = cx + (out.x + 1) * 0.5f * cw; + out.y = cy + (out.y + 1) * 0.5f * ch; + out.z = out.z * 0.5 + 0.5; return out; } diff --git a/native/cocos/renderer/renderer/Camera.h b/native/cocos/renderer/renderer/Camera.h index d101506554..a2a924d9ea 100644 --- a/native/cocos/renderer/renderer/Camera.h +++ b/native/cocos/renderer/renderer/Camera.h @@ -32,6 +32,7 @@ #include "../Macro.h" #include "../Types.h" #include "View.h" +#include "../scene/NodeProxy.hpp" #ifdef near #undef near @@ -44,67 +45,172 @@ RENDERER_BEGIN class FrameBuffer; -class INode; +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Manage scene camera. + */ class Camera : public Ref { public: + /** + * @brief The default constructor. + */ Camera(); + /** + * @brief The default destructor. + */ ~Camera(); + /** + * @brief Gets the camera type. + */ ProjectionType getType() const { return _projection; } - + /** + * @brief Sets the camera type. + */ + inline void setType(ProjectionType value) { _projection = value; } + /** + * @brief Gets the view height for orthographic camera. + */ inline float getOrthoHeight() const { return _orthoHeight; } + /** + * @brief Sets the view height for orthographic camera. + */ inline void setOrthoHeight(float value) { _orthoHeight = value; } - + /** + * @brief Gets the field of view for the camera. + */ inline float getFov() const { return _fov; } + /** + * @brief Sets the field of view for the camera. + */ inline void setFov(float fov) { _fov = fov; } - + /** + * @brief Gets the near clip plane. + */ inline float getNear() const { return _near; } + /** + * @brief Sets the near clip plane. + */ inline void setNear(float near) { _near = near; } - + /** + * @brief Gets the far clip plane. + */ inline float getFar() const { return _far; } + /** + * @brief Sets the far clip plane. + */ inline void setFar(float far) { _far = far; } - + /** + * @brief Gets the clear color. + */ inline void getColor(Color4F& out) const { out = _color; } + /** + * @brief Sets the clear color. + */ void setColor(float r, float g, float b, float a); - + /** + * @brief Gets the depth of the camera, camera of smaller depth gets rendered earlier. + */ inline float getDepth() const { return _depth; } + /** + * @brief Sets the depth of the camera, camera of smaller depth gets rendered earlier + */ void setDepth(float depth); - + /** + * @brief Gets the culling mask. + */ + inline int getCullingMask() const { return _cullingMask; } + /** + * @brief Sets the culling mask. + */ + inline void setCullingMask(int mask) { _cullingMask = mask; } + /** + * @brief Gets the stencil value to clear + */ inline int getStencil() const { return _stencil; } + /** + * @brief Sets the stencil value to clear + */ void setStencil(int stencil); - + /** + * @brief Gets the clear flags including color, stencil and depth. + */ inline uint8_t getClearFlags() const { return _clearFlags; } + /** + * @brief Sets the clear flags including color, stencil and depth. + */ void setClearFlags(uint8_t flags ); - + /** + * @brief Gets rect. + */ inline Rect* getRect(Rect& out) const { out = _rect; return &out; } + /** + * @brief Sets rect. + */ void setRect(float x, float y, float w, float h); - + /** + * @brief Gets stages. + */ inline const std::vector& getStages() const { return _stages; } + /** + * @brief Sets stages. + */ void setStages(const std::vector& stages); - + /** + * @brief Gets the frame buffer as render target. + */ inline FrameBuffer* getFrameBuffer() const { return _framebuffer; } + /** + * @brief Sets the frame buffer as render target. + */ void setFrameBuffer(FrameBuffer* framebuffer); - + /** + * @brief Sets the world matrix. + */ void setWorldMatrix(const Mat4& worldMatrix); - + /** + * @brief Extracts the camera info to view. + */ const View& extractView(int width, int height); - + /** + * @brief Transform a screen position to world in the current camera projection. + */ Vec3& screenToWorld(Vec3& out, const Vec3& screenPos, int width, int height) const; + /** + * @brief Transform a world position to screen in the current camera projection. + */ Vec3& worldToScreen(Vec3& out, const Vec3& worldPos, int width, int height) const; - - void setNode(INode* node); - inline INode* getNode() const { return _node; } - + /** + * @brief Sets the related node proxy which provids model matrix for camera. + */ + void setNode(NodeProxy* node); + /** + * @brief Gets the related node proxy which provids model matrix for camera. + */ + inline NodeProxy* getNode() const { return _node; } + /** + * @brief Sets the camera render priority. + */ + void setPriority(int priority) { _priority = priority; } + /** + * @brief Gets the camera render priority. + */ + int getPriority() const { return _priority; } private: - INode* _node = nullptr; + NodeProxy* _node = nullptr; ProjectionType _projection = ProjectionType::PERSPECTIVE; // clear options Color4F _color = {0.2f, 0.3f, 0.47f, 1.f}; float _depth = 1.f; int _stencil = 1; + int _cullingMask = 1; uint8_t _clearFlags = ClearFlag::COLOR | ClearFlag::DEPTH; // stage & framebuffer @@ -124,6 +230,10 @@ private: Vec3 _worldPos; View _cachedView; + int _priority = 0; }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Config.h b/native/cocos/renderer/renderer/Config.h index 81a6dc0177..c545db1933 100644 --- a/native/cocos/renderer/renderer/Config.h +++ b/native/cocos/renderer/renderer/Config.h @@ -31,11 +31,33 @@ RENDERER_BEGIN +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Stage config which use to store stageID. + */ class Config { public: + /** + * @brief Adds stage id by name. + * @param[in] name Stage name. + */ static void addStage(const std::string& name); + /** + * @brief Gets stage id by name. + * @param[in] name Stage name. + * @return Stage id. + */ static int getStageID(const std::string& name); + /** + * @brief Gets all stage id by a list of names and store in uint32 value by AND operation. + * @param[in] nameList Stage name list. + * @return A uint32 represents all stages. + */ static unsigned int getStageIDs(const std::vector& nameList); private: @@ -43,4 +65,7 @@ private: static std::unordered_map _name2stageID; }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Effect.cpp b/native/cocos/renderer/renderer/Effect.cpp index e4847eee68..3cdba239f3 100644 --- a/native/cocos/renderer/renderer/Effect.cpp +++ b/native/cocos/renderer/renderer/Effect.cpp @@ -27,7 +27,12 @@ RENDERER_BEGIN +std::map Effect::_defineBitOrder; +std::vector Effect::_sharedDefineList; + Effect::Effect() +: _hash(0) +, _definesKey(0) {} void Effect::init(const Vector& techniques, @@ -41,6 +46,7 @@ void Effect::init(const Vector& techniques, for (const auto defineTemplate: _defineTemplates) _cachedNameValues.emplace(defineTemplate.at("name").asString(), defineTemplate.at("value")); + generateKey(); } Effect::~Effect() @@ -70,7 +76,7 @@ Technique* Effect::getTechnique(const std::string& stage) const return nullptr; } -Value Effect::getDefineValue(const std::string& name) const +Value Effect::getDefine(const std::string& name) const { for (const auto& def : _defineTemplates) { @@ -82,24 +88,25 @@ Value Effect::getDefineValue(const std::string& name) const return Value::Null; } -void Effect::setDefineValue(const std::string& name, const Value& value) +void Effect::define(const std::string& name, const Value& value) { for (auto& def : _defineTemplates) { if (name == def.at("name").asString()) { def["value"] = value; - _cachedNameValues[name] = value; + if (_cachedNameValues[name] != value) + { + _cachedNameValues[name] = value; + generateKey(); + } return; } - } + }; } ValueMap* Effect::extractDefines() { -// for (auto& def : _defineTemplates) -// out.emplace(def.at("name").asString(), def.at("value")); - return &_cachedNameValues; } @@ -117,4 +124,50 @@ void Effect::setProperty(const std::string& name, const Property& property) _properties[name] = property; } +void Effect::_updateDefineBitOrder(const ValueMap& nameValues) +{ + for (auto& tmplDefs : nameValues) + { + if (_defineBitOrder.find(tmplDefs.first) == _defineBitOrder.end()) + { + _sharedDefineList.push_back(tmplDefs.first); + _defineBitOrder[tmplDefs.first] = _sharedDefineList.size(); + } + } +} + +void Effect::generateKey() +{ + // Update global order when has new define. + _updateDefineBitOrder(_cachedNameValues); + + _definesKey = 0; + for (auto& tmplDefs : _cachedNameValues) { + uint32_t value = tmplDefs.second.asUnsignedInt(); + CCASSERT(value <= 1,"Define value can't greater than 1"); + value <<= _defineBitOrder[tmplDefs.first]; + _definesKey |= value; + } + + // Reserve 8 bit for the OR operation with program id in ProgramLib. + _definesKey <<= 8; +} + +void Effect::copy(Effect& effect) +{ + _hash = effect._hash; + auto& otherTech = effect._techniques; + for (auto it = otherTech.begin(); it != otherTech.end(); it ++) + { + auto tech = new Technique(); + tech->autorelease(); + tech->copy(**it); + _techniques.pushBack(tech); + } + _defineTemplates = effect._defineTemplates; + _cachedNameValues = effect._cachedNameValues; + _properties = effect._properties; + _definesKey = effect._definesKey; +} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Effect.h b/native/cocos/renderer/renderer/Effect.h index 5ae79b1a14..034590b533 100644 --- a/native/cocos/renderer/renderer/Effect.h +++ b/native/cocos/renderer/renderer/Effect.h @@ -26,6 +26,7 @@ #include #include +#include #include "base/CCRef.h" #include "base/CCValue.h" #include "../Macro.h" @@ -33,37 +34,145 @@ RENDERER_BEGIN +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Fundamental class of material system, contains techniques, shader template define settings and uniform properties.\n + * JS API: renderer.Effect + * @code + * let pass = new renderer.Pass('sprite'); + * pass.setDepth(false, false); + * pass.setCullMode(gfx.CULL_NONE); + * let mainTech = new renderer.Technique( + * ['transparent'], + * [ + * { name: 'texture', type: renderer.PARAM_TEXTURE_2D }, + * { name: 'color', type: renderer.PARAM_COLOR4 } + * ], + * [ + * pass + * ] + * ); + * let effect = new renderer.Effect( + * [ + * mainTech + * ], + * { + * 'color': {r: 1, g: 1, b: 1, a: 1} + * }, + * [ + * { name: 'useTexture', value: true }, + * { name: 'useModel', value: false }, + * { name: 'alphaTest', value: false }, + * { name: 'useColor', value: true } + * ] + * ); + * @endcode + */ class Effect : public Ref { public: using Property = Technique::Parameter; + /* + * @brief The default constructor. + */ Effect(); + /* + * @brief The default destructor. + */ ~Effect(); + /* + * @brief Initialize with techniques, properties and define settings. + * @param[in] techniques All techniques in an array + * @param[in] properties All properties in a map + * @param[in] defineTemplates All defines and their value in a map + */ void init(const Vector& techniques, const std::unordered_map& properties, const std::vector& defineTemplates); + /** + * @brief Clears techniques and define list. + */ void clear(); + /** + * @brief Gets technique by stage. + */ Technique* getTechnique(const std::string& stage) const; + /* + * @brief Gets all techniques. + */ const Vector& getTechniques() const { return _techniques; } - Value getDefineValue(const std::string& name) const; + /** + * @brief Gets define property value by name. + */ + Value getDefine(const std::string& name) const; + /** + * @brief Sets a define's value. + */ + void define(const std::string& name, const Value& value); + /* + * @brief Gets all define values. + */ const std::vector& getDefines() const { return _defineTemplates; } - void setDefineValue(const std::string& name, const Value& value); + /* + * @brief Extracts all defines. + */ ValueMap* extractDefines(); + /** + * @brief Gets uniform property value by name. + */ const Property& getProperty(const std::string& name) const; + /** + * @brief Sets uniform property value by name. + */ void setProperty(const std::string& name, const Property& property); - + /* + * @brief Gets all uniform properties. + */ const std::unordered_map& getProperties() const { return _properties; } - + /** + * @brief Updates hash. + */ + void updateHash(double hash) { _hash = hash; }; + /** + * @brief Gets hash. + */ + double getHash() const { return _hash; }; + + /* + * @brief Gets the define key for the current define settings. + */ + const int32_t& getDefinesKey() { return _definesKey; }; + /** + * @brief Deep copy from other effect. + */ + void copy(Effect& effect); + private: + double _hash; + int32_t _definesKey; Vector _techniques; std::vector _defineTemplates; ValueMap _cachedNameValues; std::unordered_map _properties; + + // Global define order. + static std::map _defineBitOrder; + static std::vector _sharedDefineList; + static void _updateDefineBitOrder(const ValueMap& nameValues); + + void generateKey(); }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/ForwardRenderer.cpp b/native/cocos/renderer/renderer/ForwardRenderer.cpp index 0db6332dd9..19e2e30d92 100644 --- a/native/cocos/renderer/renderer/ForwardRenderer.cpp +++ b/native/cocos/renderer/renderer/ForwardRenderer.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,6 +28,7 @@ #include "gfx/Texture2D.h" #include "gfx/VertexBuffer.h" #include "gfx/IndexBuffer.h" +#include "gfx/FrameBuffer.h" #include "ProgramLib.h" #include "View.h" #include "Scene.h" @@ -35,7 +36,7 @@ #include "InputAssembler.h" #include "Pass.h" #include "Camera.h" - +#include RENDERER_BEGIN @@ -55,14 +56,30 @@ bool ForwardRenderer::init(DeviceGraphics* device, std::vectorgetCameras(); + scene->sortCameras(); + auto& cameras = scene->getCameras(); for (auto camera : cameras) BaseRenderer::render(camera->extractView(_width, _height), scene); scene->removeModels(); } +void ForwardRenderer::renderCamera(Camera* camera, Scene* scene) +{ + // reset(); + int width = _width; + int height = _height; + FrameBuffer* fb = camera->getFrameBuffer(); + if (nullptr != fb) { + width = fb->getWidth(); + height = fb->getHeight(); + } + View view = camera->extractView(width, height); + BaseRenderer::render(view, scene); + + scene->removeModels(); +} + void ForwardRenderer::transparentStage(const View& view, const std::vector& items) { // update uniforms diff --git a/native/cocos/renderer/renderer/ForwardRenderer.h b/native/cocos/renderer/renderer/ForwardRenderer.h index 292ca6c321..731fc1c708 100644 --- a/native/cocos/renderer/renderer/ForwardRenderer.h +++ b/native/cocos/renderer/renderer/ForwardRenderer.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,16 +25,43 @@ #pragma once #include "BaseRenderer.h" +#include "Camera.h" RENDERER_BEGIN +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief A builtin forward renderer implementation + */ class ForwardRenderer final : public BaseRenderer { public: + /** + * @brief The default constructor. + */ ForwardRenderer(); + /** + * @brief Initializes the forward renderer. + * @param[in] device DeviceGraphics pointer. + * @param[in] programTemplates All linked programs. + * @param[in] defaultTexture Default texture pointer. + * @param[in] width. + * @param[in] height. + */ bool init(DeviceGraphics* device, std::vector& programTemplates, Texture2D* defaultTexture, int width, int height); + /** + * @brief Renders the given render scene. + */ void render(Scene* scene); + /** + * @brief Renders the given render scene with a given camera setting. + */ + void renderCamera(Camera* camera, Scene* scene); private: void transparentStage(const View& view, const std::vector& items); @@ -43,4 +70,7 @@ private: int _height = 0; }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/InputAssembler.cpp b/native/cocos/renderer/renderer/InputAssembler.cpp index a2062e8d04..359be41763 100644 --- a/native/cocos/renderer/renderer/InputAssembler.cpp +++ b/native/cocos/renderer/renderer/InputAssembler.cpp @@ -48,6 +48,18 @@ InputAssembler::~InputAssembler() RENDERER_SAFE_RELEASE(_indexBuffer); } +void InputAssembler::clear() +{ + CC_SAFE_RELEASE(_vertexBuffer); + CC_SAFE_RELEASE(_indexBuffer); + + _vertexBuffer = nullptr; + _indexBuffer = nullptr; + _primitiveType = PrimitiveType::TRIANGLES; + _start = 0; + _count = -1; +} + InputAssembler& InputAssembler::operator=(const InputAssembler& o) { CC_SAFE_RELEASE(_vertexBuffer); diff --git a/native/cocos/renderer/renderer/InputAssembler.h b/native/cocos/renderer/renderer/InputAssembler.h index 2ea233af37..cdb0b100c4 100644 --- a/native/cocos/renderer/renderer/InputAssembler.h +++ b/native/cocos/renderer/renderer/InputAssembler.h @@ -32,6 +32,14 @@ RENDERER_BEGIN class VertexBuffer; class IndexBuffer; +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief InputAssembler is an fundamental data structure to store vertex buffer and index buffer. + */ class InputAssembler { public: @@ -43,24 +51,62 @@ public: InputAssembler& operator=(const InputAssembler& o); InputAssembler& operator=(InputAssembler&& o); + /** + * @brief Initializes with vertex buffer, index buffer and primitive type. + */ bool init(VertexBuffer* vb, IndexBuffer* ib, PrimitiveType pt = PrimitiveType::TRIANGLES); - + /** + * @brief Gets the primitive count. + */ uint32_t getPrimitiveCount() const; + /** + * @brief Sets the vertex buffer. + */ void setVertexBuffer(VertexBuffer* vb); + /** + * @brief Gets the vertex buffer. + */ inline VertexBuffer* getVertexBuffer() const { return _vertexBuffer; } + /** + * @brief Sets the index buffer. + */ void setIndexBuffer(IndexBuffer* ib); + /** + * @brief Gets the index buffer. + */ inline IndexBuffer* getIndexBuffer() const { return _indexBuffer; } + /** + * @brief Sets the index offset in buffer. + */ inline void setStart(int start) { _start = start; } + /** + * @brief Gets the index offset in buffer. + */ inline int getStart() const { return _start; } + /** + * @brief Sets the count of indices. + */ inline void setCount(int count) { _count = count; } + /** + * @brief Gets the count of indices. + */ inline int getCount() const { return _count; } + /** + * @brief Gets the primitive type. + */ inline PrimitiveType getPrimitiveType() const { return _primitiveType; } + /** + * @brief Sets the primitive type. + */ inline void setPrimitiveType(PrimitiveType type) { _primitiveType = type; } - + /** + * @brief Clears all field. + */ + void clear(); private: friend class BaseRenderer; @@ -71,4 +117,6 @@ private: int _count = -1; }; +// end of renderer group +/// @} RENDERER_END diff --git a/native/cocos/renderer/renderer/Light.h b/native/cocos/renderer/renderer/Light.h index f9b70858fd..dd1e86df30 100644 --- a/native/cocos/renderer/renderer/Light.h +++ b/native/cocos/renderer/renderer/Light.h @@ -39,77 +39,202 @@ class Texture2D; class RenderBuffer; class DeviceGraphics; +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Manage scene light. + */ class Light : public Ref { public: + /** + * @brief Light type. + */ enum class LightType { + /** + * Directional light + */ DIRECTIONAL, + /** + * Point light + */ POINT, + /** + * Spot light + */ SPOT }; + /** + * @brief Shadow type. + */ enum class ShadowType { + /** + * No shadow + */ NONE, + /** + * Hard shadow + */ HARD, + /** + * Soft shadow + */ SOFT }; + /** + * @brief The default constructor. + */ Light(); + /** + * @brief Sets the light color. + */ void setColor(float r, float g, float b); + /** + * @brief Gets the light color. + */ inline Color3F getColor() const { return _color; } - + /** + * @brief Sets the light intensity. + */ void setIntensity(float val); + /** + * @brief Gets the light intensity. + */ inline float getIntensity() const { return _intensity; } - + /** + * @brief Sets the light type. + */ inline void setType(LightType type) { _type = type; } + /** + * @brief Gets the light type. + */ inline LightType getType() const { return _type; } - + /** + * @brief Sets the spot light angle. + */ void setSpotAngle(float val); + /** + * @brief Gets the spot light angle. + */ inline float getSpotAngle() const { return _spotAngle; } + /** + * @brief Sets the light attenuation exponent. + */ void setSpotExp(float val); + /** + * @brief Gets the light attenuation exponent. + */ inline float getSpotExp() const { return _spotExp; } - + /** + * @brief Sets spot or point light range. + */ inline void setRange(float val) { _range = val; } + /** + * @brief Gets spot or point light range. + */ inline float getRange() const { return _range; } - + /** + * @brief Gets the shadow type. + */ void setShadowType(ShadowType val); + /** + * @brief Gets the shadow type. + */ inline ShadowType getShadowType() const { return _shadowType; } - + /** + * @brief Gets the shadow map texture. + */ inline Texture2D* getShadowMap() const { return _shadowMap; } - + /** + * @brief Gets the view projection matrix. + */ inline Mat4 getViewPorjMatrix() const { return _viewProjMatrix; } + /** + * @brief Gets the view projection matrix. + */ inline const Mat4& getViewProjMatrix() const { return _viewProjMatrix; } - + /** + * @brief Sets the resolution of shadow + */ void setShadowResolution(uint32_t val); + /** + * @brief Gets the resolution of shadow + */ inline uint32_t getShadowResolution() const { return _shadowResolution; } + /** + * @brief Sets the shadow bias setting. + */ inline void setShadowBias(float val) { _shadowBias = val; } + /** + * @brief Gets the shadow bias setting. + */ inline float getShadowBias() const { return _shadowBias; } - + /** + * @brief Sets the shadow darkness setting. + */ inline void setShadowDarkness(uint32_t val) { _shadowDarkness = val; } + /** + * @brief Gets the shadow darkness setting. + */ inline uint32_t getShadowDarkness() const { return _shadowDarkness; } + /** + * @brief Sets the min depth of shadow. + */ inline void setShadowMinDepth(float val) { _shadowMinDepth = val; } + /** + * @brief Gets the min depth of shadow. + */ float getShadowMinDepth() const; - + /** + * @brief Sets the max depth of shadow. + */ inline void setShadowMaxDepth(float val) { _shadowMaxDepth = val; } + /** + * @brief Gets the max depth of shadow. + */ float getShadowMaxDepth() const; - + /** + * @brief Sets the shadow scale. + */ inline void setShadowScale(float val) { _shadowScale = val; } + /** + * @brief Gets the shadow scale. + */ inline float getShadowScale() const { return _shadowScale; } - + /** + * @brief Sets the frustum edge fall off. + */ inline void setFrustumEdgeFalloff(uint32_t val) { _frustumEdgeFalloff = val; } + /** + * @brief Gets the frustum edge fall off. + */ inline uint32_t getFrustumEdgeFalloff() const { return _frustumEdgeFalloff; } - + /** + * @brief Sets the world matrix. + */ void setWorldMatrix(const Mat4& worldMatrix); + /** + * @brief Gets the world matrix. + */ inline const Mat4& getWorldMatrix() const { return _worldMatrix; } - + /** + * @brief Extract light informations to view. + */ void extractView(View& out, const std::vector& stages); - + /** + * @brief Update light and generate new shadow map. + */ void update(DeviceGraphics* device); private: @@ -156,4 +281,7 @@ private: Mat4 _worldRT; }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Model.h b/native/cocos/renderer/renderer/Model.h index c7f105f84f..199d81d792 100644 --- a/native/cocos/renderer/renderer/Model.h +++ b/native/cocos/renderer/renderer/Model.h @@ -37,7 +37,11 @@ RENDERER_BEGIN class Effect; class InputAssembler; class Model; -class INode; + +/** + * @addtogroup renderer + * @{ + */ struct DrawItem { @@ -59,28 +63,71 @@ private: static ccCArray* _pool;; }; +/** + * @brief Model contains InputAssembler, effect, culling mask and model matrix. + */ class Model { public: + /** + * @brief The default constructor. + */ Model(); + /** + * @brief The default destructor. + */ ~Model(); - + /** + * @brief Gets input assembler count. + */ inline uint32_t getInputAssemblerCount() const { return (uint32_t)_inputAssemblers.size(); } - + /** + * @brief Indicates whether the model's data is in dynamic input assembler. + */ inline bool isDynamicIA() const { return _dynamicIA; } + /** + * @brief Sets whether the model's data is in dynamic input assembler. + */ inline void setDynamicIA(bool value) { _dynamicIA = value; } - + /** + * @brief Gets draw item count. + */ inline uint32_t getDrawItemCount() const { return _dynamicIA ? 1 : (uint32_t)_inputAssemblers.size(); } + /** + * @brief Sets model matrix. + */ inline void setWorldMatix(const Mat4& matrix) { _worldMatrix = std::move(matrix); } + /** + * @brief Gets mode matrix. + */ inline const Mat4& getWorldMatrix() const { return _worldMatrix; } - - inline void setViewId(int val) { _viewID = val; } - inline int getViewId() const { return _viewID; } - + /** + * @brief Sets culling mask. + */ + inline void setCullingMask(int val) { _cullingMask = val; } + /** + * @brief Gets culling mask. + */ + inline int getCullingMask() const { return _cullingMask; } + /** + * @brief Adds a input assembler. + */ void addInputAssembler(const InputAssembler& ia); + /** + * @brief Clears all input assemblers. + */ void clearInputAssemblers(); + /** + * @brief Adds an effect. + */ void addEffect(Effect* effect); + /** + * @brief Clears all effects. + */ void clearEffects(); + /** + * @brief Extract draw item for the given index during rendering process. + */ void extractDrawItem(DrawItem& out, uint32_t index) const; private: @@ -93,7 +140,10 @@ private: std::vector _inputAssemblers; std::vector _defines; bool _dynamicIA = false; - int _viewID = -1; + int _cullingMask = -1; }; +// end of renderer group +/// @} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Pass.cpp b/native/cocos/renderer/renderer/Pass.cpp index 5cc3a2e731..0bd9183c97 100644 --- a/native/cocos/renderer/renderer/Pass.cpp +++ b/native/cocos/renderer/renderer/Pass.cpp @@ -103,4 +103,47 @@ void Pass::setStencilBack(StencilFunc stencilFunc, _stencilWriteMaskBack = stencilWriteMask; } +void Pass::copy(const Pass& pass) +{ + // blending + _blend = pass._blend; + _blendEq = pass._blendEq; + _blendAlphaEq = pass._blendAlphaEq; + _blendSrc = pass._blendSrc; + _blendDst = pass._blendDst; + _blendSrcAlpha = pass._blendSrcAlpha; + _blendDstAlpha = pass._blendDstAlpha; + _blendColor = pass._blendColor; + + // depth + _depthTest = pass._depthTest; + _depthWrite = pass._depthWrite; + _depthFunc = pass._depthFunc; + + // stencil + + _stencilTest = pass._stencilTest; + // front + _stencilRefFront = pass._stencilRefFront; + _stencilFuncFront = pass._stencilFuncFront; + _stencilFailOpFront = pass._stencilFailOpFront; + _stencilZFailOpFront = pass._stencilZFailOpFront; + _stencilZPassOpFront = pass._stencilZPassOpFront; + _stencilWriteMaskFront = pass._stencilWriteMaskFront; + _stencilMaskFront = pass._stencilMaskFront; + // back + _stencilRefBack = pass._stencilRefBack; + _stencilFuncBack = pass._stencilFuncBack; + _stencilFailOpBack = pass._stencilFailOpBack; + _stencilZFailOpBack = pass._stencilZFailOpBack; + _stencilZPassOpBack = pass._stencilZPassOpBack; + _stencilWriteMaskBack = pass._stencilWriteMaskBack; + _stencilMaskBack = pass._stencilMaskBack; + + // cull mode + _cullMode = pass._cullMode; + + _programName = pass._programName; +} + RENDERER_END diff --git a/native/cocos/renderer/renderer/Pass.h b/native/cocos/renderer/renderer/Pass.h index 21f969744d..d28cfbbadc 100644 --- a/native/cocos/renderer/renderer/Pass.h +++ b/native/cocos/renderer/renderer/Pass.h @@ -31,14 +31,52 @@ RENDERER_BEGIN +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief Pass describes base render pass configurations, including program, cull face, blending, depth testing and stencil testing configs.\n + * JS API: renderer.Pass + * @code + * let pass = new renderer.Pass('sprite'); + * pass.setDepth(false, false); + * pass.setCullMode(gfx.CULL_NONE); + * pass.setBlend( + * gfx.BLEND_FUNC_ADD, + * gfx.BLEND_SRC_ALPHA, gfx.BLEND_ONE_MINUS_SRC_ALPHA, + * gfx.BLEND_FUNC_ADD, + * gfx.BLEND_SRC_ALPHA, gfx.BLEND_ONE_MINUS_SRC_ALPHA + * ); + * @endcode + */ class Pass : public Ref { public: + /** + * @brief Constructor with linked program name. + * @param[in] programName Shader program name + */ Pass(const std::string& programName); Pass() {} ~Pass(); + /** + * @brief Sets cull mode. + * @param[in] cullMode Cull front or back or both. + */ void setCullMode(CullMode cullMode); + /** + * @brief Sets blend mode. + * @param[in] blendEq RGB blend equation. + * @param[in] blendSrc Src RGB blend factor. + * @param[in] blendDst Dst RGB blend factor. + * @param[in] blendAlphaEq Alpha blend equation. + * @param[in] blendSrcAlpha Src Alpha blend equation. + * @param[in] blendDstAlpha Dst Alpha blend equation. + * @param[in] blendColor Blend constant color value. + */ void setBlend(BlendOp blendEq = BlendOp::ADD, BlendFactor blendSrc = BlendFactor::ONE, BlendFactor blendDst = BlendFactor::ZERO, @@ -46,9 +84,18 @@ public: BlendFactor blendSrcAlpha = BlendFactor::ONE, BlendFactor blendDstAlpha = BlendFactor::ZERO, uint32_t blendColor = 0xffffffff); + /** + * @brief Switch depth test or write, and sets depth test function. + * @param[in] depthTest Enable depth test or not. + * @param[in] depthWrite Enable depth write or not. + * @param[in] depthFunc Depth test function. + */ void setDepth(bool depthTest = false, bool depthWrite = false, DepthFunc depthFunc = DepthFunc::LESS); + /** + * @brief Sets stencil front-facing function, reference, mask, fail operation, write mask. + */ void setStencilFront(StencilFunc stencilFunc = StencilFunc::ALWAYS, uint32_t stencilRef = 0, uint8_t stencilMask = 0xff, @@ -56,6 +103,9 @@ public: StencilOp stencilZFailOp = StencilOp::KEEP, StencilOp stencilZPassOp = StencilOp::KEEP, uint8_t stencilWriteMask = 0xff); + /** + * @brief Sets stencil back-facing function, reference, mask, fail operation, write mask. + */ void setStencilBack(StencilFunc stencilFunc = StencilFunc::ALWAYS, uint32_t stencilRef = 0, uint8_t stencilMask = 0xff, @@ -63,10 +113,26 @@ public: StencilOp stencilZFailOp = StencilOp::KEEP, StencilOp stencilZPassOp = StencilOp::KEEP, uint8_t stencilWriteMask = 0xff); + /* + * @brief Sets stencil test enabled or not. + */ inline void setStencilTest(bool value) { _stencilTest = value; } + /** + * @brief Gets stencil test enabled or not. + */ inline bool getStencilTest() const { return _stencilTest; } + /** + * @brief Sets linked program name. + */ inline void setProgramName(const std::string& programName) { _programName = programName; } + /** + * @brief Disable stencil test. + */ inline void disableStencilTest() { _stencilTest = false; } + /** + * @brief deep copy from other pass. + */ + void copy(const Pass& pass); private: friend class BaseRenderer; @@ -112,4 +178,6 @@ private: std::string _programName = ""; }; +// end of renderer group +/// @} RENDERER_END diff --git a/native/cocos/renderer/renderer/ProgramLib.cpp b/native/cocos/renderer/renderer/ProgramLib.cpp index caeefbcf7a..5573b7ca0c 100644 --- a/native/cocos/renderer/renderer/ProgramLib.cpp +++ b/native/cocos/renderer/renderer/ProgramLib.cpp @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -190,32 +190,18 @@ void ProgramLib::define(const std::string& name, const std::string& vert, const templ.defines = defines; } -uint32_t ProgramLib::getKey(const std::string& name, const ValueMap& defines) +uint32_t ProgramLib::getKey(const std::string& name, int32_t ekey) { auto iter = _templates.find(name); assert(iter != _templates.end()); auto& tmpl = iter->second; - int32_t key = 0; - for (auto& tmplDefs : tmpl.defines) { - auto& tmplDefMap = tmplDefs.asValueMap(); - std::string tempName = tmplDefMap["name"].asString(); - auto iter2 = defines.find(tempName); - if (iter2 == defines.end()) { - continue; - } -// const auto& value = iter2->second; -// key |= tmplDefs._map(100); //IDEA: - uint32_t offset = tmplDefMap["_offset"].asUnsignedInt(); - key |= 1 << offset; - } - - return key << 8 | tmpl.id; + return ekey | tmpl.id; } -Program* ProgramLib::getProgram(const std::string& name, const ValueMap& defines) +Program* ProgramLib::getProgram(const std::string& name, const ValueMap& defines, int32_t definesKey) { - uint32_t key = getKey(name, defines); + uint32_t key = getKey(name, definesKey); auto iter = _cache.find(key); if (iter != _cache.end()) { iter->second->retain(); diff --git a/native/cocos/renderer/renderer/ProgramLib.h b/native/cocos/renderer/renderer/ProgramLib.h index 825b703f72..4a94886b98 100644 --- a/native/cocos/renderer/renderer/ProgramLib.h +++ b/native/cocos/renderer/renderer/ProgramLib.h @@ -2,17 +2,17 @@ Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -36,9 +36,20 @@ RENDERER_BEGIN class DeviceGraphics; class Program; +/** + * @addtogroup renderer + * @{ + */ + +/** + * @brief This class manages shader template and linked programs, material can customize shader by setting different defines. + */ class ProgramLib final { public: + /** + * @brief Program template + */ struct Template { uint32_t id = 0; @@ -48,14 +59,29 @@ public: ValueVector defines; }; + /** + * @brief Constructor with device and all initial templates. + */ ProgramLib(DeviceGraphics* device, std::vector