Torque3D Documentation / _generateds / sfxALProvider.cpp

sfxALProvider.cpp

Engine/source/sfx/openal/sfxALProvider.cpp

More...

Classes:

Detailed Description

Public Variables

 MODULE_END 
 MODULE_INIT 
 MODULE_SHUTDOWN 
SFXALProvider * mProvider 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#include "platform/platform.h"
 24
 25#include "sfx/sfxProvider.h"
 26#include "sfx/openal/sfxALDevice.h"
 27#include "sfx/openal/aldlist.h"
 28#include "sfx/openal/LoadOAL.h"
 29
 30#include "core/strings/stringFunctions.h"
 31#include "console/console.h"
 32#include "core/module.h"
 33
 34
 35class SFXALProvider : public SFXProvider
 36{
 37public:
 38
 39   SFXALProvider()
 40      : SFXProvider( "OpenAL" ) { dMemset(&mOpenAL,0,sizeof(mOpenAL)); mALDL = NULL; }
 41   virtual ~SFXALProvider();
 42
 43protected:
 44   OPENALFNTABLE mOpenAL;
 45   ALDeviceList *mALDL;
 46
 47   struct ALDeviceInfo : SFXDeviceInfo
 48   {
 49      
 50   };
 51
 52   void init();
 53
 54public:
 55   SFXDevice *createDevice( const String& deviceName, bool useHardware, S32 maxBuffers );
 56
 57};
 58
 59MODULE_BEGIN( OpenAL )
 60
 61   MODULE_INIT_BEFORE( SFX )
 62   MODULE_SHUTDOWN_AFTER( SFX )
 63   
 64   SFXALProvider* mProvider;
 65   
 66   MODULE_INIT
 67   {
 68      mProvider = new SFXALProvider;
 69   }
 70   
 71   MODULE_SHUTDOWN
 72   {
 73      delete mProvider;
 74   }
 75
 76MODULE_END;
 77
 78void SFXALProvider::init()
 79{
 80   if( LoadOAL10Library( NULL, &mOpenAL ) != AL_TRUE )
 81   {
 82      Con::printf( "SFXALProvider - OpenAL not available." );
 83      return;
 84   }
 85   mALDL = new ALDeviceList( mOpenAL );
 86
 87   // Did we get any devices?
 88   if ( mALDL->GetNumDevices() < 1 )
 89   {
 90      Con::printf( "SFXALProvider - No valid devices found!" );
 91      return;
 92   }
 93
 94   // Cool, loop through them, and caps em
 95   const char *deviceFormat = "OpenAL v%d.%d %s";
 96
 97   char temp[256];
 98   for( S32 i = 0; i < mALDL->GetNumDevices(); i++ )
 99   {
100      ALDeviceInfo* info = new ALDeviceInfo;
101      
102      info->name = String( mALDL->GetDeviceName( i ) );
103
104      S32 major, minor, eax = 0;
105
106      mALDL->GetDeviceVersion( i, &major, &minor );
107
108      // Apologies for the blatent enum hack -patw
109      for( S32 j = SFXALEAX2; j < SFXALEAXRAM; j++ )
110         eax += (int)mALDL->IsExtensionSupported( i, (SFXALCaps)j );
111
112      if( eax > 0 )
113      {
114         eax += 2; // EAX support starts at 2.0
115         dSprintf( temp, sizeof( temp ), "[EAX %d.0] %s", eax, ( mALDL->IsExtensionSupported( i, SFXALEAXRAM ) ? "EAX-RAM" : "" ) );
116      }
117      else
118         dStrcpy( temp, "", 256 );
119
120      info->driver = String::ToString( deviceFormat, major, minor, temp );
121      info->hasHardware = eax > 0;
122      info->maxBuffers = mALDL->GetMaxNumSources( i );
123
124      mDeviceInfo.push_back( info );
125   }
126
127   regProvider( this );
128}
129
130SFXALProvider::~SFXALProvider()
131{
132   UnloadOAL10Library();
133
134   if (mALDL)
135   delete mALDL;
136}
137
138SFXDevice *SFXALProvider::createDevice( const String& deviceName, bool useHardware, S32 maxBuffers )
139{
140   ALDeviceInfo *info = dynamic_cast< ALDeviceInfo* >
141      ( _findDeviceInfo( deviceName) );
142
143   // Do we find one to create?
144   if ( info )
145      return new SFXALDevice( this, mOpenAL, info->name, useHardware, maxBuffers );
146
147   return NULL;
148}
149