Table of Contents

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 GLControl

Gl control template to config this new one created.

device IRenderDevice

Target 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 GLModel

Gl model.

device IRenderDevice

Target render device.

Properties

AutoAdjustNearFar

Auto adjust near,far to prevent z-fighting.

public bool AutoAdjustNearFar { get; set; }

Property Value

bool
See Also

CameraPos

CameraPos [world].

public Vector3 CameraPos { get; set; }

Property Value

Vector3

CameraTarget

CameraTarget [world].

public Vector3 CameraTarget { get; set; }

Property Value

Vector3

CameraUp

CameraUp [world]

public Vector3 CameraUp { get; set; }

Property Value

Vector3

ClearColor

Default scene background color ( Default: black ).

public Color ClearColor { get; set; }

Property Value

Color

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

ControlFigureVisibileDelegate

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

string

DepthShader

Depth only shader for shadow cube maps ( retrieved from gl context ).

public GLPipeline DepthShader { get; }

Property Value

GLPipeline

Device

Render device associateed to this control.

public IRenderDevice Device { get; }

Property Value

IRenderDevice

Far

Far clipping plane distance [world].

public float Far { get; set; }

Property Value

float
See Also

FovDeg

Perspective field of view [world] (deg).

public float FovDeg { get; set; }

Property Value

float
See Also

FrameRate

Stats the number of render per sec given by latest rendered frames.

public float FrameRate { get; set; }

Property Value

float

GLContext

Gl context reference ( retrieved through gl model ).

public GLContext GLContext { get; }

Property Value

GLContext

GLModel

Gl model associated to this control.

public GLModel GLModel { get; }

Property Value

GLModel

ID

unique control ID

public string ID { get; }

Property Value

string

IdentifyCoord

If true an overlay display vertex under mouse coord.

public bool IdentifyCoord { get; set; }

Property Value

bool

IsControlInvalidated

Triggered by control view/preferences and by model lights changes.

public bool IsControlInvalidated { get; }

Property Value

bool

IsInitial

States if this gl control is the initial created into a gl split view.

public bool IsInitial { get; }

Property Value

bool

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

bool

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

bool

LastCameraView

public CameraViewType? LastCameraView { get; }

Property Value

CameraViewType?

LastRenderTime

Time (sec) required for latest render.

public float LastRenderTime { get; set; }

Property Value

float

MainShader

Main shader ( retrieved from gl context ).

public GLPipeline MainShader { get; }

Property Value

GLPipeline

ModelMatrix

ModelMatrix [local] of this control.

public Matrix4x4 ModelMatrix { get; set; }

Property Value

Matrix4x4
See Also

ModelMatrixFmt

Formatted version of model matrix.

public string? ModelMatrixFmt { get; }

Property Value

string

Near

Near clipping plane distance [world].

public float Near { get; set; }

Property Value

float
See Also

NormalShader

Geometry shader used if ShowNormals enabled ( retrieved from gl context ).

public GLPipeline NormalShader { get; }

Property Value

GLPipeline

OrthoZoom

Ortho zoom [eye] factor.

public float OrthoZoom { get; set; }

Property Value

float
See Also

Perspective

If true perspective projection matrix will be used, orthogonal projection matrix elsewhere. (default:true)

public bool Perspective { get; set; }

Property Value

bool
See Also

PointerCoord

Actual pointer coord [screen]

public Vector2 PointerCoord { get; set; }

Property Value

Vector2

PointerLRayCast

Actual pointer raycast [local]

public Line? PointerLRayCast { get; }

Property Value

Line

ProjectionMatrix

ProjectionMatrix [eye].

public Matrix4x4 ProjectionMatrix { get; set; }

Property Value

Matrix4x4
See Also

ProjectionMatrixFmt

Formatted version of project matrix.

public string? ProjectionMatrixFmt { get; }

Property Value

string

RenderCount

Stats the count of completed Render(IRenderDevice?) calls.

public int RenderCount { get; }

Property Value

int

RotationCenter

Rotation center [local].

public Vector3 RotationCenter { get; }

Property Value

Vector3

ScreenModelMatrix

Screen model matrix [world].

public Matrix4x4 ScreenModelMatrix { get; set; }

Property Value

Matrix4x4
See Also

ScreenProjectionMatrix

ScreenProjectionMatrix [eye].

public Matrix4x4 ScreenProjectionMatrix { get; set; }

Property Value

Matrix4x4
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

bool

ShadeWithEdgeShader

Geometry shader used if ShadeWithEdge enabled ( retrieved from gl context ).

public GLPipeline ShadeWithEdgeShader { get; }

Property Value

GLPipeline

ShadowHeight

Shadow height (pixels)

public uint ShadowHeight { get; set; }

Property Value

uint

ShadowWidth

Shadow width (pixels)

public uint ShadowWidth { get; set; }

Property Value

uint

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

bool

ShowModelBBox

If true the model bbox as lines are displayed using a temporary vertex manager at runtime.

public bool ShowModelBBox { get; set; }

Property Value

bool

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

bool
See Also

Tag

User defined object.

public object? Tag { get; set; }

Property Value

object

Title

Title

public string Title { get; set; }

Property Value

string

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

bool

UseTexture

