コード例 #1
0
        private static void Bake()
        {
            var renderTexture = new Texture(2048, 2048, filterMin: TextureMinFilter.Linear);
            var renderTarget = new RenderTarget(AAQuality.Off, new[] {new ContentRef<Texture>(renderTexture)});
            var scenes = ContentProvider.GetAvailableContent(typeof (Scene))
                .Where(s => Path.GetDirectoryName(s.Path) == "Data\\Scenes")
                .Select(s => (Scene) s.Res);

            foreach (var scene in scenes)
            {
                TileSystemSceneCruncher.CrunchScene(scene, renderTarget, renderTexture);
            }

            renderTexture.Dispose();
            renderTarget.Dispose();
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: swtrse/duality
		private void SetupPickingRT()
		{
			Vector2 refSize = DualityApp.TargetResolution;
			if (this.pickingTex == null || 
				this.pickingTex.PixelWidth != MathF.RoundToInt(refSize.X) || 
				this.pickingTex.PixelHeight != MathF.RoundToInt(refSize.Y))
			{
				if (this.pickingTex != null) this.pickingTex.Dispose();
				if (this.pickingRT != null) this.pickingRT.Dispose();
				this.pickingTex = new Texture(
					MathF.RoundToInt(refSize.X), MathF.RoundToInt(refSize.Y), Texture.SizeMode.Default, 
					TextureMagFilter.Nearest, TextureMinFilter.Nearest);
				this.pickingRT = new RenderTarget(AAQuality.Off, this.pickingTex);
			}
		}
コード例 #3
0
ファイル: Camera.cs プロジェクト: priyanshus1/duality
 private void SetupPickingRT(Point2 size)
 {
     if (this.pickingTex == null ||
         this.pickingTex.PixelWidth != size.X ||
         this.pickingTex.PixelHeight != size.Y)
     {
         if (this.pickingTex != null) this.pickingTex.Dispose();
         if (this.pickingRT != null) this.pickingRT.Dispose();
         this.pickingTex = new Texture(
             size.X, size.Y, TextureSizeMode.Default,
             TextureMagFilter.Nearest, TextureMinFilter.Nearest);
         this.pickingRT = new RenderTarget(AAQuality.Off, this.pickingTex);
     }
 }
コード例 #4
0
ファイル: CanvasTest.cs プロジェクト: KSLcom/duality
		private Pixmap.Layer RenderToTexture(int width, int height, Action<Canvas> renderMethod)
		{
			Pixmap.Layer pixelData;

			using (Texture texture = new Texture(width, height, Texture.SizeMode.NonPowerOfTwo))
			using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
			using (DrawDevice device = new DrawDevice())
			{
				device.Perspective = PerspectiveMode.Flat;
				device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
				device.RenderMode = RenderMatrix.OrthoScreen;
				device.Target = renderTarget;
				device.ViewportRect = new Rect(renderTarget.Width, renderTarget.Height);

				device.BeginRendering(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);
				{
					Canvas canvas = new Canvas(device);
					renderMethod(canvas);
				}
				device.EndRendering();
				
				RenderTarget.Bind(RenderTarget.None);

				pixelData = texture.RetrievePixelData();
			}

			return pixelData;
		}
コード例 #5
0
		/// <summary>
		/// Binds a RenderTarget in order to use it.
		/// </summary>
		/// <param name="target">The RenderTarget to be bound.</param>
		public static void Bind(ContentRef<RenderTarget> target)
		{
			RenderTarget nextBound = target.IsExplicitNull ? null : target.Res;
			if (curBound == nextBound) return;

			if (curBound != null && nextBound != curBound)
			{
				// Blit multisampled fbo
				if (curBound.Samples > 0)
				{
					GL.Ext.BindFramebuffer(FramebufferTarget.ReadFramebuffer, curBound.glFboIdMSAA);
					GL.Ext.BindFramebuffer(FramebufferTarget.DrawFramebuffer, curBound.glFboId);
					for (int i = 0; i < curBound.targetInfo.Count; i++)
					{
						GL.ReadBuffer((ReadBufferMode)((int)ReadBufferMode.ColorAttachment0 + i));
						GL.DrawBuffer((DrawBufferMode)((int)DrawBufferMode.ColorAttachment0 + i));
						GL.Ext.BlitFramebuffer(
							0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
							0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
							ClearBufferMask.ColorBufferBit, (ExtFramebufferBlit)(int)BlitFramebufferFilter.Nearest);
					}
					GL.ReadBuffer(ReadBufferMode.Back);
					GL.DrawBuffer(DrawBufferMode.Back);
					GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
				}

				// Generate Mipmaps for last bound
				for (int i = 0; i < curBound.targetInfo.Count; i++)
				{
					if (curBound.targetInfo[i].target.Res.HasMipmaps)
					{
						GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

						int lastTexId;
						GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);

						if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId) 
							GL.BindTexture(TextureTarget.Texture2D, curBound.targetInfo[i].target.Res.OglTexId);

						GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D);

						if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId) 
							GL.BindTexture(TextureTarget.Texture2D, lastTexId);
					}
				}
			}

			// Bind new RenderTarget
			if (nextBound == null)
			{
				curBound = null;
				GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
				GL.DrawBuffer(DrawBufferMode.Back);
			}
			else
			{
				curBound = target.Res;
				GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, curBound.Samples > 0 ? curBound.glFboIdMSAA : curBound.glFboId);
				DrawBuffersEnum[] buffers = new DrawBuffersEnum[curBound.targetInfo.Count];
				for (int i = 0; i < buffers.Length; i++)
				{
					buffers[i] = (DrawBuffersEnum)((int)DrawBuffersEnum.ColorAttachment0 + i);
				}
				GL.DrawBuffers(curBound.targetInfo.Count, buffers);
			}
		}
