Commit effff995 authored by Oliver Bock's avatar Oliver Bock
Browse files

Preparations to control/store graphics runtime parameters in project preferences

* <project_specific> XML tag may be parsed to extract runtime parameters for graphics applications
* Added dedicated fps and quality attribute handlers to BOINC Adapter (still mock-ups)
* Added FPS initializer to WindowManager
* Starsphere's fog is enabled at medium quality and higher
* Starsphere's anti-aliased rendering is enabled at high quality only
* Using conservative default values: 20 fps, low quality
* Reduced initial resolution to 800x600
parent 25576731
......@@ -538,6 +538,12 @@ case "$1" in
distclean || failure
exit 0
;;
"--starsphere")
# "hidden" bonus option :-)
TARGET=$TARGET_LINUX
build_starsphere || failure
exit 0
;;
*)
print_usage
exit 1
......
......@@ -28,6 +28,12 @@ AbstractGraphicsEngine::~AbstractGraphicsEngine()
{
}
int AbstractGraphicsEngine::frameRate()
{
m_BoincAdapter.refresh();
return m_BoincAdapter.graphicsFrameRate();
}
void AbstractGraphicsEngine::refreshLocalBOINCInformation()
{
m_BoincAdapter.refresh();
......
......@@ -166,6 +166,15 @@ public:
* \see refreshLocalBOINCInformation()
*/
virtual void refreshBOINCInformation() = 0;
/**
* \brief Retrieves the frame rate at which the graphics engine should be invoked for rendering
*
* \return The frame rate to be used for rendering
*
* \see BOINCClientAdapter::graphicsFrameRate()
*/
int frameRate();
protected:
/**
......
......@@ -88,6 +88,24 @@ string BOINCClientAdapter::applicationInformation() const
return m_SharedMemoryAreaContents;
}
string BOINCClientAdapter::projectInformation() const
{
// TODO: check if we have to add the <project_specific> tag!
return m_UserData.project_preferences;
}
int BOINCClientAdapter::graphicsFrameRate() const
{
// TODO: parse projectInformation() when available
return 20;
}
BOINCClientAdapter::GraphicsQualitySetting BOINCClientAdapter::graphicsQualitySetting() const
{
// TODO: parse projectInformation() when available
return BOINCClientAdapter::LowGraphicsQualitySetting;
}
string BOINCClientAdapter::coreVersion() const
{
stringstream buffer;
......
......@@ -53,6 +53,18 @@ public:
/// Destructor
virtual ~BOINCClientAdapter();
/**
* \brief Defined quality settings for graphics applications
*
* \see graphicsQualitySetting
* \see graphicsFrameRate
*/
enum GraphicsQualitySetting {
LowGraphicsQualitySetting = 1,
MediumGraphicsQualitySetting = 2,
HighGraphicsQualitySetting = 4
};
/**
* \brief Initializes the BOINC client adapter instance
......@@ -158,9 +170,72 @@ public:
/**
* \brief Retrieves information provided by the running science application
*
* \return The application specific information string (i.e. XML)
* \return The application specific information string (i.e. XML) found in APP_INIT_DATA
*
* \see m_UserData
*/
string applicationInformation() const;
/**
* \brief Retrieves specific information provided by the currently active project
*
* All projects using this framework are highly recommended to adhere to the following XML schema
* (not yet literally a XML schema, will be provided later) with respect to graphics settings:
*
\verbatim
<project_specific>
<graphics fps="20" quality="low">
<starsphere>
<feature id="globe" enabled="true" />
</starsphere>
<waverider>
<feature id="sound" enabled="false" />
</waverider>
</graphics>
</project_specific>
\endverbatim
*
* The \c graphics tag and its two attributes \b must be provided as shown above where
* the \c fps attribute contains the frame rate as integer value and \c quality contains
* a lowercase string value describing the quality setting to be used (supported values: \c low,
* \c medium, \c high). Please note that the children of the \c graphics tag are just examples
* of how graphics application specific settings (e.g. features) should be stored per implementation.
*
* \return The project specific information string (i.e. XML) found in \c APP_INIT_DATA
*
* \see m_UserData
* \see GraphicsQualitySetting
* \see graphicsFrameRate
* \see graphicsQualitySetting
*/
string projectInformation() const;
/**
* \brief Retrieves the frame rate at which the project's graphics application should be rendered
*
* This setting is given by the \c fps attribute of the \c graphics tag that's
* part of the \c project_specific XML tag.
*
* \return The frame rate to be used for rendering
*
* \see projectInformation
* \see m_UserData
*/
int graphicsFrameRate() const;
/**
* \brief Retrieves the quality setting at which the project's graphics application should be rendered
*
* This setting is given by the \c quality attribute of the \c graphics tag that's
* part of the \c project_specific XML tag.
*
* \return The quality setting to be used for rendering
*
* \see GraphicsQualitySetting
* \see projectInformation
* \see m_UserData
*/
GraphicsQualitySetting graphicsQualitySetting() const;
private:
/**
......@@ -202,7 +277,8 @@ private:
/**
* \brief Information structure returned by the BOINC client API.
*
* It contains initial information about the current work unit computation session.
* It contains information about the currently active project, science application,
* user account, work unit and computation session.
*/
APP_INIT_DATA m_UserData;
};
......
......@@ -28,7 +28,7 @@ WindowManager::~WindowManager()
{
}
bool WindowManager::initialize(const int width, const int height)
bool WindowManager::initialize(const int width, const int height, const int frameRate)
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
cerr << "Window system could not be initalized: " << SDL_GetError() << endl;
......@@ -52,9 +52,10 @@ bool WindowManager::initialize(const int width, const int height)
m_DesktopBitsPerPixel = videoInfo->vfmt->BitsPerPixel;
}
// set initial non-fullscreen resolution
// set initial non-fullscreen resolution as well as the render interval
m_WindowedWidth = width;
m_WindowedHeight = height;
m_RenderEventInterval = 1000.0f / frameRate;
/*
* SDL_ASYNCBLIT - Surface benutzt asynchrone Blits, wenn möglich
......@@ -146,9 +147,8 @@ void WindowManager::eventLoop()
// be sure there's at least one observer!
assert(eventObservers.size() > 0);
// TODO: make interval setting available to the outside
// set two main timers (interval in ms)
SDL_AddTimer(40, &timerCallbackRenderEvent, NULL);
SDL_AddTimer(m_RenderEventInterval, &timerCallbackRenderEvent, NULL);
SDL_AddTimer(1000, &timerCallbackBOINCUpdateEvent, NULL);
// events we don't ignore, hence use
......
......@@ -70,10 +70,11 @@ public:
*
* \param width The optional initial width of the main window
* \param height The optional initial height of the main window
* \param frameRate The optional initial frame rate to be used
*
* \return TRUE if successfull, otherwise FALSE
*/
bool initialize(const int width = 1024, const int height = 768);
bool initialize(const int width = 800, const int height = 600, const int frameRate = 20);
/**
* \brief Registeres a new event observer
......@@ -189,6 +190,9 @@ private:
*/
static Uint32 timerCallbackBOINCUpdateEvent(Uint32 interval, void *param);
/// The render event interval (in ms) for invoking the render event observer
float m_RenderEventInterval;
/// The current width of the host's desktop
int m_DesktopWidth;
......
......@@ -721,20 +721,22 @@ void Starsphere::initialize(const int width, const int height, const Resource *f
glClearColor(0.0, 0.0, 0.0, 0.0); // background is black
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
// some polishing
glShadeModel(GL_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
// enable opt-in quality feature
if(m_BoincAdapter.graphicsQualitySetting() == BOINCClientAdapter::HighGraphicsQualitySetting) {
// some polishing
glShadeModel(GL_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
}
// FSAA will be enabled explicitly when needed!
glDisable(GL_MULTISAMPLE_ARB);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
// we need alpha blending for proper font rendering
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -743,10 +745,16 @@ void Starsphere::initialize(const int width, const int height, const Resource *f
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// fog aids depth perception
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogf(GL_FOG_DENSITY, 0.085);
// enable opt-in quality feature
if(m_BoincAdapter.graphicsQualitySetting() == BOINCClientAdapter::MediumGraphicsQualitySetting ||
m_BoincAdapter.graphicsQualitySetting() == BOINCClientAdapter::HighGraphicsQualitySetting)
{
// fog aids depth perception
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogf(GL_FOG_DENSITY, 0.085);
glHint(GL_FOG_HINT, GL_DONT_CARE);
}
// create pre-drawn display lists
make_stars();
......
......@@ -42,7 +42,7 @@ int main(int argc, char **argv)
}
// initialize window manager
if(!window.initialize()) {
if(!window.initialize(800, 600, graphics->frameRate())) {
cerr << "Window manager could not be initialized!" << endl;
delete graphics;
exit(1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment