

#include "Foundation/OpenALUtils.hpp"

#include "Foundation/Log.hpp"

#include <sstream>

using namespace crimild;

void openal::Utils::checkErrors( std::string prefix )
{
    int error = alGetError();
    if ( error != AL_NO_ERROR ) {
        std::string errorDescription = "";
        switch ( error ) {
            case ALC_NO_ERROR:
                errorDescription = "AL_NO_ERROR";
                break;
            case ALC_INVALID_DEVICE:
                errorDescription = "ALC_INVALID_DEVICE";
                break;
            case ALC_INVALID_CONTEXT:
                errorDescription = "ALC_INVALID_CONTEXT";
                break;
            case ALC_INVALID_ENUM:
                errorDescription = "ALC_INVALID_ENUM";
                break;
            case ALC_INVALID_VALUE:
                errorDescription = "ALC_INVALID_VALUE";
                break;
            case ALC_OUT_OF_MEMORY:
                errorDescription = "ALC_OUT_OF_MEMORY";
                break;
            default:
                errorDescription = "Invalid error code";
                break;
        }

        std::stringstream ss;
        ss << prefix << ": "
           << "(0x" << error << ") " << errorDescription;

        CRIMILD_LOG_ERROR( ss.str() );
    }
}
