BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
BrawlLib.OpenGL.GLPanel Class Reference
Inheritance diagram for BrawlLib.OpenGL.GLPanel:
BrawlLib.Internal.Windows.Controls.GLTexturePanel BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanel

Public Member Functions

 GLPanel ()
 
void ClearViewports ()
 
void AddViewport (GLViewport v)
 
void RemoveViewport (GLViewport v)
 
void RemoveViewport (int index)
 
void FitViewports ()
 
void BeginUpdate ()
 
void EndUpdate ()
 
new void Capture ()
 
void Release ()
 
GLViewport GetViewport (int x, int y)
 
virtual void CreateDefaultViewport ()
 
float GetDepth (Vector2 v)
 
virtual float GetDepth (int x, int y)
 
Vector3 TraceZ (Vector3 point, float z)
 
IEnumerator< GLViewportGetEnumerator ()
 

Protected Member Functions

override void Dispose (bool disposing)
 
override void OnLoad (EventArgs e)
 
virtual void OnReset (object sender, EventArgs e)
 
virtual void OnContextChanged (bool isNowCurrent)
 
override void DestroyHandle ()
 
override void OnHandleDestroyed (EventArgs e)
 
override void OnPaintBackground (PaintEventArgs e)
 
override void OnPaint (PaintEventArgs e)
 
override void OnMouseMove (MouseEventArgs e)
 
override void OnResize (EventArgs e)
 
virtual void OnRender (PaintEventArgs e)
 
virtual void OnRenderViewport (PaintEventArgs e, GLViewport v)
 

Protected Attributes

TKContext _ctx
 
int _updateCounter
 
GLViewport _currentViewport
 
GLViewport _highlightedViewport
 
List< GLViewport_viewports = new List<GLViewport>()
 

Properties

static GLPanel Current [get]
 
TKContext Context [get]
 
GLViewport HighlightedViewport [get]
 
GLViewport CurrentViewport [get, set]
 

Events

ViewportAction OnCurrentViewportChanged
 

Constructor & Destructor Documentation

◆ GLPanel()

BrawlLib.OpenGL.GLPanel.GLPanel ( )
inline
94 {
95 SetStyle(
96 ControlStyles.UserPaint |
97 ControlStyles.AllPaintingInWmPaint |
98 ControlStyles.Opaque |
99 ControlStyles.ResizeRedraw,
100 true);
101
102 _viewports = new List<GLViewport>();
103 }
List< GLViewport > _viewports
Definition: GLPanel.cs:51

Member Function Documentation

◆ AddViewport()

void BrawlLib.OpenGL.GLPanel.AddViewport ( GLViewport  v)
inline
117 {
118 _viewports.Add(v);
119 v._owner = this;
120 v.Resize();
121 v.OnInvalidate += Invalidate;
122 }

◆ BeginUpdate()

void BrawlLib.OpenGL.GLPanel.BeginUpdate ( )
inline
240 {
242 }
int _updateCounter
Definition: GLPanel.cs:48

◆ Capture()

new void BrawlLib.OpenGL.GLPanel.Capture ( )
inline
253 {
254 if (InvokeRequired)
255 {
256 Invoke(new Action(Capture));
257 return;
258 }
259
260 if (_ctx == null)
261 {
262 _ctx = new TKContext(this);
263 }
264
265 _ctx.Capture();
266 }
new void Capture()
Definition: GLPanel.cs:252
TKContext _ctx
Definition: GLPanel.cs:44
void Capture(bool force=false)
Definition: TKContext.cs:126

◆ ClearViewports()

void BrawlLib.OpenGL.GLPanel.ClearViewports ( )
inline
106 {
107 foreach (GLViewport v in _viewports)
108 {
109 v._owner = null;
110 v.OnInvalidate -= Invalidate;
111 }
112
113 _viewports.Clear();
114 }

◆ CreateDefaultViewport()

virtual void BrawlLib.OpenGL.GLPanel.CreateDefaultViewport ( )
inlinevirtual

Reimplemented in BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanel.

353 {
354 AddViewport(GLViewport.DefaultPerspective);
355 }
void AddViewport(GLViewport v)
Definition: GLPanel.cs:116

◆ DestroyHandle()

override void BrawlLib.OpenGL.GLPanel.DestroyHandle ( )
inlineprotected
308 {
309 DisposeContext();
310 base.DestroyHandle();
311 }

◆ Dispose()

override void BrawlLib.OpenGL.GLPanel.Dispose ( bool  disposing)
inlineprotected
150 {
151 DisposeContext();
152 base.Dispose(disposing);
153 }

◆ EndUpdate()

