当前位置: 首页>>代码示例>>C#>>正文


C# Vector2I.Size方法代码示例

本文整理汇总了C#中Vector2I.Size方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2I.Size方法的具体用法?C# Vector2I.Size怎么用?C# Vector2I.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2I的用法示例。


在下文中一共展示了Vector2I.Size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetScreenData

        private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
        {
            const uint headerPadding = 256; // Need to allocate some space for the bitmap headers
            const uint bytesPerPixel = 4;
            uint imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
            uint dataSizeInBytes = imageSizeInBytes + headerPadding;

            byte[] returnData = null;
            if(screenData == null)
                screenData = new byte[imageSizeInBytes];
            else if(screenData.Length != imageSizeInBytes)
            {
                Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length * bytesPerPixel + " received");
                return returnData;
            }

            MyBindableResource imageSource = Backbuffer;
            if (imageSource == null)
                return returnData;

            if(imageSizeInBytes > int.MaxValue)
            {
                Debug.Fail("Image size too large to read!");
                return returnData;
            }

            MyBindableResource imageResource = imageSource;
            if (resolution.X != imageResource.GetSize().X || resolution.Y != imageResource.GetSize().Y)
            {
                imageResource = m_lastScreenDataResource;
                if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
                {
                    if (m_lastScreenDataResource != null && m_lastScreenDataResource != Backbuffer)
                    {
                        m_lastScreenDataResource.Release();
                    }
                    m_lastScreenDataResource = null;

                    imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 0, 0);
                }

                MyCopyToRT.Run(imageResource, imageSource, new MyViewport(resolution));
            }

            m_lastScreenDataResource = imageResource;

            Stream dataStream = m_lastDataStream;
            if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
            {
                if (m_lastDataStream != null)
                {
                    m_lastDataStream.Dispose();
                    m_lastDataStream = null;
                }
                dataStream = new DataStream((int)dataSizeInBytes, true, true);
            }

            m_lastDataStream = dataStream;

            Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);

            if (!(dataStream.CanRead && dataStream.CanSeek))
            {
                Debug.Fail("Screen data stream does not support the necessary operations to get the data");
                return returnData;
            }

            fixed (byte* dataPointer = screenData)
            {
                GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
            }

            returnData = screenData;

            if (m_lastDataStream != null)
                m_lastDataStream.Seek(0, SeekOrigin.Begin);

            return returnData;
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:79,代码来源:MyRender-DrawScene.cs

示例2: GetScreenData

        private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
        {
            const uint headerPadding = 256; // Need to allocate some space for the bitmap headers
            const uint bytesPerPixel = 4;
            uint imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
            uint dataSizeInBytes = imageSizeInBytes + headerPadding;

            byte[] returnData = null;
            if(screenData == null)
                screenData = new byte[imageSizeInBytes];
            else if(screenData.Length != imageSizeInBytes)
            {
                Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length + " received");
                return returnData;
            }

            MyBindableResource imageSource = Backbuffer;
            MyBindableResource imageSourceResourceView = null;

            if (imageSource != null && (resolution.X != imageSource.GetSize().X || resolution.Y != imageSource.GetSize().Y))
            {
                MyViewKey viewKey = new MyViewKey { View = MyViewEnum.SrvView, Fmt = MyRender11Constants.DX11_BACKBUFFER_FORMAT };
                if(m_backbufferCopyResource == null)
                {
                    m_backbufferCopyResource = new MyCustomTexture(m_resolution.X, m_resolution.Y, BindFlags.ShaderResource, MyRender11Constants.DX11_BACKBUFFER_FORMAT);
                    m_backbufferCopyResource.AddView(viewKey);
                }
                MyRenderContext.Immediate.DeviceContext.CopyResource(imageSource.m_resource, m_backbufferCopyResource.m_resource);
                imageSource = m_backbufferCopyResource;
                imageSourceResourceView = m_backbufferCopyResource.GetView(viewKey);
            }

            if (imageSource == null)
                return returnData;

            if(imageSizeInBytes > int.MaxValue)
            {
                Debug.Fail("Image size too large to read!");
                return returnData;
            }

            MyBindableResource imageResource = imageSource;
            bool shouldResize = imageSourceResourceView != null;
            if (shouldResize)
            {
                imageResource = m_lastScreenDataResource;
                if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
                {
                    if (m_lastScreenDataResource != null && (m_lastScreenDataResource != m_backbufferCopyResource && m_lastScreenDataResource != Backbuffer))
                    {
                        m_lastScreenDataResource.Release();
                    }
                    m_lastScreenDataResource = null;

                    imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 1, 0);
                }
                var RC = MyRenderContext.Immediate;
                var deviceContext = RC.DeviceContext;
                deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                deviceContext.Rasterizer.SetViewport(0, 0, resolution.X, resolution.Y);
                deviceContext.PixelShader.Set(MyDebugRenderer.BlitTextureShader);
                deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

                RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, imageResource);
                RC.BindSRV(0, imageSourceResourceView);
                MyDebugRenderer.DrawQuad(0, 0, resolution.X, resolution.Y, MyScreenPass.QuadVS);
                //MyCopyToRT.Run(imageResource, imageSourceResourceView, new MyViewport(resolution));
            }

            m_lastScreenDataResource = imageResource;

            Stream dataStream = m_lastDataStream;
            if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
            {
                if (m_lastDataStream != null)
                {
                    m_lastDataStream.Dispose();
                    m_lastDataStream = null;
                }
                dataStream = new DataStream((int)dataSizeInBytes, true, true);
                dataStream.Seek(0, SeekOrigin.Begin);
            }

            m_lastDataStream = dataStream;

            Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);

            if (!(dataStream.CanRead && dataStream.CanSeek))
            {
                Debug.Fail("Screen data stream does not support the necessary operations to get the data");
                return returnData;
            }

            fixed (byte* dataPointer = screenData)
            {
                GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
            }

            returnData = screenData;

//.........这里部分代码省略.........
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:101,代码来源:MyRender-DrawScene.cs

示例3: BasicTexture1D

 public BasicTexture1D(Vector2I size)
     : this(size.Size())
 { }
开发者ID:GoodAI,项目名称:BrainSimulator,代码行数:3,代码来源:BasicTextures.cs


注:本文中的Vector2I.Size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。