예제 #1
0
파일: Context.cs 프로젝트: zeta1999/Vrmac
        /// <summary>Initialize the object.</summary>
        public void initialize(iRenderingContext rc, Rational?displayRefresh)
        {
            if (null != renderContext)
            {
                throw new ApplicationException("Already initialized");
            }
            dispatcher          = Dispatcher.currentDispatcher;
            this.displayRefresh = displayRefresh;
            if (null == dispatcher)
            {
                throw new ApplicationException("Context.initialize requires the current thread to have a dispatcher");
            }

            renderContext = rc;
            context       = rc.context;
            swapChain     = rc.swapChain;
            if (rc is iDiligentWindow window)
            {
                dpiScalingFactor = window.dpiScaling;
            }

            using (var device = rc.device)
            {
                isOpenGlDevice = device.isGlDevice();

                var scDesc = swapChain.GetDesc();
                swapChainSize         = new CSize(scDesc.Width, scDesc.Height);
                swapChainFormats      = new SwapChainFormats(scDesc.ColorBufferFormat, scDesc.DepthBufferFormat, getSampleCount(swapChain));
                swapChainBuffersCount = scDesc.BufferCount;

                animation = new Animations(this);
                scene.createResources(this, device);
            }
            initializeAsync();
        }
예제 #2
0
        /// <summary>Save 8 bit/pixel grayscale TGA image</summary>
        public static void saveGrayscale(Stream stm, ReadOnlySpan <byte> data, CSize size, int stride)
        {
            if (stride < size.cx || size.cx <= 0 || size.cy <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (size.cx >= 0x10000 || size.cy >= 0x10000)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (data.Length != size.cy * stride)
            {
                throw new ArgumentException();
            }

            TgaHeader header = new TgaHeader()
            {
                ColorMapType = eColorMapType.None,
                ImageType    = eImageType.Grayscale,
                // By default, rows order in TGAs is bottom to top. Not what we want. That's why setting bit #5 of the ImageDescriptor header field.
                ImageDescriptor = 0b00100000,
                Width           = (ushort)size.cx,
                Height          = (ushort)size.cy,
                PixelDepth      = 8,
            };

            {
                // The usability is not great, BTW
                var span1 = MemoryMarshal.CreateReadOnlySpan(ref header, 1);
                var span2 = MemoryMarshal.Cast <TgaHeader, byte>(span1);
                stm.Write(span2);
            }

            if (stride == size.cx)
            {
                // No padding whatsoever, write the complete file in 1 shot
                stm.Write(data);
            }
            else
            {
                // Rows have padding, need to skip stuff.
                for (int y = 0; y < size.cy; y++)
                {
                    int off = y * stride;
                    stm.Write(data.Slice(off, size.cx));
                }
            }
        }
예제 #3
0
파일: Context.cs 프로젝트: zeta1999/Vrmac
        void iContent.swapChainRecreated(iDiligentWindow window)
        {
            try
            {
                swapChain = window.swapChain;
                context   = window.context;

                timersHardPause?.Dispose();
                timersHardPause = null;

                var scDesc = swapChain.GetDesc();
                swapChainSize = new CSize(scDesc.Width, scDesc.Height);
                byte samples = swapChainFormats.sampleCount;
                swapChainFormats      = new SwapChainFormats(scDesc.ColorBufferFormat, scDesc.DepthBufferFormat, samples);
                swapChainBuffersCount = scDesc.BufferCount;
            }
            catch (Exception ex)
            {
                NativeContext.cacheException(ex);
                throw;
            }
        }