예제 #1
0
        /// <summary>
        /// Creates a new render texture element.
        /// </summary>
        /// <param name="texture">Render texture to display in the element.</param>
        /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as 
        ///                     default layout options. Style will be retrieved from the active GUISkin. If not specified 
        ///                     default element style is used.</param>
        /// <param name="options">Options that allow you to control how is the element  positioned and sized. This will 
        ///                       override any similar options set by style.</param>
        public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
        {
            IntPtr texturePtr = IntPtr.Zero;
            if (texture != null)
                texturePtr = texture.GetCachedPtr();

            Internal_CreateInstance(this, texturePtr, false, style, options);
        }
예제 #2
0
        /// <summary>
        /// Creates a new render texture element.
        /// </summary>
        /// <param name="texture">Render texture to display in the element.</param>
        /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
        /// <param name="options">Options that allow you to control how is the element  positioned and sized. This will 
        ///                       override any similar options set by style.</param>
        public GUIRenderTexture(RenderTexture2D texture, bool transparent, params GUIOption[] options)
        {
            IntPtr texturePtr = IntPtr.Zero;
            if (texture != null)
                texturePtr = texture.GetCachedPtr();

            Internal_CreateInstance(this, texturePtr, transparent, "", options);
        }
예제 #3
0
        /// <summary>
        /// Creates a new render texture element.
        /// </summary>
        /// <param name="texture">Render texture to display in the element.</param>
        /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
        ///                     default layout options. Style will be retrieved from the active GUISkin. If not specified
        ///                     default element style is used.</param>
        /// <param name="options">Options that allow you to control how is the element  positioned and sized. This will
        ///                       override any similar options set by style.</param>
        public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
        {
            IntPtr texturePtr = IntPtr.Zero;

            if (texture != null)
            {
                texturePtr = texture.GetCachedPtr();
            }

            Internal_CreateInstance(this, texturePtr, false, style, options);
        }
예제 #4
0
        /// <summary>
        /// Creates a new render texture element.
        /// </summary>
        /// <param name="texture">Render texture to display in the element.</param>
        /// <param name="transparent">Determines should the texture be rendered with transparency active.</param>
        /// <param name="options">Options that allow you to control how is the element  positioned and sized. This will
        ///                       override any similar options set by style.</param>
        public GUIRenderTexture(RenderTexture2D texture, bool transparent, params GUIOption[] options)
        {
            IntPtr texturePtr = IntPtr.Zero;

            if (texture != null)
            {
                texturePtr = texture.GetCachedPtr();
            }

            Internal_CreateInstance(this, texturePtr, transparent, "", options);
        }
예제 #5
0
        /// <summary>
        /// Creates a new scene axes GUI.
        /// </summary>
        /// <param name="window">Window in which the GUI is located in.</param>
        /// <param name="panel">Panel onto which to place the GUI element.</param>
        /// <param name="width">Width of the GUI element.</param>
        /// <param name="height">Height of the GUI element.</param>
        /// <param name="projType">Projection type to display on the GUI.</param>
        public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType)
        {
            renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height);
            renderTexture.Priority = 1;

            SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);
            camera = cameraSO.AddComponent<Camera>();
            camera.Target = renderTexture;
            camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

            cameraSO.Position = new Vector3(0, 0, 5);
            cameraSO.LookAt(new Vector3(0, 0, 0));

            camera.Priority = 2;
            camera.NearClipPlane = 0.05f;
            camera.FarClipPlane = 1000.0f;
            camera.ClearColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
            camera.ProjectionType = ProjectionType.Orthographic;
            camera.Layers = SceneAxesHandle.LAYER;
            camera.AspectRatio = 1.0f;
            camera.OrthoHeight = 2.0f;
            camera.HDR = false;

            renderTextureGUI = new GUIRenderTexture(renderTexture, true);

            GUILayoutY layout = panel.AddLayoutY();
            GUILayoutX textureLayout = layout.AddLayoutX();
            textureLayout.AddElement(renderTextureGUI);
            textureLayout.AddFlexibleSpace();

            Rect2I bounds = new Rect2I(0, 0, width, height);
            sceneHandles = new SceneHandles(window, camera);
            renderTextureGUI.Bounds = bounds;

            labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered);
            layout.AddElement(labelGUI);
            layout.AddFlexibleSpace();

            this.panel = panel;
            this.bounds = bounds;
        }