コード例 #6
0
ファイル: RenderTarget.cs プロジェクト: undue/duality
        /// <summary>
        /// Binds a RenderTarget in order to use it.
        /// </summary>
        /// <param name="target">The RenderTarget to be bound.</param>
        public static void Bind(ContentRef <RenderTarget> target)
        {
            RenderTarget nextBound = target.IsExplicitNull ? null : target.Res;

            if (curBound == nextBound)
            {
                return;
            }

            if (curBound != null && nextBound != curBound)
            {
                // Blit multisampled fbo
                if (curBound.Samples > 0)
                {
                    GL.Ext.BindFramebuffer(FramebufferTarget.ReadFramebuffer, curBound.glFboIdMSAA);
                    GL.Ext.BindFramebuffer(FramebufferTarget.DrawFramebuffer, curBound.glFboId);
                    for (int i = 0; i < curBound.targetInfo.Count; i++)
                    {
                        GL.ReadBuffer((ReadBufferMode)((int)ReadBufferMode.ColorAttachment0 + i));
                        GL.DrawBuffer((DrawBufferMode)((int)DrawBufferMode.ColorAttachment0 + i));
                        GL.Ext.BlitFramebuffer(
                            0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
                            0, 0, curBound.targetInfo[i].target.Res.TexelWidth, curBound.targetInfo[i].target.Res.TexelHeight,
                            ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
                    }
                    GL.ReadBuffer(ReadBufferMode.Back);
                    GL.DrawBuffer(DrawBufferMode.Back);
                    GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                }

                // Generate Mipmaps for last bound
                for (int i = 0; i < curBound.targetInfo.Count; i++)
                {
                    if (curBound.targetInfo[i].target.Res.HasMipmaps)
                    {
                        GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

                        int lastTexId;
                        GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);

                        if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId)
                        {
                            GL.BindTexture(TextureTarget.Texture2D, curBound.targetInfo[i].target.Res.OglTexId);
                        }

                        GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D);

                        if (lastTexId != curBound.targetInfo[i].target.Res.OglTexId)
                        {
                            GL.BindTexture(TextureTarget.Texture2D, lastTexId);
                        }
                    }
                }
            }

            // Bind new RenderTarget
            if (nextBound == null)
            {
                curBound = null;
                GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                GL.DrawBuffer(DrawBufferMode.Back);
            }
            else
            {
                curBound = target.Res;
                GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, curBound.Samples > 0 ? curBound.glFboIdMSAA : curBound.glFboId);
                DrawBuffersEnum[] buffers = new DrawBuffersEnum[curBound.targetInfo.Count];
                for (int i = 0; i < buffers.Length; i++)
                {
                    buffers[i] = (DrawBuffersEnum)((int)DrawBuffersEnum.ColorAttachment0 + i);
                }
                GL.DrawBuffers(curBound.targetInfo.Count, buffers);
            }
        }
コード例 #7
0
ファイル: PickingRenderSetup.cs プロジェクト: fossabot/jazz2
        protected override void OnRenderPointOfView(Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize)
        {
            // Set up the picking render target to match the proper size
            if (this.pickingTex == null)
            {
                this.pickingTex = new Texture(
                    (int)viewportRect.W,
                    (int)viewportRect.H,
                    TextureSizeMode.Default,
                    TextureMagFilter.Nearest,
                    TextureMinFilter.Nearest);
            }
            if (this.pickingRT == null)
            {
                this.pickingRT = new RenderTarget(
                    AAQuality.Off,
                    true,
                    this.pickingTex);
                this.pickingRT.DepthBuffer = true;
            }
            this.ResizeRenderTarget(this.pickingRT, (Point2)viewportRect.Size);

            ContentRef <RenderTarget> oldDeviceTarget = drawDevice.Target;
            VisibilityFlag            oldDeviceMask   = drawDevice.VisibilityMask;

            drawDevice.PickingIndex = 1;
            drawDevice.ClearColor   = ColorRgba.Black;
            drawDevice.ClearDepth   = 1.0f;
            drawDevice.Target       = this.pickingRT;
            drawDevice.TargetSize   = imageSize;
            drawDevice.ViewportRect = new Rect(this.pickingRT.Size);

            if (this.pickingMap == null)
            {
                this.pickingMap = new List <ICmpRenderer>();
            }
            this.pickingMap.Clear();

            // Render the world
            {
                drawDevice.VisibilityMask = oldDeviceMask & VisibilityFlag.AllGroups;
                drawDevice.Projection     = ProjectionMode.Orthographic;
                drawDevice.ClearFlags     = ClearFlag.All;

                drawDevice.PrepareForDrawcalls();
                this.CollectRendererDrawcalls(scene, drawDevice);
                drawDevice.Render();
            }

            // Render screen overlays
            if (this.renderOverlay)
            {
                drawDevice.VisibilityMask = oldDeviceMask;
                drawDevice.Projection     = ProjectionMode.Screen;
                drawDevice.ClearFlags     = ClearFlag.None;

                drawDevice.PrepareForDrawcalls();
                this.CollectRendererDrawcalls(scene, drawDevice);
                drawDevice.Render();
            }

            drawDevice.PickingIndex   = 0;
            drawDevice.VisibilityMask = oldDeviceMask;
            drawDevice.Target         = oldDeviceTarget;

            // Move data to local buffer
            int pxNum     = this.pickingTex.ContentWidth * this.pickingTex.ContentHeight;
            int pxByteNum = pxNum * 4;

            if (this.pickingBuffer == null)
            {
                this.pickingBuffer = new byte[pxByteNum];
            }
            else if (pxByteNum > this.pickingBuffer.Length)
            {
                Array.Resize(ref this.pickingBuffer, Math.Max(this.pickingBuffer.Length * 2, pxByteNum));
            }

            this.pickingRT.GetPixelData(this.pickingBuffer);
        }