Chapter 4: Using Augments
|
image by George Hagerman,
hagerman@vt.edu |
[Back]
[Up]
[Next]
4.1 What are Augments?
Augments are a plug in architechture for dgiGL applications. No additional
coding is required on the part of the application programmer in order to use
augments. Augments are used to carry out actions automatically at critical
times. Specifically, augments provide opportunities for callbacks before
::config
is called, after ::config
is called, before
each frame, and after each frame. Furthermore, as we will learn, augments
do not have to be implemented in the application program. They can be loaded
from precompiled dynimically shared objects at run time.
4.1.1 Code for a Simple Augment
simple_augment.C
#include
#include
#include "dgiGL.H"
simple_augment : public dgiGLAugment
{
public:
simple_augment(dgiGL *app);
int preConfig(void);
int postConfig(void);
int preFrame(void);
int postFrame(void);
};
simple_augment::simple_augment(dgiGL *app)
{
printf("==> simple_augment Constructor Here\n");
validate();
}
int simple_augment::preConfig(void)
{
printf("==> simple_augment::preConfig Here\n");
return 0;
}
int simple_augment::postConfig(void)
{
printf("==> simple_augment::postConfig Here\n");
return 0;
}
int simple_augment::preFrame(void);
{
printf("==> simple_augment::preFrame Here\n");
return 0;
}
int simple_augment::postConfig(void)
{
printf("==> simple_augment::postFrame Here\n");
return 0;
}
int cb_null(dgiGLDisplayInfo *d)
{
return 0;
}
int main(int argc, char **argv)
{
dgiGL g;
simple_augment *s = new simple_augment;
g.display()->setInitFunc(cb_null);
g.display()->setDisplayFunc(cb_null);
g.add(s);
while (1) {
sync();
frame();
}
return EXIT_SUCCESS;
}
The above code simply defines an augment that prints out its status at
each callback. The main program then goes into a loop so that it can reach
its callback points. If at anytime an augment reaches a state where it does
not want to be called at the callback points, it may be removed from the
callback list by returning DGIGL_REMOVE_OBJECT
from any callback
method.
4.2 Loading Augments from DSOs
The feature which makes augments so versatile is that they may be loaded
from DSOs (Dynamically Shared Objects). In this way generic code may be
written to handle a task, then integrated with dgiGL applications. A DSO
containing an augment would be structured as follows:
simple_augment_DSO.C
#include
#include
#include "dgiGL.H"
simple_augment : public dgiGLAugment
{
public:
simple_augment(dgiGL *app);
int preConfig(void);
int postConfig(void);
int preFrame(void);
int postFrame(void);
};
simple_augment::simple_augment(dgiGL *app)
{
printf("==> simple_augment Constructor Here\n");
validate();
}
int simple_augment::preConfig(void)
{
printf("==> simple_augment::preConfig Here\n");
return 0;
}
int simple_augment::postConfig(void)
{
printf("==> simple_augment::postConfig Here\n");
return 0;
}
int simple_augment::preFrame(void);
{
printf("==> simple_augment::preFrame Here\n");
return 0;
}
int simple_augment::postConfig(void)
{
printf("==> simple_augment::postFrame Here\n");
return 0;
}
extern "C" void *dtkDSO_loader(void *arg)
{
return (void *) new simple_augment(dgiGL *arg);
}
4.3 Using Augments to Define a Graphics Configuration
4.4 Using Augments to Define an Input Configuration
[Back]
[Up]
[Next]