void BrawlLib.OpenGL.GLPanel.EndUpdate ( )
inline
245 {
246 if ((_updateCounter = Math.Max(_updateCounter - 1, 0)) == 0)
247 {
248 Invalidate();
249 }
250 }

◆ FitViewports()

void BrawlLib.OpenGL.GLPanel.FitViewports ( )
inline
166 {
167 //TODO: this doesn't work right in every circumstance
168
169 foreach (GLViewport v in _viewports)
170 {
171 Vector4 p = v.Percentages;
172 GLViewport x = null, y = null, z = null, w = null;
173 Vector4 diff = new Vector4(float.MaxValue);
174 foreach (GLViewport v2 in _viewports)
175 {
176 if (v2 == v)
177 {
178 continue;
179 }
180
181 float diff2 = Math.Abs(p._x - v2.Percentages._x);
182 if (diff2 <= diff._x)
183 {
184 x = v2;
185 diff._x = diff2;
186 }
187
188 diff2 = Math.Abs(p._y - v2.Percentages._y);
189 if (diff2 <= diff._y)
190 {
191 y = v2;
192 diff._y = diff2;
193 }
194
195 diff2 = Math.Abs(p._z - v2.Percentages._z);
196 if (diff2 <= diff._z)
197 {
198 z = v2;
199 diff._z = diff2;
200 }
201
202 diff2 = Math.Abs(p._w - v2.Percentages._w);
203 if (diff2 <= diff._w)
204 {
205 w = v2;
206 diff._w = diff2;
207 }
208 }
209
210 Vector4 average = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
211 if (diff._x > 0.0f && x != null)
212 {
213 average._x = (v.Percentages._x + x.Percentages._x) / 2.0f;
214 x.SetXPercentage(average._x);
215 }
216
217 if (diff._y > 0.0f && y != null)
218 {
219 average._y = (v.Percentages._y + y.Percentages._y) / 2.0f;
220 y.SetYPercentage(average._y);
221 }
222
223 if (diff._z > 0.0f && z != null)
224 {
225 average._z = (v.Percentages._z + z.Percentages._z) / 2.0f;
226 z.SetZPercentage(average._z);
227 }
228
229 if (diff._w > 0.0f && w != null)
230 {
231 average._w = (v.Percentages._w + w.Percentages._w) / 2.0f;
232 w.SetWPercentage(average._w);
233 }
234
235 v.SetPercentages(average);
236 }
237 }
Definition: Vector4.cs:12
float _x
Definition: Vector4.cs:13
float _z
Definition: Vector4.cs:13
float _y
Definition: Vector4.cs:13
float _w
Definition: Vector4.cs:13

◆ GetDepth() [1/2]

virtual float BrawlLib.OpenGL.GLPanel.GetDepth ( int  x,
int  y 
)
inlinevirtual
363 {
364 float val = 0;
365 GL.ReadPixels(x, Height - y, 1, 1, PixelFormat.DepthComponent, PixelType.Float,
366 ref val);
367 return val;
368 }

◆ GetDepth() [2/2]

float BrawlLib.OpenGL.GLPanel.GetDepth ( Vector2  v)
inline
358 {
359 return GetDepth((int) (v._x + 0.5f), (int) (v._y + 0.5f));
360 }
float GetDepth(Vector2 v)
Definition: GLPanel.cs:357
float _y
Definition: Vector2.cs:17
float _x
Definition: Vector2.cs:11

◆ GetEnumerator()

IEnumerator< GLViewport > BrawlLib.OpenGL.GLPanel.GetEnumerator ( )
inline
501 {
502 return _viewports.GetEnumerator();
503 }

◆ GetViewport()

GLViewport BrawlLib.OpenGL.GLPanel.GetViewport ( int  x,
int  y 
)
inline
324 {
325 if (_viewports.Count == 1)
326 {
327 return _viewports[0];
328 }
329
330 x = x.Clamp(0, Width);
331 y = Height - y.Clamp(0, Height);
332
333 foreach (GLViewport w in _viewports)
334 {
335 if (x >= w.Region.X &&
336 x <= w.Region.X + w.Region.Width &&
337 y >= w.Region.Y &&
338 y <= w.Region.Y + w.Region.Height)
339 {
340 return w;
341 }
342 }
343
344 if (_viewports.Count == 0)
345 {
347 }
348
349 return _viewports[0];
350 }
virtual void CreateDefaultViewport()
Definition: GLPanel.cs:352

◆ OnContextChanged()

virtual void BrawlLib.OpenGL.GLPanel.OnContextChanged ( bool  isNowCurrent)
inlineprotectedvirtual

