Ejemplo n.º 1
0
        public unsafe void Decode(IContext context, ManualMipChain target, ManualMipChain temporalDiff, ManualMipChain previous, int mostDetailedMip)
        {
            var pipeline = context.Pipeline;
            fullTextureProcessor.PrepareContext(context);
            pipeline.Viewports[0].Set(target.Width, target.Height);
            framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, target[0], 0);
            pipeline.Framebuffer = framebuffer;

            Vector4 mipInfoData;
            var mipInfoPtr = (int*)&mipInfoData;
            mipInfoPtr[0] = mostDetailedMip;
            mipInfoPtr[1] = 1 << mostDetailedMip;
            mipInfoBuffer.SetDataByMapping(pclWorkarounds, (IntPtr)mipInfoPtr);

            pipeline.UniformBuffers[0] = mipInfoBuffer;
            pipeline.Textures[0] = temporalDiff[mostDetailedMip];
            pipeline.Samplers[0] = sampler;
            pipeline.Textures[1] = previous[0];
            pipeline.Samplers[1] = sampler;
            pipeline.Textures[2] = previous[mostDetailedMip];
            pipeline.Samplers[2] = sampler;

            context.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);
            framebuffer.DetachColorStartingFrom(0);
        }
Ejemplo n.º 2
0
        public unsafe void Draw(IContext context, IRavcGameWindow gameWindow, ITexture2D frameTexture, int x, int y)
        {
            var pipeline = context.Pipeline;

            pipeline.Program = program;
            pipeline.VertexArray = vertexArray;

            var windowAspectRatio = (float)gameWindow.ClientWidth / Math.Max(gameWindow.ClientHeight, 1);
            var textureAspectRatio = (float)frameTexture.Width / Math.Max(frameTexture.Height, 1);

            int adjustedTextureWidth = gameWindow.ClientWidth;
            int adjustedTextureHeight = gameWindow.ClientHeight;

            if (windowAspectRatio > textureAspectRatio)
                adjustedTextureWidth = (int)(gameWindow.ClientHeight * textureAspectRatio);
            if (windowAspectRatio < textureAspectRatio)
                adjustedTextureHeight = (int)(gameWindow.ClientWidth / textureAspectRatio);

            int aspectOffsetX = (gameWindow.ClientWidth - adjustedTextureWidth) / 2;
            int aspectOffsetY = (gameWindow.ClientHeight - adjustedTextureHeight) / 2;

            int adjustedSize = texture.Width * adjustedTextureWidth / frameTexture.Width;

            int viewportX = x * adjustedTextureWidth / frameTexture.Width + aspectOffsetX;
            int viewportY = gameWindow.ClientHeight - (y * adjustedTextureHeight / frameTexture.Height + aspectOffsetY) - adjustedSize;
            pipeline.Viewports[0].Set(viewportX, viewportY, adjustedSize, adjustedSize);
            pipeline.Rasterizer.SetDefault();
            pipeline.Rasterizer.MultisampleEnable = false;

            pipeline.Textures[0] = texture;
            pipeline.Samplers[0] = sampler;

            pipeline.DepthStencil.SetDefault();
            pipeline.DepthStencil.DepthMask = false;

            pipeline.Blend.SetDefault(false);
            pipeline.Blend.BlendEnable = true;
            pipeline.Blend.Targets[0].Color.SrcFactor = BlendFactor.SrcAlpha;
            pipeline.Blend.Targets[0].Color.DestFactor = BlendFactor.OneMinusSrcAlpha;
            pipeline.Blend.Targets[0].Alpha.SrcFactor = BlendFactor.SrcAlpha;
            pipeline.Blend.Targets[0].Alpha.SrcFactor = BlendFactor.OneMinusSrcAlpha;

            context.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);
        }
Ejemplo n.º 3
0
        public unsafe void Process(IContext context, ITexture2D target, ITexture2D texture0, ITexture2D texture1)
        {
            var pipeline = context.Pipeline;
            fullTextureProcessor.PrepareContext(context);
            pipeline.Framebuffer = framebuffer;
            pipeline.Samplers[0] = sampler;
            pipeline.Samplers[1] = sampler;
            pipeline.UniformBuffers[0] = mipInfoBuffer;
            pipeline.Viewports[0].Set(target.Width, target.Height);

            Vector4 mipInfoData;
            var mipInfoPtr = (int*)&mipInfoData;
            mipInfoPtr[0] = 0;
            mipInfoPtr[1] = 1;
            mipInfoBuffer.SetDataByMapping(pclWorkarounds, (IntPtr)mipInfoPtr);

            framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, target, 0);
            pipeline.Textures[0] = texture0;
            pipeline.Textures[1] = texture1;

            context.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);
            framebuffer.DetachColorStartingFrom(0);
        }
Ejemplo n.º 4
0
        public unsafe void GenerateMips(IContext context, ManualMipChain target)
        {
            var pipeline = context.Pipeline;
            fullTextureProcessor.PrepareContext(context);
            pipeline.Framebuffer = framebuffer;
            pipeline.Samplers[0] = sampler;
            pipeline.UniformBuffers[0] = mipInfoBuffer;

            for (int i = 1; i < EncodingConstants.MipLevels; i++)
            {
                pipeline.Viewports[0].Set(target.Width >> i, target.Height >> i);

                Vector4 mipInfoData;
                var mipInfoPtr = (int*)&mipInfoData;
                mipInfoPtr[0] = i;
                mipInfoBuffer.SetDataByMapping(pclWorkarounds, (IntPtr)mipInfoPtr);

                framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, target[i], 0);
                pipeline.Textures[0] = target[i - 1];

                context.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0);
                framebuffer.DetachColorStartingFrom(0);
            }
        }