If true triangles with texture will display the texture, empty elsewhere. (default:true)

public bool UseTexture { get; set; }

Property Value

bool

VertexVisbiility

If true a geometry shader will generate addictional point that marks primitive vertexes.

public bool VertexVisbiility { get; set; }

Property Value

bool

VertexVisibilityLineShader

Geometry shader used to show line vertexes if VertexVisbiility enabled ( retrieved from gl context ).

public GLPipeline VertexVisibilityLineShader { get; }

Property Value

GLPipeline

VertexVisibilityTriShader

Geometry shader used to show triangle vertexes if VertexVisbiility enabled ( retrieved from gl context ).

public GLPipeline VertexVisibilityTriShader { get; }

Property Value

GLPipeline

ViewMatrix

ViewMatrix [world] of this control.

public Matrix4x4 ViewMatrix { get; set; }

Property Value

Matrix4x4
See Also

ViewMatrixFmt

Formatted version of view matrix.

public string? ViewMatrixFmt { get; }

Property Value

string

Wireframe

If true triangles will be displayed using lines, shaded elsewhere (default:false).

public bool Wireframe { get; set; }

Property Value

bool

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

sAngleXRad float
sAngleYRad float
invalidate bool

If true refresh the scene.

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 CameraViewType

Cube view type CameraViewType.

zoomFit bool

If true execute a zoom fit (Default: true).

invalidate bool

If true refresh the scene.

CameraZoom(float, bool)

Zoom eye space by given scale factor.

public void CameraZoom(float scale, bool invalidate = true)

Parameters

scale float

Zoom scale factor.

invalidate bool

If true refresh the scene.

See Also

CameraZoomIn(float, bool)

Zoom in eye space.

public void CameraZoomIn(float scale = 0.1, bool invalidate = true)

Parameters

scale float

Zoom in scale factor.

invalidate bool

If true refresh the scene.

CameraZoomOut(float, bool)

Zoom out eye space.

public void CameraZoomOut(float scale = 0.1, bool invalidate = true)

Parameters

scale float

Zoom out scale factor.

invalidate bool

If true refresh the scene.

CaptureImage(string)

Capture an image of current control using offscreen render device and actual rendere device size.

public void CaptureImage(string offscreenPathfilename)

Parameters

offscreenPathfilename string

Pathfilename 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 string

Pathfilename where to save the capture.

w int

Width of capture image (pixels).

h int

Height of capture image (pixels).

GetGLMatrixes()

Retrieve model/view/projection matrixes and camera pos/target/up through a single object.

public GLMatrixes GetGLMatrixes()

Returns

GLMatrixes

GetViewNfo(bool)

Retrieve actual view config.

public ViewNfo GetViewNfo(bool includeLights = true)

Parameters

includeLights bool

If true (default) lights will saved within view nfo.

Returns

ViewNfo
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 InvalidateEnum

Type 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 double

Eye space x angle rotation (rad).

angleYRad double

Eye 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 bool

If 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 Vector2

Pan screen position from.

screenTo Vector2

Pan screen position to.

mFrom GLMatrixes

(Optional) begin pan matrixes.

invalidate bool

If true refresh the scene.

See Also

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 Vector2

Screen coord (x,y) [screen].

Returns

Line

Examples

Example \snippet{'trimleft'} example-0007/Program.cs RayCast

Render(IRenderDevice?)

Main gl render process.

public void Render(IRenderDevice? device = null)

Parameters

device IRenderDevice

Target 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 bool

If 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

nfo ViewNfo

view config object

includeLights bool

If true (default) lights set to the model.

See Also

Size()

Get render surface size (pixels).

public Vector2 Size()

Returns

Vector2

SwitchSelectionMode(bool)

Switch (model) selection mode.

public void SwitchSelectionMode(bool invalidate = true)

Parameters

invalidate bool

If 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

angleDeg float

Tilt angle (deg) [view].

invalidate bool

If true refresh the scene.

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 bool

If 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 bool

If true refresh the scene.

See Also

ToggleShadeWithEdge(bool)

Toggle shade with edge.

public void ToggleShadeWithEdge(bool invalidate = true)

Parameters

invalidate bool

If 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 bool

If true refresh the scene.

ToggleShowNormals(bool)

Toggle show normals.

public void ToggleShowNormals(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

See Also

ToggleUseShadow(bool)

Toggle shadows generation.

public void ToggleUseShadow(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

See Also

ToggleUseTexture(bool)

Toggle use of textures.

public void ToggleUseTexture(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

See Also

ToggleVertexVisibility(bool)

Toggle vertex visibility.

public void ToggleVertexVisibility(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

ToggleWireframe(bool)

Toggle wireframe mode.

public void ToggleWireframe(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

See Also

ZoomFit(bool)

Fit gl model into the view.

public void ZoomFit(bool invalidate = true)

Parameters

invalidate bool

If true refresh the scene.

See Also

Events

InvalidateAllRequest

public event EventHandler? InvalidateAllRequest

Event Type

EventHandler

NotEmptyRenderPreview

Event generated at first non bbox empty render generated.

public event RenderPreviewDelegate? NotEmptyRenderPreview

Event Type

RenderPreviewDelegate

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler

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

Event Type

EventHandler