Ejemplo n.º 1
0
        protected override void InitializeService()
        {
            if (RenderStack.Graphics.Configuration.canUseFramebufferObject)
            {
                framebuffer = FramebufferFactory.Create(size, size);
                framebuffer.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Red,
                    PixelInternalFormat.Rgb8
                    //PixelInternalFormat.R8
                    //PixelInternalFormat.Rgb32f
                    );
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent24,
                    0
                    );
                framebuffer.Begin();
                framebuffer.Check();
                framebuffer.End();
            }

            camera.Projection.ProjectionType  = ProjectionType.Other;
            camera.Projection.NearParameter.X = 0.01f;
        }
Ejemplo n.º 2
0
        /** Initialises the renderer, creating the internal buffers with the given dimensions. */
        public FramebufferManager(int width, int height, int lowResWidth, int lowResHeight)
        {
            HighLevelRenderer.shaderDrawSprite = Video.loadShader("drawSprite");
            HighLevelRenderer.shaderIndexedBitmapSprite = Video.loadShader("indexedBitmapSprite");

            highResBuffer = new Framebuffer(width, height);
            lowResBuffer = new Framebuffer(lowResWidth, lowResHeight);
        }
Ejemplo n.º 3
0
        public void Blit(IFramebuffer target, ClearBufferMask mask, BlitFramebufferFilter filter)
        {
            FramebufferGL3 targetGL3 = (FramebufferGL3)target;

            GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, framebufferObject);
            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, targetGL3.framebufferObject);
            GL.BlitFramebuffer(0, 0, viewport.Width, viewport.Height, 0, 0, target.Viewport.Width, target.Viewport.Height, mask, filter);
        }
Ejemplo n.º 4
0
 private void DestroyFramebuffers()
 {
     if (framebuffer != null)
     {
         framebuffer.Dispose();
         framebuffer = null;
     }
 }
        public EmulatedDisplayDriver(EmulatorWindow emulatorWindow, int visibleWidth, int visibleHeight)
        {
            _emulatorWindow = emulatorWindow;
            VisibleWidth    = visibleWidth;
            VisibleHeight   = visibleHeight;

            Framebuffer = new EmulatedFramebuffer(_emulatorWindow, visibleWidth, visibleHeight);
        }
Ejemplo n.º 6
0
        public unsafe HighlightDrawer(IGraphicsInfra infra, IBlurDrawer blurDrawer, IQuadDrawer quadDrawer, IBleedDrawer bleedDrawer, IOffScreenContainer offScreenContainer)
        {
            this.infra              = infra;
            this.blurDrawer         = blurDrawer;
            this.quadDrawer         = quadDrawer;
            this.bleedDrawer        = bleedDrawer;
            this.offScreenContainer = offScreenContainer;

            #region Shader Text
            const string vertexShaderText =
                @"#version 150
in vec4 in_position;

void main()
{
    gl_Position = in_position;
}
";

            const string fragmentShaderText =
                @"#version 150
out vec4 out_color;

void main()
{
    out_color = vec4(1, 1, 1, 1);
}
";
            #endregion

            var vs = infra.GlContext.Create.VertexShader(vertexShaderText);
            var fs = infra.GlContext.Create.FragmentShader(fragmentShaderText);
            program = infra.GlContext.Create.Program(new ShaderProgramDescription
            {
                VertexShaders        = vs.EnumSelf(),
                FragmentShaders      = fs.EnumSelf(),
                VertexAttributeNames = new[] { "in_position" }
            });

            var vertices = new[]
            {
                new Vector4(-1, 1, 0.5f, 1),
                new Vector4(-1, -1, 0.5f, 1),
                new Vector4(1, 1, 0.5f, 1),
                new Vector4(1, -1, 0.5f, 1)
            };

            IBuffer vb;

            fixed(Vector4 *pVertices = vertices)
            vb = infra.GlContext.Create.Buffer(BufferTarget.Array, vertices.Length * sizeof(Vector4), BufferUsageHint.StaticDraw, (IntPtr)pVertices);

            vao = infra.GlContext.Create.VertexArray();
            vao.SetVertexAttributeF(0, vb, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, sizeof(Vector4), 0);

            drawSpotFramebuffer = infra.GlContext.Create.Framebuffer();
        }
