Don't recreate the effect when switching between the dedicated effect types

This commit is contained in:
Chris Robinson 2011-09-01 18:51:24 -07:00
parent 942c8bf8a7
commit 812d91cbf8

View File

@ -521,35 +521,59 @@ static ALenum ResizeEffectSlotArray(ALCcontext *Context, ALsizei count)
static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect) static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect)
{ {
if(EffectSlot->effect.type != (effect?effect->type:AL_EFFECT_NULL)) ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL);
ALeffectState *NewState = NULL;
ALenum err = AL_NO_ERROR;
if(newtype == AL_EFFECT_NULL && EffectSlot->effect.type != AL_EFFECT_NULL)
{ {
ALeffectState *NewState = NULL; NewState = NoneCreate();
if(!effect || effect->type == AL_EFFECT_NULL) if(!NewState) err = AL_OUT_OF_MEMORY;
NewState = NoneCreate(); }
else if(effect->type == AL_EFFECT_EAXREVERB) else if(newtype == AL_EFFECT_EAXREVERB && EffectSlot->effect.type != AL_EFFECT_EAXREVERB)
NewState = EAXVerbCreate(); {
else if(effect->type == AL_EFFECT_REVERB) NewState = EAXVerbCreate();
NewState = VerbCreate(); if(!NewState) err = AL_OUT_OF_MEMORY;
else if(effect->type == AL_EFFECT_ECHO) }
NewState = EchoCreate(); else if(newtype == AL_EFFECT_REVERB && EffectSlot->effect.type != AL_EFFECT_REVERB)
else if(effect->type == AL_EFFECT_RING_MODULATOR) {
NewState = ModulatorCreate(); NewState = VerbCreate();
else if(effect->type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) if(!NewState) err = AL_OUT_OF_MEMORY;
NewState = DedicatedCreate(); }
else if(effect->type == AL_EFFECT_DEDICATED_DIALOGUE) else if(newtype == AL_EFFECT_ECHO && EffectSlot->effect.type != AL_EFFECT_ECHO)
NewState = DedicatedCreate(); {
/* No new state? An error occured.. */ NewState = EchoCreate();
if(NewState == NULL || if(!NewState) err = AL_OUT_OF_MEMORY;
ALEffect_DeviceUpdate(NewState, Context->Device) == AL_FALSE) }
else if(newtype == AL_EFFECT_RING_MODULATOR && EffectSlot->effect.type != AL_EFFECT_RING_MODULATOR)
{
NewState = ModulatorCreate();
if(!NewState) err = AL_OUT_OF_MEMORY;
}
else if((newtype == AL_EFFECT_DEDICATED_DIALOGUE || newtype == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) &&
EffectSlot->effect.type != AL_EFFECT_DEDICATED_DIALOGUE && EffectSlot->effect.type != AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
{
NewState = DedicatedCreate();
if(!NewState) err = AL_OUT_OF_MEMORY;
}
if(err != AL_NO_ERROR)
{
alSetError(Context, err);
return;
}
if(NewState)
{
if(ALEffect_DeviceUpdate(NewState, Context->Device) == AL_FALSE)
{ {
if(NewState) ALEffect_Destroy(NewState);
ALEffect_Destroy(NewState);
alSetError(Context, AL_OUT_OF_MEMORY); alSetError(Context, AL_OUT_OF_MEMORY);
return; return;
} }
if(EffectSlot->EffectState) NewState = ExchangePtr((void**)&EffectSlot->EffectState, NewState);
ALEffect_Destroy(EffectSlot->EffectState); ALEffect_Destroy(NewState);
EffectSlot->EffectState = NewState; NewState = NULL;
if(!effect) if(!effect)
memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect)); memset(&EffectSlot->effect, 0, sizeof(EffectSlot->effect));