Click or drag to resize
Ab4d.SharpEngine logo

SceneView Class

SceneView object provides the view to the Scene and renders the objects defined by the Scene. The view is defined by the Camera and the size (Width and Height) properties. SceneView defines many graphics buffers that are used during rendering. Those buffers are initialized by calling the Initialize method.
Inheritance Hierarchy

Namespace: Ab4d.SharpEngine
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 1.0.8740+deb2991acfe86a95cca780cd4f82bcae2805c1a5
Syntax
C#
public class SceneView : SceneComponent, IDisposable

The SceneView type exposes the following members.

Constructors
 NameDescription
Public methodSceneView Creates a SceneView object without the specified Scene object.
Top
Properties
 NameDescription
Public propertyBackBuffersInitialized Gets a Boolean that specifies if the back buffers for this SceneView have been created. When this is true, then Width and Height define the size of the back buffers.
Public propertyBackgroundColor Color of the background. The color is not pre-multiplied by the alpha component.
Public propertyBackgroundSpritesRenderingLayer Gets a RenderingLayer that contains sprites that are rendered before any other 3D object is rendered. This RenderingLayer is not added to Ab4d.SharpEngine.RenderingLayers collection but is rendered in RenderSpritesRenderingStep.
Public propertyCamera Gets or sets an ICamera that is used to show the scene.
Public propertyDefaultBeginRenderPassRenderingStep Default BeginRenderPassRenderingStep
Public propertyDefaultCompleteRenderingStep Default CompleteRenderingStep
Public propertyDefaultInitializeRenderingStep Default InitializeRenderingStep
Public propertyDefaultRenderObjectsRenderingStep Default RenderObjectsRenderingStep
Public propertyDepthStencilFormat Gets the format of DepthStencilImage
Public propertyDepthStencilImage Gets the GpuImage that is used as a depth-stencil buffer.
Public propertyDpiScaleX Gets or sets a float that represents a DPI scale factor in X direction: 1 means 96 DPI, 1.5 means 144 DPI, etc. This value is used in line and pixel rendering and scales the line thickness or size of pixels.
Public propertyDpiScaleY Gets or sets a float that represents a DPI scale factor in Y direction: 1 means 96 DPI, 1.5 means 144 DPI, etc. This value is used in line and pixel rendering and scales the line thickness or size of pixels.
Public propertyFormat Gets or sets a texture format that is used for SwapChain. By default this is set to BGRA, but in cases when using shared texture or when the engine is only rendering to bitmap, it is also possible to specify the RGBA format.
Public propertyFrameBuffers Gets an array of used Framebuffers
Public propertyFrameNumber Gets the current frame number. The frame number is increased at the beginning of Render(Boolean, Boolean, Boolean) method and before calling Update method. The first rendered frame number is 1 (0 means that no frame was rendered yet). See LastSubmittedFrameNumber to get the frame number that was lastly submitted to the graphics card.
Public propertyGpuDevice Gets the VulkanDevice that was used to initialize this SceneView.
Public propertyGraphicsCommandPool Gets the default graphics command pool.
Public propertyHeight Gets the heigth in pixels of this SceneView.
Public propertyIsCollectingStatistics Gets or sets a Boolean that specified is statistics is collected during rendering. Statistics is written to the Statistics property.
Public propertyIsPerSampleShading True when per-sample shading is used. This can be used to eliminate aliasing and smooth out e.g. high frequency texture maps. To set the value of per-sample shading, set the PreferredIsPerSampleShading before the SceneView is initialized.
Public propertyLastSubmittedFrameNumber Gets a frame number that was submitted to the graphics card for execution. This may be lower than the FrameNumber because FrameNumber is increased before the Update phase, when the LastSubmittedFrameNumber is set when the frame is sent to the graphics card. This value is increased in the InitializeRenderingStep.
Public propertyMaxConcurrentlySubmittedFrames Gets the number of frames that can be rendered in the background on the graphics card. In case when the engine is waiting for the graphics card to finish rendering, then this value is 0 (no background rendering while this app is being executed). Otherwise this value can be as big as SwapChainImagesCount.
Public propertyMSAAImage Gets the GpuImage that is used as multi-sampled buffer.
Public propertyOverlaySpritesRenderingLayer Gets a RenderingLayer that contains sprites that are rendered after 3D objects are rendered. This RenderingLayer is not added to Ab4d.SharpEngine.RenderingLayers collection but is rendered in RenderSpritesRenderingStep.
Public propertyPreferredIsPerSampleShading PreferredIsPerSampleShading can be set before the SceneView is initialized and defines if the per-sample shading is used. After initializing the SceneView, the actually used multi-sampling count is set to the IsPerSampleShading property.
Public propertyPreferredMultiSampleCount PreferredMultiSampleCount can be set before the SceneView is initialized and defines the multi-sampling count (MSAA) that will be used if supported by the device. After initializing the SceneView, the actually used multi-sampling count is set to the UsedMultiSampleCount property.
Public propertyPresentQueue Gets the present queue.
Public propertyPrimaryCommandBuffers Get an array of primary command buffers.
Public propertyRenderBackgroundSpritesRenderingStep Default RenderSpritesRenderingStep that render background sprites.
Public propertyRenderingContext Gets the RenderingContext
Public propertyRenderingSteps Gets the rendering steps that are executed to render a frame.
Public propertyRenderOverlaySpritesRenderingStep Default RenderSpritesRenderingStep that render overlay sprites.
Public propertyRenderPass Gets the RenderPass
Public propertyStatistics Gets the RenderingStatistics that was taken during the rendering of the last frame. To enable collecting statistics set the IsCollectingStatistics to true. When no statistics is collected, then this property is set to null.
Public propertySupersamplingCount SupersamplingCount - always 1 in this version because super-sampling is not supported.
Public propertySupersamplingFactor SupersamplingFactor - always 1 in this version because super-sampling is not supported.
Public propertySurface Gets the Vulkan surface that will show the rendered SceneView. Set to SurfaceKHR.Null when no surface is used.
Public propertySurfaceDetails Gets SurfaceDetails of the used Surface.
Public propertySwapChain Gets the GpuSwapChain
Public propertySwapChainFormat Gets the format of the SwapChain
Public propertySwapChainImagesCount Gets the number of used swap chain images.
Public propertyUsedMultiSampleCount Gets used sample count in multi-sampling (MSAA) used by this SceneView. 1 indicates that no multi-sampling is used. To set the value of multi-sampling count, set the PreferredMultiSampleCount before the SceneView is initialized.
Public propertyUsedMultiSampleCountFlags Gets used multi-sampling as a SampleCountFlags.
Public propertyUseSurfacePreTransform Gets or sets a Boolean that specifies if Surface pre-transform is used (view is rendered with the same rotation as the surface).
Public propertyViewRotation Gets or sets rotation of the view (sometimes also called view pre-transform).
Public propertyWaitForVSync Gets or sets a Boolean that specifies if the SceneView is waiting for a v-sync provided by the surface.
Public propertyWidth Gets the width in pixels of this SceneView.
Top
Methods
 NameDescription
Public methodAddAnimation Adds the specified animation to the list of animations that are updated in each update phase.
Public methodBoundingBox3DTo2D Converts a 3D BoundingBox to the two Vector2 that define the 2D bounding box on the screen.
Public methodCalculateCameraPlanes(ICamera, Single, Single) CalculateCameraPlanes sets the zNear and zFar parameters to camera near plane distance and camera far plane distance. The values are calculated with using the bounding box of the current scene and specified camera. CalculateCameraPlanes returns false if the calculated values are not correct (are 0, NaN or Infinity). This can happen when camera's matrices are not set.
Public methodStatic memberCalculateCameraPlanes(Matrix4x4, Boolean, Vector3, Single, Single, Single) CalculateCameraPlanes sets the zNear and zFar parameters to camera near plane distance and camera far plane distance. CalculateCameraPlanes returns false if the calculated values are not correct (are 0, NaN or Infinity). This can happen when camera's matrices are not set.
Public methodCanConvertPoint3DTo2D CanConvertPoint3DTo2D returns true when the matrix to convert 3D world position to screen 2D position can be generated.
Public methodCaptureNextFrameInRenderDoc CaptureNextFrameInRenderDoc will try to capture the next frame in RenderDoc. The application that is using SharpEngine must be started from RenderDoc. This works only on Windows. The method returns true when the RenderDocHelper was correctly initialized and when the capture is possible. The actual capture will start before the next frame will be rendered.
Protected methodChooseDepthStencilFormat virtual ChooseDepthStencilFormat that can be overriden to set a different Format for the depth-stencil buffer. Returns Format.Undefined if not supported
Protected methodChooseSwapPresentMode virtual ChooseSwapPresentMode that can be overriden to set a different PresentModeKHR.
Protected methodChooseSwapSurfaceFormat(SurfaceDetails) virtual ChooseSwapSurfaceFormat that can be overriden to set a different SurfaceFormatKHR
Protected methodChooseSwapSurfaceFormat(SurfaceFormatKHR) virtual ChooseSwapSurfaceFormat that can be overriden to set a different SurfaceFormatKHR
Public methodCreateBackgroundSpriteBatch Creates a SpriteBatch that will be rendered before the objects in this SceneView are rendered. SpriteBatch that is created from SceneView object can use relative and absolute coordinates. To remove the created SpriteBatch call the RemoveSpriteBatch(SpriteBatch, Boolean) or RemoveAllSpriteBatches(Boolean) methods. It is also possible to add sprites that are rendered when rendering the Scene - in this case call CreateBackgroundSpriteBatch(String) or CreateOverlaySpriteBatch(String) methods.
Public methodCreateOverlaySpriteBatch Creates a SpriteBatch that will be rendered after the objects in this SceneView are rendered. SpriteBatch that is created from SceneView object can use relative and absolute coordinates. To remove the created SpriteBatch call the RemoveSpriteBatch(SpriteBatch, Boolean) or RemoveAllSpriteBatches(Boolean) methods. It is also possible to add sprites that are rendered when rendering the Scene - in this case call CreateBackgroundSpriteBatch(String) or CreateOverlaySpriteBatch(String) methods.
Public methodDispose Dispose
Protected methodDispose(Boolean) Dispose
(Overrides ComponentBaseDispose(Boolean))
Public methodDumpCameraInfo Writes string about the details about the current camera to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodDumpRenderingStatistics Writes string with major rendering statistics from the last rendered frame to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodDumpRenderingSteps Writes string about each used rendering step to the console (when the application is debugged in Visual Studio the result is written to Output window or Immediate Window if started from there; in Rider the result is written to Debug Output window).
Public methodGetAllHitObjects(Ray) GetAllHitObjects method executes a hit testing by using the specified Ray on the SceneNodes that are shown by this SceneView and returns a list of RayHitTestResult objects sorted from the closest to the farthest object. When no object is hit, an empty list is returned.
Public methodGetAllHitObjects(Single, Single, Boolean) GetAllHitObjects method executes a hit testing from the specified x and y positions on the SceneNodes that are shown by this SceneView and returns a list of RayHitTestResult objects sorted from the closest to the farthest object. When no object is hit, an empty list is returned.
Public methodGetCameraInfo Gets a string that shows the details about the current camera.
Public methodGetClosestHitObject(Ray) GetClosestHitObject method executes a hit testing by using the specified Ray on the SceneNodes that are shown by this SceneView and returns a RayHitTestResult object with the closest triangle hit. When no triangle is hit, null is returned.
Public methodGetClosestHitObject(Single, Single, Boolean) GetClosestHitObject method executes a hit testing from the specified x and y positions on the SceneNodes that are shown by this SceneView and returns a RayHitTestResult object with the closest triangle hit. When no triangle is hit, null is returned.
Protected methodGetCurrentSurfaceSize Gets the size of the Surface
Public methodGetCurrentSwapChainImage Returns the Vulkan Image that is used as the current swap chain image.
Public methodGetImageAvailableSemaphore Gets the Semaphore that is used to signal when the rendered image is available.
Public methodGetRayFromCamera(Int32, Int32, Boolean, Boolean) Returns a Ray that goes into a direction that is calculated from the specified x and y position in screen coordinates. For perspective camera the ray starts at the current camera position. The ray can be used for hit testing from the mouse position defined by x and y (relative to this DXScene object). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).
Public methodGetRayFromCamera(Single, Single, Boolean, Boolean) Returns a Ray that goes into a direction that is calculated from the specified x and y position in screen coordinates. For perspective camera the ray starts at the current camera position. The ray can be used for hit testing from the mouse position defined by x and y (relative to this DXScene object). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).
Public methodGetRayFromNearPlane(Int32, Int32, Boolean, Boolean) Returns a Ray that starts at the camera's near plane and goes into a direction that is calculated from the specified x and y position in screen coordinates. The ray can be used for hit testing from the mouse position defined by x and y (relative to this DXScene object). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).
Public methodGetRayFromNearPlane(Single, Single, Boolean, Boolean) Returns a Ray that starts at the camera's near plane and goes into a direction that is calculated from the specified x and y position in screen coordinates. The ray can be used for hit testing from the mouse position defined by x and y (relative to this DXScene object). When the Ray cannot be created (size is zero or camera matrix is not valid), then a Ray with zero Direction is returned (Ray.IsValid would return false).
Public methodGetRenderFinishedSemaphore Gets the Semaphore that is used to signal when the rendering is finished.
Public methodGetRenderingStatisticsInfo Returns a string with major rendering statistics from the last rendered frame. To collect statistics set the IsCollectingStatistics to true before rendering a frame.
Public methodGetRenderingStepsInfo Gets a string that shows each used rendering step in its own line.
Public methodGetWorldToViewMatrix Gets Matrix4x4 that can be used to convert 3D coordinates to 2D view (screen) coordinates. If the method returns true, than the worldToViewMatrix was set; if false is returned than the matrix cannot be calculated.
Public methodGetWorldToViewportMatrix Gets Matrix4x4 that can be used to convert 3D coordinates to 2D viewport (screen) coordinates. If the method returns true, than the worldToViewportMatrix was set; if false is returned than the matrix cannot be calculated.
Public methodInitialize(SurfaceKHR, Single, Single) Initializes the SceneView with the size from the specified Vulkan Surface. Optionally it is possible to set the DPI scale because that data is not available from the surface.
Public methodInitialize(VulkanSurfaceProvider, Single, Single) Initializes the SceneView with the size from the specified vulkanSurfaceProvider that can return a Vulkan Surface. Optionally it is possible to set the DPI scale because that data is not available from the surface.
Public methodInitialize(Int32, Int32, Single, Single) Initializes the SceneView with the specified size. This method can be called only when the SceneView was created without a Surface parameter (call Initialize(SurfaceKHR, Single, Single) or Initialize(VulkanSurfaceProvider, Single, Single) when a valid Surface is provided).
Public methodInitialize(VulkanDevice, VulkanSurfaceProvider, Single, Single) Initializes the SceneView with the size from the specified vulkanSurfaceProvider that can return a Vulkan Surface. Optionally it is possible to set the DPI scale because that data is not available from the surface.
Public methodInitialize(VulkanDevice, SurfaceKHR, Single, Single) Initializes the SceneView with the size from the specified Vulkan Surface. Optionally it is possible to set the DPI scale because that data is not available from the surface.
Public methodInitializeWithDefaultSurface Initializes the SceneView with the size from the DefaultSurface that was used to create the VulkanDevice. Optionally it is possible to set the DPI scale because that data is not available from the surface.
Protected methodIsCommandBuffersRecreateNeeded IsCommandBuffersRecreateNeeded returns true if Scene.DirtyFlags and DirtyFlags require that the command buffer is recreated.
Public methodIsFrameRenderingFinished Returns true if the frame with the specified number was fully rendered (no tasks on the GPU are still running for this frame).
Protected methodIsRenderingLayersRecreateNeeded IsRenderingLayersRecreateNeeded returns true if Scene.DirtyFlags and DirtyFlags require that the RenderingLayers are recreated by calling CollectRenderingItems(RenderingContext) methods on all SceneNodes..
Public methodLine3DTo2D(Vector3, Vector3, Boolean) Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera's near plane.
Public methodStatic memberLine3DTo2D(Vector3, Vector3, Camera, Single, Single) Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera's near plane.
Public methodNotifyChange NotifyChange method adds the specified SceneViewDirtyFlags to the changes flags for this SceneView.
Protected methodOnInitializeDeviceResources OnInitializeDeviceResources
(Overrides SceneComponentOnInitializeDeviceResources(VulkanDevice))
Protected methodOnSceneRendered OnSceneRendered
Protected methodOnSceneUpdating OnSceneUpdating
Protected methodOnViewResized OnViewSizeChanged
Public methodPoint3DTo2D(Vector3, Boolean) Point3DTo2D converts a world space 3D position (as Vector3) to the 2D screen position (as Vector2). To calculate the 2D position for the final UI element, set the adjustByDpiScale to true otherwise the 2D positions will be positioned inside the view defined by SceneView's Width and Height.
Public methodPoint3DTo2D(Vector3, Camera, Single, Single) Point3DTo2D converts a world space 3D point (as Vector3) to the 2D point (as Vector2) on the view that is defined by specified camera, viewWidth and viewHeight.
Public methodPoints3DTo2D(Span, Void, Vector3, Span, Void) 
Public methodPoints3DTo2D(Vector3, Vector2, Transform, Boolean, Boolean) Points3DTo2D calculates 2D screen positions from the specified 3D positions. To calculate the 2D positions for the final UI element, set the adjustByDpiScale to true otherwise the 2D positions will be positioned inside the view defined by SceneView's Width and Height. Calculated 2D positions are stored into the specified points2D array (its size must be at least the size of the 3D positions).
Public methodPoints3DTo2D(Span, Void, Vector3, Span, Void, Vector2, Camera, Single) 
Public methodPoints3DTo2D(Vector3, Vector2, Camera, Single, Single, Transform, Boolean, Boolean) Points3DTo2D calculates 2D positions from the specified 3D positions. Calculated 2D positions are stored into the specified points2D array (its size must be at least the size of the 3D positions).
Public methodRegisterStagingGpuBufferReadyCallback RegisterStagingGpuBufferReadyCallback can be called to copy the rendered image to a staging GpuBuffer and call the provided action when the staging buffer is ready to be copied to the main memory. To get the GpuImage instead of a staging buffer, use the RegisterStagingGpuImageReadyCallback(ActionGpuImage). To unregister call UnregisterStagingGpuBufferReadyCallback(ActionGpuBuffer, Int32, Int32) method.
Public methodRegisterStagingGpuImageReadyCallback RegisterStagingGpuImageReadyCallback can be called to copy the rendered image to a staging GpuImage and call the provided action when the staging buffer is ready to be copied to the main memory. To get the GpuBuffer as a staging buffer, use the RegisterStagingGpuBufferReadyCallback(ActionGpuBuffer, Int32, Int32). To unregister call UnregisterStagingGpuImageReadyCallback(ActionGpuImage) method.
Public methodRemoveAllSpriteBatches Removes all SpriteBatches.
Public methodRemoveAnimation Remove the specified animation from the list of animations.
Public methodRemoveSpriteBatch Removes the specified SpriteBatch from the list of sprite batches associated to this Scene (created by CreateBackgroundSpriteBatch(String) or CreateOverlaySpriteBatch(String) methods).
Public methodRender Render method checked the dirty flags of this SceneView and the Scene and when there are some changes rendered the next frame. Rendering cna be forced by setting forceRender to true.
Public methodRenderToGpuBuffer Renders the current scene view to the bitmap and saves the image data a GpuBuffer that is passed to the specified stagingGpuBufferReady Action (parameters: GpuBuffer gpuBuffer, int imageWidth, int imageHeight). The data in the GpuBuffer always have 4 bytes per pixel and have no row padding (stride = width * 4).
Public methodRenderToGpuImage Renders the current scene view to the bitmap and saves the image data a GpuImage that is passed to the specified stagingGpuImageReady Action.
Public methodRenderToRawImageData(Boolean, Boolean, StandardBitmapFormats) Renders the current scene view to the bitmap that is represented by RawImageData object. To reuse the RawImageData and its data array, call RenderToRawImageData that takes RawImageData as the first parameter.
Public methodRenderToRawImageData(RawImageData, Boolean, Boolean, StandardBitmapFormats) Renders the current scene view to the bitmap and saves the image data into an existing RawImageData object. When the rendered size is the same or smaller, then the existing Data array is preserved, otherwise a new Data array is created.
Public methodResize(Boolean) Resizes the current SceneView by updating the size from the size of the Surface. When no Surface is used, then Resize(Int32, Int32, SurfaceTransformFlagsKHR, Boolean) must be used.
Public methodResize(Int32, Int32, SurfaceTransformFlagsKHR, Boolean) Resizes the current SceneView to the provided size. When SceneView is rendered to the Surface, then call the Resize(Boolean) method.
Public methodToString
(Overrides ObjectToString)
Public methodUnregisterStagingGpuBufferReadyCallback Removes the specified Action from the actions that were registered by calling the RegisterStagingGpuBufferReadyCallback(ActionGpuBuffer, Int32, Int32) method.
Public methodUnregisterStagingGpuImageReadyCallback Removes the specified Action from the actions that were registered by calling the RegisterStagingGpuImageReadyCallback(ActionGpuImage) method.
Public methodUpdateAnimations Update all Scene's animations and all animations that are added by calling the AddAnimation(IAnimation) (this is done automatically by the animation classes).
Public methodWaitUntilRendered WaitUntilRendered method waits until this SceneView finishes rendering the current frame.
Top
Events
 NameDescription
Public eventFirstFrameRendered SceneRendered is triggered after the first frame is rendered.
Public eventSceneRendered SceneRendered is triggered after each frame is rendered.
Public eventSceneUpdating SceneUpdating is triggered when the scene is updating. This event should be used to animate or update the scene objects before they are rendered.
Public eventViewResized ViewResized is triggered when the size (Width and Height) is changed.
Top
Fields
 NameDescription
Public fieldDirtyFlags Gets the dirty flags for this SceneView. This value is reset to None when calling Update(Boolean) method.
Public fieldStatic memberPresentOnGraphicsQueue 
Public fieldStatic memberRequireCommandBuffersRecodingDirtyFlagsBit When this bit is set in the DirtyFlags, then command buffer needs to be recorded again.
Public fieldStatic memberRequireDisposeAllRenderingItemsFlagsBit When this bit is set in the DirtyFlags, then all the RenderingItems need to be regenerated.
Public fieldStatic memberRequireRenderingLayersCreationDirtyFlagsBit When this bit is set in the DirtyFlags, then the rendering layers need to be regenerated and command buffer needs to be recorded again.
Top
See Also