Reimplemented in BrawlLib.Internal.Windows.Controls.Model_Panel.ModelPanel.

297 {
298 //Don't update anything if this context has just been released
299 if (isNowCurrent)
300 {
301 OnResize(EventArgs.Empty);
302 }
303
304 _currentPanel = isNowCurrent ? this : null;
305 }
override void OnResize(EventArgs e)
Definition: GLPanel.cs:463

◆ OnHandleDestroyed()

override void BrawlLib.OpenGL.GLPanel.OnHandleDestroyed ( EventArgs  e)
inlineprotected
314 {
315 DisposeContext();
316 base.OnHandleDestroyed(e);
317 }

◆ OnLoad()

override void BrawlLib.OpenGL.GLPanel.OnLoad ( EventArgs  e)
inlineprotected
274 {
275 _ctx = new TKContext(this);
276
277 Capture();
278
279 Vector3 v = (Vector3) BackColor;
280 GL.ClearColor(v._x, v._y, v._z, 0.0f);
281 GL.ClearDepth(1.0);
282
283 OnInit(_ctx);
284
285 _ctx.ContextChanged += OnContextChanged;
286 _ctx.ResetOccured += OnReset;
287
288 base.OnLoad(e);
289 }
virtual void OnContextChanged(bool isNowCurrent)
Definition: GLPanel.cs:296
virtual void OnReset(object sender, EventArgs e)
Definition: GLPanel.cs:291
Definition: Vector3.cs:40
float _y
Definition: Vector3.cs:41
float _z
Definition: Vector3.cs:41
float _x
Definition: Vector3.cs:41

◆ OnMouseMove()

override void BrawlLib.OpenGL.GLPanel.OnMouseMove ( MouseEventArgs  e)
inlineprotected
412 {
413 if (_viewports.Count > 1)
414 {
416 }
417
418 base.OnMouseMove(e);
419 }
GLViewport GetViewport(int x, int y)
Definition: GLPanel.cs:323
GLViewport _highlightedViewport
Definition: GLPanel.cs:50

◆ OnPaint()

override void BrawlLib.OpenGL.GLPanel.OnPaint ( PaintEventArgs  e)
inlineprotected
371 {
372 if (_updateCounter > 0)
373 {
374 return;
375 }
376
377 if (_ctx == null)
378 {
379 base.OnPaint(e);
380 }
381 else if (Monitor.TryEnter(_ctx))
382 {
383 try
384 {
385 //Direct OpenGL calls to this panel
386 Capture();
387
388 OnRender(e);
389
390 //Display newly rendered back buffer
391 _ctx.Swap();
392
393 //Check for errors
394 ErrorCode code = GL.GetError();
395 if (code != ErrorCode.NoError)
396 {
397 this.Reset(); //Stops the red X of death in its tracks
398 }
399 }
400 finally
401 {
402 Monitor.Exit(_ctx);
403 }
404 }
405 }
virtual void OnRender(PaintEventArgs e)
Definition: GLPanel.cs:475
void Swap()
Definition: TKContext.cs:153

◆ OnPaintBackground()

override void BrawlLib.OpenGL.GLPanel.OnPaintBackground ( PaintEventArgs  e)
inlineprotected
320 {
321 }

◆ OnRender()

virtual void BrawlLib.OpenGL.GLPanel.OnRender ( PaintEventArgs  e)
inlineprotectedvirtual

Reimplemented in BrawlLib.Internal.Windows.Controls.GLTexturePanel.

476 {
477 GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
478 foreach (GLViewport v in _viewports)
479 {
480 OnRenderViewport(e, v);
481 }
482
483 Wii.Graphics.ShaderGenerator._forceRecompile = false;
484 }
virtual void OnRenderViewport(PaintEventArgs e, GLViewport v)
Definition: GLPanel.cs:486

◆ OnRenderViewport()

virtual void BrawlLib.OpenGL.GLPanel.OnRenderViewport ( PaintEventArgs  e,
GLViewport  v 
)
inlineprotectedvirtual

◆ OnReset()

virtual void BrawlLib.OpenGL.GLPanel.OnReset ( object  sender,
EventArgs  e 
)
inlineprotectedvirtual
292 {
293 OnInit(_ctx);
294 }

◆ OnResize()

override void BrawlLib.OpenGL.GLPanel.OnResize ( EventArgs  e)
inlineprotected
464 {
465 _ctx?.Update();
466
467 foreach (GLViewport v in _viewports)
468 {
469 v.Resize();
470 }
471
472 Invalidate();
473 }
void Update()
Definition: TKContext.cs:208

◆ Release()

