DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dueca::BareDuecaGLWindow Class Referenceabstract

This class provides a barebones, simple GL canvas for you to draw on, as an alternative to the toolkit-integrated DuecaGLWindow. More...

#include <BareDuecaGLWindow.hxx>

Public Member Functions

 BareDuecaGLWindow (const char *window_title="A DUECA GL window", bool pass_pointer=false, bool pass_keys=false, bool pass_passive=false, bool pointer_visible=false, unsigned display_periods=0, bool pass_touch=false)
 Construct a GL window based on X11 interaction.
 
bool setFullScreen (const bool &fs=true)
 Request full screen drawing – or not.
 
bool selectCursor (const int &cursor)
 Request a cursor type.
 
bool setWindow (const std::vector< int > &wpos)
 Set the window position, at least if the window manager will honour this.
 
void openWindow ()
 open the window.
 
void setWindow (int posx, int poxy, int width, int height)
 Set up the window initial position and size.
 
virtual ~BareDuecaGLWindow ()
 Destructor.
 
virtual void reshape (int x, int y)
 This is called if the size of the window is changed.
 
virtual void display ()=0
 This is called whenever the display needs to be redrawn.
 
virtual void initGL ()
 This is called when the window is ready, for first-time set-up.
 
void waitSwap ()
 Wait on the buffer swap.
 
void redraw ()
 Indicate that a redraw is required.
 
virtual void keyboard (unsigned char key, int x, int y)
 Called when a key is pressed, override to get key information.
 
virtual void special (int key, int x, int y)
 Called when a function key is pressed.
 
virtual void mouse (int button, int state, int x, int y)
 This is called whenever a mouse button event comes in.
 
virtual void motion (int x, int y)
 This is called whenever a mouse motion event comes in.
 
virtual void passive (int x, int y)
 This is called whenever a mouse motion event comes in, but none of the buttons are pressed.
 
virtual void touch (unsigned finger, bool s, float x, float y)
 This is called for touch events.
 
int getWidth ()
 Obtain the current widget width.
 
int getHeight ()
 Obtain the current widget height.
 
int getXOffset ()
 Obtain current widget x-position.
 
int getYOffset ()
 Obtain current widget y-position.
 
void swapBuffers ()
 Swapbuffers is only for compatibility with DuecaGLWindow.
 

Detailed Description

This class provides a barebones, simple GL canvas for you to draw on, as an alternative to the toolkit-integrated DuecaGLWindow.

It will directly open a window in the native windowing environment of your system.

You can use it to have a display that is synced to your graphics card retrace. In that case, either create a drawing class that derives from this BareDuecaGLWindow, or use double inheritance to derive a DUECA module also from this class.

In your doCalculation routine, use the following basic pattern. You need two variables defined in your class,

  1. claim_thread is a flag that indicates whether the drawing is in its own thread (a necessity for following the graphics card retrace) or not. Typically, you make this user-configurable.

  2. run_until is a TimeTickType, that is set in startModule and stopModule. Initialize to 0.

  3. have_to_open is a flag to remember to open the display. Initialize to true.

// at the start of your calculation loop:
canvas.openWindow();
have_to_open = false;
}
// this loop is done continuously for running in a claimed thread,
// once otherwise
do {
// if in an endless loop, record waiting for the next frame retrace and
// the buffer swap
if ( claim_thread ) {
do_calc.logBlockingWait();
canvas.waitSwap(); // or self->waitSwap();
do_calc.logBlockingWaitOver();
}
// check the current simulation time, and determine how much time passed
// since the clock ticked
TimeTickType current_tick = SimTime::getTimeTick();
int64_t frac = Ticker::single()->getUsecsSinceTick(current_tick);
// get the latest data from the simulation
try {
// use StreamReaderLatest to get to your data.
// if you can and need to, use the frac to extrapolate your data
// calculation to get difference between writing (logical time) and
// current time
DataTimeSpec span(r.timeSpec().getValidityStart(), current_tick);
double late = span.getDtInSeconds() + frac * 1e-6 + t_predict;
// with that, update your canvas state, or your own state if
// you inherited. For advanced simulations, use "late" to
// extrapolate
}
// redraw the image
canvas.redraw();
}
while (run_until >= SimTime::getTimeTick());
static TimeTickType getTimeTick()
Return the current time tick.
Definition SimTime.hxx:88
This is a "light weight object" that enables you to read the latest set of data on a StreamChannelEnd...
Definition StreamReaderLatest.hxx:43
static Ticker * single()
Make sure this class is callable from scheme.
Definition Ticker.hxx:277

startModule and stopModule need to be adjusted accordingly:

void MyCode::startModule(const TimeSpec &time)
{
do_calc.switchOn(time);
if (claim_thread) {
run_until = MAX_TIMETICK;
myalarm.requestAlarm(time.getValidityStart());
}
}
// stop the module
void MyCode::stopModule(const TimeSpec &time)
{
do_calc.switchOff(time);
if (claim_thread) {
run_until = time.getValidityEnd();
}
}
/endcode
By default run_until should be zero. myalarm and myclock give aperiodic and
periodic activation, so in your header, add:
\code
PeriodicAlarm myclock;
AperiodicAlarm myalarm;
A TimeSpec is a specification for a time interval.
Definition TimeSpec.hxx:71
TimeTickType getValidityStart() const
Returns the time at which the interval starts.
Definition TimeSpec.hxx:188

And depending on the mode, connect one or the other to your activity in your complete() method.

do_calc.setTrigger(myalarm);
}
else {
do_calc.setTrigger(myclock);
}

Instead of triggering on the time of your own clock, you can of course also trigger on incoming data.

Don't forget to adjust your clock's rate if you get passed a time spec

bool MyCode::setTimeSpec(const TimeSpec& ts)
{
// a time span of 0 is not acceptable
if (ts.getValiditySpan() == 0) return false;
// specify the timespec to the activity
myclock.changePeriodAndOffset(ts);
}
TimeTickType getValiditySpan() const
Returns the size of the interval.
Definition TimeSpec.hxx:196

Constructor & Destructor Documentation

◆ BareDuecaGLWindow()

dueca::BareDuecaGLWindow::BareDuecaGLWindow ( const char * window_title = "A DUECA GL window",
bool pass_pointer = false,
bool pass_keys = false,
bool pass_passive = false,
bool pointer_visible = false,
unsigned display_periods = 0,
bool pass_touch = false )

Construct a GL window based on X11 interaction.

Parameters
window_titleTitle for the window
pass_pointerPass pointer actions (clicks, release, drag) through the "mouse" callback
pass_keysPass keypresses through the "keyboard" and "special" callbacks
pass_passiveAlso pass passive mouse/pointer motion
pointer_visibleShow the pointer in the screen
display_periodsIf nonzero, attempt to sync to the display refresh, number indicates division
pass_touchPass touch events

Member Function Documentation

◆ setFullScreen()

bool dueca::BareDuecaGLWindow::setFullScreen ( const bool & fs = true)

Request full screen drawing – or not.

Can be linked to Scheme in a parameter table. Use this call before opening the window with openWindow.

◆ setWindow() [1/2]

bool dueca::BareDuecaGLWindow::setWindow ( const std::vector< int > & wpos)

Set the window position, at least if the window manager will honour this.

Can be linked to Scheme in a parameter table. Use this call before opening the window with openWindow.

◆ openWindow()

void dueca::BareDuecaGLWindow::openWindow ( )

open the window.

Take care to do this in the same thread as in which you will be running the drawing and waiting.

◆ setWindow() [2/2]

void dueca::BareDuecaGLWindow::setWindow ( int posx,
int poxy,
int width,
int height )

Set up the window initial position and size.

Honouring of initial position depends on the window manager. Use this call before opening the window with openWindow.

◆ reshape()

virtual void dueca::BareDuecaGLWindow::reshape ( int x,
int y )
virtual

This is called if the size of the window is changed.

You might need to update the image set-up for a different screen format.

◆ display()

virtual void dueca::BareDuecaGLWindow::display ( )
pure virtual

This is called whenever the display needs to be redrawn.

When called, the appropriate display context has been made current.

◆ initGL()

virtual void dueca::BareDuecaGLWindow::initGL ( )
virtual

This is called when the window is ready, for first-time set-up.

DO NOT CALL THIS FUNCTION YOURSELF! Override this function, and when it is called, you can assume the gl code is possible. So creating viewports, GL lists, allocating textures etc. can be done in initGL.

◆ redraw()

void dueca::BareDuecaGLWindow::redraw ( )

Indicate that a redraw is required.

This will set the context, and call your display routine.

◆ swapBuffers()

void dueca::BareDuecaGLWindow::swapBuffers ( )
inline

Swapbuffers is only for compatibility with DuecaGLWindow.

Does nothing.


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