Browse Source

GCC 4.5 compatibility: no unrestricted unions.

Vladimír Vondruš 13 years ago
parent
commit
9d0c6b44de
  1. 24
      src/Trade/PhongMaterialData.cpp
  2. 20
      src/Trade/PhongMaterialData.h

24
src/Trade/PhongMaterialData.cpp

@ -27,33 +27,33 @@
namespace Magnum { namespace Trade {
Vector3& PhongMaterialData::ambientColor() {
CORRADE_ASSERT(!(_flags & Flag::AmbientTexture), "Trade::PhongMaterialData::ambientColor(): the material has ambient texture", _ambient.color);
return _ambient.color;
CORRADE_ASSERT(!(_flags & Flag::AmbientTexture), "Trade::PhongMaterialData::ambientColor(): the material has ambient texture", _ambient.color());
return _ambient.color();
}
UnsignedInt& PhongMaterialData::ambientTexture() {
CORRADE_ASSERT(_flags & Flag::AmbientTexture, "Trade::PhongMaterialData::ambientTexture(): the material doesn't have ambient texture", _ambient.texture);
return _ambient.texture;
CORRADE_ASSERT(_flags & Flag::AmbientTexture, "Trade::PhongMaterialData::ambientTexture(): the material doesn't have ambient texture", _ambient.texture());
return _ambient.texture();
}
Vector3& PhongMaterialData::diffuseColor() {
CORRADE_ASSERT(!(_flags & Flag::DiffuseTexture), "Trade::PhongMaterialData::diffuseColor(): the material has diffuse texture", _diffuse.color);
return _diffuse.color;
CORRADE_ASSERT(!(_flags & Flag::DiffuseTexture), "Trade::PhongMaterialData::diffuseColor(): the material has diffuse texture", _diffuse.color());
return _diffuse.color();
}
UnsignedInt& PhongMaterialData::diffuseTexture() {
CORRADE_ASSERT(_flags & Flag::DiffuseTexture, "Trade::PhongMaterialData::diffuseTexture(): the material doesn't have diffuse texture", _diffuse.texture);
return _diffuse.texture;
CORRADE_ASSERT(_flags & Flag::DiffuseTexture, "Trade::PhongMaterialData::diffuseTexture(): the material doesn't have diffuse texture", _diffuse.texture());
return _diffuse.texture();
}
Vector3& PhongMaterialData::specularColor() {
CORRADE_ASSERT(!(_flags & Flag::SpecularTexture), "Trade::PhongMaterialData::specularColor(): the material has specular texture", _specular.color);
return _specular.color;
CORRADE_ASSERT(!(_flags & Flag::SpecularTexture), "Trade::PhongMaterialData::specularColor(): the material has specular texture", _specular.color());
return _specular.color();
}
UnsignedInt& PhongMaterialData::specularTexture() {
CORRADE_ASSERT(_flags & Flag::SpecularTexture, "Trade::PhongMaterialData::specularTexture(): the material doesn't have specular texture", _specular.texture);
return _specular.texture;
CORRADE_ASSERT(_flags & Flag::SpecularTexture, "Trade::PhongMaterialData::specularTexture(): the material doesn't have specular texture", _specular.texture());
return _specular.texture();
}
}}

20
src/Trade/PhongMaterialData.h

@ -134,12 +134,28 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData {
Float shininess() const { return _shininess; }
private:
#ifndef CORRADE_GCC45_COMPATIBILITY
union Source {
Source() {}
Vector3 color;
UnsignedInt texture;
public:
Vector3& color() { return color; }
UnsignedInt& texture() { return texture; }
private:
Vector3 _color;
UnsignedInt _texture;
};
#else
class Source {
public:
Vector3& color() { return *reinterpret_cast<Vector3*>(&data); }
UnsignedInt& texture() { return *reinterpret_cast<UnsignedInt*>(&data); }
private:
char data[sizeof(Vector3)];
};
#endif
Source _ambient,
_diffuse,

Loading…
Cancel
Save