예제 #1
0
        internal override Bitmap toBitmap()
        {
            if (!HasData)
            {
                return(new Bitmap(1, 1));
            }
            switch (GraphFormat)
            {
            case GraphicsFormat.FORMAT_1BPP: return(paint1BPP());

            case GraphicsFormat.FORMAT_2BPP: return(paint2BPP());

            case GraphicsFormat.FORMAT_4BPP: return(paint4BPP());

            case GraphicsFormat.FORMAT_8BPP: return(paint8BPP());

            case GraphicsFormat.FORMAT_16BPP: return(paint16Bpp());

            case GraphicsFormat.FORMAT_24BPP: return(paint24Bpp());

            case GraphicsFormat.FORMAT_32BPP: return(paint32Bpp());

            default: throw new Exception("Unknown error; invalid Graphics Format " + graphFormat.ToString());
            }
        }
예제 #2
0
        //     interface ISerializer
        //     {
        //         void SerializeBytes(NativeArray<byte> data);
        //         NativeArray<byte> DeserializeBytes();
        //     }

        public void OnBeforeSerialize()
        {
            if (state == State._Valid)
            {
                format = graphicsFormat.ToString("g");
                data   = SerializeBytes();
            }
        }
        void GraphicsFormatToFormatAndChannelTransformString(GraphicsFormat graphicsFormat, out string format, out string channelTransform)
        {
            string formatString   = graphicsFormat.ToString();
            int    lastUnderscore = formatString.LastIndexOf('_');

            if (lastUnderscore < 0)
            {
                format           = "None";
                channelTransform = "None";
                return;
            }
            format           = formatString.Substring(0, lastUnderscore);
            channelTransform = formatString.Substring(lastUnderscore + 1);
        }
예제 #4
0
        protected void OnRenderTextureGUI(GUIElements guiElements)
        {
            GUI.changed = false;

            EditorGUILayout.IntPopup(m_Dimension, styles.dimensionStrings, styles.dimensionValues, styles.dimension);

            // Note that TextureInspector.IsTexture3D/Cube/2DArray/etc. exist. Those functions will use the actual target object to determine the dimension.
            // This because they are drawing preview settings based on the selected target objects.
            // Here we are drawing the one and only Render Texture GUI so we have the dimension field as most correct value.
            bool isTexture3D      = (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex3D);
            bool isTexture2DArray = (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex2DArray);

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(styles.size, EditorStyles.popup);
            EditorGUILayout.DelayedIntField(m_Width, GUIContent.none, GUILayout.MinWidth(40));
            GUILayout.Label(styles.cross);
            EditorGUILayout.DelayedIntField(m_Height, GUIContent.none, GUILayout.MinWidth(40));
            if (isTexture3D || isTexture2DArray)
            {
                GUILayout.Label(styles.cross);
                EditorGUILayout.DelayedIntField(m_Depth, GUIContent.none, GUILayout.MinWidth(40));
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if ((guiElements & GUIElements.RenderTargetAAGUI) != 0)
            {
                EditorGUILayout.IntPopup(m_AntiAliasing, styles.renderTextureAntiAliasing, styles.renderTextureAntiAliasingValues, styles.antiAliasing);
            }

            GraphicsFormat colorFormat           = (GraphicsFormat)m_ColorFormat.intValue;
            GraphicsFormat compatibleColorFormat = SystemInfo.GetCompatibleFormat(colorFormat, FormatUsage.Render);

            GraphicsFormat depthStencilFormat               = (GraphicsFormat)m_DepthStencilFormat.intValue;
            bool           isDepthStencilUnused             = depthStencilFormat == GraphicsFormat.None;
            bool           isDepthStencilFormatIncompatible = !isDepthStencilUnused && SystemInfo.GetCompatibleFormat(depthStencilFormat, FormatUsage.Render) == GraphicsFormat.None;
            GraphicsFormat compatibleDepthStencilFormat     = (isDepthStencilUnused) ? GraphicsFormat.None :
                                                              GraphicsFormatUtility.GetDepthStencilFormat(GraphicsFormatUtility.GetDepthBits(depthStencilFormat), (GraphicsFormatUtility.IsStencilFormat(depthStencilFormat)) ? 8 : 0);

            // If no fallbacks are found for the color AND depth stencil buffer, disable the EnableCompatibleFormat field
            // If only one of the two fails, checkbox can still be interacted with
            if (!(compatibleColorFormat == GraphicsFormat.None && compatibleDepthStencilFormat == GraphicsFormat.None))
            {
                EditorGUILayout.PropertyField(m_EnableCompatibleFormat, styles.enableCompatibleFormat);
            }

            EditorGUILayout.PropertyField(m_ColorFormat, styles.colorFormat);
            m_sRGB.boolValue = GraphicsFormatUtility.IsSRGBFormat((GraphicsFormat)m_ColorFormat.intValue);

            if (compatibleColorFormat != colorFormat)
            {
                string text = string.Format("Format {0} is not supported on this platform. ", colorFormat.ToString());
                if (compatibleColorFormat != GraphicsFormat.None)
                {
                    if (m_EnableCompatibleFormat.boolValue)
                    {
                        text += string.Format("Using {0} as a compatible format.", compatibleColorFormat.ToString());
                    }
                    else
                    {
                        text += string.Format("You may enable Compatible Format to fallback automatically to a platform specific compatible format, {0} on this device.", compatibleColorFormat.ToString());
                    }
                }
                EditorGUILayout.HelpBox(text, m_EnableCompatibleFormat.boolValue && compatibleColorFormat != GraphicsFormat.None ? MessageType.Warning : MessageType.Error);
            }

            // 3D Textures with a depth buffer aren't supported.
            if (!isTexture3D)
            {
                if ((guiElements & GUIElements.RenderTargetDepthGUI) != 0)
                {
                    EditorGUILayout.PropertyField(m_DepthStencilFormat, styles.depthStencilFormat);
                }

                if (depthStencilFormat != compatibleDepthStencilFormat)
                {
                    string text = string.Format("Format {0} is not supported on this platform. ", depthStencilFormat.ToString());
                    if (compatibleDepthStencilFormat != GraphicsFormat.None)
                    {
                        if (m_EnableCompatibleFormat.boolValue)
                        {
                            text += string.Format("Using {0} as a compatible format.", compatibleDepthStencilFormat.ToString());
                        }
                        else
                        {
                            text += string.Format("You may enable Compatible Format to fallback automatically to a platform specific compatible format, {0} on this device.", compatibleDepthStencilFormat.ToString());
                        }
                    }
                    EditorGUILayout.HelpBox(text, m_EnableCompatibleFormat.boolValue && compatibleDepthStencilFormat != GraphicsFormat.None ? MessageType.Warning : MessageType.Error);
                }

                if ((GraphicsFormat)m_DepthStencilFormat.intValue == GraphicsFormat.None && (GraphicsFormat)m_ColorFormat.intValue == GraphicsFormat.None)
                {
                    EditorGUILayout.HelpBox("You cannot set both color format and depth format to None", MessageType.Error);
                }
            }

            // Mip map generation is not supported yet for 3D textures (and for depth only textures).
            if (!(isTexture3D || RenderTextureIsDepthOnly()))
            {
                EditorGUILayout.PropertyField(m_EnableMipmaps, styles.enableMipmaps);
                if (m_EnableMipmaps.boolValue)
                {
                    ++EditorGUI.indentLevel;
                    EditorGUILayout.PropertyField(m_AutoGeneratesMipmaps, styles.autoGeneratesMipmaps);
                    --EditorGUI.indentLevel;
                }
            }
            else
            {
                if (isTexture3D)
                {
                    // Mip map generation is not supported yet for 3D textures.
                    EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info);
                }

                if (RenderTextureIsDepthOnly())
                {
                    // Mip map generation is not supported yet for depth-only textures.
                    EditorGUILayout.HelpBox("Depth-only RenderTextures do not support Mip Maps.", MessageType.Info);
                }
            }

            EditorGUILayout.PropertyField(m_UseDynamicScale, styles.useDynamicScale);

            var rt = target as RenderTexture;

            if (GUI.changed && rt != null)
            {
                rt.Release();
                m_RepaintDelay = 5;
            }

            // Trigger delayed repaint to allow camera's to be rendered before thumbnail is generated.
            if (m_RepaintDelay > 0)
            {
                --m_RepaintDelay;
                if (m_RepaintDelay == 0)
                {
                    EditorUtility.SetDirty(target);
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            DoWrapModePopup();
            DoFilterModePopup();

            if (!RenderTextureHasDepth()) // Render Textures with depth are forced to 0 Aniso Level
            {
                DoAnisoLevelSlider();
            }
            else
            {
                EditorGUILayout.HelpBox("RenderTextures with depth are forced to have an Aniso Level of 0.", MessageType.Info);
            }

            if (RenderTextureHasDepth()) // Depth-only textures have shadow mode
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_ShadowSamplingMode, styles.shadowSamplingMode);
                // Shadow mode unlike the other filter settings requires re-creating the rt if it changed
                // as it's an actual creation flag on the texture.
                if (EditorGUI.EndChangeCheck() && rt != null)
                {
                    rt.Release();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Only render textures with depth can have shadow filtering.", MessageType.Info);
            }

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                ApplySettingsToTextures();
            }
        }
