]> Dogcows Code - chaz/yoink/blob - src/moof/video.hh
build system enhancements
[chaz/yoink] / src / moof / video.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_VIDEO_HH_
13 #define _MOOF_VIDEO_HH_
14
15 /**
16 * \file video.hh
17 * Classes for managing a video context.
18 */
19
20 #include <string>
21
22 #include <boost/shared_ptr.hpp>
23 #include <SDL/SDL.h>
24
25 #include <moof/backend.hh>
26 #include <moof/math.hh>
27 #include <moof/timer.hh>
28
29
30 namespace moof {
31
32
33 class settings;
34
35 class video;
36 typedef boost::shared_ptr<video> video_ptr;
37
38
39 class video
40 {
41 public:
42
43 struct attributes
44 {
45 int color_buffer[4]; // rgba
46 int frame_buffer;
47 bool is_double_buffer;
48 int depth_buffer;
49 int stencil_buffer;
50 int accumulator_buffer[4]; // rgba
51 bool is_stereo;
52 int multisample_buffers;
53 int multisample_samples;
54 bool is_swap_control;
55 bool is_hardware_only;
56 int mode[3]; // width, height, bpp
57 bool is_fullscreen;
58 bool is_resizable;
59 bool is_cursor_visible;
60 bool is_cursor_captured;
61
62 attributes();
63 attributes(const settings& settings);
64
65 private:
66
67 void init();
68
69 backend mBackend;
70 };
71
72
73 static video_ptr alloc(const attributes& attribs)
74 {
75 return video_ptr(new video(attribs));
76 }
77
78 explicit video(const std::string& caption = "Moof!!");
79 explicit video(const class attributes& attribs);
80 video(const std::string& caption,
81 const class attributes& attribs);
82 ~video();
83
84 class attributes attributes() const;
85
86 void mode(const int mode[3]);
87
88 void resize(int width, int height);
89 bool iconify();
90
91 void caption(const std::string& caption);
92 const std::string& caption() const;
93
94 void fullscreen(bool full);
95 bool fullscreen() const;
96 void toggle_fullscreen();
97
98 void resizable(bool is_resizable);
99 bool resizable() const;
100 void toggle_resizable();
101
102 void cursor_visible(bool is_cursor_visible);
103 bool cursor_visible() const;
104 void toggle_cursor_visible();
105
106 void cursor_captured(bool is_cursor_captured);
107 bool cursor_captured() const;
108 void toggle_cursor_captured();
109
110
111 /**
112 * Swap the video buffers if double-buffered.
113 */
114 void swap(scalar t = timer::ticks());
115
116
117 /**
118 * Make this video context the current context which will be effected
119 * by future draw commands.
120 */
121 void make_current() const;
122
123 /**
124 * Get the current video context where draw commands are sent.
125 */
126 static video* current()
127 {
128 return current_;
129 }
130
131
132 /**
133 * Get the width of the video display.
134 * \return The pixel width.
135 */
136 int width() const;
137
138 /**
139 * Get the height of the video display.
140 * \return The pixel height.
141 */
142 int height() const;
143
144
145 void show_fps(bool show)
146 {
147 show_fps_ = show;
148 fps_accumulator_ = SCALAR(0.0);
149 fps_counter_ = 0;
150 last_swap_ = SCALAR(0.0);
151 }
152
153 bool show_fps() const
154 {
155 return show_fps_;
156 }
157
158
159 private:
160
161 void init();
162
163 void recreate_context();
164 void set_opengl_attributes();
165
166 // TODO: this implementation is not well hidden
167
168 SDL_Surface* context_;
169 int flags_;
170 class attributes attributes_;
171 bool show_fps_;
172 std::string caption_;
173 scalar fps_accumulator_;
174 int fps_counter_;
175 scalar last_swap_;
176
177 static video* current_;
178 };
179
180
181 } // namespace moof
182
183 #endif // _MOOF_VIDEO_HH_
184
This page took 0.035054 seconds and 4 git commands to generate.