예제 #6
0
        /// <summary>
        /// Creates the scene camera and updates the render texture. Should be called at least once before using the
        /// scene view. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            width = MathEx.Max(20, width);
            height = MathEx.Max(20, height);

            // Note: Depth buffer and readable flags are required because ScenePicking uses it
            Texture2D colorTex = new Texture2D(width, height, PixelFormat.R8G8B8A8, TextureUsage.Render | TextureUsage.CPUReadable);
            Texture2D depthTex = new Texture2D(width, height, PixelFormat.D32_S8X24, TextureUsage.DepthStencil | TextureUsage.CPUReadable);

            renderTexture = new RenderTexture2D(colorTex, depthTex);
            renderTexture.Priority = 1;

            if (camera == null)
            {
                SceneObject sceneCameraSO = new SceneObject("SceneCamera", true);
                camera = sceneCameraSO.AddComponent<Camera>();
                camera.Target = renderTexture;
                camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

                sceneCameraSO.Position = new Vector3(0, 0.5f, 1);
                sceneCameraSO.LookAt(new Vector3(0, 0.5f, 0));

                camera.Priority = 2;
                camera.NearClipPlane = 0.05f;
                camera.FarClipPlane = 2500.0f;
                camera.ClearColor = ClearColor;
                camera.Layers = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera

                cameraController = sceneCameraSO.AddComponent<SceneCamera>();

                renderTextureGUI = new GUIRenderTexture(renderTexture);
                rtPanel.AddElement(renderTextureGUI);

                sceneGrid = new SceneGrid(camera);
                sceneSelection = new SceneSelection(camera);
                sceneGizmos = new SceneGizmos(camera);
                sceneHandles = new SceneHandles(this, camera);
            }
            else
            {
                camera.Target = renderTexture;
                renderTextureGUI.RenderTexture = renderTexture;
            }

            Rect2I rtBounds = new Rect2I(0, 0, width, height);
            renderTextureGUI.Bounds = rtBounds;
            focusCatcher.Bounds = GUIUtility.CalculateBounds(rtPanel, GUI);

            sceneAxesGUI.SetPosition(width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY);

            // TODO - Consider only doing the resize once user stops resizing the widget in order to reduce constant
            // render target destroy/create cycle for every single pixel.

            camera.AspectRatio = width / (float)height;

            if (profilerCamera != null)
                profilerCamera.Target = renderTexture;
        }
예제 #7
0
 private static extern void Internal_Create(RenderTexture2D instance, IntPtr[] colorSurfaces, IntPtr depthStencilSurface);
예제 #8
0
 private static extern void Internal_CreateDetailed(RenderTexture2D instance, PixelFormat format,
                                                    int width, int height, int numSamples, bool gammaCorrection, bool createDepth, PixelFormat depthStencilFormat);
예제 #9
0
        /// <summary>
        /// Creates or rebuilds the main render texture. Should be called at least once before using the
        /// game window. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            height = height - HeaderHeight;

            int rtWidth = MathEx.Max(20, width);
            int rtHeight = MathEx.Max(20, height);

            if (selectedAspectRatio != 0) // 0 is free aspect
            {
                AspectRatio aspectRatio = aspectRatios[selectedAspectRatio - 1];

                int visibleAreaHeight = rtHeight;

                float aspectInv = aspectRatio.height/(float)aspectRatio.width;
                rtHeight = MathEx.RoundToInt(rtWidth*aspectInv);

                if (rtHeight > visibleAreaHeight)
                {
                    rtHeight = visibleAreaHeight;
                    float aspect = aspectRatio.width / (float)aspectRatio.height;
                    rtWidth = MathEx.RoundToInt(rtHeight * aspect);
                }
            }

            RenderTexture2D renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, rtWidth, rtHeight) { Priority = 1};

            EditorApplication.MainRenderTarget = renderTexture;
            renderTextureGUI.RenderTexture = renderTexture;

            int offsetX = (width - rtWidth)/2;
            int offsetY = (height - rtHeight)/2;

            Rect2I rtBounds = new Rect2I(offsetX, offsetY, rtWidth, rtHeight);
            renderTextureGUI.Bounds = rtBounds;

            Rect2I bgBounds = new Rect2I(0, 0, width, height);
            renderTextureBg.Bounds = bgBounds;
        }
예제 #10
0
 private static extern void Internal_CreateDetailed(RenderTexture2D instance, PixelFormat format, 
     int width, int height, int numSamples, bool gammaCorrection, bool createDepth, PixelFormat depthStencilFormat);
예제 #11
0
 private static extern void Internal_Create(RenderTexture2D instance, IntPtr[] colorSurfaces, IntPtr depthStencilSurface);