Ejemplo n.º 7
0
        public RenderingRuntime(IGraphicsInfra infra, ISceneRendererPool sceneRendererPool, IOffScreenContainer offScreenContainer)
        {
            this.infra                 = infra;
            this.sceneRendererPool     = sceneRendererPool;
            this.offScreenContainer    = offScreenContainer;
            offScreenCacheDeathNote    = new List <object>();
            sceneRendererSettingsCache = new Dictionary <Tuple3 <bool>, IPropertyBag>();

            glContext      = infra.GlContext;
            rttFramebuffer = glContext.Create.Framebuffer();
        }
Ejemplo n.º 8
0
 public void CleanupWindowSizeResources()
 {
     if (linear != null)
     {
         linear.Dispose();
         linear = null;
     }
     if (multisampleResolve != null)
     {
         multisampleResolve.Dispose();
         multisampleResolve = null;
     }
 }
Ejemplo n.º 9
0
 private void CreateFramebuffers()
 {
     framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.ColorAttachment0,
         //PixelFormat.RedInteger,
         RenderbufferStorage.R16f,
         0
         );
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.DepthAttachment,
         //PixelFormat.DepthComponent,
         RenderbufferStorage.DepthComponent32,
         0
         );
     framebuffer.Begin();
     framebuffer.Check();
     framebuffer.End();
 }
Ejemplo n.º 10
0
        public void CreateWindowSizeResources()
        {
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources()");
            @default = FramebufferFactory.Create(window);

            if (Configuration.gammaCorrect)
            {
                bool sRgbEnable = GL.IsEnabled(EnableCap.FramebufferSrgb);

                linear = FramebufferFactory.Create(window.Width, window.Height);

                int samples = 4;

                linear.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    RenderbufferStorage.Rgb32f,
                    samples
                    );
                linear.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    samples
                    );
                linear.Begin();
                linear.Check();
                linear.End();

                multisampleResolve = FramebufferFactory.Create(window.Width, window.Height);
                multisampleResolve.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    PixelInternalFormat.Rgb32f
                    );
                multisampleResolve.Begin();
                multisampleResolve.Check();
                multisampleResolve.End();
            }
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources() done");
        }
Ejemplo n.º 11
0
        public void Render(StereoMode mode)
        {
#if true
            float[]      offset           = { -1.0f, 1.0f };
            float        stereoSeparation = sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0];
            IFramebuffer framebuffer      = views[0];
            for (int viewIndex = 0; viewIndex < 2; ++viewIndex)
            {
                framebuffer = views[viewIndex];

                renderer.Requested.Camera   = sceneManager.Camera;
                renderer.Requested.Viewport = framebuffer.Viewport;
                framebuffer.Begin();
                //framebufferManager.Default.Begin();

                sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0] = offset[viewIndex] * stereoSeparation;
                mainSceneRenderer.Render(viewIndex);
                framebuffer.End();
            }
            sceneManager.Camera.Projection.StereoParameters.EyeSeparation[0] = stereoSeparation;
#endif

#if true
            Debug.WriteLine("=== Render Stereo Combine");

            renderer.Requested.Viewport = highLevelRenderer.WindowViewport;
            renderer.Requested.Camera   = sceneManager.Camera;
            renderer.RenderCurrentClear();

            highLevelRenderer.Use2DCamera();

            renderer.Requested.Mesh     = quadRenderer.Mesh;
            renderer.Requested.Material = stereoMerge;
            renderer.Requested.Program  = (mode != null && mode.Program != null) ? mode.Program : blend;
            renderer.Requested.MeshMode = MeshMode.PolygonFill;
            renderer.SetFrame(renderer.DefaultFrame);
            renderer.SetTexture("t_left", views[0][FramebufferAttachment.ColorAttachment0]);
            renderer.SetTexture("t_right", views[1][FramebufferAttachment.ColorAttachment0]);
            renderer.RenderCurrent();
#endif
        }
Ejemplo n.º 12
0
        private void ClearShadow(int lightIndex)
        {
            if (
                (RenderStack.Graphics.Configuration.canUseTextureArrays == false) &&
                (lightIndex > 0)
                )
            {
                return;
            }

            IFramebuffer framebuffer = shadow;

            renderer.Requested.Viewport = framebuffer.Viewport;

            var shadowAttachment = example.Renderer.Configuration.hardwareShadowPCF
                ? FramebufferAttachment.DepthAttachment
                : FramebufferAttachment.ColorAttachment0;

            framebuffer.Begin();
            if (
                (RenderStack.Graphics.Configuration.canUseTextureArrays) &&
                (RenderStack.Graphics.Configuration.glslVersion >= 330)
                )
            {
                framebuffer.AttachTextureLayer(shadowAttachment, 0, lightIndex);
            }

            GL.Viewport(
                renderer.Requested.Viewport.X,
                renderer.Requested.Viewport.Y,
                renderer.Requested.Viewport.Width,
                renderer.Requested.Viewport.Height
                );

            renderer.PartialGLStateResetToDefaults();

            GL.Disable(EnableCap.ScissorTest);
            GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
Ejemplo n.º 13
0
        public void copyFramebuffer(IFramebuffer source, IFramebuffer target, bool fromLowres)
        {
            //Bind shader
            LowLevelRenderer.shader = HighLevelRenderer.shaderDrawSprite;
            target.bind();

            //Set target size uniforms
            var tmatrix = fromLowres ? Util.Maths.matrixFitRectIntoScreen(lowResWidth, lowResHeight, highResWidth, highResHeight)
                                     : Matrix4.Identity;

            HighLevelRenderer.shaderDrawSprite["transformMatrix"].SetValue(tmatrix);

            float yflip = fromLowres ? -1 : 1;
            HighLevelRenderer.shaderDrawSprite["uvMatrix"].SetValue(new Matrix4(new float[] {1,0,0,0,
                                                                                            0,yflip,0,0,
                                                                                            0,0,0,0,
                                                                                            0,0,0,1}));
            //Bind source texture
            Gl.BindTexture(TextureTarget.Texture2D, source.textures()[0]);
            LowLevelRenderer.geometry = LowLevelRenderer.quad;
            LowLevelRenderer.draw();
        }
Ejemplo n.º 14
0
        public void Draw(IFramebuffer targetFramebuffer, IRenderbuffer depthStencil)
        {
            infra.GlContext.States.DepthStencil.StencilTestEnable.Set(true);
            infra.GlContext.States.Blend.BlendEnable.Set(false);
            infra.GlContext.States.DepthStencil.DepthMask.Set(false);
            infra.GlContext.States.DepthStencil.DepthTestEnable.Set(false);
            infra.GlContext.States.DepthStencil.Back.StencilWriteMask.Set(0xff);
            infra.GlContext.States.DepthStencil.Front.StencilWriteMask.Set(0xff);
            infra.GlContext.States.Rasterizer.CullFaceEnable.Set(false);

            var offScreen = offScreenContainer.Get(this, depthStencil, depthStencil.Width, depthStencil.Height, depthStencil.Samples, OffScreenTtl);

            drawSpotFramebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.Color0, offScreen.ColorBuffer);
            drawSpotFramebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil);
            drawSpotFramebuffer.ClearColor(0, new Color4(0, 0, 0, 0));
            infra.GlContext.Bindings.Framebuffers.Draw.Set(drawSpotFramebuffer);

            infra.GlContext.Bindings.Program.Set(program);
            infra.GlContext.Bindings.VertexArray.Set(vao);

            SetStencilFunc(StencilFunction.Equal);
            infra.GlContext.Actions.Draw.Arrays(BeginMode.TriangleStrip, 0, 4);
            offScreen.Resolve();
            infra.GlContext.Bindings.Framebuffers.Draw.Set(offScreen.Framebuffer);
            SetStencilFunc(StencilFunction.Always);

            bleedDrawer.Draw(offScreen.ResolvedTex, Common.Numericals.Colors.Color4.Orange);
            offScreen.Resolve();
            infra.GlContext.Bindings.Framebuffers.Draw.Set(targetFramebuffer);
            SetStencilFunc(StencilFunction.Notequal);
            quadDrawer.Draw(offScreen.ResolvedTex);
            //quadDrawer.Draw(Common.Numericals.Colors.Color4.Blue);
            SetStencilFunc(StencilFunction.Always);

            infra.GlContext.States.DepthStencil.StencilTestEnable.Set(false);
            infra.GlContext.States.DepthStencil.DepthMask.Set(true);
            infra.GlContext.States.DepthStencil.DepthTestEnable.Set(true);
        }
Ejemplo n.º 15
0
        private void CreateFramebuffers()
        {
            if (useFramebuffer == false)
            {
                return;
            }

            framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
            if (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.RedInteger,
                    RenderbufferStorage.R32ui,
                    0
                    );
            }
            else
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.Rgb,
                    RenderbufferStorage.Rgb8,
                    0
                    );
            }
            framebuffer.AttachRenderBuffer(
                FramebufferAttachment.DepthAttachment,
                //PixelFormat.DepthComponent,
                RenderbufferStorage.DepthComponent32,
                0
                );
            framebuffer.Begin();
            framebuffer.Check();
            framebuffer.End();
        }
Ejemplo n.º 16
0
        public override void Initialize()
        {
            renderTarget = Context.Create.Texture2D(RenderTargetSize, RenderTargetSize, TextureHelper.CalculateMipCount(RenderTargetSize, 1, 1), Format.Rgba8);
            depthStencil = Context.Create.Renderbuffer(RenderTargetSize, RenderTargetSize, Format.Depth24Stencil8);

            framebuffer = Context.Create.Framebuffer();
            framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, renderTarget, 0);
            framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil);

            var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 24 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[]
            {
                new Vertex(1f, -1f, 1f, 1f, 0f, 0f, 0f, 0f),
                new Vertex(1f, 1f, 1f, 1f, 0f, 0f, 1f, 0f),
                new Vertex(1f, 1f, -1f, 1f, 0f, 0f, 1f, 1f),
                new Vertex(1f, -1f, -1f, 1f, 0f, 0f, 0f, 1f),

                new Vertex(1f, 1f, 1f, 0f, 1f, 0f, 0f, 0f),
                new Vertex(-1f, 1f, 1f, 0f, 1f, 0f, 1f, 0f),
                new Vertex(-1f, 1f, -1f, 0f, 1f, 0f, 1f, 1f),
                new Vertex(1f, 1f, -1f, 0f, 1f, 0f, 0f, 1f),

                new Vertex(-1f, 1f, 1f, -1f, 0f, 0f, 0f, 0f),
                new Vertex(-1f, -1f, 1f, -1f, 0f, 0f, 1f, 0f),
                new Vertex(-1f, -1f, -1f, -1f, 0f, 0f, 1f, 1f),
                new Vertex(-1f, 1f, -1f, -1f, 0f, 0f, 0f, 1f),

                new Vertex(-1f, -1f, 1f, 0f, -1f, 0f, 0f, 0f),
                new Vertex(1f, -1f, 1f, 0f, -1f, 0f, 1f, 0f),
                new Vertex(1f, -1f, -1f, 0f, -1f, 0f, 1f, 1f),
                new Vertex(-1f, -1f, -1f, 0f, -1f, 0f, 0f, 1f),

                new Vertex(-1f, -1f, 1f, 0f, 0f, 1f, 0f, 0f),
                new Vertex(-1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f),
                new Vertex(1f, 1f, 1f, 0f, 0f, 1f, 1f, 1f),
                new Vertex(1f, -1f, 1f, 0f, 0f, 1f, 0f, 1f),

                new Vertex(-1f, 1f, -1f, 0f, 0f, -1f, 0f, 0f),
                new Vertex(-1f, -1f, -1f, 0f, 0f, -1f, 1f, 0f),
                new Vertex(1f, -1f, -1f, 0f, 0f, -1f, 1f, 1f),
                new Vertex(1f, 1f, -1f, 0f, 0f, -1f, 0f, 1f)
            });

            var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 36 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[]
            {
                0, 1, 2, 0, 2, 3,
                4, 5, 6, 4, 6, 7,
                8, 9, 10, 8, 10, 11,
                12, 13, 14, 12, 14, 15,
                16, 17, 18, 16, 18, 19,
                20, 21, 22, 20, 22, 23
            });

            vertexArray = Context.Create.VertexArray();
            vertexArray.SetElementArrayBuffer(indexBuffer);
            vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 0);
            vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 12);
            vertexArray.SetVertexAttributeF(2, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 32, 24);

            transformBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
            cameraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
            #if INTEL_WORKAROUND
            cameraOutsideBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
            #endif
            cameraExtraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw);
            lightBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw);

            using (var textureLoader = new TextureLoader("../Textures/DiffuseTest.png"))
            {
                diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Rgba8);
                for (int i = 0; i < diffuseMap.MipCount; i++)
                    diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte);
            }

            sampler = Context.Create.Sampler();
            sampler.SetMagFilter(TextureMagFilter.Linear);
            sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear);
            sampler.SetMaxAnisotropy(16f);

            IVertexShader vsh = Context.Create.VertexShader(VertexShaderText);
            IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText);
            program = Context.Create.Program(new ShaderProgramDescription
            {
                VertexShaders = new[] {vsh},
                FragmentShaders = new[] {fsh},
                VertexAttributeNames = new[] {"in_position", "in_normal", "in_tex_coord"},
                UniformBufferNames = new[] {"Transform", "Camera", "Light"},
                SamplerNames = new[] {"DiffuseMap"}
            });
        }
Ejemplo n.º 17
0
        public void SetLightCount(int n)
        {
            if (n == currentLightCount)
            {
                return;
            }

            currentLightCount = n;

            // \todo if n < currentLightCount ?

            if (RenderStack.Graphics.Configuration.useGl1 == true)
            {
                return;
            }

            if (shadow != null)
            {
                shadow.Dispose();
            }
            shadow = FramebufferFactory.Create(Configuration.shadowResolution, Configuration.shadowResolution);

            if (example.Renderer.Configuration.hardwareShadowPCF)
            {
                shadowAttachment = FramebufferAttachment.DepthAttachment;
                var texture = shadow.AttachTextureArray(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    PixelInternalFormat.DepthComponent,
                    n
                    );
            }
            else
            {
                shadowAttachment = FramebufferAttachment.ColorAttachment0;
                if (
                    (RenderStack.Graphics.Configuration.canUseTextureArrays) &&
                    (RenderStack.Graphics.Configuration.glslVersion >= 330)
                    )
                {
                    shadow.AttachTextureArray(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f,
                        n
                        );
                }
                else
                {
                    shadow.AttachTexture(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f
                        );
                }
                shadow.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    0
                    );
            }
            shadow.Begin();
            shadow.Check();
            shadow.End();

            var noShadow = materialManager.Textures["NoShadow"] = new TextureGL(
                1, 1, PixelFormat.Red, PixelInternalFormat.R16f, n
                );

            System.Single[] whiteData = new System.Single[n];
            for (int i = 0; i < n; ++i)
            {
                whiteData[i] = 1.0f;
            }
            noShadow.Upload(whiteData, 0);
        }
Ejemplo n.º 18
0
 public GpuFinalDecoder(IPclWorkarounds pclWorkarounds, IClientSettings settings, IContext context)
 {
     this.pclWorkarounds = pclWorkarounds;
     fullTextureProcessor = new FullTextureProcessor(settings, context, FragmentShaderText, new[] { "DiffTexture", "PrevTextureDetailed", "PrevTextureMip" });
     framebuffer = context.Create.Framebuffer();
     mipInfoBuffer = context.Create.Buffer(BufferTarget.UniformBuffer, 16, BufferUsageHint.DynamicDraw);
     sampler = context.Create.Sampler();
 }
Ejemplo n.º 19
0
 public void highresFxActive(bool active)
 {
     var w = highResBuffer.width();
     var h = highResBuffer.height();
     highResBuffer.Dispose();
     if (active)
         highResBuffer = new DoubleFramebuffer(w, h);
     else
     {
         highResBuffer = screenFramebuffer;
     }
     resizeHighRes(w, h);
 }
