UnityのLow-Level Native Plugin Interface
Unityには、LowLevelNativePluginInterfaceというものがあって
C++で直に描画apiを叩けます。
https://docs.unity3d.com/Manual/NativePluginInterface.html
ですが、公式ではGL.issueplugineventのサンプルしかあらず
CommandBufferに乗せる方法やGameビューとシーンビュー両方表示する
機能が存在してなかったので、はっときます
ちなみに、カメラ毎に並列描画してないので、マルチスレッドの対策としては
issuplugineventの実行事に、DirectXでいうClearからPresentまでの処理を詰め込んで実行すればいい。
描画リソースに関してはゲーム側でReleaseされたとしても参照カウント形式で使い終わるまで保持すればいい。
それと描画の設計は、
1Frameで使うリソース × 遅延するフレームの数
を用意して、使ってないフレーム用リソースに書き込んでいって
一番古い順からissuplugineventで実行がいいんかね。
public class RenderingTest : MonoBehaviour { private const CameraEvent RENDER_PASS = CameraEvent.BeforeForwardOpaque; public Camera camera_; public CommandBuffer command_; void Start() { camera_ = GetComponent<Camera>(); command_ = new CommandBuffer(); command_.name = "Use Rendering Plugin"; command_.IssuePluginEvent(UseRenderingPlugin.GetRenderEventFunc(), 1); camera_.AddCommandBuffer(RENDER_PASS, command_); foreach (Camera sceneCamera in UnityEditor.SceneView.GetAllSceneCameras()) { if (sceneCamera.cameraType == CameraType.SceneView) { sceneCamera.AddCommandBuffer(RENDER_PASS, command_); } } } public void OnDisable() { foreach (var sceneCamera in UnityEditor.SceneView.GetAllSceneCameras()) { sceneCamera.RemoveCommandBuffer(RENDER_PASS, command_); } camera_.RemoveCommandBuffer(RENDER_PASS, command_); } void OnPostRender() { UseRenderingPlugin.SetTimeFromUnity(Time.timeSinceLevelLoad); } private void OnPreRender() { /**/ } }