Commit c2236586 authored by hybrid's avatar hybrid

Merged revisions 2407:2436 from 1.5 branch. CopyToScaling bug fix, big endian...

Merged revisions 2407:2436 from 1.5 branch. CopyToScaling bug fix, big endian .x bug fix, STL loading fixed, binary attributes loading fixed.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2440 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8e9c3de2
...@@ -488,7 +488,7 @@ namespace video ...@@ -488,7 +488,7 @@ namespace video
const f32 maxVal = (f32)core::max_(color.getRed(), color.getGreen(), color.getBlue()); const f32 maxVal = (f32)core::max_(color.getRed(), color.getGreen(), color.getBlue());
const f32 minVal = (f32)core::min_(color.getRed(), color.getGreen(), color.getBlue()); const f32 minVal = (f32)core::min_(color.getRed(), color.getGreen(), color.getBlue());
Luminance = (maxVal/minVal)*0.5f; Luminance = (maxVal/minVal)*0.5f;
if (maxVal==minVal) if (core::equals(maxVal, minVal))
{ {
Hue=0.f; Hue=0.f;
Saturation=0.f; Saturation=0.f;
...@@ -506,7 +506,7 @@ namespace video ...@@ -506,7 +506,7 @@ namespace video
} }
if (maxVal==color.getRed()) if (maxVal==color.getRed())
Hue = (color.getRed()-color.getBlue())/delta; Hue = (color.getGreen()-color.getBlue())/delta;
else if (maxVal==color.getGreen()) else if (maxVal==color.getGreen())
Hue = 2+(color.getBlue()-color.getRed())/delta; Hue = 2+(color.getBlue()-color.getRed())/delta;
else if (maxVal==color.getBlue()) else if (maxVal==color.getBlue())
...@@ -520,12 +520,12 @@ namespace video ...@@ -520,12 +520,12 @@ namespace video
inline void SColorHSL::toRGB(SColor &color) const inline void SColorHSL::toRGB(SColor &color) const
{ {
if ( Saturation == 0.0f) // grey if (core::iszero(Saturation)) // grey
{ {
u8 c = (u8) ( Luminance * 255.0 ); u8 c = (u8) ( Luminance * 255.0 );
color.setRed ( c ); color.setRed(c);
color.setGreen ( c ); color.setGreen(c);
color.setBlue ( c ); color.setBlue(c);
return; return;
} }
......
...@@ -338,8 +338,8 @@ public: ...@@ -338,8 +338,8 @@ public:
} }
//! Get size of array. //! Get number of occupied elements of the array.
/** \return Size of elements used in the array. */ /** \return Size of elements in the array which are actually occupied. */
u32 size() const u32 size() const
{ {
return used; return used;
...@@ -348,7 +348,7 @@ public: ...@@ -348,7 +348,7 @@ public:
//! Get amount of memory allocated. //! Get amount of memory allocated.
/** \return Amount of memory allocated. The amount of bytes /** \return Amount of memory allocated. The amount of bytes
allocated would be allocated_size() * sizeof(ElementsUsed); */ allocated would be allocated_size() * sizeof(ElementTypeUsed); */
u32 allocated_size() const u32 allocated_size() const
{ {
return allocated; return allocated;
......
...@@ -1692,9 +1692,9 @@ public: ...@@ -1692,9 +1692,9 @@ public:
return L"string"; return L"string";
} }
virtual void getBinary(void* outdata, s32 maxLenght) virtual void getBinary(void* outdata, s32 maxLength)
{ {
s32 dataSize = maxLenght; s32 dataSize = maxLength;
c8* datac8 = (c8*)(outdata); c8* datac8 = (c8*)(outdata);
s32 p = 0; s32 p = 0;
const c8* dataString = Value.c_str(); const c8* dataString = Value.c_str();
...@@ -1714,9 +1714,9 @@ public: ...@@ -1714,9 +1714,9 @@ public:
} }
}; };
virtual void setBinary(void* data, s32 maxLenght) virtual void setBinary(void* data, s32 maxLength)
{ {
s32 dataSize = maxLenght; s32 dataSize = maxLength;
c8* datac8 = (c8*)(data); c8* datac8 = (c8*)(data);
char tmp[3]; char tmp[3];
tmp[2] = 0; tmp[2] = 0;
......
...@@ -1366,6 +1366,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader) ...@@ -1366,6 +1366,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader)
Attributes.getLast()->setString(reader->getAttributeValue(L"value")); Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
} }
else else
if (element == L"binary")
{
addBinary(name.c_str(), 0, 0);
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"color") if (element == L"color")
{ {
addColor(name.c_str(), video::SColor()); addColor(name.c_str(), video::SColor());
......
...@@ -350,7 +350,7 @@ void CGUIButton::setPressedImage(video::ITexture* image) ...@@ -350,7 +350,7 @@ void CGUIButton::setPressedImage(video::ITexture* image)
PressedImage = image; PressedImage = image;
if (image) if (image)
{ {
core::dimension2di signedSize(image->getOriginalSize()); const core::dimension2di signedSize(image->getOriginalSize());
PressedImageRect = core::rect<s32>(core::position2d<s32>(0,0), signedSize); PressedImageRect = core::rect<s32>(core::position2d<s32>(0,0), signedSize);
} }
} }
......
...@@ -1410,14 +1410,17 @@ void CImage::copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT fo ...@@ -1410,14 +1410,17 @@ void CImage::copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT fo
else else
{ {
u8* tgtpos = (u8*) target; u8* tgtpos = (u8*) target;
u8* dstpos = (u8*) Data; u8* srcpos = (u8*) Data;
const u32 bwidth = width*bpp; const u32 bwidth = width*bpp;
const u32 rest = pitch-bwidth;
for (u32 y=0; y<height; ++y) for (u32 y=0; y<height; ++y)
{ {
memcpy(target, Data, height*pitch); // copy scanline
memset(tgtpos+width, 0, pitch-bwidth); memcpy(tgtpos, srcpos, bwidth);
// clear pitch
memset(tgtpos+bwidth, 0, rest);
tgtpos += pitch; tgtpos += pitch;
dstpos += Pitch; srcpos += Pitch;
} }
return; return;
} }
......
...@@ -140,13 +140,16 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -140,13 +140,16 @@ IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
video::SColor color(0xffffffff); video::SColor color(0xffffffff);
if (attrib & 0x8000) if (attrib & 0x8000)
color = video::A1R5G5B5toA8R8G8B8(attrib); color = video::A1R5G5B5toA8R8G8B8(attrib);
mb->Vertices.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df())); if (normal==core::vector3df())
mb->Vertices.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df())); normal=core::plane3df(vertex[2],vertex[1],vertex[0]).Normal;
mb->Vertices.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df())); mb->Vertices.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df()));
mb->Vertices.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df()));
mb->Vertices.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df()));
mb->Indices.push_back(vCount); mb->Indices.push_back(vCount);
mb->Indices.push_back(vCount+1); mb->Indices.push_back(vCount+1);
mb->Indices.push_back(vCount+2); mb->Indices.push_back(vCount+2);
} // end while (file->getPos() < filesize) } // end while (file->getPos() < filesize)
mesh->getMeshBuffer(0)->recalculateBoundingBox();
// Create the Animated mesh if there's anything in the mesh // Create the Animated mesh if there's anything in the mesh
SAnimatedMesh* pAM = 0; SAnimatedMesh* pAM = 0;
...@@ -205,6 +208,7 @@ void CSTLMeshFileLoader::getNextVector(io::IReadFile* file, core::vector3df& vec ...@@ -205,6 +208,7 @@ void CSTLMeshFileLoader::getNextVector(io::IReadFile* file, core::vector3df& vec
getNextToken(file, tmp); getNextToken(file, tmp);
core::fast_atof_move(tmp.c_str(), vec.Z); core::fast_atof_move(tmp.c_str(), vec.Z);
} }
vec.X=-vec.X;
} }
......
...@@ -265,8 +265,8 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode* ...@@ -265,8 +265,8 @@ ISceneNodeAnimator* CSceneNodeAnimatorCollisionResponse::createClone(ISceneNode*
if (!newManager) newManager = SceneManager; if (!newManager) newManager = SceneManager;
CSceneNodeAnimatorCollisionResponse * newAnimator = CSceneNodeAnimatorCollisionResponse * newAnimator =
new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius, (Gravity * 1000.0f), Translation, new CSceneNodeAnimatorCollisionResponse(newManager, World, Object, Radius,
SlidingSpeed); (Gravity * 1000.0f), Translation, SlidingSpeed);
return newAnimator; return newAnimator;
} }
......
...@@ -2257,9 +2257,11 @@ void CXMeshFileLoader::readUntilEndOfLine() ...@@ -2257,9 +2257,11 @@ void CXMeshFileLoader::readUntilEndOfLine()
u16 CXMeshFileLoader::readBinWord() u16 CXMeshFileLoader::readBinWord()
{ {
u8 *Q = (u8 *)P; #ifdef __BIG_ENDIAN__
u16 tmp = 0; const u16 tmp = os::Byteswap::byteswap(*(u16 *)P);
tmp = Q[0] + (Q[1] << 8); #else
const u16 tmp = *(u16 *)P;
#endif
P += 2; P += 2;
return tmp; return tmp;
} }
...@@ -2267,9 +2269,11 @@ u16 CXMeshFileLoader::readBinWord() ...@@ -2267,9 +2269,11 @@ u16 CXMeshFileLoader::readBinWord()
u32 CXMeshFileLoader::readBinDWord() u32 CXMeshFileLoader::readBinDWord()
{ {
u8 *Q = (u8 *)P; #ifdef __BIG_ENDIAN__
u32 tmp = 0; const u32 tmp = os::Byteswap::byteswap(*(u32 *)P);
tmp = Q[0] + (Q[1] << 8) + (Q[2] << 16) + (Q[3] << 24); #else
const u32 tmp = *(u32 *)P;
#endif
P += 4; P += 4;
return tmp; return tmp;
} }
...@@ -2281,7 +2285,7 @@ u32 CXMeshFileLoader::readInt() ...@@ -2281,7 +2285,7 @@ u32 CXMeshFileLoader::readInt()
{ {
if (!BinaryNumCount) if (!BinaryNumCount)
{ {
u16 tmp = readBinWord(); // 0x06 or 0x03 const u16 tmp = readBinWord(); // 0x06 or 0x03
if (tmp == 0x06) if (tmp == 0x06)
BinaryNumCount = readBinDWord(); BinaryNumCount = readBinDWord();
else else
...@@ -2304,7 +2308,7 @@ f32 CXMeshFileLoader::readFloat() ...@@ -2304,7 +2308,7 @@ f32 CXMeshFileLoader::readFloat()
{ {
if (!BinaryNumCount) if (!BinaryNumCount)
{ {
u16 tmp = readBinWord(); // 0x07 or 0x42 const u16 tmp = readBinWord(); // 0x07 or 0x42
if (tmp == 0x07) if (tmp == 0x07)
BinaryNumCount = readBinDWord(); BinaryNumCount = readBinDWord();
else else
...@@ -2313,17 +2317,26 @@ f32 CXMeshFileLoader::readFloat() ...@@ -2313,17 +2317,26 @@ f32 CXMeshFileLoader::readFloat()
--BinaryNumCount; --BinaryNumCount;
if (FloatSize == 8) if (FloatSize == 8)
{ {
char tmp[8]; #ifdef __BIG_ENDIAN__
memcpy(tmp, P, 8); c8 ctmp[8];
*((f32*)(ctmp+4)) = os::Byteswap::byteswap(*(f32 *)P);
*((f32*)(ctmp)) = os::Byteswap::byteswap(*(f32 *)P+4);
const f32 tmp = (f32)(*(f64 *)ctmp);
#else
const f32 tmp = (f32)(*(f64 *)P);
#endif
P += 8; P += 8;
return (f32)(*(f64 *)tmp); return tmp;
} }
else else
{ {
char tmp[4]; #ifdef __BIG_ENDIAN__
memcpy(tmp, P, 4); const f32 tmp = os::Byteswap::byteswap(*(f32 *)P);
#else
const f32 tmp = *(f32 *)P;
#endif
P += 4; P += 4;
return *(f32 *)tmp; return tmp;
} }
} }
findNextNoneWhiteSpaceNumber(); findNextNoneWhiteSpaceNumber();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment