Exemple #1
0
 /// <summary>
 /// Make a new GraphicsData object. Use load(String) to load data.
 /// </summary>
 /// <param name="isTiled">If the data is tiled or not.</param>
 public GraphicsData(bool isTiled, PaletteData palData)
     : base()
 {
     tiled = isTiled;
     tileSize = new Point(8, 8);
     width = 64;
     height = 128;
     zoom = 1;
     this.paletteData = palData;
     isBigEndian = true;
     graphFormat = GraphicsFormat.FORMAT_4BPP;
 }
Exemple #2
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, 1, RenderTextureMemoryless.None, VRTextureUsage.None, false));
 }
    // Internal function
    RTHandle AllocAutoSizedRenderTexture(
        int width,
        int height,
        int slices,
        DepthBits depthBufferBits,
        GraphicsFormat colorFormat,
        FilterMode filterMode,
        TextureWrapMode wrapMode,
        TextureDimension dimension,
        bool enableRandomWrite,
        bool useMipMap,
        bool autoGenerateMips,
        bool isShadowMap,
        int anisoLevel,
        float mipMapBias,
        bool enableMSAA,
        bool bindTextureMS,
        bool useDynamicScale,
        RenderTextureMemoryless memoryless,
        string name
        )
    {
        // Here user made a mistake in setting up msaa/bindMS, hence the warning
        if (!enableMSAA && bindTextureMS == true)
        {
            Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
            bindTextureMS = false;
        }

        bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false;

        // Here we purposefully disable MSAA so we just force the bindMS param to false.
        if (!allocForMSAA)
        {
            bindTextureMS = false;
        }

        // MSAA Does not support random read/write.
        bool UAV = enableRandomWrite;

        if (allocForMSAA && (UAV == true))
        {
            Debug.LogWarning("RTHandle that is MSAA-enabled cannot allocate MSAA RT with 'enableRandomWrite = true'.");
            UAV = false;
        }

        int        msaaSamples = allocForMSAA ? (int)m_ScaledRTCurrentMSAASamples : 1;
        RTCategory category    = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular;

        // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
        RenderTexture rt;

        if (isShadowMap || depthBufferBits != DepthBits.None)
        {
            RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
            rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = UAV,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
            };
        }
        else
        {
            rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = UAV,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: allocForMSAA, msaaSamples: m_ScaledRTCurrentMSAASamples)
            };
        }

        rt.Create();

        var rth = new RTHandle(this);

        rth.SetRenderTexture(rt, category);
        rth.m_EnableMSAA           = enableMSAA;
        rth.m_EnableRandomWrite    = enableRandomWrite;
        rth.useScaling             = true;
        rth.m_EnableHWDynamicScale = useDynamicScale;
        rth.m_Name = name;
        m_AutoSizedRTs.Add(rth);
        return(rth);
    }
Exemple #4
0
        public static void CreateRenderTexture(ref RenderTexture texture, int width, int height, FilterMode filterMode, GraphicsFormat format)
        {
            if (texture == null || !texture.IsCreated() || texture.width != width || texture.height != height || texture.graphicsFormat != format)
            {
                if (texture != null)
                {
                    texture.Release();
                }
                texture = new RenderTexture(width, height, 0);
                texture.graphicsFormat    = format;
                texture.enableRandomWrite = true;

                texture.autoGenerateMips = false;
                texture.Create();
            }
            texture.wrapMode   = TextureWrapMode.Clamp;
            texture.filterMode = filterMode;
        }
Exemple #5
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, [UnityEngine.Internal.DefaultValue("1")] int antiAliasing, [UnityEngine.Internal.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode, [UnityEngine.Internal.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [UnityEngine.Internal.DefaultValue("false")] bool useDynamicScale)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale));
 }
Exemple #6
0
 private static void Internal_Create([Writable] CubemapArray mono, int ext, int count, int mipCount, GraphicsFormat format, TextureCreationFlags flags)
 {
     if (!Internal_CreateImpl(mono, ext, count, mipCount, format, flags))
     {
         throw new UnityException("Failed to create cubemap array texture because of invalid parameters.");
     }
 }
 /// <summary>
 /// Creates a new VideoStream object.
 /// The track is created with a source texture `ptr`.
 /// It is noted that streamed video might be flipped when not action was taken. Almost case it has no problem to use other constructor instead.
 ///
 /// See Also: Texture.GetNativeTexturePtr
 /// </summary>
 /// <param name="label"></param>
 /// <param name="texturePtr"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="format"></param>
 public VideoStreamTrack(string label, IntPtr texturePtr, int width, int height, GraphicsFormat format)
     : base(WebRTC.Context.CreateVideoTrack(label))
 {
     WebRTC.ValidateTextureSize(width, height, Application.platform);
     WebRTC.ValidateGraphicsFormat(format);
     WebRTC.Context.SetVideoEncoderParameter(GetSelfOrThrow(), width, height, format, texturePtr);
     WebRTC.Context.InitializeEncoder(GetSelfOrThrow());
     tracks.Add(this);
 }
 static private extern AsyncGPUReadbackRequest Request_Internal_Texture_4([NotNull] Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat);
 static private extern AsyncGPUReadbackRequest Request_Internal_Texture_6([NotNull] Texture src, int mipIndex, GraphicsFormat dstFormat, void *output, int allocationSize);
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     ValidateFormat(src, dstFormat);
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_Texture_7(src, mipIndex, x, width, y, height, z, depth, dstFormat, output.GetUnsafePtr(), output.Length * UnsafeUtility.SizeOf <T>());
         SetUpScriptingRequest(request, callback);
         return(request);
     }
 }
 static private extern AsyncGPUReadbackRequest Request_Internal_Texture_2([NotNull] Texture src, int mipIndex, GraphicsFormat dstFormat);
        static public AsyncGPUReadbackRequest Request(Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null)
        {
            ValidateFormat(src, dstFormat);
            AsyncGPUReadbackRequest request = Request_Internal_Texture_4(src, mipIndex, x, width, y, height, z, depth, dstFormat);

            SetUpScriptingRequest(request, callback);
            return(request);
        }
Exemple #13
0
 public override GraphicsFormat GetCompatibleFormat(GraphicsFormat format, FormatUsage usage)
 {
     return(base.GetCompatibleFormat(format, usage));
 }
Exemple #14
0
 public override bool IsFormatSupported(GraphicsFormat format, FormatUsage usage)
 {
     return(base.IsFormatSupported(format, usage));
 }
Exemple #15
0
        private static bool Internal_CreateImpl([Writable] /* 0x00000001800D4E50-0x00000001800D4E60 */ Cubemap mono, int ext, int mipCount, GraphicsFormat format, TextureCreationFlags flags, IntPtr nativeTex) => default; // 0x00000001809661D0-0x0000000180966230

        private static void Internal_Create([Writable] /* 0x00000001800D4E50-0x00000001800D4E60 */ Cubemap mono, int ext, int mipCount, GraphicsFormat format, TextureCreationFlags flags, IntPtr nativeTex)
        {
        }                                                                                                                                                                                                               // 0x0000000180966230-0x0000000180966300
 static private extern AsyncGPUReadbackRequest Request_Internal_Texture_7([NotNull] Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, void *output, int allocationSize);
Exemple #17
0
 extern private static bool Internal_CreateImpl([Writable] CubemapArray mono, int ext, int count, int mipCount, GraphicsFormat format, TextureCreationFlags flags);
Exemple #18
0
 public void SetVideoEncoderParameter(IntPtr track, int width, int height, GraphicsFormat format, IntPtr texturePtr)
 {
     NativeMethods.ContextSetVideoEncoderParameter(self, track, width, height, format, texturePtr);
 }
Exemple #19
0
 extern private static void Internal_Create([Writable] SparseTexture mono, int width, int height, GraphicsFormat format, int mipCount);
 public virtual bool IsFormatSupported(GraphicsFormat format, FormatUsage usage)
 {
     return(EditorSystemInfo.IsFormatSupported(format, usage));
 }
Exemple #21
0
 [TestCase((GraphicsFormat)88)] //LegacyARGB32_UNorm
 public void ValidateLegacyGraphicsFormat(GraphicsFormat format)
 {
     Assert.That(() => WebRTC.ValidateGraphicsFormat(format), Throws.Nothing);
 }
 public virtual GraphicsFormat GetCompatibleFormat(GraphicsFormat format, FormatUsage usage)
 {
     return(EditorSystemInfo.GetCompatibleFormat(format, usage));
 }
Exemple #23
0
 private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None, VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
 {
     return(RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, format, depthBuffer)
     {
         msaaSamples = antiAliasing,
         memoryless = memorylessMode,
         vrUsage = vrUsage,
         useDynamicScale = useDynamicScale
     }));
 }
Exemple #24
0
        public static RenderTexture NewUAV(int w, int h, int d = 0, RenderTextureFormat format = RenderTextureFormat.ARGBFloat, GraphicsFormat graphicsFormat = GraphicsFormat.R32G32B32A32_SFloat)
        {
            var rt = new RenderTexture(w, h, d, format);

            rt.graphicsFormat    = graphicsFormat;
            rt.enableRandomWrite = true;
            rt.Create();
            return(rt);
        }
Exemple #25
0
 public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
 {
     return(RenderTexture.GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, false));
 }
