public void Render(CommandList cl, ISurfaceCopyStageModel stage, GpuSurface source)
        {
            if (cl == null || stage == null || source == null)
            {
                _frameworkMessenger.Report("Warning: you are feeding the Surface Copy Stage Renderer null inputs, aborting");
                return;
            }

            //Ensure the staging texture is of the correct size
            var stagingTexture = _gpuSurfaceManager.RetrieveSurface(stage.StagingTextureId);

            var doStagingTexturePropertiesMatch = source.Texture.Width == stagingTexture.Texture.Width &&
                                                  source.Texture.Height == stagingTexture.Texture.Height;

            var pixelFormatOfSource = source.Texture.Format;

            if (pixelFormatOfSource != stagingTexture.Texture.Format)
            {
                doStagingTexturePropertiesMatch = false;
            }

            if (!doStagingTexturePropertiesMatch)
            {
                stage.SetPixelFormatAndCreateStagingTextureAndDataArray(source.Texture.Width,
                                                                        source.Texture.Height,
                                                                        TexturePixelFormatConverter.ConvertVeldridToYak(pixelFormatOfSource));
                stagingTexture = _gpuSurfaceManager.RetrieveSurface(stage.StagingTextureId);
            }

            cl.CopyTexture(source.Texture, stagingTexture.Texture);
        }
Example #2
0
        public IRenderTarget CreateRenderTarget(uint width,
                                                uint height,
                                                bool autoClearColourAndDepthEachFrame = true,
                                                SamplerType samplerType   = SamplerType.Anisotropic,
                                                uint numberOfMipMapLevels = 1)

        {
            if (width == 0 || height == 0)
            {
                throw new Yak2DException("Surfaces -> CreateRenderTarget(), dimensions cannot be zero");
            }

            if (numberOfMipMapLevels == 0)
            {
                numberOfMipMapLevels = 1;
            }

            return(_surfaceManager.CreateRenderSurface(
                       false,
                       width,
                       height,
                       TexturePixelFormatConverter.ConvertYakToVeldrid(_systemComponents.SwapChainFramebufferPixelFormat),
                       true,
                       autoClearColourAndDepthEachFrame,
                       autoClearColourAndDepthEachFrame,
                       samplerType,
                       numberOfMipMapLevels
                       ));
        }
Example #3
0
 private ulong CreateSurface(uint width, uint height, SamplerType samplerType)
 {
     return(_surfaceManager.CreateRenderSurface(true,
                                                width,
                                                height,
                                                TexturePixelFormatConverter.ConvertYakToVeldrid(_systemComponents.SwapChainFramebufferPixelFormat),
                                                false,
                                                false,
                                                false,
                                                samplerType,
                                                1).Id);
 }
Example #4
0
        public void SetPixelFormatAndCreateStagingTextureAndDataArray(uint stagingTextureWidth, uint stagingTextureHeight, TexturePixelFormat pixelFormat)
        {
            _pixelFormat = TexturePixelFormatConverter.ConvertYakToVeldrid(pixelFormat);

            _stagingTextureWidth  = stagingTextureWidth;
            _stagingTextureHeight = stagingTextureHeight;

            if (StagingTextureId != 0UL)
            {
                _surfaceManager.DestroySurface(StagingTextureId);
            }

            StagingTextureId = _surfaceManager.CreateGpuCpuStagingSurface(_stagingTextureWidth,
                                                                          _stagingTextureHeight,
                                                                          _pixelFormat).Id;

            _data = new byte[4 * _stagingTextureWidth * _stagingTextureHeight];
        }
 public ISurfaceCopyStageModel CreateSurfaceCopyDataStage(uint stagingTextureWidth,
                                                          uint stagingTextureHeight,
                                                          Action <TextureData> callback,
                                                          bool useFloat32PixelFormat)
 {
     return(new SurfaceCopyStageModel(_frameworkMessenger,
                                      _systemComponents,
                                      _gpuSurfaceManager,
                                      stagingTextureWidth,
                                      stagingTextureHeight,
                                      useFloat32PixelFormat ? Veldrid.PixelFormat.R32_Float : TexturePixelFormatConverter.ConvertYakToVeldrid(_systemComponents.SwapChainFramebufferPixelFormat),
                                      callback));
 }
Example #6
0
        public SurfaceCopyStageModel(IFrameworkMessenger frameworkMessenger,
                                     ISystemComponents systemComponents,
                                     IGpuSurfaceManager surfaceManager,
                                     uint stagingTextureWidth,
                                     uint stagingTextureHeight,
                                     PixelFormat pixelFormat,
                                     Action <TextureData> callback)
        {
            _frameworkMessenger = frameworkMessenger;
            _systemComponents   = systemComponents;
            _surfaceManager     = surfaceManager;

            SetCallback(callback);

            SetPixelFormatAndCreateStagingTextureAndDataArray(stagingTextureWidth, stagingTextureHeight, TexturePixelFormatConverter.ConvertVeldridToYak(pixelFormat));
        }