Compare commits

...

18 Commits

Author SHA1 Message Date
Tim Moore
11479cd8c3 Merge branch 'ehofman/sound' 2010-01-16 23:49:36 +01:00
ehofman
176e760de1 test for an AL or ALC error before calling an ALUT function. 2010-01-16 15:50:29 +01:00
Tim Moore
430c60ed1a Merge branch 'ehofman/sound' 2010-01-13 07:57:35 +01:00
Tim Moore
dfea3623f6 Merge branch 'tat/framework' 2010-01-13 07:57:30 +01:00
Tim Moore
b38783e4cb Merge branch 'ehofman/subsys' 2010-01-11 07:15:11 +01:00
Tim Moore
9382a4c21b Merge branch 'jester/aptsign' 2010-01-11 07:14:51 +01:00
Tim Moore
3cd4c5566f Merge branch 'timoore/effects' 2010-01-11 07:14:23 +01:00
Tim Moore
601c0977df Merge branch 'jmt/geodistance' 2010-01-11 07:10:46 +01:00
ehofman
c56f036bab Tatsuhiro Nishioka:
These patches fixes minor bug in addition to providing --with-openal-framework and --with-cocoa-framework.
Now you can use your own version of OpenAL.framework for selecting various audio output device.
Plus, you can build FG/SG on Snow Leopard with cocoa configuration.
2010-01-05 22:12:37 +01:00
torsten
44dd50c0ef Csaba Halasz:
Fix airport signs by reverting to rev 1.22 of apt_sign.cxx. Tweaked a little to handle missing materials better.
2010-01-05 22:11:57 +01:00
ehofman
56919ae45f MacOS returns an unsopported AL error when a file is not found, work around this. 2010-01-05 22:10:22 +01:00
jmt
578af00b0d Allow geocentric distance computations to return radians. 2010-01-03 10:10:02 +01:00
Tim Moore
d6c0bf69b6 fix up some merge weirdness 2010-01-01 13:32:03 +01:00
ehofman
e8884b4ec0 Also unbind subsystem groups in reverse order and destruct them in reverse order to be consistent. 2009-12-31 19:42:53 +01:00
ehofman
5e79609955 unbind in reverse order to try to prevent order dependency problems. 2009-12-30 00:20:08 +01:00
ehofman
4950c96f1c Rearrange alut error checking a bit 2009-12-30 00:05:01 +01:00
jmt
51b0cf535e XML encodings: support 'ASCII' as an alias for 'US-ASCII' 2009-12-29 23:53:28 +01:00
ehofman
4cc17a7f6e keep a pointer to the OpenAL vendor and renderer for reference 2009-12-27 09:24:24 +01:00
9 changed files with 112 additions and 43 deletions

View File

@@ -144,6 +144,15 @@ AC_ARG_WITH(osg_framework, [ --with-osg-framework=PREFIX Specify the prefix
if test "x$with_osg_framework" != "x"; then
echo "osg framework prefix is $with_osg_framework"
CPPFLAGS = "$CPPFLAGS -F$with-osg-framework"
export DYLD_FRAMEWORK_PATH="$DYLD_FRAMEWORK_PATH:$with_osg_framework"
fi
dnl specifying OpenAL.framework (for user provided OpenAL.framework / ALUT)
AC_ARG_WITH(openal_framework, [ --with-openal-framework=PREFIX Speicfy the prefix path to OpenAL.framework ])
if test "x$with_openal_framework" != "x"; then
echo "OpenAL framework prefix is $with_openal_framework"
fi
dnl Determine an extra directories to add to include/lib search paths
@@ -305,9 +314,18 @@ case "${host}" in
LIBS="$LIBS -framework IOKit -framework OpenAL"
openal_LIBS="$LIBS"
# not sure how to test if OpenAL exists on MacOS (does it come by default?)
OPENAL_OK="yes"
ALUT_OK="yes"
ALUT_OK="no"
if test "x$with_openal_lib" != "x"; then
echo "libopenal is not supported on Mac OS platform."
openal_LIBS=""
fi
OPENAL_OK="yes"
# Looking for alut.h, if found assume that it is a part of
# the OpenAL package.
AC_CHECK_HEADERS([OpenAL/alut.h],[ALUT_OK="yes"])
dnl Thank you Christian Bauer from SheepSaver
dnl Modified by Tatsuhiro Nishioka for accepting a given framework path
@@ -338,6 +356,12 @@ case "${host}" in
AS_VAR_POPDEF([ac_Framework])dnl
])
dnl Check for OpenAL.framework when --with-openal-framework is specified
dnl Of cource OpenAL.framework needs to have alut.h
if test "x$with_openal_framework" != "x"; then
AC_CHECK_FRAMEWORK(OpenAL, [#include <OpenAL/alut.h>], $with_openal_framework)
fi
;;
*)

View File

@@ -540,7 +540,7 @@ SGGeodesy::courseRad(const SGGeoc& from, const SGGeoc& to)
}
double
SGGeodesy::distanceM(const SGGeoc& from, const SGGeoc& to)
SGGeodesy::distanceRad(const SGGeoc& from, const SGGeoc& to)
{
// d = 2*asin(sqrt((sin((lat1-lat2)/2))^2 +
// cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
@@ -550,5 +550,12 @@ SGGeodesy::distanceM(const SGGeoc& from, const SGGeoc& to)
double tmp2 = sin(0.5*(from.getLongitudeRad() - to.getLongitudeRad()));
double square = tmp1*tmp1 + cosLatFrom*cosLatTo*tmp2*tmp2;
double s = SGMiscd::min(sqrt(SGMiscd::max(square, 0)), 1);
return 2 * asin(s) * SG_RAD_TO_NM * SG_NM_TO_METER;
return 2 * asin(s);
}
double
SGGeodesy::distanceM(const SGGeoc& from, const SGGeoc& to)
{
return distanceRad(from, to) * SG_RAD_TO_NM * SG_NM_TO_METER;
}

View File

@@ -61,6 +61,7 @@ public:
static void advanceRadM(const SGGeoc& geoc, double course, double distance,
SGGeoc& result);
static double courseRad(const SGGeoc& from, const SGGeoc& to);
static double distanceRad(const SGGeoc& from, const SGGeoc& to);
static double distanceM(const SGGeoc& from, const SGGeoc& to);
};

View File

@@ -69,7 +69,6 @@ EffectMap effectMap;
double SGNewCloud::sprite_density = 1.0;
SGNewCloud::SGNewCloud(string type,
const SGPath &tex_path,
string tex,
@@ -214,7 +213,7 @@ osg::ref_ptr<EffectGeode> SGNewCloud::genCloud() {
z = height * cos(elev) * 0.5f;
}
// Determine the height and width as scaling factors on the minimum size (used to create the quad)
// Determine the height and width as scaling factors on the minimum size (used to create the quad).
float sprite_width = 1.0f + sg_random() * (max_sprite_width - min_sprite_width) / min_sprite_width;
float sprite_height = 1.0f + sg_random() * (max_sprite_height - min_sprite_height) / min_sprite_height;

View File

@@ -106,6 +106,10 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
osg::Group* object = new osg::Group;
object->setName(content);
SGMaterial *material = 0;
Effect *lighted_state = 0;
Effect *unlighted_state = 0;
// Part I: parse & measure
for (const char *s = content.data(); *s; s++) {
string name;
@@ -215,31 +219,32 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
}
}
if (newmat.size()) {
SGMaterial *m = matlib->find(newmat);
if (!m) {
// log error, but keep using previous material to at least show something
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
} else {
material = m;
// set material states (lighted & unlighted)
lighted_state = material->get_effect();
newmat.append(".unlighted");
if (newmat.size() == 0 )
continue;
SGMaterial *material = matlib->find(newmat);
if (!material) {
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
continue;
m = matlib->find(newmat);
if (m) {
unlighted_state = m->get_effect();
} else {
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
unlighted_state = lighted_state;
}
}
newmat.clear();
}
// set material states (lighted & unlighted)
Effect *lighted_state = material->get_effect();
Effect *unlighted_state;
string u = newmat + ".unlighted";
SGMaterial *m = matlib->find(u);
if (m) {
unlighted_state = m->get_effect();
} else {
SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
unlighted_state = lighted_state;
}
newmat = "";
// This can only happen if the default material is missing.
// Error has been already logged in the block above.
if (!material) continue;
SGMaterialGlyph *glyph = material->get_glyph(name);
if (!glyph) {
SG_LOG( SG_TERRAIN, SG_ALERT, SIGN "unsupported glyph `" << *s << '\'');

View File

@@ -69,7 +69,9 @@ SGSoundMgr::SGSoundMgr() :
_geod_pos(SGGeod::fromCart(SGVec3d::zeros())),
_velocity(SGVec3d::zeros()),
_orientation(SGQuatd::zeros()),
_bad_doppler(false)
_bad_doppler(false),
_renderer("unknown"),
_vendor("unknown")
{
#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
if (_alut_init == 0) {
@@ -158,10 +160,10 @@ void SGSoundMgr::init(const char *devname) {
else break;
}
string vendor = (const char *)alGetString(AL_VENDOR);
string renderer = (const char *)alGetString(AL_RENDERER);
if ( vendor != "OpenAL Community" ||
(renderer != "Software" && renderer != "OpenAL Sample Implementation")
_vendor = (const char *)alGetString(AL_VENDOR);
_renderer = (const char *)alGetString(AL_RENDERER);
if ( _vendor != "OpenAL Community" ||
(_renderer != "Software" && _renderer != "OpenAL Sample Implementation")
)
{
_bad_doppler = true;
@@ -220,6 +222,9 @@ void SGSoundMgr::stop() {
alcDestroyContext(_context);
alcCloseDevice(_device);
_context = NULL;
_renderer = "unknown";
_vendor = "unknown";
}
}
@@ -547,12 +552,14 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
ALfloat freqf;
testForALError("load file");
testForALCError("load file");
data = alutLoadMemoryFromFile(samplepath.c_str(), &format, &size, &freqf );
freq = (ALsizei)freqf;
if (data == NULL) {
int error = alutGetError();
int error = alutGetError();
if (data == NULL || error != ALUT_ERROR_NO_ERROR) {
string msg = "Failed to load wav file: ";
msg.append(alutGetErrorString(error));
msg.append(alutGetErrorString(error));
throw sg_io_exception(msg.c_str(), sg_location(samplepath));
return false;
}
@@ -568,7 +575,18 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
ALenum error = alGetError();
if ( error != AL_NO_ERROR ) {
string msg = "Failed to load wav file: ";
msg.append(alGetString(error));
const ALchar *errorString = alGetString(error);
if (errorString) {
msg.append(errorString);
} else {
// alGetString returns NULL when an unexpected or OS specific error
// occurs: e.g. -43 on Mac when file is not found.
// In this case, alGetString() sets 'Invalid Enum' error, so
// showing with the original error number is helpful.
stringstream ss;
ss << alGetString(alGetError()) << "(" << error << ")";
msg.append(ss.str());
}
throw sg_io_exception(msg.c_str(), sg_location(samplepath));
return false;
}

View File

@@ -289,6 +289,12 @@ public:
*/
vector<const char*> get_available_devices();
/**
* Get the current OpenAL vendor or rendering backend.
*/
const string& get_vendor() { return _vendor; }
const string& get_renderer() { return _renderer; }
private:
static int _alut_init;
@@ -321,6 +327,8 @@ private:
vector<ALuint> _sources_in_use;
bool _bad_doppler;
string _renderer;
string _vendor;
bool testForALError(string s);
bool testForALCError(string s);

View File

@@ -110,10 +110,11 @@ SGSubsystemGroup::SGSubsystemGroup ()
SGSubsystemGroup::~SGSubsystemGroup ()
{
for (unsigned int i = 0; i < _members.size(); i++)
// reverse order to prevent order dependency problems
for (unsigned int i = _members.size(); i > 0; i--)
{
_members[i]->printTimingStatistics();
delete _members[i];
_members[i-1]->printTimingStatistics();
delete _members[i-1];
}
}
@@ -148,8 +149,9 @@ SGSubsystemGroup::bind ()
void
SGSubsystemGroup::unbind ()
{
for (unsigned int i = 0; i < _members.size(); i++)
_members[i]->subsystem->unbind();
// reverse order to prevent order dependency problems
for (unsigned int i = _members.size(); i > 0; i--)
_members[i-1]->subsystem->unbind();
}
void
@@ -381,7 +383,8 @@ SGSubsystemMgr::bind ()
void
SGSubsystemMgr::unbind ()
{
for (int i = 0; i < MAX_GROUPS; i++)
// reverse order to prevent order dependency problems
for (int i = MAX_GROUPS-1; i >= 0; i--)
_groups[i].unbind();
}

View File

@@ -1365,6 +1365,10 @@ int getEncodingIndex(const char *name)
for (i = 0; i < sizeof(encodingNames)/sizeof(encodingNames[0]); i++)
if (streqci(name, encodingNames[i]))
return i;
if (streqci(name, "ASCII"))
return US_ASCII_ENC;
return UNKNOWN_ENC;
}