Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

GLElement

Samuel Gratzl edited this page Dec 4, 2013 · 2 revisions

GLElement is the new approach for creating a structured objected oriented way for creating OpenGL based visualizations.

Basic Concepts

important classes:

  • GLElement is the basic element
  • GLElementContainer composite pattern implementation. It uses a IGLLayout2 layouter object to position children
  • AnimatedGLElementContainer similar to GLElementContainer but the transition between different layout result will be animated.
  • GLElementDecorator decorator / wrapper over another GLElement
  • PickableGLElement every GLElement can be made pickable, this special subclass is just a utility to simplify this task and react on picking events

Renderers

besides the elements itself renderers (IGLRenderer) are used for rendering simple task. For example to add an element, which renders a simple colored quad, you could either create a subclass of a GLElement and render the quad or just instantiate a GLElement and give it a corresponding renderer.

Basic UI classes

  • GLButton
  • GLSpinner
  • GLComboBox
  • GLSlider

Picking

Every GLElement has two different render stages: render and picking. The former one will be displayed to the use, while the latter one will be used for picking. The advantages of splitting this two render stages are:

  • simpler picking you normally just need to render a simple quad for picking, while the rendering stage could render a text, color, stashing,...
  • better caching it is often the case that you need to adapt the rendering to user interaction, e.g. change the color if the user hovers the element. However, this won't affect the picking at all, which therefore can be simpler cached.

PickingIds

Every element needs to be enabled to be pickable by setting the visibility of the element to PICKABLE. Afterwards IPickingListener can be registered using the onPick method. A simplified version is to use the PickableGLElement, which already registered a picking listener and provides simple methods to override.

Besides the single picking id per element, one can request and manage additional picking ids by its own. During the init phase, one can request additional picking ids from the context. Be sure, that you release the picking ids again, during the takeDown phase. Additional utility class PickingPool for managing a range of picking ids, targeting the same picking listener but with different picking object ids.

Caching

You normally don't need to care about putting the content of an GLElement into a display list. This will be automatically handled for you. To be more precise, every element has an internal state, how long it is stable (= no repaint request during the last render stage). If the element is stable and the content is complex enough, it will be cached within a display list. Depending on the type of the element this could include a whole subtree of element tree.

The caching is done for the render and picking state independently. A important step is to notify the element that should be repainted, either using repaint, repaintPick or repaintAll. The last one is just a shorthand for calling both previous methods. If you call one of the methods all parent element as well as itself will be queued for repainting and all associated caches will be deleted.