Class GLControl
- Namespace
- SearchAThing.OpenGL.Core
- Assembly
- netcore-opengl-core.dll
Provides basic opengl abstraction to create entities such as GLPoint, GLLine and GLTriangle.
It provides high level functions to manage camera view and related pan/zoom functions.
The Invalidate(InvalidateEnum) emit a RenderInvalidated event that
SearchAThing.OpenGL.GUI.AvaloniaGLControl listen to invalidte its visual.
public class GLControl : INotifyPropertyChanged
- Inheritance
-
GLControl
- Implements
- Inherited Members
- Extension Methods
Constructors
GLControl(GLControl, IRenderDevice)
Create a new gl control using the same control properties of the given template.
public GLControl(GLControl template, IRenderDevice device)
Parameters
template
GLControlGl control template to config this new one created.
device
IRenderDeviceTarget render device.
GLControl(GLModel, IRenderDevice)
Create a new gl control attached to given model and rendering to the given rendere device.
public GLControl(GLModel glModel, IRenderDevice device)
Parameters
glModel
GLModelGl model.
device
IRenderDeviceTarget render device.
Properties
AutoAdjustNearFar
Auto adjust near,far to prevent z-fighting.
public bool AutoAdjustNearFar { get; set; }
Property Value
- See Also
CameraPos
CameraPos [world].
public Vector3 CameraPos { get; set; }
Property Value
CameraTarget
CameraTarget [world].
public Vector3 CameraTarget { get; set; }
Property Value
CameraUp
CameraUp [world]
public Vector3 CameraUp { get; set; }
Property Value
ClearColor
Default scene background color ( Default: black ).
public Color ClearColor { get; set; }
Property Value
ControlFigureVisible
Control specific custom figure visibility.
If null default model figure visibiltiy not changes.
Args: (GLControl glControl, GLFigureBase figure).
public ControlFigureVisibileDelegate? ControlFigureVisible { get; set; }
Property Value
Remarks
Keep delegate function as light as possible to avoid performance penalty.
ControlOverlay1
ControlOverlay1 ( used for IdentifyCoord output )
public string ControlOverlay1 { get; set; }
Property Value
DepthShader
Depth only shader for shadow cube maps ( retrieved from gl context ).
public GLPipeline DepthShader { get; }
Property Value
Device
Render device associateed to this control.
public IRenderDevice Device { get; }
Property Value
Far
Far clipping plane distance [world].
public float Far { get; set; }
Property Value
- See Also
FovDeg
Perspective field of view [world] (deg).
public float FovDeg { get; set; }
Property Value
- See Also
FrameRate
Stats the number of render per sec given by latest rendered frames.
public float FrameRate { get; set; }
Property Value
GLContext
Gl context reference ( retrieved through gl model ).
public GLContext GLContext { get; }
Property Value
GLModel
Gl model associated to this control.
public GLModel GLModel { get; }
Property Value
ID
unique control ID
public string ID { get; }
Property Value
IdentifyCoord
If true an overlay display vertex under mouse coord.
public bool IdentifyCoord { get; set; }
Property Value
IsControlInvalidated
Triggered by control view/preferences and by model lights changes.
public bool IsControlInvalidated { get; }
Property Value
IsInitial
States if this gl control is the initial created into a gl split view.
public bool IsInitial { get; }
Property Value
IsRenderInvalidated
States if last render transferred is actually invalidated respect to the gl model or this gl control view/preferences.
Evaluated in Render(IRenderDevice?) to avoid re-entrance.
public bool IsRenderInvalidated { get; }
Property Value
IsRendering
States if rendering is in progress.
Its used by Render(IRenderDevice?) and Invalidate(InvalidateEnum) to avoid re-entrance from RenderInvalidated event callback.
public bool IsRendering { get; }
Property Value
LastCameraView
public CameraViewType? LastCameraView { get; }
Property Value
LastRenderTime
Time (sec) required for latest render.
public float LastRenderTime { get; set; }
Property Value
MainShader
Main shader ( retrieved from gl context ).
public GLPipeline MainShader { get; }
Property Value
ModelMatrix
ModelMatrix [local] of this control.
public Matrix4x4 ModelMatrix { get; set; }
Property Value
- See Also
ModelMatrixFmt
Formatted version of model matrix.
public string? ModelMatrixFmt { get; }
Property Value
Near
Near clipping plane distance [world].
public float Near { get; set; }
Property Value
- See Also
NormalShader
Geometry shader used if ShowNormals enabled ( retrieved from gl context ).
public GLPipeline NormalShader { get; }
Property Value
OrthoZoom
Ortho zoom [eye] factor.
public float OrthoZoom { get; set; }
Property Value
- See Also
Perspective
If true perspective projection matrix will be used, orthogonal projection matrix elsewhere. (default:true)
public bool Perspective { get; set; }
Property Value
- See Also
PointerCoord
Actual pointer coord [screen]
public Vector2 PointerCoord { get; set; }
Property Value
PointerLRayCast
Actual pointer raycast [local]
public Line? PointerLRayCast { get; }
Property Value
ProjectionMatrix
ProjectionMatrix [eye].
public Matrix4x4 ProjectionMatrix { get; set; }
Property Value
- See Also
ProjectionMatrixFmt
Formatted version of project matrix.
public string? ProjectionMatrixFmt { get; }
Property Value
RenderCount
Stats the count of completed Render(IRenderDevice?) calls.
public int RenderCount { get; }
Property Value
RotationCenter
Rotation center [local].
public Vector3 RotationCenter { get; }
Property Value
ScreenModelMatrix
Screen model matrix [world].
public Matrix4x4 ScreenModelMatrix { get; set; }
Property Value
- See Also
ScreenProjectionMatrix
ScreenProjectionMatrix [eye].
public Matrix4x4 ScreenProjectionMatrix { get; set; }
Property Value
- See Also
ShadeWithEdge
If true a geometry shader will generate addictional lines that marks triangle edges if displayed in shaded mode.
public bool ShadeWithEdge { get; set; }
Property Value
ShadeWithEdgeShader
Geometry shader used if ShadeWithEdge enabled ( retrieved from gl context ).
public GLPipeline ShadeWithEdgeShader { get; }
Property Value
ShadowHeight
Shadow height (pixels)
public uint ShadowHeight { get; set; }
Property Value
ShadowWidth
Shadow width (pixels)
public uint ShadowWidth { get; set; }
Property Value
ShowCameraObject
If true a green camera frustum object represented with lines are displayed using a temporary vertex manager at runtime.
public bool ShowCameraObject { get; set; }
Property Value
ShowModelBBox
If true the model bbox as lines are displayed using a temporary vertex manager at runtime.
public bool ShowModelBBox { get; set; }
Property Value
ShowNormals
If true a geometry shader will create yellow vertex normals using a size specified by a factor of the bbox.
public bool ShowNormals { get; set; }
Property Value
- See Also
Tag
User defined object.
public object? Tag { get; set; }
Property Value
Title
Title
public string Title { get; set; }
Property Value
UseShadow
If true and at least one point light exists in the gl model shadows are dropped, no shadow elsewhere (default:true).
public bool UseShadow { get; set; }
Property Value
UseTexture
If true triangles with texture will display the texture, empty elsewhere. (default:true)
public bool UseTexture { get; set; }
Property Value
VertexVisbiility
If true a geometry shader will generate addictional point that marks primitive vertexes.
public bool VertexVisbiility { get; set; }
Property Value
VertexVisibilityLineShader
Geometry shader used to show line vertexes if VertexVisbiility enabled ( retrieved from gl context ).
public GLPipeline VertexVisibilityLineShader { get; }
Property Value
VertexVisibilityTriShader
Geometry shader used to show triangle vertexes if VertexVisbiility enabled ( retrieved from gl context ).
public GLPipeline VertexVisibilityTriShader { get; }
Property Value
ViewMatrix
ViewMatrix [world] of this control.
public Matrix4x4 ViewMatrix { get; set; }
Property Value
- See Also
ViewMatrixFmt
Formatted version of view matrix.
public string? ViewMatrixFmt { get; }
Property Value
Wireframe
If true triangles will be displayed using lines, shaded elsewhere (default:false).
public bool Wireframe { get; set; }
Property Value
Methods
CameraRotate(float, float, bool)
Rotate the camera [view] a given rotation center [local]. ( not yet tested )
public void CameraRotate(float sAngleXRad, float sAngleYRad, bool invalidate = true)
Parameters
- See Also
CameraRotateDown()
Rotate the camera down of a little factor.
public void CameraRotateDown()
CameraRotateLeft()
Rotate the camera left of little factor.
public void CameraRotateLeft()
CameraRotateRight()
Rotate the camera right of a little factor.
public void CameraRotateRight()
CameraRotateUp()
Rotate the camera up of a little factor.
public void CameraRotateUp()
CameraView(CameraViewType, bool, bool)
Set the view using given cube view type.
public void CameraView(CameraViewType type, bool zoomFit = true, bool invalidate = true)
Parameters
type
CameraViewTypeCube view type CameraViewType.
zoomFit
boolIf true execute a zoom fit (Default: true).
invalidate
boolIf true refresh the scene.
CameraZoom(float, bool)
Zoom eye space by given scale factor.
public void CameraZoom(float scale, bool invalidate = true)
Parameters
- See Also
CameraZoomIn(float, bool)
Zoom in eye space.
public void CameraZoomIn(float scale = 0.1, bool invalidate = true)
Parameters
CameraZoomOut(float, bool)
Zoom out eye space.
public void CameraZoomOut(float scale = 0.1, bool invalidate = true)
Parameters
CaptureImage(string)
Capture an image of current control using offscreen render device and actual rendere device size.
public void CaptureImage(string offscreenPathfilename)
Parameters
offscreenPathfilename
stringPathfilename where to save the capture.
CaptureImage(string, int, int)
Capture an image of current control using offscreen render device with given render device size.
public void CaptureImage(string offscreenPathfilename, int w, int h)
Parameters
offscreenPathfilename
stringPathfilename where to save the capture.
w
intWidth of capture image (pixels).
h
intHeight of capture image (pixels).
GetGLMatrixes()
Retrieve model/view/projection matrixes and camera pos/target/up through a single object.
public GLMatrixes GetGLMatrixes()
Returns
GetViewNfo(bool)
Retrieve actual view config.
public ViewNfo GetViewNfo(bool includeLights = true)
Parameters
includeLights
boolIf true (default) lights will saved within view nfo.
Returns
- See Also
Invalidate(InvalidateEnum)
Regenerate the model with BuildModel if this is the first invalidation
or the invalidate argument is of type RebuildModelAndRedraw.
Emits a RenderInvalidated event that avalonia gl control will intercept to update the render surface.
public void Invalidate(InvalidateEnum invalidate = InvalidateEnum.RedrawOnly)
Parameters
invalidate
InvalidateEnumType of invalidation (Default:RedrawOnly).
InvalidateAll()
All gl split control invalidation.
public void InvalidateAll()
LoadView(string?)
Restore current view config from given pathfilename.
public void LoadView(string? pathfilename = null)
Parameters
pathfilename
string
- See Also
ModelRotate(double, double, Vector3?, GLMatrixes?, bool)
Rotate the model by given [eye] x,y angles around given [local] rotation center.
public void ModelRotate(double angleXRad, double angleYRad, Vector3? rot_center = null, GLMatrixes? mFrom = null, bool invalidate = true)
Parameters
angleXRad
doubleEye space x angle rotation (rad).
angleYRad
doubleEye space y angle rotation (rad).
rot_center
Vector3?(Optional) Local space (x,y,z) rotation center [local].
mFrom
GLMatrixes(Optional) gl matrixes at rotation start.
invalidate
boolIf true refresh the scene.
ModelRotateDown()
Rotate the model down of a little factor.
public void ModelRotateDown()
ModelRotateLeft()
Rotate the model left of a little factor.
public void ModelRotateLeft()
ModelRotateRight()
Rotate the model right of a little factor.
public void ModelRotateRight()
ModelRotateUp()
Rotate the model up of a little factor.
public void ModelRotateUp()
OnPropertyChanged(string?)
invoke this method to forward propertchanged event notification. note: not needed to specify propertyName set by compiler service to called property.
protected void OnPropertyChanged(string? propertyName = null)
Parameters
propertyName
string
Pan(in Vector2, in Vector2, GLMatrixes?, bool)
Pan the view by the given screen translation.
public void Pan(in Vector2 screenFrom, in Vector2 screenTo, GLMatrixes? mFrom = null, bool invalidate = true)
Parameters
screenFrom
Vector2Pan screen position from.
screenTo
Vector2Pan screen position to.
mFrom
GLMatrixes(Optional) begin pan matrixes.
invalidate
boolIf true refresh the scene.
- See Also
-
PerspectivePan(in Vector3, in Vector2, in Vector2, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, out Vector3, out Vector3)
PanDown()
Pan the view down of a little factor
public void PanDown()
PanLeft()
Pan the view left of a little factor.
public void PanLeft()
PanRight()
Pan the view right of a little factor.
public void PanRight()
PanUp()
Pan the view up of a little factor.
public void PanUp()
RayCastLocal(in Vector2)
Create a raycast Line suitable for hit test of figure primitives.
public Line RayCastLocal(in Vector2 screen)
Parameters
screen
Vector2Screen coord (x,y) [screen].
Returns
Examples
Example \snippet{'trimleft'} example-0007/Program.cs RayCast
Render(IRenderDevice?)
Main gl render process.
public void Render(IRenderDevice? device = null)
Parameters
device
IRenderDeviceTarget render surface.
SaveView(string?)
Save actual view info to given pathfilename.
A Notification GLControl.NotificationRequest event emitted.
ViewDefaultPathfilename
public void SaveView(string? pathfilename = null)
Parameters
pathfilename
string
SetRotationCenter(bool)
Set the rotation center for model and camera.
public void SetRotationCenter(bool keepSelection = false)
Parameters
keepSelection
boolIf false (Default) the active selection will cleared and mode back to view gesture.
SetViewNfo(ViewNfo, bool)
Restore current view config.
public void SetViewNfo(ViewNfo nfo, bool includeLights = true)
Parameters
- See Also
Size()
Get render surface size (pixels).
public Vector2 Size()
Returns
SwitchSelectionMode(bool)
Switch (model) selection mode.
public void SwitchSelectionMode(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
Tilt(float, bool)
Tilt camera [view] by rotating it's up vector around [view] z axis.
public void Tilt(float angleDeg = 2, bool invalidate = true)
Parameters
- See Also
TiltLeft()
Tilt the camera left of a little factor.
public void TiltLeft()
TiltRight()
Titl the camera right of a little factor.
public void TiltRight()
ToggleCameraObject(bool)
Toggle display of camera frustum object ( generated at runtime through a temporary vertex manager ).
public void ToggleCameraObject(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
ToggleIdentifyCoord()
Toggle identify vertex coord.
public void ToggleIdentifyCoord()
TogglePerspective(bool)
Toggle perspective mode.
public void TogglePerspective(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ToggleShadeWithEdge(bool)
Toggle shade with edge.
public void ToggleShadeWithEdge(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ToggleShowModelBBox(bool)
Toggle display of model bounding box ( generated at runtime through a temporary vertex manager ).
public void ToggleShowModelBBox(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
ToggleShowNormals(bool)
Toggle show normals.
public void ToggleShowNormals(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ToggleUseShadow(bool)
Toggle shadows generation.
public void ToggleUseShadow(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ToggleUseTexture(bool)
Toggle use of textures.
public void ToggleUseTexture(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ToggleVertexVisibility(bool)
Toggle vertex visibility.
public void ToggleVertexVisibility(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
ToggleWireframe(bool)
Toggle wireframe mode.
public void ToggleWireframe(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
ZoomFit(bool)
Fit gl model into the view.
public void ZoomFit(bool invalidate = true)
Parameters
invalidate
boolIf true refresh the scene.
- See Also
Events
InvalidateAllRequest
public event EventHandler? InvalidateAllRequest
Event Type
NotEmptyRenderPreview
Event generated at first non bbox empty render generated.
public event RenderPreviewDelegate? NotEmptyRenderPreview
Event Type
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged
Event Type
RenderInvalidated
Event emitted when Invalidate(InvalidateEnum) called.
Handled by avalonia gl control to execute the Render(IRenderDevice?) and transfer gl pixels to the device target surface.
public event EventHandler? RenderInvalidated