{-# LANGUAGE ForeignFunctionInterface #-}{-# OPTIONS_HADDOCK hide #-}---------------------------------------------------------------------------------- |-- Module : Sound.OpenAL.ALC.QueryUtils-- Copyright : (c) Sven Panne 2003-2013-- License : BSD3-- -- Maintainer : Sven Panne <svenpanne@gmail.com>-- Stability : stable-- Portability : portable----------------------------------------------------------------------------------moduleSound.OpenAL.ALC.QueryUtils(StringQuery(..),getString,getStringRaw,IntQuery(..),marshalIntQuery,getInteger,getIntegerv,alcIsExtensionPresent)whereimportControl.Monad(when)importGraphics.Rendering.OpenGL.GL.StateVarimportForeign.C.TypesimportForeign.Marshal.Array(withArray,peekArray)importForeign.Ptr(Ptr)importSound.OpenAL.ALC.ALCboolean(unmarshalALCboolean)importSound.OpenAL.ALC.BasicTypes(ALCboolean,ALCchar,ALCint,ALCenum,ALCsizei)importSound.OpenAL.ALC.String(withALCString,peekALCString)importSound.OpenAL.Config(Device,ALCdevice(..),nullDevice,marshalDevice)importSound.OpenAL.Constants(alc_DEFAULT_DEVICE_SPECIFIER,alc_DEVICE_SPECIFIER,alc_EXTENSIONS,alc_CAPTURE_DEFAULT_DEVICE_SPECIFIER,alc_CAPTURE_DEVICE_SPECIFIER,alc_ATTRIBUTES_SIZE,alc_ALL_ATTRIBUTES,alc_MAJOR_VERSION,alc_MINOR_VERSION,alc_CAPTURE_SAMPLES)--------------------------------------------------------------------------------dataStringQuery=DefaultDeviceSpecifier|DeviceSpecifier|Extensions|CaptureDefaultDeviceSpecifier|CaptureDeviceSpecifier|ALCErrorCategoryALCenummarshalStringQuery::StringQuery->ALCenummarshalStringQueryx=casexofDefaultDeviceSpecifier->alc_DEFAULT_DEVICE_SPECIFIERDeviceSpecifier->alc_DEVICE_SPECIFIERExtensions->alc_EXTENSIONSCaptureDefaultDeviceSpecifier->alc_CAPTURE_DEFAULT_DEVICE_SPECIFIERCaptureDeviceSpecifier->alc_CAPTURE_DEVICE_SPECIFIERALCErrorCategorye->e--------------------------------------------------------------------------------getString::MaybeDevice->StringQuery->IOStringgetStringdevicequery=getStringRawdevicequery>>=peekALCStringgetStringRaw::MaybeDevice->StringQuery->IO(PtrALCchar)getStringRawmaybeDevice=alcGetString(marshalMaybeDevicemaybeDevice).marshalStringQuerymarshalMaybeDevice::MaybeDevice->ALCdevicemarshalMaybeDevice=marshalDevice.maybenullDeviceidforeignimportccallunsafe"alcGetString"alcGetString::ALCdevice->ALCenum->IO(PtrALCchar)--------------------------------------------------------------------------------dataIntQuery=AttributesSize|AllAttributes|MajorVersion|MinorVersion|CaptureSamplesmarshalIntQuery::IntQuery->ALCenummarshalIntQueryx=casexofAttributesSize->alc_ATTRIBUTES_SIZEAllAttributes->alc_ALL_ATTRIBUTESMajorVersion->alc_MAJOR_VERSIONMinorVersion->alc_MINOR_VERSIONCaptureSamples->alc_CAPTURE_SAMPLES--------------------------------------------------------------------------------getInteger::MaybeDevice->IntQuery->IOALCintgetIntegermaybeDevicequery=fmaphead$getIntegervmaybeDevicequery1-- We are extremely careful below to avoid segfaults in case that there is no-- current context, an invalid device, etc.getIntegerv::MaybeDevice->IntQuery->ALCsizei->IO[ALCint]getIntegervmaybeDevicequerynumALCints=letn=fromIntegralnumALCintsinwithArray(replicaten0)$\buf->dowhen(numALCints>0)$alcGetIntegerv(marshalMaybeDevicemaybeDevice)(marshalIntQueryquery)numALCintsbufpeekArraynbufforeignimportccallunsafe"alcGetIntegerv"alcGetIntegerv::ALCdevice->ALCenum->ALCsizei->PtrALCint->IO()---------------------------------------------------------------------------------- | To verify that a given extension is available for the current context and-- the device it is associated with, use 'alcIsExtensionPresent'. For invalid-- and unsupported string tokens it contains 'False'. Using 'Nothing' as the-- device is acceptable. The extension name is not case sensitive: The-- implementation will convert the name to all upper-case internally (and will-- express extension names in upper-case).alcIsExtensionPresent::MaybeDevice->String->GettableStateVarBoolalcIsExtensionPresentmaybeDeviceextensionName=makeGettableStateVar$fmapunmarshalALCboolean$withALCStringextensionName$alcIsExtensionPresent_(marshalMaybeDevicemaybeDevice)foreignimportccallunsafe"alcIsExtensionPresent"alcIsExtensionPresent_::ALCdevice->PtrALCchar->IOALCboolean