コード例 #1
0
        public void BeginFrame(GlobalUniform global)
        {
            GlobalUniform = global;
            SetupGlobalUniform();

            LightingUniform = new LightingUniform()
            {
                PointLights = new PointLightUniform[0]
            };
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ronbrogan/OpenH2
        public static void Setup()
        {
            GL.DebugMessageCallback(callback, (IntPtr.Zero));

            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Multisample);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            UploadQuadMesh();
            MatriciesUniform = new GlobalUniform()
            {
                ProjectionMatrix = Matrix4x4.CreateOrthographic(3.55555f, 2, 0, 10),
                ViewMatrix       = Matrix4x4.Identity,
                ViewPosition     = Vector3.Zero
            };

            ShaderHandle = ShaderCompiler.CreateShader(Shader.TextureViewer);
        }
コード例 #3
0
        public override void Render(double timestep)
        {
            var renderList = world.GetGlobalResource <RenderListStore>();

            RenderingPipeline.SetModels(renderList.Models);

            foreach (var light in renderList.Lights)
            {
                RenderingPipeline.AddPointLight(light);
            }

            var cameras = world.Components <CameraComponent>();
            var cam     = cameras.First();

            var pos = cam.PositionOffset;

            if (cam.TryGetSibling <TransformComponent>(out var xform))
            {
                pos += xform.Position;
            }

            var matrices = new GlobalUniform
            {
                ViewMatrix       = cam.ViewMatrix,
                ProjectionMatrix = cam.ProjectionMatrix,
                ViewPosition     = pos
            };

            RenderingPipeline.SetGlobals(matrices);

            graphics.BeginFrame(matrices);

            RenderingPipeline.DrawAndFlush();

            graphics.EndFrame();

            renderList.Clear();
        }
コード例 #4
0
ファイル: TagPreviewFactory.cs プロジェクト: ronbrogan/OpenH2
        private static TagPreviewViewModel GetBitmPreview(BitmapTag bitm)
        {
            var preview = new TagPreviewViewModel();

            preview.AddItem("bitmap", bitm, GetBitmapPreview);

            return(preview);

            object GetBitmapPreview(BitmapTag bitm)
            {
                // HACK: hard coding texture 0, needs texture binder rewrite to support here
                if (bitm.TextureInfos[0].Width == 0 || bitm.TextureInfos[0].Height == 0)
                {
                    return(null);
                }

                var textureBinder = new OpenGLTextureBinder();

                var settings = new GameWindowSettings();

                var nsettings = new NativeWindowSettings()
                {
                    API = ContextAPI.OpenGL,
                    AutoLoadBindings = true,
                    Size             = new OpenTK.Mathematics.Vector2i(bitm.TextureInfos[0].Width, bitm.TextureInfos[0].Height),
                    Title            = "OpenH2",
                    Flags            = ContextFlags.Debug | ContextFlags.Offscreen,
                    APIVersion       = new Version(4, 0)
                };

                var window = new GameWindow(settings, nsettings);

                window.IsVisible = false;
                window.MakeCurrent();

                GL.Enable(EnableCap.DebugOutput);
                GL.DebugMessageCallback(callback, (IntPtr.Zero));

                GL.Enable(EnableCap.DepthTest);
                GL.Enable(EnableCap.CullFace);
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

                var meshId           = UploadQuadMesh();
                var matriciesUniform = new GlobalUniform()
                {
                    ProjectionMatrix = Matrix4x4.CreateOrthographic(2f, 2f, 0, 10),
                    ViewMatrix       = Matrix4x4.Identity,
                    ViewPosition     = Vector3.Zero
                };

                var shader = ShaderCompiler.CreateShader(Shader.TextureViewer);

                var handle = textureBinder.GetOrBind(bitm, out var _);

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, handle);

                GL.ClearColor(0f, 0f, 0f, 1f);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                GL.UseProgram(shader);

                GL.GenBuffers(1, out uint MatriciesUniformHandle);

                GL.BindBuffer(BufferTarget.UniformBuffer, MatriciesUniformHandle);

                GL.BufferData(BufferTarget.UniformBuffer, GlobalUniform.Size, ref matriciesUniform, BufferUsageHint.DynamicDraw);

                GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, MatriciesUniformHandle);
                GL.BindBuffer(BufferTarget.UniformBuffer, 0);

                GL.BindVertexArray(meshId);

                GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, 0);

                GL.Flush();

                var bmp = new WriteableBitmap(new PixelSize(bitm.TextureInfos[0].Width, bitm.TextureInfos[0].Height), new Avalonia.Vector(72, 72), Avalonia.Platform.PixelFormat.Rgba8888);

                using (var buf = bmp.Lock())
                {
                    GL.ReadPixels(0, 0, bitm.TextureInfos[0].Width, bitm.TextureInfos[0].Height, PixelFormat.Rgba, PixelType.UnsignedByte, buf.Address);
                }

                window.Close();
                window.Dispose();

                return(bmp);
            }
        }