OALplus (0.52.0) a C++ wrapper for OpenAL

context.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OALPLUS_CONTEXT_1303201648_HPP
14 #define OALPLUS_CONTEXT_1303201648_HPP
15 
16 #include <oalplus/config.hpp>
17 #include <oalplus/alfunc.hpp>
18 #include <oalplus/device.hpp>
21 #include <oalplus/string_query.hpp>
22 #include <oalplus/attrib_list.hpp>
23 #include <oalplus/error/alc.hpp>
24 
25 #include <oalplus/detail/sep_str_range.hpp>
26 
27 namespace oalplus {
28 
29 struct ContextValueTypeToContextAttrib
30 {
31  static std::integral_constant<int, -1> MaxValueType(void);
32 };
33 
34 
36 typedef AttributeList<
38  ContextValueTypeToContextAttrib,
39  AttributeListTraits
41 
43 typedef FinishedAttributeList<
45  AttributeListTraits
47 
49 
55 {
56 protected:
57  ::ALCdevice* _device;
58  ::ALCcontext* _context;
59 
60  ContextOps(
61  ::ALCdevice* device,
62  ::ALCcontext* context
63  ): _device(device)
64  , _context(context)
65  {
66  assert(_device);
67  assert(_context);
68  }
69 public:
71 
76  static ContextOps Current(void);
77 
79 
83  static const ALchar* GetString(StringQuery query)
84  {
85  const ALchar* str = OALPLUS_ALFUNC(GetString)(ALenum(query));
86  OALPLUS_VERIFY_SIMPLE(GetString);
87  return str;
88  }
89 
91 
96  static const char* Vendor(void)
97  {
98  return (const char*)GetString(StringQuery::Vendor);
99  }
100 
102 
107  static const char* Version(void)
108  {
109  return (const char*)GetString(StringQuery::Version);
110  }
111 
113 
118  static const char* Renderer(void)
119  {
120  return (const char*)GetString(StringQuery::Renderer);
121  }
122 
123 #if OALPLUS_DOCUMENTATION_ONLY
124 
130  static Range<String> Extensions(void);
131 #else
132  static aux::SepStrRange Extensions(void)
133  {
134  return aux::SepStrRange(
135  (const char*)GetString(StringQuery::Extensions)
136  );
137  }
138 #endif
139 
140 
143  {
144  return DeviceOps<tag::Playback>(_device);
145  }
146 
148 
152  bool MakeCurrent(void)
153  {
154  bool result = OALPLUS_ALCFUNC(MakeContextCurrent)(_context);
155  OALPLUS_VERIFY_SIMPLE_ALC(_device, MakeContextCurrent);
156  return result;
157  }
158 
160 
164  void Process(void)
165  {
166  OALPLUS_ALCFUNC(ProcessContext)(_context);
167  OALPLUS_VERIFY_SIMPLE_ALC(_device, ProcessContext);
168  }
169 
171 
175  void Suspend(void)
176  {
177  OALPLUS_ALCFUNC(SuspendContext)(_context);
178  OALPLUS_VERIFY_SIMPLE_ALC(_device, SuspendContext);
179  }
180 
182 
186  static void DistanceModel(oalplus::DistanceModel dist_model)
187  {
188  OALPLUS_ALFUNC(DistanceModel(ALenum(dist_model)));
189  OALPLUS_VERIFY_SIMPLE(DistanceModel);
190  }
191 
193 
198  static oalplus::DistanceModel DistanceModel(void)
199  {
200  ALint result;
201  OALPLUS_ALFUNC(GetIntegerv(
202  AL_DISTANCE_MODEL,
203  &result
204  ));
205  OALPLUS_VERIFY_SIMPLE(GetIntegerv);
206  return oalplus::DistanceModel(result);
207  }
208 
210 
214  static void DopplerFactor(ALfloat doppler_factor)
215  {
216  OALPLUS_ALFUNC(DopplerFactor(doppler_factor));
217  OALPLUS_CHECK_SIMPLE(DopplerFactor);
218  }
219 
221 
226  static ALfloat DopplerFactor(void)
227  {
228  ALfloat result;
229  OALPLUS_ALFUNC(GetFloatv(
230  AL_DOPPLER_FACTOR,
231  &result
232  ));
233  OALPLUS_VERIFY_SIMPLE(GetFloatv);
234  return result;
235  }
236 
238 
242  static void SpeedOfSound(ALfloat speed_of_sound)
243  {
244  OALPLUS_ALFUNC(SpeedOfSound(speed_of_sound));
245  OALPLUS_CHECK_SIMPLE(SpeedOfSound);
246  }
247 
249 
254  static ALfloat SpeedOfSound(void)
255  {
256  ALfloat result;
257  OALPLUS_ALFUNC(GetFloatv(
258  AL_SPEED_OF_SOUND,
259  &result
260  ));
261  OALPLUS_VERIFY_SIMPLE(GetFloatv);
262  return result;
263  }
264 };
265 
267 class Context
268  : public ContextOps
269 {
270 private:
271  Context(const Context&);
272 public:
274 
278  Context(const Device& device)
279  : ContextOps(
280  device._device,
281  OALPLUS_ALCFUNC(CreateContext)(device._device, nullptr)
282  )
283  {
284  OALPLUS_CHECK_SIMPLE_ALC(_device, CreateContext);
285  }
286 
288 
293  const Device& device,
294  const FinishedContextAttribs& attribs
295  ): ContextOps(
296  device._device,
297  OALPLUS_ALCFUNC(CreateContext)(
298  device._device,
299  attribs.Get()
300  )
301  )
302  {
303  OALPLUS_CHECK_SIMPLE_ALC(_device, CreateContext);
304  }
305 
308  : ContextOps(tmp._device, tmp._context)
309  {
310  tmp._context = nullptr;
311  }
312 
314 
319  ~Context(void)
320  {
321  if(_context)
322  {
323  OALPLUS_ALCFUNC(MakeContextCurrent)(nullptr);
324  OALPLUS_ALCFUNC(DestroyContext)(_context);
325  }
326  }
327 };
328 
331  : public Context
332 {
333 public:
335 
340  CurrentContext(const Device& device)
341  : Context(device)
342  {
343  MakeCurrent();
344  }
345 
347 
353  const Device& device,
354  const FinishedContextAttribs& attribs
355  ): Context(device, attribs)
356  {
357  MakeCurrent();
358  }
359 
361 
366  : Context(static_cast<Context&&>(tmp))
367  {
368  if(_context) MakeCurrent();
369  }
370 };
371 
372 } // namespace oalplus
373 
374 #endif // include guard
OpenAL string query enumeration.
bool MakeCurrent(void)
Makes this context current.
Definition: context.hpp:152
static ALfloat DopplerFactor(void)
Returns the doppler factor used by the current context.
Definition: context.hpp:226
Audio playback device.
Definition: device.hpp:257
Wrapper around a OpenAL device.
~Context(void)
Destroys this context.
Definition: context.hpp:319
Class implementing audio playback device-specific operations.
Definition: device.hpp:116
static ALfloat SpeedOfSound(void)
Returns the value of speed of sound used by the current context.
Definition: context.hpp:254
Template for OpenAL context attribute list.
OpenAL context attribute type enumeration.
Compile-time configuration options.
static const char * Version(void)
Returns the version string.
Definition: context.hpp:107
Helper macro expanding into OpenAL function name.
static const ALchar * GetString(StringQuery query)
Queries a string from the current OpenAL context.
Definition: context.hpp:83
Context(const Device &device, const FinishedContextAttribs &attribs)
Construct a context with the specified attributes using the device.
Definition: context.hpp:292
CurrentContext(const Device &device)
Creates a new context and makes it current.
Definition: context.hpp:340
static void DopplerFactor(ALfloat doppler_factor)
Sets the doppler factor for the current context.
Definition: context.hpp:214
CurrentContext(CurrentContext &&tmp)
CurrentContext is move-constructible.
Definition: context.hpp:365
static void SpeedOfSound(ALfloat speed_of_sound)
Sets the value of speed of sound for the current context.
Definition: context.hpp:242
static oalplus::DistanceModel DistanceModel(void)
Returns the distance model used by the current context.
Definition: context.hpp:198
AttributeList< ContextAttrib, ContextValueTypeToContextAttrib, AttributeListTraits > ContextAttribs
Attribute list for context attributes.
Definition: context.hpp:40
Context(const Device &device)
Construct a context using the specified device.
Definition: context.hpp:278
DeviceOps< tag::Playback > ContextsDevice(void) const
Returns the device of this context.
Definition: context.hpp:142
ContextAttrib
OpenAL context attribute enumeration.
Definition: context_attrib.hpp:24
OpenAL string query enumeration.
FinishedAttributeList< ContextAttrib, AttributeListTraits > FinishedContextAttribs
Finished list of context attribute values.
Definition: context.hpp:46
A context that is made current right after construction.
Definition: context.hpp:330
static ContextOps Current(void)
Returns the current OpenAL context.
static void DistanceModel(oalplus::DistanceModel dist_model)
Sets the distance model to be used by the current context.
Definition: context.hpp:186
static const char * Vendor(void)
Returns the vendor name.
Definition: context.hpp:96
void Process(void)
Processes this context.
Definition: context.hpp:164
CurrentContext(const Device &device, const FinishedContextAttribs &attribs)
Creates a new context and makes it current.
Definition: context.hpp:352
static Range< String > Extensions(void)
Returns a range of extension strings.
void Suspend(void)
Suspends this context.
Definition: context.hpp:175
Wrapper for OpenAL context operations.
Definition: context.hpp:267
Context(Context &&tmp)
Contexts are move-only.
Definition: context.hpp:307
Base wrapper for OpenAL context operations.
Definition: context.hpp:54
static const char * Renderer(void)
Returns the renderer name.
Definition: context.hpp:118

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).