Exemple #26
0
 extern private static bool Internal_CreateImpl([Writable] Cubemap mono, int ext, int mipCount, GraphicsFormat format, TextureCreationFlags flags, IntPtr nativeTex);
    // This method wraps around regular RenderTexture creation.
    // There is no specific logic applied to RenderTextures created this way.
    public RTHandle Alloc(
        int width,
        int height,
        int slices = 1,
        DepthBits depthBufferBits          = DepthBits.None,
        GraphicsFormat colorFormat         = GraphicsFormat.R8G8B8A8_SRGB,
        FilterMode filterMode              = FilterMode.Point,
        TextureWrapMode wrapMode           = TextureWrapMode.Repeat,
        TextureDimension dimension         = TextureDimension.Tex2D,
        bool enableRandomWrite             = false,
        bool useMipMap                     = false,
        bool autoGenerateMips              = true,
        bool isShadowMap                   = false,
        int anisoLevel                     = 1,
        float mipMapBias                   = 0f,
        MSAASamples msaaSamples            = MSAASamples.None,
        bool bindTextureMS                 = false,
        bool useDynamicScale               = false,
        RenderTextureMemoryless memoryless = RenderTextureMemoryless.None,
        string name = ""
        )
    {
        bool enableMSAA = msaaSamples != MSAASamples.None;

        if (!enableMSAA && bindTextureMS == true)
        {
            Debug.LogWarning("RTHandle allocated without MSAA but with bindMS set to true, forcing bindMS to false.");
            bindTextureMS = false;
        }

        // We need to handle this in an explicit way since GraphicsFormat does not expose depth formats. TODO: Get rid of this branch once GraphicsFormat'll expose depth related formats
        RenderTexture rt;

        if (isShadowMap || depthBufferBits != DepthBits.None)
        {
            RenderTextureFormat format = isShadowMap ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth;
            rt = new RenderTexture(width, height, (int)depthBufferBits, format, RenderTextureReadWrite.Linear)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = enableRandomWrite,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = (int)msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, slices, format, name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
            };
        }
        else
        {
            rt = new RenderTexture(width, height, (int)depthBufferBits, colorFormat)
            {
                hideFlags         = HideFlags.HideAndDontSave,
                volumeDepth       = slices,
                filterMode        = filterMode,
                wrapMode          = wrapMode,
                dimension         = dimension,
                enableRandomWrite = enableRandomWrite,
                useMipMap         = useMipMap,
                autoGenerateMips  = autoGenerateMips,
                anisoLevel        = anisoLevel,
                mipMapBias        = mipMapBias,
                antiAliasing      = (int)msaaSamples,
                bindTextureMS     = bindTextureMS,
                useDynamicScale   = m_HardwareDynamicResRequested && useDynamicScale,
                memorylessMode    = memoryless,
                name = CoreUtils.GetRenderTargetAutoName(width, height, slices, GraphicsFormatUtility.GetRenderTextureFormat(colorFormat), name, mips: useMipMap, enableMSAA: enableMSAA, msaaSamples: msaaSamples)
            };
        }

        rt.Create();

        RTCategory category = enableMSAA ? RTCategory.MSAA : RTCategory.Regular;
        var        newRT    = new RTHandle(this);

        newRT.SetRenderTexture(rt, category);
        newRT.useScaling             = false;
        newRT.m_EnableRandomWrite    = enableRandomWrite;
        newRT.m_EnableMSAA           = enableMSAA;
        newRT.m_EnableHWDynamicScale = useDynamicScale;
        newRT.m_Name = name;

        newRT.referenceSize = new Vector2Int(width, height);

        return(newRT);
    }
Exemple #28
0
 extern private static bool Internal_CreateImpl([Writable] Texture2DArray mono, int w, int h, int d, int mipCount, GraphicsFormat format, TextureCreationFlags flags);
Exemple #29
0
        private async void ConvertButton_Click(object sender, RoutedEventArgs e)
        {
            JobStatusControl.ClearLog();

            await Task.Run(() => {
                ZebraGraphics graphics = null;

                try {
                    graphics = new ZebraCardGraphics(null)
                    {
                        PrinterModel = viewModel.SelectedPrinterModelInfo.PrinterModel
                    };

                    if (!Path.IsPathRooted(viewModel.OriginalGraphicFilename))
                    {
                        throw new ArgumentException("Original graphic filename must be an absolute path");
                    }

                    System.Drawing.Image image = ImageHelper.CreateImageFromFile(viewModel.OriginalGraphicFilename);
                    byte[] imageData           = ImageHelper.ConvertImage(image);

                    int width;  // Width of final output image
                    int height; // Height of final output image

                    switch (viewModel.SelectedDimensionOption)
                    {
                    case DimensionOption.Crop:
                        int croppedWidth  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        int croppedHeight = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);
                        imageData         = CropImage(graphics, imageData, croppedWidth, croppedHeight);

                        width  = croppedWidth;
                        height = croppedHeight;
                        break;

                    case DimensionOption.Resize:
                        width  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        height = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                        JobStatusControl.UpdateLog($"Resizing image to {width}x{height}...");
                        break;

                    case DimensionOption.Original:
                    default:
                        width  = ConstrainWidth(image.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                        height = ConstrainHeight(image.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                        JobStatusControl.UpdateLog("Keeping current image dimensions unless they exceed the maximum model-specific width and height...");
                        break;
                    }

                    GraphicsFormat graphicsFormat = viewModel.SelectedGraphicsFormat;
                    MonochromeConversion monochromeConversionType = viewModel.SelectedGraphicsFormat.GetMonochromeConversion();
                    PrintType printType             = viewModel.SelectedGraphicsFormat.GetPrintType();
                    OrientationType orientationType = OrientationType.Landscape;

                    JobStatusControl.UpdateLog($"Setting orientation to {orientationType}...");

                    graphics.Initialize(width, height, orientationType, printType, System.Drawing.Color.White);
                    graphics.DrawImage(imageData, 0, 0, width, height, RotationType.RotateNoneFlipNone);
                    ApplyMonochromeConversion(graphics, printType, monochromeConversionType);

                    JobStatusControl.UpdateLog($"Writing graphic file to path {viewModel.ConvertedGraphicFilename}...");

                    WriteToFile(viewModel.ConvertedGraphicFilename, graphics.CreateImage().ImageData);

                    JobStatusControl.UpdateLog("Finished converting graphic");
                } catch (Exception exception) {
                    string errorMessage = $"Error converting graphic: {exception.Message}";
                    JobStatusControl.UpdateLog(errorMessage);
                    MessageBoxHelper.ShowError(errorMessage);
                } finally {
                    if (graphics != null)
                    {
                        graphics.Close();
                    }
                }
            });
        }
Exemple #30
0
 private static void Internal_Create([Writable] Texture2DArray mono, int w, int h, int d, int mipCount, GraphicsFormat format, TextureCreationFlags flags)
 {
     if (!Internal_CreateImpl(mono, w, h, d, mipCount, format, flags))
     {
         throw new UnityException("Failed to create 2D array texture because of invalid parameters.");
     }
 }
Exemple #31
0
        public void loadFileAsGFNT(string filename)
        {
            #region typedef
            /*
             * typedef struct {
             *   char* magHeader; // GFNT
             *   DWORD fileSize; // best to ignore; is sometimes size up to first palette
             *   char* version; // '1.02', '1.01' or '1.00' best to ignore
             *   DWORD Imagebpp;
             *   DWORD imageWidthSc; // for real width; 8 << val
             *   DWORD imageHeightSc; // for real height; 8 << val
             *   DWORD nPals;
             *   byte* image;
             *   byte* palette; // seems to be 2Bppal always.
             * } GFNTFile
             */
            #endregion

            BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open));
            br.ReadInt32(); // we should already know the magic header is GFNT
            br.ReadInt32(); // we don't need to know the filesize, and it's not even correct for multipalettes

            br.ReadInt32(); // ignore version-string

            int imbpp = br.ReadInt32();
            int imwidth = 8 << br.ReadInt32();
            int imheight = 8 << br.ReadInt32();
            int nPals = br.ReadInt32();

            int nBytesForIm = imwidth * imheight;

            switch (imbpp)
            {
                case 1: nBytesForIm /= 8; break;
                case 2: nBytesForIm /= 4; break;
                case 3: nBytesForIm /= 2; break;
                case 4: nBytesForIm *= 1; break;
                case 5: nBytesForIm *= 2; break;
                case 6: nBytesForIm *= 1; imbpp = 4; break;
                case 7: nBytesForIm *= 4; break;
                default: MainWindow.ShowError("Possibly invalid GFNT file: unknown GraphicsFormat " + imbpp); br.Close(); return;
            }

            this.Data = br.ReadBytes(nBytesForIm);

            graphFormat = (GraphicsFormat)imbpp;
            isBigEndian = true;
            tiled = false;
            width = (uint)imwidth;
            height = (uint)imheight;

            br.Close();
        }
Exemple #32
0
 [FreeFunction]                                                                                                                                                                                                       // 0x00000001800DFF80-0x00000001800DFFB0
 private static bool Internal_CreateImpl([Writable] /* 0x00000001800D4E50-0x00000001800D4E60 */ Cubemap mono, int ext, int mipCount, GraphicsFormat format, TextureCreationFlags flags, IntPtr nativeTex) => default; // 0x00000001809661D0-0x0000000180966230