-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_VIDEO_HH_
#define _MOOF_VIDEO_HH_
-/**
- * \file video.hh
- * Classes for managing a video context.
- */
-
#include <string>
#include <boost/shared_ptr.hpp>
#include <SDL/SDL.h>
#include <moof/backend.hh>
+#include <moof/math.hh>
+#include <moof/timer.hh>
+/**
+ * \file video.hh
+ * Classes for managing a video context.
+ */
+
namespace moof {
+// forward declarations
class settings;
class video;
typedef boost::shared_ptr<video> video_ptr;
-
class video
{
public:
struct attributes
{
- int color_buffer[4]; // rgba
- int frame_buffer;
- bool is_double_buffer;
- int depth_buffer;
- int stencil_buffer;
- int accumulator_buffer[4]; // rgba
- bool is_stereo;
- int multisample_buffers;
- int multisample_samples;
- bool is_swap_control;
- bool is_hardware_only;
- int mode[3]; // width, height, bpp
- bool is_fullscreen;
- bool is_resizable;
- bool is_cursor_visible;
- bool is_cursor_captured;
+ int color_buffer[4]; // rgba
+ int frame_buffer;
+ bool is_double_buffer;
+ int depth_buffer;
+ int stencil_buffer;
+ int accumulator_buffer[4]; // rgba
+ bool is_stereo;
+ int multisamples;
+ bool is_swap_control;
+ bool is_hardware_only;
+ int mode[3]; // width, height, bpp
+ bool is_fullscreen;
+ bool is_resizable;
+ bool is_cursor_visible;
+ bool is_cursor_captured;
attributes();
attributes(const settings& settings);
void init();
- backend mBackend;
+ backend backend_;
};
-
static video_ptr alloc(const attributes& attribs)
{
return video_ptr(new video(attribs));
explicit video(const std::string& caption = "Moof!!");
explicit video(const class attributes& attribs);
explicit video(const std::string& caption,
- const class attributes& attribs);
+ const class attributes& attribs);
~video();
class attributes attributes() const;
bool iconify();
void caption(const std::string& caption);
- std::string caption() const;
+ const std::string& caption() const;
void fullscreen(bool full);
bool fullscreen() const;
bool cursor_captured() const;
void toggle_cursor_captured();
-
/**
* Swap the video buffers if double-buffered.
*/
- void swap();
-
+ void swap(scalar t = timer::ticks());
/**
* Make this video context the current context which will be effected
/**
* Get the current video context where draw commands are sent.
*/
- static video* current()
+ static video& current()
{
- return current_;
+ return *current_;
}
+ /**
+ * Get whether or not a video context is in place and is ready to
+ * received drawing commands.
+ */
+ static bool ready()
+ {
+ return current_;
+ }
/**
* Get the width of the video display.
*/
int height() const;
+ void show_fps(bool show)
+ {
+ show_fps_ = show;
+ fps_accumulator_ = SCALAR(0.0);
+ fps_counter_ = 0;
+ last_swap_ = SCALAR(0.0);
+ }
+
+ bool show_fps() const
+ {
+ return show_fps_;
+ }
private:
// TODO: this implementation is not well hidden
SDL_Surface* context_;
- int flags_;
+ int flags_;
class attributes attributes_;
+ bool show_fps_;
+ std::string caption_;
+ scalar fps_accumulator_;
+ int fps_counter_;
+ scalar last_swap_;
static video* current_;
};