Ejemplo n.º 20
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            // ...

            // Create shader program

            string compute_shader =
                @"#version 460

            layout(local_size_x = 1, local_size_y = 1) in;
            layout(rgba32f, binding = 1) writeonly uniform image2D img_output;

            layout(location = 1) uniform vec4  u_color;
            layout(location = 2) uniform float u_margin;
            layout(location = 3) uniform float u_random; 

            layout(std430, binding = 1) buffer TCoord1
            {
                vec4 pos;
            } coord_inout;

            vec4[7] constants = vec4[7](
                vec4(0.0,  0.85,  0.2,   -0.15),  
                vec4(0.0,  0.04, -0.26,   0.28),  
                vec4(0.0, -0.04,  0.23,   0.26),  
                vec4(0.16, 0.85,  0.22,   0.24),  
                vec4(0.0,  0.0,   0.0,    0.0 ),  
                vec4(0.0,  1.6,   1.6,    0.44),  
                vec4(1.0, 86.0,  93.0,  100.0 ));  

            void main() {
  
                  vec2 dims = vec2(imageSize(img_output)); // fetch image dimensions

                  int i = 0; 
                  for (; i < 4; ++i)
                  {
                      if (u_random*100.0 < constants[6][i])
                          break;
                  }
                  i = min(i, 3);

                  vec2 fern = vec2(
                      constants[0][i] * coord_inout.pos.x + constants[1][i] * coord_inout.pos.y + constants[4][i],
                      constants[2][i] * coord_inout.pos.x + constants[3][i] * coord_inout.pos.y + constants[5][i]);
                  coord_inout.pos.xy = fern;
                  
                  vec2 pixel_coords = vec2(
                      (fern.x + 2.1820 + u_margin) * dims.x / (2.1820 + 2.6558 + 2.0 * u_margin),  
                      dims.y - (-fern.y + 9.9983 + u_margin) * dims.y / (9.9983 + 2.0 * u_margin));
                  
                  // output to a specific pixel in the image
                  imageStore(img_output, ivec2(pixel_coords), u_color);
            }";

            this._compute_prog = openGLFactory.ComputeShaderProgram(compute_shader);
            this._compute_prog.Generate();

            // Model view projection shader storage block objects and buffers
            _coord_ssbo = openGLFactory.NewStorageBuffer();
            TCoordinate coord_data = new TCoordinate(Vector2.Zero);

            this._coord_ssbo.Create(ref coord_data, IStorageBuffer.Usage.ReadWrite);
            this._coord_ssbo.Bind(1);

            // framebuffers

            _fbo = openGLFactory.NewFramebuffer();
            _fbo.Create(_image_cx, _image_cy, IFramebuffer.Kind.texture, IFramebuffer.Format.RGBA_F32, true, false);
            _fbo.Clear(new Color4(0.2f, 0.1f, 0.0f, 1.0f));

            // states

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);

            base.OnLoad();
        }
Ejemplo n.º 21
0
 public GpuDebugger(IPclWorkarounds pclWorkarounds, IClientSettings settings, IContext context)
 {
     this.pclWorkarounds = pclWorkarounds;
     fullTextureProcessor = new FullTextureProcessor(settings, context, FragmentShaderText, new[] { "Texture0", "Texture1" });
     framebuffer = context.Create.Framebuffer();
     mipInfoBuffer = context.Create.Buffer(BufferTarget.UniformBuffer, 16, BufferUsageHint.DynamicDraw);
     sampler = context.Create.Sampler();
 }
Ejemplo n.º 22
0
 public OffScreen(IGraphicsInfra infra)
 {
     this.infra         = infra;
     Framebuffer        = infra.GlContext.Create.Framebuffer();
     resolveFramebuffer = infra.GlContext.Create.Framebuffer();
 }
Ejemplo n.º 23
0
        public override void Initialize()
        {
            renderTarget = Context.Create.Texture2D(RenderTargetSize, RenderTargetSize, TextureHelper.CalculateMipCount(RenderTargetSize, 1, 1), Format.Rgba8);
            depthStencil = Context.Create.Renderbuffer(RenderTargetSize, RenderTargetSize, Format.Depth24Stencil8);

            framebuffer = Context.Create.Framebuffer();
            framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, renderTarget, 0);
            framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil);

            var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 24 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[]
            {
                new Vertex(1f, -1f, 1f, 1f, 0f, 0f, 0f, 0f),
                new Vertex(1f, 1f, 1f, 1f, 0f, 0f, 1f, 0f),
                new Vertex(1f, 1f, -1f, 1f, 0f, 0f, 1f, 1f),
                new Vertex(1f, -1f, -1f, 1f, 0f, 0f, 0f, 1f),

                new Vertex(1f, 1f, 1f, 0f, 1f, 0f, 0f, 0f),
                new Vertex(-1f, 1f, 1f, 0f, 1f, 0f, 1f, 0f),
                new Vertex(-1f, 1f, -1f, 0f, 1f, 0f, 1f, 1f),
                new Vertex(1f, 1f, -1f, 0f, 1f, 0f, 0f, 1f),

                new Vertex(-1f, 1f, 1f, -1f, 0f, 0f, 0f, 0f),
                new Vertex(-1f, -1f, 1f, -1f, 0f, 0f, 1f, 0f),
                new Vertex(-1f, -1f, -1f, -1f, 0f, 0f, 1f, 1f),
                new Vertex(-1f, 1f, -1f, -1f, 0f, 0f, 0f, 1f),

                new Vertex(-1f, -1f, 1f, 0f, -1f, 0f, 0f, 0f),
                new Vertex(1f, -1f, 1f, 0f, -1f, 0f, 1f, 0f),
                new Vertex(1f, -1f, -1f, 0f, -1f, 0f, 1f, 1f),
                new Vertex(-1f, -1f, -1f, 0f, -1f, 0f, 0f, 1f),

                new Vertex(-1f, -1f, 1f, 0f, 0f, 1f, 0f, 0f),
                new Vertex(-1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f),
                new Vertex(1f, 1f, 1f, 0f, 0f, 1f, 1f, 1f),
                new Vertex(1f, -1f, 1f, 0f, 0f, 1f, 0f, 1f),

                new Vertex(-1f, 1f, -1f, 0f, 0f, -1f, 0f, 0f),
                new Vertex(-1f, -1f, -1f, 0f, 0f, -1f, 1f, 0f),
                new Vertex(1f, -1f, -1f, 0f, 0f, -1f, 1f, 1f),
                new Vertex(1f, 1f, -1f, 0f, 0f, -1f, 0f, 1f)
            });

            var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 36 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[]
            {
                0, 1, 2, 0, 2, 3,
                4, 5, 6, 4, 6, 7,
                8, 9, 10, 8, 10, 11,
                12, 13, 14, 12, 14, 15,
                16, 17, 18, 16, 18, 19,
                20, 21, 22, 20, 22, 23
            });

            vertexArray = Context.Create.VertexArray();
            vertexArray.SetElementArrayBuffer(indexBuffer);
            vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 0);
            vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 12);
            vertexArray.SetVertexAttributeF(2, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 32, 24);

            transformBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
            cameraBuffer    = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
#if INTEL_WORKAROUND
            cameraOutsideBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw);
#endif
            cameraExtraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw);
            lightBuffer       = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw);

            using (var textureLoader = new TextureLoader("../Textures/DiffuseTest.png"))
            {
                diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Rgba8);
                for (int i = 0; i < diffuseMap.MipCount; i++)
                {
                    diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte);
                }
            }

            sampler = Context.Create.Sampler();
            sampler.SetMagFilter(TextureMagFilter.Linear);
            sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear);
            sampler.SetMaxAnisotropy(16f);

            IVertexShader   vsh = Context.Create.VertexShader(VertexShaderText);
            IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText);
            program = Context.Create.Program(new ShaderProgramDescription
            {
                VertexShaders        = new[] { vsh },
                FragmentShaders      = new[] { fsh },
                VertexAttributeNames = new[] { "in_position", "in_normal", "in_tex_coord" },
                UniformBufferNames   = new[] { "Transform", "Camera", "Light" },
                SamplerNames         = new[] { "DiffuseMap" }
            });
        }
Ejemplo n.º 24
0
 public void Blit(IFramebuffer target, ClearBufferMask mask, OpenTK.Graphics.OpenGL.BlitFramebufferFilter filter)
 {
     throw new InvalidOperationException();
 }
Ejemplo n.º 25
0
 public void Blit(IFramebuffer target, ClearBufferMask mask, BlitFramebufferFilter filter)
 {
     // \todo
 }
Ejemplo n.º 26
0
 public void BlitFramebuffer(IFramebuffer src, IFramebuffer dst, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, ClearBufferMask mask, BlitFramebufferFilter filter)
 {
     context.Bindings.Framebuffers.Read.Set(src);
     context.Bindings.Framebuffers.Draw.Set(dst);
     context.GL.BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, (uint)mask, (int)filter);
 }