/// <summary>
        /// Creates a new sprite texture that references the entire area of the provided texture.
        /// </summary>
        /// <param name="texture">Texture to wrap by the sprite texture.</param>
        public SpriteTexture(Texture2D texture)
        {
            Vector2 offset = Vector2.Zero;
            Vector2 scale = Vector2.One;

            Internal_CreateInstance(this, texture, ref offset, ref scale);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new 2D render texture using existing textures as render destinations.
        /// </summary>
        /// <param name="colorSurface">Color texture to render color data to.</param>
        /// <param name="depthStencilSurface">Optional depth/stencil texture to render depth/stencil data to.</param>
        public RenderTexture2D(Texture2D colorSurface, Texture2D depthStencilSurface = null)
        {
            IntPtr[] colorSurfaceInstances = new IntPtr[1];
            colorSurfaceInstances[0] = colorSurface.GetCachedPtr();

            IntPtr depthStencilInstance = IntPtr.Zero;
            if (depthStencilSurface != null)
                depthStencilInstance = depthStencilSurface.GetCachedPtr();

            Internal_Create(this, colorSurfaceInstances, depthStencilInstance);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new 2D render texture using one or multiple color textures and a depth/stencil texture.
        /// </summary>
        /// <param name="colorSurfaces">Color texture(s) to render color data to. </param>
        /// <param name="depthStencilSurface">>Optional depth/stencil texture to render depth/stencil data to.</param>
        public RenderTexture2D(Texture2D[] colorSurfaces, Texture2D depthStencilSurface = null)
        {
            IntPtr[] colorSurfaceInstances = new IntPtr[colorSurfaces.Length];

            for(int i = 0; i < colorSurfaces.Length; i++)
                colorSurfaceInstances[i] = colorSurfaces[i] != null ? colorSurfaces[i].GetCachedPtr() : IntPtr.Zero;

            IntPtr depthStencilInstance = IntPtr.Zero;
            if (depthStencilSurface != null)
                depthStencilInstance = depthStencilSurface.GetCachedPtr();

            Internal_Create(this, colorSurfaceInstances, depthStencilInstance);
        }
        /// <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;
        }
            /// <summary>
            /// Creates a new horizontal slider.
            /// </summary>
            /// <param name="guiTexture">GUI element to display the slider color range on.</param>
            /// <param name="guiSlider">Slider rendered on top of the texture that may be moved by the user to select a 
            ///                         color.</param>
            /// <param name="width">Width of the slider in pixels.</param>
            /// <param name="height">Height of the slider in pixels.</param>
            public ColorSlider1DHorz(GUITexture guiTexture, GUISliderH guiSlider, int width, int height)
            {
                this.width = width;
                this.height = height;
                this.guiTexture = guiTexture;
                this.guiSlider = guiSlider;

                texture = new Texture2D(width, height);
                spriteTexture = new SpriteTexture(texture);
            }
            /// <summary>
            /// Creates a new color box.
            /// </summary>
            /// <param name="guiTexture">GUI element to display the 2D color range on.</param>
            /// <param name="guiSliderHandle">Texture to be used for displaying the position of the currently selected 
            ///                               color.</param>
            /// <param name="width">Width of the slider in pixels.</param>
            /// <param name="height">Height of the slider in pixels.</param>
            public ColorSlider2D(GUITexture guiTexture, GUITexture guiSliderHandle, int width, int height)
            {
                this.width = width;
                this.height = height;

                this.guiTexture = guiTexture;
                this.guiSliderHandle = guiSliderHandle;

                texture = new Texture2D(width, height);
                spriteTexture = new SpriteTexture(texture);
            }
Beispiel #7
0
 private static extern void Internal_CreateInstance(Texture2D instance, PixelFormat format, int width, 
     int height, TextureUsage usage, int numSamples, bool hasMipmaps, bool gammaCorrection);
Beispiel #8
0
 private static extern void Internal_GetDepthStencilSurface(IntPtr thisPtr, out Texture2D surface);
Beispiel #9
0
 private static extern void Internal_GetColorSurfaces(IntPtr thisPtr, out Texture2D[] surfaces);
Beispiel #10
0
        /// <summary>
        /// Assigns a 2D texture to the shader parameter with the specified name.
        /// </summary>
        /// <param name="name">Name of the shader parameter.</param>
        /// <param name="value">Value of the parameter.</param>
        public void SetTexture2D(string name, Texture2D value)
        {
            IntPtr texturePtr = IntPtr.Zero;
            if (value != null)
                texturePtr = value.GetCachedPtr();

            Internal_SetTexture2D(mCachedPtr, name, texturePtr);
        }
 /// <summary>
 /// Creates a new sprite texture that references a sub-area of the provided texture.
 /// </summary>
 /// <param name="texture">Texture to wrap by the sprite texture.</param>
 /// <param name="uvOffset">Top-left position of the area used by the sprite texture, in normalized coordinates.
 ///                        </param>
 /// <param name="uvScale">Size of the area used by the sprite texture, in normalized coordinates.</param>
 public SpriteTexture(Texture2D texture, Vector2 uvOffset, Vector2 uvScale)
 {
     Internal_CreateInstance(this, texture, ref uvOffset, ref uvScale);
 }
 private static extern void Internal_CreateInstance(SpriteTexture instance, 
     Texture2D texture, ref Vector2 offset, ref Vector2 scale);