コード例 #1
0
        public void Render(ref RenderContext context, CameraData[] cameras, Matrix4[] transforms)
        {
            context.CommandBuffer.QueueCommand(RenderCommandsLibrary.GenerateShadowMaps());

            for (int i = 0; i < cameras.Length; i++)
            {
                Matrix4    cameraTransform = transforms[i];
                CameraData camera          = cameras[i];

                context.CommandBuffer.QueueCommand(new RenderCommand("Bind color FBO", (ref RenderContext context) =>
                {
                    camera.Framebuffer.Bind();
                    //Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer_color);
                    //Ogl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, camera.DepthTargetTexture.Handle, 0);
                    //Ogl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, camera.ColorTargetTexture.handle, 0);
                    //FramebufferErrorCode status = Ogl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                    //if (status != FramebufferErrorCode.FramebufferComplete)
                    //    DevTools.DevConsole.Log(DevTools.LogType.Error, status);

                    Ogl.Enable(EnableCap.DepthTest);
                    Ogl.Enable(EnableCap.CullFace);
                    Ogl.Enable(EnableCap.ProgramPointSize);
                    Ogl.Enable(EnableCap.Multisample);
                    Ogl.PointSize(10f);
                }));

                context.CommandBuffer.QueueCommand(RenderCommandsLibrary.DrawGeometry(camera, cameraTransform));
                context.CommandBuffer.QueueCommand(RenderCommandsLibrary.DrawGizmos(camera, cameraTransform));
                context.CommandBuffer.QueueCommand(RenderCommandsLibrary.DrawSkybox(camera, cameraTransform));

                context.CommandBuffer.QueueCommand(new RenderCommand("Unbind FBO", (ref RenderContext context) =>
                {
                    //TODO: Blit f*****g up at some point wtf
                    Framebuffer.Blit(camera.Framebuffer, camera.FinalFramebuffer, ClearBufferMask.ColorBufferBit);
                    Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                }));
            }

            //context.CommandBuffer.QueueCommand(RenderCommandsLibrary.DrawUI());
        }
コード例 #2
0
ファイル: RCL_UIRender.cs プロジェクト: luxgile/Entygine
        public static RenderCommand DrawUI()
        {
            return(new RenderCommand("Draw UI", (ref RenderContext context) =>
            {
                if (!context.TryGetData(out UICanvasRenderData canvasRenderData))
                {
                    return;
                }

                Ogl.Disable(EnableCap.CullFace);
                Ogl.Disable(EnableCap.DepthTest);

                Ogl.Enable(EnableCap.Blend);
                Ogl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

                Matrix4 projection = canvasRenderData.Camera.CalculateProjection();

                List <UICanvas> canvases = canvasRenderData.GetCanvases();
                for (int i = 0; i < canvases.Count; i++)
                {
                    UICanvas canvas = canvases[i];
                    canvas.deltaTimeText.Text = $"{FrameContext.Current.count} frame - {FrameContext.Current.delta * 1000:F1}ms - {1 / FrameContext.Current.delta:F1}fps";

                    canvas.UpdateRenderers();
                    var renderables = canvas.GetRenderables();
                    for (int m = 0; m < renderables.Count; m++)
                    {
                        UI_IRenderable currRenderable = renderables[m];
                        currRenderable.Material.SetMatrix("projection", projection);
                        currRenderable.DrawUI(canvasRenderData.Mesh);
                    }
                }

                Ogl.Enable(EnableCap.CullFace);
                Ogl.Enable(EnableCap.DepthTest);
                Ogl.Disable(EnableCap.Blend);
            }));
コード例 #3
0
ファイル: EntygineApp.cs プロジェクト: luxgile/Entygine
        public static void LoadEngine()
        {
            if (loadedEngine)
            {
                return;
            }

            loadedEngine = true;

            Ogl.enableErrorCheck = true;

            InitConsole();

            DevConsole.Log(LogType.Info, "Creating Entity World...");

            coreWorker = new WorkerCycleCore();
            EntityWorld world = InitEcs();

            RenderPipelineCore.SetPipeline(new ForwardRenderPipeline());

            InitPhysics();
            InitSkybox();
            InitUI(world);
            InitLight();
            InitScene(world);

            DevConsole.Log(LogType.Info, "Entity world created.");

            Ogl.ClearColor(0.1f, 0.1f, 0.2f, 1.0f);
            Ogl.Enable(EnableCap.DepthTest);
            Ogl.Enable(EnableCap.CullFace);
            Ogl.Enable(EnableCap.ProgramPointSize);
            Ogl.PointSize(10f);

            EntityWorld InitEcs()
            {
                EntityWorld world = EntityWorld.CreateWorld();

                world.Runner.AssignToWorker(coreWorker).CreateSystemsAuto(world);
                EntityWorld.SetActive(world);
                return(world);
            }

            void InitPhysics()
            {
                PhysicsRunner physicsRunner = new PhysicsRunner();
                PhysicsWorld  world         = new PhysicsWorld();

                PhysicsWorld.SetDefaultWorld(world);
                physicsRunner.AddWorld(world);
                physicsRunner.AssignToWorker(coreWorker);
            }

            void InitScene(EntityWorld world)
            {
                Mesh   meshResource   = MeshPrimitives.CreateCube(1);
                Shader shaderResource = Shader.CreateShaderWithPath(AssetBrowser.Utilities.LocalToAbsolutePath(@"Shaders\standard.vert"),
                                                                    AssetBrowser.Utilities.LocalToAbsolutePath(@"Shaders\standard.frag"), "Standard Shader");

                Texture2D     texture          = new Texture2D(AssetBrowser.Utilities.LocalToAbsolutePath(@"Textures\Box.png"), "Box");
                Material      materialResource = new Material(shaderResource, texture);
                SC_RenderMesh renderMesh       = new SC_RenderMesh(meshResource, materialResource);

                EntityArchetype meshArchetype = new EntityArchetype(typeof(SC_RenderMesh), typeof(C_Transform), typeof(C_Position));
                EntityArchetype boxArchetype  = new EntityArchetype(typeof(SC_RenderMesh), typeof(C_Transform), typeof(C_Position), typeof(C_BoxTag));

                Entity planeEntity = world.EntityManager.CreateEntity(meshArchetype);

                world.EntityManager.SetComponent(planeEntity, new C_Position()
                {
                    value = new Vec3f(0, 0, 0)
                });
                //world.EntityManager.SetComponent(planeEntity, new C_PhysicsBody() { body = new PhysicBody() { isStatic = true } });
                Mesh     planeMesh     = MeshPrimitives.CreatePlaneXZ(50);
                Material planeMaterial = new Material(shaderResource, Texture2D.CreateWhiteTexture(64, 64));

                world.EntityManager.SetSharedComponent(planeEntity, new SC_RenderMesh(planeMesh, planeMaterial));

                Entity planeEntity2 = world.EntityManager.CreateEntity(meshArchetype);

                world.EntityManager.SetComponent(planeEntity2, new C_Position()
                {
                    value = new Vec3f(0, 5, -10)
                });
                //world.EntityManager.SetComponent(planeEntity2, new C_PhysicsBody() { body = new PhysicBody() { isStatic = true } });

                Mesh     planeMesh2     = MeshPrimitives.CreatePlaneXY(10);
                Material planeMaterial2 = new Material(shaderResource, texture);

                world.EntityManager.SetSharedComponent(planeEntity2, new SC_RenderMesh(planeMesh2, planeMaterial2));

                Entity boxEntity = world.EntityManager.CreateEntity(boxArchetype);

                world.EntityManager.SetComponent(boxEntity, new C_Position()
                {
                    value = new Vec3f(0, 2, 0)
                });
                //world.EntityManager.SetComponent(boxEntity, new C_PhysicsBody() { body = new PhysicBody() });
                world.EntityManager.SetSharedComponent(boxEntity, renderMesh);

                Entity boxEntity2 = world.EntityManager.CreateEntity(boxArchetype);

                world.EntityManager.SetComponent(boxEntity2, new C_Position()
                {
                    value = new Vec3f(2, 2, 0)
                });
                //world.EntityManager.SetComponent(boxEntity2, new C_PhysicsBody() { body = new PhysicBody() });
                world.EntityManager.SetSharedComponent(boxEntity2, renderMesh);

                Entity boxEntity3 = world.EntityManager.CreateEntity(boxArchetype);

                world.EntityManager.SetComponent(boxEntity3, new C_Position()
                {
                    value = new Vec3f(-2, 2, 0)
                });
                //world.EntityManager.SetComponent(boxEntity3, new C_PhysicsBody() { body = new PhysicBody() });

                world.EntityManager.SetSharedComponent(boxEntity3, renderMesh);

                EntityArchetype editorCameraArchetype = new EntityArchetype(typeof(C_Camera), typeof(C_Transform), typeof(C_EditorCamera));
                Entity          cameraEditorEntity    = world.EntityManager.CreateEntity(editorCameraArchetype);

                world.EntityManager.SetComponent(cameraEditorEntity, new C_Camera()
                {
                    cameraData = CameraData.CreatePerpectiveCamera(45f, 800f / 600f, 0.1f, 100f)
                });

                world.EntityManager.SetComponent(cameraEditorEntity, new C_EditorCamera()
                {
                    speed = 10f, focusPoint = new Vector3(0, 2, 0), focusDistance = 12, pitch = 20, yaw = 115, sensitivity = 20
                });
            }

            void InitLight()
            {
                if (RenderPipelineCore.TryGetContext(out LightsRenderData lightData))
                {
                    lightData.lights.Add(new DirectionalLight());
                }
            }

            void InitUI(EntityWorld world)
            {
                EntityArchetype canvasArch = new EntityArchetype(typeof(C_UICanvas));
                var             entity     = world.EntityManager.CreateEntity(canvasArch);

                world.EntityManager.SetComponent(entity, new C_UICanvas()
                {
                    canvas = new UICanvas()
                });
            }