예제 #5
0
 internal bool ValidateFormat(GraphicsFormat format, FormatUsage usage)
 {
     if (SystemInfo.IsFormatSupported(format, usage))
     {
         return(true);
     }
     else
     {
         Debug.LogError(String.Format("Texture creation failed. '{0}' is not supported for {1} usage on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", format.ToString(), usage.ToString()), this);
         return(false);
     }
 }
예제 #6
0
 /// <summary>
 /// Returns the color space of the specified graphics format.
 /// </summary>
 /// <param name="format">The graphics format to probe.</param>
 /// <returns></returns>
 internal static ImageRecorderSettings.ColorSpaceType GetColorSpaceType(GraphicsFormat format)
 {
     // All sRGB formats end with "_SRGB"?
     return(format.ToString().EndsWith("_SRGB") ? ImageRecorderSettings.ColorSpaceType.sRGB_sRGB : ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB);
 }
        protected void OnRenderTextureGUI(GUIElements guiElements)
        {
            GUI.changed = false;

            bool isTexture3D = (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex3D);

            EditorGUILayout.IntPopup(m_Dimension, styles.dimensionStrings, styles.dimensionValues, styles.dimension);

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(styles.size, EditorStyles.popup);
            EditorGUILayout.DelayedIntField(m_Width, GUIContent.none, GUILayout.MinWidth(40));
            GUILayout.Label(styles.cross);
            EditorGUILayout.DelayedIntField(m_Height, GUIContent.none, GUILayout.MinWidth(40));
            if (isTexture3D)
            {
                GUILayout.Label(styles.cross);
                EditorGUILayout.DelayedIntField(m_Depth, GUIContent.none, GUILayout.MinWidth(40));
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if ((guiElements & GUIElements.RenderTargetAAGUI) != 0)
            {
                EditorGUILayout.IntPopup(m_AntiAliasing, styles.renderTextureAntiAliasing, styles.renderTextureAntiAliasingValues, styles.antiAliasing);
            }

            GraphicsFormat format           = (GraphicsFormat)m_ColorFormat.intValue;
            GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(format, FormatUsage.Render);

            using (new EditorGUI.DisabledScope(compatibleFormat == GraphicsFormat.None))
                EditorGUILayout.PropertyField(m_EnableCompatibleFormat, styles.enableCompatibleFormat);

            EditorGUILayout.PropertyField(m_ColorFormat, styles.colorFormat);

            if (compatibleFormat != format)
            {
                string text = string.Format("Format {0} is not supported on this platform. ", format.ToString());
                if (compatibleFormat != GraphicsFormat.None)
                {
                    if (m_EnableCompatibleFormat.boolValue)
                    {
                        text += string.Format("Using {0} as a compatible format.", compatibleFormat.ToString());
                    }
                    else
                    {
                        text += string.Format("You may enable Compatible Color Format to fallback automatically to a platform specific comptible format, {0} on this device.", compatibleFormat.ToString());
                    }
                }
                EditorGUILayout.HelpBox(text, m_EnableCompatibleFormat.boolValue && compatibleFormat != GraphicsFormat.None ? MessageType.Warning : MessageType.Error);
            }

            if ((guiElements & GUIElements.RenderTargetDepthGUI) != 0)
            {
                EditorGUILayout.PropertyField(m_DepthFormat, styles.depthBuffer);
            }

            m_sRGB.boolValue = GraphicsFormatUtility.IsSRGBFormat(format);

            using (new EditorGUI.DisabledScope(isTexture3D))
            {
                EditorGUILayout.PropertyField(m_EnableMipmaps, styles.enableMipmaps);
                using (new EditorGUI.DisabledScope(!m_EnableMipmaps.boolValue))
                    EditorGUILayout.PropertyField(m_AutoGeneratesMipmaps, styles.autoGeneratesMipmaps);
            }

            if (isTexture3D)
            {
                // Mip map generation is not supported yet for 3D textures.
                EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info);
            }

            EditorGUILayout.PropertyField(m_UseDynamicScale, styles.useDynamicScale);

            var rt = target as RenderTexture;

            if (GUI.changed && rt != null)
            {
                rt.Release();
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            DoWrapModePopup();
            DoFilterModePopup();

            using (new EditorGUI.DisabledScope(RenderTextureHasDepth())) // Render Textures with depth are forced to 0 Aniso Level
            {
                DoAnisoLevelSlider();
            }
            if (RenderTextureHasDepth())
            {
                // RenderTextures don't enforce this nicely. RenderTexture only forces Aniso to 0 if the gfx card
                // supports depth, rather than forcing Aniso to zero depending on what the user asks of the RT. If the
                // user requests any kind of depth then we will force aniso to zero here.
                m_Aniso.intValue = 0;
                EditorGUILayout.HelpBox("RenderTextures with depth must have an Aniso Level of 0.", MessageType.Info);
            }

            if (EditorGUI.EndChangeCheck())
            {
                ApplySettingsToTextures();
            }
        }
예제 #8
0
        internal bool ValidateFormat(GraphicsFormat format, FormatUsage usage)
        {
            bool flag = SystemInfo.IsFormatSupported(format, usage);
            bool result;

            if (flag)
            {
                result = true;
            }
            else
            {
                Debug.LogError(string.Format("Texture creation failed. '{0}' is not supported for {1} usage on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", format.ToString(), usage.ToString()), this);
                result = false;
            }
            return(result);
        }
예제 #9
0
        internal static GraphicsFormat GetCompatibleFormat(RenderTextureFormat renderTextureFormat, RenderTextureReadWrite readWrite)
        {
            GraphicsFormat graphicsFormat   = GraphicsFormatUtility.GetGraphicsFormat(renderTextureFormat, readWrite);
            GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
            bool           flag             = graphicsFormat == compatibleFormat;
            GraphicsFormat result;

            if (flag)
            {
                result = graphicsFormat;
            }
            else
            {
                Debug.LogWarning(string.Format("'{0}' is not supported. RenderTexture::GetTemporary fallbacks to {1} format on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", graphicsFormat.ToString(), compatibleFormat.ToString()));
                result = compatibleFormat;
            }
            return(result);
        }