void BrawlLib.OpenGL.GLPanel.Release ( )
inline
269 {
270 _ctx?.Release();
271 }
void Release()
Definition: TKContext.cs:197

◆ RemoveViewport() [1/2]

void BrawlLib.OpenGL.GLPanel.RemoveViewport ( GLViewport  v)
inline
125 {
126 if (_viewports.Contains(v))
127 {
128 v._owner = null;
129 v.OnInvalidate -= Invalidate;
130 _viewports.Remove(v);
131 FitViewports();
132 Invalidate();
133 }
134 }
void FitViewports()
Definition: GLPanel.cs:165

◆ RemoveViewport() [2/2]

void BrawlLib.OpenGL.GLPanel.RemoveViewport ( int  index)
inline
137 {
138 if (index < 0 || index >= _viewports.Count)
139 {
140 return;
141 }
142
143 GLViewport v = _viewports[index];
144 v._owner = null;
145 v.OnInvalidate -= Invalidate;
146 _viewports.RemoveAt(index);
147 }

◆ TraceZ()

Vector3 BrawlLib.OpenGL.GLPanel.TraceZ ( Vector3  point,
float  z 
)
inline
422 {
423 GLCamera camera = CurrentViewport.Camera;
424 if (camera == null)
425 {
426 return new Vector3();
427 }
428
429 double a = point._z - z;
430 //Perform trig functions, using camera for angles
431
432 //Get angle, truncating to MOD 180
433 //double angleX = _camera._rotation._y - ((int)(_camera._rotation._y / 180.0) * 180);
434
435 double angleX = Math.IEEERemainder(-camera._rotation._y, 180.0);
436 if (angleX < -90.0f)
437 {
438 angleX = -180.0f - angleX;
439 }
440
441 if (angleX > 90.0f)
442 {
443 angleX = 180.0f - angleX;
444 }
445
446 double angleY = Math.IEEERemainder(camera._rotation._x, 180.0);
447 if (angleY < -90.0f)
448 {
449 angleY = -180.0f - angleY;
450 }
451
452 if (angleY > 90.0f)
453 {
454 angleY = 180.0f - angleY;
455 }
456
457 float lenX = (float) (Math.Tan(angleX * Math.PI / 180.0) * a);
458 float lenY = (float) (Math.Tan(angleY * Math.PI / 180.0) * a);
459
460 return new Vector3(point._x + lenX, point._y + lenY, z);
461 }
GLViewport CurrentViewport
Definition: GLPanel.cs:60
GLCamera Camera
Definition: GLViewport.cs:54

Member Data Documentation

◆ _ctx

TKContext BrawlLib.OpenGL.GLPanel._ctx
protected

◆ _currentViewport

GLViewport BrawlLib.OpenGL.GLPanel._currentViewport
protected

◆ _highlightedViewport

GLViewport BrawlLib.OpenGL.GLPanel._highlightedViewport
protected

◆ _updateCounter

int BrawlLib.OpenGL.GLPanel._updateCounter
protected

◆ _viewports

List<GLViewport> BrawlLib.OpenGL.GLPanel._viewports = new List<GLViewport>()
protected

Property Documentation

◆ Context

TKContext BrawlLib.OpenGL.GLPanel.Context
get

◆ Current

GLPanel BrawlLib.OpenGL.GLPanel.Current
staticget
29 {
30 get
31 {
32 if (_currentPanel == null && TKContext.CurrentContext != null)
33 {
34 TKContext.CurrentContext.Capture(true);
35 }
36
37 return _currentPanel;
38 }
39 }

◆ CurrentViewport

GLViewport BrawlLib.OpenGL.GLPanel.CurrentViewport
getset
60 {
61 get
62 {
63 if (_currentViewport == null)
64 {
65 if (_viewports.Count == 0)
66 {
68 }
69
71 }
72
73 if (_currentViewport._owner != this)
74 {
75 _currentViewport._owner = this;
76 }
77
78 return _currentViewport;
79 }
80 set
81 {
82 _currentViewport = value;
83
85
86 if (!_viewports.Contains(_currentViewport) && _currentViewport != null)
87 {
89 }
90 }
91 }
ViewportAction OnCurrentViewportChanged
Definition: GLPanel.cs:46
GLViewport _currentViewport
Definition: GLPanel.cs:49

◆ HighlightedViewport

GLViewport BrawlLib.OpenGL.GLPanel.HighlightedViewport
get

Event Documentation

◆ OnCurrentViewportChanged

ViewportAction BrawlLib.OpenGL.GLPanel.OnCurrentViewportChanged

The documentation for this class was generated from the following file: